]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph.ui/src/org/simantics/scenegraph/ui/LinkToActiveWorkbenchPartHandler.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scenegraph.ui / src / org / simantics / scenegraph / ui / LinkToActiveWorkbenchPartHandler.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.scenegraph.ui;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.Command;
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.commands.State;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.commands.ICommandService;
22 import org.eclipse.ui.handlers.HandlerUtil;
23
24 /**
25  * @author Tuukka Lehtonen
26  */
27 public class LinkToActiveWorkbenchPartHandler extends AbstractHandler {
28
29     static final String COMMAND = "org.simantics.scenegraph.linkToActiveWorkbenchPart";
30     static final String STATE   = "org.simantics.scenegraph.linkToActiveWorkbenchPart.state";
31
32     @Override
33     public Object execute(ExecutionEvent event) throws ExecutionException {
34         IWorkbenchPart part = HandlerUtil.getActivePart(event);
35         if (part == null || !(part instanceof SceneGraphViewPart))
36             return null;
37         SceneGraphViewPart sg = (SceneGraphViewPart) part;
38
39         ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
40         Command command = service.getCommand(COMMAND);
41         State state = command.getState(STATE);
42         Boolean value = (Boolean) state.getValue();
43         value = !value;
44         state.setValue(value);
45
46         sg.linkToActiveWorkbenchPart(value);
47
48         return null;
49     }
50
51 }