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.simantics.Simantics;
13 import org.simantics.db.WriteGraph;
14 import org.simantics.db.common.request.WriteRequest;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.district.selection.ElementSelector;
17 import org.simantics.district.selection.ui.parts.ElementSelectionView;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class DeleteElementSelector {
23 private static final Logger LOGGER = LoggerFactory.getLogger(DeleteElementSelector.class);
26 EPartService partService;
29 public boolean canExecute(ESelectionService selectionService) {
30 MPart part = partService.getActivePart();
31 if (part == null) return false;
33 Object object = part.getObject();
34 if (object == null || !(object instanceof ElementSelectionView))
37 ElementSelectionView view = (ElementSelectionView)object;
38 return view.getSelectedItem() != null;
42 public void editElementSelector(IEclipseContext context, IWorkbench workbench) {
43 MPart part = partService.getActivePart();
44 if (part == null) return;
46 Object object = part.getObject();
47 if (object == null || !(object instanceof ElementSelectionView))
50 ElementSelectionView view = (ElementSelectionView)object;
51 ElementSelector selectedItem = view.getSelectedItem();
53 if (selectedItem == null)
56 Simantics.getSession().async(new WriteRequest() {
58 public void perform(WriteGraph graph) throws DatabaseException {
59 graph.markUndoPoint();
60 graph.deny(selectedItem.getResource());