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.util.HashMap;
045:
046: import org.netbeans.modules.uml.common.ETException;
047: import org.netbeans.modules.uml.common.ETStrings;
048: import org.netbeans.modules.uml.core.metamodel.core.foundation.FactoryRetriever;
049: import org.netbeans.modules.uml.core.metamodel.core.foundation.ICreationFactory;
050: import org.netbeans.modules.uml.ui.products.ad.viewfactory.IETGraphObjectUI;
051: import org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment;
052: import org.netbeans.modules.uml.ui.support.viewfactorysupport.IDrawEngine;
053:
054: /**
055: * @author Embarcadero Technologies Inc.
056: *
057: *
058: */
059: public class ETDrawEngineFactory {
060:
061: public ETDrawEngineFactory() {
062: }
063:
064: public static IDrawEngine createDrawEngine(IETGraphObjectUI objectUI)
065: throws ETException {
066: IDrawEngine drawEngine = ETDrawEngineFactory
067: .createDrawEngine(objectUI.getDrawEngineClass());
068: if (drawEngine != null) {
069: drawEngine.setParent(objectUI);
070: objectUI.setDrawEngine(drawEngine);
071:
072: // We can not init the engine here, because it causes infinite loops. The Engine
073: // Datamember must be set first.
074: //drawEngine.init();
075:
076: }
077: return drawEngine;
078: }
079:
080: public static IDrawEngine createDrawEngine(String name)
081: throws ETException {
082: ICreationFactory factory = FactoryRetriever.instance()
083: .getCreationFactory();
084: Object value = factory.retrieveEmptyMetaType("DrawEngines",
085: name, null);
086:
087: return value instanceof IDrawEngine ? (IDrawEngine) value
088: : null;
089: }
090:
091: public static ICompartment createCompartment(String name)
092: throws ETException {
093: try {
094: ICompartment newCompartment = (ICompartment) Class.forName(
095: COMPARTMENT_PACKAGE + getCompartmentClass(name))
096: .newInstance();
097: return newCompartment;
098: } catch (Exception e) {
099: e.printStackTrace();
100: throw new ETException(ETStrings.E_CMN_UNEXPECTED_EXC,
101: "ETDrawEngineFactory.createCompartment()", e
102: .getMessage());
103: }
104: }
105:
106: private static final String COMPARTMENT_PACKAGE = "org.netbeans.modules.uml.ui.products.ad.compartments.";
107:
108: // compartments
109: public static final String ATTRIBUTE_LIST_COMPARTMENT = "ETAttributeListCompartment";
110: public static final String CLASS_ATTRIBUTE_COMPARTMENT = "ETClassAttributeCompartment";
111: public static final String CLASS_OPERATION_COMPARTMENT = "ETClassOperationCompartment";
112: public static final String CLASS_NAME_COMPARTMENT = "ETClassNameCompartment";
113: public static final String CLASS_NAME_LIST_COMPARTMENT = "ETClassNameListCompartment";
114: public static final String OPERATION_LIST_COMPARTMENT = "ETOperationListCompartment";
115: public static final String REDEFINED_OPERATION_LIST_COMPARTMENT = "ETRedefinedOperationListCompartment";
116: public static final String STEREOTYPE_COMPARTMENT = "ETStereoTypeCompartment";
117: public static final String TAGGED_VALUES_COMPARTMENT = "ETTaggedValuesCompartment";
118:
119: private static HashMap compartmentMap;
120:
121: private static String getCompartmentClass(String pCompartmentName) {
122: if (compartmentMap == null) {
123: initComparmtentMap();
124: return (String) compartmentMap.get(pCompartmentName);
125: } else {
126: return (String) compartmentMap.get(pCompartmentName);
127: }
128: }
129:
130: private static void initComparmtentMap() {
131:
132: compartmentMap = new HashMap();
133:
134: compartmentMap.put(ATTRIBUTE_LIST_COMPARTMENT,
135: ATTRIBUTE_LIST_COMPARTMENT);
136: compartmentMap.put(CLASS_ATTRIBUTE_COMPARTMENT,
137: CLASS_ATTRIBUTE_COMPARTMENT);
138: compartmentMap.put(CLASS_OPERATION_COMPARTMENT,
139: CLASS_OPERATION_COMPARTMENT);
140: compartmentMap.put(CLASS_NAME_COMPARTMENT,
141: CLASS_NAME_COMPARTMENT);
142: compartmentMap.put(CLASS_NAME_LIST_COMPARTMENT,
143: CLASS_NAME_LIST_COMPARTMENT);
144: compartmentMap.put(OPERATION_LIST_COMPARTMENT,
145: OPERATION_LIST_COMPARTMENT);
146: compartmentMap.put(REDEFINED_OPERATION_LIST_COMPARTMENT,
147: REDEFINED_OPERATION_LIST_COMPARTMENT);
148: compartmentMap.put(STEREOTYPE_COMPARTMENT,
149: STEREOTYPE_COMPARTMENT);
150: compartmentMap.put(TAGGED_VALUES_COMPARTMENT,
151: TAGGED_VALUES_COMPARTMENT);
152:
153: compartmentMap.put("ADAttributeListCompartment",
154: ATTRIBUTE_LIST_COMPARTMENT);
155: compartmentMap.put("ADClassAttributeCompartment",
156: CLASS_ATTRIBUTE_COMPARTMENT);
157: compartmentMap.put("ADClassOperationCompartment",
158: CLASS_OPERATION_COMPARTMENT);
159: compartmentMap.put("ADClassNameCompartment",
160: CLASS_NAME_COMPARTMENT);
161: compartmentMap.put("ADClassNameListCompartment",
162: CLASS_NAME_LIST_COMPARTMENT);
163: compartmentMap.put("ADOperationListCompartment",
164: OPERATION_LIST_COMPARTMENT);
165: compartmentMap.put("ADRedefinedOperationListCompartment",
166: REDEFINED_OPERATION_LIST_COMPARTMENT);
167: compartmentMap.put("StereotypeCompartment",
168: STEREOTYPE_COMPARTMENT);
169: }
170: }
|