]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/FlagOperationHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / FlagOperationHandler.java
index c3b7d50000619775aaedd00b7f296caf7bf6ddd7..0208929a52e625b97555f930952822d2cd2c419e 100644 (file)
@@ -1,82 +1,82 @@
-package org.simantics.modeling.ui.actions;\r
-\r
-import java.lang.reflect.InvocationTargetException;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;\r
-import org.eclipse.jface.operation.IRunnableWithProgress;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.IStructuredSelection;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.handlers.HandlerUtil;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.CancelTransactionException;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.SelectionHints;\r
-import org.simantics.g2d.canvas.ICanvasContext;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class FlagOperationHandler extends AbstractHandler {\r
-\r
-    protected abstract void perform(IProgressMonitor monitor, WriteGraph graph, List<Resource> flags,\r
-            ICanvasContext canvasContext) throws DatabaseException;\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-        //System.out.println("mergeFlags");\r
-        ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()\r
-            .getSelection();\r
-\r
-        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);\r
-        final ICanvasContext canvasContext = (ICanvasContext) part.getAdapter(ICanvasContext.class);\r
-\r
-        if (selection instanceof IStructuredSelection) {\r
-            final List<Resource> flags = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);\r
-            try {\r
-                Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
-                new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {\r
-                    @Override\r
-                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {\r
-                        runWithProgress(monitor, flags, canvasContext);\r
-                    }\r
-                });\r
-            } catch (InvocationTargetException e) {\r
-                ExceptionUtils.logAndShowError(e.getTargetException());\r
-            } catch (InterruptedException e) {\r
-            }\r
-        }\r
-        return null;\r
-    }\r
-\r
-    protected void runWithProgress(final IProgressMonitor monitor, final List<Resource> flags, final ICanvasContext canvasContext) throws InvocationTargetException {\r
-        try {\r
-            Simantics.getSession().sync(new WriteRequest() {\r
-                @Override\r
-                public void perform(WriteGraph graph) throws DatabaseException {\r
-                    graph.markUndoPoint();\r
-                    FlagOperationHandler.this.perform(monitor, graph, flags, canvasContext);\r
-                }\r
-            });\r
-        } catch (CancelTransactionException e) {\r
-            // OK.\r
-        } catch (DatabaseException e) {\r
-            throw new InvocationTargetException(e);\r
-        } finally {\r
-            monitor.done();\r
-        }\r
-    }\r
-\r
+package org.simantics.modeling.ui.actions;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.CancelTransactionException;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.g2d.canvas.ICanvasContext;
+import org.simantics.utils.ui.ExceptionUtils;
+import org.simantics.utils.ui.ISelectionUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public abstract class FlagOperationHandler extends AbstractHandler {
+
+    protected abstract void perform(IProgressMonitor monitor, WriteGraph graph, List<Resource> flags,
+            ICanvasContext canvasContext) throws DatabaseException;
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+        //System.out.println("mergeFlags");
+        ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
+            .getSelection();
+
+        IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
+        final ICanvasContext canvasContext = (ICanvasContext) part.getAdapter(ICanvasContext.class);
+
+        if (selection instanceof IStructuredSelection) {
+            final List<Resource> flags = ISelectionUtils.getPossibleKeys(selection, SelectionHints.KEY_MAIN, Resource.class);
+            try {
+                Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+                new ProgressMonitorDialog(shell).run(true, false, new IRunnableWithProgress() {
+                    @Override
+                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+                        runWithProgress(monitor, flags, canvasContext);
+                    }
+                });
+            } catch (InvocationTargetException e) {
+                ExceptionUtils.logAndShowError(e.getTargetException());
+            } catch (InterruptedException e) {
+            }
+        }
+        return null;
+    }
+
+    protected void runWithProgress(final IProgressMonitor monitor, final List<Resource> flags, final ICanvasContext canvasContext) throws InvocationTargetException {
+        try {
+            Simantics.getSession().sync(new WriteRequest() {
+                @Override
+                public void perform(WriteGraph graph) throws DatabaseException {
+                    graph.markUndoPoint();
+                    FlagOperationHandler.this.perform(monitor, graph, flags, canvasContext);
+                }
+            });
+        } catch (CancelTransactionException e) {
+            // OK.
+        } catch (DatabaseException e) {
+            throw new InvocationTargetException(e);
+        } finally {
+            monitor.done();
+        }
+    }
+
 }
\ No newline at end of file