KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > mdrxml > looks > DocumentsLook


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is Forte for Java, Community Edition. The Initial
16  * Developer of the Original Software is Sun Microsystems, Inc. Portions
17  * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.mdrxml.looks;
21
22 import java.awt.datatransfer.Transferable JavaDoc;
23 import java.awt.datatransfer.StringSelection JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.Iterator JavaDoc;
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 /**
39  *
40  * @author Tomas Zezula
41  */

42 public class DocumentsLook extends DefaultLook {
43     
44     private static final String JavaDoc ICON = "org/netbeans/modules/mdrxml/resources/packageproxy";
45     
46     /** Creates a new instance of DocumentsLook */
47     public DocumentsLook() {
48         super (NbBundle.getMessage (DocumentsLook.class, "TXT_DocumentsLook"));
49     }
50     
51     public Object JavaDoc 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 JavaDoc getName (Look.NodeSubstitute substitute) {
58         RefPackage pkg = (RefPackage) substitute.getRepresentedObject ();
59         MDRepository repo = ((MDRObject)pkg).repository();
60         String JavaDoc[] 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 JavaDoc getDisplayName (Look.NodeSubstitute substitute) {
69         return this.getName (substitute);
70     }
71     
72     public String JavaDoc iconBase (Look.NodeSubstitute substitute) {
73         return ICON;
74     }
75     
76     public Object JavaDoc[] 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 JavaDoc rootNodes = rnClass.refAllOfClass ();
83             Object JavaDoc[] result = new Object JavaDoc [rootNodes.size()];
84             Iterator JavaDoc 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 JavaDoc clipboardCopy (Look.NodeSubstitute substitute) throws IOException JavaDoc {
95         return new StringSelection JavaDoc (this.getName(substitute));
96     }
97     
98     public boolean canCopy (Look.NodeSubstitute substitute) {
99         return true;
100     }
101     
102 }
103
Popular Tags