X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2FDuplicatePinnedViewHandler.java;h=51aec07c6d11b92d5dc234206305f363cee4ea92;hb=HEAD;hp=a84478976cf6d8eb9e1ba0d4d59fc469b9e602c4;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git 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 index a84478976..51aec07c6 100644 --- 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 @@ -1,72 +1,72 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * 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.actions; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.ui.services.IServiceScopes; -import org.simantics.browsing.ui.platform.PropertyPageView; -import org.simantics.utils.ui.ExceptionUtils; -import org.simantics.utils.ui.workbench.WorkbenchUtils; - -/** - * @author Tuukka Lehtonen - */ -public class DuplicatePinnedViewHandler extends AbstractHandler { - - private static final String PIN_SELECTION_COMMAND = "org.simantics.modeling.ui.pinSelection"; - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchPart originalPart = HandlerUtil.getActivePartChecked(event); - if (!(originalPart instanceof PropertyPageView)) - return null; - PropertyPageView originalPropertyView = (PropertyPageView) originalPart; - - try { - // Activate a new unique instance of the same property page view. - // Its initialization procedures and IContributedContentsView - // implementation should take care that the view will be initialized - // with a property page just like the original. - ISelection originalSelection = originalPropertyView.getLastSelection(); - - final String id = originalPart.getSite().getId() + "Pinned:" + UUID.randomUUID().toString(); - PropertyPageView newPart = (PropertyPageView) WorkbenchUtils.activateView(id); - - newPart.partActivated(originalPart); - newPart.selectionChanged(originalPart, originalSelection); - - // Make sure that the view is pinned and that its pinned button is in the right state. - newPart.pinWorkbenchSelection(true); - - ICommandService commandService = (ICommandService) newPart.getViewSite().getService(ICommandService.class); - Map filter = new HashMap(); - filter.put(IServiceScopes.PARTSITE_SCOPE, newPart.getSite()); - commandService.refreshElements(PIN_SELECTION_COMMAND, filter); - - } catch (Exception e) { - ExceptionUtils.logAndShowError(e); - } - - return null; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * 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.actions; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.services.IServiceScopes; +import org.simantics.browsing.ui.platform.PropertyPageView; +import org.simantics.utils.ui.ExceptionUtils; +import org.simantics.utils.ui.workbench.WorkbenchUtils; + +/** + * @author Tuukka Lehtonen + */ +public class DuplicatePinnedViewHandler extends AbstractHandler { + + private static final String PIN_SELECTION_COMMAND = "org.simantics.modeling.ui.pinSelection"; //$NON-NLS-1$ + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchPart originalPart = HandlerUtil.getActivePartChecked(event); + if (!(originalPart instanceof PropertyPageView)) + return null; + PropertyPageView originalPropertyView = (PropertyPageView) originalPart; + + try { + // Activate a new unique instance of the same property page view. + // Its initialization procedures and IContributedContentsView + // implementation should take care that the view will be initialized + // with a property page just like the original. + ISelection originalSelection = originalPropertyView.getLastSelection(); + + final String id = originalPart.getSite().getId() + "Pinned:" + UUID.randomUUID().toString(); //$NON-NLS-1$ + PropertyPageView newPart = (PropertyPageView) WorkbenchUtils.activateView(id); + + newPart.partActivated(originalPart); + newPart.selectionChanged(originalPart, originalSelection); + + // Make sure that the view is pinned and that its pinned button is in the right state. + newPart.pinWorkbenchSelection(true); + + ICommandService commandService = (ICommandService) newPart.getViewSite().getService(ICommandService.class); + Map filter = new HashMap(); + filter.put(IServiceScopes.PARTSITE_SCOPE, newPart.getSite()); + commandService.refreshElements(PIN_SELECTION_COMMAND, filter); + + } catch (Exception e) { + ExceptionUtils.logAndShowError(e); + } + + return null; + } + +}