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.SelectorPropertiesDialog;
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.enterprisemodel.systemimplementationmodel.Entity;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorClass;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
033:
034: /* BOSelector user object class */
035:
036: public class SelectorUserObject extends BaseUserObject {
037: public static final int ADD_FIELD = 1;
038:
039: private Selector mSelector = null;
040: private AddNewFieldAction mAddNewFieldAction = new AddNewFieldAction();
041: private StudyDependenciesAction mShowDataTypeDependenciesAction = new StudyDependenciesAction();
042:
043: public SelectorUserObject(Selector pSelector) {
044: super (pSelector, Application.SELECTOR_ICON);
045: mSelector = pSelector;
046: }
047:
048: public SelectorUserObject(Selector pSelector, String pCaption,
049: int pMode) {
050: super (pSelector, pCaption, pMode);
051: mSelector = pSelector;
052: }
053:
054: // create new selector module
055: public static void addNewSelector(Entity pEntity) throws Exception {
056: new SelectorUserObject(null).addNewObject(
057: getObjectPackage(pEntity), pEntity.getSelectors());
058: }
059:
060: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
061: SystemImplementationModelPackage lSystemImplementationModelPackage = pPackage
062: .getEnterpriseModel().getSystemImplementationModel();
063: SelectorClass lClass = lSystemImplementationModelPackage
064: .getSelector();
065: return new SelectorUserObject(lClass.createSelector());
066: }
067:
068: public Selector getSelector() {
069: return mSelector;
070: }
071:
072: // return object root node captions
073: public String getRootNodeName() {
074: return Application.getString("selectors_node");
075: }
076:
077: // fill actions list
078: public void fillActionsList(ArrayList pList) {
079: switch (mMode) {
080: case ALL_ACTIONS:
081: super .fillActionsList(pList);
082: pList.add(new SeparatorAction());
083: pList.add(mAddNewFieldAction);
084: pList.add(new SeparatorAction());
085: pList.add(mShowDataTypeDependenciesAction);
086: break;
087: case ADD_FIELD:
088: pList.add(mAddNewFieldAction);
089: break;
090: }
091: }
092:
093: // load object properties into grid control
094: public void loadObjectProperties(PropertiesTableModel pModel)
095: throws Exception {
096: super .loadObjectProperties(pModel);
097: if (pModel == null || mSelector == null)
098: return;
099:
100: pModel
101: .AddProperty("SQL select", mSelector
102: .getTextOfSqlSelect());
103: pModel.AddProperty("Implicit", boolToString(mSelector
104: .isImplicit()));
105: pModel
106: .AddProperty("Plural", boolToString(mSelector
107: .isPlural()));
108: pModel.AddProperty("Cardinality", mSelector.getCardinality()
109: .toString());
110: }
111:
112: // get object editor
113: public BasePropertiesDialog getObjectEditor() {
114: return new SelectorPropertiesDialog();
115: }
116:
117: // add event
118: public void addField() throws Exception {
119: SelectorInputFieldUserObject.addNewField(mSelector);
120: }
121:
122: // can duplicate model element
123: public boolean canDuplicate() {
124: return true;
125: }
126:
127: // duplicate model element
128: public ModelElement duplicate() throws Exception {
129: Selector lSelector = (Selector) Application.sModelRepository
130: .duplicateModelElement(mSelector);
131: lSelector.setEntity(mSelector.getEntity());
132: return lSelector;
133: }
134:
135: /* Actions */
136:
137: public class AddNewFieldAction extends BaseAction {
138: public AddNewFieldAction() {
139: super ("Add New Field", Application
140: .getAddIcon(Application.FIELDS_ICON));
141: }
142:
143: public void actionPerformed(ActionEvent e) {
144: try {
145: addField();
146: } catch (Throwable t) {
147: Application.processError(t);
148: }
149: }
150: }
151: }
|