+++ /dev/null
-package org.simantics.district.network.ui.contributions;
-
-import javax.inject.Named;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-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.ui.IEditorPart;
-import org.simantics.DatabaseJob;
-import org.simantics.Simantics;
-import org.simantics.db.WriteGraph;
-import org.simantics.db.common.request.WriteRequest;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.district.network.ui.internal.Activator;
-import org.simantics.ui.workbench.IResourceEditorInput;
-import org.simantics.ui.workbench.e4.E4WorkbenchUtils;
-
-public class RunMappingHandler {
-
- @CanExecute
- public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
- IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
- return activeEditorPart != null;
- }
-
- @Execute
- public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart mActiveEditorPart) {
- Job job = new DatabaseJob("Map network to Apros") {
-
- @Override
- protected IStatus run(IProgressMonitor monitor) {
- try {
- IEditorPart activeEditorPart = E4WorkbenchUtils.getActiveIEditorPart(mActiveEditorPart);
- IResourceEditorInput input = (IResourceEditorInput) activeEditorPart.getEditorInput();
- Simantics.getSession().syncRequest(new WriteRequest() {
-
- @Override
- public void perform(WriteGraph graph) throws DatabaseException {
- Object result = Simantics.applySCL("Apros/District/DistrictMapping", "mapNetworkToAprosProgress", graph, monitor, input.getResource());
- }
- });
- } catch (DatabaseException e) {
- return new Status(IStatus.ERROR, Activator.PLUGIN_ID, getName() + " failed.", e);
- }
- return Status.OK_STATUS;
- }
- };
- job.setUser(true);
- job.schedule();
- }
-}