]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/PinSelectionHandler.java
(refs #7561) Allow extra parameters to the application of type alias
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / actions / PinSelectionHandler.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.actions;
13
14 import java.util.Map;
15
16 import org.eclipse.core.commands.AbstractHandler;
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.ui.IWorkbenchPartSite;
21 import org.eclipse.ui.commands.IElementUpdater;
22 import org.eclipse.ui.handlers.HandlerUtil;
23 import org.eclipse.ui.menus.UIElement;
24 import org.eclipse.ui.services.IServiceScopes;
25 import org.simantics.browsing.ui.platform.PropertyPageView;
26
27 public class PinSelectionHandler extends AbstractHandler implements IElementUpdater {
28
29     @Override
30     public Object execute(ExecutionEvent event) throws ExecutionException {
31         IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
32         if (!(part instanceof PropertyPageView))
33             return null;
34
35         PropertyPageView ppv = (PropertyPageView) part;
36         ppv.pinWorkbenchSelection(!ppv.isWorkbenchSelectionPinned());
37
38         return null;
39     }
40
41     @SuppressWarnings("rawtypes")
42     @Override
43     public void updateElement(UIElement element, Map parameters) {
44         IWorkbenchPartSite site = (IWorkbenchPartSite) parameters.get(IServiceScopes.PARTSITE_SCOPE);
45         if (site != null) {
46             IWorkbenchPart part = site.getPart();
47             if (part instanceof PropertyPageView) {
48                 PropertyPageView ppv = (PropertyPageView) part;
49                 element.setChecked(ppv.isWorkbenchSelectionPinned());
50             }
51         }
52     }
53
54 }