1 package org.simantics.district.region.ui.handlers;
3 import javax.inject.Named;
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;
19 public class RemoveRegionHandler {
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";
26 public boolean canExecute() {
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());