1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.modeling.ui.actions;
\r
14 import java.util.HashMap;
\r
15 import java.util.Map;
\r
16 import java.util.UUID;
\r
18 import org.eclipse.core.commands.AbstractHandler;
\r
19 import org.eclipse.core.commands.ExecutionEvent;
\r
20 import org.eclipse.core.commands.ExecutionException;
\r
21 import org.eclipse.jface.viewers.ISelection;
\r
22 import org.eclipse.ui.IWorkbenchPart;
\r
23 import org.eclipse.ui.commands.ICommandService;
\r
24 import org.eclipse.ui.handlers.HandlerUtil;
\r
25 import org.eclipse.ui.services.IServiceScopes;
\r
26 import org.simantics.browsing.ui.platform.PropertyPageView;
\r
27 import org.simantics.utils.ui.ExceptionUtils;
\r
28 import org.simantics.utils.ui.workbench.WorkbenchUtils;
\r
31 * @author Tuukka Lehtonen
\r
33 public class DuplicatePinnedViewHandler extends AbstractHandler {
\r
35 private static final String PIN_SELECTION_COMMAND = "org.simantics.modeling.ui.pinSelection";
\r
38 public Object execute(ExecutionEvent event) throws ExecutionException {
\r
39 IWorkbenchPart originalPart = HandlerUtil.getActivePartChecked(event);
\r
40 if (!(originalPart instanceof PropertyPageView))
\r
42 PropertyPageView originalPropertyView = (PropertyPageView) originalPart;
\r
45 // Activate a new unique instance of the same property page view.
\r
46 // Its initialization procedures and IContributedContentsView
\r
47 // implementation should take care that the view will be initialized
\r
48 // with a property page just like the original.
\r
49 ISelection originalSelection = originalPropertyView.getLastSelection();
\r
51 final String id = originalPart.getSite().getId() + "Pinned:" + UUID.randomUUID().toString();
\r
52 PropertyPageView newPart = (PropertyPageView) WorkbenchUtils.activateView(id);
\r
54 newPart.partActivated(originalPart);
\r
55 newPart.selectionChanged(originalPart, originalSelection);
\r
57 // Make sure that the view is pinned and that its pinned button is in the right state.
\r
58 newPart.pinWorkbenchSelection(true);
\r
60 ICommandService commandService = (ICommandService) newPart.getViewSite().getService(ICommandService.class);
\r
61 Map<Object, Object> filter = new HashMap<Object, Object>();
\r
62 filter.put(IServiceScopes.PARTSITE_SCOPE, newPart.getSite());
\r
63 commandService.refreshElements(PIN_SELECTION_COMMAND, filter);
\r
65 } catch (Exception e) {
\r
66 ExceptionUtils.logAndShowError(e);
\r