001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form;
043:
044: import java.util.ArrayList;
045: import java.awt.datatransfer.*;
046: import java.util.List;
047: import javax.swing.Action;
048:
049: import org.openide.nodes.*;
050: import org.openide.actions.*;
051: import org.openide.util.actions.SystemAction;
052:
053: import org.netbeans.modules.form.actions.AddAction;
054: import org.openide.util.datatransfer.PasteType;
055:
056: /**
057: * This class represents the root node of "Other Components".
058: *
059: * @author Tomas Pavek
060: */
061:
062: class FormOthersNode extends FormNode {
063:
064: public FormOthersNode(FormModel formModel) {
065: super (new OthersChildren(formModel), formModel);
066:
067: getCookieSet().add(
068: new OthersIndex((OthersChildren) getChildren()));
069: setIconBaseWithExtension("org/netbeans/modules/form/resources/formNonVisual.gif"); // NOI18N
070: setName("Others Node"); // NOI18N
071: setName(FormUtils.getBundleString("CTL_NonVisualComponents")); // NOI18N
072: }
073:
074: @Override
075: public Action[] getActions(boolean context) {
076: if (actions == null) { // from AbstractNode
077: List<Action> l = new ArrayList<Action>();
078: if (!getFormModel().isReadOnly()) {
079: l.add(SystemAction.get(AddAction.class));
080: l.add(null);
081: l.add(SystemAction.get(PasteAction.class));
082: l.add(null);
083: l.add(SystemAction.get(ReorderAction.class));
084: l.add(null);
085: }
086: for (Action a : super .getActions(context)) {
087: l.add(a);
088: }
089: actions = l.toArray(new Action[l.size()]);
090: }
091:
092: return actions;
093: }
094:
095: @Override
096: protected void createPasteTypes(Transferable t,
097: java.util.List<PasteType> s) {
098: CopySupport.createPasteTypes(t, s, getFormModel(), null);
099: }
100:
101: // -------------
102:
103: static class OthersChildren extends FormNodeChildren {
104:
105: private FormModel formModel;
106:
107: protected OthersChildren(FormModel formModel) {
108: this .formModel = formModel;
109: updateKeys();
110: }
111:
112: // FormNodeChildren implementation
113: @Override
114: protected void updateKeys() {
115: setKeys(formModel.getOtherComponents().toArray());
116: }
117:
118: protected Node[] createNodes(Object key) {
119: Node node = new RADComponentNode((RADComponent) key);
120: node.getChildren().getNodes(); // enforce subnodes creation
121: return new Node[] { node };
122: }
123:
124: protected final FormModel getFormModel() {
125: return formModel;
126: }
127: }
128:
129: // -------------
130:
131: static final class OthersIndex extends
132: org.openide.nodes.Index.Support {
133: private OthersChildren children;
134:
135: public OthersIndex(OthersChildren children) {
136: this .children = children;
137: }
138:
139: public Node[] getNodes() {
140: return children.getNodes();
141: }
142:
143: public int getNodesCount() {
144: return getNodes().length;
145: }
146:
147: public void reorder(int[] perm) {
148: ComponentContainer cont = children.getFormModel()
149: .getModelContainer();
150: cont.reorderSubComponents(perm);
151: children.getFormModel().fireComponentsReordered(cont, perm);
152: // children.updateKeys();
153: }
154: }
155: }
|