]> gerrit.simantics Code Review - simantics/district.git/blob
46b11a2febedada000c662607628f96727ece4e9
[simantics/district.git] /
1 package org.simantics.district.region.ui.handlers;
2
3 import javax.inject.Named;
4
5 import org.eclipse.e4.core.di.annotations.CanExecute;
6 import org.eclipse.e4.core.di.annotations.Execute;
7 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
8 import org.eclipse.e4.ui.services.IServiceConstants;
9 import org.eclipse.jface.viewers.ISelection;
10 import org.eclipse.swt.widgets.Shell;
11 import org.simantics.Simantics;
12 import org.simantics.db.request.Write;
13 import org.simantics.district.region.DiagramRegions;
14 import org.simantics.district.region.DiagramRegions.DiagramRegion;
15 import org.simantics.utils.ui.ISelectionUtils;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class RemoveRegionHandler {
20
21     private static final Logger LOGGER = LoggerFactory.getLogger(RemoveRegionHandler.class);
22     public static final String COMMAND_ID = "org.simantics.district.region.ui.command.removeRegion";
23     public static final String LABEL = "Remove Region";
24
25     @CanExecute
26     public boolean canExecute() {
27         return true;
28     }
29
30     @Execute
31     public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell,
32             @Named(IServiceConstants.ACTIVE_PART) MPart part,
33             @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
34         DiagramRegion region = ISelectionUtils.filterSingleSelection(selection, DiagramRegion.class);
35         Simantics.getSession().asyncRequest((Write) graph -> {
36             DiagramRegions.removeRegion(graph, region.getResource());
37         });
38     }
39 }