1 package org.simantics.district.network.ui.contributions;
3 import javax.inject.Named;
5 import org.eclipse.core.runtime.IProgressMonitor;
6 import org.eclipse.core.runtime.IStatus;
7 import org.eclipse.core.runtime.Status;
8 import org.eclipse.core.runtime.jobs.Job;
9 import org.eclipse.e4.core.di.annotations.CanExecute;
10 import org.eclipse.e4.core.di.annotations.Execute;
11 import org.eclipse.e4.ui.model.application.ui.basic.MPart;
12 import org.eclipse.e4.ui.services.IServiceConstants;
13 import org.eclipse.ui.IEditorPart;
14 import org.simantics.DatabaseJob;
15 import org.simantics.Simantics;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.WriteRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.district.network.ui.internal.Activator;
20 import org.simantics.ui.workbench.IResourceEditorInput;
21 import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
23 public class RunMappingHandler {
26 public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
27 IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
28 return activeEditorPart != null;
32 public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
33 Job job = new DatabaseJob("Map network to Apros") {
36 protected IStatus run(IProgressMonitor monitor) {
38 IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
39 IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
40 Simantics.getSession().syncRequest(new WriteRequest() {
43 public void perform(WriteGraph graph) throws DatabaseException {
44 Object result = Simantics.applySCL("Apros/District/DistrictMapping", "mapNetworkToAprosProgress", graph, monitor, input.getResource());
47 } catch (DatabaseException e) {
48 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
50 return Status.OK_STATUS;