+ /**
+ * Reinitialize this diagram editor from scratch.
+ *
+ * <p>Must be invoked from the SWT thread.</p>
+ */
+ public void reinitializeViewer() {
+ if (viewer != null) {
+ DISPOSING_POLICY.removeDisposer(disposer);
+ tryDisposeViewer();
+ try {
+ viewer = createViewer();
+ viewer.init(this, getEditorSite(), getEditorInput(), diagramContainer, selectionProvider);
+ initializeViewer();
+ } catch (PartInitException e) {
+ // This should never happen!
+ ErrorLogger.defaultLogError(e);
+ }
+ }
+ }
+
+ /**
+ * Reinitializes all {@link DiagramEditor} instances in all workbench windows for which
+ * the specified predicate returns <code>true</code>.
+ *
+ * <p>Must be invoked from the SWT thread.</p>
+ *
+ * @param predicate
+ * tester for editor inputs
+ */
+ public static void reinitializeDiagram(Predicate<IEditorInput> predicate) {
+ for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
+ for (IWorkbenchPage page : window.getPages()) {
+ for (IEditorReference editorRef : page.getEditorReferences()) {
+ try {
+ IEditorInput input = editorRef.getEditorInput();
+ if (predicate.test(input)) {
+ IEditorPart editor = editorRef.getEditor(false);
+ if (editor instanceof DiagramEditor)
+ ((DiagramEditor) editor).reinitializeViewer();
+ }
+ } catch (PartInitException e) {
+ ErrorLogger.defaultLogError(e);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Reinitializes all DiagramEditor instances in all workbench windows that have
+ * the specified <code>diagram</code> as their input.
+ *
+ * <p>Must be invoked from the SWT thread.</p>
+ *
+ * @param diagram
+ * the diagram resource for which to reinitialize all DiagramEditors
+ * for
+ */
+ public static void reinitializeDiagram(Resource diagram) {
+ reinitializeDiagram(input -> input instanceof IResourceEditorInput
+ && ((IResourceEditorInput) input).getResource().equals(diagram));
+ }
+
+ /**
+ * Reinitializes all DiagramEditor instances in all workbench windows that have
+ * the specified <code>diagrams</code> as their input.
+ *
+ * <p>Must be invoked from the SWT thread.</p>
+ *
+ * @param diagrams
+ * collection of diagram resources for which to reinitialize all DiagramEditors
+ * for
+ */
+ public static void reinitializeDiagram(Set<Resource> diagrams) {
+ reinitializeDiagram(input -> input instanceof IResourceEditorInput
+ && diagrams.contains(((IResourceEditorInput) input).getResource()));
+ }
+