1 package fr.ifremer.allegro.obsdeb.ui.swing.content.catches;
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.packet.PacketCompositionUI;
31 import fr.ifremer.allegro.obsdeb.ui.swing.content.catches.packet.PacketTableUI;
32 import fr.ifremer.allegro.obsdeb.ui.swing.content.catches.treetable.CatchesTreeTableUI;
33 import fr.ifremer.allegro.obsdeb.ui.swing.content.effort.select.SelectEffortUI;
34 import fr.ifremer.allegro.obsdeb.ui.swing.util.ObsdebUI;
35 import fr.ifremer.allegro.obsdeb.ui.swing.util.ObsdebUIUtil;
36 import java.awt.BorderLayout;
37 import java.awt.Component;
38 import java.awt.Container;
39 import java.awt.FlowLayout;
40 import java.awt.GridLayout;
41 import java.awt.LayoutManager;
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
45 import java.util.Map;
46 import java.util.TreeMap;
47 import javax.swing.Box;
48 import javax.swing.BoxLayout;
49 import javax.swing.JButton;
50 import javax.swing.JPanel;
51 import javax.swing.border.EmptyBorder;
52 import jaxx.runtime.JAXXBinding;
53 import jaxx.runtime.JAXXContext;
54 import jaxx.runtime.JAXXObject;
55 import jaxx.runtime.JAXXObjectDescriptor;
56 import jaxx.runtime.JAXXUtil;
57 import jaxx.runtime.JAXXValidator;
58 import jaxx.runtime.SwingUtil;
59 import jaxx.runtime.binding.DefaultJAXXBinding;
60 import jaxx.runtime.context.DefaultJAXXContext;
61 import jaxx.runtime.swing.CardLayout2Ext;
62 import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
63 import jaxx.runtime.swing.help.JAXXHelpUI;
64 import jaxx.runtime.validator.swing.SwingValidator;
65 import jaxx.runtime.validator.swing.SwingValidatorUtil;
66 import jaxx.runtime.validator.swing.meta.Validator;
67 import jaxx.runtime.validator.swing.meta.ValidatorField;
68 import jaxx.runtime.validator.swing.ui.ImageValidationUI;
69 import org.apache.commons.logging.Log;
70 import org.apache.commons.logging.LogFactory;
71 import org.jdesktop.swingx.JXLabel;
72 import org.jdesktop.swingx.JXTitledPanel;
73 import static org.nuiton.i18n.I18n.t;
74
75 public class CatchesUI extends JPanel implements JAXXHelpUI<ObsdebHelpBroker>, ObsdebUI<CatchesUIModel, CatchesUIHandler>, JAXXObject, JAXXValidator {
76
77
78
79
80
81 public static final String BINDING_SAVE_AND_CONTINUE_BUTTON_ENABLED = "saveAndContinueButton.enabled";
82
83
84
85
86
87 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAKVVz28bRRR+dm2nTtr0R5S0pWmVuqlIhbSuRG+JShNDaCqXoDqtKnwIs95xPGW8s50ZJ1tFRfwJ/Alw54LEjRPiwJkDF8S/gBAHrog3s+u1194Qgy151p5573vf+2bm229+h6KScOslCUNH9nzNutR5vPnixa77krb0+1S1JAu0kBB9cnnIN2HOS+aVhtvNukmvxunVmugGwqf+UPZ6HWaVfs2p6lCqNdxIZ7SUqjaS5fUw6Mk+akIqC/WrP//If+l98XUeIAyQ3XlsZeW0rEEnhTrkmafhMlY6JFVO/AOkIZl/gHzPm7kaJ0p9RLr0FXwOM3UoBUQimIbK5C1bDJsfBhrKLaJbHaqe7WjYaEuHtSXtUukQzumBFI5wlUddp8ccdYREnJbwNeI6cZpT66cHgQUtaSh2hUe5hs1p4J4YjAFmyZXiMyo1vDsB6K79/wjzt2zWAKZ8SDjzCMqh4Z3UxiQLMUbDjM/7kwOEuZhpjUizU2ZTwjjl8cfEp9zElZPweUU5ntsP2m0saTT+8D+IQm2WE0E4jRSSwV9MypyLWSUMrqTXL8bre5LSdMz1JObyUMwecTk1dHf/xx5qBNAGoL+bQ4im1o2k5NnVSLN7GZTnY7jNlmbCV0lEZbhpv0X5Vk9rZAALqb2IZk3kapKwqMgh3fS9GoYzv0cHMWtxoITrqVOBRuAMjGBwU3NNKMoeTmu42hz3jqe4FLnG1RHXMIB29e+lhV++/+277WGrWMwMHXI6vMKBFAHeA2ZKX4h8oqcZrz4hwXoTytFZsTa4nEGsES8jOax3yaQ7Jt15RFQHIYozv/7w49KnP5+B/DbMckG8bWLid6CsOxJVENwLg/ceWkbnjs7ieBG/ZzTMthnXVJpd1lDQsoePMsYfPaXKOGw8VXApwb2aObYe8SZEiZYzJEp4uuWf/lpofPuwL1MOaV87MXwgVfETKDGfM59aT43tMtND5wJFe54Y2GKWUQJa5dIWct9O2kSPdcWWCGNvuGfH+2Pa5NAQ9zvoRRquHFfiu9O/Kma+giqY1A3bnvn1AIZ9OZi8wM2xArGFnFxnxKAmKHZhP/HKOnGN0d861mujhSMD0ExzWrmbWTnDb06rblxqnwQBZ5iLrhB5g4bV4wbe7Nhthi54tO60zEa+wTNK7P8dY1hQ8Gloz6V93I3pRxGOMQrrawYl6YlH7fbVvjOmdjotEh1fGVoIvseCPVvp7UkqaXxlwwz1jSz4mrkUXReHKftGWssWNNveTtO0MKJLKXLVRJm30nyj1VEpxg9eHJetwcoJmL5nvBubz2ovZfcTnNMSJ68FBsP8Bh5WsuIyC/9gDDtnxtlTEc30oRmOshGWJuHkCulR+S8o16bmsTw1ws2pEW5PjXAHEf4B8jO4mA0MAAA=";
88 private static final Log log = LogFactory.getLog(CatchesUI.class);
89 private static final long serialVersionUID = 1L;
90
91
92
93
94
95 protected List<Object> $activeBindings = new ArrayList<Object>();
96 protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
97 protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
98 protected Map<String, Object> $objectMap = new HashMap<String, Object>();
99 protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
100 private boolean allComponentsCreated;
101 protected final JAXXContext delegateContext = new DefaultJAXXContext();
102
103
104
105
106
107 protected ObsdebHelpBroker broker;
108 protected JButton cancelButton;
109 protected JPanel catchesActions;
110 protected JPanel catchesCard;
111 protected JPanel catchesPanel;
112 protected JPanel catchesTreePanel;
113 @ValidatorField( validatorId = "validator", propertyName = "catchesTreeTableUIModel", editorName = "catchesTreeTableUI")
114 protected CatchesTreeTableUI catchesTreeTableUI;
115 protected CatchesUI catchesUI = this;
116 protected final CatchesUIHandler handler = new CatchesUIHandler();
117 protected CatchesUIModel model;
118 protected JButton saveAndContinueButton;
119 protected SelectEffortUI selectEffortUI;
120 @Validator( validatorId = "validator")
121 protected SwingValidator<CatchesUIModel> validator;
122 protected List<String> validatorIds = new ArrayList<String>();
123
124
125
126
127
128 private JPanel $JPanel0;
129
130
131
132
133
134 public CatchesUI(ObsdebUI parentUI) {
135 ObsdebUIUtil.setParentUI(this, parentUI);
136 $initialize();
137 }
138
139 public CatchesUI() {
140 $initialize();
141 }
142
143 public CatchesUI(JAXXContext parentContext) {
144 JAXXUtil.initContext(this, parentContext);
145 $initialize();
146 }
147
148 public CatchesUI(boolean param0) {
149 super(param0);
150 $initialize();
151 }
152
153 public CatchesUI(JAXXContext parentContext, boolean param1) {
154 super(param1);
155 JAXXUtil.initContext(this, parentContext);
156 $initialize();
157 }
158
159 public CatchesUI(LayoutManager param0) {
160 super(param0);
161 $initialize();
162 }
163
164 public CatchesUI(JAXXContext parentContext, LayoutManager param1) {
165 super(param1);
166 JAXXUtil.initContext(this, parentContext);
167 $initialize();
168 }
169
170 public CatchesUI(LayoutManager param0, boolean param1) {
171 super(param0 ,param1);
172 $initialize();
173 }
174
175 public CatchesUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
176 super(param1 ,param2);
177 JAXXUtil.initContext(this, parentContext);
178 $initialize();
179 }
180
181
182
183
184
185 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
186 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
187 }
188
189
190
191
192
193 @Override
194 public void applyDataBinding(String $binding) {
195 if (allComponentsCreated && $bindings.containsKey($binding)) {
196 getDataBinding($binding).applyDataBinding();
197 }
198 processDataBinding($binding);
199 }
200
201 @Override
202 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
203 super.firePropertyChange(propertyName, oldValue, newValue);
204 }
205
206 @Override
207 public Map<String, Object> get$objectMap() {
208 return $objectMap;
209 }
210
211 @Override
212 public JAXXBinding getDataBinding(String bindingId) {
213 return $bindings.get(bindingId);
214 }
215
216 @Override
217 public JAXXBinding[] getDataBindings() {
218 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
219 }
220
221 @Override
222 public Object getObjectById(String id) {
223 return $objectMap.get(id);
224 }
225
226 @Override
227 public void processDataBinding(String $binding, boolean $force) {
228 if (!$force && $activeBindings.contains($binding)) {
229 return;
230 }
231 $activeBindings.add($binding);
232 try {
233 if (allComponentsCreated && $bindings.containsKey($binding)) {
234 getDataBinding($binding).processDataBinding();
235 }
236 } finally {
237 $activeBindings.remove($binding);
238 }
239 }
240
241 @Override
242 public void processDataBinding(String $binding) {
243 processDataBinding($binding, false);
244 }
245
246 @Override
247 public void registerDataBinding(JAXXBinding binding) {
248 $bindings.put(binding.getId(), binding);
249 }
250
251 @Override
252 public void removeDataBinding(String $binding) {
253 if (allComponentsCreated && $bindings.containsKey($binding)) {
254 getDataBinding($binding).removeDataBinding();
255 }
256 }
257
258
259
260
261
262 @Override
263 public <T> T getContextValue(Class<T> clazz) {
264 return delegateContext.getContextValue(clazz, null);
265 }
266
267 @Override
268 public <T> T getContextValue(Class<T> clazz, String name) {
269 return delegateContext.getContextValue(clazz, name);
270 }
271
272 @Override
273 public JAXXContext getDelegateContext() {
274 return delegateContext;
275 }
276
277 @Override
278 public <O extends Container> O getParentContainer(Class<O> clazz) {
279 return SwingUtil.getParentContainer(this, clazz);
280 }
281
282 @Override
283 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
284 return SwingUtil.getParentContainer(source, clazz);
285 }
286
287 @Override
288 public <T> void removeContextValue(Class<T> clazz) {
289 delegateContext.removeContextValue(clazz, null);
290 }
291
292 @Override
293 public <T> void removeContextValue(Class<T> clazz, String name) {
294 delegateContext.removeContextValue(clazz, name);
295 }
296
297 @Override
298 public <T> void setContextValue(T o) {
299 delegateContext.setContextValue(o, null);
300 }
301
302 @Override
303 public <T> void setContextValue(T o, String name) {
304 delegateContext.setContextValue(o, name);
305 }
306
307
308
309
310
311 @Override
312 public SwingValidator<?> getValidator(String validatorId) {
313 return (SwingValidator<?>) (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);
314 }
315
316 @Override
317 public List<String> getValidatorIds() {
318 return validatorIds;
319 }
320
321 @Override
322 public void registerValidatorFields() {
323 SwingValidatorUtil.detectValidatorFields(this);
324 }
325
326
327
328
329
330 public ObsdebHelpBroker getBroker() {
331 return broker;
332 }
333
334 public JButton getCancelButton() {
335 return cancelButton;
336 }
337
338 public JPanel getCatchesActions() {
339 return catchesActions;
340 }
341
342 public JPanel getCatchesCard() {
343 return catchesCard;
344 }
345
346 public JPanel getCatchesPanel() {
347 return catchesPanel;
348 }
349
350 public JPanel getCatchesTreePanel() {
351 return catchesTreePanel;
352 }
353
354 public CatchesTreeTableUI getCatchesTreeTableUI() {
355 return catchesTreeTableUI;
356 }
357
358 public CatchesUIHandler getHandler() {
359 return handler;
360 }
361
362 public CatchesUIModel getModel() {
363 return model;
364 }
365
366 public JButton getSaveAndContinueButton() {
367 return saveAndContinueButton;
368 }
369
370 public SelectEffortUI getSelectEffortUI() {
371 return selectEffortUI;
372 }
373
374 public SwingValidator<CatchesUIModel> getValidator() {
375 return validator;
376 }
377
378
379
380
381
382 @Override
383 public void registerHelpId(ObsdebHelpBroker broker, Component component, String helpId) {
384 broker.installUI(component, helpId);
385 }
386
387 @Override
388 public void showHelp(String helpId) {
389 getBroker().showHelp(this, helpId);
390 }
391
392
393
394
395
396 protected JPanel get$JPanel0() {
397 return $JPanel0;
398 }
399
400
401
402
403
404 protected void addChildrenToCatchesActions() {
405 if (!allComponentsCreated) {
406 return;
407 }
408 catchesActions.add(cancelButton);
409 catchesActions.add(saveAndContinueButton);
410 }
411
412 protected void addChildrenToCatchesCard() {
413 if (!allComponentsCreated) {
414 return;
415 }
416 catchesCard.add(selectEffortUI, BorderLayout.PAGE_START);
417 catchesCard.add(catchesPanel, BorderLayout.CENTER);
418 catchesCard.add($JPanel0, BorderLayout.PAGE_END);
419 }
420
421 protected void addChildrenToCatchesPanel() {
422 if (!allComponentsCreated) {
423 return;
424 }
425 catchesPanel.add(catchesTreePanel);
426 }
427
428 protected void addChildrenToCatchesTreePanel() {
429 if (!allComponentsCreated) {
430 return;
431 }
432 catchesTreePanel.add(SwingUtil.boxComponentWithJxLayer(catchesTreeTableUI), BorderLayout.CENTER);
433 }
434
435 protected void addChildrenToCatchesUI() {
436 if (!allComponentsCreated) {
437 return;
438 }
439 add(catchesCard, CatchesUIHandler.CARD_CATCHES);
440 }
441
442 protected void addChildrenToValidator() {
443 if (!allComponentsCreated) {
444 return;
445 }
446 validator.setUiClass(ImageValidationUI.class);
447 validator.setBean(model);
448 }
449
450 protected void createBroker() {
451 $objectMap.put("broker", broker = new ObsdebHelpBroker("obsdeb.catches.help"));
452 }
453
454 protected void createCancelButton() {
455 $objectMap.put("cancelButton", cancelButton = new JButton());
456
457 cancelButton.setName("cancelButton");
458 cancelButton.setText(t("obsdeb.action.cancel.label"));
459 cancelButton.setToolTipText(t("obsdeb.action.cancel.landing.tip"));
460 cancelButton.putClientProperty("help", "obsdeb.catches.cancel.help");
461 }
462
463 protected void createCatchesActions() {
464 $objectMap.put("catchesActions", catchesActions = new JPanel());
465
466 catchesActions.setName("catchesActions");
467 catchesActions.setLayout(new GridLayout(1,0));
468 }
469
470 protected void createCatchesCard() {
471 $objectMap.put("catchesCard", catchesCard = new JPanel());
472
473 catchesCard.setName("catchesCard");
474 catchesCard.setLayout(new BorderLayout());
475 }
476
477 protected void createCatchesPanel() {
478 $objectMap.put("catchesPanel", catchesPanel = new JPanel());
479
480 catchesPanel.setName("catchesPanel");
481 catchesPanel.setLayout(getHandler().isPacketEnabled() ? new GridLayout(2,1) : new BorderLayout());
482 }
483
484 protected void createCatchesTreePanel() {
485 $objectMap.put("catchesTreePanel", catchesTreePanel = new JPanel());
486
487 catchesTreePanel.setName("catchesTreePanel");
488 catchesTreePanel.setLayout(new BorderLayout());
489 }
490
491 protected void createCatchesTreeTableUI() {
492 $objectMap.put("catchesTreeTableUI", catchesTreeTableUI = new CatchesTreeTableUI(this));
493
494 catchesTreeTableUI.setName("catchesTreeTableUI");
495 catchesTreeTableUI.putClientProperty("validatorLabel", t("obsdeb.catches.table.title"));
496 }
497
498 protected void createModel() {
499 $objectMap.put("model", model = getContextValue(CatchesUIModel.class));
500 }
501
502 protected void createSaveAndContinueButton() {
503 $objectMap.put("saveAndContinueButton", saveAndContinueButton = new JButton());
504
505 saveAndContinueButton.setName("saveAndContinueButton");
506 saveAndContinueButton.setText(t("obsdeb.action.save.continue.catches.label"));
507 saveAndContinueButton.setToolTipText(t("obsdeb.action.save.continue.catches.tip"));
508 saveAndContinueButton.putClientProperty("help", "obsdeb.catches.save.continue.help");
509 saveAndContinueButton.putClientProperty("applicationAction", SaveCatchesAndContinueAction.class);
510 }
511
512 protected void createSelectEffortUI() {
513 $objectMap.put("selectEffortUI", selectEffortUI = new SelectEffortUI(this, true));
514
515 selectEffortUI.setName("selectEffortUI");
516 selectEffortUI.putClientProperty("help", "obsdeb.catches.effort.help");
517 }
518
519 protected void createValidator() {
520 $objectMap.put("validator", validator = SwingValidator.newValidator(CatchesUIModel.class, "edit"));
521 }
522
523
524
525
526
527 private void $completeSetup() {
528 allComponentsCreated = true;
529 if (log.isDebugEnabled()) {
530 log.debug(this);
531 }
532 addChildrenToCatchesUI();
533 addChildrenToValidator();
534 addChildrenToCatchesCard();
535 addChildrenToCatchesPanel();
536 addChildrenToCatchesTreePanel();
537
538 $JPanel0.add(catchesActions, BorderLayout.CENTER);
539 addChildrenToCatchesActions();
540
541
542 JAXXUtil.applyDataBinding(this, $bindings.keySet());
543
544
545 selectEffortUI.setBorder(new EmptyBorder(10,0,10,0));
546 cancelButton.setIcon(SwingUtil.createActionIcon("cancel"));
547 saveAndContinueButton.setIcon(SwingUtil.createActionIcon("next"));
548
549
550 ObsdebHelpBroker _broker = getBroker();
551 registerHelpId(_broker, catchesUI, "obsdeb.catches.help");
552 registerHelpId(_broker, selectEffortUI, "obsdeb.catches.effort.help");
553 registerHelpId(_broker, cancelButton, "obsdeb.catches.cancel.help");
554 registerHelpId(_broker, saveAndContinueButton, "obsdeb.catches.save.continue.help");
555 _broker.prepareUI(this);
556
557 validatorIds = SwingValidatorUtil.detectValidators(this);
558 SwingValidatorUtil.installUI(this);
559 }
560
561 private void $initialize() {
562 if (allComponentsCreated) {
563 return;
564 }
565 if (log.isDebugEnabled()) {
566 log.debug(this);
567 }
568 handler.beforeInit(this);
569 $objectMap.put("catchesUI", catchesUI);
570 createModel();
571 createBroker();
572 createValidator();
573 createCatchesCard();
574 createSelectEffortUI();
575 createCatchesPanel();
576 createCatchesTreePanel();
577 createCatchesTreeTableUI();
578
579 $objectMap.put("$JPanel0", $JPanel0 = new JPanel());
580
581 $JPanel0.setName("$JPanel0");
582 $JPanel0.setLayout(new BorderLayout());
583 createCatchesActions();
584 createCancelButton();
585 createSaveAndContinueButton();
586
587 setName("catchesUI");
588 setLayout(new CardLayout2Ext(this,"catchesCardContainer"));
589 catchesUI.putClientProperty("help", "obsdeb.catches.help");
590
591
592 $registerDefaultBindings();
593 $completeSetup();
594 handler.afterInit(this);
595 }
596
597 private void $registerDefaultBindings() {
598
599 registerDataBinding(new DefaultJAXXBinding(this, BINDING_SAVE_AND_CONTINUE_BUTTON_ENABLED, true) {
600
601 @Override
602 public void applyDataBinding() {
603 if (model != null) {
604 model.addPropertyChangeListener("valid", this);
605 }
606 }
607
608 @Override
609 public void processDataBinding() {
610 if (model != null) {
611 saveAndContinueButton.setEnabled(model.isValid());
612 }
613 }
614
615 @Override
616 public void removeDataBinding() {
617 if (model != null) {
618 model.removePropertyChangeListener("valid", this);
619 }
620 }
621 });
622 }
623
624 }