1 package org.simantics.district.selection.ui.handlers;
3 import javax.inject.Inject;
5 import org.eclipse.e4.core.contexts.IEclipseContext;
6 import org.eclipse.e4.core.di.annotations.CanExecute;
7 import org.eclipse.e4.core.di.annotations.Execute;
8 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
9 import org.eclipse.e4.ui.workbench.IWorkbench;
10 import org.eclipse.e4.ui.workbench.modeling.EPartService;
11 import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
12 import org.eclipse.swt.widgets.Display;
13 import org.simantics.district.selection.ElementSelector;
14 import org.simantics.district.selection.ui.parts.ElementSelectionView;
16 public class PerformSelectionQueryHandler {
19 EPartService partService;
22 public boolean canExecute(ESelectionService selectionService) {
23 MPart part = partService.getActivePart();
24 if (part == null) return false;
26 Object object = part.getObject();
27 if (object == null || !(object instanceof ElementSelectionView))
30 ElementSelectionView view = (ElementSelectionView)object;
31 return view.getSelectedItem() != null;
35 public void performElementSelection(IEclipseContext context, IWorkbench workbench) {
36 MPart part = partService.getActivePart();
37 if (part == null) return;
39 Object object = part.getObject();
40 if (object == null || !(object instanceof ElementSelectionView))
43 ElementSelectionView view = (ElementSelectionView)object;
44 ElementSelector selectedItem = view.getSelectedItem();
46 Display display = context.getActive(Display.class);
47 view.performSelection(display, selectedItem);