1 package org.simantics.district.network.ui.visualisations;
3 import javax.annotation.PostConstruct;
4 import javax.annotation.PreDestroy;
5 import javax.inject.Inject;
7 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
8 import org.eclipse.e4.ui.workbench.modeling.EPartService;
9 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
10 import org.eclipse.e4.ui.workbench.modeling.IPartListener;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.ui.IEditorInput;
13 import org.eclipse.ui.IEditorPart;
14 import org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor;
15 import org.simantics.district.network.ui.DistrictDiagramEditor;
16 import org.simantics.ui.workbench.IResourceEditorInput;
17 import org.simantics.utils.ui.workbench.WorkbenchUtils;
19 public class DynamicVisualisationsView {
22 ESelectionService selectionService;
25 EPartService partService;
27 private DynamicVisualisationsUI ui;
30 public void postConstruct(Composite parent) {
31 ui = new DynamicVisualisationsUI(parent, 0);
33 IEditorPart editor = WorkbenchUtils.getActiveEditor();
34 if (editor instanceof DistrictDiagramEditor)
35 setDiagramResource(editor.getEditorInput());
37 partService.addPartListener(partListener);
41 public void dispose() {
42 partService.removePartListener(partListener);
47 private void setDiagramResourceFromCompatibilityEditor(MPart part) {
48 if (part.getObject() instanceof CompatibilityEditor) {
49 CompatibilityEditor editor = (CompatibilityEditor) part.getObject();
50 IEditorPart editorPart = editor.getEditor();
51 setDiagramResource(editorPart.getEditorInput());
55 private void setDiagramResource(IEditorInput input) {
56 if (input instanceof IResourceEditorInput) {
57 ui.setDiagramResource(((IResourceEditorInput) input).getResource());
61 private IPartListener partListener = new IPartListener() {
64 public void partVisible(MPart part) {
65 setDiagramResourceFromCompatibilityEditor(part);
69 public void partHidden(MPart part) {
73 public void partDeactivated(MPart part) {
77 public void partBroughtToTop(MPart part) {
78 setDiagramResourceFromCompatibilityEditor(part);
82 public void partActivated(MPart part) {
83 setDiagramResourceFromCompatibilityEditor(part);