1 package fr.ifremer.dali.ui.swing.content.manage.program.programs;
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.GridBagConstraints;
13 import java.awt.Insets;
14 import java.awt.event.ActionEvent;
15 import java.awt.event.ActionListener;
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20 import java.util.TreeMap;
21 import javax.swing.BorderFactory;
22 import javax.swing.Box;
23 import javax.swing.BoxLayout;
24 import javax.swing.JButton;
25 import javax.swing.JComboBox;
26 import javax.swing.JPanel;
27 import javax.swing.JScrollPane;
28 import jaxx.runtime.JAXXBinding;
29 import jaxx.runtime.JAXXContext;
30 import jaxx.runtime.JAXXObject;
31 import jaxx.runtime.JAXXObjectDescriptor;
32 import jaxx.runtime.JAXXUtil;
33 import jaxx.runtime.JAXXValidator;
34 import jaxx.runtime.SwingUtil;
35 import jaxx.runtime.binding.DefaultJAXXBinding;
36 import jaxx.runtime.context.DefaultJAXXContext;
37 import jaxx.runtime.swing.Table;
38 import jaxx.runtime.swing.help.JAXXHelpUI;
39 import jaxx.runtime.validator.swing.SwingValidator;
40 import jaxx.runtime.validator.swing.SwingValidatorUtil;
41 import jaxx.runtime.validator.swing.meta.Validator;
42 import jaxx.runtime.validator.swing.meta.ValidatorField;
43 import jaxx.runtime.validator.swing.ui.ImageValidationUI;
44 import org.apache.commons.logging.Log;
45 import org.apache.commons.logging.LogFactory;
46 import static org.nuiton.i18n.I18n.t;
47
48 public class ProgramsTableUI extends Table implements JAXXHelpUI<DaliHelpBroker>, DaliUI<ProgramsTableUIModel, ProgramsTableUIHandler>, JAXXObject, JAXXValidator {
49
50
51
52
53
54 public static final String BINDING_EDIT_COMBOBOX_ENABLED = "editCombobox.enabled";
55 public static final String BINDING_SHOW_MANAGERS_BUTTON_ENABLED = "showManagersButton.enabled";
56 public static final String BINDING_SHOW_RECORDER_DEPARTMENTS_BUTTON_ENABLED = "showRecorderDepartmentsButton.enabled";
57 public static final String BINDING_SHOW_RECORDER_PERSONS_BUTTON_ENABLED = "showRecorderPersonsButton.enabled";
58
59
60
61
62
63 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAK1Wz28bRRR+ceOkdhpSEqW0aoKckKq2Wq2JEAcUCm0SRUmUQBSHKqovjHcn9pTdne3sON4QFRAXrhw5wp0LEjdOiANnDlwQ/wJCHLgi3szaXq+9/iHFPuyu5733vfe+mfftfv8XpH0BK89JEBii7krmUGP/yenph5Xn1JTb1DcF8yQXEP4mUpAqw4zVXvclvFE+UOHFZnhxizsed6nbEb1xAFlfXtjUr1EqJSzHI0zfL5ba5o3Aq4sWaruoJNRv//k79bX1xXcpgMDD6maxldywqKiTyQNIMUvCPGY6J0WbuFUsQzC3ivXOqrUtm/j+B8ShL+AzmD6AKY8IBJOwOnrLGkPHB56ErCQVmx4Rl9oSds+Ewc4EdagwLGIzo84Mv4H5DZO7EuEMh7ikSg1P8KogTuvuG0fNhxOF9tGe5+kMUxLSDrcU9OG4oA8VXoQ/VRH8Eyok3O+bYBv/7WLMpvaMQjPnaLAIciPhQWyX2oYmQkldn7YWI4TZtf2SKbhtK/7elPCa2qOgGdRhUu6ZKMrr7EiC0VH5izqxBKvSt6Ly9QaFJegAhbLYBru+tq83D7PPx7Lr1Xjilu+6+r+sLnfbthvUYhKPTYVXeCBhMYal1zd5oHxfb4fMqZDtuuNcbNalxF2EhVhUuBqPmfdrvHGod1r4kcO9uNcd5XVMTS4sKo7Qk7v9nZc7nbcpToR08DwlBAi4G9tmHHMjGvNoDifKkBZ1XJZwu9yrDMdoCjXhdpcmKEBt/e/Wwu8//fnjTksI5jD3YqJrh47hgOLJ8PAwM5V6LlSBumR28ZB4G2XI+NRGEdQit5RQWKlpxuIw36sq3FDhxi7xawiRnv7j519uffzbNUjtQNbmxNohyn8PMrImkAVuW4H3/mNd0Y3GdbzeVLWpKdPsSti63NRPYeCFYQpKJD1h0qZWaMnL/Kqev65BNqRyWi0UXgbI3FICc+3yK5lf/10o/fC4xd4EdnOnr3vEYPoZTDHXZi7VQtrUyEThnPF8Wrd4pIVJ6ggxefSac7+ur2/30JSKxO7zyxpxLRvn2aWNJ6Zk3G2NkJavfNfkPMz1jkW4ljgEcVPPkS+8lDBNXVU4vkzuXeqijCqVIWPUOuYNP18wfPYpzRdyjx7l1nFPVFPvaLLV0wZ0ScKw7q9hznPmM61o6TNi+3jPEt37npJ4mFRweJM0wNtNfUZM7jjcNZQlqYJuhRlWRDo5ZW9hzSKWEw+q09wHCTOSc/uEeSfae2WgN55vbzy8J2jkuBtfS2xFxA9bd//5UYLGR0P/l8C42RjcWMd8dTPycNTA8bEy+G03jBkl5Ta54OgMr7yLXzMkV2Guha/r93qSTajr0giIWSSh6qoqTpXPl8lIK0OR1PJXAxDuXxmhcGWEByPwMcnM8LujD8baSFV8c2UmBiGMxsQgBMXE/+vM7HmuDQAA";
64 private static final Log log = LogFactory.getLog(ProgramsTableUI.class);
65 private static final long serialVersionUID = 1L;
66
67
68
69
70
71 protected List<Object> $activeBindings = new ArrayList<Object>();
72 protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
73 protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
74 protected Map<String, Object> $objectMap = new HashMap<String, Object>();
75 protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
76 private boolean allComponentsCreated;
77 protected final JAXXContext delegateContext = new DefaultJAXXContext();
78
79
80
81
82
83 protected DaliHelpBroker broker;
84 @ValidatorField( validatorId = "validator", propertyName = "singleSelectedRow", editorName = "editCombobox")
85 protected JComboBox editCombobox;
86 protected JButton editDummyButton;
87 protected final ProgramsTableUIHandler handler = createHandler();
88 protected ProgramsTableUIModel model;
89 protected SwingTable programsTable;
90 protected JButton showManagersButton;
91 protected JButton showRecorderDepartmentsButton;
92 protected JButton showRecorderPersonsButton;
93 protected ProgramsTableUI tablePanel = this;
94 @Validator( validatorId = "validator")
95 protected SwingValidator<ProgramsTableUIModel> validator;
96 protected List<String> validatorIds = new ArrayList<String>();
97
98
99
100
101
102 private JPanel $JPanel0;
103 private JPanel $JPanel1;
104 private JScrollPane $JScrollPane0;
105
106
107
108
109
110 public ProgramsTableUI(ApplicationUI parentUI) {
111 ApplicationUIUtil.setParentUI(this, parentUI);
112 $initialize();
113 }
114
115 public ProgramsTableUI() {
116 $initialize();
117 }
118
119 public ProgramsTableUI(JAXXContext parentContext) {
120 JAXXUtil.initContext(this, parentContext);
121 $initialize();
122 }
123
124
125
126
127
128 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
129 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
130 }
131
132
133
134
135
136 @Override
137 public void applyDataBinding(String $binding) {
138 if (allComponentsCreated && $bindings.containsKey($binding)) {
139 getDataBinding($binding).applyDataBinding();
140 }
141 processDataBinding($binding);
142 }
143
144 @Override
145 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
146 super.firePropertyChange(propertyName, oldValue, newValue);
147 }
148
149 @Override
150 public Map<String, Object> get$objectMap() {
151 return $objectMap;
152 }
153
154 @Override
155 public JAXXBinding getDataBinding(String bindingId) {
156 return $bindings.get(bindingId);
157 }
158
159 @Override
160 public JAXXBinding[] getDataBindings() {
161 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
162 }
163
164 @Override
165 public Object getObjectById(String id) {
166 return $objectMap.get(id);
167 }
168
169 @Override
170 public void processDataBinding(String $binding, boolean $force) {
171 if (!$force && $activeBindings.contains($binding)) {
172 return;
173 }
174 $activeBindings.add($binding);
175 try {
176 if (allComponentsCreated && $bindings.containsKey($binding)) {
177 getDataBinding($binding).processDataBinding();
178 }
179 } finally {
180 $activeBindings.remove($binding);
181 }
182 }
183
184 @Override
185 public void processDataBinding(String $binding) {
186 processDataBinding($binding, false);
187 }
188
189 @Override
190 public void registerDataBinding(JAXXBinding binding) {
191 $bindings.put(binding.getId(), binding);
192 }
193
194 @Override
195 public void removeDataBinding(String $binding) {
196 if (allComponentsCreated && $bindings.containsKey($binding)) {
197 getDataBinding($binding).removeDataBinding();
198 }
199 }
200
201
202
203
204
205 @Override
206 public <T> T getContextValue(Class<T> clazz) {
207 return delegateContext.getContextValue(clazz, null);
208 }
209
210 @Override
211 public <T> T getContextValue(Class<T> clazz, String name) {
212 return delegateContext.getContextValue(clazz, name);
213 }
214
215 @Override
216 public JAXXContext getDelegateContext() {
217 return delegateContext;
218 }
219
220 @Override
221 public <O extends Container> O getParentContainer(Class<O> clazz) {
222 return SwingUtil.getParentContainer(this, clazz);
223 }
224
225 @Override
226 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
227 return SwingUtil.getParentContainer(source, clazz);
228 }
229
230 @Override
231 public <T> void removeContextValue(Class<T> clazz) {
232 delegateContext.removeContextValue(clazz, null);
233 }
234
235 @Override
236 public <T> void removeContextValue(Class<T> clazz, String name) {
237 delegateContext.removeContextValue(clazz, name);
238 }
239
240 @Override
241 public <T> void setContextValue(T o) {
242 delegateContext.setContextValue(o, null);
243 }
244
245 @Override
246 public <T> void setContextValue(T o, String name) {
247 delegateContext.setContextValue(o, name);
248 }
249
250
251
252
253
254 @Override
255 public SwingValidator<?> getValidator(String validatorId) {
256 return (SwingValidator<?>) (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);
257 }
258
259 @Override
260 public List<String> getValidatorIds() {
261 return validatorIds;
262 }
263
264 @Override
265 public void registerValidatorFields() {
266 SwingValidatorUtil.detectValidatorFields(this);
267 }
268
269
270
271
272
273 public void doActionPerformed__on__showManagersButton(ActionEvent event) {
274 if (log.isDebugEnabled()) {
275 log.debug(event);
276 }
277 handler.showManagers();
278 }
279
280 public void doActionPerformed__on__showRecorderDepartmentsButton(ActionEvent event) {
281 if (log.isDebugEnabled()) {
282 log.debug(event);
283 }
284 handler.showRecorderDepartments();
285 }
286
287 public void doActionPerformed__on__showRecorderPersonsButton(ActionEvent event) {
288 if (log.isDebugEnabled()) {
289 log.debug(event);
290 }
291 handler.showRecorderPersons();
292 }
293
294
295
296
297
298 public DaliHelpBroker getBroker() {
299 return broker;
300 }
301
302 public JComboBox getEditCombobox() {
303 return editCombobox;
304 }
305
306 public JButton getEditDummyButton() {
307 return editDummyButton;
308 }
309
310 public ProgramsTableUIHandler getHandler() {
311 return handler;
312 }
313
314 public ProgramsTableUIModel getModel() {
315 return model;
316 }
317
318 public SwingTable getProgramsTable() {
319 return programsTable;
320 }
321
322 public JButton getShowManagersButton() {
323 return showManagersButton;
324 }
325
326 public JButton getShowRecorderDepartmentsButton() {
327 return showRecorderDepartmentsButton;
328 }
329
330 public JButton getShowRecorderPersonsButton() {
331 return showRecorderPersonsButton;
332 }
333
334 public SwingValidator<ProgramsTableUIModel> getValidator() {
335 return validator;
336 }
337
338
339
340
341
342 @Override
343 public void registerHelpId(DaliHelpBroker broker, Component component, String helpId) {
344 broker.installUI(component, helpId);
345 }
346
347 @Override
348 public void showHelp(String helpId) {
349 getBroker().showHelp(this, helpId);
350 }
351
352
353
354
355
356 protected JPanel get$JPanel0() {
357 return $JPanel0;
358 }
359
360 protected JPanel get$JPanel1() {
361 return $JPanel1;
362 }
363
364 protected JScrollPane get$JScrollPane0() {
365 return $JScrollPane0;
366 }
367
368
369
370
371
372 protected void addChildrenToTablePanel() {
373 if (!allComponentsCreated) {
374 return;
375 }
376 add($JScrollPane0, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
377 add($JPanel0, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
378 }
379
380 protected void addChildrenToValidator() {
381 if (!allComponentsCreated) {
382 return;
383 }
384 validator.setUiClass(ImageValidationUI.class);
385 validator.setBean(model);
386 }
387
388 protected void createBroker() {
389 $objectMap.put("broker", broker = new DaliHelpBroker("dali.home.help"));
390 }
391
392 protected void createEditCombobox() {
393 $objectMap.put("editCombobox", editCombobox = new JComboBox());
394
395 editCombobox.setName("editCombobox");
396 }
397
398 protected void createEditDummyButton() {
399 $objectMap.put("editDummyButton", editDummyButton = new JButton());
400
401 editDummyButton.setName("editDummyButton");
402 editDummyButton.setVisible(false);
403 editDummyButton.setText(t("dali.common.edit"));
404 }
405
406 protected ProgramsTableUIHandler createHandler() {
407 return new ProgramsTableUIHandler();
408 }
409
410 protected void createModel() {
411 $objectMap.put("model", model = getContextValue(ProgramsTableUIModel.class));
412 }
413
414 protected void createProgramsTable() {
415 $objectMap.put("programsTable", programsTable = new SwingTable());
416
417 programsTable.setName("programsTable");
418 }
419
420 protected void createShowManagersButton() {
421 $objectMap.put("showManagersButton", showManagersButton = new JButton());
422
423 showManagersButton.setName("showManagersButton");
424 showManagersButton.setVisible(false);
425 showManagersButton.setText(t("dali.program.program.managers"));
426 showManagersButton.setToolTipText(t("dali.program.program.managers.tip"));
427 showManagersButton.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__showManagersButton"));
428 }
429
430 protected void createShowRecorderDepartmentsButton() {
431 $objectMap.put("showRecorderDepartmentsButton", showRecorderDepartmentsButton = new JButton());
432
433 showRecorderDepartmentsButton.setName("showRecorderDepartmentsButton");
434 showRecorderDepartmentsButton.setVisible(false);
435 showRecorderDepartmentsButton.setText(t("dali.program.program.recorderDepartments"));
436 showRecorderDepartmentsButton.setToolTipText(t("dali.program.program.recorderDepartments.tip"));
437 showRecorderDepartmentsButton.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__showRecorderDepartmentsButton"));
438 }
439
440 protected void createShowRecorderPersonsButton() {
441 $objectMap.put("showRecorderPersonsButton", showRecorderPersonsButton = new JButton());
442
443 showRecorderPersonsButton.setName("showRecorderPersonsButton");
444 showRecorderPersonsButton.setVisible(false);
445 showRecorderPersonsButton.setText(t("dali.program.program.recorderPersons"));
446 showRecorderPersonsButton.setToolTipText(t("dali.program.program.recorderPersons.tip"));
447 showRecorderPersonsButton.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__showRecorderPersonsButton"));
448 }
449
450 protected void createValidator() {
451 $objectMap.put("validator", validator = SwingValidator.newValidator(ProgramsTableUIModel.class, null));
452 }
453
454
455
456
457
458 private void $completeSetup() {
459 allComponentsCreated = true;
460 if (log.isDebugEnabled()) {
461 log.debug(this);
462 }
463 addChildrenToTablePanel();
464 addChildrenToValidator();
465
466 $JScrollPane0.getViewport().add(programsTable);
467
468 $JPanel0.add($JPanel1, BorderLayout.LINE_START);
469
470 $JPanel1.add(SwingUtil.boxComponentWithJxLayer(editCombobox));
471 $JPanel1.add(editDummyButton);
472 $JPanel1.add(showManagersButton);
473 $JPanel1.add(showRecorderPersonsButton);
474 $JPanel1.add(showRecorderDepartmentsButton);
475
476
477 JAXXUtil.applyDataBinding(this, $bindings.keySet());
478
479
480 editCombobox.setAlignmentX(Component.CENTER_ALIGNMENT);
481 showManagersButton.setAlignmentX(Component.CENTER_ALIGNMENT);
482 showRecorderPersonsButton.setAlignmentX(Component.CENTER_ALIGNMENT);
483 showRecorderDepartmentsButton.setAlignmentX(Component.CENTER_ALIGNMENT);
484 setBorder(BorderFactory.createTitledBorder(t("dali.program.program.title")));
485 editCombobox.setModel(handler.newActionComboBoxModel(editDummyButton, showManagersButton, showRecorderPersonsButton, showRecorderDepartmentsButton));
486 editDummyButton.setIcon(SwingUtil.createActionIcon("edit"));
487 showManagersButton.setIcon(SwingUtil.createActionIcon("edit"));
488 showRecorderPersonsButton.setIcon(SwingUtil.createActionIcon("edit"));
489 showRecorderDepartmentsButton.setIcon(SwingUtil.createActionIcon("edit"));
490
491
492 validatorIds = SwingValidatorUtil.detectValidators(this);
493 SwingValidatorUtil.installUI(this);
494 }
495
496 private void $initialize() {
497 if (allComponentsCreated) {
498 return;
499 }
500 if (log.isDebugEnabled()) {
501 log.debug(this);
502 }
503 handler.beforeInit(this);
504 $objectMap.put("tablePanel", tablePanel);
505 createModel();
506 createBroker();
507 createValidator();
508
509 $objectMap.put("$JScrollPane0", $JScrollPane0 = new JScrollPane());
510
511 $JScrollPane0.setName("$JScrollPane0");
512 createProgramsTable();
513
514 $objectMap.put("$JPanel0", $JPanel0 = new JPanel());
515
516 $JPanel0.setName("$JPanel0");
517 $JPanel0.setLayout(new BorderLayout());
518
519 $objectMap.put("$JPanel1", $JPanel1 = new JPanel());
520
521 $JPanel1.setName("$JPanel1");
522 createEditCombobox();
523 createEditDummyButton();
524 createShowManagersButton();
525 createShowRecorderPersonsButton();
526 createShowRecorderDepartmentsButton();
527
528 setName("tablePanel");
529
530
531 $registerDefaultBindings();
532 $completeSetup();
533 handler.afterInit(this);
534 }
535
536 private void $registerDefaultBindings() {
537
538 registerDataBinding(new DefaultJAXXBinding(this, BINDING_EDIT_COMBOBOX_ENABLED, true) {
539
540 @Override
541 public void applyDataBinding() {
542 if (model != null) {
543 model.addPropertyChangeListener("selectedRows", this);
544 }
545 }
546
547 @Override
548 public void processDataBinding() {
549 if (model != null && model.getSelectedRows() != null) {
550 editCombobox.setEnabled(model.getSelectedRows().size() == 1);
551 }
552 }
553
554 @Override
555 public void removeDataBinding() {
556 if (model != null) {
557 model.removePropertyChangeListener("selectedRows", this);
558 }
559 }
560 });
561 registerDataBinding(new DefaultJAXXBinding(this, BINDING_SHOW_MANAGERS_BUTTON_ENABLED, true) {
562
563 @Override
564 public void applyDataBinding() {
565 if (model != null) {
566 model.addPropertyChangeListener("selectedRows", this);
567 }
568 }
569
570 @Override
571 public void processDataBinding() {
572 if (model != null && model.getSelectedRows() != null) {
573 showManagersButton.setEnabled(model.getSelectedRows().size() == 1);
574 }
575 }
576
577 @Override
578 public void removeDataBinding() {
579 if (model != null) {
580 model.removePropertyChangeListener("selectedRows", this);
581 }
582 }
583 });
584 registerDataBinding(new DefaultJAXXBinding(this, BINDING_SHOW_RECORDER_PERSONS_BUTTON_ENABLED, true) {
585
586 @Override
587 public void applyDataBinding() {
588 if (model != null) {
589 model.addPropertyChangeListener("selectedRows", this);
590 }
591 }
592
593 @Override
594 public void processDataBinding() {
595 if (model != null && model.getSelectedRows() != null) {
596 showRecorderPersonsButton.setEnabled(model.getSelectedRows().size() == 1);
597 }
598 }
599
600 @Override
601 public void removeDataBinding() {
602 if (model != null) {
603 model.removePropertyChangeListener("selectedRows", this);
604 }
605 }
606 });
607 registerDataBinding(new DefaultJAXXBinding(this, BINDING_SHOW_RECORDER_DEPARTMENTS_BUTTON_ENABLED, true) {
608
609 @Override
610 public void applyDataBinding() {
611 if (model != null) {
612 model.addPropertyChangeListener("selectedRows", this);
613 }
614 }
615
616 @Override
617 public void processDataBinding() {
618 if (model != null && model.getSelectedRows() != null) {
619 showRecorderDepartmentsButton.setEnabled(model.getSelectedRows().size() == 1);
620 }
621 }
622
623 @Override
624 public void removeDataBinding() {
625 if (model != null) {
626 model.removePropertyChangeListener("selectedRows", this);
627 }
628 }
629 });
630 }
631
632 }