1 19 20 28 29 package org.netbeans.modules.xml.schema.ui.nodes.categorized; 30 31 import java.awt.datatransfer.Transferable ; 32 import java.beans.PropertyEditor ; 33 import java.lang.reflect.InvocationTargetException ; 34 import java.text.MessageFormat ; 35 import java.util.ArrayList ; 36 import java.util.Collections ; 37 import javax.swing.Action ; 38 import org.netbeans.modules.xml.refactoring.actions.RefactorAction; 39 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode; 40 import org.openide.nodes.FilterNode; 41 import org.openide.nodes.Node; 42 import org.openide.nodes.Node.Property; 43 import org.openide.nodes.Node.PropertySet; 44 import org.openide.nodes.PropertySupport; 45 import org.openide.util.Lookup; 46 import org.openide.util.datatransfer.NewType; 47 import org.openide.util.datatransfer.PasteType; 48 import org.openide.util.lookup.AbstractLookup; 49 import org.openide.util.lookup.InstanceContent; 50 import org.openide.util.lookup.ProxyLookup; 51 52 56 public class ReadOnlySchemaComponentNode extends FilterNode { 57 private transient String displayTemplate; 58 59 public ReadOnlySchemaComponentNode(Node original ,String displayTemplate) { 60 this(original); 61 this.displayTemplate = displayTemplate; 62 } 63 64 public ReadOnlySchemaComponentNode(Node original) { 65 this(original,new Children(original), new InstanceContent()); 66 } 67 68 protected ReadOnlySchemaComponentNode(Node original, 69 org.openide.nodes.Children children, InstanceContent ic) { 70 super(original, children, new ProxyLookup(new Lookup[] { 71 new AbstractLookup(ic), original.getLookup()})); 72 ic.add(this); 73 SchemaComponentNode scn = (SchemaComponentNode) original.getLookup(). 74 lookup(SchemaComponentNode.class); 75 if(scn!=null) scn.setReferencingNode(this); 76 } 77 78 public void setDisplayTemplate(String displayTemplate) { 79 this.displayTemplate = displayTemplate; 80 } 81 82 public String getDefaultDisplayName() { 83 String displayName = null; 84 SchemaComponentNode scn = (SchemaComponentNode) 85 getLookup().lookup(SchemaComponentNode.class); 86 if (scn != null) { 87 displayName = scn.getDefaultDisplayName(); 88 } else { 89 displayName = super.getDisplayName(); 90 } 91 if(displayTemplate!=null) 92 displayName = MessageFormat.format(displayTemplate,displayName); 93 return displayName; 94 } 95 96 97 public String getHtmlDisplayName() { 98 String retValue = super.getHtmlDisplayName(); 99 if(retValue == null) retValue = getDefaultDisplayName(); 100 if(retValue != null) 101 retValue = "<font color='#999999'>"+retValue+"</font>"; 102 return retValue; 103 } 104 105 public boolean canRename() { 106 return false; 107 } 108 109 public boolean canDestroy() { 110 return false; 111 } 112 113 public boolean canCut() { 114 return false; 115 } 116 117 public boolean canCopy() { 118 return true; 120 } 121 122 public boolean hasCustomizer() { 123 return false; 124 } 125 126 public Node.PropertySet[] getPropertySets() { 127 PropertySet[] retValue; 128 129 retValue = super.getPropertySets(); 130 for(int i=0;i<retValue.length;i++) { 131 Property[] props = retValue[i].getProperties(); 132 for(int j=0;j<props.length;j++) { 133 final Property prop = props[j]; 134 props[j] = new PropertySupport.ReadOnly( 135 prop.getName(), prop.getValueType(), 136 prop.getDisplayName(),prop.getShortDescription()) { 137 public Object getValue() throws IllegalAccessException ,InvocationTargetException { 138 return prop.getValue(); 139 } 140 public PropertyEditor getPropertyEditor() { 141 return prop.getPropertyEditor(); 143 } 144 145 }; 146 } 147 } 148 return retValue; 149 } 150 151 public NewType[] getNewTypes() { 152 return new NewType[]{}; 153 } 154 155 public PasteType[] getPasteTypes(Transferable transferable) { 156 return new PasteType[0]; 158 } 159 160 public PasteType getDropType(Transferable transferable, int action, int index) { 161 return null; 163 } 164 165 public Action [] getActions(boolean context) { 166 ArrayList <Action > actionList = new ArrayList <Action >(); 167 Collections.addAll(actionList,super.getActions(context)); 168 for(int i=0;i<actionList.size();) { 169 Action a=actionList.get(i++); 170 if(a instanceof RefactorAction) { 171 actionList.remove(a); 172 break; 173 } 174 } 175 return actionList.toArray(new Action [0]); 176 } 177 178 private static class Children extends FilterNode.Children { 179 public Children(Node original) { 180 super(original); 181 } 182 183 protected Node copyNode(Node node) { 184 DetailsNode detailsNode = 186 (DetailsNode) node.getLookup().lookup(DetailsNode.class); 187 if(detailsNode!=null) detailsNode.setReadOnly(true); 188 ReadOnlySchemaComponentNode roNode = (ReadOnlySchemaComponentNode)node. 190 getLookup().lookup(ReadOnlySchemaComponentNode.class); 191 if(roNode!=null) return super.copyNode(roNode); 192 return new ReadOnlySchemaComponentNode(node); 194 } 195 } 196 } 197 | Popular Tags |