001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.ui.products.ad.viewfactory;
043:
044: import java.awt.Color;
045: import java.awt.Graphics;
046: import java.awt.Rectangle;
047: import java.awt.RenderingHints;
048: import java.awt.Stroke;
049: import java.util.List;
050:
051: import org.netbeans.modules.uml.common.ETException;
052: import org.netbeans.modules.uml.common.generics.ETPairT;
053: import org.netbeans.modules.uml.core.metamodel.core.foundation.FactoryRetriever;
054: import org.netbeans.modules.uml.core.metamodel.core.foundation.ICreationFactory;
055: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
056: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
057: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
058: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationReference;
059: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
060: import org.netbeans.modules.uml.core.support.umlsupport.IETRect;
061: import org.netbeans.modules.uml.core.support.umlsupport.IStrings;
062: import org.netbeans.modules.uml.ui.products.ad.drawengines.ETDrawEngineFactory;
063: import org.netbeans.modules.uml.ui.products.ad.drawengines.ETDrawInfo;
064: import org.netbeans.modules.uml.ui.products.ad.graphobjects.ETNode;
065: import org.netbeans.modules.uml.ui.support.applicationmanager.DrawingFactory;
066: import org.netbeans.modules.uml.ui.support.applicationmanager.INodePresentation;
067: import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchive;
068: import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchiveDefinitions;
069: import org.netbeans.modules.uml.ui.support.archivesupport.IProductArchiveElement;
070: import org.netbeans.modules.uml.ui.support.relationshipVerification.INodeVerification;
071: import org.netbeans.modules.uml.ui.support.viewfactorysupport.DrawEngineLineKindEnum;
072: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ETRectEx;
073: import org.netbeans.modules.uml.ui.support.viewfactorysupport.GDISupport;
074: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
075: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo;
076: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
077: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode;
078: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNodeUI;
079: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ITSGraphObject;
080: import org.netbeans.modules.uml.ui.swing.drawingarea.ADGraphWindow;
081: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
082: import com.tomsawyer.editor.TSEGraphWindow;
083: import com.tomsawyer.editor.TSEObjectUI;
084: import com.tomsawyer.editor.TSENode;
085: import com.tomsawyer.editor.graphics.TSEGraphics;
086: import com.tomsawyer.editor.ui.TSENodeUI;
087: import com.tomsawyer.editor.ui.TSEDefaultNodeUI; //import com.tomsawyer.util.TSConstRect;
088: import com.tomsawyer.drawing.geometry.TSConstRect;
089: import com.tomsawyer.util.TSProperty;
090: import org.netbeans.modules.uml.core.support.Debug;
091:
092: //public class ETGenericNodeUI extends TSENodeUI implements IETNodeUI
093: public class ETGenericNodeUI extends TSEDefaultNodeUI implements
094: IETNodeUI {
095: public ETGenericNodeUI() {
096: super ();
097: }
098:
099: private final String ZERO_VALUE = "";
100:
101: private IDrawEngine drawEngine = null;
102: private String drawEngineClass = null;
103:
104: private String peidValue = this .ZERO_VALUE;
105: private String meidValue = this .ZERO_VALUE;
106: private String topLevelMEIDValue = this .ZERO_VALUE;
107: private String initStringValue = this .ZERO_VALUE;
108: private String m_ReloadedOwnerPresentationXMIID = this .ZERO_VALUE;
109: private IStrings m_PresentationReferenceReferredElements = null;
110: private boolean m_WasModelElementDeleted = false;
111: private boolean m_FailedToCreateDrawEngine = false;
112:
113: private IProductArchiveElement archiveElement;
114: private IElement modelElement = null;
115: private boolean m_resizeable = true;
116: protected RenderingHints qualityHints = new RenderingHints(
117: RenderingHints.KEY_ANTIALIASING,
118: RenderingHints.VALUE_ANTIALIAS_ON);
119:
120: /**
121: * This method returns the pixel size of the nodes grapples. The size of the
122: * grapples will be scaled according to the node graph zoom level.
123: */
124: public int getGrappleSize() {
125: int retVal = 0;
126:
127: IDrawingAreaControl ctrl = getDrawingArea();
128: if (ctrl != null) {
129: retVal = getGrappleSize(ctrl.getCurrentZoom());
130: }
131:
132: return retVal;
133: }
134:
135: public void draw(TSEGraphics graphics) {
136: IDrawEngine de = getDrawEngine();
137: if (de != null) {
138: RenderingHints prevHint = graphics.getRenderingHints();
139: qualityHints.put(RenderingHints.KEY_RENDERING,
140: RenderingHints.VALUE_RENDER_QUALITY);
141:
142: graphics.setRenderingHints(qualityHints);
143: IDrawInfo drawInfo = getDrawInfo(graphics);
144: // TODO: Determine what the DrawinToMainDrawingArea and AlwaysSetFont
145: // Should be set to.
146:
147: if (drawInfo != null) {
148: Rectangle clipRect = drawInfo.clip();
149: de.doDraw(drawInfo);
150: graphics.setClip(clipRect);
151: } else {
152: GDISupport
153: .frameRectangle(
154: graphics.getGraphics(),
155: ETBaseUI
156: .getDeviceBounds(graphics, this ),
157: DrawEngineLineKindEnum.DELK_DOT, 1,
158: Color.BLACK);
159: }
160: graphics.setRenderingHints(prevHint);
161: }
162: }
163:
164: /* (non-Javadoc)
165: * @see com.tomsawyer.editor.TSEObjectUI#drawSelectedOutline(com.tomsawyer.editor.graphics.TSEGraphics)
166: */
167: public void drawSelectedOutline(TSEGraphics graphics) {
168: if (this .getOwner() != null && graphics != null) {
169: Stroke pen = GDISupport.getLineStroke(
170: DrawEngineLineKindEnum.DELK_HATCHED, 1);
171: Stroke prevPen = graphics.getStroke();
172: graphics.setStroke(pen);
173: super .drawSelectedOutline(graphics);
174: graphics.setStroke(prevPen);
175: }
176: }
177:
178: /* (non-Javadoc)
179: * @see com.tomsawyer.editor.TSEObjectUI#drawSelected(com.tomsawyer.editor.graphics.TSEGraphics)
180: */
181: public void drawSelected(TSEGraphics graphics) {
182: super .drawSelected(graphics);
183: drawSelectedOutline(graphics);
184: }
185:
186: /*
187: * Returns the GraphWindow.
188: */
189: public TSEGraphWindow getGraphWindow() {
190: return ETBaseUI.getGraphWindow(this );
191: }
192:
193: /*
194: * Returns World points, (Logical)
195: */
196: public IETRect getLogicalBounds() {
197: return ETBaseUI.getLogicalBounds(this );
198: }
199:
200: /*
201: * Returns the device bounding rect.
202: */
203: public IETRect getDeviceBounds() {
204: return ETBaseUI.getDeviceBounds(this );
205: }
206:
207: /**
208: * Retrieves the graphics context for the node ui.
209: *
210: * @param graphics The TS graphics class.
211: * @return The graphics context.
212: */
213: public IDrawInfo getDrawInfo(TSEGraphics graphics) {
214: IDrawInfo retVal = ETBaseUI.getDrawInfo(graphics, this );
215:
216: if (retVal != null) {
217: retVal.setIsTransparent(isTransparent());
218: retVal.setIsBorderDrawn(isBorderDrawn());
219: }
220:
221: // TODO: Determine what the DrawinToMainDrawingArea and AlwaysSetFont
222: // Should be set to.
223:
224: return retVal;
225: }
226:
227: /**
228: * Retrieves the graphics context for the node ui.
229: *
230: * @return The graphics context.
231: */
232: public IDrawInfo getDrawInfo() {
233: TSEGraphWindow window = this .getGraphWindow();
234: if (window != null) {
235: Graphics g = window.getGraphics();
236: TSEGraphics tsGraphics;
237:
238: if (g instanceof TSEGraphics) {
239: tsGraphics = (TSEGraphics) g;
240:
241: } else if (g != null) {
242: tsGraphics = window.newGraphics(g);
243: } else {
244: tsGraphics = null;
245: }
246:
247: return getDrawInfo(tsGraphics);
248: }
249:
250: return null;
251: }
252:
253: public void reset() {
254: super .reset();
255: this .peidValue = this .ZERO_VALUE;
256: this .meidValue = this .ZERO_VALUE;
257: this .topLevelMEIDValue = this .ZERO_VALUE;
258: this .initStringValue = this .ZERO_VALUE;
259: this .drawEngine = null;
260: }
261:
262: public void copy(TSEObjectUI sourceUI) {
263: this .reset();
264:
265: super .copy(sourceUI);
266: ETGenericNodeUI sourceNodeUI = (ETGenericNodeUI) sourceUI;
267: this .meidValue = sourceNodeUI.meidValue;
268: this .topLevelMEIDValue = sourceNodeUI.topLevelMEIDValue;
269: this .modelElement = sourceNodeUI.modelElement;
270:
271: this .setInitStringValue(sourceNodeUI.getInitStringValue());
272: this .setDrawEngineClass(sourceNodeUI.getDrawEngineClass());
273: getDrawEngine().setParent(this );
274: }
275:
276: public List getProperties() {
277: /* jyothi added this as the presEleId is not getting populated in the .eltd file
278: List list = super.getProperties();
279: list.add(new TSProperty(IProductArchiveDefinitions.PRESENTATIONELEMENTID_STRING, this.peidValue));
280: return list;
281: */
282: List list = super .getProperties();
283: String value = null;
284: IPresentationElement pPE = ((IETGraphObject) getTSObject())
285: .getPresentationElement();
286: if (pPE != null) {
287: // Get the presentation el ement id
288: String presEleId = pPE.getXMIID();
289: if (presEleId != null && presEleId.length() > 0) {
290: value = presEleId;
291: }
292: }
293:
294: list
295: .add(new TSProperty(
296: IProductArchiveDefinitions.PRESENTATIONELEMENTID_STRING,
297: value));
298: return list;
299: }
300:
301: public void setProperty(TSProperty property) {
302: //String attrString = (String) property.getValue(); //jyothi
303: if (IProductArchiveDefinitions.PRESENTATIONELEMENTID_STRING
304: .equals(property.getName())) {
305: String attrString = (String) property.getValue();
306: this .peidValue = attrString;
307: } else {
308: super .setProperty(property);
309: }
310: }
311:
312: public List getChangedProperties() {
313: List list = super .getChangedProperties();
314:
315: IPresentationElement pPE = ((IETGraphObject) getTSObject())
316: .getPresentationElement();
317: if (pPE != null) {
318: // Get the presentation element id
319: String presEleId = pPE.getXMIID();
320: if (presEleId != null && presEleId.length() > 0) {
321: list
322: .add(new TSProperty(
323: IProductArchiveDefinitions.PRESENTATIONELEMENTID_STRING,
324: presEleId));
325: }
326: }
327: return list;
328: }
329:
330: public IDrawEngine getDrawEngine() {
331: if (drawEngine == null) {
332: try {
333: this .initDrawEngine();
334: } catch (Exception e) {
335: e.printStackTrace();
336: return null;
337: }
338: }
339:
340: return drawEngine;
341: }
342:
343: public String getDrawEngineClass() {
344: return drawEngineClass;
345: }
346:
347: public void setDrawEngineClass(String string) {
348: drawEngineClass = string;
349: }
350:
351: public void setDrawEngine(IDrawEngine newDrawEngine) {
352: try {
353: if (newDrawEngine != drawEngine) {
354: drawEngine = newDrawEngine;
355: // if (drawEngine != null)
356: // drawEngine.init();
357: }
358: } catch (Exception e) {
359: e.printStackTrace();
360: }
361: }
362:
363: public String getPeidValue() {
364: return peidValue;
365: }
366:
367: private boolean initDrawEngine() throws ETException {
368: if (this .getDrawEngineClass() != null
369: && getDrawEngineClass().length() > 0) {
370: this .setDrawEngine(ETDrawEngineFactory
371: .createDrawEngine(this ));
372: return this .drawEngine != null;
373: } else
374: return false;
375: }
376:
377: public String getMeidValue() {
378: return this .meidValue;
379: }
380:
381: public String getTopLevelMEIDValue() {
382: return this .topLevelMEIDValue;
383: }
384:
385: public IElement getModelElement() {
386: return this .modelElement;
387: }
388:
389: public void setModelElement(IElement element) {
390: this .modelElement = element;
391: }
392:
393: public IProductArchiveElement getArchiveElement() {
394: return this .archiveElement;
395: }
396:
397: public void setArchiveElement(IProductArchiveElement element) {
398: this .archiveElement = element;
399: this .readFromArchive(element);
400: }
401:
402: private void readFromArchive(IProductArchiveElement element) {
403:
404: this .meidValue = element
405: .getAttributeString(IProductArchiveDefinitions.MEID_STRING);
406: this .topLevelMEIDValue = element
407: .getAttributeString(IProductArchiveDefinitions.TOPLEVELID_STRING);
408: this
409: .setInitStringValue(element
410: .getAttributeString(IProductArchiveDefinitions.INITIALIZATIONSTRING_STRING));
411:
412: IProductArchiveElement engineElement = element
413: .getElement(IProductArchiveDefinitions.ENGINENAMEELEMENT_STRING);
414: this
415: .setDrawEngineClass(engineElement
416: .getAttributeString(IProductArchiveDefinitions.ENGINENAMEATTRIBUTE_STRING));
417: }
418:
419: public void readFromArchive(IProductArchive prodArch,
420: IProductArchiveElement archEle) {
421: archiveElement = archEle;
422: ETBaseUI.readFromArchive(prodArch, archEle, this );
423: }
424:
425: public void writeToArchive(IProductArchive prodArch,
426: IProductArchiveElement archEle) {
427: ETBaseUI.writeToArchive(prodArch, archEle, this );
428: }
429:
430: /**
431: * Creates a new IPresentationElement
432: *
433: * @param pElement Not used
434: * @param pElem [out,retval] Creates the appropriate IPresentationElement for this node (right now it's
435: * always an INodePresentation.)
436: */
437: public IPresentationElement createPresentationElement(IElement pEle) {
438: IPresentationElement retObj = null;
439: INodePresentation nodePres = DrawingFactory
440: .retrieveNodePresentationMetaType();
441: if (nodePres != null) {
442: nodePres.setTSNode((ETNode) getTSObject());
443: retObj = nodePres;
444: }
445: return retObj;
446: }
447:
448: public IDrawingAreaControl getDrawingArea() {
449: return ETBaseUI.getDrawingArea(this );
450: }
451:
452: public void setDrawingArea(IDrawingAreaControl control) {
453: // We don't need to store this anymore.
454: //this.drawingArea = control;
455: }
456:
457: public String getInitStringValue() {
458: return this .initStringValue;
459: }
460:
461: public void setInitStringValue(String string) {
462: this .initStringValue = string;
463: }
464:
465: public boolean isAnnotationEditable() {
466: return false;
467: }
468:
469: public ITSGraphObject getTSObject() {
470: return getOwner() instanceof ITSGraphObject ? (ITSGraphObject) getOwner()
471: : null;
472: }
473:
474: /// Returns the Model Element XMIID that was loaded from the file.
475: public String getReloadedModelElementXMIID() {
476: return meidValue;
477: }
478:
479: /// Sets the Model Element XMIID that will be persisted to the file.
480: public void setReloadedModelElementXMIID(String newVal) {
481: meidValue = newVal;
482: }
483:
484: /// Returns the Toplevel Element XMIID that was loaded from the file.
485: public String getReloadedTopLevelXMIID() {
486: return topLevelMEIDValue;
487: }
488:
489: /// Sets the Toplevel Element XMIID that will be persisted to the file.
490: public void setReloadedTopLevelXMIID(String newVal) {
491: topLevelMEIDValue = newVal;
492: }
493:
494: /// Returns the Toplevel Element XMIID that was loaded from the file.
495: public String getReloadedPresentationXMIID() {
496: return peidValue;
497: }
498:
499: /// Sets the Toplevel Element XMIID that will be persisted to the file.
500: public void setReloadedPresentationXMIID(String newVal) {
501: peidValue = newVal;
502: }
503:
504: /// Returns the Toplevel Element XMIID that was loaded from the file.
505: public String getReloadedOwnerPresentationXMIID() {
506: return m_ReloadedOwnerPresentationXMIID;
507: }
508:
509: /// Sets the Toplevel Element XMIID that will be persisted to the file.
510: public void setReloadedOwnerPresentationXMIID(String newVal) {
511: m_ReloadedOwnerPresentationXMIID = newVal;
512: }
513:
514: public IStrings getReferredElements() {
515: return m_PresentationReferenceReferredElements;
516: }
517:
518: public void setReferredElements(IStrings newVal) {
519: m_PresentationReferenceReferredElements = newVal;
520: }
521:
522: public boolean getWasModelElementDeleted() {
523: return m_WasModelElementDeleted;
524: }
525:
526: public void setWasModelElementDeleted(boolean newVal) {
527: m_WasModelElementDeleted = newVal;
528: }
529:
530: public boolean getFailedToCreateDrawEngine() {
531: return m_FailedToCreateDrawEngine;
532: }
533:
534: public void setFailedToCreateDrawEngine(boolean newVal) {
535: m_FailedToCreateDrawEngine = newVal;
536: }
537:
538: /**
539: * This routine is called when an object needs to be created from scratch. The user has dropped
540: * a TS node on the tree and we need to create the appropriate model element and presentation elements and
541: * tie them together. After all that is done look at the initialization string and create the correct engine.
542: *
543: * @param pNamespace [in] The namespace to add the new item to
544: * @param sInitializationString [in] The init string used to create this node
545: * @param pCreatedPresentationElement [out] The presentatation element created if all goes well.
546: * @param pCreatedElement [out] The model element created if all goes well.
547: */
548: public IElement createNew(INamespace space, String initStr) {
549: IElement retEle = null;
550: IDrawingAreaControl control = getDrawingArea();
551: String metaType = ETBaseUI.getMetaType(this );
552: IETNode etObj = (IETNode) getTSObject();
553: IDiagram pDia = null;
554: if (control != null) {
555: pDia = control.getDiagram();
556: }
557:
558: INodeVerification pNodeVer = getNodeVerification();
559: IPresentationElement presEle = null;
560: if (pDia != null && pNodeVer != null) {
561: ETPairT<IElement, IPresentationElement> result = pNodeVer
562: .createAndVerify(pDia, etObj, space, metaType,
563: initStr);
564: if (result != null) {
565: retEle = result.getParamOne();
566: presEle = result.getParamTwo();
567: }
568: }
569:
570: // If we have a good model element then create the presentation element and
571: // hook the two up.
572: if (retEle != null) {
573: IPresentationElement pEle = createPresentationElement(retEle);
574: if (pEle != null) {
575: etObj.setPresentationElement(pEle);
576: pEle.addSubject(retEle);
577: if (presEle != null) {
578: IPresentationReference pRef = org.netbeans.modules.uml.ui.support.PresentationReferenceHelper
579: .createPresentationReference(presEle, pEle);
580: }
581: }
582: }
583:
584: // No need to perform any synchronization logic while
585: // this element is new
586: //setSynchState(SSK_IN_SYNCH_DEEP);
587:
588: return retEle;
589: }
590:
591: /**
592: * Creates the appropriate EdgeVerification
593: *
594: * @param pVerif [out,retval] The returned, created edge verification created through the factory
595: */
596: private INodeVerification getNodeVerification() {
597: INodeVerification retObj = null;
598: ICreationFactory factory = FactoryRetriever.instance()
599: .getCreationFactory();
600: if (factory != null) {
601: Object obj = factory.retrieveEmptyMetaType(
602: "RelationshipVerification", "NodeVerification",
603: null);
604: if (obj != null && obj instanceof INodeVerification) {
605: retObj = (INodeVerification) obj;
606: }
607: }
608: return retObj;
609: }
610:
611: public void setResizable(boolean resizeable) {
612: m_resizeable = resizeable;
613: }
614:
615: public boolean resizable() {
616: return m_resizeable;
617: }
618:
619: public boolean isResizable() {
620: return super .isResizable() && resizable();
621: }
622:
623: public String getFormattedText() {
624: return super .getFormattedText();
625: }
626:
627: /*
628: * (non-Javadoc)
629: * @see org.netbeans.modules.uml.ui.products.ad.viewfactory.IETGraphObjectUI#isOnTheScreen(com.tomsawyer.editor.graphics.TSEGraphics)
630: */
631: public boolean isOnTheScreen(TSEGraphics g) {
632: return ETBaseUI.isOnTheScreen(g, this );
633: }
634:
635: /**
636: * Gives the draw engine the chance to setup the node for the first time.
637: */
638: public void setOwner(com.tomsawyer.editor.TSENode tSENode) {
639: super .setOwner(tSENode);
640:
641: IDrawEngine engine = getDrawEngine();
642: if (engine != null) {
643: engine.setupOwner();
644: }
645: }
646:
647: protected void nullifyOwner() {
648: super .nullifyOwner();
649:
650: Debug.out.println("Nullifing the Owner");
651: }
652: }
|