Skip to content

Commit 4bd8d3f

Browse files
authored
Merge pull request #2755 from akurtakov/develop
Streamline perspective switching
2 parents 071b4e4 + d18cba2 commit 4bd8d3f

File tree

6 files changed

+35
-141
lines changed

6 files changed

+35
-141
lines changed

chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui/src/org/eclipse/chemclipse/chromatogram/xxd/peak/detector/supplier/manual/ui/handlers/DetectorHandlerCSD.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
* which is available at https://www.eclipse.org/legal/epl-2.0/
77
*
88
* SPDX-License-Identifier: EPL-2.0
9-
*
9+
*
1010
* Contributors:
1111
* Philip Wenig - initial API and implementation
1212
*******************************************************************************/
1313
package org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.handlers;
1414

15-
import java.util.ArrayList;
16-
import java.util.List;
17-
1815
import org.eclipse.chemclipse.rcp.app.ui.handlers.PerspectiveSwitchHandler;
1916
import org.eclipse.e4.core.di.annotations.Execute;
2017
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
@@ -31,9 +28,8 @@ public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
3128
* Try to select and show the perspective and view.
3229
*/
3330
String perspectiveId = "org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.perspective";
34-
List<String> viewIds = new ArrayList<>();
35-
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakCSD");
36-
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView");
31+
String[] viewIds = {"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakCSD",
32+
"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView"};
3733
PerspectiveSwitchHandler.focusPerspectiveAndView(perspectiveId, viewIds);
3834
}
3935
}

chemclipse/plugins/org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui/src/org/eclipse/chemclipse/chromatogram/xxd/peak/detector/supplier/manual/ui/handlers/DetectorHandlerMSD.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
* which is available at https://www.eclipse.org/legal/epl-2.0/
77
*
88
* SPDX-License-Identifier: EPL-2.0
9-
*
9+
*
1010
* Contributors:
1111
* Philip Wenig - initial API and implementation
1212
*******************************************************************************/
1313
package org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.handlers;
1414

15-
import java.util.ArrayList;
16-
import java.util.List;
17-
1815
import org.eclipse.chemclipse.rcp.app.ui.handlers.PerspectiveSwitchHandler;
1916
import org.eclipse.e4.core.di.annotations.Execute;
2017
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
@@ -31,9 +28,8 @@ public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
3128
* Try to select and show the perspective and view.
3229
*/
3330
String perspectiveId = "org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.perspective";
34-
List<String> viewIds = new ArrayList<>();
35-
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakMSD");
36-
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView");
31+
String[] viewIds = {"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakMSD",
32+
"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView"};
3733
PerspectiveSwitchHandler.focusPerspectiveAndView(perspectiveId, viewIds);
3834
}
3935
}

chemclipse/plugins/org.eclipse.chemclipse.rcp.app.ui/src/org/eclipse/chemclipse/rcp/app/ui/dialogs/PerspectiveSwitcherDialog.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121
import org.eclipse.chemclipse.rcp.app.ui.provider.PerspectiveSwitcherContentProvider;
2222
import org.eclipse.chemclipse.rcp.app.ui.provider.PerspectiveSwitcherLabelProvider;
2323
import org.eclipse.chemclipse.rcp.app.ui.provider.PerspectiveSwitcherViewerFilter;
24-
import org.eclipse.chemclipse.support.events.IChemClipseEvents;
24+
import org.eclipse.chemclipse.support.ui.workbench.PerspectiveSupport;
2525
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2626
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
2727
import org.eclipse.e4.core.contexts.IEclipseContext;
2828
import org.eclipse.e4.core.di.extensions.Preference;
29-
import org.eclipse.e4.core.services.events.IEventBroker;
3029
import org.eclipse.e4.ui.model.application.MApplication;
3130
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
3231
import org.eclipse.e4.ui.services.IServiceConstants;
3332
import org.eclipse.e4.ui.workbench.modeling.EModelService;
34-
import org.eclipse.e4.ui.workbench.modeling.EPartService;
3533
import org.eclipse.jface.dialogs.Dialog;
3634
import org.eclipse.jface.dialogs.IDialogConstants;
3735
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -78,9 +76,7 @@ public class PerspectiveSwitcherDialog extends Dialog implements ISelectionChang
7876
@Inject
7977
private EModelService modelService;
8078
@Inject
81-
private EPartService partService;
82-
@Inject
83-
private IEventBroker eventBroker;
79+
private PerspectiveSupport perspectiveSupport;
8480
/*
8581
* Store the previous selected perspectives
8682
*/
@@ -90,7 +86,7 @@ public class PerspectiveSwitcherDialog extends Dialog implements ISelectionChang
9086

9187
private PerspectiveSwitcherViewerFilter perspectiveSwitcherViewerFilter = new PerspectiveSwitcherViewerFilter();
9288
private List<MPerspective> perspectives = new ArrayList<>();
93-
private MPerspective selectedPerspective = null;
89+
private String selectedPerspectiveId = null;
9490

9591
@Inject
9692
public PerspectiveSwitcherDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
@@ -115,7 +111,7 @@ public void selectionChanged(SelectionChangedEvent event) {
115111
* Set the perspective selection.
116112
*/
117113
if(tableViewerControl.get().getStructuredSelection().getFirstElement() instanceof MPerspective perspective) {
118-
selectedPerspective = perspective;
114+
selectedPerspectiveId = perspective.getElementId();
119115
}
120116

121117
validateSelection();
@@ -164,14 +160,8 @@ private void initialize() {
164160

165161
private void switchPerspective() {
166162

167-
if(selectedPerspective != null) {
168-
Display.getDefault().asyncExec(() -> {
169-
170-
partService.switchPerspective(selectedPerspective);
171-
if(eventBroker != null) {
172-
eventBroker.send(IChemClipseEvents.TOPIC_APPLICATION_SELECT_PERSPECTIVE, selectedPerspective.getLabel());
173-
}
174-
});
163+
if(selectedPerspectiveId != null) {
164+
Display.getDefault().asyncExec(() -> perspectiveSupport.changePerspective(selectedPerspectiveId));
175165
}
176166
}
177167

chemclipse/plugins/org.eclipse.chemclipse.rcp.app.ui/src/org/eclipse/chemclipse/rcp/app/ui/handlers/PerspectiveSwitchHandler.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
*******************************************************************************/
1313
package org.eclipse.chemclipse.rcp.app.ui.handlers;
1414

15-
import java.util.ArrayList;
16-
import java.util.List;
17-
1815
import org.eclipse.chemclipse.rcp.app.ui.dialogs.PerspectiveChooserDialog;
1916
import org.eclipse.chemclipse.rcp.app.ui.dialogs.PerspectiveSwitcherDialog;
2017
import org.eclipse.chemclipse.rcp.app.ui.preferences.PreferenceSupplier;
21-
import org.eclipse.chemclipse.rcp.app.ui.switcher.PerspectiveSwitcher;
18+
import org.eclipse.chemclipse.support.ui.workbench.PartSupport;
19+
import org.eclipse.chemclipse.support.ui.workbench.PerspectiveSupport;
2220
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
2321
import org.eclipse.e4.core.contexts.IEclipseContext;
2422
import org.eclipse.e4.core.di.annotations.Execute;
@@ -34,7 +32,10 @@ public class PerspectiveSwitchHandler {
3432

3533
@Inject
3634
private static MApplication application;
37-
private static PerspectiveSwitcher perspectiveSwitcher;
35+
@Inject
36+
private static PartSupport partSupport;
37+
@Inject
38+
private static PerspectiveSupport perspectiveSupport;
3839

3940
@Execute
4041
public void execute(MWindow window) {
@@ -43,22 +44,10 @@ public void execute(MWindow window) {
4344
perspectiveSwitcherDialog.open();
4445
}
4546

46-
public static void focusPerspectiveAndView(String perspectiveId, String viewId) {
47-
48-
List<String> viewIds = new ArrayList<>();
49-
viewIds.add(viewId);
50-
focusPerspectiveAndView(perspectiveId, viewIds);
51-
}
52-
53-
public static void focusViews(List<String> viewIds) {
54-
55-
focusPerspectiveAndView(null, viewIds);
56-
}
57-
58-
public static void focusPerspectiveAndView(String perspectiveId, List<String> viewIds) {
47+
public static void focusPerspectiveAndView(String perspectiveId, String... viewIds) {
5948

6049
/*
61-
* Try to change the perspective and activate the requested view.
50+
* Try to change the perspective and activate the requested view
6251
*/
6352
boolean changePerspectiveAutomatically = PreferenceSupplier.getChangePerspectiveAutomatically();
6453
if(!changePerspectiveAutomatically) {
@@ -70,7 +59,7 @@ public static void focusPerspectiveAndView(String perspectiveId, List<String> vi
7059
/*
7160
* Create the switcher if null.
7261
*/
73-
if(perspectiveSwitcher == null) {
62+
if(perspectiveSupport == null) {
7463
/*
7564
* The application should definitively exists.
7665
* But this is checked to avoid a NPE.
@@ -79,19 +68,19 @@ public static void focusPerspectiveAndView(String perspectiveId, List<String> vi
7968
MWindow window = application.getChildren().get(0);
8069
if(window != null) {
8170
IEclipseContext context = window.getContext();
82-
perspectiveSwitcher = ContextInjectionFactory.make(PerspectiveSwitcher.class, context);
71+
perspectiveSupport = ContextInjectionFactory.make(PerspectiveSupport.class, context);
8372
}
8473
}
8574
}
8675
/*
8776
* Change perspective and view.
8877
*/
8978
if(perspectiveId != null) {
90-
perspectiveSwitcher.changePerspective(perspectiveId);
79+
perspectiveSupport.changePerspective(perspectiveId);
9180
}
9281

9382
for(String viewId : viewIds) {
94-
perspectiveSwitcher.focusView(viewId);
83+
partSupport.focusPart(viewId);
9584
}
9685
}
9786
}

chemclipse/plugins/org.eclipse.chemclipse.rcp.app.ui/src/org/eclipse/chemclipse/rcp/app/ui/switcher/PerspectiveSwitcher.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

chemclipse/plugins/org.eclipse.chemclipse.support.ui/src/org/eclipse/chemclipse/support/ui/workbench/PartSupport.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
* which is available at https://www.eclipse.org/legal/epl-2.0/
77
*
88
* SPDX-License-Identifier: EPL-2.0
9-
*
9+
*
1010
* Contributors:
1111
* Christoph Läubrich - initial API and implementation
1212
*******************************************************************************/
1313
package org.eclipse.chemclipse.support.ui.workbench;
1414

1515
import java.util.Collection;
1616

17-
import jakarta.inject.Inject;
18-
17+
import org.eclipse.chemclipse.support.events.IChemClipseEvents;
1918
import org.eclipse.chemclipse.support.events.IPerspectiveAndViewIds;
2019
import org.eclipse.e4.core.di.annotations.Creatable;
20+
import org.eclipse.e4.core.services.events.IEventBroker;
2121
import org.eclipse.e4.ui.model.application.MApplication;
2222
import org.eclipse.e4.ui.model.application.ui.MUIElement;
2323
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
@@ -26,9 +26,11 @@
2626
import org.eclipse.e4.ui.workbench.modeling.EPartService;
2727
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
2828

29+
import jakarta.inject.Inject;
30+
2931
/**
3032
* A helper class that can be injected into E4 parts to perform common tasks
31-
*
33+
*
3234
* @author Christoph Läubrich
3335
*
3436
*/
@@ -41,6 +43,8 @@ public class PartSupport {
4143
private EModelService eModelService;
4244
@Inject
4345
private EPartService ePartService;
46+
@Inject
47+
private IEventBroker eventBroker;
4448

4549
public void removeEditorsFromPartStack() {
4650

@@ -62,8 +66,6 @@ public boolean saveDirtyParts() {
6266

6367
/**
6468
* Load and show the part.
65-
*
66-
* @param partId
6769
*/
6870
public void focusPart(String partId) {
6971

@@ -73,6 +75,9 @@ public void focusPart(String partId) {
7375
ePartService.createPart(part.getElementId());
7476
}
7577
ePartService.showPart(part, PartState.ACTIVATE);
78+
if(eventBroker != null) {
79+
eventBroker.send(IChemClipseEvents.TOPIC_APPLICATION_SELECT_VIEW, part.getLabel());
80+
}
7681
}
7782
}
7883

0 commit comments

Comments
 (0)