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