1 package fr.ifremer.allegro.obsdeb.ui.swing.content.catches.treetable;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import fr.ifremer.allegro.obsdeb.dto.data.fishingtrip.FishingOperationGroupDTO;
28 import fr.ifremer.allegro.obsdeb.ui.swing.ObsdebHelpBroker;
29 import fr.ifremer.allegro.obsdeb.ui.swing.ObsdebUIContext;
30 import fr.ifremer.allegro.obsdeb.ui.swing.content.catches.CatchesUI;
31 import fr.ifremer.allegro.obsdeb.ui.swing.util.ObsdebUI;
32 import fr.ifremer.allegro.obsdeb.ui.swing.util.ObsdebUIUtil;
33 import java.awt.BorderLayout;
34 import java.awt.Component;
35 import java.awt.Container;
36 import java.awt.FlowLayout;
37 import java.awt.LayoutManager;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ActionListener;
40 import java.awt.event.KeyEvent;
41 import java.awt.event.KeyListener;
42 import java.awt.event.MouseEvent;
43 import java.awt.event.MouseListener;
44 import java.util.ArrayList;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.TreeMap;
49 import javax.swing.Box;
50 import javax.swing.BoxLayout;
51 import javax.swing.JButton;
52 import javax.swing.JLabel;
53 import javax.swing.JMenuItem;
54 import javax.swing.JPanel;
55 import javax.swing.JPopupMenu;
56 import javax.swing.JScrollPane;
57 import javax.swing.border.TitledBorder;
58 import jaxx.runtime.JAXXBinding;
59 import jaxx.runtime.JAXXContext;
60 import jaxx.runtime.JAXXObject;
61 import jaxx.runtime.JAXXObjectDescriptor;
62 import jaxx.runtime.JAXXUtil;
63 import jaxx.runtime.SwingUtil;
64 import jaxx.runtime.binding.DefaultJAXXBinding;
65 import jaxx.runtime.context.DefaultJAXXContext;
66 import jaxx.runtime.swing.help.JAXXHelpUI;
67 import org.apache.commons.logging.Log;
68 import org.apache.commons.logging.LogFactory;
69 import org.jdesktop.swingx.JXTreeTable;
70 import static org.nuiton.i18n.I18n.t;
71
72 public class CatchesTreeTableUI extends JPanel implements JAXXHelpUI<ObsdebHelpBroker>, ObsdebUI<CatchesTreeTableUIModel, CatchesTreeTableUIHandler>, JAXXObject {
73
74
75
76
77
78 public static final String BINDING_DELETE_BUTTON_ENABLED = "deleteButton.enabled";
79 public static final String BINDING_DELETE_MENU_ITEM_ENABLED = "deleteMenuItem.enabled";
80
81
82
83
84
85 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAMVWQW8bRRSeOLVTO20KiRrSJtAkzSHhMEZCHFCANkkTNZHTVImRInwos96pvel6Z5h9izdYRfwC4CfAnQsSN06IA2cOXBB/ASEOXBFvZte7WXutWIDAh5H95r3vve/NvG/81a+k6CuycsbCkKrAA6fD6cHW6emRdcab8ID7TeVIEIpEn4kCKTTItJ3YfSB3GzUdXo3DqzuiI4XHvQvRmzVS8eHc5X6bcwDycjai6fvVk2R7M5SB6qMmReWhfvH7b4XP7U++LBASSqxuBqksXxaVMrlSIwXHBjKLmT5kVZd5LSxDOV4L672ubTsu8/1HrMM/IB+TqRopSaYQDMjq+JQNhokPJeZqMmi2uV9XnNeZ5fJ394EcPVXUeap4hyvKXJe3lKDC8m1u0cChfhcrok3hASagcTwFBAANQHeGEKU0CUtAih1hcxdI/V/OcKhh0zQlS4lnXAF5fYw8R+b3Q4zfNlEpTMWkeyxkgJ2a1wcQxjEHxnjIvSD1nsESOHBt3AfeAXIzE9G3a+/ZwRTM012ZzabQRu1WTrynrQBAeMnObb0sJNtlZtvbxgPIXAYrsmq3xcT7muKuYHa6dWdgP+Izcn96Lblmr8W1U9aF9I5n3a+CI2vMGuZpjFnf62sHJ00lXFczRfCXMgHp1gB96F8IIHeEatEz1IVnIGQUGNKD0+TK6JBXJc7nYmY+cfJpOvnpaE40SFEFaAay0BgWi2PcimRiYUAmNKDZ/XN+7qdvf/lmr68NFcx9M9f1grThzEolJN5kR6e+EQlDAI5bPWRys0HKPp5RM9K9pZzCTuJtLA7zvWjOSIfTh8xvI0Rx6ufvvp9//8dJUtgjFX0d9pj238dmthV2Qbh2KO/dNxVd617F9QVdG07ykzZODEpnbzUeqGROzYzq3dXnIbZkKaclSV1W+Yc/5k6+vt9vywSWeWuke9qa4nuk5Hiu43EjmrEe5orktPR5YItU9/KUkORKoYyn+w2zvpnXh5IllG2kpufx7nLdAZfb28a2Duv5vQHttLqxge3RuG8b3vrbPZJRhMvSF7HoJ0xK10F8R3hbTb3iFe1t2XYskpGNNjXX54jOzO99La5kEvUiPcnFoZPE7fgccdpBCLfuyDoP9YMZe0ZoxjGhiM8NmeKeZoHopR6ogOcyTeXqMqKTA4WXWauleIsBT8tfGS6/7zSCxN0BEon7BSp5dWeE8++e0WLvgZHXMY6pFAlxSvWVIaqRxwiey1mese+I81rrrZg3mrY4RGPH7WPR9dc3qOPvdiScr+ff28xz8V925QoYlrdzWbrRi/N/NGTg/8AYd3yuLZTzEZJj7pbrtLyO+W93oxc9kXRn91F993iwD0VmCez5AMWFEcKTe6GTp3kcvXPZuck385bNgC1bjmfj4/rOEO6EXiuXImrzp3r5LB/h1j9GWEKEvwDxvyrxWAwAAA==";
86 public static final String PROPERTY$COMPONENT0 = "$Component0";
87 private static final Log log = LogFactory.getLog(CatchesTreeTableUI.class);
88 private static final long serialVersionUID = 1L;
89
90
91
92
93
94 protected List<Object> $activeBindings = new ArrayList<Object>();
95 protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
96 protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
97 protected Map<String, Object> $objectMap = new HashMap<String, Object>();
98 protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
99 private boolean allComponentsCreated;
100 protected final JAXXContext delegateContext = new DefaultJAXXContext();
101
102
103
104
105
106 protected JButton addButton;
107 protected ObsdebHelpBroker broker;
108 protected JPanel buttonPanel;
109 protected CatchesTreeTableUI catchesTreeTableUI = this;
110 protected JButton deleteButton;
111 protected JMenuItem deleteMenuItem;
112 protected final CatchesTreeTableUIHandler handler = new CatchesTreeTableUIHandler();
113 protected CatchesTreeTableUIModel model;
114 protected JButton reloadButton;
115 protected JPanel tablePanel;
116 protected JPopupMenu tablePopup;
117 protected JLabel tipLabel;
118 protected JXTreeTable treeTable;
119
120
121
122
123
124 private Component $Component0;
125 private JScrollPane $JScrollPane0;
126
127
128
129
130
131 private CatchesUI parentUI;
132
133
134 public CatchesUI getParentUI() {
135 return parentUI;
136 }
137
138
139
140
141
142 public CatchesTreeTableUI(ObsdebUI parentUI) {
143 ObsdebUIUtil.setParentUI(this, parentUI);
144 this.parentUI = (CatchesUI) parentUI;
145 $initialize();
146 }
147
148 public CatchesTreeTableUI() {
149 $initialize();
150 }
151
152 public CatchesTreeTableUI(JAXXContext parentContext) {
153 JAXXUtil.initContext(this, parentContext);
154 $initialize();
155 }
156
157 public CatchesTreeTableUI(boolean param0) {
158 super(param0);
159 $initialize();
160 }
161
162 public CatchesTreeTableUI(JAXXContext parentContext, boolean param1) {
163 super(param1);
164 JAXXUtil.initContext(this, parentContext);
165 $initialize();
166 }
167
168 public CatchesTreeTableUI(LayoutManager param0) {
169 super(param0);
170 $initialize();
171 }
172
173 public CatchesTreeTableUI(JAXXContext parentContext, LayoutManager param1) {
174 super(param1);
175 JAXXUtil.initContext(this, parentContext);
176 $initialize();
177 }
178
179 public CatchesTreeTableUI(LayoutManager param0, boolean param1) {
180 super(param0 ,param1);
181 $initialize();
182 }
183
184 public CatchesTreeTableUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
185 super(param1 ,param2);
186 JAXXUtil.initContext(this, parentContext);
187 $initialize();
188 }
189
190
191
192
193
194 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
195 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
196 }
197
198
199
200
201
202 @Override
203 public void applyDataBinding(String $binding) {
204 if (allComponentsCreated && $bindings.containsKey($binding)) {
205 getDataBinding($binding).applyDataBinding();
206 }
207 processDataBinding($binding);
208 }
209
210 @Override
211 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
212 super.firePropertyChange(propertyName, oldValue, newValue);
213 }
214
215 @Override
216 public Map<String, Object> get$objectMap() {
217 return $objectMap;
218 }
219
220 @Override
221 public JAXXBinding getDataBinding(String bindingId) {
222 return $bindings.get(bindingId);
223 }
224
225 @Override
226 public JAXXBinding[] getDataBindings() {
227 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
228 }
229
230 @Override
231 public Object getObjectById(String id) {
232 return $objectMap.get(id);
233 }
234
235 @Override
236 public void processDataBinding(String $binding, boolean $force) {
237 if (!$force && $activeBindings.contains($binding)) {
238 return;
239 }
240 $activeBindings.add($binding);
241 try {
242 if (allComponentsCreated && $bindings.containsKey($binding)) {
243 getDataBinding($binding).processDataBinding();
244 }
245 } finally {
246 $activeBindings.remove($binding);
247 }
248 }
249
250 @Override
251 public void processDataBinding(String $binding) {
252 processDataBinding($binding, false);
253 }
254
255 @Override
256 public void registerDataBinding(JAXXBinding binding) {
257 $bindings.put(binding.getId(), binding);
258 }
259
260 @Override
261 public void removeDataBinding(String $binding) {
262 if (allComponentsCreated && $bindings.containsKey($binding)) {
263 getDataBinding($binding).removeDataBinding();
264 }
265 }
266
267
268
269
270
271 @Override
272 public <T> T getContextValue(Class<T> clazz) {
273 return delegateContext.getContextValue(clazz, null);
274 }
275
276 @Override
277 public <T> T getContextValue(Class<T> clazz, String name) {
278 return delegateContext.getContextValue(clazz, name);
279 }
280
281 @Override
282 public JAXXContext getDelegateContext() {
283 return delegateContext;
284 }
285
286 @Override
287 public <O extends Container> O getParentContainer(Class<O> clazz) {
288 return SwingUtil.getParentContainer(this, clazz);
289 }
290
291 @Override
292 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
293 return SwingUtil.getParentContainer(source, clazz);
294 }
295
296 @Override
297 public <T> void removeContextValue(Class<T> clazz) {
298 delegateContext.removeContextValue(clazz, null);
299 }
300
301 @Override
302 public <T> void removeContextValue(Class<T> clazz, String name) {
303 delegateContext.removeContextValue(clazz, name);
304 }
305
306 @Override
307 public <T> void setContextValue(T o) {
308 delegateContext.setContextValue(o, null);
309 }
310
311 @Override
312 public <T> void setContextValue(T o, String name) {
313 delegateContext.setContextValue(o, name);
314 }
315
316
317
318
319
320 public void doActionPerformed__on__reloadButton(ActionEvent event) {
321 if (log.isDebugEnabled()) {
322 log.debug(event);
323 }
324 handler.reloadData();
325 }
326
327 public void doKeyPressed__on__treeTable(KeyEvent event) {
328 if (log.isDebugEnabled()) {
329 log.debug(event);
330 }
331 handler.openRowMenu(event, tablePopup);
332 }
333
334 public void doMouseClicked__on__treeTable(MouseEvent event) {
335 if (log.isDebugEnabled()) {
336 log.debug(event);
337 }
338 handler.autoSelectRowInTable(event, tablePopup);
339 }
340
341
342
343
344
345 public JButton getAddButton() {
346 return addButton;
347 }
348
349 public ObsdebHelpBroker getBroker() {
350 return broker;
351 }
352
353 public JPanel getButtonPanel() {
354 return buttonPanel;
355 }
356
357 public JButton getDeleteButton() {
358 return deleteButton;
359 }
360
361 public JMenuItem getDeleteMenuItem() {
362 return deleteMenuItem;
363 }
364
365 public CatchesTreeTableUIHandler getHandler() {
366 return handler;
367 }
368
369 public CatchesTreeTableUIModel getModel() {
370 return model;
371 }
372
373 public JButton getReloadButton() {
374 return reloadButton;
375 }
376
377 public JPanel getTablePanel() {
378 return tablePanel;
379 }
380
381 public JPopupMenu getTablePopup() {
382 return tablePopup;
383 }
384
385 public JLabel getTipLabel() {
386 return tipLabel;
387 }
388
389 public JXTreeTable getTreeTable() {
390 return treeTable;
391 }
392
393
394
395
396
397 public void set$Component0(Component $Component0) {
398 Component oldValue = this.$Component0;
399 this.$Component0 = $Component0;
400 firePropertyChange(PROPERTY$COMPONENT0, oldValue, $Component0);
401 }
402
403
404
405
406
407 @Override
408 public void registerHelpId(ObsdebHelpBroker broker, Component component, String helpId) {
409 broker.installUI(component, helpId);
410 }
411
412 @Override
413 public void showHelp(String helpId) {
414 getBroker().showHelp(this, helpId);
415 }
416
417
418
419
420
421 protected Component get$Component0() {
422 return $Component0;
423 }
424
425 protected JScrollPane get$JScrollPane0() {
426 return $JScrollPane0;
427 }
428
429
430
431
432
433 protected void addChildrenToButtonPanel() {
434 if (!allComponentsCreated) {
435 return;
436 }
437 buttonPanel.add(addButton);
438 buttonPanel.add(reloadButton);
439 buttonPanel.add(deleteButton);
440 buttonPanel.add($Component0);
441 buttonPanel.add(tipLabel);
442 }
443
444 protected void addChildrenToCatchesTreeTableUI() {
445 if (!allComponentsCreated) {
446 return;
447 }
448 add(tablePanel);
449 }
450
451 protected void addChildrenToTablePanel() {
452 if (!allComponentsCreated) {
453 return;
454 }
455 tablePanel.add(buttonPanel, BorderLayout.WEST);
456 tablePanel.add($JScrollPane0, BorderLayout.CENTER);
457 }
458
459 protected void addChildrenToTablePopup() {
460 if (!allComponentsCreated) {
461 return;
462 }
463 tablePopup.add(deleteMenuItem);
464 }
465
466 protected void createAddButton() {
467 $objectMap.put("addButton", addButton = new JButton());
468
469 addButton.setName("addButton");
470 addButton.setToolTipText(t("obsdeb.action.add.catches.tip"));
471 addButton.putClientProperty("help", "obsdeb.catches.add.help");
472 addButton.putClientProperty("applicationAction", AddCatchesAction.class);
473 }
474
475 protected void createBroker() {
476 $objectMap.put("broker", broker = new ObsdebHelpBroker("obsdeb.catches.help"));
477 }
478
479 protected void createButtonPanel() {
480 $objectMap.put("buttonPanel", buttonPanel = new JPanel());
481
482 buttonPanel.setName("buttonPanel");
483 buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.PAGE_AXIS));
484 }
485
486 protected void createDeleteButton() {
487 $objectMap.put("deleteButton", deleteButton = new JButton());
488
489 deleteButton.setName("deleteButton");
490 deleteButton.setToolTipText(t("obsdeb.action.delete.catches.tip"));
491 deleteButton.putClientProperty("help", "obsdeb.catches.delete.help");
492 deleteButton.putClientProperty("applicationAction", DeleteCatchesAction.class);
493 }
494
495 protected void createDeleteMenuItem() {
496 $objectMap.put("deleteMenuItem", deleteMenuItem = new JMenuItem());
497
498 deleteMenuItem.setName("deleteMenuItem");
499 deleteMenuItem.setText(t("obsdeb.action.delete.label"));
500 deleteMenuItem.setToolTipText(t("obsdeb.action.delete.catches.tip"));
501 deleteMenuItem.putClientProperty("applicationAction", DeleteCatchesAction.class);
502 }
503
504 protected void createModel() {
505 $objectMap.put("model", model = getContextValue(CatchesTreeTableUIModel.class));
506 }
507
508 protected void createReloadButton() {
509 $objectMap.put("reloadButton", reloadButton = new JButton());
510
511 reloadButton.setName("reloadButton");
512 reloadButton.setToolTipText(t("obsdeb.action.aggregate.catches.tip"));
513 reloadButton.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__reloadButton"));
514 reloadButton.putClientProperty("help", "obsdeb.catches.aggregate.help");
515 }
516
517 protected void createTablePanel() {
518 $objectMap.put("tablePanel", tablePanel = new JPanel());
519
520 tablePanel.setName("tablePanel");
521 tablePanel.setLayout(new BorderLayout());
522 }
523
524 protected void createTablePopup() {
525 $objectMap.put("tablePopup", tablePopup = new JPopupMenu());
526
527 tablePopup.setName("tablePopup");
528 }
529
530 protected void createTipLabel() {
531 $objectMap.put("tipLabel", tipLabel = new JLabel());
532
533 tipLabel.setName("tipLabel");
534 tipLabel.setToolTipText(t("obsdeb.catches.table.tip"));
535 }
536
537 protected void createTreeTable() {
538 $objectMap.put("treeTable", treeTable = new JXTreeTable());
539
540 treeTable.setName("treeTable");
541 treeTable.addKeyListener(JAXXUtil.getEventListener(KeyListener.class, "keyPressed", this, "doKeyPressed__on__treeTable"));
542 treeTable.addMouseListener(JAXXUtil.getEventListener(MouseListener.class, "mouseClicked", this, "doMouseClicked__on__treeTable"));
543 }
544
545
546
547
548
549 private void $completeSetup() {
550 allComponentsCreated = true;
551 if (log.isDebugEnabled()) {
552 log.debug(this);
553 }
554 addChildrenToCatchesTreeTableUI();
555 addChildrenToTablePopup();
556 addChildrenToTablePanel();
557 addChildrenToButtonPanel();
558
559 $JScrollPane0.getViewport().add(treeTable);
560
561
562 JAXXUtil.applyDataBinding(this, $bindings.keySet());
563
564
565 deleteMenuItem.setIcon(SwingUtil.createActionIcon("delete"));
566 tablePanel.setBorder(new TitledBorder(t("obsdeb.catches.table.title")));
567 addButton.setIcon(SwingUtil.createActionIcon("add"));
568 addButton.setEnabled(true);
569 reloadButton.setIcon(SwingUtil.createActionIcon("aggregate"));
570 deleteButton.setIcon(SwingUtil.createActionIcon("delete"));
571 tipLabel.setHorizontalAlignment(JLabel.CENTER);
572 tipLabel.setIcon(SwingUtil.createActionIcon("about"));
573
574
575 ObsdebHelpBroker _broker = getBroker();
576 registerHelpId(_broker, catchesTreeTableUI, "obsdeb.catches.table.help");
577 registerHelpId(_broker, addButton, "obsdeb.catches.add.help");
578 registerHelpId(_broker, reloadButton, "obsdeb.catches.aggregate.help");
579 registerHelpId(_broker, deleteButton, "obsdeb.catches.delete.help");
580 _broker.prepareUI(this);
581 }
582
583 private void $initialize() {
584 if (allComponentsCreated) {
585 return;
586 }
587 if (log.isDebugEnabled()) {
588 log.debug(this);
589 }
590 handler.beforeInit(this);
591 $objectMap.put("catchesTreeTableUI", catchesTreeTableUI);
592 createModel();
593 createBroker();
594 createTablePopup();
595 createDeleteMenuItem();
596 createTablePanel();
597 createButtonPanel();
598 createAddButton();
599 createReloadButton();
600 createDeleteButton();
601
602 $objectMap.put("$Component0", $Component0 = Box.createVerticalGlue());
603
604 $Component0.setName("$Component0");
605 createTipLabel();
606
607 $objectMap.put("$JScrollPane0", $JScrollPane0 = new JScrollPane());
608
609 $JScrollPane0.setName("$JScrollPane0");
610 createTreeTable();
611
612 setName("catchesTreeTableUI");
613 setLayout(new BorderLayout());
614 catchesTreeTableUI.putClientProperty("help", "obsdeb.catches.table.help");
615
616
617 $registerDefaultBindings();
618 $completeSetup();
619 handler.afterInit(this);
620 }
621
622 private void $registerDefaultBindings() {
623
624 registerDataBinding(new DefaultJAXXBinding(this, BINDING_DELETE_MENU_ITEM_ENABLED, true) {
625
626 @Override
627 public void applyDataBinding() {
628 if (model != null) {
629 model.addPropertyChangeListener("selectedRows", this);
630 }
631 }
632
633 @Override
634 public void processDataBinding() {
635 if (model != null && model.getSelectedRows() != null) {
636 deleteMenuItem.setEnabled(!model.getSelectedRows().isEmpty());
637 }
638 }
639
640 @Override
641 public void removeDataBinding() {
642 if (model != null) {
643 model.removePropertyChangeListener("selectedRows", this);
644 }
645 }
646 });
647 registerDataBinding(new DefaultJAXXBinding(this, BINDING_DELETE_BUTTON_ENABLED, true) {
648
649 @Override
650 public void applyDataBinding() {
651 if (model != null) {
652 model.addPropertyChangeListener("selectedRows", this);
653 }
654 }
655
656 @Override
657 public void processDataBinding() {
658 if (model != null && model.getSelectedRows() != null) {
659 deleteButton.setEnabled(!model.getSelectedRows().isEmpty());
660 }
661 }
662
663 @Override
664 public void removeDataBinding() {
665 if (model != null) {
666 model.removePropertyChangeListener("selectedRows", this);
667 }
668 }
669 });
670 }
671
672 }