1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import javax.swing.JComboBox; |
13 | |
import javax.swing.JComponent; |
14 | |
import javax.swing.JLabel; |
15 | |
import javax.swing.JPanel; |
16 | |
import javax.swing.JScrollPane; |
17 | |
import javax.swing.JTable; |
18 | |
import javax.swing.ListSelectionModel; |
19 | |
import javax.swing.border.BevelBorder; |
20 | |
|
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.observablecollections.ObservableList; |
27 | |
import org.jdesktop.swingbinding.SwingBindings; |
28 | |
|
29 | |
import bibliothek.gui.dock.common.CLocation; |
30 | |
|
31 | |
import com.jgoodies.forms.layout.CellConstraints; |
32 | |
import com.jgoodies.forms.layout.FormLayout; |
33 | |
|
34 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
35 | |
import org.openpermis.editor.policy.gui.checklist.CheckList; |
36 | |
import org.openpermis.editor.policy.gui.component.TimeStampPicker; |
37 | |
import org.openpermis.editor.policy.presenter.DecisionPresenter; |
38 | |
import org.openpermis.editor.policy.presenter.PolicyContext; |
39 | |
import org.openpermis.policy.Role; |
40 | |
import org.openpermis.policy.bean.PartBean; |
41 | |
import org.openpermis.policy.bean.PolicyBean; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | 0 | public class DecisionTool |
49 | |
extends AbstractToolView<DecisionPresenter> |
50 | |
{ |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 0 | private static final CLocation DEFAULT_LOCATION = CLocation.base().normalEast(0.33); |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
private JComboBox authorityList; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
private JComboBox resourceDomainList; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
private JComboBox actionList; |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
private CheckList<Role> roleList; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
private TimeStampPicker timeStampPicker; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
private JLabel decisionLabel; |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
private JPanel decisionPanel; |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
private JTable parameterTable; |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public DecisionTool (ApplicationContext context, AdapterTrader trader) { |
110 | 0 | super(context, trader); |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
private void bindPresenterProperties (DecisionPresenter presenter, BindingGroup bindings) { |
119 | 0 | bindComboBox( |
120 | |
bindings, |
121 | |
this.authorityList, |
122 | |
presenter, |
123 | |
"authority", |
124 | |
presenter.getAuthorityPool().getPoolList() |
125 | |
); |
126 | |
|
127 | 0 | bindComboBox( |
128 | |
bindings, |
129 | |
this.resourceDomainList, |
130 | |
presenter, |
131 | |
"resourceDomain", |
132 | |
presenter.getResourceDomainPool().getPoolList() |
133 | |
); |
134 | |
|
135 | 0 | bindComboBox( |
136 | |
bindings, |
137 | |
this.actionList, |
138 | |
presenter, |
139 | |
"action", |
140 | |
presenter.getActionPool().getPoolList() |
141 | |
); |
142 | |
|
143 | 0 | this.roleList.bind(presenter.getRolePool().getPoolList(), presenter.getSelectedRoles()); |
144 | |
|
145 | 0 | bindings.addBinding( |
146 | |
Bindings.createAutoBinding( |
147 | |
UpdateStrategy.READ_WRITE, |
148 | |
presenter, |
149 | |
BeanProperty.create("evaluationTimeStamp"), |
150 | |
this.timeStampPicker, |
151 | |
BeanProperty.create("timeStamp") |
152 | |
) |
153 | |
); |
154 | |
|
155 | 0 | bindings.addBinding( |
156 | |
Bindings.createAutoBinding( |
157 | |
UpdateStrategy.READ, |
158 | |
presenter, |
159 | |
BeanProperty.create("decisionText"), |
160 | |
this.decisionLabel, |
161 | |
BeanProperty.create("text") |
162 | |
) |
163 | |
); |
164 | 0 | bindings.addBinding( |
165 | |
Bindings.createAutoBinding( |
166 | |
UpdateStrategy.READ, |
167 | |
presenter, |
168 | |
BeanProperty.create("decisionColor"), |
169 | |
this.decisionPanel, |
170 | |
BeanProperty.create("background") |
171 | |
) |
172 | |
); |
173 | 0 | this.parameterTable.setModel(presenter.getParameterTableModel()); |
174 | 0 | } |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
private void bindComboBox ( |
180 | |
BindingGroup bindings, |
181 | |
JComboBox comboBox, |
182 | |
DecisionPresenter presenter, |
183 | |
String presenterProperty, |
184 | |
ObservableList<? extends PartBean> beanList |
185 | |
) { |
186 | 0 | bindings.addBinding( |
187 | |
SwingBindings.createJComboBoxBinding(UpdateStrategy.READ, beanList, comboBox) |
188 | |
); |
189 | 0 | bindings.addBinding( |
190 | |
Bindings.createAutoBinding( |
191 | |
UpdateStrategy.READ_WRITE, |
192 | |
presenter, |
193 | |
BeanProperty.create(presenterProperty), |
194 | |
comboBox, |
195 | |
BeanProperty.create("selectedItem") |
196 | |
) |
197 | |
); |
198 | 0 | } |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
private CheckList<Role> createRoleList () { |
204 | 0 | final CheckList<Role> checkList = new CheckList<Role>(); |
205 | 0 | checkList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
206 | 0 | checkList.setVisibleRowCount(5); |
207 | 0 | return checkList; |
208 | |
} |
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
private JPanel createDecisionPane (JLabel label) { |
214 | 0 | final JPanel panel = new JPanel(); |
215 | 0 | panel.setBorder(new BevelBorder(BevelBorder.LOWERED)); |
216 | 0 | panel.add(label); |
217 | 0 | return panel; |
218 | |
} |
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public void refresh (PolicyBean policy, PolicyContext context) { |
226 | 0 | setPresenter(policy != null ? new DecisionPresenter(policy, context) : null); |
227 | 0 | } |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
@Override |
233 | |
protected void attachPresenter (DecisionPresenter presenter, BindingGroup bindings) { |
234 | 0 | super.attachPresenter(presenter, bindings); |
235 | 0 | bindPresenterProperties(presenter, bindings); |
236 | 0 | } |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
@Override |
244 | |
protected JComponent createContentPane () { |
245 | 0 | final FormLayout layout = new FormLayout( |
246 | |
"pref, $lcgap, fill:min(100dlu;pref):grow", |
247 | |
"pref, $rgap, pref, $rgap, pref, pref, $rgap, pref, $rgap, pref, $ugap, pref" |
248 | |
); |
249 | 0 | final JPanel panel = new JPanel(layout); |
250 | 0 | final CellConstraints cc = new CellConstraints(); |
251 | |
|
252 | 0 | panel.add(label("authority"), cc.xy(1, 1)); |
253 | 0 | this.authorityList = new JComboBox(); |
254 | 0 | panel.add(this.authorityList, cc.xy(3, 1)); |
255 | |
|
256 | 0 | panel.add(label("resource"), cc.xy(1, 3)); |
257 | 0 | this.resourceDomainList = new JComboBox(); |
258 | 0 | panel.add(this.resourceDomainList, cc.xy(3, 3)); |
259 | |
|
260 | 0 | panel.add(label("action"), cc.xy(1, 5)); |
261 | 0 | this.actionList = new JComboBox(); |
262 | 0 | panel.add(this.actionList, cc.xy(3, 5)); |
263 | 0 | this.parameterTable = new JTable(); |
264 | 0 | panel.add(this.parameterTable, cc.xy(3, 6)); |
265 | |
|
266 | 0 | panel.add(label("roles"), cc.xy(1, 8)); |
267 | 0 | this.roleList = createRoleList(); |
268 | 0 | panel.add(new JScrollPane(this.roleList), cc.xy(3, 8)); |
269 | |
|
270 | 0 | panel.add(label("evaluationTime"), cc.xy(1, 10)); |
271 | 0 | this.timeStampPicker = new TimeStampPicker(); |
272 | 0 | panel.add(this.timeStampPicker, cc.xy(3, 10)); |
273 | |
|
274 | 0 | panel.add(label("decision"), cc.xy(1, 12)); |
275 | 0 | this.decisionLabel = new JLabel(" "); |
276 | 0 | this.decisionPanel = createDecisionPane(this.decisionLabel); |
277 | 0 | panel.add(this.decisionPanel, cc.xy(3, 12)); |
278 | |
|
279 | 0 | return new JScrollPane(panel); |
280 | |
} |
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
@Override |
286 | |
public CLocation getDefaultLocation () { |
287 | 0 | return DEFAULT_LOCATION; |
288 | |
} |
289 | |
|
290 | |
} |