blob: 4531ebb3b0193e1ccd232109a58d0099997db435 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*****************************************************************************
* Copyright (c) 2009 Atos Origin.
*
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.navigator.factory;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.navigator.actions.RenameNamedElementAction;
import org.eclipse.papyrus.navigator.internal.Activator;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.navigator.CommonNavigator;
/**
* The Class RenameActionFactory for creating a rename action for named element
*
* @author Emilien Perico
*/
public class RenameActionFactory implements IActionHandlerFactory {
protected List<Action> actions = new LinkedList<Action>();
protected RenameNamedElementAction renameNamedElementAction;
/**
* {@inheritDoc}
*/
public List<Action> createActions(EditingDomain editingDomain) {
// Rename NamedElement action
// fjcano #290514 :: command to rename elements in the model explorer
this.renameNamedElementAction = new RenameNamedElementAction(editingDomain);
this.renameNamedElementAction.setImageDescriptor(Activator.getImageDescriptor("icons/etool16/rename.gif"));
actions.add(renameNamedElementAction);
return actions;
}
/**
* {@inheritDoc}
*/
public void activate(CommonNavigator activeViewPart) {
this.renameNamedElementAction.setActiveWorkbenchPart(activeViewPart);
ISelectionProvider selectionProvider = null;
if(activeViewPart.getCommonViewer() instanceof ISelectionProvider) {
selectionProvider = activeViewPart.getCommonViewer();
selectionProvider.addSelectionChangedListener(renameNamedElementAction);
}
}
/**
* {@inheritDoc}
*/
public void deactivate(CommonNavigator activeViewPart) {
this.renameNamedElementAction.setActiveWorkbenchPart(null);
ISelectionProvider selectionProvider = null;
if(activeViewPart.getCommonViewer() instanceof ISelectionProvider) {
selectionProvider = activeViewPart.getCommonViewer();
selectionProvider.removeSelectionChangedListener(renameNamedElementAction);
}
}
/**
* {@inheritDoc}
*/
public void fillActionBars(IActionBars actionBars) {
actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameNamedElementAction);
}
/**
* {@inheritDoc}
*/
public void update(IStructuredSelection structuredSelection) {
this.renameNamedElementAction.updateSelection(structuredSelection);
}
/**
* {@inheritDoc}
*/
public List<Action> getActions() {
return actions;
}
}
|