|
1 | 1 | package gov.noaa.gsd.viz.ensemble.control;
|
2 | 2 |
|
3 |
| -import java.util.ArrayList; |
4 |
| -import java.util.List; |
5 |
| - |
6 | 3 | import org.eclipse.ui.IEditorPart;
|
| 4 | +import org.eclipse.ui.IEditorReference; |
7 | 5 | import org.eclipse.ui.IPartListener2;
|
8 |
| -import org.eclipse.ui.IWorkbenchPart; |
9 | 6 | import org.eclipse.ui.IWorkbenchPartReference;
|
10 |
| -import org.eclipse.ui.PlatformUI; |
11 |
| -import org.eclipse.ui.internal.EditorReference; |
12 |
| -import org.eclipse.ui.part.EditorPart; |
13 | 7 |
|
14 | 8 | import com.raytheon.uf.viz.core.IDisplayPaneContainer;
|
15 |
| -import com.raytheon.uf.viz.core.VizApp; |
16 |
| -import com.raytheon.viz.ui.editor.AbstractEditor; |
| 9 | +import com.raytheon.uf.viz.xy.timeseries.TimeSeriesEditor; |
| 10 | + |
| 11 | +import gov.noaa.gsd.viz.ensemble.control.EnsembleTool.EnsembleToolCompatibility; |
| 12 | +import gov.noaa.gsd.viz.ensemble.control.EnsembleTool.EnsembleToolMode; |
17 | 13 |
|
18 | 14 | /**
|
19 | 15 | * This is the part listener for the editors associated with Ensemble Tool.
|
|
25 | 21 | * Date Ticket# Engineer Description
|
26 | 22 | * ------------ ---------- ----------- --------------------------
|
27 | 23 | * Nov 17, 2014 5056 polster Initial creation
|
| 24 | + * Mar 01, 2017 19443 polster handle part opened for time series |
28 | 25 | *
|
29 | 26 | * </pre>
|
30 | 27 | *
|
|
33 | 30 | */
|
34 | 31 | public class EnsembleEditorPartListener implements IPartListener2 {
|
35 | 32 |
|
36 |
| - private List<IDisplayPaneContainer> editors = null; |
| 33 | + private boolean ignorePartActivatedEvent = false; |
37 | 34 |
|
38 | 35 | public EnsembleEditorPartListener() {
|
39 |
| - editors = new ArrayList<>(); |
40 |
| - } |
41 |
| - |
42 |
| - public void addEditor(IDisplayPaneContainer e) { |
43 |
| - editors.add(e); |
44 |
| - } |
45 |
| - |
46 |
| - public void removeEditor(IDisplayPaneContainer e) { |
47 |
| - editors.remove(e); |
48 | 36 | }
|
49 | 37 |
|
50 | 38 | @Override
|
51 | 39 | public void partActivated(IWorkbenchPartReference partRef) {
|
52 | 40 |
|
53 |
| - if (containsPart(partRef)) { |
54 |
| - IEditorPart editorPart = (EditorPart) partRef.getPart(false); |
55 |
| - |
56 |
| - if (editorPart instanceof IDisplayPaneContainer) { |
57 |
| - IDisplayPaneContainer editor = (IDisplayPaneContainer) editorPart; |
58 |
| - EnsembleTool.getInstance().setEditor(editor); |
59 |
| - EnsembleTool.getInstance().refreshTool(true); |
| 41 | + /* |
| 42 | + * Ignore the part activated event when ignore flag is set |
| 43 | + */ |
| 44 | + if (!ignorePartActivatedEvent) { |
| 45 | + EnsembleToolCompatibility compatibility = EnsembleTool |
| 46 | + .getEditorCompatibility(partRef); |
| 47 | + if (compatibility == EnsembleToolCompatibility.COMPATIBLE_CONTAINS_ENSEMBLE_TOOL_LAYER |
| 48 | + || compatibility == EnsembleToolCompatibility.COMPATIBLE_NO_ENSEMBLE_TOOL_LAYER) { |
| 49 | + EnsembleTool.getInstance().refreshToolByActiveEditor(); |
60 | 50 | }
|
61 | 51 | }
|
62 | 52 | }
|
63 | 53 |
|
64 | 54 | @Override
|
65 |
| - public void partDeactivated(IWorkbenchPartReference partRef) { |
66 |
| - if (containsPart(partRef)) { |
67 |
| - // TODO |
68 |
| - } |
| 55 | + public void partClosed(final IWorkbenchPartReference partRef) { |
| 56 | + // Needed only because the interface requires it |
69 | 57 | }
|
70 | 58 |
|
71 | 59 | @Override
|
72 |
| - public void partBroughtToTop(IWorkbenchPartReference partRef) { |
73 |
| - if (containsPart(partRef)) { |
74 |
| - // TODO |
75 |
| - } |
| 60 | + public void partDeactivated(IWorkbenchPartReference partRef) { |
| 61 | + // Needed only because the interface requires it |
76 | 62 | }
|
77 | 63 |
|
78 | 64 | @Override
|
79 |
| - public void partClosed(IWorkbenchPartReference partRef) { |
80 |
| - if (containsPart(partRef)) { |
81 |
| - |
82 |
| - EditorPart editorPart = (EditorPart) partRef.getPart(false); |
83 |
| - if (editorPart instanceof AbstractEditor) { |
84 |
| - VizApp.runSync(new Runnable() { |
85 |
| - public void run() { |
86 |
| - |
87 |
| - if (!PlatformUI.getWorkbench().isClosing()) { |
88 |
| - EnsembleTool.getInstance() |
89 |
| - .verifyCloseActiveToolLayer(); |
90 |
| - } |
91 |
| - |
92 |
| - } |
93 |
| - }); |
94 |
| - } |
95 |
| - } |
| 65 | + public void partBroughtToTop(IWorkbenchPartReference partRef) { |
| 66 | + // Needed only because the interface requires it |
96 | 67 | }
|
97 | 68 |
|
98 |
| - @SuppressWarnings("restriction") |
99 | 69 | @Override
|
100 | 70 | public void partOpened(IWorkbenchPartReference partRef) {
|
101 |
| - if (containsPart(partRef)) { |
102 |
| - /* ignore */ |
103 |
| - } |
104 | 71 | /*
|
105 | 72 | * Did another editor open? If so, if there is not already a tool layer
|
106 | 73 | * associated with it the tell the manager about the new editor.
|
107 | 74 | */
|
108 |
| - else if (partRef instanceof EditorReference) { |
109 |
| - EditorPart openedEditor = (EditorPart) ((EditorReference) partRef) |
110 |
| - .getPart(false); |
111 |
| - if (openedEditor instanceof IDisplayPaneContainer) { |
| 75 | + if (partRef instanceof IEditorReference) { |
| 76 | + IEditorPart openedEditor = ((IEditorReference) partRef) |
| 77 | + .getEditor(false); |
| 78 | + if (openedEditor instanceof TimeSeriesEditor |
| 79 | + && EnsembleTool.isExtant()) { |
112 | 80 | IDisplayPaneContainer editor = (IDisplayPaneContainer) openedEditor;
|
113 |
| - EnsembleTool.getInstance().setEditor(editor); |
114 |
| - if (!EnsembleTool.getInstance().hasToolLayer(editor)) { |
115 |
| - EnsembleTool.getInstance().createToolLayer(editor); |
| 81 | + /* |
| 82 | + * The time series editor opens automatically when a time series |
| 83 | + * product is requested from the Volume Browser. If the ensemble |
| 84 | + * tool is editable when the time series editor is opened then |
| 85 | + * read the products into the ensemble tool. |
| 86 | + */ |
| 87 | + if (EnsembleTool.getInstance().isToolEditable()) { |
| 88 | + EnsembleTool.getInstance().setEditor(editor); |
| 89 | + /* |
| 90 | + * Ensemble Tool only allows one time series editor at one |
| 91 | + * time to be associated. |
| 92 | + */ |
| 93 | + if (!EnsembleTool.hasToolLayer(editor)) { |
| 94 | + EnsembleTool.getInstance().createToolLayer(editor, |
| 95 | + EnsembleToolMode.LEGENDS_TIME_SERIES); |
| 96 | + } |
| 97 | + EnsembleTool.getInstance().refreshTool(true); |
| 98 | + } |
| 99 | + /* |
| 100 | + * If the ensemble tool was not editable then make sure it gets |
| 101 | + * or stays minimized. |
| 102 | + */ |
| 103 | + else { |
| 104 | + EnsembleTool.getInstance().setEditor(null); |
| 105 | + EnsembleTool.getInstance().refreshToolByActiveEditor(); |
116 | 106 | }
|
117 |
| - EnsembleTool.getInstance().refreshTool(true); |
118 | 107 | }
|
119 | 108 | }
|
120 | 109 | }
|
121 | 110 |
|
122 | 111 | @Override
|
123 | 112 | public void partHidden(IWorkbenchPartReference partRef) {
|
124 |
| - if (containsPart(partRef)) { |
125 |
| - // TODO |
126 |
| - } |
| 113 | + // Needed only because the interface requires it |
127 | 114 | }
|
128 | 115 |
|
129 | 116 | @Override
|
130 | 117 | public void partVisible(IWorkbenchPartReference partRef) {
|
131 |
| - if (containsPart(partRef)) { |
132 |
| - // TODO |
133 |
| - } |
| 118 | + // Needed only because the interface requires it |
134 | 119 | }
|
135 | 120 |
|
136 | 121 | @Override
|
137 | 122 | public void partInputChanged(IWorkbenchPartReference partRef) {
|
138 |
| - if (containsPart(partRef)) { |
139 |
| - // TODO |
140 |
| - } |
| 123 | + // Needed only because the interface requires it |
141 | 124 | }
|
142 | 125 |
|
143 |
| - private boolean containsPart(IWorkbenchPartReference ref) { |
144 |
| - boolean containsPart = false; |
145 |
| - IWorkbenchPart part = ref.getPart(false); |
146 |
| - if (part != null) { |
147 |
| - |
148 |
| - } |
149 |
| - for (IDisplayPaneContainer ep : editors) { |
150 |
| - if (part.equals(ep)) { |
151 |
| - containsPart = true; |
152 |
| - break; |
153 |
| - } |
154 |
| - } |
155 |
| - return containsPart; |
| 126 | + /** |
| 127 | + * Allow this listener to ignore incoming part activated events. |
| 128 | + * |
| 129 | + * @param ignore |
| 130 | + * boolean to turn on/off the "ignore" state |
| 131 | + */ |
| 132 | + public void ignorePartActivatedEvent(boolean ignore) { |
| 133 | + ignorePartActivatedEvent = ignore; |
156 | 134 | }
|
| 135 | + |
157 | 136 | }
|
0 commit comments