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.support.applicationmanager;
043:
044: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
045: import org.netbeans.modules.uml.core.metamodel.core.foundation.PresentationElement;
046: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram;
047: import org.netbeans.modules.uml.core.support.umlutils.ETList;
048: import org.netbeans.modules.uml.ui.products.ad.viewfactory.IETGraphObjectUI;
049: import org.netbeans.modules.uml.ui.support.drawingproperties.IColorProperty;
050: import org.netbeans.modules.uml.ui.support.drawingproperties.IDrawingPropertyProvider;
051: import org.netbeans.modules.uml.ui.support.drawingproperties.IFontProperty;
052: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
053: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
054: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
055: import org.netbeans.modules.uml.ui.support.drawingproperties.IDrawingProperty;
056: import com.tomsawyer.editor.ui.TSENodeUI;
057: import com.tomsawyer.editor.ui.TSEEdgeUI;
058: import com.tomsawyer.editor.TSEObject;
059: import com.tomsawyer.editor.TSEObjectUI;
060:
061: /*
062: *
063: * @author KevinM
064: *
065: */
066: public abstract class GraphPresentation extends PresentationElement
067: implements IGraphPresentation, IDrawingPropertyProvider {
068:
069: //private IETGraphObjectUI m_ui = null;
070:
071: /**
072: *
073: */
074: public GraphPresentation() {
075: super ();
076: }
077:
078: /* (non-Javadoc)
079: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#getModelElement()
080: */
081: public IElement getModelElement() {
082: IETGraphObjectUI ui = getUI();
083:
084: return ui != null ? ui.getModelElement() : null;
085: }
086:
087: /* (non-Javadoc)
088: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#setModelElement(null)
089: */
090: public void setModelElement(IElement value) {
091: IETGraphObjectUI ui = getUI();
092: if (ui != null) {
093: ui.setModelElement(value);
094: }
095: }
096:
097: /**
098: *
099: * Returns the first element on the subjects collection.
100: *
101: * @param subject[out] the first element in the list
102: *
103: * @return HRESULTs
104: *
105: */
106: public IElement getFirstSubject() {
107: IElement retVal = getModelElement();
108:
109: if (retVal == null) {
110: IElement pElement = super .getFirstSubject();
111:
112: // Verify the connection from the ME to the PE. This'll fail if our parent
113: if (pElement != null) {
114: // CComPtr < IPresentationElement > pPE;
115: // _VH(GetPEInterface(&pPE));
116:
117: boolean bPEIsPresent = pElement.isPresent(this );
118: if (bPEIsPresent == false) {
119: // We've got to reconnect
120: pElement.addPresentationElement(this );
121: }
122:
123: retVal = pElement;
124: setModelElement(pElement);
125: }
126: }
127:
128: return retVal;
129: }
130:
131: /* (non-Javadoc)
132: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#getIsOnDiagram(org.netbeans.modules.uml.core.metamodel.diagrams.IDiagram)
133: */
134: public boolean getIsOnDiagram(IDiagram pDiagram) {
135: boolean retVal = false;
136:
137: IETGraphObjectUI ui = getUI();
138: if (ui != null) {
139: if ((ui.getTSObject() != null)
140: && (ui.getDrawEngine() != null)) {
141: IDiagram assocDiagram = ui.getDrawEngine().getDiagram();
142: if (assocDiagram == pDiagram) {
143: retVal = true;
144: }
145: }
146: }
147: return retVal;
148: }
149:
150: /* (non-Javadoc)
151: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#getIsOnDiagramFilename(java.lang.String)
152: */
153: public boolean getIsOnDiagramFilename(String sFullFilename) {
154: IETGraphObjectUI ui = getUI();
155: return ui != null && ui.getDrawEngine() != null ? ui
156: .getDrawEngine().getDiagram().getFilename().equals(
157: sFullFilename) : false;
158: }
159:
160: /* (non-Javadoc)
161: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#getSelected()
162: */
163: public boolean getSelected() {
164: try {
165: IETGraphObjectUI ui = getUI();
166: return ui != null && ui.getTSObject() != null ? ui
167: .getTSObject().isSelected() : false;
168: } catch (Exception e) {
169: return false;
170: }
171: }
172:
173: /* (non-Javadoc)
174: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#setSelected(boolean)
175: */
176: public void setSelected(boolean value) {
177: try {
178: IETGraphObjectUI ui = getUI();
179: if (ui != null && ui.getDrawEngine() != null) {
180: ui.getDrawEngine().getParent().getOwner().setSelected(
181: value);
182: }
183: } catch (Exception e) {
184: }
185: }
186:
187: /* (non-Javadoc)
188: * @see org.netbeans.modules.uml.ui.support.applicationmanager.ILabelPresentation#invalidate()
189: */
190: public void invalidate() {
191: }
192:
193: protected boolean isNode() {
194: return getUI() instanceof TSENodeUI;
195: }
196:
197: protected boolean isEdge() {
198: return getUI() instanceof TSEEdgeUI;
199: }
200:
201: // public IETGraphObjectUI getUI()
202: // {
203: // return m_ui;
204: // }
205:
206: /* (non-Javadoc)
207: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#getDrawEngine()
208: */
209: public IDrawEngine getDrawEngine() {
210: return getUI() != null ? getUI().getDrawEngine() : null;
211: }
212:
213: /* (non-Javadoc)
214: * @see org.netbeans.modules.uml.ui.support.applicationmanager.IGraphPresentation#getETGraphObject()
215: */
216: public IETGraphObject getETGraphObject() {
217: IETGraphObject retVal = null;
218: TSEObjectUI ui = (TSEObjectUI) getUI();
219:
220: TSEObject tssGraphObj = ui != null ? ui.getOwner() : null;
221: if (tssGraphObj instanceof IETGraphObject) {
222: retVal = (IETGraphObject) tssGraphObj;
223: }
224: return retVal;
225: }
226:
227: /**
228: * Called when the element connected to this PE has possibly been reparented to another document as a result of SCC operations.")]
229: */
230: public void externalElementLoaded() {
231: // Just clear out our cached model element. When the user checks in/out of SCC the elements
232: // selected go into another document. The SCCIntegrator will handle those element to make sure
233: // any in memory objects get their dom node changed, but not children. So, for instance, if
234: // you check in an end of a generalization, the generalization will NOT get it's DOM node changed.
235: // So we have to loop over all PE's during SCC events and clear out the ME cache on everything.
236: clearModelElementCache();
237:
238: // Now get the first subject to re-establish the cache and verify the connection from the PE
239: // to the ME and back.
240: IElement pTempElement = getFirstSubject();
241: }
242:
243: /**
244: * Clear model element cache
245: */
246: public void clearModelElementCache() {
247: // Clear out the cached model element. This is done in several spots. For instance, if we're
248: // checking the connection to the model element it defeats purposes to use a cached element.
249: setModelElement(null);
250: }
251:
252: // IDrawingPropertyProvider
253: public ETList<IDrawingProperty> getDrawingProperties() {
254: ETList<IDrawingProperty> pProperties = null;
255:
256: IDrawEngine pDE = getDrawEngine();
257: if (pDE != null) {
258: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
259: pProperties = pProvider.getDrawingProperties();
260: }
261:
262: return pProperties;
263: }
264:
265: public void saveColor(String sDrawEngineType, String sResourceName,
266: int nColor) {
267: IDrawEngine pDE = getDrawEngine();
268: if (pDE != null) {
269: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
270: pProvider.saveColor(sDrawEngineType, sResourceName, nColor);
271: }
272: }
273:
274: public void saveColor2(IColorProperty pProperty) {
275: IDrawEngine pDE = getDrawEngine();
276: if (pDE != null) {
277: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
278: pProvider.saveColor2(pProperty);
279: }
280: }
281:
282: public void saveFont(String sDrawEngineName, String sResourceName,
283: String sFaceName, int nHeight, int nWeight,
284: boolean bItalic, int nColor) {
285: IDrawEngine pDE = getDrawEngine();
286: if (pDE != null) {
287: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
288: pProvider.saveFont(sDrawEngineName, sResourceName,
289: sFaceName, nHeight, nWeight, bItalic, nColor);
290: }
291: }
292:
293: public void saveFont2(IFontProperty pProperty) {
294: IDrawEngine pDE = getDrawEngine();
295: if (pDE != null) {
296: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
297: pProvider.saveFont2(pProperty);
298: }
299: }
300:
301: public void resetToDefaultResource(String sDrawEngineName,
302: String sResourceName, String sResourceType) {
303: IDrawEngine pDE = getDrawEngine();
304: if (pDE != null) {
305: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
306: pProvider.resetToDefaultResource(sDrawEngineName,
307: sResourceName, sResourceType);
308: }
309: }
310:
311: public void resetToDefaultResources() {
312: IDrawEngine pDE = getDrawEngine();
313: if (pDE != null) {
314: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
315: pProvider.resetToDefaultResources();
316: }
317: }
318:
319: public void resetToDefaultResources2(String sDrawEngineName) {
320: IDrawEngine pDE = getDrawEngine();
321: if (pDE != null) {
322: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
323: pProvider.resetToDefaultResources2(sDrawEngineName);
324: }
325: }
326:
327: public void dumpToFile(String sFile, boolean bDumpChildren,
328: boolean bAppendToExistingFile) {
329: IDrawEngine pDE = getDrawEngine();
330: if (pDE != null) {
331: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
332: pProvider.dumpToFile(sFile, bDumpChildren,
333: bAppendToExistingFile);
334: }
335: }
336:
337: public boolean displayFontDialog(IFontProperty pProperty) {
338: IDrawEngine pDE = getDrawEngine();
339: if (pDE != null) {
340: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
341: return pProvider.displayFontDialog(pProperty);
342: } else {
343: return false;
344: }
345: }
346:
347: public boolean displayColorDialog(IColorProperty pProperty) {
348: IDrawEngine pDE = getDrawEngine();
349: if (pDE != null) {
350: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
351: return pProvider.displayColorDialog(pProperty);
352: } else {
353: return false;
354: }
355:
356: }
357:
358: public void invalidateProvider() {
359: IDrawEngine pDE = getDrawEngine();
360: if (pDE != null) {
361: IDrawingPropertyProvider pProvider = (IDrawingPropertyProvider) pDE;
362: pProvider.invalidateProvider();
363: }
364: }
365: }
|