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