Source Code Cross Referenced for ADDrawingAreaControl.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » swing » drawingarea » 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.ui.swing.drawingarea 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


00001:        /*
00002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
00003:         *
00004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
00005:         *
00006:         * The contents of this file are subject to the terms of either the GNU
00007:         * General Public License Version 2 only ("GPL") or the Common
00008:         * Development and Distribution License("CDDL") (collectively, the
00009:         * "License"). You may not use this file except in compliance with the
00010:         * License. You can obtain a copy of the License at
00011:         * http://www.netbeans.org/cddl-gplv2.html
00012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
00013:         * specific language governing permissions and limitations under the
00014:         * License.  When distributing the software, include this License Header
00015:         * Notice in each file and include the License file at
00016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
00017:         * particular file as subject to the "Classpath" exception as provided
00018:         * by Sun in the GPL Version 2 section of the License file that
00019:         * accompanied this code. If applicable, add the following below the
00020:         * License Header, with the fields enclosed by brackets [] replaced by
00021:         * your own identifying information:
00022:         * "Portions Copyrighted [year] [name of copyright owner]"
00023:         *
00024:         * Contributor(s):
00025:         *
00026:         * The Original Software is NetBeans. The Initial Developer of the Original
00027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
00028:         * Microsystems, Inc. All Rights Reserved.
00029:         *
00030:         * If you wish your version of this file to be governed by only the CDDL
00031:         * or only the GPL Version 2, indicate your decision by adding
00032:         * "[Contributor] elects to include this software in this distribution
00033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
00034:         * single choice of license, a recipient has the option to distribute
00035:         * your version of this file under either the CDDL, the GPL Version 2 or
00036:         * to extend the choice of license to its licensees as provided above.
00037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
00038:         * Version 2 license, then the option applies only if the new code is
00039:         * made subject to such option by the copyright holder.
00040:         */
00041:
00042:        package org.netbeans.modules.uml.ui.swing.drawingarea;
00043:
00044:        import java.awt.BorderLayout;
00045:        import java.awt.Frame;
00046:        import java.awt.Insets;
00047:        import java.awt.Point;
00048:        import java.awt.Rectangle;
00049:        import java.awt.datatransfer.UnsupportedFlavorException;
00050:        import java.awt.dnd.DnDConstants;
00051:        import java.awt.dnd.DropTargetDropEvent;
00052:        import java.awt.event.ActionEvent;
00053:        import java.awt.event.ActionListener;
00054:        import java.awt.event.ComponentEvent;
00055:        import java.awt.event.ComponentListener;
00056:        import java.awt.event.FocusAdapter;
00057:        import java.awt.event.FocusEvent;
00058:        import java.awt.event.InputEvent;
00059:        import java.awt.event.KeyEvent;
00060:        import java.awt.event.KeyListener;
00061:        import java.awt.event.MouseAdapter;
00062:        import java.awt.event.MouseEvent;
00063:        import java.awt.event.MouseWheelEvent;
00064:        import java.awt.event.MouseWheelListener;
00065:        import java.awt.event.WindowAdapter;
00066:        import java.io.BufferedReader;
00067:        import java.io.File;
00068:        import java.io.FileInputStream;
00069:        import java.io.FileNotFoundException;
00070:        import java.io.IOException;
00071:        import java.io.InputStreamReader;
00072:        import java.io.Reader;
00073:        import java.io.UnsupportedEncodingException;
00074:        import java.lang.ref.WeakReference;
00075:        import java.util.ArrayList;
00076:        import java.util.Collection;
00077:        import java.util.Collections;
00078:        import java.util.HashMap;
00079:        import java.util.Hashtable;
00080:        import java.util.Iterator;
00081:        import java.util.LinkedList;
00082:        import java.util.List;
00083:        import java.util.ResourceBundle;
00084:        import java.util.Set;
00085:        import java.util.Vector;
00086:        import javax.swing.AbstractAction;
00087:        import javax.swing.Action;
00088:        import javax.swing.JComponent;
00089:        import javax.swing.JFileChooser;
00090:        import javax.swing.JMenu;
00091:        import javax.swing.JOptionPane;
00092:        import javax.swing.JPanel;
00093:        import javax.swing.JPopupMenu;
00094:        import javax.swing.JSeparator;
00095:        import javax.swing.JTextField;
00096:        import javax.swing.JToolBar;
00097:        import javax.swing.KeyStroke;
00098:        import javax.swing.SwingUtilities;
00099:        import javax.swing.plaf.basic.BasicFileChooserUI;
00100:        import com.tomsawyer.drawing.TSDGraphManager;
00101:        import com.tomsawyer.drawing.geometry.TSConstPoint;
00102:        import com.tomsawyer.drawing.geometry.TSConstRect;
00103:        import com.tomsawyer.drawing.geometry.TSRect;
00104:        import com.tomsawyer.editor.TSEEdge;
00105:        import com.tomsawyer.editor.TSEEdgeLabel;
00106:        import com.tomsawyer.editor.TSEGraph;
00107:        import com.tomsawyer.editor.TSEGraphImageEncoder;
00108:        import com.tomsawyer.editor.TSEGraphManager;
00109:        import com.tomsawyer.editor.TSEGraphWindow;
00110:        import com.tomsawyer.editor.TSEHitTesting;
00111:        import com.tomsawyer.editor.TSELineGrid;
00112:        import com.tomsawyer.editor.TSELocalization;
00113:        import com.tomsawyer.editor.TSENode;
00114:        import com.tomsawyer.editor.TSENodeLabel;
00115:        import com.tomsawyer.editor.TSEObject;
00116:        import com.tomsawyer.editor.TSEObjectUI;
00117:        import com.tomsawyer.editor.TSEPNode;
00118:        import com.tomsawyer.editor.TSEPointGrid;
00119:        import com.tomsawyer.editor.TSEWindowTool;
00120:        import com.tomsawyer.editor.TSTransform;
00121:        import com.tomsawyer.editor.complexity.TSEFoldingManager;
00122:        import com.tomsawyer.editor.complexity.TSEHidingManager;
00123:        import com.tomsawyer.editor.complexity.TSENestingManager;
00124:        import com.tomsawyer.editor.dialog.TSDoublePercentDocument;
00125:        import com.tomsawyer.editor.dialog.TSFileChooser;
00126:        import com.tomsawyer.editor.dialog.TSFileFilter;
00127:        import com.tomsawyer.editor.event.TSEEventManager;
00128:        import com.tomsawyer.editor.event.TSESelectionChangeEvent;
00129:        import com.tomsawyer.editor.event.TSESelectionChangeListener;
00130:        import com.tomsawyer.editor.event.TSEViewportChangeEvent;
00131:        import com.tomsawyer.editor.event.TSEViewportChangeListener;
00132:        import com.tomsawyer.editor.export.TSESaveAsImageDialog;
00133:        import com.tomsawyer.editor.service.TSEAllOptionsServiceInputData;
00134:        import com.tomsawyer.graph.TSEdge;
00135:        import com.tomsawyer.graph.TSGraph;
00136:        import com.tomsawyer.graph.TSGraphManager;
00137:        import com.tomsawyer.graph.TSGraphObject;
00138:        import com.tomsawyer.graph.TSNode;
00139:        import com.tomsawyer.graph.event.TSEventManager;
00140:        import com.tomsawyer.graph.event.TSGraphChangeEvent;
00141:        import com.tomsawyer.graph.event.TSGraphChangeEventData;
00142:        import com.tomsawyer.graph.event.TSGraphChangeListener;
00143:        import com.tomsawyer.service.TSServiceOutputData;
00144:        import com.tomsawyer.service.layout.TSLayoutConstants;
00145:        import com.tomsawyer.service.layout.jlayout.TSHierarchicalLayoutInputTailor;
00146:        import com.tomsawyer.service.layout.jlayout.TSJLayoutConstants;
00147:        import com.tomsawyer.service.layout.jlayout.TSLayoutInputTailor;
00148:        import com.tomsawyer.service.layout.jlayout.TSOrthogonalLayoutInputTailor;
00149:        import com.tomsawyer.service.layout.jlayout.client.TSLayoutProxy;
00150:        import com.tomsawyer.util.TSLicenseManager;
00151:        import com.tomsawyer.util.TSObject;
00152:        import com.tomsawyer.util.TSProperty;
00153:        import com.tomsawyer.xml.editor.TSEEnumerationTable;
00154:        import com.tomsawyer.xml.editor.TSEVisualizationXMLReader;
00155:        import com.tomsawyer.xml.editor.TSEVisualizationXMLWriter;
00156:        import java.io.BufferedWriter;
00157:        import java.io.BufferedWriter;
00158:        import java.io.OutputStreamWriter;
00159:        import java.io.OutputStreamWriter;
00160:        import java.io.Writer;
00161:        import java.util.HashSet;
00162:        import java.util.logging.Level;
00163:        import java.util.logging.Logger;
00164:        import javax.imageio.stream.FileImageOutputStream;
00165:        import javax.swing.event.DocumentEvent;
00166:        import javax.swing.event.DocumentListener;
00167:        import java.util.prefs.Preferences;
00168:        import org.dom4j.Document;
00169:        import org.dom4j.Node;
00170:        import org.netbeans.modules.uml.UMLCoreModule;
00171:        import org.netbeans.modules.uml.common.ETException;
00172:        import org.netbeans.modules.uml.common.ETSystem;
00173:        import org.netbeans.modules.uml.common.generics.ETPairT;
00174:        import org.netbeans.modules.uml.common.generics.ETTripleT;
00175:        import org.netbeans.modules.uml.common.generics.IteratorT;
00176:        import org.netbeans.modules.uml.core.IApplication;
00177:        import org.netbeans.modules.uml.core.coreapplication.IPreferenceManager2;
00178:        import org.netbeans.modules.uml.core.eventframework.EventBlocker;
00179:        import org.netbeans.modules.uml.core.eventframework.IEventPayload;
00180:        import org.netbeans.modules.uml.core.metamodel.core.foundation.FactoryRetriever;
00181:        import org.netbeans.modules.uml.core.metamodel.core.foundation.ICreationFactory;
00182:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
00183:        import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
00184:        import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
00185:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
00186:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IVersionableElement;
00187:        import org.netbeans.modules.uml.core.metamodel.diagrams.DiagramEnums;
00188:        import org.netbeans.modules.uml.core.metamodel.diagrams.DiagramValidation;
00189:        import org.netbeans.modules.uml.core.metamodel.diagrams.GraphObjectValidation;
00190:        import org.netbeans.modules.uml.core.metamodel.diagrams.IBroadcastAction;
00191:        import org.netbeans.modules.uml.core.metamodel.diagrams.ICoreRelationshipDiscovery;
00192:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDelayedAction;
00193:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
00194:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramValidateKind;
00195:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramValidateResponse;
00196:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramValidateResult;
00197:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramValidation;
00198:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramValidationResult;
00199:        import org.netbeans.modules.uml.core.metamodel.diagrams.IDrawingToolKind;
00200:        import org.netbeans.modules.uml.core.metamodel.diagrams.IGraphEventKind;
00201:        import org.netbeans.modules.uml.core.metamodel.diagrams.IGraphObjectValidation;
00202:        import org.netbeans.modules.uml.core.metamodel.diagrams.IGraphicExportDetails;
00203:        import org.netbeans.modules.uml.core.metamodel.diagrams.ILayoutKind;
00204:        import org.netbeans.modules.uml.core.metamodel.diagrams.IPresentationElementToDeleteAction;
00205:        import org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram;
00206:        import org.netbeans.modules.uml.core.metamodel.diagrams.ISynchStateKind;
00207:        import org.netbeans.modules.uml.core.metamodel.dynamics.ICombinedFragment;
00208:        import org.netbeans.modules.uml.core.metamodel.dynamics.IMessage;
00209:        import org.netbeans.modules.uml.core.metamodel.dynamics.IMessageConnector;
00210:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
00211:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IFeature;
00212:        import org.netbeans.modules.uml.core.metamodel.structure.IProject;
00213:        import org.netbeans.modules.uml.core.scm.ISCMDiagramItem;
00214:        import org.netbeans.modules.uml.core.scm.ISCMItem;
00215:        import org.netbeans.modules.uml.core.scm.ISCMItemGroup;
00216:        import org.netbeans.modules.uml.core.scm.SCMFeatureKind;
00217:        import org.netbeans.modules.uml.core.support.Debug;
00218:        import org.netbeans.modules.uml.core.support.UMLLogger;
00219:        import org.netbeans.modules.uml.core.support.umlmessagingcore.MsgCoreConstants;
00220:        import org.netbeans.modules.uml.core.support.umlmessagingcore.UMLMessagingHelper;
00221:        import org.netbeans.modules.uml.core.support.umlsupport.ETDeviceRect;
00222:        import org.netbeans.modules.uml.core.support.umlsupport.ETPoint;
00223:        import org.netbeans.modules.uml.core.support.umlsupport.ETRect;
00224:        import org.netbeans.modules.uml.core.support.umlsupport.FileExtensions;
00225:        import org.netbeans.modules.uml.core.support.umlsupport.FileSysManip;
00226:        import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
00227:        import org.netbeans.modules.uml.core.support.umlsupport.IETRect;
00228:        import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
00229:        import org.netbeans.modules.uml.core.support.umlsupport.StringUtilities;
00230:        import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
00231:        import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
00232:        import org.netbeans.modules.uml.core.support.umlutils.ETList;
00233:        import org.netbeans.modules.uml.core.support.umlutils.ElementLocator;
00234:        import org.netbeans.modules.uml.core.support.umlutils.IElementLocator;
00235:        import org.netbeans.modules.uml.core.support.umlutils.IPropertyElement;
00236:        import org.netbeans.modules.uml.core.support.umlutils.InvalidArguments;
00237:        import org.netbeans.modules.uml.core.support.umlutils.PropertyElements;
00238:        import org.netbeans.modules.uml.core.workspacemanagement.ITwoPhaseCommit;
00239:        import org.netbeans.modules.uml.core.workspacemanagement.IWorkspace;
00240:        import org.netbeans.modules.uml.ui.controls.drawingarea.CachedDiagrams;
00241:        import org.netbeans.modules.uml.ui.controls.drawingarea.DiagramAreaEnumerations;
00242:        import org.netbeans.modules.uml.ui.controls.drawingarea.DiagramValidator;
00243:        import org.netbeans.modules.uml.ui.controls.drawingarea.DrawEnginesToResetAction;
00244:        import org.netbeans.modules.uml.ui.controls.drawingarea.DrawingAreaEventHandler;
00245:        import org.netbeans.modules.uml.ui.controls.drawingarea.GetHelper;
00246:        import org.netbeans.modules.uml.ui.controls.drawingarea.IDiagramValidator;
00247:        import org.netbeans.modules.uml.ui.controls.drawingarea.IDrawEnginesToResetAction;
00248:        import org.netbeans.modules.uml.ui.controls.drawingarea.IDrawingAreaEventDispatcher;
00249:        import org.netbeans.modules.uml.ui.controls.drawingarea.IElementBroadcastAction;
00250:        import org.netbeans.modules.uml.ui.controls.drawingarea.IExecutableAction;
00251:        import org.netbeans.modules.uml.ui.controls.drawingarea.ISimpleBroadcastAction;
00252:        import org.netbeans.modules.uml.ui.controls.drawingarea.ISimpleElementsAction;
00253:        import org.netbeans.modules.uml.ui.controls.drawingarea.ISimpleElementsAction.SEAK;
00254:        import org.netbeans.modules.uml.ui.controls.drawingarea.ITopographyChangeAction;
00255:        import org.netbeans.modules.uml.ui.controls.drawingarea.ITransformAction;
00256:        import org.netbeans.modules.uml.ui.controls.drawingarea.IUIDiagram;
00257:        import org.netbeans.modules.uml.ui.controls.drawingarea.SimpleBroadcastAction;
00258:        import org.netbeans.modules.uml.ui.controls.drawingarea.SimpleElementsAction;
00259:        import org.netbeans.modules.uml.ui.controls.drawingarea.TopographyChangeAction;
00260:        import org.netbeans.modules.uml.ui.controls.drawingarea.TransformAction;
00261:        import org.netbeans.modules.uml.ui.products.ad.application.ApplicationView;
00262:        import org.netbeans.modules.uml.ui.products.ad.application.IMenuManager;
00263:        import org.netbeans.modules.uml.ui.products.ad.compartments.ETCompartment;
00264:        import org.netbeans.modules.uml.ui.products.ad.diagramengines.ADCoreEngine;
00265:        import org.netbeans.modules.uml.ui.products.ad.diagramengines.DrawingAreaContextMenuSorter;
00266:        import org.netbeans.modules.uml.ui.products.ad.diagramengines.IADSequenceDiagEngine;
00267:        import org.netbeans.modules.uml.ui.products.ad.drawengines.ETContainerDrawEngine;
00268:        import org.netbeans.modules.uml.ui.support.applicationmanager.NodePresentation;
00269:        import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETEdge;
00270:        import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETEdgeLabel;
00271:        import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETGraph;
00272:        import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETGraphManager;
00273:        import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETNode;
00274:        import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETNodeLabel;
00275:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETEGraphImageEncoder;
00276:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericEdgeLabelUI;
00277:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericEdgeUI;
00278:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericGraphUI;
00279:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericNodeLabelUI;
00280:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericNodeUI;
00281:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETNullGraphUI;
00282:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETUIFactory;
00283:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.IETGraphObjectUI;
00284:        import org.netbeans.modules.uml.ui.products.ad.viewfactory.RelationEdge;
00285:        import org.netbeans.modules.uml.ui.support.ADTransferable;
00286:        import org.netbeans.modules.uml.ui.support.CreationFactoryHelper;
00287:        import org.netbeans.modules.uml.ui.support.DispatchHelper;
00288:        import org.netbeans.modules.uml.ui.support.DragAndDropSupport;
00289:        import org.netbeans.modules.uml.ui.support.ElementReloader;
00290:        import org.netbeans.modules.uml.ui.support.PresentationReferenceHelper;
00291:        import org.netbeans.modules.uml.ui.support.ProductHelper;
00292:        import org.netbeans.modules.uml.ui.support.QuestionResponse;
00293:        import org.netbeans.modules.uml.ui.support.SimpleQuestionDialogResultKind;
00294:        import org.netbeans.modules.uml.ui.support.SwingPreferenceQuestionDialog;
00295:        import org.netbeans.modules.uml.ui.support.applicationmanager.DiagramKeyboardAccessProvider;
00296:        import org.netbeans.modules.uml.ui.support.applicationmanager.IEdgePresentation;
00297:        import org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation;
00298:        import org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation;
00299:        import org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation;
00300:        import org.netbeans.modules.uml.ui.support.applicationmanager.IPresentationTypesMgr;
00301:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProduct;
00302:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProductGraphPresentation;
00303:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProxyUserInterface;
00304:        import org.netbeans.modules.uml.ui.support.applicationmanager.NameCollisionListener;
00305:        import org.netbeans.modules.uml.ui.support.applicationmanager.PresentationTypeDetails;
00306:        import org.netbeans.modules.uml.ui.support.applicationmanager.ProductGraphPresentation;
00307:        import org.netbeans.modules.uml.ui.support.applicationmanager.TSGraphObjectKind;
00308:        import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchive;
00309:        import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchiveDefinitions;
00310:        import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchiveElement;
00311:        import org.netbeans.modules.uml.ui.support.archivesupport.ProductArchiveImpl;
00312:        import org.netbeans.modules.uml.ui.support.commondialogs.IPreferenceQuestionDialog;
00313:        import org.netbeans.modules.uml.ui.support.commondialogs.IQuestionDialog;
00314:        import org.netbeans.modules.uml.ui.support.commondialogs.MessageDialogKindEnum;
00315:        import org.netbeans.modules.uml.ui.support.commondialogs.MessageIconKindEnum;
00316:        import org.netbeans.modules.uml.ui.support.commondialogs.MessageResultKindEnum;
00317:        import org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenu;
00318:        import org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenuItem;
00319:        import org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenuSorter;
00320:        import org.netbeans.modules.uml.ui.support.diagramsupport.DiagramTypesManager;
00321:        import org.netbeans.modules.uml.ui.support.diagramsupport.ETLayoutStyleMap;
00322:        import org.netbeans.modules.uml.ui.support.diagramsupport.IDiagramTypesManager;
00323:        import org.netbeans.modules.uml.ui.support.diagramsupport.IProxyDiagramManager;
00324:        import org.netbeans.modules.uml.ui.support.diagramsupport.ProxyDiagramManager;
00325:        import org.netbeans.modules.uml.ui.support.drawingproperties.IColorProperty;
00326:        import org.netbeans.modules.uml.ui.support.drawingproperties.IDrawingProperty;
00327:        import org.netbeans.modules.uml.ui.support.drawingproperties.IDrawingPropertyProvider;
00328:        import org.netbeans.modules.uml.ui.support.drawingproperties.IFontProperty;
00329:        import org.netbeans.modules.uml.ui.support.helpers.ETSmartWaitCursor;
00330:        import org.netbeans.modules.uml.ui.support.helpers.GUIBlocker;
00331:        import org.netbeans.modules.uml.ui.support.helpers.IGUIBlocker;
00332:        import org.netbeans.modules.uml.ui.support.helpers.IGUIBlocker.GBK;
00333:        import org.netbeans.modules.uml.ui.support.helpers.UserInputBlocker;
00334:        import org.netbeans.modules.uml.ui.support.messaging.IZoomDialog;
00335:        import org.netbeans.modules.uml.ui.support.messaging.ZoomDialog;
00336:        import org.netbeans.modules.uml.ui.support.umltsconversions.RectConversions;
00337:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ETPointEx;
00338:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ETRectEx;
00339:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment;
00340:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
00341:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETEdge;
00342:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
00343:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETLabel;
00344:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode;
00345:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.IEventManager;
00346:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ILabelManager;
00347:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets;
00348:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject;
00349:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.IToolTipData;
00350:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ResourceMgr;
00351:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
00352:        import org.netbeans.modules.uml.ui.support.visitors.ETDrawEngineTypesMatchVistor;
00353:        import org.netbeans.modules.uml.ui.support.visitors.ETFindObjectVisitor;
00354:        import org.netbeans.modules.uml.ui.support.visitors.ETGraphObjectTraversal;
00355:        import org.netbeans.modules.uml.ui.support.visitors.IETGraphObjectVisitor;
00356:        import org.netbeans.modules.uml.ui.swing.commondialogs.SwingQuestionDialogImpl;
00357:        import org.netbeans.modules.uml.ui.swing.drawingarea.diagramtools.ADCreateNodeState;
00358:        import org.netbeans.modules.uml.ui.swing.drawingarea.diagramtools.ADDrawingAreaSelectState;
00359:        import org.netbeans.modules.uml.ui.swing.drawingarea.diagramtools.ADMoveSelectedState;
00360:        import org.netbeans.modules.uml.ui.swing.drawingarea.diagramtools.ADReconnectEdgeState;
00361:        import org.netbeans.modules.uml.ui.swing.testbed.addin.menu.Separator;
00362:        import org.netbeans.modules.uml.ui.swing.testbed.addin.menu.TestBedMenuManager;
00363:        import org.netbeans.modules.uml.ui.swing.trackbar.JTrackBar;
00364:        import org.netbeans.modules.uml.util.DummyCorePreference;
00365:        import org.openide.DialogDescriptor;
00366:        import org.openide.DialogDisplayer;
00367:        import org.openide.ErrorManager;
00368:        import org.openide.NotifyDescriptor;
00369:        import org.openide.cookies.InstanceCookie;
00370:        import org.openide.filesystems.FileObject;
00371:        import org.openide.filesystems.FileSystem;
00372:        import org.openide.filesystems.FileUtil;
00373:        import org.openide.filesystems.FileUtil;
00374:        import org.openide.filesystems.Repository;
00375:        import org.openide.loaders.DataObject;
00376:        import org.openide.loaders.DataObjectNotFoundException;
00377:        import org.openide.util.HelpCtx;
00378:        import org.openide.util.NbBundle;
00379:        import org.openide.util.NbPreferences;
00380:        import org.openide.util.Utilities;
00381:
00382:        /*
00383:         * Main Display Control for all UML Diagram Types.
00384:         */
00385:        /*
00386:         * Main Display Control for all UML Diagram Types.
00387:         */
00388:        public class ADDrawingAreaControl extends ApplicationView implements 
00389:                IDrawingPropertyProvider, IDrawingAreaControl, ActionListener,
00390:                ADParameterReader, ITwoPhaseCommit, MouseWheelListener,
00391:                KeyListener {
00392:
00393:            static {
00394:                //JM: Fix for Bug#6299069
00395:                //            TSELocalization.setBundlePath("com.tomsawyer.module.resources.");
00396:                TSELocalization
00397:                        .setBundlePath("org.netbeans.modules.uml.tomsawyer.");
00398:            }
00399:            private static final Logger logger = Logger
00400:                    .getLogger("uml.ui.swing.drawingarea.ADDrawingAreaControl");
00401:            private Hashtable<String, String> m_CachedPreferences = new Hashtable<String, String>();
00402:            private boolean m_isDirty = false;
00403:            private INamespace m_Namespace = null;
00404:            //private String m_PreCommitFileName = "";
00405:            private String m_FileName = "";
00406:            private Vector m_ViewsReadWriteFromETLFile = new Vector();
00407:            private String m_Name = "";
00408:            private String m_Alias = "";
00409:            private String m_Documentation = "";
00410:            private IDiagramEngine m_DiagramEngine = null;
00411:            private double m_nZoomLevelFromArchive = 0.0;
00412:            private double m_OnDrawZoom = 1.0f;
00413:            private Point m_CenterFromArchive;
00414:            private Vector m_AssociatedDiagrams = new Vector();
00415:            private HashMap m_AssociatedElements = new HashMap(); //its a HashMap<String, Vector<String>>
00416:            private IDiagram m_Diagram = null;
00417:            private String m_DiagramKindDisplayName = "";
00418:            private String m_DiagramXmiid = "";
00419:            private boolean m_LoadedFromFile = false;
00420:            private boolean m_DiagramSavedWithAliasOn = false;
00421:            private boolean m_ReadOnly = false;
00422:            private boolean m_AbortDiagramLoad = false;
00423:            private boolean m_ItemsSelected = false;
00424:            private boolean m_TooltipsEnabled = false;
00425:            protected DrawingAreaInitString m_NodeInitializationString = new DrawingAreaInitString();
00426:            protected DrawingAreaInitString m_EdgeInitializationString = new DrawingAreaInitString();
00427:            private IProductArchive m_ProductArchive = null;
00428:            private IElement modelElement;
00429:            private ADDrawingAreaResourceBundle resourceBundle = null;
00430:            private ADDrawingAreaActions actions = null;
00431:            protected ADDrawingAreaPrinter m_printer = null;
00432:            private static final String BUNDLE_NAME = "org.netbeans.modules.uml.ui.swing.drawingarea.Bundle"; //$NON-NLS-1$
00433:            private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
00434:                    .getBundle(BUNDLE_NAME);
00435:            /// Listener to the name collision event
00436:            private NameCollisionListener m_NameCollisionListener = null;
00437:            /// Handler for name collision events
00438:            private DrawingAreaCollisionHandler m_CollisionHandler = null;
00439:            /**
00440:             * This field is the next index number to be assigned to untitled documents.
00441:             */
00442:            private int nextNewDocIndex = 1;
00443:            /**
00444:             * This variable holds the graph window, the main component of this example editor.
00445:             */
00446:            private ADGraphWindow m_GraphWindow;
00447:            /**
00448:             * This variable stores the installed layout server.
00449:             */
00450:            // private TSLayoutServer layoutServer = null;
00451:            private TSLayoutProxy m_layoutProxy = null;
00452:            /**
00453:             * This variable stores a reference to the overview window.
00454:             */
00455:            private ETDiagramOverviewWindow overviewWindow = null;
00456:            /**
00457:             * Layout Properties Dialog
00458:             */
00459:            protected ETLayoutPropertiesDialog layoutPropertiesDialog = null;
00460:            /**
00461:             * Drawing Properties Dialog
00462:             */
00463:            protected ETDrawingPreferencesDialog graphPreferencesDialog = null;
00464:            /**
00465:             * This variable stores the coordinates and size of the overview window.
00466:             */
00467:            private Rectangle overviewBounds = new Rectangle(0, 0,
00468:                    ETDiagramOverviewWindow.WIDTH,
00469:                    ETDiagramOverviewWindow.HEIGHT);
00470:            /**
00471:             * This variable is set to true when the bounds of the overview
00472:             * window have been set.
00473:             */
00474:            private boolean overviewBoundsCreated;
00475:            /**
00476:             * The track bar used by the diagram.  The track bar implemementation is
00477:             * determined by the diagram engine.
00478:             */
00479:            private JTrackBar m_TrackBar = null;
00480:            private Insets windowInsets = new Insets(12, 12, 29, 29);
00481:            private TSEGraph m_graph;
00482:            private WindowHandler windowHandler;
00483:            private MouseHandler mouseHandler;
00484:            private KeyHandler keyHandler;
00485:            private FocusAdapter focusAdapter;
00486:            private JToolBar mainToolBar;
00487:            private JToolBar umlToolBar;
00488:            private JPanel northPanel;
00489:            private JPanel centerPanel;
00490:            private TSELineGrid lineGrid;
00491:            private TSEPointGrid pointGrid;
00492:            private ADComboBox zoomComboBox;
00493:            private String graphFileName;
00494:            private TSFileChooser fileChooser;
00495:            protected boolean autoFitInWindow;
00496:            protected IDrawingAreaEventDispatcher m_drawingAreaDispatcher;
00497:            private DrawingAreaEventHandler m_DrawingAreaEventsSink = null;
00498:            private WeakReference m_EditCompartment = null;
00499:            private IPresentationTypesMgr m_PresentationTypesMgr = null;
00500:            //   private PopupMenuExtender  m_ContextMenu        = null;
00501:            private TestBedMenuManager m_ContextMenuManager = null;
00502:            private JMenu m_ContextPopup = new JMenu();
00503:            //   private StructuredSelectionProvider m_SelectionProvider = new StructuredSelectionProvider();
00504:            private boolean m_showToolbars = true;
00505:            private MyGraphChangeListener trackBarModifyListener = null;
00506:            private ViewportChangeListener trackBarChangeListener = null;
00507:            private boolean populating = false;
00508:            // Sun Issue 6184441:  It appears that TS is setting up the clipboard
00509:            // then sending use a the delete command, which we were then clearing
00510:            // the clipboard.  We use m_bCutting to indicate we are cutting so that
00511:            // we don't clear the clipboard.
00512:            // @see cut()
00513:            // @see clearClipboard()
00514:            private boolean m_bCutting = false;
00515:            private TSEGraphManager m_graphManager;
00516:            private TSLayoutInputTailor m_layoutInputTailor;
00517:            private TSHierarchicalLayoutInputTailor m_hierarchicalInputTailor;
00518:            private TSOrthogonalLayoutInputTailor m_orthogonalLayoutInputTailor;
00519:            private TSServiceOutputData m_serviceOutputData;
00520:            private TSEAllOptionsServiceInputData m_allOptionsServiceInputData;
00521:            private TSEVisualizationXMLWriter xmlWriter;
00522:            private TSEVisualizationXMLReader xmlReader;
00523:            private Hashtable serviceInputDataTable = new Hashtable();
00524:            private ETNode m_lastSelectedNode = null;
00525:            private IETLabel m_lastSelectedLabel = null;
00526:            private IETGraphObject m_graphObj = null;
00527:            private List m_selectedNodesGroup = new ArrayList();
00528:            private List tempList = new ArrayList(); //temp list for use in fireSelectEvent
00529:            private String mSelectedPaletteBttn;
00530:            public static String DIRTYSTATE = "dirty"; // NOI18N;
00531:            private DiagramKeyboardAccessProvider kbAccessProvider = null;
00532:
00533:            public ADDrawingAreaControl() {
00534:
00535:                super ("org.netbeans.modules.uml.view.drawingarea");
00536:                m_drawingAreaDispatcher = null;
00537:                m_DiagramKindDisplayName = "Diagram";
00538:
00539:                try {
00540:                    init();
00541:                    registerContextMenu(true);
00542:                } catch (Exception e) {
00543:                    e.printStackTrace();
00544:                }
00545:                this .setEnabled(true);
00546:            }
00547:
00548:            public void actionPerformed(ActionEvent event) {
00549:                String action = event.getActionCommand();
00550:            }
00551:
00552:            private void init() throws Exception {
00553:                m_PresentationTypesMgr = CreationFactoryHelper
00554:                        .getPresentationTypesMgr();
00555:
00556:                UMLCoreModule.instantiateDrawingLibrary();
00557:                //invoke TS licensing system
00558:                this .initializeTSLicense();
00559:
00560:                // create the user interface
00561:                this .createGUI();
00562:
00563:                this .getGraphWindow().setAllowRedraw(false);
00564:
00565:                // install the layout server
00566:                this .installLayoutServer();
00567:
00568:                // set default values
00569:                this .setDefaults();
00570:
00571:                //initialize event sinks
00572:                initEventSink();
00573:
00574:                addComponetListeners();
00575:
00576:                // Create the name collision listener
00577:                m_NameCollisionListener = new NameCollisionListener();
00578:                m_CollisionHandler = new DrawingAreaCollisionHandler();
00579:
00580:                if (m_NameCollisionListener != null
00581:                        && m_CollisionHandler != null) {
00582:                    m_NameCollisionListener.setHandler(m_CollisionHandler);
00583:                    m_CollisionHandler.setDrawingArea(this );
00584:                }
00585:                this .getGraphWindow().setAllowRedraw(true);
00586:            }
00587:
00588:            private void initEventSink() {
00589:                if (m_DrawingAreaEventsSink == null) {
00590:                    m_DrawingAreaEventsSink = new DrawingAreaEventHandler();
00591:                }
00592:                if (m_DrawingAreaEventsSink != null) {
00593:                    DispatchHelper helper = new DispatchHelper();
00594:                    helper.registerForWSElementEvents(m_DrawingAreaEventsSink);
00595:                    helper
00596:                            .registerForElementModifiedEvents(m_DrawingAreaEventsSink);
00597:                    helper.registerForLifeTimeEvents(m_DrawingAreaEventsSink);
00598:                    helper
00599:                            .registerForClassifierFeatureEvents(m_DrawingAreaEventsSink);
00600:                    helper.registerForTransformEvents(m_DrawingAreaEventsSink);
00601:                    helper
00602:                            .registerForTypedElementEvents(m_DrawingAreaEventsSink);
00603:                    helper.registerForRelationEvents(m_DrawingAreaEventsSink);
00604:                    helper
00605:                            .registerForNamedElementEvents(m_DrawingAreaEventsSink);
00606:                    helper
00607:                            .registerForExternalElementEventsSink(m_DrawingAreaEventsSink);
00608:                    helper
00609:                            .registerForAffectedElementEvents(m_DrawingAreaEventsSink);
00610:                    helper
00611:                            .registerForAssociationEndEvents(m_DrawingAreaEventsSink);
00612:                    helper
00613:                            .registerForStereotypeEventsSink(m_DrawingAreaEventsSink);
00614:                    helper.registerForSCMEvents(m_DrawingAreaEventsSink);
00615:                    helper
00616:                            .registerElementDisposalEvents(m_DrawingAreaEventsSink);
00617:                    helper
00618:                            .registerForNamespaceModifiedEvents(m_DrawingAreaEventsSink);
00619:                    helper.registerForAttributeEvents(m_DrawingAreaEventsSink);
00620:                    helper.registerForOperationEvents(m_DrawingAreaEventsSink);
00621:                    helper.registerForParameterEvents(m_DrawingAreaEventsSink);
00622:                    helper
00623:                            .registerForBehavioralFeatureEvents(m_DrawingAreaEventsSink);
00624:                    helper
00625:                            .registerForRedefinableElementModifiedEvents(m_DrawingAreaEventsSink);
00626:                    helper.registerForDynamicsEvents(m_DrawingAreaEventsSink);
00627:                    helper.registerForFeatureEvents(m_DrawingAreaEventsSink);
00628:                    helper.registerForInitEvents(m_DrawingAreaEventsSink);
00629:                    helper.registerForProjectEvents(m_DrawingAreaEventsSink);
00630:                    helper
00631:                            .registerForActivityEdgeEvents(m_DrawingAreaEventsSink);
00632:                    m_DrawingAreaEventsSink.setDrawingAreaControl(this );
00633:                }
00634:            }
00635:
00636:            private void revokeEventSinks() {
00637:                if (m_DrawingAreaEventsSink != null) {
00638:                    try {
00639:                        DispatchHelper helper = new DispatchHelper();
00640:                        helper.revokeWSElementSink(m_DrawingAreaEventsSink);
00641:                        helper
00642:                                .revokeElementModifiedSink(m_DrawingAreaEventsSink);
00643:                        helper.revokeLifeTimeSink(m_DrawingAreaEventsSink);
00644:                        helper
00645:                                .revokeClassifierFeatureSink(m_DrawingAreaEventsSink);
00646:                        helper.revokeTransformSink(m_DrawingAreaEventsSink);
00647:                        helper.revokeTypedElementSink(m_DrawingAreaEventsSink);
00648:                        helper.revokeRelationSink(m_DrawingAreaEventsSink);
00649:                        helper.revokeNamedElementSink(m_DrawingAreaEventsSink);
00650:                        helper
00651:                                .revokeExternalElementEventsSink(m_DrawingAreaEventsSink);
00652:                        helper
00653:                                .revokeAffectedElementEvents(m_DrawingAreaEventsSink);
00654:                        helper
00655:                                .revokeAssociationEndEvents(m_DrawingAreaEventsSink);
00656:                        helper
00657:                                .revokeStereotypeEventsSink(m_DrawingAreaEventsSink);
00658:                        helper.revokeSCMSink(m_DrawingAreaEventsSink);
00659:                        helper
00660:                                .revokeElementDisposalEventsSink(m_DrawingAreaEventsSink);
00661:                        helper
00662:                                .revokeNamespaceModifiedSink(m_DrawingAreaEventsSink);
00663:                        helper.revokeAttributeSink(m_DrawingAreaEventsSink);
00664:                        helper.revokeOperationSink(m_DrawingAreaEventsSink);
00665:                        helper.revokeParameterSink(m_DrawingAreaEventsSink);
00666:                        helper
00667:                                .revokeBehavioralFeatureSink(m_DrawingAreaEventsSink);
00668:                        helper
00669:                                .revokeRedefinableElementModifiedEvents(m_DrawingAreaEventsSink);
00670:                        helper.revokeDynamicsSink(m_DrawingAreaEventsSink);
00671:                        helper.revokeFeatureSink(m_DrawingAreaEventsSink);
00672:                        helper.revokeInitSink(m_DrawingAreaEventsSink);
00673:                        helper.revokeProjectSink(m_DrawingAreaEventsSink);
00674:                        helper.revokeActivityEdgeSink(m_DrawingAreaEventsSink);
00675:                    } catch (InvalidArguments e) {
00676:                        // TODO Auto-generated catch block
00677:                        e.printStackTrace();
00678:                    }
00679:                }
00680:            }
00681:
00682:            /**
00683:             * This method installs a layout proxy.
00684:             */
00685:            private void initializeTSLicense() {
00686:                try {
00687:                    // Initialize licensing.
00688:                    TSLicenseManager.initTSSLicensing();
00689:                    Debug.out.println(" In try of initializeTSLicense...");
00690:                } catch (Exception e) {
00691:                    Debug.out
00692:                            .println(" Exception in TSLicenseManager.initTSSLicensing() ");
00693:                    e.printStackTrace();
00694:                }
00695:            }
00696:
00697:            private void installLayoutServer() {
00698:                try {
00699:                    // Create the graph drawing.
00700:                    m_graphManager = getGraphManager();
00701:                    m_graph = getCurrentGraph();
00702:
00703:                    // Create the layout proxy.
00704:                    m_layoutProxy = new TSLayoutProxy();
00705:
00706:                    // Create a service input data object.
00707:                    m_allOptionsServiceInputData = new TSEAllOptionsServiceInputData(
00708:                            this .getGraphManager());
00709:
00710:                    // Create an input tailor object for the graph manager and one for the graph.
00711:                    m_layoutInputTailor = new TSLayoutInputTailor(
00712:                            m_allOptionsServiceInputData);
00713:
00714:                    // Set the graph manager to be laid out.
00715:                    m_layoutInputTailor.setGraphManager(m_graphManager);
00716:
00717:                    // Set layout as the current operation.
00718:                    m_layoutInputTailor.setAsCurrentOperation();
00719:
00720:                    // Create a service output data object.
00721:                    m_serviceOutputData = new TSServiceOutputData();
00722:
00723:                    //this.layoutServer = new ADLocalLayoutProxy();
00724:                } catch (Throwable t) {
00725:                    t.printStackTrace();
00726:                }
00727:            }
00728:
00729:            /**
00730:             * This method creates the graphical user interface.
00731:             */
00732:            private void createGUI() {
00733:                // set the layout
00734:                this .setLayout(new BorderLayout());
00735:
00736:                this .northPanel = new JPanel(new BorderLayout());
00737:                //      this.northPanel.setBorder(new EmptyBorder(1, 1, 1, 1));
00738:                this .add(this .northPanel, BorderLayout.NORTH);
00739:
00740:                this .centerPanel = new JPanel(new BorderLayout());
00741:                //      this.centerPanel.setBorder(new EmptyBorder(1, 1, 1, 1));
00742:                this .add(this .centerPanel, BorderLayout.CENTER);
00743:
00744:                ETSmartWaitCursor waitCursor = new ETSmartWaitCursor();
00745:                // create the window handler
00746:                this .windowHandler = new WindowHandler();
00747:
00748:                this .setGraphFileName(null);
00749:                this .initGraphWindow();
00750:                this .setChanged(false);
00751:
00752:                ADDrawingAreaControl.registerNewUIs();
00753:                // create key commands
00754:                this .registerKeyCommands(this );
00755:
00756:                this .requestFocusInWindow();
00757:                waitCursor.stop();
00758:            }
00759:
00760:            //JM: added this method to register the ui classes for TSEVisualizationXMLReader
00761:            static void registerNewUIs() {
00762:                TSEEnumerationTable.getTable().addUIName(
00763:                        ETUIFactory.GENERIC_NODE_UI, ETGenericNodeUI.class);
00764:                TSEEnumerationTable.getTable().addUIName(
00765:                        ETUIFactory.GENERIC_NODE_LABEL_UI,
00766:                        ETGenericNodeLabelUI.class);
00767:                TSEEnumerationTable.getTable().addUIName("relationEdge",
00768:                        RelationEdge.class);
00769:                TSEEnumerationTable.getTable().addUIName("basicEdge",
00770:                        ETGenericEdgeUI.class);
00771:                TSEEnumerationTable.getTable().addUIName(
00772:                        ETUIFactory.GENERIC_EDGE_LABEL_UI,
00773:                        ETGenericEdgeLabelUI.class);
00774:                //TSEEnumerationTable.getTable().addUIName(
00775:                //	"etpNode",
00776:                //	ETGenericPathNodeUI.class);
00777:                TSEEnumerationTable.getTable().addUIName(
00778:                        ETUIFactory.GENERIC_GRAPH_UI, ETGenericGraphUI.class);
00779:            }
00780:
00781:            /**
00782:             * This method sets whether the graph has been modified since
00783:             * the last time it was saved or loaded.
00784:             */
00785:            public void setChanged(boolean changed) {
00786:                if (this .getGraphWindow() != null) {
00787:                    this .getGraphWindow().setChanged(changed);
00788:                }
00789:            }
00790:
00791:            /**
00792:             * This method sets the default state, zoom level, node and edge
00793:             * UIs, and various other defaults.
00794:             */
00795:            private void setDefaults() {
00796:                // set the default state to select
00797:                this .getActions().onSwitchToSelect();
00798:
00799:                // turn on the tool tips
00800:                getGraphWindow().setToolTipShown(true);
00801:
00802:                // create the line and point grids.
00803:                this .lineGrid = new TSELineGrid();
00804:                this .pointGrid = new TSEPointGrid();
00805:
00806:                // turn off the grid.
00807:                this .getActions().onGridType(
00808:                        ADDrawingAreaConstants.GRID_TYPE + ".none", false);
00809:
00810:                // set its spacing.
00811:                this .getActions().onGridSize(
00812:                        ADDrawingAreaConstants.GRID_SIZE + ".10", false);
00813:
00814:                // set auto fit in window to false
00815:                this .setAutoFitInWindow(false);
00816:            }
00817:
00818:            /**
00819:             * This method sets all user specified properties for the
00820:             * node or edge UI specified by the user.
00821:             */
00822:            private void setUIAttributes(String type, TSEObjectUI ui) {
00823:                for (int attr = 1;; ++attr) {
00824:                    String name = this .getResources().getStringResource(
00825:                            type + ".property." + attr + ".name");
00826:                    String value = this .getResources().getStringResource(
00827:                            type + ".property." + attr + ".value");
00828:                    if (name == null || value == null) {
00829:                        return;
00830:                    }
00831:                    ui.setProperty(new TSProperty(name, value));
00832:                }
00833:            }
00834:
00835:            /**
00836:             * This method registers all the key actions to the related keys.
00837:             */
00838:            public void registerKeyCommands(JComponent component) {
00839:                kbAccessProvider = DiagramKeyboardAccessProvider
00840:                        .getInstance(this );
00841:                kbAccessProvider.registerKeyCommands(component);
00842:            }
00843:
00844:            /**
00845:             * This method unregisters some keys, which are used to zoom and
00846:             * scroll, when "auto fit in window" is on. It simply binds them
00847:             * to a dummy command.
00848:             */
00849:            public void unregisterKeyCommands(JComponent component) {
00850:                DiagramKeyboardAccessProvider kbAccessProvider = DiagramKeyboardAccessProvider
00851:                        .getInstance(this );
00852:                kbAccessProvider.unregisterKeyCommands(component);
00853:            }
00854:
00855:            /**
00856:             * This method opens a file dialog and prompts the user to select
00857:             * the name of the graph. This method returns null if the user
00858:             * cancels the dialog.
00859:             */
00860:            private List getFileNames(boolean load) {
00861:                List fileNames;
00862:
00863:                fileNames = this .getLocalFiles(load);
00864:
00865:                if (fileNames == null) {
00866:                    return null;
00867:                }
00868:                String plainExtension = ".tsv";
00869:
00870:                Iterator iter = fileNames.iterator();
00871:
00872:                while (iter.hasNext()) {
00873:                    String fileName = iter.next().toString();
00874:
00875:                    if (fileName.indexOf('.') < 0) {
00876:                        fileName += plainExtension;
00877:                    }
00878:                }
00879:
00880:                return fileNames;
00881:            }
00882:
00883:            /**
00884:             * This method returns a local file name.
00885:             */
00886:            private List getLocalFiles(boolean load) {
00887:                // stores the return code of the file chooser
00888:                int rc;
00889:
00890:                if (this .getGraphFileName() != null && !load) {
00891:                    this .getFileChooser().setSelectedFileAndFilter(
00892:                            new File(this .getGraphFileName()));
00893:                } else {
00894:                    this .getFileChooser().setSelectedFile(new File(""));
00895:                }
00896:
00897:                if (load) {
00898:                    this .getFileChooser().setDialogTitle(
00899:                            RESOURCE_BUNDLE.getString("IDS_OPEN"));
00900:                    this .getFileChooser().cancelSelection();
00901:                    rc = this .getFileChooser().showOpenDialog(this );
00902:                } else {
00903:                    this .getFileChooser().setDialogTitle(
00904:                            RESOURCE_BUNDLE.getString("IDS_SAVEAS"));
00905:
00906:                    rc = this .getFileChooser().showSaveDialog(this );
00907:                }
00908:
00909:                if (rc != JFileChooser.APPROVE_OPTION) {
00910:                    return null;
00911:                } else {
00912:                    File[] files = this .getFileChooser().getSelectedFiles();
00913:
00914:                    if (files == null) {
00915:                        return null;
00916:                    } else {
00917:                        if (files.length == 0) {
00918:                            // this is a workaround for Swing bug 4528663
00919:                            if (this .getFileChooser().getUI() instanceof  BasicFileChooserUI) {
00920:                                BasicFileChooserUI ui = (BasicFileChooserUI) this 
00921:                                        .getFileChooser().getUI();
00922:                                ui.getApproveSelectionAction().actionPerformed(
00923:                                        null);
00924:                            }
00925:
00926:                            files = new File[] { this .getFileChooser()
00927:                                    .getSelectedFile() };
00928:                        }
00929:
00930:                        List paths = new LinkedList();
00931:
00932:                        for (int i = 0; i < files.length; i++) {
00933:                            File selectedFile = files[i];
00934:
00935:                            // the path contains the full path name to the choosen
00936:                            // file
00937:                            String path = selectedFile.getAbsolutePath();
00938:
00939:                            // the filename is without path.
00940:                            String fileName = selectedFile.getName();
00941:
00942:                            // determine what extension to add to the filesname
00943:                            // using our specific file filter
00944:                            if (this .getFileChooser().getFileFilter() instanceof  TSFileFilter) {
00945:                                // the file filter contains the extension that
00946:                                // should be applied to the filename
00947:                                TSFileFilter filter = (TSFileFilter) this 
00948:                                        .getFileChooser().getFileFilter();
00949:
00950:                                // if the choosen file has no extension
00951:                                // adding the extension is enough
00952:                                if (fileName.indexOf('.') < 0) {
00953:                                    path += "." + filter.getExtension();
00954:                                } else if (load) {
00955:                                    // if the chosen extension in the file filter
00956:                                    // is different from the extension the file has
00957:                                    // it should be replaced.
00958:                                    String plainExtension = ".tsv";
00959:                                    String zipExtension = ".tsvz";
00960:
00961:                                    // replace only known extensions
00962:                                    // like this plain extension
00963:                                    if (path.endsWith(plainExtension)) {
00964:                                        // cut the extension of the path
00965:                                        path = path.substring(0, path.length()
00966:                                                - plainExtension.length());
00967:                                    }
00968:
00969:                                    // replace only known extensions
00970:                                    // like this compressed extension
00971:                                    if (path.endsWith(zipExtension)) {
00972:                                        // cut the extension of the path
00973:                                        path = path.substring(0, path.length()
00974:                                                - plainExtension.length());
00975:                                    }
00976:
00977:                                    // add the chosen extension
00978:                                    path += "." + filter.getExtension();
00979:                                }
00980:                            }
00981:
00982:                            paths.add(path);
00983:                        }
00984:
00985:                        return paths;
00986:                    }
00987:                }
00988:            }
00989:
00990:            /**
00991:             * This method returns the file chooser dialog used by this
00992:             * application.
00993:             */
00994:            private TSFileChooser getFileChooser() {
00995:                if (this .fileChooser == null) {
00996:                    this .fileChooser = new TSFileChooser(System
00997:                            .getProperty("user.dir"));
00998:
00999:                    TSFileFilter extensionFilter;
01000:                    extensionFilter = new TSFileFilter("tsv",
01001:                            "Tom Sawyer Visualiztion (*.tsv)");
01002:                    this .fileChooser.addChoosableFileFilter(extensionFilter);
01003:                    this .fileChooser.addChoosableFileFilter(new TSFileFilter(
01004:                            "tsvz",
01005:                            "Compressed Tom Sawyer Visualiztion (*.tsvz)"));
01006:                    this .fileChooser
01007:                            .setFileSelectionMode(JFileChooser.FILES_ONLY);
01008:
01009:                    // allow multiple file selection only if using multiple windows
01010:                    this .fileChooser.setMultiSelectionEnabled(false);
01011:
01012:                    this .fileChooser.removeChoosableFileFilter(this .fileChooser
01013:                            .getAcceptAllFileFilter());
01014:                    this .fileChooser.setFileFilter(extensionFilter);
01015:                    TSELocalization.setComponentOrientation(this .fileChooser);
01016:                }
01017:
01018:                this .fileChooser.rescanCurrentDirectory();
01019:                return this .fileChooser;
01020:            }
01021:
01022:            /**
01023:             * Set up the resource manager for this drawing area
01024:             *
01025:             * @param pProductArchive [in] The archive (etlp) that contains resource manager information on
01026:             * colors and fonts.
01027:             */
01028:            private void loadResourceManager(IProductArchive prodArchive) {
01029:                ETSmartWaitCursor wait = new ETSmartWaitCursor();
01030:                ResourceMgr pMgr = ResourceMgr.instance(
01031:                        (IDrawingAreaControl) this , prodArchive);
01032:                if (prodArchive != null) {
01033:                    pMgr.readFromArchive(prodArchive);
01034:                }
01035:                wait.stop();
01036:            }
01037:
01038:            /**
01039:             * Load from a file
01040:             *
01041:             * @param sFilename [in] The full path filename to load (this can be an etl or etlp file)
01042:             * @param pFileCode [out,retval] Tells how the load went.
01043:             */
01044:            public static class DABlocker {
01045:
01046:                static boolean orig = false;
01047:
01048:                public DABlocker() {
01049:                }
01050:
01051:                public static void startBlocking() {
01052:                    ++m_Instances;
01053:
01054:                    if (m_Instances == 1) {
01055:                        orig = EventBlocker.startBlocking();
01056:                    }
01057:                }
01058:
01059:                public static void stopBlocking() {
01060:                    --m_Instances;
01061:
01062:                    if (m_Instances == 0) {
01063:                        EventBlocker.stopBlocking(orig);
01064:                    }
01065:                }
01066:
01067:                public static boolean getIsDisabled() {
01068:                    return m_Instances != 0;
01069:                }
01070:
01071:                private static int m_Instances = 0;
01072:            }
01073:
01074:            /**
01075:             * Load from a file
01076:             *
01077:             * @param sFilename [in] The full path filename to load (this can be an etl or etlp file)
01078:             * @param pFileCode [out,retval] Tells how the load went.
01079:             */
01080:            public int load(String filename, final boolean fitToZoom) {
01081:                final ETSmartWaitCursor waitCursor = new ETSmartWaitCursor();
01082:
01083:                int result = -1;
01084:                IOSemaphore.startInstance();
01085:                try {
01086:                    setPopulating(true);
01087:
01088:                    boolean prodArchiveLoadedOK = false;
01089:                    if (!m_LoadedFromFile) {
01090:                        m_LoadedFromFile = true;
01091:
01092:                        // kill modified events from getting to the diagram prematurely
01093:                        //DAEventBlocker blocker = new DAEventBlocker();
01094:                        try {
01095:                            DABlocker.startBlocking();
01096:                            // Don't go through put here, just do it directly
01097:                            m_FileName = filename;
01098:
01099:                            TSGraphManager pGraphMgr = getCurrentGraphManager();
01100:                            if (pGraphMgr != null) {
01101:                                IProductArchive pArchive = new ProductArchiveImpl();
01102:
01103:                                // Verify we have a etlp file
01104:                                String etlpFilename = FileSysManip
01105:                                        .ensureExtension(
01106:                                                filename,
01107:                                                FileExtensions.DIAGRAM_PRESENTATION_EXT);
01108:                                File file = new File(filename);
01109:                                if (file.exists()) {
01110:                                    prodArchiveLoadedOK = pArchive
01111:                                            .load(etlpFilename);
01112:                                }
01113:                                setFileName(filename, false);
01114:
01115:                                // If the product archive was loaded ok then continue with the loading process
01116:                                if (prodArchiveLoadedOK) {
01117:                                    boolean readGMFOk = true;
01118:
01119:                                    IProduct prod = getProduct();
01120:                                    if (prod != null) {
01121:                                        IDiagram pDia = getDiagram();
01122:                                        prod.setSerializingDiagram(pDia);
01123:
01124:                                        // Tell TomSawyer to load the file
01125:                                        if (pGraphMgr instanceof  TSDGraphManager) {
01126:                                            try {
01127:                                                //JM : trying to split it for TS related gmf and xml files
01128:                                                boolean isFileTSVxml = true; // It file a TSVisualization xml file
01129:                                                Reader reader = null;
01130:                                                if (isFileTSVxml) {
01131:
01132:                                                    FileInputStream fileReader = new FileInputStream(
01133:                                                            filename);
01134:                                                    InputStreamReader inpReader = new InputStreamReader(
01135:                                                            fileReader);
01136:                                                    reader = new BufferedReader(
01137:                                                            inpReader);
01138:                                                    if (reader.ready()) {
01139:                                                        try {
01140:                                                            xmlReader = new TSEVisualizationXMLReader(
01141:                                                                    reader);
01142:                                                            xmlReader
01143:                                                                    .setGraphManager(pGraphMgr);
01144:                                                            xmlReader
01145:                                                                    .setServiceInputData(m_allOptionsServiceInputData);
01146:                                                            xmlReader
01147:                                                                    .setPreferences(this 
01148:                                                                            .getGraphWindow()
01149:                                                                            .getPreferences());
01150:                                                            xmlReader
01151:                                                                    .setStrict(true);
01152:
01153:                                                            xmlReader.read();
01154:                                                        } catch (Exception ex) {
01155:                                                            Debug.out
01156:                                                                    .println(" Exception in xmlREading... So, it is NOT a TSVisulatization file.. it might be GMF...");
01157:                                                            isFileTSVxml = false; // not TSV .. might be in gmf format..
01158:                                                        }
01159:
01160:                                                        if (!isFileTSVxml) {
01161:                                                            // it is a gmf file..
01162:                                                            reader = new BufferedReader(
01163:                                                                    new InputStreamReader(
01164:                                                                            new FileInputStream(
01165:                                                                                    filename),
01166:                                                                            "UTF-8"));
01167:
01168:                                                            if (reader.ready()) {
01169:                                                                TSLayoutInputTailor tailor = new TSLayoutInputTailor(
01170:                                                                        this 
01171:                                                                                .getServiceInputData((TSEGraphManager) pGraphMgr));
01172:                                                                tailor
01173:                                                                        .setGraphManager((TSEGraphManager) pGraphMgr);
01174:
01175:                                                                try {
01176:                                                                    ((TSEGraphManager) pGraphMgr)
01177:                                                                            .readGMF(
01178:                                                                                    reader,
01179:                                                                                    this 
01180:                                                                                            .getServiceInputData((TSEGraphManager) pGraphMgr));
01181:                                                                } catch (Exception e) {
01182:                                                                    e
01183:                                                                            .printStackTrace();
01184:                                                                }
01185:                                                            }
01186:                                                            isFileTSVxml = true; //setting back to true to make TSVisualziation default
01187:                                                        }
01188:                                                        ((TSDGraphManager) pGraphMgr)
01189:                                                                .setMainDisplayGraph(this 
01190:                                                                        .getGraph());
01191:                                                        ((TSEGraphManager) pGraphMgr)
01192:                                                                .setGraphWindow(this 
01193:                                                                        .getGraphWindow());
01194:                                                        //now I need to load all the readwrite items
01195:                                                        postReadGMFFile(pArchive);
01196:                                                    } else {
01197:                                                        if (getGraphWindow() == null) {
01198:                                                            this 
01199:                                                                    .initGraphWindow();
01200:                                                        }
01201:                                                    }
01202:                                                    reader = null;
01203:                                                }
01204:                                            } catch (UnsupportedEncodingException e) {
01205:                                                e.printStackTrace();
01206:                                                sendErrorMessage("Failed to load %f");
01207:                                                readGMFOk = false;
01208:                                                if (pGraphMgr instanceof  ETGraphManager) {
01209:                                                    ETGraphManager pETGraphMgr = (ETGraphManager) pGraphMgr;
01210:                                                    pETGraphMgr
01211:                                                            .onFailedToLoadDiagram();
01212:                                                }
01213:                                            } catch (FileNotFoundException e) {
01214:                                                e.printStackTrace();
01215:                                                sendErrorMessage("Unable to locate the file %f");
01216:
01217:                                                readGMFOk = false;
01218:                                                if (pGraphMgr instanceof  ETGraphManager) {
01219:                                                    ETGraphManager pETGraphMgr = (ETGraphManager) pGraphMgr;
01220:                                                    pETGraphMgr
01221:                                                            .onFailedToLoadDiagram();
01222:                                                }
01223:                                            } catch (IOException e) {
01224:                                                e.printStackTrace();
01225:                                                sendErrorMessage("Failed to load %f");
01226:
01227:                                                readGMFOk = false;
01228:                                                if (pGraphMgr instanceof  ETGraphManager) {
01229:                                                    ETGraphManager pETGraphMgr = (ETGraphManager) pGraphMgr;
01230:                                                    pETGraphMgr
01231:                                                            .onFailedToLoadDiagram();
01232:                                                }
01233:                                            } catch (RuntimeException e) {
01234:                                                e.printStackTrace();
01235:                                                sendErrorMessage("Failed to load %f");
01236:
01237:                                                readGMFOk = false;
01238:                                                if (pGraphMgr instanceof  ETGraphManager) {
01239:                                                    ETGraphManager pETGraphMgr = (ETGraphManager) pGraphMgr;
01240:                                                    pETGraphMgr
01241:                                                            .onFailedToLoadDiagram();
01242:                                                }
01243:                                            }
01244:                                        }
01245:                                        //result = pGraphMgr.load(filename, false, false);
01246:                                        recalculateCRCs();
01247:                                        prod.setSerializingDiagram(null);
01248:                                    }
01249:
01250:                                    long timeStart = System.currentTimeMillis();
01251:
01252:                                    // set up the resource manager for this drawing
01253:                                    loadResourceManager(pArchive);
01254:
01255:                                    long timeFinish = System
01256:                                            .currentTimeMillis();
01257:                                    long tsDelta = timeFinish - timeStart;
01258:                                    ETSystem.out
01259:                                            .println("ADDrawingAreaControl.loadResourceManager() completed in ( "
01260:                                                    + StringUtilities
01261:                                                            .timeToString(
01262:                                                                    tsDelta, 3)
01263:                                                    + " )");
01264:
01265:                                    timeStart = System.currentTimeMillis();
01266:
01267:                                    readFromArchive(pArchive);
01268:
01269:                                    timeFinish = System.currentTimeMillis();
01270:                                    tsDelta = timeFinish - timeStart;
01271:                                    ETSystem.out
01272:                                            .println("ADDrawingAreaControl.readFromArchive() completed in ( "
01273:                                                    + StringUtilities
01274:                                                            .timeToString(
01275:                                                                    tsDelta, 3)
01276:                                                    + " )");
01277:
01278:                                    if (m_AbortDiagramLoad) {
01279:                                        // The window was closed during the open process.  This can sometimes
01280:                                        // happen during SCC when it gets checked out.
01281:                                        return result;
01282:                                    }
01283:
01284:                                    JTrackBar bar = getTrackBar();
01285:                                    if (readGMFOk && bar != null) {
01286:                                        bar.initialize();
01287:                                        bar.load(pArchive);
01288:                                    }
01289:                                }
01290:                            }
01291:                        } finally {
01292:                            DABlocker.stopBlocking();
01293:                        }
01294:
01295:                        if (prodArchiveLoadedOK) {
01296:                            if (m_DiagramEngine != null) {
01297:                                m_DiagramEngine.setupLayoutSettings(false);
01298:                            }
01299:
01300:                            // Tell the outside world that this drawing area is open for business
01301:                            IDiagram pDia = getDiagram();
01302:                            if (getDrawingAreaDispatcher() != null
01303:                                    && pDia != null) {
01304:                                IEventPayload payload = getDrawingAreaDispatcher()
01305:                                        .createPayload("DiagramOpened");
01306:                                getDrawingAreaDispatcher()
01307:                                        .fireDrawingAreaOpened(pDia, payload);
01308:                            }
01309:                        }
01310:                    }
01311:                } finally {
01312:                    IOSemaphore.stopInstance();
01313:                }
01314:
01315:                // Set the diagram zoom level, but give the graphwindow a chance to process msg's first.
01316:                Runnable runnable = new Runnable() {
01317:
01318:                    public void run() {
01319:                        TSEGraph graph = getGraph();
01320:                        TSEGraphWindow window = getGraphWindow();
01321:                        if (graph != null && window != null) {
01322:                            graph.setBoundsUpdatingEnabled(true);
01323:                            graph.updateBounds();
01324:                            window.setZoomLevel(m_nZoomLevelFromArchive, false);
01325:                            if (m_CenterFromArchive != null) {
01326:                                TSConstPoint point = new TSConstPoint(
01327:                                        m_CenterFromArchive.getX(),
01328:                                        m_CenterFromArchive.getY());
01329:                                getGraphWindow().centerPointInWindow(point,
01330:                                        true);
01331:                            } else {
01332:                                window.centerGraph(true);
01333:                            }
01334:                            getGraphWindow().resetWorkBounds();
01335:                            getGraphWindow().updateScrollBarValues();
01336:
01337:                            //                    if(fitToZoom == true)
01338:                            //                    {
01339:                            //                        SwingUtilities.invokeLater(new Runnable()
01340:                            //                        {
01341:                            //
01342:                            //                            public void run()
01343:                            //                            {
01344:                            //                                getGraphWindow().fitInWindow(true);
01345:                            //                            }
01346:                            //                        });
01347:                            //                    }
01348:                        }
01349:                        getResources().setLayoutStyle(getLayoutStyle());
01350:                        setPopulating(false);
01351:                        waitCursor.stop();
01352:                    }
01353:                };
01354:                SwingUtilities.invokeLater(runnable);
01355:
01356:                return result;
01357:            }
01358:
01359:            private void postReadGMFFile(IProductArchive pArchive) {
01360:                try {
01361:                    ETGraph graph = (ETGraph) getGraph();
01362:
01363:                    IteratorT<ETNode> iter = new IteratorT(graph.nodes());
01364:                    for (ETNode node = iter.next(); node != null; node = iter
01365:                            .next()) {
01366:                        ETGenericNodeUI nodeUI = (ETGenericNodeUI) node.getUI();
01367:
01368:                        nodeUI.setDrawingArea(this );
01369:                        addReadWriteItem(node);
01370:                    }
01371:
01372:                    IteratorT<ETEdge> edgeIter = new IteratorT(graph.edges());
01373:                    int edgeIndex = 0;
01374:                    for (ETEdge edge = edgeIter.next(); edge != null; edge = edgeIter
01375:                            .next()) {
01376:                        TSEObjectUI tseUI = edge.getUI();
01377:                        edgeIndex++;
01378:                        if (tseUI != null && tseUI instanceof  ETGenericEdgeUI) {
01379:                            try {
01380:                                ETGenericEdgeUI ui = (ETGenericEdgeUI) edge
01381:                                        .getUI();
01382:                                ui.setDrawingArea(this );
01383:                                addReadWriteItem(edge);
01384:                            } catch (Exception e) {
01385:                                // Discard the edge that failed to read.
01386:                                this .getGraph().discard(edge);
01387:                                // Continue reading the rest of the edges.
01388:                                edgeIter.reset(this .getGraph().edges(),
01389:                                        edgeIndex--);
01390:                            }
01391:                        }
01392:                    }
01393:
01394:                    IteratorT<ETEdgeLabel> edgeLabelIter = new IteratorT(graph
01395:                            .edgeLabels());
01396:                    for (ETEdgeLabel edgeLabel = edgeLabelIter.next(); edgeLabel != null; edgeLabel = edgeLabelIter
01397:                            .next()) {
01398:                        ETGenericEdgeLabelUI edgeLabelUI = (ETGenericEdgeLabelUI) edgeLabel
01399:                                .getUI();
01400:
01401:                        edgeLabelUI.setDrawingArea(this );
01402:                        addReadWriteItem(edgeLabel);
01403:                    }
01404:
01405:                    IteratorT<ETNodeLabel> nodeLabelIter = new IteratorT(graph
01406:                            .nodeLabels());
01407:                    for (ETNodeLabel nodeLabel = nodeLabelIter.next(); nodeLabel != null; nodeLabel = nodeLabelIter
01408:                            .next()) {
01409:                        TSEObjectUI ui = nodeLabel.getUI();
01410:                        if (ui instanceof  ETGenericNodeLabelUI) {
01411:                            ETGenericNodeLabelUI nodeLabelUI = (ETGenericNodeLabelUI) ui;
01412:
01413:                            nodeLabelUI.setDrawingArea(this );
01414:                        }
01415:                        addReadWriteItem(nodeLabel);
01416:                    }
01417:                } catch (Exception e) {
01418:                    e.printStackTrace();
01419:                }
01420:            }
01421:
01422:            private void postWriteGMFFile(IProductArchive pArchive) {
01423:                try {
01424:                    IElementLocator locator = new ElementLocator();
01425:                    ETGraph graph = (ETGraph) getGraph();
01426:
01427:                    IteratorT<ETNode> iter = new IteratorT(graph.nodes());
01428:                    for (ETNode node = iter.next(); node != null; node = iter
01429:                            .next()) {
01430:                        addReadWriteItem(node);
01431:                    }
01432:
01433:                    IteratorT<ETEdge> edgeIter = new IteratorT(graph.edges());
01434:                    for (ETEdge edge = edgeIter.next(); edge != null; edge = edgeIter
01435:                            .next()) {
01436:                        addReadWriteItem(edge);
01437:                    }
01438:
01439:                    IteratorT<ETEdgeLabel> edgeLabelIter = new IteratorT(graph
01440:                            .edgeLabels());
01441:                    for (ETEdgeLabel edgeLabel = edgeLabelIter.next(); edgeLabel != null; edgeLabel = edgeLabelIter
01442:                            .next()) {
01443:                        addReadWriteItem(edgeLabel);
01444:                    }
01445:
01446:                    IteratorT<ETNodeLabel> nodeLabelIter = new IteratorT(graph
01447:                            .nodeLabels());
01448:                    for (ETNodeLabel nodeLabel = nodeLabelIter.next(); nodeLabel != null; nodeLabel = nodeLabelIter
01449:                            .next()) {
01450:                        addReadWriteItem(nodeLabel);
01451:                    }
01452:                } catch (Exception e) {
01453:                    e.printStackTrace();
01454:                }
01455:            }
01456:
01457:            /**
01458:             * Recalculates the file crcs
01459:             *
01460:             * @return true if the recalculation was done successfully
01461:             */
01462:            private boolean recalculateCRCs() {
01463:                boolean didRecalculate = false;
01464:                if (m_FileName != null && m_FileName.length() > 0) {
01465:                    String etlpFile = FileSysManip.ensureExtension(m_FileName,
01466:                            FileExtensions.DIAGRAM_PRESENTATION_EXT);
01467:                    String etldFile = FileSysManip.ensureExtension(m_FileName,
01468:                            FileExtensions.DIAGRAM_LAYOUT_EXT);
01469:
01470:                    if (etlpFile != null && etldFile != null) {
01471:                        File fileETLP = new File(etlpFile);
01472:                        File fileETLD = new File(etldFile);
01473:                        if (!fileETLP.canWrite() && !fileETLD.canWrite()) {
01474:                            setReadOnly(true);
01475:
01476:                            // Go back to select mode
01477:                            enterMode(IDrawingToolKind.DTK_SELECTION);
01478:                        }
01479:                    }
01480:                }
01481:                return didRecalculate;
01482:            }
01483:
01484:            /**
01485:             * This method switches the graph window to the create node state.
01486:             */
01487:            public void onSwitchToCreateNodes() {
01488:                setGraphState(new ADCreateNodeState());
01489:            }
01490:
01491:            public void setGraphState(TSEWindowTool tool) {
01492:                getGraphWindow().switchTool(tool);
01493:            }
01494:
01495:            /**
01496:             * This method sets the Auto Fit In Window option.
01497:             */
01498:            public void setAutoFitInWindow(boolean autoFitInWindow) {
01499:                this .autoFitInWindow = autoFitInWindow;
01500:
01501:                if (this .autoFitInWindow) {
01502:                    getGraphWindow().fitInWindow(false);
01503:                }
01504:            }
01505:
01506:            /**
01507:             * This method creates toolbars.
01508:             * It requests them from the resource bundle which knows how
01509:             * to create toolbars from the resources.
01510:             */
01511:            private void createToolbars() {
01512:                // create the toolbars used by the application
01513:                this .mainToolBar = this .addToolBar("toolbar.main");
01514:            }
01515:
01516:            private void initGraphWindow() {
01517:                this .initGraphWindow(new ADGraphWindow(this , null, true));
01518:                m_GraphWindow.hasFileName = false;
01519:            }
01520:
01521:            public void addGraphWindow(ADGraphWindow newGraphWindow) {
01522:                if (m_GraphWindow == null) {
01523:                    m_GraphWindow = newGraphWindow;
01524:                }
01525:
01526:                if (m_GraphWindow != null) {
01527:                    m_GraphWindow.addMouseWheelListener(this );
01528:
01529:                    this .graphFileName = m_GraphWindow.getGraphFileName();
01530:
01531:                    this .centerPanel.add(m_GraphWindow);
01532:
01533:                    this .requestFocusInWindow();
01534:                }
01535:            }
01536:
01537:            /**
01538:             * This method returns the title for the next new document
01539:             */
01540:            private String nextNewDocTitle() {
01541:                String title = this .getResources().getString("file.noname")
01542:                        + this .nextNewDocIndex
01543:                        + "."
01544:                        + this .getResources().getStringResource(
01545:                                "file.plain.extension");
01546:                this .nextNewDocIndex++;
01547:
01548:                return title;
01549:            }
01550:
01551:            public String getGraphFileName() {
01552:                return this .graphFileName;
01553:            }
01554:
01555:            public void setGraphFileName(String filename) {
01556:                this .graphFileName = filename;
01557:            }
01558:
01559:            /**
01560:             * This method builds a toolbar from the specified resource and
01561:             * adds it to the appropriate panel.
01562:             */
01563:            public JToolBar addToolBar(String name) {
01564:                JToolBar toolBar = this .getResources().createToolBar(name,
01565:                        this .getActions());
01566:
01567:                if (toolBar == null) {
01568:                    return toolBar;
01569:                }
01570:
01571:                addToolBar(name, toolBar);
01572:
01573:                return toolBar;
01574:            }
01575:
01576:            /**
01577:             * @param name
01578:             * @param toolBar
01579:             */
01580:            protected JToolBar addToolBar(String name, JToolBar toolBar) {
01581:                // place it in the panel specified by its location resource.
01582:                Object location = this .getResources().getObjectResource(
01583:                        name + ".location");
01584:
01585:                JPanel panel;
01586:                panel = this .northPanel;
01587:
01588:                // put it in the panel's border layout region specified by its sublocation resource.
01589:                Object subLocation = this .getResources().getObjectResource(
01590:                        name + ".sublocation");
01591:
01592:                if (subLocation == null) {
01593:                    subLocation = BorderLayout.CENTER;
01594:                }
01595:                if (m_showToolbars) {
01596:                    panel.add(toolBar, subLocation);
01597:                }
01598:                return toolBar;
01599:            }
01600:
01601:            public ADComboBox getZoomComboBox() {
01602:                if (this .zoomComboBox == null) {
01603:                    String[] zoomLevels = new String[] { "400%", "200%",
01604:                            "100%", "75%", "50%", "25%",
01605:                            RESOURCE_BUNDLE.getString("IDS_ZOOMTOFIT") };
01606:
01607:                    this .zoomComboBox = new ADComboBox(zoomLevels);
01608:                    this .zoomComboBox.setEditable(true);
01609:                    this .zoomComboBox
01610:                            .setActionCommand(ADDrawingAreaConstants.ZOOM_CHANGE);
01611:
01612:                    //         Dimension comboBoxSize = new Dimension(90, 25);
01613:                    //         this.zoomComboBox.setPreferredSize(comboBoxSize);
01614:                    JTextField zoomField = (JTextField) this .zoomComboBox
01615:                            .getEditor().getEditorComponent();
01616:
01617:                    zoomField.setDocument(new TSDoublePercentDocument(
01618:                            Double.POSITIVE_INFINITY));
01619:                }
01620:
01621:                return this .zoomComboBox;
01622:            }
01623:
01624:            public ADDrawingAreaResourceBundle getResources() {
01625:                if (this .resourceBundle == null) {
01626:                    this .resourceBundle = (ADDrawingAreaResourceBundle) ResourceBundle
01627:                            .getBundle("org.netbeans.modules.uml.ui.swing.drawingarea.ADDrawingAreaBundle");
01628:
01629:                    this .resourceBundle.setParameterReader(this );
01630:                    this .resourceBundle.setDrawingArea(this );
01631:                }
01632:
01633:                return this .resourceBundle;
01634:            }
01635:
01636:            public String getParameter(String key) {
01637:                return null;
01638:            }
01639:
01640:            /**
01641:             * This method returns the graph manager that this application is
01642:             * displaying.
01643:             */
01644:            public TSEGraphManager getGraphManager() {
01645:                // We need to be careful of recursion, the ADGraphWindow tries to get our graph manager.
01646:                // TODO: We should move all the graph and file management stuff into the graph window and or
01647:                // the graph manager.
01648:                return getGraphWindow().getGraphManager();
01649:            }
01650:
01651:            /**
01652:             * This method returns the main display graph of the selected graph window
01653:             * of this application..
01654:             */
01655:            public TSEGraph getGraph() {
01656:                ADGraphWindow window = getGraphWindow();
01657:                return window != null ? window.getGraph() : null;
01658:            }
01659:
01660:            //JM: to get the layoutInputTailor object to use in ADDrawingAreaActions:
01661:            public TSLayoutInputTailor getLayoutInputTailor() {
01662:                return this .m_layoutInputTailor != null ? m_layoutInputTailor
01663:                        : null;
01664:            }
01665:
01666:            /**
01667:             * This method returns the selected graph window this application operates
01668:             * on.
01669:             */
01670:            public ADGraphWindow getGraphWindow() {
01671:                return m_GraphWindow;
01672:            }
01673:
01674:            /**
01675:             * This method returns whether the Auto Fit In Window option is on or
01676:             * off.
01677:             */
01678:            public boolean isAutoFitInWindow() {
01679:                return this .autoFitInWindow;
01680:            }
01681:
01682:            /**
01683:             * This class implements a window handler. It manages window
01684:             * events, such as the window being closed.
01685:             */
01686:            class WindowHandler extends WindowAdapter {
01687:            }
01688:
01689:            public boolean hasGraphWindow() {
01690:                return this .m_GraphWindow != null;
01691:            }
01692:
01693:            /*
01694:             * Factory function, creates the drawingarea actions.
01695:             */
01696:            protected ADDrawingAreaActions createDrawingAreaActions() {
01697:                return new ADDrawingAreaActions(this );
01698:            }
01699:
01700:            /**
01701:             * This method returns the unique instance of ADEditorActions. The
01702:             * ADEditorActions object is allocated on the first call to this
01703:             * method. This method will allocate the ADEditorActions object if
01704:             * it has not yet been created.
01705:             */
01706:            public ADDrawingAreaActions getActions() {
01707:                if (this .actions == null) {
01708:                    this .actions = createDrawingAreaActions();
01709:                }
01710:
01711:                return this .actions;
01712:            }
01713:
01714:            public Frame getOwnerFrame() {
01715:                return JOptionPane.getFrameForComponent(SwingUtilities
01716:                        .getRootPane(this ));
01717:            }
01718:
01719:            public Frame getMainFrame() {
01720:                IProxyUserInterface ui = ProductHelper.getProxyUserInterface();
01721:                return ui != null ? ui.getWindowHandle() : null;
01722:            }
01723:
01724:            public IProductArchive getProductArchive() {
01725:                if (this .m_ProductArchive != null) {
01726:                    return m_ProductArchive;
01727:                } else {
01728:                    m_ProductArchive = new ProductArchiveImpl();
01729:                    return m_ProductArchive;
01730:                }
01731:            }
01732:
01733:            /**
01734:             * This method performs a layout on the graph.
01735:             */
01736:            public void onApplyLayout(String command) {
01737:                // show the wait cursor
01738:                ETSmartWaitCursor waitCursor = new ETSmartWaitCursor();
01739:                try {
01740:                    // disable user actions for the duration of the layout
01741:                    this .getGraphWindow().setUserActionEnabled(false);
01742:
01743:                    // if the command specified the layout style we need
01744:                    // to adjust layout properties. Otherwise we use the
01745:                    // style that is already set
01746:                    String layoutStyle = null;
01747:                    //boolean incremental = false;
01748:                    if (!command.equals(ADDrawingAreaConstants.APPLY_LAYOUT)) {
01749:                        layoutStyle = command
01750:                                .substring(
01751:                                        ADDrawingAreaConstants.APPLY_LAYOUT
01752:                                                .length() + 1).toUpperCase();
01753:                    }
01754:
01755:                    if (layoutStyle == null) {
01756:                        //layoutStyle = this.getGraph().getLayoutStyle();
01757:                    }
01758:
01759:                    // we save the original layout style, so that when the ongoing one
01760:                    // fails, we can set it back.
01761:                    int originalLayoutStyle = this .m_layoutInputTailor
01762:                            .getLayoutStyle(this .getGraph());
01763:
01764:                    if (layoutStyle
01765:                            .indexOf(ADDrawingAreaConstants.INCREMENTAL_LAYOUT) >= 0) {
01766:                        layoutStyle = layoutStyle.substring(0, layoutStyle
01767:                                .lastIndexOf("."));
01768:                        //incremental = true;
01769:                        m_layoutInputTailor.setIncrementalLayout(true);
01770:                    } else {
01771:                        m_layoutInputTailor.setIncrementalLayout(false);
01772:                    }
01773:                    int layoutStyleInt = new Integer(layoutStyle).intValue();
01774:                    setLayoutStyle(layoutStyleInt);
01775:                } catch (Exception e) {
01776:                    e.printStackTrace();
01777:
01778:                    // apparently layout server cannot be reached
01779:                    this .m_layoutProxy = null;
01780:
01781:                    // tell the user about it
01782:                    JOptionPane.showMessageDialog(this , this .getResources()
01783:                            .getStringResource("dialog.layoutError.message"),
01784:                            this .getResources().getStringResource(
01785:                                    "dialog.layoutError.title"),
01786:                            JOptionPane.ERROR_MESSAGE);
01787:                } finally {
01788:                    // show the default cursor
01789:                    waitCursor.stop();
01790:                }
01791:
01792:                // re-enable user actions
01793:                this .getGraphWindow().setUserActionEnabled(true);
01794:            }
01795:
01796:            /**
01797:             * This method creates and or toggles displays an overview window.
01798:             */
01799:            public void onShowOverviewWindow() {
01800:                // position the overview window on the top right of the graph
01801:                // window.
01802:                boolean currentlyVisible = this .getIsOverviewWindowOpen();
01803:                if (!this .overviewBoundsCreated) {
01804:                    int x = getGraphWindow().getLocationOnScreen().x
01805:                            + getGraphWindow().getSize().width
01806:                            - ETDiagramOverviewWindow.WIDTH
01807:                            - this .windowInsets.right;
01808:
01809:                    int y = getGraphWindow().getLocationOnScreen().y
01810:                            + this .windowInsets.top;
01811:                    this .overviewBounds = new Rectangle(x, y,
01812:                            ETDiagramOverviewWindow.WIDTH,
01813:                            ETDiagramOverviewWindow.HEIGHT);
01814:                    this .overviewBoundsCreated = true;
01815:                }
01816:
01817:                if (this .overviewWindow == null) {
01818:                    this .overviewWindow = new ETDiagramOverviewWindow(this 
01819:                            .getOwnerFrame(), this .getResources()
01820:                            .getStringResource("dialog.overviewWindow.title"),
01821:                            this .getGraphWindow());
01822:
01823:                    this .overviewWindow.setBounds(this .overviewBounds);
01824:                }
01825:
01826:                // disable the move/zoom state of the overview window when the autoFitInWindow option is on.
01827:                if (overviewWindow != null) {
01828:                    this .overviewWindow.setGraphWindow(getGraphWindow());
01829:
01830:                    this .overviewWindow.setVisible(!currentlyVisible);
01831:                    if (!currentlyVisible) {
01832:                        // Enable it
01833:                        //this.overviewWindow.getOverviewComponent().setStateEnabled(!this.isAutoFitInWindow()); //JM
01834:                        this .overviewWindow.getOverviewComponent()
01835:                                .setToolEnabled(true);
01836:                    }
01837:                    //this.refresh(true);
01838:                }
01839:            }
01840:
01841:            /*
01842:             * Synchronizes the secondard windows with the main display area.
01843:             */
01844:            public void updateSecondaryWindows() {
01845:                // notify the overview window that we have changed the graph window.
01846:                if (this .isOverviewWindowOpen()
01847:                        && getGraphWindow().isUserActionEnabled()) {
01848:                    ((TSGraph) this .getGraph())
01849:                            .fireEvent(new TSEViewportChangeEvent(
01850:                                    TSEViewportChangeEvent.ZOOM, null));
01851:                    ((TSGraph) this .getGraph())
01852:                            .fireEvent(new TSEViewportChangeEvent(
01853:                                    TSEViewportChangeEvent.PAN, null));
01854:                }
01855:            }
01856:
01857:            public ETEdge addEdgeForType(String metaType, ETNode sourceNode,
01858:                    ETNode targetNode, boolean bSelected,
01859:                    boolean bDeselectAllOthers) throws ETException {
01860:                ETEdge retVal = null;
01861:
01862:                IPresentationTypesMgr mgr = getPresentationTypesMgr();
01863:                if (mgr != null) {
01864:                    String initString = mgr.getMetaTypeInitString(metaType,
01865:                            getDiagramKind());
01866:
01867:                    TSEdge edge = addEdge(initString, sourceNode, targetNode,
01868:                            bSelected, bDeselectAllOthers);
01869:
01870:                    if (edge instanceof  ETEdge) {
01871:                        retVal = (ETEdge) edge;
01872:                    }
01873:                }
01874:
01875:                return retVal;
01876:            }
01877:
01878:            /**
01879:             * Adds an edge to the diagram.
01880:             */
01881:            public TSEdge addEdge(String edgeInitString, TSNode pSourceNode,
01882:                    TSNode pTargetNode, boolean bSelect,
01883:                    boolean bDeselectAllOthers) throws ETException {
01884:                TSEdge retVal = null;
01885:
01886:                TSEGraph graph = getGraph();
01887:                if (graph != null) {
01888:                    retVal = graph.addEdge(pSourceNode, pTargetNode);
01889:                    if (retVal instanceof  ETEdge) {
01890:                        ETEdge gEdge = (ETEdge) retVal;
01891:
01892:                        IPresentationTypesMgr mgr = getPresentationTypesMgr();
01893:                        PresentationTypeDetails details = mgr
01894:                                .getInitStringDetails(edgeInitString,
01895:                                        getDiagramKind());
01896:
01897:                        int delimiter = edgeInitString.indexOf(' ');
01898:                        String edgeUIClass = delimiter > 0 ? edgeInitString
01899:                                .substring(0, delimiter) : edgeInitString;
01900:                        ETGenericEdgeUI edgeUI = ETUIFactory.createEdgeUI(
01901:                                edgeUIClass, edgeInitString, details
01902:                                        .getEngineName(), this );
01903:                        gEdge.setUI(edgeUI);
01904:
01905:                        onPostAddEdge((IETEdge) gEdge);
01906:
01907:                        if ((bSelect == true) || (bDeselectAllOthers == true)) {
01908:                            selectAndFireEvents(retVal, bSelect,
01909:                                    bDeselectAllOthers);
01910:                        }
01911:                    }
01912:                }
01913:
01914:                return retVal;
01915:            }
01916:
01917:            /**
01918:             * Adds an edge to the diagram.
01919:             *
01920:             * @param edgeInitString The initialization string for the edge.
01921:             * @param pSourceNode The source for the edge.
01922:             * @param pTargetNode The target for the edge.
01923:             * @param bSelect Should we select this new graph object?
01924:             * @param bDeselectAllOthers Should we deselect all other objects?
01925:             * @param pElementToAssignToEdge The element to assign to the edge
01926:             * @return The created edge.  <code>null</code> if no edge is created.
01927:             */
01928:            public TSEdge addEdge(String edgeInitString, TSNode pSourceNode,
01929:                    TSNode pTargetNode, boolean bSelect,
01930:                    boolean bDeselectAllOthers, IElement elementToAssignToEdge)
01931:                    throws ETException {
01932:                TSEdge retVal = null;
01933:
01934:                if (edgeInitString.length() > 0) {
01935:                    IElement pPrevElement = this .getModelElement();
01936:                    setModelElement(elementToAssignToEdge);
01937:                    retVal = addEdge(edgeInitString, pSourceNode, pTargetNode,
01938:                            bSelect, bDeselectAllOthers);
01939:                    setModelElement(pPrevElement);
01940:                }
01941:
01942:                return retVal;
01943:            }
01944:
01945:            /**
01946:             *
01947:             * Helper to determine if class compartments are currently selected.  If so then cut/copy/paste
01948:             * operations are prohibited.
01949:             *
01950:             * @return TRUE if a single class node containing selected compartments is selected
01951:             *
01952:             */
01953:            private boolean areCompartmentsSelected() {
01954:                boolean bSelected = false;
01955:                ETList<IPresentationElement> pSelected = getSelected();
01956:
01957:                long count = pSelected != null ? pSelected.size() : 0;
01958:                // 2 possible situations exist, they could be cutting entire nodes or in the case of
01959:                // a class diagram, could be cutting just a couple compartments
01960:                // the test is if a single
01961:                // special case, if a single node has been selected, check it for selected compartments
01962:                if (count == 1) {
01963:                    IETGraphObject pProduct = TypeConversions
01964:                            .getETGraphObject(pSelected.get(0));
01965:
01966:                    if (pProduct != null) {
01967:                        ETList<IElement> pDragElements = pProduct
01968:                                .getDragElements();
01969:                        bSelected = pDragElements != null
01970:                                && pDragElements.size() > 0;
01971:                    }
01972:                }
01973:                return bSelected;
01974:            }
01975:
01976:            public void cut() {
01977:                // Return if we're blocked
01978:                if (UserInputBlocker.getIsDisabled(GBK.DIAGRAM_DELETION)) {
01979:                    //ATLASSERT(0 &&_T("CAxDrawingAreaControl::Cut blocked\n") );
01980:                    return;
01981:                }
01982:
01983:                if (!m_ReadOnly) {
01984:                    // Need to clear all the clipboards of the other diagrams
01985:                    IProxyDiagramManager pManager = ProxyDiagramManager
01986:                            .instance();
01987:                    ISimpleBroadcastAction pAction = new SimpleBroadcastAction();
01988:
01989:                    /// W2662, Cutting when compartments are selected is temporarily disabled
01990:                    if (!areCompartmentsSelected()) {
01991:                        if (pManager != null && pAction != null) {
01992:                            pAction
01993:                                    .setKind(DiagramAreaEnumerations.SBK_CLEAR_CLIPBOARD);
01994:                            pManager.broadcastToAllOpenDiagrams(pAction);
01995:
01996:                            // Since TS doesn't have copy and paste working between diagrams yet
01997:                            // we also copy the selected elements onto the IProduct clipboard.
01998:                            // If a paste is performed we first check to see if we've got something in the TS clipboard,
01999:                            // if not then check the proxy diagram clip.
02000:                            IProduct pProduct = getProduct();
02001:
02002:                            if (pProduct != null) {
02003:                                // Clear it out first
02004:                                pProduct.setCrossDiagramClipboard("");
02005:
02006:                                ETList<IPresentationElement> pSelected = getSelected();
02007:
02008:                                // Notify the track bar that a change has been made
02009:                                if (m_TrackBar != null) {
02010:                                    try {
02011:                                        m_TrackBar
02012:                                                .removePresentationElements(pSelected);
02013:                                    } catch (Exception e) {
02014:                                        e.printStackTrace();
02015:                                    }
02016:                                }
02017:
02018:                                ADTransferable transferable = new ADTransferable(
02019:                                        "DRAGGEDITEMS");
02020:
02021:                                transferable
02022:                                        .addModelAndPresentationElements(pSelected);
02023:                                transferable.addGenericElement(Integer
02024:                                        .toString(this .hashCode()));
02025:                                String text = null;
02026:
02027:                                try {
02028:                                    text = (String) transferable
02029:                                            .getTransferData(ADTransferable.ADDataFlavor.stringFlavor);
02030:                                } catch (UnsupportedFlavorException e) {
02031:                                    throw new AssertionError(
02032:                                            "Unsupported Flavor "
02033:                                                    + e.toString());
02034:                                } catch (IOException e) {
02035:                                    throw new AssertionError("IOException "
02036:                                            + e.toString());
02037:                                }
02038:
02039:                                if (text != null && text.length() > 0) {
02040:                                    // Put these items on the clip
02041:                                    pProduct.setCrossDiagramClipboard(text);
02042:                                }
02043:                            }
02044:                        }
02045:
02046:                        // The GET will copy to TS internal clip and the windows clip.
02047:                        // Sun Issue 6184441:  It appears that TS is setting up the clipboard
02048:                        // then sending use a the delete command, which we were then clearing
02049:                        // the clipboard.  We use m_bCutting to indicate we are cutting so that
02050:                        // we don't clear the clipboard.
02051:                        // @see clearClipboard()
02052:                        m_bCutting = true;
02053:                        GetHelper.cut(this .getGraphWindow());
02054:                        m_bCutting = false;
02055:
02056:                        this .setIsDirty(true);
02057:                    } else {
02058:                        //::MessageBeep((UINT)-1);
02059:                    }
02060:                }
02061:            }
02062:
02063:            public void copy() {
02064:                // Need to clear all the clipboards of the other diagrams
02065:                IProxyDiagramManager pManager = ProxyDiagramManager.instance();
02066:                ISimpleBroadcastAction pAction = new SimpleBroadcastAction();
02067:
02068:                boolean bHandled = false;
02069:
02070:                ETList<TSGraphObject> selectedObjs = null;
02071:                if (getGraph() instanceof  ETGraph) {
02072:                    ETGraph etGraph = (ETGraph) getGraph();
02073:                    selectedObjs = etGraph.getSelectedObjects(false, false);
02074:                }
02075:
02076:                // First fire it off to the diagram engine
02077:                if (m_DiagramEngine != null) {
02078:                    bHandled = m_DiagramEngine.preCopy();
02079:                }
02080:
02081:                // Allow the engine to cancel the copy
02082:                if (!bHandled) {
02083:                    if (pManager != null && pAction != null) {
02084:                        pAction
02085:                                .setKind(DiagramAreaEnumerations.SBK_CLEAR_CLIPBOARD);
02086:
02087:                        pManager.broadcastToAllOpenDiagrams(pAction);
02088:
02089:                        ETElementManager manager = new ETElementManager(this );
02090:
02091:                        // The GET will copy to TS internal clip and the windows clip.
02092:                        manager.onPreCopy();
02093:                        GetHelper.copy(getGraphWindow());
02094:                        manager.onPostCopy();
02095:
02096:                        // Since TS doesn't have copy and paste working between diagrams yet
02097:                        // we also copy the selected elements onto the IProduct clipboard.
02098:                        // If a paste is performed we first check to see if we've got something in the TS clipboard,
02099:                        // if not then check the proxy diagram clip.
02100:                        IProduct pProduct = getProduct();
02101:
02102:                        if (pProduct != null) {
02103:                            // Clear it out first
02104:                            pProduct.setCrossDiagramClipboard("");
02105:
02106:                            ETList<IPresentationElement> pSelected = getSelected();
02107:
02108:                            ADTransferable transferable = new ADTransferable(
02109:                                    "DRAGGEDITEMS");
02110:
02111:                            transferable
02112:                                    .addModelAndPresentationElements(pSelected);
02113:                            transferable.addGenericElement(Integer
02114:                                    .toString(this .hashCode()));
02115:                            String text = null;
02116:
02117:                            try {
02118:                                text = (String) transferable
02119:                                        .getTransferData(ADTransferable.ADDataFlavor.stringFlavor);
02120:                            } catch (UnsupportedFlavorException e) {
02121:                                throw new AssertionError("Unsupported Flavor "
02122:                                        + e.toString());
02123:                            } catch (IOException e) {
02124:                                throw new AssertionError("IOException "
02125:                                        + e.toString());
02126:                            }
02127:
02128:                            if (text != null && text.length() > 0) {
02129:                                // Put these items on the clip
02130:                                pProduct.setCrossDiagramClipboard(text);
02131:                            }
02132:                        }
02133:                    }
02134:
02135:                    if (selectedObjs != null) {
02136:                        Iterator<TSGraphObject> iter = selectedObjs.iterator();
02137:                        while (iter.hasNext() == true) {
02138:                            TSGraphObject obj = iter.next();
02139:                            TSGraph graph = obj.getOwnerGraph();
02140:                            if (graph != null) {
02141:                                TSGraphManager manager = graph
02142:                                        .getOwnerGraphManager();
02143:                                if (manager instanceof  TSEGraphManager) {
02144:                                    TSEGraphManager tseManager = (TSEGraphManager) manager;
02145:                                    tseManager.setGraphWindow(getGraphWindow());
02146:                                }
02147:                            }
02148:                        }
02149:                    }
02150:
02151:                    if (m_DiagramEngine != null) {
02152:                        m_DiagramEngine.postCopy();
02153:                    }
02154:                }
02155:            }
02156:
02157:            public void paste() {
02158:
02159:                int nDiagramKind = getDiagramKind();
02160:
02161:                if (nDiagramKind != DiagramEnums.DK_SEQUENCE_DIAGRAM) {
02162:                    // The XML fragment that's on the ADProduct has a generic element
02163:                    // which is the hashcode of the diagram.  We use this hashcode to
02164:                    // determine if this is a cross diagram paste or intra diagram paste.
02165:                    IProduct pProduct = getProduct();
02166:
02167:                    if (pProduct != null && m_DiagramEngine != null) {
02168:                        // Clear it out first
02169:                        String clip = pProduct.getCrossDiagramClipboard();
02170:                        if ((clip != null) && (!clip.equals(""))) {
02171:                            Document pDoc = XMLManip.loadXML(clip);
02172:                            if (pDoc != null) {
02173:                                String query = "//DRAGGEDITEMS/GENERICELEMENT[@DESCSTRING=\"";
02174:                                query += Integer.toString(this .hashCode());
02175:                                query += "\"]";
02176:
02177:                                Node root = pDoc.selectSingleNode(query);
02178:                                if (root != null) {
02179:                                    // This adproduct paste information is from us, so just use
02180:                                    // the TS clipboard.
02181:                                    GetHelper.paste(getGraphWindow());
02182:                                } else {
02183:                                    // Use cross diagram paste since last diagram to copy/cut was
02184:                                    // not us.
02185:                                    m_DiagramEngine.beginCrossDiagramPaste();
02186:                                }
02187:                            }
02188:                        }
02189:                    }
02190:                }
02191:            }
02192:
02193:            public void onDeleteSelected() {
02194:                if (!getReadOnly()) {
02195:                    getGraphWindow().deleteSelected();
02196:                }
02197:            }
02198:
02199:            public void duplicate() {
02200:                getGraphWindow().duplicate();
02201:            }
02202:
02203:            public void onClearAll() {
02204:                //getGraphWindow().clearAll(true);
02205:                getGraphWindow().clearAll();
02206:            }
02207:
02208:            /* (non-Javadoc)
02209:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#itemsOnClipboard(boolean)
02210:             */
02211:            public boolean itemsOnClipboard() {
02212:                boolean bItemsOnClipboard = GetHelper
02213:                        .itemsOnClipboard(getGraphWindow());
02214:
02215:                if (!bItemsOnClipboard) {
02216:                    // No items in our clipboard.  Is there a copy String on the product?
02217:                    // Since TS doesn't have copy and paste working between diagrams yet
02218:                    // we also copy the selected elements onto the IProduct clipboard.
02219:                    // If a paste is performed we first check to see if we've got something in the TS clipboard,
02220:                    // if not then check the proxy diagram clip.
02221:                    // Sun Issue 6184447:  Implemented code from C++ to get new diagrams
02222:                    // do enable the Paste menu item properly.
02223:                    IProduct product = getProduct();
02224:                    if (product != null) {
02225:                        String sClipString = product.getCrossDiagramClipboard();
02226:                        if (sClipString.length() > 0) {
02227:                            bItemsOnClipboard = true;
02228:                        }
02229:                    }
02230:                }
02231:
02232:                return bItemsOnClipboard;
02233:            }
02234:
02235:            /**
02236:             * Get the type of this drawing
02237:             *
02238:             * @param pVal [out,retval] Returns the type of this diagram as a DiagramKind
02239:             */
02240:            public int getDiagramKind() {
02241:                return getDiagramKind(getDiagramKind2());
02242:            }
02243:
02244:            /**
02245:             * Get the type of this drawing
02246:             *
02247:             * Returns the type of this diagram as a DiagramKind, given a diagram display name.
02248:             */
02249:            protected int getDiagramKind(String diagramKindDisplayName) {
02250:                Integer fromName = DiagramTypeMap
02251:                        .getDiagramType(diagramKindDisplayName);
02252:                return fromName != null ? fromName.intValue() : 0;
02253:            }
02254:
02255:            /**
02256:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl#Filename()
02257:             */
02258:            public String getFilename() {
02259:                return m_FileName;
02260:            }
02261:
02262:            /**
02263:             * Fit the current diagram to the window.
02264:             */
02265:            public void fitInWindow() {
02266:                this .getActions().onFitInWindow();
02267:            }
02268:
02269:            /**
02270:             * Does this graph have edges?
02271:             */
02272:            public long hasEdges(boolean bHasEdges) {
02273:                long count = this .getGraph().numberOfEdges();
02274:                if (count > 0) {
02275:                    bHasEdges = true;
02276:                } else {
02277:                    bHasEdges = false;
02278:                }
02279:                return count;
02280:            }
02281:
02282:            /**
02283:             * Does this graph have edges, labels or nodes?
02284:             */
02285:            public long hasGraphObjects(boolean bHasGraphObjects) {
02286:                TSEGraph pGraph = getGraph();
02287:
02288:                long count = pGraph != null ? pGraph.numberOfEdges()
02289:                        + pGraph.numberOfLabels() + pGraph.numberOfNodes() : 0;
02290:                bHasGraphObjects = count > 0 ? true : false;
02291:                return count;
02292:            }
02293:
02294:            /**
02295:             * Does this graph have labels?
02296:             */
02297:            public long hasLabels(boolean bHasLabels) {
02298:                long count = this .getGraph().numberOfLabels();
02299:                bHasLabels = count > 0 ? true : false;
02300:                return count;
02301:            }
02302:
02303:            /**
02304:             * Does this graph have nodes?
02305:             */
02306:            public long hasNodes(boolean bHasNodes) {
02307:                long count = this .getGraph().numberOfNodes();
02308:                bHasNodes = count > 0 ? true : false;
02309:                return count;
02310:            }
02311:
02312:            /**
02313:             * Shows the print setup dialog
02314:             */
02315:            public void loadPrintSetupDialog() {
02316:                this .getActions().onPrintSetup();
02317:            }
02318:
02319:            /**
02320:             * Get the name of this drawing.
02321:             */
02322:            @Override
02323:            public String getName() {
02324:                return m_Name;
02325:            }
02326:
02327:            /**
02328:             * Set the name of this drawing.
02329:             */
02330:            @Override
02331:            public void setName(String newVal) {
02332:                //		this.setGraphFileName(newVal);
02333:                // Use the diagram manager to verify the name
02334:                IProxyDiagramManager pDiaMgr = ProxyDiagramManager.instance();
02335:                String validDiaName = "";
02336:                boolean isCorrect = false;
02337:
02338:                // Let the diagram manager verify this name is ok
02339:                validDiaName = newVal; //pDiaMgr.getValidDiagramName(newVal);
02340:                boolean isSame = true;
02341:                boolean fireEvents = true;
02342:                if (m_Name != null && m_Name.length() > 0) {
02343:                    // If the namespace is being changed then fire an event
02344:                    if (validDiaName != null && validDiaName.length() > 0) {
02345:                        if (!m_Name.equals(validDiaName)) {
02346:                            isSame = false;
02347:                        }
02348:                    } else {
02349:                        isSame = false;
02350:                    }
02351:                } else if (validDiaName != null && validDiaName.length() > 0) {
02352:                    isSame = false;
02353:                    fireEvents = false;
02354:                }
02355:
02356:                if (!isSame) {
02357:                    boolean proceed = true;
02358:
02359:                    // Let folks know that the name is being changed.
02360:                    if (getDrawingAreaDispatcher() != null && fireEvents) {
02361:                        proceed = fireDrawingAreaPrePropertyChange(DiagramAreaEnumerations.DAPK_NAME);
02362:                    }
02363:
02364:                    if (proceed) {
02365:                        m_Name = validDiaName;
02366:                        if (fireEvents) {
02367:                            setIsDirty(true);
02368:                            // Let folks know that the name has changed.
02369:                            fireDrawingAreaPropertyChange(DiagramAreaEnumerations.DAPK_NAME);
02370:                        }
02371:
02372:                        setDiagramNodeNameAndOwner();
02373:                    }
02374:                }
02375:            }
02376:
02377:            /**
02378:             * Prints this graph
02379:             *
02380:             * @param bShowDialog Set to true to show the print dialog to the user.
02381:             */
02382:            public void printGraph(boolean showDialog) {
02383:                ADDrawingAreaPrinter helper = getDrawingAreaPrinter();
02384:                if (getDiagramEngine() != null) {
02385:                    getDiagramEngine().prePrint(helper.getPrintSetup());
02386:                }
02387:
02388:                Vector titleVector = new Vector();
02389:                titleVector.add(getName());
02390:
02391:                helper.getPrintSetup().setCaption(titleVector);
02392:                helper.print(showDialog);
02393:
02394:                if (getDiagramEngine() != null) {
02395:                    getDiagramEngine().postPrint(helper.getPrintSetup());
02396:                }
02397:            }
02398:
02399:            /**
02400:             * Zoom the diagram.
02401:             */
02402:            public void zoom(double scaleFactor) {
02403:                String strZoom = (new Double(100. * scaleFactor)).toString();
02404:                this .getActions().onZoom(strZoom);
02405:            }
02406:
02407:            /**
02408:             * Zoom in
02409:             */
02410:            public void zoomIn() {
02411:                this .getActions().onZoomIn();
02412:            }
02413:
02414:            /**
02415:             * Zoom out
02416:             */
02417:            public void zoomOut() {
02418:                this .getActions().onZoomOut();
02419:            }
02420:
02421:            /*
02422:             * Is the overview window open.
02423:             */
02424:            public boolean isOverviewWindowOpen() {
02425:                return this .overviewWindow != null ? this .overviewWindow
02426:                        .isVisible() : false;
02427:            }
02428:
02429:            /*
02430:             *
02431:             */
02432:            public void overviewWindow(boolean showIt) {
02433:                if (isOverviewWindowOpen() != showIt) {
02434:                    onShowOverviewWindow(); // This guy toggles.
02435:                }
02436:            }
02437:
02438:            /**
02439:             * Puts the drawing area into print preview mode
02440:             *
02441:             * @param sTitle The title of the print job - seen on the pages.
02442:             * @param bCanMoveParent Not sure!!
02443:             */
02444:            public void printPreview(String title, boolean canMoveParent) {
02445:                ADDrawingAreaPrinter helper = getDrawingAreaPrinter();
02446:                if (getDiagramEngine() != null) {
02447:                    getDiagramEngine().prePrint(helper.getPrintSetup());
02448:                }
02449:
02450:                Vector titleVector = new Vector();
02451:                titleVector.add(title);
02452:
02453:                helper.getPrintSetup().setCaption(titleVector);
02454:                helper.onPrintPreview();
02455:
02456:                if (getDiagramEngine() != null) {
02457:                    getDiagramEngine().postPrint(helper.getPrintSetup());
02458:                }
02459:            }
02460:
02461:            /**
02462:             * Returns true if the IElement being dropped is valid for this diagram
02463:             *
02464:             * @param pMovingElement [in] The element being dropped
02465:             * @return true if pMovingElement is valid to drop on this diagram
02466:             */
02467:            protected boolean isValidDropElement(IElement pMovingElement) {
02468:                boolean bIsValid = false;
02469:
02470:                try {
02471:                    IDiagramTypesManager pManager = DiagramTypesManager
02472:                            .instance();
02473:                    if (pMovingElement != null && pManager != null) {
02474:                        String sElementType = pMovingElement.getElementType();
02475:                        String sShortDisplayName = pManager
02476:                                .getShortDiagramTypeName(getDiagramKind2());
02477:
02478:                        // Make sure our diagram type is in the list, or ALL is in the list.
02479:                        bIsValid = ValidDropTargets.instance()
02480:                                .isValidDropTarget(sElementType,
02481:                                        sShortDisplayName);
02482:                    }
02483:                } catch (Exception e) {
02484:                    e.printStackTrace();
02485:                    bIsValid = false;
02486:                }
02487:                return bIsValid;
02488:            }
02489:
02490:            /*
02491:             *  (non-Javadoc)
02492:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl#processOnDropElement(org.netbeans.modules.uml.core.metamodel.core.foundation.IElement)
02493:             */
02494:            public IElement processOnDropElement(IElement pElementBeingDropped) {
02495:                if (getDiagramEngine() == null) {
02496:                    return pElementBeingDropped;
02497:                }
02498:                ETPairT<Boolean, IElement> processedElement = m_DiagramEngine
02499:                        .processOnDropElement(pElementBeingDropped);
02500:                IElement pDrawEngineChangedElement = processedElement
02501:                        .getParamTwo();
02502:                boolean bCancelThisElement = processedElement.getParamOne()
02503:                        .booleanValue();
02504:
02505:                // If we aren't canceled and the diagram engine didn't change the metatype being created
02506:                // then use the type passed into us.
02507:                if (bCancelThisElement == false
02508:                        && pDrawEngineChangedElement == null) {
02509:                    pDrawEngineChangedElement = pElementBeingDropped;
02510:                }
02511:                // This is a fix for bug#5110404 [should not allow dragging a package to a sequence diagram]
02512:                //Commenting out to fix bug#6283146
02513:                /*else if (bCancelThisElement == true)
02514:                {
02515:                pElementBeingDropped = null;
02516:                }*/
02517:
02518:                // Now make sure that the projecttreeengine.etc file says that this diagram is valid, the exception
02519:                // are attributes and operations which are allowed to be dropped on other classes
02520:                IFeature pFeature = pDrawEngineChangedElement instanceof  IFeature ? (IFeature) pDrawEngineChangedElement
02521:                        : null;
02522:                boolean validDropElement = isValidDropElement(pDrawEngineChangedElement);
02523:
02524:                if ((bCancelThisElement == true)
02525:                        || (pFeature == null
02526:                                && pDrawEngineChangedElement != null && validDropElement == false)) {
02527:                    String sElementType;
02528:                    String sMessageString;
02529:
02530:                    if (pDrawEngineChangedElement != null) {
02531:                        sElementType = pDrawEngineChangedElement
02532:                                .getElementType();
02533:                    } else {
02534:                        sElementType = pElementBeingDropped.getElementType();
02535:                    }
02536:                    if (!validDropElement) {
02537:                        sMessageString = sElementType.concat(" "
02538:                                + RESOURCE_BUNDLE.getString("DROP_CANCELED"));
02539:                        sendMessage(MsgCoreConstants.MT_INFO, sMessageString);
02540:                    }
02541:                    pDrawEngineChangedElement = null;
02542:                    pElementBeingDropped = null;
02543:                }
02544:                return pDrawEngineChangedElement != null ? pDrawEngineChangedElement
02545:                        : pElementBeingDropped;
02546:            }
02547:
02548:            public void switchToDefaultState() {
02549:                getResources().setDefault();
02550:                setGraphState(getGraphWindow().getDefaultTool());
02551:            }
02552:
02553:            /**
02554:             * This method initializes the window that displays and manipulates the graph.
02555:             */
02556:            private void initGraphWindow(ADGraphWindow newGraphWindow) {
02557:                if (this .m_GraphWindow != null) {
02558:                    return; // Only do this once.
02559:                }
02560:                this .m_GraphWindow = newGraphWindow;
02561:
02562:                // register a graph change listener with the window which
02563:                // is responsible for setting the enabled state of all buttons
02564:                trackBarModifyListener = new MyGraphChangeListener();
02565:                //adding listeners - JM
02566:                TSEGraphManager graphManager = getGraphManager();
02567:                TSEventManager graphEventManager = graphManager
02568:                        .getEventManager();
02569:                graphEventManager.addGraphChangeListener(graphManager,
02570:                        getActions());
02571:                graphEventManager.addGraphChangeListener(graphManager,
02572:                        trackBarModifyListener,
02573:                        TSGraphChangeEvent.ANY_DISCARDED);
02574:                if (graphEventManager instanceof  TSEEventManager) {
02575:                    ((TSEEventManager) graphEventManager)
02576:                            .addSelectionChangeListener(graphManager,
02577:                                    getActions());
02578:                    ((TSEEventManager) graphEventManager)
02579:                            .addViewportChangeListener(getGraphWindow(),
02580:                                    getActions());
02581:                }
02582:
02583:                // specify the default state the graph window restores on reset
02584:                // operations
02585:                try {
02586:                    ADDrawingAreaSelectState tool = new ADDrawingAreaSelectState();
02587:                    tool.setReconnectEdgeTool(new ADReconnectEdgeState(tool));
02588:                    getGraphWindow().setDefaultTool(tool);
02589:                } catch (Exception e) {
02590:                }
02591:
02592:                this .m_GraphWindow.setupETDefaultDrawingPreferences();
02593:
02594:                // see if the user has specified the undo limit, and if so
02595:                // set it on the graph window
02596:                try {
02597:                    int limit = Integer.parseInt(this .getResources()
02598:                            .getStringResource("editor.undo.limit"));
02599:                    getGraphWindow().setUndoLimit(limit);
02600:                } catch (Exception e) {
02601:                    ETSystem.out.println("Unable to set requested undo limit.");
02602:                }
02603:
02604:                this .addGraphWindow(getGraphWindow());
02605:                addKeyListener(this );
02606:
02607:                // add a mouse listener to the canvas that requests focus for the root pane whenever it is clicked on.
02608:                mouseHandler = new MouseHandler(this );
02609:                getGraphWindow().getCanvas().addMouseListener(mouseHandler);
02610:
02611:                //add a key listener too - this will be used to edit the name of the dropped classes
02612:                keyHandler = new KeyHandler();
02613:                getGraphWindow().addKeyListener(keyHandler);
02614:                getGraphWindow().getInputMap().put(
02615:                        KeyStroke.getKeyStroke(KeyEvent.VK_A,
02616:                                KeyEvent.SHIFT_DOWN_MASK), "Edit");
02617:                getGraphWindow().getActionMap().put("Edit", new TestAction());
02618:
02619:                // now, when the canvas receives the focus, transfer it to the root pane.
02620:                focusAdapter = new FocusAdapter() {
02621:                    @Override
02622:                    public void focusGained(FocusEvent event) {
02623:                        requestFocus();
02624:                    }
02625:                };
02626:                getGraphWindow().getCanvas().addFocusListener(focusAdapter);
02627:
02628:                //      getGraphWindow().setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
02629:                trackBarChangeListener = new ViewportChangeListener();
02630:                ((TSEEventManager) graphEventManager)
02631:                        .addViewportChangeListener(getGraphWindow(),
02632:                                trackBarChangeListener);
02633:            }
02634:
02635:            public void showNotImplementedMessage() {
02636:                JOptionPane.showMessageDialog(this , this .getResources()
02637:                        .getStringResource("dialog.notImplemented.message"),
02638:                        this .getResources().getStringResource(
02639:                                "dialog.notImplemented.title"),
02640:                        JOptionPane.INFORMATION_MESSAGE);
02641:            }
02642:
02643:            private void showErrorMessage(String message) {
02644:                JOptionPane.showMessageDialog(this , message,
02645:                        this .getResources().getStringResource(
02646:                                "dialog.error.title"),
02647:                        JOptionPane.ERROR_MESSAGE);
02648:            }
02649:
02650:            /**
02651:             * Reload the model element based on the ids
02652:             *
02653:             * @param sModelElementID [in] The XMIID of the model element to reload
02654:             * @param sTopLevelID [in] The XMIID of the toplevel model element where sModelElementID can be found.
02655:             * @param pModelElement [out] The found model element
02656:             * @param pFoundProject [out] The toplevel project this model element is found in.
02657:             */
02658:            private IElement reloadModelElement(String sModelElementID,
02659:                    IProject pFoundProject) {
02660:                IApplication app = ProductHelper.getApplication();
02661:                if (app != null) {
02662:                    IElementLocator locator = new ElementLocator();
02663:                    if (pFoundProject != null) {
02664:                        return locator.findElementByID(pFoundProject,
02665:                                sModelElementID);
02666:                    }
02667:                }
02668:                return null;
02669:            }
02670:
02671:            private IProject reloadModelElement(String sTopLevelID) {
02672:                IApplication app = ProductHelper.getApplication();
02673:                return app != null ? app.getProjectByID(sTopLevelID) : null;
02674:            }
02675:
02676:            /**
02677:             * Populate associated diagrams and elements list
02678:             *
02679:             * @param pArchive [in] The archive (etlp file) that contains the presentation element information.
02680:             */
02681:            private void populateAssociatedDiagramsAndElementsList(
02682:                    IProductArchive pArchive) {
02683:                ETList<IProductArchiveElement> associatedDiagrams = pArchive
02684:                        .getAllTableEntries(IProductArchiveDefinitions.ASSOCIATED_DIAGRAMS_STRING);
02685:                ETList<IProductArchiveElement> associatedElements = pArchive
02686:                        .getAllTableEntries(IProductArchiveDefinitions.ASSOCIATED_ELEMENTS_STRING);
02687:
02688:                // Populate the associated diagrams
02689:                if (associatedDiagrams != null) {
02690:                    int count = associatedDiagrams.size();
02691:                    for (int i = 0; i < count; i++) {
02692:                        IProductArchiveElement pEle = associatedDiagrams.get(i);
02693:                        String xmiid = pEle.getID();
02694:                        if (xmiid != null && xmiid.length() > 0) {
02695:                            addAssociatedDiagram(xmiid);
02696:                        }
02697:                    }
02698:                }
02699:
02700:                // Populate the associated elements
02701:                if (associatedElements != null) {
02702:                    int count = associatedElements.size();
02703:                    for (int i = 0; i < count; i++) {
02704:                        IProductArchiveElement pEle = associatedElements.get(i);
02705:                        String xmiid = pEle.getID();
02706:                        String sTopLevelXMIID = pEle
02707:                                .getAttributeString(IProductArchiveDefinitions.TOPLEVELID_STRING);
02708:                        if (xmiid != null && xmiid.length() > 0
02709:                                && sTopLevelXMIID != null
02710:                                && sTopLevelXMIID.length() > 0) {
02711:                            addAssociatedElement(sTopLevelXMIID, xmiid);
02712:                        }
02713:                    }
02714:                }
02715:            }
02716:
02717:            /**
02718:             * Reloads the diagram data from the product archive
02719:             *
02720:             * @param pArchive [in] The archive (etlp file) that contains the presentation element information.
02721:             */
02722:            private void readFromArchive(IProductArchive pArchive) {
02723:                // Block the delayed actions
02724:                //DelayedActionBlocker blocker = new DelayedActionBlocker();
02725:                if (getGraphWindow() != null) {
02726:                    ///////////////////////////////////////////////////////////
02727:                    // We loaded ok, lets get the diagram information
02728:                    ///////////////////////////////////////////////////////////
02729:                    IProductArchiveElement pArchEle = pArchive
02730:                            .getElement(IProductArchiveDefinitions.DIAGRAMINFO_STRING);
02731:                    if (pArchEle != null) {
02732:                        // Get the diagram attributes
02733:                        long diaKind = pArchEle
02734:                                .getAttributeLong(IProductArchiveDefinitions.DRAWINGKIND_STRING);
02735:                        String sDiaKind = pArchEle
02736:                                .getAttributeString(IProductArchiveDefinitions.DRAWINGKIND2_STRING);
02737:                        m_DiagramXmiid = pArchEle
02738:                                .getAttributeString(IProductArchiveDefinitions.DIAGRAM_XMIID);
02739:                        String sMEID = pArchEle
02740:                                .getAttributeString(IProductArchiveDefinitions.NAMESPACE_MEID);
02741:                        String sTopLevelID = pArchEle
02742:                                .getAttributeString(IProductArchiveDefinitions.NAMESPACE_TOPLEVELID);
02743:                        m_Name = pArchEle
02744:                                .getAttributeString(IProductArchiveDefinitions.DIAGRAMNAME_STRING);
02745:                        m_Alias = pArchEle
02746:                                .getAttributeString(IProductArchiveDefinitions.DIAGRAMALIAS_STRING);
02747:                        m_Documentation = pArchEle
02748:                                .getAttributeString(IProductArchiveDefinitions.DIAGRAMNAME_DOCS);
02749:                        m_nZoomLevelFromArchive = pArchEle
02750:                                .getAttributeDouble(IProductArchiveDefinitions.DIAGRAM_ZOOM);
02751:                        double nPageCenterX = pArchEle
02752:                                .getAttributeDouble(IProductArchiveDefinitions.DIAGRAM_XPOS);
02753:                        double nPageCenterY = pArchEle
02754:                                .getAttributeDouble(IProductArchiveDefinitions.DIAGRAM_YPOS);
02755:                        m_DiagramSavedWithAliasOn = pArchEle
02756:                                .getAttributeBool(IProductArchiveDefinitions.LAST_SHOWALIAS_STATE);
02757:                        //m_LoadedDiagramVersion = pArchEle.getAttributeDouble(IProductArchiveDefinitions.DIAGRAMVERSION_STRING);
02758:                        boolean diaIsStub = pArchEle
02759:                                .getAttributeBool(IProductArchiveDefinitions.DIAGRAM_ISSTUB_STRING);
02760:
02761:                        if (m_nZoomLevelFromArchive == 0.0) {
02762:                            m_nZoomLevelFromArchive = 1.0;
02763:                        }
02764:
02765:                        m_CenterFromArchive = new Point((int) nPageCenterX,
02766:                                (int) nPageCenterY);
02767:
02768:                        // Set the diagram Kind, using the string first so we can eventually get rid of the
02769:                        // enumeration
02770:                        if (sDiaKind != null && sDiaKind.length() > 0) {
02771:                            setDiagramKind2(sDiaKind);
02772:                        } else {
02773:                            sDiaKind = CachedDiagrams
02774:                                    .getNewDiagramType((int) diaKind);
02775:                            setDiagramKind2(sDiaKind);
02776:                        }
02777:
02778:                        // Reconnect to the model element
02779:                        if (sMEID != null && sMEID.length() > 0
02780:                                && sTopLevelID != null
02781:                                && sTopLevelID.length() > 0) {
02782:                            IProject pFoundProj = reloadModelElement(sTopLevelID);
02783:                            IElement pFoundModelEle = reloadModelElement(sMEID,
02784:                                    pFoundProj);
02785:                            if (pFoundModelEle instanceof  INamespace) {
02786:                                setNamespace((INamespace) pFoundModelEle);
02787:                            } else if (pFoundProj != null) {
02788:                                setNamespace(pFoundProj);
02789:                            } else {
02790:                                //throw and exception of InvalidArguments
02791:                            }
02792:                        } else {
02793:                            //throw and exception of InvalidArguments
02794:                        }
02795:
02796:                        // Load the associated diagrams and model elements
02797:                        populateAssociatedDiagramsAndElementsList(pArchive);
02798:
02799:                        if (!diaIsStub) {
02800:                            // We have a real diagram, not one created by the CDFS stub process
02801:                            if (m_DiagramEngine != null) {
02802:                                m_DiagramEngine.readFromArchive(pArchive,
02803:                                        pArchEle);
02804:                            }
02805:
02806:                            // Get the diagram that will be set on each of the objects
02807:                            IDiagram pDia = getDiagram();
02808:
02809:                            // Now load the objects into the product archive.  The m_ViewsReadWriteFromETLFile list was
02810:                            // created during the read process of the etl file.
02811:                            if (m_ViewsReadWriteFromETLFile != null) {
02812:                                int count = m_ViewsReadWriteFromETLFile.size();
02813:                                for (int i = 0; i < count; i++) {
02814:                                    IETGraphObject obj = (IETGraphObject) m_ViewsReadWriteFromETLFile
02815:                                            .get(i);
02816:
02817:                                    // Set the diagram and load from the archive
02818:                                    obj.setDiagram(pDia);
02819:                                    obj.load(pArchive);
02820:                                }
02821:
02822:                                // Notification of post load.  This is where presentation elements and their
02823:                                // owners are reattached
02824:                                for (int i = 0; i < count; i++) {
02825:                                    IETGraphObject obj = (IETGraphObject) m_ViewsReadWriteFromETLFile
02826:                                            .get(i);
02827:
02828:                                    obj.postLoad();
02829:                                }
02830:                            }
02831:
02832:                            // Now validate all the link ends, node draw engines, and the
02833:                            // labels on the links
02834:                            // 91395 Do we really need to correct diagram (get rid of bogus edges etc)
02835:                            // without user's knowledge? Shouldn't we just display it in a state when
02836:                            // user saved it?
02837:                            // The answer is yes we do.  See issue 91395.
02838:                            boolean temp = postLoadVerification();
02839:                            //Jyothi: #91395 Inform the user that the diagram has changed.
02840:                            if (temp) {
02841:                                SwingUtilities.invokeLater(new Runnable() {
02842:
02843:                                    public void run() {
02844:                                        System.err
02845:                                                .println("The diagram is being modified based on the changes in the model");
02846:                                        NotifyDescriptor d = new NotifyDescriptor.Message(
02847:                                                "The diagram is being modified based on the changes in the model",
02848:                                                NotifyDescriptor.INFORMATION_MESSAGE);
02849:                                        DialogDisplayer.getDefault().notify(d);
02850:                                    }
02851:                                });
02852:                            }
02853:
02854:                            // Clear our load list
02855:                            m_ViewsReadWriteFromETLFile.clear();
02856:                        } else {
02857:                            if (m_ReadOnly) {
02858:                                // See if the user wants to checkout by sending out a predirty state change event
02859:                                checkForSCCCheckout();
02860:                            }
02861:                            if (m_ReadOnly) {
02862:                                if (!m_AbortDiagramLoad) {
02863:                                    // We have a readonly diagram - we can't open this stub.  Tell the user
02864:                                }
02865:                            } else {
02866:                                // Handle the stub diagram
02867:                                initializeNewDiagram();
02868:                                // Handle any CDFS that needs to happen
02869:                                handleDelayedCDFS(pArchive);
02870:                            }
02871:                        }
02872:                    }
02873:                }
02874:            }
02875:
02876:            /**
02877:             * @param pArchive
02878:             */
02879:            private void handleDelayedCDFS(IProductArchive archive) {
02880:                ETList<IProductArchiveElement> allElements;
02881:                ETList<IElement> elements = null;
02882:                long count = 0;
02883:                ElementReloader reloader = new ElementReloader();
02884:
02885:                allElements = archive
02886:                        .getAllTableEntries(IProductArchiveDefinitions.DIAGRAM_CDFS_STRING);
02887:
02888:                for (Iterator iter = allElements.iterator(); iter.hasNext();) {
02889:                    IProductArchiveElement foundElement = (IProductArchiveElement) iter
02890:                            .next();
02891:
02892:                    String sXMIID = foundElement.getID();
02893:                    String sTopLevelXMIID = foundElement
02894:                            .getAttributeString(IProductArchiveDefinitions.TOPLEVELID_STRING);
02895:                    boolean bIgnoreThisElementForCDFS = foundElement
02896:                            .getAttributeBool(IProductArchiveDefinitions.DIAGRAM_IGNOREFORCDFS_STRING);
02897:                    if ((sXMIID.length() > 0) && (sTopLevelXMIID.length() > 0)
02898:                            && (!bIgnoreThisElementForCDFS)) {
02899:                        IElement tempElement = reloader.getElement(
02900:                                sTopLevelXMIID, sXMIID);
02901:                        if (tempElement != null) {
02902:                            if (null == elements) {
02903:                                elements = new ETArrayList<IElement>();
02904:                            }
02905:                            elements.add(tempElement);
02906:                        }
02907:                    }
02908:                }
02909:
02910:                // If we've got a list then CDFS the list.  Go ahead and post the action
02911:                // if if there aren't any elements so we'll save on opening in the event
02912:                // Fix J633:  For some reason in the java code elements get created from the namespace
02913:                //            that were not being created in the C++ code.   To fix this issue, we
02914:                //            assume that if there are no elements from the stub diagram then
02915:                //            we don't need to CDFS.
02916:                if (elements != null) {
02917:                    ISimpleElementsAction action = new CDFSAction(this );
02918:                    assert (action != null);
02919:                    if (action != null) {
02920:                        if (elements != null) {
02921:                            action.setElements(elements);
02922:                        }
02923:
02924:                        DelayedExecutor exe = new DelayedExecutor(this , action);
02925:                        ETGraphManager mgr = (ETGraphManager) this 
02926:                                .getGraphManager();
02927:                        SwingUtilities.invokeLater(exe);
02928:                    }
02929:                } else {
02930:                    // Fix J936:  Since we do not call the delayed action above,
02931:                    //            we need to save the diagram here.
02932:                    setIsDirty(true);
02933:                    // why implicit save here? How would user discard the changes later?
02934:                    //         save();
02935:                }
02936:            }
02937:
02938:            public class DelayedExecutor implements  Runnable {
02939:
02940:                IDrawingAreaControl m_Control = null;
02941:                ISimpleElementsAction m_Action = null;
02942:
02943:                public DelayedExecutor(IDrawingAreaControl ctrl,
02944:                        ISimpleElementsAction action) {
02945:                    m_Control = ctrl;
02946:                    m_Action = action;
02947:                }
02948:
02949:                public void run() {
02950:                    if ((m_Action != null) && (m_Control != null)) {
02951:                        m_Action.execute(m_Control);
02952:                    }
02953:                }
02954:            }
02955:
02956:            /**
02957:             *
02958:             */
02959:            private void checkForSCCCheckout() {
02960:                // TODO Auto-generated method stub
02961:            }
02962:
02963:            /**
02964:             *
02965:             */
02966:            private boolean postLoadVerification() {
02967:                boolean modifiedDiagram = false;
02968:
02969:                ETList<IETGraphObject> etGraphObjects = getAllItems6();
02970:
02971:                int count = etGraphObjects != null ? etGraphObjects.getCount()
02972:                        : 0;
02973:
02974:                boolean deletedPEFound = false;
02975:                boolean peRemoved = false;
02976:                boolean drawEnginesInvalid = false;
02977:
02978:                for (int index = 0; index < count; index++) {
02979:                    IETGraphObject etGraphObject = etGraphObjects.item(index);
02980:                    IPresentationElement presentationElement = TypeConversions
02981:                            .getPresentationElement(etGraphObject);
02982:
02983:                    IEdgePresentation edgePresentation = presentationElement instanceof  IEdgePresentation ? (IEdgePresentation) presentationElement
02984:                            : null;
02985:                    INodePresentation nodePresentation = presentationElement instanceof  INodePresentation ? (INodePresentation) presentationElement
02986:                            : null;
02987:
02988:                    if (edgePresentation != null
02989:                            && !edgePresentation.validateLinkEnds()
02990:                            && !edgePresentation.reconnectLinkToValidNodes()) {
02991:                        // Delete the bogus edge
02992:                        postDeletePresentationElement(presentationElement);
02993:                        peRemoved = true;
02994:                    } else if (nodePresentation != null) {
02995:                        IETGraphObject nodeETGraphObject = etGraphObject;
02996:
02997:                        IGraphObjectValidation graphObjectValidation = new GraphObjectValidation();
02998:
02999:                        if (graphObjectValidation != null) {
03000:                            graphObjectValidation
03001:                                    .addValidationKind(IDiagramValidateKind.DVK_VALIDATE_DRAWENGINE);
03002:
03003:                            nodeETGraphObject.validate(graphObjectValidation);
03004:
03005:                            int nResult = graphObjectValidation
03006:                                    .getValidationResult(IDiagramValidateKind.DVK_VALIDATE_DRAWENGINE);
03007:
03008:                            if (nResult == IDiagramValidateResult.DVR_INVALID) {
03009:                                resetDrawEngine2(nodeETGraphObject);
03010:                                drawEnginesInvalid = true;
03011:                            }
03012:                        }
03013:                    } else if (presentationElement == null) {
03014:                        TSEEdge edge = TypeConversions
03015:                                .getOwnerEdge(etGraphObject);
03016:                        if (edge != null) {
03017:                            TSNode sourceNode = edge.getSourceNode();
03018:                            TSNode targetNode = edge.getTargetNode();
03019:
03020:                            IPresentationElement sourceElement = TypeConversions
03021:                                    .getPresentationElement(sourceNode);
03022:                            IPresentationElement targetElement = TypeConversions
03023:                                    .getPresentationElement(targetNode);
03024:
03025:                            if (sourceElement != null && targetElement != null) {
03026:                                // TODO I don't think this logic is in here or goes here or something
03027:                                ISimpleElementsAction action = new SimpleElementsAction();
03028:
03029:                                if (action != null) {
03030:                                    action.add(sourceElement);
03031:                                    action.add(targetElement);
03032:                                    action
03033:                                            .setKind(DiagramAreaEnumerations.SEAK_DISCOVER_RELATIONSHIPS);
03034:                                    postDelayedAction(action);
03035:                                }
03036:                            }
03037:                        }
03038:                        if (etGraphObject != null) {
03039:                            ETList<IETGraphObject> deleteThese = new ETArrayList<IETGraphObject>();
03040:                            deleteThese.add(etGraphObject);
03041:
03042:                            removeGraphObjects(deleteThese, false, false);
03043:                            modifiedDiagram = true;
03044:                        }
03045:                    }
03046:
03047:                    if (peRemoved == false && etGraphObject != null) {
03048:                        //            boolean wasDeleted = etGraphObject.getWasModelElementDeleted();
03049:                        if (etGraphObject.getWasModelElementDeleted()) {
03050:                            ETList<IETGraphObject> deleteThese = new ETArrayList<IETGraphObject>();
03051:                            deleteThese.add(etGraphObject);
03052:
03053:                            removeGraphObjects(deleteThese, false, false);
03054:                            modifiedDiagram = true;
03055:
03056:                            /*
03057:                            TSEEdge tseEdge = TypeConversions.getOwnerEdge(etGraphObject);
03058:                            TSENode tseNode = TypeConversions.getOwnerNode(etGraphObject);
03059:                            if(tseEdge != null) {
03060:                            postDeletePresentationElement(tseEdge);
03061:                            deletedPEFound = true;
03062:                            }
03063:                            else if (tseNode != null) {
03064:                            postDeletePresentationElement(tseNode);
03065:                            deletedPEFound = true;
03066:                            }
03067:                             */
03068:                        } else {
03069:                            IDrawEngine drawEngine = etGraphObject.getEngine();
03070:                            if (drawEngine != null) {
03071:                                ILabelManager labelManager = drawEngine
03072:                                        .getLabelManager();
03073:                                if (labelManager != null) {
03074:                                    labelManager.resetLabelsText();
03075:                                }
03076:                            }
03077:                        }
03078:                    }
03079:                }
03080:
03081:                etGraphObjects = null;
03082:
03083:                if (deletedPEFound) {
03084:                    //			SendMessage(MT_DEBUG, IDS_FOUNDDELETEDPES);
03085:                    setIsDirty(true);
03086:                }
03087:                if (peRemoved) {
03088:                    //			SendMessage(MT_DEBUG,IDS_PRESENTATIONELEMENTSWEREREMOVED);
03089:                    setIsDirty(true);
03090:                }
03091:
03092:                if (drawEnginesInvalid) {
03093:                    //			SendMessage(MT_DEBUG,IDS_DRAWENGINESREST);
03094:                    setIsDirty(true);
03095:                }
03096:                return modifiedDiagram;
03097:            }
03098:
03099:            /**
03100:             * Adds an associated diagram to our list
03101:             *
03102:             * @param sDiagramXMIID [in] The xmiid of the diagram to associate to.
03103:             */
03104:            public void addAssociatedDiagram(String sDiagramXMIID) {
03105:                if (!m_ReadOnly && sDiagramXMIID != null
03106:                        && sDiagramXMIID.length() > 0) {
03107:                    if (!sDiagramXMIID.equals(m_DiagramXmiid)) {
03108:                        boolean found = false;
03109:                        if (m_AssociatedDiagrams != null) {
03110:                            int count = m_AssociatedDiagrams.size();
03111:                            for (int i = 0; i < count; i++) {
03112:                                String str = (String) m_AssociatedDiagrams
03113:                                        .get(i);
03114:                                if (str.equals(sDiagramXMIID)) {
03115:                                    found = true;
03116:                                    break;
03117:                                }
03118:                            }
03119:                        } else {
03120:                            m_AssociatedDiagrams = new Vector();
03121:                        }
03122:                        if (!found) {
03123:                            m_AssociatedDiagrams.add(sDiagramXMIID);
03124:                            if (!IOSemaphore.isIOHappenning()) {
03125:                                setIsDirty(true);
03126:                            }
03127:                        }
03128:                    }
03129:                }
03130:            }
03131:
03132:            /**
03133:             * Adds an associated diagram to our list
03134:             *
03135:             * @param pDiagram [in] The diagram we should associate to
03136:             */
03137:            public void addAssociatedDiagram2(IProxyDiagram pDiagram) {
03138:                if (pDiagram != null) {
03139:                    String xmiid = pDiagram.getXMIID();
03140:                    if (!m_ReadOnly && xmiid != null && xmiid.length() > 0) {
03141:                        addAssociatedDiagram(xmiid);
03142:                    }
03143:                }
03144:            }
03145:
03146:            /**
03147:             * Adds an associated element to our list
03148:             *
03149:             * @param sTopLevelElementXMIID [in] The elements toplevel id
03150:             * @param sModelElementXMIID [in] The element we should associate to
03151:             */
03152:            public void addAssociatedElement(String xmiid, String meID) {
03153:                if (!m_ReadOnly && xmiid != null && xmiid.length() > 0
03154:                        && meID != null && meID.length() > 0) {
03155:                    Object obj = m_AssociatedElements.get(xmiid);
03156:                    if (obj == null) {
03157:                        Vector meidCol = new Vector();
03158:                        meidCol.add(meID);
03159:                        m_AssociatedElements.put(xmiid, meidCol);
03160:                        if (!IOSemaphore.isIOHappenning()) {
03161:                            setIsDirty(true);
03162:                        }
03163:                    } else {
03164:                        Vector meidCol = (Vector) obj;
03165:
03166:                        //see if this element already exists
03167:                        boolean foundEle = false;
03168:                        int count = meidCol.size();
03169:                        for (int i = 0; i < count; i++) {
03170:                            String str = (String) meidCol.get(i);
03171:                            if (str != null && str.equals(meID)) {
03172:                                foundEle = true;
03173:                                break;
03174:                            }
03175:                        }
03176:
03177:                        if (!foundEle) {
03178:                            meidCol.add(meID);
03179:                            if (!IOSemaphore.isIOHappenning()) {
03180:                                setIsDirty(true);
03181:                            }
03182:                        }
03183:                    }
03184:                }
03185:            }
03186:
03187:            /**
03188:             * Adds an associated element to our list
03189:             *
03190:             * @param pElement [in] The element we should associate to
03191:             */
03192:            public void addAssociatedElement2(IElement pElement) {
03193:                if (!m_ReadOnly && pElement != null) {
03194:                    String topId = pElement.getTopLevelId();
03195:                    String xmiid = pElement.getXMIID();
03196:                    if (topId != null && topId.length() > 0 && xmiid != null
03197:                            && xmiid.length() > 0) {
03198:                        addAssociatedElement(topId, xmiid);
03199:                    }
03200:                }
03201:            }
03202:
03203:            /* (non-Javadoc)
03204:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#addPresentationElementToTrackBar(com.embarcadero.describe.foundation.IPresentationElement)
03205:             */
03206:            public void addPresentationElementToTrackBar(
03207:                    IPresentationElement pElement) {
03208:                // Make sure the graph window is valid, there is a lot of posting going
03209:                // on in the Webreport, (Kevin)
03210:                if (getTrackBar() != null && this .getGraphWindow() != null) {
03211:                    getTrackBar().addPresentationElement(pElement);
03212:                }
03213:            }
03214:
03215:            /**
03216:             * Adds an item to the ETL read/write list.
03217:             *
03218:             * @param pItem [in] The graph object to add to our list of items that need to be serialized.
03219:             */
03220:            public void addReadWriteItem(IETGraphObject pItem) {
03221:                // We need to make sure that the object views all are loaded from the IProductArchive.  Hidden and
03222:                // folded nodes aren't in our list of graph objects on the anchor view.  We have to call buildFoldGraphList(true)
03223:                // buildNestedGraphList(true) and for each graph get the .hideGraph property.  Them combine all those
03224:                // objects for a list of every node.  What a pain!  Rather then that we keep track of what TS has serialized
03225:                // in and use that to reload our objects.
03226:                if (pItem != null) {
03227:                    boolean found = false;
03228:                    if (m_ViewsReadWriteFromETLFile != null) {
03229:                        int count = m_ViewsReadWriteFromETLFile.size();
03230:                        for (int i = 0; i < count; i++) {
03231:                            IETGraphObject obj = (IETGraphObject) m_ViewsReadWriteFromETLFile
03232:                                    .get(i);
03233:                            if (obj.equals(pItem)) {
03234:                                found = true;
03235:                                break;
03236:                            }
03237:                        }
03238:                    } else {
03239:                        m_ViewsReadWriteFromETLFile = new Vector();
03240:                    }
03241:                    if (!found) {
03242:                        m_ViewsReadWriteFromETLFile.add(pItem);
03243:                    }
03244:                }
03245:            }
03246:
03247:            /**
03248:             * Begins the editing context so if there's a name collision we can handle it.
03249:             *
03250:             * @param pCompartment [in] The compartment being edited
03251:             */
03252:            public void beginEditContext(ICompartment pCompartment) {
03253:                if (m_CollisionHandler != null
03254:                        && m_NameCollisionListener != null) {
03255:                    m_NameCollisionListener.setEnabled(true);
03256:                    m_CollisionHandler.setCompartment(pCompartment);
03257:                }
03258:            }
03259:
03260:            /* (non-Javadoc)
03261:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#beginOLEDrag(com.tomsawyer.graph.TSGraphObject)
03262:             */
03263:            public void beginOLEDrag(TSGraphObject graphObject) {
03264:                // TODO Auto-generated method stub
03265:            }
03266:
03267:            /* (non-Javadoc)
03268:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#centerPresentationElement(com.embarcadero.describe.foundation.IPresentationElement, boolean, boolean)
03269:             */
03270:            public void centerPresentationElement(
03271:                    IPresentationElement pPresentationElement,
03272:                    boolean bSelectIt, boolean bDeselectAllOthers) {
03273:                if (null == getGraphWindow()) {
03274:                    return;
03275:                }
03276:
03277:                IETGraphObject tsObject = TypeConversions
03278:                        .getETGraphObject(pPresentationElement);
03279:                if (tsObject != null) {
03280:                    if (bDeselectAllOthers) {
03281:                        getGraphWindow().deselectAll(false);
03282:                    }
03283:
03284:                    if (bSelectIt) {
03285:                        getGraphWindow().selectObject(tsObject.getObject(),
03286:                                true);
03287:                    }
03288:
03289:                    TSConstPoint goToPoint = null;
03290:                    if (tsObject.isNode() == true) {
03291:
03292:                        if (tsObject instanceof  ETNode) {
03293:                            ETNode node = (ETNode) tsObject;
03294:                            goToPoint = node.getCenter();
03295:                        }
03296:                    } else if (tsObject.isEdge() == true) {
03297:                        if (tsObject instanceof  ETNode) {
03298:                            ETEdge edge = (ETEdge) tsObject;
03299:                            goToPoint = edge.getSourcePoint();
03300:                        }
03301:                    }
03302:
03303:                    if (goToPoint != null) {
03304:                        getGraphWindow().centerPointInWindow(goToPoint, true);
03305:                    }
03306:                }
03307:            }
03308:
03309:            /**
03310:             * Centers and,optionally, selects the following presentation element on the drawing area
03311:             *
03312:             * @param sXMIID [in] The xmiid of the presentation element to center
03313:             * @param bSelectIt [in] true if we should select it.
03314:             * @param bDeselectAllOthers [in] true if we should deselect all others.
03315:             */
03316:            public void centerPresentationElement2(String sXMIID,
03317:                    boolean bSelectIt, boolean bDeselectAllOthers) {
03318:                IPresentationElement pe = this .findPresentationElement(sXMIID);
03319:                if (pe != null) {
03320:                    centerPresentationElement(pe, bSelectIt, bDeselectAllOthers);
03321:                }
03322:            }
03323:
03324:            //JM: wrote this method to select presentation object in the graph
03325:            public void selectPresentationElement(
03326:                    IPresentationElement pPresentationElement,
03327:                    boolean bSelectIt, boolean bDeselectAllOthers) {
03328:
03329:                if (null == getGraphWindow()) {
03330:                    return;
03331:                }
03332:                IETGraphObject tsObject = TypeConversions
03333:                        .getETGraphObject(pPresentationElement);
03334:                if (tsObject != null) {
03335:                    if (bDeselectAllOthers) {
03336:                        getGraphWindow().deselectAll(false);
03337:                    }
03338:                    if (bSelectIt) {
03339:                        getGraphWindow().selectObject(tsObject.getObject(),
03340:                                true);
03341:                        //tell the world that selection has changed
03342:                        ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
03343:                                : null;
03344:                        if (etGraph != null) {
03345:                            this .fireSelectEvent(etGraph.getSelectedObjects(
03346:                                    false, false));
03347:                            this .refresh(true);
03348:                        }
03349:                    }
03350:                }
03351:            }
03352:
03353:            /* (non-Javadoc)
03354:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#changeEdgeDescription(java.lang.String)
03355:             */
03356:            public void changeEdgeDescription(String edgeUI) {
03357:                splitEdgeViewDescription(edgeUI);
03358:
03359:                ETGenericEdgeUI ui = null;
03360:                String type = edgeUI;
03361:
03362:                TSEGraphWindow graph = getGraphWindow();
03363:
03364:                if (graph != null) {
03365:                    IPresentationTypesMgr mgr = getPresentationTypesMgr();
03366:                    PresentationTypeDetails details = mgr.getInitStringDetails(
03367:                            edgeUI, getDiagramKind());
03368:
03369:                    int delimiter = edgeUI.indexOf(' ');
03370:                    String edgeUIClass = edgeUI.substring(0, delimiter);
03371:                    String drawEngineClass = details.getEngineName();
03372:
03373:                    if ((edgeUIClass != null) && (edgeUIClass.length() > 0)
03374:                            && (drawEngineClass != null)
03375:                            && (drawEngineClass.length() > 0)) {
03376:                        try {
03377:                            ui = ETUIFactory.createEdgeUI(edgeUIClass, edgeUI,
03378:                                    drawEngineClass, this );
03379:                            //             ui.setDrawEngineClass(drawEngineClass);
03380:                            //             ui.setDrawingArea(control);
03381:                        } catch (ETException e) {
03382:                            //            this.showErrorMessage(e.getMessage());
03383:                        }
03384:
03385:                        // add user specified properties
03386:                        this .setUIAttributes(type, ui);
03387:
03388:                        if (ui != null) {
03389:                            graph.setCurrentEdgeUI(ui);
03390:                        }
03391:
03392:                        graph
03393:                                .setEdgeCreatedWithLabel("true".equals(getResources().getStringResource(type + ".labeled"))); //$NON-NLS-1$ //$NON-NLS-2$
03394:                    }
03395:                }
03396:            }
03397:
03398:            /**
03399:             * Clears the TS clipboard
03400:             */
03401:            public void clearClipboard() {
03402:                // Sun Issue 6184441:  It appears that TS is setting up the clipboard
03403:                // then sending use a the delete command, which we were then clearing
03404:                // the clipboard.  We use m_bCutting to indicate we are cutting so that
03405:                // we don't clear the clipboard.
03406:                // @see cut()
03407:                if (!m_bCutting) {
03408:                    GetHelper.clearClipboard(this .getGraphWindow());
03409:                }
03410:            }
03411:
03412:            /**
03413:             * Paste the items from the clipboard assumed to be from another diagram
03414:             */
03415:            public void crossDiagramPaste(Point location) {
03416:
03417:                // Since TS doesn't have copy and paste working between diagrams yet
03418:                // we also copy the selected elements onto the IProduct clipboard.
03419:                // If a paste is performed we first check to see if we've got something in the TS clipboard,
03420:                // if not then check the proxy diagram clip.
03421:                IProduct pProduct = getProduct();
03422:
03423:                if (pProduct != null) {
03424:                    // Get the clip string from the product.
03425:                    String sClipString = pProduct.getCrossDiagramClipboard();
03426:
03427:                    if (sClipString != null && sClipString.length() > 0) {
03428:                        String tempString = sClipString;
03429:                        TSConstPoint pPoint = m_GraphWindow
03430:                                .getWorldPoint(location);
03431:                        IApplication pApplication = ProductHelper
03432:                                .getApplication();
03433:
03434:                        if (pPoint != null && pApplication != null) {
03435:                            // DragAndDropSupport dragAndDropSupport;
03436:                            ETList<IElement> pModelElements = new ETArrayList<IElement>();
03437:                            ETList<IPresentationElement> pPresentationElements = new ETArrayList<IPresentationElement>();
03438:                            ETList<String> diagramLocations = new ETArrayList<String>();
03439:
03440:                            DragAndDropSupport.getElementsOnClipboard(
03441:                                    tempString, pApplication, "DRAGGEDITEMS",
03442:                                    pModelElements, pPresentationElements,
03443:                                    diagramLocations);
03444:
03445:                            clonePresentationElements(pPoint,
03446:                                    pPresentationElements);
03447:                        }
03448:                    }
03449:                }
03450:            }
03451:
03452:            /**
03453:             * Clones these presentation elements
03454:             *
03455:             * @param pCurrentPoint [in] Our current location
03456:             * @param pPEs [in] The presentation elements to be cloned and dropped on to the drawing area.
03457:             */
03458:            private void clonePresentationElements(TSConstPoint pCurrentPoint,
03459:                    ETList<IPresentationElement> pPEs) {
03460:                int toCloneCount = 0;
03461:                double x = 0;
03462:                double y = 0;
03463:                IDiagram pDiagram = getDiagram();
03464:                IDiagram pSourceDiagram = null;
03465:                TSGraph pGraph = getGraph();
03466:
03467:                if (pCurrentPoint != null && pPEs != null && pGraph != null) {
03468:                    toCloneCount = pPEs.getCount();
03469:                    x = pCurrentPoint.getX();
03470:                    y = pCurrentPoint.getY();
03471:                }
03472:
03473:                if (toCloneCount != 0) {
03474:                    // Get the selected node bounding rectangle,
03475:                    // so we don't have to invalidate the entire drawing area
03476:                    TSRect pInvalidateRect = null;
03477:                    TSConstRect rectBounding = new TSRect(0, 0, 0, 0);
03478:
03479:                    // Create a union of the presentation elements view bounding rects
03480:                    for (int i = 0; i < toCloneCount; i++) {
03481:                        IPresentationElement pThisPE = pPEs.item(i);
03482:                        if (pThisPE != null) {
03483:                            TSENode pTSENode = TypeConversions
03484:                                    .getOwnerNode(pThisPE);
03485:                            if (pTSENode != null) {
03486:                                TSConstRect this Bounds = (TSConstRect) pTSENode
03487:                                        .getBounds();
03488:
03489:                                if (i == 0) {
03490:                                    rectBounding = this Bounds;
03491:                                } else {
03492:                                    rectBounding = rectBounding
03493:                                            .union(this Bounds);
03494:                                }
03495:                            }
03496:
03497:                            if (pSourceDiagram == null
03498:                                    && pThisPE instanceof  IProductGraphPresentation) {
03499:                                // Get the source diagram from this presentation elment
03500:                                IProductGraphPresentation pGraphPresentation = (IProductGraphPresentation) pThisPE;
03501:                                pSourceDiagram = pGraphPresentation
03502:                                        .getDiagram();
03503:                            }
03504:                        }
03505:                    }
03506:
03507:                    // We have to keep track of new presentation elements and how they related to the old
03508:                    // presentation elements.  Specifically we use this when creating edges and we need to
03509:                    // know the new source and target nodes.
03510:                    ETList<IPresentationElement> oldPEs = new ETArrayList<IPresentationElement>();
03511:                    ETList<IPresentationElement> newPEs = new ETArrayList<IPresentationElement>();
03512:
03513:                    // See now what the offset is from the bounding rect of all the PEs to the
03514:                    // current point being the center.
03515:                    TSConstPoint boundingCenter = rectBounding.getCenter();
03516:                    double centerX = boundingCenter.getX();
03517:                    double centerY = boundingCenter.getY();
03518:
03519:                    double deltaX = x - centerX;
03520:                    double deltaY = y - centerY;
03521:
03522:                    // This loop clones all node presentation elements.  We need to do nodes first
03523:                    // because the edges need their source and target nodes before we create them.
03524:                    for (int i = 0; i < toCloneCount; i++) {
03525:                        IPresentationElement pThisPE = (IPresentationElement) pPEs
03526:                                .item(i);
03527:                        INodePresentation nodePE = null;
03528:                        if (pThisPE instanceof  INodePresentation) {
03529:                            nodePE = (INodePresentation) pThisPE;
03530:                        }
03531:                        if (nodePE != null) {
03532:                            boolean bIsAllowed = false;
03533:
03534:                            IDrawEngine pThisDrawEngine = TypeConversions
03535:                                    .getDrawEngine(pThisPE);
03536:                            TSENode pTSENode = TypeConversions
03537:                                    .getOwnerNode(nodePE);
03538:                            IETNode etnode = TypeConversions.getETNode(nodePE);
03539:                            IElement pElement = TypeConversions
03540:                                    .getElement(nodePE);
03541:
03542:                            if (pElement != null) {
03543:                                bIsAllowed = isAllowedOnDiagram(pElement);
03544:                            }
03545:
03546:                            if (pThisDrawEngine != null && pTSENode != null
03547:                                    && etnode != null && bIsAllowed) {
03548:                                long nWidth = nodePE.getWidth();
03549:                                long nHeight = nodePE.getHeight();
03550:                                int nXCenter = nodePE.getCenter().getX();
03551:                                int nYCenter = nodePE.getCenter().getY();
03552:
03553:                                IETPoint pCenterPoint = new ETPoint(nXCenter
03554:                                        + (int) deltaX, nYCenter + (int) deltaY);
03555:
03556:                                IETNode pCreatedNode = etnode.createNodeCopy(
03557:                                        pDiagram, pCenterPoint);
03558:                                etnode.setDiagram(getDiagram());
03559:
03560:                                // Add this to our list of presentation elements
03561:                                IPresentationElement pCreatedPE = TypeConversions
03562:                                        .getPresentationElement(pCreatedNode);
03563:
03564:                                if (pCreatedPE instanceof  IProductGraphPresentation) {
03565:                                    IProductGraphPresentation pgp = (IProductGraphPresentation) pCreatedPE;
03566:                                    pgp
03567:                                            .reconnectPresentationElement(TypeConversions
03568:                                                    .getElement(pThisPE));
03569:                                }
03570:
03571:                                // retain the size and the center point of the node the same
03572:                                // as those of the souce node.
03573:                                if (pCreatedPE instanceof  NodePresentation) {
03574:                                    NodePresentation nodePre = (NodePresentation) pCreatedPE;
03575:                                    long newWidth = nodePre.getWidth();
03576:                                    long newHeight = nodePre.getHeight();
03577:                                    IETPoint newCenterPoint = nodePre
03578:                                            .getCenter();
03579:                                    // Make sure to keep the center point of the node the same as the source node
03580:                                    nodePre.getTSNode().setCenter(
03581:                                            (double) pCenterPoint.getX(),
03582:                                            (double) pCenterPoint.getY());
03583:                                    if (newWidth != nWidth
03584:                                            || newHeight != nHeight) {
03585:                                        // set the size to the size of the source node
03586:                                        nodePre.resize(nWidth, nHeight, false);
03587:                                    }
03588:                                }
03589:
03590:                                oldPEs.add(nodePE);
03591:                                newPEs.add(pCreatedPE);
03592:                            }
03593:                        }
03594:                    }
03595:
03596:                    // Now create the edges
03597:                    for (int i = 0; i < toCloneCount; i++) {
03598:                        IPresentationElement pThisPE = pPEs.item(i);
03599:
03600:                        IEdgePresentation pEdgePE = null;
03601:                        if (pThisPE instanceof  IEdgePresentation) {
03602:                            pEdgePE = (IEdgePresentation) pThisPE;
03603:                        }
03604:                        if (pEdgePE != null) {
03605:                            // Get the edges from and to node
03606:                            INodePresentation pFromPENode = pEdgePE
03607:                                    .getEdgeFromPresentationElement();
03608:                            INodePresentation pToPENode = pEdgePE
03609:                                    .getEdgeToPresentationElement();
03610:
03611:                            IPresentationElement pCreatedFromPENode = null;
03612:                            IPresentationElement pCreatedToPENode = null;
03613:                            IDrawEngine pThisDrawEngine = TypeConversions
03614:                                    .getDrawEngine(pThisPE);
03615:
03616:                            // Translate the old source and target to the new presentation element nodes
03617:                            // that should be used for the new source and target
03618:                            if (pThisDrawEngine != null && pFromPENode != null
03619:                                    && pToPENode != null) {
03620:                                for (int listIndex = 0; listIndex < oldPEs
03621:                                        .getCount(); listIndex++) {
03622:                                    if (pCreatedFromPENode == null
03623:                                            && pFromPENode == oldPEs
03624:                                                    .get(listIndex)) {
03625:                                        pCreatedFromPENode = newPEs
03626:                                                .get(listIndex);
03627:                                    } else if (pCreatedToPENode == null
03628:                                            && pToPENode == oldPEs
03629:                                                    .get(listIndex)) {
03630:                                        pCreatedToPENode = newPEs
03631:                                                .get(listIndex);
03632:                                    }
03633:
03634:                                    // Break when we find the source and targets
03635:                                    if (pCreatedFromPENode != null
03636:                                            && pCreatedToPENode != null) {
03637:                                        break;
03638:                                    }
03639:                                }
03640:                            }
03641:
03642:                            if (pCreatedFromPENode != null
03643:                                    && pCreatedToPENode != null
03644:                                    || pFromPENode == pToPENode) {
03645:                                if (pFromPENode == pToPENode) {
03646:                                    pCreatedToPENode = pCreatedFromPENode;
03647:                                }
03648:                                TSEEdge pTSEEdge = TypeConversions
03649:                                        .getOwnerEdge(pEdgePE, false);
03650:                                IETEdge pETEdge = TypeConversions
03651:                                        .getETEdge(pTSEEdge);
03652:
03653:                                if (pTSEEdge != null && pETEdge != null) {
03654:                                    TSConstPoint sourcePoint = (TSConstPoint) pTSEEdge
03655:                                            .getSourcePoint();
03656:
03657:                                    IETPoint pNewSourcePoint = new ETPoint(
03658:                                            (int) (Math.round(sourcePoint
03659:                                                    .getX()
03660:                                                    + deltaX)), (int) (Math
03661:                                                    .round(sourcePoint.getY()
03662:                                                            + deltaY)));
03663:
03664:                                    IETEdge pCreatedEdge = pETEdge
03665:                                            .createEdgeCopy(pDiagram,
03666:                                                    pNewSourcePoint,
03667:                                                    pCreatedFromPENode,
03668:                                                    pCreatedToPENode);
03669:                                    pCreatedEdge.setDiagram(getDiagram());
03670:
03671:                                    // Add this to our list of presentation elements
03672:                                    IPresentationElement pCreatedPE = TypeConversions
03673:                                            .getPresentationElement(pCreatedEdge);
03674:
03675:                                    if (pCreatedPE instanceof  IProductGraphPresentation) {
03676:                                        IProductGraphPresentation pgp = (IProductGraphPresentation) pCreatedPE;
03677:                                        pgp
03678:                                                .reconnectPresentationElement(TypeConversions
03679:                                                        .getElement(pThisPE));
03680:                                    }
03681:
03682:                                    // take care of the bends (i.e. path nodes) if any
03683:                                    int noOfPathNodes = pTSEEdge
03684:                                            .numberOfPathNodes();
03685:                                    if (noOfPathNodes > 0) {
03686:                                        TSConstPoint pNewBendPoint = null;
03687:                                        List bendPointList = new ArrayList();
03688:                                        Iterator bendPointIter = pTSEEdge
03689:                                                .bendPoints().iterator();
03690:                                        while (bendPointIter.hasNext()) {
03691:                                            TSConstPoint bendPoint = (TSConstPoint) bendPointIter
03692:                                                    .next();
03693:                                            pNewBendPoint = new TSConstPoint(
03694:                                                    bendPoint.getX() + deltaX,
03695:                                                    bendPoint.getY() + deltaY);
03696:                                            bendPointList.add(pNewBendPoint);
03697:                                        }
03698:                                        ((TSEEdge) pCreatedEdge)
03699:                                                .reroute(bendPointList);
03700:                                    }
03701:                                    oldPEs.add(pEdgePE);
03702:                                    newPEs.add(pCreatedPE);
03703:                                }
03704:                            }
03705:                        }
03706:                    }
03707:
03708:                    // Now restore presentation references.  If I find a partial presentation reference I'll
03709:                    // delete the node I just created if it's a referred element.  This will stop someone from
03710:                    // copying just the port on the component diagram and doing a paste without its
03711:                    // component diagram.
03712:                    for (int i = 0; i < toCloneCount; i++) {
03713:                        IPresentationElement pThisPE = pPEs.item(i);
03714:                        INodePresentation pNodePE = null;
03715:                        if (pThisPE instanceof  INodePresentation) {
03716:                            pNodePE = (INodePresentation) pThisPE;
03717:                        }
03718:                        if (pNodePE != null) {
03719:                            ETList<IPresentationElement> pReferrencingElements = PresentationReferenceHelper
03720:                                    .getAllReferencingElements(pNodePE);
03721:
03722:                            int count = 0;
03723:                            if (pReferrencingElements != null) {
03724:                                count = pReferrencingElements.getCount();
03725:                            }
03726:
03727:                            if (count != 0) {
03728:                                // This pNodePE is a child of some other object in a presentationreference relationship
03729:                                // make sure the parent is there or post a delete of this PE we just created.
03730:                                boolean bDone = false;
03731:                                for (int j = 0; j < count && bDone == false; j++) {
03732:                                    IPresentationElement pRefPE = pReferrencingElements
03733:                                            .item(j);
03734:                                    if (pRefPE != null) {
03735:                                        boolean bIsInList = pPEs
03736:                                                .isInList(pRefPE);
03737:                                        if (!bIsInList) {
03738:                                            for (int listIndex = 0; listIndex < oldPEs
03739:                                                    .getCount(); listIndex++) {
03740:                                                if (pNodePE == oldPEs
03741:                                                        .get(listIndex)) {
03742:                                                    // Find the node we just created that matches pNodePE and whack that guy.
03743:                                                    postDeletePresentationElement(newPEs
03744:                                                            .get(listIndex));
03745:                                                    oldPEs.remove(listIndex);
03746:                                                    newPEs.remove(listIndex);
03747:                                                    bDone = true;
03748:                                                    break;
03749:                                                }
03750:                                            }
03751:                                        } else {
03752:                                            // Find the parent and child in our created list and restore the presentation reference
03753:                                            // relationship
03754:                                            IPresentationElement pParentPE = null;
03755:                                            IPresentationElement pChildPE = null;
03756:
03757:                                            for (int listIndex = 0; listIndex < oldPEs
03758:                                                    .getCount(); ++listIndex) {
03759:                                                if (pParentPE == null
03760:                                                        && pRefPE == oldPEs
03761:                                                                .get(listIndex)) {
03762:                                                    pParentPE = newPEs
03763:                                                            .get(listIndex);
03764:                                                } else if (pChildPE == null
03765:                                                        && pNodePE == oldPEs
03766:                                                                .get(listIndex)) {
03767:                                                    pChildPE = newPEs
03768:                                                            .get(listIndex);
03769:                                                }
03770:
03771:                                                if (pParentPE != null
03772:                                                        && pChildPE != null) {
03773:                                                    break;
03774:                                                }
03775:                                            }
03776:
03777:                                            if (pParentPE != null
03778:                                                    && pChildPE != null) {
03779:                                                PresentationReferenceHelper
03780:                                                        .createPresentationReference(
03781:                                                                pParentPE,
03782:                                                                pChildPE);
03783:                                            } else if (pNodePE != null) {
03784:                                                for (int listIndex = 0; listIndex < oldPEs
03785:                                                        .getCount(); ++listIndex) {
03786:                                                    if (pNodePE == oldPEs
03787:                                                            .get(listIndex)) {
03788:                                                        // The parent is gone.  Don't leave the child hanging, just delete it
03789:                                                        postDeletePresentationElement(pRefPE);
03790:                                                        oldPEs
03791:                                                                .remove(listIndex);
03792:                                                        newPEs
03793:                                                                .remove(listIndex);
03794:                                                        break;
03795:                                                    }
03796:                                                }
03797:                                            }
03798:                                        }
03799:                                    }
03800:                                }
03801:                            }
03802:                        }
03803:                    }
03804:
03805:                    // Now tell each of the created presentation elements that they have just been pasted
03806:                    ETElementManager manager = new ETElementManager(this );
03807:                    for (int listIndex = 0; listIndex < newPEs.getCount(); ++listIndex) {
03808:                        if (newPEs.get(listIndex) != null) {
03809:                            // Fire the event
03810:                            manager
03811:                                    .dispatchToETGraphObject(
03812:                                            newPEs.get(listIndex),
03813:                                            IGraphEventKind.GEK_POST_CROSS_DIAGRAM_PASTE);
03814:                        }
03815:                    }
03816:
03817:                    // Now go through all the nodes and begin containment on them if necessary.  This will
03818:                    // change the namespace of the just dropped element to that of the container
03819:                    if (m_DiagramEngine != null) {
03820:                        for (int listIndex = 0; listIndex < newPEs.getCount(); ++listIndex) {
03821:                            if (newPEs.get(listIndex) instanceof  INodePresentation) {
03822:                                INodePresentation nodePresentation = (INodePresentation) newPEs
03823:                                        .get(listIndex);
03824:                                m_DiagramEngine
03825:                                        .postAddObjectHandleContainment(nodePresentation);
03826:                            }
03827:                        }
03828:                    }
03829:                }
03830:                refresh(true);
03831:            }
03832:
03833:            /* (non-Javadoc)
03834:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#delayedLayoutStyle(int, boolean)
03835:             */
03836:            public void delayedLayoutStyle(int nLayoutStyle,
03837:                    boolean bIgnoreContainment) {
03838:                // TODO Auto-generated method stub
03839:            }
03840:
03841:            /* (non-Javadoc)
03842:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#deleteChildGraph(com.tomsawyer.graph.TSGraphObject)
03843:             */
03844:            public void deleteChildGraph(TSGraphObject pGraphObject) {
03845:                // TODO Auto-generated method stub
03846:            }
03847:
03848:            /* (non-Javadoc)
03849:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#deleteSelected(boolean)
03850:             */
03851:            public void deleteSelected(boolean bAskUser) {
03852:                if (getReadOnly() == false) {
03853:                    handleKeyDown(KeyEvent.VK_DELETE, 0, bAskUser);
03854:                }
03855:            }
03856:
03857:            /**
03858:             * Delete these items, the model elements might be deleted as well
03859:             * depending on the state of the bAffectModelDataAsWell flag.
03860:             *
03861:             * @param nodeVector The nodes to delete.
03862:             * @param edgeVector The edges to delete.
03863:             * @param edgeLabelVector The edge labels to delete.
03864:             * @param nodeLabelVector The node labels to delete.
03865:             * @param bAffectModelDataAsWell Set to true to delete model
03866:             *                               elements as well.
03867:             */
03868:            private void deleteTheseItems(ETList<TSENode> selectedNodes,
03869:                    ETList<TSEEdge> selectedEdges,
03870:                    ETList<TSENodeLabel> selectedNodeLabels,
03871:                    ETList<TSEEdgeLabel> selectedEdgeLabels,
03872:                    boolean affeModelDataAsWell, boolean removeFromImport) {
03873:                try {
03874:
03875:                    // This flag is used in case we have disconnected elements.  In that case there
03876:                    // is no PE and we need to refresh the entire diagram.
03877:                    boolean bCouldntGetPresentationElement = false;
03878:
03879:                    for (Iterator<TSENode> iter = selectedNodes.iterator(); iter
03880:                            .hasNext();) {
03881:                        INodePresentation pres = TypeConversions
03882:                                .getNodePresentation(iter.next());
03883:                        if (pres != null) {
03884:                            pres.invalidate();
03885:                        } else {
03886:                            bCouldntGetPresentationElement = true;
03887:                        }
03888:                    }
03889:
03890:                    for (Iterator<TSEEdge> iter = selectedEdges.iterator(); iter
03891:                            .hasNext();) {
03892:                        IEdgePresentation pres = TypeConversions
03893:                                .getEdgePresentation(iter.next());
03894:                        if (pres != null) {
03895:                            pres.invalidate();
03896:                        } else {
03897:                            bCouldntGetPresentationElement = true;
03898:                        }
03899:                    }
03900:
03901:                    for (Iterator<TSENodeLabel> iter = selectedNodeLabels
03902:                            .iterator(); iter.hasNext();) {
03903:                        ILabelPresentation pres = TypeConversions
03904:                                .getLabelPresentation(iter.next());
03905:                        if (pres != null) {
03906:                            pres.invalidate();
03907:                        } else {
03908:                            bCouldntGetPresentationElement = true;
03909:                        }
03910:                    }
03911:
03912:                    for (Iterator<TSEEdgeLabel> iter = selectedEdgeLabels
03913:                            .iterator(); iter.hasNext();) {
03914:                        ILabelPresentation pres = TypeConversions
03915:                                .getLabelPresentation(iter.next());
03916:                        if (pres != null) {
03917:                            pres.invalidate();
03918:                        } else {
03919:                            bCouldntGetPresentationElement = true;
03920:                        }
03921:                    }
03922:
03923:                    if (bCouldntGetPresentationElement == true) {
03924:                        refresh(true);
03925:                    }
03926:
03927:                    ETList<TSObject> selected = new ETArrayList();
03928:                    selected.addAll(selectedNodes);
03929:                    selected.addAll(selectedEdges);
03930:                    selected.addAll(selectedNodeLabels);
03931:                    selected.addAll(selectedEdgeLabels);
03932:                    removeGraphObjects(selected, affeModelDataAsWell,
03933:                            removeFromImport);
03934:
03935:                    //         removeNodeLabels(selectedNodeLabels, affeModelDataAsWell);
03936:                    //         removeEdgeLabels(selectedEdgeLabels, affeModelDataAsWell);
03937:                    //         removeEdges(selectedEdges, affeModelDataAsWell);
03938:                    //         removeNodes(selectedNodes, affeModelDataAsWell);
03939:                    //JM: Cleaning up both clipboards after delete to Fix Bug#6286590
03940:                    this .clearClipboard();
03941:                    this .getProduct().setCrossDiagramClipboard("");
03942:
03943:                    refresh(true);
03944:                } catch (Exception e) {
03945:                    e.printStackTrace();
03946:                }
03947:            }
03948:
03949:            /*
03950:             * Returns true if the object is on the diagram.
03951:             */
03952:            public boolean getIsOnDiagram(ITSGraphObject pObject) {
03953:                if (pObject instanceof  IETGraphObject) {
03954:                    return !visit(new ETFindObjectVisitor(
03955:                            (IETGraphObject) pObject));
03956:                }
03957:                return false;
03958:            }
03959:
03960:            /*
03961:             * Removes any kind of ITSGraphObject from the diagram.
03962:             */
03963:            protected void removeGraphObjects(List objects,
03964:                    boolean affectModelElement, boolean removeFromImport) {
03965:                try {
03966:                    IteratorT<ITSGraphObject> iter = new IteratorT<ITSGraphObject>(
03967:                            objects);
03968:                    while (iter.hasNext()) {
03969:                        final ITSGraphObject curObj = iter.next();
03970:                        if (curObj == null) {
03971:                            continue;
03972:                        }
03973:                        if (affectModelElement == true) {
03974:                            // The user wants to affect a model element deletion so tell the
03975:                            // graph object to affect the model data file - in most cases the
03976:                            // element is deleted, in some cases something more exciting
03977:                            // happens (ie nested link removes the child from the namespace).
03978:                            affectModelElement((TSGraphObject) curObj
03979:                                    .getObject());
03980:                        }
03981:                        if (removeFromImport) {
03982:                            IElement e = TypeConversions
03983:                                    .getElement((TSGraphObject) curObj
03984:                                            .getObject());
03985:                            getProject().removeElementImport(e);
03986:                        }
03987:
03988:                        SwingUtilities.invokeLater(new Runnable() {
03989:
03990:                            public void run() {
03991:                                //If its still on the diagram delete it
03992:                                if (getIsOnDiagram(curObj)) {
03993:                                    curObj.delete();
03994:                                    refresh(true);
03995:                                }
03996:                            }
03997:                        });
03998:                    }
03999:                } catch (Exception e) {
04000:                    e.printStackTrace();
04001:                }
04002:            }
04003:
04004:            //   protected void removeNodeLabels(ETList<TSENodeLabel> labels,
04005:            //   boolean affectModelElement)
04006:            //   {
04007:            //      this.removeGraphObjects(labels, affectModelElement);
04008:            //   }
04009:            //
04010:            //   protected void removeEdgeLabels(ETList<TSEEdgeLabel> labels, boolean affectModelElement)
04011:            //   {
04012:            //      this.removeGraphObjects(labels, affectModelElement);
04013:            //   }
04014:            //
04015:            //   protected void removeEdges(ETList<TSEEdge> edges, boolean affectModelElement)
04016:            //   {
04017:            //      this.removeGraphObjects(edges, affectModelElement);
04018:            //   }
04019:            //
04020:            //   protected void removeNodes(ETList<TSENode> nodes,  boolean affectModelElement)
04021:            //   {
04022:            //      this.removeGraphObjects(nodes, affectModelElement);
04023:            //   }
04024:
04025:            protected void affectModelElement(TSGraphObject obj) {
04026:                IETGraphObject gObj = TypeConversions.getETGraphObject(obj);
04027:                if (gObj != null) {
04028:                    gObj.affectModelElementDeletion();
04029:                }
04030:
04031:                handlePreDeleteObject(obj);
04032:            }
04033:
04034:            /**
04035:             * Handles the pre delete event without checking for the use input block.
04036:             *
04037:             * @param graphObj The graph object that is being deleted.
04038:             */
04039:            protected boolean handlePreDeleteObject(TSGraphObject graphObj) {
04040:                boolean retVal = false;
04041:
04042:                if (getReadOnly() == true) {
04043:                    retVal = true;
04044:                } else if (graphObj != null) {
04045:                    // Empty out the clipboard in case this element is sitting in there
04046:                    clearClipboard();
04047:
04048:                    if (graphObj instanceof  IETNode) {
04049:                        IETNode node = (IETNode) graphObj;
04050:
04051:                        // Notify all the connected edges that they are about to be deleted,
04052:                        // since TS is not sending those edges
04053:                        List inEdges = node.getInEdges();
04054:                        for (Iterator iter = inEdges.iterator(); iter.hasNext();) {
04055:                            TSEEdge curEdge = (TSEEdge) iter.next();
04056:                            sendPreDeleteLinkEvents(curEdge);
04057:                        }
04058:
04059:                        List outEdges = node.getOutEdges();
04060:                        for (Iterator iter = outEdges.iterator(); iter
04061:                                .hasNext();) {
04062:                            TSEEdge curEdge = (TSEEdge) iter.next();
04063:                            sendPreDeleteLinkEvents(curEdge);
04064:                        }
04065:                    }
04066:
04067:                    // Remove the presentation object
04068:                    IPresentationElement presentationElement = TypeConversions
04069:                            .getPresentationElement(graphObj);
04070:                    if (presentationElement != null) {
04071:                        removePresentationElement(presentationElement);
04072:
04073:                        JTrackBar bar = getTrackBar();
04074:                        if (bar != null) {
04075:                            bar.removePresentationElement(presentationElement);
04076:                        }
04077:                    }
04078:
04079:                    setIsDirty(true);
04080:                }
04081:
04082:                return retVal;
04083:            }
04084:
04085:            /**
04086:             * Calls OnPreDeleteLink on the to and from nodes, if available
04087:             *
04088:             * @param pObject [in] The object, which is a TS edge, that is about to be deleted
04089:             */
04090:            protected void sendPreDeleteLinkEvents(TSEEdge graphObject) {
04091:                if (graphObject != null) {
04092:                    IEdgePresentation presElement = TypeConversions
04093:                            .getEdgePresentation(graphObject);
04094:                    if (presElement != null) {
04095:                        ETPairT<INodePresentation, INodePresentation> nodes = presElement
04096:                                .getEdgeFromAndToPresentationElement();
04097:
04098:                        INodePresentation fromNode = nodes.getParamOne();
04099:                        if (fromNode != null) {
04100:                            fromNode.onPreDeleteLink(presElement, true);
04101:                        }
04102:
04103:                        INodePresentation toNode = nodes.getParamTwo();
04104:                        if (toNode != null) {
04105:                            toNode.onPreDeleteLink(presElement, false);
04106:                        }
04107:                    }
04108:                }
04109:            }
04110:
04111:            /**
04112:             * Removes this presentation element from all of its associated model elements.
04113:             *
04114:             * @param presentationElement The presentation element to be removed.
04115:             */
04116:            protected void removePresentationElement(
04117:                    IPresentationElement presentationElement) {
04118:                if (presentationElement != null) {
04119:                    ETList<IElement> subjects = presentationElement
04120:                            .getSubjects();
04121:                    if (subjects != null) {
04122:                        for (Iterator<IElement> iter = subjects.iterator(); iter
04123:                                .hasNext();) {
04124:                            IElement curElement = iter.next();
04125:                            if (curElement != null) {
04126:                                curElement
04127:                                        .removePresentationElement(presentationElement);
04128:                            }
04129:                        }
04130:                    }
04131:                }
04132:            }
04133:
04134:            /**
04135:             * Gather up all the selected items into vectors
04136:             *
04137:             * @param selectedNodes The selected nodes.
04138:             * @param selectedEdges The selected edges.
04139:             * @param selectedNodeLabels The selected node labels.
04140:             * @param selectedEdgeLabels The selected edge labels.
04141:             */
04142:            protected void gatherSelectedItems(ETList<TSENode> selectedNodes,
04143:                    ETList<TSEEdge> selectedEdges,
04144:                    ETList<TSENodeLabel> selectedNodeLabels,
04145:                    ETList<TSEEdgeLabel> selectedEdgeLabels) {
04146:                TSEGraph graph = getGraph();
04147:                if (graph != null) {
04148:                    List nodes = graph.selectedNodes();
04149:                    if (nodes != null) {
04150:                        selectedNodes.addAll(nodes);
04151:                    }
04152:
04153:                    List edges = graph.selectedEdges();
04154:                    if (edges != null) {
04155:                        selectedEdges.addAll(edges);
04156:                    }
04157:
04158:                    List edgeLabels = graph.selectedEdgeLabels();
04159:                    if (edgeLabels != null) {
04160:                        selectedEdgeLabels.addAll(edgeLabels);
04161:                    }
04162:
04163:                    List nodeLabels = graph.selectedNodeLabels();
04164:                    if (nodeLabels != null) {
04165:                        selectedNodeLabels.addAll(nodeLabels);
04166:                    }
04167:                }
04168:            }
04169:
04170:            /* (non-Javadoc)
04171:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#deviceToLogicalPoint(com.embarcadero.describe.umlsupport.IETPoint)
04172:             */
04173:            public IETPoint deviceToLogicalPoint(IETPoint device) {
04174:                IETPoint etPoint = null;
04175:
04176:                if (device != null) {
04177:                    etPoint = deviceToLogicalPoint(device.getX(), device.getY());
04178:                }
04179:
04180:                return etPoint;
04181:            }
04182:
04183:            /* (non-Javadoc)
04184:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#deviceToLogicalPoint(com.embarcadero.describe.umlsupport.IETPoint)
04185:             */
04186:            public IETPoint deviceToLogicalPoint(int x, int y) {
04187:                IETPoint etPoint = null;
04188:
04189:                ADGraphWindow wnd = getGraphWindow();
04190:                if (wnd != null) {
04191:                    etPoint = new ETPointEx(wnd
04192:                            .getNonalignedWorldPoint(new Point(x, y)));
04193:                }
04194:
04195:                return etPoint;
04196:            }
04197:
04198:            /* (non-Javadoc)
04199:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#deviceToLogicalRect(com.embarcadero.describe.umlsupport.IETRect)
04200:             */
04201:            public IETRect deviceToLogicalRect(IETRect pDevice) {
04202:                return deviceToLogicalRect((int) pDevice.getLeft(),
04203:                        (int) pDevice.getTop(), (int) pDevice.getWidth(),
04204:                        (int) pDevice.getHeight());
04205:            }
04206:
04207:            /* (non-Javadoc)
04208:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#deviceToLogicalRect(com.embarcadero.describe.umlsupport.IETRect)
04209:             */
04210:            public IETRect deviceToLogicalRect(double left, double top,
04211:                    double width, double height) {
04212:                if (getGraphWindow() != null) {
04213:                    TSTransform transform = getGraphWindow().getTransform();
04214:                    if (transform != null) {
04215:                        return new ETRectEx(transform.boundsToWorld((int) left,
04216:                                (int) top, (int) width, (int) height));
04217:                    }
04218:                }
04219:
04220:                return null;
04221:            }
04222:
04223:            /**
04224:             * Alerts the nodes/edges/labels that their underlying model element has gone to that great model in the sky
04225:             *
04226:             * @param pTargets [in] A list of all the guys that need to know that a model element has been deleted.
04227:             */
04228:            public void elementDeleted(INotificationTargets pTargets) {
04229:
04230:                if (pTargets != null) {
04231:                    // Tell the listeners about the event we're about to dispatch
04232:                    this .fireChangeNotificationTranslator(pTargets);
04233:
04234:                    ETList<IPresentationElement> pPEs = pTargets
04235:                            .getPresentationElementsToNotify();
04236:
04237:                    if (pPEs != null) {
04238:                        try {
04239:                            IteratorT<IPresentationElement> iter = new IteratorT<IPresentationElement>(
04240:                                    pPEs);
04241:                            while (iter.hasNext()) {
04242:                                IPresentationElement presentationElement = iter
04243:                                        .next();
04244:                                if (presentationElement != null) {
04245:                                    IETGraphObject etGraphObject = TypeConversions
04246:                                            .getETGraphObject(presentationElement);
04247:                                    if (etGraphObject != null) {
04248:                                        etGraphObject
04249:                                                .modelElementDeleted(pTargets);
04250:                                        setIsDirty(true);
04251:                                        //etGraphObject.delete();
04252:                                    }
04253:                                }
04254:                            }
04255:                        } catch (Exception e) {
04256:                            e.printStackTrace();
04257:                        }
04258:                    }
04259:                }
04260:
04261:                // Fix J1427:  This refresh call is not in the C++, but seems to be necessary.
04262:                //             I (BDB) have added the invokeLater() to delay the action after the
04263:                //             lifeline draw engines have validated themselves when the user deletes
04264:                //             an operation from the project tree that is the invoked operation of
04265:                //             a message on an SQD.
04266:                SwingUtilities.invokeLater(new Runnable() {
04267:
04268:                    public void run() {
04269:                        refresh(false);
04270:                    }
04271:                });
04272:            }
04273:
04274:            /* (non-Javadoc)
04275:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#elementModified(org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets)
04276:             */
04277:            public void elementModified(INotificationTargets pTargets) {
04278:                // setLastChangeTime();
04279:                fireChangeNotificationTranslator(pTargets);
04280:
04281:                IElement modelElement = pTargets.getChangedModelElement();
04282:                ETList<IPresentationElement> presentationElements = pTargets
04283:                        .getPresentationElementsToNotify();
04284:
04285:                if (presentationElements != null) {
04286:                    try {
04287:                        IteratorT<IPresentationElement> iter = new IteratorT<IPresentationElement>(
04288:                                presentationElements);
04289:                        while (iter.hasNext()) {
04290:                            IPresentationElement presentationElement = iter
04291:                                    .next();
04292:
04293:                            if (presentationElement != null) {
04294:                                IETGraphObject etGraphObject = TypeConversions
04295:                                        .getETGraphObject(presentationElement);
04296:                                if (etGraphObject != null) {
04297:                                    if (presentationElement instanceof  IGraphPresentation) {
04298:                                        IGraphPresentation gPresentation = (IGraphPresentation) presentationElement;
04299:                                        gPresentation.invalidate();
04300:                                    }
04301:                                    etGraphObject
04302:                                            .modelElementHasChanged(pTargets);
04303:                                    setIsDirty(true);
04304:
04305:                                    GraphObjectValidation graphObjectValidation = new GraphObjectValidation();
04306:                                    graphObjectValidation
04307:                                            .addValidationKind(IDiagramValidateKind.DVK_VALIDATE_LINKENDS);
04308:                                    graphObjectValidation
04309:                                            .addValidationKind(IDiagramValidateKind.DVK_VALIDATE_CONNECTIONTOELEMENT);
04310:
04311:                                    int result = graphObjectValidation
04312:                                            .getValidationResult(IDiagramValidateKind.DVK_VALIDATE_LINKENDS);
04313:                                    if (result == IDiagramValidateResult.DVR_INVALID) {
04314:                                        if (presentationElement instanceof  IEdgePresentation) {
04315:                                            IEdgePresentation edgePresentation = (IEdgePresentation) presentationElement;
04316:                                            boolean successfullyConnected = edgePresentation
04317:                                                    .reconnectLinkToValidNodes();
04318:                                            if (!successfullyConnected) {
04319:                                                postDeletePresentationElement(presentationElement);
04320:                                            }
04321:                                        }
04322:                                    }
04323:
04324:                                    result = graphObjectValidation
04325:                                            .getValidationResult(IDiagramValidateKind.DVK_VALIDATE_CONNECTIONTOELEMENT);
04326:                                    if (result == IDiagramValidateResult.DVR_INVALID) {
04327:                                        postDeletePresentationElement(presentationElement);
04328:                                    }
04329:                                }
04330:                            }
04331:                        }
04332:                    } catch (InvalidArguments e) {
04333:                        e.printStackTrace();
04334:                    }
04335:                }
04336:                //this.refresh(false);
04337:            }
04338:
04339:            void fireChangeNotificationTranslator(INotificationTargets targets) {
04340:                IDiagram diagram = getDiagram();
04341:
04342:                if (diagram != null && m_drawingAreaDispatcher != null) {
04343:                    IEventPayload payload = m_drawingAreaDispatcher
04344:                            .createPayload("ChangeNotificationTranslator");
04345:
04346:                    m_drawingAreaDispatcher.fireGetNotificationTargets(diagram,
04347:                            targets, payload);
04348:                }
04349:            }
04350:
04351:            /* (non-Javadoc)
04352:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#elementTransformed(com.embarcadero.describe.coreinfrastructure.IClassifier)
04353:             */
04354:            public void elementTransformed(IClassifier classifier) {
04355:                ETList<IPresentationElement> pPresentationElements = getAllItems2(classifier);
04356:                int count = 0;
04357:                if (pPresentationElements != null) {
04358:                    count = pPresentationElements.size();
04359:                }
04360:
04361:                for (int i = 0; i < count; i++) {
04362:                    IPresentationElement pPresentationElement = pPresentationElements
04363:                            .get(i);
04364:
04365:                    if (pPresentationElement != null) {
04366:                        IETGraphObject pETGraphObject = TypeConversions
04367:                                .getETGraphObject(pPresentationElement);
04368:                        if (pETGraphObject != null) {
04369:                            if (m_PresentationTypesMgr != null) {
04370:                                int nDiagramKind = getDiagramKind();
04371:                                String sInitString = m_PresentationTypesMgr
04372:                                        .getMetaTypeInitString(classifier,
04373:                                                nDiagramKind);
04374:                                if (sInitString != null
04375:                                        && sInitString.length() > 0) {
04376:                                    resetDrawEngine(pETGraphObject, sInitString);
04377:                                } else {
04378:                                    postDeletePresentationElement(pPresentationElement);
04379:                                }
04380:                            }
04381:                            setIsDirty(true);
04382:                        }
04383:                    }
04384:                }
04385:            }
04386:
04387:            /**
04388:             * Ends the editing context so if there's a name collision we can handle it.
04389:             */
04390:            public void endEditContext() {
04391:                if (m_CollisionHandler != null
04392:                        && m_NameCollisionListener != null) {
04393:                    m_NameCollisionListener.setEnabled(false);
04394:                    m_CollisionHandler.setCompartment(null);
04395:                }
04396:            }
04397:
04398:            /* (non-Javadoc)
04399:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#endOnDrawZoom()
04400:             */
04401:            public void endOnDrawZoom() {
04402:                // TODO Auto-generated method stub
04403:            }
04404:
04405:            /* (non-Javadoc)
04406:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#enterMode(int)
04407:             */
04408:            public void enterMode(int nDrawingToolKind) {
04409:                if (getDiagramEngine() != null) {
04410:                    getDiagramEngine().enterMode(nDrawingToolKind);
04411:
04412:                    // For these tools selection reset the state on any 'select' state listeners.
04413:                    // These result in the drawing area state being changed to 'select'
04414:                    if (nDrawingToolKind == IDrawingToolKind.DTK_SELECTION
04415:                            || nDrawingToolKind == IDrawingToolKind.DTK_ZOOM
04416:                            || nDrawingToolKind == IDrawingToolKind.DTK_MOUSE_ZOOM
04417:                            || nDrawingToolKind == IDrawingToolKind.DTK_PAN
04418:                            || nDrawingToolKind == IDrawingToolKind.DTK_EDGENAV_MOUSE) {
04419:                        setSelectStateOnPalette();
04420:                    }
04421:                }
04422:            }
04423:
04424:            /**
04425:             * Puts the drawing area into a specific mode based on the sButtonID.
04426:             * sButtonID is a key in the PresentationTypes.etc file.
04427:             *
04428:             * @param sButtonID The button string in the presentation types file.  A
04429:             *                  lookup is performed tofigure out the TS init string.
04430:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#enterModeFromButton(java.lang.String)
04431:             */
04432:            public void enterModeFromButton(String sButtonID) {
04433:                boolean handled = false;
04434:
04435:                // save edit and deselect
04436:                saveEditCompartment();
04437:
04438:                //getGraphWindow().deselectAll(false);
04439:                if (getDiagramEngine() != null) {
04440:                    handled = getDiagramEngine().enterModeFromButton(sButtonID);
04441:                }
04442:
04443:                if (handled == false) {
04444:                    IPresentationTypesMgr mgr = getPresentationTypesMgr();
04445:                    if (mgr != null) {
04446:                        String initStr = mgr.getButtonInitString(sButtonID,
04447:                                getDiagramKind());
04448:                        PresentationTypeDetails details = mgr
04449:                                .getInitStringDetails(initStr, getDiagramKind());
04450:
04451:                        int objectKind = details.getObjectKind();
04452:                        if (objectKind != TSGraphObjectKind.TSGOK_INVALID
04453:                                && initStr.length() > 0) {
04454:                            switch (objectKind) {
04455:                            case TSGraphObjectKind.TSGOK_NODE:
04456:                                setNodeDescription(initStr);
04457:                                break;
04458:                            case TSGraphObjectKind.TSGOK_EDGE:
04459:                                setEdgeDescription(initStr);
04460:                                break;
04461:                            case TSGraphObjectKind.TSGOK_NODE_DECORATOR:
04462:                                setMode(
04463:                                        ADDrawingAreaConstants.CREATE_NODE_DECORATOR_CMD,
04464:                                        initStr);
04465:                                break;
04466:                            case TSGraphObjectKind.TSGOK_NODE_RESIZE:
04467:                                //setMode(ADDrawingAreaConstants.NODE_RESIZE_CMD, initStr);
04468:                                setNodeDescription(initStr);
04469:                                break;
04470:                            default:
04471:                                sendDebugMessage("Unknown object kind");
04472:                            }
04473:                        }
04474:                    }
04475:                }
04476:            }
04477:
04478:            public void setSelectedPaletteButton(String sButtonID) {
04479:                mSelectedPaletteBttn = sButtonID;
04480:            }
04481:
04482:            public String getSelectedPaletteButton() {
04483:                return mSelectedPaletteBttn;
04484:            }
04485:
04486:            private void saveEditCompartment() {
04487:                if (getEditCompartment() != null) {
04488:                    getEditCompartment().save();
04489:                    m_EditCompartment = null;
04490:                }
04491:            }
04492:
04493:            public void onMoveForward() {
04494:                executeStackingCommand(IDrawingAreaControl.SOK_MOVEFORWARD,
04495:                        true);
04496:            }
04497:
04498:            public void onMoveToFront() {
04499:                executeStackingCommand(IDrawingAreaControl.SOK_MOVETOFRONT,
04500:                        true);
04501:            }
04502:
04503:            public void onMoveBackward() {
04504:                executeStackingCommand(IDrawingAreaControl.SOK_MOVEBACKWARD,
04505:                        true);
04506:            }
04507:
04508:            public void onMoveToBack() {
04509:                executeStackingCommand(IDrawingAreaControl.SOK_MOVETOBACK, true);
04510:            }
04511:
04512:            public void executeStackingCommand(int pStackingCommand,
04513:                    boolean pRedraw) {
04514:                if (this .isStackingCommandAllowed(pStackingCommand)) {
04515:                    ETList<IPresentationElement> selectedObjects = this 
04516:                            .getSelected();
04517:                    this .executeStackingCommand(selectedObjects,
04518:                            pStackingCommand, pRedraw);
04519:                }
04520:            }
04521:
04522:            public void executeStackingCommand(
04523:                    IPresentationElement pPresentationElement,
04524:                    int pStackingCommand, boolean pRedraw) {
04525:                if (this .isStackingCommandAllowed(pStackingCommand)) {
04526:                    if (pPresentationElement != null) {
04527:
04528:                        ETList<IPresentationElement> peList = new ETArrayList<IPresentationElement>();
04529:
04530:                        peList.add(pPresentationElement);
04531:                        this .executeStackingCommand(peList, pStackingCommand,
04532:                                pRedraw);
04533:                    }
04534:                }
04535:            }
04536:
04537:            public void executeStackingCommand(
04538:                    ETList<IPresentationElement> pPresentationElements,
04539:                    int pStackingCommand, boolean pRedraw) {
04540:
04541:                if (this .isStackingCommandAllowed(pStackingCommand)) {
04542:                    if (pPresentationElements != null) {
04543:                        TSEGraph graph = this .getGraph();
04544:
04545:                        //1. create the smallest bounding rect of the passed in elements
04546:                        TSConstRect selBounds = this 
04547:                                .buildMinBoundingRect(pPresentationElements);
04548:                        if (selBounds == null) {
04549:                            return;
04550:                        }
04551:                        //2. get all the visible nodes with bounds that intersect the targe bounding rect
04552:                        List overlappingNodes = graph.getNodesTouchingBounds(
04553:                                selBounds, null);
04554:
04555:                        //3. get the selected nodes out of the overlapping nodes and save them to prevSelected list
04556:                        List prevSelected = new ArrayList();
04557:                        prevSelected.addAll(this .getSelected(overlappingNodes));
04558:
04559:                        // Fix IZ=95094 - Move to back affects not selected elements
04560:                        // The root cause of this issue is if there are other nodes intersecting with the
04561:                        // bounding rect of the container but not intersecting with the selected nodes,
04562:                        // redrawing the container node will cover up these nodes.
04563:                        // Need to get all the nodes that intersect the extended bounding rect and
04564:                        // redraw them all.
04565:                        // 4. find the smallest bounding rect that covers all the overlapping nodes
04566:                        ETList<IPresentationElement> overlappingPEs = new ETArrayList<IPresentationElement>();
04567:                        Iterator listIter = overlappingNodes.iterator();
04568:                        while (listIter.hasNext()) {
04569:                            TSNode graphObj = (ETNode) listIter.next();
04570:                            IPresentationElement pe = TypeConversions
04571:                                    .getPresentationElement(graphObj);
04572:                            overlappingPEs.add(pe);
04573:                        }
04574:                        selBounds = buildMinBoundingRect(overlappingPEs);
04575:
04576:                        //5. get all nodes that touch the extended bounding rec
04577:                        List extendedOverlappingNodes = graph
04578:                                .getNodesTouchingBounds(selBounds, null);
04579:
04580:                        // make sure the passed in elements are selected
04581:                        Iterator peIter = pPresentationElements.iterator();
04582:                        while (peIter.hasNext()) {
04583:                            IPresentationElement pe = (IPresentationElement) peIter
04584:                                    .next();
04585:                            if (pe instanceof  INodePresentation) {
04586:                                TSENode element = ((INodePresentation) pe)
04587:                                        .getTSNode();
04588:                                element.setSelected(true);
04589:                            }
04590:                        }
04591:
04592:                        // Fixed IZ=95091 - Element moved to back is still shown above container
04593:                        // Cause: contained objects in a container is being redrawn
04594:                        // as a result of the Refresh() call at the end of this method;
04595:                        // Set the flag not to redraw objects contained in a container if any.
04596:                        ignoreDrawContainedObject(overlappingNodes, true);
04597:
04598:                        if (pStackingCommand == IDrawingAreaControl.SOK_MOVETOFRONT) {
04599:                            List tmpList = new ArrayList();
04600:                            Iterator desiredStackListIter = extendedOverlappingNodes
04601:                                    .iterator();
04602:                            while (desiredStackListIter.hasNext()) {
04603:                                TSENode stackedObj = (TSENode) desiredStackListIter
04604:                                        .next();
04605:                                if (stackedObj.isSelected()) {
04606:                                    tmpList.add(stackedObj);
04607:                                }
04608:                            }
04609:
04610:                            Collections.reverse(tmpList);
04611:                            Iterator tmpIter = tmpList.iterator();
04612:                            while (tmpIter.hasNext()) {
04613:                                TSENode tmpObj = (TSENode) tmpIter.next();
04614:                                graph.remove(tmpObj);
04615:                                graph.insert(tmpObj);
04616:                            }
04617:                        } else if (pStackingCommand == IDrawingAreaControl.SOK_MOVETOBACK) {
04618:                            Collections.reverse(extendedOverlappingNodes);
04619:                            Iterator desiredStackListIter = extendedOverlappingNodes
04620:                                    .iterator();
04621:                            while (desiredStackListIter.hasNext()) {
04622:                                TSENode stackedNode = (TSENode) desiredStackListIter
04623:                                        .next();
04624:                                if (!stackedNode.isSelected()) {
04625:                                    graph.remove(stackedNode);
04626:                                    graph.insert(stackedNode);
04627:                                }
04628:                            }
04629:                        } else if (pStackingCommand == IDrawingAreaControl.SOK_MOVEFORWARD) {
04630:                            List tmpList = new ArrayList();
04631:                            if (((TSENode) extendedOverlappingNodes.get(0))
04632:                                    .isSelected()) {
04633:                                return;
04634:                            }
04635:                            Collections.reverse(extendedOverlappingNodes);
04636:                            Iterator desiredStackListIter = extendedOverlappingNodes
04637:                                    .iterator();
04638:                            while (desiredStackListIter.hasNext()) {
04639:                                TSENode stackedObj = (TSENode) desiredStackListIter
04640:                                        .next();
04641:                                if (stackedObj.isSelected()) {
04642:                                    tmpList.add(stackedObj);
04643:                                } else {
04644:                                    graph.remove(stackedObj);
04645:                                    graph.insert(stackedObj);
04646:
04647:                                    Iterator tmpIter = tmpList.iterator();
04648:                                    while (tmpIter.hasNext()) {
04649:                                        TSENode tmpObj = (TSENode) tmpIter
04650:                                                .next();
04651:                                        graph.remove(tmpObj);
04652:                                        graph.insert(tmpObj);
04653:                                    }
04654:                                    tmpList.clear();
04655:                                }
04656:                            }
04657:                        } else if (pStackingCommand == IDrawingAreaControl.SOK_MOVEBACKWARD) {
04658:                            List bakList = new ArrayList();
04659:                            List tmpList = new ArrayList();
04660:                            Iterator desiredStackListIter = extendedOverlappingNodes
04661:                                    .iterator();
04662:                            while (desiredStackListIter.hasNext()) {
04663:                                TSENode stackedObj = (TSENode) desiredStackListIter
04664:                                        .next();
04665:                                if (stackedObj.isSelected()) {
04666:                                    tmpList.add(stackedObj);
04667:                                } else {
04668:                                    bakList.add(stackedObj);
04669:
04670:                                    Iterator tmpIter = tmpList.iterator();
04671:                                    while (tmpIter.hasNext()) {
04672:                                        TSENode tmpObj = (TSENode) tmpIter
04673:                                                .next();
04674:                                        bakList.add(tmpObj);
04675:                                    }
04676:                                    tmpList.clear();
04677:                                }
04678:                            }
04679:
04680:                            Collections.reverse(bakList);
04681:                            Iterator bakIter = bakList.iterator();
04682:                            while (bakIter.hasNext()) {
04683:                                TSENode stackedObj = (TSENode) bakIter.next();
04684:                                if (stackedObj.isSelected()) {
04685:                                    // if the selected node is next to the last node in overlappingNodes list,
04686:                                    // do not redraw it.
04687:                                    int index = overlappingNodes
04688:                                            .indexOf(stackedObj);
04689:                                    if (index >= (overlappingNodes.size() - 2)) {
04690:                                        continue;
04691:                                    }
04692:                                }
04693:                                graph.remove(stackedObj);
04694:                                graph.insert(stackedObj);
04695:                            }
04696:                        }
04697:
04698:                        // Reselect originally selected objects
04699:                        Iterator reselectIter = prevSelected.iterator();
04700:                        while (reselectIter.hasNext()) {
04701:                            TSENode graphObj = (TSENode) reselectIter.next();
04702:                            graphObj.setSelected(true);
04703:                        }
04704:
04705:                        if (pRedraw) {
04706:                            this .refresh(false);
04707:                        }
04708:                    }
04709:                }
04710:            }
04711:
04712:            private void ignoreDrawContainedObject(List overlappingNodes,
04713:                    boolean ignore) {
04714:                Iterator listIter = overlappingNodes.iterator();
04715:                while (listIter.hasNext()) {
04716:                    TSENode stackedObj = (TSENode) listIter.next();
04717:                    if (stackedObj != null) {
04718:                        ETGenericNodeUI nodeUI = (ETGenericNodeUI) stackedObj
04719:                                .getNodeUI();
04720:                        IDrawEngine objDrawEngine = nodeUI.getDrawEngine();
04721:                        if (objDrawEngine instanceof  ETContainerDrawEngine) {
04722:                            ((ETContainerDrawEngine) objDrawEngine)
04723:                                    .setIgnoreDrawContained(ignore);
04724:                        }
04725:                    }
04726:                }
04727:            }
04728:
04729:            // Used by ExecuteStackingCommand to calculate min bounding rect of specfied elements
04730:            private TSConstRect buildMinBoundingRect(List pPresentationElements) {
04731:                TSConstRect retValue = null;
04732:                if (pPresentationElements != null) {
04733:                    Iterator peIterator = pPresentationElements.iterator();
04734:                    while (peIterator.hasNext()) {
04735:                        IPresentationElement pe = (IPresentationElement) peIterator
04736:                                .next();
04737:
04738:                        if (pe instanceof  IGraphPresentation) {
04739:                            IETGraphObject element = ((IGraphPresentation) pe)
04740:                                    .getETGraphObject();
04741:                            if (element != null) {
04742:                                if (retValue == null) {
04743:                                    retValue = element.getBounds();
04744:                                } else {
04745:                                    retValue = retValue.union(element
04746:                                            .getBounds());
04747:                                }
04748:                            }
04749:                        }
04750:                    }
04751:                }
04752:                return retValue;
04753:            }
04754:
04755:            //	Used by ExecuteStackingCommand
04756:            private List getSelected(List graphObjects) {
04757:                List retValue = new ArrayList();
04758:                if (graphObjects != null) {
04759:                    Iterator Iter = graphObjects.iterator();
04760:                    while (Iter.hasNext()) {
04761:                        IETGraphObject obj = (IETGraphObject) Iter.next();
04762:                        if (obj.isNode() && obj.isSelected()) {
04763:                            retValue.add(obj);
04764:                        }
04765:                    }
04766:                }
04767:                return retValue;
04768:            }
04769:
04770:            /*
04771:             * Returns the presentation element on the drawing area control with the specified xml id
04772:             *
04773:             * @param sXMLID [in] The presentation element to search for on the diagram.
04774:             * @param pPresentationElement [out,retval] The found presentation element.
04775:             */
04776:            public IPresentationElement findPresentationElement(String sXMLID) {
04777:                return GetHelper.findPresentationElement(getGraphWindow(),
04778:                        getDiagram(), sXMLID);
04779:            }
04780:
04781:            /* (non-Javadoc)
04782:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#fireDrawingAreaContextMenuSelected(org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenu, org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenuItem)
04783:             */
04784:            public void fireDrawingAreaContextMenuSelected(
04785:                    IProductContextMenu contextMenu,
04786:                    IProductContextMenuItem selectedItem) {
04787:                // TODO Auto-generated method stub
04788:            }
04789:
04790:            /* (non-Javadoc)
04791:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#fireTooltipEvent(com.embarcadero.describe.foundation.IPresentationElement, org.netbeans.modules.uml.ui.support.viewfactorysupport.IToolTipData)
04792:             */
04793:            public void fireTooltipEvent(IPresentationElement pPE,
04794:                    IToolTipData pTooltip) {
04795:                // TODO Auto-generated method stub
04796:            }
04797:
04798:            /**
04799:             * Gets the diagram alias
04800:             *
04801:             * @param pVal [out,retval] The alias of the diagram.
04802:             */
04803:            public String getAlias() {
04804:                return m_Alias != null && m_Alias.length() > 0 ? m_Alias
04805:                        : getName();
04806:            }
04807:
04808:            /**
04809:             * Return all the objects on the diagram that are of the indicated type
04810:             *
04811:             * @param sType The element type for the query
04812:             * @return The presentation elements of this type
04813:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllByType(java.lang.String)
04814:             */
04815:            public ETList<IPresentationElement> getAllByType(String sType) {
04816:                return GetHelper.getAllByType(getGraphWindow(), sType);
04817:            }
04818:
04819:            /*
04820:             * Returns a list presentation elements from the search that intersect pRect, null it none found.
04821:             */
04822:            protected ETList<IPresentationElement> getObjectsViaRect(
04823:                    IETRect pRect, boolean bTouchingRect, List searchList) {
04824:                ETList<IPresentationElement> objectIntersectingRect = new ETArrayList<IPresentationElement>();
04825:
04826:                if (searchList != null && pRect != null) {
04827:                    TSConstRect tsRect = RectConversions.etRectToTSRect(pRect);
04828:                    Iterator<IETGraphObject> Iter = searchList.iterator();
04829:                    while (Iter.hasNext()) {
04830:                        IETGraphObject graphObj = Iter.next();
04831:                        IPresentationElement nodePE = TypeConversions
04832:                                .getPresentationElement(graphObj);
04833:
04834:                        if (nodePE != null
04835:                                && (bTouchingRect && graphObj.getBounds()
04836:                                        .intersects(tsRect))
04837:                                || (!bTouchingRect && tsRect.contains(graphObj
04838:                                        .getBounds()))) {
04839:                            objectIntersectingRect.add(nodePE);
04840:                        }
04841:                    }
04842:                }
04843:                return objectIntersectingRect.getCount() > 0 ? objectIntersectingRect
04844:                        : null;
04845:            }
04846:
04847:            /* (non-Javadoc)
04848:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllEdgesViaRect(com.embarcadero.describe.umlsupport.IETRect, boolean)
04849:             */
04850:            public ETList<IPresentationElement> getAllEdgesViaRect(
04851:                    IETRect pRect, boolean bTouchingRect) {
04852:                TSEGraph pGraph = getGraph();
04853:                return pGraph != null ? getObjectsViaRect(pRect, bTouchingRect,
04854:                        pGraph.edges()) : null;
04855:            }
04856:
04857:            /* (non-Javadoc)
04858:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllElementsByDrawEngineType(java.lang.String)
04859:             */
04860:            public ETList<IPresentationElement> getAllElementsByDrawEngineType(
04861:                    String sType) {
04862:                try {
04863:                    if (sType != null && sType.length() > 0) {
04864:                        ETList<IPresentationElement> pFoundPresentationElements = new ETArrayList<IPresentationElement>();
04865:
04866:                        visit(new ETDrawEngineTypesMatchVistor(
04867:                                pFoundPresentationElements, sType));
04868:
04869:                        return pFoundPresentationElements.size() > 0 ? pFoundPresentationElements
04870:                                : null;
04871:                    }
04872:                } catch (Exception e) {
04873:                    e.printStackTrace();
04874:                }
04875:                return null;
04876:            }
04877:
04878:            /*
04879:             * Returns true if all graphobjects were visited.
04880:             */
04881:            public boolean visit(IETGraphObjectVisitor visitor) {
04882:                ETGraphObjectTraversal traversal = new ETGraphObjectTraversal(
04883:                        (ETGraph) this .getGraph());
04884:                traversal.addVisitor(visitor);
04885:                return traversal.traverse();
04886:            }
04887:
04888:            /* (non-Javadoc)
04889:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllElementsByType(java.lang.String)
04890:             */
04891:            public ETList<IElement> getAllElementsByType(String sType) {
04892:                ETList<IElement> elementsOfType = new ETArrayList<IElement>();
04893:
04894:                TSEGraph pGraph = getGraph();
04895:                if (pGraph != null) {
04896:                    addAllByType(elementsOfType, sType, pGraph.nodes());
04897:                    addAllByType(elementsOfType, sType, pGraph.edges());
04898:                }
04899:
04900:                return elementsOfType.size() > 0 ? elementsOfType : null;
04901:            }
04902:
04903:            protected boolean addAllByType(ETList<IElement> elements,
04904:                    String sType, List c) {
04905:                if (c != null) {
04906:                    Iterator<IETGraphObject> iter = c.iterator();
04907:                    while (iter.hasNext()) {
04908:                        IElement element = TypeConversions.getElement(iter
04909:                                .next());
04910:                        if (element != null) {
04911:                            String elementType = element.getElementType();
04912:                            if ((elementType != null)
04913:                                    && elementType.equals(sType)) {
04914:                                elements.add(element);
04915:                            }
04916:                        }
04917:                    }
04918:                    return true;
04919:                }
04920:                return false;
04921:            }
04922:
04923:            /**
04924:             * Returns all the graph objects
04925:             * The stacking order of the output list is from bottom to top.
04926:             *
04927:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllGraphObjects()
04928:             */
04929:            public ETList<TSObject> getAllGraphObjects() {
04930:                ETGraph graph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
04931:                        : null;
04932:                return graph != null ? graph.getAllGraphObjects() : null;
04933:            }
04934:
04935:            /* (non-Javadoc)
04936:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllItems()
04937:             */
04938:            public ETList<IPresentationElement> getAllItems() {
04939:                return GetHelper.getAllItems(m_GraphWindow, getDiagram());
04940:            }
04941:
04942:            /* (non-Javadoc)
04943:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllItems2(com.embarcadero.describe.foundation.IElement)
04944:             */
04945:            public ETList<IPresentationElement> getAllItems2(
04946:                    IElement pModelElement) {
04947:                return GetHelper.getAllItems2(m_GraphWindow, getDiagram(),
04948:                        pModelElement);
04949:            }
04950:
04951:            /*
04952:             * Returns a list of all the model elements on the diagram.
04953:             */
04954:            public ETList<IElement> getAllModelElements() {
04955:                final ETList<IElement> elements = new ETArrayList<IElement>();
04956:                visit(new IETGraphObjectVisitor() {
04957:
04958:                    public boolean visit(IETGraphObject object) {
04959:                        IElement pElement = TypeConversions.getElement(object
04960:                                .getPresentationElement());
04961:                        if (pElement != null) {
04962:                            elements.add(pElement);
04963:                        }
04964:                        return true;
04965:                    }
04966:                });
04967:
04968:                return elements.size() > 0 ? elements : null;
04969:            }
04970:
04971:            /* (non-Javadoc)
04972:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllItems3()
04973:             */
04974:            public ETList<IElement> getAllItems3() {
04975:                return getAllModelElements();
04976:            }
04977:
04978:            /* (non-Javadoc)
04979:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllItems4()
04980:             */
04981:            public ETList<IETGraphObject> getAllItems4() {
04982:                TSEGraph tsGraph = getGraph();
04983:                ETGraph graph = (tsGraph instanceof  ETGraph) ? (ETGraph) tsGraph
04984:                        : null;
04985:                return (graph != null) ? graph.getAllETGraphObjects() : null;
04986:            }
04987:
04988:            /*
04989:             * Retuns a list of all the node and edge labels on the diagram.
04990:             */
04991:            public ETList<IETLabel> getAllLabels() {
04992:                ETGraph graph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
04993:                        : null;
04994:                ETList<IETLabel> retVal = new ETArrayList<IETLabel>();
04995:                if (graph != null) {
04996:                    List nodeLabels = graph.nodeLabels();
04997:                    if (nodeLabels != null) {
04998:                        retVal.addAll(nodeLabels);
04999:                    }
05000:
05001:                    List edgeLabels = graph.edgeLabels();
05002:                    if (edgeLabels != null) {
05003:                        retVal.addAll(edgeLabels);
05004:                    }
05005:                }
05006:                return retVal;
05007:            }
05008:
05009:            /* (non-Javadoc)
05010:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllItems5()
05011:             */
05012:            public ETList<IETLabel> getAllItems5() {
05013:                return getAllLabels();
05014:            }
05015:
05016:            /* (non-Javadoc)
05017:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllItems6()
05018:             */
05019:            public ETList<IETGraphObject> getAllItems6() {
05020:                // In the Java version we don't have IETElement they are graphObjects.
05021:                return getAllItems4();
05022:            }
05023:
05024:            public ETList<IPresentationElement> getAllItems(String topLevelId,
05025:                    String meid) {
05026:                ElementReloader reloader = new ElementReloader();
05027:                IElement foundEle = reloader.getElement(topLevelId, meid);
05028:                return foundEle != null ? getAllItems2(foundEle) : null;
05029:            }
05030:
05031:            /**
05032:             * Returns a list of all the node presentation elements that represent the IElement
05033:             *
05034:             * @param pModelElement [in] The model element for which we need presentation elements for
05035:             * @param pFoundObjects [out,retval] The presentation elements on this diagram which represent pModelElement
05036:             */
05037:            public ETList<IPresentationElement> getAllNodeItems(
05038:                    IElement pModelElement) {
05039:                TSEGraph graph = getCurrentGraph();
05040:                try {
05041:
05042:                    if (graph != null) {
05043:                        ETList<IPresentationElement> pees = getAllItems2(pModelElement);
05044:                        if (pees != null) {
05045:                            int count = pees.size();
05046:                            if (count > 0) {
05047:                                ETList<IPresentationElement> retObj = new ETArrayList<IPresentationElement>();
05048:                                for (int i = 0; i < count; i++) {
05049:                                    IPresentationElement pPE = pees.get(i);
05050:                                    if (pPE instanceof  INodePresentation) {
05051:                                        retObj.add((INodePresentation) pPE);
05052:                                    }
05053:                                }
05054:                                return retObj;
05055:                            }
05056:                        }
05057:
05058:                        return pees.size() > 0 ? pees : null;
05059:                    }
05060:                } catch (Exception e) {
05061:                    ETSystem.out.println(e.toString());
05062:                }
05063:                return null;
05064:            }
05065:
05066:            /* (non-Javadoc)
05067:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getAllNodesViaRect(com.embarcadero.describe.umlsupport.IETRect, boolean)
05068:             */
05069:            public ETList<IPresentationElement> getAllNodesViaRect(
05070:                    IETRect pRect, boolean bTouchingRect) {
05071:                TSEGraph pGraph = getGraph();
05072:                return pGraph != null ? getObjectsViaRect(pRect, bTouchingRect,
05073:                        pGraph.nodes()) : null;
05074:            }
05075:
05076:            /**
05077:             * Are the tooltips enabled?
05078:             *
05079:             * @param bEnabled [out,retval] true if tooltips are enabled.
05080:             */
05081:            public boolean getAreTooltipsEnabled() {
05082:                return m_TooltipsEnabled;
05083:            }
05084:
05085:            /**
05086:             * Returns the diagrams associated with this diagram
05087:             *
05088:             * @param pDiagrams [out,retval] The diagrams associated with this diagram.
05089:             */
05090:            public ETList<IProxyDiagram> getAssociatedDiagrams() {
05091:                ETList<IProxyDiagram> retObj = new ETArrayList<IProxyDiagram>();
05092:                if (m_AssociatedDiagrams != null) {
05093:                    IProxyDiagramManager proxyMgr = ProxyDiagramManager
05094:                            .instance();
05095:                    int count = m_AssociatedDiagrams.size();
05096:                    for (int i = 0; i < count; i++) {
05097:                        String diaName = (String) m_AssociatedDiagrams.get(i);
05098:                        //IProxyDiagram dia = proxyMgr.getDiagram(diaName);
05099:                        IProxyDiagram dia = proxyMgr
05100:                                .getDiagramForXMIID(diaName);
05101:                        if (dia != null) {
05102:                            retObj.add(dia);
05103:                        }
05104:                    }
05105:                }
05106:                return retObj;
05107:            }
05108:
05109:            /**
05110:             * Returns a list of the elements associated with this diagram
05111:             *
05112:             * @param pElements [out,retval] The elements associated with this diagram
05113:             */
05114:            public ETList<IElement> getAssociatedElements() {
05115:                ETList<IElement> retObj = new ETArrayList<IElement>();
05116:                if (m_AssociatedElements != null) {
05117:                    ElementReloader reloader = new ElementReloader();
05118:                    Set keys = m_AssociatedElements.keySet();
05119:                    Collection vals = m_AssociatedElements.values();
05120:                    Iterator<String> iter = keys.iterator();
05121:                    Iterator<String> iter2 = vals.iterator();
05122:
05123:                    while (iter.hasNext()) {
05124:                        //get all the meIds associated with this
05125:                        Object obj = iter2.next();
05126:                        String xmiid = (String) iter.next();
05127:                        if (obj != null && obj instanceof  Vector) {
05128:                            Vector meidCol = (Vector) obj;
05129:                            int count = meidCol.size();
05130:                            for (int i = 0; i < count; i++) {
05131:                                String str = (String) meidCol.get(i);
05132:
05133:                                // xmiid, and meId
05134:                                IElement foundEle = reloader.getElement(xmiid,
05135:                                        str);
05136:                                if (foundEle != null) {
05137:                                    retObj.add(foundEle);
05138:                                }
05139:                            }
05140:                        }
05141:                    }
05142:                }
05143:                return retObj.size() > 0 ? retObj : null;
05144:            }
05145:
05146:            //JM: getCurrentGraph() is not giving the correct value after we close and open the projects and/or ide.
05147:            // hence getting the selected graph from the graph manager.
05148:
05149:            /* (non-Javadoc)
05150:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getCurrentGraph()
05151:             */
05152:            //   public TSEGraph getCurrentGraph()
05153:            //   {
05154:            //      // We need to store the graph for the web report.
05155:            //      if (this.m_graph == null && m_GraphWindow != null)
05156:            //      {
05157:            //         m_graph = m_GraphWindow.getGraph();
05158:            //      }
05159:            //      return this.m_graph;
05160:            //   }
05161:            public TSEGraph getCurrentGraph() {
05162:                m_graph = this .getGraphManager().selectedGraph();
05163:                return m_graph;
05164:            }
05165:
05166:            /* (non-Javadoc)
05167:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getCurrentGraphManager()
05168:             */
05169:            public TSGraphManager getCurrentGraphManager() {
05170:                return getGraphWindow() != null ? getGraphWindow()
05171:                        .getGraphManager() : null;
05172:            }
05173:
05174:            /* (non-Javadoc)
05175:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getCurrentZoom()
05176:             */
05177:            public double getCurrentZoom() {
05178:                double zoom = 1.0;
05179:
05180:                if (getGraphWindow() != null) {
05181:                    zoom = getGraphWindow().getZoomLevel();
05182:                }
05183:
05184:                return zoom;
05185:            }
05186:
05187:            /**
05188:             * Returns the IDiagram that represents this active x control
05189:             *
05190:             * @param pDiagram [out,retval] Returns the diagram that represents this activex control.  The IDiagram
05191:             * acts as a proxy for the control.
05192:             */
05193:            public IDiagram getDiagram() {
05194:                IDiagram retDia = null;
05195:                if (m_Diagram == null && getDiagramKind2().length() > 0) {
05196:                    IDiagramTypesManager pMgr = DiagramTypesManager.instance();
05197:                    String diaType = pMgr.getUMLType(getDiagramKind2());
05198:                    if (diaType == null) {
05199:                        diaType = "";
05200:                    }
05201:
05202:                    if (diaType.length() > 0) {
05203:                        Object obj = FactoryRetriever.instance().createType(
05204:                                diaType, null);
05205:                        if (obj instanceof  IDiagram) {
05206:                            m_Diagram = (IDiagram) obj;
05207:                        }
05208:
05209:                        if (m_Diagram != null) {
05210:                            retDia = m_Diagram;
05211:                            setDiagramNodeNameAndOwner();
05212:
05213:                            // Set the backpointer on the IDiagram to point to this active x control
05214:                            if (m_Diagram instanceof  IUIDiagram) {
05215:                                IUIDiagram axDia = (IUIDiagram) m_Diagram;
05216:                                axDia.setDrawingArea(this );
05217:                            }
05218:                        }
05219:                    }
05220:
05221:                    if (m_DiagramXmiid != null && m_DiagramXmiid.length() > 0
05222:                            && m_Diagram != null) {
05223:                        m_Diagram.setXMIID(m_DiagramXmiid);
05224:                    }
05225:                } else if (m_Diagram != null) {
05226:                    retDia = m_Diagram;
05227:                }
05228:
05229:                return retDia;
05230:            }
05231:
05232:            /* (non-Javadoc)
05233:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getDiagramEngine()
05234:             */
05235:            public IDiagramEngine getDiagramEngine() {
05236:                return m_DiagramEngine;
05237:            }
05238:
05239:            public String getDiagramKind2() {
05240:                return m_DiagramKindDisplayName;
05241:            }
05242:
05243:            /* (non-Javadoc)
05244:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getDiagramWindowHandle()
05245:             */
05246:            public int getDiagramWindowHandle() {
05247:                // TODO Auto-generated method stub
05248:                return 0;
05249:            }
05250:
05251:            /* (non-Javadoc)
05252:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getDocumentation()
05253:             */
05254:            public String getDocumentation() {
05255:                return m_Documentation;
05256:            }
05257:
05258:            /* (non-Javadoc)
05259:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getEdgeDescription()
05260:             */
05261:            public String getEdgeDescription() {
05262:                // TODO Auto-generated method stub
05263:                return null;
05264:            }
05265:
05266:            /* (non-Javadoc)
05267:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getExtremeZoomValues(double, double)
05268:             */
05269:            public ETPairT<Double, Double> getExtremeZoomValues() {
05270:                // Don't let the user zoom to far in when we are drawing on the sequenece diagram.
05271:                if (getDiagramKind() != DiagramEnums.DK_SEQUENCE_DIAGRAM
05272:                        && this .getDiagram() != null) {
05273:                    return getDiagram().getExtremeZoomValues();
05274:                } else {
05275:                    return new ETPairT<Double, Double>(new Double(0.05),
05276:                            new Double(4.0));
05277:                }
05278:            }
05279:
05280:            // Watch out! this does not work
05281:            public TSGraphObject getGraphObjectAtMouse(int logicalX,
05282:                    int logicalY) {
05283:                TSGraphObject retObj = null;
05284:                if (getGraphWindow() != null) {
05285:                    TSEWindowTool tool = getGraphWindow().getCurrentTool();
05286:                    if (tool != null) {
05287:                        //convert to world points
05288:                        Point p = getGraphWindow().getCanvas()
05289:                                .getLocationOnScreen();
05290:                        TSConstPoint newPoint = new TSConstPoint(
05291:                                (double) logicalX + p.x, (double) logicalY
05292:                                        + p.y);
05293:                        retObj = (TSGraphObject) tool.getHitTesting()
05294:                                .getGraphObjectAt(new TSConstPoint(newPoint),
05295:                                        this .getGraph(), true);
05296:                    }
05297:                }
05298:                return retObj;
05299:            }
05300:
05301:            /* (non-Javadoc)
05302:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getGridSize()
05303:             */
05304:            public int getGridSize() {
05305:                // TODO Auto-generated method stub
05306:                return 0;
05307:            }
05308:
05309:            /* (non-Javadoc)
05310:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getGridType()
05311:             */
05312:            public int getGridType() {
05313:                // TODO Auto-generated method stub
05314:                return 0;
05315:            }
05316:
05317:            /* (non-Javadoc)
05318:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getHasChildGraph(com.tomsawyer.graph.TSNode)
05319:             */
05320:            public boolean getHasChildGraph(TSNode pNode) {
05321:                // TODO Auto-generated method stub
05322:                return false;
05323:            }
05324:
05325:            /* (non-Javadoc)
05326:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getHasParentGraph()
05327:             */
05328:            public boolean getHasParentGraph() {
05329:                // TODO Auto-generated method stub
05330:                return false;
05331:            }
05332:
05333:            /* (non-Javadoc)
05334:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getHasSelected(boolean)
05335:             */
05336:            public boolean getHasSelected(boolean bDeep) {
05337:                return this .getGraphManager().selectedGraph().hasSelected();
05338:            }
05339:
05340:            /* (non-Javadoc)
05341:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getHasSelectedEdges(boolean)
05342:             */
05343:            public boolean getHasSelectedEdges(boolean bDeep) {
05344:                TSEGraph pGraph = this .getCurrentGraph();
05345:                return pGraph != null ? pGraph.hasSelectedEdges() : false;
05346:            }
05347:
05348:            /* (non-Javadoc)
05349:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getHasSelectedLabels(boolean)
05350:             */
05351:            public boolean getHasSelectedLabels(boolean bDeep) {
05352:                TSEGraph pGraph = this .getCurrentGraph();
05353:                return pGraph != null ? pGraph.hasSelectedEdgeLabels()
05354:                        || pGraph.hasSelectedNodeLabels() : false;
05355:            }
05356:
05357:            /* (non-Javadoc)
05358:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getHasSelectedNodes(boolean)
05359:             */
05360:            public boolean getHasSelectedNodes(boolean bDeep) {
05361:                return this .getGraphManager().selectedGraph()
05362:                        .hasSelectedNodes();
05363:            }
05364:
05365:            /**
05366:             * IsDirty is true when there is data that needs to be saved
05367:             *
05368:             * @param bIsDirty [out,retval] true if this diagram needs to be saved.
05369:             */
05370:            public boolean getIsDirty() {
05371:                return m_isDirty;
05372:            }
05373:
05374:            /**
05375:             * Returns true if the model element is displayed in the diagram, NOT whether its in the viewport.
05376:             *
05377:             * @param pModelElement [in] The model element to query
05378:             * @param bIsDisplayed [out,retval] true if this model element is displayed.
05379:             */
05380:            public boolean getIsDisplayed(IElement pModelElement) {
05381:                final IElement pSearchForElement = pModelElement;
05382:                boolean visitedAll = visit(new IETGraphObjectVisitor() {
05383:
05384:                    public boolean visit(IETGraphObject object) {
05385:                        IElement pElement = TypeConversions.getElement(object
05386:                                .getPresentationElement());
05387:                        if (pElement != null
05388:                                && pElement.isSame(pSearchForElement)) {
05389:                            return false; // Break the traversal.
05390:                        }
05391:                        return true;
05392:                    }
05393:                });
05394:                return !visitedAll;
05395:            }
05396:
05397:            /* (non-Javadoc)
05398:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getIsGraphPreferencesDialogOpen()
05399:             */
05400:            public boolean getIsGraphPreferencesDialogOpen() {
05401:                return graphPreferencesDialog != null
05402:                        && graphPreferencesDialog.isVisible();
05403:            }
05404:
05405:            /* (non-Javadoc)
05406:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getIsLayoutPropertiesDialogOpen()
05407:             */
05408:            public boolean getIsLayoutPropertiesDialogOpen() {
05409:                return layoutPropertiesDialog != null
05410:                        && layoutPropertiesDialog.isVisible();
05411:            }
05412:
05413:            /* (non-Javadoc)
05414:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getIsOverviewWindowOpen()
05415:             */
05416:            public boolean getIsOverviewWindowOpen() {
05417:                return this .isOverviewWindowOpen();
05418:            }
05419:
05420:            /* (non-Javadoc)
05421:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getLastSelectedButton()
05422:             */
05423:            public int getLastSelectedButton() {
05424:                // TODO Auto-generated method stub
05425:                return 0;
05426:            }
05427:
05428:            /* (non-Javadoc)
05429:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getLayoutRunning()
05430:             */
05431:            public boolean getLayoutRunning() {
05432:                // TODO Auto-generated method stub
05433:                return false;
05434:            }
05435:
05436:            /* (non-Javadoc)
05437:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getMidPoint(com.tomsawyer.graph.TSEdge, com.embarcadero.describe.umlsupport.IETPoint)
05438:             */
05439:            public IETPoint getMidPoint(TSEdge pEdge) {
05440:                return GetHelper.getMidPoint((IETEdge) pEdge);
05441:            }
05442:
05443:            /* (non-Javadoc)
05444:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getModelElement()
05445:             */
05446:            public IElement getModelElement() {
05447:                return modelElement;
05448:            }
05449:
05450:            /* (non-Javadoc)
05451:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getModeLocked()
05452:             */
05453:            public boolean getModeLocked() {
05454:                // TODO Auto-generated method stub
05455:                return false;
05456:            }
05457:
05458:            /* (non-Javadoc)
05459:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getNamespace()
05460:             */
05461:            public INamespace getNamespace() {
05462:                if (m_Namespace == null) {
05463:                    //get the project namespace
05464:                    IApplication pApp = ProductHelper.getApplication();
05465:                    if (pApp != null) {
05466:                        if (pApp.getNumOpenedProjects() > 0) {
05467:                            m_Namespace = pApp.getProjects().get(0);
05468:                        }
05469:                        //namespace = pApp.getProjectByFileName(s_sProjectLocation);
05470:                    }
05471:                }
05472:                return m_Namespace;
05473:            }
05474:
05475:            /**
05476:             * Returns the the namespace to use when elements are created on the diagram.  Usually this
05477:             * is the same as the namespace of the diagram
05478:             *
05479:             * @param pNamespace [out,retval] The namespace that owns this diagram.
05480:             */
05481:            public INamespace getNamespaceForCreatedElements() {
05482:                return m_DiagramEngine != null ? m_DiagramEngine
05483:                        .getNamespaceForCreatedElements() : getNamespace();
05484:            }
05485:
05486:            /**
05487:             * Sets / Gets the name or alias of this element.
05488:             */
05489:            public String getNameWithAlias() {
05490:                return ProductHelper.getShowAliasedNames() ? getAlias()
05491:                        : getName();
05492:            }
05493:
05494:            /* (non-Javadoc)
05495:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getNodeDescription()
05496:             */
05497:            public String getNodeDescription() {
05498:                StringBuffer nodeDesc = new StringBuffer(
05499:                        m_NodeInitializationString.m_TSInitializationString);
05500:
05501:                if (m_NodeInitializationString.m_ObjectInitializersString
05502:                        .length() > 0) {
05503:                    nodeDesc.append(" ");
05504:                    nodeDesc
05505:                            .append(m_NodeInitializationString.m_ObjectInitializersString);
05506:                }
05507:
05508:                return nodeDesc.toString();
05509:            }
05510:
05511:            /* (non-Javadoc)
05512:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getOverviewWindowRect(int, int, int, int)
05513:             */
05514:            public IETRect getOverviewWindowRect() {
05515:                if (this .overviewWindow != null) {
05516:                    return new ETRect(overviewWindow.getBounds());
05517:                } else if (this .overviewBounds != null) {
05518:                    return new ETRect(overviewBounds);
05519:                }
05520:                return null;
05521:            }
05522:
05523:            /* (non-Javadoc)
05524:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getPreferenceValue(java.lang.String, java.lang.String)
05525:             */
05526:            public String getPreferenceValue(String sPath, String sName) {
05527:                throw new UnsupportedOperationException(
05528:                        "this should never happen.");
05529:                //      String sValue = "";
05530:                //      boolean bFoundInCache = false;
05531:                //      if(sPath != null && sName != null)
05532:                //      {
05533:                //         if (sPath.equals("Diagrams"))
05534:                //         {
05535:                //            if (m_CachedPreferences.get(sName) != null)
05536:                //            {
05537:                //               sValue = m_CachedPreferences.get(sName);
05538:                //
05539:                //               bFoundInCache = true;
05540:                //            }
05541:                //         }
05542:                //      }
05543:                //
05544:                //      if (!bFoundInCache)
05545:                //      {
05546:                //         IPreferenceManager2 pMgr = ProductHelper.getPreferenceManager();
05547:                //         if (pMgr != null)
05548:                //         {
05549:                //            String sData = pMgr.getPreferenceValue( sPath, sName);
05550:                //            if (sData != null && sData.length() > 0)
05551:                //            {
05552:                //               sValue = sData;
05553:                //            }
05554:                //         }
05555:                //
05556:                //         // Add to our cache if the pref hive is Diagrams
05557:                //         if (sPath.equals("Diagrams"))
05558:                //         {
05559:                //            m_CachedPreferences.put(sName, sValue);
05560:                //         }
05561:                //      }
05562:                //      return sValue;
05563:            }
05564:
05565:            /* (non-Javadoc)
05566:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getPresentationTypesMgr()
05567:             */
05568:            public IPresentationTypesMgr getPresentationTypesMgr() {
05569:                return m_PresentationTypesMgr;
05570:            }
05571:
05572:            /**
05573:             * Returns the current toplevel IProject for this diagram
05574:             *
05575:             * @param pProject [out,retval] The toplevel project of the namespace owning this diagram.
05576:             */
05577:            public IProject getProject() {
05578:                return m_Namespace != null ? m_Namespace.getProject() : null;
05579:            }
05580:
05581:            /**
05582:             * Returns the proxy diagram for this diagram
05583:             *
05584:             * @param pProxyDiagram [out,retval] The proxy diagram representing this diagram.
05585:             */
05586:            public IProxyDiagram getProxyDiagram() {
05587:                return getProxyDiagram(m_FileName);
05588:            }
05589:
05590:            /**
05591:             * Uses a IProxyDiagramManager to determine the IProxyDiagram from a full path filename
05592:             *
05593:             * @param bsFilename [in] Path to the file containing the diagram
05594:             * @param pProxyDiagram [out] The proxy diagram
05595:             *
05596:             * @return HRESULT
05597:             */
05598:            public IProxyDiagram getProxyDiagram(String filename) {
05599:                return ProxyDiagramManager.instance().getDiagram(filename);
05600:            }
05601:
05602:            /**
05603:             * Gets the fully qualified diagram name
05604:             *
05605:             * @param pVal [out,retval] The fully qualified name of the diagram.
05606:             */
05607:            public String getQualifiedName() {
05608:                String retVal = "";
05609:                String diaName = getName();
05610:                INamespace space = getNamespace();
05611:                boolean includeProjName = ProductHelper
05612:                        .useProjectInQualifiedName();
05613:                if (diaName != null && diaName.length() > 0 && space != null) {
05614:                    boolean isProject = false;
05615:                    if (space instanceof  IProject) {
05616:                        isProject = true;
05617:                    }
05618:
05619:                    if (!includeProjName && isProject) {
05620:                        retVal = diaName;
05621:                    } else {
05622:                        retVal = space.getQualifiedName();
05623:                        retVal += "::";
05624:                        retVal += diaName;
05625:                    }
05626:                }
05627:                return retVal;
05628:            }
05629:
05630:            /**
05631:             * Is this diagram readonly?
05632:             *
05633:             * @param pVal [out,retval] true if the diagram is readonly
05634:             */
05635:            public boolean getReadOnly() {
05636:                return m_ReadOnly;
05637:            }
05638:
05639:            /* (non-Javadoc)
05640:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getRelationshipDiscovery()
05641:             */
05642:            public ICoreRelationshipDiscovery getRelationshipDiscovery() {
05643:                return getDiagramEngine() != null ? getDiagramEngine()
05644:                        .getRelationshipDiscovery() : null;
05645:            }
05646:
05647:            /*
05648:             *	Retuns a list of selected presentation elements.
05649:             */
05650:            public ETList<IPresentationElement> getSelected() {
05651:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
05652:                        : null;
05653:                if (etGraph != null) {
05654:                    ETList<IPresentationElement> selectdPes = new ETArrayList<IPresentationElement>();
05655:                    ETList<TSGraphObject> selected = etGraph
05656:                            .getSelectedObjects(false, false);
05657:                    if (selected != null) {
05658:                        Iterator<TSGraphObject> iter = selected.iterator();
05659:                        while (iter.hasNext()) {
05660:                            TSGraphObject tsObj = iter.next();
05661:                            IETGraphObject obj = tsObj instanceof  IETGraphObject ? (IETGraphObject) tsObj
05662:                                    : null;
05663:                            IPresentationElement pe = obj != null ? obj
05664:                                    .getPresentationElement() : null;
05665:                            if (pe != null) {
05666:                                selectdPes.add(pe);
05667:                            }
05668:                        }
05669:                    }
05670:                    return selectdPes.size() > 0 ? selectdPes : null;
05671:                }
05672:                return null;
05673:            }
05674:
05675:            public ETList<IPresentationElement> getSelectedPresentionNodes() {
05676:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
05677:                        : null;
05678:
05679:                if (etGraph != null) {
05680:                    ETList<IPresentationElement> selectdPes = new ETArrayList<IPresentationElement>();
05681:
05682:                    ETList<TSGraphObject> selected = etGraph
05683:                            .getSelectedObjects(false, false);
05684:
05685:                    if (selected != null) {
05686:                        Iterator<TSGraphObject> iter = selected.iterator();
05687:
05688:                        while (iter.hasNext()) {
05689:                            TSGraphObject tsObj = iter.next();
05690:
05691:                            IETGraphObject obj = tsObj instanceof  IETGraphObject ? (IETGraphObject) tsObj
05692:                                    : null;
05693:
05694:                            IPresentationElement pe = obj != null ? obj
05695:                                    .getPresentationElement() : null;
05696:
05697:                            if (pe != null && pe instanceof  INodePresentation) {
05698:                                selectdPes.add(pe);
05699:                            }
05700:                        }
05701:                    }
05702:
05703:                    return selectdPes.size() > 0 ? selectdPes : null;
05704:                }
05705:
05706:                return null;
05707:            }
05708:
05709:            public void deselectAll() {
05710:                ETList<IETGraphObject> graphObjects = getSelected3();
05711:
05712:                if (graphObjects == null || graphObjects.size() == 0) {
05713:                    return;
05714:                }
05715:                for (IETGraphObject graphObj : graphObjects) {
05716:                    graphObj.setSelected(false);
05717:                    graphObj.invalidate();
05718:                }
05719:
05720:                getGraph().deselectAll();
05721:                //invalidate();
05722:                refresh(true);
05723:            }
05724:
05725:            public void selectThese(List<IETGraphObject> graphObjects) {
05726:                if (graphObjects == null || graphObjects.size() == 0) {
05727:                    return;
05728:                }
05729:                for (IETGraphObject graphObj : graphObjects) {
05730:                    graphObj.setSelected(true);
05731:                }
05732:
05733:                getGraphWindow().drawGraph();
05734:                fireSelectEvent(graphObjects);
05735:                refresh(true);
05736:            }
05737:
05738:            /**
05739:             * Returns a list of the selected items (nodes and edges).
05740:             */
05741:            public ETList<IETGraphObject> getSelectedNodesAndEdges() {
05742:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
05743:                        : null;
05744:                if (etGraph != null) {
05745:                    ETList<IETGraphObject> selected = new ETArrayList<IETGraphObject>();
05746:                    List selectedNodes = etGraph.selectedNodes();
05747:                    if (selectedNodes != null) {
05748:                        selected.addAll(selectedNodes);
05749:                    }
05750:                    List selectedEdges = etGraph.selectedEdges();
05751:                    if (selectedEdges != null) {
05752:                        selected.addAll(selectedEdges);
05753:                    }
05754:                    return selected.size() > 0 ? selected : null;
05755:                }
05756:                return null;
05757:            }
05758:
05759:            /**
05760:             * Returns a list of the selected items (nodes and edges).
05761:             */
05762:            public ETList<IETGraphObject> getSelectedNodes() {
05763:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
05764:                        : null;
05765:
05766:                if (etGraph != null) {
05767:                    ETList<IETGraphObject> selected = new ETArrayList<IETGraphObject>();
05768:                    List selectedNodes = etGraph.selectedNodes();
05769:
05770:                    if (selectedNodes != null) {
05771:                        selected.addAll(selectedNodes);
05772:                    }
05773:                    return selected.size() > 0 ? selected : null;
05774:                }
05775:
05776:                return null;
05777:            }
05778:
05779:            public ETList<IPresentationElement> getSelectedNodes2() {
05780:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
05781:                        : null;
05782:
05783:                if (etGraph != null) {
05784:                    ETList<IPresentationElement> selected = new ETArrayList<IPresentationElement>();
05785:
05786:                    List selectedNodes = etGraph.selectedNodes();
05787:
05788:                    if (selectedNodes != null) {
05789:                        selected.addAll(selectedNodes);
05790:                    }
05791:                    return selected.size() > 0 ? selected : null;
05792:                }
05793:
05794:                return null;
05795:            }
05796:
05797:            /**
05798:             * Returns a list of the selected items (nodes and edges).
05799:             */
05800:            public ETList<IETGraphObject> getSelected2() {
05801:                return getSelectedNodesAndEdges();
05802:            }
05803:
05804:            /**
05805:             * Returns a list of the selected items (nodes, edges and nodelabels and edgeLabels).
05806:             */
05807:            public ETList<IETGraphObject> getSelected3() {
05808:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
05809:                        : null;
05810:
05811:                if (etGraph != null) {
05812:                    // Get the selected nodes and edges.
05813:                    ETList<IETGraphObject> selected = getSelected2();
05814:                    selected = selected != null ? selected
05815:                            : new ETArrayList<IETGraphObject>();
05816:
05817:                    // Now tack on the labels.
05818:                    List selectedNodeLabels = etGraph.selectedNodeLabels();
05819:                    if (selectedNodeLabels != null) {
05820:                        selected.addAll(selectedNodeLabels);
05821:                    }
05822:                    List selectedEdgeLabels = etGraph.selectedEdgeLabels();
05823:                    if (selectedEdgeLabels != null) {
05824:                        selected.addAll(selectedEdgeLabels);
05825:                    }
05826:                    return selected.size() > 0 ? selected : null;
05827:                }
05828:                return null;
05829:            }
05830:
05831:            public ETList<IElement> getSelectedElements() {
05832:                ETList<IPresentationElement> selected = getSelected();
05833:                if (selected != null) {
05834:                    ETList<IElement> elements = new ETArrayList<IElement>();
05835:                    Iterator<IPresentationElement> iter = selected.iterator();
05836:                    while (iter.hasNext()) {
05837:                        elements.addAll(iter.next().getSubjects());
05838:                    }
05839:                    return elements.size() > 0 ? elements : null;
05840:                }
05841:                return null;
05842:            }
05843:
05844:            /* (non-Javadoc)
05845:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getSelected4()
05846:             */
05847:            public ETList<IElement> getSelected4() {
05848:                return getSelectedElements();
05849:            }
05850:
05851:            /* (non-Javadoc)
05852:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getSelectedByType(java.lang.String)
05853:             */
05854:            public ETList<IPresentationElement> getSelectedByType(String sType) {
05855:                // TODO Auto-generated method stub
05856:                return null;
05857:            }
05858:
05859:            /* (non-Javadoc)
05860:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getSelectedLabels()
05861:             */
05862:            public ETList<IETLabel> getSelectedLabels() {
05863:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
05864:                        : null;
05865:
05866:                if (etGraph != null) {
05867:                    // Get the selected nodes and edges.
05868:                    ETList<IETLabel> selected = new ETArrayList<IETLabel>();
05869:                    // Now tack on the labels.
05870:                    List selectedNodeLabels = etGraph.selectedNodeLabels();
05871:                    if (selectedNodeLabels != null) {
05872:                        selected.addAll(selectedNodeLabels);
05873:                    }
05874:                    List selectedEdgeLabels = etGraph.selectedEdgeLabels();
05875:                    if (selectedEdgeLabels != null) {
05876:                        selected.addAll(selectedEdgeLabels);
05877:                    }
05878:                    return selected.size() > 0 ? selected : null;
05879:                }
05880:                return null;
05881:            }
05882:
05883:            /* (non-Javadoc)
05884:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getShowGrid()
05885:             */
05886:            public boolean getShowGrid() {
05887:                // TODO Auto-generated method stub
05888:                return false;
05889:            }
05890:
05891:            /* (non-Javadoc)
05892:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getTrackBar()
05893:             */
05894:            public JTrackBar getTrackBar() {
05895:                return m_TrackBar;
05896:            }
05897:
05898:            /* (non-Javadoc)
05899:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getWindowHandle()
05900:             */
05901:            public int getWindowHandle() {
05902:                // TODO Auto-generated method stub
05903:                return 0;
05904:            }
05905:
05906:            /* (non-Javadoc)
05907:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#goToChildGraph(com.tomsawyer.graph.TSNode)
05908:             */
05909:            public void goToChildGraph(TSNode pNode) {
05910:                // TODO Auto-generated method stub
05911:            }
05912:
05913:            /* (non-Javadoc)
05914:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#goToParentGraph()
05915:             */
05916:            public void goToParentGraph() {
05917:                // TODO Auto-generated method stub
05918:            }
05919:
05920:            /**
05921:             * This method creates the drawing preferences dialog.
05922:             */
05923:            public void createGraphPreferencesDialog() {
05924:                String title = RESOURCE_BUNDLE
05925:                        .getString("IDS_GRAPH_PROPERTIES_DLG_TITLE");
05926:
05927:                this .graphPreferencesDialog = new ETDrawingPreferencesDialog(
05928:                        this .getOwnerFrame(), title, this .getGraphWindow());
05929:
05930:                this .graphPreferencesDialog
05931:                        .setLocationRelativeTo(SwingUtilities.getRootPane(this ));
05932:
05933:                this .graphPreferencesDialog
05934:                        .addWindowListener(this .windowHandler);
05935:            }
05936:
05937:            /* (non-Javadoc)
05938:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#graphPreferencesDialog(boolean)
05939:             */
05940:            public void graphPreferencesDialog(boolean bShow) {
05941:                if (bShow && this .graphPreferencesDialog == null) {
05942:                    this .createGraphPreferencesDialog();
05943:                }
05944:
05945:                if (graphPreferencesDialog != null) {
05946:                    graphPreferencesDialog.setVisible(bShow);
05947:                }
05948:                this .repaint();
05949:            }
05950:
05951:            /* (non-Javadoc)
05952:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#handleDeepSyncBroadcast(com.embarcadero.describe.foundation.IElement[], boolean)
05953:             */
05954:            public void handleDeepSyncBroadcast(IElement[] pElements,
05955:                    boolean bSizeToContents) {
05956:                // TODO Auto-generated method stub
05957:            }
05958:
05959:            /*
05960:             *	Returns true if it was handled.
05961:             */
05962:            public boolean onDeleteKeyDown(boolean bAskUserAboutDelete) {
05963:                // Make sure we are not in move selected mode, or the app will crash becuase the selection
05964:                // Lists should not change will in this mode.
05965:                if (!(getGraphWindow().getCurrentTool() instanceof  ADMoveSelectedState)) {
05966:                    ETElementManager manager = new ETElementManager(this );
05967:                    manager.onPreDeleteGatherSelected();
05968:
05969:                    if (getDiagramEngine() != null) {
05970:                        IDiagramEngine engine = getDiagramEngine();
05971:                        if (engine.preHandleDeleteKey() == false) {
05972:                            // Guys please see public ETList < TSGraphObject > ETGraph.getSelectedObjects()
05973:                            // This is a mess.
05974:                            ETArrayList<TSENode> selectedNodes = new ETArrayList();
05975:                            ETArrayList<TSEEdge> selectedEdges = new ETArrayList();
05976:                            ETArrayList<TSENodeLabel> selectedNodeLabels = new ETArrayList();
05977:                            ETArrayList<TSEEdgeLabel> selectedEdgeLabels = new ETArrayList();
05978:                            gatherSelectedItems(selectedNodes, selectedEdges,
05979:                                    selectedNodeLabels, selectedEdgeLabels);
05980:
05981:                            //verify that something is selected
05982:                            if (selectedNodes.size() > 0
05983:                                    || selectedEdges.size() > 0
05984:                                    || selectedNodeLabels.size() > 0
05985:                                    || selectedEdgeLabels.size() > 0) {
05986:                                // TODO:  In C++ this was a stored registry value
05987:                                boolean bDefaultDeleteModelElements = true;
05988:
05989:                                ETTripleT<Integer, Boolean, Boolean> deleteWithAlsoResult = null;
05990:                                DataVerificationResults results = null;
05991:
05992:                                // Determine if there are any combined fragments in the selected nodes
05993:                                if (containsModelElement(selectedNodes,
05994:                                        ICombinedFragment.class)) {
05995:                                    // Ask the user if he wants to delete the objects, and
05996:                                    // possibly also the message associated with the message connectors
05997:                                    IPreferenceQuestionDialog cpQuestionDialog = new SwingPreferenceQuestionDialog();
05998:                                    if (cpQuestionDialog != null) {
05999:                                        String strKey = "Default";
06000:                                        String strPath = "Diagrams|SequenceDiagram";
06001:                                        String strName = "UML_ShowMe_Delete_Combined_Fragment_Messages";
06002:                                        String strAlsoQuestion = RESOURCE_BUNDLE
06003:                                                .getString("IDS_ALSO_DELETE_CF_MESSAGES");
06004:                                        deleteWithAlsoResult = cpQuestionDialog
06005:                                                .displayDeleteWithAlso(
06006:                                                        strKey,
06007:                                                        strPath,
06008:                                                        strName,
06009:                                                        bDefaultDeleteModelElements,
06010:                                                        strAlsoQuestion);
06011:
06012:                                        Boolean bDeleteMessagesAlso = (Boolean) deleteWithAlsoResult
06013:                                                .getParamThree();
06014:                                        if (bDeleteMessagesAlso.booleanValue()) {
06015:                                            selectCombinedFragmentMessages(selectedNodes);
06016:                                        }
06017:                                    }
06018:                                } else if (containsModelElement(selectedEdges,
06019:                                        IMessageConnector.class)) {
06020:                                    // Ask the user if he wants to delete the objects, and
06021:                                    // possibly also the message associated with the message connectors
06022:                                    IPreferenceQuestionDialog cpQuestionDialog = new SwingPreferenceQuestionDialog();
06023:                                    if (cpQuestionDialog != null) {
06024:                                        String bsKey = "Default";
06025:                                        String bsPath = "Diagrams|CollaborationDiagram";
06026:                                        String bsName = "UML_ShowMe_Delete_Connector_Messages";
06027:                                        String bsAlsoQuestion = RESOURCE_BUNDLE
06028:                                                .getString("IDS_ALSO_DELETE_MESSAGES");
06029:                                        deleteWithAlsoResult = cpQuestionDialog
06030:                                                .displayDeleteWithAlso(
06031:                                                        bsKey,
06032:                                                        bsPath,
06033:                                                        bsName,
06034:                                                        bDefaultDeleteModelElements,
06035:                                                        bsAlsoQuestion);
06036:                                        Boolean bDeleteMessagesAlso = (Boolean) deleteWithAlsoResult
06037:                                                .getParamThree();
06038:                                        if (bDeleteMessagesAlso.booleanValue()) {
06039:                                            selectMessageConnectorMessages(
06040:                                                    selectedEdges,
06041:                                                    selectedEdgeLabels);
06042:                                        }
06043:
06044:                                        boolean canceled = true;
06045:                                        Integer val = (Integer) deleteWithAlsoResult
06046:                                                .getParamOne();
06047:                                        if (val.intValue() > 0) {
06048:                                            canceled = true;
06049:                                        } else {
06050:                                            canceled = false;
06051:                                        }
06052:                                        Boolean affectModel = (Boolean) deleteWithAlsoResult
06053:                                                .getParamTwo();
06054:                                        results = new DataVerificationResults(
06055:                                                canceled, affectModel
06056:                                                        .booleanValue());
06057:                                    }
06058:                                } else {
06059:                                    results = engine.verifyDataDeletion(
06060:                                            selectedNodes, selectedEdges,
06061:                                            selectedNodeLabels,
06062:                                            selectedEdgeLabels);
06063:                                }
06064:
06065:                                if (deleteWithAlsoResult != null) {
06066:                                    Integer val = (Integer) deleteWithAlsoResult
06067:                                            .getParamOne();
06068:                                    boolean canceled = val.intValue() > 0;
06069:                                    Boolean affectModel = (Boolean) deleteWithAlsoResult
06070:                                            .getParamTwo();
06071:                                    results = new DataVerificationResults(
06072:                                            canceled, affectModel
06073:                                                    .booleanValue());
06074:                                }
06075:
06076:                                if (results.isCancelAction() == false) {
06077:                                    manager.onPreDelete();
06078:                                    ETList<TSObject> selected = new ETArrayList();
06079:                                    selected.addAll(selectedNodes);
06080:                                    selected.addAll(selectedEdges);
06081:                                    selected.addAll(selectedNodeLabels);
06082:                                    selected.addAll(selectedEdgeLabels);
06083:                                    removeGraphObjects(selected, results
06084:                                            .isAffectModelElement(), results
06085:                                            .getRemoveFromImport());
06086:
06087:                                    // Tell the world that the select list has changed.
06088:                                    postSelectEvent();
06089:                                    //Also clear  m_lastSelectedNode & lastSelectedlabel
06090:                                    m_lastSelectedNode = null;
06091:                                    m_lastSelectedLabel = null;
06092:                                } else {
06093:                                    manager.onDeleteCancelled();
06094:                                }
06095:                            }
06096:                        }
06097:                    }
06098:                    this .refresh(true);
06099:                    return true;
06100:                }
06101:                return false;
06102:            }
06103:
06104:            /* (non-Javadoc)
06105:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#handleKeyDown(int, int, boolean)
06106:             */
06107:            public boolean handleKeyDown(int nKeyCode, int nShift,
06108:                    boolean bAskUserAboutDelete) {
06109:                boolean handled = false;
06110:                if (!handled) {
06111:                    ETElementManager manager = new ETElementManager(this );
06112:                    handled = manager.onKeyDown(nKeyCode, nShift);
06113:                }
06114:
06115:                if (!handled && !getReadOnly()) {
06116:                    // If no one handled it, then see if its a VK_DELETE, in that case
06117:                    // we need to handle the delete ourselves.  With TS 5.1 we need to move this,
06118:                    // in 5.0 TS has a bug where the predelete is fired AFTER all edges have been
06119:                    // removed!
06120:                    if (nKeyCode == KeyEvent.VK_DELETE) {
06121:                        handled = onDeleteKeyDown(bAskUserAboutDelete);
06122:                    }
06123:
06124:                    //Jyothi: cycle through nodes when tab/shift-tab is pressed
06125:                    if (nKeyCode == KeyEvent.VK_TAB) {
06126:                        //             System.err.println(" tab key pressed !");
06127:                        handled = onTabKeyDown(nShift);
06128:                    }
06129:
06130:                    //cycle through edges when shift up/down is pressed
06131:                    if ((nShift == 0)
06132:                            && ((nKeyCode == KeyEvent.VK_UP) || (nKeyCode == KeyEvent.VK_DOWN))) {
06133:                        //             System.err.println(" shift up/down pressed! ");
06134:                        handled = onShiftUpDown(nKeyCode, nShift);
06135:                    }
06136:
06137:                    //cycle through the lables when shift pgup/pgdown is pressed
06138:                    if ((nShift == 0)
06139:                            && ((nKeyCode == KeyEvent.VK_PAGE_UP) || (nKeyCode == KeyEvent.VK_PAGE_DOWN))) {
06140:                        handled = onShiftPageUpDown(nKeyCode, nShift);
06141:                    }
06142:                }
06143:
06144:                return handled;
06145:            }
06146:
06147:            public boolean handleCharTyped(char ch) {
06148:                boolean handled = false;
06149:                ETElementManager manager = new ETElementManager(this );
06150:                handled = manager.onCharTyped(ch);
06151:                return handled;
06152:            }
06153:
06154:            private boolean isArrowKey(int keyCode) {
06155:                return keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN
06156:                        || keyCode == KeyEvent.VK_RIGHT
06157:                        || keyCode == KeyEvent.VK_LEFT;
06158:            }
06159:
06160:            // cycle thru all labels in the diagram
06161:            private boolean onShiftPageUpDown(int nKeyCode, int shiftDown) {
06162:                IETLabel nextLabel = null;
06163:                int nextIndex = 0;
06164:
06165:                ETList<IETLabel> labelsList = getAllLabels();
06166:                if (labelsList == null || labelsList.size() <= 0) {
06167:                    return false;
06168:                }
06169:                //Take care of the case where labels are selected by mouse and m_lastSelectedLabel is not initialized.
06170:                if (m_lastSelectedLabel == null) {
06171:                    m_lastSelectedLabel = getLastSelectedLabel();
06172:                }
06173:                //getnext label in the labelsList and select it..
06174:                if (labelsList != null && labelsList.size() > 0) {
06175:                    if (labelsList.contains(m_lastSelectedLabel)) {
06176:                        if (nKeyCode == KeyEvent.VK_PAGE_UP) {
06177:                            nextIndex = (labelsList
06178:                                    .indexOf(m_lastSelectedLabel)) + 1;
06179:                            if (nextIndex >= labelsList.size()) {
06180:                                nextIndex = 0;
06181:                            }
06182:                        } else if (nKeyCode == KeyEvent.VK_PAGE_DOWN) {
06183:                            nextIndex = (labelsList
06184:                                    .indexOf(m_lastSelectedLabel)) - 1;
06185:                            if (nextIndex < 0) {
06186:                                nextIndex = labelsList.size() - 1;
06187:                            }
06188:                        }
06189:                        nextLabel = (IETLabel) labelsList.get(nextIndex);
06190:                        selectLabel(nextLabel);
06191:                    } else if (m_lastSelectedLabel != null) {
06192:                        selectLabel(m_lastSelectedLabel);
06193:                    } else {
06194:                        // since m_lastSelectedLabel is null, we need a default value
06195:                        m_lastSelectedLabel = (labelsList.get(0));
06196:                        //if there is no selected element on the diagram, then have a default one selected
06197:                        if (getSelectedLabels() == null) {
06198:                            selectLabel(m_lastSelectedLabel);
06199:                        }
06200:                    }
06201:                }
06202:                return true;
06203:            }
06204:
06205:            private void selectLabel(IETLabel nextLabel) {
06206:                getGraphWindow().deselectAll(true);
06207:                setSelectedCompartments(false);
06208:                if (nextLabel != null) {
06209:                    m_graphObj = nextLabel;
06210:                    if (m_graphObj instanceof  ETNodeLabel) {
06211:                        getGraphWindow().selectObject((ETNodeLabel) nextLabel,
06212:                                true);
06213:                        this .fireSelectEvent((ETNodeLabel) nextLabel);
06214:                        m_lastSelectedLabel = nextLabel;
06215:                    } else if (m_graphObj instanceof  ETEdgeLabel) {
06216:                        getGraphWindow().selectObject((ETEdgeLabel) nextLabel,
06217:                                true);
06218:                        this .fireSelectEvent((ETEdgeLabel) nextLabel);
06219:                        m_lastSelectedLabel = nextLabel;
06220:                    }
06221:                }
06222:            }
06223:
06224:            private boolean onShiftUpDown(int nKeyCode, int shiftDown) {
06225:                //first get the selected node
06226:                ETEdge nextEdge = null;
06227:                int nextIndex = 0;
06228:                ETNode selectedNode = getLastSelectedNode();
06229:                ETEdge selectedEdge = getSelectedEdge();
06230:
06231:                if ((selectedNode == null) && (selectedEdge != null)) {
06232:                    selectedNode = m_lastSelectedNode;
06233:                }
06234:                if (selectedNode != null) {
06235:                    //           System.err.println("selectedNode is NOT null... so get its edges.. ");
06236:                    //get all the edges of this node..
06237:                    ETList<IETEdge> edgeList = selectedNode.getEdges();
06238:                    if (edgeList != null && edgeList.size() > 0) {
06239:                        if (selectedEdge != null) {
06240:                            if (edgeList.contains(selectedEdge)) {
06241:                                if (nKeyCode == KeyEvent.VK_UP) {
06242:                                    nextIndex = (edgeList.indexOf(selectedEdge)) + 1;
06243:                                    if (nextIndex >= edgeList.size()) {
06244:                                        nextIndex = 0;
06245:                                    }
06246:                                } else if (nKeyCode == KeyEvent.VK_DOWN) {
06247:                                    nextIndex = (edgeList.indexOf(selectedEdge)) - 1;
06248:                                    if (nextIndex < 0) {
06249:                                        nextIndex = edgeList.size() - 1;
06250:                                    }
06251:                                }
06252:                                nextEdge = (ETEdge) edgeList.get(nextIndex);
06253:                            }
06254:                        } else {
06255:                            //selectedEdge is null
06256:                            nextEdge = (ETEdge) edgeList.get(0);
06257:                        }
06258:                        getGraphWindow().deselectAll(true);
06259:                        setSelectedCompartments(false);
06260:                        // Select objects in the selected group, m_selectedNodesGroup.
06261:                        // These objects are added to the group via shift+/-
06262:                        getGraphWindow()
06263:                                .selectGroup(m_selectedNodesGroup, true);
06264:                        if (nextEdge != null) {
06265:                            m_graphObj = nextEdge;
06266:                            getGraphWindow().selectObject(nextEdge, true);
06267:                            this .fireSelectEvent(nextEdge);
06268:                        }
06269:                    }
06270:                }
06271:                return true;
06272:            }
06273:
06274:            private boolean onTabKeyDown(int shiftDown) {
06275:                //begin traversal..
06276:                ETNode nextNode = null;
06277:                int nextIndex = 0;
06278:
06279:                TSEGraph graph = this .getGraph();
06280:                List nodeList = graph.nodes();
06281:                if (nodeList == null || nodeList.size() <= 0) {
06282:                    return false;
06283:                }
06284:
06285:                if (graph.hasSelectedNodes()) {
06286:
06287:                    //Take care of the case where nodes are selected by mouse and m_lastSelectedNode is not initialized.
06288:                    if (m_lastSelectedNode == null) {
06289:                        m_lastSelectedNode = getLastSelectedNode();
06290:                    }
06291:                    //get next node in the nodeList and select it..
06292:                    if (m_lastSelectedNode != null
06293:                            && nodeList.contains(m_lastSelectedNode)) {
06294:                        if (shiftDown == 1) {
06295:                            // shift is NOT down.. so tab forward..
06296:                            nextIndex = (nodeList.indexOf(m_lastSelectedNode)) + 1;
06297:                            if (nextIndex >= nodeList.size()) {
06298:                                nextIndex = 0;
06299:                            }
06300:                        } else if (shiftDown == 0) {
06301:                            //shift is down.. so tab backwards..
06302:                            nextIndex = (nodeList.indexOf(m_lastSelectedNode)) - 1;
06303:                            if (nextIndex < 0) {
06304:                                nextIndex = nodeList.size() - 1;
06305:                            }
06306:                        }
06307:                        nextNode = (ETNode) nodeList.get(nextIndex);
06308:                        // 1. deselect all nodes and and compartments if any
06309:                        getGraphWindow().deselectAll(true);
06310:                        setSelectedCompartments(false);
06311:                        // 2. select objects in the selected group, m_selectedNodesGroup.
06312:                        // These objects are added to the group via shift+/-
06313:                        getGraphWindow()
06314:                                .selectGroup(m_selectedNodesGroup, true);
06315:                        // 3. select the next object (must be done after calling selectGroup() in step2
06316:                        // to maintain the correct order of selection)
06317:                        getGraphWindow().selectObject(nextNode, true);
06318:                        // 4. fire selecteEvent for the nextNode
06319:                        this .fireSelectEvent(nextNode);
06320:                        //Fix for #88831
06321:                        IETGraphObjectUI nodeUI = nextNode.getETUI();
06322:                        if (nodeUI != null
06323:                                && !nodeUI.isOnTheScreen(nodeUI.getDrawInfo()
06324:                                        .getTSEGraphics())) {
06325:                            //node is NOT visible on the screen, so center it.
06326:                            IPresentationElement presElt = TypeConversions
06327:                                    .getPresentationElement((TSObject) nextNode);
06328:                            centerPresentationElement(presElt, true, false);
06329:                        }
06330:                        m_lastSelectedNode = nextNode;
06331:                    }
06332:                } else if (m_lastSelectedNode != null) {
06333:                    getGraphWindow().deselectAll(true);
06334:                    setSelectedCompartments(false);
06335:                    getGraphWindow().selectObject(m_lastSelectedNode, true);
06336:                    this .fireSelectEvent(m_lastSelectedNode);
06337:                } else {
06338:                    // since selectedNode is null, we need a default value
06339:                    m_lastSelectedNode = (ETNode) (nodeList.get(0));
06340:                    //if there is no selected element on the diagram, then have a default one selected
06341:                    if (getSelectedEdge() == null) {
06342:                        getGraphWindow().deselectAll(true);
06343:                        setSelectedCompartments(false);
06344:                        getGraphWindow().selectObject(m_lastSelectedNode, true);
06345:                        this .fireSelectEvent(m_lastSelectedNode);
06346:                    }
06347:                }
06348:                m_graphObj = m_lastSelectedNode;
06349:                return true;
06350:            }
06351:
06352:            //we just need a single selected node
06353:            private ETNode getLastSelectedNode() {
06354:                ETNode lastSelectedNode = null;
06355:                if (getGraph().hasSelectedNodes()) {
06356:                    List selectedNodeList = this .getGraph().selectedNodes();
06357:                    if (selectedNodeList != null) {
06358:                        int count = selectedNodeList.size();
06359:                        if (count > 0) {
06360:                            lastSelectedNode = (ETNode) selectedNodeList
06361:                                    .get(count - 1);
06362:                        }
06363:                    }
06364:                }
06365:                return lastSelectedNode;
06366:            }
06367:
06368:            private ETEdge getSelectedEdge() {
06369:                ETEdge selectedEdge = null;
06370:                if (getGraph().hasSelectedEdges()) {
06371:                    List selectedEdgeList = getGraph().selectedEdges();
06372:                    if (selectedEdgeList != null && selectedEdgeList.size() > 0) {
06373:                        selectedEdge = (ETEdge) selectedEdgeList.get(0);
06374:                        //               System.err.println(" selected edge = "+selectedEdge);
06375:                    }
06376:                }
06377:                return selectedEdge;
06378:            }
06379:
06380:            private IETLabel getLastSelectedLabel() {
06381:
06382:                IETLabel lastSelectedLabel = null;
06383:                ETList<IETLabel> labelList = getAllLabels();
06384:                if (labelList != null && labelList.size() > 0) {
06385:                    lastSelectedLabel = labelList.get(labelList.size() - 1);
06386:                }
06387:                return lastSelectedLabel;
06388:            }
06389:
06390:            /* (non-Javadoc)
06391:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#hasChildren(com.embarcadero.describe.foundation.IPresentationElement, boolean)
06392:             */
06393:            public boolean hasChildren(IPresentationElement pPE, boolean bHidden) {
06394:                // TODO Auto-generated method stub
06395:                return false;
06396:            }
06397:
06398:            /* (non-Javadoc)
06399:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#hasParents(com.embarcadero.describe.foundation.IPresentationElement, boolean)
06400:             */
06401:            public boolean hasParents(IPresentationElement pPE, boolean bHidden) {
06402:                // TODO Auto-generated method stub
06403:                return false;
06404:            }
06405:
06406:            /* (non-Javadoc)
06407:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#hide(com.embarcadero.describe.foundation.IPresentationElement, int, boolean)
06408:             */
06409:            public void hide(IPresentationElement pPE, int numLevels,
06410:                    boolean bChildren) {
06411:                GetHelper
06412:                        .hide(this .getGraphWindow(), pPE, numLevels, bChildren);
06413:                setIsDirty(true);
06414:            }
06415:
06416:            /* (non-Javadoc)
06417:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#unhide(com.embarcadero.describe.foundation.IPresentationElement, int, boolean)
06418:             */
06419:            public void unhide(IPresentationElement pPE, int numLevels,
06420:                    boolean bChildren) {
06421:                GetHelper.unhide(this .getGraphWindow(), pPE, numLevels,
06422:                        bChildren);
06423:                setIsDirty(true);
06424:            }
06425:
06426:            /* (non-Javadoc)
06427:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#getLayoutStyle()
06428:             */
06429:            public int getLayoutStyle() {
06430:                return ETLayoutStyleMap.getLayoutStyle(
06431:                        m_DiagramKindDisplayName, getGraph(),
06432:                        m_layoutInputTailor);
06433:            }
06434:
06435:            /*
06436:             * Converts an ILayoutKind into a string for communication with the layout server.
06437:            public String getLayoutCommandString(int ilayoutKind)
06438:            {
06439:            return ETLayoutStyleMap.getLayoutCommandString(ilayoutKind, getGraph(), this.m_layoutInputTailor);
06440:            }
06441:             */
06442:            /**
06443:             * Immediately puts the layout style on the GET, doesn't do a post.  Here's the email I sent
06444:             * to TS support on 5-28-02 documenting the problem (PSIRR).
06445:             *
06446:             * I've noticed something that is worries me.  Certain commands to TS will crash the GET
06447:             * (ie changing topology while in an event).  I now have a case where running the windows
06448:             * message pump produces different layouts.  I have a menu button that creates a diagram then
06449:             * looks in a tree to see what's selected.  Based on what's selected nodes/edges are created.
06450:             * After creating the diagram and the node/edges it then puts the GET into orthogonal layout
06451:             * style.
06452:             *
06453:             * Watch the AVI first.  If I set the layout style immediately after creating the diagram and
06454:             * edges I get what you see in the AVI - disconnected edges pointing off into outer space.
06455:             * If I instead post the layout command onto the windows messages stack and then execute the
06456:             * command after allowing the message queue to finish I get the picture below.  The only
06457:             * difference is delaying execution of the layout command by using the windows message pump -
06458:             * that's all it takes to create the layout seen below and the layout at the end of the avi.
06459:             *
06460:             * @param nLayoutStyle [in] The new layout style.
06461:             * @param bSilent [in] true to skip asking the user if it's ok
06462:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#immediatelySetLayoutStyle(int, boolean)
06463:             */
06464:            public void immediatelySetLayoutStyle(int nLayoutStyle,
06465:                    boolean bSilent) {
06466:                if (getGraphWindow() != null && !IOSemaphore.isIOHappenning()) {
06467:                    // First ask a question since this operation cannot be undone
06468:                    if (bSilent || askOkToLayoutDiagram()) {
06469:                        // TS fits the diagram to the window after the layout.  We preserve the zoom level here
06470:                        double curZoom = getCurrentZoom();
06471:
06472:                        // Let folks know that the layout is being changed.
06473:                        if (fireDrawingAreaPrePropertyChange(DiagramAreaEnumerations.DAPK_LAYOUT)) {
06474:                            boolean handled = false;
06475:                            if (m_DiagramEngine != null) {
06476:                                handled = m_DiagramEngine
06477:                                        .preDoLayout(nLayoutStyle);
06478:                            }
06479:
06480:                            if (!handled) {
06481:                                boolean incremental = nLayoutStyle == ILayoutKind.LK_INCREMENTAL_LAYOUT;
06482:
06483:                                int layoutStyle = nLayoutStyle;
06484:
06485:                                // Performing the layout with commands.
06486:                                boolean hasNodes = false;
06487:                                if (this .hasNodes(hasNodes) > 0) {
06488:                                    m_allOptionsServiceInputData
06489:                                            .addAsListener(this 
06490:                                                    .getGraphManager());
06491:                                    int tsLayoutStyle = ETLayoutStyleMap
06492:                                            .mapLayoutKind2TsLayout(nLayoutStyle);
06493:
06494:                                    //JM: fix for Bug#6383449
06495:                                    //                           if ((tsLayoutStyle == TSLayoutConstants.LAYOUT_STYLE_NO_STYLE) && (incremental == true))
06496:                                    if (incremental) {
06497:                                        m_layoutInputTailor
06498:                                                .setIncrementalLayout(true);
06499:                                        getGraphWindow()
06500:                                                .transmit(
06501:                                                        new ADLayoutCommand(
06502:                                                                getGraphWindow(),
06503:                                                                this .m_layoutProxy,
06504:                                                                this .m_allOptionsServiceInputData));
06505:                                    } else {
06506:                                        // 83132, set direction according to uml convention
06507:                                        if (tsLayoutStyle == TSLayoutConstants.LAYOUT_STYLE_HIERARCHICAL) {
06508:                                            TSHierarchicalLayoutInputTailor tailor = new TSHierarchicalLayoutInputTailor(
06509:                                                    m_allOptionsServiceInputData,
06510:                                                    this .getGraph());
06511:                                            tailor
06512:                                                    .setLevelDirection(TSJLayoutConstants.DIRECTION_BOTTOM_TO_TOP);
06513:                                        }
06514:                                        getGraphWindow()
06515:                                                .transmit(
06516:                                                        new ADLayoutCommand(
06517:                                                                getGraphWindow(),
06518:                                                                this .m_layoutProxy,
06519:                                                                this .m_allOptionsServiceInputData,
06520:                                                                tsLayoutStyle));
06521:                                    }
06522:                                }
06523:                            }
06524:
06525:                            if (m_DiagramEngine != null) {
06526:                                m_DiagramEngine.postDoLayout();
06527:                            }
06528:
06529:                            // Let folks know that the layout is being changed.
06530:                            fireDrawingAreaPropertyChange(DiagramAreaEnumerations.DAPK_LAYOUT);
06531:                        }
06532:                        zoom(curZoom);
06533:                    }
06534:                }
06535:            }
06536:
06537:            /**
06538:             * Ask if it's ok to layout the diagram
06539:             *
06540:             * @return true if it's ok to layout the diagram
06541:             */
06542:            private boolean askOkToLayoutDiagram() {
06543:                int resultKind = SimpleQuestionDialogResultKind.SQDRK_RESULT_NO;
06544:
06545:                // get preference for displaying a small amount of empty lists
06546:                //kris richards - "AskBeforeLayout" pref expuged. Set to true.
06547:                Preferences prefs = NbPreferences
06548:                        .forModule(DummyCorePreference.class);
06549:
06550:                if (prefs.getBoolean("UML_Ask_Before_Layout", true)) {
06551:                    // If we don't have any graph objects then don't bother asking
06552:                    boolean hasObjs = GetHelper.hasGraphObjects(m_GraphWindow);
06553:                    if (hasObjs) {
06554:                        // Determine if the user wants to layout the diagram
06555:                        IQuestionDialog dialog = new SwingQuestionDialogImpl();
06556:
06557:                        String title = RESOURCE_BUNDLE
06558:                                .getString("IDS_LAYOUTQUESTION_TITLE");
06559:                        String message = RESOURCE_BUNDLE
06560:                                .getString("IDS_CHANGELAYOUT");
06561:                        String checkbox = RESOURCE_BUNDLE
06562:                                .getString("IDS_DONTASKAGAIN");
06563:                        QuestionResponse result = dialog
06564:                                .displaySimpleQuestionDialogWithCheckbox(
06565:                                        MessageDialogKindEnum.SQDK_YESNO,
06566:                                        MessageIconKindEnum.EDIK_ICONWARNING,
06567:                                        message, checkbox, title,
06568:                                        MessageResultKindEnum.SQDRK_RESULT_YES,
06569:                                        false);
06570:
06571:                        if (result.isChecked() == true) {
06572:                            prefs.putBoolean("UML_Ask_Before_Layout", false);
06573:                        }
06574:                        resultKind = result.getResult();
06575:                    }
06576:                } else {
06577:                    resultKind = SimpleQuestionDialogResultKind.SQDRK_RESULT_YES;
06578:                }
06579:
06580:                return resultKind == SimpleQuestionDialogResultKind.SQDRK_RESULT_YES;
06581:            }
06582:
06583:            protected void setPreferenceValue(String sLocID, String sID,
06584:                    String sValue) {
06585:                IPreferenceManager2 mgr = ProductHelper.getPreferenceManager();
06586:                if (mgr != null) {
06587:                    String sPath = sLocID != null && sLocID.length() > 0 ? sLocID
06588:                            : "";
06589:                    String sName = sID != null && sID.length() > 0 ? sID : "";
06590:
06591:                    // Change our cache if the pref hive is Diagrams
06592:                    if (sLocID != null && sLocID.equals("Diagrams")) {
06593:                        m_CachedPreferences.put(sID, sValue);
06594:                    }
06595:
06596:                    mgr.setPreferenceValue(sPath, sName, sValue);
06597:                }
06598:            }
06599:
06600:            /**
06601:             * Initializes a newly created diagram.  This also adds it to the current
06602:             * namespace.
06603:             *
06604:             * @param pNamespace [in] The namespace for this diagram
06605:             * @param sName [in] The name of the diagram
06606:             * @param nKind [in] The kind of the diagram.
06607:             */
06608:            public void initializeNewDiagram(INamespace pNamespace,
06609:                    String sName, int pKind) {
06610:                ETSmartWaitCursor waitCursor = new ETSmartWaitCursor();
06611:                setDiagramKind(pKind);
06612:                setNamespace(pNamespace);
06613:                String fulFileName = getFullFileName(sName);
06614:                setName(sName);
06615:
06616:                if (fulFileName != null && fulFileName.length() > 0) {
06617:                    setFileName(fulFileName, true);
06618:                    //         setIsDirty(true);
06619:                }
06620:
06621:                initializeNewDiagram();
06622:                waitCursor.stop();
06623:            }
06624:
06625:            /**
06626:             * Initializes a new diagram.  Called by the other InitializeNewDiagram.  Use this when
06627:             * you've already set the namespace, name and type of the diagram
06628:             */
06629:            private void initializeNewDiagram() {
06630:                // set up an empty resource manager for this drawing
06631:                loadResourceManager(null);
06632:
06633:                // Fire the precreate trigger
06634:                if (getDrawingAreaDispatcher() != null) {
06635:                    boolean proceed;
06636:                    IDiagram pDiagram = getDiagram();
06637:
06638:                    if (m_drawingAreaDispatcher != null) {
06639:                        IEventPayload payload = m_drawingAreaDispatcher
06640:                                .createPayload("FireDrawingAreaPreCreated");
06641:                        proceed = m_drawingAreaDispatcher
06642:                                .fireDrawingAreaPreCreated(this , payload);
06643:                    } else {
06644:                        proceed = true;
06645:                    }
06646:                    if (proceed) {
06647:                        IEventPayload payload = m_drawingAreaDispatcher
06648:                                .createPayload("FireDrawingAreaPostCreated");
06649:                        m_drawingAreaDispatcher.fireDrawingAreaPostCreated(
06650:                                this , payload);
06651:
06652:                        if (m_DiagramEngine != null) {
06653:                            m_DiagramEngine.initializeNewDiagram();
06654:
06655:                            // Fix J1714:  This code was not needed in C++,
06656:                            // but we implement it here to ensure that there is
06657:                            // a default layout style for the diagram.
06658:                            // Set the default layout style without setting the diagram dirty
06659:                            /* JM
06660:                            getGraph().setLayoutStyle( TSDGraph.ORTHOGONAL );
06661:                             */
06662:                            // Setup our default layout settings
06663:                            m_DiagramEngine.setupLayoutSettings(true);
06664:                        }
06665:
06666:                        // Tell the outside world that this drawing area is open for business
06667:                        payload = m_drawingAreaDispatcher
06668:                                .createPayload("DiagramOpened");
06669:                        m_drawingAreaDispatcher.fireDrawingAreaOpened(pDiagram,
06670:                                payload);
06671:                    }
06672:                    zoom(1.0);
06673:                }
06674:            }
06675:
06676:            /* (non-Javadoc)
06677:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#invertSelection()
06678:             */
06679:            public void invertSelection() {
06680:
06681:                ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
06682:                        : null;
06683:                if (etGraph != null) {
06684:                    visit(new IETGraphObjectVisitor() {
06685:
06686:                        public boolean visit(IETGraphObject object) {
06687:                            // Toggle the selection.
06688:                            object.invalidate();
06689:                            object.setSelected(!object.isSelected());
06690:                            return true;
06691:                        }
06692:                    });
06693:
06694:                    this .fireSelectEvent(etGraph.getSelectedObjects(false,
06695:                            false));
06696:                    this .refresh(true);
06697:                }
06698:            }
06699:
06700:            /**
06701:             * Is this model element type allowed on this diagram?
06702:             *
06703:             * @param pElement [in] The element to query
06704:             * @param bIsAllowed [out,retval] true if the element is allowed on this diagram type.
06705:             */
06706:            public boolean isAllowedOnDiagram(IElement pElement) {
06707:                boolean isAllowed = false;
06708:                if (pElement != null && m_PresentationTypesMgr != null
06709:                        && m_PresentationTypesMgr.validateFile()) {
06710:                    // Get the element type
06711:                    String elemType = pElement.getElementType();
06712:
06713:                    // Get the type of this diagram
06714:                    int diaKind = getDiagramKind();
06715:
06716:                    String viewDesc = m_PresentationTypesMgr
06717:                            .getMetaTypeInitString(elemType, diaKind);
06718:                    if (viewDesc != null && viewDesc.length() > 0) {
06719:                        isAllowed = true;
06720:                    }
06721:                }
06722:                return isAllowed;
06723:            }
06724:
06725:            /**
06726:             * Is this an associated diagram?
06727:             *
06728:             * @param sDiagramXMIID [in] The diagram xmiid
06729:             * @param bIsAssociated [out,retval] TRUE if the diagram is associated with this diagram.
06730:             */
06731:            public boolean isAssociatedDiagram(String sDiagramXMIID) {
06732:                boolean isAssociated = false;
06733:                if (sDiagramXMIID != null && sDiagramXMIID.length() > 0) {
06734:                    if (m_AssociatedDiagrams != null) {
06735:                        int count = m_AssociatedDiagrams.size();
06736:                        for (int i = 0; i < count; i++) {
06737:                            String str = (String) m_AssociatedDiagrams.get(i);
06738:                            if (sDiagramXMIID.equals(str)) {
06739:                                isAssociated = true;
06740:                                break;
06741:                            }
06742:                        }
06743:                    }
06744:                }
06745:                return isAssociated;
06746:            }
06747:
06748:            /**
06749:             * Is this an associated diagram?
06750:             *
06751:             * @param pDiagram [in] The diagram
06752:             * @param bIsAssociated [out,retval] TRUE if the diagram is associated with this diagram.
06753:             */
06754:            public boolean isAssociatedDiagram2(IProxyDiagram pDiagram) {
06755:                if (pDiagram != null) {
06756:                    String xmiid = pDiagram.getXMIID();
06757:                    if (xmiid != null && xmiid.length() > 0) {
06758:                        return isAssociatedDiagram(xmiid);
06759:                    }
06760:                }
06761:                return false;
06762:            }
06763:
06764:            /**
06765:             * Is this an associated element?
06766:             *
06767:             * @param sModelElementXMIID [in] The model element id
06768:             * @param bIsAssociated [out,retval] TRUE if the model element is associated with this diagram.
06769:             */
06770:            public boolean isAssociatedElement(String sModelElementXMIID) {
06771:                if (sModelElementXMIID != null
06772:                        && sModelElementXMIID.length() > 0) {
06773:                    if (m_AssociatedElements != null) {
06774:                        Collection col = m_AssociatedElements.values();
06775:                        Iterator iter = col.iterator();
06776:                        while (iter.hasNext()) {
06777:                            Object obj = iter.next();
06778:                            if (obj != null && obj instanceof  Vector) {
06779:                                Vector meidCol = (Vector) obj;
06780:                                if (meidCol.contains(sModelElementXMIID)) {
06781:                                    return true;
06782:                                }
06783:                            }
06784:                        }
06785:                    }
06786:                }
06787:                return false;
06788:            }
06789:
06790:            /**
06791:             * Is this an associated element?
06792:             *
06793:             * @param pElement [in] The model element
06794:             * @param bIsAssociated [out,retval] TRUE if the model element is associated with this diagram.
06795:             */
06796:            public boolean isAssociatedElement2(IElement pElement) {
06797:                boolean isAssociated = false;
06798:                if (pElement != null) {
06799:                    String xmiid = pElement.getXMIID();
06800:                    if (xmiid != null && xmiid.length() > 0) {
06801:                        return isAssociatedElement(xmiid);
06802:                    }
06803:                }
06804:                return false;
06805:            }
06806:
06807:            /* (non-Javadoc)
06808:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#isSame(com.embarcadero.describe.diagrams.IDiagram)
06809:             */
06810:            public boolean isSame(IDiagram pDiagram) {
06811:                if (pDiagram != null) {
06812:                    String filename = getFilename();
06813:                    return filename != null
06814:                            && filename.equals(pDiagram.getFilename());
06815:                }
06816:                return false;
06817:            }
06818:
06819:            public boolean isStackingCommandAllowed(int pStackingCommand) {
06820:                return true;
06821:            }
06822:
06823:            /* (non-Javadoc)
06824:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#killTooltip()
06825:             */
06826:            public void killTooltip() {
06827:                // TODO Auto-generated method stub
06828:            }
06829:
06830:            protected void createLayoutPropertiesDialog() {
06831:                /*
06832:                Object tag = this.getGraphWindow().getGraph().getTag();
06833:                String name;
06834:                if (tag != null && !"".equals(tag.toString().trim()))
06835:                {
06836:                name = tag.toString();
06837:                }
06838:                else
06839:                {
06840:                name = this.getFilename();
06841:                }
06842:                 */
06843:                String title = RESOURCE_BUNDLE
06844:                        .getString("IDS_LAYOUT_PROPERTIES_DLG_TITLE");
06845:
06846:                this .layoutPropertiesDialog = new ETLayoutPropertiesDialog(
06847:                        getOwnerFrame(), title, this .getGraphWindow(),
06848:                        this .m_layoutProxy, this .m_allOptionsServiceInputData); // this should probably be changed to TSEServiceInputData...
06849:                this .layoutPropertiesDialog
06850:                        .setLocationRelativeTo(SwingUtilities.getRootPane(this ));
06851:            }
06852:
06853:            /* (non-Javadoc)
06854:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#layoutPropertiesDialog(boolean)
06855:             */
06856:            public void layoutPropertiesDialog(boolean bShow) {
06857:                if (bShow) {
06858:                    if (this .layoutPropertiesDialog == null) {
06859:                        this .createLayoutPropertiesDialog();
06860:                    }
06861:                }
06862:
06863:                if (layoutPropertiesDialog != null) {
06864:                    layoutPropertiesDialog.setVisible(bShow);
06865:                    layoutPropertiesDialog.repaint();
06866:                }
06867:                this .refresh(true);
06868:            }
06869:
06870:            /* (non-Javadoc)
06871:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#logicalToDevicePoint(com.embarcadero.describe.umlsupport.IETPoint)
06872:             */
06873:            public IETPoint logicalToDevicePoint(IETPoint pLogical) {
06874:                IETPoint retVal = null;
06875:
06876:                if (getGraphWindow() != null) {
06877:                    TSTransform transform = getGraphWindow().getTransform();
06878:                    if (transform != null) {
06879:                        Point p = transform.pointToDevice(pLogical.getX(),
06880:                                pLogical.getY());
06881:
06882:                        retVal = new ETPoint(p.x, p.y);
06883:                    }
06884:                }
06885:
06886:                return retVal;
06887:            }
06888:
06889:            /* (non-Javadoc)
06890:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#logicalToDevicePoint(com.embarcadero.describe.umlsupport.IETPoint)
06891:             */
06892:            public IETPoint logicalToDevicePoint(double x, double y) {
06893:                IETPoint retVal = null;
06894:
06895:                if (getGraphWindow() != null) {
06896:                    TSTransform transform = getGraphWindow().getTransform();
06897:                    if (transform != null) {
06898:                        Point p = transform.pointToDevice(x, y);
06899:
06900:                        retVal = new ETPoint(p.x, p.y);
06901:                    }
06902:                }
06903:
06904:                return retVal;
06905:            }
06906:
06907:            /* (non-Javadoc)
06908:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#logicalToDeviceRect(com.embarcadero.describe.umlsupport.IETRect)
06909:             */
06910:            public IETRect logicalToDeviceRect(IETRect pLogical) {
06911:                return logicalToDeviceRect(pLogical.getLeft(), pLogical
06912:                        .getTop(), pLogical.getRight(), pLogical.getBottom());
06913:            }
06914:
06915:            /* (non-Javadoc)
06916:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#logicalToDeviceRect(com.embarcadero.describe.umlsupport.IETRect)
06917:             */
06918:            public IETRect logicalToDeviceRect(double left, double top,
06919:                    double right, double bottom) {
06920:                if (getGraphWindow() != null) {
06921:                    TSTransform transform = getGraphWindow().getTransform();
06922:                    if (transform != null) {
06923:                        return new ETDeviceRect(transform.boundsToDevice(left,
06924:                                bottom, right, top));
06925:                    }
06926:                }
06927:
06928:                return null;
06929:            }
06930:
06931:            /**
06932:             * Goes to a custom zoom setting by bringing up a dialog and allowing the
06933:             * user to type in a zoom zetting.
06934:             */
06935:            public void onCustomZoom() {
06936:                double currentZoom = getCurrentZoom();
06937:
06938:                IZoomDialog pZoomDialog = new ZoomDialog(this .getOwnerFrame());
06939:
06940:                if (pZoomDialog != null) {
06941:                    double nSelectedZoom = currentZoom;
06942:
06943:                    boolean bFitToPage = false;
06944:
06945:                    ETPairT<Double, Boolean> result = pZoomDialog
06946:                            .display(currentZoom);
06947:                    if (result != null) {
06948:                        nSelectedZoom = ((Double) result.getParamOne())
06949:                                .doubleValue();
06950:                        bFitToPage = ((Boolean) result.getParamTwo())
06951:                                .booleanValue();
06952:                    }
06953:
06954:                    if (bFitToPage) {
06955:                        this .fitInWindow();
06956:                    } else if (currentZoom != nSelectedZoom) {
06957:                        zoom(nSelectedZoom);
06958:                    }
06959:                }
06960:            }
06961:
06962:            /* (non-Javadoc)
06963:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postDelayedAction(com.embarcadero.describe.diagrams.IDelayedAction)
06964:             */
06965:            public void postDelayedAction(IDelayedAction pAction) {
06966:                onHandleDelayedAction(pAction);
06967:            }
06968:
06969:            /*
06970:             * Safely deletes all the presentation elements in the list.
06971:             */
06972:            public void postDeletePresentationElements(
06973:                    ETList<IPresentationElement> pes) {
06974:                try {
06975:                    if (pes != null) {
06976:                        IteratorT<IPresentationElement> iter = new IteratorT<IPresentationElement>(
06977:                                pes);
06978:
06979:                        while (iter.hasNext()) {
06980:                            // This can be trouble if the pe is a child presentation that was deleted
06981:                            // already so make sure it's on the diagram.
06982:                            IPresentationElement pe = iter.next();
06983:
06984:                            if (getIsOnDiagram(TypeConversions
06985:                                    .getETGraphObject(pe))) {
06986:                                postDeletePresentationElement(pe);
06987:
06988:                                iter.remove();
06989:                            }
06990:                        }
06991:                    }
06992:                } catch (Exception e) {
06993:                    e.printStackTrace();
06994:                }
06995:            }
06996:
06997:            /* (non-Javadoc)
06998:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postDeletePresentationElement(com.embarcadero.describe.foundation.IPresentationElement)
06999:             */
07000:            public void postDeletePresentationElement(
07001:                    final IPresentationElement pPE) {
07002:                if (pPE != null) {
07003:                    // Fix J1170:  This call needs to be delayed so the diagram gets refreshed after all changes
07004:                    //             to the presentation elements.  In this case it was lifelines on the SQD.
07005:                    SwingUtilities.invokeLater(new Runnable() {
07006:
07007:                        public void run() {
07008:                            postDelayedAction(new PresentationElementToDeleteAction(
07009:                                    pPE));
07010:                        }
07011:                    });
07012:                }
07013:            }
07014:
07015:            /* (non-Javadoc)
07016:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postDeletePresentationElement(com.tomsawyer.graph.TSGraphObject)
07017:             */
07018:            public void postDeletePresentationElement(TSGraphObject pGraphObject) {
07019:
07020:                // PRINTSCOPEKEY(DrawingAreaDebug); // Used to print the scope in debug.
07021:                if (pGraphObject == null) {
07022:                    return;
07023:                }
07024:                try {
07025:                    IPresentationElementToDeleteAction pDeleteAction = new PresentationElementToDeleteAction(
07026:                            pGraphObject);
07027:                    if (pDeleteAction != null) {
07028:                        postDelayedAction(pDeleteAction);
07029:                    }
07030:                } catch (Exception e) {
07031:                    e.printStackTrace();
07032:                }
07033:            }
07034:
07035:            /* (non-Javadoc)
07036:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postEditLabel(org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation)
07037:             */
07038:            public void postEditLabel(ILabelPresentation pPE) {
07039:                if (null == pPE) {
07040:                    throw new IllegalArgumentException();
07041:                }
07042:                ISimplePresentationAction action = new SimplePresentationAction();
07043:                if (action != null) {
07044:                    action.add(pPE);
07045:                    action.setKind(DiagramAreaEnumerations.SPAK_EDITLABEL);
07046:                    postDelayedAction(action);
07047:                }
07048:            }
07049:
07050:            /* (non-Javadoc)
07051:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postInvalidate(com.embarcadero.describe.foundation.IPresentationElement)
07052:             */
07053:            public void postInvalidate(IPresentationElement pPresentationElement) {
07054:                if (UserInputBlocker.getIsDisabled(GBK.DIAGRAM_INVALIDATE)) {
07055:                    return;
07056:                }
07057:
07058:                if (pPresentationElement instanceof  ProductGraphPresentation) {
07059:                    ProductGraphPresentation graphPE = (ProductGraphPresentation) pPresentationElement;
07060:
07061:                    this .refreshRect(graphPE.getBoundingRect());
07062:                }
07063:
07064:                //      if (pPresentationElement instanceof IGraphPresentation)
07065:                //      {
07066:                //         IGraphPresentation graphPresentation = (IGraphPresentation)pPresentationElement;
07067:                //
07068:                //         IETRect currentRect = graphPresentation.getViewBoundingRect();
07069:                //         if (currentRect && m_InvalidateBeforeRect && pControl)
07070:                //         {
07071:                //            currentRect.unionWith(m_InvalidateBeforeRect);
07072:                //
07073:                //            // RefreshRect is expecting the y-axis to be inverted.
07074:                //            currentRect.normalizeRect(true);
07075:                //
07076:                //            refreshRect(currentRect);
07077:                //         }
07078:                //         else
07079:                //         {
07080:                //            graphPresentation.invalidate();
07081:                //         }
07082:                //      }
07083:            }
07084:
07085:            /* (non-Javadoc)
07086:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postSelectEvent()
07087:             */
07088:            public void postSelectEvent() {
07089:                postSimpleDelayedAction(DiagramAreaEnumerations.SPAK_SELECT_EVENT);
07090:            }
07091:
07092:            /* (non-Javadoc)
07093:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postSimpleDelayedAction(int)
07094:             */
07095:            public void postSimpleDelayedAction(int nKind) {
07096:                postDelayedAction(new SimplePresentationAction(nKind));
07097:            }
07098:
07099:            /* (non-Javadoc)
07100:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postSimplePresentationDelayedAction(com.embarcadero.describe.foundation.IPresentationElement, int)
07101:             */
07102:            public void postSimplePresentationDelayedAction(
07103:                    IPresentationElement pPE, int nKind) {
07104:                ISimplePresentationAction simpleAction = new SimplePresentationAction(
07105:                        nKind);
07106:                simpleAction.add(pPE);
07107:
07108:                postDelayedAction(simpleAction);
07109:            }
07110:
07111:            /* (non-Javadoc)
07112:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#postSimplePresentationDelayedAction(com.embarcadero.describe.foundation.IPresentationElement, int)
07113:             */
07114:            public void postSimplePresentationDelayedAction(
07115:                    ETList<IPresentationElement> pPEs, int nKind) {
07116:                ISimplePresentationAction simpleAction = new SimplePresentationAction(
07117:                        nKind);
07118:                simpleAction.setPresentationElements(pPEs);
07119:
07120:                postDelayedAction(simpleAction);
07121:            }
07122:
07123:            /* (non-Javadoc)
07124:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#preferencesChanged(com.embarcadero.describe.umlutils.IPropertyElement[])
07125:             */
07126:            // Font and Color are dropped from 6.2 due to new resource management
07127:            public boolean preferencesChanged(IPropertyElement[] pProperties) {
07128:                if (m_ReadOnly) {
07129:                    return false;
07130:                }
07131:
07132:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
07133:                boolean bDidChange = false;
07134:                PropertyElements pPropertyElements = new PropertyElements(
07135:                        pProperties);
07136:
07137:                // Now see if aliased or show tagged values has changed
07138:                IPropertyElement pAliasPropertyElement = pPropertyElements
07139:                        .getElement("", "ShowAliasedNames", false);
07140:
07141:                // Now see if aliased or show tagged values has changed
07142:                //kris richards - "DisplayTVs" pref expunged. Set to true.
07143:                //IPropertyElement pDisplayTVsPropertyElement = pPropertyElements.getElement("", "DisplayTVs", false);
07144:                // Process the diagram preferences
07145:                ETList<IPropertyElement> diagramProps = new ETArrayList<IPropertyElement>();
07146:
07147:                ETList<IPropertyElement> pPropertyElementList = pPropertyElements
07148:                        .getList();
07149:                int nCount = pPropertyElementList.size();
07150:                for (int i = 0; i < nCount; i++) {
07151:                    IPropertyElement pElement = pPropertyElementList.get(i);
07152:                    if (pElement != null) {
07153:                        IPropertyElement pParentElement = null;
07154:                        String sParentName = "";
07155:
07156:                        pParentElement = pElement.getParent();
07157:                        if (pParentElement != null) {
07158:                            sParentName = pParentElement.getName();
07159:
07160:                            if (sParentName.equals("Diagrams")) {
07161:                                // Its something else
07162:                                diagramProps.add(pElement);
07163:                            }
07164:                        }
07165:                    }
07166:                }
07167:
07168:                // Process the diagram preferences
07169:                for (int j = 0; j < diagramProps.size(); j++) {
07170:                    IPropertyElement pElement = diagramProps.get(j);
07171:                    if (pElement != null) {
07172:                        String sName = pElement.getName();
07173:                        String sValue = pElement.getValue();
07174:                        if (sName.length() > 0 && sValue.length() > 0) {
07175:                            m_CachedPreferences.put(sName, sValue);
07176:                            bDidChange = true;
07177:                        }
07178:                    }
07179:                }
07180:
07181:                // Handle the alias change if necessary.  Check ResizeOnAliasToggle preference to
07182:                // see if we need to resize them too.
07183:                if (pAliasPropertyElement != null) {
07184:                    syncElements(false);
07185:
07186:                    //kris richards - "AskBeforeLayout" pref expuged. Set to true.
07187:                    Preferences prefs = NbPreferences
07188:                            .forModule(ADDrawingAreaControl.class);
07189:
07190:                    //ResizeOnAliasToggle converted to UML_Resize_with_Show_Aliases_Mode
07191:                    // with default false.
07192:                    if (prefs.getBoolean("UML_Resize_with_Show_Aliases_Mode",
07193:                            false)) {
07194:                        // Resize all the elements
07195:                        // WHY ARE WE SETTING THIS TO FALSE IF CONDITION IS TRUE?
07196:                        sizeToContents(false);
07197:                    }
07198:                    bDidChange = true;
07199:                } else {
07200:                    syncElements(false);
07201:                    bDidChange = true;
07202:                }
07203:
07204:                if (bDidChange) {
07205:                    // properties have been set, mark this diagram dirty and invalidate
07206:                    setIsDirty(true);
07207:                    refresh(false);
07208:                }
07209:
07210:                return true;
07211:            }
07212:
07213:            /* (non-Javadoc)
07214:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#pumpMessages(boolean)
07215:             */
07216:            public void pumpMessages(boolean bJustDrawingMessages) {
07217:                Thread.yield();
07218:            }
07219:
07220:            /**
07221:             * Ask the user what to do about a name collision
07222:             *
07223:             * @param pCompartmentBeingEdited [in] The compartment being edited
07224:             * @param pElement [in] The element being renamed
07225:             * @param sProposedName [in] The new name
07226:             * @param pCollidingElements [in] A list of elements this name collides with
07227:             * @param pCell [in] The result cell.  Used to cancel the rename.
07228:             */
07229:            public void questionUserAboutNameCollision(
07230:                    ICompartment pCompartmentBeingEdited,
07231:                    INamedElement pElement, String sProposedName,
07232:                    ETList<INamedElement> pCollidingElements, IResultCell pCell) {
07233:                if (m_DiagramEngine != null) {
07234:                    boolean bContinue = m_DiagramEngine
07235:                            .questionUserAboutNameCollision(
07236:                                    pCompartmentBeingEdited, pElement,
07237:                                    sProposedName, pCollidingElements);
07238:                    if (!bContinue) {
07239:                        // Engine cancelled it
07240:                        pCell.setContinue(false);
07241:                    }
07242:                }
07243:            }
07244:
07245:            /* (non-Javadoc)
07246:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#receiveBroadcast(com.embarcadero.describe.diagrams.IBroadcastAction)
07247:             */
07248:            public void receiveBroadcast(IBroadcastAction pAction) {
07249:                if (pAction != null) {
07250:                    // Block the delayed actions
07251:                    //CDelayedActionBlocker blocker(_T("ReceiveBroadcast"));
07252:                    if (pAction instanceof  ISimpleBroadcastAction) {
07253:                        ISimpleBroadcastAction pSimple = (ISimpleBroadcastAction) pAction;
07254:                        int nKind = pSimple.getKind();
07255:                        switch (nKind) {
07256:                        case DiagramAreaEnumerations.SBK_DEEP_SYNC: {
07257:                            syncElements(false);
07258:                        }
07259:                            break;
07260:                        case DiagramAreaEnumerations.SBK_TOOLTIPS_ON: {
07261:                            setEnableTooltips(true);
07262:                        }
07263:                            break;
07264:                        case DiagramAreaEnumerations.SBK_TOOLTIPS_OFF: {
07265:                            setEnableTooltips(false);
07266:                        }
07267:                            break;
07268:                        case DiagramAreaEnumerations.SBK_CLEAR_CLIPBOARD: {
07269:                            clearClipboard();
07270:                        }
07271:                            break;
07272:                        /* TODO
07273:                        case DiagramAreaEnumerations.SBK_FLUSH_DELAYEDACTION_QUEUE :
07274:                        {
07275:                        if (m_hWnd)
07276:                        {
07277:                        ::PostMessage(m_hWnd, WM_DELAYEDACTION,0,0);
07278:                        }
07279:                        }
07280:                        break;
07281:                         */
07282:                        }
07283:                    } else if (pAction instanceof  IElementBroadcastAction) {
07284:                        IElementBroadcastAction pElementAction = (IElementBroadcastAction) pAction;
07285:                        ETList<IElement> pElements = pElementAction
07286:                                .getModelElements();
07287:                        int nKind = pElementAction.getKind();
07288:                        switch (nKind) {
07289:                        case DiagramAreaEnumerations.EBK_DEEP_SYNC:
07290:                        case DiagramAreaEnumerations.EBK_DEEP_SYNC_AND_RESIZE: {
07291:                            ISimpleElementsAction pElementsAction = new SimpleElementsAction();
07292:                            if (pElementsAction != null) {
07293:                                pElementsAction.setElements(pElements);
07294:                                if (nKind == DiagramAreaEnumerations.EBK_DEEP_SYNC) {
07295:                                    pElementsAction
07296:                                            .setKind(DiagramAreaEnumerations.SEAK_DEEPSYNC_BROADCAST);
07297:                                } else {
07298:                                    pElementsAction
07299:                                            .setKind(DiagramAreaEnumerations.SEAK_DEEPSYNC_AND_RESIZE_BROADCAST);
07300:                                }
07301:                                postDelayedAction(pElementsAction);
07302:                            }
07303:                        }
07304:                            break;
07305:                        }
07306:                    }
07307:                }
07308:            }
07309:
07310:            /* (non-Javadoc)
07311:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#reconnectLink(com.embarcadero.describe.foundation.IPresentationElement, com.embarcadero.describe.foundation.IPresentationElement, com.embarcadero.describe.foundation.IPresentationElement)
07312:             */
07313:            public boolean reconnectLink(IPresentationElement pLink,
07314:                    IPresentationElement pOldNode, IPresentationElement pNewNode) {
07315:                // TODO Auto-generated method stub
07316:                return false;
07317:            }
07318:
07319:            /* (non-Javadoc)
07320:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#refresh(boolean)
07321:             */
07322:            public void refresh(boolean bPostMessage) {
07323:                TSEGraphWindow window = getGraphWindow();
07324:                if (window != null) {
07325:                    DrawingAreaRefreshHelper.refreshDrawingArea(this ,
07326:                            !bPostMessage);
07327:                }
07328:            }
07329:
07330:            /* (non-Javadoc)
07331:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#refreshRect(com.embarcadero.describe.umlsupport.IETRect)
07332:             */
07333:            public void refreshRect(IETRect pRefreshRect) {
07334:                TSEGraphWindow window = getGraphWindow();
07335:                if (window != null) {
07336:                    if (pRefreshRect != null) {
07337:                        window.addInvalidRegion(RectConversions
07338:                                .etRectToTSRect(pRefreshRect));
07339:                        DrawingAreaRefreshHelper
07340:                                .refreshDrawingArea(this , false);
07341:                    } else {
07342:                        DrawingAreaRefreshHelper.refreshDrawingArea(this , true);
07343:                    }
07344:                }
07345:            }
07346:
07347:            /**
07348:             * Removes an associated diagram from our list
07349:             *
07350:             * @param sDiagramXMIID [in] The xmiid of the diagram to remove.
07351:             */
07352:            public void removeAssociatedDiagram(String sDiagramXMIID) {
07353:                if (!m_ReadOnly && sDiagramXMIID != null
07354:                        && sDiagramXMIID.length() > 0) {
07355:                    if (m_AssociatedDiagrams != null) {
07356:                        int count = m_AssociatedDiagrams.size();
07357:                        for (int i = 0; i < count; i++) {
07358:                            String str = (String) m_AssociatedDiagrams.get(i);
07359:                            if (str.equals(sDiagramXMIID)) {
07360:                                m_AssociatedDiagrams.remove(i);
07361:                                setIsDirty(true);
07362:                                break;
07363:                            }
07364:                        }
07365:                    }
07366:                }
07367:            }
07368:
07369:            /**
07370:             * Removes an associated diagram from our list
07371:             *
07372:             * @param pDiagram [in] The diagram we should remove
07373:             */
07374:            public void removeAssociatedDiagram2(IProxyDiagram pDiagram) {
07375:                if (pDiagram != null) {
07376:                    String xmiid = pDiagram.getXMIID();
07377:                    if (!m_ReadOnly && xmiid != null && xmiid.length() > 0) {
07378:                        removeAssociatedDiagram(xmiid);
07379:                    }
07380:                }
07381:            }
07382:
07383:            /**
07384:             * Removes an associated element from our list
07385:             *
07386:             * @param sTopLevelElementXMIID [in] The elements toplevel id
07387:             * @param sModelElementXMIID [in] The element we should remove
07388:             */
07389:            public void removeAssociatedElement(String topXMIID, String meID) {
07390:                if (!m_ReadOnly && topXMIID != null && topXMIID.length() > 0
07391:                        && meID != null && meID.length() > 0) {
07392:                    if (m_AssociatedElements != null) {
07393:                        Object obj = m_AssociatedElements.get(topXMIID);
07394:                        if (obj != null) {
07395:                            // Found it so erase
07396:                            if (obj instanceof  Vector) {
07397:                                Vector meidCol = (Vector) obj;
07398:                                meidCol.remove(meID);
07399:
07400:                                if (meidCol.size() == 0) {
07401:                                    m_AssociatedElements.remove(topXMIID);
07402:                                }
07403:                            }
07404:                            setIsDirty(true);
07405:                        }
07406:                    }
07407:                }
07408:            }
07409:
07410:            /**
07411:             * Removes an associated element from our list
07412:             *
07413:             * @param pElement [in] The element we should remove
07414:             */
07415:            public void removeAssociatedElement2(IElement pElement) {
07416:                if (pElement != null) {
07417:                    String topId = pElement.getTopLevelId();
07418:                    String xmiid = pElement.getXMIID();
07419:                    if (!m_ReadOnly && topId != null && topId.length() > 0
07420:                            && xmiid != null && xmiid.length() > 0) {
07421:                        removeAssociatedElement(topId, xmiid);
07422:                    }
07423:                }
07424:            }
07425:
07426:            /* (non-Javadoc)
07427:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#removeElements(com.embarcadero.describe.foundation.IPresentationElement[])
07428:             */
07429:            public void removeElements(
07430:                    ETList<IPresentationElement> pItemsToRemove) {
07431:                ETList<TSENode> nodeList = new ETArrayList<TSENode>();
07432:                ETList<TSEEdge> edgeList = new ETArrayList<TSEEdge>();
07433:                ETList<TSENodeLabel> nodeLabelList = new ETArrayList<TSENodeLabel>();
07434:                ETList<TSEEdgeLabel> edgeLabelList = new ETArrayList<TSEEdgeLabel>();
07435:
07436:                int count = 0;
07437:                if (pItemsToRemove != null) {
07438:                    count = pItemsToRemove.getCount();
07439:                }
07440:                if (count > 0) {
07441:                    for (int index = 0; index < count; index++) {
07442:                        IPresentationElement pe = pItemsToRemove.item(index);
07443:
07444:                        if (pe != null) {
07445:                            TSENode node = TypeConversions.getOwnerNode(pe);
07446:                            TSEEdge edge = TypeConversions.getOwnerEdge(pe,
07447:                                    false);
07448:                            //                TSEEdgeLabel edgeLabel = TypeConversions.getEdgeLabel(pe);
07449:                            if (node != null) {
07450:                                nodeList.addIfNotInList(node);
07451:                            }
07452:
07453:                            if (edge != null) {
07454:                                edgeList.addIfNotInList(edge);
07455:                            }
07456:                            //               if(edgeLabel != null) {
07457:                            //                   edgeLabelList.addIfNotInList(edgeLabel);
07458:                            //               }
07459:                            INodePresentation nodePresentation = null;
07460:                            if (pe instanceof  INodePresentation) {
07461:                                nodePresentation = (INodePresentation) pe;
07462:                            }
07463:                            IEdgePresentation edgePresentation = null;
07464:                            if (pe instanceof  IEdgePresentation) {
07465:                                edgePresentation = (IEdgePresentation) pe;
07466:
07467:                                //               if(nodePresentation != null)
07468:                                //                  nodePresentation.setTSNode(null);
07469:                                //               else if(edgePresentation != null)
07470:                                //                  edgePresentation.setTSEdge(null);
07471:                            }
07472:                        }
07473:                    }
07474:
07475:                    pItemsToRemove = null;
07476:
07477:                    deleteTheseItems(nodeList, edgeList, nodeLabelList,
07478:                            edgeLabelList, false, false);
07479:
07480:                    // Fix J1170:  Added this refresh section of code from C++
07481:                    // It's possible that the delete just whacked this diagram.  If the element that
07482:                    // got deleted was the owner of this diagram then ... we're gone to!
07483:                    // TODO if( isWindow() )
07484:                    {
07485:                        refresh(false);
07486:                    }
07487:                }
07488:            }
07489:
07490:            /*
07491:             * In the C++ code this routine is used to delay the actions.
07492:             * In the Java code we just call the actions themselves, and if needed they delay themselves
07493:             *
07494:             * There is a lot of code on the C++ side that is not implemented here.
07495:             */
07496:            protected boolean onHandleDelayedAction(IDelayedAction action) {
07497:                // This code is similar to the C++ code, but it did not seem to help CDFS during Web Report,
07498:                // so I'm (BDB) leaving it out for now.
07499:                //      try
07500:                //      {
07501:                //         while (DABlocker.getIsDisabled() || IOSemaphore.isIOHappenning())
07502:                //         {
07503:                //            Thread.sleep(500);
07504:                //         }
07505:                //      }
07506:                //      catch( InterruptedException e )
07507:                //      {
07508:                //         e.printStackTrace();
07509:                //      }
07510:                boolean handled = m_DiagramEngine != null ? m_DiagramEngine
07511:                        .handleDelayedAction(action) : false;
07512:                if (!handled) {
07513:                    if (action instanceof  IExecutableAction) {
07514:                        IExecutableAction selfExecutableAction = (IExecutableAction) action;
07515:
07516:                        // The presentation action handles all events.  If the diagram engine wants to
07517:                        // handle some it has the opportunity at the top of this loop.
07518:                        selfExecutableAction.execute(this );
07519:                    }
07520:                }
07521:
07522:                return handled;
07523:            }
07524:
07525:            /* (non-Javadoc)
07526:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#resetDrawEngine(org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject, java.lang.String)
07527:             */
07528:            public void resetDrawEngine(IETGraphObject pETGraphObject,
07529:                    String sNewInitString) {
07530:                IDrawEnginesToResetAction pResetAction = new DrawEnginesToResetAction();
07531:                if (pResetAction != null) {
07532:                    pResetAction.init2(pETGraphObject, sNewInitString);
07533:                    postDelayedAction(pResetAction);
07534:                }
07535:            }
07536:
07537:            /* (non-Javadoc)
07538:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#resetDrawEngine2(org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject)
07539:             */
07540:            public void resetDrawEngine2(IETGraphObject pETElement) {
07541:                // TODO Auto-generated method stub
07542:            }
07543:
07544:            /**
07545:             * Save this diagram.
07546:             */
07547:            public synchronized void save() {
07548:                if (getIsDirty()) {
07549:                    // Directly save to real diagram files.  No need to save to temp files;
07550:                    // hence no need to call preCommit.
07551:                    //preCommit();
07552:                    commit();
07553:                    getDiagram().setIsDirty(false);
07554:                }
07555:            }
07556:
07557:            //    public void save()
07558:            //    {
07559:            //        if (getIsDirty())
07560:            //        {
07561:            //            Mutex m = new Mutex();
07562:            //
07563:            //            m.writeAccess(new Mutex.Action()
07564:            //            {
07565:            //
07566:            //                public Object run()
07567:            //                {
07568:            //                    preCommit();
07569:            //                    commit();
07570:            //                    return null;
07571:            //                }
07572:            //            });
07573:            //        }
07574:            //        getDiagram().setIsDirty(false);
07575:            //    }
07576:
07577:            /**
07578:             * Allows the diagram to perform some cleanup before the diagram is actually
07579:             * closed.
07580:             */
07581:            public synchronized void preClose() {
07582:                onDestroy();
07583:                notifyAll();
07584:            }
07585:
07586:            /*
07587:             * Hides and releases references to the secondary windows, ie the overview, layout properties, drawing, and the Preferences.
07588:             */
07589:            protected void closeAllSecondaryWindows() {
07590:                if (this .isOverviewWindowOpen()) {
07591:                    this .overviewWindow(false);
07592:                }
07593:
07594:                if (getIsGraphPreferencesDialogOpen()) {
07595:                    this .graphPreferencesDialog(false);
07596:                }
07597:
07598:                if (getIsLayoutPropertiesDialogOpen()) {
07599:                    layoutPropertiesDialog(false);
07600:                }
07601:            }
07602:
07603:            /**
07604:             * Handles the destruction of this control.
07605:             */
07606:            protected void onDestroy() {
07607:                IOSemaphore.startInstance();
07608:                try {
07609:                    if (kbAccessProvider != null) {
07610:                        if (kbAccessProvider.getDiagramDrawingCtrl() == this ) {
07611:                            kbAccessProvider.unregisterKeyCommands(this );
07612:                            kbAccessProvider.setDiagramDrawingCtrl(null);
07613:                        }
07614:                        kbAccessProvider = null;
07615:                    }
07616:                    // Use a null graph ui, so no threads can draw the graph.
07617:                    this .getCurrentGraph().setUI(new ETNullGraphUI());
07618:
07619:                    closeAllSecondaryWindows();
07620:                    m_GraphWindow.setVisible(false);
07621:                    releaseTSResource();
07622:
07623:                    if (m_DiagramEngine != null) {
07624:                        m_DiagramEngine.revokeAccelerators();
07625:                        m_DiagramEngine.detach();
07626:                    }
07627:
07628:                    if (m_drawingAreaDispatcher != null) {
07629:                        IEventPayload payload = m_drawingAreaDispatcher
07630:                                .createPayload("DiagramClosed");
07631:                        m_drawingAreaDispatcher.fireDrawingAreaClosed(
07632:                                m_Diagram, m_isDirty, payload);
07633:                    }
07634:
07635:                    // Tell the product that this drawing area no longer exists
07636:                    if (m_Diagram != null) {
07637:                        IProduct prod = getProduct();
07638:                        if (prod != null) {
07639:                            prod.removeDiagram(m_Diagram);
07640:                        }
07641:                    }
07642:
07643:                    if (m_CollisionHandler != null) {
07644:                        m_CollisionHandler.setDrawingArea(null);
07645:                    }
07646:
07647:                    m_NameCollisionListener = null;
07648:
07649:                    //         m_Drop.revoke();
07650:                    registerAllSinks(false);
07651:                    m_DrawingAreaEventsSink = null;
07652:
07653:                    m_Namespace = null;
07654:                    modelElement = null;
07655:                    m_drawingAreaDispatcher = null;
07656:
07657:                    revokeResourceManager();
07658:
07659:                    // Fixed 113264.
07660:                    // Remove trackBarChangeListener and trackBarModifyListener listeners form
07661:                    // the event sources. The event source (1st parameter) must be the same event
07662:                    // source used when adding these listerner (see initGraphWindow() ); otherwise,
07663:                    // the listeners are till listerning to events even afer the garph has been destroyed.
07664:                    TSEGraphManager graphManager = getGraphManager();
07665:                    TSEventManager graphEventManager = graphManager
07666:                            .getEventManager();
07667:                    if (trackBarChangeListener != null) {
07668:                        ((TSEEventManager) graphEventManager)
07669:                                .removeViewportChangeListener(getGraphWindow(),
07670:                                        getActions());
07671:                        ((TSEEventManager) graphEventManager)
07672:                                .removeViewportChangeListener(getGraphWindow(),
07673:                                        trackBarChangeListener);
07674:                    }
07675:
07676:                    if (trackBarModifyListener != null) {
07677:                        graphEventManager.removeGraphChangeListener(
07678:                                graphManager, getActions());
07679:                        graphEventManager.removeGraphChangeListener(
07680:                                graphManager, trackBarModifyListener);
07681:                    }
07682:
07683:                    //m_GraphWindow.removeGraphChangeListener(getActions());
07684:                    m_Diagram = null;
07685:
07686:                    //JM: cleaning up service input data table..
07687:                    if (this .serviceInputDataTable != null
07688:                            && this .getGraphWindow() != null) {
07689:                        this .serviceInputDataTable.remove(this .getGraphWindow()
07690:                                .getGraphManager());
07691:                    }
07692:
07693:                    //         m_PresentationsTypesMgr = null;
07694:                    if (m_GraphWindow != null) {
07695:                        m_GraphWindow.m_drawingAreaCtrl = null;
07696:                        m_GraphWindow.removeMouseWheelListener(this );
07697:                        m_GraphWindow.getCanvas().removeFocusListener(
07698:                                focusAdapter);
07699:                        m_GraphWindow.getCanvas().removeMouseListener(
07700:                                mouseHandler);
07701:                        m_GraphWindow.removeKeyListener(keyHandler);
07702:
07703:                        m_GraphWindow.getInputMap(WHEN_FOCUSED).clear();
07704:                        m_GraphWindow.getInputMap(WHEN_IN_FOCUSED_WINDOW)
07705:                                .clear();
07706:                        m_GraphWindow.getInputMap(
07707:                                WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).clear();
07708:                        m_GraphWindow.getActionMap().clear();
07709:
07710:                        m_GraphWindow = null;
07711:                    }
07712:                    xmlReader = null;
07713:                    if (resourceBundle != null) {
07714:                        this .resourceBundle.clearDrawingAreaControlRefs();
07715:                        this .resourceBundle = null;
07716:                    }
07717:
07718:                    getInputMap(WHEN_FOCUSED).clear();
07719:                    getInputMap(WHEN_IN_FOCUSED_WINDOW).clear();
07720:                    getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).clear();
07721:                    getActionMap().clear();
07722:
07723:                    actions.clearDrawingAreaControlRefs();
07724:                    actions = null;
07725:                    this .removeKeyListener(this );
07726:                    remove(centerPanel);
07727:                    remove(northPanel);
07728:                } finally {
07729:                    IOSemaphore.stopInstance();
07730:                }
07731:            }
07732:
07733:            /**
07734:             * Remove the resource manager for this drawing area
07735:             */
07736:            protected void revokeResourceManager() {
07737:                ResourceMgr mgr = ResourceMgr.instance(this );
07738:                if (mgr != null) {
07739:                    mgr.revoke();
07740:                }
07741:            }
07742:
07743:            /**
07744:             * Release the Tom Sawyer references to the drawing area control.
07745:             */
07746:            protected void releaseTSResource() {
07747:                // Remove all our presentation elements, the only difference is that the IETGraphObject.delete gets invoked,
07748:                // If we want we can just remove this, TSS can handle is alot faster then we can.  (Kevin)
07749:                ETList<IPresentationElement> presentationElements = getAllItems();
07750:                if (presentationElements != null) {
07751:                    for (Iterator<IPresentationElement> iter = presentationElements
07752:                            .iterator(); iter.hasNext();) {
07753:                        GetHelper.removePresentationElement(iter.next());
07754:                    }
07755:                }
07756:
07757:                getGraphWindow().resetGraphWindow();
07758:                // Now whack the graph.
07759:                //getGraphWindow().getGraphManager().emptyTopology(); //JM: This is not required..
07760:                TSEGraphManager originalManager = getGraphManager();
07761:                if (originalManager != null) {
07762:                    TSENestingManager.discardManager(originalManager);
07763:                    TSEFoldingManager.discardManager(originalManager);
07764:                    TSEHidingManager.discardManager(originalManager);
07765:                }
07766:            }
07767:
07768:            /* (non-Javadoc)
07769:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#saveAsGraphic(java.lang.String, int)
07770:             */
07771:            public boolean saveAsGraphic(String sFilename, int nKind) {
07772:                return GetHelper.saveAsGraphic(this .getGraphWindow(),
07773:                        sFilename, nKind);
07774:            }
07775:
07776:            /* (non-Javadoc)
07777:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#saveAsGraphic2(java.lang.String, int, com.embarcadero.describe.diagrams.IGraphicExportDetails)
07778:             */
07779:            public IGraphicExportDetails saveAsGraphic2(String sFilename,
07780:                    int nKind) {
07781:                return GetHelper.saveAsGraphic2(this .getGraphWindow(),
07782:                        sFilename, nKind);
07783:            }
07784:
07785:            public IGraphicExportDetails saveAsGraphic2(String sFilename,
07786:                    int nKind, double scale) {
07787:                return GetHelper.saveAsGraphic2(this .getGraphWindow(),
07788:                        sFilename, nKind, scale);
07789:            }
07790:
07791:            /* (non-Javadoc)
07792:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#selectAll(boolean)
07793:             */
07794:            public void selectAll(boolean bSelect) {
07795:                if (this .getGraphWindow() != null) {
07796:                    if (bSelect) {
07797:                        this .getGraphWindow().selectAll(true);
07798:                    } else {
07799:                        this .getGraphWindow().deselectAll(true);
07800:                    }
07801:
07802:                    ETGraph etGraph = getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
07803:                            : null;
07804:
07805:                    if (etGraph != null) {
07806:                        this .fireSelectEvent(etGraph.getSelectedObjects(false,
07807:                                false));
07808:                    }
07809:                }
07810:            }
07811:
07812:            /* (non-Javadoc)
07813:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#selectAllSimilar()
07814:             */
07815:            public void selectAllSimilar() {
07816:
07817:                ETList<IETGraphObject> selected = getSelected3();
07818:                ETGraph etGraph = selected != null
07819:                        && getGraph() instanceof  ETGraph ? (ETGraph) getGraph()
07820:                        : null;
07821:                if (etGraph != null) {
07822:                    ETList<IETGraphObject> allObjects = etGraph
07823:                            .getAllETGraphObjects();
07824:
07825:                    allObjects.removeThese(selected);
07826:                    Iterator<IETGraphObject> selectedIter = selected.iterator();
07827:                    while (selectedIter.hasNext()) {
07828:                        IETGraphObject selectedObject = selectedIter.next();
07829:                        IDrawEngine selectedDrawEngine = selectedObject
07830:                                .getEngine();
07831:
07832:                        String sDrawEngineType = selectedDrawEngine != null ? selectedDrawEngine
07833:                                .getDrawEngineMatchID()
07834:                                : null;
07835:                        if (sDrawEngineType != null
07836:                                && sDrawEngineType.length() > 0) {
07837:                            Iterator<IETGraphObject> allObjectsIter = allObjects
07838:                                    .iterator();
07839:                            while (allObjectsIter.hasNext()) {
07840:                                IETGraphObject graphObject = allObjectsIter
07841:                                        .next();
07842:                                if (!graphObject.isSelected()) {
07843:                                    IDrawEngine nonSelectedDrawEngine = graphObject
07844:                                            .getEngine();
07845:                                    String nonSelectedMatchID = nonSelectedDrawEngine != null ? nonSelectedDrawEngine
07846:                                            .getDrawEngineMatchID()
07847:                                            : null;
07848:
07849:                                    if (nonSelectedMatchID != null
07850:                                            && nonSelectedMatchID
07851:                                                    .equals(sDrawEngineType)) {
07852:                                        graphObject.setSelected(true);
07853:                                        graphObject.invalidate();
07854:                                    }
07855:                                }
07856:                            }
07857:                        }
07858:                    }
07859:
07860:                    this .fireSelectEvent(etGraph != null ? etGraph
07861:                            .getSelectedObjects(false, false) : null);
07862:                    this .refresh(true);
07863:                }
07864:            }
07865:
07866:            /**
07867:             * Puts the diagram alias
07868:             *
07869:             * @param newVal [in] The new alias of the diagram.
07870:             */
07871:            public void setAlias(String newVal) {
07872:                boolean isSame = true;
07873:                boolean fireEvents = true;
07874:
07875:                if (m_Alias != null && m_Alias.length() > 0) {
07876:                    // If the namespace is being changed then fire an event
07877:                    if (newVal != null && newVal.length() > 0) {
07878:                        if (!m_Alias.equals(newVal)) {
07879:                            isSame = false;
07880:                        }
07881:                    } else {
07882:                        isSame = false;
07883:                    }
07884:                } else if (newVal != null && newVal.length() > 0) {
07885:                    isSame = false;
07886:                    fireEvents = false;
07887:                }
07888:
07889:                if (!isSame) {
07890:                    boolean proceed = true;
07891:
07892:                    // Let folks know that the alias is being changed.
07893:                    if (getDrawingAreaDispatcher() != null && fireEvents) {
07894:                        proceed = fireDrawingAreaPrePropertyChange(DiagramAreaEnumerations.DAPK_ALIAS);
07895:                    }
07896:
07897:                    if (proceed) {
07898:                        m_Alias = newVal;
07899:                        if (fireEvents) {
07900:                            setIsDirty(true);
07901:
07902:                            // Let folks know that the alias has changed.
07903:                            fireDrawingAreaPropertyChange(DiagramAreaEnumerations.DAPK_ALIAS);
07904:                        }
07905:                    }
07906:                }
07907:            }
07908:
07909:            /**
07910:             * Set the type of this drawing
07911:             *
07912:             * @param newVal [in] The new type of this diagram (ie DK_CLASS_DIAGRAM)
07913:             */
07914:            public void setDiagramKind(int value) {
07915:                IDiagramTypesManager diaMgr = DiagramTypesManager.instance();
07916:                m_DiagramKindDisplayName = diaMgr.getDiagramTypeName(value);
07917:                if (m_DiagramKindDisplayName != null
07918:                        && m_DiagramKindDisplayName.length() > 0) {
07919:                    if (m_DiagramEngine != null) {
07920:                        m_DiagramEngine.detach();
07921:                        m_DiagramEngine = null;
07922:                    }
07923:
07924:                    String engineType = diaMgr
07925:                            .getDiagramEngine(m_DiagramKindDisplayName);
07926:                    if (engineType != null && engineType.length() > 0) {
07927:                        ICreationFactory pCreatFact = FactoryRetriever
07928:                                .instance().getCreationFactory();
07929:                        Object obj = pCreatFact.retrieveEmptyMetaType(
07930:                                "DiagramEngines", engineType, null);
07931:
07932:                        if (obj != null) {
07933:                            if (obj instanceof  IDiagramEngine) {
07934:                                m_DiagramEngine = (IDiagramEngine) obj;
07935:                            }
07936:
07937:                            if (m_DiagramEngine != null) {
07938:                                m_DiagramEngine.attach(this );
07939:
07940:                                // Set the quickkeys
07941:                                m_DiagramEngine.setQuickKeys(getGraphWindow());
07942:
07943:                                // Register any accelerators
07944:                                m_DiagramEngine.registerAccelerators();
07945:
07946:                                // Go back to select draw mode
07947:                                enterMode(IDrawingToolKind.DTK_SELECTION);
07948:                            }
07949:                        }
07950:                    }
07951:                }
07952:
07953:                // Since the diagram kind has changed we should reset the IDiagram, if we
07954:                // have one, because it may not represent the correct diagram type anymore.
07955:                m_Diagram = null;
07956:                //      if((m_Diagram != null) && (m_Diagram.getDiagramKind() != value))
07957:                //      {
07958:                //          m_Diagram = null;
07959:                //      }
07960:                // Now set up any track bar based on the diagram type
07961:                initializeTrackBar();
07962:
07963:                if (m_showToolbars) {
07964:                    this .createToolbars();
07965:                }
07966:            }
07967:
07968:            /**
07969:             * Set the type of this drawing.  This routine converts the string to a DiagramKind (ie
07970:             * "Class Diagram" to DK_CLASS_DIAGRAM).
07971:             *
07972:             * @param newVal [in] Sets the kind of this diagram.
07973:             */
07974:            public void setDiagramKind2(String value) {
07975:                setDiagramKind(DiagramTypesManager.instance().getDiagramKind(
07976:                        value));
07977:            }
07978:
07979:            /**
07980:             * Sets the documentation associated with this diagram
07981:             *
07982:             * @param sDocs [in] The new documentation for this diagram.
07983:             */
07984:            public void setDocumentation(String value) {
07985:                boolean isSame = false;
07986:
07987:                // If the documentation is being changed then fire an event
07988:                if (m_Documentation.equals(value)) {
07989:                    isSame = true;
07990:                }
07991:
07992:                if (!isSame) {
07993:
07994:                    // Let folks know that the documentation is being changed.
07995:                    boolean proceed = fireDrawingAreaPrePropertyChange(DiagramAreaEnumerations.DAPK_DOCUMENTATION);
07996:
07997:                    if (proceed) {
07998:                        m_Documentation = value;
07999:                        setIsDirty(true);
08000:
08001:                        fireDrawingAreaPropertyChange(DiagramAreaEnumerations.DAPK_DOCUMENTATION);
08002:                    }
08003:                }
08004:            }
08005:
08006:            /* (non-Javadoc)
08007:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setEdgeDescription(java.lang.String)
08008:             */
08009:            public void setEdgeDescription(String value) {
08010:                setMode(ADDrawingAreaConstants.ADD_EDGE_CMD, value);
08011:            }
08012:
08013:            /* (non-Javadoc)
08014:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setEnableTooltips(boolean)
08015:             */
08016:            public void setEnableTooltips(boolean bEnable) {
08017:                // TODO Auto-generated method stub
08018:            }
08019:
08020:            /* (non-Javadoc)
08021:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setFocus()
08022:             */
08023:            public void setFocus() {
08024:                //requestFocus();
08025:                super .requestFocusInWindow();
08026:            }
08027:
08028:            public boolean isFocused() {
08029:                return isFocusOwner();
08030:            }
08031:
08032:            /* (non-Javadoc)
08033:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setGridSize(int)
08034:             */
08035:            public void setGridSize(int value) {
08036:                // TODO Auto-generated method stub
08037:            }
08038:
08039:            /* (non-Javadoc)
08040:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setGridType(int)
08041:             */
08042:            public void setGridType(int value) {
08043:                // TODO Auto-generated method stub
08044:            }
08045:
08046:            /**
08047:             * Set IsDirty true when there is data that needs to be saved
08048:             *
08049:             * @param bIsDirty [in] Set the diagram as dirty.
08050:             */
08051:            public void setIsDirty(boolean value) {
08052:                if (m_isDirty == value) {
08053:                    return;
08054:                }
08055:                IProxyUserInterface pProxyUserInterface = ProductHelper
08056:                        .getProxyUserInterface();
08057:                if (pProxyUserInterface != null) {
08058:                    IDiagram dia = getDiagram();
08059:                    if (dia != null) {
08060:                        boolean proceed = true;
08061:
08062:                        // Let folks know that the dirty flag is being changed.
08063:                        if (getDrawingAreaDispatcher() != null) {
08064:                            IEventPayload payload = m_drawingAreaDispatcher
08065:                                    .createPayload("FireDrawingAreaPrePropertyChange");
08066:                            IProxyDiagram pProxy = getProxyDiagram();
08067:                            if (pProxy != null) {
08068:                                proceed = m_drawingAreaDispatcher
08069:                                        .fireDrawingAreaPrePropertyChange(
08070:                                                pProxy,
08071:                                                DiagramAreaEnumerations.DAPK_DIRTYSTATE,
08072:                                                payload);
08073:                            }
08074:                        }
08075:
08076:                        if (proceed) {
08077:
08078:                            pProxyUserInterface.dirtyStateChanged(dia, value);
08079:
08080:                            fireDrawingAreaPropertyChange(IDrawingAreaPropertyKind.DAPK_DIRTYSTATE);
08081:                            firePropertyChange(DIRTYSTATE, m_isDirty, value);
08082:                            m_isDirty = value;
08083:                        }
08084:
08085:                        // Tell the namespace that it has a child that's dirty
08086:                        if (m_Namespace != null) {
08087:                            IProject pProject = m_Namespace.getProject();
08088:                            if (pProject != null) {
08089:                                // Just let the Project know that one of its children is dirty.
08090:                                // In effect however, the .etd file or event the .etx file that the
08091:                                // diagram is appearing in is unchanged.
08092:                                pProject.setChildrenDirty(m_isDirty);
08093:                            }
08094:                        }
08095:                    }
08096:                }
08097:            }
08098:
08099:            /* (non-Javadoc)
08100:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setLastSelectedButton(int)
08101:             */
08102:            public void setLastSelectedButton(int value) {
08103:                // TODO Auto-generated method stub
08104:            }
08105:
08106:            /**
08107:             * Sets the drawing area to a new layout style.
08108:             *
08109:             * @param nLayoutStyle [in] The new layout style for this diagram.
08110:             */
08111:            public void setLayoutStyle(int nLayoutStyle) {
08112:                ETSystem.out.println("m_ReadOnly = " + m_ReadOnly);
08113:                if (!m_ReadOnly) {
08114:                    ITopographyChangeAction pAction = new TopographyChangeAction();
08115:                    pAction.setKind(DiagramAreaEnumerations.TAK_LAYOUTCHANGE);
08116:                    pAction.setLayoutStyle(nLayoutStyle);
08117:                    postDelayedAction(pAction);
08118:                    getResources().setLayoutStyle(nLayoutStyle);
08119:                }
08120:            }
08121:
08122:            /**
08123:             * Sets the drawing area to a new layout style.  This routine does it without asking the user
08124:             * if the layout is ok.
08125:             *
08126:             * @param nLayoutStyle [in] The new layout style for this diagram.
08127:             */
08128:            public void setLayoutStyleSilently(int nLayoutStyle) {
08129:                if (!m_ReadOnly) {
08130:                    ITopographyChangeAction pAction = new TopographyChangeAction();
08131:                    pAction
08132:                            .setKind(DiagramAreaEnumerations.TAK_LAYOUTCHANGE_SILENT);
08133:                    pAction.setLayoutStyle(nLayoutStyle);
08134:                    postDelayedAction(pAction);
08135:                    getResources().setLayoutStyle(nLayoutStyle);
08136:                }
08137:            }
08138:
08139:            /* (non-Javadoc)
08140:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setModelElement(com.embarcadero.describe.foundation.IElement)
08141:             */
08142:            public void setModelElement(IElement value) {
08143:                modelElement = value;
08144:            }
08145:
08146:            /* (non-Javadoc)
08147:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setModeLocked(boolean)
08148:             */
08149:            public void setModeLocked(boolean value) {
08150:                // TODO Auto-generated method stub
08151:            }
08152:
08153:            /**
08154:             * Initializes the diagram with a namespace
08155:             *
08156:             * @param pNamespace [in] The new namespace for this diagram.
08157:             */
08158:            public void setNamespace(INamespace pNamespace) {
08159:                boolean isSame = true;
08160:                boolean fireEvents = true;
08161:
08162:                if (m_Namespace != null) {
08163:                    // If the namespace is being changed then fire an event
08164:                    if (pNamespace != null) {
08165:                        isSame = m_Namespace.isSame(pNamespace);
08166:                    } else {
08167:                        isSame = false;
08168:                    }
08169:                } else if (pNamespace != null) {
08170:                    isSame = false;
08171:                    fireEvents = false;
08172:                }
08173:
08174:                if (!isSame) {
08175:                    boolean proceed = true;
08176:                    if (fireEvents) {
08177:                        proceed = fireDrawingAreaPrePropertyChange(DiagramAreaEnumerations.DAPK_NAMESPACE);
08178:                    }
08179:
08180:                    if (proceed) {
08181:                        m_Namespace = pNamespace;
08182:
08183:                        if (fireEvents) {
08184:                            //No need to set dirty state for nameSpace change. The change apply right away.
08185:                            //setIsDirty(true);
08186:                            // Let folks know that the namespace has changed.
08187:                            fireDrawingAreaPropertyChange(DiagramAreaEnumerations.DAPK_NAMESPACE);
08188:
08189:                            // Tell the product elements about the events
08190:                            //ETElementManager = new ETElementManager(this);
08191:                            //manager.onDiagramNamespaceChanged();
08192:                        }
08193:
08194:                        setDiagramNodeNameAndOwner();
08195:                    }
08196:                }
08197:            }
08198:
08199:            /**
08200:             * Sets / Gets the name or alias of this element.
08201:             */
08202:            public void setNameWithAlias(String value) {
08203:                if (ProductHelper.getShowAliasedNames()) {
08204:                    setAlias(value);
08205:                } else {
08206:                    setName(value);
08207:                }
08208:            }
08209:
08210:            /* (non-Javadoc)
08211:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setNodeDescription(java.lang.String)
08212:             */
08213:            public void setNodeDescription(String value) {
08214:                setMode(ADDrawingAreaConstants.ADD_NODE_CMD, value);
08215:            }
08216:
08217:            /* (non-Javadoc)
08218:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setOnDrawZoom(double)
08219:             */
08220:            public void setOnDrawZoom(double nOnDrawZoom) {
08221:                m_OnDrawZoom = nOnDrawZoom;
08222:            }
08223:
08224:            /* (non-Javadoc)
08225:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setOverviewWindowRect(int, int, int, int)
08226:             */
08227:            public void setOverviewWindowRect(int nLeft, int nTop, int nWidth,
08228:                    int nHeight) {
08229:                // TODO Auto-generated method stub
08230:            }
08231:
08232:            /**
08233:             * Is this diagram readonly?
08234:             *
08235:             * @param newVal [in] true to make the diagram readonly
08236:             */
08237:            public void setReadOnly(boolean value) {
08238:                if (m_ReadOnly != value) {
08239:                    // Let folks know that the reaonly is being changed - can't cancel this
08240:                    fireDrawingAreaPrePropertyChange(DiagramAreaEnumerations.DAPK_READONLY);
08241:
08242:                    // Set the readonly flag, the cancel flag is ignored
08243:                    m_ReadOnly = value;
08244:
08245:                    // Register or unregister for all sinks
08246:                    registerAllSinks(m_ReadOnly ? false : true);
08247:
08248:                    // Send out the post event
08249:                    fireDrawingAreaPropertyChange(DiagramAreaEnumerations.DAPK_READONLY);
08250:                }
08251:            }
08252:
08253:            /**
08254:             * Registers/Unregisters all sinks
08255:             *
08256:             * @param bDoRegister [in] true to register, false to revoke
08257:             */
08258:            private void registerAllSinks(boolean doRegister) {
08259:                if (doRegister) {
08260:                    initEventSink();
08261:                } else {
08262:                    revokeEventSinks();
08263:                }
08264:            }
08265:
08266:            private boolean fireDrawingAreaPrePropertyChange(int propKind) {
08267:                return fireDrawingAreaPrePropertyChange(
08268:                        "FireDrawingAreaPrePropertyChange", propKind);
08269:            }
08270:
08271:            /**
08272:             * Fires the pre property change event
08273:             */
08274:            private boolean fireDrawingAreaPrePropertyChange(String payload,
08275:                    int propKind) {
08276:                boolean proceed = true;
08277:                if (getDrawingAreaDispatcher() != null && payload != null) {
08278:                    IEventPayload ePayload = m_drawingAreaDispatcher
08279:                            .createPayload(payload);
08280:                    IProxyDiagram dia = getProxyDiagram();
08281:                    if (dia != null) {
08282:                        proceed = m_drawingAreaDispatcher
08283:                                .fireDrawingAreaPrePropertyChange(dia,
08284:                                        propKind, ePayload);
08285:                    }
08286:                }
08287:                return proceed;
08288:            }
08289:
08290:            private void fireDrawingAreaPropertyChange(
08291:                    int iDrawingAreaPropertyKind) {
08292:                fireDrawingAreaPropertyChange("DrawingAreaPostPropertyChange",
08293:                        iDrawingAreaPropertyKind);
08294:            }
08295:
08296:            /**
08297:             * Fires the property change event
08298:             */
08299:            private void fireDrawingAreaPropertyChange(String payload,
08300:                    int propKind) {
08301:                if (getDrawingAreaDispatcher() != null && payload != null) {
08302:                    IEventPayload ePayload = m_drawingAreaDispatcher
08303:                            .createPayload(payload);
08304:                    IProxyDiagram dia = getProxyDiagram();
08305:                    if (dia != null) {
08306:                        m_drawingAreaDispatcher
08307:                                .fireDrawingAreaPostPropertyChange(dia,
08308:                                        propKind, ePayload);
08309:                    }
08310:                }
08311:            }
08312:
08313:            /* (non-Javadoc)
08314:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#setShowGrid(boolean)
08315:             */
08316:            public void setShowGrid(boolean value) {
08317:                // TODO Auto-generated method stub
08318:            }
08319:
08320:            protected TSESaveAsImageDialog saveAsImageDialog = null;
08321:
08322:            public String getExportAsImageTitle() {
08323:                String title = new String(RESOURCE_BUNDLE
08324:                        .getString("IDS_EXPORTASIMAGE"));
08325:                return title;
08326:            }
08327:
08328:            //JM: Fix for Bug#6283632 - begin
08329:            public void showImageDialog() {
08330:                if (this .saveAsImageDialog == null) {
08331:                    SunSaveAsImageDialog myDialog = new SunSaveAsImageDialog(
08332:                            getOwnerFrame(), getExportAsImageTitle(), this 
08333:                                    .getGraphWindow(),
08334:                            TSESaveAsImageDialog.JPG_FORMAT
08335:                                    | TSESaveAsImageDialog.SVG_FORMAT
08336:                                    | TSESaveAsImageDialog.PNG_FORMAT);
08337:                    this .saveAsImageDialog = myDialog;
08338:                }
08339:                this .saveAsImageDialog.setVisible(!this .saveAsImageDialog
08340:                        .isVisible());
08341:            }
08342:
08343:            class SunSaveAsImageDialog extends TSESaveAsImageDialog {
08344:
08345:                public SunSaveAsImageDialog(Frame ownerFrame, String title,
08346:                        ADGraphWindow graphWindow, int flags) {
08347:                    super (ownerFrame, title, graphWindow, flags);
08348:                    if (super .type == null) {
08349:                        super .type = "jpg";
08350:                    }
08351:
08352:                    // reset the text for the fileName field
08353:                    String defaultFileName = RESOURCE_BUNDLE
08354:                            .getString("default.fileName");
08355:
08356:                    File defaultFile = new File(System.getProperty("user.home")
08357:                            + File.separatorChar + defaultFileName + "." + type);
08358:
08359:                    try {
08360:
08361:                        super .fileName.setText(defaultFile.getCanonicalPath());
08362:                    } catch (IOException ex) {
08363:                        ex.printStackTrace();
08364:                    }
08365:
08366:                    //Jyothi:
08367:                    KeyStroke escape = KeyStroke.getKeyStroke(
08368:                            KeyEvent.VK_ESCAPE, 0, false);
08369:                    Action escapeAction = new AbstractAction() {
08370:
08371:                        public void actionPerformed(ActionEvent e) {
08372:                            dispose();
08373:                        }
08374:                    };
08375:                    super .getRootPane().getInputMap(
08376:                            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
08377:                            escape, "ESCAPE");
08378:                    super .getRootPane().getActionMap().put("ESCAPE",
08379:                            escapeAction);
08380:
08381:                    fileName.getDocument().addDocumentListener(
08382:                            new DocumentListener() {
08383:
08384:                                public void changedUpdate(DocumentEvent e) {
08385:                                    documentChanged();
08386:                                }
08387:
08388:                                public void insertUpdate(DocumentEvent e) {
08389:                                    documentChanged();
08390:                                }
08391:
08392:                                public void removeUpdate(DocumentEvent e) {
08393:                                    documentChanged();
08394:                                }
08395:
08396:                                private void documentChanged() {
08397:                                    if (fileName.getText().trim().equals("")) {
08398:                                        disable(okButton);
08399:                                        return;
08400:                                    }
08401:
08402:                                    File file = new File(fileName.getText());
08403:
08404:                                    if (!file.exists()) {
08405:                                        enable(okButton);
08406:                                    } else if (file.isFile() && file.canWrite()) {
08407:                                        enable(okButton);
08408:                                    } else {
08409:                                        disable(okButton);
08410:                                    }
08411:                                }
08412:                            });
08413:                }
08414:
08415:                // provide custom image encoder to write image files #82394
08416:                @Override
08417:                public TSEGraphImageEncoder newGraphImageEncoder(
08418:                        TSEGraphWindow window) {
08419:                    return new ETEGraphImageEncoder(window);
08420:                }
08421:
08422:                // override TSESaveAsImageDialog.onOK to workaround #82394
08423:                @Override
08424:                public boolean onOK() {
08425:                    if (!"jpg".equals(type)) {
08426:                        // NOI18N
08427:                        return super .onOK();
08428:                    }
08429:                    boolean success = true;
08430:                    try {
08431:                        File file = new File(fileName.getText());
08432:                        if (file.exists() && !overWriteConfirm()) {
08433:                            return false;
08434:                        }
08435:                        boolean visibleAreaOnly = visible.isSelected();
08436:                        int zoomType = TSEGraphWindow.FIT_IN_WINDOW;
08437:
08438:                        if (actual.isSelected()) {
08439:                            zoomType = TSEGraphWindow.ACTUAL_SIZE;
08440:                        } else if (custom.isSelected()) {
08441:                            zoomType = TSEGraphWindow.CUSTOM_SIZE;
08442:                        } else if (zoomLevel.isSelected()) {
08443:                            zoomType = TSEGraphWindow.CURRENT_ZOOM_LEVEL;
08444:                        }
08445:                        boolean grid = drawGrid.isSelected();
08446:                        boolean selectedOnly = selected.isSelected();
08447:                        float quality = qualityField.parse(qualityField
08448:                                .getText());
08449:
08450:                        FileImageOutputStream fio = new FileImageOutputStream(
08451:                                new File(fileName.getText()));
08452:                        ETEGraphImageEncoder encoder = new ETEGraphImageEncoder(
08453:                                getGraphWindow());
08454:                        encoder.write("jpg", fio, visibleAreaOnly, zoomType,
08455:                                grid, selectedOnly, quality, width.parse(width
08456:                                        .getText()), height.parse(height
08457:                                        .getText()));
08458:                    } catch (Exception e) {
08459:                        success = false;
08460:                        ErrorManager.getDefault().notify(e);
08461:                    }
08462:                    return success;
08463:                }
08464:            }
08465:
08466:            //JM: Fix for Bug#6283632 - end
08467:
08468:            /* (non-Javadoc)
08469:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#sizeToContents(boolean)
08470:             */
08471:            public void sizeToContents(boolean bJustSelectedElements) {
08472:
08473:                ETList<IPresentationElement> pPresentationElements = null;
08474:
08475:                if (bJustSelectedElements) {
08476:                    pPresentationElements = this .getSelected();
08477:                } else {
08478:                    pPresentationElements = getAllItems();
08479:                }
08480:
08481:                int count = 0;
08482:                if (pPresentationElements != null) {
08483:
08484:                    Iterator<IPresentationElement> iter = pPresentationElements
08485:                            .iterator();
08486:                    while (iter.hasNext()) {
08487:                        IPresentationElement pPresentationElement = iter.next();
08488:                        if (pPresentationElement != null
08489:                                && pPresentationElement instanceof  INodePresentation) {
08490:
08491:                            INodePresentation pNodePres = (INodePresentation) pPresentationElement;
08492:
08493:                            pNodePres.sizeToContents();
08494:                            pNodePres.invalidate();
08495:                        }
08496:                    }
08497:                }
08498:                // need to call refresh here because the drawing are does not refresh properly
08499:                //when the newly sized node is smaller than the original size
08500:                // Kevins Comments about the comment above, element invalidate only add there regions
08501:                // to the Invalidation Region it doesn't repaint the window.  Also someone changed the drawEngine
08502:                // Invalidation to repaint the window which is not what we want
08503:                this .refresh(true);
08504:            }
08505:
08506:            public static final int RESIZE_ANCHOR_POINT_CENTER = 0;
08507:            public static final int RESIZE_ANCHOR_POINT_TOPLEFT = 1;
08508:            public static final int RESIZE_ANCHOR_POINT_TOPRIGHT = 2;
08509:            public static final int RESIZE_ANCHOR_POINT_BOTTOMLEFT = 3;
08510:            public static final int RESIZE_ANCHOR_POINT_BOTTOMRIGHT = 4;
08511:            private static int savedAnchorPoint = RESIZE_ANCHOR_POINT_CENTER;
08512:
08513:            /** (non-Javadoc)
08514:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#sizeToContents(boolean)
08515:             */
08516:            public boolean resizeDimensions() {
08517:                ETList<IPresentationElement> presElements = null;
08518:                presElements = getSelectedPresentionNodes();
08519:
08520:                if (presElements == null) {
08521:                    return false;
08522:                }
08523:                double initHeight = 0;
08524:                double initWidth = 0;
08525:
08526:                if (presElements.size() == 1
08527:                        && presElements.get(0) instanceof  INodePresentation) {
08528:                    INodePresentation nodePres = (INodePresentation) presElements
08529:                            .get(0);
08530:                    initHeight = nodePres.getHeight();
08531:                    initWidth = nodePres.getWidth();
08532:                }
08533:
08534:                ResizeElementsPanel resizePanel = new ResizeElementsPanel(Math
08535:                        .round(initHeight), Math.round(initWidth),
08536:                        savedAnchorPoint, presElements);
08537:
08538:                ResizeElementsDescriptor resizeDesc = new ResizeElementsDescriptor(
08539:                        resizePanel,
08540:                        NbBundle.getMessage(ADDrawingAreaControl.class,
08541:                                "LBL_ResizeElementsDialog_Title"), // NOI18N
08542:                        true, DialogDescriptor.OK_CANCEL_OPTION,
08543:                        DialogDescriptor.OK_OPTION,
08544:                        DialogDescriptor.DEFAULT_ALIGN, new HelpCtx(
08545:                                "uml_basics_diag_elements_kbshortcuts"), // NOI18N
08546:                        resizePanel); // button action listener
08547:
08548:                resizePanel.getAccessibleContext().setAccessibleName(
08549:                        NbBundle.getMessage(ADDrawingAreaControl.class,
08550:                                "ACSN_ResizeElementsDialog")); // NOI18N
08551:
08552:                resizePanel.getAccessibleContext().setAccessibleDescription(
08553:                        NbBundle.getMessage(ADDrawingAreaControl.class,
08554:                                "ACSD_ResizeElementsDialog")); // NOI18N
08555:
08556:                resizePanel.requestFocus();
08557:
08558:                Object result = DialogDisplayer.getDefault().notify(resizeDesc);
08559:
08560:                if (result == DialogDescriptor.OK_OPTION) {
08561:                    initHeight = resizePanel.getResizeHeight();
08562:                    initWidth = resizePanel.getResizeWidth();
08563:                    savedAnchorPoint = resizePanel.getAnchorPoint();
08564:
08565:                    double top = 0;
08566:                    double bottom = 0;
08567:                    double right = 0;
08568:                    double left = 0;
08569:
08570:                    switch (savedAnchorPoint) {
08571:                    case RESIZE_ANCHOR_POINT_TOPLEFT:
08572:                        bottom = -1D * initHeight;
08573:                        right = initWidth;
08574:                        break;
08575:                    case RESIZE_ANCHOR_POINT_TOPRIGHT:
08576:                        bottom = -1D * initHeight;
08577:                        left = -1D * initWidth;
08578:                        break;
08579:                    case RESIZE_ANCHOR_POINT_BOTTOMLEFT:
08580:                        top = initHeight;
08581:                        right = initWidth;
08582:                        break;
08583:                    case RESIZE_ANCHOR_POINT_BOTTOMRIGHT:
08584:                        top = initHeight;
08585:                        left = -1D * initWidth;
08586:                        break;
08587:                    default:
08588:                        // center
08589:                        top = initHeight / 2D;
08590:                        bottom = initHeight / 2D * -1D;
08591:                        left = initWidth / 2D * -1D;
08592:                        right = initWidth / 2D;
08593:                    }
08594:
08595:                    for (IPresentationElement presElem : presElements) {
08596:                        if (presElem != null
08597:                                && presElem instanceof  INodePresentation) {
08598:                            INodePresentation nodePres = (INodePresentation) presElem;
08599:                            TSENode tsNode = nodePres.getTSNode();
08600:                            nodePres.invalidate();
08601:
08602:                            switch (savedAnchorPoint) {
08603:                            case RESIZE_ANCHOR_POINT_TOPLEFT:
08604:                                tsNode.setBounds(tsNode.getLeft(), tsNode
08605:                                        .getTop()
08606:                                        + bottom, tsNode.getLeft() + right,
08607:                                        tsNode.getTop()); // top
08608:                                break;
08609:                            case RESIZE_ANCHOR_POINT_TOPRIGHT:
08610:                                tsNode.setBounds(tsNode.getRight() + left,
08611:                                        tsNode.getTop() + bottom, tsNode
08612:                                                .getRight(), tsNode.getTop()); // top
08613:                                break;
08614:                            case RESIZE_ANCHOR_POINT_BOTTOMLEFT:
08615:                                tsNode.setBounds(tsNode.getLeft(), tsNode
08616:                                        .getBottom(), tsNode.getLeft() + right,
08617:                                        tsNode.getBottom() + top); // top
08618:                                break;
08619:                            case RESIZE_ANCHOR_POINT_BOTTOMRIGHT:
08620:                                tsNode.setBounds(tsNode.getRight() + left,
08621:                                        tsNode.getBottom(), tsNode.getRight(),
08622:                                        tsNode.getBottom() + top); // top
08623:                                break;
08624:                            default:
08625:                                // center
08626:                                tsNode.setBounds(tsNode.getCenterX() + left,
08627:                                        tsNode.getCenterY() + top, tsNode
08628:                                                .getCenterX()
08629:                                                + right, tsNode.getCenterY()
08630:                                                + bottom); // top
08631:                            }
08632:
08633:                            // TS always tells the node it was resized interactively
08634:                            // when we do it programmatically we don't want that
08635:                            if (nodePres.getDrawEngine() != null)
08636:                                nodePres.getDrawEngine().onResized();
08637:
08638:                            // Update the orginal size.
08639:                            tsNode.setOriginalSize(tsNode.getWidth(), tsNode
08640:                                    .getHeight());
08641:                            nodePres.invalidate();
08642:                        } // if instanceof INodePresentation
08643:                    } // for
08644:
08645:                    // need to call refresh here because the drawing are does not refresh
08646:                    // properly when the newly sized node is smaller than the original size
08647:                    refresh(true);
08648:                } // if "OK" response from Resize dialog
08649:
08650:                requestFocus();
08651:                return true;
08652:            }
08653:
08654:            /* (non-Javadoc)
08655:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#sizeToContentsWithTrackBar(com.embarcadero.describe.foundation.IPresentationElement)
08656:             */
08657:            public void sizeToContentsWithTrackBar(IPresentationElement pElement) {
08658:                if (pElement != null) {
08659:                    IETGraphObject object = TypeConversions
08660:                            .getETGraphObject(pElement);
08661:                    if (object != null) {
08662:                        object.sizeToContents();
08663:
08664:                        if (getTrackBar() != null) {
08665:                            getTrackBar().resize(pElement);
08666:                        }
08667:                    }
08668:                }
08669:            }
08670:
08671:            /* (non-Javadoc)
08672:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#sortNodesLeftToRight(com.embarcadero.describe.foundation.IPresentationElement[])
08673:             */
08674:            public ETList<IPresentationElement> sortNodesLeftToRight(
08675:                    ETList<IPresentationElement> pUnsortedList) {
08676:                // TODO Auto-generated method stub
08677:                return null;
08678:            }
08679:
08680:            /* (non-Javadoc)
08681:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#syncElements(boolean)
08682:             */
08683:            public void syncElements(boolean bOnlySelectedElements) {
08684:                IDiagramValidation pLocalValidation = new DiagramValidation();
08685:                if (pLocalValidation != null) {
08686:                    // Validate both nodes and edges
08687:                    pLocalValidation.setValidateNodes(true);
08688:                    pLocalValidation.setValidateLinks(true);
08689:
08690:                    // In this case, don't validate anything but deep, and make it a force
08691:                    pLocalValidation
08692:                            .addValidationKind(IDiagramValidateKind.DVK_VALIDATE_RESYNC_DEEP);
08693:                    pLocalValidation
08694:                            .addValidationKind(IDiagramValidateKind.DVK_VALIDATE_CONNECTIONTOELEMENT);
08695:
08696:                    validateDiagram(bOnlySelectedElements, pLocalValidation);
08697:                }
08698:            }
08699:
08700:            /* (non-Javadoc)
08701:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#transform(org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject, java.lang.String)
08702:             */
08703:            public void transform(IETGraphObject pETGraphObject,
08704:                    String sToElement) {
08705:                if (sToElement != null && sToElement.length() > 0) {
08706:                    ITransformAction pTransformAction = new TransformAction();
08707:                    if (pTransformAction != null) {
08708:                        IPresentationElement pPE = TypeConversions
08709:                                .getPresentationElement(pETGraphObject);
08710:                        if (pPE != null) {
08711:                            pTransformAction.setPresentationElement(pPE);
08712:                            pTransformAction.setNewElementType(sToElement);
08713:                            postDelayedAction(pTransformAction);
08714:                            postDelayedAction(new ReSelectionAction());
08715:                        }
08716:                    }
08717:                }
08718:            }
08719:
08720:            class ReSelectionAction implements  IExecutableAction,
08721:                    IDelayedAction {
08722:
08723:                public String getDescription() {
08724:                    return "ReSelectionAction";
08725:                }
08726:
08727:                public void execute(IDrawingAreaControl pControl) {
08728:                    if (pControl.getGraphWindow().getGraph() != null
08729:                            && pControl.getGraphWindow().getGraph() instanceof  ETGraph) {
08730:                        ETGraph etGraph = (ETGraph) pControl.getGraphWindow()
08731:                                .getGraph();
08732:                        ETList<TSGraphObject> selectedObjs = etGraph
08733:                                .getSelectedObjects(false, false);
08734:                        if (selectedObjs != null) {
08735:                            pControl.fireSelectEvent(selectedObjs);
08736:                        }
08737:                    }
08738:                }
08739:            }
08740:
08741:            /* (non-Javadoc)
08742:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#unfoldNode(com.tomsawyer.graph.TSNode)
08743:             */
08744:            public void unfoldNode(TSNode pCurrentNode) {
08745:                // TODO Auto-generated method stub
08746:            }
08747:
08748:            /* (non-Javadoc)
08749:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#validateDiagram(boolean, com.embarcadero.describe.diagrams.IDiagramValidation)
08750:             */
08751:            public IDiagramValidationResult validateDiagram(
08752:                    boolean bOnlySelectedElements,
08753:                    IDiagramValidation pDiagramValidation) {
08754:                IDiagramValidationResult localResult = null;
08755:
08756:                if (!m_ReadOnly) {
08757:
08758:                    IDiagramValidation localValidation = null;
08759:
08760:                    if (pDiagramValidation == null) {
08761:                        localValidation = new DiagramValidation();
08762:
08763:                        localValidation.setValidateNodes(true);
08764:                        localValidation.setValidateLinks(true);
08765:
08766:                        localValidation
08767:                                .addValidationKind(IDiagramValidateKind.DVK_VALIDATE_ALL);
08768:                        localValidation
08769:                                .removeValidationKind(IDiagramValidateKind.DVK_VALIDATE_RESYNC_DEEP);
08770:
08771:                        localValidation
08772:                                .addValidationResponse(IDiagramValidateResponse.DVRSP_VALIDATE_ALL);
08773:                    } else {
08774:                        localValidation = pDiagramValidation;
08775:                    }
08776:
08777:                    IDiagram diagram = getDiagram();
08778:                    if (diagram != null) {
08779:                        IDiagramValidator validator = new DiagramValidator();
08780:                        if (validator != null) {
08781:                            localResult = validator.validateDiagram(diagram,
08782:                                    bOnlySelectedElements, localValidation);
08783:
08784:                            if (m_TrackBar != null) {
08785:                                m_TrackBar.updateAllCarNames();
08786:                            }
08787:                        }
08788:                    }
08789:                }
08790:
08791:                return localResult;
08792:            }
08793:
08794:            public void onDrop(DropTargetDropEvent event, TSEObject graphObject) {
08795:                if (!m_ReadOnly
08796:                        && event
08797:                                .isDataFlavorSupported(ADTransferable.ADDataFlavor)) {
08798:                    event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE
08799:                            | DnDConstants.ACTION_LINK);
08800:
08801:                    IPresentationElement peDroppedOn = null;
08802:                    IDrawEngine drawEngine = null;
08803:                    ICompartment compartmentDroppedOn = null;
08804:
08805:                    ADTransferable.ADTransferData eventData = null;
08806:
08807:                    TSConstPoint dropPoint = getGraphWindow()
08808:                            .getNonalignedWorldPoint(event.getLocation());
08809:
08810:                    try {
08811:                        eventData = (ADTransferable.ADTransferData) event
08812:                                .getTransferable().getTransferData(
08813:                                        ADTransferable.ADDataFlavor);
08814:
08815:                        double dx = 0;
08816:                        double dy = 0;
08817:
08818:                        if (graphObject != null) {
08819:                            IGraphPresentation etElement = TypeConversions
08820:                                    .getETElement((TSObject) graphObject);
08821:                            peDroppedOn = TypeConversions
08822:                                    .getPresentationElement((TSObject) graphObject);
08823:
08824:                            if (peDroppedOn != null) {
08825:                                drawEngine = TypeConversions
08826:                                        .getDrawEngine(peDroppedOn);
08827:                                if (drawEngine != null) {
08828:                                    IETPoint pt = new ETPointEx(dropPoint);
08829:                                    compartmentDroppedOn = drawEngine
08830:                                            .getCompartmentAtPoint(pt);
08831:                                }
08832:                            }
08833:                        }
08834:
08835:                        ETList<IElement> additionalDropElement = new ETArrayList<IElement>();
08836:                        boolean cancel = fireDrawingAreaContextOnDrop(true,
08837:                                peDroppedOn, compartmentDroppedOn, eventData,
08838:                                additionalDropElement);
08839:
08840:                        // Add the additional model elements to the collection of model elements
08841:                        // that need to be processed.
08842:                        ArrayList<IElement> modelElements = eventData
08843:                                .getModelElements();
08844:                        for (Iterator<IElement> addIter = additionalDropElement
08845:                                .iterator(); addIter.hasNext();) {
08846:                            IElement curElement = addIter.next();
08847:                            if (modelElements.contains(curElement) == false) {
08848:                                modelElements.add(curElement);
08849:                            }
08850:                        }
08851:
08852:                        IteratorT<IElement> iter = new IteratorT(modelElements);
08853:                        IElement element = iter.next();
08854:                        for (; element != null; element = iter.next()) {
08855:                            // TODO: Need to process diagrams.
08856:                            IElement processedElement = processOnDropElement(element);
08857:                            if (processedElement == null) {
08858:                                continue;
08859:
08860:                                // TODO: Handle dropping on an existing node.
08861:                            }
08862:                            ETNode newNode = addNode(processedElement,
08863:                                    new ETPointEx(dropPoint.getX() + dx,
08864:                                            dropPoint.getY() - dy), !iter
08865:                                            .hasNext());
08866:                            dx = dx + 10;
08867:                            dy = dy + 10;
08868:                            if (newNode != null) {
08869:                                newNode.sizeToContents();
08870:                            }
08871:
08872:                            //					nodeVerification.createAndVerify(this.getDiagram(), (IETNode) newNode, nameSpace);
08873:                            //					if (newNode == null) {
08874:                            //						event.dropComplete(false);
08875:                            //						break;
08876:                            //					}
08877:                            //onPostAddNode((ETNode)newNode);
08878:                            setModelElement(null);
08879:                        }
08880:                        this .refresh(true);
08881:                        // Here's where relatoinship discovery happens
08882:                        if (m_DiagramEngine != null) {
08883:                            ETList<IElement> pList = new ETArrayList<IElement>();
08884:                            if (eventData.getModelElements() != null) {
08885:                                pList.addAll(eventData.getModelElements());
08886:                                m_DiagramEngine.postOnDrop(pList, true);
08887:                            }
08888:                        }
08889:                    } catch (Exception e) {
08890:                        e.printStackTrace();
08891:                        event.dropComplete(false);
08892:                    } finally {
08893:                        fireDrawingAreaContextOnDrop(false, peDroppedOn,
08894:                                compartmentDroppedOn, eventData, null);
08895:                    }
08896:                }
08897:            }
08898:
08899:            /**
08900:             * Fires the context menu on drop events
08901:             *
08902:             * @param bFirePreEvent <code>true</code> if this is a pre drop event
08903:             * @param pPresentationElementDroppedOn The presentation element dropped upon
08904:             * @param pCompartmentDroppedOn The compartment dropped upon
08905:             * @param sClipString The string currently on the clipboard
08906:             * @param pAdditionalDropElements Additional elements the user wants to treat as dropped.
08907:             * @return Set to <code>true</code> to cancel the event (pre only)
08908:             */
08909:            protected boolean fireDrawingAreaContextOnDrop(
08910:                    boolean firePreEvent,
08911:                    IPresentationElement pPresentationElementDroppedOn,
08912:                    ICompartment pCompartmentDroppedOn,
08913:                    ADTransferable.ADTransferData dropData,
08914:                    ETList<IElement> pAdditionalDropElements) {
08915:                boolean retVal = false;
08916:
08917:                IDiagram diagram = getDiagram();
08918:
08919:                IDrawingAreaEventDispatcher dispatcher = getDrawingAreaDispatcher();
08920:                if ((dispatcher != null) && (dropData != null)) {
08921:                    IDrawingAreaDropContext context = new DrawingAreaDropContext(
08922:                            dropData, pPresentationElementDroppedOn,
08923:                            pCompartmentDroppedOn);
08924:                    if (firePreEvent == true) {
08925:                        IEventPayload payload = dispatcher
08926:                                .createPayload("DrawingAreaPreDrop");
08927:                        dispatcher.fireDrawingAreaPreDrop(diagram, context,
08928:                                payload);
08929:                        retVal = context.getCancel();
08930:
08931:                        ETList<IElement> additional = context
08932:                                .getAdditionalDropElements();
08933:                        pAdditionalDropElements.addAll(additional);
08934:                    } else {
08935:                        IEventPayload payload = dispatcher
08936:                                .createPayload("DrawingAreaPostDrop");
08937:                        dispatcher.fireDrawingAreaPostDrop(diagram, context,
08938:                                payload);
08939:                    }
08940:                }
08941:
08942:                return retVal;
08943:            }
08944:
08945:            protected String getNodeElementUIClass(IElement element) {
08946:                String elementType = element.getElementType();
08947:                return ETUIFactory.GENERIC_NODE_UI;
08948:            }
08949:
08950:            /**
08951:             * Adds a node to the diagram.
08952:             *
08953:             * @param element The model element that is to be added to the diagram.
08954:             * @param pt The center location for the node.
08955:             * @param repaint <code>true</code> if the diagram is to be refreshed,
08956:             *                <code>false</code> if the diagram is not to be refreshed.
08957:             */
08958:            protected ETNode addNode(IElement element, IETPoint pt,
08959:                    boolean repaint) throws ETException {
08960:                ETNode retVal = addNode(element, pt);
08961:
08962:                if (repaint == true) {
08963:                    refresh(true);
08964:                }
08965:
08966:                return retVal;
08967:            }
08968:
08969:            /**
08970:             * Adds a node to the diagram.
08971:             *
08972:             * @param nodeInitString The initialization string for the node.
08973:             * @param location The center location for the node.
08974:             * @param bSelect Should we select this new graph object?
08975:             * @param bDeselectAllOthers Should we deselect all other objects?
08976:             * @param pElementToAssignToNode The element to assign the node to
08977:             * @return The created node.  NULL if no node is created.
08978:             */
08979:            public ETNode addNode(IElement element, IETPoint pt)
08980:                    throws ETException {
08981:                IPresentationTypesMgr mgr = getPresentationTypesMgr();
08982:                if (mgr != null) {
08983:                    TSNode node = addNode(mgr.getMetaTypeInitString(element,
08984:                            getDiagramKind()), pt, false, false, element);
08985:                    return node instanceof  ETNode ? (ETNode) node : null;
08986:                } else {
08987:                    return null;
08988:                }
08989:            }
08990:
08991:            /**
08992:             * Adds a node to the diagram.  The type of the node is specified by the
08993:             * metatype name.
08994:             *
08995:             * @param metaDataType The type of node to create.
08996:             * @param location The location of the new node.
08997:             * @param bSelect <code>true</code> if the diagram is to be selected.
08998:             * @param bDeselectAllOthers <code>true</code> if all selected nodes are to
08999:             *                           be deselected.
09000:             * @return The new node.
09001:             */
09002:            public ETNode addNodeForType(String metaDataType,
09003:                    IETPoint location, boolean bSelect,
09004:                    boolean bDeselectAllOthers) throws ETException {
09005:                IPresentationTypesMgr mgr = getPresentationTypesMgr();
09006:                if (mgr != null) {
09007:                    TSNode node = addNode(mgr.getMetaTypeInitString(
09008:                            metaDataType, getDiagramKind()), location, false,
09009:                            false);
09010:                    return node instanceof  ETNode ? (ETNode) node : null;
09011:                } else {
09012:                    return null;
09013:                }
09014:            }
09015:
09016:            /**
09017:             * Adds a node to the diagram.  The initstring be used to determine the
09018:             * UI object and the draw engine used to present the node.
09019:             *
09020:             * @param nodeInitString The initialization string.
09021:             * @param location The location of the new node.
09022:             * @param bSelect <code>true</code> if the diagram is to be selected.
09023:             * @param bDeselectAllOthers <code>true</code> if all selected nodes are to
09024:             *                           be deselected.
09025:             * @return The new node.
09026:             */
09027:            public TSNode addNode(String nodeInitString, IETPoint location,
09028:                    boolean bSelect, boolean bDeselectAllOthers)
09029:                    throws ETException {
09030:                TSNode retVal = null;
09031:
09032:                TSEGraph graph = getGraph();
09033:                if (graph != null) {
09034:                    IGUIBlocker blocker = null;
09035:                    try {
09036:                        blocker = new GUIBlocker(GBK.DIAGRAM_CONTAINMENT);
09037:
09038:                        IPresentationTypesMgr mgr = getPresentationTypesMgr();
09039:                        PresentationTypeDetails details = mgr
09040:                                .getInitStringDetails(nodeInitString,
09041:                                        getDiagramKind());
09042:
09043:                        if (details != null) {
09044:                            int graphKind = details.getObjectKind();
09045:                            if (graphKind != TSGraphObjectKind.TSGOK_EDGE) {
09046:                                retVal = graph.addNode();
09047:                                if (retVal instanceof  ETNode) {
09048:                                    ETNode gNode = (ETNode) retVal;
09049:                                    gNode.setCenter(location.getX(), location
09050:                                            .getY());
09051:
09052:                                    int delimiter = nodeInitString.indexOf(' ');
09053:                                    String nodeUIClass = delimiter > 0 ? nodeInitString
09054:                                            .substring(0, delimiter)
09055:                                            : nodeInitString;
09056:                                    ETGenericNodeUI nodeUI = ETUIFactory
09057:                                            .createNodeUI(nodeUIClass,
09058:                                                    nodeInitString, details
09059:                                                            .getEngineName(),
09060:                                                    this );
09061:                                    gNode.setUI(nodeUI);
09062:
09063:                                    onPostAddNode((IETNode) gNode);
09064:                                    if ((bSelect == true)
09065:                                            || (bDeselectAllOthers == true)) {
09066:                                        selectAndFireEvents(retVal, bSelect,
09067:                                                bDeselectAllOthers);
09068:                                    }
09069:                                }
09070:                            }
09071:                        }
09072:                    } finally {
09073:                        blocker.clearBlockers();
09074:                    }
09075:                }
09076:
09077:                return retVal;
09078:            }
09079:
09080:            /**
09081:             * Adds a node to the diagram.
09082:             *
09083:             * @param nodeInitString The initialization string for the node.
09084:             * @param location The center location for the node.
09085:             * @param bSelect Should we select this new graph object?
09086:             * @param bDeselectAllOthers Should we deselect all other objects?
09087:             * @param pElementToAssignToNode The element to assign the node to
09088:             * @return The created node.  NULL if no node is created.
09089:             */
09090:            public TSNode addNode(String nodeInitString, IETPoint location,
09091:                    boolean bSelect, boolean bDeselectAllOthers,
09092:                    IElement pElementToAssignToNode) throws ETException {
09093:                TSNode retVal = null;
09094:
09095:                if (nodeInitString.length() > 0) {
09096:                    // Save the current model element before changing it.
09097:                    IElement pPrevElement = this .getModelElement();
09098:                    setModelElement(pElementToAssignToNode);
09099:
09100:                    retVal = addNode(nodeInitString, location, bSelect,
09101:                            bDeselectAllOthers);
09102:
09103:                    // Restore it.
09104:                    this .setModelElement(pPrevElement);
09105:                }
09106:
09107:                return retVal;
09108:            }
09109:
09110:            /*
09111:             * Gets called after an addNode call, the node reprents the node just added to the diagram.
09112:             */
09113:            protected void onPostAddNode(IETNode node) {
09114:                onPostAddObject(node);
09115:            }
09116:
09117:            protected void onPostAddEdge(IETEdge edge) {
09118:                onPostAddObject(edge);
09119:            }
09120:
09121:            protected void onPostAddObject(IETGraphObject object) {
09122:                if (object != null) {
09123:                    postAddObject(object, object.isNode()); // Only resize the nodes.
09124:                }
09125:            }
09126:
09127:            public boolean showAccessiblePopupMenu() {
09128:                return showPopupMenu(null);
09129:            }
09130:
09131:            private boolean showPopupMenu(MouseEvent e) {
09132:                ETList<IPresentationElement> selected = getSelected();
09133:                if (selected == null) {
09134:                    fireSelectEvent(new ArrayList()); // to select diagram itself
09135:                }
09136:
09137:                boolean retVal = true;
09138:                if (e != null) {
09139:                    retVal = e.isPopupTrigger();
09140:                }
09141:
09142:                ADGraphWindow graphWindow = getGraphWindow();
09143:                if (graphWindow != null) {
09144:                    TSEWindowTool curState = graphWindow.getCurrentTool();
09145:                    TSEWindowTool defaultState = graphWindow.getDefaultTool();
09146:                    if ((retVal == true) && (curState == defaultState)) {
09147:                        if (m_ContextMenuManager.getRemoveAllWhenShown() == true) {
09148:                            m_ContextMenuManager.removeAll();
09149:                            m_ContextPopup.removeAll();
09150:                        }
09151:
09152:                        Point eventPoint = null;
09153:                        if (e != null) {
09154:                            eventPoint = e.getPoint();
09155:                        }
09156:
09157:                        m_ContextMenuManager.setLocation(eventPoint);
09158:
09159:                        TSEHitTesting hitTest = graphWindow.getHitTesting();
09160:                        m_ContextMenuManager.setContextObject(null); // represents Diagram
09161:                        TSEObject contextObj = null;
09162:                        if ((hitTest != null) && (eventPoint != null)) {
09163:                            TSConstPoint pt = graphWindow
09164:                                    .getNonalignedWorldPoint(eventPoint);
09165:                            contextObj = hitTest.getGraphObjectAt(pt,
09166:                                    graphWindow.getGraph(), true);
09167:                            if (contextObj != null) {
09168:                                m_ContextMenuManager
09169:                                        .setContextObject(contextObj);
09170:                                if (Utilities.isUnix() || Utilities.isMac()) {
09171:                                    selectAndFireEvents(
09172:                                            (TSGraphObject) contextObj, true,
09173:                                            false);
09174:                                }
09175:                            }
09176:                        } else if ((e == null) && (selected != null)) {
09177:                            // Make the last selected object the context object.
09178:                            IPresentationElement pres = selected.get(selected
09179:                                    .size() - 1);
09180:                            contextObj = (TSEObject) TypeConversions
09181:                                    .getTSObject(pres);
09182:                            m_ContextMenuManager.setContextObject(contextObj);
09183:                        }
09184:
09185:                        menuAboutToShow(m_ContextMenuManager);
09186:                        m_ContextMenuManager.createMenuBar();
09187:                        JPopupMenu menu = m_ContextPopup.getPopupMenu();
09188:
09189:                        // The (0, 0) location will be used when the diagram is selected.
09190:                        int x = 0;
09191:                        int y = 0;
09192:                        if (e != null) {
09193:                            x = e.getX();
09194:                            y = e.getY();
09195:                        } else if (contextObj != null) {
09196:                            double logicalX = contextObj.getLeft();
09197:                            double logicalY = contextObj.getTop();
09198:
09199:                            TSTransform transform = getGraphWindow()
09200:                                    .getTransform();
09201:                            if (transform != null) {
09202:                                x = transform.xToDevice(logicalX);
09203:                                y = transform.yToDevice(logicalY);
09204:                            }
09205:                        }
09206:
09207:                        menu.show(this , x, y);
09208:                    }
09209:
09210:                    if (retVal) {
09211:                        setSelectStateOnPalette();
09212:                    }
09213:                }
09214:
09215:                return retVal;
09216:            }
09217:
09218:            /*
09219:             * Inner keyboard Listener.
09220:             *
09221:             */
09222:            private class KeyHandler implements  KeyListener {
09223:
09224:                public void keyTyped(KeyEvent e) {
09225:                    handleKey(e);
09226:                }
09227:
09228:                public void keyPressed(KeyEvent e) {
09229:                    handleKey(e);
09230:                }
09231:
09232:                public void keyReleased(KeyEvent e) {
09233:                    handleKey(e);
09234:                }
09235:
09236:                private void handleKey(KeyEvent e) {
09237:                    ETList<IPresentationElement> elems = getSelected();
09238:                    if (elems != null) {
09239:                        int count = elems.size();
09240:                        if (count == 1) {
09241:                            IPresentationElement pEle = elems.get(0);
09242:                            IElement modEle = pEle.getFirstSubject();
09243:                            if (modEle != null) {
09244:                                IDrawEngine engine = TypeConversions
09245:                                        .getDrawEngine(pEle);
09246:                                if (engine != null) {
09247:                                    ICompartment compartment = engine
09248:                                            .getDefaultCompartment();
09249:                                    if (compartment != null
09250:                                            && compartment instanceof  ETCompartment) {
09251:                                        compartment.editCompartment(false, e
09252:                                                .getKeyCode(),
09253:                                                e.isShiftDown() ? 0 : 1, 0);
09254:                                    }
09255:                                }
09256:                            }
09257:                        }
09258:                    }
09259:                }
09260:            }
09261:
09262:            private class TestAction extends AbstractAction {
09263:
09264:                public void actionPerformed(ActionEvent e) {
09265:                    ETSystem.out.println("hello");
09266:                }
09267:            }
09268:
09269:            private class MouseHandler extends MouseAdapter {
09270:
09271:                private JPanel m_View = null;
09272:
09273:                public MouseHandler(JPanel view) {
09274:                    m_View = view;
09275:                }
09276:
09277:                @Override
09278:                public void mousePressed(MouseEvent event) {
09279:                    //if I was editing something on drawing area, need to commit that
09280:                    saveEditCompartment();
09281:                    requestFocus();
09282:                    showPopupMenu(event);
09283:                }
09284:
09285:                @Override
09286:                public void mouseReleased(MouseEvent event) {
09287:                    // Some Operating Systems will show the popupmenu on the mouse
09288:                    // down and some will show it on the mouse up.
09289:                    showPopupMenu(event);
09290:                }
09291:
09292:                //      public boolean showAccessiblePopupMenu()
09293:                //      {
09294:                //          return showPopupMenu(null);
09295:                //      }
09296:                //
09297:                //      private boolean showPopupMenu(MouseEvent e)
09298:                //      {
09299:                //          ETList < IPresentationElement > selected = getSelected();
09300:                //          if (selected ==null)
09301:                //          {
09302:                //              fireSelectEvent(new ArrayList()); // to select diagram itself
09303:                //          }
09304:                //
09305:                //          boolean retVal = true;
09306:                //          if(e != null)
09307:                //          {
09308:                //              retVal = e.isPopupTrigger();
09309:                //          }
09310:                //
09311:                //          ADGraphWindow graphWindow = getGraphWindow();
09312:                //          if (graphWindow != null)
09313:                //          {
09314:                //              TSEWindowTool curState = graphWindow.getCurrentTool();
09315:                //              TSEWindowTool defaultState = graphWindow.getDefaultTool();
09316:                //              if ((retVal == true) && (curState == defaultState))
09317:                //              {
09318:                //                  if (m_ContextMenuManager.getRemoveAllWhenShown() == true)
09319:                //                  {
09320:                //                      m_ContextMenuManager.removeAll();
09321:                //                      m_ContextPopup.removeAll();
09322:                //                  }
09323:                //
09324:                //                  m_ContextMenuManager.setLocation(e.getPoint());
09325:                //
09326:                //                  TSEHitTesting hitTest = graphWindow.getHitTesting();
09327:                //                  m_ContextMenuManager.setContextObject(null); // represents Diagram
09328:                //                  if ((hitTest != null) && (e != null))
09329:                //                  {
09330:                //                      TSConstPoint pt = graphWindow.getNonalignedWorldPoint(e.getPoint());
09331:                //                      m_ContextMenuManager.setContextObject(hitTest.getGraphObjectAt(pt, graphWindow.getGraph(), true));
09332:                //                  }
09333:                //                  else if((e == null) && (selected != null))
09334:                //                  {
09335:                //                      // Make the last selected object the context object.
09336:                //                      m_ContextMenuManager.setContextObject(selected.get(selected.size() - 1));
09337:                //                  }
09338:                //
09339:                //                  menuAboutToShow(m_ContextMenuManager);
09340:                //                  m_ContextMenuManager.createMenuBar();
09341:                //                  JPopupMenu menu = m_ContextPopup.getPopupMenu();
09342:                //                  menu.show(m_View, e.getX(), e.getY());
09343:                //              }
09344:                //              else
09345:                //              {
09346:                //                  super.mousePressed(e);
09347:                //              }
09348:                //
09349:                //              if(retVal)
09350:                //              {
09351:                //                  setSelectStateOnPalette();
09352:                //              }
09353:                //          }
09354:                //
09355:                //          return retVal;
09356:                //      }
09357:            }
09358:
09359:            @Override
09360:            public void registerContextMenu(String id, boolean clearBeforeShow) {
09361:                m_ContextMenuManager = new TestBedMenuManager();
09362:                m_ContextMenuManager.setRemoveAllWhenShown(clearBeforeShow);
09363:
09364:                m_ContextMenuManager.setMenuItem(m_ContextPopup);
09365:                //      m_ContextMenu = new PopupMenuExtender(id, m_ContextMenuManager, prov, this);
09366:            }
09367:
09368:            public void createViewControl(JPanel parent) {
09369:                parent.setLayout(new BorderLayout());
09370:            }
09371:
09372:            @Override
09373:            public void menuAboutToShow(IMenuManager manager) {
09374:
09375:                //create our menu items
09376:                addDefaultMenuItems(manager);
09377:
09378:                //Now tell the sinks that the context menu should be created.
09379:                fireDrawingAreaContextMenuPrepare(manager);
09380:
09381:                //tell the diagram engine that context menu is about to appear
09382:                if (m_DiagramEngine != null) {
09383:                    m_DiagramEngine.onContextMenu(manager);
09384:                }
09385:
09386:                // The following does not make sence when multiple objects are selected because it always sends the event
09387:                // to the first object in the list which does not signify anything.
09388:                // Instead send the event to the object under the cursor.
09389:                //--------------------------
09390:                //now tell the nodes that context menu is about to appear
09391:                ETGraph etGraph = (ETGraph) getGraph();
09392:
09393:                Object targetObj = manager.getContextObject();
09394:                TSGraphObject graphObj = (targetObj instanceof  TSGraphObject) ? (TSGraphObject) targetObj
09395:                        : null;
09396:                if (graphObj != null) {
09397:                    IETGraphObject etElem = TypeConversions
09398:                            .getETGraphObject(graphObj);
09399:                    if (etElem != null) {
09400:                        etElem.onContextMenu(manager);
09401:                    }
09402:                    //Fix for Issuezilla#82825. The following is a workaround for having AddOperation 
09403:                    //on edge as well as all bendpoints of MessageToSelf in a SQD
09404:                    else if (graphObj instanceof  TSEPNode
09405:                            && m_DiagramEngine instanceof  IADSequenceDiagEngine) {
09406:                        if (((TSEPNode) graphObj).isPathNode()) {
09407:                            TSGraphObject gObj = ((TSEPNode) graphObj)
09408:                                    .getOwner();
09409:                            IETGraphObject etElem1 = TypeConversions
09410:                                    .getETGraphObject(gObj);
09411:                            if (etElem1 != null) {
09412:                                manager.setContextObject(etElem1);
09413:                                etElem1.onContextMenu(manager);
09414:                            }
09415:                        }
09416:                    }
09417:
09418:                } else {
09419:                    manager.setContextObject(etGraph);
09420:                }
09421:
09422:                addAddinMenus(manager);
09423:
09424:                // Sort it before shows up
09425:                IProductContextMenuSorter pProductContextMenuSorter = new DrawingAreaContextMenuSorter();
09426:                pProductContextMenuSorter.sort(manager);
09427:
09428:                //JM: Printing context menu items...
09429:                //      printContextMenuItems(manager);
09430:                // Now tell the sinks that the menu has been created and they can override the implementations.
09431:                fireDrawingAreaContextMenuPrepared(manager);
09432:            }
09433:
09434:            //   private void printContextMenuItems(IMenuManager manager) {
09435:            //       IContributionItem[] pContributionItems = manager.getItems();
09436:            //       if (pContributionItems != null) {
09437:            //           int count = pContributionItems.length;
09438:            //           for (int i = 0 ; i < count ; i++) {
09439:            //		IContributionItem pTempMenuItem = pContributionItems[i];
09440:            //                System.out.println(" menu Item = "+pTempMenuItem.getLabel());
09441:            //           }
09442:            //       }
09443:            //   }
09444:
09445:            private void addAddinMenus(IMenuManager mgr) {
09446:                mgr.add(new Separator());
09447:
09448:                Action[] actions = getActionsFromRegistry("contextmenu/uml/diagram");
09449:
09450:                for (Action curAction : actions) {
09451:                    if (curAction == null) {
09452:                        // Make Sure the Seperators are kept.
09453:                        mgr.add(new Separator());
09454:                    } else if (curAction.isEnabled()) {
09455:                        mgr.add(new BaseActionWrapper(curAction));
09456:                    }
09457:                }
09458:            }
09459:
09460:            /**
09461:             * The registry information that is retrieved from layer files to build
09462:             * the list of actions supported by this node.
09463:             *
09464:             * @param path The registry path that is used for the lookup.
09465:             * @return The list of actions in the path.  null will be used if when
09466:             *         seperators can be placed.
09467:             */
09468:            protected Action[] getActionsFromRegistry(String path) {
09469:                ArrayList<Action> actions = new ArrayList<Action>();
09470:                FileSystem system = Repository.getDefault()
09471:                        .getDefaultFileSystem();
09472:
09473:                try {
09474:                    if (system != null) {
09475:                        FileObject lookupDir = system.findResource(path);
09476:
09477:                        if (lookupDir != null) {
09478:                            FileObject[] children = lookupDir.getChildren();
09479:
09480:                            for (FileObject curObj : children) {
09481:                                try {
09482:                                    DataObject dObj = DataObject.find(curObj);
09483:
09484:                                    if (dObj != null) {
09485:                                        InstanceCookie cookie = (InstanceCookie) dObj
09486:                                                .getCookie(InstanceCookie.class);
09487:
09488:                                        if (cookie != null) {
09489:                                            Object obj = cookie
09490:                                                    .instanceCreate();
09491:
09492:                                            if (obj instanceof  Action) {
09493:                                                actions.add((Action) obj);
09494:                                            } else if (obj instanceof  JSeparator) {
09495:                                                actions.add(null);
09496:                                            }
09497:                                        }
09498:                                    } // dObj != null
09499:                                }
09500:
09501:                                catch (ClassNotFoundException e) {
09502:                                    // Unable to create the instance for some reason.  So the
09503:                                    // do not worry about adding the instance to the list.
09504:                                }
09505:                            } // for-each FileObject
09506:                        } // if lookupDir != null
09507:                    } // if system != null
09508:                }
09509:
09510:                catch (DataObjectNotFoundException e) {
09511:                    // Basically Bail at this time.
09512:                }
09513:
09514:                catch (IOException ioE) {
09515:                }
09516:
09517:                Action[] retVal = new Action[actions.size()];
09518:                actions.toArray(retVal);
09519:                return retVal;
09520:            }
09521:
09522:            private void addDefaultMenuItems(IMenuManager mgr) {
09523:                //no default items
09524:            }
09525:
09526:            /**
09527:             * Fires the context menu pre display event
09528:             */
09529:            private void fireDrawingAreaContextMenuPrepare(
09530:                    IMenuManager contextMenu) {
09531:                IDiagram dia = getDiagram();
09532:                if (getDrawingAreaDispatcher() != null && dia != null) {
09533:                    IEventPayload payload = m_drawingAreaDispatcher
09534:                            .createPayload("DrawingAreaContextMenuPrepare");
09535:                    m_drawingAreaDispatcher.fireDrawingAreaContextMenuPrepare(
09536:                            dia, null, payload);
09537:                }
09538:            }
09539:
09540:            /**
09541:             * Fires the context menu post display event.  This allows sinks to put their own implementation on the buttons.
09542:             */
09543:            private void fireDrawingAreaContextMenuPrepared(
09544:                    IMenuManager contextMenu) {
09545:                IDiagram dia = getDiagram();
09546:                if (getDrawingAreaDispatcher() != null && dia != null) {
09547:                    IEventPayload payload = m_drawingAreaDispatcher
09548:                            .createPayload("DrawingAreaContextMenuPrepared");
09549:                    m_drawingAreaDispatcher.fireDrawingAreaContextMenuPrepared(
09550:                            dia, null, payload);
09551:                }
09552:            }
09553:
09554:            /*
09555:             * Returns the selected compartments for the graph object.
09556:             */
09557:            public ETList<ICompartment> getSelectedCompartments(
09558:                    TSGraphObject pGraphObject) {
09559:                IETGraphObject obj = pGraphObject instanceof  IETGraphObject ? (IETGraphObject) pGraphObject
09560:                        : null;
09561:
09562:                if (obj != null && obj.getEngine() != null) {
09563:                    return obj.getEngine().getSelectedCompartments();
09564:                }
09565:                return null;
09566:            }
09567:
09568:            public void setSelectedCompartments(boolean state) {
09569:                ETList<ICompartment> selectedCompartments = null;
09570:                ICompartment selectedCompartment = null;
09571:                //       ETList <IETGraphObject> graphObjects =  getSelectedNodes();
09572:                ETList<TSObject> graphObjects = getAllGraphObjects();
09573:                if (graphObjects == null) {
09574:                    return;
09575:                }
09576:                for (TSObject graphObj : graphObjects) {
09577:                    if (graphObj != null && graphObj instanceof  IETNode) {
09578:                        IDrawEngine drawEngine = TypeConversions
09579:                                .getDrawEngine(graphObj);
09580:                        if (drawEngine != null) {
09581:                            selectedCompartments = drawEngine
09582:                                    .getSelectedCompartments();
09583:                            if (selectedCompartments != null
09584:                                    && selectedCompartments.size() > 0) {
09585:                                //                       selectedCompartment = (ICompartment) selectedCompartments.iterator().next();
09586:                                //                       selectedCompartment.setSelected(false);
09587:                                Iterator<ICompartment> iter = selectedCompartments
09588:                                        .iterator();
09589:                                while (iter.hasNext()) {
09590:                                    selectedCompartment = (ICompartment) iter
09591:                                            .next();
09592:                                    selectedCompartment.setSelected(false);
09593:                                }
09594:                            }
09595:                        }
09596:                    }
09597:                }
09598:            }
09599:
09600:            /*
09601:             * Returns true if the graph object is selected.
09602:             */
09603:            public boolean isSelected(TSGraphObject pGraphObject) {
09604:                if (pGraphObject instanceof  ITSGraphObject) {
09605:                    ITSGraphObject obj = (ITSGraphObject) pGraphObject;
09606:                    return obj.isSelected();
09607:                } else {
09608:                    return false;
09609:                }
09610:            }
09611:
09612:            public IElement getIElement2(ETEdge object, IElementLocator pLocator) {
09613:                if (object == null) {
09614:                    return null;
09615:                }
09616:                if (pLocator == null) {
09617:                    pLocator = new ElementLocator();
09618:                }
09619:                ETGenericEdgeUI ui = (ETGenericEdgeUI) object.getUI();
09620:                if (ui != null) {
09621:                    return pLocator.findElementByID(ui.getTopLevelMEIDValue(),
09622:                            ui.getMeidValue());
09623:                } else {
09624:                    return null;
09625:                }
09626:            }
09627:
09628:            public IElement getIElement(ETNode object, IElementLocator pLocator) {
09629:                if (object == null) {
09630:                    return null;
09631:                }
09632:                if (pLocator == null) {
09633:                    pLocator = new ElementLocator();
09634:                }
09635:                ETGenericNodeUI nodeUI = (ETGenericNodeUI) object.getUI();
09636:                if (nodeUI != null) {
09637:                    return pLocator.findElementByID(nodeUI
09638:                            .getTopLevelMEIDValue(), nodeUI.getMeidValue());
09639:                } else {
09640:                    return null;
09641:                }
09642:            }
09643:
09644:            public IElement getIElement(ETNode node) {
09645:                return getIElement(node, null);
09646:            }
09647:
09648:            /*
09649:             * Sets the selection state on a graph object
09650:             */
09651:            protected void setSelect(TSGraphObject pGraphObject, boolean bSelect) {
09652:                if (pGraphObject instanceof  ITSGraphObject) {
09653:                    ITSGraphObject obj = (ITSGraphObject) pGraphObject;
09654:                    obj.setSelected(bSelect);
09655:                }
09656:            }
09657:
09658:            /*
09659:             * getDrawingAreaDispatcher is a demand load accessor to the drawArea Event Dispatcher.
09660:             */
09661:            public IDrawingAreaEventDispatcher getDrawingAreaDispatcher() {
09662:                if (m_drawingAreaDispatcher == null) {
09663:                    DispatchHelper helper = new DispatchHelper();
09664:                    m_drawingAreaDispatcher = helper.getDrawingAreaDispatcher();
09665:                }
09666:                return m_drawingAreaDispatcher;
09667:            }
09668:
09669:            /**
09670:             * Selects the element and fires the events
09671:             *
09672:             * @param pGraphObject The graph object to select or unselect
09673:             * @param bSelect Set to true to select this guy, otherwise it's an unselect.
09674:             * @param bDeselectAllOthers Should we deselect all other objects?
09675:             * @see org.netbeans.modules.uml.ui.swing.drawingarea.IAxDrawingAreaControl#selectAndFireEvents(com.tomsawyer.graph.TSGraphObject, boolean, boolean)
09676:             */
09677:            public void selectAndFireEvents(TSGraphObject pGraphObject,
09678:                    boolean bSelect, boolean bDeselectAllOthers) {
09679:                if (bDeselectAllOthers) {
09680:                    // Save the currently selected objects.
09681:                    ETList<IPresentationElement> unselectedItems = this 
09682:                            .getSelected();
09683:
09684:                    // Remove the select state from all objects.
09685:                    getGraphWindow().deselectAll(false);
09686:
09687:                    if (this .getActions().getEnableSelectionEvents() == false) {
09688:                        //				getDrawingAreaDispatcher().fireUnselect(this.getDiagram(),
09689:                        //					unselectedItems,
09690:                        //					getDrawingAreaDispatcher().createPayload("DrawingAreaSelChanged"));
09691:                    }
09692:                }
09693:
09694:                if (pGraphObject != null) {
09695:                    // Don't send the un/select event twice
09696:                    if (bSelect && !isSelected(pGraphObject) || !bSelect
09697:                            && isSelected(pGraphObject)) {
09698:                        setSelect(pGraphObject, bSelect);
09699:
09700:                        if (bSelect) {
09701:                            this .fireSelectEvent(pGraphObject);
09702:                        } else {
09703:                            this .fireUnselectEvent(pGraphObject);
09704:                        }
09705:                    }
09706:                }
09707:            }
09708:
09709:            /*
09710:             * Disables the Drawing area action listener from Sending Selection and deselection events.
09711:             * We need this because sometime we don't want to notify that objects selection state has changed.
09712:             */
09713:            public void disableSelectionChangeEvents() {
09714:                this .getActions().setEnableSelectionEvents(false);
09715:            }
09716:
09717:            /*
09718:             * Enables the drawing area action listener so it will fire selection and deselection change events.
09719:             */
09720:            public void enableSelectionChangeEvents() {
09721:                this .getActions().setEnableSelectionEvents(true);
09722:            }
09723:
09724:            /*
09725:             * This method just fires the selection notification it doesn't change the state of the graph object.
09726:             */
09727:            public void fireSelectEvent(TSGraphObject pGraphObject) {
09728:                IEventPayload payload = getDrawingAreaDispatcher()
09729:                        .createPayload("DrawingAreaSelChanged");
09730:                //      ETList < IPresentationElement > selectedItems = this.getSelected();
09731:                //this.getDrawingAreaDispatcher().fireSelect(this.getDiagram(),null,null,//getSelectedCompartments(pGraphObject),
09732:                //			payload);
09733:                //Jyothi:For some reason the contents of this method have been commented out..
09734:                //I need to use it for A11y tab select feature.. hence this workaround
09735:                tempList.add(pGraphObject);
09736:                fireSelectEvent(tempList);
09737:                tempList.clear();
09738:            }
09739:
09740:            /*
09741:             * This method just fires the selection notification it doesn't change the state of the graph object.
09742:             */
09743:            //NOTE: The selection change event is fired in ADDrawingAreaSelectState.onMouseClicked()
09744:            public void fireSelectEvent(List pSelectedGraphObjs) {
09745:                ETArrayList<IPresentationElement> presentationElementList = new ETArrayList<IPresentationElement>();
09746:                ETList<ICompartment> selectedCompartments = null;
09747:                ICompartment selectedCompartment = null;
09748:
09749:                IEventPayload payload = getDrawingAreaDispatcher()
09750:                        .createPayload("DrawingAreaSelChanged");
09751:
09752:                try {
09753:                    if (pSelectedGraphObjs != null) {
09754:                        IDrawEngine drawEngine = null;
09755:                        Iterator<TSEObject> iter = pSelectedGraphObjs
09756:                                .iterator();
09757:                        while (iter.hasNext()) {
09758:                            TSEObject graphObject = iter.next();
09759:                            IETGraphObjectUI ui = graphObject.getUI() instanceof  IETGraphObjectUI ? (IETGraphObjectUI) graphObject
09760:                                    .getUI()
09761:                                    : null;
09762:                            if (ui != null) {
09763:                                drawEngine = ui.getDrawEngine();
09764:                                if (drawEngine != null) {
09765:                                    presentationElementList.add(drawEngine
09766:                                            .getPresentation());
09767:                                }
09768:                            }
09769:                        }
09770:                        if (drawEngine != null) {
09771:                            selectedCompartments = drawEngine
09772:                                    .getSelectedCompartments();
09773:                            if (selectedCompartments != null
09774:                                    && selectedCompartments.size() > 0) {
09775:                                selectedCompartment = (ICompartment) selectedCompartments
09776:                                        .iterator().next();
09777:                            }
09778:                        }
09779:                    } else {
09780:                        clearSelectedNodesGroup();
09781:                        // Deselect all selected compartments.
09782:                        setSelectedCompartments(false);
09783:                    }
09784:                    //even if nothing is selected I need to fire the event.
09785:                    this .getDrawingAreaDispatcher().fireSelect(
09786:                            this .getDiagram(), presentationElementList,
09787:                            selectedCompartment, payload);
09788:
09789:                    //        ETElementManager mgr = new ETElementManager(this);
09790:                    //        mgr.onPostSelect(presentationElementList);
09791:                    IDiagramValidator diagramValidator = new DiagramValidator();
09792:                    for (Iterator<IPresentationElement> iter = presentationElementList
09793:                            .iterator(); iter.hasNext();) {
09794:                        IPresentationElement element = iter.next();
09795:                        IETGraphObject etGraphObject = TypeConversions
09796:                                .getETGraphObject(element);
09797:                        if (etGraphObject != null) {
09798:                            diagramValidator.doPostSelectValidation(m_Diagram,
09799:                                    etGraphObject);
09800:                        }
09801:                    }
09802:                } catch (Exception e) {
09803:                    e.printStackTrace();
09804:                }
09805:
09806:                // ETSystem.out.println("ADDrawignAreaControl.fireSelectEvent()");
09807:            }
09808:
09809:            /*
09810:             * This method just fires the deslection notification it doesn't change the state of the graph object.
09811:             */
09812:            public void fireUnselectEvent(List pGraphObjects) {
09813:                if (pGraphObjects != null) {
09814:                    Iterator<TSGraphObject> iter = pGraphObjects.iterator();
09815:                    while (iter.hasNext()) {
09816:                        fireUnselectEvent(iter.next());
09817:                    }
09818:                }
09819:            }
09820:
09821:            /*
09822:             * This method just fires the deslection notification it doesn't change the state of the graph object.
09823:             */
09824:            public void fireUnselectEvent(TSGraphObject pGraphObject) {
09825:                IEventPayload payload = getDrawingAreaDispatcher()
09826:                        .createPayload("DrawingAreaSelChanged");
09827:                ETList<IPresentationElement> selectedItems = this .getSelected();
09828:
09829:                /*
09830:                if (pElement != null)
09831:                {
09832:                IPresentationElement pElement = getPresentationElement(pGraphObject);
09833:                IPresentationElement[] unselectedItems = new IPresentationElement[1];
09834:                unselectedItems[0] = pElement;
09835:                }
09836:                 */
09837:                //		getDrawingAreaDispatcher().fireUnselect(this.getDiagram(),
09838:                //												selectedItems,
09839:                //												payload);
09840:            }
09841:
09842:            /**
09843:             * ITwoPhaseCommit interface.
09844:             * Take the temp files generated in the precommit and move them into the original
09845:             * files to commit them.
09846:             */
09847:            //    public void commit()
09848:            //    {
09849:            //        if (m_PreCommitFileName.length() > 0)
09850:            //        {
09851:            //             String tempFile = m_PreCommitFileName;
09852:            //            String tempETLFile = StringUtilities.ensureExtension(tempFile,
09853:            //                    FileExtensions.DIAGRAM_PRECOMMIT_LAYOUT_EXT);
09854:            //
09855:            //            String tempETLPFile = StringUtilities.ensureExtension(tempFile,
09856:            //                    FileExtensions.DIAGRAM_PRECOMMIT_PRESENTATION_EXT);
09857:            //            String realTOMFile = StringUtilities.ensureExtension(tempFile,
09858:            //                    FileExtensions.DIAGRAM_LAYOUT_EXT);
09859:            //            String realPRSFile = StringUtilities.ensureExtension(tempFile,
09860:            //                    FileExtensions.DIAGRAM_PRESENTATION_EXT);
09861:            //
09862:            //            m_PreCommitFileName = "";
09863:            //
09864:            //            // Make sure both of the temp files are there
09865:            //            File tempETL = new File(tempETLFile);
09866:            //            File tempETLP = new File(tempETLPFile);
09867:            //            File realTOM = new File(realTOMFile);
09868:            //            File realPRS = new File(realPRSFile);
09869:            //
09870:            //            if (tempETL.exists() && tempETLP.exists()) 
09871:            //            {
09872:            //                try
09873:            //                {
09874:            //                    if (realTOM.exists())
09875:            //                    {
09876:            //                        realTOM.delete();
09877:            //                    }
09878:            //                    if (realPRS.exists())
09879:            //                    {
09880:            //                        realPRS.delete();
09881:            //                    }
09882:            //                    boolean rename1 = tempETL.renameTo(realTOM);
09883:            //                    boolean rename2 = tempETLP.renameTo(realPRS);
09884:            //                    if (rename1 && rename2)
09885:            //                    {
09886:            //                        setIsDirty(false);
09887:            //
09888:            //                        // Let folks know that the diagram has been saved
09889:            //                        if (getDrawingAreaDispatcher() != null)
09890:            //                        {
09891:            //                            IEventPayload payload = m_drawingAreaDispatcher.createPayload("DrawingAreaPostSave");
09892:            //                            IProxyDiagram pProxy = getProxyDiagram();
09893:            //                            if (pProxy != null)
09894:            //                            {
09895:            //                                m_drawingAreaDispatcher.fireDrawingAreaPostSave(pProxy,
09896:            //                                        payload);
09897:            //                            }
09898:            //                        }
09899:            //                    } else {
09900:            //                        assert rename1 : "failed to rename "+tempETLFile;
09901:            //                        assert rename2 : "failed to rename "+tempETLPFile;
09902:            //                    }
09903:            //                } catch (Exception e)
09904:            //                {
09905:            //                    // TODO Auto-generated catch block
09906:            //                    e.printStackTrace();
09907:            //                }
09908:            //            } else
09909:            //            {
09910:            //                assert false : "could not find commit temporary files " + tempETLFile +" or/and "+ tempETLPFile;
09911:            //            }
09912:            //        }
09913:            //    }
09914:            /**
09915:             * Creates a fullpath filename for this diagram
09916:             *
09917:             * @param sName [out,retval] The full path filename of this diagram.
09918:             */
09919:            private String getFullFileName(String name) {
09920:                String retFileName = null;
09921:                // If the user enters a filename then use that as the proposed filename.
09922:                // If the filename is not absolute then we use the project directory
09923:                // as the location of the file.  If, for some reason, the filename argument
09924:                // is 0 then we use the name of the diagram as the name of the file and the
09925:                // workspace location for the directory.
09926:                if (name != null && name.length() > 0) {
09927:                    String formatStr = null;
09928:                    long timeInMillis = System.currentTimeMillis();
09929:
09930:                    // To avoid conflicts between filenames, esp for large groups that are
09931:                    // using an SCC to manage their model we append a timestamp to the
09932:                    // file name.
09933:                    retFileName = name + "_" + timeInMillis;
09934:                } else {
09935:                    retFileName = m_Name;
09936:                }
09937:
09938:                // Make sure we have a legal file.  If it is just a name then add the
09939:                // .etld extension and put it in the same spot as the workspace.
09940:                String buffer = retFileName;
09941:                String drive = null;
09942:                int pos = buffer.indexOf(":");
09943:                if (pos >= 0) {
09944:                    drive = buffer.substring(0, pos);
09945:                }
09946:
09947:                if (drive == null && m_Namespace != null) {
09948:                    // Assume we don't have a path and create one from the project directory
09949:                    IProject proj = m_Namespace.getProject();
09950:                    if (proj != null) {
09951:                        String fileName = proj.getFileName();
09952:                        if (fileName != null && fileName.length() > 0) {
09953:                            try {
09954:                                fileName = (new File(fileName))
09955:                                        .getCanonicalPath();
09956:                                int posSlash = fileName
09957:                                        .lastIndexOf(File.separator);
09958:                                if (posSlash >= 0) {
09959:                                    fileName = fileName.substring(0,
09960:                                            posSlash + 1);
09961:                                    fileName += buffer;
09962:                                    buffer = fileName;
09963:                                }
09964:                            } catch (Exception e) {
09965:                            }
09966:                        }
09967:                    }
09968:                }
09969:
09970:                if (!buffer.endsWith(FileExtensions.DIAGRAM_LAYOUT_EXT)) {
09971:                    buffer += FileExtensions.DIAGRAM_LAYOUT_EXT;
09972:                }
09973:
09974:                return buffer;
09975:            }
09976:
09977:            /**
09978:             * Returns the current product
09979:             *
09980:             * @param pManager [out,retval] Our current product
09981:             */
09982:            public IProduct getProduct() {
09983:                return ProductHelper.getProduct();
09984:            }
09985:
09986:            /*
09987:             * Returns the logical view port rectangle, (ie the inner interactive rect in the overview window).
09988:             */
09989:            public IETRect getLogicalViewPortRect() {
09990:                ADGraphWindow graphWindow = this .getGraphWindow();
09991:                if (graphWindow != null) {
09992:                    return new ETRectEx(graphWindow.getWorldBounds());
09993:                }
09994:                return null;
09995:            }
09996:
09997:            /**
09998:             * ITwoPhaseCommit interface.  Creates a temporary file in preparation for
09999:             * committing.
10000:             */
10001:            public void preCommit() {
10002:                UMLLogger
10003:                        .logMessage(
10004:                                logger,
10005:                                "preCommit() is no longer needed. Used commit() instead.",
10006:                                Level.FINE); // NOI18N
10007:            }
10008:
10009:            public synchronized void commit() {
10010:                if (m_isDirty) {
10011:                    //          getGraph().updateBounds();
10012:                    m_nZoomLevelFromArchive = this .getCurrentZoom();
10013:                    // Save the viewport center.
10014:                    IETRect logicalViewPort = getLogicalViewPortRect();
10015:
10016:                    if (logicalViewPort != null) {
10017:                        m_CenterFromArchive = logicalViewPort.getCenterPoint();
10018:                    }
10019:
10020:                    boolean proceed = true;
10021:                    IDrawingAreaEventDispatcher drawingDispatcher = getDrawingAreaDispatcher();
10022:
10023:                    // Let folks know that the diagram is being saved
10024:                    if (drawingDispatcher != null) {
10025:                        IEventPayload payload = drawingDispatcher
10026:                                .createPayload("DrawingAreaPreSave");
10027:                        IProxyDiagram pProxy = getProxyDiagram();
10028:                        if (pProxy != null) {
10029:                            drawingDispatcher.fireDrawingAreaPreSave(pProxy,
10030:                                    payload);
10031:                        }
10032:                    }
10033:
10034:                    if (proceed) {
10035:                        if (m_FileName.length() > 0) {
10036:                            // Create the file names for our two diagram files
10037:                            String fileName = m_FileName;
10038:                            String ETLDFilename = StringUtilities
10039:                                    .ensureExtension(fileName,
10040:                                            FileExtensions.DIAGRAM_LAYOUT_EXT);
10041:                            String ETLPFilename = StringUtilities
10042:                                    .ensureExtension(
10043:                                            fileName,
10044:                                            FileExtensions.DIAGRAM_PRESENTATION_EXT);
10045:
10046:                            saveETLDAndETLPFiles(ETLDFilename, ETLPFilename);
10047:                            setIsDirty(false);
10048:
10049:                            // Let folks know that the diagram has been saved
10050:                            if (drawingDispatcher != null) {
10051:                                IEventPayload payload = drawingDispatcher
10052:                                        .createPayload("DrawingAreaPostSave");
10053:                                IProxyDiagram pProxy = getProxyDiagram();
10054:                                if (pProxy != null) {
10055:                                    drawingDispatcher.fireDrawingAreaPostSave(
10056:                                            pProxy, payload);
10057:                                }
10058:                            }
10059:                        }
10060:                    }
10061:                }
10062:            }
10063:
10064:            //    public void preCommit()
10065:            //    {
10066:            //        boolean retVal = true;
10067:            //        if (m_isDirty)
10068:            //        {
10069:            ////          getGraph().updateBounds();
10070:            //            m_nZoomLevelFromArchive = this.getCurrentZoom();
10071:            //            // Save the viewport center.
10072:            //            IETRect logicalViewPort = getLogicalViewPortRect();
10073:            //
10074:            //            if (logicalViewPort != null)
10075:            //            {
10076:            //                m_CenterFromArchive = logicalViewPort.getCenterPoint();
10077:            //            }
10078:            //
10079:            //            boolean proceed = true;
10080:            //
10081:            //            // Let folks know that the diagram is being saved
10082:            //            if (getDrawingAreaDispatcher() != null)
10083:            //            {
10084:            //                IEventPayload payload = m_drawingAreaDispatcher.createPayload("DrawingAreaPreSave");
10085:            //                IProxyDiagram pProxy = getProxyDiagram();
10086:            //                if (pProxy != null)
10087:            //                {
10088:            //                    m_drawingAreaDispatcher.fireDrawingAreaPreSave(pProxy,
10089:            //                            payload);
10090:            //                }
10091:            //            }
10092:            //
10093:            //            if (proceed)
10094:            //            {
10095:            //                m_PreCommitFileName = "";
10096:            //                if (m_FileName.length() > 0)
10097:            //                {
10098:            //                    // Create the file names for our two diagram files
10099:            //                    String fileName = m_FileName;
10100:            //                    String tempETLDFilename = StringUtilities.ensureExtension(fileName,
10101:            //                            FileExtensions.DIAGRAM_PRECOMMIT_LAYOUT_EXT);
10102:            //                    String tempETLPFilename = StringUtilities.ensureExtension(fileName,
10103:            //                            FileExtensions.DIAGRAM_PRECOMMIT_PRESENTATION_EXT);
10104:            //
10105:            //                    saveETLDAndETLPFiles(tempETLDFilename, tempETLPFilename);
10106:            //                    m_PreCommitFileName = tempETLDFilename; 
10107:            //                    // dirty state should be changed after commit()
10108:            ////               setIsDirty(false);
10109:            //                } else
10110:            //                {
10111:            //                    retVal = false;
10112:            //                }
10113:            //            } else
10114:            //            {
10115:            //                retVal = false;
10116:            //            }
10117:            //        }
10118:            //    }
10119:
10120:            /**
10121:             * Part of the ITwoPhaseCommit interface.  Is this drawing dirty?
10122:             *
10123:             * @param bIsDirty [out,retval] true if the diagram needs to be saved.
10124:             */
10125:            public boolean isDirty() {
10126:                return m_isDirty;
10127:            }
10128:
10129:            /**
10130:             * Saves associated diagrams and elements list
10131:             *
10132:             * @param pArchive [in] The archive (etlp file) we're saving to
10133:             */
10134:            private void saveAssociatedDiagramsAndElementsList(
10135:                    IProductArchive prodArchive) {
10136:                int count = m_AssociatedDiagrams.size();
10137:                for (int i = 0; i < count; i++) {
10138:                    String name = (String) m_AssociatedDiagrams.elementAt(i);
10139:                    prodArchive
10140:                            .insertIntoTable(
10141:                                    IProductArchiveDefinitions.ASSOCIATED_DIAGRAMS_STRING,
10142:                                    name);
10143:                }
10144:
10145:                count = m_AssociatedElements.size();
10146:                Iterator iter1 = m_AssociatedElements.keySet().iterator();
10147:                Iterator iter2 = m_AssociatedElements.values().iterator();
10148:                int nKey = 0;
10149:                for (int i = 0; i < count; i++) {
10150:                    //need to get the key from m_AssociatedElements
10151:                    String value = (String) iter1.next();
10152:
10153:                    Object obj = iter2.next();
10154:                    if (obj instanceof  Vector) {
10155:                        Vector meidCol = (Vector) obj;
10156:                        int meidCount = meidCol.size();
10157:
10158:                        for (int j = 0; j < meidCount; j++) {
10159:                            String name = (String) meidCol.get(j);
10160:
10161:                            ETPairT<IProductArchiveElement, Integer> val = prodArchive
10162:                                    .insertIntoTable(
10163:                                            IProductArchiveDefinitions.ASSOCIATED_ELEMENTS_STRING,
10164:                                            name);
10165:                            nKey = ((Integer) val.getParamTwo()).intValue();
10166:                            IProductArchiveElement foundElement = val
10167:                                    .getParamOne();
10168:
10169:                            if (foundElement != null) {
10170:                                foundElement
10171:                                        .addAttributeString(
10172:                                                IProductArchiveDefinitions.TOPLEVELID_STRING,
10173:                                                value);
10174:                            }
10175:                        }
10176:                    }
10177:                }
10178:            }
10179:
10180:            /**
10181:             * Save this drawing to the etld and etlp files
10182:             *
10183:             * @param sTOMFilename [in] The etl file to save our TS information to.
10184:             * @param sPRSFilename [in] The etlp file to save our presentation information to.
10185:             */
10186:            private void saveETLDAndETLPFiles(String sTOMFilename,
10187:                    String sPRSFilename) {
10188:                TSGraphManager pGraphMgr = getCurrentGraphManager();
10189:
10190:                if (pGraphMgr != null) {
10191:                    IProductArchive prodArchive = new ProductArchiveImpl();
10192:
10193:                    // Save the persistent track bar information
10194:                    if (getTrackBar() != null) {
10195:                        getTrackBar().save(prodArchive);
10196:                    }
10197:
10198:                    // Tell Tom Sawyer to save
10199:                    IProduct prod = getProduct();
10200:                    if (prod != null) {
10201:                        IDiagram dia = getDiagram();
10202:                        prod.setSerializingDiagram(dia);
10203:                        OutputStreamWriter out = null;
10204:                        Writer writer = null;
10205:                        try {
10206:                            FileObject etldFO = FileUtil.createData(new File(
10207:                                    sTOMFilename));
10208:
10209:                            out = new OutputStreamWriter(etldFO
10210:                                    .getOutputStream());
10211:                            writer = new BufferedWriter(out);
10212:
10213:                            xmlWriter = new TSEVisualizationXMLWriter(writer);
10214:                            xmlWriter.setGraphManager(this .getGraphManager());
10215:                            xmlWriter
10216:                                    .setServiceInputData(this .m_allOptionsServiceInputData);
10217:                            xmlWriter.setPreferences(this .getGraphWindow()
10218:                                    .getPreferences());
10219:                            xmlWriter.setUsingTemplates(false);
10220:                            xmlWriter.write();
10221:                            postWriteGMFFile(prodArchive);
10222:                        } catch (Exception ex) {
10223:                            UMLLogger.logException(logger, ex, Level.WARNING);
10224:                        } finally {
10225:                            try {
10226:                                if (out != null) {
10227:                                    out.close();
10228:                                }
10229:                                if (writer != null) {
10230:                                    writer.close();
10231:                                }
10232:                            } catch (IOException ex) {
10233:                                UMLLogger.logMessage(logger, ex.getMessage(),
10234:                                        Level.WARNING);
10235:                            }
10236:                        }
10237:                        prod.setSerializingDiagram(null);
10238:                    }
10239:
10240:                    // Save to the archive file
10241:                    writeToArchive(prodArchive);
10242:
10243:                    // Everything is working so save the product archive to file
10244:                    if (prodArchive != null) {
10245:                        boolean saveWorked = prodArchive.save(sPRSFilename);
10246:                    }
10247:                }
10248:            }
10249:
10250:            /**
10251:             * Saves resource manager data for this drawing area
10252:             *
10253:             * @param pProductArchive [in] Saves the resource manager information (fonts and colors) into the
10254:             * product archive (etlp file).
10255:             */
10256:            private void saveResourceManager(IProductArchive prodArchive) {
10257:                ResourceMgr pMgr = ResourceMgr
10258:                        .instance((IDrawingAreaControl) this );
10259:                if (pMgr != null && prodArchive != null) {
10260:                    pMgr.writeToArchive(prodArchive);
10261:                }
10262:            }
10263:
10264:            /**
10265:             * Sets the IDiagrams xmlnode's name attribute
10266:             */
10267:            private void setDiagramNodeNameAndOwner() {
10268:                IDiagram pDiagram = this .getDiagram();
10269:
10270:                Node node = pDiagram != null ? pDiagram.getNode() : null;
10271:                if (node != null) {
10272:                    XMLManip.setAttributeValue(node, "name", m_Name);
10273:                }
10274:
10275:                if (m_Namespace != null) {
10276:                    pDiagram.setOwner(m_Namespace);
10277:                }
10278:            }
10279:
10280:            /**
10281:             * Sets the filename for this drawing area.  If this filename is not in
10282:             * the current workspace then a new element is created in the workspace.
10283:             *
10284:             * @param newVal [in] The new filename
10285:             * @param bNewDiagram [in] Set to true if this is a new diagram.
10286:             */
10287:            public void setFileName(String fileName, boolean newFile) {
10288:                if (newFile) {
10289:                    IProxyDiagramManager diaMan = ProxyDiagramManager
10290:                            .instance();
10291:                    String newFileName = null;
10292:                    if (m_Namespace != null) {
10293:                        newFileName = diaMan.verifyUniqueDiagramName(
10294:                                m_Namespace, fileName);
10295:                        if (newFileName != null && newFileName.length() > 0) {
10296:                            m_FileName = newFileName;
10297:                        } else {
10298:                            m_FileName = fileName;
10299:                        }
10300:                    }
10301:                } else {
10302:                    m_FileName = fileName;
10303:                }
10304:
10305:                if (m_FileName != null && m_FileName.length() > 0) {
10306:                    IDiagram pDiagram = getDiagram();
10307:                    IProduct pProd = getProduct();
10308:                    if (pProd != null && pDiagram != null) {
10309:                        // Make sure the diagram is in the workspace
10310:                        pProd.addDiagram(pDiagram);
10311:                    }
10312:                }
10313:            }
10314:
10315:            /**
10316:             * Saves the diagram data to the product archive
10317:             *
10318:             * @param pArchive [in] The archive where we need to save presentation information.
10319:             */
10320:            private void writeToArchive(IProductArchive prodArchive) {
10321:                if (getGraphWindow() != null) {
10322:                    // save resource info
10323:                    saveResourceManager(prodArchive);
10324:
10325:                    // Save our associated diagrams and elements
10326:                    saveAssociatedDiagramsAndElementsList(prodArchive);
10327:
10328:                    // Save this diagrams stuff
10329:                    IProductArchiveElement pCreatedElement = prodArchive
10330:                            .createElement(IProductArchiveDefinitions.DIAGRAMINFO_STRING);
10331:                    if (pCreatedElement != null) {
10332:                        if (m_DiagramEngine != null) {
10333:                            m_DiagramEngine.writeToArchive(prodArchive,
10334:                                    pCreatedElement);
10335:                        }
10336:
10337:                        String diaKind = getDiagramKind2();
10338:
10339:                        // Add the current zoom
10340:                        pCreatedElement.addAttributeDouble(
10341:                                IProductArchiveDefinitions.DIAGRAM_ZOOM,
10342:                                m_nZoomLevelFromArchive);
10343:
10344:                        // Add the current page center
10345:                        pCreatedElement.addAttributeDouble(
10346:                                IProductArchiveDefinitions.DIAGRAM_XPOS,
10347:                                m_CenterFromArchive.x);
10348:                        pCreatedElement.addAttributeDouble(
10349:                                IProductArchiveDefinitions.DIAGRAM_YPOS,
10350:                                m_CenterFromArchive.y);
10351:
10352:                        // Add the name of the diagram
10353:                        pCreatedElement.addAttributeString(
10354:                                IProductArchiveDefinitions.DIAGRAMNAME_STRING,
10355:                                m_Name);
10356:
10357:                        // Add the alias of the diagram
10358:                        pCreatedElement.addAttributeString(
10359:                                IProductArchiveDefinitions.DIAGRAMALIAS_STRING,
10360:                                m_Alias);
10361:
10362:                        // Add the documentation of the diagram
10363:                        pCreatedElement.addAttributeString(
10364:                                IProductArchiveDefinitions.DIAGRAMNAME_DOCS,
10365:                                m_Documentation);
10366:
10367:                        // Add the kind of the diagram
10368:                        pCreatedElement.addAttributeString(
10369:                                IProductArchiveDefinitions.DRAWINGKIND2_STRING,
10370:                                diaKind);
10371:
10372:                        // Save the state of the alias flag
10373:                        pCreatedElement
10374:                                .addAttributeBool(
10375:                                        IProductArchiveDefinitions.LAST_SHOWALIAS_STATE,
10376:                                        ProductHelper.getShowAliasedNames() ? true
10377:                                                : false);
10378:
10379:                        // Add the namespace that owns this diagram
10380:                        if (m_Namespace != null) {
10381:                            String xmiid = m_Namespace.getXMIID();
10382:                            String topLevelXmiid = m_Namespace.getTopLevelId();
10383:
10384:                            if (xmiid != null && topLevelXmiid != null
10385:                                    && xmiid.length() > 0
10386:                                    && topLevelXmiid.length() > 0) {
10387:                                pCreatedElement
10388:                                        .addAttributeString(
10389:                                                IProductArchiveDefinitions.NAMESPACE_TOPLEVELID,
10390:                                                topLevelXmiid);
10391:                                pCreatedElement
10392:                                        .addAttributeString(
10393:                                                IProductArchiveDefinitions.NAMESPACE_MEID,
10394:                                                xmiid);
10395:                            }
10396:                        }
10397:
10398:                        // Add the id of the diagram
10399:                        IDiagram dia = getDiagram();
10400:                        if (dia != null) {
10401:                            String diaXmiid = dia.getXMIID();
10402:                            if (diaXmiid != null && diaXmiid.length() > 0) {
10403:                                pCreatedElement
10404:                                        .addAttributeString(
10405:                                                IProductArchiveDefinitions.DIAGRAM_XMIID,
10406:                                                diaXmiid);
10407:                            }
10408:                        }
10409:
10410:                        // Save the dll version information
10411:                        // Now save all the nodes to the product archive
10412:                        int count = m_ViewsReadWriteFromETLFile.size();
10413:                        for (int i = 0; i < count; i++) {
10414:                            IETGraphObject obj = (IETGraphObject) m_ViewsReadWriteFromETLFile
10415:                                    .elementAt(i);
10416:                            obj.save(prodArchive);
10417:                        }
10418:                        m_ViewsReadWriteFromETLFile.clear();
10419:                    }
10420:                }
10421:            }
10422:
10423:            public TSELineGrid getLineGrid() {
10424:                return lineGrid;
10425:            }
10426:
10427:            public ETDiagramOverviewWindow getOverviewWindow() {
10428:                return overviewWindow;
10429:            }
10430:
10431:            public TSEPointGrid getPointGrid() {
10432:                return pointGrid;
10433:            }
10434:
10435:            /*
10436:             * The State tools call this after a new object has been added to the diagram.
10437:             */
10438:            public void onInteractiveObjCreated(TSEObjectUI ui) {
10439:                if (ui instanceof  IETGraphObjectUI) {
10440:                    IETGraphObjectUI graphUI = (IETGraphObjectUI) ui;
10441:                    postAddObject(graphUI.getTSObject(), false);
10442:
10443:                    //         IDrawEngine engine = graphUI.getDrawEngine();
10444:                    //         if(engine != null)
10445:                    //         {
10446:                    //            addPresentationElementToTrackBar(engine.getPresentation());
10447:                    //         }
10448:                }
10449:            }
10450:
10451:            public void setEditCompartment(ETCompartment editCtrl) {
10452:                if (editCtrl != null) {
10453:                    m_EditCompartment = new WeakReference(editCtrl);
10454:                } else {
10455:                    m_EditCompartment = null;
10456:                }
10457:            }
10458:
10459:            private ETCompartment getEditCompartment() {
10460:                return (m_EditCompartment != null) ? (ETCompartment) m_EditCompartment
10461:                        .get()
10462:                        : null;
10463:            }
10464:
10465:            //**************************************************
10466:            // Helper Methods
10467:            //**************************************************
10468:
10469:            /**
10470:             * Sends a debug message to the message service.  The String may have some
10471:             * embedded strings which are intepreted as follows.
10472:             *
10473:             * %n - Name of the drawing area
10474:             * %f - Filename of the drawing area
10475:             * %F - Temp Filename of the drawing area
10476:             * %p - The temp name of the presentation data
10477:             * %P - The temp name of the presentation data
10478:             * %w - The name of the workspace
10479:             *
10480:             * @param messageType The type of message to send (ie error, debug...)
10481:             * @param message The message string to send.  See the format codes in
10482:             *                the desc of this function.
10483:             */
10484:            protected void sendDebugMessage(String message) {
10485:                sendMessage(MsgCoreConstants.MT_DEBUG, message);
10486:            }
10487:
10488:            /**
10489:             * Sends a debug message to the message service.  The String may have some
10490:             * embedded strings which are intepreted as follows.
10491:             *
10492:             * %n - Name of the drawing area
10493:             * %f - Filename of the drawing area
10494:             * %F - Temp Filename of the drawing area
10495:             * %p - The temp name of the presentation data
10496:             * %P - The temp name of the presentation data
10497:             * %w - The name of the workspace
10498:             *
10499:             * @param messageType The type of message to send (ie error, debug...)
10500:             * @param message The message string to send.  See the format codes in
10501:             *                the desc of this function.
10502:             */
10503:            protected void sendErrorMessage(String message) {
10504:                sendMessage(MsgCoreConstants.MT_ERROR, message);
10505:            }
10506:
10507:            /**
10508:             * Sends a message to the message service.  The String may have some
10509:             * embedded strings which are intepreted as follows.
10510:             *
10511:             * %n - Name of the drawing area
10512:             * %f - Filename of the drawing area
10513:             * %F - Temp Filename of the drawing area
10514:             * %p - The temp name of the presentation data
10515:             * %P - The temp name of the presentation data
10516:             * %w - The name of the workspace
10517:             *
10518:             * @param messageType The type of message to send (ie error, debug...)
10519:             * @param message The message string to send.  See the format codes in
10520:             *                the desc of this function.
10521:             */
10522:            protected void sendMessage(int type, String message) {
10523:                String finalMessage = message;
10524:
10525:                finalMessage.replaceAll("%n", getName());
10526:                finalMessage
10527:                        .replaceAll("%f", FileExtensions.DIAGRAM_LAYOUT_EXT);
10528:                finalMessage.replaceAll("%F",
10529:                        FileExtensions.DIAGRAM_PRECOMMIT_LAYOUT_EXT);
10530:                finalMessage.replaceAll("%p",
10531:                        FileExtensions.DIAGRAM_PRESENTATION_EXT);
10532:                finalMessage.replaceAll("%P",
10533:                        FileExtensions.DIAGRAM_PRECOMMIT_PRESENTATION_EXT);
10534:
10535:                // Replace the %w in the message with the name of the workspacetoReplace( _T( "%n" ));
10536:                if (finalMessage.indexOf("%w") >= 0) {
10537:                    IWorkspace ws = ProductHelper.getWorkspace();
10538:                    if (ws != null) {
10539:                        finalMessage.replaceAll("%w", ws.getName());
10540:                    }
10541:                }
10542:
10543:                UMLMessagingHelper helper = new UMLMessagingHelper();
10544:                helper.sendMessage(type, finalMessage);
10545:            }
10546:
10547:            /**
10548:             * @param i
10549:             * @param type
10550:             */
10551:            protected void setMode(int mode, String viewDescription) {
10552:                if (getDiagramEngine() != null) {
10553:                    IDiagramEngine engine = getDiagramEngine();
10554:
10555:                    switch (mode) {
10556:                    case ADDrawingAreaConstants.CREATE_NODE_DECORATOR_CMD:
10557:                        splitNodeViewDescription(viewDescription);
10558:                        engine.enterMode2("NODE_DECORATOR", "", "",
10559:                                viewDescription);
10560:                        break;
10561:                    case ADDrawingAreaConstants.NODE_RESIZE_CMD:
10562:                        splitNodeViewDescription(viewDescription);
10563:                        engine.enterMode2("NODE_RESIZE", "", "",
10564:                                viewDescription);
10565:                        break;
10566:                    case ADDrawingAreaConstants.ADD_NODE_CMD: {
10567:                        splitNodeViewDescription(viewDescription);
10568:                        //               int delimiter = viewDescription.indexOf(' ');
10569:                        //               if(delimiter >= 0)
10570:                        //               {
10571:                        //                  String TSTypeName = viewDescription.substring(0, delimiter);
10572:                        //                  String uiClass    = viewDescription.substring(delimiter + 1);
10573:                        //                  engine.enterMode2("ADD_NODE", "", "", uiClass);
10574:                        //               }
10575:                        engine.enterMode2("ADD_NODE", "", "", viewDescription);
10576:                        break;
10577:                    }
10578:                    case ADDrawingAreaConstants.ADD_EDGE_CMD: {
10579:                        splitEdgeViewDescription(viewDescription);
10580:                        //               int delimiter = viewDescription.indexOf(' ');
10581:                        //               if(delimiter >= 0)
10582:                        //               {
10583:                        //                  String TSTypeName = viewDescription.substring(0, delimiter);
10584:                        //                  String uiClass    = viewDescription.substring(delimiter + 1);
10585:                        //                  engine.enterMode2("ADD_EDGE", "", "", uiClass);
10586:                        //               }
10587:                        engine.enterMode2("ADD_EDGE", "", "", viewDescription);
10588:                        break;
10589:                    }
10590:                    }
10591:                }
10592:            }
10593:
10594:            /*
10595:             * Returns the Printer class.
10596:             */
10597:            public ADDrawingAreaPrinter getDrawingAreaPrinter() {
10598:                if (m_printer == null) {
10599:                    m_printer = new ADDrawingAreaPrinter(getGraphWindow(),
10600:                            getResources());
10601:                }
10602:
10603:                return m_printer;
10604:            }
10605:
10606:            /**
10607:             * Get the current graph view on the control
10608:             */
10609:            protected void initializeTrackBar() {
10610:                if (m_DiagramEngine != null) {
10611:                    m_TrackBar = m_DiagramEngine.initializeTrackBar();
10612:                }
10613:
10614:                if (m_TrackBar != null) {
10615:                    //         m_TrackBar.setDiagram(diagram);
10616:                    centerPanel.add(m_TrackBar, BorderLayout.NORTH);
10617:                }
10618:            }
10619:
10620:            protected ETList<IPresentationElement> buildPresentationList(
10621:                    ETList<IETGraphObject> objects) {
10622:                ETArrayList<IPresentationElement> retVal = new ETArrayList<IPresentationElement>();
10623:
10624:                for (Iterator<IETGraphObject> iter = objects.iterator(); iter
10625:                        .hasNext();) {
10626:                    IETGraphObject curObject = iter.next();
10627:                    retVal.add(curObject.getPresentationElement());
10628:                }
10629:
10630:                return retVal;
10631:            }
10632:
10633:            public void onGraphEvent(int pGraphEventKind, IETPoint pStartPoint,
10634:                    IETPoint pEndPoint, ETList<IETGraphObject> affectedObjects) {
10635:                switch (pGraphEventKind) {
10636:                case IGraphEventKind.GEK_POST_SELECT:
10637:                    // Send the event to the graph
10638:                    ((ETGraph) this .getCurrentGraph()).onGraphEvent(
10639:                            pGraphEventKind, pStartPoint, pEndPoint,
10640:                            affectedObjects);
10641:                    break;
10642:                case IGraphEventKind.GEK_POST_CREATE:
10643:                    // Send the event to the graph
10644:                    ((ETGraph) this .getCurrentGraph()).onGraphEvent(
10645:                            pGraphEventKind, pStartPoint, pEndPoint,
10646:                            affectedObjects);
10647:                    break;
10648:                case IGraphEventKind.GEK_PRE_MOVE:
10649:                    this .onPreMoveObjects(affectedObjects, pStartPoint,
10650:                            pEndPoint, false);
10651:                    break;
10652:                case IGraphEventKind.GEK_POST_MOVE:
10653:                    this .onPostMoveObjects(affectedObjects, pStartPoint,
10654:                            pEndPoint, false);
10655:                    break;
10656:                case IGraphEventKind.GEK_PRE_RESIZE:
10657:                    handlePreResize(affectedObjects);
10658:                    break;
10659:                case IGraphEventKind.GEK_POST_RESIZE:
10660:                    handlePostResize(affectedObjects);
10661:                    break;
10662:                case IGraphEventKind.GEK_PRE_LAYOUT:
10663:                    handlePreLayout(affectedObjects);
10664:                    break;
10665:                case IGraphEventKind.GEK_POST_LAYOUT:
10666:                    handlePostLayout(affectedObjects);
10667:                    break;
10668:                case IGraphEventKind.GEK_POST_DELETE:
10669:                    handleDeleteObject(affectedObjects);
10670:                    break;
10671:                }
10672:            }
10673:
10674:            protected void handlePreResize(
10675:                    ETList<IETGraphObject> affectedObjects) {
10676:                if (getReadOnly()) {
10677:                    return;
10678:                }
10679:                JTrackBar bar = getTrackBar();
10680:                IDiagramEngine engine = getDiagramEngine();
10681:                for (Iterator<IETGraphObject> iter = affectedObjects.iterator(); iter
10682:                        .hasNext();) {
10683:                    boolean handled = false;
10684:                    IETGraphObject graphObj = iter.next();
10685:
10686:                    if (bar != null) {
10687:                        bar.resize(graphObj.getPresentationElement());
10688:                    }
10689:
10690:                    if ((engine != null) && (graphObj instanceof  TSGraphObject)) {
10691:                        handled = engine
10692:                                .onPreResizeObjects((TSGraphObject) graphObj);
10693:                    }
10694:
10695:                    if (!handled) {
10696:                        graphObj.onGraphEvent(IGraphEventKind.GEK_PRE_RESIZE);
10697:                    }
10698:                }
10699:            }
10700:
10701:            protected void handlePreLayout(
10702:                    ETList<IETGraphObject> affectedObjects) {
10703:                if (getReadOnly()) {
10704:                    return;
10705:                }
10706:                for (Iterator<IETGraphObject> iter = affectedObjects.iterator(); iter
10707:                        .hasNext();) {
10708:                    IETGraphObject graphObj = iter.next();
10709:
10710:                    graphObj.onGraphEvent(IGraphEventKind.GEK_PRE_LAYOUT);
10711:                }
10712:            }
10713:
10714:            protected void handlePostLayout(
10715:                    ETList<IETGraphObject> affectedObjects) {
10716:                if (getReadOnly()) {
10717:                    return;
10718:                }
10719:                for (Iterator<IETGraphObject> iter = affectedObjects.iterator(); iter
10720:                        .hasNext();) {
10721:                    IETGraphObject graphObj = iter.next();
10722:
10723:                    graphObj.onGraphEvent(IGraphEventKind.GEK_POST_LAYOUT);
10724:                }
10725:            }
10726:
10727:            protected void handlePostResize(
10728:                    ETList<IETGraphObject> affectedObjects) {
10729:                if (getReadOnly() == false) {
10730:                    JTrackBar bar = getTrackBar();
10731:                    IDiagramEngine engine = getDiagramEngine();
10732:                    for (Iterator<IETGraphObject> iter = affectedObjects
10733:                            .iterator(); iter.hasNext();) {
10734:                        boolean handled = false;
10735:                        IETGraphObject graphObj = iter.next();
10736:
10737:                        if (bar != null) {
10738:                            bar.resize(graphObj.getPresentationElement());
10739:                        }
10740:
10741:                        if ((engine != null)
10742:                                && (graphObj instanceof  TSGraphObject)) {
10743:                            handled = engine
10744:                                    .onPostResizeObjects((TSGraphObject) graphObj);
10745:
10746:                            if (!handled) {
10747:                                graphObj
10748:                                        .onGraphEvent(IGraphEventKind.GEK_POST_RESIZE);
10749:                            }
10750:                        }
10751:                        setIsDirty(true);
10752:                    }
10753:                }
10754:            }
10755:
10756:            protected void handleDeleteObject(
10757:                    ETList<IETGraphObject> affectedObjects) {
10758:                if (affectedObjects != null) {
10759:                    // Empty out the clipboard in case this element is sitting in there
10760:                    clearClipboard();
10761:
10762:                    for (Iterator<IETGraphObject> iter = affectedObjects
10763:                            .iterator(); iter.hasNext();) {
10764:                        IETGraphObject curObject = iter.next();
10765:
10766:                        if (curObject instanceof  ETNode) {
10767:                            ETNode curNode = (ETNode) curObject;
10768:
10769:                            // Notify all the connected edges that they are about to be deleted,
10770:                            // since TS is not sending those edges
10771:                            sendDeleteLinkEvents(curNode.inEdges());
10772:                            sendDeleteLinkEvents(curNode.outEdges());
10773:                        }
10774:
10775:                        IPresentationElement element = TypeConversions
10776:                                .getPresentationElement(curObject);
10777:
10778:                        if ((element != null) && (getTrackBar() != null)) {
10779:                            ((JTrackBar) getTrackBar())
10780:                                    .removePresentationElement(element);
10781:                        }
10782:                    }
10783:
10784:                    setIsDirty(true);
10785:                }
10786:            }
10787:
10788:            protected void sendDeleteLinkEvents(List links) {
10789:                if (links != null) {
10790:                    for (Iterator iter = links.iterator(); iter.hasNext();) {
10791:                        TSObject curEdge = (TSObject) iter.next();
10792:                        sendDeleteLinkEvents(curEdge);
10793:                    }
10794:                }
10795:            }
10796:
10797:            protected void sendDeleteLinkEvents(TSObject link) {
10798:                if (link != null) {
10799:                    IPresentationElement element = TypeConversions
10800:                            .getPresentationElement(link);
10801:                    if (element instanceof  IEdgePresentation) {
10802:                        IEdgePresentation edgePresentation = (IEdgePresentation) element;
10803:                        IETGraphObject edgeObject = TypeConversions
10804:                                .getETGraphObject(edgePresentation);
10805:
10806:                        IDrawEngine fromEngine = TypeConversions
10807:                                .getDrawEngine(edgePresentation
10808:                                        .getFromGraphObject());
10809:                        IEventManager fromManager = fromEngine
10810:                                .getEventManager();
10811:                        if (fromManager != null) {
10812:                            fromManager.onPreDeleteLink(edgeObject, true);
10813:                        }
10814:
10815:                        IDrawEngine toEngine = TypeConversions
10816:                                .getDrawEngine(edgePresentation
10817:                                        .getToGraphObject());
10818:                        IEventManager toManager = toEngine.getEventManager();
10819:                        if (toManager != null) {
10820:                            toManager.onPreDeleteLink(edgeObject, true);
10821:                        }
10822:                    }
10823:                }
10824:            }
10825:
10826:            /**
10827:             * Attaches the TS node to our UML metamodel.  If this is a drag and drop operation then the m_ModelElement will be
10828:             * non-zero.  If this is a drop of a new object then m_ModelElement will be zero.  Depending on the state, Attach or Create
10829:             * is called on the IETElement which this node is implementing.
10830:             */
10831:            public void postAddObject(ITSGraphObject graphObj, boolean resize) {
10832:                if (m_ReadOnly) {
10833:                    postDeletePresentationElement((TSGraphObject) graphObj);
10834:                } else {
10835:                    setIsDirty(true);
10836:
10837:                    // m_bAbortDiagramLoad will be set to TRUE if the
10838:                    // diagram is checked out of SCC and needs to be
10839:                    // closed and reopened.
10840:                    if (m_AbortDiagramLoad) {
10841:                        //            m_isDirty = false;
10842:                        setIsDirty(false);
10843:                    } else if (graphObj != null) {
10844:                        // We have a bridge being added.  Some bridges create other elements so
10845:                        // fire this off to a handler
10846:                        ETElementManager mgr = new ETElementManager(this );
10847:                        mgr
10848:                                .handlePostAddObject((TSGraphObject) graphObj,
10849:                                        false);
10850:                        if (m_DiagramEngine != null) {
10851:                            m_DiagramEngine
10852:                                    .postAddObject((TSGraphObject) graphObj);
10853:                        }
10854:
10855:                        // This flag is used to tell us when we should fire an event because we went from
10856:                        // something selected to nothing selected.  It helps us avoid firing events when the user
10857:                        // clicks on the background with nothing selected.
10858:                        m_ItemsSelected = true;
10859:
10860:                        // Tell the outside world about the create
10861:                        IPresentationElement pPE = TypeConversions
10862:                                .getPresentationElement((TSGraphObject) graphObj);
10863:                        if (pPE != null) {
10864:                            //fireDrawingAreaPresentationElementAction(pPE, PEA_CREATED);
10865:                        }
10866:
10867:                        // Make sure the model element is set for the graphObj.
10868:                        if (graphObj.getETUI() != null) {
10869:                            IElement modelElement = pPE != null ? pPE
10870:                                    .getFirstSubject() : null;
10871:
10872:                            if (modelElement == null) {
10873:                                modelElement = this .getModelElement();
10874:                            }
10875:                            if (modelElement != null) {
10876:                                graphObj.getETUI()
10877:                                        .setModelElement(modelElement);
10878:                            }
10879:                            // Finally init the draw engine.
10880:                            IDrawEngine de = graphObj.getETUI().getDrawEngine();
10881:                            if (de != null) {
10882:                                try {
10883:                                    // If we don't call init here, we have problems with the inplace text editor, drop
10884:                                    // a class then just start typing.
10885:                                    //if (!de.isInitialized())
10886:                                    {
10887:                                        de.init();
10888:                                    }
10889:
10890:                                    if (graphObj instanceof  IETGraphObject) {
10891:                                        IETGraphObject etGraphObj = (IETGraphObject) graphObj;
10892:                                        etGraphObj
10893:                                                .setSynchState(ISynchStateKind.SSK_IN_SYNCH_DEEP);
10894:                                    }
10895:                                } catch (Exception e) {
10896:                                    e.printStackTrace();
10897:                                }
10898:                            }
10899:                        }
10900:                    }
10901:                }
10902:            }
10903:
10904:            /**
10905:             * Fired when something happens on a presentation element (ie doubleclick).
10906:             */
10907:            private void fireDrawingAreaPresentationElementAction(
10908:                    IPresentationElement pPE, int nAction) {
10909:                if (getDrawingAreaDispatcher() != null) {
10910:                    IEventPayload payload = m_drawingAreaDispatcher
10911:                            .createPayload("DrawingAreaPresentationElementAction");
10912:                    IDiagram pDia = getDiagram();
10913:                    if (pDia != null) {
10914:                        //m_drawingAreaDispatcher.fireDrawingAreaPresentationElementAction(pDia, pPE, nAction, payload);
10915:                    }
10916:                }
10917:            }
10918:
10919:            /*
10920:             *
10921:             */
10922:            public String getNodeInitString() {
10923:                return ""; //m_NodeInitString;
10924:            }
10925:
10926:            public String getEdgeInitString() {
10927:                return ""; //m_EdgeInitString;
10928:            }
10929:
10930:            /**
10931:             * A key has been typed.  The diagram is marked as dirty.
10932:             * @param e
10933:             */
10934:            public void keyTyped(KeyEvent e) {
10935:                if (getReadOnly() == false) {
10936:                    if (e.isControlDown()) {
10937:                        if (Character.toUpperCase(e.getKeyChar()) == KeyEvent.VK_S) {
10938:                            //                   setIsDirty(false);
10939:                        }
10940:                    } else {
10941:                        if (!(e.isAltDown() || e.isMetaDown())) {
10942:                            char ch = e.getKeyChar();
10943:                            if ((int) ch != 8 && (int) ch != 127
10944:                                    && (int) ch != 10) {
10945:                                handleCharTyped(e.getKeyChar());
10946:                                //                       setIsDirty(true);
10947:                            }
10948:                        }
10949:                    }
10950:                }
10951:            }
10952:
10953:            public void keyPressed(KeyEvent e) {
10954:                boolean handled = false;
10955:                if (getReadOnly() == false) {
10956:                    //if the key was typed while one of the presentation elements was selected,
10957:                    //we want to go in edit mode, if its not an accelerator key
10958:                    boolean foundAccelKey = false;
10959:
10960:                    // Accelerator keys don't get propagated down, neither do keys
10961:                    // when an accelerator is depressed
10962:                    if (e.isControlDown() || e.isAltDown() || e.isMetaDown()) {
10963:                        foundAccelKey = true;
10964:                    }
10965:
10966:                    int keyCode = e.getKeyCode();
10967:
10968:                    // conover - this is not the right way to map keys: see ADDrawingAreaActions
10969:                    //         // resize node when Alt-Shift-<arrow> is pressed
10970:                    //         if (isArrowKey(keyCode) && e.isAltDown() && e.isShiftDown())
10971:                    //         {
10972:                    //             // System.err.println(" shift up/down pressed! ");
10973:                    //             onHandleResize(keyCode);
10974:                    //         }
10975:                    // In order for the NetBeans Edit | Delete menu to be enabled I have
10976:                    // to use the NetBeans action mechanism.  So, if I andle the Delete Key
10977:                    // here, I will be trying to delete the node twice.  Therefore,
10978:                    // I am not going to handle the keystroke here.  In the future I will
10979:                    // need to make all of the diagram actions NetBeans actions.  That
10980:                    // way they will be able to play in the NetBeans accelerator
10981:                    // mechanism.
10982:                    // else
10983:                    if ((!foundAccelKey) && (keyCode != KeyEvent.VK_DELETE)) {
10984:                        handled = handleKeyDown(keyCode, e.isShiftDown() ? 0
10985:                                : 1, false);
10986:                    } else if (e.isControlDown() && e.isShiftDown()
10987:                            && (e.getKeyCode() == KeyEvent.VK_EQUALS)) {
10988:                        addToSelectedGraphObjectsGroup(m_graphObj);
10989:                        getGraphWindow()
10990:                                .selectGroup(m_selectedNodesGroup, true);
10991:                        handled = true;
10992:                    } else if (e.isControlDown() && e.isShiftDown()
10993:                            && (e.getKeyCode() == KeyEvent.VK_MINUS)) {
10994:                        removeFromSelectedGraphObjectsGroup(m_graphObj);
10995:                        getGraphWindow()
10996:                                .selectGroup(m_selectedNodesGroup, true);
10997:                        handled = true;
10998:                    }
10999:                }
11000:            }
11001:
11002:            public void keyReleased(KeyEvent e) {
11003:                if (getReadOnly() == false) {
11004:                    if (getTrackBar() != null) {
11005:                        getTrackBar().onKeyUp(e);
11006:                    }
11007:                }
11008:
11009:                int keyCode = e.getKeyCode();
11010:                if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT
11011:                        || keyCode == KeyEvent.VK_UP
11012:                        || keyCode == KeyEvent.VK_DOWN) {
11013:                    if (e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK) {
11014:                        getActions().onPostMoveObjects();
11015:                    }
11016:                }
11017:            }
11018:
11019:            protected void onHandleCancel() {
11020:                // exit element creation mode and reset cursor to "selection arrow"
11021:                switchToDefaultState();
11022:
11023:                // and refresh the palette so that the selected tool gets unselected
11024:                setSelectStateOnPalette();
11025:
11026:                // reset some members
11027:                if (tempList != null) {
11028:                    tempList.clear();
11029:                }
11030:
11031:                m_lastSelectedNode = null;
11032:                m_lastSelectedLabel = null;
11033:
11034:                clearSelectedNodesGroup();
11035:
11036:                // Deselect all selected compartments.
11037:                setSelectedCompartments(false);
11038:
11039:                // Remove the select state from all objects.
11040:                getGraphWindow().deselectAll(true);
11041:
11042:                refresh(true);
11043:                // Need to fire a selectedEvent with no selected object to
11044:                // get the property sheet default to the diagram itselt
11045:                ETList<TSGraphObject> selectedObjects = null;
11046:                this .fireSelectEvent(selectedObjects);
11047:            }
11048:
11049:            protected void onHandleResize(int resizeCommand) {
11050:                double wide = 0D;
11051:                double tall = 0D;
11052:
11053:                switch (resizeCommand) {
11054:                // make it wider
11055:                case ADDrawingAreaConstants.NODE_RESIZE_WIDER_CMD:
11056:                    wide = 5D;
11057:                    break;
11058:                // make it thinner
11059:                case ADDrawingAreaConstants.NODE_RESIZE_THINNER_CMD:
11060:                    wide = -5D;
11061:                    break;
11062:                // make it taller
11063:                case ADDrawingAreaConstants.NODE_RESIZE_TALLER_CMD:
11064:                    tall = 5D;
11065:                    break;
11066:                // make it shorter
11067:                case ADDrawingAreaConstants.NODE_RESIZE_SHORTER_CMD:
11068:                    tall = -5D;
11069:                    break;
11070:                default:
11071:                    return;
11072:                }
11073:
11074:                ETList<IETGraphObject> graphObjects = null;
11075:                graphObjects = getSelectedNodes();
11076:
11077:                if (graphObjects == null) {
11078:                    return;
11079:                }
11080:                for (IETGraphObject graphObj : graphObjects) {
11081:                    if (graphObj != null && graphObj instanceof  IETNode) {
11082:                        ETNode etNode = (ETNode) graphObj;
11083:
11084:                        INodePresentation nodePres = (INodePresentation) etNode
11085:                                .getPresentationElement();
11086:
11087:                        TSENode tsNode = nodePres.getTSNode();
11088:
11089:                        // if not change width, then skip setting the width
11090:                        if (wide != 0) {
11091:                            double curwidth = tsNode.getWidth();
11092:
11093:                            // prevent setting width less than 5
11094:                            if ((curwidth + wide) >= 5) {
11095:                                tsNode.setWidth(curwidth + wide);
11096:                            } else // if width is already 5, do nothing
11097:                            if (curwidth != 5) {
11098:                                tsNode.setWidth(5D);
11099:                            }
11100:                        } else if (tall != 0) {
11101:                            double curheight = tsNode.getHeight();
11102:
11103:                            // prevent setting height less than 5
11104:                            if ((curheight + tall) >= 5) {
11105:                                tsNode.setHeight(curheight + tall);
11106:                            } else // if height is already 5, do nothing
11107:                            if (curheight != 5) {
11108:                                tsNode.setHeight(5D);
11109:                            }
11110:                        }
11111:                    }
11112:                }
11113:
11114:                // need to call refresh here because the drawing are does not refresh
11115:                // properly when the newly sized node is smaller than the original size
11116:                refresh(true);
11117:            }
11118:
11119:            /**
11120:             * Listen to the mouse wheel events.  Scrolls the window when the user moves
11121:             * the mouse wheel.  If the user also has the control key pressed then the
11122:             * zoom will be affected.
11123:             */
11124:            public void mouseWheelMoved(MouseWheelEvent e) {
11125:                if ((e.getModifiersEx() & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK) {
11126:                    // I want the scrolling of the mouse wheel to zoom in and the
11127:                    // down scroll to zoom out.
11128:                    double newZoomFactor = -e.getWheelRotation() * 0.1;
11129:                    getGraphWindow().zoom(newZoomFactor, true);
11130:                } else {
11131:                    int unitsToScroll = 1;
11132:                    if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
11133:                        unitsToScroll = e.getUnitsToScroll() * 10;
11134:                    } else {
11135:                    }
11136:
11137:                    getGraphWindow().scrollBy(0, unitsToScroll, true);
11138:                }
11139:                //      int rotation = e.getWheelRotation();
11140:            }
11141:
11142:            //public void finalize()
11143:            //{
11144:            //   	super.finalize();
11145:            // }
11146:
11147:            //public class GraphChangeListener implements TSEGraphChangeListener
11148:            public class MyGraphChangeListener implements  TSGraphChangeListener {
11149:
11150:                public void graphChanged(TSGraphChangeEvent event) {
11151:                    long eventType = event.getType();
11152:                    if (eventType == TSGraphChangeEvent.NODE_REMOVED
11153:                            || eventType == TSGraphChangeEvent.NODE_DISCARDED) {
11154:                        ETList<IETGraphObject> deletedObject = new ETArrayList<IETGraphObject>();
11155:
11156:                        TSGraphChangeEventData data = (TSGraphChangeEventData) event
11157:                                .getData();
11158:                        Object obj = data.getSource();
11159:                        if (obj instanceof  TSObject) {
11160:                            deletedObject.add(TypeConversions
11161:                                    .getETGraphObject((TSObject) obj));
11162:                            onGraphEvent(IGraphEventKind.GEK_POST_DELETE, null,
11163:                                    null, deletedObject);
11164:                        }
11165:                    }
11166:                }
11167:            }
11168:
11169:            public class SelectionChangeListener implements 
11170:                    TSESelectionChangeListener {
11171:
11172:                public void selectionChanged(TSESelectionChangeEvent event) {
11173:                    //           Debug.out.println(" ADDrawingAreaControl : SelectionChangeListener class : selectionChanged -- in selectionChanged ");
11174:                }
11175:            }
11176:
11177:            //JM: added this to listen to zoom events
11178:            public class ViewportChangeListener implements 
11179:                    TSEViewportChangeListener {
11180:
11181:                public void viewportChanged(TSEViewportChangeEvent event) {
11182:                    //           Debug.out.println(" !!!!!!!!!!!!ADDrawingAreaControl : ViewportChangeListener class : viewportChanged -- in viewportChanged ");
11183:                    if ((event.getType() == TSEViewportChangeEvent.ZOOM)
11184:                            || (event.getType() == TSEViewportChangeEvent.PAN)) {
11185:                        JTrackBar bar = (JTrackBar) getTrackBar();
11186:                        if (bar != null) {
11187:                            bar.onPostScrollZoom();
11188:                        }
11189:                        fireDrawingAreaPropertyChange(IDrawingAreaPropertyKind.DAPK_ZOOM);
11190:                    }
11191:                }
11192:            }
11193:
11194:            protected String splitNodeViewDescription(String desc) {
11195:                return m_NodeInitializationString.splitViewDescription(desc);
11196:            }
11197:
11198:            protected String splitEdgeViewDescription(String desc) {
11199:                return m_EdgeInitializationString.splitViewDescription(desc);
11200:            }
11201:
11202:            // IDrawingPropertyProvider
11203:            public ETList<IDrawingProperty> getDrawingProperties() {
11204:                ETList<IDrawingProperty> pProperties = null;
11205:
11206:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11207:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11208:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11209:                if (pMgr != null && pProvider != null) {
11210:                    pProperties = pMgr.getDrawingProperties(pProvider);
11211:                }
11212:
11213:                return pProperties;
11214:            }
11215:
11216:            public void saveColor(String sDrawEngineType, String sResourceName,
11217:                    int nColor) {
11218:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11219:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11220:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11221:                if (pMgr != null && pProvider != null) {
11222:                    setIsDirty(true);
11223:                    pMgr.saveColor(sDrawEngineType, sResourceName, nColor);
11224:                }
11225:            }
11226:
11227:            public void saveColor2(IColorProperty pProperty) {
11228:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11229:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11230:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11231:                if (pMgr != null && pProvider != null) {
11232:                    setIsDirty(true);
11233:                    pMgr.saveColor2(pProperty);
11234:                }
11235:            }
11236:
11237:            public void saveFont(String sDrawEngineName, String sResourceName,
11238:                    String sFaceName, int nHeight, int nWeight,
11239:                    boolean bItalic, int nColor) {
11240:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11241:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11242:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11243:                if (pMgr != null && pProvider != null) {
11244:                    setIsDirty(true);
11245:                    pMgr.saveFont(sDrawEngineName, sResourceName, sFaceName,
11246:                            nHeight, nWeight, bItalic, nColor);
11247:                }
11248:            }
11249:
11250:            public void saveFont2(IFontProperty pProperty) {
11251:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11252:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11253:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11254:                if (pMgr != null && pProvider != null) {
11255:                    setIsDirty(true);
11256:                    pMgr.saveFont2(pProperty);
11257:                }
11258:            }
11259:
11260:            public void resetToDefaultResource(String sDrawEngineName,
11261:                    String sResourceName, String sResourceType) {
11262:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11263:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11264:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11265:                if (pMgr != null && pProvider != null) {
11266:                    setIsDirty(true);
11267:                    pMgr.resetToDefaultResource(sDrawEngineName, sResourceName,
11268:                            sResourceType);
11269:                    refresh(false);
11270:                }
11271:            }
11272:
11273:            public void resetToDefaultResources() {
11274:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11275:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11276:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11277:                if (pMgr != null && pProvider != null) {
11278:                    setIsDirty(true);
11279:                    pMgr.resetToDefaultResources();
11280:
11281:                    ETList<IPresentationElement> pPresentationElements = getAllItems();
11282:                    int numItems = 0;
11283:                    if (pPresentationElements != null) {
11284:                        numItems = pPresentationElements.size();
11285:                    }
11286:                    for (int i = 0; i < numItems; i++) {
11287:                        IPresentationElement pThisPE = pPresentationElements
11288:                                .get(i);
11289:                        IDrawEngine pDrawEngine = TypeConversions
11290:                                .getDrawEngine(pThisPE);
11291:
11292:                        IDrawingPropertyProvider pProvider1 = (IDrawingPropertyProvider) pDrawEngine;
11293:                        if (pProvider1 != null) {
11294:                            pProvider1.resetToDefaultResources();
11295:
11296:                            // Now size to contents if we need to
11297:                            if (pThisPE instanceof  INodePresentation) {
11298:                                INodePresentation pNodePE = (INodePresentation) pThisPE;
11299:                                pNodePE.sizeToContents();
11300:                            } else {
11301:                                // Now size to contents if we need to
11302:                                if (pThisPE instanceof  ILabelPresentation) {
11303:                                    ILabelPresentation pLabelPE = (ILabelPresentation) pThisPE;
11304:                                    //pLabelPE.sizeToContents();
11305:                                }
11306:                            }
11307:                        }
11308:                    }
11309:
11310:                    refresh(false);
11311:                }
11312:            }
11313:
11314:            public void resetToDefaultResources2(String sDrawEngineName) {
11315:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11316:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11317:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11318:                if (pMgr != null && pProvider != null) {
11319:                    setIsDirty(true);
11320:                    pMgr.resetToDefaultResources2(sDrawEngineName);
11321:
11322:                    ETList<IPresentationElement> pPresentationElements = getAllItems();
11323:                    int numItems = 0;
11324:                    if (pPresentationElements != null) {
11325:                        numItems = pPresentationElements.size();
11326:                    }
11327:                    for (int i = 0; i < numItems; i++) {
11328:                        IPresentationElement pThisPE = pPresentationElements
11329:                                .get(i);
11330:                        IDrawEngine pDrawEngine = TypeConversions
11331:                                .getDrawEngine(pThisPE);
11332:
11333:                        IDrawingPropertyProvider pProvider1 = (IDrawingPropertyProvider) pDrawEngine;
11334:                        if (pProvider1 != null) {
11335:                            pProvider1.resetToDefaultResources();
11336:
11337:                            // Now size to contents if we need to
11338:                            INodePresentation pNodePE = (INodePresentation) pThisPE;
11339:                            if (pNodePE != null) {
11340:                                pNodePE.sizeToContents();
11341:                            }
11342:                        }
11343:                    }
11344:
11345:                    refresh(false);
11346:                }
11347:            }
11348:
11349:            public void dumpToFile(String sFile, boolean bDumpChildren,
11350:                    boolean bAppendToExistingFile) {
11351:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11352:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11353:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11354:                if (pMgr != null && pProvider != null) {
11355:                    setIsDirty(true);
11356:                    pMgr.dumpToFile(sFile, bAppendToExistingFile);
11357:
11358:                    if (bDumpChildren) {
11359:                        ETList<IPresentationElement> pPresentationElements = getAllItems();
11360:                        int numItems = 0;
11361:                        if (pPresentationElements != null) {
11362:                            numItems = pPresentationElements.size();
11363:                        }
11364:
11365:                        for (int i = 0; i < numItems; i++) {
11366:                            IPresentationElement pThisPE = pPresentationElements
11367:                                    .get(i);
11368:                            IProductGraphPresentation pGraphPE = (IProductGraphPresentation) pThisPE;
11369:                            if (pGraphPE != null) {
11370:                                IDrawEngine pEngine = pGraphPE.getDrawEngine();
11371:                                IDrawingPropertyProvider pProvider1 = (IDrawingPropertyProvider) pEngine;
11372:                                if (pProvider1 != null) {
11373:                                    pProvider1.dumpToFile(sFile, true, true);
11374:                                }
11375:                            }
11376:                        }
11377:                    }
11378:                }
11379:            }
11380:
11381:            public boolean displayFontDialog(IFontProperty pProperty) {
11382:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11383:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11384:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11385:                if (pMgr != null && pProvider != null) {
11386:                    setIsDirty(true);
11387:                    return pMgr.displayFontDialog(pProperty);
11388:                } else {
11389:                    return false;
11390:                }
11391:            }
11392:
11393:            public boolean displayColorDialog(IColorProperty pProperty) {
11394:                IDrawingAreaControl pAxDrawingArea = (IDrawingAreaControl) this ;
11395:                IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) this ;
11396:                ResourceMgr pMgr = ResourceMgr.instance(pAxDrawingArea);
11397:                if (pMgr != null && pProvider != null) {
11398:                    setIsDirty(true);
11399:                    return pMgr.displayColorDialog(pProperty);
11400:                } else {
11401:                    return false;
11402:                }
11403:            }
11404:
11405:            public void invalidateProvider() {
11406:                refresh(true);
11407:            }
11408:
11409:            /*
11410:             * Executes the Relationship Disovery Command.
11411:             */
11412:            public void executeRelationshipDiscovery() {
11413:                ISimpleElementsAction action = new SimpleElementsAction();
11414:                if (action != null) {
11415:                    ETList<IElement> pAllFirstSubjects = getSelected4();
11416:                    action
11417:                            .setKind(ISimpleElementsAction.SEAK.DISCOVER_RELATIONSHIPS);
11418:                    action.setElements(pAllFirstSubjects);
11419:                    postDelayedAction(action);
11420:                }
11421:            }
11422:
11423:            public JToolBar getToolbar() {
11424:                createToolbars();
11425:                return mainToolBar;
11426:            }
11427:
11428:            public void setShowDefaultToolbar(boolean bShow) {
11429:                m_showToolbars = bShow;
11430:            }
11431:
11432:            /**
11433:             * Fired after a paste operation occurs
11434:             */
11435:            public void onPostPaste(TSGraphObject pastedToObject,
11436:                    List nodeList, List edgeList, List nodeLabelList,
11437:                    List edgeLabelList, boolean handled) {
11438:                ETElementManager manager = new ETElementManager(this );
11439:                manager.onPostPaste(nodeList, edgeList, nodeLabelList,
11440:                        edgeLabelList);
11441:
11442:                setIsDirty(true);
11443:                //clear the last selected node after paste to continue tab-traversal
11444:                m_lastSelectedNode = null;
11445:                m_lastSelectedLabel = null;
11446:            }
11447:
11448:            /*
11449:             *
11450:             * @author KevinM
11451:             *
11452:             * Listens for visibility changes on this component, it hides or display???s the secondary windows.
11453:             *
11454:             */
11455:            protected class DrawingVisibilityListener implements 
11456:                    ComponentListener {
11457:
11458:                class SecondaryWindowVisibility extends Object {
11459:
11460:                    public boolean overviewVisible;
11461:                    public boolean drawingPropertiesVisible;
11462:                    public boolean layoutPropertiesVisible;
11463:                }
11464:
11465:                {
11466:                }
11467:
11468:                /**
11469:                 * Invoked when the component's size changes.
11470:                 */
11471:                public void componentResized(ComponentEvent e) {
11472:                }
11473:
11474:                /**
11475:                 * Invoked when the component's position changes.
11476:                 */
11477:                public void componentMoved(ComponentEvent e) {
11478:                }
11479:
11480:                /**
11481:                 * Invoked when the component has been made visible.
11482:                 */
11483:                public void componentShown(ComponentEvent e) {
11484:                    ETSystem.out.println("componentShown");
11485:                    restoreSecondaryWindows();
11486:                }
11487:
11488:                /**
11489:                 * Invoked when the component has been made invisible.
11490:                 */
11491:                public void componentHidden(ComponentEvent e) {
11492:                    ETSystem.out.println("componentHidden");
11493:                    populateVisibityData();
11494:                    closeAllSecondaryWindows();
11495:                }
11496:
11497:                /*
11498:                 * Saves the window state for each Secondary window.
11499:                 */
11500:                protected void populateVisibityData() {
11501:                    if (visibilityData == null) {
11502:                        visibilityData = new SecondaryWindowVisibility();
11503:                        visibilityData.overviewVisible = isOverviewWindowOpen();
11504:                        visibilityData.drawingPropertiesVisible = getIsGraphPreferencesDialogOpen();
11505:                        visibilityData.layoutPropertiesVisible = getIsLayoutPropertiesDialogOpen();
11506:                    }
11507:                }
11508:
11509:                /*
11510:                 * Restores the secondary windows if they were visible before this component was hidden.
11511:                 */
11512:                protected void restoreSecondaryWindows() {
11513:                    if (visibilityData != null) {
11514:                        overviewWindow(visibilityData.overviewVisible);
11515:                        graphPreferencesDialog(visibilityData.drawingPropertiesVisible);
11516:                        layoutPropertiesDialog(visibilityData.layoutPropertiesVisible);
11517:                        visibilityData = null;
11518:                    }
11519:                }
11520:
11521:                protected SecondaryWindowVisibility visibilityData = null;
11522:            }
11523:
11524:            /*
11525:             * Registers for ComponentListener events.
11526:             */
11527:            public void addComponetListeners() {
11528:                this .addComponentListener(new DrawingVisibilityListener());
11529:            }
11530:
11531:            /**
11532:             * Fired before any nodes,edges or labels are moved
11533:             *
11534:             * This routine is responsible for notifying the objects that are about to be moved about that fact.  The
11535:             * notification comes through the IETElement interface.
11536:             */
11537:            protected void onPreMoveObjects(
11538:                    ETList<IETGraphObject> affectedObjects,
11539:                    IETPoint pStartPoint, IETPoint pEndPoint, boolean handled) {
11540:                // Return if we're blocked
11541:                if (UserInputBlocker.getIsDisabled(GBK.DIAGRAM_MOVEMENT)
11542:                        && handled) {
11543:                    handled = true;
11544:                    return;
11545:                }
11546:
11547:                if (this .m_ReadOnly) {
11548:                    handled = true;
11549:                    return;
11550:                }
11551:
11552:                // In case the object is moved by keyboard, there are no mouse points.
11553:                // In that case, x interval and y interval are set to zero.
11554:                int xInterval = 0;
11555:                int yInterval = 0;
11556:
11557:                if (pStartPoint != null && pEndPoint != null) {
11558:                    xInterval = pEndPoint.getX() - pStartPoint.getX();
11559:                    yInterval = pEndPoint.getY() - pStartPoint.getY();
11560:                }
11561:
11562:                // Notify the engine
11563:                if (m_DiagramEngine != null) {
11564:                    m_DiagramEngine.onPreMoveObjects(affectedObjects,
11565:                            xInterval, yInterval);
11566:                }
11567:
11568:                if (handled == false) {
11569:                    ETElementManager manager = new ETElementManager(this );
11570:
11571:                    ETList<IPresentationElement> pTempSelectedList = new ETArrayList<IPresentationElement>();
11572:
11573:                    pTempSelectedList = GetHelper.addToPresentationElements(
11574:                            affectedObjects, pTempSelectedList);
11575:                    manager.onPreMove(pTempSelectedList);
11576:                }
11577:            }
11578:
11579:            /**
11580:             * Fired after any nodes, edges, or labels are moved
11581:             *
11582:             * This routine is responsible for two things.
11583:             * 1.  Notify the track bar, if there is one about the move so it can update the cars.
11584:             * 2.  Notify the objects being moved that is is about to be moved.  Do this through the IETElement interfaces.
11585:             *
11586:             * @param nodeList [in] A list of nodes that were moved
11587:             * @param edgeList [in] A list of edges that were moved
11588:             * @param labelList [in] A list of labels that were moved
11589:             * @param dx [in] The x location of the cursor
11590:             * @param dy [in] The y location of the cursor
11591:             * @param handled [out] Set to VARIANT_TRUE to cancel the move
11592:             */
11593:            protected void onPostMoveObjects(
11594:                    ETList<IETGraphObject> affectedObjects,
11595:                    IETPoint pStartPoint, IETPoint pEndPoint, boolean handled) {
11596:
11597:                ETList<IPresentationElement> pTempSelectedList = new ETArrayList<IPresentationElement>();
11598:                pTempSelectedList = GetHelper.addToPresentationElements(
11599:                        affectedObjects, pTempSelectedList);
11600:
11601:                // First tell the trackbar that stuff has moved
11602:                if (getTrackBar() != null && pStartPoint != null
11603:                        && pEndPoint != null) {
11604:                    getTrackBar().moveObjects(
11605:                            buildPresentationList(affectedObjects),
11606:                            pEndPoint.getX() - pStartPoint.getX());
11607:                }
11608:                if (handled == false) {
11609:                    // In case the object is moved by keyboard, there are no mouse points.
11610:                    // In that case, x interval and y interval are set to zero.
11611:                    int xInterval = 0;
11612:                    int yInterval = 0;
11613:
11614:                    if (pStartPoint != null && pEndPoint != null) {
11615:                        xInterval = pEndPoint.getX() - pStartPoint.getX();
11616:                        yInterval = pEndPoint.getY() - pStartPoint.getY();
11617:                    }
11618:
11619:                    // Originally I tried to send the product element the OnPostResize event here.  But
11620:                    // if the product element does anything with connectors (ie deleting them) then
11621:                    // TS crashed.  So I figure this is a bad place to be making those changes.  Instead
11622:                    // we post event to handle it in a better spot.
11623:                    PostMoveDetails pDetails = new PostMoveDetails(
11624:                            pTempSelectedList, xInterval, yInterval);
11625:                    this .onHandlePostMove(pDetails);
11626:                }
11627:                setIsDirty(true);
11628:            }
11629:
11630:            /**
11631:             * Originally I tried to send the product element the OnPostMove event from TS.  But
11632:             * if the product element does anything with connectors (ie deleting them) then
11633:             * TS crashed.  So I figure this is a bad place to be making those changes.  Instead
11634:             * we post event to handle it in a better spot.  This routine handles the post message.
11635:             */
11636:            protected void onHandlePostMove(PostMoveDetails pDetails) {
11637:                if (pDetails != null) {
11638:                    ETElementManager manager = new ETElementManager(this );
11639:
11640:                    manager.onPostMove(pDetails.m_PresentationElements);
11641:
11642:                    // Notify the engine
11643:                    if (m_DiagramEngine != null) {
11644:                        m_DiagramEngine.delayedPostMoveObjects(
11645:                                pDetails.m_PresentationElements, pDetails.m_dx,
11646:                                pDetails.m_dy);
11647:                    }
11648:
11649:                    //delete pDetails;
11650:                }
11651:            }
11652:
11653:            // This interior class is used to store presentation elements that have been moved.  During
11654:            // post move TS has not yet layed out the edges so any edge calculations are wrong!  We delay
11655:            // sending out postmoves to our IETElements through this class and a windows message
11656:            private class PostMoveDetails {
11657:
11658:                ETList<IPresentationElement> m_PresentationElements = null;
11659:                int m_dx;
11660:                int m_dy;
11661:
11662:                public PostMoveDetails(
11663:                        ETList<IPresentationElement> pPresentationElements,
11664:                        int dx, int dy) {
11665:                    m_PresentationElements = pPresentationElements;
11666:                    m_dx = dx;
11667:                    m_dy = dy;
11668:                }
11669:            }
11670:
11671:            /**
11672:             * Returns true if any of the TS objects in the input collection are associated with the input class type
11673:             */
11674:            protected boolean containsModelElement(Collection list,
11675:                    Class interfacetype) {
11676:                boolean containsModelElement = false;
11677:
11678:                if (list.size() > 0) {
11679:                    for (Iterator iter = list.iterator(); iter.hasNext();) {
11680:                        TSObject object = (TSObject) iter.next();
11681:
11682:                        IElement element = TypeConversions.getElement(object);
11683:                        if (element != null
11684:                                && interfacetype.isAssignableFrom(element
11685:                                        .getClass())) {
11686:                            containsModelElement = true;
11687:                            break;
11688:                        }
11689:                    }
11690:                }
11691:
11692:                return containsModelElement;
11693:            }
11694:
11695:            /**
11696:             * Adds any message labels associated with message connector edges
11697:             */
11698:            protected void selectMessageConnectorMessages(
11699:                    ETList<TSEEdge> redgeVector,
11700:                    ETList<TSEEdgeLabel> redgeLabelVector) {
11701:                if (redgeVector.size() > 0) {
11702:                    for (int i = 0; i < redgeVector.size(); i++) {
11703:                        IElement element = TypeConversions
11704:                                .getElement(redgeVector.get(i));
11705:                        if (element instanceof  IMessageConnector) {
11706:                            ETEdge edge = (ETEdge) redgeVector.get(i);
11707:                            ETList<IETLabel> pLabelList = edge.getLabels();
11708:                            if (pLabelList != null) {
11709:                                for (int index = 0; index < pLabelList.size(); index++) {
11710:                                    TSEEdgeLabel pLabel = (TSEEdgeLabel) (pLabelList
11711:                                            .get(index));
11712:                                    if (pLabel != null) {
11713:                                        redgeLabelVector.add(pLabel);
11714:                                    }
11715:                                }
11716:                            }
11717:                        }
11718:                    }
11719:
11720:                    // Fix W7815:  Remove any duplicate edge labels, because the edge's label may also have been selected
11721:                    for (int j = redgeLabelVector.size() - 1; j >= 0; j--) {
11722:                        TSEEdgeLabel pLabel = redgeLabelVector.get(j);
11723:                        for (int k = 0; k < j; k++) {
11724:                            if (redgeLabelVector.get(j).equals(pLabel)) {
11725:                                redgeLabelVector.remove(pLabel);
11726:                                break;
11727:                            }
11728:                        }
11729:                    }
11730:                }
11731:            }
11732:
11733:            /*
11734:             * Set when the diagrma is creating itself from selected elements.
11735:             */
11736:            public void setPopulating(boolean busy) {
11737:                populating = busy;
11738:            }
11739:
11740:            /*
11741:             * Returns if the is busy populating
11742:             */
11743:            public boolean getPopulating() {
11744:                return populating || !getGraphWindow().getAllowRedraw();
11745:            }
11746:
11747:            /**
11748:             * Adds any message edges contained inside any of the nodes that are combined fragments
11749:             */
11750:            protected void selectCombinedFragmentMessages(
11751:                    ETArrayList<TSENode> nodes) {
11752:                if (nodes.size() > 0) {
11753:                    for (Iterator iter = nodes.iterator(); iter.hasNext();) {
11754:                        TSENode tseNode = (TSENode) iter.next();
11755:
11756:                        IElement element = TypeConversions.getElement(tseNode);
11757:                        if (element instanceof  ICombinedFragment) {
11758:                            ICombinedFragment combinedFragment = (ICombinedFragment) element;
11759:
11760:                            IDrawEngine drawEngine = TypeConversions
11761:                                    .getDrawEngine(tseNode);
11762:                            if (drawEngine != null) {
11763:                                IETRect etRect = drawEngine
11764:                                        .getLogicalBoundingRect(false);
11765:                                if (etRect != null) {
11766:                                    ETList<IPresentationElement> pes = getAllEdgesViaRect(
11767:                                            etRect, false);
11768:                                    if (pes != null) {
11769:                                        for (Iterator iterator = pes.iterator(); iterator
11770:                                                .hasNext();) {
11771:                                            IPresentationElement pe = (IPresentationElement) iterator
11772:                                                    .next();
11773:
11774:                                            IElement innerElement = TypeConversions
11775:                                                    .getElement(pe);
11776:                                            if (innerElement instanceof  IMessage) {
11777:                                                IMessage message = (IMessage) innerElement;
11778:
11779:                                                // We can't simply select the edges,
11780:                                                // because the lifeline pieces don't get deleted
11781:                                                message.delete();
11782:                                            }
11783:                                        }
11784:                                    }
11785:                                }
11786:                            }
11787:                        }
11788:                    }
11789:                }
11790:            }
11791:
11792:            /**
11793:             * SCC notification.  We use this to see if this diagram got checked in/out
11794:             *
11795:             * @param kind [in] The kind of action that was performed (ie FK_CHECK_OUT)
11796:             * @param files [in] A list of files that were acted upon.
11797:             */
11798:            public void onFeatureExecuted(int kind, ISCMItemGroup files) {
11799:                String originalFilename = m_FileName;
11800:                String tempETLFilename = FileSysManip.ensureExtension(
11801:                        originalFilename, FileExtensions.DIAGRAM_LAYOUT_EXT);
11802:                String tempETLPFilename = FileSysManip.ensureExtension(
11803:                        originalFilename,
11804:                        FileExtensions.DIAGRAM_PRESENTATION_EXT);
11805:
11806:                if (kind == SCMFeatureKind.FK_GET_LATEST_VERSION
11807:                        || kind == SCMFeatureKind.FK_CHECK_IN
11808:                        || kind == SCMFeatureKind.FK_CHECK_OUT
11809:                        || kind == SCMFeatureKind.FK_UNDO_CHECK_OUT
11810:                        || kind == SCMFeatureKind.FK_ADD_TO_SOURCE_CONTROL) {
11811:                    boolean this DiagramWasAffected = false;
11812:                    int count = files.getCount();
11813:                    for (int index = 0; index < count; index++) {
11814:                        ISCMItem this Item = files.item(index);
11815:                        if (this Item instanceof  ISCMDiagramItem) {
11816:                            ISCMDiagramItem diagramItem = (ISCMDiagramItem) this Item;
11817:                            String layoutFile = diagramItem.getLayoutFile();
11818:
11819:                            if ((layoutFile != null)
11820:                                    && (layoutFile.length() > 0)) {
11821:                                if ((layoutFile
11822:                                        .equalsIgnoreCase(tempETLFilename) == true)
11823:                                        || (layoutFile
11824:                                                .equalsIgnoreCase(tempETLPFilename) == true)) {
11825:                                    this DiagramWasAffected = true;
11826:                                }
11827:                            }
11828:                        }
11829:                    }
11830:
11831:                    if (this DiagramWasAffected == true) {
11832:                        recalculateCRCs();
11833:                    }
11834:                }
11835:            }
11836:
11837:            /**
11838:             * Re-establishes the link between the model element and presentation elements.  This is called
11839:             * in response to a ExternalElementLoaded event where SCC moves the IElement from one DOM to another,
11840:             * in doing so it deletes all the presentation element data from the IElement.  We need to go through
11841:             * our presentation elements and reattach them.
11842:             *
11843:             * @param pVerElement  The element whose presentation elements should be re-established.
11844:             */
11845:            public void reestablishPresentationElementOwnership(
11846:                    IVersionableElement pVerElement) {
11847:                if (pVerElement != null) {
11848:                    ISimpleElementsAction pAction = new SimpleElementsAction();
11849:                    if (pVerElement instanceof  IElement) {
11850:                        pAction.add((IElement) pVerElement);
11851:                        pAction.setKind(SEAK.RECONNECT_PRESENTATION_ELEMENTS);
11852:                        postDelayedAction(pAction);
11853:                    }
11854:                }
11855:            }
11856:
11857:            private IDrawingAreaSelectStateEnteredSink drawingAreaSelectStateEnteredSink;
11858:
11859:            /** This method removes any selections on the palette.
11860:             *  This is used when the user right clicks on the canvas
11861:             *  or press the ESC key or selects a button on the toolbar
11862:             *  which sets the state of the graph window to select
11863:             */
11864:            public void setSelectStateOnPalette() {
11865:                if (drawingAreaSelectStateEnteredSink != null) {
11866:                    drawingAreaSelectStateEnteredSink.onSelectToolSelected();
11867:                    //reset the selected button
11868:                    this .setSelectedPaletteButton(null);
11869:                }
11870:            }
11871:
11872:            public void addDrawingAreaToolSelectionSink(
11873:                    IDrawingAreaSelectStateEnteredSink listener) {
11874:                this .drawingAreaSelectStateEnteredSink = listener;
11875:            }
11876:
11877:            public IDrawingAreaSelectStateEnteredSink getDrawingAreaSelectStateEnteredSink() {
11878:                return drawingAreaSelectStateEnteredSink;
11879:            }
11880:
11881:            //JM:
11882:            /**
11883:             * This method returns the service input data associated with the
11884:             * specified graph manager of the graph window.
11885:             */
11886:            public TSEAllOptionsServiceInputData getServiceInputData(
11887:                    TSEGraphWindow graphWindow) {
11888:                TSEAllOptionsServiceInputData result = null;
11889:
11890:                if (graphWindow != null) {
11891:                    result = this .getServiceInputData(graphWindow
11892:                            .getGraphManager());
11893:                }
11894:
11895:                return result;
11896:            }
11897:
11898:            /**
11899:             * This method returns the service input data associated with the
11900:             * specified graph manager.
11901:             */
11902:            public TSEAllOptionsServiceInputData getServiceInputData(
11903:                    TSEGraphManager graphManager) {
11904:                TSEAllOptionsServiceInputData result = null;
11905:
11906:                if (this .getGraphWindow() != null) {
11907:                    if (this .serviceInputDataTable.containsKey(graphManager)) {
11908:                        result = (TSEAllOptionsServiceInputData) this .serviceInputDataTable
11909:                                .get(graphManager);
11910:                    } else {
11911:                        result = new TSEAllOptionsServiceInputData(graphManager);
11912:                        this .serviceInputDataTable.put(graphManager, result);
11913:                        TSLayoutInputTailor tailor = new TSLayoutInputTailor(
11914:                                result);
11915:                        tailor.setGraphManager(graphManager);
11916:                    }
11917:                }
11918:
11919:                return result;
11920:            }
11921:
11922:            private void addToSelectedGraphObjectsGroup(IETGraphObject obj) {
11923:                if ((obj != null) && (m_selectedNodesGroup != null)
11924:                        && (!m_selectedNodesGroup.contains(obj))) {
11925:                    m_selectedNodesGroup.add(obj);
11926:                }
11927:            }
11928:
11929:            private void removeFromSelectedGraphObjectsGroup(IETGraphObject obj) {
11930:                if ((obj != null) && (m_selectedNodesGroup.contains(obj))) {
11931:                    m_selectedNodesGroup.remove(obj);
11932:                }
11933:            }
11934:
11935:            public List getSelectedNodesGroup() {
11936:                return m_selectedNodesGroup;
11937:            }
11938:
11939:            private void clearSelectedNodesGroup() {
11940:                m_selectedNodesGroup.clear();
11941:            }
11942:
11943:            private void printSelectedNodesGroup() {
11944:                if (m_selectedNodesGroup != null) {
11945:                    System.err.println(" m_selectedNodesGroup size = "
11946:                            + m_selectedNodesGroup.size());
11947:                }
11948:                System.err.println("group = " + m_selectedNodesGroup);
11949:            }
11950:
11951:            //   public IETPoint getCenterPoint()
11952:            //   {
11953:            //        return new ETPoint(
11954:            //            (int)getLogicalViewPortRect().getCenterX(),
11955:            //            (int)getLogicalViewPortRect().getCenterY());
11956:            //   }
11957:
11958:            //    public ArrayList<ETNode> addNodeToCenter(ArrayList<IElement> elements)
11959:            //    {
11960:            //        if (elements == null || elements.size() == 0)
11961:            //            return null;
11962:            //
11963:            //        ETNode addedNode = null;
11964:            //        double nudge = 0D;
11965:            //        final double nudgeBy = 25;
11966:            //        ArrayList<ETNode> addedNodes = new ArrayList<ETNode>(elements.size());
11967:            //
11968:            //        for (IElement element: elements)
11969:            //        {
11970:            //            addedNode = addNodeToCenter(element);
11971:            //
11972:            //            if (addedNode == null)
11973:            //                continue;
11974:            //
11975:            //            addedNode.setCenterX(addedNode.getCenterX() + nudge);
11976:            //            addedNode.setCenterY(addedNode.getCenterY() - nudge);
11977:            //
11978:            //            addedNodes.add(addedNode);
11979:            //
11980:            //            nudge+= nudgeBy;
11981:            //        }
11982:            //
11983:            //        invalidate();
11984:            //        refresh(true);
11985:            //        return addedNodes;
11986:            //    }
11987:            public List<IETGraphObject> addNodeToCenter(List<IElement> elements) {
11988:                if (elements == null || elements.size() == 0) {
11989:                    return null;
11990:                }
11991:                List<IETGraphObject> addedNodes = new ArrayList<IETGraphObject>(
11992:                        elements.size());
11993:
11994:                ADCoreEngine coreEngine = null;
11995:
11996:                if (getDiagramEngine() instanceof  ADCoreEngine) {
11997:                    coreEngine = (ADCoreEngine) getDiagramEngine();
11998:                }
11999:                for (IElement element : elements) {
12000:
12001:                    // Fix for issue # 89538.  The element needs to be proceesed before being added.
12002:                    IElement processedElement = processOnDropElement(element);
12003:                    if (processedElement == null) {
12004:                        continue;
12005:                    }
12006:
12007:                    IETPoint pCenterPoint = coreEngine.getLogicalCenter();
12008:                    if (pCenterPoint != null) {
12009:                        int x = pCenterPoint.getX();
12010:                        int y = pCenterPoint.getY();
12011:                        int xOffset = coreEngine.getAcceleratorOffset().x;
12012:                        int yOffset = coreEngine.getAcceleratorOffset().y;
12013:
12014:                        pCenterPoint.setPoints(x + xOffset, y + yOffset);
12015:
12016:                        try {
12017:                            ETNode pCreatedNode = addNode(processedElement,
12018:                                    pCenterPoint, true);
12019:
12020:                            if (pCreatedNode != null) {
12021:                                pCreatedNode.sizeToContents();
12022:                                addedNodes.add((IETGraphObject) pCreatedNode);
12023:                            }
12024:                            setModelElement(null);
12025:                        }
12026:
12027:                        catch (Exception e) {
12028:                            e.printStackTrace();
12029:                        }
12030:
12031:                        // Increment the accelerator offset in case the
12032:                        //  user hits the accel key again
12033:                        coreEngine.getAcceleratorOffset().setLocation(
12034:                                xOffset + 20, yOffset - 20);
12035:                    }
12036:                }
12037:
12038:                invalidate();
12039:                refresh(true);
12040:                return addedNodes;
12041:            }
12042:
12043:            public static final int ALIGN_LEFT = 0;
12044:            public static final int ALIGN_HCENTER = 1;
12045:            public static final int ALIGN_RIGHT = 2;
12046:            public static final int ALIGN_TOP = 3;
12047:            public static final int ALIGN_VCENTER = 4;
12048:            public static final int ALIGN_BOTTOM = 5;
12049:
12050:            public boolean alignLeft() {
12051:                return align(ALIGN_LEFT);
12052:            }
12053:
12054:            public boolean alignHorizontalCenter() {
12055:                return align(ALIGN_HCENTER);
12056:            }
12057:
12058:            public boolean alignRight() {
12059:                return align(ALIGN_RIGHT);
12060:            }
12061:
12062:            public boolean alignTop() {
12063:                return align(ALIGN_TOP);
12064:            }
12065:
12066:            public boolean alignVerticalCenter() {
12067:                return align(ALIGN_VCENTER);
12068:            }
12069:
12070:            public boolean alignBottom() {
12071:                return align(ALIGN_BOTTOM);
12072:            }
12073:
12074:            private boolean align(int alignHow) {
12075:                ETList<IETGraphObject> selGraphNodes = GetHelper
12076:                        .getSelectedNodes((ETGraph) getGraph());
12077:
12078:                if (selGraphNodes == null) {
12079:                    return false;
12080:                }
12081:
12082:                Set<IPresentationElement> containedElems = new HashSet<IPresentationElement>();
12083:
12084:                List<IETGraphObject> alignNodes = new ArrayList<IETGraphObject>();
12085:                Iterator<IETGraphObject> iter = selGraphNodes.iterator();
12086:
12087:                // find all contained nodes of the selected nodes
12088:                while (iter.hasNext()) {
12089:                    IETGraphObject etGraphObj = iter.next();
12090:                    IDrawEngine drawEng = etGraphObj.getEngine();
12091:
12092:                    if (drawEng instanceof  ETContainerDrawEngine) {
12093:                        ETContainerDrawEngine etcDrawEng = (ETContainerDrawEngine) etGraphObj
12094:                                .getEngine();
12095:
12096:                        containedElems.addAll(etcDrawEng.getContained());
12097:                    }
12098:                }
12099:
12100:                iter = selGraphNodes.iterator();
12101:                // keep only top level nodes for the alignment
12102:                while (iter.hasNext()) {
12103:                    IETGraphObject tsObj = iter.next();
12104:                    IPresentationElement presElem = tsObj != null ? tsObj
12105:                            .getPresentationElement() : null;
12106:
12107:                    if (!containedElems.contains(presElem))
12108:                        alignNodes.add(tsObj);
12109:                }
12110:
12111:                if (alignNodes == null || alignNodes.size() < 2)
12112:                    return false;
12113:
12114:                TSConstRect anchor = null;
12115:
12116:                // loop through selected elements and align them
12117:                for (IETGraphObject graphObj : alignNodes) {
12118:                    if (anchor == null) {
12119:                        anchor = graphObj.getObject().getBounds();
12120:                        continue; // this is the node to align to
12121:                    }
12122:
12123:                    TSConstRect bounds = graphObj.getObject().getBounds();
12124:
12125:                    TSConstPoint newCenter = calculateNewCenter(anchor, bounds,
12126:                            alignHow);
12127:
12128:                    moveNode(graphObj, (int) newCenter.getX()
12129:                            - (int) bounds.getCenterX(), (int) newCenter.getY()
12130:                            - (int) bounds.getCenterY(), true);
12131:                } // for
12132:
12133:                // need to call refresh here because the drawing area does not refresh
12134:                // properly when elements are moved
12135:                refresh(true);
12136:                requestFocus();
12137:                return true;
12138:            }
12139:
12140:            private void moveNode(IETGraphObject etGraphObj, int diffX,
12141:                    int diffY, boolean deep) {
12142:                INodePresentation containerNodePres = (INodePresentation) etGraphObj
12143:                        .getPresentationElement();
12144:
12145:                int fromCenterX = containerNodePres.getCenter().getX();
12146:                int fromCenterY = containerNodePres.getCenter().getY();
12147:
12148:                ETList<IETGraphObject> containedObjects = null;
12149:
12150:                if (deep
12151:                        && etGraphObj.getEngine() instanceof  ETContainerDrawEngine) {
12152:                    ETContainerDrawEngine etcDrawEng = (ETContainerDrawEngine) etGraphObj
12153:                            .getEngine();
12154:
12155:                    containedObjects = etcDrawEng.getAllContainedObjects();
12156:                }
12157:
12158:                containerNodePres.moveTo(fromCenterX + diffX, fromCenterY
12159:                        + diffY);
12160:
12161:                if (deep && containedObjects != null
12162:                        && containedObjects.size() > 0) {
12163:                    Iterator<IETGraphObject> iter = containedObjects.iterator();
12164:
12165:                    while (iter.hasNext()) {
12166:                        IETGraphObject obj = iter.next();
12167:
12168:                        INodePresentation nodePres = (INodePresentation) obj
12169:                                .getPresentationElement();
12170:
12171:                        fromCenterX = nodePres.getCenter().getX();
12172:                        fromCenterY = nodePres.getCenter().getY();
12173:
12174:                        nodePres.moveTo(fromCenterX + diffX, fromCenterY
12175:                                + diffY);
12176:                        // moveNode(obj, diffX, diffY, deep);
12177:                    }
12178:                }
12179:            }
12180:
12181:            private TSConstPoint calculateNewCenter(TSConstRect anchorRect,
12182:                    TSConstRect alignRect, int alignHow) {
12183:                switch (alignHow) {
12184:                case ALIGN_LEFT:
12185:                    return new TSConstPoint(
12186:                            anchorRect.getCenterX()
12187:                                    - ((anchorRect.getWidth() - alignRect
12188:                                            .getWidth()) / 2), alignRect
12189:                                    .getCenterY());
12190:
12191:                case ALIGN_HCENTER:
12192:                    return new TSConstPoint(alignRect.getCenterX(), anchorRect
12193:                            .getCenterY());
12194:
12195:                case ALIGN_RIGHT:
12196:                    return new TSConstPoint(
12197:                            anchorRect.getCenterX()
12198:                                    + ((anchorRect.getWidth() - alignRect
12199:                                            .getWidth()) / 2), alignRect
12200:                                    .getCenterY());
12201:
12202:                case ALIGN_TOP:
12203:                    return new TSConstPoint(alignRect.getCenterX(),
12204:                            anchorRect.getCenterY()
12205:                                    + ((anchorRect.getHeight() - alignRect
12206:                                            .getHeight()) / 2));
12207:
12208:                case ALIGN_VCENTER:
12209:                    return new TSConstPoint(anchorRect.getCenterX(), alignRect
12210:                            .getCenterY());
12211:
12212:                case ALIGN_BOTTOM:
12213:                    return new TSConstPoint(alignRect.getCenterX(),
12214:                            anchorRect.getCenterY()
12215:                                    - ((anchorRect.getHeight() - alignRect
12216:                                            .getHeight()) / 2));
12217:                }
12218:
12219:                // if all else fails, return the same center so it doesn't move at all
12220:                // should never reach here, though
12221:                return alignRect.getCenter();
12222:            }
12223:
12224:            // disabled - feature to be added with Meteora
12225:            //    public final static int DISTRIBUTE_LEFT_EDGE = 0;
12226:            //    public final static int DISTRIBUTE_HCENTER = 1;
12227:            //    public final static int DISTRIBUTE_RIGHT_EDGE = 2;
12228:            //    public final static int DISTRIBUTE_TOP_EDGE = 3;
12229:            //    public final static int DISTRIBUTE_VCENTER = 4;
12230:            //    public final static int DISTRIBUTE_BOTTOM_EDGE = 5;
12231:            //
12232:            //    public boolean distributeLeftEdge()
12233:            //    {
12234:            //        return distribute(DISTRIBUTE_LEFT_EDGE);
12235:            //    }
12236:            //
12237:            //    public boolean distributeHorizontalCenter()
12238:            //    {
12239:            //        return distribute(DISTRIBUTE_HCENTER);
12240:            //    }
12241:            //
12242:            //    public boolean distributeRightEdge()
12243:            //    {
12244:            //        return distribute(DISTRIBUTE_RIGHT_EDGE);
12245:            //    }
12246:            //
12247:            //    public boolean distributeTopEdge()
12248:            //    {
12249:            //        return distribute(DISTRIBUTE_TOP_EDGE);
12250:            //    }
12251:            //
12252:            //    public boolean distributeVerticalCenter()
12253:            //    {
12254:            //        return distribute(DISTRIBUTE_VCENTER);
12255:            //    }
12256:            //
12257:            //    public boolean distributeBottomEdge()
12258:            //    {
12259:            //        return distribute(DISTRIBUTE_BOTTOM_EDGE);
12260:            //    }
12261:            //
12262:            //
12263:            //    private boolean distribute(int distributeHow)
12264:            //    {
12265:            //       ETList<IPresentationElement> presElements = null;
12266:            //       presElements = getSelectedPresentionNodes();
12267:            //
12268:            //       if (presElements == null || presElements.size() < 3)
12269:            //           return false;
12270:            //
12271:            //       List<Double> sortedCoords = new ArrayList<Double>(presElements.size());
12272:            //       List<INodePresentation> distributeThese =
12273:            //           new ArrayList<INodePresentation>(presElements.size());
12274:            //
12275:            //       // loop through selected elements and align them
12276:            //       for (IPresentationElement presElem: presElements)
12277:            //       {
12278:            //           if (presElem != null && presElem instanceof INodePresentation)
12279:            //           {
12280:            //               INodePresentation nodePres = (INodePresentation)presElem;
12281:            //               TSENode tsNode = nodePres.getTSNode();
12282:            //
12283:            //               double coord = getDistributeCoord(distributeHow, tsNode);
12284:            //               int i = 0;
12285:            //
12286:            //               // put the X coords in sorted order, at the same time
12287:            //               // use that sorting to sort the distributeThese list
12288:            //               // in the same order
12289:            //               for (Double curX: sortedCoords)
12290:            //               {
12291:            //                   if (coord < coord)
12292:            //                       break;
12293:            //
12294:            //                   i++;
12295:            //               }
12296:            //
12297:            //               sortedCoords.add(i, coord);
12298:            //               distributeThese.add(i, nodePres);
12299:            //           } // if instanceof INodePresentation
12300:            //       } // for
12301:            //
12302:            //       // after filtering out non-nodes, do we still have
12303:            //       // 3 nodes to do distribution
12304:            //       if (sortedCoords.size() < 3)
12305:            //           return false;
12306:            //
12307:            //       // calculate the width of the two outermost node centers
12308:            //       double spread =
12309:            //           sortedCoords.get(0) - sortedCoords.get(distributeThese.size()-1);
12310:            //
12311:            //       // calculate the inteval distance to distribute the nodes
12312:            //       double intervalDist = Math.abs(spread / (distributeThese.size() - 1));
12313:            //
12314:            //       // move node 2 through n-1 to their new distributed intervals
12315:            //       // node 1 and n are already in the right location
12316:            //       double baseCoord = sortedCoords.get(0);
12317:            //
12318:            //       for (int j=1; j < distributeThese.size()-1; j++)
12319:            //       {
12320:            //           distributeNode(
12321:            //               distributeHow,
12322:            //               distributeThese.get(j),
12323:            //               (baseCoord + j * intervalDist));
12324:            //       }
12325:            //
12326:            //       // need to call refresh here because the drawing area does not refresh
12327:            //       // properly when elements are moved
12328:            //       refresh(true);
12329:            //
12330:            //       requestFocus();
12331:            //       return true;
12332:            //    }
12333:            //
12334:            //    private double getDistributeCoord(int distribType, TSENode node)
12335:            //    {
12336:            //        switch(distribType)
12337:            //        {
12338:            //            case DISTRIBUTE_LEFT_EDGE:
12339:            //                return node.getCenterX() - node.getWidth()/2;
12340:            //
12341:            //            case DISTRIBUTE_HCENTER:
12342:            //                return node.getCenterX();
12343:            //
12344:            //            case DISTRIBUTE_RIGHT_EDGE:
12345:            //                return node.getCenterX() + node.getWidth()/2;
12346:            //
12347:            //            case DISTRIBUTE_TOP_EDGE:
12348:            //                return node.getCenterY() - node.getHeight()/2;
12349:            //
12350:            //            case DISTRIBUTE_VCENTER:
12351:            //                return node.getCenterY();
12352:            //
12353:            //            case DISTRIBUTE_BOTTOM_EDGE:
12354:            //                return node.getCenterY() + node.getHeight()/2;
12355:            //        }
12356:            //
12357:            //        return 0D;
12358:            //    }
12359:            //
12360:            //    private void distributeNode(
12361:            //        int distribType, INodePresentation node, double distributeTo)
12362:            //    {
12363:            //        node.invalidate();
12364:            //
12365:            //        switch(distribType)
12366:            //        {
12367:            //            case DISTRIBUTE_LEFT_EDGE:
12368:            //                node.getTSNode().setCenterX(distributeTo + (node.getWidth()/2));
12369:            //                break;
12370:            //
12371:            //            case DISTRIBUTE_HCENTER:
12372:            //                node.getTSNode().setCenterX(distributeTo);
12373:            //                break;
12374:            //
12375:            //            case DISTRIBUTE_RIGHT_EDGE:
12376:            //                node.getTSNode().setCenterX(distributeTo - (node.getWidth()/2));
12377:            //                break;
12378:            //
12379:            //            case DISTRIBUTE_TOP_EDGE:
12380:            //                node.getTSNode().setCenterY(distributeTo + (node.getHeight()/2));
12381:            //                break;
12382:            //
12383:            //            case DISTRIBUTE_VCENTER:
12384:            //                node.getTSNode().setCenterY(distributeTo);
12385:            //                break;
12386:            //
12387:            //            case DISTRIBUTE_BOTTOM_EDGE:
12388:            //                node.getTSNode().setCenterY(distributeTo - (node.getHeight()/2));
12389:            //                break;
12390:            //        }
12391:            //
12392:            //        node.invalidate();
12393:            //    }
12394:        }
www__.j__a___v___a2_s___._c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.