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: /*
043: * Created on Jan 26, 2004
044: *
045: */
046: package org.netbeans.modules.uml.ui.controls.drawingarea;
047:
048: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
049: import org.netbeans.modules.uml.core.metamodel.core.foundation.IPresentationElement;
050: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAggregation;
051: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IAssociation;
052: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
053: import org.netbeans.modules.uml.ui.support.applicationmanager.IProductGraphPresentation;
054: import org.netbeans.modules.uml.ui.support.viewfactorysupport.TypeConversions;
055: import org.netbeans.modules.uml.ui.swing.drawingarea.IDrawingAreaControl;
056:
057: /**
058: * @author jingmingm
059: *
060: */
061: public class TransformAction implements IExecutableAction,
062: ITransformAction {
063: protected String m_NewElementType = null;
064: protected IPresentationElement m_PresentationElement = null;
065:
066: public String getDescription() {
067: return "TransformAction : ";
068: }
069:
070: public String getNewElementType() {
071: return m_NewElementType;
072: }
073:
074: public void setNewElementType(String newVal) {
075: m_NewElementType = newVal;
076: }
077:
078: public IPresentationElement get_PresentationElement() {
079: return m_PresentationElement;
080: }
081:
082: public void setPresentationElement(IPresentationElement newVal) {
083: m_PresentationElement = newVal;
084: }
085:
086: public void execute() {
087: }
088:
089: public void execute(IDrawingAreaControl pControl) {
090: pControl.setIsDirty(true);
091:
092: IElement pElement = TypeConversions
093: .getElement(m_PresentationElement);
094: IProductGraphPresentation pGraphPresentation = (IProductGraphPresentation) m_PresentationElement;
095:
096: if (pElement != null && m_NewElementType != null
097: && m_NewElementType.length() > 0) {
098: String sElementType = pElement.getElementType();
099: if (pGraphPresentation != null) {
100: pGraphPresentation.invalidate();
101: }
102:
103: if (sElementType.equals("Aggregation")
104: && m_NewElementType.equals("Association")) {
105: // Going from an Aggregation to an Association
106: if (pElement instanceof IAggregation) {
107: IAggregation pAggregation = (IAggregation) pElement;
108: IAssociation pCreatedItem = pAggregation
109: .transformToAssociation();
110: }
111: } else if ((sElementType.equals("Aggregation") || sElementType
112: .equals("Association"))
113: && (m_NewElementType.equals("Aggregation") || m_NewElementType
114: .equals("Composite Aggregation"))) {
115: // Going from an Association to an Association (might be composite)
116: if (pElement instanceof IAssociation) {
117: IAssociation pAssociation = (IAssociation) pElement;
118: IAggregation pCreatedItem = pAssociation
119: .transformToAggregation(false);
120:
121: if (pCreatedItem != null
122: && m_NewElementType
123: .equals("Composite Aggregation")) {
124: pCreatedItem.setIsComposite(true);
125: }
126: }
127: } else {
128: if (pElement instanceof IClassifier) {
129: IClassifier pClassifier = (IClassifier) pElement;
130: IClassifier pNewForm = pClassifier
131: .transform(m_NewElementType);
132: }
133: }
134: }
135: // Update the window.
136: pControl.refresh(true);
137: }
138: }
|