Source Code Cross Referenced for UMLModelRootNode.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » project » ui » nodes » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » uml » org.netbeans.modules.uml.project.ui.nodes 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * UMLModelRootNode.java
044:         *
045:         * Created on March 1, 2005, 6:26 PM
046:         */
047:
048:        package org.netbeans.modules.uml.project.ui.nodes;
049:
050:        import java.util.ArrayList;
051:        import java.util.List;
052:        import java.awt.Image;
053:        import java.beans.PropertyChangeEvent;
054:        import java.beans.PropertyChangeListener;
055:        import java.io.File;
056:        import javax.swing.Action;
057:        import javax.swing.SwingUtilities;
058:        import org.netbeans.spi.project.support.ant.PropertyEvaluator;
059:
060:        import org.openide.nodes.Children;
061:        import org.openide.nodes.Node;
062:        import org.openide.util.actions.SystemAction;
063:        import org.openide.util.NbBundle;
064:        import org.openide.util.datatransfer.NewType;
065:
066:        import org.netbeans.modules.uml.project.UMLProjectHelper;
067:        import org.netbeans.modules.uml.project.ui.NetBeansUMLProjectTreeModel;
068:        import org.netbeans.modules.uml.project.UMLProject;
069:        import org.netbeans.modules.uml.project.ui.nodes.actions.NewDiagramType;
070:        import org.netbeans.modules.uml.project.ui.nodes.actions.NewPackageType;
071:        import org.netbeans.modules.uml.project.ui.nodes.actions.NewElementType;
072:        import org.netbeans.modules.uml.project.UMLProjectModule;
073:        import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeControl;
074:        import org.netbeans.modules.uml.ui.support.projecttreesupport.ProjectTreeComparable;
075:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
076:        import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
077:        import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
078:        import org.netbeans.modules.uml.ui.controls.filter.IFilterDialog;
079:        import org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink;
080:        import org.netbeans.modules.uml.ui.support.DispatchHelper;
081:        import org.netbeans.modules.uml.ui.swing.projecttree.JFilterDialog;
082:        import org.netbeans.modules.uml.project.ui.nodes.actions.FilterAction;
083:        import javax.swing.tree.DefaultTreeModel;
084:        import org.netbeans.modules.uml.resources.images.ImageUtil;
085:        import org.openide.actions.PropertiesAction;
086:        import org.openide.actions.SaveAction;
087:        import org.openide.cookies.SaveCookie;
088:        import org.openide.filesystems.FileUtil;
089:        import org.openide.loaders.DataObject;
090:        import org.openide.nodes.Node.Cookie;
091:
092:        /**
093:         *
094:         * @author Mike
095:         */
096:        public class UMLModelRootNode extends UMLModelElementNode implements 
097:                ModelRootNodeCookie, IProjectTreeFilterDialogEventsSink {
098:            private Image mIcon = null;
099:            private UMLProjectHelper mHelper = null;
100:
101:            private final String displayName;
102:            private IFilterDialog filterDialog = null;
103:            private DefaultTreeModel treeModelFilter = null;
104:
105:            /* TODO - remove the 3 second sleep and fix this
106:             See HACK in static related to race condition
107:            private static ADProjectTreeEngine mEngine = new ADProjectTreeEngine();
108:            private static NetBeansUMLProjectTreeModel mModel = new NetBeansUMLProjectTreeModel();
109:             */
110:            //	private static ADProjectTreeEngine mEngine = null;
111:            //	private static NetBeansUMLProjectTreeModel mModel = null;
112:            //
113:            //	static
114:            //	{
115:            //		// TODO - remove HACK sleeps.
116:            //		// These were suggested by Alexi Mokeev re:
117:            //		// "Project saving and freeze issue"
118:            //		mEngine = new ADProjectTreeEngine();
119:            //		try
120:            //		{Thread.sleep(3000);}
121:            //		catch(Exception e)
122:            //		{}
123:            //		mModel = new NetBeansUMLProjectTreeModel();
124:            //		try
125:            //		{Thread.sleep(3000);}
126:            //		catch(Exception e)
127:            //		{}
128:            //
129:            //		mEngine.initialize(mModel);
130:            //	}
131:            public UMLModelRootNode(UMLProject project,
132:                    UMLProjectHelper helper, PropertyEvaluator eval) {
133:                super ();
134:                //            super(obj, new UMLChildren(), new ProjectTreeItemImpl());
135:                UMLProjectModule.addModelNode(this , project);
136:                mHelper = helper;
137:
138:                setElement(mHelper.getProject());
139:                getData().setSortPriority(1);
140:                getData().setDescription(
141:                        IProjectTreeControl.PROJECT_DESCRIPTION);
142:
143:                //mEngine.initialize(mModel);
144:                Children ch = getChildren();
145:                if (ch != null && ch instanceof  UMLChildren) {
146:                    final UMLChildren children = (UMLChildren) ch;
147:                    ((UMLChildren) ch).setItem(this );
148:                }
149:
150:                this .displayName = NbBundle.getMessage(UMLModelRootNode.class,
151:                        "CTL_UMLModelRootNode"); //NOI18N
152:
153:                setIconBaseWithExtension(ImageUtil.IMAGE_FOLDER
154:                        + "model-root-node.png"); // NOI18N
155:
156:                try {
157:                    File f = new File(new File(mHelper.getProject()
158:                            .getFileName()).getCanonicalPath());
159:                    final DataObject dobj = DataObject.find(FileUtil
160:                            .toFileObject(f));
161:
162:                    if (dobj != null) {
163:                        if (mHelper.getProject().getDirty()) {
164:                            Cookie cookie = dobj.getCookie(SaveCookie.class);
165:                            if (cookie != null)
166:                                getCookieSet().add(cookie);
167:                        }
168:
169:                        dobj
170:                                .addPropertyChangeListener(new PropertyChangeListener() {
171:                                    public void propertyChange(
172:                                            PropertyChangeEvent evt) {
173:                                        if (evt.getPropertyName().equals(
174:                                                DataObject.PROP_MODIFIED)) {
175:                                            if (((Boolean) evt.getNewValue())
176:                                                    .booleanValue()) {
177:                                                if (getCookie(SaveCookie.class) == null)
178:                                                    getCookieSet()
179:                                                            .add(
180:                                                                    dobj
181:                                                                            .getCookie(SaveCookie.class));
182:                                            } else {
183:                                                Cookie cookie = getCookie(SaveCookie.class);
184:                                                if (cookie != null)
185:                                                    getCookieSet().remove(
186:                                                            cookie);
187:                                            }
188:                                        }
189:                                    }
190:                                });
191:                    }
192:                } catch (Exception e) {
193:                    // project file object not found, 
194:                }
195:            }
196:
197:            public String getDisplayName() {
198:                return this .displayName;
199:            }
200:
201:            public String getName() {
202:                return this .getDisplayName();
203:            }
204:
205:            /**
206:             * Get the new types that can be created in this node. For example, a node
207:             * representing a class will permit attributes, operations, classes,
208:             * interfaces, and enumerations to be added.
209:             *
210:             * @return An array of new type operations that are allowed.
211:             */
212:            public NewType[] getNewTypes() {
213:                String elType = getElementType();
214:                NewType[] retVal = null;
215:
216:                if (getModelElement() instanceof  INamespace) {
217:                    // Package types: Java Package (or an organizing folder)
218:                    // Project types: UML Modeling Project
219:                    if (elType.equals(ELEMENT_TYPE_PROJECT)) {
220:                        return new NewType[] { new NewDiagramType(this ),
221:                                new NewPackageType(this ),
222:                                new NewElementType(this ) };
223:                    }
224:                } // if getModelElement() instanceof INamespace
225:
226:                // The NewAction code does not check for null.  Therefore, we have
227:                // to create a new object just to keep them from throwing.
228:                if (retVal == null) {
229:                    retVal = new NewType[0];
230:                }
231:
232:                return retVal;
233:            }
234:
235:            public Action[] getActions(boolean context) {
236:                ArrayList<Action> actions = new ArrayList<Action>();
237:
238:                // actions.add(CommonProjectActions.openSubprojectsAction());
239:                // actions.add(CommonProjectActions.closeProjectAction());
240:
241:                //actions.add(SystemAction.get(NewAction.class));
242:                super .getNewMenuAction(actions);
243:                actions.add(SystemAction.get(FilterAction.class));
244:                addContextMenu(actions);
245:
246:                actions.add(null);
247:                actions.add(SystemAction.get(SaveAction.class));
248:                actions.add(null);
249:                actions.add(SystemAction.get(PropertiesAction.class));
250:
251:                Action[] retVal = new Action[actions.size()];
252:                actions.toArray(retVal);
253:                return retVal;
254:            }
255:
256:            /**
257:             * Retrieves the associated model element.  The model element will be the
258:             * IProject that represent the project.
259:             *
260:             * @return The IProject instance.
261:             * @see IProject
262:             */
263:            public IElement getModelElement() {
264:                if (mHelper == null)
265:                    return null;
266:
267:                return mHelper.getProject();
268:            }
269:
270:            /**
271:             * Adds the model element to the lookup.
272:             *
273:             * @param element The Model element that represents the project.
274:             */
275:            protected void addElementCookie(IElement element) {
276:            }
277:
278:            public Node.Cookie getCookie(Class type) {
279:                Node.Cookie cookie = super .getCookie(type);
280:                if (cookie == null) {
281:                    IElement element = getModelElement();
282:                    if (element instanceof  Node.Cookie) {
283:                        if (type.isAssignableFrom(element.getClass()) == true) {
284:                            cookie = (Node.Cookie) element;
285:                        }
286:                    }
287:                }
288:                // MCF experiment
289:                if (cookie == null) {
290:                    if (type.isAssignableFrom(ModelRootNodeCookie.class) == true)
291:                        return this ;
292:
293:                }
294:                return cookie;
295:            }
296:
297:            //////////////////////////////////////
298:
299:            //    public String getDisplayName()
300:            //    {
301:            //       return mHelper.getDisplayName();
302:            //    }
303:
304:            public Image getIcon(int type) {
305:                Image original = super .getIcon(type);
306:                //return broken ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
307:                return original;
308:            }
309:
310:            public Image getOpenedIcon(int type) {
311:                Image original = super .getOpenedIcon(type);
312:                //return broken ? Utilities.mergeImages(original, brokenProjectBadge, 8, 0) : original;
313:                return original;
314:            }
315:
316:            public static NetBeansUMLProjectTreeModel getProjectTreeModel() {
317:                return UMLProjectModule.getProjectTreeModel();
318:            }
319:
320:            public void recalculateChildren() {
321:                UMLChildren children = (UMLChildren) getChildren();
322:                children.recalculateChildren();
323:            }
324:
325:            ///////////////////////////////////////////////////////////////////////////
326:            // Helper Methods
327:
328:            /**
329:             * Initializes the node with the default cookies.  <b>Note:</b>  Do not
330:             * call this method if a looup is added.  When a lookup is added then the
331:             * lookup is used to find the cookies.
332:             */
333:            protected void initCookies() {
334:
335:            }
336:
337:            // Implementations for interface IProjectTreeFilterDialogEventsSink
338:            //////////////////////////////////////////////////////////////////
339:
340:            /* (non-Javadoc)
341:             * @see org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink#onProjectTreeFilterDialogInit(org.netbeans.modules.uml.ui.controls.filter.IFilterDialog, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
342:             */
343:            public void onProjectTreeFilterDialogInit(IFilterDialog dialog,
344:                    IResultCell cell) {
345:            }
346:
347:            /* (non-Javadoc)
348:             * @see org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink#onProjectTreeFilterDialogOKActivated(org.netbeans.modules.uml.ui.controls.filter.IFilterDialog, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
349:             */
350:            public void onProjectTreeFilterDialogOKActivated(
351:                    IFilterDialog dialog, IResultCell cell) {
352:                if (dialog != null && dialog instanceof  JFilterDialog) {
353:                    JFilterDialog filterDialog = (JFilterDialog) dialog;
354:
355:                    // setFilterDialog(dialog);
356:                    setTreeModelFilter(filterDialog.getTreeModel());
357:
358:                    // Model root node children are refresh with filter applied
359:                    // TODO - unfortunately, this "flattens" any expanded nodes
360:                    // instead of leaving them in their current expanded state
361:                    SwingUtilities.invokeLater(new Runnable() {
362:                        public void run() {
363:                            recalculateChildren();
364:                        }
365:                    });
366:                }
367:            }
368:
369:            public void filterListenerRegistered(boolean register) {
370:                DispatchHelper dispatchHelper = new DispatchHelper();
371:
372:                if (register)
373:                    // cvc - CR#6271053
374:                    // listen for Filter dialog OK action
375:                    dispatchHelper.registerProjectTreeFilterDialogEvents(this );
376:
377:                else
378:                    // cvc - CR 6271328
379:                    // only listen while Filter dialog is "alive" otherwise, all
380:                    // projects will listen to each others' filter dialogs
381:                    dispatchHelper.revokeProjectTreeFilterDialogSink(this );
382:            }
383:
384:            public DefaultTreeModel getTreeModelFilter() {
385:                return treeModelFilter;
386:            }
387:
388:            public void setTreeModelFilter(DefaultTreeModel val) {
389:                this .treeModelFilter = val;
390:            }
391:
392:            // Gets the Context menu for the Model node from layer.xml
393:            protected void addContextMenu(List actions) {
394:                Action[] nodeActions = null;
395:                //        UMLElementNode node = new UMLElementNode();
396:                nodeActions = getActionsFromRegistry("contextmenu/uml/designpatternformodel");
397:                //                node.getActionsFromRegistry("contextmenu/uml/designpatternformodel");
398:
399:                for (Action curAction : nodeActions) {
400:                    if (curAction == null)
401:                        actions.add(null);
402:
403:                    else if (curAction.isEnabled())
404:                        actions.add(curAction);
405:                }
406:                actions.add(null);
407:
408:                nodeActions = getActionsFromRegistry("Actions/UML/Search");
409:                for (Action curAction : nodeActions) {
410:                    if (curAction == null)
411:                        actions.add(null);
412:
413:                    else if (curAction.isEnabled())
414:                        actions.add(curAction);
415:                }
416:
417:                actions.add(null);
418:
419:                nodeActions = getActionsFromRegistry("contextmenu/uml/report");
420:                for (Action curAction : nodeActions) {
421:                    if (curAction == null)
422:                        actions.add(null);
423:
424:                    else if (curAction.isEnabled())
425:                        actions.add(curAction);
426:                }
427:            }
428:
429:            public boolean canCopy() {
430:                return false;
431:            }
432:
433:            public boolean canCut() {
434:                return false;
435:            }
436:
437:            public boolean canRename() {
438:                return false;
439:            }
440:
441:            public boolean canDestroy() {
442:                return false;
443:            }
444:
445:            /* (non-Javadoc)
446:             * @see java.lang.Object#equals(java.lang.Object)
447:             */
448:            public boolean equals(Object obj) {
449:                // NB60TBD special case for diagrams root node to make it work with NB60
450:                if (obj instanceof  UMLDiagramsRootNode) {
451:                    return false;
452:                }
453:                return super.equals(obj);
454:            }
455:
456:        }
w___ww_.j___a_va2___s.___co_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.