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