]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.selection.ui/src/org/simantics/district/selection/ui/handlers/PerformSelectionQueryHandler.java
Some tweaks to the element selection query view
[simantics/district.git] / org.simantics.district.selection.ui / src / org / simantics / district / selection / ui / handlers / PerformSelectionQueryHandler.java
1 package org.simantics.district.selection.ui.handlers;
2
3 import javax.inject.Inject;
4
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;
15
16 public class PerformSelectionQueryHandler {
17
18         @Inject
19         EPartService partService;
20         
21         @CanExecute
22         public boolean canExecute(ESelectionService selectionService) {
23                 MPart part = partService.getActivePart();
24                 if (part == null) return false;
25                 
26                 Object object = part.getObject();
27                 if (object == null || !(object instanceof ElementSelectionView))
28                         return false;
29                 
30                 ElementSelectionView view = (ElementSelectionView)object;
31                 return view.getSelectedItem() != null;
32         }
33         
34         @Execute
35         public void performElementSelection(IEclipseContext context, IWorkbench workbench) {
36                 MPart part = partService.getActivePart();
37                 if (part == null) return;
38                 
39                 Object object = part.getObject();
40                 if (object == null || !(object instanceof ElementSelectionView))
41                         return;
42                 
43                 ElementSelectionView view = (ElementSelectionView)object;
44                 ElementSelector selectedItem = view.getSelectedItem();
45                 
46                 Display display = context.getActive(Display.class);
47                 view.performSelection(display, selectedItem);
48         }
49 }