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