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.drawengines;
043:
044: import java.awt.Color;
045: import java.awt.event.ActionEvent;
046:
047: import org.netbeans.modules.uml.core.metamodel.core.constructs.IInclude;
048: import org.netbeans.modules.uml.core.metamodel.core.constructs.IUseCase;
049: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
050: import org.netbeans.modules.uml.ui.products.ad.application.IMenuManager;
051: import org.netbeans.modules.uml.ui.products.ad.application.action.ContextMenuActionClass;
052: import org.netbeans.modules.uml.ui.support.NodeEndKindEnum;
053: import org.netbeans.modules.uml.ui.support.applicationmanager.IEdgePresentation;
054: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo;
055: import org.netbeans.modules.uml.ui.support.viewfactorysupport.DrawEngineArrowheadKindEnum;
056: import org.netbeans.modules.uml.ui.support.viewfactorysupport.DrawEngineLineKindEnum;
057:
058: /**
059: * @author jingmingm
060: *
061: */
062: public class ETIncludeEdgeDrawEngine extends ETEdgeDrawEngine {
063: public String getElementType() {
064: String type = super .getElementType();
065: if (type == null) {
066: type = new String("Include");
067: }
068: return type;
069: }
070:
071: /*
072: * (non-Javadoc)
073: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine#doDraw(org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawInfo)
074: */
075: public void doDraw(IDrawInfo drawInfo) {
076: super .doDraw(drawInfo);
077: }
078:
079: /*
080: * (non-Javadoc)
081: * @see org.netbeans.modules.uml.ui.products.ad.drawengines.ETEdgeDrawEngine#getLineKind()
082: */
083: protected int getLineKind() {
084: return DrawEngineLineKindEnum.DELK_DASH;
085: }
086:
087: /*
088: * (non-Javadoc)
089: * @see org.netbeans.modules.uml.ui.products.ad.drawengines.ETEdgeDrawEngine#getEndArrowKind()
090: */
091: protected int getEndArrowKind() {
092: return DrawEngineArrowheadKindEnum.DEAK_UNFILLEDARROW;
093: }
094:
095: /*
096: * (non-Javadoc)
097: * @see org.netbeans.modules.uml.ui.products.ad.application.action.IETContextMenuHandler#setSensitivityAndCheck(java.lang.String, org.netbeans.modules.uml.ui.products.ad.application.action.ContextMenuActionClass)
098: */
099: public boolean setSensitivityAndCheck(String id,
100: ContextMenuActionClass pClass) {
101: boolean bFlag = handleStandardLabelSensitivityAndCheck(id,
102: pClass);
103: if (!bFlag) {
104: bFlag = super .setSensitivityAndCheck(id, pClass);
105: }
106:
107: return bFlag;
108: }
109:
110: /*
111: * (non-Javadoc)
112: * @see org.netbeans.modules.uml.ui.products.ad.application.action.IETContextMenuHandler#onHandleButton(java.awt.event.ActionEvent, java.lang.String)
113: */
114: public boolean onHandleButton(ActionEvent e, String id) {
115: boolean handled = handleStandardLabelSelection(e, id);
116: if (!handled) {
117: handled = super .onHandleButton(e, id);
118: }
119: return handled;
120: }
121:
122: /*
123: * (non-Javadoc)
124: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine#onContextMenu(org.netbeans.modules.uml.ui.products.ad.application.IMenuManager)
125: */
126: public void onContextMenu(IMenuManager manager) {
127: // Add the stereotype label pullright
128: addStandardLabelsToPullright(StandardLabelKind.SLK_ALL, manager);
129:
130: super .onContextMenu(manager);
131: }
132:
133: /**
134: * This is the name of the drawengine used when storing and reading from the product archive
135: *
136: * @param sID A unique identifier for this draw engine. Used when persisting to the etlp file.
137: */
138: public String getDrawEngineID() {
139: return "IncludeEdgeDrawEngine";
140: }
141:
142: /**
143: * Verify the ends are correct
144: */
145: public void verifyEdgeEnds() {
146: IEdgePresentation pPE = getIEdgePresentation();
147: IElement modEle = pPE != null ? pPE.getFirstSubject() : null;
148:
149: if (modEle instanceof IInclude) {
150: IInclude pInclude = (IInclude) modEle;
151: IUseCase pBase = pInclude.getBase();
152: IUseCase pAddition = pInclude.getAddition();
153:
154: // This edge is a dashed line with an arrowhead on the base end
155: int endKind = pPE.getNodeEnd(pBase);
156: if (endKind == NodeEndKindEnum.NEK_TO) {
157: if (!isParentDiagramReadOnly()) {
158: // This is wrong. It ends up with an incorrect parent/child relationship.
159: // Switch it unless the diagram is readonly
160: postSwapEdgeEnds();
161: }
162: }
163: }
164: }
165:
166: /**
167: * Is this draw engine valid for the element it is representing?
168: *
169: * @param bIsValid[in] true if this draw engine can correctly represent the attached model element.
170: */
171: public boolean isDrawEngineValidForModelElement() {
172: String metaType = getMetaTypeOfElement();
173: return metaType != null && metaType.equals("Include");
174: }
175:
176: /**
177: * Returns the metatype of the label manager we should use
178: *
179: * @param return The metatype in essentialconfig.etc that defines the label manager
180: */
181: public String getManagerMetaType(int nManagerKind) {
182: return nManagerKind == MK_LABELMANAGER ? "SimpleStereotypeAndNameLabelManager"
183: : "";
184: }
185:
186: /**
187: * The forced stereotype text on the label manager
188: *
189: * @param return The stereotype text that should appear in a label - readonly
190: */
191: protected String getForcedStereotypeText() {
192: String text = "";
193: IElement modEle = getFirstModelElement();
194: if (modEle != null) {
195: String metaType = modEle.getElementType();
196: if (metaType != null && metaType.equals("Include")) {
197: text = "include";
198: }
199: }
200: return text;
201: }
202:
203: /* (non-Javadoc)
204: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine#initResources()
205: */
206: public void initResources() {
207: this .setLineColor("includeedgecolor", Color.BLACK);
208: super.initResources();
209: }
210: }
|