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