svn-gvsig-desktop / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / andami / actioninfo / impl / DefaultActionInfoStatusCache.java @ 39070
History | View | Annotate | Download (2.17 KB)
1 |
package org.gvsig.andami.actioninfo.impl; |
---|---|
2 |
|
3 |
import java.util.HashMap; |
4 |
import java.util.Map; |
5 |
|
6 |
import org.gvsig.andami.actioninfo.ActionInfo; |
7 |
import org.gvsig.andami.actioninfo.ActionInfoStatusCache; |
8 |
import org.gvsig.andami.plugins.ExtensionHelper; |
9 |
import org.gvsig.andami.plugins.IExtension; |
10 |
|
11 |
public class DefaultActionInfoStatusCache implements ActionInfoStatusCache { |
12 |
|
13 |
private class Status { |
14 |
Boolean isEnabled = null; |
15 |
Boolean isVisible = null; |
16 |
} |
17 |
|
18 |
private Map<IExtension,Status> extensions = null; |
19 |
private Map<ActionInfo,Status> actions = null; |
20 |
|
21 |
public DefaultActionInfoStatusCache() {
|
22 |
this.clear();
|
23 |
} |
24 |
|
25 |
public void clear() { |
26 |
extensions = new HashMap<IExtension, Status>(); |
27 |
actions = new HashMap<ActionInfo, Status>(); |
28 |
} |
29 |
|
30 |
|
31 |
public boolean isEnabled(ActionInfo action) { |
32 |
Status status; |
33 |
IExtension extension = action.getExtension(); |
34 |
if( extension == null ) { |
35 |
return false; |
36 |
} |
37 |
if( ExtensionHelper.canQueryByAction(extension) ) {
|
38 |
status = actions.get(action); |
39 |
if( status == null ) { |
40 |
status = new Status();
|
41 |
actions.put(action, status); |
42 |
} |
43 |
if( status.isEnabled == null ) { |
44 |
status.isEnabled = new Boolean( action.isEnabled() ); |
45 |
} |
46 |
} else {
|
47 |
status = extensions.get(extension); |
48 |
if( status == null ) { |
49 |
status = new Status();
|
50 |
extensions.put(extension, status); |
51 |
} |
52 |
if( status.isEnabled == null ) { |
53 |
status.isEnabled = new Boolean( extension.isEnabled() ); |
54 |
} |
55 |
} |
56 |
return status.isEnabled.booleanValue();
|
57 |
} |
58 |
|
59 |
public boolean isVisible(ActionInfo action) { |
60 |
Status status; |
61 |
IExtension extension = action.getExtension(); |
62 |
if( extension == null ) { |
63 |
return false; |
64 |
} |
65 |
if( ExtensionHelper.canQueryByAction(extension) ) {
|
66 |
status = actions.get(action); |
67 |
if( status == null ) { |
68 |
status = new Status();
|
69 |
actions.put(action, status); |
70 |
} |
71 |
if( status.isVisible == null ) { |
72 |
status.isVisible = new Boolean( action.isVisible() ); |
73 |
} |
74 |
} else {
|
75 |
status = extensions.get(extension); |
76 |
if( status == null ) { |
77 |
status = new Status();
|
78 |
extensions.put(extension, status); |
79 |
} |
80 |
if( status.isVisible == null ) { |
81 |
status.isVisible = new Boolean( extension.isVisible() ); |
82 |
} |
83 |
} |
84 |
return status.isVisible.booleanValue();
|
85 |
} |
86 |
|
87 |
} |