1 package fr.ifremer.dali.ui.swing.content.manage.rule.rulelist;
2
3 import fr.ifremer.dali.ui.swing.DaliHelpBroker;
4 import fr.ifremer.dali.ui.swing.DaliUIContext;
5 import fr.ifremer.dali.ui.swing.util.DaliUI;
6 import fr.ifremer.quadrige3.ui.swing.ApplicationUI;
7 import fr.ifremer.quadrige3.ui.swing.ApplicationUIUtil;
8 import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
9 import java.awt.BorderLayout;
10 import java.awt.Component;
11 import java.awt.Container;
12 import java.awt.LayoutManager;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.awt.event.MouseEvent;
16 import java.awt.event.MouseListener;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.TreeMap;
22 import javax.swing.BorderFactory;
23 import javax.swing.Box;
24 import javax.swing.BoxLayout;
25 import javax.swing.JButton;
26 import javax.swing.JMenuItem;
27 import javax.swing.JPanel;
28 import javax.swing.JPopupMenu;
29 import javax.swing.JScrollPane;
30 import jaxx.runtime.JAXXBinding;
31 import jaxx.runtime.JAXXContext;
32 import jaxx.runtime.JAXXObject;
33 import jaxx.runtime.JAXXObjectDescriptor;
34 import jaxx.runtime.JAXXUtil;
35 import jaxx.runtime.SwingUtil;
36 import jaxx.runtime.binding.DefaultJAXXBinding;
37 import jaxx.runtime.context.DefaultJAXXContext;
38 import jaxx.runtime.swing.help.JAXXHelpUI;
39 import org.apache.commons.logging.Log;
40 import org.apache.commons.logging.LogFactory;
41 import static org.nuiton.i18n.I18n.t;
42
43 public class RuleListUI extends JPanel implements JAXXHelpUI<DaliHelpBroker>, DaliUI<RuleListUIModel, RuleListUIHandler>, JAXXObject {
44
45
46
47
48
49 public static final String BINDING_DELETE_RULE_LIST_BUTTON_ENABLED = "deleteRuleListButton.enabled";
50 public static final String BINDING_DUPLICATE_RULE_LIST_BUTTON_ENABLED = "duplicateRuleListButton.enabled";
51 public static final String BINDING_EDIT_RULE_LIST_CODE_ENABLED = "editRuleListCode.enabled";
52 public static final String BINDING_NEW_RULE_LIST_BUTTON_ENABLED = "newRuleListButton.enabled";
53
54
55
56
57
58 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAK1Wz28bRRQeu3bSOKE/EpK0aiBOKG1yGVP1hEIgv9VETqnqVIrIoYx3p86ksz+6OxvbWEGIfwCOHOHOBYkbJ8SBMwcuiH8BIQ5cK96btXe9ydpxGyx5tJ553zfvfTPf837/F8n7Hpk7Yo0G9QJbCYvTndX9/Y+rR9xQG9w3POEqxyPhJ5Ml2QMyakbzviLvHJQRXmrDS+uO5To2t7vQS2VS8FVTcv+Qc6XIW0mE4fulSrS81HADr8MaJZXG+u0/f2e/Nr/4LktIw4XsxqCU4nmouJJcmWSFqcg47HTMSpLZNUjDE3YN8n0D59Yl8/2HzOIvyOdkuEyGXOYBmSLzg5esOTS+4SpS8ALJy8JXT7YVWXnmUfHM4xb3qMmkoIGgfh32p4ZjK6CjFrNZjVME6UECkj6OKFxXMw8pkrcck0tFNi9KuYs8Me9Q1XOec0+Ruz2JN+DXA8Cs6cgYeh3Z/T1WlfzJ9iNmY3rTqGqjDdypGJ4jJS4hZCRCFhSCHjluAIpNJSB6cpfbQbzPNW4K1SlgHdJXZDKBwfBtxS2Mn4xgY93pKUK76nsRMNMTNX4/LlJnRCv4rCFIMh5xXb69owt8Dy5TMl2cTRbXib2Hv4s4vB1LZvN6p5K1QCk4MjKRIAxnMXwuQk2bgSuFwRRPYnH53WTom3C4vF+cR24lDATWpLE1Y+9kDkheC6jIjYOzbsYNQh/fOOVjJNSrL6cmfv/pzx+3Oua9AntPpoZ29R4wles5LlxIgVtfDZ0bKCFLu8xdOiAjPhRohI1pJiWxSnsZkoP9riOcIpw+YP4hUOSH//j5l6lPf7tEslukIB1mbjGM3yYj6tADFRxpNtyPVnRGY/XLMF6Dbxad4ngmOmW1taafQmCTGh6Ho9kTSnIzXFlQC/PaQ5EJ8TCowpD5xcUTKOzpMaybDAjKrIrOmW31BZ00QOuZFK2jgqsjv/47UflhpaN3Buq/2TM81jz/CRkSthQ21+2y3QlT2+Oo6/PAdOKOl9YDSaIJum0fl/R4/4ywOYgGHYVjb2MDI5eYCR07p3gDuvBVrYfhWJZjU7COIqPKceSecPd6rA9zG90LFNMt3TGp8CvsmG+G0wuoIybyvhYIn5ZImi3PSzsPjeApc0NbQvKrugQ8xY3TXg2XqIESnZyqNmc4bjMq95YuJ1ynkeepDC9IsvT59Niua+N2q/G8rUaNq/AGcPOxU/cXFqkvPuMLi8Xl5eK94p07xTgM2pHkXcEQK/xNaMVICYgoeBCFe7Ww19V5prWRaHT9RB4Ke2Ik83j3remsJdVNDYnVPGrN9ZITJLJc1ezW538XM7XJv6rRcviveurqJTsPBoR/t0lxZvvEnr5337T6aVCcWy7agZSvqVXP4Ie8jsm8qq5nXjTO0zQDl0uypgMHQK58AN2cFavCNiGnD8/wZ3AsnMuI0w0cmukMswPkVIDzqdkWvAzu92G6PVAuX/ZhuHthhsUBqskJI3yF6cFxc6AsvrqwEv0YBlOiHwMq8R9/65ierQ0AAA==";
59 private static final Log log = LogFactory.getLog(RuleListUI.class);
60 private static final long serialVersionUID = 1L;
61
62
63
64
65
66 protected List<Object> $activeBindings = new ArrayList<Object>();
67 protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
68 protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
69 protected Map<String, Object> $objectMap = new HashMap<String, Object>();
70 protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
71 private boolean allComponentsCreated;
72 protected final JAXXContext delegateContext = new DefaultJAXXContext();
73
74
75
76
77
78 protected DaliHelpBroker broker;
79 protected JButton deleteRuleListButton;
80 protected JButton duplicateRuleListButton;
81 protected JMenuItem editRuleListCode;
82 protected final RuleListUIHandler handler = createHandler();
83 protected RuleListUIModel model;
84 protected JButton newRuleListButton;
85 protected RuleListUI ruleListUI = this;
86 protected SwingTable rulesTableUI;
87 protected JScrollPane rulesTableUIPanel;
88 protected JPopupMenu tablePopup;
89
90
91
92
93
94 private JPanel $JPanel0;
95 private JPanel $JPanel1;
96
97
98
99
100
101 public RuleListUI(ApplicationUI parentUI) {
102 ApplicationUIUtil.setParentUI(this, parentUI);
103 $initialize();
104 }
105
106 public RuleListUI() {
107 $initialize();
108 }
109
110 public RuleListUI(JAXXContext parentContext) {
111 JAXXUtil.initContext(this, parentContext);
112 $initialize();
113 }
114
115 public RuleListUI(boolean param0) {
116 super(param0);
117 $initialize();
118 }
119
120 public RuleListUI(JAXXContext parentContext, boolean param1) {
121 super(param1);
122 JAXXUtil.initContext(this, parentContext);
123 $initialize();
124 }
125
126 public RuleListUI(LayoutManager param0) {
127 super(param0);
128 $initialize();
129 }
130
131 public RuleListUI(JAXXContext parentContext, LayoutManager param1) {
132 super(param1);
133 JAXXUtil.initContext(this, parentContext);
134 $initialize();
135 }
136
137 public RuleListUI(LayoutManager param0, boolean param1) {
138 super(param0 ,param1);
139 $initialize();
140 }
141
142 public RuleListUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
143 super(param1 ,param2);
144 JAXXUtil.initContext(this, parentContext);
145 $initialize();
146 }
147
148
149
150
151
152 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
153 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
154 }
155
156
157
158
159
160 @Override
161 public void applyDataBinding(String $binding) {
162 if (allComponentsCreated && $bindings.containsKey($binding)) {
163 getDataBinding($binding).applyDataBinding();
164 }
165 processDataBinding($binding);
166 }
167
168 @Override
169 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
170 super.firePropertyChange(propertyName, oldValue, newValue);
171 }
172
173 @Override
174 public Map<String, Object> get$objectMap() {
175 return $objectMap;
176 }
177
178 @Override
179 public JAXXBinding getDataBinding(String bindingId) {
180 return $bindings.get(bindingId);
181 }
182
183 @Override
184 public JAXXBinding[] getDataBindings() {
185 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
186 }
187
188 @Override
189 public Object getObjectById(String id) {
190 return $objectMap.get(id);
191 }
192
193 @Override
194 public void processDataBinding(String $binding, boolean $force) {
195 if (!$force && $activeBindings.contains($binding)) {
196 return;
197 }
198 $activeBindings.add($binding);
199 try {
200 if (allComponentsCreated && $bindings.containsKey($binding)) {
201 getDataBinding($binding).processDataBinding();
202 }
203 } finally {
204 $activeBindings.remove($binding);
205 }
206 }
207
208 @Override
209 public void processDataBinding(String $binding) {
210 processDataBinding($binding, false);
211 }
212
213 @Override
214 public void registerDataBinding(JAXXBinding binding) {
215 $bindings.put(binding.getId(), binding);
216 }
217
218 @Override
219 public void removeDataBinding(String $binding) {
220 if (allComponentsCreated && $bindings.containsKey($binding)) {
221 getDataBinding($binding).removeDataBinding();
222 }
223 }
224
225
226
227
228
229 @Override
230 public <T> T getContextValue(Class<T> clazz) {
231 return delegateContext.getContextValue(clazz, null);
232 }
233
234 @Override
235 public <T> T getContextValue(Class<T> clazz, String name) {
236 return delegateContext.getContextValue(clazz, name);
237 }
238
239 @Override
240 public JAXXContext getDelegateContext() {
241 return delegateContext;
242 }
243
244 @Override
245 public <O extends Container> O getParentContainer(Class<O> clazz) {
246 return SwingUtil.getParentContainer(this, clazz);
247 }
248
249 @Override
250 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
251 return SwingUtil.getParentContainer(source, clazz);
252 }
253
254 @Override
255 public <T> void removeContextValue(Class<T> clazz) {
256 delegateContext.removeContextValue(clazz, null);
257 }
258
259 @Override
260 public <T> void removeContextValue(Class<T> clazz, String name) {
261 delegateContext.removeContextValue(clazz, name);
262 }
263
264 @Override
265 public <T> void setContextValue(T o) {
266 delegateContext.setContextValue(o, null);
267 }
268
269 @Override
270 public <T> void setContextValue(T o, String name) {
271 delegateContext.setContextValue(o, name);
272 }
273
274
275
276
277
278 public void doActionPerformed__on__editRuleListCode(ActionEvent event) {
279 if (log.isDebugEnabled()) {
280 log.debug(event);
281 }
282 handler.editRuleListCode();
283 }
284
285 public void doActionPerformed__on__newRuleListButton(ActionEvent event) {
286 if (log.isDebugEnabled()) {
287 log.debug(event);
288 }
289 model.addNewRow();
290 }
291
292 public void doMouseClicked__on__rulesTableUI(MouseEvent event) {
293 if (log.isDebugEnabled()) {
294 log.debug(event);
295 }
296 handler.autoSelectRowInTable(event, tablePopup);
297 }
298
299
300
301
302
303 public DaliHelpBroker getBroker() {
304 return broker;
305 }
306
307 public JButton getDeleteRuleListButton() {
308 return deleteRuleListButton;
309 }
310
311 public JButton getDuplicateRuleListButton() {
312 return duplicateRuleListButton;
313 }
314
315 public JMenuItem getEditRuleListCode() {
316 return editRuleListCode;
317 }
318
319 public RuleListUIHandler getHandler() {
320 return handler;
321 }
322
323 public RuleListUIModel getModel() {
324 return model;
325 }
326
327 public JButton getNewRuleListButton() {
328 return newRuleListButton;
329 }
330
331 public SwingTable getRulesTableUI() {
332 return rulesTableUI;
333 }
334
335 public JScrollPane getRulesTableUIPanel() {
336 return rulesTableUIPanel;
337 }
338
339 public JPopupMenu getTablePopup() {
340 return tablePopup;
341 }
342
343
344
345
346
347 @Override
348 public void registerHelpId(DaliHelpBroker broker, Component component, String helpId) {
349 broker.installUI(component, helpId);
350 }
351
352 @Override
353 public void showHelp(String helpId) {
354 getBroker().showHelp(this, helpId);
355 }
356
357
358
359
360
361 protected JPanel get$JPanel0() {
362 return $JPanel0;
363 }
364
365 protected JPanel get$JPanel1() {
366 return $JPanel1;
367 }
368
369
370
371
372
373 protected void addChildrenToRuleListUI() {
374 if (!allComponentsCreated) {
375 return;
376 }
377 add(rulesTableUIPanel);
378 add($JPanel0, BorderLayout.PAGE_END);
379 }
380
381 protected void addChildrenToRulesTableUIPanel() {
382 if (!allComponentsCreated) {
383 return;
384 }
385 rulesTableUIPanel.getViewport().add(rulesTableUI);
386 }
387
388 protected void addChildrenToTablePopup() {
389 if (!allComponentsCreated) {
390 return;
391 }
392 tablePopup.add(editRuleListCode);
393 }
394
395 protected void createBroker() {
396 $objectMap.put("broker", broker = new DaliHelpBroker("dali.home.help"));
397 }
398
399 protected void createDeleteRuleListButton() {
400 $objectMap.put("deleteRuleListButton", deleteRuleListButton = new JButton());
401
402 deleteRuleListButton.setName("deleteRuleListButton");
403 deleteRuleListButton.setText(t("dali.common.delete"));
404 deleteRuleListButton.setToolTipText(t("dali.common.delete"));
405 deleteRuleListButton.putClientProperty("applicationAction", DeleteRuleListAction.class);
406 }
407
408 protected void createDuplicateRuleListButton() {
409 $objectMap.put("duplicateRuleListButton", duplicateRuleListButton = new JButton());
410
411 duplicateRuleListButton.setName("duplicateRuleListButton");
412 duplicateRuleListButton.setText(t("dali.action.duplicate.label"));
413 duplicateRuleListButton.setToolTipText(t("dali.action.duplicate.ruleList.tip"));
414 duplicateRuleListButton.putClientProperty("applicationAction", DuplicateRuleListAction.class);
415 }
416
417 protected void createEditRuleListCode() {
418 $objectMap.put("editRuleListCode", editRuleListCode = new JMenuItem());
419
420 editRuleListCode.setName("editRuleListCode");
421 editRuleListCode.setText(t("dali.rule.ruleList.editCode"));
422 editRuleListCode.setToolTipText(t("dali.rule.ruleList.editCode.tip"));
423 editRuleListCode.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__editRuleListCode"));
424 }
425
426 protected RuleListUIHandler createHandler() {
427 return new RuleListUIHandler();
428 }
429
430 protected void createModel() {
431 $objectMap.put("model", model = getContextValue(RuleListUIModel.class));
432 }
433
434 protected void createNewRuleListButton() {
435 $objectMap.put("newRuleListButton", newRuleListButton = new JButton());
436
437 newRuleListButton.setName("newRuleListButton");
438 newRuleListButton.setText(t("dali.common.new"));
439 newRuleListButton.setToolTipText(t("dali.common.new"));
440 newRuleListButton.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__newRuleListButton"));
441 }
442
443 protected void createRulesTableUI() {
444 $objectMap.put("rulesTableUI", rulesTableUI = new SwingTable());
445
446 rulesTableUI.setName("rulesTableUI");
447 rulesTableUI.addMouseListener(JAXXUtil.getEventListener(MouseListener.class, "mouseClicked", this, "doMouseClicked__on__rulesTableUI"));
448 }
449
450 protected void createRulesTableUIPanel() {
451 $objectMap.put("rulesTableUIPanel", rulesTableUIPanel = new JScrollPane());
452
453 rulesTableUIPanel.setName("rulesTableUIPanel");
454 }
455
456 protected void createTablePopup() {
457 $objectMap.put("tablePopup", tablePopup = new JPopupMenu());
458
459 tablePopup.setName("tablePopup");
460 }
461
462
463
464
465
466 private void $completeSetup() {
467 allComponentsCreated = true;
468 if (log.isDebugEnabled()) {
469 log.debug(this);
470 }
471 addChildrenToRuleListUI();
472 addChildrenToRulesTableUIPanel();
473 addChildrenToTablePopup();
474
475 $JPanel0.add($JPanel1, BorderLayout.LINE_START);
476
477 $JPanel1.add(newRuleListButton);
478 $JPanel1.add(duplicateRuleListButton);
479 $JPanel1.add(deleteRuleListButton);
480
481
482 JAXXUtil.applyDataBinding(this, $bindings.keySet());
483
484
485 newRuleListButton.setAlignmentX(Component.CENTER_ALIGNMENT);
486 duplicateRuleListButton.setAlignmentX(Component.CENTER_ALIGNMENT);
487 deleteRuleListButton.setAlignmentX(Component.CENTER_ALIGNMENT);
488 setBorder(BorderFactory.createTitledBorder(t("dali.rule.ruleList.title")));
489 editRuleListCode.setIcon(SwingUtil.createActionIcon("edit"));
490 newRuleListButton.setIcon(SwingUtil.createActionIcon("add"));
491 duplicateRuleListButton.setIcon(SwingUtil.createActionIcon("copy"));
492 deleteRuleListButton.setIcon(SwingUtil.createActionIcon("delete"));
493 }
494
495 private void $initialize() {
496 if (allComponentsCreated) {
497 return;
498 }
499 if (log.isDebugEnabled()) {
500 log.debug(this);
501 }
502 handler.beforeInit(this);
503 $objectMap.put("ruleListUI", ruleListUI);
504 createModel();
505 createBroker();
506 createRulesTableUIPanel();
507 createTablePopup();
508 createEditRuleListCode();
509 createRulesTableUI();
510
511 $objectMap.put("$JPanel0", $JPanel0 = new JPanel());
512
513 $JPanel0.setName("$JPanel0");
514 $JPanel0.setLayout(new BorderLayout());
515
516 $objectMap.put("$JPanel1", $JPanel1 = new JPanel());
517
518 $JPanel1.setName("$JPanel1");
519 createNewRuleListButton();
520 createDuplicateRuleListButton();
521 createDeleteRuleListButton();
522
523 setName("ruleListUI");
524 setLayout(new BorderLayout());
525 ruleListUI.putClientProperty("validatorLabel", t("dali.rule.ruleList.title"));
526
527
528 $registerDefaultBindings();
529 $completeSetup();
530 handler.afterInit(this);
531 }
532
533 private void $registerDefaultBindings() {
534
535 registerDataBinding(new DefaultJAXXBinding(this, BINDING_EDIT_RULE_LIST_CODE_ENABLED, true, true) {
536
537 @Override
538 public void applyDataBinding() {
539 if (model != null) {
540 model.addPropertyChangeListener("singleSelectedRow", this);
541 }
542 if (model != null) {
543 model.addPropertyChangeListener("saveEnabled", this);
544 }
545 }
546
547 @Override
548 public void processDataBinding() {
549 if (model != null && model.getSingleSelectedRow() != null) {
550 editRuleListCode.setEnabled(model.getSingleSelectedRow() != null && model.getSingleSelectedRow().isEditable() && model.getSingleSelectedRow().isNewCode() && model.isSaveEnabled());
551 }
552 }
553
554 @Override
555 public void removeDataBinding() {
556 if (model != null) {
557 model.removePropertyChangeListener("singleSelectedRow", this);
558 }
559 if (model != null) {
560 model.removePropertyChangeListener("saveEnabled", this);
561 }
562 }
563 });
564 registerDataBinding(new DefaultJAXXBinding(this, BINDING_NEW_RULE_LIST_BUTTON_ENABLED, true) {
565
566 @Override
567 public void applyDataBinding() {
568 if (model != null) {
569 model.addPropertyChangeListener("saveEnabled", this);
570 }
571 }
572
573 @Override
574 public void processDataBinding() {
575 if (model != null) {
576 newRuleListButton.setEnabled(model.isSaveEnabled());
577 }
578 }
579
580 @Override
581 public void removeDataBinding() {
582 if (model != null) {
583 model.removePropertyChangeListener("saveEnabled", this);
584 }
585 }
586 });
587 registerDataBinding(new DefaultJAXXBinding(this, BINDING_DUPLICATE_RULE_LIST_BUTTON_ENABLED, true, true) {
588
589 @Override
590 public void applyDataBinding() {
591 if (model != null) {
592 model.addPropertyChangeListener("selectedRows", this);
593 }
594 if (model != null) {
595 model.addPropertyChangeListener("singleSelectedRow", this);
596 }
597 if (model != null) {
598 model.addPropertyChangeListener("saveEnabled", this);
599 }
600 }
601
602 @Override
603 public void processDataBinding() {
604 if (model != null && model.getSelectedRows() != null && model.getSingleSelectedRow() != null) {
605 duplicateRuleListButton.setEnabled(model.getSelectedRows().size() == 1 && model.getSingleSelectedRow().isEditable() && model.isSaveEnabled());
606 }
607 }
608
609 @Override
610 public void removeDataBinding() {
611 if (model != null) {
612 model.removePropertyChangeListener("selectedRows", this);
613 }
614 if (model != null) {
615 model.removePropertyChangeListener("singleSelectedRow", this);
616 }
617 if (model != null) {
618 model.removePropertyChangeListener("saveEnabled", this);
619 }
620 }
621 });
622 registerDataBinding(new DefaultJAXXBinding(this, BINDING_DELETE_RULE_LIST_BUTTON_ENABLED, true, true) {
623
624 @Override
625 public void applyDataBinding() {
626 if (model != null) {
627 model.addPropertyChangeListener("selectedRows", this);
628 }
629 if (model != null) {
630 model.addPropertyChangeListener("singleSelectedRow", this);
631 }
632 if (model != null) {
633 model.addPropertyChangeListener("saveEnabled", this);
634 }
635 }
636
637 @Override
638 public void processDataBinding() {
639 if (model != null && model.getSelectedRows() != null && model.getSingleSelectedRow() != null) {
640 deleteRuleListButton.setEnabled(!model.getSelectedRows().isEmpty() && model.getSingleSelectedRow().isEditable() && model.isSaveEnabled());
641 }
642 }
643
644 @Override
645 public void removeDataBinding() {
646 if (model != null) {
647 model.removePropertyChangeListener("selectedRows", this);
648 }
649 if (model != null) {
650 model.removePropertyChangeListener("singleSelectedRow", this);
651 }
652 if (model != null) {
653 model.removePropertyChangeListener("saveEnabled", this);
654 }
655 }
656 });
657 }
658
659 }