Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* Philip Wenig - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.handlers;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.rcp.app.ui.handlers.PerspectiveSwitchHandler;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
Expand All @@ -31,9 +28,8 @@ public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
* Try to select and show the perspective and view.
*/
String perspectiveId = "org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.perspective";
List<String> viewIds = new ArrayList<>();
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakCSD");
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView");
String[] viewIds = {"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakCSD",
"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView"};
PerspectiveSwitchHandler.focusPerspectiveAndView(perspectiveId, viewIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* Philip Wenig - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.handlers;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.rcp.app.ui.handlers.PerspectiveSwitchHandler;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
Expand All @@ -31,9 +28,8 @@ public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part) {
* Try to select and show the perspective and view.
*/
String perspectiveId = "org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.perspective";
List<String> viewIds = new ArrayList<>();
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakMSD");
viewIds.add("org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView");
String[] viewIds = {"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.manualDetectedPeakMSD",
"org.eclipse.chemclipse.chromatogram.xxd.peak.detector.supplier.manual.ui.views.chromatogramSelectionView"};
PerspectiveSwitchHandler.focusPerspectiveAndView(perspectiveId, viewIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
import org.eclipse.chemclipse.rcp.app.ui.provider.PerspectiveSwitcherContentProvider;
import org.eclipse.chemclipse.rcp.app.ui.provider.PerspectiveSwitcherLabelProvider;
import org.eclipse.chemclipse.rcp.app.ui.provider.PerspectiveSwitcherViewerFilter;
import org.eclipse.chemclipse.support.events.IChemClipseEvents;
import org.eclipse.chemclipse.support.ui.workbench.PerspectiveSupport;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.extensions.Preference;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ISelectionChangedListener;
Expand Down Expand Up @@ -78,9 +76,7 @@ public class PerspectiveSwitcherDialog extends Dialog implements ISelectionChang
@Inject
private EModelService modelService;
@Inject
private EPartService partService;
@Inject
private IEventBroker eventBroker;
private PerspectiveSupport perspectiveSupport;
/*
* Store the previous selected perspectives
*/
Expand All @@ -90,7 +86,7 @@ public class PerspectiveSwitcherDialog extends Dialog implements ISelectionChang

private PerspectiveSwitcherViewerFilter perspectiveSwitcherViewerFilter = new PerspectiveSwitcherViewerFilter();
private List<MPerspective> perspectives = new ArrayList<>();
private MPerspective selectedPerspective = null;
private String selectedPerspectiveId = null;

@Inject
public PerspectiveSwitcherDialog(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
Expand All @@ -115,7 +111,7 @@ public void selectionChanged(SelectionChangedEvent event) {
* Set the perspective selection.
*/
if(tableViewerControl.get().getStructuredSelection().getFirstElement() instanceof MPerspective perspective) {
selectedPerspective = perspective;
selectedPerspectiveId = perspective.getElementId();
}

validateSelection();
Expand Down Expand Up @@ -164,14 +160,8 @@ private void initialize() {

private void switchPerspective() {

if(selectedPerspective != null) {
Display.getDefault().asyncExec(() -> {

partService.switchPerspective(selectedPerspective);
if(eventBroker != null) {
eventBroker.send(IChemClipseEvents.TOPIC_APPLICATION_SELECT_PERSPECTIVE, selectedPerspective.getLabel());
}
});
if(selectedPerspectiveId != null) {
Display.getDefault().asyncExec(() -> perspectiveSupport.changePerspective(selectedPerspectiveId));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
*******************************************************************************/
package org.eclipse.chemclipse.rcp.app.ui.handlers;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.chemclipse.rcp.app.ui.dialogs.PerspectiveChooserDialog;
import org.eclipse.chemclipse.rcp.app.ui.dialogs.PerspectiveSwitcherDialog;
import org.eclipse.chemclipse.rcp.app.ui.preferences.PreferenceSupplier;
import org.eclipse.chemclipse.rcp.app.ui.switcher.PerspectiveSwitcher;
import org.eclipse.chemclipse.support.ui.workbench.PartSupport;
import org.eclipse.chemclipse.support.ui.workbench.PerspectiveSupport;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.annotations.Execute;
Expand All @@ -34,7 +32,10 @@ public class PerspectiveSwitchHandler {

@Inject
private static MApplication application;
private static PerspectiveSwitcher perspectiveSwitcher;
@Inject
private static PartSupport partSupport;
@Inject
private static PerspectiveSupport perspectiveSupport;

@Execute
public void execute(MWindow window) {
Expand All @@ -43,22 +44,10 @@ public void execute(MWindow window) {
perspectiveSwitcherDialog.open();
}

public static void focusPerspectiveAndView(String perspectiveId, String viewId) {

List<String> viewIds = new ArrayList<>();
viewIds.add(viewId);
focusPerspectiveAndView(perspectiveId, viewIds);
}

public static void focusViews(List<String> viewIds) {

focusPerspectiveAndView(null, viewIds);
}

public static void focusPerspectiveAndView(String perspectiveId, List<String> viewIds) {
public static void focusPerspectiveAndView(String perspectiveId, String... viewIds) {

/*
* Try to change the perspective and activate the requested view.
* Try to change the perspective and activate the requested view
*/
boolean changePerspectiveAutomatically = PreferenceSupplier.getChangePerspectiveAutomatically();
if(!changePerspectiveAutomatically) {
Expand All @@ -70,7 +59,7 @@ public static void focusPerspectiveAndView(String perspectiveId, List<String> vi
/*
* Create the switcher if null.
*/
if(perspectiveSwitcher == null) {
if(perspectiveSupport == null) {
/*
* The application should definitively exists.
* But this is checked to avoid a NPE.
Expand All @@ -79,19 +68,19 @@ public static void focusPerspectiveAndView(String perspectiveId, List<String> vi
MWindow window = application.getChildren().get(0);
if(window != null) {
IEclipseContext context = window.getContext();
perspectiveSwitcher = ContextInjectionFactory.make(PerspectiveSwitcher.class, context);
perspectiveSupport = ContextInjectionFactory.make(PerspectiveSupport.class, context);
}
}
}
/*
* Change perspective and view.
*/
if(perspectiveId != null) {
perspectiveSwitcher.changePerspective(perspectiveId);
perspectiveSupport.changePerspective(perspectiveId);
}

for(String viewId : viewIds) {
perspectiveSwitcher.focusView(viewId);
partSupport.focusPart(viewId);
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.support.ui.workbench;

import java.util.Collection;

import jakarta.inject.Inject;

import org.eclipse.chemclipse.support.events.IChemClipseEvents;
import org.eclipse.chemclipse.support.events.IPerspectiveAndViewIds;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
Expand All @@ -26,9 +26,11 @@
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;

import jakarta.inject.Inject;

/**
* A helper class that can be injected into E4 parts to perform common tasks
*
*
* @author Christoph Läubrich
*
*/
Expand All @@ -41,6 +43,8 @@ public class PartSupport {
private EModelService eModelService;
@Inject
private EPartService ePartService;
@Inject
private IEventBroker eventBroker;

public void removeEditorsFromPartStack() {

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

/**
* Load and show the part.
*
* @param partId
*/
public void focusPart(String partId) {

Expand All @@ -73,6 +75,9 @@ public void focusPart(String partId) {
ePartService.createPart(part.getElementId());
}
ePartService.showPart(part, PartState.ACTIVATE);
if(eventBroker != null) {
eventBroker.send(IChemClipseEvents.TOPIC_APPLICATION_SELECT_VIEW, part.getLabel());
}
}
}

Expand Down