1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import java.awt.Container; |
13 | |
import java.awt.Dimension; |
14 | |
import java.awt.Toolkit; |
15 | |
import java.awt.event.ActionEvent; |
16 | |
import java.awt.event.ItemEvent; |
17 | |
import java.awt.event.ItemListener; |
18 | |
import java.beans.PropertyChangeEvent; |
19 | |
import java.beans.PropertyChangeListener; |
20 | |
import java.io.IOException; |
21 | |
import java.io.StringWriter; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Calendar; |
24 | |
import java.util.Collections; |
25 | |
import java.util.Enumeration; |
26 | |
import java.util.List; |
27 | |
|
28 | |
import javax.swing.AbstractAction; |
29 | |
import javax.swing.ButtonGroup; |
30 | |
import javax.swing.DefaultComboBoxModel; |
31 | |
import javax.swing.JButton; |
32 | |
import javax.swing.JCheckBox; |
33 | |
import javax.swing.JComboBox; |
34 | |
import javax.swing.JComponent; |
35 | |
import javax.swing.JDialog; |
36 | |
import javax.swing.JFrame; |
37 | |
import javax.swing.JLabel; |
38 | |
import javax.swing.JOptionPane; |
39 | |
import javax.swing.JPanel; |
40 | |
import javax.swing.JRadioButton; |
41 | |
import javax.swing.JScrollPane; |
42 | |
import javax.swing.JTable; |
43 | |
import javax.swing.JTextArea; |
44 | |
import javax.swing.JTextField; |
45 | |
import javax.swing.JTree; |
46 | |
import javax.swing.JViewport; |
47 | |
import javax.swing.UIManager; |
48 | |
import javax.swing.border.Border; |
49 | |
import javax.swing.event.AncestorEvent; |
50 | |
import javax.swing.event.AncestorListener; |
51 | |
import javax.swing.plaf.UIResource; |
52 | |
import javax.swing.table.DefaultTableModel; |
53 | |
import javax.swing.table.TableModel; |
54 | |
import javax.swing.tree.DefaultTreeModel; |
55 | |
import javax.swing.tree.TreeNode; |
56 | |
import javax.swing.tree.TreePath; |
57 | |
import javax.swing.tree.TreeSelectionModel; |
58 | |
|
59 | |
import org.jdesktop.application.Action; |
60 | |
import org.jdesktop.application.ApplicationContext; |
61 | |
import org.jdesktop.beansbinding.BindingGroup; |
62 | |
import org.slf4j.Logger; |
63 | |
import org.slf4j.LoggerFactory; |
64 | |
|
65 | |
import com.generationjava.io.xml.PrettyPrinterXmlWriter; |
66 | |
import com.generationjava.io.xml.SimpleXmlWriter; |
67 | |
import com.jgoodies.forms.layout.CellConstraints; |
68 | |
import com.jgoodies.forms.layout.FormLayout; |
69 | |
|
70 | |
import org.openpermis.basic.PartialTime; |
71 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
72 | |
import org.openpermis.editor.policy.adapter.overview.Overview; |
73 | |
import org.openpermis.editor.policy.beans.PropertyChange; |
74 | |
import org.openpermis.editor.policy.gui.checklist.CheckList; |
75 | |
import org.openpermis.editor.policy.gui.component.TimeStampPicker; |
76 | |
import org.openpermis.editor.policy.presenter.TargetAccessRulePresenter; |
77 | |
import org.openpermis.editor.policy.renderer.RendererFactory; |
78 | |
import org.openpermis.policy.ParameterList; |
79 | |
import org.openpermis.policy.Predicate; |
80 | |
import org.openpermis.policy.Role; |
81 | |
import org.openpermis.policy.TimeStamp; |
82 | |
import org.openpermis.policy.bean.ActionBean; |
83 | |
import org.openpermis.policy.bean.ObligationBean; |
84 | |
import org.openpermis.policy.bean.PolicyBean; |
85 | |
import org.openpermis.policy.bean.TargetAccessRuleBean; |
86 | |
import org.openpermis.policy.bean.TargetBean; |
87 | |
import org.openpermis.policy.io.xml.PermisXmlWriter; |
88 | |
import org.openpermis.policy.predicate.AbstractPredicate; |
89 | |
import org.openpermis.policy.predicate.And; |
90 | |
import org.openpermis.policy.predicate.Argument; |
91 | |
import org.openpermis.policy.predicate.Constant; |
92 | |
import org.openpermis.policy.predicate.CurrentTime; |
93 | |
import org.openpermis.policy.predicate.Not; |
94 | |
import org.openpermis.policy.predicate.Or; |
95 | |
import org.openpermis.policy.predicate.Present; |
96 | |
import org.openpermis.policy.predicate.SubstringOf; |
97 | |
import org.openpermis.policy.predicate.TimeConstant; |
98 | |
import org.openpermis.policy.predicate.Value; |
99 | |
import org.openpermis.policy.predicate.ValueRelationalPredicate; |
100 | |
import org.openpermis.policy.predicate.ValueSet; |
101 | |
import org.openpermis.policy.predicate.ValueSetRelationalPredicate; |
102 | |
import org.openpermis.policy.predicate.ValueRelationalPredicate.Relation; |
103 | |
import org.openpermis.policy.predicate.ValueSetRelationalPredicate.SetRelation; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | 0 | public class TargetAccessRuleEditor |
110 | |
extends AbstractEditor<TargetAccessRulePresenter> |
111 | |
implements AncestorListener |
112 | |
{ |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | 0 | private static final Logger LOGGER = |
121 | |
LoggerFactory.getLogger(TargetAccessRuleEditor.class); |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | 0 | private static final Class<?>[] SUPPORTED_TYPES = { |
128 | |
Integer.class, Double.class, Boolean.class, String.class |
129 | |
}; |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | 0 | private static final Class<?>[] RELATION_SUPPORTED_TYPES = { |
136 | |
Integer.class, Double.class |
137 | |
}; |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | 0 | private static final Object[] CONDITION_TERM_TYPES = { |
143 | |
"Boolean", |
144 | |
"Relational", |
145 | |
"Time Span", |
146 | |
"Substring Of", |
147 | |
"Set", |
148 | |
"Present" |
149 | |
}; |
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | 0 | private static final Object[] BOOLEAN_TERM_TYPES = {"AND", "OR", "NOT", "TRUE", "FALSE"}; |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
private CheckList<TargetBean> targetList; |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
private CheckList<Role> roleList; |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
private CheckList<ObligationBean> obligationList; |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | 0 | private JTree conditionTree = new JTree(); |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | 0 | private PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { |
188 | 0 | public void propertyChange (PropertyChangeEvent evt) { |
189 | 0 | updateState(); |
190 | 0 | } |
191 | |
}; |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public TargetAccessRuleEditor ( |
202 | |
ApplicationContext context, AdapterTrader trader, TargetAccessRulePresenter presenter |
203 | |
) { |
204 | 0 | super(context, trader, presenter); |
205 | 0 | } |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
@SuppressWarnings({ "unchecked" }) |
214 | |
private Object add (Object subTreeRoot, Object parentOfAdded) { |
215 | |
|
216 | 0 | Object[] modifiedOperands = null; |
217 | 0 | if (subTreeRoot instanceof AbstractPredicate) { |
218 | 0 | List operands = new ArrayList(((AbstractPredicate) subTreeRoot).getOperands()); |
219 | 0 | if (subTreeRoot == parentOfAdded) { |
220 | 0 | final Object[] newTerm = new Object[] {null}; |
221 | 0 | createNewTerm(newTerm); |
222 | 0 | if (newTerm[0] != null) { |
223 | 0 | operands.add(newTerm[0]); |
224 | |
} |
225 | |
} |
226 | 0 | modifiedOperands = new Object[operands.size()]; |
227 | 0 | for (int i = 0; i < operands.size(); i++) { |
228 | 0 | modifiedOperands[i] = add(operands.get(i), parentOfAdded); |
229 | |
} |
230 | |
} |
231 | 0 | return recreatePredicate(subTreeRoot, modifiedOperands); |
232 | |
} |
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
@SuppressWarnings("unchecked") |
238 | |
private Object remove ( |
239 | |
Object root, Object toBeDeleted |
240 | |
) { |
241 | 0 | Object[] modifiedOperands = null; |
242 | 0 | if (root instanceof AbstractPredicate) { |
243 | 0 | List operands = new ArrayList(((AbstractPredicate) root).getOperands()); |
244 | |
|
245 | 0 | if (operands.contains(toBeDeleted)) { |
246 | 0 | if ( |
247 | |
root instanceof Not && operands.size() > 1 || |
248 | |
root instanceof And && operands.size() > 2 || |
249 | |
root instanceof Or && operands.size() > 2) { |
250 | 0 | operands.remove(toBeDeleted); |
251 | |
} else { |
252 | 0 | JOptionPane.showMessageDialog(null, getFromMap("cantRemove")); |
253 | |
} |
254 | |
} |
255 | |
|
256 | 0 | modifiedOperands = new Object[operands.size()]; |
257 | 0 | for (int i = 0; i < operands.size(); i++) { |
258 | 0 | modifiedOperands[i] = remove(operands.get(i), toBeDeleted); |
259 | |
} |
260 | |
} |
261 | 0 | return recreatePredicate(root, modifiedOperands); |
262 | |
} |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
@SuppressWarnings("unchecked") |
268 | |
private Object edit (Object root, Object toBeEdited) { |
269 | |
List modifiedOperandsList; |
270 | 0 | if ( |
271 | |
root instanceof AbstractPredicate || |
272 | |
root.equals(Predicate.TRUE) || |
273 | |
root.equals(Predicate.FALSE) |
274 | |
) { |
275 | 0 | if (root instanceof AbstractPredicate) { |
276 | 0 | modifiedOperandsList = new ArrayList(((AbstractPredicate) root).getOperands()); |
277 | |
} else { |
278 | 0 | modifiedOperandsList = new ArrayList(); |
279 | |
} |
280 | 0 | if ( |
281 | |
root == toBeEdited && |
282 | |
( |
283 | |
root instanceof And || |
284 | |
root instanceof Or || |
285 | |
root instanceof Not || |
286 | |
root.equals(Predicate.TRUE) || |
287 | |
root.equals(Predicate.FALSE) |
288 | |
) |
289 | |
) { |
290 | 0 | Object[] possibilities = { "AND", "OR", "NOT" }; |
291 | 0 | String s = (String) JOptionPane.showInputDialog( |
292 | |
null, |
293 | |
getFromMap("changeTermTypeTo"), |
294 | |
getFromMap("changeTernType"), |
295 | |
JOptionPane.PLAIN_MESSAGE, |
296 | |
null, possibilities, |
297 | |
"AND"); |
298 | |
|
299 | 0 | if (possibilities[0].equals(s)) { |
300 | 0 | root = new And(createATrue(), createATrue()); |
301 | 0 | for (Object o : modifiedOperandsList) { |
302 | 0 | if (!(o instanceof AbstractPredicate)) { |
303 | 0 | modifiedOperandsList.clear(); |
304 | 0 | break; |
305 | |
} |
306 | |
} |
307 | 0 | while (modifiedOperandsList.size() < 2) { |
308 | 0 | modifiedOperandsList.add(createATrue()); |
309 | |
} |
310 | 0 | } else if (possibilities[1].equals(s)) { |
311 | 0 | root = new Or(createATrue(), createATrue()); |
312 | 0 | for (Object o : modifiedOperandsList) { |
313 | 0 | if (!(o instanceof AbstractPredicate)) { |
314 | 0 | modifiedOperandsList.clear(); |
315 | 0 | break; |
316 | |
} |
317 | |
} |
318 | 0 | while (modifiedOperandsList.size() < 2) { |
319 | 0 | modifiedOperandsList.add(createATrue()); |
320 | |
} |
321 | 0 | } else if (possibilities[2].equals(s)) { |
322 | 0 | root = new Not(createAFalse()); |
323 | 0 | for (Object o : modifiedOperandsList) { |
324 | 0 | if (!(o instanceof AbstractPredicate)) { |
325 | 0 | modifiedOperandsList.clear(); |
326 | 0 | break; |
327 | |
} |
328 | |
} |
329 | 0 | if (modifiedOperandsList.size() == 0) { |
330 | 0 | modifiedOperandsList.add(createAFalse()); |
331 | |
} |
332 | |
} |
333 | 0 | } |
334 | |
} else { |
335 | 0 | modifiedOperandsList = new ArrayList(); |
336 | |
} |
337 | |
|
338 | 0 | Object[] modifiedOperandsArray = new Object[modifiedOperandsList.size()]; |
339 | 0 | for (int i = 0; i < modifiedOperandsList.size(); i++) { |
340 | 0 | modifiedOperandsArray[i] = edit(modifiedOperandsList.get(i), toBeEdited); |
341 | |
} |
342 | |
|
343 | 0 | return recreatePredicate(root, modifiedOperandsArray); |
344 | |
} |
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
@SuppressWarnings("unchecked") |
350 | |
private Object recreatePredicate (Object root, Object[] operands) { |
351 | 0 | if (root instanceof And) { |
352 | 0 | Predicate[] predicates = new Predicate[operands.length]; |
353 | 0 | for (int i = 0; i < operands.length; i++) { |
354 | 0 | predicates[i] = (Predicate) operands[i]; |
355 | |
} |
356 | 0 | return new And(predicates); |
357 | 0 | } else if (root instanceof Or) { |
358 | 0 | Predicate[] predicates = new Predicate[operands.length]; |
359 | 0 | for (int i = 0; i < operands.length; i++) { |
360 | 0 | predicates[i] = (Predicate) operands[i]; |
361 | |
} |
362 | 0 | return new Or(predicates); |
363 | 0 | } else if (root instanceof Not) { |
364 | 0 | return new Not((Predicate) operands[0]); |
365 | 0 | } else if (root instanceof Present) { |
366 | 0 | return new Present((Value) operands[0]); |
367 | 0 | } else if (root instanceof ValueRelationalPredicate) { |
368 | 0 | return new ValueRelationalPredicate( |
369 | |
((ValueRelationalPredicate) root).getRelation(), |
370 | |
(Value) operands[0], |
371 | |
(Value) operands[1] |
372 | |
); |
373 | 0 | } else if (root instanceof ValueSetRelationalPredicate) { |
374 | 0 | return new ValueSetRelationalPredicate( |
375 | |
((ValueSetRelationalPredicate) root).getRelation(), |
376 | |
(ValueSet) operands[0], |
377 | |
(ValueSet) operands[1] |
378 | |
); |
379 | 0 | } else if (root instanceof SubstringOf) { |
380 | 0 | return new SubstringOf((Value) operands[0], (Value) operands[1]); |
381 | 0 | } else if (root instanceof Constant) { |
382 | 0 | return new Constant(((Constant) root).getValue()); |
383 | 0 | } else if (root instanceof Argument) { |
384 | 0 | final Argument argument = (Argument) root; |
385 | 0 | return new Argument(argument.getName(), argument.getType()); |
386 | 0 | } else if (root instanceof CurrentTime) { |
387 | 0 | return new CurrentTime(); |
388 | 0 | } else if (root instanceof ValueSet) { |
389 | 0 | return new ValueSet(((ValueSet) root).getValues()); |
390 | 0 | } else if (root instanceof TimeConstant) { |
391 | 0 | return new TimeConstant(((TimeConstant) root).getValue()); |
392 | |
} else { |
393 | 0 | return null; |
394 | |
} |
395 | |
} |
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
@SuppressWarnings({ "unchecked", "serial" }) |
401 | |
private void createNewTerm (final Object[] newTerm) { |
402 | |
|
403 | 0 | String termType = (String) JOptionPane.showInputDialog( |
404 | |
null, |
405 | |
getFromMap("chooseTheTermType"), |
406 | |
getFromMap("addAPrediateTerm"), |
407 | |
JOptionPane.PLAIN_MESSAGE, |
408 | |
null, |
409 | |
CONDITION_TERM_TYPES, |
410 | |
CONDITION_TERM_TYPES[0] |
411 | |
); |
412 | |
|
413 | |
|
414 | 0 | if (CONDITION_TERM_TYPES[0].equals(termType)) { |
415 | 0 | String booleanTermType = (String) JOptionPane.showInputDialog( |
416 | |
null, |
417 | |
getFromMap("chooseTheTermType"), |
418 | |
getFromMap("addAPrediateTerm"), |
419 | |
JOptionPane.PLAIN_MESSAGE, |
420 | |
null, |
421 | |
BOOLEAN_TERM_TYPES, |
422 | |
BOOLEAN_TERM_TYPES[0]); |
423 | |
|
424 | 0 | if (BOOLEAN_TERM_TYPES[0].equals(booleanTermType)) { |
425 | 0 | Object[] firstOperand = new Object[] {null}; |
426 | 0 | createNewTerm(firstOperand); |
427 | 0 | Object[] secondOperand = new Object[] {null}; |
428 | 0 | createNewTerm(secondOperand); |
429 | 0 | if (firstOperand[0] != null && secondOperand[0] != null) { |
430 | 0 | newTerm[0] = new And((Predicate) firstOperand[0], (Predicate) secondOperand[0]); |
431 | |
} |
432 | 0 | } else if (BOOLEAN_TERM_TYPES[1].equals(booleanTermType)) { |
433 | 0 | Object[] firstOperand = new Object[] {null}; |
434 | 0 | createNewTerm(firstOperand); |
435 | 0 | Object[] secondOperand = new Object[] {null}; |
436 | 0 | createNewTerm(secondOperand); |
437 | 0 | if (firstOperand[0] != null && secondOperand[0] != null) { |
438 | 0 | newTerm[0] = new Or((Predicate) firstOperand[0], (Predicate) secondOperand[0]); |
439 | |
} |
440 | 0 | } else if (BOOLEAN_TERM_TYPES[2].equals(booleanTermType)) { |
441 | 0 | Object[] firstOperand = new Object[] {null}; |
442 | 0 | createNewTerm(firstOperand); |
443 | 0 | if (firstOperand[0] != null) { |
444 | 0 | newTerm[0] = new Not((Predicate) firstOperand[0]); |
445 | |
} |
446 | 0 | } else if (BOOLEAN_TERM_TYPES[3].equals(booleanTermType)) { |
447 | 0 | newTerm[0] = createATrue(); |
448 | 0 | } else if (BOOLEAN_TERM_TYPES[4].equals(booleanTermType)) { |
449 | 0 | newTerm[0] = createAFalse(); |
450 | |
} |
451 | 0 | } else if (CONDITION_TERM_TYPES[5].equals(termType)) { |
452 | 0 | final Value[] value = new Value[] { null }; |
453 | 0 | showAValueDialog(value, null, true); |
454 | 0 | newTerm[0] = new Present(value[0]); |
455 | 0 | } else if (CONDITION_TERM_TYPES[1].equals(termType)) { |
456 | 0 | final JDialog dialog = new JDialog((JFrame) null, true); |
457 | 0 | final FormLayout layout = new FormLayout( |
458 | |
"8dlu, 60dlu, 8dlu, 60dlu, 8dlu", |
459 | |
"8dlu, pref,pref, 8dlu, pref, pref, 8dlu, pref," + |
460 | |
"8dlu, pref, pref, 8dlu, pref, 8dlu"); |
461 | |
|
462 | 0 | dialog.setLayout(layout); |
463 | 0 | dialog.setSize(new Dimension(300, 300)); |
464 | |
|
465 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
466 | 0 | dialog.setLocation( |
467 | |
(screenSize.width - dialog.getWidth()) / 2, |
468 | |
(screenSize.height - dialog.getHeight()) / 2 |
469 | |
); |
470 | |
|
471 | 0 | int rowNumber = 0; |
472 | 0 | final CellConstraints cc = new CellConstraints(); |
473 | 0 | rowNumber += 2; |
474 | 0 | dialog.add( |
475 | |
new JLabel(getFromMap("operandsType")), |
476 | |
cc.xyw(2, rowNumber, 3) |
477 | |
); |
478 | 0 | final JComboBox typeCombo = new JComboBox(RELATION_SUPPORTED_TYPES); |
479 | 0 | rowNumber += 1; |
480 | 0 | dialog.add(typeCombo, cc.xyw(2, rowNumber, 3)); |
481 | |
|
482 | 0 | rowNumber += 2; |
483 | 0 | final Value[] firstOperand = new Value[] { null }; |
484 | 0 | final JLabel firstOperanLabel = new JLabel(""); |
485 | 0 | dialog.add( |
486 | |
new JButton( |
487 | |
new AbstractAction(getFromMap("firstOperand")) { |
488 | 0 | public void actionPerformed (ActionEvent e) { |
489 | 0 | showAValueDialog(firstOperand, typeCombo, false); |
490 | 0 | if (firstOperand[0] != null) { |
491 | 0 | if (firstOperand[0] instanceof Constant) { |
492 | 0 | firstOperanLabel.setText( |
493 | |
((Constant) firstOperand[0]).getValue().toString() |
494 | |
); |
495 | 0 | } else if (firstOperand[0] instanceof Argument) { |
496 | 0 | firstOperanLabel.setText( |
497 | |
((Argument) firstOperand[0]).getName().toString() |
498 | |
); |
499 | |
} |
500 | |
} |
501 | 0 | } |
502 | |
} |
503 | |
), |
504 | |
cc.xyw(2, rowNumber, 3) |
505 | |
); |
506 | 0 | rowNumber += 1; |
507 | 0 | dialog.add(firstOperanLabel, cc.xyw(2, rowNumber, 3)); |
508 | 0 | final JComboBox operatorCombo = new JComboBox( |
509 | |
ValueRelationalPredicate.Relation.values() |
510 | |
); |
511 | 0 | rowNumber += 2; |
512 | 0 | dialog.add(operatorCombo, cc.xyw(2, rowNumber, 3)); |
513 | 0 | rowNumber += 2; |
514 | 0 | final Value[] secondOperand = new Value[] { null }; |
515 | 0 | final JLabel secondOperanLabel = new JLabel(""); |
516 | 0 | dialog.add( |
517 | |
new JButton( |
518 | |
new AbstractAction(getFromMap("secondOperand")) { |
519 | 0 | public void actionPerformed (ActionEvent e) { |
520 | 0 | showAValueDialog(secondOperand, typeCombo, false); |
521 | 0 | if (secondOperand[0] != null) { |
522 | 0 | if (secondOperand[0] instanceof Constant) { |
523 | 0 | secondOperanLabel.setText( |
524 | |
((Constant) secondOperand[0]).getValue().toString() |
525 | |
); |
526 | 0 | } else if (secondOperand[0] instanceof Argument) { |
527 | 0 | secondOperanLabel.setText( |
528 | |
((Argument) secondOperand[0]).getName().toString() |
529 | |
); |
530 | |
} |
531 | |
} |
532 | 0 | } |
533 | |
} |
534 | |
), |
535 | |
cc.xyw(2, rowNumber, 3) |
536 | |
); |
537 | 0 | rowNumber += 1; |
538 | 0 | dialog.add(secondOperanLabel, cc.xyw(2, rowNumber, 3)); |
539 | 0 | rowNumber += 2; |
540 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("ok")) { |
541 | 0 | public void actionPerformed (ActionEvent e) { |
542 | 0 | if ( |
543 | |
firstOperand[0] == null || |
544 | |
secondOperand[0] == null || |
545 | |
!firstOperand[0].getType().equals(secondOperand[0].getType()) |
546 | |
) { |
547 | 0 | JOptionPane.showMessageDialog( |
548 | |
null, |
549 | |
getFromMap("inputNotValid") |
550 | |
); |
551 | 0 | newTerm[0] = null; |
552 | 0 | dialog.setVisible(false); |
553 | 0 | return; |
554 | |
} |
555 | 0 | newTerm[0] = new ValueRelationalPredicate( |
556 | |
(Relation) operatorCombo.getSelectedItem(), |
557 | |
firstOperand[0], secondOperand[0] |
558 | |
); |
559 | 0 | dialog.setVisible(false); |
560 | 0 | } |
561 | |
}), cc.xy(2, rowNumber)); |
562 | 0 | dialog.add( |
563 | |
new JButton( |
564 | |
new AbstractAction(getFromMap("cancel")) { |
565 | 0 | public void actionPerformed (ActionEvent e) { |
566 | 0 | newTerm[0] = null; |
567 | 0 | dialog.setVisible(false); |
568 | 0 | } |
569 | |
} |
570 | |
), |
571 | |
cc.xy(4, rowNumber) |
572 | |
); |
573 | 0 | dialog.setVisible(true); |
574 | 0 | } else if (CONDITION_TERM_TYPES[3].equals(termType)) { |
575 | 0 | final JDialog dialog = new JDialog((JFrame) null, true); |
576 | 0 | final FormLayout layout = new FormLayout( |
577 | |
"8dlu, 60dlu, 8dlu, 60dlu, 8dlu", |
578 | |
"8dlu, pref,pref, 8dlu, pref, pref, 8dlu, pref, 8dlu" |
579 | |
); |
580 | |
|
581 | 0 | dialog.setLayout(layout); |
582 | 0 | dialog.setSize(new Dimension(300, 200)); |
583 | |
|
584 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
585 | 0 | dialog.setLocation( |
586 | |
(screenSize.width - dialog.getWidth()) / 2, |
587 | |
(screenSize.height - dialog.getHeight()) / 2 |
588 | |
); |
589 | |
|
590 | 0 | final CellConstraints cc = new CellConstraints(); |
591 | 0 | final JComboBox parameterField = new JComboBox( |
592 | |
getNamesOfArgumentsOfGivenType(String.class) |
593 | |
); |
594 | |
|
595 | 0 | dialog.add(new JLabel(getFromMap("enterTheArgumentName")), cc.xyw(2, 2, 3)); |
596 | 0 | dialog.add(parameterField, cc.xyw(2, 3, 3)); |
597 | 0 | dialog.add(new JLabel(getFromMap("substringOf")), cc.xyw(2, 5, 3)); |
598 | 0 | final JTextField superStringField = new JTextField(); |
599 | 0 | dialog.add(superStringField, cc.xyw(2, 6, 3)); |
600 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("ok")) { |
601 | |
|
602 | 0 | public void actionPerformed (ActionEvent e) { |
603 | 0 | if (parameterField.getSelectedItem().toString().length() == 0) { |
604 | 0 | newTerm[0] = null; |
605 | 0 | dialog.setVisible(false); |
606 | 0 | return; |
607 | |
} |
608 | 0 | newTerm[0] = new SubstringOf( |
609 | |
new Argument(parameterField.getSelectedItem().toString(), String.class), |
610 | |
new Constant(superStringField.getText()) |
611 | |
); |
612 | 0 | dialog.setVisible(false); |
613 | 0 | } |
614 | |
}), cc.xy(2, 8)); |
615 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("cancel")) { |
616 | |
|
617 | 0 | public void actionPerformed (ActionEvent e) { |
618 | 0 | newTerm[0] = null; |
619 | 0 | dialog.setVisible(false); |
620 | 0 | } |
621 | |
}), cc.xy(4, 8)); |
622 | 0 | dialog.setVisible(true); |
623 | 0 | } else if (CONDITION_TERM_TYPES[2].equals(termType)) { |
624 | 0 | final JDialog dialog = new JDialog((JFrame) null, true); |
625 | 0 | final FormLayout layout = new FormLayout( |
626 | |
"8dlu, 80dlu, 40dlu, 40dlu, 8dlu", |
627 | |
"8dlu, pref, 8dlu, pref," + |
628 | |
"8dlu, pref, pref, pref, pref, pref, pref, pref," + |
629 | |
"pref, pref, pref, 8dlu, pref, 8dlu" |
630 | |
); |
631 | |
|
632 | 0 | dialog.setLayout(layout); |
633 | 0 | dialog.setSize(new Dimension(350, 450)); |
634 | |
|
635 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
636 | 0 | dialog.setLocation( |
637 | |
(screenSize.width - dialog.getWidth()) / 2, |
638 | |
(screenSize.height - dialog.getHeight()) / 2 |
639 | |
); |
640 | |
|
641 | 0 | int rowNumber = 0; |
642 | 0 | final CellConstraints cc = new CellConstraints(); |
643 | |
|
644 | 0 | rowNumber += 2; |
645 | 0 | dialog.add(new JLabel(getFromMap("currentTime")), cc.xyw(2, rowNumber, 3)); |
646 | 0 | final JComboBox operatorCombo = new JComboBox( |
647 | |
ValueRelationalPredicate.Relation.values() |
648 | |
); |
649 | 0 | rowNumber += 2; |
650 | 0 | dialog.add(operatorCombo, cc.xyw(2, rowNumber, 3)); |
651 | 0 | rowNumber += 2; |
652 | 0 | final TimeStampPicker timePicker = new TimeStampPicker(); |
653 | 0 | dialog.add(timePicker, cc.xyw(2, rowNumber, 3)); |
654 | 0 | rowNumber += 1; |
655 | |
|
656 | 0 | dialog.add(new JLabel(getFromMap("hour")), cc.xy(2, rowNumber)); |
657 | 0 | final Integer[] hoursOfDay = new Integer[24]; |
658 | 0 | for (int i = 0; i < hoursOfDay.length; i++) { |
659 | 0 | hoursOfDay[i] = Integer.valueOf(i); |
660 | |
} |
661 | 0 | final JComboBox hoursOfDayCombo = new JComboBox(hoursOfDay); |
662 | 0 | dialog.add(hoursOfDayCombo, cc.xy(3, rowNumber)); |
663 | 0 | final Integer[] minutesOfHour = new Integer[60]; |
664 | 0 | for (int i = 0; i < minutesOfHour.length; i++) { |
665 | 0 | minutesOfHour[i] = Integer.valueOf(i); |
666 | |
} |
667 | 0 | final JComboBox minutesCombo = new JComboBox(minutesOfHour); |
668 | 0 | dialog.add(minutesCombo, cc.xy(4, rowNumber)); |
669 | |
|
670 | |
|
671 | 0 | final JRadioButton defaultPlicyOffsetRButton = |
672 | |
new JRadioButton(getFromMap("policyOffset")); |
673 | 0 | defaultPlicyOffsetRButton.setSelected(true); |
674 | |
|
675 | 0 | dialog.add(defaultPlicyOffsetRButton, cc.xyw(2, ++rowNumber, 3)); |
676 | |
|
677 | 0 | final JRadioButton manualOffsetRButton = |
678 | |
new JRadioButton(getFromMap("offset")); |
679 | 0 | dialog.add(manualOffsetRButton, cc.xy(2, ++rowNumber)); |
680 | |
|
681 | 0 | ButtonGroup group = new ButtonGroup(); |
682 | 0 | group.add(manualOffsetRButton); |
683 | 0 | group.add(defaultPlicyOffsetRButton); |
684 | |
|
685 | |
|
686 | 0 | final Integer[] offsetHours = new Integer[23]; |
687 | 0 | for (int i = 0; i < offsetHours.length; i++) { |
688 | 0 | offsetHours[i] = Integer.valueOf(i - 11); |
689 | |
} |
690 | 0 | final JComboBox hoursOffsetCombo = new JComboBox(offsetHours); |
691 | 0 | hoursOffsetCombo.setSelectedItem(Integer.valueOf(0)); |
692 | 0 | dialog.add(hoursOffsetCombo, cc.xy(3, rowNumber)); |
693 | 0 | final JComboBox minutesOffsetCombo = new JComboBox(minutesOfHour); |
694 | 0 | dialog.add(minutesOffsetCombo, cc.xy(4, rowNumber)); |
695 | |
|
696 | 0 | final JCheckBox yearCheckBox = |
697 | |
new JCheckBox(getFromMap("yearWildcard")); |
698 | 0 | final JCheckBox monthCheckBox = |
699 | |
new JCheckBox(getFromMap("monthOfYearWildcard")); |
700 | 0 | final JCheckBox dayOfCheckBox = |
701 | |
new JCheckBox(getFromMap("dayOfMonthWildcard")); |
702 | 0 | final JCheckBox hourCheckBox = |
703 | |
new JCheckBox(getFromMap("hourOfDayWildcard")); |
704 | 0 | final JCheckBox minuteCheckBox = |
705 | |
new JCheckBox(getFromMap("minuteOfHourWildcard")); |
706 | 0 | final JCheckBox secondOfMinuteCheckBox = |
707 | |
new JCheckBox(getFromMap("secondOfMinuteWildcard")); |
708 | |
|
709 | 0 | dialog.add(yearCheckBox, cc.xyw(2, ++rowNumber, 3)); |
710 | 0 | dialog.add(monthCheckBox, cc.xyw(2, ++rowNumber, 3)); |
711 | 0 | dialog.add(dayOfCheckBox, cc.xyw(2, ++rowNumber, 3)); |
712 | 0 | dialog.add(hourCheckBox, cc.xyw(2, ++rowNumber, 3)); |
713 | 0 | dialog.add(minuteCheckBox, cc.xyw(2, ++rowNumber, 3)); |
714 | 0 | dialog.add(secondOfMinuteCheckBox, cc.xyw(2, ++rowNumber, 3)); |
715 | |
|
716 | 0 | rowNumber += 2; |
717 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("ok")) { |
718 | 0 | public void actionPerformed (ActionEvent e) { |
719 | |
|
720 | 0 | final Calendar selectedTime = Calendar.getInstance(); |
721 | |
|
722 | 0 | final TimeStamp timeStamp = timePicker.getTimeStamp(); |
723 | 0 | if (timeStamp != null) { |
724 | 0 | selectedTime.setTime(timeStamp.getDate()); |
725 | 0 | selectedTime.set( |
726 | |
Calendar.ZONE_OFFSET, |
727 | |
timeStamp.getTimeZone().getRawOffset() |
728 | |
); |
729 | |
} |
730 | |
|
731 | 0 | selectedTime.set( |
732 | |
Calendar.HOUR_OF_DAY, |
733 | |
((Integer) hoursOfDayCombo.getSelectedItem()).intValue() |
734 | |
); |
735 | 0 | selectedTime.set( |
736 | |
Calendar.MINUTE, |
737 | |
((Integer) minutesCombo.getSelectedItem()).intValue() |
738 | |
); |
739 | 0 | selectedTime.set(Calendar.SECOND, 0); |
740 | 0 | selectedTime.set(Calendar.MILLISECOND, 0); |
741 | |
|
742 | |
|
743 | 0 | final PartialTime parialTime = new PartialTime( |
744 | |
yearCheckBox.isSelected() ? |
745 | |
true : false, |
746 | |
selectedTime.get(Calendar.YEAR), |
747 | |
monthCheckBox.isSelected() ? |
748 | |
-1 : selectedTime.get(Calendar.MONTH), |
749 | |
dayOfCheckBox.isSelected() ? |
750 | |
-1 : selectedTime.get(Calendar.DAY_OF_MONTH), |
751 | |
hourCheckBox.isSelected() ? |
752 | |
-1 : ((Integer) hoursOfDayCombo.getSelectedItem()).intValue(), |
753 | |
minuteCheckBox.isSelected() ? |
754 | |
-1 : ((Integer) minutesCombo.getSelectedItem()).intValue(), |
755 | |
secondOfMinuteCheckBox.isSelected() ? |
756 | |
-1 : 0, |
757 | |
manualOffsetRButton.isSelected(), |
758 | |
((Integer) hoursOffsetCombo.getSelectedItem()).intValue(), |
759 | |
((Integer) minutesOffsetCombo.getSelectedItem()).intValue(), |
760 | |
getPresenter().getContext().getPolicyBean().getDateTimeZone(), |
761 | |
true |
762 | |
); |
763 | |
|
764 | 0 | newTerm[0] = new ValueRelationalPredicate( |
765 | |
(Relation) operatorCombo.getSelectedItem(), |
766 | |
new CurrentTime(), |
767 | |
new TimeConstant(parialTime) |
768 | |
); |
769 | 0 | dialog.setVisible(false); |
770 | 0 | } |
771 | |
}), cc.xy(2, rowNumber)); |
772 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("cancel")) { |
773 | |
|
774 | 0 | public void actionPerformed (ActionEvent e) { |
775 | 0 | newTerm[0] = null; |
776 | 0 | dialog.setVisible(false); |
777 | 0 | } |
778 | |
}), cc.xyw(3, rowNumber, 2)); |
779 | 0 | dialog.setVisible(true); |
780 | 0 | } else if (CONDITION_TERM_TYPES[4].equals(termType)) { |
781 | 0 | final JDialog dialog = new JDialog((JFrame) null, true); |
782 | 0 | final FormLayout layout = new FormLayout( |
783 | |
"8dlu, 60dlu, 8dlu, 60dlu, 8dlu", |
784 | |
"8dlu, pref,pref," + |
785 | |
"8dlu, pref," + |
786 | |
"8dlu, pref," + |
787 | |
"8dlu, pref, pref," + |
788 | |
"8dlu, pref," + |
789 | |
"8dlu, pref," + |
790 | |
"8dlu"); |
791 | |
|
792 | 0 | dialog.setLayout(layout); |
793 | 0 | dialog.setSize(new Dimension(300, 500)); |
794 | |
|
795 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
796 | 0 | dialog.setLocation( |
797 | |
(screenSize.width - dialog.getWidth()) / 2, |
798 | |
(screenSize.height - dialog.getHeight()) / 2 |
799 | |
); |
800 | |
|
801 | 0 | int rowNumber = 0; |
802 | 0 | final CellConstraints cc = new CellConstraints(); |
803 | |
|
804 | |
|
805 | 0 | rowNumber += 2; |
806 | 0 | dialog.add(new JLabel(getFromMap("firstSet")), cc.xyw(2, rowNumber, 3)); |
807 | 0 | rowNumber += 1; |
808 | 0 | final List<Value <?>> firstSetValuesList = new ArrayList<Value <?>>(); |
809 | 0 | final DefaultTableModel firstSetModel = makeASetTableModel(firstSetValuesList); |
810 | 0 | JScrollPane scrollPane = new JScrollPane(new HeaderlessJTable(firstSetModel)); |
811 | 0 | scrollPane.setPreferredSize(new Dimension(200, 100)); |
812 | 0 | dialog.add(scrollPane, cc.xyw(2, rowNumber, 3)); |
813 | |
|
814 | |
|
815 | 0 | rowNumber += 2; |
816 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("addValueToSet")) { |
817 | 0 | public void actionPerformed (ActionEvent e) { |
818 | 0 | final Value[] firstOperand = new Value[] { null }; |
819 | 0 | showAValueDialog(firstOperand, null, false); |
820 | 0 | if (firstOperand[0] != null) { |
821 | 0 | firstSetValuesList.add(firstOperand[0]); |
822 | 0 | firstSetModel.fireTableDataChanged(); |
823 | |
} |
824 | 0 | } |
825 | |
}), cc.xyw(2, rowNumber, 3)); |
826 | 0 | final JComboBox operatorCombo = new JComboBox( |
827 | |
ValueSetRelationalPredicate.SetRelation.values() |
828 | |
); |
829 | 0 | rowNumber += 2; |
830 | 0 | dialog.add(operatorCombo, cc.xyw(2, rowNumber, 3)); |
831 | 0 | rowNumber += 2; |
832 | |
|
833 | 0 | dialog.add(new JLabel(getFromMap("secondSet")), cc.xyw(2, rowNumber, 3)); |
834 | 0 | rowNumber += 1; |
835 | 0 | final List<Value <?>> secondSetValuesList = new ArrayList<Value <?>>(); |
836 | 0 | final DefaultTableModel secondSetModel = |
837 | |
makeASetTableModel(secondSetValuesList); |
838 | 0 | JScrollPane scrollPane2 = new JScrollPane(new HeaderlessJTable(secondSetModel)); |
839 | 0 | scrollPane2.setPreferredSize(new Dimension(200, 100)); |
840 | 0 | dialog.add(scrollPane2, cc.xyw(2, rowNumber, 3)); |
841 | |
|
842 | 0 | rowNumber += 2; |
843 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("addValueToSet")) { |
844 | 0 | public void actionPerformed (ActionEvent e) { |
845 | 0 | final Value[] secondOperand = new Value[] { null }; |
846 | 0 | showAValueDialog(secondOperand, null, false); |
847 | 0 | if (secondOperand[0] != null) { |
848 | 0 | secondSetValuesList.add(secondOperand[0]); |
849 | 0 | secondSetModel.fireTableDataChanged(); |
850 | |
} |
851 | 0 | } |
852 | |
}), cc.xyw(2, rowNumber, 3)); |
853 | |
|
854 | 0 | rowNumber += 2; |
855 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("ok")) { |
856 | 0 | public void actionPerformed (ActionEvent e) { |
857 | 0 | newTerm[0] = new ValueSetRelationalPredicate( |
858 | |
(SetRelation) operatorCombo.getSelectedItem(), |
859 | |
new ValueSet(firstSetValuesList), new ValueSet(secondSetValuesList) |
860 | |
); |
861 | 0 | dialog.setVisible(false); |
862 | 0 | } |
863 | |
}), cc.xy(2, rowNumber)); |
864 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("cancel")) { |
865 | |
|
866 | 0 | public void actionPerformed (ActionEvent e) { |
867 | 0 | newTerm[0] = null; |
868 | 0 | dialog.setVisible(false); |
869 | 0 | } |
870 | |
}), cc.xy(4, rowNumber)); |
871 | 0 | dialog.setVisible(true); |
872 | |
} |
873 | 0 | } |
874 | |
|
875 | |
|
876 | |
|
877 | |
|
878 | |
private String[] getNamesOfArgumentsOfGivenType (Class<?> givenType) { |
879 | 0 | List<ParameterList.Parameter> argumentsOfGivenType = |
880 | |
new ArrayList<ParameterList.Parameter>(); |
881 | 0 | for (TargetBean t : getPresenter().getTargets()) { |
882 | 0 | for (ActionBean a : t.getActions()) { |
883 | 0 | for (ParameterList.Parameter p : a.getParameters()) { |
884 | 0 | if (p.getType().equals(givenType)) { |
885 | 0 | argumentsOfGivenType.add(p); |
886 | |
} |
887 | |
} |
888 | |
} |
889 | |
} |
890 | 0 | String[] argumentNames = new String[argumentsOfGivenType.size()]; |
891 | 0 | for (int i = 0; i < argumentsOfGivenType.size(); i++) { |
892 | 0 | argumentNames[i] = argumentsOfGivenType.get(i).getName(); |
893 | |
} |
894 | 0 | return argumentNames; |
895 | |
} |
896 | |
|
897 | |
@SuppressWarnings("serial") |
898 | |
private DefaultTableModel makeASetTableModel (final List<Value<?>> firstSetValuesList) { |
899 | 0 | final DefaultTableModel firstSetModel = new DefaultTableModel() { |
900 | |
public boolean isCellEditable (int row, int column) { |
901 | 0 | return false; |
902 | |
} |
903 | |
|
904 | |
public int getColumnCount () { |
905 | 0 | return 1; |
906 | |
} |
907 | |
|
908 | |
public int getRowCount () { |
909 | 0 | return firstSetValuesList.size(); |
910 | |
} |
911 | |
|
912 | |
@SuppressWarnings("unchecked") |
913 | 0 | public Object getValueAt (int rowIndex, int columnIndex) { |
914 | 0 | final Value value = firstSetValuesList.get(rowIndex); |
915 | 0 | if (value instanceof Constant) { |
916 | 0 | return |
917 | |
value.getType().getSimpleName().toString() + |
918 | |
" " + |
919 | |
((Constant) value).getValue().toString(); |
920 | 0 | } else if (value instanceof Argument) { |
921 | 0 | return |
922 | |
value.getType().getSimpleName().toString() + |
923 | |
" " + |
924 | |
((Argument) value).getName().toString(); |
925 | |
} |
926 | 0 | return null; |
927 | |
} |
928 | |
}; |
929 | 0 | return firstSetModel; |
930 | |
} |
931 | |
|
932 | |
@SuppressWarnings({ "unchecked", "serial" }) |
933 | |
private void showAValueDialog ( |
934 | |
final Value[] newValue, |
935 | |
JComboBox typeCombo, |
936 | |
boolean argumentOnly) { |
937 | |
|
938 | 0 | final JDialog dialog = new JDialog((JFrame) null, true); |
939 | 0 | final FormLayout layout = new FormLayout( |
940 | |
"8dlu, 60dlu, 8dlu, 60dlu, 8dlu", |
941 | |
"8dlu, pref, pref, 8dlu, pref, pref, pref, pref, 8dlu, pref, pref, 8dlu" |
942 | |
); |
943 | |
|
944 | 0 | dialog.setLayout(layout); |
945 | 0 | dialog.setSize(new Dimension(300, 300)); |
946 | |
|
947 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
948 | 0 | dialog.setLocation( |
949 | |
(screenSize.width - dialog.getWidth()) / 2, |
950 | |
(screenSize.height - dialog.getHeight()) / 2 |
951 | |
); |
952 | |
|
953 | 0 | int rowNumber = 2; |
954 | 0 | final CellConstraints cc = new CellConstraints(); |
955 | |
|
956 | 0 | if (typeCombo == null) { |
957 | 0 | dialog.add(new JLabel(getFromMap("valueType")), cc.xyw(2, rowNumber, 3)); |
958 | 0 | typeCombo = new JComboBox(SUPPORTED_TYPES); |
959 | 0 | rowNumber += 1; |
960 | 0 | dialog.add(typeCombo, cc.xyw(2, rowNumber, 3)); |
961 | |
} else { |
962 | 0 | dialog.add(new JLabel(getFromMap("valueType")), cc.xyw(2, rowNumber, 3)); |
963 | 0 | rowNumber += 1; |
964 | 0 | dialog.add(new JLabel(typeCombo.getSelectedItem().toString()), cc.xyw(2, rowNumber, 3)); |
965 | |
} |
966 | |
|
967 | 0 | final JComboBox finalTypeCombo = typeCombo; |
968 | |
|
969 | 0 | rowNumber += 2; |
970 | 0 | final JRadioButton parameterRButton = |
971 | |
new JRadioButton(getFromMap("enterArgumentName")); |
972 | 0 | final JRadioButton valueRButton = |
973 | |
new JRadioButton(getFromMap("enterValueName")); |
974 | 0 | ButtonGroup group = new ButtonGroup(); |
975 | 0 | group.add(parameterRButton); |
976 | 0 | group.add(valueRButton); |
977 | 0 | parameterRButton.setSelected(true); |
978 | 0 | dialog.add(parameterRButton, cc.xyw(2, rowNumber, 3)); |
979 | 0 | rowNumber += 1; |
980 | 0 | final Class type = (Class) typeCombo.getSelectedItem(); |
981 | 0 | final JComboBox argumentsCombo = new JComboBox( |
982 | |
getNamesOfArgumentsOfGivenType(type) |
983 | |
); |
984 | |
|
985 | 0 | final ItemListener typeChangeListener = new ItemListener() { |
986 | 0 | public void itemStateChanged (ItemEvent arg0) { |
987 | 0 | argumentsCombo.setModel( |
988 | |
new DefaultComboBoxModel( |
989 | |
getNamesOfArgumentsOfGivenType((Class) arg0.getItem()) |
990 | |
) |
991 | |
); |
992 | 0 | } |
993 | |
}; |
994 | 0 | finalTypeCombo.addItemListener(typeChangeListener); |
995 | |
|
996 | 0 | dialog.add(argumentsCombo, cc.xyw(2, rowNumber, 3)); |
997 | 0 | rowNumber += 1; |
998 | 0 | dialog.add(valueRButton, cc.xyw(2, rowNumber, 3)); |
999 | 0 | rowNumber += 1; |
1000 | 0 | final JTextField valueField = new JTextField(); |
1001 | 0 | dialog.add(valueField, cc.xyw(2, rowNumber, 3)); |
1002 | 0 | if (argumentOnly) { |
1003 | 0 | valueRButton.setEnabled(false); |
1004 | 0 | valueField.setEnabled(false); |
1005 | |
} |
1006 | |
|
1007 | 0 | rowNumber += 2; |
1008 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("ok")) { |
1009 | |
|
1010 | 0 | public void actionPerformed (ActionEvent e) { |
1011 | |
try { |
1012 | 0 | if (parameterRButton.isSelected()) { |
1013 | 0 | newValue[0] = new Argument( |
1014 | |
argumentsCombo.getSelectedItem().toString(), |
1015 | |
(Class) finalTypeCombo.getSelectedItem() |
1016 | |
); |
1017 | 0 | dialog.setVisible(false); |
1018 | |
} else { |
1019 | 0 | newValue[0] = new Constant( |
1020 | |
((Class) finalTypeCombo.getSelectedItem()). |
1021 | |
getConstructor(String.class).newInstance(valueField.getText()) |
1022 | |
); |
1023 | |
} |
1024 | 0 | finalTypeCombo.setEnabled(false); |
1025 | 0 | } catch (Exception e1) { |
1026 | 0 | LOGGER.info(e1.getMessage()); |
1027 | 0 | JOptionPane.showMessageDialog( |
1028 | |
null, |
1029 | |
getFromMap("invalidValueEntered") |
1030 | |
); |
1031 | 0 | newValue[0] = null; |
1032 | |
} finally { |
1033 | 0 | finalTypeCombo.removeItemListener(typeChangeListener); |
1034 | 0 | } |
1035 | 0 | dialog.setVisible(false); |
1036 | 0 | } |
1037 | |
}), cc.xy(2, rowNumber)); |
1038 | 0 | dialog.add(new JButton(new AbstractAction(getFromMap("cancel")) { |
1039 | |
|
1040 | 0 | public void actionPerformed (ActionEvent e) { |
1041 | 0 | newValue[0] = null; |
1042 | 0 | dialog.setVisible(false); |
1043 | 0 | } |
1044 | |
}), cc.xy(4, rowNumber)); |
1045 | 0 | dialog.setVisible(true); |
1046 | 0 | } |
1047 | |
|
1048 | |
|
1049 | |
|
1050 | |
|
1051 | |
private String getFromMap (String key) { |
1052 | 0 | return getResourceMap().getString(key); |
1053 | |
} |
1054 | |
|
1055 | |
|
1056 | |
|
1057 | |
|
1058 | |
private Predicate createATrue () { |
1059 | 0 | return new ValueRelationalPredicate( |
1060 | |
ValueRelationalPredicate.Relation.Equal, |
1061 | |
new Constant<Integer>(Integer.valueOf(1)), |
1062 | |
new Constant<Integer>(Integer.valueOf(1)) |
1063 | |
); |
1064 | |
} |
1065 | |
|
1066 | |
|
1067 | |
|
1068 | |
|
1069 | |
private Predicate createAFalse () { |
1070 | 0 | return new ValueRelationalPredicate( |
1071 | |
ValueRelationalPredicate.Relation.Equal, |
1072 | |
new Constant<Integer>(Integer.valueOf(0)), |
1073 | |
new Constant<Integer>(Integer.valueOf(1)) |
1074 | |
); |
1075 | |
} |
1076 | |
|
1077 | |
|
1078 | |
|
1079 | |
|
1080 | |
|
1081 | |
|
1082 | |
@Action |
1083 | |
public void addTarget () { |
1084 | 0 | LOGGER.debug("addTarget"); |
1085 | 0 | getPresenter().addTarget( |
1086 | |
new EditPartCommand<TargetBean>(getViewContext())); |
1087 | 0 | } |
1088 | |
|
1089 | |
|
1090 | |
|
1091 | |
|
1092 | |
@Action |
1093 | |
public void removeTarget () { |
1094 | 0 | LOGGER.debug("removeTarget"); |
1095 | 0 | TargetBean activeTarget = this.targetList.getActivePart(); |
1096 | 0 | if (activeTarget != null) { |
1097 | 0 | PolicyBean policy = this.getPresenter().getContext().getPolicyBean(); |
1098 | 0 | List<TargetAccessRuleBean> parents = |
1099 | |
policy.getParentTargetAccessRules(this.targetList.getActivePart()); |
1100 | 0 | if ((parents.size() > 1) |
1101 | |
&& showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) { |
1102 | 0 | return; |
1103 | |
} |
1104 | 0 | getPresenter().removeActiveTarget(activeTarget); |
1105 | 0 | } else { |
1106 | 0 | LOGGER.debug("no part selected"); |
1107 | |
} |
1108 | 0 | } |
1109 | |
|
1110 | |
|
1111 | |
|
1112 | |
|
1113 | |
@Action |
1114 | |
public void editTarget () { |
1115 | 0 | LOGGER.debug("editTarget"); |
1116 | 0 | TargetBean activeTarget = this.targetList.getActivePart(); |
1117 | 0 | if (activeTarget != null) { |
1118 | 0 | editPart(this.targetList.getActivePart()); |
1119 | |
} |
1120 | 0 | } |
1121 | |
|
1122 | |
|
1123 | |
|
1124 | |
|
1125 | |
@Action |
1126 | |
public void addObligation () { |
1127 | 0 | LOGGER.debug("addObligation"); |
1128 | 0 | getPresenter().addObligation( |
1129 | |
new EditPartCommand<ObligationBean>(getViewContext())); |
1130 | 0 | } |
1131 | |
|
1132 | |
|
1133 | |
|
1134 | |
|
1135 | |
@Action |
1136 | |
public void removeObligation () { |
1137 | 0 | LOGGER.debug("removeObligation"); |
1138 | 0 | ObligationBean activeObligation = this.obligationList.getActivePart(); |
1139 | 0 | if (activeObligation != null) { |
1140 | 0 | PolicyBean policy = this.getPresenter().getContext().getPolicyBean(); |
1141 | 0 | List<TargetAccessRuleBean> parents = |
1142 | |
policy.getParentTargetAccessRules(this.obligationList.getActivePart()); |
1143 | 0 | if ((parents.size() > 1) |
1144 | |
&& showYesNoDialog("nRefsTitle", "nRefs", JOptionPane.NO_OPTION)) { |
1145 | 0 | return; |
1146 | |
} |
1147 | 0 | getPresenter().removeActiveObligation(activeObligation); |
1148 | 0 | } else { |
1149 | 0 | LOGGER.debug("no part selected"); |
1150 | |
} |
1151 | 0 | } |
1152 | |
|
1153 | |
|
1154 | |
|
1155 | |
|
1156 | |
@Action |
1157 | |
public void editObligation () { |
1158 | 0 | LOGGER.debug("editObligation"); |
1159 | 0 | ObligationBean activeObligation = this.obligationList.getActivePart(); |
1160 | 0 | if (activeObligation != null) { |
1161 | 0 | editPart(this.obligationList.getActivePart()); |
1162 | |
} |
1163 | 0 | } |
1164 | |
|
1165 | |
|
1166 | |
|
1167 | |
|
1168 | |
|
1169 | |
@Action |
1170 | |
|
1171 | |
public void add () { |
1172 | 0 | LOGGER.debug("add"); |
1173 | 0 | final TreePath selectionPath = this.conditionTree.getSelectionPath(); |
1174 | 0 | if (selectionPath == null) { |
1175 | 0 | JOptionPane.showMessageDialog(null, getFromMap("noTermSelected")); |
1176 | 0 | return; |
1177 | |
} |
1178 | |
|
1179 | 0 | final Object rootTerm = |
1180 | |
((TermNode) this.conditionTree.getModel().getRoot()).getTerm(); |
1181 | 0 | final Object selectedTerm = |
1182 | |
((TermNode) selectionPath.getLastPathComponent()).getTerm(); |
1183 | |
|
1184 | 0 | if (selectedTerm instanceof And || selectedTerm instanceof Or) { |
1185 | 0 | getPresenter().updateConditionAtModel((Predicate) add(rootTerm, selectedTerm)); |
1186 | |
} else { |
1187 | 0 | JOptionPane.showMessageDialog(null, getFromMap("termAdditionNotAllowed")); |
1188 | |
} |
1189 | 0 | } |
1190 | |
|
1191 | |
|
1192 | |
|
1193 | |
|
1194 | |
|
1195 | |
|
1196 | |
@Action |
1197 | |
public void remove () { |
1198 | 0 | LOGGER.debug("remove"); |
1199 | 0 | final TreePath selectionPath = this.conditionTree.getSelectionPath(); |
1200 | 0 | if (selectionPath == null) { |
1201 | 0 | return; |
1202 | |
} |
1203 | |
|
1204 | 0 | if ( |
1205 | |
((TermNode) this.conditionTree.getModel().getRoot()). |
1206 | |
getTerm().equals(Predicate.TRUE) |
1207 | |
) { |
1208 | 0 | JOptionPane.showMessageDialog(null, getFromMap("termDeletionNotAllowed")); |
1209 | |
} else { |
1210 | 0 | getPresenter().updateConditionAtModel( |
1211 | |
(Predicate) remove( |
1212 | |
((TermNode) this.conditionTree.getModel(). |
1213 | |
getRoot()).getTerm(), |
1214 | |
((TermNode) selectionPath.getLastPathComponent()).getTerm() |
1215 | |
) |
1216 | |
); |
1217 | |
} |
1218 | 0 | } |
1219 | |
|
1220 | |
|
1221 | |
|
1222 | |
|
1223 | |
|
1224 | |
@Action |
1225 | |
|
1226 | |
public void edit () { |
1227 | 0 | LOGGER.debug("edit"); |
1228 | 0 | final TreePath selectionPath = this.conditionTree.getSelectionPath(); |
1229 | 0 | if (selectionPath == null) { |
1230 | 0 | JOptionPane.showMessageDialog(null, getFromMap("noTermSelected")); |
1231 | 0 | return; |
1232 | |
} |
1233 | |
|
1234 | 0 | final Object rootTerm = |
1235 | |
((TermNode) this.conditionTree.getModel().getRoot()).getTerm(); |
1236 | 0 | final Object selectedTerm = |
1237 | |
((TermNode) selectionPath.getLastPathComponent()).getTerm(); |
1238 | |
|
1239 | 0 | if ( |
1240 | |
selectedTerm instanceof And || |
1241 | |
selectedTerm instanceof Or || |
1242 | |
selectedTerm instanceof Not || |
1243 | |
selectedTerm.equals(Predicate.TRUE) || |
1244 | |
selectedTerm.equals(Predicate.FALSE) |
1245 | |
) { |
1246 | 0 | getPresenter().updateConditionAtModel((Predicate) edit(rootTerm, selectedTerm)); |
1247 | |
} else { |
1248 | 0 | JOptionPane.showMessageDialog(null, getFromMap("termEditingNotAllowed")); |
1249 | |
} |
1250 | 0 | } |
1251 | |
|
1252 | |
|
1253 | |
|
1254 | |
|
1255 | |
|
1256 | |
|
1257 | |
|
1258 | |
@PropertyChange(bean = TargetAccessRulePresenter.class) |
1259 | |
public void updateState () { |
1260 | 0 | final Predicate condition = getPresenter().getCondition(); |
1261 | 0 | this.conditionTree.getSelectionModel().setSelectionMode( |
1262 | |
TreeSelectionModel.SINGLE_TREE_SELECTION |
1263 | |
); |
1264 | 0 | this.conditionTree.setModel( |
1265 | |
new DefaultTreeModel(new TermNode(condition, condition, null)) |
1266 | |
); |
1267 | |
|
1268 | 0 | for (int i = 0; i < this.conditionTree.getRowCount(); i++) { |
1269 | 0 | this.conditionTree.expandRow(i); |
1270 | |
} |
1271 | 0 | } |
1272 | |
|
1273 | |
|
1274 | |
|
1275 | |
|
1276 | |
|
1277 | |
|
1278 | |
@Override |
1279 | |
protected void bind (BindingGroup bindings) { |
1280 | 0 | this.targetList.bind( |
1281 | |
getPresenter().getTargetPool().getPoolList(), |
1282 | |
getPresenter().getTargets() |
1283 | |
); |
1284 | 0 | this.roleList.bind( |
1285 | |
getPresenter().getRolePool().getPoolList(), |
1286 | |
getPresenter().getRoles() |
1287 | |
); |
1288 | 0 | this.obligationList.bind( |
1289 | |
getPresenter().getObligationPool().getPoolList(), |
1290 | |
getPresenter().getObligations() |
1291 | |
); |
1292 | 0 | getPresenter().addPropertyChangeListener( |
1293 | |
this.propertyChangeListener |
1294 | |
); |
1295 | 0 | } |
1296 | |
|
1297 | |
|
1298 | |
|
1299 | |
|
1300 | |
|
1301 | |
|
1302 | |
private JComponent roleList () { |
1303 | 0 | final FormLayout layout = new FormLayout( |
1304 | |
"pref, fill:pref:grow", |
1305 | |
"pref, fill:pref:grow" |
1306 | |
); |
1307 | 0 | final JPanel panel = new JPanel(); |
1308 | 0 | panel.setLayout(layout); |
1309 | 0 | final CellConstraints cc = new CellConstraints(); |
1310 | 0 | panel.add(label("roles"), cc.xy(1, 1)); |
1311 | 0 | panel.add(toolBar("roleToolBar"), cc.xy(2, 1)); |
1312 | 0 | this.roleList.setVisibleRowCount(5); |
1313 | 0 | panel.add(new JScrollPane(this.roleList), cc.xyw(1, 2, 2)); |
1314 | 0 | return panel; |
1315 | |
} |
1316 | |
|
1317 | |
|
1318 | |
|
1319 | |
|
1320 | |
private JComponent targetList () { |
1321 | 0 | final FormLayout layout = new FormLayout( |
1322 | |
"pref, fill:pref:grow", |
1323 | |
"pref, fill:pref:grow" |
1324 | |
); |
1325 | 0 | final JPanel panel = new JPanel(); |
1326 | 0 | panel.setLayout(layout); |
1327 | 0 | final CellConstraints cc = new CellConstraints(); |
1328 | 0 | panel.add(label("targets"), cc.xy(1, 1)); |
1329 | 0 | panel.add(toolBar("targetToolBar"), cc.xy(2, 1)); |
1330 | 0 | this.targetList.setVisibleRowCount(5); |
1331 | 0 | panel.add(new JScrollPane(this.targetList), cc.xyw(1, 2, 2)); |
1332 | 0 | return panel; |
1333 | |
} |
1334 | |
|
1335 | |
|
1336 | |
|
1337 | |
|
1338 | |
private JComponent obligationList () { |
1339 | 0 | final FormLayout layout = new FormLayout( |
1340 | |
"pref, fill:pref:grow", |
1341 | |
"pref, fill:pref:grow" |
1342 | |
); |
1343 | 0 | final JPanel panel = new JPanel(); |
1344 | 0 | panel.setLayout(layout); |
1345 | 0 | final CellConstraints cc = new CellConstraints(); |
1346 | 0 | panel.add(label("obligations"), cc.xy(1, 1)); |
1347 | 0 | panel.add(toolBar("obligationToolBar"), cc.xy(2, 1)); |
1348 | 0 | this.obligationList.setVisibleRowCount(5); |
1349 | 0 | panel.add(new JScrollPane(this.obligationList), cc.xyw(1, 2, 2)); |
1350 | 0 | return panel; |
1351 | |
} |
1352 | |
|
1353 | |
|
1354 | |
|
1355 | |
|
1356 | |
@SuppressWarnings("unused") |
1357 | |
private JComponent predicateXml () { |
1358 | 0 | final FormLayout layout = new FormLayout( |
1359 | |
"pref, fill:pref:grow", |
1360 | |
"pref, fill:pref:grow" |
1361 | |
); |
1362 | 0 | final JPanel panel = new JPanel(); |
1363 | 0 | panel.setLayout(layout); |
1364 | 0 | final CellConstraints cc = new CellConstraints(); |
1365 | |
|
1366 | 0 | final Predicate condition = getPresenter().getCondition(); |
1367 | 0 | if (!condition.equals(Predicate.TRUE)) { |
1368 | 0 | final StringWriter stringWriter = new StringWriter(); |
1369 | 0 | final PrettyPrinterXmlWriter xmlWriter = |
1370 | |
new PrettyPrinterXmlWriter(new SimpleXmlWriter(stringWriter)); |
1371 | 0 | final PermisXmlWriter permisXmlWriter = new PermisXmlWriter(stringWriter); |
1372 | |
try { |
1373 | 0 | permisXmlWriter.writeCondition(condition, xmlWriter); |
1374 | 0 | } catch (IOException e) { |
1375 | 0 | LOGGER.error(e.getMessage()); |
1376 | 0 | } |
1377 | 0 | panel.add(new JTextArea(stringWriter.getBuffer().toString()), cc.xy(1, 1)); |
1378 | 0 | } else { |
1379 | 0 | panel.add(new JTextArea(), cc.xy(1, 1)); |
1380 | |
} |
1381 | |
|
1382 | 0 | return panel; |
1383 | |
} |
1384 | |
|
1385 | |
|
1386 | |
|
1387 | |
|
1388 | |
private JComponent predicateTree () { |
1389 | 0 | final FormLayout layout = new FormLayout( |
1390 | |
"pref, fill:pref:grow", |
1391 | |
"pref, fill:pref:grow" |
1392 | |
); |
1393 | 0 | final JPanel panel = new JPanel(); |
1394 | 0 | panel.setLayout(layout); |
1395 | 0 | final CellConstraints cc = new CellConstraints(); |
1396 | 0 | panel.add(label("terms"), cc.xy(1, 1)); |
1397 | 0 | panel.add(toolBar("termsToolBar"), cc.xy(2, 1)); |
1398 | 0 | updateState(); |
1399 | 0 | panel.add(new JScrollPane(this.conditionTree), cc.xyw(1, 2, 2)); |
1400 | |
|
1401 | 0 | return panel; |
1402 | |
} |
1403 | |
|
1404 | |
|
1405 | |
|
1406 | |
|
1407 | |
public void fillContentPane (JPanel panel) { |
1408 | 0 | final FormLayout layout = new FormLayout( |
1409 | |
"8dlu, fill:pref:grow, 8dlu", |
1410 | |
"8dlu, pref, 8dlu, pref, 8dlu, pref, 8dlu, fill:pref:grow, 8dlu" |
1411 | |
); |
1412 | |
|
1413 | 0 | panel.setLayout(layout); |
1414 | 0 | final CellConstraints cc = new CellConstraints(); |
1415 | 0 | this.roleList = new CheckList<Role>(); |
1416 | 0 | this.roleList.setDoubleClickAction(getActionMap().get("editRole")); |
1417 | 0 | this.roleList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
1418 | |
|
1419 | 0 | this.targetList = new CheckList<TargetBean>(); |
1420 | 0 | this.targetList.setDoubleClickAction(getActionMap().get("editTarget")); |
1421 | 0 | this.targetList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
1422 | 0 | this.targetList.setItemRenderer( |
1423 | |
RendererFactory.createTableCellRenderer(this.getAdapteeTrader(), Overview.class) |
1424 | |
); |
1425 | |
|
1426 | 0 | this.obligationList = new CheckList<ObligationBean>(); |
1427 | 0 | this.obligationList.setDoubleClickAction(getActionMap().get("editObligation")); |
1428 | 0 | this.obligationList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
1429 | 0 | this.obligationList.setItemRenderer( |
1430 | |
RendererFactory.createTableCellRenderer(this.getAdapteeTrader(), Overview.class) |
1431 | |
); |
1432 | |
|
1433 | 0 | panel.add(targetList(), cc.xy(2, 2)); |
1434 | 0 | panel.add(roleList(), cc.xy(2, 4)); |
1435 | 0 | panel.add(obligationList(), cc.xy(2, 6)); |
1436 | 0 | panel.add(predicateTree(), cc.xy(2, 8)); |
1437 | 0 | } |
1438 | |
|
1439 | |
|
1440 | |
|
1441 | |
|
1442 | |
|
1443 | |
|
1444 | |
public void ancestorAdded (AncestorEvent event) { |
1445 | |
|
1446 | 0 | } |
1447 | |
|
1448 | |
|
1449 | |
|
1450 | |
|
1451 | |
public void ancestorMoved (AncestorEvent event) { |
1452 | |
|
1453 | 0 | } |
1454 | |
|
1455 | |
|
1456 | |
|
1457 | |
|
1458 | |
public void ancestorRemoved (AncestorEvent event) { |
1459 | 0 | getPresenter().removePropertyChangeListener( |
1460 | |
this.propertyChangeListener |
1461 | |
); |
1462 | 0 | } |
1463 | |
} |
1464 | |
|
1465 | |
|
1466 | |
|
1467 | |
|
1468 | |
class TermNode implements TreeNode { |
1469 | |
|
1470 | |
|
1471 | |
|
1472 | |
|
1473 | |
private TermNode parent; |
1474 | |
|
1475 | |
|
1476 | |
|
1477 | |
|
1478 | |
private Object term; |
1479 | |
|
1480 | |
|
1481 | |
|
1482 | |
|
1483 | |
private List<TermNode> children; |
1484 | |
|
1485 | |
|
1486 | |
|
1487 | |
|
1488 | |
private Object rootTerm; |
1489 | |
|
1490 | |
|
1491 | |
|
1492 | |
|
1493 | 0 | private StringBuffer stringBuffer = new StringBuffer(); |
1494 | |
|
1495 | |
|
1496 | |
|
1497 | |
|
1498 | |
|
1499 | |
|
1500 | |
public TermNode ( |
1501 | |
Object rootTerm, |
1502 | |
Object term, |
1503 | |
TermNode parent |
1504 | 0 | ) { |
1505 | 0 | this.term = term; |
1506 | 0 | this.parent = parent; |
1507 | 0 | this.rootTerm = rootTerm; |
1508 | 0 | this.children = new ArrayList<TermNode>(); |
1509 | 0 | if (term instanceof AbstractPredicate) { |
1510 | 0 | final List<?> operands = |
1511 | |
new ArrayList<Object>(((AbstractPredicate<?>) this.term).getOperands()); |
1512 | 0 | for (Object r : operands) { |
1513 | 0 | this.children.add(new TermNode(this.rootTerm, r, this)); |
1514 | |
} |
1515 | |
} |
1516 | 0 | } |
1517 | |
|
1518 | |
|
1519 | |
|
1520 | |
|
1521 | |
|
1522 | |
|
1523 | |
public Enumeration<TermNode> children () { |
1524 | 0 | return Collections.enumeration(this.children); |
1525 | |
} |
1526 | |
|
1527 | |
|
1528 | |
|
1529 | |
|
1530 | |
public boolean getAllowsChildren () { |
1531 | 0 | return true; |
1532 | |
} |
1533 | |
|
1534 | |
|
1535 | |
|
1536 | |
|
1537 | |
public TreeNode getChildAt (int childIndex) { |
1538 | 0 | return this.children.get(childIndex); |
1539 | |
} |
1540 | |
|
1541 | |
|
1542 | |
|
1543 | |
|
1544 | |
public int getChildCount () { |
1545 | 0 | return this.children.size(); |
1546 | |
} |
1547 | |
|
1548 | |
|
1549 | |
|
1550 | |
|
1551 | |
public int getIndex (TreeNode node) { |
1552 | 0 | return this.children.indexOf(node); |
1553 | |
} |
1554 | |
|
1555 | |
|
1556 | |
|
1557 | |
|
1558 | |
public TreeNode getParent () { |
1559 | 0 | return this.parent; |
1560 | |
} |
1561 | |
|
1562 | |
|
1563 | |
|
1564 | |
|
1565 | |
public boolean isLeaf () { |
1566 | 0 | return this.children.size() == 0; |
1567 | |
} |
1568 | |
|
1569 | |
|
1570 | |
|
1571 | |
|
1572 | |
public Object getTerm () { |
1573 | 0 | return this.term; |
1574 | |
} |
1575 | |
|
1576 | |
|
1577 | |
|
1578 | |
|
1579 | |
@SuppressWarnings("unchecked") |
1580 | |
@Override |
1581 | |
public String toString () { |
1582 | 0 | if (this.term instanceof And) { |
1583 | 0 | return "AND"; |
1584 | 0 | } else if (this.term instanceof Or) { |
1585 | 0 | return "OR"; |
1586 | 0 | } else if (this.term instanceof Not) { |
1587 | 0 | return "NOT"; |
1588 | 0 | } else if (this.term instanceof Present) { |
1589 | 0 | return "IS PRESENT"; |
1590 | 0 | } else if (this.term instanceof ValueRelationalPredicate) { |
1591 | 0 | return ((ValueRelationalPredicate) this.term).getRelation().toString(); |
1592 | 0 | } else if (this.term instanceof ValueSetRelationalPredicate) { |
1593 | 0 | return ((ValueSetRelationalPredicate) this.term).getRelation().toString(); |
1594 | 0 | } else if (this.term instanceof SubstringOf) { |
1595 | 0 | return "SUBSTRING OF"; |
1596 | 0 | } else if (this.term instanceof Constant) { |
1597 | 0 | return ((Constant) this.term).getValue().toString(); |
1598 | 0 | } else if (this.term instanceof Argument) { |
1599 | 0 | return ((Argument) this.term).getName().toString(); |
1600 | 0 | } else if (this.term instanceof CurrentTime) { |
1601 | 0 | return "CURRENT TIME"; |
1602 | 0 | } else if (this.term instanceof ValueSet) { |
1603 | 0 | final List<Value<?>> values = ((ValueSet) this.term).getValues(); |
1604 | 0 | this.stringBuffer.setLength(0); |
1605 | 0 | this.stringBuffer.append("VALUE SET ("); |
1606 | 0 | for (Value v : values) { |
1607 | 0 | if (v instanceof Argument) { |
1608 | 0 | this.stringBuffer.append("ARGUMENT " + ((Argument<?>) v).getName() + " "); |
1609 | 0 | } else if (v instanceof Constant) { |
1610 | 0 | this.stringBuffer.append("CONSTANT " + ((Constant<?>) v).getValue() + " "); |
1611 | |
} else { |
1612 | 0 | this.stringBuffer.append(v + " "); |
1613 | |
} |
1614 | |
} |
1615 | 0 | this.stringBuffer.append(")"); |
1616 | 0 | return this.stringBuffer.toString(); |
1617 | 0 | } else if (this.term.equals(Predicate.TRUE)) { |
1618 | 0 | return "TRUE"; |
1619 | 0 | } else if (this.term.equals(Predicate.FALSE)) { |
1620 | 0 | return "FALSE"; |
1621 | |
} else { |
1622 | 0 | return this.term.toString(); |
1623 | |
} |
1624 | |
} |
1625 | |
|
1626 | |
} |
1627 | |
|
1628 | |
@SuppressWarnings("serial") |
1629 | |
class HeaderlessJTable extends JTable { |
1630 | |
|
1631 | |
|
1632 | |
|
1633 | |
|
1634 | |
|
1635 | |
|
1636 | |
|
1637 | |
public HeaderlessJTable (TableModel dm) { |
1638 | 0 | super(dm); |
1639 | 0 | } |
1640 | |
|
1641 | |
|
1642 | |
|
1643 | |
|
1644 | |
|
1645 | |
|
1646 | |
protected void configureEnclosingScrollPane () { |
1647 | 0 | Container p = getParent(); |
1648 | 0 | if (p instanceof JViewport) { |
1649 | 0 | Container gp = p.getParent(); |
1650 | 0 | if (gp instanceof JScrollPane) { |
1651 | 0 | JScrollPane scrollPane = (JScrollPane) gp; |
1652 | 0 | JViewport viewport = scrollPane.getViewport(); |
1653 | 0 | if (viewport == null || viewport.getView() != this) { |
1654 | 0 | return; |
1655 | |
} |
1656 | 0 | Border border = scrollPane.getBorder(); |
1657 | 0 | if (border == null || border instanceof UIResource) { |
1658 | 0 | scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder")); |
1659 | |
} |
1660 | |
} |
1661 | |
} |
1662 | 0 | } |
1663 | |
} |
1664 | |
|
1665 | |
|