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: /*
043: *
044: * Created on Jun 2, 2003
045: * @author Trey Spiva
046: */
047: package org.netbeans.modules.uml.ui.controls.projecttree;
048:
049: import java.util.Comparator;
050: import org.netbeans.modules.uml.ui.support.projecttreesupport.ITreeItem;
051: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
052: import org.netbeans.modules.uml.core.metamodel.structure.IProject;
053: import org.netbeans.modules.uml.core.support.umlutils.ETList;
054: import org.netbeans.modules.uml.core.workspacemanagement.IWorkspace;
055:
056: /**
057: *
058: * @author Trey Spiva
059: */
060: public interface IProjectTreeModel {
061: /**
062: * Adds a listener for the TreeModelEvent posted after the tree changes.
063: *
064: * @param listener The lisener to add.
065: */
066: public void addProjectTreeModelListener(
067: IProjectTreeModelListener listener);
068:
069: /**
070: * Removes a listener previously added with <code>addProjectTreeModelListener</code>
071: *
072: * @param listener The listener to remove.
073: */
074: public void removeProjectTreeModelListener(
075: IProjectTreeModelListener listener);
076:
077: /**
078: * Returns the child of parent at a given index in the parent's child
079: * array. parent must be a node previously obtained from this data source.
080: * This should not return null if index is a valid index for parent (that is
081: * index >= 0 && index < getChildCount(parent)).
082: *
083: * @param parent A ITreeItem in the tree, obtained from this data source
084: * @param index The child to retrieve.
085: * @return
086: */
087: public ITreeItem getChildItem(Object parent, int index);
088:
089: /**
090: * Returns the number of children of parent. Returns 0 if the node is a leaf
091: * or if it has no children. parent must be a ITreeItem previously obtained
092: * from this data source.
093: *
094: * @param parent A ITreeItem in the tree, obtained from this data source
095: * @return
096: */
097: public int getChildCount(Object parent);
098:
099: /**
100: * Returns <code>true</code> if node is a leaf. It is possible for this
101: * method to return <code>false</code> even if node has no children. A
102: * directory in a filesystem, for example, may contain no files; the node
103: * representing the directory is not a leaf, but it also has no children.
104: *
105: * @param node A ITreeItem in the tree, obtained from this data source
106: * @return
107: */
108: public boolean isLeaf(Object node);
109:
110: /**
111: * Retrieves the workspace that the project tree is associated
112: * with.
113: *
114: * @return The workspace.
115: */
116: public IWorkspace getWorkspace();
117:
118: /**
119: * Retrieve the tree's root item.
120: *
121: * @return The root item.
122: */
123: public ITreeItem getRootItem();
124:
125: /**
126: * Retrieve Diagrams root node
127: *
128: * @return The Diagrams item.
129: */
130: public ITreeItem getDiagramsRootNode(IProject project);
131:
132: /**
133: * Check if the node is an instance of Diagrams root node
134: *
135: * @return true if the node is an instance of UMLDiagramRootNode; false otherwise.
136: */
137: public boolean isDiagramsRootNode(ITreeItem node);
138:
139: public IProjectTreeItem addItem(IProjectTreeItem parent,
140: String name, String text, long sortPriority,
141: IElement element, Object supportTreeItem, String description);
142:
143: public IProjectTreeItem addItem(ITreeItem parent, String name,
144: String text, long sortPriority, IElement element,
145: Object supportTreeItem, String description);
146:
147: /**
148: * Apends the node to the end of the parents child list.
149: *
150: * @param parent The parent to recieve the new node.
151: * @param node The node to be added.
152: */
153: public void addItem(ITreeItem parent, ITreeItem node);
154:
155: /**
156: * Inserts the new node into the parent child list at a specified location.
157: * The notifyOfAddedChildren will be sent after the node is added.
158: *
159: * @param parent The parent to recieve the new node.
160: * @param node The node to be added.
161: * @param index The index to insert the node. If the index is greater than
162: * the number of children the node will be appended to the
163: * end of the child list.
164: */
165: // public void insertItem(ITreeItem parent, ITreeItem node, int index);
166:
167: /**
168: * Remove all instances of the model element from the tree.
169: *
170: * @param element The element to remove.
171: */
172: public void removeAll(IElement element);
173:
174: /**
175: * Remove the specified node from its parent node. All model listeners will
176: * be notified of the change.
177: *
178: * @param node The node to remove.
179: */
180: public void removeNodeFromParent(ITreeItem node);
181:
182: /**
183: * The IProject will be associated to the node that represents the IWSProject
184: * element.
185: *
186: * @param pProject The project that has been opened.
187: * @return The ITreeItem that is the project node.
188: */
189: public ITreeItem projectOpened(IProject pProject);
190:
191: /**
192: * Clears the content of the model. This basically a refresh.
193: */
194: public void clear();
195:
196: /**
197: * Retrieves the index of a child node.
198: *
199: * @param parent The parent of the child node.
200: * @param child The child node to find.
201: * @return The index value. -1 if the second parameter is not a child of the
202: * parent node. The method <code>equals</code> is used to find the
203: * child node.
204: */
205: public int getIndexOfChild(ITreeItem parent, ITreeItem child);
206:
207: /**
208: * Sorts the children of a node. The children will be sorted occuring to
209: * the default sort order.
210: *
211: * @param parent The parent who children are to be sorted.
212: */
213: public void sortChildren(ITreeItem parent);
214:
215: /**
216: * Sorts the children of a node. The children will be sorted occuring to
217: * the Comparable interface.
218: *
219: * @param parent The parent who children are to be sorted.
220: * @param compare The comparable interface used to sort the children.
221: * @see Comparable
222: */
223: public void sortChildren(ITreeItem parent, Comparator compare);
224:
225: /**
226: * Locates the nodes that represents the model element.
227: *
228: * @param element The model element to locate.
229: * @return The tree Node. <code>null</code> is returned if the node
230: * is not found.
231: */
232: public ETList<ITreeItem> findNodes(IElement element);
233:
234: /**
235: * Locates the nodes that represents the diagram.
236: *
237: * @param filename The name of the file that specifies the diagram.
238: * @return The tree Nodes. <code>null</code> is returned if the node
239: * is not found.
240: */
241: public ETList<ITreeItem> findDiagramNodes(String filename);
242:
243: /**
244: * Locates the nodes that represents the model element.
245: *
246: * @param element The model element to locate.
247: * @return The tree Node. <code>null</code> is returned if the node
248: * is not found.
249: */
250: public ETList<ITreeItem> findNodes(Comparator<ITreeItem> comparator);
251:
252: /**
253: * Notifies all listeners that some of the nodes structure has changed.
254: * The mannor that the controls are notified is specific to the platform.
255: * <br>
256: * <b>Example:</b> For a Swing control the registered TreeModelListener will
257: * recieve the treeStructureChanged event.
258: *
259: * @parms items The tree items that has been changed.
260: */
261: public void notifyOfStructureChange(ETList<ITreeItem> items);
262:
263: /**
264: * Notifies all listeners that a child was removed from its parent.
265: * The mannor that the controls are notified is specific to the platform.
266: * <br>
267: * <b>Example:</b> For a Swing control the registered TreeModelListener will
268: * recieve the treeNodesRemoved event.
269: *
270: * @parms parent The parent tree item that is affected.
271: * @param childIndices The index of the child nodes that was removed.
272: * @param children The children nodes that was removed.
273: */
274: public void notifyOfRemovedChildren(ITreeItem parent,
275: int[] childIndices, ITreeItem[] children);
276:
277: /**
278: * Notifies all listeners that a child was added to a parent.
279: * The mannor that the controls are notified is specific to the platform.
280: * <br>
281: * <b>Example:</b> For a Swing control the registered TreeModelListener will
282: * recieve the treeNodesInserted event.
283: *
284: * @parms parent The parent tree item that is affected.
285: * @param childIndices The index of the child nodes that was added.
286: * @param children The children nodes that was added.
287: */
288: public void notifyOfAddedChildren(ITreeItem parent,
289: int[] childIndices/*,
290: ITreeItem[] children*/);
291:
292: /**
293: * Notifies all listeners that the content of some nodes has changed.
294: * The mannor that the controls are notified is specific to the platform.
295: * <br>
296: * <b>Example:</b> For a Swing control the registered TreeModelListener will
297: * recieve the treeNodesChanged event.
298: *
299: * @parms parent The parent tree item that is affected.
300: * @param childIndices The index of the child nodes that was added.
301: * @param children The children nodes that was added.
302: */
303: public void notifyOfNodesChanged(ITreeItem parent,
304: int[] childIndices, ITreeItem[] nodes);
305:
306: /**
307: * Test if it is OK to delete a tree item.
308: *
309: * @param item The item to test.
310: * @return <b>true</b> if it is OK to delete the tree item, <b>false</b> if
311: * it is not OK to delete the tree item.
312: */
313: public boolean canDelete(IProjectTreeItem item);
314:
315: /**
316: * Test if it is OK to edit a tree item.
317: *
318: * @param item The item to test.
319: * @return <b>true</b> if it is OK to delete the tree item, <b>false</b> if
320: * it is not OK to delete the tree item.
321: */
322: public boolean canEdit(IProjectTreeItem item);
323:
324: /**
325: * Retrieves the node factory to use when creating nodes for the model.
326: *
327: * @return The factory to use.
328: */
329: public ProjectTreeNodeFactory getNodeFactory();
330:
331: /**
332: * Retreives the name of the model.
333: */
334: public String getModelName();
335:
336: /**
337: * Fires an event when a given tree node is expanded
338: *
339: * @param item The item to be expanded.
340: *
341: */
342: public void fireItemExpanding(ITreeItem item);
343:
344: }
|