svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / actioninfo / impl / DefaultActionInfoStatusCache.java @ 41748
History | View | Annotate | Download (3.97 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.andami.actioninfo.impl; |
25 |
|
26 |
import java.util.HashMap; |
27 |
import java.util.Map; |
28 |
|
29 |
import org.gvsig.andami.actioninfo.ActionInfo; |
30 |
import org.gvsig.andami.actioninfo.ActionInfoStatusCache; |
31 |
import org.gvsig.andami.plugins.ExtensionHelper; |
32 |
import org.gvsig.andami.plugins.IExtension; |
33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.identitymanagement.SimpleIdentity; |
35 |
import org.gvsig.tools.identitymanagement.SimpleIdentityManager; |
36 |
|
37 |
public class DefaultActionInfoStatusCache implements ActionInfoStatusCache { |
38 |
|
39 |
private SimpleIdentityManager identityManager;
|
40 |
|
41 |
private class Status { |
42 |
Boolean isEnabled = null; |
43 |
Boolean isVisible = null; |
44 |
} |
45 |
|
46 |
private Map<IExtension,Status> extensions = null; |
47 |
private Map<ActionInfo,Status> actions = null; |
48 |
|
49 |
public DefaultActionInfoStatusCache() {
|
50 |
this.clear();
|
51 |
} |
52 |
|
53 |
public void clear() { |
54 |
extensions = new HashMap<IExtension, Status>(); |
55 |
actions = new HashMap<ActionInfo, Status>(); |
56 |
} |
57 |
|
58 |
private SimpleIdentityManager getIdentityManager() {
|
59 |
if( this.identityManager == null ) { |
60 |
this.identityManager = ToolsLocator.getIdentityManager();
|
61 |
} |
62 |
return this.identityManager; |
63 |
} |
64 |
|
65 |
private SimpleIdentity getCurrentUser() {
|
66 |
return this.getIdentityManager().getCurrentIdentity(); |
67 |
} |
68 |
|
69 |
public boolean isEnabled(ActionInfo action) { |
70 |
if( !this.getCurrentUser().isAuthorized(action.getName()) ) { |
71 |
return false; |
72 |
} |
73 |
Status status; |
74 |
IExtension extension = action.getExtension(); |
75 |
if( extension == null ) { |
76 |
return false; |
77 |
} |
78 |
if( ExtensionHelper.canQueryByAction(extension) ) {
|
79 |
status = actions.get(action); |
80 |
if( status == null ) { |
81 |
status = new Status();
|
82 |
actions.put(action, status); |
83 |
} |
84 |
if( status.isEnabled == null ) { |
85 |
status.isEnabled = new Boolean( action.isEnabled() ); |
86 |
} |
87 |
} else {
|
88 |
status = extensions.get(extension); |
89 |
if( status == null ) { |
90 |
status = new Status();
|
91 |
extensions.put(extension, status); |
92 |
} |
93 |
if( status.isEnabled == null ) { |
94 |
status.isEnabled = new Boolean( extension.isEnabled() ); |
95 |
} |
96 |
} |
97 |
return status.isEnabled.booleanValue();
|
98 |
} |
99 |
|
100 |
public boolean isVisible(ActionInfo action) { |
101 |
if( !this.getCurrentUser().isAuthorized(action.getName()) ) { |
102 |
return false; |
103 |
} |
104 |
Status status; |
105 |
IExtension extension = action.getExtension(); |
106 |
if( extension == null ) { |
107 |
return false; |
108 |
} |
109 |
if( ExtensionHelper.canQueryByAction(extension) ) {
|
110 |
status = actions.get(action); |
111 |
if( status == null ) { |
112 |
status = new Status();
|
113 |
actions.put(action, status); |
114 |
} |
115 |
if( status.isVisible == null ) { |
116 |
status.isVisible = new Boolean( action.isVisible() ); |
117 |
} |
118 |
} else {
|
119 |
status = extensions.get(extension); |
120 |
if( status == null ) { |
121 |
status = new Status();
|
122 |
extensions.put(extension, status); |
123 |
} |
124 |
if( status.isVisible == null ) { |
125 |
status.isVisible = new Boolean( extension.isVisible() ); |
126 |
} |
127 |
} |
128 |
return status.isVisible.booleanValue();
|
129 |
} |
130 |
|
131 |
} |