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.util.Collection;
018:
019: import com.metaboss.applications.designstudio.Application;
020: import com.metaboss.applications.designstudio.BasePropertiesDialog;
021: import com.metaboss.applications.designstudio.BaseUserObject;
022: import com.metaboss.applications.designstudio.propertiesdialogs.PropertyPropertiesDialog;
023: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
024: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
025: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
026: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Property;
027: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyClass;
028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
029:
030: /* Property user object */
031:
032: public class PropertyUserObject extends BaseUserObject {
033: public static final int PROPERTY_ACTION = 1;
034:
035: private Property mProperty = null;
036:
037: //private AddPropertyAction mAddPropertyAction = new AddPropertyAction();
038:
039: public PropertyUserObject(Property pProperty) {
040: super (pProperty, Application.PROPERTY_ICON);
041: mProperty = pProperty;
042: }
043:
044: public PropertyUserObject(Property pProperty, String pCaption,
045: int pMode) {
046: super (pProperty, pCaption, pMode);
047: mProperty = pProperty;
048: }
049:
050: // create new datatype
051: public static void addNewProperty(DataType pDataType)
052: throws Exception {
053: new PropertyUserObject(null).addNewObject(
054: getObjectPackage(pDataType), pDataType
055: .getTypetemplateProperties());
056: }
057:
058: public static void addNewProperty(Property pProperty)
059: throws Exception {
060: new PropertyUserObject(null).addNewObject(
061: getObjectPackage(pProperty), pProperty
062: .getSubProperties());
063: }
064:
065: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
066: PropertyClass lClass = pPackage.getDataDictionaryModel()
067: .getProperty();
068: return new PropertyUserObject(lClass.createProperty());
069: }
070:
071: // create new property
072: public static PropertyUserObject createNewProperty(
073: DataType pDataType, PropertyDescriptor pDescriptor)
074: throws Exception {
075: PropertyUserObject lResult = null;
076: Application.beginTransaction();
077: try {
078: lResult = (PropertyUserObject) new PropertyUserObject(null)
079: .createNewObject(BaseUserObject
080: .getObjectPackage(pDataType));
081: defineProperty(lResult, pDataType
082: .getTypetemplateProperties(), pDescriptor);
083: Application.commit();
084: } finally {
085: if (Application.isInTransaction()) {
086: Application.rollback();
087: lResult = null;
088: }
089: }
090: return lResult;
091: }
092:
093: public static PropertyUserObject createNewProperty(
094: Property pMasterProperty, PropertyDescriptor pDescriptor)
095: throws Exception {
096: PropertyUserObject lResult = null;
097: Application.beginTransaction();
098: try {
099: lResult = (PropertyUserObject) new PropertyUserObject(null)
100: .createNewObject(BaseUserObject
101: .getObjectPackage(pMasterProperty));
102: defineProperty(lResult, pMasterProperty.getSubProperties(),
103: pDescriptor);
104: Application.commit();
105: } finally {
106: if (Application.isInTransaction()) {
107: Application.rollback();
108: lResult = null;
109: }
110: }
111: return lResult;
112: }
113:
114: public static void defineProperty(PropertyUserObject pProperty,
115: Collection pMasterCollection, PropertyDescriptor pDescriptor) {
116: if (pProperty != null) {
117: Property lProperty = pProperty.getProperty();
118: lProperty.setDescriptor(pDescriptor);
119: lProperty.setName(pDescriptor.getName());
120: lProperty.setDescriptor(pDescriptor);
121: pMasterCollection.add(lProperty);
122: }
123: }
124:
125: public Property getProperty() {
126: return mProperty;
127: }
128:
129: // return object root node captions
130: public String getRootNodeName() {
131: return Application.getString("properties_node");
132: }
133:
134: // load object properties into grid control
135: public void loadObjectProperties(PropertiesTableModel pModel)
136: throws Exception {
137: super .loadObjectProperties(pModel);
138: if (pModel == null || mProperty == null)
139: return;
140:
141: addModelElement(pModel, "Descriptor", mProperty.getDescriptor());
142: pModel.AddProperty("Key", mProperty.getKey());
143: pModel.AddProperty("Value", mProperty.getValue());
144: pModel.AddProperty("Array Index", mProperty.getArrayIndex());
145: }
146:
147: public BasePropertiesDialog getObjectEditor() {
148: return new PropertyPropertiesDialog();
149: }
150:
151: // fill actions list
152: /*public void fillActionsList(ArrayList pList)
153: {
154: switch (mMode)
155: {
156: case ALL_ACTIONS:
157: super.fillActionsList(pList);
158: pList.add(new SeparatorAction());
159: pList.add(mAddPropertyAction);
160: break;
161: case PROPERTY_ACTION:
162: pList.add(mAddPropertyAction);
163: break;
164: }
165: }*/
166:
167: // add property
168: private void addProperty() throws Exception {
169: PropertyUserObject.addNewProperty(mProperty);
170: }
171:
172: /* Actions */
173:
174: /*public class AddPropertyAction extends BaseAction
175: {
176: public AddPropertyAction()
177: {
178: super("Add New Property", Application.getAddIcon(Application.PROPERTY_ICON));
179: }
180:
181: public void actionPerformed(ActionEvent e)
182: {
183: try
184: {
185: addProperty();
186: }
187: catch(Throwable t)
188: {
189: Application.processError(t);
190: }
191: }
192: }*/
193: }
|