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.SimpleObjectPropertiesdialog;
026: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
027: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
029: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
030: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachineClass;
031:
032: /* StateMachine user object */
033:
034: public class StateMachineUserObject extends BaseUserObject {
035: public static final int ADD_STATE = 1;
036: public static final int ADD_TRANSITION = 2;
037:
038: private StateMachine mStateMachine = null;
039: private Entity mMasterEntity = null;
040: private AddNewEntityStateAction mAddNewEntityStateAction = new AddNewEntityStateAction();
041: private AddNewStateTransitionAction mAddNewStateTransitionAction = new AddNewStateTransitionAction();
042:
043: public StateMachineUserObject(StateMachine pStateMachine) {
044: super (pStateMachine, Application.STATEMACHINE_ICON);
045: mStateMachine = pStateMachine;
046: }
047:
048: public StateMachineUserObject(StateMachine pStateMachine,
049: String pCaption, int pMode) {
050: super (pStateMachine, pCaption, pMode);
051: mStateMachine = pStateMachine;
052: }
053:
054: // create new StateMachine
055: public static void addNewStateMachine(Entity pEntity)
056: throws Exception {
057: StateMachineUserObject lObject = new StateMachineUserObject(
058: null);
059: lObject.mMasterEntity = pEntity;
060: lObject.addNewObject(getObjectPackage(pEntity), null);
061: }
062:
063: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
064: StateMachineClass lClass = pPackage.getStateMachineModel()
065: .getStateMachine();
066: StateMachine lMachine = lClass.createStateMachine();
067: if (mMasterEntity != null)
068: mMasterEntity.setStateMachine(lMachine);
069: return new StateMachineUserObject(lMachine);
070: }
071:
072: // return object root node captions
073: public String getRootNodeName() {
074: return null;
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(mAddNewEntityStateAction);
084: pList.add(mAddNewStateTransitionAction);
085: break;
086: case ADD_STATE:
087: pList.add(mAddNewEntityStateAction);
088: break;
089: case ADD_TRANSITION:
090: pList.add(mAddNewStateTransitionAction);
091: break;
092: }
093: }
094:
095: // load object properties into grid control
096: public void loadObjectProperties(PropertiesTableModel pModel)
097: throws Exception {
098: super .loadObjectProperties(pModel);
099: if (pModel == null || mStateMachine == null)
100: return;
101:
102: //???addModelElement(pModel, "Initial State", mStateMachine.getInitialState());
103: }
104:
105: public BasePropertiesDialog getObjectEditor() {
106: return new SimpleObjectPropertiesdialog("State Machine");
107: }
108:
109: // add new State
110: public void addNewState() throws Exception {
111: StateUserObject.addNewState(mStateMachine);
112: }
113:
114: // add new State Transition
115: public void addNewStateTransition() throws Exception {
116: TransitionUserObject.addNewTransition(mStateMachine);
117: }
118:
119: /* Actions */
120:
121: /* Add New Entity State Action Class */
122:
123: public class AddNewEntityStateAction extends BaseAction {
124: public AddNewEntityStateAction() {
125: super ("Add New Entity State", Application
126: .getAddIcon(Application.STATE_ICON));
127: }
128:
129: public void actionPerformed(ActionEvent arg0) {
130: try {
131: addNewState();
132: } catch (Exception e) {
133: e.printStackTrace();
134: }
135: }
136: }
137:
138: /* Add New State Transition Action Class */
139:
140: public class AddNewStateTransitionAction extends BaseAction {
141: public AddNewStateTransitionAction() {
142: super ("Add New State Transition", Application
143: .getAddIcon(Application.STATETRANSITION_ICON));
144: }
145:
146: public void actionPerformed(ActionEvent arg0) {
147: try {
148: addNewStateTransition();
149: } catch (Exception e) {
150: e.printStackTrace();
151: }
152: }
153: }
154: }
|