Source Code Cross Referenced for BaseUserObject.java in  » UML » MetaBoss » com » metaboss » applications » designstudio » 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 
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;
016:
017:        import java.awt.Cursor;
018:        import java.awt.datatransfer.DataFlavor;
019:        import java.awt.datatransfer.Transferable;
020:        import java.awt.datatransfer.UnsupportedFlavorException;
021:        import java.awt.event.ActionEvent;
022:        import java.io.IOException;
023:        import java.util.ArrayList;
024:        import java.util.Arrays;
025:        import java.util.Collection;
026:        import java.util.List;
027:
028:        import javax.jmi.model.MofClass;
029:        import javax.swing.Icon;
030:        import javax.swing.JOptionPane;
031:        import javax.swing.JTabbedPane;
032:        import javax.swing.UIManager;
033:
034:        import com.metaboss.applications.designstudio.attachmentspanel.AttachmentsPanel;
035:        import com.metaboss.applications.designstudio.components.SeparatorAction;
036:        import com.metaboss.applications.designstudio.dependencyview.DependencyViewPanel;
037:        import com.metaboss.applications.designstudio.propertiesview.PropertiesTableModel;
038:        import com.metaboss.applications.designstudio.sourceview.SourceViewPanel;
039:        import com.metaboss.applications.designstudio.tagstable.TagsPanel;
040:        import com.metaboss.applications.designstudio.userobjects.ModelElementAttachmentUserObject;
041:        import com.metaboss.applications.designstudio.userobjects.ModelUserObject;
042:        import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
043:        import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
044:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachment;
045:        import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachmentUtils;
046:
047:        /*    Base class for User Objects    */
048:
049:        public class BaseUserObject implements  Transferable {
050:            public static final String SOURCE_ATTACH = "Source";
051:            public static final int ALL_ACTIONS = 0;
052:            public static final int EMPTY_ACTION = -1;
053:            public static final DataFlavor USEROBJECT_FLAVOR = new DataFlavor(
054:                    DataFlavor.javaJVMLocalObjectMimeType, "UserObject"); //$NON-NLS-1$
055:
056:            // convert bool to string
057:            public static String boolToString(boolean lbool) {
058:                return (lbool) ? "yes" : "no";
059:            }
060:
061:            public static void addModelElement(PropertiesTableModel pModel,
062:                    String pName, ModelElement pObject) {
063:                pModel.AddProperty(pName, (pObject != null) ? pObject.getName()
064:                        : "");
065:            }
066:
067:            public static MetaBossModelPackage getObjectPackage(
068:                    ModelElement pPbject) {
069:                if (pPbject != null)
070:                    return (MetaBossModelPackage) pPbject.refOutermostPackage();
071:                else
072:                    return null;
073:            }
074:
075:            protected ModelElement mObject = null;
076:            protected Collection mMasterCollection = null;
077:            protected String mCaption = "";
078:            protected String mRef = "";
079:            protected MetaBossModelPackage mOldPackage = null;
080:            protected int mMode = 0;
081:            protected String mID = "";
082:            public boolean mConfirmDelete = true;
083:            public int mWarningCount = 0;
084:            //icon
085:            private Icon mIcon = null;
086:            private Icon mOpenIcon = null;
087:            private Icon mClosedIcon = null;
088:            //actions 
089:            //protected BaseAction    			mAddAction = new AddNewAction();
090:            protected BaseAction mEditAction = new EditAction();
091:            protected BaseAction mDeleteAction = new DeleteAction();
092:            protected BaseAction mViewSourceAction = new ViewSourceAction();
093:            protected BaseAction mDeleteSourceAction = new DeleteSourceAction();
094:            protected MoveToTopAction mMoveToTopAction = new MoveToTopAction();
095:            protected MoveUpAction mMoveUpAction = new MoveUpAction();
096:            protected MoveDownAction mMoveDownAction = new MoveDownAction();
097:            protected MoveToBottomAction mMoveToBottomAction = new MoveToBottomAction();
098:            protected DuplicateAction mDuplicateAction = null;
099:
100:            public BaseUserObject(ModelElement pObject, String pCaption,
101:                    int pMode) {
102:                this (pObject, null);
103:                mCaption = pCaption;
104:                mMode = pMode;
105:            }
106:
107:            public BaseUserObject(ModelElement pObject) {
108:                this (pObject, null);
109:            }
110:
111:            public BaseUserObject(ModelElement pObject, Icon aIcon) {
112:                mObject = pObject;
113:                if (mObject != null)
114:                    mID = mObject.refMofId();
115:
116:                if (aIcon != null) {
117:                    mIcon = aIcon;
118:                    mOpenIcon = aIcon;
119:                    mClosedIcon = aIcon;
120:                } else {
121:                    LoadDefaultIcons();
122:                }
123:            }
124:
125:            public boolean equals(Object obj) {
126:                if (obj instanceof  BaseUserObject)
127:                    return obj.getClass().equals(getClass())
128:                            && ((BaseUserObject) obj).getID().equals(getID());
129:                else
130:                    return super .equals(obj);
131:            }
132:
133:            public String toString() {
134:                if (mCaption.length() > 0)
135:                    return mCaption;
136:                else {
137:                    if (mObject != null)
138:                        return mObject.getName();
139:                    else
140:                        return null;
141:                }
142:            }
143:
144:            // get element package
145:            public MetaBossModelPackage getPackage() {
146:                if (mObject != null)
147:                    return (MetaBossModelPackage) mObject.refOutermostPackage();
148:                else
149:                    return mOldPackage;
150:            }
151:
152:            // get master element
153:            public ModelElement getMasterElement() {
154:                if (mObject != null)
155:                    return (ModelElement) mObject.refImmediateComposite();
156:                else
157:                    return null;
158:            }
159:
160:            // return collection
161:            public Collection getMasterCollection() {
162:                return mMasterCollection;
163:            }
164:
165:            public void setMasterCollection(Collection pCollection) {
166:                mMasterCollection = pCollection;
167:            }
168:
169:            // return mode
170:            public int getMode() {
171:                return mMode;
172:            }
173:
174:            public String getID() {
175:                return mID;
176:            }
177:
178:            // return ref of the object
179:            public String getRef() {
180:                if (mObject != null)
181:                    return mObject.getRef();
182:                else
183:                    return mRef;
184:            }
185:
186:            // return object root node captions
187:            public String getRootNodeName() {
188:                return "New Objects";
189:            }
190:
191:            // return object's description or any other information for tool tips
192:            public String getToolTip() {
193:                return (mObject != null) ? mObject.getDescription() : null;
194:            }
195:
196:            // return object caption fo container
197:            public String getContainerCaption() {
198:                ModelUserObject lModel = Application.getModel(getPackage());
199:                return (lModel != null) ? lModel.getModelName() + " : "
200:                        + toString() : toString();
201:            }
202:
203:            // get Element type
204:            public String getElementType() {
205:                return ((MofClass) mObject.refMetaObject()).refGetValue("name")
206:                        .toString();
207:            }
208:
209:            // return BOObject
210:            public ModelElement getBOObject() {
211:                return mObject;
212:            }
213:
214:            // get icon
215:            public Icon getIcon() {
216:                return mIcon;
217:            }
218:
219:            // get icon for opened node
220:            public Icon getOpenIcon() {
221:                return mOpenIcon;
222:            }
223:
224:            // get icon for closed mode
225:            public Icon getClosedIcon() {
226:                return mClosedIcon;
227:            }
228:
229:            // return Actions array
230:            public Object[] getActions() {
231:                ArrayList lActionsList = new ArrayList();
232:                fillActionsList(lActionsList);
233:                return lActionsList.toArray();
234:            }
235:
236:            // fill actions list
237:            public void fillActionsList(ArrayList pList) {
238:                //???if (mMasterCollection!=null) pList.add(mAddAction);
239:                pList.add(mEditAction);
240:                pList.add(mDeleteAction);
241:                if (canDuplicate()) {
242:                    if (mDuplicateAction == null)
243:                        mDuplicateAction = new DuplicateAction();
244:                    pList.add(mDuplicateAction);
245:                }
246:                if (hasSource()) {
247:                    pList.add(new SeparatorAction());
248:                    pList.add(mViewSourceAction);
249:                    pList.add(mDeleteSourceAction);
250:                }
251:                ModelCollectionInfo lCollectionInfo = extractMasterCollection();
252:                if (lCollectionInfo != null) {
253:                    setMoveActionsActivity();
254:                    pList.add(new SeparatorAction());
255:                    pList.add(mMoveToTopAction);
256:                    pList.add(mMoveUpAction);
257:                    pList.add(mMoveDownAction);
258:                    pList.add(mMoveToBottomAction);
259:                }
260:            }
261:
262:            // create new model object
263:            public BaseUserObject createNewObject(MetaBossModelPackage pPackage) {
264:                return null;
265:            }
266:
267:            // add new object
268:            public BaseUserObject addNewObject(MetaBossModelPackage pPackage,
269:                    Collection pMasterCollection) throws Exception {
270:                BaseUserObject lResult = null;
271:                boolean lNeedTransaction = !Application.isInTransaction();
272:
273:                if (lNeedTransaction)
274:                    Application.beginTransaction();
275:                try {
276:                    lResult = createNewObject(pPackage);
277:                    if (pMasterCollection != null) {
278:                        pMasterCollection.add(lResult.getBOObject());
279:                        lResult.mMasterCollection = pMasterCollection;
280:                    }
281:                    if (lNeedTransaction)
282:                        Application.commit();
283:                } finally {
284:                    if (lNeedTransaction)
285:                        Application.checkAndRollback();
286:                }
287:                Application.fireObjectSelect(lResult);
288:                lResult.editObject();
289:                return lResult;
290:            }
291:
292:            public BaseUserObject addNewObject(MetaBossModelPackage pPackage)
293:                    throws Exception {
294:                return addNewObject(pPackage, mMasterCollection);
295:            }
296:
297:            // edit object
298:            public void editObject() throws Exception {
299:                BasePropertiesDialog lDialog = getObjectEditor();
300:                if (lDialog == null)
301:                    throw new Exception(Application
302:                            .getString("nodialog_message"));
303:
304:                lDialog.loadProperties(mObject);
305:                if (lDialog.getModalResult() == BasePropertiesDialog.MR_OK) {
306:                    boolean lNeedTransaction = !Application.isInTransaction();
307:                    if (lNeedTransaction)
308:                        Application.beginTransaction();
309:                    try {
310:                        lDialog.saveProperties(mObject);
311:                        if (lNeedTransaction)
312:                            Application.commit();
313:                    } finally {
314:                        if (lNeedTransaction)
315:                            Application.checkAndRollback();
316:                    }
317:                    Application.fireObjectEdited(this );
318:                }
319:                if (mObject != null)
320:                    mRef = mObject.getRef();
321:            }
322:
323:            // delete object
324:            public void deleteObject() throws Exception {
325:                if (mObject == null)
326:                    return;
327:
328:                boolean lNeedTransaction = !Application.isInTransaction();
329:                if (lNeedTransaction)
330:                    Application.beginTransaction();
331:                try {
332:                    mRef = mObject.getRef();
333:                    mOldPackage = getPackage();
334:
335:                    mObject.refDelete();
336:                    mObject = null;
337:                    if (lNeedTransaction)
338:                        Application.commit();
339:                } finally {
340:                    if (lNeedTransaction)
341:                        Application.checkAndRollback();
342:                }
343:            }
344:
345:            // get text for delete message 	
346:            public String getDeletePromptText() {
347:                Object[] arguments = { toString() };
348:                return java.text.MessageFormat.format(Application
349:                        .getString("delete_message"), arguments);
350:            }
351:
352:            // get object editor
353:            public BasePropertiesDialog getObjectEditor() {
354:                return null;
355:            }
356:
357:            // load object properties into grid control
358:            public void loadObjectProperties(PropertiesTableModel pModel)
359:                    throws Exception {
360:                if (pModel == null || mObject == null)
361:                    return;
362:
363:                //ModelElement lElement = getMasterElement();
364:                //if (lElement!=null) pModel.AddProperty("Master Element", lElement.getName()); 
365:
366:                pModel.AddProperty("MofId", mObject.refMofId());
367:                pModel.AddProperty("Name", mObject.getName());
368:                pModel.AddProperty("Type", getElementType());
369:                pModel.AddProperty("Ref", mObject.getRef());
370:                pModel.AddProperty("Owner Identifier", mObject
371:                        .getOwnerIdentifier());
372:                pModel.AddProperty("Description", mObject.getDescription());
373:            }
374:
375:            // add extra properties tabs
376:            public void addExtraPropertiesTabs(JTabbedPane pTabbedPane) {
377:                if (mObject != null) {
378:                    if (mObject.getTags().size() > 0)
379:                        pTabbedPane.insertTab(
380:                                Application.getString("tags_tab"), null,
381:                                new TagsPanel(mObject), null, 1);
382:                    if (mObject.getAttachments().size() > 0)
383:                        pTabbedPane.insertTab(Application
384:                                .getString("attachments_tab"), null,
385:                                new AttachmentsPanel(mObject), null, 1);
386:                }
387:            }
388:
389:            /*public BaseAction getAddAction()
390:            {
391:            	return mAddAction;
392:            }*/
393:
394:            public BaseAction getEditAction() {
395:                return mEditAction;
396:            }
397:
398:            public BaseAction getDeleteAction() {
399:                return mDeleteAction;
400:            }
401:
402:            // get object fields set information
403:            public Object[] getFieldDescriptors() {
404:                return null;
405:            }
406:
407:            // get element source from attachments 
408:            public String getSourceFromAttachment() {
409:                return ModelElementAttachmentUserObject
410:                        .getSourceFromAttachment(getSource());
411:            }
412:
413:            // check element has attached source code
414:            public boolean hasSource() {
415:                ModelElementAttachment lAttachment = getSource();
416:                return (lAttachment != null);
417:            }
418:
419:            // get element source attachment
420:            public ModelElementAttachment getSource() {
421:                if (mObject != null) {
422:                    ModelElementAttachment lAttachment = mObject
423:                            .findAttachment(SOURCE_ATTACH);
424:                    return lAttachment;
425:                }
426:                return null;
427:            }
428:
429:            public boolean addToTree() {
430:                return true;
431:            }
432:
433:            // load default icons
434:            public void LoadDefaultIcons() {
435:                //mIcon = UIManager.getIcon("Tree.leafIcon");
436:                mIcon = UIManager.getIcon("Tree.closedIcon");
437:                mOpenIcon = UIManager.getIcon("Tree.openIcon");
438:                mClosedIcon = UIManager.getIcon("Tree.closedIcon");
439:            }
440:
441:            // convert tree element to an action code
442:            public int convertCaptionToAction(String pCaption) {
443:                return EMPTY_ACTION;
444:            }
445:
446:            // view source    
447:            protected void viewSource() {
448:                Application.fireShowContainer(new SourceViewPanel(this ), this ,
449:                        Application.VIEWSOURCE_ICON);
450:            }
451:
452:            // delete source attachment
453:            protected void deleteSource() throws Exception {
454:                boolean lNeedTransaction = !Application.isInTransaction();
455:
456:                if (lNeedTransaction)
457:                    Application.beginTransaction();
458:                try {
459:                    ModelElementAttachment lAttachment = getSource();
460:                    if (lAttachment != null) {
461:                        ModelElementAttachmentUtils
462:                                .deleteAttachmentData(lAttachment);
463:                        lAttachment.refDelete();
464:                    }
465:                    if (lNeedTransaction)
466:                        Application.commit();
467:                } finally {
468:                    if (lNeedTransaction)
469:                        Application.checkAndRollback();
470:                }
471:                Application.fireObjectSelected(this );
472:            }
473:
474:            // add new source attachment
475:            protected void addSource() throws Exception {
476:                boolean lNeedTransaction = !Application.isInTransaction();
477:                boolean lOK = false;
478:
479:                if (lNeedTransaction)
480:                    Application.beginTransaction();
481:                try {
482:                    ModelElementAttachmentUserObject
483:                            .addSourceAttachment(mObject);
484:                    if (lNeedTransaction)
485:                        Application.commit();
486:                    lOK = true;
487:                } finally {
488:                    if (lNeedTransaction)
489:                        Application.checkAndRollback();
490:                }
491:                Application.fireObjectSelected(this );
492:                if (lOK)
493:                    viewSource();
494:            }
495:
496:            // add new diagram
497:            protected void addNewDiagram() {
498:                //???
499:            }
500:
501:            // view systems diagram
502:            public void viewDependencies() {
503:                ModelElement lElement = getBOObject();
504:                if (lElement == null)
505:                    return;
506:                try {
507:                    Application
508:                            .fireShowContainer(new DependencyViewPanel(
509:                                    lElement, 1), this ,
510:                                    Application.SYSTEMSDIAGRAM_ICON);
511:                } catch (Exception e) {
512:                    e.printStackTrace();
513:                }
514:            }
515:
516:            /*      Property Access Methods       */
517:
518:            /*             Caption                */
519:
520:            // get caption
521:            public String GetCaption() {
522:                return mCaption;
523:            }
524:
525:            // set caption value
526:            public void SetCaption(String value) {
527:                mCaption = value;
528:            }
529:
530:            /*              Mode                 */
531:
532:            // get user object mode
533:            public int GetMode() {
534:                return mMode;
535:            }
536:
537:            // set user object mode
538:            public void SetMode(int value) {
539:                mMode = value;
540:            }
541:
542:            /*     Transferable interface implementation       */
543:
544:            private DataFlavor[] flavors = { USEROBJECT_FLAVOR };
545:
546:            /* (non-Javadoc)
547:             * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
548:             */
549:            public DataFlavor[] getTransferDataFlavors() {
550:                return flavors;
551:            }
552:
553:            /* (non-Javadoc)
554:             * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
555:             */
556:            public boolean isDataFlavorSupported(DataFlavor flavor) {
557:                return Arrays.asList(flavors).contains(flavor);
558:            }
559:
560:            /* (non-Javadoc)
561:             * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
562:             */
563:            public Object getTransferData(DataFlavor flavor)
564:                    throws UnsupportedFlavorException, IOException {
565:                if (flavor == USEROBJECT_FLAVOR) {
566:                    return this ;
567:                } else {
568:                    throw new UnsupportedFlavorException(flavor);
569:                }
570:            }
571:
572:            // return master collection
573:            protected ModelCollectionInfo extractMasterCollection() {
574:                return null;
575:            }
576:
577:            // move user object to the very top
578:            public void moveUserObjectToTop() throws Exception {
579:                ModelCollectionInfo lCollectionInfo = extractMasterCollection();
580:                if (lCollectionInfo != null) {
581:                    List lCollection = lCollectionInfo.mCollection;
582:                    if (lCollection != null) {
583:                        int lIndex = lCollection.indexOf(mObject);
584:                        moveUserObject(lCollection, 0, lIndex);
585:                    }
586:                }
587:            }
588:
589:            // move user object up
590:            public void moveUserObjectUp() throws Exception {
591:                ModelCollectionInfo lCollectionInfo = extractMasterCollection();
592:                if (lCollectionInfo != null) {
593:                    List lCollection = lCollectionInfo.mCollection;
594:                    if (lCollection != null) {
595:                        int lIndex = lCollection.indexOf(mObject);
596:                        if (lIndex > 0)
597:                            moveUserObject(lCollection, lIndex - 1, lIndex);
598:                    }
599:                }
600:            }
601:
602:            // move user object up
603:            public void moveUserObjectDown() throws Exception {
604:                ModelCollectionInfo lCollectionInfo = extractMasterCollection();
605:                if (lCollectionInfo != null) {
606:                    List lCollection = lCollectionInfo.mCollection;
607:                    if (lCollection != null) {
608:                        int lIndex = lCollection.indexOf(mObject);
609:                        if (lIndex < (lCollection.size() - 1))
610:                            moveUserObject(lCollection, lIndex + 1, lIndex);
611:                    }
612:                }
613:            }
614:
615:            // move user object to the very bottom
616:            public void moveUserObjectToBottom() throws Exception {
617:                ModelCollectionInfo lCollectionInfo = extractMasterCollection();
618:                if (lCollectionInfo != null) {
619:                    List lCollection = lCollectionInfo.mCollection;
620:                    if (lCollection != null) {
621:                        int lIndex = lCollection.indexOf(mObject);
622:                        moveUserObject(lCollection, lCollection.size() - 1,
623:                                lIndex);
624:                    }
625:                }
626:            }
627:
628:            private void moveUserObject(List pUserObjectCollection,
629:                    int pNewIndex, int pCurrentIndex) throws Exception {
630:                if (pNewIndex != pCurrentIndex) {
631:                    boolean lNeedTransaction = !Application.isInTransaction();
632:                    if (lNeedTransaction)
633:                        Application.beginTransaction();
634:                    try {
635:                        Object lObject = pUserObjectCollection
636:                                .remove(pCurrentIndex);
637:                        pUserObjectCollection.add(pNewIndex, lObject);
638:
639:                        if (lNeedTransaction)
640:                            Application.commit();
641:                        Application.fireIndexChanged(this , pCurrentIndex,
642:                                pNewIndex);
643:                        Application.fireObjectEdited(this );
644:                    } finally {
645:                        if (lNeedTransaction)
646:                            Application.checkAndRollback();
647:                    }
648:                    setMoveActionsActivity();
649:                }
650:            }
651:
652:            // set enabled property for "move up" and "move down" actions
653:            protected void setMoveActionsActivity() {
654:                boolean lUpEnabled = false;
655:                boolean lDownEnabled = false;
656:
657:                ModelCollectionInfo lCollectionInfo = extractMasterCollection();
658:                if (lCollectionInfo != null) {
659:                    List lCollection = lCollectionInfo.mCollection;
660:                    if (lCollection != null) {
661:                        int lIndex = lCollection.indexOf(mObject);
662:                        if (lIndex > 0)
663:                            lUpEnabled = true;
664:                        if (lIndex < lCollection.size() - 1)
665:                            lDownEnabled = true;
666:                    }
667:                }
668:
669:                mMoveToTopAction.setEnabled(lUpEnabled);
670:                mMoveUpAction.setEnabled(lUpEnabled);
671:                mMoveDownAction.setEnabled(lDownEnabled);
672:                mMoveToBottomAction.setEnabled(lDownEnabled);
673:            }
674:
675:            // can duplicate model element
676:            public boolean canDuplicate() {
677:                return false;
678:            }
679:
680:            // duplicate model element
681:            public ModelElement duplicate() throws Exception {
682:                return null;
683:            }
684:
685:            // returns true if drop object could be accepted
686:            public boolean canAcceptDropObject(BaseUserObject pUserObject,
687:                    boolean pCopy) {
688:                return mObject != null
689:                        && mObject.mayContain(pUserObject.getBOObject());
690:            }
691:
692:            // accept drop object
693:            public void acceptDropObject(BaseUserObject pUserObject,
694:                    boolean pCopy) throws Exception {
695:                boolean lNeedTransaction = !Application.isInTransaction();
696:                boolean lOK = false;
697:
698:                if (lNeedTransaction)
699:                    Application.beginTransaction();
700:                try {
701:                    transactionalAccept(pUserObject, pCopy);
702:                    if (lNeedTransaction)
703:                        Application.commit();
704:                    lOK = true;
705:                } finally {
706:                    if (lNeedTransaction)
707:                        Application.checkAndRollback();
708:                }
709:                if (!pCopy) {
710:                    //Application.fireObjectDeleted(pUserObject);
711:                    //Application.fireObjectInserted(pUserObject);
712:                    Application.fireObjectMoved(pUserObject);
713:                }
714:            }
715:
716:            // acccept drop target in transaction
717:            protected void transactionalAccept(BaseUserObject pUserObject,
718:                    boolean pCopy) throws Exception {
719:                //???
720:            }
721:
722:            /*          Auxilary clases          */
723:
724:            /*    Model Collection info class     */
725:
726:            public class ModelCollectionInfo {
727:                public List mCollection = null;
728:                public ModelElement mElement = null;
729:
730:                public ModelCollectionInfo(List pCollection,
731:                        ModelElement pElement) {
732:                    mCollection = pCollection;
733:                    mElement = pElement;
734:                }
735:            }
736:
737:            /*				Actions				 */
738:
739:            /*public class AddNewAction extends BaseAction
740:            {
741:            	public AddNewAction()
742:            	{
743:            		super("Add", Application.ADDNEW_ICON);
744:            	}
745:            
746:            	public void actionPerformed(ActionEvent e) 
747:            	{
748:            		try
749:            		{
750:            			addNewObject(getPackage());
751:            		}
752:            		catch(Throwable t)
753:            		{
754:            			Application.processError(t);
755:            		}
756:            	}
757:            }*/
758:
759:            public class EditAction extends BaseAction {
760:                public EditAction() {
761:                    super (Application.getString("editproperties_action"),
762:                            Application.EDIT_ICON);
763:                }
764:
765:                public void actionPerformed(ActionEvent e) {
766:                    try {
767:                        editObject();
768:                    } catch (Throwable t) {
769:                        Application.processError(t);
770:                    }
771:                }
772:            }
773:
774:            public class DeleteAction extends BaseAction {
775:                public DeleteAction() {
776:                    super (Application.getString("delete_action"),
777:                            Application.DELETE_ICON);
778:                }
779:
780:                public void actionPerformed(ActionEvent e) {
781:                    try {
782:                        int n = (mConfirmDelete) ? JOptionPane
783:                                .showConfirmDialog(null, getDeletePromptText(),
784:                                        Application.getString("confirm"),
785:                                        JOptionPane.YES_NO_OPTION) : 0;
786:                        if (n == 0)
787:                            deleteObject();
788:                    } catch (Throwable t) {
789:                        Application.processError(t);
790:                    }
791:                }
792:            }
793:
794:            public class ViewSourceAction extends BaseAction {
795:                public ViewSourceAction() {
796:                    super (Application.getString("editsource_action"),
797:                            Application.VIEWSOURCE_ICON);
798:                }
799:
800:                public void actionPerformed(ActionEvent e) {
801:                    try {
802:                        viewSource();
803:                    } catch (Throwable t) {
804:                        t.printStackTrace();
805:                    }
806:                }
807:            }
808:
809:            public class DeleteSourceAction extends BaseAction {
810:                public DeleteSourceAction() {
811:                    super (Application.getString("deletesource_action"),
812:                            Application.DELETESOURCE_ICON);
813:                }
814:
815:                public void actionPerformed(ActionEvent e) {
816:                    try {
817:                        int n = (mConfirmDelete) ? JOptionPane
818:                                .showConfirmDialog(null, Application
819:                                        .getString("deleteattachment_message"),
820:                                        Application.getString("confirm"),
821:                                        JOptionPane.YES_NO_OPTION) : 0;
822:                        if (n == 0)
823:                            deleteSource();
824:                    } catch (Throwable t) {
825:                        t.printStackTrace();
826:                    }
827:                }
828:            }
829:
830:            public class AddSourceAction extends BaseAction {
831:                public AddSourceAction() {
832:                    super (Application.getString("addsource_action"),
833:                            Application.ADDSOURCE_ICON);
834:                }
835:
836:                public void actionPerformed(ActionEvent e) {
837:                    try {
838:                        addSource();
839:                    } catch (Throwable t) {
840:                        t.printStackTrace();
841:                    }
842:                }
843:            }
844:
845:            /*      Add Diagram Action        */
846:
847:            public class AddDiagramAction extends BaseAction {
848:                public AddDiagramAction() {
849:                    super (Application.getString("adddiagram_action"),
850:                            Application.getAddIcon(Application.DIAGRAM_ICON));
851:                }
852:
853:                public void actionPerformed(ActionEvent e) {
854:                    addNewDiagram();
855:                }
856:            }
857:
858:            /*      Show Systems diagram        */
859:
860:            public class StudyDependenciesAction extends BaseAction {
861:                public StudyDependenciesAction() {
862:                    super (Application.getString("studydependencies_action"),
863:                            Application.FITTOSIZE_ICON);
864:                }
865:
866:                public void actionPerformed(ActionEvent arg0) {
867:                    viewDependencies();
868:                }
869:            }
870:
871:            /*   Move model element to top action   */
872:            public class MoveToTopAction extends BaseAction {
873:                public MoveToTopAction() {
874:                    super ("Move To Top", Application.MOVEUP_ICON);
875:                }
876:
877:                public void actionPerformed(ActionEvent e) {
878:                    try {
879:                        moveUserObjectToTop();
880:                    } catch (Exception ex) {
881:                        ex.printStackTrace();
882:                    }
883:                }
884:            }
885:
886:            /*   Move model element up action   */
887:            public class MoveUpAction extends BaseAction {
888:                public MoveUpAction() {
889:                    super ("Move Up", Application.MOVEUP_ICON);
890:                }
891:
892:                public void actionPerformed(ActionEvent e) {
893:                    try {
894:                        moveUserObjectUp();
895:                    } catch (Exception ex) {
896:                        ex.printStackTrace();
897:                    }
898:                }
899:            }
900:
901:            /*   Move model element down action   */
902:
903:            public class MoveDownAction extends BaseAction {
904:                public MoveDownAction() {
905:                    super ("Move Down", Application.MOVEDOWN_ICON);
906:                }
907:
908:                public void actionPerformed(ActionEvent e) {
909:                    try {
910:                        moveUserObjectDown();
911:                    } catch (Exception ex) {
912:                        ex.printStackTrace();
913:                    }
914:                }
915:            }
916:
917:            /*   Move model element to bottom action   */
918:            public class MoveToBottomAction extends BaseAction {
919:                public MoveToBottomAction() {
920:                    super ("Move To Bottom", Application.MOVEDOWN_ICON);
921:                }
922:
923:                public void actionPerformed(ActionEvent e) {
924:                    try {
925:                        moveUserObjectToBottom();
926:                    } catch (Exception ex) {
927:                        ex.printStackTrace();
928:                    }
929:                }
930:            }
931:
932:            /*      Duplicate ModelElement Action       */
933:
934:            public class DuplicateAction extends BaseAction {
935:                public DuplicateAction() {
936:                    super ("Duplicate Element", Application.COPYELEMENT_ICON);
937:                }
938:
939:                public void actionPerformed(ActionEvent e) {
940:                    try {
941:                        Cursor lCursor = Application.mainFrame.getCursor();
942:                        try {
943:                            Application.mainFrame.setCursor(new Cursor(
944:                                    Cursor.WAIT_CURSOR));
945:
946:                            boolean lInTransaction = Application
947:                                    .isInTransaction();
948:                            if (!lInTransaction)
949:                                Application.beginTransaction();
950:                            try {
951:                                duplicate();
952:                                if (!lInTransaction)
953:                                    Application.commit();
954:                            } finally {
955:                                if (!lInTransaction)
956:                                    Application.checkAndRollback();
957:                            }
958:                        } catch (Exception ex) {
959:                            Application.processError(ex);
960:                        } finally {
961:                            Application.mainFrame.setCursor(lCursor);
962:                        }
963:                    } catch (Throwable t) {
964:                        Application.processError(t);
965:                    }
966:                }
967:            }
968:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.