1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import java.beans.PropertyChangeEvent; |
13 | |
import java.beans.PropertyChangeListener; |
14 | |
import java.net.URI; |
15 | |
|
16 | |
import javax.swing.JComponent; |
17 | |
import javax.swing.JList; |
18 | |
import javax.swing.JOptionPane; |
19 | |
import javax.swing.JScrollPane; |
20 | |
|
21 | |
import org.jdesktop.application.Action; |
22 | |
import org.jdesktop.application.ApplicationContext; |
23 | |
import org.jdesktop.beansbinding.BeanProperty; |
24 | |
import org.jdesktop.beansbinding.BindingGroup; |
25 | |
import org.jdesktop.beansbinding.Bindings; |
26 | |
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy; |
27 | |
import org.jdesktop.swingbinding.SwingBindings; |
28 | |
import org.slf4j.Logger; |
29 | |
import org.slf4j.LoggerFactory; |
30 | |
|
31 | |
import bibliothek.gui.dock.common.CLocation; |
32 | |
|
33 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
34 | |
import org.openpermis.editor.policy.adapter.overview.Overview; |
35 | |
import org.openpermis.editor.policy.gui.DoubleClickForwarder; |
36 | |
import org.openpermis.editor.policy.presenter.PolicyContext; |
37 | |
import org.openpermis.editor.policy.presenter.RoleHierarchyListPresenter; |
38 | |
import org.openpermis.editor.policy.renderer.RendererFactory; |
39 | |
import org.openpermis.policy.bean.PolicyBean; |
40 | |
import org.openpermis.policy.bean.RoleHierarchyBean; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class RoleHierarchyListTool |
47 | |
extends AbstractToolView<RoleHierarchyListPresenter> |
48 | |
implements PropertyChangeListener |
49 | |
{ |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 0 | private static final Logger LOGGER = |
58 | |
LoggerFactory.getLogger(RoleHierarchyListTool.class); |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | private static final CLocation DEFAULT_ROLE_HIERARCHY_LIST_LOCATION = |
65 | |
DEFAULT_LOCATION.south(0.6); |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
private JList list; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public RoleHierarchyListTool (ApplicationContext context, AdapterTrader trader) { |
83 | 0 | super(context, trader); |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
@Action |
93 | |
public void addHierarchy () { |
94 | 0 | if (this.getPresenter() == null) { |
95 | 0 | return; |
96 | |
} |
97 | 0 | LOGGER.debug("addHierarchy"); |
98 | |
|
99 | 0 | String identifier = (String) JOptionPane.showInputDialog( |
100 | |
null, |
101 | |
getResourceMap().getString("addHierarchy.Dialog.text"), |
102 | |
getResourceMap().getString("addHierarchy.Dialog.title"), |
103 | |
JOptionPane.PLAIN_MESSAGE, |
104 | |
null, |
105 | |
null, |
106 | |
"" |
107 | |
); |
108 | |
|
109 | |
|
110 | |
URI uri; |
111 | |
try { |
112 | 0 | uri = URI.create(identifier); |
113 | 0 | } catch (Exception e) { |
114 | 0 | uri = null; |
115 | 0 | } |
116 | 0 | if (uri != null) { |
117 | 0 | this.getPresenter().addRoleHierarchy(uri); |
118 | |
} |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
@Action |
126 | |
public void removeHierarchy () { |
127 | 0 | if (this.getPresenter() == null) { |
128 | 0 | return; |
129 | |
} |
130 | 0 | LOGGER.debug("removeHierarchy"); |
131 | 0 | final RoleHierarchyBean roleHierarchy = this.getPresenter().getActive(); |
132 | 0 | if (roleHierarchy != null) { |
133 | 0 | this.getPresenter().removeRoleHierarchy(roleHierarchy); |
134 | |
} |
135 | 0 | } |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
@Action |
142 | |
public void editHierarchy () { |
143 | 0 | if (this.getPresenter() == null) { |
144 | 0 | return; |
145 | |
} |
146 | 0 | final RoleHierarchyBean roleHierarchy = this.getPresenter().getActive(); |
147 | 0 | if (roleHierarchy != null) { |
148 | 0 | editPart(roleHierarchy); |
149 | |
} |
150 | 0 | } |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public void refresh (PolicyBean policy, PolicyContext context) { |
158 | 0 | if (policy == null) { |
159 | 0 | setPresenter(null); |
160 | |
} else { |
161 | 0 | setPresenter(new RoleHierarchyListPresenter(policy, context)); |
162 | |
} |
163 | 0 | } |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
@Override |
171 | |
protected void updateActions () { |
172 | 0 | super.updateActions(); |
173 | 0 | final boolean hasPresenter = this.getPresenter() != null; |
174 | 0 | final boolean hasActive = hasPresenter && this.getPresenter().getActive() != null; |
175 | 0 | getActionMap().get("addHierarchy").setEnabled(hasPresenter); |
176 | 0 | getActionMap().get("removeHierarchy").setEnabled(hasActive); |
177 | 0 | getActionMap().get("editHierarchy").setEnabled(hasActive); |
178 | 0 | } |
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
@Override |
184 | |
protected void detachPresenter (RoleHierarchyListPresenter presenter) { |
185 | 0 | super.detachPresenter(presenter); |
186 | 0 | presenter.removePropertyChangeListener(this); |
187 | 0 | } |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
@Override |
193 | |
protected void attachPresenter ( |
194 | |
RoleHierarchyListPresenter presenter, BindingGroup bindings |
195 | |
) { |
196 | 0 | super.attachPresenter(presenter, bindings); |
197 | 0 | presenter.addPropertyChangeListener(this); |
198 | 0 | bindings.addBinding( |
199 | |
SwingBindings.createJListBinding( |
200 | |
UpdateStrategy.READ, |
201 | |
this.getPresenter().getRoleHierarchies(), |
202 | |
this.list |
203 | |
) |
204 | |
); |
205 | 0 | bindings.addBinding( |
206 | |
Bindings.createAutoBinding( |
207 | |
UpdateStrategy.READ_WRITE, |
208 | |
this.getPresenter(), |
209 | |
BeanProperty.create("active"), |
210 | |
this.list, |
211 | |
BeanProperty.create("selectedElement") |
212 | |
) |
213 | |
); |
214 | 0 | } |
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
@Override |
220 | |
public CLocation getDefaultLocation () { |
221 | 0 | return DEFAULT_ROLE_HIERARCHY_LIST_LOCATION; |
222 | |
} |
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
@Override |
230 | |
public JComponent createContentPane () { |
231 | 0 | this.list = new JList(new Object[0]); |
232 | 0 | this.list.setCellRenderer( |
233 | |
RendererFactory.createListCellRenderer(this.getAdapteeTrader(), Overview.class) |
234 | |
); |
235 | 0 | DoubleClickForwarder.register(this.list, getActionMap().get("editHierarchy")); |
236 | 0 | return new JScrollPane(this.list); |
237 | |
} |
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
public void propertyChange (PropertyChangeEvent event) { |
245 | 0 | updateActions(); |
246 | 0 | } |
247 | |
|
248 | |
} |