001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.wsdl.refactoring.ui.tree;
043:
044: import java.beans.BeanInfo;
045: import java.text.MessageFormat;
046: import java.util.HashMap;
047: import java.util.List;
048: import java.util.Map;
049: import javax.swing.Icon;
050: import javax.swing.ImageIcon;
051:
052: import org.netbeans.modules.refactoring.api.RefactoringElement;
053: import org.netbeans.modules.refactoring.spi.ui.TreeElementFactory;
054: import org.netbeans.modules.refactoring.spi.ui.*;
055: import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
056: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
057: import org.netbeans.modules.xml.wsdl.ui.netbeans.module.WSDLDataObject;
058: import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.NodesFactory;
059: import org.netbeans.modules.xml.xam.Component;
060: import org.netbeans.modules.xml.xam.Model;
061: import org.netbeans.modules.xml.xam.ModelSource;
062: import org.netbeans.modules.xml.xam.Named;
063: import org.netbeans.modules.xml.xam.Referenceable;
064: import org.openide.filesystems.FileObject;
065: import org.openide.loaders.DataObject;
066: import org.openide.nodes.Node;
067: import org.openide.util.NbBundle;
068: import org.openide.util.Utilities;
069: import org.openide.util.lookup.Lookups;
070:
071: /**
072: *
073: * @author Jan Becicka
074: */
075: public class WSDLTreeElement implements TreeElement {
076:
077: RefactoringElement element = null;
078: Component comp;
079: Node node = null;
080:
081: WSDLTreeElement(RefactoringElement element) {
082: this .element = element;
083: this .comp = element.getLookup().lookup(WSDLComponent.class);
084:
085: assert comp instanceof WSDLComponent : "This TreeElement handles WSDLComponents only";
086:
087: try {
088: Model model = comp.getModel();
089: if (model instanceof WSDLModel) {
090: ModelSource ms = model.getModelSource();
091: FileObject fo = (FileObject) ms.getLookup().lookup(
092: FileObject.class);
093: if (fo != null) {
094: DataObject dObj = DataObject.find(fo);
095: if (dObj != null && dObj instanceof WSDLDataObject) {
096: node = NodesFactory.getInstance().create(comp);
097: }
098: }
099: }
100: } catch (Exception e) {
101: e.printStackTrace();
102: }
103:
104: //TO DO if the node is null???
105: }
106:
107: WSDLTreeElement(Object element) {
108: this .comp = (WSDLComponent) element;
109:
110: try {
111: Model model = comp.getModel();
112: if (model instanceof WSDLModel) {
113: ModelSource ms = model.getModelSource();
114: FileObject fo = (FileObject) ms.getLookup().lookup(
115: FileObject.class);
116: if (fo != null) {
117: DataObject dObj = DataObject.find(fo);
118: if (dObj != null && dObj instanceof WSDLDataObject) {
119: node = NodesFactory.getInstance().create(comp);
120: }
121: }
122: }
123: } catch (Exception e) {
124: e.printStackTrace();
125: }
126: }
127:
128: public TreeElement getParent(boolean isLogical) {
129: TreeElement result = null;
130: if (comp.getParent() != null) {
131: return TreeElementFactory.getTreeElement(comp.getParent());
132: } else {
133: FileObject fo = (FileObject) comp.getModel()
134: .getModelSource().getLookup().lookup(
135: FileObject.class);
136: return TreeElementFactory.getTreeElement(fo);
137: }
138:
139: }
140:
141: public Icon getIcon() {
142: return new ImageIcon(node.getIcon(BeanInfo.ICON_COLOR_16x16));
143:
144: }
145:
146: public String getText(boolean isLogical) {
147: if (element != null) {
148: String htmlDisplayName = node.getHtmlDisplayName();
149: String usageTreeNodeLabel = MessageFormat.format(
150: NbBundle.getMessage(WSDLTreeElement.class,
151: "LBL_Usage_Node"), new Object[] {
152: node.getName(),
153: node.getShortDescription(), // comp type
154: htmlDisplayName == null ? ""
155: : htmlDisplayName });
156: return usageTreeNodeLabel;
157:
158: } else
159: return node.getName();
160:
161: }
162:
163: public Object getUserObject() {
164: if (element != null)
165: return element;
166: else
167: return comp;
168:
169: }
170: }
|