]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/DuplicatePinnedViewHandler.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / DuplicatePinnedViewHandler.java
diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/DuplicatePinnedViewHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/DuplicatePinnedViewHandler.java
new file mode 100644 (file)
index 0000000..a844789
--- /dev/null
@@ -0,0 +1,72 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\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.actions;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.UUID;\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.jface.viewers.ISelection;\r
+import org.eclipse.ui.IWorkbenchPart;\r
+import org.eclipse.ui.commands.ICommandService;\r
+import org.eclipse.ui.handlers.HandlerUtil;\r
+import org.eclipse.ui.services.IServiceScopes;\r
+import org.simantics.browsing.ui.platform.PropertyPageView;\r
+import org.simantics.utils.ui.ExceptionUtils;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class DuplicatePinnedViewHandler extends AbstractHandler {\r
+\r
+    private static final String PIN_SELECTION_COMMAND = "org.simantics.modeling.ui.pinSelection";\r
+\r
+    @Override\r
+    public Object execute(ExecutionEvent event) throws ExecutionException {\r
+        IWorkbenchPart originalPart = HandlerUtil.getActivePartChecked(event);\r
+        if (!(originalPart instanceof PropertyPageView))\r
+            return null;\r
+        PropertyPageView originalPropertyView = (PropertyPageView) originalPart;\r
+\r
+        try {\r
+            // Activate a new unique instance of the same property page view.\r
+            // Its initialization procedures and IContributedContentsView\r
+            // implementation should take care that the view will be initialized\r
+            // with a property page just like the original.\r
+            ISelection originalSelection = originalPropertyView.getLastSelection();\r
+\r
+            final String id = originalPart.getSite().getId() + "Pinned:" + UUID.randomUUID().toString();\r
+            PropertyPageView newPart = (PropertyPageView) WorkbenchUtils.activateView(id);\r
+\r
+            newPart.partActivated(originalPart);\r
+            newPart.selectionChanged(originalPart, originalSelection);\r
+\r
+            // Make sure that the view is pinned and that its pinned button is in the right state.\r
+            newPart.pinWorkbenchSelection(true);\r
+\r
+            ICommandService commandService = (ICommandService) newPart.getViewSite().getService(ICommandService.class);\r
+            Map<Object, Object> filter = new HashMap<Object, Object>();\r
+            filter.put(IServiceScopes.PARTSITE_SCOPE, newPart.getSite());\r
+            commandService.refreshElements(PIN_SELECTION_COMMAND, filter);\r
+\r
+        } catch (Exception e) {\r
+            ExceptionUtils.logAndShowError(e);\r
+        }\r
+\r
+        return null;\r
+    }\r
+\r
+}\r