1 19 20 package org.netbeans.modules.form; 21 22 import java.util.ArrayList ; 23 import java.awt.datatransfer.*; 24 25 import org.openide.nodes.*; 26 import org.openide.cookies.*; 27 import org.openide.actions.*; 28 import org.openide.util.actions.SystemAction; 29 30 import org.netbeans.modules.form.actions.AddAction; 31 import org.netbeans.modules.form.project.ClassSource; 32 33 38 39 class FormOthersNode extends FormNode { 40 41 public FormOthersNode(FormModel formModel) { 42 super(new OthersChildren(formModel), formModel); 43 44 getCookieSet().add(new OthersIndex((OthersChildren)getChildren())); 45 setIconBase("org/netbeans/modules/form/resources/formNonVisual"); setName("Others Node"); setName(FormUtils.getBundleString("CTL_NonVisualComponents")); } 49 50 public javax.swing.Action [] getActions(boolean context) { 51 if (systemActions == null) { ArrayList actions = new ArrayList (10); 53 54 if (!getFormModel().isReadOnly()) { 55 actions.add(SystemAction.get(AddAction.class)); 56 actions.add(null); 57 actions.add(SystemAction.get(PasteAction.class)); 58 actions.add(null); 59 actions.add(SystemAction.get(ReorderAction.class)); 60 actions.add(null); 61 } 62 63 javax.swing.Action [] superActions = super.getActions(context); 64 for (int i=0; i < superActions.length; i++) 65 actions.add(superActions[i]); 66 67 systemActions = new SystemAction[actions.size()]; 68 actions.toArray(systemActions); 69 } 70 71 return systemActions; 72 } 73 74 protected void createPasteTypes(Transferable t, java.util.List s) { 75 FormModel formModel = getFormModel(); 76 if (formModel.isReadOnly()) 77 return; 78 79 boolean copy = t.isDataFlavorSupported( 80 CopySupport.getComponentCopyFlavor()); 81 boolean cut = t.isDataFlavorSupported( 82 CopySupport.getComponentCutFlavor()); 83 84 if (copy || cut) { RADComponent transComp = null; 86 try { 87 Object data = t.getTransferData(t.getTransferDataFlavors()[0]); 88 if (data instanceof RADComponent) 89 transComp = (RADComponent) data; 90 } 91 catch (UnsupportedFlavorException e) {} catch (java.io.IOException e) {} 94 if (transComp != null 95 && (!cut || CopySupport.canPasteCut(transComp, formModel, null))) 96 { 97 s.add(new CopySupport.RADPaste(t, formModel, null)); 98 } 99 } 100 else { ClassSource classSource = CopySupport.getCopiedBeanClassSource(t); 102 if (classSource != null) { 103 s.add(new CopySupport.ClassPaste(t, classSource, formModel, null)); 104 } 105 } 106 } 107 108 110 static class OthersChildren extends FormNodeChildren { 111 112 private FormModel formModel; 113 114 protected OthersChildren(FormModel formModel) { 115 this.formModel = formModel; 116 updateKeys(); 117 } 118 119 protected void updateKeys() { 121 setKeys(formModel.getOtherComponents().toArray()); 122 } 123 124 protected Node[] createNodes(Object key) { 125 Node node = new RADComponentNode((RADComponent)key); 126 node.getChildren().getNodes(); return new Node[] { node }; 128 } 129 130 protected final FormModel getFormModel() { 131 return formModel; 132 } 133 } 134 135 137 static final class OthersIndex extends org.openide.nodes.Index.Support { 138 private OthersChildren children; 139 140 public OthersIndex(OthersChildren children) { 141 this.children = children; 142 } 143 144 public Node[] getNodes() { 145 return children.getNodes(); 146 } 147 148 public int getNodesCount() { 149 return getNodes().length; 150 } 151 152 public void reorder(int[] perm) { 153 ComponentContainer cont = children.getFormModel().getModelContainer(); 154 cont.reorderSubComponents(perm); 155 children.getFormModel().fireComponentsReordered(cont, perm); 156 } 158 } 159 } 160 | Popular Tags |