]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/RenameNodeHandler.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / handlers / RenameNodeHandler.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.modeling.ui.modelBrowser.handlers;\r
13 \r
14 import org.eclipse.core.commands.AbstractHandler;\r
15 import org.eclipse.core.commands.ExecutionEvent;\r
16 import org.eclipse.core.commands.ExecutionException;\r
17 import org.eclipse.jface.action.IStatusLineManager;\r
18 import org.eclipse.jface.viewers.ISelection;\r
19 import org.eclipse.ui.IActionBars;\r
20 import org.eclipse.ui.IWorkbenchPart;\r
21 import org.eclipse.ui.handlers.HandlerUtil;\r
22 import org.simantics.browsing.ui.GraphExplorer;\r
23 import org.simantics.browsing.ui.NodeContext;\r
24 import org.simantics.browsing.ui.common.ColumnKeys;\r
25 import org.simantics.utils.ui.ISelectionUtils;\r
26 import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
27 \r
28 public class RenameNodeHandler extends AbstractHandler {\r
29 \r
30     @Override\r
31     public Object execute(ExecutionEvent event) throws ExecutionException {\r
32         ISelection sel = HandlerUtil.getCurrentSelection(event);\r
33         NodeContext ctx = ISelectionUtils.filterSingleSelection(sel, NodeContext.class);\r
34         if (ctx == null)\r
35             return null;\r
36 \r
37         IWorkbenchPart part = HandlerUtil.getActivePart(event);\r
38         if (part == null)\r
39             return null;\r
40 \r
41         IActionBars bars = WorkbenchUtils.getActionBars(part);\r
42         IStatusLineManager status = bars.getStatusLineManager();\r
43 \r
44         GraphExplorer graphExplorer = (GraphExplorer) part.getAdapter(GraphExplorer.class);\r
45         if (graphExplorer != null) {\r
46                 String error = graphExplorer.startEditing(ctx, ColumnKeys.SINGLE); \r
47             if (error != null) {\r
48                 status.setErrorMessage(error);\r
49             } else {\r
50                 status.setErrorMessage(null);\r
51             }\r
52         }\r
53 \r
54         return null;\r
55     }\r
56 \r
57 \r
58 }\r