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 com.metaboss.applications.designstudio.Application;
018: import com.metaboss.applications.designstudio.BasePropertiesDialog;
019: import com.metaboss.applications.designstudio.BaseUserObject;
020: import com.metaboss.applications.designstudio.propertiesdialogs.StateTransitionPropertiesDialog;
021: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
022: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
023: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
024: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
025: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
026: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.Transition;
027: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.TransitionClass;
028:
029: /* StateTransition node user object */
030:
031: public class TransitionUserObject extends BaseUserObject {
032: private Transition mStateTransition = null;
033:
034: public TransitionUserObject(Transition pStateTransition) {
035: super (pStateTransition, Application.STATETRANSITION_ICON);
036: mStateTransition = pStateTransition;
037: }
038:
039: // create new Transition
040: public static TransitionUserObject addNewTransition(
041: StateMachine pStateMachine) throws Exception {
042: return (TransitionUserObject) new TransitionUserObject(null)
043: .addNewObject(getObjectPackage(pStateMachine),
044: pStateMachine.getTransitions());
045: }
046:
047: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
048: TransitionClass lClass = pPackage.getStateMachineModel()
049: .getTransition();
050: return new TransitionUserObject(lClass.createTransition());
051: }
052:
053: // create new transition
054: public static TransitionUserObject addNewTransition(
055: StateMachine pStateMachine, State pFromState, State pToState)
056: throws Exception {
057: TransitionUserObject lResult = null;
058: Application.beginTransaction();
059: try {
060: lResult = (TransitionUserObject) new TransitionUserObject(
061: null).createNewObject(BaseUserObject
062: .getObjectPackage(pStateMachine));
063: if (lResult != null) {
064: Transition lTransition = lResult.getStateTransition();
065: pStateMachine.getTransitions().add(lTransition);
066: if (pFromState != null) {
067: if (pFromState.getType() == StateTypeEnum.FINAL)
068: throw new Exception(
069: "You can't start any transition from the Final State!");
070: lTransition.setStartState(pFromState);
071: }
072: if (pToState != null) {
073: if (pToState.getType() == StateTypeEnum.INITIAL)
074: throw new Exception(
075: "You can't point any transition to the Initial State!");
076: lTransition.setEndState(pToState);
077: }
078: if (pFromState != null && pToState != null)
079: lTransition.setName(pFromState.getName() + "To"
080: + pToState.getName());
081: }
082: Application.commit();
083: } finally {
084: if (Application.isInTransaction()) {
085: Application.rollback();
086: lResult = null;
087: }
088: }
089: //Application.fireObjectInserted(lResult);
090: return lResult;
091: }
092:
093: public Transition getStateTransition() {
094: return mStateTransition;
095: }
096:
097: // return object root node captions
098: public String getRootNodeName() {
099: return Application.getString("transitions_node");
100: }
101:
102: // load object properties into grid control
103: public void loadObjectProperties(PropertiesTableModel pModel)
104: throws Exception {
105: super .loadObjectProperties(pModel);
106: if (pModel == null || mStateTransition == null)
107: return;
108:
109: addModelElement(pModel, "Start State", mStateTransition
110: .getStartState());
111: addModelElement(pModel, "End State", mStateTransition
112: .getEndState());
113: }
114:
115: public BasePropertiesDialog getObjectEditor() {
116: return new StateTransitionPropertiesDialog();
117: }
118: }
|