1 19 20 package org.netbeans.modules.xml.schema.ui.nodes.categorized; 21 22 import java.lang.ref.SoftReference ; 23 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext; 24 import org.netbeans.modules.xml.xam.ui.column.Column; 25 import org.netbeans.modules.xml.xam.ui.column.ColumnProvider; 26 import org.netbeans.modules.xml.xam.ui.customizer.CustomizerProvider; 27 import org.openide.filesystems.FileObject; 28 import org.openide.loaders.DataObject; 29 import org.openide.loaders.DataObjectNotFoundException; 30 import org.openide.nodes.Children; 31 import org.openide.nodes.AbstractNode; 32 import org.openide.nodes.Node; 33 import org.openide.util.Lookup; 34 import org.openide.util.NbBundle; 35 import org.openide.util.lookup.AbstractLookup; 36 import org.openide.util.lookup.InstanceContent; 37 import org.openide.util.lookup.Lookups; 38 import org.openide.util.lookup.ProxyLookup; 39 40 43 public class DetailsNode extends AbstractNode 44 { 45 46 private CustomizerProvider provider; 47 50 private boolean readonly; 51 52 53 public DetailsNode(SchemaUIContext context, CustomizerProvider provider) 54 { 55 this(context,provider,new InstanceContent()); 56 } 57 58 private DetailsNode(SchemaUIContext context, 59 CustomizerProvider provider, 60 InstanceContent contents) 61 { 62 63 super(Children.LEAF, createLookup(context, contents)); 64 setDisplayName(getTypeDisplayName()); 65 setIconBaseWithExtension( 66 "org/netbeans/modules/xml/schema/ui/nodes/resources/"+ 67 "XML-Schema-element-details.png"); 68 69 this.provider = provider; 70 71 contents.add(this); 72 contents.add(context); 73 contents.add(provider); 74 contents.add( 75 new ColumnProvider() 76 { 77 public Column getColumn() 78 { 79 DetailsColumn column=columnRef!=null ? 80 columnRef.get() : null; 81 if (column==null) 82 { 83 column=createColumn(); 84 columnRef=new SoftReference <DetailsColumn>(column); 85 } 86 column.setReadOnly(isReadOnly()); 87 return column; 88 } 89 90 private SoftReference <DetailsColumn> columnRef; 91 }); 92 try { 93 FileObject fobj = (FileObject) context.getModel(). 96 getModelSource().getLookup().lookup(FileObject.class); 97 if (fobj != null) { 98 contents.add(DataObject.find(fobj)); 99 } 100 } catch (DataObjectNotFoundException donfe) { 101 } 102 } 103 104 110 private static Lookup createLookup(SchemaUIContext context, 111 InstanceContent contents) { 112 return new ProxyLookup(new Lookup[] { 117 Lookups.exclude(context.getLookup(), new Class [] { 118 Node.class, 119 DataObject.class, 120 }), 121 new AbstractLookup(contents), 122 }); 123 } 124 125 public boolean isReadOnly() 126 { 127 return readonly; 128 } 129 130 public void setReadOnly(boolean readonly) 131 { 132 this.readonly = readonly; 133 } 134 135 138 protected DetailsColumn createColumn() 139 { 140 return new DetailsColumn(provider.getCustomizer()); 141 } 142 143 144 145 148 public String getTypeDisplayName() 149 { 150 return NbBundle.getMessage(DetailsNode.class, "LBL_DetailsNode"); } 152 153 public int hashCode() 154 { 155 return provider.hashCode(); 156 } 157 158 } 159 | Popular Tags |