]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardPasteHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / handlers / StandardPasteHandler.java
index 51140988bcd505220271becb41c3f7082c86f1f4..32e3ef60ff13afa83a43e6061d6f1ae6b1c284b9 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.modeling.ui.modelBrowser.handlers;\r
-\r
-\r
-import java.lang.reflect.InvocationTargetException;\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.commands.IHandler;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.SubMonitor;\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.swt.widgets.Shell;\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.common.primitiverequest.Adapter;\r
-import org.simantics.db.common.utils.Logger;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.adapter.PasteHandler;\r
-import org.simantics.ui.SimanticsUI;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.ExceptionUtils;\r
-\r
-public class StandardPasteHandler extends AbstractHandler implements IHandler {\r
-\r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-\r
-        final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();\r
-        final PasteHandler handler = SimanticsUI.filterSingleSelection(selection, PasteHandler.class);\r
-       if (handler != null) {\r
-               \r
-               try {\r
-                       \r
-                   Simantics.getSession().markUndoPoint();\r
-                       IRunnableWithProgress op = pasteResourceFromClipboard(handler);\r
-                       \r
-                       Shell shell = HandlerUtil.getActiveShell(event);\r
-                       new ProgressMonitorDialog(shell).run(true, true, op);\r
-                       \r
-               } catch (InvocationTargetException e) {\r
-                       Throwable t = e.getCause();\r
-                       if (t != null) {\r
-                               ExceptionUtils.logAndShowError("Paste Failed", t.getMessage(), e);\r
-                       } else {\r
-                               ExceptionUtils.logAndShowError("Paste Failed", "Paste failed for unknown reason.", e);\r
-                       }\r
-               } catch (InterruptedException e) {\r
-                       ErrorLogger.defaultLogError(e);\r
-               }\r
-               \r
-        }\r
-       return null;\r
-    }\r
-    \r
-    public static IRunnableWithProgress pasteResourceFromClipboard(final PasteHandler handler) {\r
-       \r
-       IRunnableWithProgress op = new IRunnableWithProgress() {\r
-\r
-                       @Override\r
-                       public void run(IProgressMonitor monitor) throws InvocationTargetException,\r
-                       InterruptedException {\r
-                               SubMonitor progress = SubMonitor.convert(monitor, 100);\r
-                               try {\r
-                                       progress.beginTask("Copying", 100);\r
-                                       progress.worked(50);\r
-                                       progress.subTask("Please wait..");\r
-                           handler.pasteFromClipboard(Simantics.getClipboard());\r
-                               } catch (Exception e) {\r
-                                       throw new InvocationTargetException(e);\r
-                               } finally {\r
-                                       monitor.done();\r
-                               }\r
-                       }\r
-               };\r
-               return op;\r
-       \r
-    }\r
-    \r
-    public static void pasteResourceFromClipboardWithoutMonitor (final PasteHandler handler) {\r
-       try {\r
-               handler.pasteFromClipboard(Simantics.getClipboard());\r
-               } catch (DatabaseException e) {\r
-                       try {\r
-                               throw new InvocationTargetException(e);\r
-                       } catch (InvocationTargetException e1) {\r
-                               e1.getCause().printStackTrace();\r
-                       }\r
-                       e.printStackTrace();\r
-               }\r
-    }\r
-    \r
-    public static <T> T getPasteHandlerFromResource (Resource resource, Class<T> assignableFrom) {\r
-    \r
-    try {\r
-        return Simantics.getSession().syncRequest(new Adapter<T>(resource, assignableFrom));\r
-    } catch (DatabaseException e) {\r
-        Logger.defaultLogError(e);\r
-        return null;\r
-    }\r
-    }\r
-}\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.ui.modelBrowser.handlers;
+
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.common.primitiverequest.Adapter;
+import org.simantics.db.common.utils.Logger;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.PasteHandler;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.utils.ui.ErrorLogger;
+import org.simantics.utils.ui.ExceptionUtils;
+
+public class StandardPasteHandler extends AbstractHandler implements IHandler {
+
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+        final ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+        final PasteHandler handler = SimanticsUI.filterSingleSelection(selection, PasteHandler.class);
+       if (handler != null) {
+               
+               try {
+                       
+                   Simantics.getSession().markUndoPoint();
+                       IRunnableWithProgress op = pasteResourceFromClipboard(handler);
+                       
+                       Shell shell = HandlerUtil.getActiveShell(event);
+                       new ProgressMonitorDialog(shell).run(true, true, op);
+                       
+               } catch (InvocationTargetException e) {
+                       Throwable t = e.getCause();
+                       if (t != null) {
+                               ExceptionUtils.logAndShowError("Paste Failed", t.getMessage(), e);
+                       } else {
+                               ExceptionUtils.logAndShowError("Paste Failed", "Paste failed for unknown reason.", e);
+                       }
+               } catch (InterruptedException e) {
+                       ErrorLogger.defaultLogError(e);
+               }
+               
+        }
+       return null;
+    }
+    
+    public static IRunnableWithProgress pasteResourceFromClipboard(final PasteHandler handler) {
+       
+       IRunnableWithProgress op = new IRunnableWithProgress() {
+
+                       @Override
+                       public void run(IProgressMonitor monitor) throws InvocationTargetException,
+                       InterruptedException {
+                               SubMonitor progress = SubMonitor.convert(monitor, 100);
+                               try {
+                                       progress.beginTask("Copying", 100);
+                                       progress.worked(50);
+                                       progress.subTask("Please wait..");
+                           handler.pasteFromClipboard(Simantics.getClipboard());
+                               } catch (Exception e) {
+                                       throw new InvocationTargetException(e);
+                               } finally {
+                                       monitor.done();
+                               }
+                       }
+               };
+               return op;
+       
+    }
+    
+    public static void pasteResourceFromClipboardWithoutMonitor (final PasteHandler handler) {
+       try {
+               handler.pasteFromClipboard(Simantics.getClipboard());
+               } catch (DatabaseException e) {
+                       try {
+                               throw new InvocationTargetException(e);
+                       } catch (InvocationTargetException e1) {
+                               e1.getCause().printStackTrace();
+                       }
+                       e.printStackTrace();
+               }
+    }
+    
+    public static <T> T getPasteHandlerFromResource (Resource resource, Class<T> assignableFrom) {
+    
+    try {
+        return Simantics.getSession().syncRequest(new Adapter<T>(resource, assignableFrom));
+    } catch (DatabaseException e) {
+        Logger.defaultLogError(e);
+        return null;
+    }
+    }
+}
+