1 package org.simantics.district.network.ui.contributions;
5 import javax.inject.Named;
7 import org.eclipse.core.runtime.IProgressMonitor;
8 import org.eclipse.core.runtime.IStatus;
9 import org.eclipse.core.runtime.Status;
10 import org.eclipse.core.runtime.jobs.Job;
11 import org.eclipse.e4.core.di.annotations.CanExecute;
12 import org.eclipse.e4.core.di.annotations.Execute;
13 import org.eclipse.e4.ui.services.IServiceConstants;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.simantics.DatabaseJob;
16 import org.simantics.Simantics;
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.WriteRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.layer0.SelectionHints;
22 import org.simantics.district.network.DistrictNetworkUtil;
23 import org.simantics.district.network.ui.internal.Activator;
24 import org.simantics.utils.ui.ISelectionUtils;
26 public class DrawMapToggleHandler {
29 public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection) {
30 final List<Resource> diagrams = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
31 return diagrams.size() > 0;
35 public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
36 final List<Resource> diagrams = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
37 Job job = new DatabaseJob("Toggle draw map") {
40 protected IStatus run(IProgressMonitor monitor) {
42 Simantics.getSession().syncRequest(new WriteRequest() {
45 public void perform(WriteGraph graph) throws DatabaseException {
46 DistrictNetworkUtil.toggleDrawMap(graph, diagrams.get(0));
49 } catch (DatabaseException e) {
50 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
52 return Status.OK_STATUS;