merge the formfield patch from ooo-build
[ooovba.git] / scripting / java / org / openoffice / netbeans / modules / office / nodes / ParcelDescriptorChildren.java
blobfb38ecfe7c6cda77991ecf16ebb1fcfbaae062dc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ParcelDescriptorChildren.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package org.openoffice.netbeans.modules.office.nodes;
33 import java.util.*;
34 import javax.swing.event.ChangeEvent;
35 import javax.swing.event.ChangeListener;
37 import org.w3c.dom.NodeList;
38 import org.w3c.dom.Element;
40 import org.openide.nodes.*;
41 import org.openoffice.netbeans.modules.office.actions.ParcelDescriptorParserCookie;
43 /** List of children of a containing node.
44 * Remember to document what your permitted keys are!
46 * @author tomaso
48 public class ParcelDescriptorChildren extends Children.Keys implements ChangeListener {
50 private ParcelDescriptorParserCookie parserCookie = null;
52 public ParcelDescriptorChildren(ParcelDescriptorParserCookie cookie) {
53 parserCookie = cookie;
56 private void refreshKeys() {
57 NodeList nl;
58 int len;
60 if (parserCookie == null ||
61 (nl = parserCookie.getScriptElements()) == null ||
62 (len = nl.getLength()) == 0) {
63 setKeys(Collections.EMPTY_SET);
64 return;
67 ArrayList keys = new ArrayList(len);
68 for (int i = 0; i < len; i++)
69 keys.add(nl.item(i));
70 setKeys(keys);
73 protected void addNotify() {
74 super.addNotify();
75 parserCookie.addChangeListener(this);
76 refreshKeys();
79 protected void removeNotify() {
80 super.removeNotify();
81 parserCookie.removeChangeListener(this);
82 setKeys(Collections.EMPTY_SET);
85 protected Node[] createNodes(Object key) {
86 Element el = (Element)key;
87 System.out.println("element is: " + el);
88 return new Node[] {new ScriptNode(el)};
91 public void stateChanged(ChangeEvent e) {
92 refreshKeys();