0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.modules.uml.ui.products.ad.graphobjects;
0043:
0044: import org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation;
0045: import java.util.Iterator;
0046: import org.netbeans.modules.uml.common.ETSystem;
0047: import org.netbeans.modules.uml.common.ETException;
0048: import org.netbeans.modules.uml.common.generics.IteratorT;
0049: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0050: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
0051: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
0052: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
0053: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramValidateKind;
0054: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramValidateResult;
0055: import org.netbeans.modules.uml.core.metamodel.diagrams.IGraphEventKind;
0056: import org.netbeans.modules.uml.core.metamodel.diagrams.IGraphObjectValidation;
0057: import org.netbeans.modules.uml.core.metamodel.diagrams.ISynchStateKind;
0058: import org.netbeans.modules.uml.core.support.umlsupport.ETRect;
0059: import org.netbeans.modules.uml.core.support.umlsupport.IETPoint;
0060: import org.netbeans.modules.uml.core.support.umlsupport.IETRect;
0061: import org.netbeans.modules.uml.core.support.umlsupport.IStrings;
0062: import org.netbeans.modules.uml.core.support.umlutils.ETArrayList;
0063: import org.netbeans.modules.uml.core.support.umlutils.ETList;
0064: import org.netbeans.modules.uml.ui.controls.drawingarea.IUIDiagram;
0065: import org.netbeans.modules.uml.ui.products.ad.application.IMenuManager;
0066: import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETBaseUI;
0067: import org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericNodeUI;
0068: import org.netbeans.modules.uml.ui.products.ad.viewfactory.IETGraphObjectUI;
0069: import org.netbeans.modules.uml.ui.support.ElementReloader;
0070: import org.netbeans.modules.uml.ui.support.PresentationReferenceHelper;
0071: import org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation;
0072: import org.netbeans.modules.uml.ui.support.applicationmanager.IProductGraphPresentation;
0073: import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchive;
0074: import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchiveElement;
0075: import org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenu;
0076: import org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenuItem;
0077: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
0078: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETEdge;
0079: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
0080: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETLabel;
0081: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode;
0082: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IEventManager;
0083: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ILabelManager;
0084: import org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets;
0085: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject;
0086: import org.netbeans.modules.uml.ui.support.viewfactorysupport.NotificationTargets;
0087: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
0088: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
0089: import com.tomsawyer.editor.TSEGraph;
0090: import com.tomsawyer.editor.TSEGraphWindow;
0091: import com.tomsawyer.editor.TSENode;
0092: import com.tomsawyer.editor.TSEObject;
0093: import com.tomsawyer.editor.TSEObjectUI;
0094: import com.tomsawyer.editor.tool.TSEMoveSelectedTool;
0095: import com.tomsawyer.editor.ui.TSENodeUI;
0096: import com.tomsawyer.graph.TSGraphObject;
0097: import com.tomsawyer.drawing.TSNodeLabel;
0098: import com.tomsawyer.drawing.TSConnector;
0099: import com.tomsawyer.drawing.geometry.TSConstPoint;
0100: import com.tomsawyer.drawing.geometry.TSConstRect;
0101: import com.tomsawyer.drawing.geometry.TSConstSize;
0102: import com.tomsawyer.drawing.geometry.TSRect;
0103: import com.tomsawyer.util.TSObject;
0104: import org.netbeans.modules.uml.core.support.Debug;
0105: import java.util.List;
0106: import org.netbeans.modules.uml.core.metamodel.core.foundation.UMLXMLManip;
0107:
0108: public class ETNode extends TSENode implements IETNode {
0109: //private IGraphPresentation m_presentation;
0110: private INodePresentation m_presentation = null;
0111: int mSynchState = ISynchStateKind.SSK_UNKNOWN_SYNCH_STATE;
0112:
0113: /**
0114: * Constructor of the class. This constructor should be implemented
0115: * to enable <code>TSENode</code> inheritance.
0116: */
0117: protected ETNode() {
0118: super ();
0119: }
0120:
0121: /* jyothi wrote this
0122: protected TSENodeUI newNodeUI() {
0123: return (new ETGenericNodeUI());
0124: }
0125: */
0126: protected void finalize() {
0127: // try
0128: // {
0129: // super.finalize();
0130: // FactoryRetriever ret = FactoryRetriever.instance();
0131: // String xmiid = XMLManip.getAttributeValue(m_Node, "xmi.id");
0132: // if (xmiid != null && xmiid.length() > 0)
0133: // {
0134: // ret.removeObject(xmiid);
0135: // }
0136: // }
0137: // catch (Throwable e)
0138: // {
0139: // }
0140: Debug.out.println("");
0141: }
0142:
0143: /**
0144: * This method allocates a new label for this node. This method
0145: * should be implemented to enable <code>TSENodeLabel</code>
0146: * inheritance.
0147: *
0148: * @return an object of the type derived from <code>TSENodeLabel</code>
0149: */
0150: protected TSNodeLabel newLabel() {
0151: ETSystem.out.println("Inside ETNode.newLabel()");
0152: return (new ETNodeLabel());
0153: }
0154:
0155: /**
0156: * This method allocates a new connector for this node. This method
0157: * should be implemented to enable <code>TSEConnector</code>
0158: * inheritance.
0159: *
0160: * @return an object of the type derived from <code>TSEConnector</code>
0161: */
0162: protected TSConnector newConnector() {
0163: return (new ETConnector());
0164: }
0165:
0166: /**
0167: * This method copies attributes of the source object to this
0168: * object. The source object has to be of the type compatible
0169: * with this class (equal or derived). The method should make a
0170: * deep copy of all instance variables declared in this class.
0171: * Variables of simple (non-object) types are automatically copied
0172: * by the call to the copy method of the super class.
0173: *
0174: * @param sourceObject the source from which all attributes must
0175: * be copied
0176: */
0177: public void copy(Object sourceObject) {
0178: setPresentationElement(null);
0179:
0180: // copy the attributes of the super class first
0181: super .copy(sourceObject);
0182:
0183: IElement modelElement = TypeConversions
0184: .getElement((TSObject) sourceObject);
0185: if (modelElement != null) {
0186: ETBaseUI.attachAndCreatePresentationElement(modelElement,
0187: getETUI().getInitStringValue(), false, getETUI());
0188: }
0189:
0190: }
0191:
0192: /**
0193: * This method sets the resizability of this node. It also ensures
0194: * that layout respects the RESIZABILITY_PRESERVE_ASPECT flag if
0195: * possible.
0196: */
0197: public void setResizability(int resizability) {
0198: super .setResizability(resizability);
0199:
0200: int value;
0201:
0202: // make the layout server respect the RESIZABILITY_PRESERVE_ASPECT flag.
0203: /* commented by jyothi
0204: TSIntLayoutProperty layoutProperty = new TSIntLayoutProperty(TSTailorProperties.ORTHOGONAL_NODE_RESIZE_STYLE);
0205:
0206: if ((resizability & TSENode.RESIZABILITY_PRESERVE_ASPECT) != 0) {
0207: value = TSLayoutPropertyEnums.RESIZE_STYLE_PRESERVE_ASPECT_RATIO;
0208: } else {
0209: value = TSLayoutPropertyEnums.RESIZE_STYLE_STRETCHABLE;
0210:
0211: }
0212:
0213: // set the value and the property. This will replace any existing property of the same type.
0214: layoutProperty.setCurrentValue(value);
0215: this.setTailorProperty(layoutProperty);
0216: */
0217: }
0218:
0219: /* (non-Javadoc)
0220: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode#connected()
0221: */
0222: public boolean connected() {
0223: return hasChildren() || hasParents();
0224: }
0225:
0226: /* (non-Javadoc)
0227: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode#hasChildren()
0228: */
0229: public boolean hasChildren() {
0230: return outDegree() > 0;
0231: }
0232:
0233: /* (non-Javadoc)
0234: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode#hasParents()
0235: */
0236: public boolean hasParents() {
0237: return inDegree() > 0;
0238: }
0239:
0240: /* (non-Javadoc)
0241: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#affectModelElementDeletion()
0242: */
0243: public void affectModelElementDeletion() {
0244: IETGraphObjectUI ui = this .getETUI();
0245: if (ui != null) {
0246: IDrawEngine de = ui.getDrawEngine();
0247: if (de != null) {
0248: de.affectModelElementDeletion();
0249: }
0250: }
0251: }
0252:
0253: /* (non-Javadoc)
0254: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getDiagram()
0255: */
0256: public IDiagram getDiagram() {
0257: IDrawingAreaControl da = getDrawingAreaControl();
0258: return da != null ? da.getDiagram() : null;
0259: }
0260:
0261: /* (non-Javadoc)
0262: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getEngine()
0263: */
0264: public IDrawEngine getEngine() {
0265: return getETUI() != null ? getETUI().getDrawEngine() : null;
0266: }
0267:
0268: public IDrawingAreaControl getDrawingAreaControl() {
0269: return getETUI() != null ? getETUI().getDrawingArea() : null;
0270: }
0271:
0272: /* (non-Javadoc)
0273: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getObjectView()
0274: */
0275: public TSEObjectUI getObjectView() {
0276: return super .getUI();
0277: }
0278:
0279: /* (non-Javadoc)
0280: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getPresentationElement()
0281: */
0282: public IPresentationElement getPresentationElement() {
0283: return m_presentation;
0284: }
0285:
0286: /* (non-Javadoc)
0287: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getReferredElements()
0288: */
0289: public IStrings getReferredElements() {
0290: IETGraphObjectUI ui = getETUI();
0291: return ui != null ? ui.getReferredElements() : null;
0292: }
0293:
0294: /* (non-Javadoc)
0295: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getReloadedModelElementXMIID()
0296: */
0297: public String getReloadedModelElementXMIID() {
0298: IETGraphObjectUI ui = getETUI();
0299: return ui != null ? ui.getReloadedModelElementXMIID() : null;
0300: }
0301:
0302: /* (non-Javadoc)
0303: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getReloadedOwnerPresentationXMIID()
0304: */
0305: public String getReloadedOwnerPresentationXMIID() {
0306: IETGraphObjectUI ui = getETUI();
0307: return ui != null ? ui.getReloadedOwnerPresentationXMIID()
0308: : null;
0309: }
0310:
0311: /* (non-Javadoc)
0312: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getReloadedPresentationXMIID()
0313: */
0314: public String getReloadedPresentationXMIID() {
0315: IETGraphObjectUI ui = getETUI();
0316: return ui != null ? ui.getReloadedPresentationXMIID() : null;
0317: }
0318:
0319: /* (non-Javadoc)
0320: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getReloadedTopLevelXMIID()
0321: */
0322: public String getReloadedTopLevelXMIID() {
0323: IETGraphObjectUI ui = getETUI();
0324: return ui != null ? ui.getReloadedTopLevelXMIID() : null;
0325: }
0326:
0327: /* (non-Javadoc)
0328: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getTopLevelXMIID()
0329: */
0330: public String getTopLevelXMIID() {
0331: // TODO Auto-generated method stub
0332: return null;
0333: }
0334:
0335: /**
0336: * Reads this element from the etlp file
0337: */
0338: public void load(IProductArchive pProductArchive) {
0339: //implemented from BaseGraphObject.cpp
0340: if (pProductArchive != null) {
0341: String reloadedXMIID = getReloadedPresentationXMIID();
0342: IProductArchiveElement foundEle;
0343: if (reloadedXMIID.length() > 0) {
0344: foundEle = pProductArchive.getElement(reloadedXMIID);
0345: } else {
0346: foundEle = null;
0347: }
0348:
0349: if (foundEle != null) {
0350: readFromArchive(pProductArchive, foundEle);
0351: }
0352: }
0353: }
0354:
0355: /* (non-Javadoc)
0356: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#modelElementDeleted(org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets)
0357: */
0358: public void modelElementDeleted(INotificationTargets pTargets) {
0359: IDrawEngine pEng = getETUI().getDrawEngine();
0360: if (pEng != null) {
0361: pEng.modelElementDeleted(pTargets);
0362: }
0363: }
0364:
0365: /**
0366: * Notification that the model element has changed.
0367: *
0368: * @param pTargets [in] Contains information about what the event was and who is getting
0369: * notified.
0370: */
0371: public void modelElementHasChanged(INotificationTargets pTargets) {
0372: IDrawEngine pEng = getETUI().getDrawEngine();
0373: if (pEng != null) {
0374: pEng.modelElementHasChanged(pTargets);
0375:
0376: /// Now tell the label manager
0377: ILabelManager labelMgr = pEng.getLabelManager();
0378: if (labelMgr != null) {
0379: labelMgr.modelElementHasChanged(pTargets);
0380: }
0381: }
0382:
0383: }
0384:
0385: /* (non-Javadoc)
0386: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#onGraphEvent(int)
0387: */
0388: public void onGraphEvent(int nKind) {
0389: if (nKind == IGraphEventKind.GEK_PRE_LAYOUT) {
0390: // make sure the current size is the orginalSize or
0391: // the layout server will set it back to the size on creation.
0392: // Kevin.
0393: setOriginalSize(getBounds().getSize());
0394: }
0395: ETBaseUI.onGraphEvent(nKind, getETUI());
0396: }
0397:
0398: /* (non-Javadoc)
0399: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#onKeydown(int, int)
0400: */
0401: public boolean onKeydown(int nKeyCode, int nShift) {
0402: return ETBaseUI.onKeyDown(nKeyCode, nShift, getETUI());
0403: }
0404:
0405: /* (non-Javadoc)
0406: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#onCharTyped(char)
0407: */
0408: public boolean onCharTyped(char ch) {
0409: return ETBaseUI.onCharTyped(ch, getETUI());
0410: }
0411:
0412: /* (non-Javadoc)
0413: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#onKeyup(int, int)
0414: */
0415: public boolean onKeyup(int nKeyCode, int nShift) {
0416: // TODO Auto-generated method stub
0417: return false;
0418: }
0419:
0420: /* (non-Javadoc)
0421: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#postLoad()
0422: */
0423: public void postLoad() {
0424: IPresentationElement pEle = getPresentationElement();
0425: ElementReloader reloader = new ElementReloader();
0426:
0427: String reloadedOwnerPresXMIID = getReloadedOwnerPresentationXMIID();
0428: String reloadedTopLevelXMIID = getReloadedTopLevelXMIID();
0429: IStrings refElemList = getReferredElements();
0430:
0431: boolean deleted = false;
0432: if (reloadedOwnerPresXMIID.length() > 0
0433: && reloadedTopLevelXMIID.length() > 0 && pEle != null) {
0434: boolean attachFailed = true;
0435:
0436: // Get this presentation element and reattach. If we are a bridge and cannot
0437: // reattach then delete ourselves
0438: IElement modEle = reloader.getElement(
0439: reloadedTopLevelXMIID, reloadedOwnerPresXMIID);
0440: if (modEle != null) {
0441: modEle.addElement(pEle);
0442: attachFailed = false;
0443: }
0444:
0445: if (attachFailed) {
0446: IDrawingAreaControl control = getDrawingAreaControl();
0447: if (control != null) {
0448: control.postDeletePresentationElement(pEle);
0449: deleted = true;
0450: }
0451: }
0452: }
0453:
0454: // Recreate the presentation reference relationships
0455: if (!deleted && refElemList != null) {
0456: long count = refElemList.getCount();
0457: Iterator<String> refElemIter = refElemList.iterator();
0458: while (refElemIter.hasNext()) {
0459: String refId = refElemIter.next();
0460: IElement modEle = reloader.getElement(refId);
0461: if (modEle != null
0462: && modEle instanceof IPresentationElement) {
0463: PresentationReferenceHelper
0464: .createPresentationReference(pEle,
0465: (IPresentationElement) modEle);
0466:
0467: }
0468: }
0469: }
0470:
0471: // This call will allow the draw engine
0472: // to process information after all objects have been loaded.
0473: IDrawEngine engine = getEngine();
0474: if (!deleted && engine != null) {
0475: engine.postLoad();
0476: }
0477: }
0478:
0479: /* (non-Javadoc)
0480: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#readData(int)
0481: */
0482: public void readData(int pTSEData) {
0483: // TODO Auto-generated method stub
0484: }
0485:
0486: /**
0487: * Restore from the product archive
0488: *
0489: * @param pProductArchive [in] The archive we're reading from
0490: * @param pElement [in] The current element, this is where this graph object's elements and attributes should be.
0491: */
0492: public void readFromArchive(IProductArchive prodArch,
0493: IProductArchiveElement archEle) {
0494: if (prodArch != null && archEle != null) {
0495: TSEObjectUI ui = getUI();
0496: if (ui != null && ui instanceof ETGenericNodeUI) {
0497: ((ETGenericNodeUI) ui).readFromArchive(prodArch,
0498: archEle);
0499: }
0500: }
0501: }
0502:
0503: /**
0504: * Saves this element to the etlp file
0505: *
0506: * @param pProductArchive [in] The archive file we're serializing to.
0507: */
0508: public void save(IProductArchive prodArch) {
0509: IETGraphObjectUI ui = this .getETUI();
0510: if (ui != null) {
0511: ETBaseUI.save(prodArch, ui);
0512: }
0513: }
0514:
0515: /* (non-Javadoc)
0516: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setDiagram(org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram)
0517: */
0518: public void setDiagram(IDiagram value) {
0519: //Implemented from ETGraphObjectImpl.cpp
0520: if (value instanceof IUIDiagram) {
0521: // m_RawDrawingAreaControl = ((IUIDiagram)value).getDrawingArea();
0522: // if (m_RawDrawingAreaControl != null)
0523: // {
0524: // m_RawDrawingAreaControl = null;
0525: // }
0526: }
0527: }
0528:
0529: /* (non-Javadoc)
0530: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setObjectView(com.tomsawyer.editor.TSEObjectUI)
0531: */
0532: public void setObjectView(TSEObjectUI value) {
0533: setUI(value);
0534: }
0535:
0536: public void setUI(TSEObjectUI ui) {
0537: super .setUI(ui);
0538: //ETGenericNodeUI etgennodeui = new ETGenericNodeUI();
0539: /*
0540: List l = ui.getProperties();
0541: for (int i=0; i<l.size(); i++) {
0542: Debug.out.println(" Property = "+l.get(i));
0543: }
0544: Debug.out.println(" ui object : class = "+ui.getClass()+" owner = "+ui.getOwner());
0545: */
0546: // Keep the presentation element n'sync.
0547: if (ui instanceof IETGraphObjectUI || ui == null) {
0548: IPresentationElement pe = this .getPresentationElement();
0549: IGraphPresentation graphPE = pe instanceof IGraphPresentation ? (IGraphPresentation) pe
0550: : null;
0551:
0552: // if (graphPE != null)
0553: // graphPE.setUI((IETGraphObjectUI) ui);
0554: }
0555: }
0556:
0557: /* (non-Javadoc)
0558: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setPresentationElement(org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement)
0559: */
0560: public void setPresentationElement(IPresentationElement value) {
0561: // m_presentation = value instanceof IGraphPresentation ? (IGraphPresentation) value : null;
0562: m_presentation = value instanceof INodePresentation ? (INodePresentation) value
0563: : null;
0564: // Make sure the back pointer is in sync
0565: if (m_presentation != null && getETUI() != null) {
0566: //m_presentation.setUI(getETUI());
0567: m_presentation.setTSNode(this );
0568: }
0569: }
0570:
0571: /* (non-Javadoc)
0572: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setReferredElements(org.netbeans.modules.uml.core.support.umlsupport.IStrings)
0573: */
0574: public void setReferredElements(IStrings value) {
0575: IETGraphObjectUI ui = getETUI();
0576: if (ui != null) {
0577: ui.setReferredElements(value);
0578: }
0579: }
0580:
0581: /* (non-Javadoc)
0582: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setReloadedModelElementXMIID(java.lang.String)
0583: */
0584: public void setReloadedModelElementXMIID(String value) {
0585: IETGraphObjectUI ui = getETUI();
0586: if (ui != null) {
0587: ui.setReloadedModelElementXMIID(value);
0588: }
0589: }
0590:
0591: /* (non-Javadoc)
0592: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setReloadedOwnerPresentationXMIID(java.lang.String)
0593: */
0594: public void setReloadedOwnerPresentationXMIID(String value) {
0595: IETGraphObjectUI ui = getETUI();
0596: if (ui != null) {
0597: ui.setReloadedOwnerPresentationXMIID(value);
0598: }
0599: }
0600:
0601: /* (non-Javadoc)
0602: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setReloadedPresentationXMIID(java.lang.String)
0603: */
0604: public void setReloadedPresentationXMIID(String value) {
0605: IETGraphObjectUI ui = getETUI();
0606: if (ui != null) {
0607: ui.setReloadedPresentationXMIID(value);
0608: }
0609: }
0610:
0611: /* (non-Javadoc)
0612: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setReloadedTopLevelXMIID(java.lang.String)
0613: */
0614: public void setReloadedTopLevelXMIID(String value) {
0615: IETGraphObjectUI ui = getETUI();
0616: if (ui != null) {
0617: ui.setReloadedTopLevelXMIID(value);
0618: }
0619: }
0620:
0621: /* (non-Javadoc)
0622: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#sizeToContents()
0623: */
0624: public void sizeToContents() {
0625: if (getEngine() != null) {
0626: getEngine().sizeToContents();
0627: }
0628: }
0629:
0630: /* (non-Javadoc)
0631: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#writeData(int)
0632: */
0633: public void writeData(int pTSEDataMgr) {
0634: // TODO Auto-generated method stub
0635: }
0636:
0637: /* (non-Javadoc)
0638: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#writeToArchive(org.netbeans.modules.uml.ui.support.archivesupport.IProductArchive, org.netbeans.modules.uml.ui.support.archivesupport.IProductArchiveElement)
0639: */
0640: public void writeToArchive(IProductArchive prodArch,
0641: IProductArchiveElement archEle) {
0642: if (prodArch != null && archEle != null) {
0643: IETGraphObjectUI ui = getETUI();
0644: if (ui != null && ui instanceof ETGenericNodeUI)
0645: ((ETGenericNodeUI) ui)
0646: .writeToArchive(prodArch, archEle);
0647: }
0648: }
0649:
0650: /* (non-Javadoc)
0651: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#copy(org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject)
0652: */
0653: public void copy(ITSGraphObject objToClone) {
0654: // TODO Auto-generated method stub
0655:
0656: }
0657:
0658: protected TSEGraphWindow getGraphWindow() {
0659: IDrawingAreaControl ctrl = getDrawingAreaControl();
0660: return ctrl != null ? ctrl.getGraphWindow() : null;
0661: }
0662:
0663: protected void invalidateEdges(List edges) {
0664: IDrawingAreaControl ctrl = getDrawingAreaControl();
0665:
0666: if (ctrl == null || edges == null)
0667: return;
0668:
0669: TSEGraphWindow window = ctrl.getGraphWindow();
0670: if (window != null) {
0671: IteratorT<TSEObject> iter = new IteratorT<TSEObject>(edges);
0672: while (iter.hasNext())
0673: window.addInvalidRegion(iter.next());
0674: }
0675: }
0676:
0677: public void invalidateInEdges() {
0678: invalidateEdges(getInEdges());
0679: }
0680:
0681: public void invalidateOutEdges() {
0682: invalidateEdges(getOutEdges());
0683: }
0684:
0685: public void invalidateEdges() {
0686: invalidateInEdges();
0687: invalidateOutEdges();
0688: }
0689:
0690: /**
0691: * Used during paste, this creates a copy of this node.
0692: *
0693: * @param pTargetDiagram [in] The diagram this node is to appear on
0694: * @param pCenter [in] The location of the node
0695: * @param pCopy [out,retval] The created node
0696: */
0697: public IETNode createNodeCopy(IDiagram pTargetDiagram,
0698: IETPoint pCenterPoint) {
0699: IDrawingAreaControl pControl = null;
0700: TSEGraph pTSGraph = null;
0701: IETNode copy = null;
0702:
0703: if (pTargetDiagram != null) {
0704: IUIDiagram uiDiagram = null;
0705: if (pTargetDiagram instanceof IUIDiagram)
0706: uiDiagram = (IUIDiagram) pTargetDiagram;
0707:
0708: if (uiDiagram != null) {
0709: pControl = uiDiagram.getDrawingArea();
0710:
0711: if (pControl != null) {
0712: pTSGraph = pControl.getCurrentGraph();
0713: }
0714: }
0715: }
0716:
0717: TSENode pCreatedNode = null;
0718: // Change the init string to a known ADViewFactory type and create a new node
0719: try {
0720: // Fixed issue 93686
0721: // the hardcoded intStr "org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericNodeUI"
0722: // passed to the addNode method is not a complete string; therefore it causes an incorrectly result
0723: // when addNode tries to find the details of the node. Calling addNode(IElemenent, IPoint) instead.
0724:
0725: pCreatedNode = (TSENode) pControl.addNode(TypeConversions
0726: .getElement((IETGraphObject) this ), pCenterPoint);
0727: // pCreatedNode = (TSENode)pControl.addNode("org.netbeans.modules.uml.ui.products.ad.viewfactory.ETGenericNodeUI",
0728: // pCenterPoint,false,false,TypeConversions.getElement((IETGraphObject)this));
0729: } catch (ETException e) {
0730: e.printStackTrace();
0731: }
0732:
0733: if (pCreatedNode != null) {
0734: // Convert the created node to our type so we can do an operator=
0735: TSENodeUI createdNodeUI = pCreatedNode.getNodeUI();
0736: createdNodeUI.copy(getNodeUI());
0737:
0738: // Set the drawing area backpointer
0739: IETGraphObject pETGraphObject = TypeConversions
0740: .getETGraphObject(createdNodeUI);
0741:
0742: pETGraphObject.setDiagram(pTargetDiagram);
0743:
0744: // Set the size and location of the node
0745: TSConstSize size = getSize();
0746: pCreatedNode.setSize(size);
0747:
0748: if (pETGraphObject instanceof IETNode)
0749: copy = (IETNode) pETGraphObject;
0750: }
0751: return copy;
0752: }
0753:
0754: /*
0755: * Returns the set of labels.
0756: */
0757: public ETList<IETLabel> getLabels() {
0758: return getLabels(true, true);
0759: }
0760:
0761: /*
0762: * Returns the set of labels.
0763: */
0764: public ETList<IETLabel> getLabels(boolean includeSelected,
0765: boolean includeNonselected) {
0766: List labels = this .labels();
0767: if (labels != null && labels.size() > 0) {
0768: ETList<IETLabel> filteredLabels = new ETArrayList<IETLabel>();
0769: IteratorT<IETLabel> iter = new IteratorT<IETLabel>(labels);
0770: while (iter.hasNext()) {
0771: IETLabel label = iter.next();
0772: boolean isSelected = label.isSelected();
0773: if ((includeSelected && isSelected)
0774: || (includeNonselected && !isSelected)) {
0775: filteredLabels.add(label);
0776: }
0777: }
0778:
0779: return filteredLabels.size() > 0 ? filteredLabels : null;
0780: }
0781: return null;
0782: }
0783:
0784: /*
0785: * The drawing area control doesn't delete non selected items, its our job to fire the delete notifications.
0786: */
0787: protected void deleteNonSelectedLabels() {
0788: ETList<IETLabel> labels = getLabels(false, true);
0789: if (labels != null) {
0790: Iterator<IETLabel> iter = labels.iterator();
0791: while (iter.hasNext()) {
0792: iter.next().delete();
0793: }
0794: }
0795: }
0796:
0797: protected void deleteNonSelectedEdges(List edges) {
0798: if (edges != null) {
0799: IteratorT<IETGraphObject> iter = new IteratorT<IETGraphObject>(
0800: edges);
0801: while (iter.hasNext()) {
0802: IETGraphObject pObj = iter.next();
0803: if (!pObj.isSelected()) {
0804: pObj.delete();
0805: iter.reset(edges);
0806: }
0807: }
0808: }
0809: }
0810:
0811: protected void deleteNonSelectedEdges() {
0812: deleteNonSelectedEdges(this .getInEdges());
0813: deleteNonSelectedEdges(this .getOutEdges());
0814: }
0815:
0816: /* (non-Javadoc)
0817: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#delete()
0818: */
0819: public void delete() {
0820: deleteNonSelectedLabels();
0821: deleteNonSelectedEdges();
0822: TSENodeUI ui = this .getUI() instanceof TSENodeUI ? (TSENodeUI) getUI()
0823: : null;
0824:
0825: this .invalidate();
0826: IDrawEngine drawEngine = this .getEngine();
0827: if (drawEngine != null) {
0828: drawEngine.onDiscardParentETElement();
0829: }
0830: getOwnerGraph().discard(this );
0831: if (ui != null) {
0832: ui.setOwner(null);
0833: }
0834: }
0835:
0836: /* (non-Javadoc)
0837: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#getETUI()
0838: */
0839: public IETGraphObjectUI getETUI() {
0840: return super .getUI() instanceof IETGraphObjectUI ? (IETGraphObjectUI) super
0841: .getUI()
0842: : null;
0843: }
0844:
0845: /* (non-Javadoc)
0846: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#getObject()
0847: */
0848: public TSEObject getObject() {
0849: return this ;
0850: }
0851:
0852: /* (non-Javadoc)
0853: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#isEdge()
0854: */
0855: public boolean isEdge() {
0856: return false;
0857: }
0858:
0859: /* (non-Javadoc)
0860: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#isLabel()
0861: */
0862: public boolean isLabel() {
0863: return false;
0864: }
0865:
0866: /* (non-Javadoc)
0867: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#isNode()
0868: */
0869: public boolean isNode() {
0870: return true;
0871: }
0872:
0873: /* (non-Javadoc)
0874: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject#setText(java.lang.Object)
0875: */
0876: public void setText(Object text) {
0877: super .setTag(text);
0878: }
0879:
0880: public void onContextMenu(IMenuManager manager) {
0881: ETBaseUI.onContextMenu(manager, getETUI());
0882: }
0883:
0884: public IElement create(INamespace space, String initStr) {
0885: IElement retEle = null;
0886: retEle = ETBaseUI.create(space, initStr, getETUI());
0887: if (retEle != null) {
0888: INotificationTargets targets = new NotificationTargets();
0889: targets.setChangedModelElement(retEle);
0890: modelElementHasChanged(targets);
0891: }
0892: return retEle;
0893: }
0894:
0895: public void attach(IElement modEle, String initStr) {
0896: ETBaseUI.attach(modEle, initStr, getETUI());
0897: INotificationTargets targets = new NotificationTargets();
0898: targets.setChangedModelElement(modEle);
0899: modelElementHasChanged(targets);
0900: }
0901:
0902: public void onPostAddLink(IETGraphObject newLink, boolean isFromNode) {
0903: ETBaseUI.onPostAddLink(newLink, isFromNode, getETUI());
0904: }
0905:
0906: public List getInEdges() {
0907: return inEdges();
0908: }
0909:
0910: public List getOutEdges() {
0911: return outEdges();
0912: }
0913:
0914: public IETRect getEdgeBounds() {
0915: IETRect boundingRect = new ETRect();
0916: try {
0917: IteratorT<IETEdge> edgeIter = new IteratorT<IETEdge>(
0918: getInEdges());
0919: while (edgeIter.hasNext()) {
0920: IDrawEngine edgeEngine = TypeConversions
0921: .getDrawEngine(edgeIter.next());
0922: if (edgeEngine != null) {
0923: IETRect edgeRect = edgeEngine.getBoundingRect();
0924:
0925: boundingRect.unionWith(edgeRect);
0926: }
0927: }
0928: edgeIter.reset(getOutEdges());
0929:
0930: while (edgeIter.hasNext()) {
0931: IDrawEngine edgeEngine = TypeConversions
0932: .getDrawEngine(edgeIter.next());
0933: if (edgeEngine != null) {
0934: IETRect edgeRect = edgeEngine.getBoundingRect();
0935:
0936: boundingRect.unionWith(edgeRect);
0937: }
0938: }
0939: } catch (Exception e) {
0940: }
0941: return boundingRect;
0942: }
0943:
0944: public void onDiscard(TSGraphObject oldOwner) {
0945: // Should we call the super here?????? Kevin M
0946: //Jyothi: Fix for Bug#6258424
0947: super .onDiscard(oldOwner);
0948:
0949: if (getDrawingAreaControl() != null) {
0950: getDrawingAreaControl().refreshRect(getEdgeBounds());
0951: }
0952: }
0953:
0954: /* (non-Javadoc)
0955: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#create(org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace, java.lang.String, org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement, org.netbeans.modules.uml.core.metamodel.core.foundation.IElement)
0956: */
0957: public void create(INamespace pNamespace,
0958: String sInitializationString,
0959: IPresentationElement pCreatedPresentationElement,
0960: IElement pCreatedElement) {
0961: // TODO Auto-generated method stub
0962:
0963: }
0964:
0965: /* (non-Javadoc)
0966: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getGraphObject()
0967: */
0968: public TSGraphObject getGraphObject() {
0969: return this ;
0970: }
0971:
0972: /* (non-Javadoc)
0973: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getInitializationString()
0974: */
0975: public String getInitializationString() {
0976: // TODO Auto-generated method stub
0977: return null;
0978: }
0979:
0980: /* (non-Javadoc)
0981: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getOLEDragElements(org.netbeans.modules.uml.core.metamodel.core.foundation.IElement[])
0982: */
0983: public ETList<IElement> getDragElements() {
0984: // TODO Auto-generated method stub
0985: return null;
0986: }
0987:
0988: /* (non-Javadoc)
0989: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getSynchState()
0990: */
0991: public int getSynchState() {
0992: return mSynchState;
0993: }
0994:
0995: /* (non-Javadoc)
0996: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#getWasModelElementDeleted()
0997: */
0998: public boolean getWasModelElementDeleted() {
0999: // this used to check an attribute, but per Pat, that is soon to be obsolete
1000: return TypeConversions.getElement((IETGraphObject) this ) == null;
1001: }
1002:
1003: /* (non-Javadoc)
1004: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#handleAccelerator(int)
1005: */
1006: public boolean handleAccelerator(String accelerator) {
1007: boolean bHandled = false;
1008:
1009: IETGraphObjectUI ui = this .getETUI();
1010: if (ui != null) {
1011: IDrawEngine de = ui.getDrawEngine();
1012: if (de != null) {
1013: bHandled = de.handleAccelerator(accelerator);
1014: }
1015: }
1016:
1017: return bHandled;
1018: }
1019:
1020: /* (non-Javadoc)
1021: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#handleLeftMouseBeginDrag(org.netbeans.modules.uml.core.support.umlsupport.IETPoint, org.netbeans.modules.uml.core.support.umlsupport.IETPoint)
1022: */
1023: public boolean handleLeftMouseBeginDrag(IETPoint pStartPos,
1024: IETPoint pCurrentPos) {
1025: // TODO Auto-generated method stub
1026: return false;
1027: }
1028:
1029: /* (non-Javadoc)
1030: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#handleLeftMouseDrag(org.netbeans.modules.uml.core.support.umlsupport.IETPoint, org.netbeans.modules.uml.core.support.umlsupport.IETPoint)
1031: */
1032: public boolean handleLeftMouseDrag(IETPoint pStartPos,
1033: IETPoint pCurrentPos) {
1034: // TODO Auto-generated method stub
1035: return false;
1036: }
1037:
1038: /* (non-Javadoc)
1039: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#handleLeftMouseDrop(org.netbeans.modules.uml.core.support.umlsupport.IETPoint, org.netbeans.modules.uml.core.metamodel.core.foundation.IElement[], boolean)
1040: */
1041: public boolean handleLeftMouseDrop(IETPoint ptCurrentPos,
1042: IElement[] pElements, boolean bMoving) {
1043: // TODO Auto-generated method stub
1044: return false;
1045: }
1046:
1047: /* (non-Javadoc)
1048: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#invalidate()
1049: */
1050: public void invalidate() {
1051: /* IDrawingAreaControl ctrl = getDrawingAreaControl();
1052:
1053: if (ctrl == null)
1054: return;
1055:
1056: TSEGraphWindow window = ctrl.getGraphWindow();
1057: if (window != null && this.getETUI() != null && this.getETUI().getOwner() == this)
1058: {
1059: window.addInvalidRegion(this);
1060: }
1061: */
1062: IDrawEngine engine = getEngine();
1063: if (engine != null) {
1064: engine.invalidate();
1065: }
1066: }
1067:
1068: /* (non-Javadoc)
1069: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#onContextMenu(org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenu, int, int)
1070: */
1071: public void onContextMenu(IProductContextMenu pContextMenu,
1072: int logicalX, int logicalY) {
1073: // TODO Auto-generated method stub
1074:
1075: }
1076:
1077: /* (non-Javadoc)
1078: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#onContextMenuHandleSelection(org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenu, org.netbeans.modules.uml.ui.support.contextmenusupport.IProductContextMenuItem)
1079: */
1080: public void onContextMenuHandleSelection(
1081: IProductContextMenu pContextMenu,
1082: IProductContextMenuItem pMenuItem) {
1083: // TODO Auto-generated method stub
1084:
1085: }
1086:
1087: /**
1088: * Called to notify the node that a link has been added.
1089: *
1090: * @param pLinkAboutToBeDeleted The link about to be deleted
1091: * @param bIsFromNode <code>true</code> if this is the from node.
1092: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#onPreDeleteLink(org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject, boolean)
1093: */
1094: public long onPreDeleteLink(IETGraphObject pLinkAboutToBeDeleted,
1095: boolean bIsFromNode) {
1096:
1097: IPresentationElement element = getPresentationElement();
1098: if (element instanceof IProductGraphPresentation) {
1099: IProductGraphPresentation presentation = (IProductGraphPresentation) element;
1100: IEventManager manager = presentation.getEventManager();
1101: if (manager != null) {
1102: manager.onPreDeleteLink(pLinkAboutToBeDeleted,
1103: bIsFromNode);
1104: }
1105: }
1106:
1107: return 0;
1108: }
1109:
1110: /* (non-Javadoc)
1111: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#performDeepSynch()
1112: */
1113: public long performDeepSynch() {
1114: IETGraphObjectUI ui = this .getETUI();
1115: if (ui != null) {
1116: IDrawEngine de = ui.getDrawEngine();
1117: if (de != null) {
1118: de.performDeepSynch();
1119:
1120: // Reset the text on all the labels, including changing the aliasing based on
1121: // the friendly names.
1122: ILabelManager pLabelManager = de.getLabelManager();
1123: if (pLabelManager != null) {
1124: pLabelManager.resetLabelsText();
1125: }
1126: }
1127: }
1128: return 0;
1129: }
1130:
1131: /* (non-Javadoc)
1132: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#resetDrawEngine(java.lang.String)
1133: */
1134: public long resetDrawEngine(String sInitializationString) {
1135: m_presentation.setModelElement(null);
1136: ETBaseUI.resetDrawEngine(sInitializationString, getETUI());
1137: return 0;
1138: }
1139:
1140: /* (non-Javadoc)
1141: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setEngineParent(com.tomsawyer.editor.TSEObjectUI)
1142: */
1143: public long setEngineParent(TSEObjectUI pObjectView) {
1144: // TODO Auto-generated method stub
1145: return 0;
1146: }
1147:
1148: /* (non-Javadoc)
1149: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setInitializationString(java.lang.String)
1150: */
1151: public void setInitializationString(String value) {
1152: // TODO Auto-generated method stub
1153:
1154: }
1155:
1156: /* (non-Javadoc)
1157: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#setSynchState(int)
1158: */
1159: public void setSynchState(int value) {
1160: mSynchState = value;
1161: }
1162:
1163: /* (non-Javadoc)
1164: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#transform(java.lang.String)
1165: */
1166: public IPresentationElement transform(String typeName) {
1167: // TODO Auto-generated method stub-didn't see the emplementation in C++
1168: return null;
1169: }
1170:
1171: /* (non-Javadoc)
1172: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject#validate(org.netbeans.modules.uml.core.metamodel.diagrams.IGraphObjectValidation)
1173: */
1174: public long validate(IGraphObjectValidation pValidationKind) {
1175: checkConnectionToPresentationElement(pValidationKind);
1176: checkDrawEngine(pValidationKind, true);
1177: return 0;
1178: }
1179:
1180: private void checkConnectionToPresentationElement(
1181: IGraphObjectValidation pValidationKind) {
1182: if (pValidationKind == null) {
1183: //error
1184: return;
1185: }
1186:
1187: boolean bCheckConnectionToElement = pValidationKind
1188: .getValidationKind(IDiagramValidateKind.DVK_VALIDATE_CONNECTIONTOELEMENT);
1189:
1190: // Check connection to our element
1191: if (bCheckConnectionToElement) {
1192: int dvResult = IDiagramValidateResult.DVR_INVALID;
1193:
1194: IPresentationElement pe = getPresentationElement();
1195:
1196: IGraphPresentation graphPE = null;
1197: if (graphPE instanceof IGraphPresentation)
1198: graphPE = (IGraphPresentation) pe;
1199:
1200: if (graphPE != null) {
1201: // Clear our cached ME so that a proper connection can be verified
1202: // graphPE.clearModelElementCache();
1203: }
1204:
1205: // Get the IElement for this graph object
1206: IElement element = TypeConversions
1207: .getElement((IETGraphObject) this );
1208:
1209: // #82727, 87841 validate element in case it was removed from repository
1210: // in a situation where delete notification was not propagated
1211: if (pe != null
1212: && element != null
1213: && element.getNode().getDocument() != null
1214: && UMLXMLManip.findElementByID(element.getNode()
1215: .getDocument(), element.getXMIID()) != null) {
1216: // See if the element knows about this presentation elment
1217: boolean bPEIsPresent = element.isPresent(pe);
1218: if (!bPEIsPresent) {
1219: // We've got to reconnect
1220: element.addPresentationElement(pe);
1221: bPEIsPresent = element.isPresent(pe);
1222: }
1223:
1224: if (bPEIsPresent) {
1225: dvResult = IDiagramValidateResult.DVR_VALID;
1226: }
1227: }
1228:
1229: pValidationKind
1230: .setValidationResult(
1231: IDiagramValidateKind.DVK_VALIDATE_CONNECTIONTOELEMENT,
1232: dvResult);
1233: }
1234: }
1235:
1236: private void checkDrawEngine(
1237: IGraphObjectValidation pValidationKind,
1238: boolean bAllowDeepSync) {
1239: if (pValidationKind == null) {
1240: // error
1241: return;
1242: }
1243:
1244: int dvrDrawEngine = IDiagramValidateResult.DVR_INVALID;
1245:
1246: // Get what we should validate and set the invalid/valid states to a default.
1247: boolean bCheckDrawEngine = pValidationKind
1248: .getValidationKind(IDiagramValidateKind.DVK_VALIDATE_DRAWENGINE);
1249:
1250: boolean bCheckResyncDeep = pValidationKind
1251: .getValidationKind(IDiagramValidateKind.DVK_VALIDATE_RESYNC_DEEP);
1252:
1253: // Check the draw engine and go deep if necessary
1254: if (bCheckDrawEngine) {
1255: IDrawEngine engine = getEngine();
1256: if (engine != null) {
1257: boolean bIsValid = engine
1258: .isDrawEngineValidForModelElement();
1259: if (bIsValid) {
1260: dvrDrawEngine = IDiagramValidateResult.DVR_VALID;
1261:
1262: if (bAllowDeepSync) {
1263: if (bCheckResyncDeep) {
1264: bIsValid = engine.validateNode();
1265: }
1266: }
1267: }
1268: }
1269: }
1270:
1271: if (bCheckDrawEngine) {
1272: pValidationKind.setValidationResult(
1273: IDiagramValidateKind.DVK_VALIDATE_DRAWENGINE,
1274: dvrDrawEngine);
1275: }
1276: if (bCheckResyncDeep) {
1277: // Set the resync deep invalid to tell the caller that we do have a deep resync function.
1278: // If we leave it alone the diagram validator doesn't call deep sync.
1279: pValidationKind.setValidationResult(
1280: IDiagramValidateKind.DVK_VALIDATE_RESYNC_DEEP,
1281: IDiagramValidateResult.DVR_INVALID);
1282: }
1283: }
1284:
1285: public void setSelected(boolean selected) {
1286: //if (this.getGraphWindow() != null && getGraphWindow().getCurrentState() instanceof TSEMoveSelectedState)
1287: if (this .getGraphWindow() != null
1288: && getGraphWindow().getCurrentTool() instanceof TSEMoveSelectedTool) {
1289: ETSystem.out
1290: .println("Warning: can not change selection lists while in TSEMoveSelectedState state.");
1291: return;
1292: }
1293: super .setSelected(selected);
1294: }
1295:
1296: public void moveTo(TSConstPoint pt) {
1297: // ETTSRectEx bounds = new ETTSRectEx(this.getBounds());
1298: TSRect bounds = new TSRect(this .getBounds());
1299: if (bounds != null) {
1300: bounds.setCenter(pt);
1301: this .setBounds(bounds);
1302: }
1303: }
1304:
1305: public void setBounds(TSConstRect bounds) {
1306: super .setBounds(bounds);
1307: }
1308:
1309: /* (non-Javadoc)
1310: * @see com.tomsawyer.drawing.TSDNode#addConnector()
1311: */
1312: public TSConnector addConnector() {
1313: TSConnector connector = new ETConnector(this );
1314: insert(connector);
1315:
1316: return connector;
1317: }
1318:
1319: public void remove(TSConnector connector) {
1320: super .remove(connector);
1321: }
1322:
1323: public void discard(TSConnector connector) {
1324: super .discard(connector);
1325: }
1326:
1327: public void discardAllConnectors() {
1328: super .discardAllConnectors();
1329: }
1330:
1331: /* (non-Javadoc)
1332: * @see com.tomsawyer.editor.TSEObject#getToolTipText()
1333: */
1334: public String getToolTipText() {
1335: // The Commented out area if for Debug purposes only.
1336:
1337: String retVal = super .getToolTipText();
1338: retVal += "<hr><br><b>Node Drawing Area Control:</b> ";
1339:
1340: IDrawingAreaControl ctrl = getDrawingAreaControl();
1341: if (ctrl != null) {
1342: retVal += ctrl.getName();
1343: } else {
1344: retVal += "<i>NULL</i>";
1345: }
1346:
1347: retVal += "<b>X</b>: " + getLeft();
1348: retVal += "<b>Y</b>: " + getTop();
1349: retVal += "<b>Width</b>: " + getWidth();
1350: retVal += "<b>Height</b>: " + getHeight();
1351:
1352: retVal += "<hr>";
1353: IPresentationElement element = this .getPresentationElement();
1354: if (element instanceof IGraphPresentation) {
1355: retVal += "<br>";
1356: retVal += "<b>Presentation Element:</b> #"
1357: + element.hashCode();
1358:
1359: IGraphPresentation pElement = (IGraphPresentation) element;
1360: IETGraphObjectUI ui = pElement.getUI();
1361: retVal += "<br><b>Node UI:</b> ";
1362: if (ui != null) {
1363: retVal += "#" + Integer.toHexString(ui.hashCode());
1364: } else {
1365: retVal += "<i>NULL</i>";
1366: }
1367: }
1368:
1369: retVal += "<hr>";
1370: IElement modelElement = element.getFirstSubject();
1371: ETList<IPresentationElement> elements = modelElement
1372: .getPresentationElements();
1373: retVal += "<b>Number Of Presentation Elements:</b> "
1374: + elements.size();
1375: int index = 0;
1376: for (IPresentationElement curElement : elements) {
1377: retVal += "<br>";
1378: retVal += "<b><font color=\"0000ff\">Presentation Drawing Area Control ["
1379: + index++ + "]:</font></b> ";
1380: if (curElement instanceof IGraphPresentation) {
1381: retVal += Integer.toHexString(curElement.hashCode())
1382: + " UI: ";
1383: IGraphPresentation pElement = (IGraphPresentation) curElement;
1384: IETGraphObjectUI ui = pElement.getUI();
1385: //IDrawingAreaControl ctrl2 = ui.getDrawingArea();
1386: if (ui != null) {
1387: retVal += Integer.toHexString(ui.hashCode());
1388: } else {
1389: retVal += "<i>NULL</i>";
1390: }
1391: } else {
1392: retVal += "<i>NULL</i>";
1393: }
1394: }
1395: return retVal;
1396:
1397: // //Disable label tooltips
1398: // return null;
1399: }
1400:
1401: /*
1402: * Returns the edge interfaces connected to this node.
1403: */
1404: public ETList<IETEdge> getEdges(boolean includeInEdges,
1405: boolean includeOutEdges) {
1406: // Because of recursive edges, we may have duplicates in this list.
1407: // So, filter out the duplicate edges.
1408:
1409: ETList<IETEdge> edges = new ETArrayList<IETEdge>();
1410: if (includeInEdges) {
1411: IteratorT<IETEdge> edgeIter = new IteratorT<IETEdge>(
1412: getInEdges());
1413: while (edgeIter.hasNext()) {
1414: IETEdge curEdge = edgeIter.next();
1415: if (edges.contains(curEdge) == false) {
1416: edges.add(curEdge);
1417: }
1418: }
1419: }
1420:
1421: if (includeOutEdges) {
1422: IteratorT<IETEdge> edgeIter = new IteratorT<IETEdge>(
1423: getOutEdges());
1424: while (edgeIter.hasNext()) {
1425: IETEdge curEdge = edgeIter.next();
1426: if (edges.contains(curEdge) == false) {
1427: edges.add(curEdge);
1428: }
1429: }
1430: }
1431: return edges;
1432: }
1433:
1434: /*
1435: * Returns all the edge interfaces connected to this node.
1436: */
1437: public ETList<IETEdge> getEdges() {
1438: return getEdges(true, true);
1439: }
1440:
1441: //jyothi - wrote to remove compilation error.. need to work on this
1442: public boolean isConnector() {
1443: return false;
1444: }
1445: }
|