1 19 20 package org.netbeans.modules.mdrxml.looks; 21 22 import java.awt.datatransfer.Transferable ; 23 import java.awt.datatransfer.StringSelection ; 24 import java.io.IOException ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import javax.jmi.reflect.*; 28 import javax.jmi.model.*; 29 import org.openide.util.NbBundle; 30 import org.netbeans.api.looks.*; 31 import org.netbeans.spi.looks.*; 32 import org.netbeans.api.mdr.*; 33 import xmlmodel.XmlmodelPackage; 34 import xmlmodel.RootNodeClass; 35 import xmlmodel.RootNode; 36 import org.netbeans.modules.mdrxml.util.XMLModelEventTranslator; 37 import org.netbeans.modules.mdrxml.util.NodeEventTranslator; 38 42 public class DocumentsLook extends DefaultLook { 43 44 private static final String ICON = "org/netbeans/modules/mdrxml/resources/packageproxy"; 45 46 47 public DocumentsLook() { 48 super (NbBundle.getMessage (DocumentsLook.class, "TXT_DocumentsLook")); 49 } 50 51 public Object attachTo (Look.NodeSubstitute substitute) { 52 super.attachTo (substitute); 53 XMLModelEventTranslator translator = XMLModelEventTranslator.addXMLPackage(substitute); 54 return new NodeEventTranslator (translator,(RefBaseObject)substitute.getRepresentedObject(),substitute); 55 } 56 57 public String getName (Look.NodeSubstitute substitute) { 58 RefPackage pkg = (RefPackage) substitute.getRepresentedObject (); 59 MDRepository repo = ((MDRObject)pkg).repository(); 60 String [] names = repo.getExtentNames (); 61 for (int i=0; i< names.length; i++) { 62 if (repo.getExtent (names[i]).equals (pkg)) 63 return names[i]; 64 } 65 return ((MofPackage)pkg.refMetaObject()).getName(); 66 } 67 68 public String getDisplayName (Look.NodeSubstitute substitute) { 69 return this.getName (substitute); 70 } 71 72 public String iconBase (Look.NodeSubstitute substitute) { 73 return ICON; 74 } 75 76 public Object [] getChildObjects (Look.NodeSubstitute substitute) { 77 XmlmodelPackage pkg = (XmlmodelPackage) substitute.getRepresentedObject (); 78 MDRepository repo = ((MDRObject)pkg).repository (); 79 repo.beginTrans (false); 80 try { 81 RootNodeClass rnClass = pkg.getRootNode (); 82 Collection rootNodes = rnClass.refAllOfClass (); 83 Object [] result = new Object [rootNodes.size()]; 84 Iterator it = rootNodes.iterator (); 85 for (int i=0; it.hasNext(); i++) { 86 result[i] = it.next(); 87 } 88 return result; 89 }finally { 90 repo.endTrans (); 91 } 92 } 93 94 public Transferable clipboardCopy (Look.NodeSubstitute substitute) throws IOException { 95 return new StringSelection (this.getName(substitute)); 96 } 97 98 public boolean canCopy (Look.NodeSubstitute substitute) { 99 return true; 100 } 101 102 } 103 | Popular Tags |