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.infrastructure.coreinfrastructure.IClassifier;
046: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IDerivation;
047: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETGraphObject;
048: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IETNode;
049: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
050: import org.netbeans.modules.uml.ui.swing.drawingarea.IReconnectEdgeContext;
051:
052: /**
053: * @author sumitabhk
054: *
055: */
056: public class DerivationEdgePresentation extends EdgePresentation {
057:
058: /**
059: * Verifies that this link has valid ends.
060: *
061: * @param bIsValid [out,retval] true if the ends of this link match the underlying metadata
062: */
063: public boolean validateLinkEnds() {
064: boolean isValid = false;
065: if (isDerivation()) {
066: isValid = validateSimpleLinkEnds();
067: }
068: return isValid;
069: }
070:
071: /**
072: * Try to reconnect the link to valid objects.
073: *
074: * @param bSuccessfullyReconnected [out,retval] true if this link was successfully connected.
075: *
076: * @return HRESULT
077: */
078: public boolean reconnectLinkToValidNodes() {
079: boolean success = false;
080: if (isDerivation()) {
081: success = reconnectSimpleLinkToValidNodes();
082: }
083: return success;
084: }
085:
086: /**
087: * Try to reconnect the link from pOldNode to pNewNode.
088: *
089: * @param pContext [in] Information about how the edge was reconnected
090: * @param bSuccessfullyReconnected [out,retval] Set to true to allow this reconnect to succeed.
091: *
092: * @return HRESULT
093: */
094: public boolean reconnectLink(Object dispContext) {
095: boolean success = false;
096: IETNode oldNode = null;
097: IETNode newNode = null;
098: IETNode anchorNode = null;
099: if (dispContext instanceof IReconnectEdgeContext) {
100: IReconnectEdgeContext pContext = (IReconnectEdgeContext) dispContext;
101: oldNode = pContext.getPreConnectNode();
102: newNode = pContext.getProposedEndNode();
103: anchorNode = pContext.getAnchoredNode();
104:
105: // Allow the target draw engine to determine if connectors should be created
106: setReconnectConnectorFlag(pContext);
107: }
108:
109: if (oldNode != null && newNode != null && anchorNode != null) {
110: if (isDerivation()) {
111: IElement pEdgeElement = null;
112: IElement pFromNodeEle = null;
113: IElement pToNodeEle = null;
114:
115: // Get the elements for this PE's model element and the model element of
116: // the from and to nodes.
117: pEdgeElement = getModelElement();
118: pFromNodeEle = TypeConversions.getElement(oldNode);
119: pToNodeEle = TypeConversions.getElement(newNode);
120:
121: if (pEdgeElement != null && pFromNodeEle != null
122: && pToNodeEle != null) {
123: if (pToNodeEle instanceof IClassifier
124: && pEdgeElement instanceof IDerivation) {
125: IClassifier pToNodeClassifier = (IClassifier) pToNodeEle;
126: IDerivation pDerivation = (IDerivation) pEdgeElement;
127:
128: IClassifier pDerivedClassifier = null;
129: IClassifier pTemplate = null;
130: IClassifier pCurrEle = null;
131:
132: pDerivedClassifier = pDerivation
133: .getDerivedClassifier();
134: pTemplate = pDerivation.getTemplate();
135: if (pDerivedClassifier != null
136: && pTemplate != null) {
137: boolean bFromNodeDerivedClassifier = false;
138: boolean bFromNodeTemplate = false;
139:
140: // See if the node we're disconnecting is the implementing classifier or Template
141: bFromNodeDerivedClassifier = pDerivedClassifier
142: .isSame(pFromNodeEle);
143: bFromNodeTemplate = pTemplate
144: .isSame(pFromNodeEle);
145:
146: if (bFromNodeDerivedClassifier) {
147: pDerivation
148: .setDerivedClassifier(pToNodeClassifier);
149:
150: // Verify the change took place
151: pCurrEle = pDerivation
152: .getDerivedClassifier();
153: success = pToNodeClassifier
154: .isSame(pCurrEle);
155: }
156:
157: if (bFromNodeTemplate) {
158: pDerivation
159: .setTemplate(pToNodeClassifier);
160:
161: // Verify the change took place
162: pCurrEle = pDerivation.getTemplate();
163: success = pToNodeClassifier
164: .isSame(pCurrEle);
165: }
166: }
167: }
168: }
169: }
170: }
171: return success;
172: }
173:
174: /**
175: * Verify this guy is a Derivation.
176: */
177: public boolean isDerivation() {
178: boolean retVal = false;
179: IETGraphObject pETElement = getETGraphObject();
180: if (pETElement != null) {
181: IElement pEdgeElement = TypeConversions
182: .getElement(pETElement);
183: if (pEdgeElement instanceof IDerivation) {
184: retVal = true;
185: }
186: }
187: return retVal;
188: }
189:
190: }
|