1 package fr.ifremer.reefdb.ui.swing.content.manage.referential.unit;
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.quadrige3.ui.swing.ApplicationUI;
28 import fr.ifremer.quadrige3.ui.swing.ApplicationUIUtil;
29 import fr.ifremer.reefdb.ui.swing.ReefDbHelpBroker;
30 import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
31 import fr.ifremer.reefdb.ui.swing.content.ReefDbMainUI;
32 import fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.local.ReferentialUnitsLocalUI;
33 import fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.national.ReferentialUnitsNationalUI;
34 import fr.ifremer.reefdb.ui.swing.util.ReefDbUI;
35 import java.awt.BorderLayout;
36 import java.awt.Component;
37 import java.awt.Container;
38 import java.awt.FlowLayout;
39 import java.awt.GridBagConstraints;
40 import java.awt.GridLayout;
41 import java.awt.Insets;
42 import java.awt.LayoutManager;
43 import java.util.ArrayList;
44 import java.util.HashMap;
45 import java.util.List;
46 import java.util.Map;
47 import java.util.TreeMap;
48 import javax.swing.BorderFactory;
49 import javax.swing.Box;
50 import javax.swing.BoxLayout;
51 import javax.swing.JButton;
52 import javax.swing.JPanel;
53 import javax.swing.JScrollPane;
54 import jaxx.runtime.JAXXBinding;
55 import jaxx.runtime.JAXXContext;
56 import jaxx.runtime.JAXXObject;
57 import jaxx.runtime.JAXXObjectDescriptor;
58 import jaxx.runtime.JAXXUtil;
59 import jaxx.runtime.JAXXValidator;
60 import jaxx.runtime.SwingUtil;
61 import jaxx.runtime.binding.DefaultJAXXBinding;
62 import jaxx.runtime.context.DefaultJAXXContext;
63 import jaxx.runtime.swing.Table;
64 import jaxx.runtime.swing.help.JAXXHelpUI;
65 import jaxx.runtime.validator.swing.SwingValidator;
66 import jaxx.runtime.validator.swing.SwingValidatorUtil;
67 import jaxx.runtime.validator.swing.meta.Validator;
68 import jaxx.runtime.validator.swing.meta.ValidatorField;
69 import jaxx.runtime.validator.swing.ui.ImageValidationUI;
70 import org.apache.commons.logging.Log;
71 import org.apache.commons.logging.LogFactory;
72 import static org.nuiton.i18n.I18n.t;
73
74 public class ReferentialUnitsUI extends JPanel implements JAXXHelpUI<ReefDbHelpBroker>, ReefDbUI<ReferentialUnitsUIModel, ReferentialUnitsUIHandler>, JAXXObject, JAXXValidator {
75
76
77
78
79
80 public static final String BINDING_SAVE_BOUTON_ENABLED = "saveBouton.enabled";
81
82
83
84
85
86 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAK1VTW8jRRBtG9tZ23wmym6ARcqG3cgRaAxc+AiCTbwbbYITIM5GEZYI7Zl20ktP99DTk9iygvYn8BPgzgWJGyfEgTMHLoi/gBAHrojqnsmMJ57YRiFSWp7uqlevqrteffsHKvoS3XqEez1LBlxRl1hbawcHH3YeEVvdI74tqaeEROFfLo/ybVR14n1foZfbTe1ej9zrDeF6ghM+5L3aRBVf9RnxjwlRCr2U9rB9v96Kj1d7XiDPUWNSWahf//Vn/ivn8Td5hHoesKtCKouTvJJMCk2Up45CsxDpBNcZ5kdAQ1J+BHyf0nsNhn1/B7vkC/QlmmmikoclgCm0NH3KBsP49zyFrt3e+ghzwl5TaLsrLdqVxCXSkoR0nY4VUMs/hfiWLbgCOMvFHB8ROO4SHZhiZgWcKms32XgI3/7DTc8zQUoKFV3hEKbQ7v+Kv61BkyCljhSfE6nQK2Oi7ML3vc4D8Fs31ol7+QQz6mCoEyCkbiw+iDBaet0/30wQKlBowZgupkI39GX1Io+tVnyibcuxy8ztPdxhBEq/kAoZupkzbTkfO7wgL5RhBysqOHxsKvTpFcrLI5yROicBNIWFmMmNi0yawg5pHFyBBtMgIxwi6DSB83f7OrRLqthmN13nqs2ET9YDpSA+mkuZh7va8NbQVeITsi6C6GA5OpXoxdQ1gUpYiUokbZxro6IMYBvutT0qLLtwFErKwgVJ0YDm9J/rc7/+8Pv3G8M6Mp9pOiSD0N+eFB70ANWhnwlFJFCU1bext9pGZZ8w0FCjkTcziLWiYyAH8Z7T7pZ2tx5g/xggijO//fjT9c9+eQLlN1CFCexsYG2/icrqWEIVBHN63vt3DaMnT6/B+iz853VzCuno5iwNeMDYGbyfQ8FZf1+ThcsNG0S/d4UKSgakB9W5mVGdmGKn/PPfc63v7p5XKAeMn7/UPKlS8RNUopxRTozWRjKaqa1VzyeBIxK5zBJQlGp8L5IDy6xvjJSiAI/1EHseg6R1X63ZeoUnOWjoFxp+WrbGhxpVsPne1F2DSjbmtlbR+VGAD0hfobcHYxrPXGOofmAMMwXUz7caazuN+80zXXPSgyEyF7nZwnUND+DUC3Qqb5kS61/voHQ/TUq5dEnKs4MWNNm4jAu6Cy/P983/nm9rbf9+ku1sOtswWlUJwfaot2dMFiKTkJYxMUIFDTRDuH6vMK3vDMx8s6gPI4l2+7WVxeXlxfM9MylqK2dZdRzSmUllzA010ceDdfMr7L6+ZUuCFdmjCuiEJzVVW4qoZ0htLPbQcYQtrWSTGzNrJpEd7vidK5INR0LMFHTtMJ7ITb2r0KuD6REyU71smE1zKQz34QIVevpdoIQXO5Q78ADfGwmT02tlIqLedvXCsxGWpuBUgfoccRfyORiDdGcqLqdjEGpTcClQOxyiV2LxeAKLfwHKU+rDNgwAAA==";
87 private static final Log log = LogFactory.getLog(ReferentialUnitsUI.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 ReefDbHelpBroker broker;
107 protected JButton closeButton;
108 protected final ReferentialUnitsUIHandler handler = createHandler();
109 protected ReferentialUnitsUIModel model;
110 @ValidatorField( validatorId = "validator", propertyName = "localUIModel", editorName = "referentialUnitsLocalUI")
111 protected ReferentialUnitsLocalUI referentialUnitsLocalUI;
112 protected ReferentialUnitsNationalUI referentialUnitsNationalUI;
113 protected JButton saveBouton;
114 protected JScrollPane scrollPane;
115 @Validator( validatorId = "validator")
116 protected SwingValidator<ReferentialUnitsUIModel> validator;
117 protected List<String> validatorIds = new ArrayList<String>();
118
119
120
121
122
123 private ReferentialUnitsUI $JPanel0 = this;
124 private JPanel $JPanel1;
125 private Table $Table0;
126
127
128
129
130
131 public ReferentialUnitsUI(ReefDbMainUI parentUI) {
132 ApplicationUIUtil.setParentUI(this, parentUI);
133 $initialize();
134 }
135
136 public ReferentialUnitsUI(LayoutManager param0, boolean param1) {
137 super(param0 ,param1);
138 $initialize();
139 }
140
141 public ReferentialUnitsUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
142 super(param1 ,param2);
143 JAXXUtil.initContext(this, parentContext);
144 $initialize();
145 }
146
147 public ReferentialUnitsUI(boolean param0) {
148 super(param0);
149 $initialize();
150 }
151
152 public ReferentialUnitsUI(JAXXContext parentContext, boolean param1) {
153 super(param1);
154 JAXXUtil.initContext(this, parentContext);
155 $initialize();
156 }
157
158 public ReferentialUnitsUI() {
159 $initialize();
160 }
161
162 public ReferentialUnitsUI(JAXXContext parentContext) {
163 JAXXUtil.initContext(this, parentContext);
164 $initialize();
165 }
166
167 public ReferentialUnitsUI(LayoutManager param0) {
168 super(param0);
169 $initialize();
170 }
171
172 public ReferentialUnitsUI(JAXXContext parentContext, LayoutManager param1) {
173 super(param1);
174 JAXXUtil.initContext(this, parentContext);
175 $initialize();
176 }
177
178
179
180
181
182 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
183 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
184 }
185
186
187
188
189
190 @Override
191 public void applyDataBinding(String $binding) {
192 if (allComponentsCreated && $bindings.containsKey($binding)) {
193 getDataBinding($binding).applyDataBinding();
194 }
195 processDataBinding($binding);
196 }
197
198 @Override
199 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
200 super.firePropertyChange(propertyName, oldValue, newValue);
201 }
202
203 @Override
204 public Map<String, Object> get$objectMap() {
205 return $objectMap;
206 }
207
208 @Override
209 public JAXXBinding getDataBinding(String bindingId) {
210 return $bindings.get(bindingId);
211 }
212
213 @Override
214 public JAXXBinding[] getDataBindings() {
215 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
216 }
217
218 @Override
219 public Object getObjectById(String id) {
220 return $objectMap.get(id);
221 }
222
223 @Override
224 public void processDataBinding(String $binding, boolean $force) {
225 if (!$force && $activeBindings.contains($binding)) {
226 return;
227 }
228 $activeBindings.add($binding);
229 try {
230 if (allComponentsCreated && $bindings.containsKey($binding)) {
231 getDataBinding($binding).processDataBinding();
232 }
233 } finally {
234 $activeBindings.remove($binding);
235 }
236 }
237
238 @Override
239 public void processDataBinding(String $binding) {
240 processDataBinding($binding, false);
241 }
242
243 @Override
244 public void registerDataBinding(JAXXBinding binding) {
245 $bindings.put(binding.getId(), binding);
246 }
247
248 @Override
249 public void removeDataBinding(String $binding) {
250 if (allComponentsCreated && $bindings.containsKey($binding)) {
251 getDataBinding($binding).removeDataBinding();
252 }
253 }
254
255
256
257
258
259 @Override
260 public <T> T getContextValue(Class<T> clazz) {
261 return delegateContext.getContextValue(clazz, null);
262 }
263
264 @Override
265 public <T> T getContextValue(Class<T> clazz, String name) {
266 return delegateContext.getContextValue(clazz, name);
267 }
268
269 @Override
270 public JAXXContext getDelegateContext() {
271 return delegateContext;
272 }
273
274 @Override
275 public <O extends Container> O getParentContainer(Class<O> clazz) {
276 return SwingUtil.getParentContainer(this, clazz);
277 }
278
279 @Override
280 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
281 return SwingUtil.getParentContainer(source, clazz);
282 }
283
284 @Override
285 public <T> void removeContextValue(Class<T> clazz) {
286 delegateContext.removeContextValue(clazz, null);
287 }
288
289 @Override
290 public <T> void removeContextValue(Class<T> clazz, String name) {
291 delegateContext.removeContextValue(clazz, name);
292 }
293
294 @Override
295 public <T> void setContextValue(T o) {
296 delegateContext.setContextValue(o, null);
297 }
298
299 @Override
300 public <T> void setContextValue(T o, String name) {
301 delegateContext.setContextValue(o, name);
302 }
303
304
305
306
307
308 @Override
309 public SwingValidator<?> getValidator(String validatorId) {
310 return (SwingValidator<?>) (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);
311 }
312
313 @Override
314 public List<String> getValidatorIds() {
315 return validatorIds;
316 }
317
318 @Override
319 public void registerValidatorFields() {
320 SwingValidatorUtil.detectValidatorFields(this);
321 }
322
323
324
325
326
327 public ReefDbHelpBroker getBroker() {
328 return broker;
329 }
330
331 public JButton getCloseButton() {
332 return closeButton;
333 }
334
335 public ReferentialUnitsUIHandler getHandler() {
336 return handler;
337 }
338
339 public ReferentialUnitsUIModel getModel() {
340 return model;
341 }
342
343 public ReferentialUnitsLocalUI getReferentialUnitsLocalUI() {
344 return referentialUnitsLocalUI;
345 }
346
347 public ReferentialUnitsNationalUI getReferentialUnitsNationalUI() {
348 return referentialUnitsNationalUI;
349 }
350
351 public JButton getSaveBouton() {
352 return saveBouton;
353 }
354
355 public JScrollPane getScrollPane() {
356 return scrollPane;
357 }
358
359 public SwingValidator<ReferentialUnitsUIModel> getValidator() {
360 return validator;
361 }
362
363
364
365
366
367 @Override
368 public void registerHelpId(ReefDbHelpBroker broker, Component component, String helpId) {
369 broker.installUI(component, helpId);
370 }
371
372 @Override
373 public void showHelp(String helpId) {
374 getBroker().showHelp(this, helpId);
375 }
376
377
378
379
380
381 protected JPanel get$JPanel1() {
382 return $JPanel1;
383 }
384
385 protected Table get$Table0() {
386 return $Table0;
387 }
388
389
390
391
392
393 protected void addChildrenToScrollPane() {
394 if (!allComponentsCreated) {
395 return;
396 }
397 scrollPane.getViewport().add($Table0);
398 }
399
400 protected void addChildrenToValidator() {
401 if (!allComponentsCreated) {
402 return;
403 }
404 validator.setUiClass(ImageValidationUI.class);
405 validator.setBean(model);
406 }
407
408 protected void createBroker() {
409 $objectMap.put("broker", broker = new ReefDbHelpBroker("reefdb.home.help"));
410 }
411
412 protected void createCloseButton() {
413 $objectMap.put("closeButton", closeButton = new JButton());
414
415 closeButton.setName("closeButton");
416 closeButton.setText(t("reefdb.common.close"));
417 closeButton.putClientProperty("applicationActionKey", fr.ifremer.reefdb.ui.swing.util.ReefDbKeyStrokes.CANCEL);
418 closeButton.putClientProperty("applicationAction", CloseAction.class);
419 }
420
421 protected ReferentialUnitsUIHandler createHandler() {
422 return new ReferentialUnitsUIHandler();
423 }
424
425 protected void createModel() {
426 $objectMap.put("model", model = getContextValue(ReferentialUnitsUIModel.class));
427 }
428
429 protected void createReferentialUnitsLocalUI() {
430 $objectMap.put("referentialUnitsLocalUI", referentialUnitsLocalUI = new ReferentialUnitsLocalUI(this));
431
432 referentialUnitsLocalUI.setName("referentialUnitsLocalUI");
433 referentialUnitsLocalUI.putClientProperty("validatorLabel", t("reefdb.manage.referential.local.label"));
434 }
435
436 protected void createReferentialUnitsNationalUI() {
437 $objectMap.put("referentialUnitsNationalUI", referentialUnitsNationalUI = new ReferentialUnitsNationalUI(this));
438
439 referentialUnitsNationalUI.setName("referentialUnitsNationalUI");
440 }
441
442 protected void createSaveBouton() {
443 $objectMap.put("saveBouton", saveBouton = new JButton());
444
445 saveBouton.setName("saveBouton");
446 saveBouton.setText(t("reefdb.common.save"));
447 saveBouton.setToolTipText(t("reefdb.action.save.units"));
448 saveBouton.putClientProperty("applicationActionKey", fr.ifremer.reefdb.ui.swing.util.ReefDbKeyStrokes.SAVE);
449 saveBouton.putClientProperty("applicationAction", SaveAction.class);
450 }
451
452 protected void createScrollPane() {
453 $objectMap.put("scrollPane", scrollPane = new JScrollPane());
454
455 scrollPane.setName("scrollPane");
456 scrollPane.putClientProperty("onlyVerticalScrollable", true);
457 }
458
459 protected void createValidator() {
460 $objectMap.put("validator", validator = SwingValidator.newValidator(ReferentialUnitsUIModel.class, null));
461 }
462
463
464
465
466
467 private void $completeSetup() {
468 allComponentsCreated = true;
469 if (log.isDebugEnabled()) {
470 log.debug(this);
471 }
472
473 add(scrollPane, BorderLayout.CENTER);
474 add($JPanel1, BorderLayout.PAGE_END);
475 addChildrenToValidator();
476 addChildrenToScrollPane();
477
478 $Table0.add(referentialUnitsNationalUI, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
479 $Table0.add(SwingUtil.boxComponentWithJxLayer(referentialUnitsLocalUI), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
480
481 $JPanel1.add(closeButton);
482 $JPanel1.add(saveBouton);
483
484
485 JAXXUtil.applyDataBinding(this, $bindings.keySet());
486
487
488 closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
489 saveBouton.setAlignmentX(Component.CENTER_ALIGNMENT);
490 scrollPane.setBorder(null);
491 referentialUnitsNationalUI.setBorder(BorderFactory.createTitledBorder(t("reefdb.manage.referential.national.label")));
492 referentialUnitsLocalUI.setBorder(BorderFactory.createTitledBorder(t("reefdb.manage.referential.local.label")));
493 closeButton.setIcon(SwingUtil.createActionIcon("cancel"));
494 saveBouton.setIcon(SwingUtil.createActionIcon("save"));
495
496
497 validatorIds = SwingValidatorUtil.detectValidators(this);
498 SwingValidatorUtil.installUI(this);
499 }
500
501 private void $initialize() {
502 if (allComponentsCreated) {
503 return;
504 }
505 if (log.isDebugEnabled()) {
506 log.debug(this);
507 }
508 handler.beforeInit(this);
509 $objectMap.put("$JPanel0", $JPanel0);
510 createModel();
511 createBroker();
512 createValidator();
513 createScrollPane();
514
515 $objectMap.put("$Table0", $Table0 = new Table());
516
517 $Table0.setName("$Table0");
518 createReferentialUnitsNationalUI();
519 createReferentialUnitsLocalUI();
520
521 $objectMap.put("$JPanel1", $JPanel1 = new JPanel());
522
523 $JPanel1.setName("$JPanel1");
524 $JPanel1.setLayout(new GridLayout(1,0));
525 createCloseButton();
526 createSaveBouton();
527
528 setName("$JPanel0");
529 setLayout(new BorderLayout());
530
531
532 $registerDefaultBindings();
533 $completeSetup();
534 handler.afterInit(this);
535 }
536
537 private void $registerDefaultBindings() {
538
539 registerDataBinding(new DefaultJAXXBinding(this, BINDING_SAVE_BOUTON_ENABLED, true, true) {
540
541 @Override
542 public void applyDataBinding() {
543 if (model != null) {
544 model.addPropertyChangeListener("modify", this);
545 }
546 if (model != null) {
547 model.addPropertyChangeListener("valid", this);
548 }
549 }
550
551 @Override
552 public void processDataBinding() {
553 if (model != null) {
554 saveBouton.setEnabled(model.isModify() && model.isValid());
555 }
556 }
557
558 @Override
559 public void removeDataBinding() {
560 if (model != null) {
561 model.removePropertyChangeListener("modify", this);
562 }
563 if (model != null) {
564 model.removePropertyChangeListener("valid", this);
565 }
566 }
567 });
568 }
569
570 }