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.PropertyDescriptorPropertiesDialog;
026: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
027: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptorClass;
030: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
031:
032: /* Property Descripter user object */
033:
034: public class PropertyDescriptorUserObject extends BaseUserObject {
035: public static final int PROPERTY_ACTION = 1;
036:
037: private PropertyDescriptor mPropertyDescriptor = null;
038: private AddPropertyAction mAddPropertyAction = new AddPropertyAction();
039:
040: public PropertyDescriptorUserObject(
041: PropertyDescriptor pPropertyDescriptor) {
042: super (pPropertyDescriptor, Application.PROPERTYDESCRIPTOR_ICON);
043: mPropertyDescriptor = pPropertyDescriptor;
044: }
045:
046: public PropertyDescriptorUserObject(
047: PropertyDescriptor pPropertyDescriptor, String pCaption,
048: int pMode) {
049: super (pPropertyDescriptor, pCaption, pMode);
050: mPropertyDescriptor = pPropertyDescriptor;
051: }
052:
053: // create new datatype
054: public static void addNewPropertyDescriptor(
055: TypeTemplate pTypeTemplate) throws Exception {
056: new PropertyDescriptorUserObject(null).addNewObject(
057: getObjectPackage(pTypeTemplate), pTypeTemplate
058: .getPropertyDescriptors());
059: }
060:
061: public static void addNewPropertyDescriptor(
062: PropertyDescriptor pPropertyDescriptor) throws Exception {
063: new PropertyDescriptorUserObject(null).addNewObject(
064: getObjectPackage(pPropertyDescriptor),
065: pPropertyDescriptor.getSubPropertyDescriptors());
066: }
067:
068: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
069: PropertyDescriptorClass lClass = pPackage
070: .getDataDictionaryModel().getPropertyDescriptor();
071: return new PropertyDescriptorUserObject(lClass
072: .createPropertyDescriptor());
073: }
074:
075: public PropertyDescriptor getPropertyDescriptor() {
076: return mPropertyDescriptor;
077: }
078:
079: // return object root node captions
080: public String getRootNodeName() {
081: return Application.getString("propertydescriptors_node");
082: }
083:
084: // load object properties into grid control
085: public void loadObjectProperties(PropertiesTableModel pModel)
086: throws Exception {
087: super .loadObjectProperties(pModel);
088: if (pModel == null || mPropertyDescriptor == null)
089: return;
090:
091: pModel.AddProperty("Array", boolToString(mPropertyDescriptor
092: .isArray()));
093: pModel.AddProperty("Container",
094: boolToString(mPropertyDescriptor.isContainer()));
095: }
096:
097: public BasePropertiesDialog getObjectEditor() {
098: return new PropertyDescriptorPropertiesDialog();
099: }
100:
101: // fill actions list
102: public void fillActionsList(ArrayList pList) {
103: switch (mMode) {
104: case ALL_ACTIONS:
105: super .fillActionsList(pList);
106: pList.add(new SeparatorAction());
107: pList.add(mAddPropertyAction);
108: break;
109: case PROPERTY_ACTION:
110: pList.add(mAddPropertyAction);
111: break;
112: }
113: }
114:
115: // add property
116: private void addProperty() throws Exception {
117: PropertyDescriptorUserObject
118: .addNewPropertyDescriptor(mPropertyDescriptor);
119: }
120:
121: /* Actions */
122:
123: public class AddPropertyAction extends BaseAction {
124: public AddPropertyAction() {
125: super ("Add New Property Descriptor", Application
126: .getAddIcon(Application.PROPERTYDESCRIPTOR_ICON));
127: }
128:
129: public void actionPerformed(ActionEvent e) {
130: try {
131: addProperty();
132: } catch (Throwable t) {
133: Application.processError(t);
134: }
135: }
136: }
137: }
|