001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.userobjects;
016:
017: import java.awt.event.ActionEvent;
018: import java.util.ArrayList;
019:
020: import com.metaboss.applications.designstudio.Application;
021: import com.metaboss.applications.designstudio.BaseAction;
022: import com.metaboss.applications.designstudio.BasePropertiesDialog;
023: import com.metaboss.applications.designstudio.BaseUserObject;
024: import com.metaboss.applications.designstudio.components.SeparatorAction;
025: import com.metaboss.applications.designstudio.propertiesdialogs.TypeTemplatePropertiesDialog;
026: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
027: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
028: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.AbstractNamespace;
030: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
031: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplateClass;
032: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplateLanguage;
033:
034: /* TypeTemplate user object */
035:
036: public class TypeTemplateUserObject extends BaseUserObject {
037: public static final int PROPERTY_ACTION = 1;
038:
039: private TypeTemplate mTypeTemplate = null;
040: private AddPropertyAction mAddPropertyAction = new AddPropertyAction();
041: private AddSourceAction mAddSourceAction = new AddSourceAction();
042: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
043:
044: public TypeTemplateUserObject(TypeTemplate pTypetemplate) {
045: super (pTypetemplate, Application.TYPETEMPLATE_ICON);
046: mTypeTemplate = pTypetemplate;
047: }
048:
049: public TypeTemplateUserObject(TypeTemplate pTypetemplate,
050: String pCaption, int pMode) {
051: super (pTypetemplate, pCaption, pMode);
052: mTypeTemplate = pTypetemplate;
053: }
054:
055: // create new datatype
056: public static void addNewTypeTemplate(AbstractNamespace pNamespace)
057: throws Exception {
058: new TypeTemplateUserObject(null).addNewObject(
059: getObjectPackage(pNamespace), pNamespace
060: .getTypeTemplates());
061: }
062:
063: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
064: TypeTemplateClass lClass = pPackage.getDataDictionaryModel()
065: .getTypeTemplate();
066: return new TypeTemplateUserObject(lClass.createTypeTemplate());
067: }
068:
069: public TypeTemplate getTypetemplate() {
070: return mTypeTemplate;
071: }
072:
073: // return object root node captions
074: public String getRootNodeName() {
075: return Application.getString("typetemplates_node");
076: }
077:
078: // load object properties into grid control
079: public void loadObjectProperties(PropertiesTableModel pModel)
080: throws Exception {
081: super .loadObjectProperties(pModel);
082: if (pModel == null || mTypeTemplate == null)
083: return;
084:
085: TypeTemplateLanguage lLanguage = mTypeTemplate.getLanguage();
086: if (lLanguage != null)
087: pModel.AddProperty("Language", lLanguage.toString());
088: }
089:
090: // fill actions list
091: public void fillActionsList(ArrayList pList) {
092: switch (mMode) {
093: case ALL_ACTIONS:
094: super .fillActionsList(pList);
095: pList.add(new SeparatorAction());
096: if (!hasSource())
097: pList.add(mAddSourceAction);
098: pList.add(mAddPropertyAction);
099: pList.add(new SeparatorAction());
100: pList.add(mShowDataTypeDependenciesAction);
101: break;
102: case PROPERTY_ACTION:
103: pList.add(mAddPropertyAction);
104: break;
105: }
106: }
107:
108: public BasePropertiesDialog getObjectEditor() {
109: return new TypeTemplatePropertiesDialog();
110: }
111:
112: // add property
113: private void addProperty() throws Exception {
114: PropertyDescriptorUserObject
115: .addNewPropertyDescriptor(mTypeTemplate);
116: }
117:
118: // can duplicate model element
119: public boolean canDuplicate() {
120: return true;
121: }
122:
123: // duplicate model element
124: public ModelElement duplicate() throws Exception {
125: TypeTemplate lTypeTemplate = (TypeTemplate) Application.sModelRepository
126: .duplicateModelElement(mTypeTemplate);
127: lTypeTemplate.setNamespace(mTypeTemplate.getNamespace());
128: return lTypeTemplate;
129: }
130:
131: /* Actions */
132:
133: public class AddPropertyAction extends BaseAction {
134: public AddPropertyAction() {
135: super ("Add New Property Descriptor", Application
136: .getAddIcon(Application.PROPERTYDESCRIPTOR_ICON));
137: }
138:
139: public void actionPerformed(ActionEvent e) {
140: try {
141: addProperty();
142: } catch (Throwable t) {
143: Application.processError(t);
144: }
145: }
146: }
147: }
|