Source Code Cross Referenced for FlowEditor.java in  » Workflow-Engines » OpenWFE » org » openwfe » gpe » ui » 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 » Workflow Engines » OpenWFE » org.openwfe.gpe.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.openwfe.gpe.ui;
002:
003:        import java.io.ByteArrayInputStream;
004:        import java.io.ByteArrayOutputStream;
005:        import java.io.IOException;
006:        import java.io.InputStream;
007:        import java.io.ObjectInputStream;
008:        import java.io.ObjectOutputStream;
009:        import java.io.OutputStream;
010:        import java.util.EventObject;
011:
012:        import org.eclipse.swt.SWT;
013:
014:        import org.eclipse.core.resources.IFile;
015:        import org.eclipse.core.resources.IMarker;
016:        import org.eclipse.core.resources.IWorkspace;
017:        import org.eclipse.core.resources.ResourcesPlugin;
018:        import org.eclipse.core.runtime.CoreException;
019:        import org.eclipse.core.runtime.IPath;
020:        import org.eclipse.core.runtime.IProgressMonitor;
021:        import org.eclipse.jface.action.IAction;
022:        import org.eclipse.jface.dialogs.ProgressMonitorDialog;
023:        import org.eclipse.ui.IEditorInput;
024:        import org.eclipse.ui.IEditorPart;
025:        import org.eclipse.ui.IFileEditorInput;
026:        import org.eclipse.ui.IWorkbenchPart;
027:        import org.eclipse.ui.actions.WorkspaceModifyOperation;
028:        import org.eclipse.ui.dialogs.SaveAsDialog;
029:        import org.eclipse.ui.part.FileEditorInput;
030:        import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
031:
032:        import org.eclipse.gef.ContextMenuProvider;
033:        import org.eclipse.gef.DefaultEditDomain;
034:        import org.eclipse.gef.EditPart;
035:        import org.eclipse.gef.KeyHandler;
036:        import org.eclipse.gef.KeyStroke;
037:        import org.eclipse.gef.commands.CommandStack;
038:        import org.eclipse.gef.dnd.TemplateTransferDragSourceListener;
039:        import org.eclipse.gef.editparts.ScalableRootEditPart;
040:        import org.eclipse.gef.palette.PaletteRoot;
041:        import org.eclipse.gef.tools.ConnectionCreationTool;
042:        import org.eclipse.gef.ui.actions.ActionRegistry;
043:        import org.eclipse.gef.ui.actions.DirectEditAction;
044:        import org.eclipse.gef.ui.actions.GEFActionConstants;
045:        import org.eclipse.gef.ui.parts.GraphicalEditorWithPalette;
046:        import org.eclipse.gef.ui.parts.GraphicalViewerKeyHandler;
047:
048:        import org.openwfe.gpe.FlowEditorPaletteFactory;
049:        import org.openwfe.gpe.actions.FlowContextMenuProvider;
050:        import org.openwfe.gpe.model.ActivityDiagram;
051:        import org.openwfe.gpe.parts.FlowElementPartFactory;
052:
053:        /**
054:         * 
055:         * @author helena
056:         * This class creates the new editor window with the palette and the outline
057:         */
058:        public class FlowEditor extends GraphicalEditorWithPalette {
059:
060:            ActivityDiagram diagram;
061:            private PaletteRoot root;
062:            private KeyHandler sharedKeyHandler;
063:            private boolean savePreviouslyNeeded = false;
064:            CommandStack stack = null;
065:            EditPart viewer = null;
066:            ActionRegistry registry = null;
067:
068:            public FlowEditor() {
069:                DefaultEditDomain defaultEditDomain = new DefaultEditDomain(
070:                        this );
071:                defaultEditDomain.setActiveTool(new ConnectionCreationTool());
072:                setEditDomain(defaultEditDomain);
073:            }
074:
075:            /**
076:             * @see org.eclipse.gef.commands.CommandStackListener#commandStackChanged(java.util.EventObject)
077:             */
078:            public void commandStackChanged(EventObject event) {
079:                if (isDirty()) {
080:                    if (!savePreviouslyNeeded()) {
081:                        setSavePreviouslyNeeded(true);
082:                        firePropertyChange(IEditorPart.PROP_DIRTY);
083:                    }
084:                } else {
085:                    setSavePreviouslyNeeded(false);
086:                    firePropertyChange(IEditorPart.PROP_DIRTY);
087:                }
088:                super .commandStackChanged(event);
089:            }
090:
091:            /**
092:             * @see org.eclipse.gef.ui.parts.GraphicalEditor#createActions()
093:             */
094:            protected void createActions() {
095:                super .createActions();
096:                ActionRegistry registry = getActionRegistry();
097:                IAction action;
098:
099:                action = new DirectEditAction((IWorkbenchPart) this );
100:                registry.registerAction(action);
101:                getSelectionActions().add(action.getId());
102:            }
103:
104:            /**
105:             * Creates an appropriate output stream and writes the activity diagram out to this stream.
106:             * @param os the base output stream
107:             * @throws IOException
108:             */
109:            protected void createOutputStream(OutputStream os)
110:                    throws IOException {
111:                ObjectOutputStream out = new ObjectOutputStream(os);
112:                out.writeObject(diagram);
113:                out.close();
114:            }
115:
116:            /**
117:             * @see org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()
118:             */
119:            protected void configureGraphicalViewer() {
120:                super .configureGraphicalViewer();
121:                getGraphicalViewer()
122:                        .setRootEditPart(new ScalableRootEditPart());
123:                getGraphicalViewer().setEditPartFactory(
124:                        new FlowElementPartFactory());
125:                getGraphicalViewer().setKeyHandler(
126:                        new GraphicalViewerKeyHandler(getGraphicalViewer())
127:                                .setParent(getCommonKeyHandler()));
128:
129:                ContextMenuProvider provider = new FlowContextMenuProvider(
130:                        getGraphicalViewer(), getActionRegistry());
131:                getGraphicalViewer().setContextMenu(provider);
132:                getSite().registerContextMenu(
133:                        "org.openwfe.gpe.editor.contextmenu", //$NON-NLS-1$
134:                        provider, getGraphicalViewer());
135:
136:            }
137:
138:            /**
139:             * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
140:             */
141:            protected void initializeGraphicalViewer() {
142:                getGraphicalViewer().setContents(diagram);
143:                //getGraphicalViewer().addDropTargetListener(
144:                //new FlowTemplateTransferDropTargetListener(getGraphicalViewer()));
145:
146:            }
147:
148:            /**
149:             * @see org.eclipse.gef.ui.parts.GraphicalEditorWithPalette#initializePaletteViewer()
150:             */
151:            protected void initializePaletteViewer() {
152:                super .initializePaletteViewer();
153:                getPaletteViewer().addDragSourceListener(
154:                        new TemplateTransferDragSourceListener(
155:                                getPaletteViewer()));
156:            }
157:
158:            /**
159:             * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
160:             */
161:            public void doSave(IProgressMonitor monitor) {
162:                try {
163:                    ByteArrayOutputStream out = new ByteArrayOutputStream();
164:                    createOutputStream(out);
165:                    IFile file = ((IFileEditorInput) getEditorInput())
166:                            .getFile();
167:                    file.setContents(
168:                            new ByteArrayInputStream(out.toByteArray()), true,
169:                            false, monitor);
170:                    out.close();
171:                    getCommandStack().markSaveLocation();
172:                } catch (Exception e) {
173:                    e.printStackTrace();
174:                }
175:            }
176:
177:            /**
178:             * @see org.eclipse.ui.ISaveablePart#doSaveAs()
179:             */
180:            public void doSaveAs() {
181:                SaveAsDialog dialog = new SaveAsDialog(getSite()
182:                        .getWorkbenchWindow().getShell());
183:                dialog.setOriginalFile(((IFileEditorInput) getEditorInput())
184:                        .getFile());
185:                dialog.open();
186:                IPath path = dialog.getResult();
187:
188:                if (path == null)
189:                    return;
190:
191:                IWorkspace workspace = ResourcesPlugin.getWorkspace();
192:                final IFile file = workspace.getRoot().getFile(path);
193:
194:                WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
195:                    public void execute(final IProgressMonitor monitor)
196:                            throws CoreException {
197:                        try {
198:                            ByteArrayOutputStream out = new ByteArrayOutputStream();
199:                            createOutputStream(out);
200:                            file.create(new ByteArrayInputStream(out
201:                                    .toByteArray()), true, monitor);
202:                            out.close();
203:                        } catch (Exception e) {
204:                            e.printStackTrace();
205:                        }
206:                    }
207:                };
208:
209:                try {
210:                    new ProgressMonitorDialog(getSite().getWorkbenchWindow()
211:                            .getShell()).run(false, true, op);
212:                    setInput(new FileEditorInput((IFile) file));
213:                    getCommandStack().markSaveLocation();
214:                } catch (Exception e) {
215:                    e.printStackTrace();
216:                }
217:            }
218:
219:            protected KeyHandler getCommonKeyHandler() {
220:                if (sharedKeyHandler == null) {
221:                    sharedKeyHandler = new KeyHandler();
222:                    sharedKeyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0),
223:                            getActionRegistry().getAction(
224:                                    GEFActionConstants.DELETE));
225:                    sharedKeyHandler.put(KeyStroke.getPressed(SWT.F2, 0),
226:                            getActionRegistry().getAction(
227:                                    GEFActionConstants.DIRECT_EDIT));
228:                }
229:                return sharedKeyHandler;
230:            }
231:
232:            /**
233:             * @see org.eclipse.gef.ui.parts.GraphicalEditorWithPalette#getPaletteRoot()
234:             */
235:            protected PaletteRoot getPaletteRoot() {
236:                if (root == null)
237:                    root = FlowEditorPaletteFactory.createPalette();
238:                return root;
239:            }
240:
241:            public void gotoMarker(IMarker marker) {
242:            }
243:
244:            /**
245:             * @see org.eclipse.ui.ISaveablePart#isDirty()
246:             */
247:            public boolean isDirty() {
248:                return isSaveOnCloseNeeded();
249:            }
250:
251:            /**
252:             * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
253:             */
254:            public boolean isSaveAsAllowed() {
255:                return true;
256:            }
257:
258:            /**
259:             * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
260:             */
261:            public boolean isSaveOnCloseNeeded() {
262:                return getCommandStack().isDirty();
263:            }
264:
265:            private boolean savePreviouslyNeeded() {
266:                return savePreviouslyNeeded;
267:            }
268:
269:            /**
270:             * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
271:             */
272:            protected void setInput(IEditorInput input) {
273:                super .setInput(input);
274:
275:                IFile file = ((IFileEditorInput) input).getFile();
276:                try {
277:                    InputStream is = file.getContents(false);
278:                    ObjectInputStream ois = new ObjectInputStream(is);
279:                    diagram = (ActivityDiagram) ois.readObject();
280:                    ois.close();
281:                } catch (Exception e) {
282:                    //This is just an example.  All exceptions caught here.
283:                    e.printStackTrace();
284:                    diagram = new ActivityDiagram();
285:                }
286:            }
287:
288:            private void setSavePreviouslyNeeded(boolean value) {
289:                savePreviouslyNeeded = value;
290:            }
291:
292:            public DiagramOutlinePage createContentOutlinePage() {
293:                if (getGraphicalViewer() != null
294:                        && getGraphicalViewer().getContents() != null
295:                        && getActionRegistry() != null) {
296:                    DiagramOutlinePage page = new DiagramOutlinePage(
297:                            getCommandStack(), getGraphicalViewer()
298:                                    .getContents(), getActionRegistry());
299:                    return page;
300:                }
301:                return null;
302:            }
303:
304:            public Object getAdapter(Class aClass) {
305:                if (aClass == CommandStack.class) {
306:                    return getCommandStack();
307:                } else if (aClass == IContentOutlinePage.class) {
308:                    return createContentOutlinePage();
309:                }
310:                return super .getAdapter(aClass);
311:            }
312:
313:            /**
314:             * @return Returns the registry.
315:             */
316:            public ActionRegistry getRegistry() {
317:                return registry;
318:            }
319:
320:            /**
321:             * @return Returns the stack.
322:             */
323:            public CommandStack getStack() {
324:                return stack;
325:            }
326:
327:            /**
328:             * @return Returns the viewer.
329:             */
330:            public EditPart getViewer() {
331:                return viewer;
332:            }
333:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.