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-2007 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.uml.project.ui.nodes;
043:
044: import javax.swing.Action;
045:
046: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
047: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
048: import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeItem;
049: import org.netbeans.modules.uml.ui.controls.projecttree.ProjectTreeItemImpl;
050: import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder;
051: import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem;
052: import org.netbeans.modules.uml.project.ui.nodes.actions.NewDiagramType;
053: import org.netbeans.modules.uml.project.ui.nodes.actions.NewPackageType;
054: import org.netbeans.modules.uml.project.ui.nodes.actions.NewElementType;
055: import org.netbeans.modules.uml.project.ui.nodes.actions.NewAttributeType;
056: import org.netbeans.modules.uml.project.ui.nodes.actions.NewOperationType;
057:
058: import org.openide.nodes.Children;
059: import org.openide.util.Lookup;
060: import org.openide.util.datatransfer.NewType;
061:
062: /**
063: *
064: * @author Trey Spiva
065: */
066: public class UMLFolderNode extends UMLElementNode implements
067: ITreeFolder {
068:
069: private String m_GetMethodName = ""; // NOI18N
070: private String m_Name = ""; // NOI18N
071: private String m_ID = ""; // NOI18N
072:
073: public final static String METHOD_NAME_GET_ATTRIBUTES = "getAttributes"; // NOI18N
074: public final static String METHOD_NAME_GET_OPERATIONS = "getOperations"; // NOI18N
075:
076: public UMLFolderNode() {
077: this (new ProjectTreeItemImpl());
078: }
079:
080: public UMLFolderNode(Lookup lookup) {
081: this (lookup, new ProjectTreeItemImpl());
082: }
083:
084: public UMLFolderNode(Children ch, Lookup lookup) {
085: this (ch, lookup, new ProjectTreeItemImpl());
086: }
087:
088: /**
089: * @param item
090: */
091: public UMLFolderNode(IProjectTreeItem item) {
092: super (item);
093: }
094:
095: /**
096: * @param item
097: */
098: public UMLFolderNode(Lookup lookup, IProjectTreeItem item) {
099: super (lookup, item);
100: }
101:
102: /**
103: * @param item
104: */
105: public UMLFolderNode(Children ch, Lookup lookup,
106: IProjectTreeItem item) {
107: super (ch, lookup, item);
108: }
109:
110: /* (non-Javadoc)
111: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem#addChild(org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem)
112: */
113: public void addChild(ITreeItem item) {
114: // String yourID = item.getData().getModelElementXMIID();
115: // String myID = getData().getModelElementXMIID();
116: // if(yourID.equals(myID) == false)
117: // {
118: super .addChild(item);
119: // }
120: }
121:
122: public void setID(String id) {
123: m_ID = id;
124: }
125:
126: /* (non-Javadoc)
127: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getID()
128: */
129: public String getID() {
130: return m_ID;
131: }
132:
133: /* (non-Javadoc)
134: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setGetMethod(java.lang.String)
135: */
136: public void setGetMethod(String name) {
137: m_GetMethodName = name;
138: }
139:
140: /* (non-Javadoc)
141: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getGetMethod()
142: */
143: public String getGetMethod() {
144: return m_GetMethodName;
145: }
146:
147: /**
148: * Sets the element that this tree folder represents.
149: *
150: * @param newVal The element that this folder represents
151: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setElement(com.embarcadero.describe.foundation.IElement)
152: */
153: public void setElement(IElement newVal) {
154: IProjectTreeItem data = getData();
155: if (data != null) {
156: data.setModelElement(newVal);
157: }
158: }
159:
160: /**
161: * Get the new types that can be created in this node. For example, a node
162: * representing a class will permit attributes, operations, classes,
163: * interfaces, and enumerations to be added.
164: *
165: * @return An array of new type operations that are allowed.
166: */
167: public NewType[] getNewTypes() {
168: String elType = getElementType();
169:
170: NewType[] retVal = null;
171:
172: if (getModelElement() instanceof INamespace) {
173: // Class types: Java Class
174: if (elType.equals(ELEMENT_TYPE_CLASS)) {
175: if (getGetMethod().equals(METHOD_NAME_GET_OPERATIONS)) {
176: return new NewType[] { new NewOperationType(this ) };
177: }
178:
179: else if (getGetMethod().equals(
180: METHOD_NAME_GET_ATTRIBUTES)) {
181: return new NewType[] { new NewAttributeType(this ) };
182: }
183: }
184:
185: else if (elType.equals(ELEMENT_TYPE_OPERATION)) {
186: return new NewType[] { new NewDiagramType(this ),
187: new NewPackageType(this ),
188: new NewElementType(this ) };
189: }
190: } // if getModelElement() instanceof INamespace
191:
192: if (retVal == null) {
193: retVal = new NewType[0];
194: }
195:
196: return retVal;
197: }
198:
199: public Action[] getActions(boolean context) {
200: String elemType = getElementType();
201: if (elemType.equals(ELEMENT_TYPE_OPERATION)
202: || elemType.equals(ELEMENT_TYPE_ATTRIBUTE)
203: || getName().equals("Operations") || // NOI18N
204: getName().equals("Attributes")) // NOI18N
205: {
206: return super .getNewMenuAction();
207: // return new Action[]
208: // {
209: // SystemAction.get(NewAction.class)
210: // };
211: }
212:
213: else
214: return new Action[] { null };
215: }
216:
217: public boolean canDestroy() {
218: return false;
219: }
220:
221: /**
222: * Returns the element that this tree folder represents.
223: *
224: * @return The element that this folder represents, or NULL
225: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#getElement()
226: */
227: public IElement getElement() {
228: IElement retVal = null;
229:
230: IProjectTreeItem data = getData();
231: if (data != null) {
232: retVal = data.getModelElement();
233: }
234:
235: return retVal;
236: }
237:
238: /* (non-Javadoc)
239: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setPath(java.lang.String)
240: */
241: public void setPath(ITreeItem[] defPath) {
242: IProjectTreeItem data = getData();
243: if (data != null) {
244: data.setPath(defPath);
245: }
246: }
247:
248: /* (non-Javadoc)
249: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#setIsGetMethodAnImport(boolean)
250: */
251: public void setIsGetMethodAnImport(boolean value) {
252:
253: }
254:
255: /**
256: * Is the get method the one used to get imported packages or elements?
257: *
258: * retVal <b>true</b> if the get method is one used to get package or element
259: * imports.
260: * @see org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeFolder#isGetMethodAnImport()
261: */
262: public boolean isGetMethodAnImport() {
263: boolean retVal = false;
264: if ((getGetMethod().equals("ImportedElements") == true) || // NOI18N
265: (getGetMethod().equals("ImportedPackages") == true)) // NOI18N
266: {
267: retVal = true;
268: }
269:
270: return retVal;
271: }
272:
273: /**
274: * Is the get method the one used to get imported elements?
275: *
276: * @return <b>true</b> if the get method is an import, <b>false</b>
277: * if the get method is not an import.
278: */
279: public boolean isGetMethodAnImportElement() {
280: boolean retVal = false;
281: if (getGetMethod().equals("ImportedElements")) // NOI18N
282: {
283: retVal = true;
284: }
285:
286: return retVal;
287: }
288:
289: /**
290: * Is the get method the one used to get imported packages?
291: *
292: * @return <b>true</b> if the get method is an import, <b>false</b>
293: * if the get method is not an import.
294: */
295: public boolean isGetMethodAnImportPackage() {
296: boolean retVal = false;
297: if (getGetMethod().equals("ImportedPackages")) // NOI18N
298: {
299: retVal = true;
300: }
301:
302: return retVal;
303: }
304:
305: public String getType() {
306: return getName();
307: }
308:
309: /* (non-Javadoc)
310: * @see java.lang.Object#equals(java.lang.Object)
311: */
312: public boolean equals(Object obj) {
313: boolean retVal = false;
314:
315: if (obj instanceof ITreeFolder) {
316: ITreeFolder folder = (ITreeFolder) obj;
317:
318: if ((getDisplayName() != null)
319: && (folder.getDisplayName() != null)) {
320: if (getDisplayName().equals(folder.getDisplayName()) == true) {
321: if ((getID() == null) && (folder.getID() == null)) {
322: retVal = true;
323: } else if ((getID() != null)
324: && (folder.getID() != null)) {
325: retVal = getID().equals(folder.getID());
326: }
327: }
328: }
329: }
330:
331: return retVal;
332: }
333:
334: public void setName(String val) {
335: m_Name = val;
336: super .setName(val);
337: }
338:
339: public String getName() {
340: return m_Name;
341: }
342:
343: public boolean canRename() {
344: return false;
345: }
346: }
|