Source Code Cross Referenced for StatesPanel.java in  » UML » MetaBoss » com » metaboss » applications » designstudio » statesmodel » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » MetaBoss » com.metaboss.applications.designstudio.statesmodel 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.statesmodel;
016:
017:        import java.awt.Point;
018:        import java.util.ArrayList;
019:        import java.util.Hashtable;
020:        import java.util.Map;
021:
022:        import org.jgraph.JGraph;
023:        import org.jgraph.graph.CellMapper;
024:        import org.jgraph.graph.DefaultGraphCell;
025:        import org.jgraph.graph.Port;
026:        import org.jgraph.graph.VertexView;
027:
028:        import com.metaboss.applications.designstudio.Application;
029:        import com.metaboss.applications.designstudio.BaseGraphModel;
030:        import com.metaboss.applications.designstudio.BaseGraphPanel;
031:        import com.metaboss.applications.designstudio.BaseUserObject;
032:        import com.metaboss.applications.designstudio.Application.ObjectChangedEvent;
033:        import com.metaboss.applications.designstudio.components.DesignGraph;
034:        import com.metaboss.applications.designstudio.components.VertexCell;
035:        import com.metaboss.applications.designstudio.userobjects.StateUserObject;
036:        import com.metaboss.applications.designstudio.userobjects.TransitionUserObject;
037:        import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
038:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
039:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
040:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateType;
041:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
042:        import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.Transition;
043:        import com.metaboss.sdlctools.models.metabossmodel.visualmodel.EntityStateDiagram;
044:
045:        /*		Entity States diagram container panel class 		*/
046:
047:        public class StatesPanel extends BaseGraphPanel {
048:            public final static int ADD_STATE = 1;
049:            public final static int ADD_STARTSTATE = 2;
050:            public final static int ADD_FINALSTATE = 3;
051:            public final static int ADD_TRANSITION = 4;
052:
053:            private AddStartStateAction mAddStartStateAction;
054:
055:            public StatesPanel(EntityStateDiagram pDiagram) throws Exception {
056:                super (pDiagram.getEntity(), pDiagram);
057:
058:                mGraph.beginUpdate();
059:                try {
060:                    mGraph.setShowClassVertex(false);
061:                    mGraph.setShowEdgesLabels(false);
062:                    mViewEdgesCaptionsAction.setChecked(false);
063:                } finally {
064:                    mGraph.stopUpdate(false);
065:                }
066:                setActionsState();
067:            }
068:
069:            public DesignGraph createGraph() throws Exception {
070:                return new DesignGraph(mModel) {
071:                    protected VertexView createVertexView(JGraph graph,
072:                            CellMapper cm, Object v) {
073:                        if (((VertexCell) v).getUserObject() instanceof  StateUserObject)
074:                            return new StateVertexView(v, this , cm);
075:                        else
076:                            return super .createVertexView(graph, cm, v);
077:                    }
078:                };
079:            }
080:
081:            public BaseGraphModel createModel() throws Exception {
082:                return new StatesModel((EntityStateDiagram) mDiagram);
083:            }
084:
085:            // return entity
086:            public Entity getEntity() {
087:                Object lObject = getBOObject();
088:                if (lObject != null && lObject instanceof  Entity)
089:                    return (Entity) lObject;
090:                else
091:                    return null;
092:            }
093:
094:            public StateMachine getStateMachine() {
095:                Entity lEntity = getEntity();
096:                return (lEntity != null) ? lEntity.getStateMachine() : null;
097:            }
098:
099:            // connect Edges
100:            public void connectEdges(Port pFrom, Port pTo) {
101:                State lFromState = null;
102:                State lToState = null;
103:
104:                if (pFrom != null) {
105:                    Object lFromObject = ((DefaultGraphCell) pFrom)
106:                            .getUserObject();
107:                    if (lFromObject instanceof  StateUserObject)
108:                        lFromState = ((StateUserObject) lFromObject).getState();
109:                }
110:                if (pTo != null) {
111:                    Object lToObject = ((DefaultGraphCell) pTo).getUserObject();
112:                    if (lToObject instanceof  StateUserObject)
113:                        lToState = ((StateUserObject) lToObject).getState();
114:                }
115:
116:                TransitionUserObject lTransition = null;
117:                switch (mState) {
118:                case ADD_TRANSITION:
119:                    try {
120:                        lTransition = TransitionUserObject.addNewTransition(
121:                                getStateMachine(), lFromState, lToState);
122:                    } catch (Exception e) {
123:                        Application.processError(e);
124:                    }
125:                    setSelection(NO_SELECTION);
126:                    mGraph.repaint();
127:                    break;
128:                }
129:
130:                if (lTransition != null) {
131:                    try {
132:                        ((StatesModel) mModel).addTransition(lTransition
133:                                .getStateTransition());
134:                    } catch (Exception e) {
135:                        Application.processError(e);
136:                    }
137:                }
138:            }
139:
140:            protected void processObjectInserted(BaseUserObject pObject)
141:                    throws Exception {
142:                Object[] cells = mModel.getUserObjectCells(pObject);
143:                if (cells.length == 0) {
144:                    if (pObject instanceof  StateUserObject) {
145:                        State lState = ((StateUserObject) pObject).getState();
146:                        if (lState != null
147:                                && lState.getStateMachine().equals(
148:                                        getStateMachine()))
149:                            ((StatesModel) mModel).addStateCell(lState,
150:                                    new Point(0, 0));
151:                    } else if (pObject instanceof  TransitionUserObject) {
152:                        Transition lTransition = (Transition) pObject
153:                                .getBOObject();
154:                        if (lTransition != null
155:                                && lTransition.getStateMachine().equals(
156:                                        getStateMachine()))
157:                            ((StatesModel) mModel).addTransition(lTransition);
158:                    }
159:                }
160:                setActionsState();
161:            }
162:
163:            protected void processObjectEdited(BaseUserObject pObject)
164:                    throws Exception {
165:                if (pObject instanceof  TransitionUserObject) {
166:                    Transition lTransition = (Transition) pObject.getBOObject();
167:                    if (lTransition != null
168:                            && lTransition.getStateMachine().equals(
169:                                    getStateMachine())) {
170:                        Map lViewMap = new Hashtable();
171:                        ((StatesModel) mModel).checkTransition(lTransition,
172:                                lViewMap);
173:                        updateModel(lViewMap);
174:                    }
175:                } else if (pObject instanceof  StateUserObject) {
176:                    ((StatesModel) mModel)
177:                            .checkState(((StateUserObject) pObject).getState());
178:                    setActionsState();
179:                }
180:                super .processObjectEdited(pObject);
181:            }
182:
183:            protected void processObjectDeleted(ObjectChangedEvent event)
184:                    throws Exception {
185:                super .processObjectDeleted(event);
186:                setActionsState();
187:            }
188:
189:            protected void fillToolBarActions(ArrayList pActionsList) {
190:                super .fillToolBarActions(pActionsList);
191:                pActionsList.add(new AddStateAction());
192:                mAddStartStateAction = new AddStartStateAction();
193:                pActionsList.add(mAddStartStateAction);
194:                //pActionsList.add(new AddStartStateAction());
195:                pActionsList.add(new AddFinalStateAction());
196:                pActionsList.add(new AddTransitionAction());
197:            }
198:
199:            // process selection
200:            protected boolean processSelection(int pSelection, int X, int Y) {
201:                switch (pSelection) {
202:                case ADD_STATE:
203:                    addNewState(X, Y);
204:                    return true;
205:                case ADD_STARTSTATE:
206:                    addNewExtraState(X, Y, StateTypeEnum.INITIAL);
207:                    return true;
208:                case ADD_FINALSTATE:
209:                    addNewExtraState(X, Y, StateTypeEnum.FINAL);
210:                    return true;
211:                case ADD_TRANSITION:
212:                    Application.showWarning(Application
213:                            .getString("selectvertex_message"));
214:                    return true;
215:                }
216:                return false;
217:            }
218:
219:            // insert entity vertex into the model    
220:            private void addNewState(int X, int Y) {
221:                try {
222:                    StateMachine lStateMachine = getStateMachine();
223:                    if (lStateMachine != null) {
224:                        StateUserObject lObject = StateUserObject
225:                                .addNewState(getStateMachine());
226:                        if (lObject != null)
227:                            ((StatesModel) mModel).addStateCell(lObject
228:                                    .getState(), new Point(X, Y));
229:                    }
230:                } catch (Exception e) {
231:                    Application.processError(e);
232:                }
233:            }
234:
235:            private void addNewExtraState(int X, int Y, StateType pType) {
236:                try {
237:                    StateUserObject lObject = StateUserObject.createNewState(
238:                            getStateMachine(), pType);
239:                    if (lObject != null)
240:                        ((StatesModel) mModel).addStateCell(lObject.getState(),
241:                                new Point(X, Y));
242:                } catch (Exception e) {
243:                    Application.processError(e);
244:                }
245:            }
246:
247:            private void setActionsState() {
248:                if (!mLoading && mAddStartStateAction != null) {
249:                    DefaultGraphCell lCell = ((StatesModel) mModel)
250:                            .findInitialState();
251:                    mAddStartStateAction.setEnabled(lCell == null);
252:                }
253:            }
254:
255:            // check object excepted by current diagram
256:            public boolean isObjectExcepted(BaseUserObject pObject) {
257:                boolean lResult = false;
258:                if (pObject != null
259:                        && mModel != null
260:                        && (pObject instanceof  StateUserObject || pObject instanceof  TransitionUserObject)) {
261:                    StatesModel lModel = (StatesModel) mModel;
262:                    DefaultGraphCell lCell = lModel.findElementCell(pObject);
263:                    if (lCell == null) {
264:                        if (pObject instanceof  StateUserObject) {
265:                            StateUserObject lStateUserObject = (StateUserObject) pObject;
266:                            State lState = ((StateUserObject) lStateUserObject)
267:                                    .getState();
268:                            if (lState != null
269:                                    && lModel.getEntity().equals(
270:                                            lState.getStateMachine()
271:                                                    .getEntity())) {
272:                                lResult = true;
273:                                if (lState.getType() == StateTypeEnum.INITIAL) {
274:                                    DefaultGraphCell lStartCell = lModel
275:                                            .findInitialState();
276:                                    if (lStartCell != null)
277:                                        lResult = false;
278:                                }
279:                            }
280:                        } else if (pObject instanceof  TransitionUserObject) {
281:                            TransitionUserObject lTransitionUserObject = (TransitionUserObject) pObject;
282:                            Transition lTransition = lTransitionUserObject
283:                                    .getStateTransition();
284:                            if (lTransition != null
285:                                    && lModel.getEntity().equals(
286:                                            lTransition.getStateMachine()
287:                                                    .getEntity())) {
288:                                DefaultGraphCell lCellA = lModel
289:                                        .findElementCell(lTransition
290:                                                .getStartState());
291:                                DefaultGraphCell lCellB = lModel
292:                                        .findElementCell(lTransition
293:                                                .getEndState());
294:                                lResult = (lCellA != null && lCellB != null);
295:                            }
296:                        }
297:                    }
298:                }
299:                return lResult;
300:            }
301:
302:            // insert new object into the diagram
303:            public void dropObject(BaseUserObject pObject, Point aLocation) {
304:                if (pObject == null || mModel == null)
305:                    return;
306:
307:                StatesModel lModel = (StatesModel) mModel;
308:                if (pObject instanceof  StateUserObject) {
309:                    StateUserObject lStateUserObject = (StateUserObject) pObject;
310:                    try {
311:                        lModel.addStateCell(lStateUserObject.getState(),
312:                                aLocation);
313:                    } catch (Exception e) {
314:                        e.printStackTrace();
315:                    }
316:                } else if (pObject instanceof  TransitionUserObject) {
317:                    TransitionUserObject lTransitionUserObject = (TransitionUserObject) pObject;
318:                    try {
319:                        lModel.addTransition(lTransitionUserObject
320:                                .getStateTransition());
321:                    } catch (Exception e) {
322:                        e.printStackTrace();
323:                    }
324:                }
325:            }
326:
327:            /*		       Actions		      */
328:
329:            /*		   Add State Action		  */
330:
331:            public class AddStateAction extends BaseSelectionAction {
332:                public AddStateAction() {
333:                    super (ADD_STATE, "New State", Application.STATE_ICON);
334:                }
335:            }
336:
337:            /*		Add Start State Action		*/
338:
339:            public class AddStartStateAction extends BaseSelectionAction {
340:                public AddStartStateAction() {
341:                    super (ADD_STARTSTATE, "New Initial State",
342:                            Application.GRAPH_INITIALSTATE_ICON);
343:                }
344:            }
345:
346:            /*		Add Final State Action		*/
347:
348:            public class AddFinalStateAction extends BaseSelectionAction {
349:                public AddFinalStateAction() {
350:                    super (ADD_FINALSTATE, "New Final State",
351:                            Application.GRAPH_FINALSTATE_ICON);
352:                }
353:            }
354:
355:            /*		Add Transition Action		*/
356:
357:            public class AddTransitionAction extends BaseSelectionAction {
358:                public AddTransitionAction() {
359:                    super (ADD_TRANSITION, "New Transition",
360:                            Application.GRAPH_ASSOCIATION_ICON);
361:                }
362:            }
363:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.