1 | /** |
2 | * <copyright> |
3 | * </copyright> |
4 | * |
5 | * $Id$ |
6 | */ |
7 | package de.uka.ipd.sdq.pipesandfilters.presentation; |
8 | |
9 | |
10 | import java.io.IOException; |
11 | import java.io.InputStream; |
12 | |
13 | import java.util.ArrayList; |
14 | import java.util.Collection; |
15 | import java.util.Collections; |
16 | import java.util.EventObject; |
17 | import java.util.HashMap; |
18 | import java.util.Iterator; |
19 | import java.util.LinkedHashMap; |
20 | import java.util.List; |
21 | import java.util.Map; |
22 | |
23 | import org.eclipse.core.resources.IFile; |
24 | import org.eclipse.core.resources.IMarker; |
25 | import org.eclipse.core.resources.IResource; |
26 | import org.eclipse.core.resources.IResourceChangeEvent; |
27 | import org.eclipse.core.resources.IResourceChangeListener; |
28 | import org.eclipse.core.resources.IResourceDelta; |
29 | import org.eclipse.core.resources.IResourceDeltaVisitor; |
30 | import org.eclipse.core.resources.ResourcesPlugin; |
31 | |
32 | import org.eclipse.core.runtime.CoreException; |
33 | import org.eclipse.core.runtime.IPath; |
34 | import org.eclipse.core.runtime.IProgressMonitor; |
35 | import org.eclipse.core.runtime.NullProgressMonitor; |
36 | |
37 | import org.eclipse.jface.action.IMenuListener; |
38 | import org.eclipse.jface.action.IMenuManager; |
39 | import org.eclipse.jface.action.IStatusLineManager; |
40 | import org.eclipse.jface.action.IToolBarManager; |
41 | import org.eclipse.jface.action.MenuManager; |
42 | import org.eclipse.jface.action.Separator; |
43 | |
44 | import org.eclipse.jface.dialogs.MessageDialog; |
45 | import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
46 | |
47 | import org.eclipse.jface.viewers.ColumnWeightData; |
48 | import org.eclipse.jface.viewers.ISelection; |
49 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
50 | import org.eclipse.jface.viewers.ISelectionProvider; |
51 | import org.eclipse.jface.viewers.IStructuredSelection; |
52 | import org.eclipse.jface.viewers.ListViewer; |
53 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
54 | import org.eclipse.jface.viewers.StructuredSelection; |
55 | import org.eclipse.jface.viewers.StructuredViewer; |
56 | import org.eclipse.jface.viewers.TableLayout; |
57 | import org.eclipse.jface.viewers.TableViewer; |
58 | import org.eclipse.jface.viewers.TreeViewer; |
59 | import org.eclipse.jface.viewers.Viewer; |
60 | |
61 | import org.eclipse.swt.SWT; |
62 | |
63 | import org.eclipse.swt.custom.CTabFolder; |
64 | |
65 | import org.eclipse.swt.dnd.DND; |
66 | import org.eclipse.swt.dnd.Transfer; |
67 | |
68 | import org.eclipse.swt.events.ControlAdapter; |
69 | import org.eclipse.swt.events.ControlEvent; |
70 | |
71 | import org.eclipse.swt.graphics.Point; |
72 | |
73 | import org.eclipse.swt.layout.FillLayout; |
74 | |
75 | import org.eclipse.swt.widgets.Composite; |
76 | import org.eclipse.swt.widgets.Menu; |
77 | import org.eclipse.swt.widgets.Table; |
78 | import org.eclipse.swt.widgets.TableColumn; |
79 | import org.eclipse.swt.widgets.Tree; |
80 | import org.eclipse.swt.widgets.TreeColumn; |
81 | |
82 | import org.eclipse.ui.IActionBars; |
83 | import org.eclipse.ui.IEditorInput; |
84 | import org.eclipse.ui.IEditorPart; |
85 | import org.eclipse.ui.IEditorSite; |
86 | import org.eclipse.ui.IPartListener; |
87 | import org.eclipse.ui.IWorkbenchPart; |
88 | import org.eclipse.ui.PartInitException; |
89 | |
90 | import org.eclipse.ui.dialogs.SaveAsDialog; |
91 | |
92 | import org.eclipse.ui.ide.IGotoMarker; |
93 | |
94 | import org.eclipse.ui.part.FileEditorInput; |
95 | import org.eclipse.ui.part.MultiPageEditorPart; |
96 | |
97 | import org.eclipse.ui.views.contentoutline.ContentOutline; |
98 | import org.eclipse.ui.views.contentoutline.ContentOutlinePage; |
99 | import org.eclipse.ui.views.contentoutline.IContentOutlinePage; |
100 | |
101 | import org.eclipse.ui.views.properties.IPropertySheetPage; |
102 | import org.eclipse.ui.views.properties.PropertySheet; |
103 | import org.eclipse.ui.views.properties.PropertySheetPage; |
104 | |
105 | import org.eclipse.emf.common.command.BasicCommandStack; |
106 | import org.eclipse.emf.common.command.Command; |
107 | import org.eclipse.emf.common.command.CommandStack; |
108 | import org.eclipse.emf.common.command.CommandStackListener; |
109 | |
110 | import org.eclipse.emf.common.notify.AdapterFactory; |
111 | import org.eclipse.emf.common.notify.Notification; |
112 | |
113 | import org.eclipse.emf.common.ui.MarkerHelper; |
114 | import org.eclipse.emf.common.ui.ViewerPane; |
115 | |
116 | import org.eclipse.emf.common.ui.editor.ProblemEditorPart; |
117 | |
118 | import org.eclipse.emf.common.ui.viewer.IViewerProvider; |
119 | |
120 | import org.eclipse.emf.common.util.BasicDiagnostic; |
121 | import org.eclipse.emf.common.util.Diagnostic; |
122 | import org.eclipse.emf.common.util.URI; |
123 | |
124 | import org.eclipse.emf.ecore.EObject; |
125 | import org.eclipse.emf.ecore.EValidator; |
126 | |
127 | import org.eclipse.emf.ecore.resource.Resource; |
128 | import org.eclipse.emf.ecore.resource.ResourceSet; |
129 | |
130 | import org.eclipse.emf.ecore.util.EContentAdapter; |
131 | import org.eclipse.emf.ecore.util.EcoreUtil; |
132 | |
133 | import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; |
134 | import org.eclipse.emf.edit.domain.EditingDomain; |
135 | import org.eclipse.emf.edit.domain.IEditingDomainProvider; |
136 | |
137 | import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator; |
138 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
139 | import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
140 | |
141 | import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
142 | |
143 | import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor; |
144 | |
145 | import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor; |
146 | |
147 | import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter; |
148 | import org.eclipse.emf.edit.ui.dnd.LocalTransfer; |
149 | import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter; |
150 | |
151 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; |
152 | import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; |
153 | import org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider; |
154 | |
155 | import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper; |
156 | import org.eclipse.emf.edit.ui.util.EditUIUtil; |
157 | |
158 | import org.eclipse.emf.edit.ui.view.ExtendedPropertySheetPage; |
159 | |
160 | import de.uka.ipd.sdq.pipesandfilters.provider.pipesandfiltersItemProviderAdapterFactory; |
161 | |
162 | import de.uka.ipd.sdq.identifier.provider.IdentifierItemProviderAdapterFactory; |
163 | |
164 | import org.eclipse.ui.actions.WorkspaceModifyOperation; |
165 | |
166 | |
167 | /** |
168 | * This is an example of a pipesandfilters model editor. |
169 | * <!-- begin-user-doc --> |
170 | * <!-- end-user-doc --> |
171 | * @generated |
172 | */ |
173 | public class pipesandfiltersEditor |
174 | extends MultiPageEditorPart |
175 | implements IEditingDomainProvider, ISelectionProvider, IMenuListener, IViewerProvider, IGotoMarker { |
176 | /** |
177 | * This keeps track of the editing domain that is used to track all changes to the model. |
178 | * <!-- begin-user-doc --> |
179 | * <!-- end-user-doc --> |
180 | * @generated |
181 | */ |
182 | protected AdapterFactoryEditingDomain editingDomain; |
183 | |
184 | /** |
185 | * This is the one adapter factory used for providing views of the model. |
186 | * <!-- begin-user-doc --> |
187 | * <!-- end-user-doc --> |
188 | * @generated |
189 | */ |
190 | protected ComposedAdapterFactory adapterFactory; |
191 | |
192 | /** |
193 | * This is the content outline page. |
194 | * <!-- begin-user-doc --> |
195 | * <!-- end-user-doc --> |
196 | * @generated |
197 | */ |
198 | protected IContentOutlinePage contentOutlinePage; |
199 | |
200 | /** |
201 | * This is a kludge... |
202 | * <!-- begin-user-doc --> |
203 | * <!-- end-user-doc --> |
204 | * @generated |
205 | */ |
206 | protected IStatusLineManager contentOutlineStatusLineManager; |
207 | |
208 | /** |
209 | * This is the content outline page's viewer. |
210 | * <!-- begin-user-doc --> |
211 | * <!-- end-user-doc --> |
212 | * @generated |
213 | */ |
214 | protected TreeViewer contentOutlineViewer; |
215 | |
216 | /** |
217 | * This is the property sheet page. |
218 | * <!-- begin-user-doc --> |
219 | * <!-- end-user-doc --> |
220 | * @generated |
221 | */ |
222 | protected PropertySheetPage propertySheetPage; |
223 | |
224 | /** |
225 | * This is the viewer that shadows the selection in the content outline. |
226 | * The parent relation must be correctly defined for this to work. |
227 | * <!-- begin-user-doc --> |
228 | * <!-- end-user-doc --> |
229 | * @generated |
230 | */ |
231 | protected TreeViewer selectionViewer; |
232 | |
233 | /** |
234 | * This inverts the roll of parent and child in the content provider and show parents as a tree. |
235 | * <!-- begin-user-doc --> |
236 | * <!-- end-user-doc --> |
237 | * @generated |
238 | */ |
239 | protected TreeViewer parentViewer; |
240 | |
241 | /** |
242 | * This shows how a tree view works. |
243 | * <!-- begin-user-doc --> |
244 | * <!-- end-user-doc --> |
245 | * @generated |
246 | */ |
247 | protected TreeViewer treeViewer; |
248 | |
249 | /** |
250 | * This shows how a list view works. |
251 | * A list viewer doesn't support icons. |
252 | * <!-- begin-user-doc --> |
253 | * <!-- end-user-doc --> |
254 | * @generated |
255 | */ |
256 | protected ListViewer listViewer; |
257 | |
258 | /** |
259 | * This shows how a table view works. |
260 | * A table can be used as a list with icons. |
261 | * <!-- begin-user-doc --> |
262 | * <!-- end-user-doc --> |
263 | * @generated |
264 | */ |
265 | protected TableViewer tableViewer; |
266 | |
267 | /** |
268 | * This shows how a tree view with columns works. |
269 | * <!-- begin-user-doc --> |
270 | * <!-- end-user-doc --> |
271 | * @generated |
272 | */ |
273 | protected TreeViewer treeViewerWithColumns; |
274 | |
275 | /** |
276 | * This keeps track of the active viewer pane, in the book. |
277 | * <!-- begin-user-doc --> |
278 | * <!-- end-user-doc --> |
279 | * @generated |
280 | */ |
281 | protected ViewerPane currentViewerPane; |
282 | |
283 | /** |
284 | * This keeps track of the active content viewer, which may be either one of the viewers in the pages or the content outline viewer. |
285 | * <!-- begin-user-doc --> |
286 | * <!-- end-user-doc --> |
287 | * @generated |
288 | */ |
289 | protected Viewer currentViewer; |
290 | |
291 | /** |
292 | * This listens to which ever viewer is active. |
293 | * <!-- begin-user-doc --> |
294 | * <!-- end-user-doc --> |
295 | * @generated |
296 | */ |
297 | protected ISelectionChangedListener selectionChangedListener; |
298 | |
299 | /** |
300 | * This keeps track of all the {@link org.eclipse.jface.viewers.ISelectionChangedListener}s that are listening to this editor. |
301 | * <!-- begin-user-doc --> |
302 | * <!-- end-user-doc --> |
303 | * @generated |
304 | */ |
305 | protected Collection<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>(); |
306 | |
307 | /** |
308 | * This keeps track of the selection of the editor as a whole. |
309 | * <!-- begin-user-doc --> |
310 | * <!-- end-user-doc --> |
311 | * @generated |
312 | */ |
313 | protected ISelection editorSelection = StructuredSelection.EMPTY; |
314 | |
315 | /** |
316 | * The MarkerHelper is responsible for creating workspace resource markers presented |
317 | * in Eclipse's Problems View. |
318 | * <!-- begin-user-doc --> |
319 | * <!-- end-user-doc --> |
320 | * @generated |
321 | */ |
322 | protected MarkerHelper markerHelper = new EditUIMarkerHelper(); |
323 | |
324 | /** |
325 | * This listens for when the outline becomes active |
326 | * <!-- begin-user-doc --> |
327 | * <!-- end-user-doc --> |
328 | * @generated |
329 | */ |
330 | protected IPartListener partListener = |
331 | new IPartListener() { |
332 | public void partActivated(IWorkbenchPart p) { |
333 | if (p instanceof ContentOutline) { |
334 | if (((ContentOutline)p).getCurrentPage() == contentOutlinePage) { |
335 | getActionBarContributor().setActiveEditor(pipesandfiltersEditor.this); |
336 | |
337 | setCurrentViewer(contentOutlineViewer); |
338 | } |
339 | } |
340 | else if (p instanceof PropertySheet) { |
341 | if (((PropertySheet)p).getCurrentPage() == propertySheetPage) { |
342 | getActionBarContributor().setActiveEditor(pipesandfiltersEditor.this); |
343 | handleActivate(); |
344 | } |
345 | } |
346 | else if (p == pipesandfiltersEditor.this) { |
347 | handleActivate(); |
348 | } |
349 | } |
350 | public void partBroughtToTop(IWorkbenchPart p) { |
351 | // Ignore. |
352 | } |
353 | public void partClosed(IWorkbenchPart p) { |
354 | // Ignore. |
355 | } |
356 | public void partDeactivated(IWorkbenchPart p) { |
357 | // Ignore. |
358 | } |
359 | public void partOpened(IWorkbenchPart p) { |
360 | // Ignore. |
361 | } |
362 | }; |
363 | |
364 | /** |
365 | * Resources that have been removed since last activation. |
366 | * <!-- begin-user-doc --> |
367 | * <!-- end-user-doc --> |
368 | * @generated |
369 | */ |
370 | protected Collection<Resource> removedResources = new ArrayList<Resource>(); |
371 | |
372 | /** |
373 | * Resources that have been changed since last activation. |
374 | * <!-- begin-user-doc --> |
375 | * <!-- end-user-doc --> |
376 | * @generated |
377 | */ |
378 | protected Collection<Resource> changedResources = new ArrayList<Resource>(); |
379 | |
380 | /** |
381 | * Resources that have been saved. |
382 | * <!-- begin-user-doc --> |
383 | * <!-- end-user-doc --> |
384 | * @generated |
385 | */ |
386 | protected Collection<Resource> savedResources = new ArrayList<Resource>(); |
387 | |
388 | /** |
389 | * Map to store the diagnostic associated with a resource. |
390 | * <!-- begin-user-doc --> |
391 | * <!-- end-user-doc --> |
392 | * @generated |
393 | */ |
394 | protected Map<Resource, Diagnostic> resourceToDiagnosticMap = new LinkedHashMap<Resource, Diagnostic>(); |
395 | |
396 | /** |
397 | * Controls whether the problem indication should be updated. |
398 | * <!-- begin-user-doc --> |
399 | * <!-- end-user-doc --> |
400 | * @generated |
401 | */ |
402 | protected boolean updateProblemIndication = true; |
403 | |
404 | /** |
405 | * Adapter used to update the problem indication when resources are demanded loaded. |
406 | * <!-- begin-user-doc --> |
407 | * <!-- end-user-doc --> |
408 | * @generated |
409 | */ |
410 | protected EContentAdapter problemIndicationAdapter = |
411 | new EContentAdapter() { |
412 | @Override |
413 | public void notifyChanged(Notification notification) { |
414 | if (notification.getNotifier() instanceof Resource) { |
415 | switch (notification.getFeatureID(Resource.class)) { |
416 | case Resource.RESOURCE__IS_LOADED: |
417 | case Resource.RESOURCE__ERRORS: |
418 | case Resource.RESOURCE__WARNINGS: { |
419 | Resource resource = (Resource)notification.getNotifier(); |
420 | Diagnostic diagnostic = analyzeResourceProblems(resource, null); |
421 | if (diagnostic.getSeverity() != Diagnostic.OK) { |
422 | resourceToDiagnosticMap.put(resource, diagnostic); |
423 | } |
424 | else { |
425 | resourceToDiagnosticMap.remove(resource); |
426 | } |
427 | |
428 | if (updateProblemIndication) { |
429 | getSite().getShell().getDisplay().asyncExec |
430 | (new Runnable() { |
431 | public void run() { |
432 | updateProblemIndication(); |
433 | } |
434 | }); |
435 | } |
436 | break; |
437 | } |
438 | } |
439 | } |
440 | else { |
441 | super.notifyChanged(notification); |
442 | } |
443 | } |
444 | |
445 | @Override |
446 | protected void setTarget(Resource target) { |
447 | basicSetTarget(target); |
448 | } |
449 | |
450 | @Override |
451 | protected void unsetTarget(Resource target) { |
452 | basicUnsetTarget(target); |
453 | } |
454 | }; |
455 | |
456 | /** |
457 | * This listens for workspace changes. |
458 | * <!-- begin-user-doc --> |
459 | * <!-- end-user-doc --> |
460 | * @generated |
461 | */ |
462 | protected IResourceChangeListener resourceChangeListener = |
463 | new IResourceChangeListener() { |
464 | public void resourceChanged(IResourceChangeEvent event) { |
465 | IResourceDelta delta = event.getDelta(); |
466 | try { |
467 | class ResourceDeltaVisitor implements IResourceDeltaVisitor { |
468 | protected ResourceSet resourceSet = editingDomain.getResourceSet(); |
469 | protected Collection<Resource> changedResources = new ArrayList<Resource>(); |
470 | protected Collection<Resource> removedResources = new ArrayList<Resource>(); |
471 | |
472 | public boolean visit(IResourceDelta delta) { |
473 | if (delta.getResource().getType() == IResource.FILE) { |
474 | if (delta.getKind() == IResourceDelta.REMOVED || |
475 | delta.getKind() == IResourceDelta.CHANGED && delta.getFlags() != IResourceDelta.MARKERS) { |
476 | Resource resource = resourceSet.getResource(URI.createURI(delta.getFullPath().toString()), false); |
477 | if (resource != null) { |
478 | if (delta.getKind() == IResourceDelta.REMOVED) { |
479 | removedResources.add(resource); |
480 | } |
481 | else if (!savedResources.remove(resource)) { |
482 | changedResources.add(resource); |
483 | } |
484 | } |
485 | } |
486 | } |
487 | |
488 | return true; |
489 | } |
490 | |
491 | public Collection<Resource> getChangedResources() { |
492 | return changedResources; |
493 | } |
494 | |
495 | public Collection<Resource> getRemovedResources() { |
496 | return removedResources; |
497 | } |
498 | } |
499 | |
500 | ResourceDeltaVisitor visitor = new ResourceDeltaVisitor(); |
501 | delta.accept(visitor); |
502 | |
503 | if (!visitor.getRemovedResources().isEmpty()) { |
504 | removedResources.addAll(visitor.getRemovedResources()); |
505 | if (!isDirty()) { |
506 | getSite().getShell().getDisplay().asyncExec |
507 | (new Runnable() { |
508 | public void run() { |
509 | getSite().getPage().closeEditor(pipesandfiltersEditor.this, false); |
510 | } |
511 | }); |
512 | } |
513 | } |
514 | |
515 | if (!visitor.getChangedResources().isEmpty()) { |
516 | changedResources.addAll(visitor.getChangedResources()); |
517 | if (getSite().getPage().getActiveEditor() == pipesandfiltersEditor.this) { |
518 | getSite().getShell().getDisplay().asyncExec |
519 | (new Runnable() { |
520 | public void run() { |
521 | handleActivate(); |
522 | } |
523 | }); |
524 | } |
525 | } |
526 | } |
527 | catch (CoreException exception) { |
528 | PipesandfiltersEditorPlugin.INSTANCE.log(exception); |
529 | } |
530 | } |
531 | }; |
532 | |
533 | /** |
534 | * Handles activation of the editor or it's associated views. |
535 | * <!-- begin-user-doc --> |
536 | * <!-- end-user-doc --> |
537 | * @generated |
538 | */ |
539 | protected void handleActivate() { |
540 | // Recompute the read only state. |
541 | // |
542 | if (editingDomain.getResourceToReadOnlyMap() != null) { |
543 | editingDomain.getResourceToReadOnlyMap().clear(); |
544 | |
545 | // Refresh any actions that may become enabled or disabled. |
546 | // |
547 | setSelection(getSelection()); |
548 | } |
549 | |
550 | if (!removedResources.isEmpty()) { |
551 | if (handleDirtyConflict()) { |
552 | getSite().getPage().closeEditor(pipesandfiltersEditor.this, false); |
553 | } |
554 | else { |
555 | removedResources.clear(); |
556 | changedResources.clear(); |
557 | savedResources.clear(); |
558 | } |
559 | } |
560 | else if (!changedResources.isEmpty()) { |
561 | changedResources.removeAll(savedResources); |
562 | handleChangedResources(); |
563 | changedResources.clear(); |
564 | savedResources.clear(); |
565 | } |
566 | } |
567 | |
568 | /** |
569 | * Handles what to do with changed resources on activation. |
570 | * <!-- begin-user-doc --> |
571 | * <!-- end-user-doc --> |
572 | * @generated |
573 | */ |
574 | protected void handleChangedResources() { |
575 | if (!changedResources.isEmpty() && (!isDirty() || handleDirtyConflict())) { |
576 | if (isDirty()) { |
577 | changedResources.addAll(editingDomain.getResourceSet().getResources()); |
578 | } |
579 | editingDomain.getCommandStack().flush(); |
580 | |
581 | updateProblemIndication = false; |
582 | for (Resource resource : changedResources) { |
583 | if (resource.isLoaded()) { |
584 | resource.unload(); |
585 | try { |
586 | resource.load(Collections.EMPTY_MAP); |
587 | } |
588 | catch (IOException exception) { |
589 | if (!resourceToDiagnosticMap.containsKey(resource)) { |
590 | resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); |
591 | } |
592 | } |
593 | } |
594 | } |
595 | |
596 | if (AdapterFactoryEditingDomain.isStale(editorSelection)) { |
597 | setSelection(StructuredSelection.EMPTY); |
598 | } |
599 | |
600 | updateProblemIndication = true; |
601 | updateProblemIndication(); |
602 | } |
603 | } |
604 | |
605 | /** |
606 | * Updates the problems indication with the information described in the specified diagnostic. |
607 | * <!-- begin-user-doc --> |
608 | * <!-- end-user-doc --> |
609 | * @generated |
610 | */ |
611 | protected void updateProblemIndication() { |
612 | if (updateProblemIndication) { |
613 | BasicDiagnostic diagnostic = |
614 | new BasicDiagnostic |
615 | (Diagnostic.OK, |
616 | "de.uka.ipd.sdq.pipesandfilters.editor", |
617 | 0, |
618 | null, |
619 | new Object [] { editingDomain.getResourceSet() }); |
620 | for (Diagnostic childDiagnostic : resourceToDiagnosticMap.values()) { |
621 | if (childDiagnostic.getSeverity() != Diagnostic.OK) { |
622 | diagnostic.add(childDiagnostic); |
623 | } |
624 | } |
625 | |
626 | int lastEditorPage = getPageCount() - 1; |
627 | if (lastEditorPage >= 0 && getEditor(lastEditorPage) instanceof ProblemEditorPart) { |
628 | ((ProblemEditorPart)getEditor(lastEditorPage)).setDiagnostic(diagnostic); |
629 | if (diagnostic.getSeverity() != Diagnostic.OK) { |
630 | setActivePage(lastEditorPage); |
631 | } |
632 | } |
633 | else if (diagnostic.getSeverity() != Diagnostic.OK) { |
634 | ProblemEditorPart problemEditorPart = new ProblemEditorPart(); |
635 | problemEditorPart.setDiagnostic(diagnostic); |
636 | problemEditorPart.setMarkerHelper(markerHelper); |
637 | try { |
638 | addPage(++lastEditorPage, problemEditorPart, getEditorInput()); |
639 | setPageText(lastEditorPage, problemEditorPart.getPartName()); |
640 | setActivePage(lastEditorPage); |
641 | showTabs(); |
642 | } |
643 | catch (PartInitException exception) { |
644 | PipesandfiltersEditorPlugin.INSTANCE.log(exception); |
645 | } |
646 | } |
647 | |
648 | if (markerHelper.hasMarkers(editingDomain.getResourceSet())) { |
649 | markerHelper.deleteMarkers(editingDomain.getResourceSet()); |
650 | if (diagnostic.getSeverity() != Diagnostic.OK) { |
651 | try { |
652 | markerHelper.createMarkers(diagnostic); |
653 | } |
654 | catch (CoreException exception) { |
655 | PipesandfiltersEditorPlugin.INSTANCE.log(exception); |
656 | } |
657 | } |
658 | } |
659 | } |
660 | } |
661 | |
662 | /** |
663 | * Shows a dialog that asks if conflicting changes should be discarded. |
664 | * <!-- begin-user-doc --> |
665 | * <!-- end-user-doc --> |
666 | * @generated |
667 | */ |
668 | protected boolean handleDirtyConflict() { |
669 | return |
670 | MessageDialog.openQuestion |
671 | (getSite().getShell(), |
672 | getString("_UI_FileConflict_label"), |
673 | getString("_WARN_FileConflict")); |
674 | } |
675 | |
676 | /** |
677 | * This creates a model editor. |
678 | * <!-- begin-user-doc --> |
679 | * <!-- end-user-doc --> |
680 | * @generated |
681 | */ |
682 | public pipesandfiltersEditor() { |
683 | super(); |
684 | initializeEditingDomain(); |
685 | } |
686 | |
687 | /** |
688 | * This sets up the editing domain for the model editor. |
689 | * <!-- begin-user-doc --> |
690 | * <!-- end-user-doc --> |
691 | * @generated |
692 | */ |
693 | protected void initializeEditingDomain() { |
694 | // Create an adapter factory that yields item providers. |
695 | // |
696 | adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE); |
697 | |
698 | adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory()); |
699 | adapterFactory.addAdapterFactory(new pipesandfiltersItemProviderAdapterFactory()); |
700 | adapterFactory.addAdapterFactory(new IdentifierItemProviderAdapterFactory()); |
701 | adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory()); |
702 | |
703 | // Create the command stack that will notify this editor as commands are executed. |
704 | // |
705 | BasicCommandStack commandStack = new BasicCommandStack(); |
706 | |
707 | // Add a listener to set the most recent command's affected objects to be the selection of the viewer with focus. |
708 | // |
709 | commandStack.addCommandStackListener |
710 | (new CommandStackListener() { |
711 | public void commandStackChanged(final EventObject event) { |
712 | getContainer().getDisplay().asyncExec |
713 | (new Runnable() { |
714 | public void run() { |
715 | firePropertyChange(IEditorPart.PROP_DIRTY); |
716 | |
717 | // Try to select the affected objects. |
718 | // |
719 | Command mostRecentCommand = ((CommandStack)event.getSource()).getMostRecentCommand(); |
720 | if (mostRecentCommand != null) { |
721 | setSelectionToViewer(mostRecentCommand.getAffectedObjects()); |
722 | } |
723 | if (propertySheetPage != null && !propertySheetPage.getControl().isDisposed()) { |
724 | propertySheetPage.refresh(); |
725 | } |
726 | } |
727 | }); |
728 | } |
729 | }); |
730 | |
731 | // Create the editing domain with a special command stack. |
732 | // |
733 | editingDomain = new AdapterFactoryEditingDomain(adapterFactory, commandStack, new HashMap<Resource, Boolean>()); |
734 | } |
735 | |
736 | /** |
737 | * This is here for the listener to be able to call it. |
738 | * <!-- begin-user-doc --> |
739 | * <!-- end-user-doc --> |
740 | * @generated |
741 | */ |
742 | @Override |
743 | protected void firePropertyChange(int action) { |
744 | super.firePropertyChange(action); |
745 | } |
746 | |
747 | /** |
748 | * This sets the selection into whichever viewer is active. |
749 | * <!-- begin-user-doc --> |
750 | * <!-- end-user-doc --> |
751 | * @generated |
752 | */ |
753 | public void setSelectionToViewer(Collection<?> collection) { |
754 | final Collection<?> theSelection = collection; |
755 | // Make sure it's okay. |
756 | // |
757 | if (theSelection != null && !theSelection.isEmpty()) { |
758 | // I don't know if this should be run this deferred |
759 | // because we might have to give the editor a chance to process the viewer update events |
760 | // and hence to update the views first. |
761 | // |
762 | // |
763 | Runnable runnable = |
764 | new Runnable() { |
765 | public void run() { |
766 | // Try to select the items in the current content viewer of the editor. |
767 | // |
768 | if (currentViewer != null) { |
769 | currentViewer.setSelection(new StructuredSelection(theSelection.toArray()), true); |
770 | } |
771 | } |
772 | }; |
773 | runnable.run(); |
774 | } |
775 | } |
776 | |
777 | /** |
778 | * This returns the editing domain as required by the {@link IEditingDomainProvider} interface. |
779 | * This is important for implementing the static methods of {@link AdapterFactoryEditingDomain} |
780 | * and for supporting {@link org.eclipse.emf.edit.ui.action.CommandAction}. |
781 | * <!-- begin-user-doc --> |
782 | * <!-- end-user-doc --> |
783 | * @generated |
784 | */ |
785 | public EditingDomain getEditingDomain() { |
786 | return editingDomain; |
787 | } |
788 | |
789 | /** |
790 | * <!-- begin-user-doc --> |
791 | * <!-- end-user-doc --> |
792 | * @generated |
793 | */ |
794 | public class ReverseAdapterFactoryContentProvider extends AdapterFactoryContentProvider { |
795 | /** |
796 | * <!-- begin-user-doc --> |
797 | * <!-- end-user-doc --> |
798 | * @generated |
799 | */ |
800 | public ReverseAdapterFactoryContentProvider(AdapterFactory adapterFactory) { |
801 | super(adapterFactory); |
802 | } |
803 | |
804 | /** |
805 | * <!-- begin-user-doc --> |
806 | * <!-- end-user-doc --> |
807 | * @generated |
808 | */ |
809 | @Override |
810 | public Object [] getElements(Object object) { |
811 | Object parent = super.getParent(object); |
812 | return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray(); |
813 | } |
814 | |
815 | /** |
816 | * <!-- begin-user-doc --> |
817 | * <!-- end-user-doc --> |
818 | * @generated |
819 | */ |
820 | @Override |
821 | public Object [] getChildren(Object object) { |
822 | Object parent = super.getParent(object); |
823 | return (parent == null ? Collections.EMPTY_SET : Collections.singleton(parent)).toArray(); |
824 | } |
825 | |
826 | /** |
827 | * <!-- begin-user-doc --> |
828 | * <!-- end-user-doc --> |
829 | * @generated |
830 | */ |
831 | @Override |
832 | public boolean hasChildren(Object object) { |
833 | Object parent = super.getParent(object); |
834 | return parent != null; |
835 | } |
836 | |
837 | /** |
838 | * <!-- begin-user-doc --> |
839 | * <!-- end-user-doc --> |
840 | * @generated |
841 | */ |
842 | @Override |
843 | public Object getParent(Object object) { |
844 | return null; |
845 | } |
846 | } |
847 | |
848 | /** |
849 | * <!-- begin-user-doc --> |
850 | * <!-- end-user-doc --> |
851 | * @generated |
852 | */ |
853 | public void setCurrentViewerPane(ViewerPane viewerPane) { |
854 | if (currentViewerPane != viewerPane) { |
855 | if (currentViewerPane != null) { |
856 | currentViewerPane.showFocus(false); |
857 | } |
858 | currentViewerPane = viewerPane; |
859 | } |
860 | setCurrentViewer(currentViewerPane.getViewer()); |
861 | } |
862 | |
863 | /** |
864 | * This makes sure that one content viewer, either for the current page or the outline view, if it has focus, |
865 | * is the current one. |
866 | * <!-- begin-user-doc --> |
867 | * <!-- end-user-doc --> |
868 | * @generated |
869 | */ |
870 | public void setCurrentViewer(Viewer viewer) { |
871 | // If it is changing... |
872 | // |
873 | if (currentViewer != viewer) { |
874 | if (selectionChangedListener == null) { |
875 | // Create the listener on demand. |
876 | // |
877 | selectionChangedListener = |
878 | new ISelectionChangedListener() { |
879 | // This just notifies those things that are affected by the section. |
880 | // |
881 | public void selectionChanged(SelectionChangedEvent selectionChangedEvent) { |
882 | setSelection(selectionChangedEvent.getSelection()); |
883 | } |
884 | }; |
885 | } |
886 | |
887 | // Stop listening to the old one. |
888 | // |
889 | if (currentViewer != null) { |
890 | currentViewer.removeSelectionChangedListener(selectionChangedListener); |
891 | } |
892 | |
893 | // Start listening to the new one. |
894 | // |
895 | if (viewer != null) { |
896 | viewer.addSelectionChangedListener(selectionChangedListener); |
897 | } |
898 | |
899 | // Remember it. |
900 | // |
901 | currentViewer = viewer; |
902 | |
903 | // Set the editors selection based on the current viewer's selection. |
904 | // |
905 | setSelection(currentViewer == null ? StructuredSelection.EMPTY : currentViewer.getSelection()); |
906 | } |
907 | } |
908 | |
909 | /** |
910 | * This returns the viewer as required by the {@link IViewerProvider} interface. |
911 | * <!-- begin-user-doc --> |
912 | * <!-- end-user-doc --> |
913 | * @generated |
914 | */ |
915 | public Viewer getViewer() { |
916 | return currentViewer; |
917 | } |
918 | |
919 | /** |
920 | * This creates a context menu for the viewer and adds a listener as well registering the menu for extension. |
921 | * <!-- begin-user-doc --> |
922 | * <!-- end-user-doc --> |
923 | * @generated |
924 | */ |
925 | protected void createContextMenuFor(StructuredViewer viewer) { |
926 | MenuManager contextMenu = new MenuManager("#PopUp"); |
927 | contextMenu.add(new Separator("additions")); |
928 | contextMenu.setRemoveAllWhenShown(true); |
929 | contextMenu.addMenuListener(this); |
930 | Menu menu= contextMenu.createContextMenu(viewer.getControl()); |
931 | viewer.getControl().setMenu(menu); |
932 | getSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer)); |
933 | |
934 | int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK; |
935 | Transfer[] transfers = new Transfer[] { LocalTransfer.getInstance() }; |
936 | viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer)); |
937 | viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer)); |
938 | } |
939 | |
940 | /** |
941 | * This is the method called to load a resource into the editing domain's resource set based on the editor's input. |
942 | * <!-- begin-user-doc --> |
943 | * <!-- end-user-doc --> |
944 | * @generated |
945 | */ |
946 | public void createModel() { |
947 | URI resourceURI = EditUIUtil.getURI(getEditorInput()); |
948 | Exception exception = null; |
949 | Resource resource = null; |
950 | try { |
951 | // Load the resource through the editing domain. |
952 | // |
953 | resource = editingDomain.getResourceSet().getResource(resourceURI, true); |
954 | } |
955 | catch (Exception e) { |
956 | exception = e; |
957 | resource = editingDomain.getResourceSet().getResource(resourceURI, false); |
958 | } |
959 | |
960 | Diagnostic diagnostic = analyzeResourceProblems(resource, exception); |
961 | if (diagnostic.getSeverity() != Diagnostic.OK) { |
962 | resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); |
963 | } |
964 | editingDomain.getResourceSet().eAdapters().add(problemIndicationAdapter); |
965 | } |
966 | |
967 | /** |
968 | * Returns a diagnostic describing the errors and warnings listed in the resource |
969 | * and the specified exception (if any). |
970 | * <!-- begin-user-doc --> |
971 | * <!-- end-user-doc --> |
972 | * @generated |
973 | */ |
974 | public Diagnostic analyzeResourceProblems(Resource resource, Exception exception) { |
975 | if (!resource.getErrors().isEmpty() || !resource.getWarnings().isEmpty()) { |
976 | BasicDiagnostic basicDiagnostic = |
977 | new BasicDiagnostic |
978 | (Diagnostic.ERROR, |
979 | "de.uka.ipd.sdq.pipesandfilters.editor", |
980 | 0, |
981 | getString("_UI_CreateModelError_message", resource.getURI()), |
982 | new Object [] { exception == null ? (Object)resource : exception }); |
983 | basicDiagnostic.merge(EcoreUtil.computeDiagnostic(resource, true)); |
984 | return basicDiagnostic; |
985 | } |
986 | else if (exception != null) { |
987 | return |
988 | new BasicDiagnostic |
989 | (Diagnostic.ERROR, |
990 | "de.uka.ipd.sdq.pipesandfilters.editor", |
991 | 0, |
992 | getString("_UI_CreateModelError_message", resource.getURI()), |
993 | new Object[] { exception }); |
994 | } |
995 | else { |
996 | return Diagnostic.OK_INSTANCE; |
997 | } |
998 | } |
999 | |
1000 | /** |
1001 | * This is the method used by the framework to install your own controls. |
1002 | * <!-- begin-user-doc --> |
1003 | * <!-- end-user-doc --> |
1004 | * @generated |
1005 | */ |
1006 | @Override |
1007 | public void createPages() { |
1008 | // Creates the model from the editor input |
1009 | // |
1010 | createModel(); |
1011 | |
1012 | // Only creates the other pages if there is something that can be edited |
1013 | // |
1014 | if (!getEditingDomain().getResourceSet().getResources().isEmpty()) { |
1015 | // Create a page for the selection tree view. |
1016 | // |
1017 | { |
1018 | ViewerPane viewerPane = |
1019 | new ViewerPane(getSite().getPage(), pipesandfiltersEditor.this) { |
1020 | @Override |
1021 | public Viewer createViewer(Composite composite) { |
1022 | Tree tree = new Tree(composite, SWT.MULTI); |
1023 | TreeViewer newTreeViewer = new TreeViewer(tree); |
1024 | return newTreeViewer; |
1025 | } |
1026 | @Override |
1027 | public void requestActivation() { |
1028 | super.requestActivation(); |
1029 | setCurrentViewerPane(this); |
1030 | } |
1031 | }; |
1032 | viewerPane.createControl(getContainer()); |
1033 | |
1034 | selectionViewer = (TreeViewer)viewerPane.getViewer(); |
1035 | selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); |
1036 | |
1037 | selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); |
1038 | selectionViewer.setInput(editingDomain.getResourceSet()); |
1039 | selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true); |
1040 | viewerPane.setTitle(editingDomain.getResourceSet()); |
1041 | |
1042 | new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory); |
1043 | |
1044 | createContextMenuFor(selectionViewer); |
1045 | int pageIndex = addPage(viewerPane.getControl()); |
1046 | setPageText(pageIndex, getString("_UI_SelectionPage_label")); |
1047 | } |
1048 | |
1049 | // Create a page for the parent tree view. |
1050 | // |
1051 | { |
1052 | ViewerPane viewerPane = |
1053 | new ViewerPane(getSite().getPage(), pipesandfiltersEditor.this) { |
1054 | @Override |
1055 | public Viewer createViewer(Composite composite) { |
1056 | Tree tree = new Tree(composite, SWT.MULTI); |
1057 | TreeViewer newTreeViewer = new TreeViewer(tree); |
1058 | return newTreeViewer; |
1059 | } |
1060 | @Override |
1061 | public void requestActivation() { |
1062 | super.requestActivation(); |
1063 | setCurrentViewerPane(this); |
1064 | } |
1065 | }; |
1066 | viewerPane.createControl(getContainer()); |
1067 | |
1068 | parentViewer = (TreeViewer)viewerPane.getViewer(); |
1069 | parentViewer.setAutoExpandLevel(30); |
1070 | parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory)); |
1071 | parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); |
1072 | |
1073 | createContextMenuFor(parentViewer); |
1074 | int pageIndex = addPage(viewerPane.getControl()); |
1075 | setPageText(pageIndex, getString("_UI_ParentPage_label")); |
1076 | } |
1077 | |
1078 | // This is the page for the list viewer |
1079 | // |
1080 | { |
1081 | ViewerPane viewerPane = |
1082 | new ViewerPane(getSite().getPage(), pipesandfiltersEditor.this) { |
1083 | @Override |
1084 | public Viewer createViewer(Composite composite) { |
1085 | return new ListViewer(composite); |
1086 | } |
1087 | @Override |
1088 | public void requestActivation() { |
1089 | super.requestActivation(); |
1090 | setCurrentViewerPane(this); |
1091 | } |
1092 | }; |
1093 | viewerPane.createControl(getContainer()); |
1094 | listViewer = (ListViewer)viewerPane.getViewer(); |
1095 | listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); |
1096 | listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); |
1097 | |
1098 | createContextMenuFor(listViewer); |
1099 | int pageIndex = addPage(viewerPane.getControl()); |
1100 | setPageText(pageIndex, getString("_UI_ListPage_label")); |
1101 | } |
1102 | |
1103 | // This is the page for the tree viewer |
1104 | // |
1105 | { |
1106 | ViewerPane viewerPane = |
1107 | new ViewerPane(getSite().getPage(), pipesandfiltersEditor.this) { |
1108 | @Override |
1109 | public Viewer createViewer(Composite composite) { |
1110 | return new TreeViewer(composite); |
1111 | } |
1112 | @Override |
1113 | public void requestActivation() { |
1114 | super.requestActivation(); |
1115 | setCurrentViewerPane(this); |
1116 | } |
1117 | }; |
1118 | viewerPane.createControl(getContainer()); |
1119 | treeViewer = (TreeViewer)viewerPane.getViewer(); |
1120 | treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); |
1121 | treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); |
1122 | |
1123 | new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory); |
1124 | |
1125 | createContextMenuFor(treeViewer); |
1126 | int pageIndex = addPage(viewerPane.getControl()); |
1127 | setPageText(pageIndex, getString("_UI_TreePage_label")); |
1128 | } |
1129 | |
1130 | // This is the page for the table viewer. |
1131 | // |
1132 | { |
1133 | ViewerPane viewerPane = |
1134 | new ViewerPane(getSite().getPage(), pipesandfiltersEditor.this) { |
1135 | @Override |
1136 | public Viewer createViewer(Composite composite) { |
1137 | return new TableViewer(composite); |
1138 | } |
1139 | @Override |
1140 | public void requestActivation() { |
1141 | super.requestActivation(); |
1142 | setCurrentViewerPane(this); |
1143 | } |
1144 | }; |
1145 | viewerPane.createControl(getContainer()); |
1146 | tableViewer = (TableViewer)viewerPane.getViewer(); |
1147 | |
1148 | Table table = tableViewer.getTable(); |
1149 | TableLayout layout = new TableLayout(); |
1150 | table.setLayout(layout); |
1151 | table.setHeaderVisible(true); |
1152 | table.setLinesVisible(true); |
1153 | |
1154 | TableColumn objectColumn = new TableColumn(table, SWT.NONE); |
1155 | layout.addColumnData(new ColumnWeightData(3, 100, true)); |
1156 | objectColumn.setText(getString("_UI_ObjectColumn_label")); |
1157 | objectColumn.setResizable(true); |
1158 | |
1159 | TableColumn selfColumn = new TableColumn(table, SWT.NONE); |
1160 | layout.addColumnData(new ColumnWeightData(2, 100, true)); |
1161 | selfColumn.setText(getString("_UI_SelfColumn_label")); |
1162 | selfColumn.setResizable(true); |
1163 | |
1164 | tableViewer.setColumnProperties(new String [] {"a", "b"}); |
1165 | tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); |
1166 | tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); |
1167 | |
1168 | createContextMenuFor(tableViewer); |
1169 | int pageIndex = addPage(viewerPane.getControl()); |
1170 | setPageText(pageIndex, getString("_UI_TablePage_label")); |
1171 | } |
1172 | |
1173 | // This is the page for the table tree viewer. |
1174 | // |
1175 | { |
1176 | ViewerPane viewerPane = |
1177 | new ViewerPane(getSite().getPage(), pipesandfiltersEditor.this) { |
1178 | @Override |
1179 | public Viewer createViewer(Composite composite) { |
1180 | return new TreeViewer(composite); |
1181 | } |
1182 | @Override |
1183 | public void requestActivation() { |
1184 | super.requestActivation(); |
1185 | setCurrentViewerPane(this); |
1186 | } |
1187 | }; |
1188 | viewerPane.createControl(getContainer()); |
1189 | |
1190 | treeViewerWithColumns = (TreeViewer)viewerPane.getViewer(); |
1191 | |
1192 | Tree tree = treeViewerWithColumns.getTree(); |
1193 | tree.setLayoutData(new FillLayout()); |
1194 | tree.setHeaderVisible(true); |
1195 | tree.setLinesVisible(true); |
1196 | |
1197 | TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE); |
1198 | objectColumn.setText(getString("_UI_ObjectColumn_label")); |
1199 | objectColumn.setResizable(true); |
1200 | objectColumn.setWidth(250); |
1201 | |
1202 | TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE); |
1203 | selfColumn.setText(getString("_UI_SelfColumn_label")); |
1204 | selfColumn.setResizable(true); |
1205 | selfColumn.setWidth(200); |
1206 | |
1207 | treeViewerWithColumns.setColumnProperties(new String [] {"a", "b"}); |
1208 | treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); |
1209 | treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); |
1210 | |
1211 | createContextMenuFor(treeViewerWithColumns); |
1212 | int pageIndex = addPage(viewerPane.getControl()); |
1213 | setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label")); |
1214 | } |
1215 | |
1216 | getSite().getShell().getDisplay().asyncExec |
1217 | (new Runnable() { |
1218 | public void run() { |
1219 | setActivePage(0); |
1220 | } |
1221 | }); |
1222 | } |
1223 | |
1224 | // Ensures that this editor will only display the page's tab |
1225 | // area if there are more than one page |
1226 | // |
1227 | getContainer().addControlListener |
1228 | (new ControlAdapter() { |
1229 | boolean guard = false; |
1230 | @Override |
1231 | public void controlResized(ControlEvent event) { |
1232 | if (!guard) { |
1233 | guard = true; |
1234 | hideTabs(); |
1235 | guard = false; |
1236 | } |
1237 | } |
1238 | }); |
1239 | |
1240 | getSite().getShell().getDisplay().asyncExec |
1241 | (new Runnable() { |
1242 | public void run() { |
1243 | updateProblemIndication(); |
1244 | } |
1245 | }); |
1246 | } |
1247 | |
1248 | /** |
1249 | * If there is just one page in the multi-page editor part, |
1250 | * this hides the single tab at the bottom. |
1251 | * <!-- begin-user-doc --> |
1252 | * <!-- end-user-doc --> |
1253 | * @generated |
1254 | */ |
1255 | protected void hideTabs() { |
1256 | if (getPageCount() <= 1) { |
1257 | setPageText(0, ""); |
1258 | if (getContainer() instanceof CTabFolder) { |
1259 | ((CTabFolder)getContainer()).setTabHeight(1); |
1260 | Point point = getContainer().getSize(); |
1261 | getContainer().setSize(point.x, point.y + 6); |
1262 | } |
1263 | } |
1264 | } |
1265 | |
1266 | /** |
1267 | * If there is more than one page in the multi-page editor part, |
1268 | * this shows the tabs at the bottom. |
1269 | * <!-- begin-user-doc --> |
1270 | * <!-- end-user-doc --> |
1271 | * @generated |
1272 | */ |
1273 | protected void showTabs() { |
1274 | if (getPageCount() > 1) { |
1275 | setPageText(0, getString("_UI_SelectionPage_label")); |
1276 | if (getContainer() instanceof CTabFolder) { |
1277 | ((CTabFolder)getContainer()).setTabHeight(SWT.DEFAULT); |
1278 | Point point = getContainer().getSize(); |
1279 | getContainer().setSize(point.x, point.y - 6); |
1280 | } |
1281 | } |
1282 | } |
1283 | |
1284 | /** |
1285 | * This is used to track the active viewer. |
1286 | * <!-- begin-user-doc --> |
1287 | * <!-- end-user-doc --> |
1288 | * @generated |
1289 | */ |
1290 | @Override |
1291 | protected void pageChange(int pageIndex) { |
1292 | super.pageChange(pageIndex); |
1293 | |
1294 | if (contentOutlinePage != null) { |
1295 | handleContentOutlineSelection(contentOutlinePage.getSelection()); |
1296 | } |
1297 | } |
1298 | |
1299 | /** |
1300 | * This is how the framework determines which interfaces we implement. |
1301 | * <!-- begin-user-doc --> |
1302 | * <!-- end-user-doc --> |
1303 | * @generated |
1304 | */ |
1305 | @SuppressWarnings("unchecked") |
1306 | @Override |
1307 | public Object getAdapter(Class key) { |
1308 | if (key.equals(IContentOutlinePage.class)) { |
1309 | return showOutlineView() ? getContentOutlinePage() : null; |
1310 | } |
1311 | else if (key.equals(IPropertySheetPage.class)) { |
1312 | return getPropertySheetPage(); |
1313 | } |
1314 | else if (key.equals(IGotoMarker.class)) { |
1315 | return this; |
1316 | } |
1317 | else { |
1318 | return super.getAdapter(key); |
1319 | } |
1320 | } |
1321 | |
1322 | /** |
1323 | * This accesses a cached version of the content outliner. |
1324 | * <!-- begin-user-doc --> |
1325 | * <!-- end-user-doc --> |
1326 | * @generated |
1327 | */ |
1328 | public IContentOutlinePage getContentOutlinePage() { |
1329 | if (contentOutlinePage == null) { |
1330 | // The content outline is just a tree. |
1331 | // |
1332 | class MyContentOutlinePage extends ContentOutlinePage { |
1333 | @Override |
1334 | public void createControl(Composite parent) { |
1335 | super.createControl(parent); |
1336 | contentOutlineViewer = getTreeViewer(); |
1337 | contentOutlineViewer.addSelectionChangedListener(this); |
1338 | |
1339 | // Set up the tree viewer. |
1340 | // |
1341 | contentOutlineViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory)); |
1342 | contentOutlineViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); |
1343 | contentOutlineViewer.setInput(editingDomain.getResourceSet()); |
1344 | |
1345 | // Make sure our popups work. |
1346 | // |
1347 | createContextMenuFor(contentOutlineViewer); |
1348 | |
1349 | if (!editingDomain.getResourceSet().getResources().isEmpty()) { |
1350 | // Select the root object in the view. |
1351 | // |
1352 | contentOutlineViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true); |
1353 | } |
1354 | } |
1355 | |
1356 | @Override |
1357 | public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager) { |
1358 | super.makeContributions(menuManager, toolBarManager, statusLineManager); |
1359 | contentOutlineStatusLineManager = statusLineManager; |
1360 | } |
1361 | |
1362 | @Override |
1363 | public void setActionBars(IActionBars actionBars) { |
1364 | super.setActionBars(actionBars); |
1365 | getActionBarContributor().shareGlobalActions(this, actionBars); |
1366 | } |
1367 | } |
1368 | |
1369 | contentOutlinePage = new MyContentOutlinePage(); |
1370 | |
1371 | // Listen to selection so that we can handle it is a special way. |
1372 | // |
1373 | contentOutlinePage.addSelectionChangedListener |
1374 | (new ISelectionChangedListener() { |
1375 | // This ensures that we handle selections correctly. |
1376 | // |
1377 | public void selectionChanged(SelectionChangedEvent event) { |
1378 | handleContentOutlineSelection(event.getSelection()); |
1379 | } |
1380 | }); |
1381 | } |
1382 | |
1383 | return contentOutlinePage; |
1384 | } |
1385 | |
1386 | /** |
1387 | * This accesses a cached version of the property sheet. |
1388 | * <!-- begin-user-doc --> |
1389 | * <!-- end-user-doc --> |
1390 | * @generated |
1391 | */ |
1392 | public IPropertySheetPage getPropertySheetPage() { |
1393 | if (propertySheetPage == null) { |
1394 | propertySheetPage = |
1395 | new ExtendedPropertySheetPage(editingDomain) { |
1396 | @Override |
1397 | public void setSelectionToViewer(List<?> selection) { |
1398 | pipesandfiltersEditor.this.setSelectionToViewer(selection); |
1399 | pipesandfiltersEditor.this.setFocus(); |
1400 | } |
1401 | |
1402 | @Override |
1403 | public void setActionBars(IActionBars actionBars) { |
1404 | super.setActionBars(actionBars); |
1405 | getActionBarContributor().shareGlobalActions(this, actionBars); |
1406 | } |
1407 | }; |
1408 | propertySheetPage.setPropertySourceProvider(new AdapterFactoryContentProvider(adapterFactory)); |
1409 | } |
1410 | |
1411 | return propertySheetPage; |
1412 | } |
1413 | |
1414 | /** |
1415 | * This deals with how we want selection in the outliner to affect the other views. |
1416 | * <!-- begin-user-doc --> |
1417 | * <!-- end-user-doc --> |
1418 | * @generated |
1419 | */ |
1420 | public void handleContentOutlineSelection(ISelection selection) { |
1421 | if (currentViewerPane != null && !selection.isEmpty() && selection instanceof IStructuredSelection) { |
1422 | Iterator<?> selectedElements = ((IStructuredSelection)selection).iterator(); |
1423 | if (selectedElements.hasNext()) { |
1424 | // Get the first selected element. |
1425 | // |
1426 | Object selectedElement = selectedElements.next(); |
1427 | |
1428 | // If it's the selection viewer, then we want it to select the same selection as this selection. |
1429 | // |
1430 | if (currentViewerPane.getViewer() == selectionViewer) { |
1431 | ArrayList<Object> selectionList = new ArrayList<Object>(); |
1432 | selectionList.add(selectedElement); |
1433 | while (selectedElements.hasNext()) { |
1434 | selectionList.add(selectedElements.next()); |
1435 | } |
1436 | |
1437 | // Set the selection to the widget. |
1438 | // |
1439 | selectionViewer.setSelection(new StructuredSelection(selectionList)); |
1440 | } |
1441 | else { |
1442 | // Set the input to the widget. |
1443 | // |
1444 | if (currentViewerPane.getViewer().getInput() != selectedElement) { |
1445 | currentViewerPane.getViewer().setInput(selectedElement); |
1446 | currentViewerPane.setTitle(selectedElement); |
1447 | } |
1448 | } |
1449 | } |
1450 | } |
1451 | } |
1452 | |
1453 | /** |
1454 | * This is for implementing {@link IEditorPart} and simply tests the command stack. |
1455 | * <!-- begin-user-doc --> |
1456 | * <!-- end-user-doc --> |
1457 | * @generated |
1458 | */ |
1459 | @Override |
1460 | public boolean isDirty() { |
1461 | return ((BasicCommandStack)editingDomain.getCommandStack()).isSaveNeeded(); |
1462 | } |
1463 | |
1464 | /** |
1465 | * This is for implementing {@link IEditorPart} and simply saves the model file. |
1466 | * <!-- begin-user-doc --> |
1467 | * <!-- end-user-doc --> |
1468 | * @generated |
1469 | */ |
1470 | @Override |
1471 | public void doSave(IProgressMonitor progressMonitor) { |
1472 | // Save only resources that have actually changed. |
1473 | // |
1474 | final Map<Object, Object> saveOptions = new HashMap<Object, Object>(); |
1475 | saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER); |
1476 | |
1477 | // Do the work within an operation because this is a long running activity that modifies the workbench. |
1478 | // |
1479 | WorkspaceModifyOperation operation = |
1480 | new WorkspaceModifyOperation() { |
1481 | // This is the method that gets invoked when the operation runs. |
1482 | // |
1483 | @Override |
1484 | public void execute(IProgressMonitor monitor) { |
1485 | // Save the resources to the file system. |
1486 | // |
1487 | boolean first = true; |
1488 | for (Resource resource : editingDomain.getResourceSet().getResources()) { |
1489 | if ((first || !resource.getContents().isEmpty() || isPersisted(resource)) && !editingDomain.isReadOnly(resource)) { |
1490 | try { |
1491 | long timeStamp = resource.getTimeStamp(); |
1492 | resource.save(saveOptions); |
1493 | if (resource.getTimeStamp() != timeStamp) { |
1494 | savedResources.add(resource); |
1495 | } |
1496 | } |
1497 | catch (Exception exception) { |
1498 | resourceToDiagnosticMap.put(resource, analyzeResourceProblems(resource, exception)); |
1499 | } |
1500 | first = false; |
1501 | } |
1502 | } |
1503 | } |
1504 | }; |
1505 | |
1506 | updateProblemIndication = false; |
1507 | try { |
1508 | // This runs the options, and shows progress. |
1509 | // |
1510 | new ProgressMonitorDialog(getSite().getShell()).run(true, false, operation); |
1511 | |
1512 | // Refresh the necessary state. |
1513 | // |
1514 | ((BasicCommandStack)editingDomain.getCommandStack()).saveIsDone(); |
1515 | firePropertyChange(IEditorPart.PROP_DIRTY); |
1516 | } |
1517 | catch (Exception exception) { |
1518 | // Something went wrong that shouldn't. |
1519 | // |
1520 | PipesandfiltersEditorPlugin.INSTANCE.log(exception); |
1521 | } |
1522 | updateProblemIndication = true; |
1523 | updateProblemIndication(); |
1524 | } |
1525 | |
1526 | /** |
1527 | * This returns whether something has been persisted to the URI of the specified resource. |
1528 | * The implementation uses the URI converter from the editor's resource set to try to open an input stream. |
1529 | * <!-- begin-user-doc --> |
1530 | * <!-- end-user-doc --> |
1531 | * @generated |
1532 | */ |
1533 | protected boolean isPersisted(Resource resource) { |
1534 | boolean result = false; |
1535 | try { |
1536 | InputStream stream = editingDomain.getResourceSet().getURIConverter().createInputStream(resource.getURI()); |
1537 | if (stream != null) { |
1538 | result = true; |
1539 | stream.close(); |
1540 | } |
1541 | } |
1542 | catch (IOException e) { |
1543 | // Ignore |
1544 | } |
1545 | return result; |
1546 | } |
1547 | |
1548 | /** |
1549 | * This always returns true because it is not currently supported. |
1550 | * <!-- begin-user-doc --> |
1551 | * <!-- end-user-doc --> |
1552 | * @generated |
1553 | */ |
1554 | @Override |
1555 | public boolean isSaveAsAllowed() { |
1556 | return true; |
1557 | } |
1558 | |
1559 | /** |
1560 | * This also changes the editor's input. |
1561 | * <!-- begin-user-doc --> |
1562 | * <!-- end-user-doc --> |
1563 | * @generated |
1564 | */ |
1565 | @Override |
1566 | public void doSaveAs() { |
1567 | SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell()); |
1568 | saveAsDialog.open(); |
1569 | IPath path = saveAsDialog.getResult(); |
1570 | if (path != null) { |
1571 | IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); |
1572 | if (file != null) { |
1573 | doSaveAs(URI.createPlatformResourceURI(file.getFullPath().toString(), true), new FileEditorInput(file)); |
1574 | } |
1575 | } |
1576 | } |
1577 | |
1578 | /** |
1579 | * <!-- begin-user-doc --> |
1580 | * <!-- end-user-doc --> |
1581 | * @generated |
1582 | */ |
1583 | protected void doSaveAs(URI uri, IEditorInput editorInput) { |
1584 | (editingDomain.getResourceSet().getResources().get(0)).setURI(uri); |
1585 | setInputWithNotify(editorInput); |
1586 | setPartName(editorInput.getName()); |
1587 | IProgressMonitor progressMonitor = |
1588 | getActionBars().getStatusLineManager() != null ? |
1589 | getActionBars().getStatusLineManager().getProgressMonitor() : |
1590 | new NullProgressMonitor(); |
1591 | doSave(progressMonitor); |
1592 | } |
1593 | |
1594 | /** |
1595 | * <!-- begin-user-doc --> |
1596 | * <!-- end-user-doc --> |
1597 | * @generated |
1598 | */ |
1599 | public void gotoMarker(IMarker marker) { |
1600 | try { |
1601 | if (marker.getType().equals(EValidator.MARKER)) { |
1602 | String uriAttribute = marker.getAttribute(EValidator.URI_ATTRIBUTE, null); |
1603 | if (uriAttribute != null) { |
1604 | URI uri = URI.createURI(uriAttribute); |
1605 | EObject eObject = editingDomain.getResourceSet().getEObject(uri, true); |
1606 | if (eObject != null) { |
1607 | setSelectionToViewer(Collections.singleton(editingDomain.getWrapper(eObject))); |
1608 | } |
1609 | } |
1610 | } |
1611 | } |
1612 | catch (CoreException exception) { |
1613 | PipesandfiltersEditorPlugin.INSTANCE.log(exception); |
1614 | } |
1615 | } |
1616 | |
1617 | /** |
1618 | * This is called during startup. |
1619 | * <!-- begin-user-doc --> |
1620 | * <!-- end-user-doc --> |
1621 | * @generated |
1622 | */ |
1623 | @Override |
1624 | public void init(IEditorSite site, IEditorInput editorInput) { |
1625 | setSite(site); |
1626 | setInputWithNotify(editorInput); |
1627 | setPartName(editorInput.getName()); |
1628 | site.setSelectionProvider(this); |
1629 | site.getPage().addPartListener(partListener); |
1630 | ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE); |
1631 | } |
1632 | |
1633 | /** |
1634 | * <!-- begin-user-doc --> |
1635 | * <!-- end-user-doc --> |
1636 | * @generated |
1637 | */ |
1638 | @Override |
1639 | public void setFocus() { |
1640 | if (currentViewerPane != null) { |
1641 | currentViewerPane.setFocus(); |
1642 | } |
1643 | else { |
1644 | getControl(getActivePage()).setFocus(); |
1645 | } |
1646 | } |
1647 | |
1648 | /** |
1649 | * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}. |
1650 | * <!-- begin-user-doc --> |
1651 | * <!-- end-user-doc --> |
1652 | * @generated |
1653 | */ |
1654 | public void addSelectionChangedListener(ISelectionChangedListener listener) { |
1655 | selectionChangedListeners.add(listener); |
1656 | } |
1657 | |
1658 | /** |
1659 | * This implements {@link org.eclipse.jface.viewers.ISelectionProvider}. |
1660 | * <!-- begin-user-doc --> |
1661 | * <!-- end-user-doc --> |
1662 | * @generated |
1663 | */ |
1664 | public void removeSelectionChangedListener(ISelectionChangedListener listener) { |
1665 | selectionChangedListeners.remove(listener); |
1666 | } |
1667 | |
1668 | /** |
1669 | * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to return this editor's overall selection. |
1670 | * <!-- begin-user-doc --> |
1671 | * <!-- end-user-doc --> |
1672 | * @generated |
1673 | */ |
1674 | public ISelection getSelection() { |
1675 | return editorSelection; |
1676 | } |
1677 | |
1678 | /** |
1679 | * This implements {@link org.eclipse.jface.viewers.ISelectionProvider} to set this editor's overall selection. |
1680 | * Calling this result will notify the listeners. |
1681 | * <!-- begin-user-doc --> |
1682 | * <!-- end-user-doc --> |
1683 | * @generated |
1684 | */ |
1685 | public void setSelection(ISelection selection) { |
1686 | editorSelection = selection; |
1687 | |
1688 | for (ISelectionChangedListener listener : selectionChangedListeners) { |
1689 | listener.selectionChanged(new SelectionChangedEvent(this, selection)); |
1690 | } |
1691 | setStatusLineManager(selection); |
1692 | } |
1693 | |
1694 | /** |
1695 | * <!-- begin-user-doc --> |
1696 | * <!-- end-user-doc --> |
1697 | * @generated |
1698 | */ |
1699 | public void setStatusLineManager(ISelection selection) { |
1700 | IStatusLineManager statusLineManager = currentViewer != null && currentViewer == contentOutlineViewer ? |
1701 | contentOutlineStatusLineManager : getActionBars().getStatusLineManager(); |
1702 | |
1703 | if (statusLineManager != null) { |
1704 | if (selection instanceof IStructuredSelection) { |
1705 | Collection<?> collection = ((IStructuredSelection)selection).toList(); |
1706 | switch (collection.size()) { |
1707 | case 0: { |
1708 | statusLineManager.setMessage(getString("_UI_NoObjectSelected")); |
1709 | break; |
1710 | } |
1711 | case 1: { |
1712 | String text = new AdapterFactoryItemDelegator(adapterFactory).getText(collection.iterator().next()); |
1713 | statusLineManager.setMessage(getString("_UI_SingleObjectSelected", text)); |
1714 | break; |
1715 | } |
1716 | default: { |
1717 | statusLineManager.setMessage(getString("_UI_MultiObjectSelected", Integer.toString(collection.size()))); |
1718 | break; |
1719 | } |
1720 | } |
1721 | } |
1722 | else { |
1723 | statusLineManager.setMessage(""); |
1724 | } |
1725 | } |
1726 | } |
1727 | |
1728 | /** |
1729 | * This looks up a string in the plugin's plugin.properties file. |
1730 | * <!-- begin-user-doc --> |
1731 | * <!-- end-user-doc --> |
1732 | * @generated |
1733 | */ |
1734 | private static String getString(String key) { |
1735 | return PipesandfiltersEditorPlugin.INSTANCE.getString(key); |
1736 | } |
1737 | |
1738 | /** |
1739 | * This looks up a string in plugin.properties, making a substitution. |
1740 | * <!-- begin-user-doc --> |
1741 | * <!-- end-user-doc --> |
1742 | * @generated |
1743 | */ |
1744 | private static String getString(String key, Object s1) { |
1745 | return PipesandfiltersEditorPlugin.INSTANCE.getString(key, new Object [] { s1 }); |
1746 | } |
1747 | |
1748 | /** |
1749 | * This implements {@link org.eclipse.jface.action.IMenuListener} to help fill the context menus with contributions from the Edit menu. |
1750 | * <!-- begin-user-doc --> |
1751 | * <!-- end-user-doc --> |
1752 | * @generated |
1753 | */ |
1754 | public void menuAboutToShow(IMenuManager menuManager) { |
1755 | ((IMenuListener)getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager); |
1756 | } |
1757 | |
1758 | /** |
1759 | * <!-- begin-user-doc --> |
1760 | * <!-- end-user-doc --> |
1761 | * @generated |
1762 | */ |
1763 | public EditingDomainActionBarContributor getActionBarContributor() { |
1764 | return (EditingDomainActionBarContributor)getEditorSite().getActionBarContributor(); |
1765 | } |
1766 | |
1767 | /** |
1768 | * <!-- begin-user-doc --> |
1769 | * <!-- end-user-doc --> |
1770 | * @generated |
1771 | */ |
1772 | public IActionBars getActionBars() { |
1773 | return getActionBarContributor().getActionBars(); |
1774 | } |
1775 | |
1776 | /** |
1777 | * <!-- begin-user-doc --> |
1778 | * <!-- end-user-doc --> |
1779 | * @generated |
1780 | */ |
1781 | public AdapterFactory getAdapterFactory() { |
1782 | return adapterFactory; |
1783 | } |
1784 | |
1785 | /** |
1786 | * <!-- begin-user-doc --> |
1787 | * <!-- end-user-doc --> |
1788 | * @generated |
1789 | */ |
1790 | @Override |
1791 | public void dispose() { |
1792 | updateProblemIndication = false; |
1793 | |
1794 | ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceChangeListener); |
1795 | |
1796 | getSite().getPage().removePartListener(partListener); |
1797 | |
1798 | adapterFactory.dispose(); |
1799 | |
1800 | if (getActionBarContributor().getActiveEditor() == this) { |
1801 | getActionBarContributor().setActiveEditor(null); |
1802 | } |
1803 | |
1804 | if (propertySheetPage != null) { |
1805 | propertySheetPage.dispose(); |
1806 | } |
1807 | |
1808 | if (contentOutlinePage != null) { |
1809 | contentOutlinePage.dispose(); |
1810 | } |
1811 | |
1812 | super.dispose(); |
1813 | } |
1814 | |
1815 | /** |
1816 | * Returns whether the outline view should be presented to the user. |
1817 | * <!-- begin-user-doc --> |
1818 | * <!-- end-user-doc --> |
1819 | * @generated |
1820 | */ |
1821 | protected boolean showOutlineView() { |
1822 | return true; |
1823 | } |
1824 | } |