1 package cz
.cvut
.promod
.services
.actionService
;
3 import cz
.cvut
.promod
.gui
.ModelerModel
;
4 import cz
.cvut
.promod
.services
.actionService
.actionUtils
.ProModAction
;
5 import org
.apache
.log4j
.Logger
;
8 import java
.util
.HashMap
;
12 * ProMod, master thesis project
13 * User: Petr Zverina, petr.zverina@gmail.com
14 * Date: 17:48:55, 10.10.2009
18 * ActionControlService implementation.
20 public class ActionControlServiceImpl
implements ActionControlService
{
22 private final Logger LOG
= Logger
.getLogger(ActionControlServiceImpl
.class);
24 private final Map
<String
, NotationSpecificActions
> notationSpecificActionsMap
;
26 public ActionControlServiceImpl(){
27 notationSpecificActionsMap
= new HashMap
<String
, NotationSpecificActions
>();
31 public boolean check() {
36 public ProModAction
getAction(final String notationIdentifier
,
37 final String moduleIdentifier
,
38 final String actionIdentifier
){
40 if(notationIdentifier
== null || actionIdentifier
== null){
44 if(notationSpecificActionsMap
.containsKey(notationIdentifier
)){
45 final NotationSpecificActions notationSpecificActions
= notationSpecificActionsMap
.get(notationIdentifier
);
47 if(moduleIdentifier
== null){
48 return notationSpecificActions
.getAction(actionIdentifier
);
50 return notationSpecificActions
.getAction(moduleIdentifier
, actionIdentifier
);
57 public ProModAction
getAction(final String notationIdentifier
, final String actionIdentifier
) {
58 return getAction(notationIdentifier
, null, actionIdentifier
);
62 public ProModAction
registerAction(final String notationIdentifier
,
63 final String moduleIdentifier
,
64 final String actionIdentifier
,
65 final ProModAction action
){
67 if(notationIdentifier
== null || actionIdentifier
== null){
68 LOG
.error("Action registration failed due to nullary info," +
69 " actionIdentifier: " + actionIdentifier
+
70 ", notationIdentifier: " + notationIdentifier
+
71 ", moduleIdentifier: " + moduleIdentifier
+ ".");
76 final ProModAction proModAction
= getAction(notationIdentifier
, moduleIdentifier
, actionIdentifier
);
78 if(proModAction
!= null){
83 LOG
.error("Nullary action is not possible to register.");
87 if(!isUniqueKeyAccelerator(notationIdentifier
, (KeyStroke
) action
.getValue(AbstractAction
.ACCELERATOR_KEY
))){
88 LOG
.error("Duplicity in action's 'ACCELERATOR KEY'," +
89 " action: " + actionIdentifier
+
90 " notation: " + notationIdentifier
+
91 " module: " + moduleIdentifier
);
92 action
.putValue(AbstractAction
.ACCELERATOR_KEY
, null);
100 setAction(notationIdentifier
, moduleIdentifier
, actionIdentifier
, action
);
102 LOG
.debug("New Action (" + actionIdentifier
+ ") has been added.");
109 * Tests whether there is no other already registered action with the same accelerator key definition. This
110 * test is done only by the 'modeler' action and actions of the same notation.
112 * @param notationIdentifier is the notation where to perform the test
113 * @param keyStroke is the accelerator key to be tested @return true if there is no such a action, false otherwise
114 * @return true if the accelerator key is unique, false otherwise
116 private boolean isUniqueKeyAccelerator(final String notationIdentifier
, final KeyStroke keyStroke
) {
118 NotationSpecificActions notationSpecificActions
= notationSpecificActionsMap
.get(notationIdentifier
);
119 if(notationSpecificActions
!= null){
120 if(notationSpecificActions
.existAcceleratorKey(keyStroke
)){
125 notationSpecificActions
= notationSpecificActionsMap
.get(ModelerModel
.MODELER_IDENTIFIER
);
126 if(notationSpecificActions
!= null){
127 if(notationSpecificActions
.existAcceleratorKey(keyStroke
)){
139 public ProModAction
registerAction(final String notationIdentifier
,
140 final String actionIdentifier
,
141 final ProModAction action
) {
143 return registerAction(
154 * @param notationIdentifier is the notation identifier
155 * @param moduleIdentifier os the module identifier
156 * @param actionIdentifier is the action identifier
157 * @param newProModAction is the action
159 private void setAction(final String notationIdentifier
,
160 final String moduleIdentifier
,
161 final String actionIdentifier
,
162 final ProModAction newProModAction
){
163 if(notationIdentifier
== null || actionIdentifier
== null){
167 if(notationSpecificActionsMap
.containsKey(notationIdentifier
)){
168 notationSpecificActionsMap
.get(notationIdentifier
).setAction(moduleIdentifier
, actionIdentifier
, newProModAction
);
170 final NotationSpecificActions notationSpecificActions
= new NotationSpecificActions();
171 notationSpecificActions
.setAction(moduleIdentifier
, actionIdentifier
, newProModAction
);
172 notationSpecificActionsMap
.put(notationIdentifier
, notationSpecificActions
);
178 public void updateActionsVisibility(final String newNotationIdentifier
) {
179 for(final NotationSpecificActions notationSpecificActions
: notationSpecificActionsMap
.values()){
180 notationSpecificActions
.updateActionVisibility(newNotationIdentifier
);
185 public boolean isRegisteredAction(final ProModAction action
) {
186 for(final NotationSpecificActions notationSpecificActions
: notationSpecificActionsMap
.values()){
187 if(notationSpecificActions
.existAction(action
)){