package org.simantics.district.region.ui.handlers; import javax.inject.Named; import org.eclipse.e4.core.di.annotations.CanExecute; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.ui.model.application.ui.basic.MPart; import org.eclipse.e4.ui.services.IServiceConstants; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Shell; import org.simantics.Simantics; import org.simantics.db.request.Write; import org.simantics.district.region.DiagramRegions; import org.simantics.district.region.DiagramRegions.DiagramRegion; import org.simantics.utils.ui.ISelectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class RemoveRegionHandler { private static final Logger LOGGER = LoggerFactory.getLogger(RemoveRegionHandler.class); public static final String COMMAND_ID = "org.simantics.district.region.ui.command.removeRegion"; public static final String LABEL = "Remove Region"; @CanExecute public boolean canExecute() { return true; } @Execute public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell activeShell, @Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) { DiagramRegion region = ISelectionUtils.filterSingleSelection(selection, DiagramRegion.class); Simantics.getSession().asyncRequest((Write) graph -> { DiagramRegions.removeRegion(graph, region.getResource()); }); } }