1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.netbeans.modules.office.nodes;
25 
26 import java.util.*;
27 import javax.swing.event.ChangeEvent;
28 import javax.swing.event.ChangeListener;
29 
30 import org.w3c.dom.NodeList;
31 import org.w3c.dom.Element;
32 
33 import org.openide.nodes.*;
34 import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorParserCookie;
35 
36 /** List of children of a containing node.
37  * Remember to document what your permitted keys are!
38  *
39  * @author tomaso
40  */
41 public class ParcelDescriptorChildren extends Children.Keys implements ChangeListener {
42 
43     private ParcelDescriptorParserCookie parserCookie = null;
44 
ParcelDescriptorChildren(ParcelDescriptorParserCookie cookie)45     public ParcelDescriptorChildren(ParcelDescriptorParserCookie cookie) {
46         parserCookie = cookie;
47     }
48 
refreshKeys()49     private void refreshKeys() {
50         NodeList nl;
51         int len;
52 
53         if (parserCookie == null ||
54             (nl = parserCookie.getScriptElements()) == null ||
55             (len = nl.getLength()) == 0) {
56             setKeys(Collections.EMPTY_SET);
57             return;
58         }
59 
60         ArrayList keys = new ArrayList(len);
61         for (int i = 0; i < len; i++)
62             keys.add(nl.item(i));
63         setKeys(keys);
64     }
65 
addNotify()66     protected void addNotify() {
67         super.addNotify();
68         parserCookie.addChangeListener(this);
69         refreshKeys();
70     }
71 
removeNotify()72     protected void removeNotify() {
73         super.removeNotify();
74         parserCookie.removeChangeListener(this);
75         setKeys(Collections.EMPTY_SET);
76     }
77 
createNodes(Object key)78     protected Node[] createNodes(Object key) {
79         Element el = (Element)key;
80         System.out.println("element is: " + el);
81         return new Node[] {new ScriptNode(el)};
82     }
83 
stateChanged(ChangeEvent e)84     public void stateChanged(ChangeEvent e) {
85         refreshKeys();
86     }
87 }
88