1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import java.awt.event.ActionEvent; |
13 | |
import java.awt.event.ActionListener; |
14 | |
import java.util.Calendar; |
15 | |
import java.util.Date; |
16 | |
import java.util.List; |
17 | |
import java.util.TimeZone; |
18 | |
|
19 | |
import javax.swing.JButton; |
20 | |
import javax.swing.JCheckBox; |
21 | |
import javax.swing.JComboBox; |
22 | |
import javax.swing.JComponent; |
23 | |
import javax.swing.JLabel; |
24 | |
import javax.swing.JOptionPane; |
25 | |
import javax.swing.JPanel; |
26 | |
import javax.swing.JScrollPane; |
27 | |
|
28 | |
import org.jdesktop.application.Action; |
29 | |
import org.jdesktop.application.ApplicationContext; |
30 | |
import org.jdesktop.beansbinding.BeanProperty; |
31 | |
import org.jdesktop.beansbinding.BindingGroup; |
32 | |
import org.jdesktop.beansbinding.Bindings; |
33 | |
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy; |
34 | |
import org.jdesktop.swingbinding.SwingBindings; |
35 | |
import org.jdesktop.swingx.JXDatePicker; |
36 | |
import org.joda.time.Period; |
37 | |
import org.joda.time.PeriodType; |
38 | |
import org.slf4j.Logger; |
39 | |
import org.slf4j.LoggerFactory; |
40 | |
|
41 | |
import com.jgoodies.forms.layout.CellConstraints; |
42 | |
import com.jgoodies.forms.layout.FormLayout; |
43 | |
|
44 | |
import org.openpermis.basic.AbsoluteTimePeriod; |
45 | |
import org.openpermis.basic.TimePeriod; |
46 | |
import org.openpermis.basic.TimePeriodConstraint; |
47 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
48 | |
import org.openpermis.editor.policy.adapter.overview.Overview; |
49 | |
import org.openpermis.editor.policy.gui.checklist.CheckList; |
50 | |
import org.openpermis.editor.policy.presenter.RoleAssignmentRulePresenter; |
51 | |
import org.openpermis.editor.policy.renderer.RendererFactory; |
52 | |
import org.openpermis.policy.Role; |
53 | |
import org.openpermis.policy.TimeStamp; |
54 | |
import org.openpermis.policy.bean.AuthorityBean; |
55 | |
import org.openpermis.policy.bean.DomainBean; |
56 | |
import org.openpermis.policy.bean.PolicyBean; |
57 | |
import org.openpermis.policy.bean.RoleAssignmentRuleBean; |
58 | |
import org.openpermis.policy.bean.RoleAssignmentRuleBeanCollection; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | public class RoleAssignmentRuleEditor |
65 | |
extends AbstractEditor<RoleAssignmentRulePresenter> |
66 | |
{ |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | private static final Logger LOGGER = |
75 | |
LoggerFactory.getLogger(RoleAssignmentRuleEditor.class); |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
private static final int MILLIS_IN_A_DAY = 24 * 3600 * 1000; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
private JComboBox authority; |
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
private JComboBox subjectDomain; |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
private CheckList<Role> roleList; |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | 0 | private JLabel delegationDepthLabel = new JLabel(); |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | 0 | private JCheckBox absolutePeriodCheckBox = new JCheckBox(); |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | 0 | private JXDatePicker startDatePicker = new JXDatePicker(); |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | 0 | private JXDatePicker endDatePicker = new JXDatePicker(); |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | 0 | private JXDatePicker referenceDatePicker = new JXDatePicker(); |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | 0 | private JCheckBox minimumFromCheckBox = new JCheckBox(); |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | 0 | private JXDatePicker minimumFromDatePicker = new JXDatePicker(); |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | 0 | private int minimumFromDays = 0; |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | 0 | private JCheckBox minimumUpToCheckBox = new JCheckBox(); |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | 0 | private JXDatePicker minimumUpToDatePicker = new JXDatePicker(); |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | 0 | private int minimumUpToDays = 0; |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | 0 | private JCheckBox maximumUpToCheckBox = new JCheckBox(); |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | 0 | private JXDatePicker maximumUpToDatePicker = new JXDatePicker(); |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | 0 | private int maximumUpToDays = 0; |
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | 0 | private TimeStamp defaultZoneTimeStamp = new TimeStamp(new Date(), TimeZone.getDefault()); |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
public RoleAssignmentRuleEditor ( |
187 | |
ApplicationContext context, AdapterTrader trader, RoleAssignmentRulePresenter presenter |
188 | |
) { |
189 | 0 | super(context, trader, presenter); |
190 | 0 | this.delegationDepthLabel.setText(String.valueOf(presenter.getDelegationDepth())); |
191 | 0 | LOGGER.debug("create RoleAssigmentRuleEditor"); |
192 | |
|
193 | 0 | ActionListener listener4CheckBoxes = new ActionListener() { |
194 | 0 | public void actionPerformed (ActionEvent e) { |
195 | 0 | updateConstraintAtModel(); |
196 | 0 | } |
197 | |
}; |
198 | |
|
199 | 0 | Calendar calender = Calendar.getInstance(); |
200 | 0 | calender.set(Calendar.MILLISECOND, 0); |
201 | 0 | calender.set(Calendar.SECOND, 0); |
202 | 0 | calender.set(Calendar.MINUTE, 0); |
203 | 0 | calender.set(Calendar.HOUR_OF_DAY, 0); |
204 | 0 | Date today = calender.getTime(); |
205 | |
|
206 | 0 | this.absolutePeriodCheckBox.addActionListener(listener4CheckBoxes); |
207 | 0 | this.startDatePicker.setDate(today); |
208 | 0 | this.endDatePicker.setDate(today); |
209 | 0 | this.startDatePicker.addActionListener(listener4CheckBoxes); |
210 | 0 | this.endDatePicker.addActionListener(listener4CheckBoxes); |
211 | |
|
212 | 0 | this.referenceDatePicker.setDate(today); |
213 | 0 | this.referenceDatePicker.addActionListener(new ActionListener() { |
214 | 0 | public void actionPerformed (ActionEvent e) { |
215 | 0 | setMinimumValidFromDayNumber(RoleAssignmentRuleEditor.this.minimumFromDays); |
216 | 0 | setMinimumValidUpToDayNumber(RoleAssignmentRuleEditor.this.minimumUpToDays); |
217 | 0 | setMaximumValidUpToDayNumber(RoleAssignmentRuleEditor.this.maximumUpToDays); |
218 | 0 | } |
219 | |
}); |
220 | |
|
221 | 0 | this.minimumFromCheckBox.addActionListener(listener4CheckBoxes); |
222 | 0 | this.minimumFromDatePicker.setDate(today); |
223 | 0 | this.minimumFromDatePicker.addActionListener(new ActionListener() { |
224 | 0 | public void actionPerformed (ActionEvent e) { |
225 | 0 | RoleAssignmentRuleEditor.this.minimumFromDays = extractMinimumFromDays(); |
226 | 0 | } |
227 | |
}); |
228 | 0 | this.minimumFromDatePicker.addActionListener(listener4CheckBoxes); |
229 | |
|
230 | 0 | this.minimumUpToCheckBox.addActionListener(listener4CheckBoxes); |
231 | 0 | this.minimumUpToDatePicker.setDate(today); |
232 | 0 | this.minimumUpToDatePicker.addActionListener(new ActionListener() { |
233 | 0 | public void actionPerformed (ActionEvent e) { |
234 | 0 | RoleAssignmentRuleEditor.this.minimumUpToDays = extractMinimumUpToDays(); |
235 | 0 | } |
236 | |
}); |
237 | 0 | this.minimumUpToDatePicker.addActionListener(listener4CheckBoxes); |
238 | |
|
239 | 0 | this.maximumUpToCheckBox.addActionListener(listener4CheckBoxes); |
240 | 0 | this.maximumUpToDatePicker.setDate(today); |
241 | 0 | this.maximumUpToDatePicker.addActionListener(new ActionListener() { |
242 | 0 | public void actionPerformed (ActionEvent e) { |
243 | 0 | RoleAssignmentRuleEditor.this.maximumUpToDays = extractMaximumUpToDays(); |
244 | 0 | } |
245 | |
}); |
246 | 0 | this.maximumUpToDatePicker.addActionListener(listener4CheckBoxes); |
247 | 0 | } |
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | |
|
255 | |
public void updateConstraintAtModel () { |
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | 0 | TimePeriod absoluteTimePeriod = null; |
262 | 0 | Period minimumValidFrom = null; |
263 | 0 | Period minimumValidUpTo = null; |
264 | 0 | Period maximumValidUpTo = null; |
265 | |
|
266 | 0 | if (this.absolutePeriodCheckBox.isSelected()) { |
267 | 0 | Date startDate = this.startDatePicker.getDate(); |
268 | 0 | Date endDate = this.endDatePicker.getDate(); |
269 | 0 | if (!startDate.before(endDate)) { |
270 | 0 | endDate = new Date(startDate.getTime() + MILLIS_IN_A_DAY); |
271 | |
|
272 | 0 | this.endDatePicker.setDate(endDate); |
273 | |
} |
274 | 0 | absoluteTimePeriod = |
275 | |
new AbsoluteTimePeriod( |
276 | |
startDate, |
277 | |
endDate |
278 | |
); |
279 | |
} |
280 | |
|
281 | 0 | int localMinimumFromDays = extractMinimumFromDays(); |
282 | 0 | int localMinimumUpToDays = extractMinimumUpToDays(); |
283 | 0 | int localMaximumUpToDays = extractMaximumUpToDays(); |
284 | |
|
285 | 0 | if (this.minimumFromCheckBox.isSelected()) { |
286 | 0 | if (localMinimumFromDays > 0) { |
287 | 0 | localMinimumFromDays = 0; |
288 | 0 | this.minimumFromDays = localMinimumFromDays; |
289 | |
|
290 | 0 | setMinimumValidFromDayNumber(this.minimumFromDays); |
291 | |
} |
292 | 0 | minimumValidFrom = new Period( |
293 | |
0, |
294 | |
0, |
295 | |
0, |
296 | |
-localMinimumFromDays, |
297 | |
0, |
298 | |
0, |
299 | |
0, |
300 | |
0 |
301 | |
); |
302 | |
} |
303 | |
|
304 | 0 | if (this.minimumUpToCheckBox.isSelected()) { |
305 | 0 | if ( |
306 | |
localMinimumUpToDays < 0 |
307 | |
) { |
308 | 0 | localMinimumUpToDays = 0; |
309 | 0 | this.minimumUpToDays = 0; |
310 | |
|
311 | 0 | setMinimumValidUpToDayNumber(this.minimumUpToDays); |
312 | |
} |
313 | 0 | minimumValidUpTo = new Period( |
314 | |
0, |
315 | |
0, |
316 | |
0, |
317 | |
localMinimumUpToDays, |
318 | |
0, |
319 | |
0, |
320 | |
0, |
321 | |
0 |
322 | |
); |
323 | |
} |
324 | |
|
325 | |
|
326 | 0 | if (this.maximumUpToCheckBox.isSelected()) { |
327 | 0 | if ( |
328 | |
localMaximumUpToDays < 0 |
329 | |
) { |
330 | 0 | localMaximumUpToDays = 0; |
331 | 0 | this.maximumUpToDays = 0; |
332 | |
|
333 | 0 | setMaximumValidUpToDayNumber(this.maximumUpToDays); |
334 | |
} |
335 | 0 | if ( |
336 | |
this.minimumUpToCheckBox.isSelected() && |
337 | |
localMinimumUpToDays > localMaximumUpToDays |
338 | |
) { |
339 | 0 | localMaximumUpToDays = localMinimumUpToDays; |
340 | 0 | this.maximumUpToDays = localMaximumUpToDays; |
341 | |
|
342 | 0 | setMaximumValidUpToDayNumber(this.maximumUpToDays); |
343 | |
} |
344 | 0 | maximumValidUpTo = new Period( |
345 | |
0, |
346 | |
0, |
347 | |
0, |
348 | |
localMaximumUpToDays, |
349 | |
0, |
350 | |
0, |
351 | |
0, |
352 | |
0 |
353 | |
); |
354 | |
} |
355 | |
|
356 | 0 | getPresenter().updateConstraintAtModel(new TimePeriodConstraint( |
357 | |
absoluteTimePeriod, |
358 | |
minimumValidFrom, |
359 | |
minimumValidUpTo, |
360 | |
maximumValidUpTo |
361 | |
)); |
362 | 0 | } |
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
public void setConstraint (TimePeriodConstraint newConstraint) { |
370 | |
|
371 | 0 | TimePeriod timePeriod = newConstraint.getAbsolutePeriod(); |
372 | |
|
373 | |
|
374 | 0 | if (timePeriod.equals(TimePeriod.INFINITE) || timePeriod.equals(TimePeriod.EMPTY)) { |
375 | 0 | this.absolutePeriodCheckBox.setSelected(false); |
376 | |
} else { |
377 | 0 | AbsoluteTimePeriod absolutePeriod = (AbsoluteTimePeriod) timePeriod; |
378 | 0 | this.startDatePicker.setDate( |
379 | |
absolutePeriod.getStart().toDateTime(this.defaultZoneTimeStamp).toDate() |
380 | |
); |
381 | 0 | this.endDatePicker.setDate( |
382 | |
absolutePeriod.getEnd().toDateTime(this.defaultZoneTimeStamp).toDate() |
383 | |
); |
384 | 0 | this.absolutePeriodCheckBox.setSelected(true); |
385 | |
|
386 | |
} |
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | 0 | Period minimumValidFromPeriod = newConstraint.getMinimumValidFrom(); |
392 | |
|
393 | 0 | if (minimumValidFromPeriod == null) { |
394 | 0 | this.minimumFromCheckBox.setSelected(false); |
395 | |
} else { |
396 | 0 | int daysNumber = |
397 | |
minimumValidFromPeriod. |
398 | |
normalizedStandard(PeriodType.time()). |
399 | |
toStandardDays().getDays(); |
400 | 0 | setMinimumValidFromDayNumber(-daysNumber); |
401 | 0 | this.minimumFromCheckBox.setSelected(true); |
402 | |
} |
403 | |
|
404 | |
|
405 | 0 | Period minimumValidUpToPeriod = newConstraint.getMinimumValidUpTo(); |
406 | |
|
407 | 0 | if (minimumValidUpToPeriod == null) { |
408 | 0 | this.minimumUpToCheckBox.setSelected(false); |
409 | |
} else { |
410 | 0 | int daysNumber = |
411 | |
minimumValidUpToPeriod. |
412 | |
normalizedStandard(PeriodType.time()). |
413 | |
toStandardDays().getDays(); |
414 | 0 | setMinimumValidUpToDayNumber(daysNumber); |
415 | 0 | this.minimumUpToCheckBox.setSelected(true); |
416 | |
} |
417 | |
|
418 | |
|
419 | 0 | Period maximumValidUpToPeriod = newConstraint.getMaximumValidUpTo(); |
420 | |
|
421 | 0 | if (maximumValidUpToPeriod == null) { |
422 | 0 | this.maximumUpToCheckBox.setSelected(false); |
423 | |
} else { |
424 | 0 | int daysNumber = |
425 | |
maximumValidUpToPeriod. |
426 | |
normalizedStandard(PeriodType.time()). |
427 | |
toStandardDays().getDays(); |
428 | 0 | setMaximumValidUpToDayNumber(daysNumber); |
429 | 0 | this.maximumUpToCheckBox.setSelected(true); |
430 | |
} |
431 | 0 | } |
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
private int extractMaximumUpToDays () { |
437 | 0 | return Math.round((this.maximumUpToDatePicker.getDate().getTime() - |
438 | |
this.referenceDatePicker.getDate().getTime()) / (float) MILLIS_IN_A_DAY); |
439 | |
} |
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
private int extractMinimumUpToDays () { |
445 | 0 | return Math.round((this.minimumUpToDatePicker.getDate().getTime() - |
446 | |
this.referenceDatePicker.getDate().getTime()) / (float) MILLIS_IN_A_DAY); |
447 | |
} |
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | |
private int extractMinimumFromDays () { |
453 | 0 | return Math.round((this.minimumFromDatePicker.getDate().getTime() - |
454 | |
this.referenceDatePicker.getDate().getTime()) / (float) MILLIS_IN_A_DAY); |
455 | |
} |
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
private void setMaximumValidUpToDayNumber (int daysNumber) { |
461 | 0 | this.maximumUpToDatePicker.setDate(addToReference(daysNumber)); |
462 | 0 | } |
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
private void setMinimumValidUpToDayNumber (int daysNumber) { |
468 | 0 | this.minimumUpToDatePicker.setDate(addToReference(daysNumber)); |
469 | 0 | } |
470 | |
|
471 | |
|
472 | |
|
473 | |
|
474 | |
private void setMinimumValidFromDayNumber (int daysNumber) { |
475 | 0 | this.minimumFromDatePicker.setDate(addToReference(daysNumber)); |
476 | 0 | } |
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
private Date addToReference (int daysNumber) { |
482 | 0 | Calendar calendar = Calendar.getInstance(); |
483 | 0 | calendar.setTime(this.referenceDatePicker.getDate()); |
484 | 0 | calendar.add(Calendar.DAY_OF_WEEK, daysNumber); |
485 | 0 | return calendar.getTime(); |
486 | |
} |
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
@Action |
494 | |
public void addAuthority () { |
495 | 0 | LOGGER.debug("addAuthority"); |
496 | 0 | getPresenter().addAuthority(new EditPartCommand<AuthorityBean>(getViewContext())); |
497 | 0 | } |
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
@Action |
503 | |
public void removeAuthority () { |
504 | 0 | LOGGER.debug("removeAuthority"); |
505 | 0 | AuthorityBean activeAuthority = this.getPresenter().getActiveAuthority(); |
506 | 0 | if (activeAuthority != null) { |
507 | |
|
508 | 0 | PolicyBean policyBean = this.getPresenter().getContext().getPolicyBean(); |
509 | 0 | RoleAssignmentRuleBeanCollection roleAssignmentRules = |
510 | |
policyBean.getRoleAssignmentRules(); |
511 | 0 | for (final RoleAssignmentRuleBean currRule : roleAssignmentRules) { |
512 | 0 | if (currRule.getAuthority().equals(activeAuthority)) { |
513 | 0 | if (showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) { |
514 | 0 | return; |
515 | |
} |
516 | |
break; |
517 | |
} |
518 | |
} |
519 | 0 | getPresenter().removeActiveAuthority(activeAuthority); |
520 | 0 | } else { |
521 | 0 | LOGGER.debug("no part selected"); |
522 | |
} |
523 | 0 | } |
524 | |
|
525 | |
|
526 | |
|
527 | |
|
528 | |
@Action |
529 | |
public void editAuthority () { |
530 | 0 | LOGGER.debug("editAuthority"); |
531 | 0 | final AuthorityBean active = getPresenter().getActiveAuthority(); |
532 | 0 | if (active != null) { |
533 | 0 | editPart(active); |
534 | |
} |
535 | 0 | } |
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | |
@Action |
541 | |
public void addSubjectDomain () { |
542 | 0 | LOGGER.debug("addSubjectDomain"); |
543 | 0 | getPresenter().addSubjectDomain(new EditPartCommand<DomainBean>(getViewContext())); |
544 | 0 | } |
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | |
@Action |
550 | |
public void removeSubjectDomain () { |
551 | 0 | LOGGER.debug("removeSubjectDomain"); |
552 | 0 | DomainBean activeSubjectDomain = this.getPresenter().getActiveSubjectDomain(); |
553 | 0 | if (activeSubjectDomain != null) { |
554 | 0 | final PolicyBean policy = this.getPresenter().getContext().getPolicyBean(); |
555 | 0 | final List<RoleAssignmentRuleBean> parents = |
556 | |
policy.getParentRoleAssignmentRules(activeSubjectDomain); |
557 | 0 | if ((parents.size() > 1) |
558 | |
&& showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) { |
559 | 0 | return; |
560 | |
} |
561 | 0 | getPresenter().removeActiveSubjectDomain(activeSubjectDomain); |
562 | 0 | } else { |
563 | 0 | LOGGER.debug("no part selected"); |
564 | |
} |
565 | 0 | } |
566 | |
|
567 | |
|
568 | |
|
569 | |
|
570 | |
@Action |
571 | |
public void editSubjectDomain () { |
572 | 0 | LOGGER.debug("editSubjectDomain"); |
573 | 0 | final DomainBean active = getPresenter().getActiveSubjectDomain(); |
574 | 0 | if (active != null) { |
575 | 0 | editPart(active); |
576 | |
} |
577 | 0 | } |
578 | |
|
579 | |
|
580 | |
|
581 | |
|
582 | |
|
583 | |
|
584 | |
@Override |
585 | |
protected void bind (BindingGroup bindings) { |
586 | 0 | bindings.addBinding( |
587 | |
SwingBindings.createJComboBoxBinding( |
588 | |
UpdateStrategy.READ, |
589 | |
getPresenter().getAuthorityPool().getPoolList(), |
590 | |
this.authority |
591 | |
) |
592 | |
); |
593 | 0 | bindings.addBinding( |
594 | |
Bindings.createAutoBinding( |
595 | |
UpdateStrategy.READ_WRITE, |
596 | |
getPresenter(), |
597 | |
BeanProperty.create("activeAuthority"), |
598 | |
this.authority, |
599 | |
BeanProperty.create("selectedItem") |
600 | |
) |
601 | |
); |
602 | 0 | bindings.addBinding( |
603 | |
SwingBindings.createJComboBoxBinding( |
604 | |
UpdateStrategy.READ, |
605 | |
getPresenter().getSubjectDomainPool().getPoolList(), |
606 | |
this.subjectDomain |
607 | |
) |
608 | |
); |
609 | 0 | bindings.addBinding( |
610 | |
Bindings.createAutoBinding( |
611 | |
UpdateStrategy.READ_WRITE, |
612 | |
getPresenter(), |
613 | |
BeanProperty.create("activeSubjectDomain"), |
614 | |
this.subjectDomain, |
615 | |
BeanProperty.create("selectedItem") |
616 | |
) |
617 | |
); |
618 | 0 | this.roleList.bind( |
619 | |
getPresenter().getRolePool().getPoolList(), |
620 | |
getPresenter().getRoles() |
621 | |
); |
622 | 0 | bindings.addBinding( |
623 | |
Bindings.createAutoBinding( |
624 | |
UpdateStrategy.READ, |
625 | |
getPresenter(), |
626 | |
BeanProperty.create("delegationDepth"), |
627 | |
this.delegationDepthLabel, |
628 | |
BeanProperty.create("text") |
629 | |
) |
630 | |
); |
631 | 0 | bindings.addBinding( |
632 | |
Bindings.createAutoBinding( |
633 | |
UpdateStrategy.READ, |
634 | |
getPresenter(), |
635 | |
BeanProperty.create("constraint"), |
636 | |
this, |
637 | |
BeanProperty.create("constraint") |
638 | |
) |
639 | |
); |
640 | 0 | } |
641 | |
|
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
|
647 | |
private JComponent attributeAuthority () { |
648 | 0 | final FormLayout layout = new FormLayout( |
649 | |
"pref, 2dlu, fill:50dlu:grow, 2dlu, pref", |
650 | |
"pref" |
651 | |
); |
652 | 0 | final JPanel panel = new JPanel(); |
653 | 0 | panel.setLayout(layout); |
654 | 0 | final CellConstraints cc = new CellConstraints(); |
655 | 0 | panel.add(label("authority"), cc.xy(1, 1)); |
656 | 0 | panel.add(this.authority, cc.xy(3, 1)); |
657 | 0 | panel.add(toolBar("authorityToolBar"), cc.xy(5, 1)); |
658 | 0 | return panel; |
659 | |
} |
660 | |
|
661 | |
|
662 | |
|
663 | |
|
664 | |
private JComponent subjectDomainChooser () { |
665 | 0 | final FormLayout layout = new FormLayout( |
666 | |
"pref, 2dlu, fill:50dlu:grow, 2dlu, pref", |
667 | |
"pref" |
668 | |
); |
669 | 0 | final JPanel panel = new JPanel(); |
670 | 0 | panel.setLayout(layout); |
671 | 0 | final CellConstraints cc = new CellConstraints(); |
672 | 0 | panel.add(label("subjectDomain"), cc.xy(1, 1)); |
673 | 0 | panel.add(this.subjectDomain, cc.xy(3, 1)); |
674 | 0 | panel.add(toolBar("subjectDomainToolBar"), cc.xy(5, 1)); |
675 | 0 | return panel; |
676 | |
} |
677 | |
|
678 | |
|
679 | |
|
680 | |
|
681 | |
private JComponent roleList () { |
682 | 0 | final FormLayout layout = new FormLayout( |
683 | |
"pref, fill:pref:grow", |
684 | |
"pref, fill:pref:grow" |
685 | |
); |
686 | 0 | final JPanel panel = new JPanel(); |
687 | 0 | panel.setLayout(layout); |
688 | 0 | final CellConstraints cc = new CellConstraints(); |
689 | 0 | panel.add(label("roles"), cc.xy(1, 1)); |
690 | 0 | panel.add(toolBar("roleToolBar"), cc.xy(2, 1)); |
691 | 0 | this.roleList.setVisibleRowCount(5); |
692 | 0 | panel.add(new JScrollPane(this.roleList), cc.xyw(1, 2, 2)); |
693 | 0 | return panel; |
694 | |
} |
695 | |
|
696 | |
|
697 | |
|
698 | |
|
699 | |
private JComponent depthAndConstraints () { |
700 | 0 | final JPanel panel = new JPanel(); |
701 | 0 | final FormLayout layout = new FormLayout( |
702 | |
"pref, pref, 10dlu, pref, pref, 10dlu, pref, pref, 17dlu, fill:pref:grow", |
703 | |
"pref, 50dlu, pref, pref, pref, pref, pref" |
704 | |
); |
705 | 0 | final CellConstraints cc = new CellConstraints(); |
706 | 0 | panel.setLayout(layout); |
707 | |
|
708 | 0 | panel.add(label("delegationDepth"), cc.xyw(1, 1, 2)); |
709 | 0 | panel.add(this.delegationDepthLabel, cc.xy(4, 1)); |
710 | 0 | final JButton plusButton = new JButton("+"); |
711 | 0 | plusButton.addActionListener(new ActionListener() { |
712 | 0 | public void actionPerformed (ActionEvent e) { |
713 | 0 | getPresenter().updateDelegationDepthAtModel( |
714 | |
getPresenter().getDelegationDepth() + 1 |
715 | |
); |
716 | 0 | } |
717 | |
}); |
718 | 0 | panel.add(plusButton, cc.xy(5, 1)); |
719 | 0 | final JButton minusButton = new JButton("-"); |
720 | 0 | minusButton.addActionListener(new ActionListener() { |
721 | 0 | public void actionPerformed (ActionEvent e) { |
722 | 0 | if (getPresenter().getDelegationDepth() > 0) { |
723 | 0 | getPresenter().updateDelegationDepthAtModel( |
724 | |
getPresenter().getDelegationDepth() - 1 |
725 | |
); |
726 | |
} |
727 | 0 | } |
728 | |
}); |
729 | 0 | panel.add(minusButton, cc.xy(8, 1)); |
730 | |
|
731 | 0 | panel.add(this.absolutePeriodCheckBox, cc.xy(1, 2)); |
732 | 0 | panel.add(label("absolutePeriod"), cc.xy(2, 2)); |
733 | 0 | panel.add(label("absolutePeriod.start"), cc.xy(4, 2)); |
734 | |
|
735 | 0 | panel.add(this.startDatePicker, cc.xy(5, 2)); |
736 | 0 | panel.add(label("absolutePeriod.end"), cc.xy(7, 2)); |
737 | 0 | panel.add(this.endDatePicker, cc.xy(8, 2)); |
738 | |
|
739 | 0 | panel.add(this.minimumFromCheckBox, cc.xy(1, 4)); |
740 | 0 | panel.add(label("minimumValidFrom"), cc.xy(2, 4)); |
741 | 0 | panel.add(this.minimumFromDatePicker, cc.xy(5, 4)); |
742 | |
|
743 | 0 | panel.add(this.minimumUpToCheckBox, cc.xy(1, 5)); |
744 | 0 | panel.add(label("minimumValidUpTo"), cc.xy(2, 5)); |
745 | 0 | panel.add(this.minimumUpToDatePicker, cc.xy(5, 5)); |
746 | |
|
747 | 0 | panel.add(this.maximumUpToCheckBox, cc.xy(1, 6)); |
748 | 0 | panel.add(label("maximumValidUpTo"), cc.xy(2, 6)); |
749 | 0 | panel.add(this.maximumUpToDatePicker, cc.xy(5, 6)); |
750 | |
|
751 | 0 | panel.add(label("referenceDate"), cc.xy(2, 7)); |
752 | 0 | panel.add(this.referenceDatePicker, cc.xy(5, 7)); |
753 | |
|
754 | 0 | return panel; |
755 | |
} |
756 | |
|
757 | |
|
758 | |
|
759 | |
|
760 | |
public void fillContentPane (JPanel panel) { |
761 | 0 | final FormLayout layout = new FormLayout( |
762 | |
"8dlu, fill:min:grow, 8dlu", |
763 | |
"8dlu, pref, 8dlu, pref, 8dlu, pref, 8dlu, pref, 8dlu, fill:pref:grow, 8dlu" |
764 | |
); |
765 | 0 | panel.setLayout(layout); |
766 | 0 | final CellConstraints cc = new CellConstraints(); |
767 | 0 | this.roleList = new CheckList<Role>(); |
768 | 0 | this.roleList.setDoubleClickAction(getActionMap().get("editRole")); |
769 | 0 | this.roleList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
770 | 0 | this.roleList.setItemRenderer( |
771 | |
RendererFactory.createTableCellRenderer(this.getAdapteeTrader(), Overview.class) |
772 | |
); |
773 | |
|
774 | 0 | this.authority = new JComboBox(); |
775 | 0 | this.authority.setRenderer( |
776 | |
RendererFactory.createListCellRenderer(this.getAdapteeTrader(), Overview.class) |
777 | |
); |
778 | |
|
779 | 0 | this.subjectDomain = new JComboBox(); |
780 | 0 | this.subjectDomain.setRenderer( |
781 | |
RendererFactory.createListCellRenderer(this.getAdapteeTrader(), Overview.class) |
782 | |
); |
783 | |
|
784 | 0 | panel.add(attributeAuthority(), cc.xy(2, 2)); |
785 | 0 | panel.add(subjectDomainChooser(), cc.xy(2, 4)); |
786 | 0 | panel.add(roleList(), cc.xy(2, 6)); |
787 | 0 | panel.add(depthAndConstraints(), cc.xy(2, 10)); |
788 | 0 | } |
789 | |
|
790 | |
} |