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 javax.swing.Icon;
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.StatePropertiesDialog;
023: import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
024: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
025: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
026: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
027: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateClass;
028: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
029: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachineClass;
030: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateType;
031: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
032:
033: /* State user object class */
034:
035: public class StateUserObject extends BaseUserObject {
036: private State mState = null;
037:
038: public StateUserObject(State pState) {
039: super (pState, Application.STATE_ICON);
040: mState = pState;
041: }
042:
043: // create new State
044: public static StateUserObject addNewState(StateMachine pStateMachine)
045: throws Exception {
046: return (StateUserObject) new StateUserObject(null)
047: .addNewObject(getObjectPackage(pStateMachine),
048: pStateMachine.getStates());
049: }
050:
051: public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
052: StateClass lClass = pPackage.getStateMachineModel().getState();
053: State lState = lClass.createState();
054: // START OF CHANGES BY ROST 17/06/2004
055: // lState.setType(StateTypeEnum.NORMAL);
056: // END OF CHANGES BY ROST 17/06/2004
057: return new StateUserObject(lState);
058: }
059:
060: // add initial state
061: public static StateUserObject createNewState(
062: StateMachine pStateMachine, StateType pType)
063: throws Exception {
064: StateUserObject lResult = null;
065: Application.beginTransaction();
066: try {
067: lResult = (StateUserObject) new StateUserObject(null)
068: .createNewObject(BaseUserObject
069: .getObjectPackage(pStateMachine));
070: if (lResult != null) {
071: State lState = lResult.getState();
072: pStateMachine.getStates().add(lState);
073: // START OF CHANGES BY ROST 17/06/2004
074: // Do commt here, so state object is fully created
075: Application.commit();
076: Application.beginTransaction();
077: // END OF CHANGES BY ROST 17/06/2004
078: lState.setType(pType);
079: }
080: Application.commit();
081: } finally {
082: if (Application.isInTransaction()) {
083: Application.rollback();
084: lResult = null;
085: }
086: }
087: return lResult;
088: }
089:
090: public State getState() {
091: return mState;
092: }
093:
094: // return object root node captions
095: public String getRootNodeName() {
096: return Application.getString("states_node");
097: }
098:
099: // get object editor
100: public BasePropertiesDialog getObjectEditor() {
101: return new StatePropertiesDialog();
102: }
103:
104: // get icon
105: public Icon getIcon() {
106: if (mState != null) {
107: if (mState.getType() == StateTypeEnum.INITIAL)
108: return Application.GRAPH_INITIALSTATE_ICON;
109: else if (mState.getType() == StateTypeEnum.FINAL)
110: return Application.GRAPH_FINALSTATE_ICON;
111: }
112: return super .getIcon();
113: }
114:
115: // get icon for opened node
116: public Icon getOpenIcon() {
117: if (mState != null) {
118: if (mState.getType() == StateTypeEnum.INITIAL)
119: return Application.GRAPH_INITIALSTATE_ICON;
120: else if (mState.getType() == StateTypeEnum.FINAL)
121: return Application.GRAPH_FINALSTATE_ICON;
122: }
123: return super .getOpenIcon();
124: }
125:
126: // get icon for closed mode
127: public Icon getClosedIcon() {
128: if (mState != null) {
129: if (mState.getType() == StateTypeEnum.INITIAL)
130: return Application.GRAPH_INITIALSTATE_ICON;
131: else if (mState.getType() == StateTypeEnum.FINAL)
132: return Application.GRAPH_FINALSTATE_ICON;
133: }
134: return super .getClosedIcon();
135: }
136:
137: // load object properties into grid control
138: public void loadObjectProperties(PropertiesTableModel pModel)
139: throws Exception {
140: super .loadObjectProperties(pModel);
141: if (pModel == null || mState == null)
142: return;
143:
144: if (mState.getType() != null)
145: pModel.AddProperty("Type", mState.getType().toString());
146: }
147:
148: // create StateMachine for Entity
149: static protected void createStateMachine(Entity pEntity)
150: throws Exception {
151: if (pEntity != null && pEntity.getStateMachine() == null) {
152: Application.beginTransaction();
153: try {
154: StateMachineClass lClass = getObjectPackage(pEntity)
155: .getStateMachineModel().getStateMachine();
156: StateMachine lStateMachine = lClass
157: .createStateMachine();
158: pEntity.setStateMachine(lStateMachine);
159: lStateMachine.setEntity(pEntity);
160: Application.commit();
161: } finally {
162: Application.checkAndRollback();
163: }
164: }
165: }
166: }
|