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.diagramengines.diagramComponentEngine;
043:
044: import org.netbeans.modules.uml.common.generics.ETPairT;
045: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
046: import org.netbeans.modules.uml.core.metamodel.infrastructure.IPort;
047: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IInterface;
048: import org.netbeans.modules.uml.ui.products.ad.ADDrawEngines.ADEdgeDrawEngine;
049: import org.netbeans.modules.uml.ui.support.applicationmanager.IEdgePresentation;
050: import org.netbeans.modules.uml.ui.support.viewfactorysupport.DrawEngineArrowheadKindEnum;
051: import org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets;
052: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ModelElementChangedKind;
053: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
054:
055: /**
056: * @author josephg
057: *
058: */
059: public class PortProvidedInterfaceEdgeDrawEngine extends
060: ADEdgeDrawEngine {
061: /* (non-Javadoc)
062: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine#getDrawEngineID()
063: */
064: public String getDrawEngineID() {
065: return "PortProvidedInterfaceEdgeDrawEngine";
066: }
067:
068: /* (non-Javadoc)
069: * @see org.netbeans.modules.uml.ui.products.ad.drawengines.ETEdgeDrawEngine#getEndArrowKind()
070: */
071: protected int getEndArrowKind() {
072: return DrawEngineArrowheadKindEnum.DEAK_NO_ARROWHEAD;
073: }
074:
075: /* (non-Javadoc)
076: * @see org.netbeans.modules.uml.ui.products.ad.drawengines.ETEdgeDrawEngine#getLineKind()
077: */
078: protected int getLineKind() {
079: return DrawEngineArrowheadKindEnum.DEAK_NO_ARROWHEAD;
080: }
081:
082: /* (non-Javadoc)
083: * @see org.netbeans.modules.uml.ui.products.ad.drawengines.ETEdgeDrawEngine#getStartArrowKind()
084: */
085: protected int getStartArrowKind() {
086: return DrawEngineArrowheadKindEnum.DEAK_NO_ARROWHEAD;
087: }
088:
089: /* (non-Javadoc)
090: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine#isDrawEngineValidForModelElement()
091: */
092: public boolean isDrawEngineValidForModelElement() {
093: return getMetaTypeOfElement().compareTo("Interface") == 0;
094: }
095:
096: /* (non-Javadoc)
097: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IEdgeDrawEngine#getAllowReconnection()
098: */
099: public boolean getAllowReconnection() {
100: return true;
101: }
102:
103: /* (non-Javadoc)
104: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine#affectModelElementDeletion()
105: */
106: public void affectModelElementDeletion() {
107: ETPairT<IPort, IInterface> elements = getRelationshipElements();
108: if (elements != null) {
109: elements.getParamOne().removeProvidedInterface(
110: elements.getParamTwo());
111: }
112: }
113:
114: /* (non-Javadoc)
115: * @see org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine#modelElementHasChanged(org.netbeans.modules.uml.ui.support.viewfactorysupport.INotificationTargets)
116: */
117: public long modelElementHasChanged(INotificationTargets pTargets) {
118: if (pTargets == null)
119: return 0;
120:
121: IElement modelElement = pTargets.getChangedModelElement();
122: int nKind = pTargets.getKind();
123:
124: if (nKind == ModelElementChangedKind.MECK_ELEMENTADDEDTONAMESPACE) {
125: IEdgePresentation this EdgePresentation = this
126: .getEdgePresentationElement();
127:
128: if (this EdgePresentation != null) {
129: if (!this EdgePresentation.validateLinkEnds()) {
130: IDrawingAreaControl control = getDrawingArea();
131: if (control != null) {
132: control
133: .postDeletePresentationElement(this EdgePresentation);
134: }
135: }
136: }
137: }
138: return 0;
139: }
140:
141: protected ETPairT<IPort, IInterface> getRelationshipElements() {
142: IPort retPort = null;
143: IInterface retInterface = null;
144: IEdgePresentation this EdgePresentation = getEdgePresentationElement();
145: if (this EdgePresentation != null) {
146: ETPairT<IElement, IElement> endElements = this EdgePresentation
147: .getEdgeFromAndToElement(false);
148:
149: if (endElements.getParamOne() instanceof IPort) {
150: retPort = (IPort) endElements.getParamOne();
151: if (endElements.getParamTwo() instanceof IInterface) {
152: retInterface = (IInterface) endElements
153: .getParamTwo();
154: }
155: } else {
156: if (endElements.getParamTwo() instanceof IPort) {
157: retPort = (IPort) endElements.getParamTwo();
158: if (endElements.getParamOne() instanceof IInterface) {
159: retInterface = (IInterface) endElements
160: .getParamOne();
161: }
162: }
163: }
164: }
165: if (retPort != null && retInterface != null)
166: return new ETPairT<IPort, IInterface>(retPort, retInterface);
167:
168: return null;
169: }
170: }
|