1 package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.fraction.menu;
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.core.dto.referential.StatusDTO;
28 import fr.ifremer.quadrige3.ui.swing.ApplicationUI;
29 import fr.ifremer.quadrige3.ui.swing.ApplicationUIUtil;
30 import fr.ifremer.quadrige3.ui.swing.component.bean.ExtendedComboBox;
31 import fr.ifremer.reefdb.dto.referential.pmfm.FractionDTO;
32 import fr.ifremer.reefdb.ui.swing.ReefDbHelpBroker;
33 import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
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.JLabel;
53 import javax.swing.JPanel;
54 import javax.swing.SwingConstants;
55 import jaxx.runtime.JAXXBinding;
56 import jaxx.runtime.JAXXContext;
57 import jaxx.runtime.JAXXObject;
58 import jaxx.runtime.JAXXObjectDescriptor;
59 import jaxx.runtime.JAXXUtil;
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 org.apache.commons.logging.Log;
66 import org.apache.commons.logging.LogFactory;
67 import static org.nuiton.i18n.I18n.t;
68
69 public class ManageFractionsMenuUI extends JPanel implements JAXXHelpUI<ReefDbHelpBroker>, ReefDbUI<ManageFractionsMenuUIModel, ManageFractionsMenuUIHandler>, JAXXObject {
70
71
72
73
74
75 public static final String BINDING_LABEL_COMBO_SELECTED_ITEM = "labelCombo.selectedItem";
76 public static final String BINDING_STATUS_COMBO_SELECTED_ITEM = "statusCombo.selectedItem";
77
78
79
80
81
82 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAALVWTW/jRBiehCRtmra7NG3VhbJ0y1cLaAKLxKV8tGmJtqt0QU2QKiIBE3uSzjKxveMxdRQt4geAxIkznLhwAIkbJ8SBMwcuK/4CQhy4It4ZO3aSukmWikqd2vN+Pe/zzjzut3+grCvQjbvE97HwLMk6FN/eOzl5u3mXGvKAuoZgjrQFCn5SaZRuoIIZ7bsSPdWoqvBSGF7atzuObVFrIHqniuZc2eXUPaVUSvTEcIThuqVaZN7xHU/0s0agkrJ+9def6S/MT79OI+Q7gG4RWtmYFBV3kqmiNDMlWoJKH5MSJ1YbYAhmtQHvgtrb58R175AOvYc+QTNVlHOIgGQSbU7fss6h431Hotmnb79DLMpfkuj9lsCsJWiHCiwobZlN7DHsnkF9bNiWhHS4QyzSpmBuUVWYEY6dTquDW4IYktkW7lDLw0faqxLuuUew9+6h4+iqOYmyHdukXCLj/y14pKrEVXNNYX9EhUQvjCl7DO8HzVsQV9becXheFdJUwYDULPwwJOBPeeUj50WXcqqxhBFrQ6cgCKyTJteDXIri+tN4Wb0vq2Ulss1x0qS8qpZRBHpTua2NeMM5aNoSvT7Q8T2PmIK16SuDXIenBTcpsfBbPjBvUlMHl21/OHEf4s0EiAVXEum5EZx1tWyMmnVetfXksHklIq3sSQljjIhdHmapYHBKROAkUXGIimBXOT4b+c+74G6cxqbnQ7tAjw/NBe49ju99fDFTDZQVHmzDIBvnpeIYTIFIrI2IhEqorf+sFn/78fcfKn1lWILaK4muA8IGN9YRtgNnlqnSVwJZ8CTjpSPi7DRQPmBMq956ArBaaAZwUO9RFY5VOL5F3FNIkZ158NPPqx/++ghKV+DE2MSsEOV/iPLyVAALNjd9581djWj+bBbWq/CbgePVYlxSoU6whHfhwZ8F8D87oIYtCOSAa94i3IX9vNo/pq4S2tA1ow6aRDM9rQT3faBuPYG6CH8z/8vfxdr3u336UtDOtQvdYwqz76EcszizqJbWUDUTpbTguNQz7Vgdk/QSgWJeHb0foUbc1Our59hKKemxhamkZ69X1k8BzV1sCEokrTPJqRlYtuTWZihKIIEt1g4ETiqXze1toEpV2dUcqKcyOqc2zgRAabjEWh0qakrzvVgp7qsBUR/mtBxiCM9fF1vAVFLtAVWaou58gJSah5J24MYH88dtKvvavbUNIGb7ZeGxL/QXF9fQH67phd6AFMVdr452HXgllR6UuodvvBg3XtN5RtvOTaw8VddwU5c+II7DmUEUiXuaSlV/X0lo8IoNdcKh/lzA9KH69oLg9W+spmYjpCb86gaKirUQYx58kwrStnmdOXUdcH1MgGROYmcDuv5fO1vu1XSlca1lWswyo84eSwSa2NNaousF3Qx9dSa1o0SCk64NzmjxNZNIstEEkPBJe+Nc7pRaixMzqu3P1PJ5coZrU2CaVTpd7zp0TJ7rl0ZyY6oMX47J8MylMTw3BRtzhLO2BXosT8Zk2p4KyzdjMrw4BZYMM4L/ZS6F4rsJKP4FVIWhGo8NAAA=";
83 private static final Log log = LogFactory.getLog(ManageFractionsMenuUI.class);
84 private static final long serialVersionUID = 1L;
85
86
87
88
89
90 protected List<Object> $activeBindings = new ArrayList<Object>();
91 protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
92 protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
93 protected Map<String, Object> $objectMap = new HashMap<String, Object>();
94 protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
95 private boolean allComponentsCreated;
96 protected final JAXXContext delegateContext = new DefaultJAXXContext();
97
98
99
100
101
102 protected ReefDbHelpBroker broker;
103 protected JButton clearButton;
104 protected final ManageFractionsMenuUIHandler handler = createHandler();
105 protected ExtendedComboBox<FractionDTO> labelCombo;
106 protected JLabel labelLabel;
107 protected JPanel menuPanel;
108 protected ManageFractionsMenuUIModel model;
109 protected JButton searchButton;
110 protected JPanel selectionButtonsPanel;
111 protected Table selectionPanel;
112 protected ExtendedComboBox<StatusDTO> statusCombo;
113 protected JLabel statusLabel;
114
115
116
117
118
119 private ManageFractionsMenuUI $JPanel0 = this;
120 private JPanel $JPanel1;
121 private JPanel $JPanel2;
122
123
124
125
126
127 public ManageFractionsMenuUI(ApplicationUI parentUI) {
128 ApplicationUIUtil.setParentUI(this, parentUI);
129 $initialize();
130 }
131
132 public ManageFractionsMenuUI(LayoutManager param0, boolean param1) {
133 super(param0 ,param1);
134 $initialize();
135 }
136
137 public ManageFractionsMenuUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
138 super(param1 ,param2);
139 JAXXUtil.initContext(this, parentContext);
140 $initialize();
141 }
142
143 public ManageFractionsMenuUI(boolean param0) {
144 super(param0);
145 $initialize();
146 }
147
148 public ManageFractionsMenuUI(JAXXContext parentContext, boolean param1) {
149 super(param1);
150 JAXXUtil.initContext(this, parentContext);
151 $initialize();
152 }
153
154 public ManageFractionsMenuUI() {
155 $initialize();
156 }
157
158 public ManageFractionsMenuUI(JAXXContext parentContext) {
159 JAXXUtil.initContext(this, parentContext);
160 $initialize();
161 }
162
163 public ManageFractionsMenuUI(LayoutManager param0) {
164 super(param0);
165 $initialize();
166 }
167
168 public ManageFractionsMenuUI(JAXXContext parentContext, LayoutManager param1) {
169 super(param1);
170 JAXXUtil.initContext(this, parentContext);
171 $initialize();
172 }
173
174
175
176
177
178 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
179 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
180 }
181
182
183
184
185
186 @Override
187 public void applyDataBinding(String $binding) {
188 if (allComponentsCreated && $bindings.containsKey($binding)) {
189 getDataBinding($binding).applyDataBinding();
190 }
191 processDataBinding($binding);
192 }
193
194 @Override
195 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
196 super.firePropertyChange(propertyName, oldValue, newValue);
197 }
198
199 @Override
200 public Map<String, Object> get$objectMap() {
201 return $objectMap;
202 }
203
204 @Override
205 public JAXXBinding getDataBinding(String bindingId) {
206 return $bindings.get(bindingId);
207 }
208
209 @Override
210 public JAXXBinding[] getDataBindings() {
211 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
212 }
213
214 @Override
215 public Object getObjectById(String id) {
216 return $objectMap.get(id);
217 }
218
219 @Override
220 public void processDataBinding(String $binding, boolean $force) {
221 if (!$force && $activeBindings.contains($binding)) {
222 return;
223 }
224 $activeBindings.add($binding);
225 try {
226 if (allComponentsCreated && $bindings.containsKey($binding)) {
227 getDataBinding($binding).processDataBinding();
228 }
229 } finally {
230 $activeBindings.remove($binding);
231 }
232 }
233
234 @Override
235 public void processDataBinding(String $binding) {
236 processDataBinding($binding, false);
237 }
238
239 @Override
240 public void registerDataBinding(JAXXBinding binding) {
241 $bindings.put(binding.getId(), binding);
242 }
243
244 @Override
245 public void removeDataBinding(String $binding) {
246 if (allComponentsCreated && $bindings.containsKey($binding)) {
247 getDataBinding($binding).removeDataBinding();
248 }
249 }
250
251
252
253
254
255 @Override
256 public <T> T getContextValue(Class<T> clazz) {
257 return delegateContext.getContextValue(clazz, null);
258 }
259
260 @Override
261 public <T> T getContextValue(Class<T> clazz, String name) {
262 return delegateContext.getContextValue(clazz, name);
263 }
264
265 @Override
266 public JAXXContext getDelegateContext() {
267 return delegateContext;
268 }
269
270 @Override
271 public <O extends Container> O getParentContainer(Class<O> clazz) {
272 return SwingUtil.getParentContainer(this, clazz);
273 }
274
275 @Override
276 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
277 return SwingUtil.getParentContainer(source, clazz);
278 }
279
280 @Override
281 public <T> void removeContextValue(Class<T> clazz) {
282 delegateContext.removeContextValue(clazz, null);
283 }
284
285 @Override
286 public <T> void removeContextValue(Class<T> clazz, String name) {
287 delegateContext.removeContextValue(clazz, name);
288 }
289
290 @Override
291 public <T> void setContextValue(T o) {
292 delegateContext.setContextValue(o, null);
293 }
294
295 @Override
296 public <T> void setContextValue(T o, String name) {
297 delegateContext.setContextValue(o, name);
298 }
299
300
301
302
303
304 public ReefDbHelpBroker getBroker() {
305 return broker;
306 }
307
308 public JButton getClearButton() {
309 return clearButton;
310 }
311
312 public ManageFractionsMenuUIHandler getHandler() {
313 return handler;
314 }
315
316 public ExtendedComboBox<FractionDTO> getLabelCombo() {
317 return labelCombo;
318 }
319
320 public JLabel getLabelLabel() {
321 return labelLabel;
322 }
323
324 public JPanel getMenuPanel() {
325 return menuPanel;
326 }
327
328 public ManageFractionsMenuUIModel getModel() {
329 return model;
330 }
331
332 public JButton getSearchButton() {
333 return searchButton;
334 }
335
336 public JPanel getSelectionButtonsPanel() {
337 return selectionButtonsPanel;
338 }
339
340 public Table getSelectionPanel() {
341 return selectionPanel;
342 }
343
344 public ExtendedComboBox<StatusDTO> getStatusCombo() {
345 return statusCombo;
346 }
347
348 public JLabel getStatusLabel() {
349 return statusLabel;
350 }
351
352
353
354
355
356 @Override
357 public void registerHelpId(ReefDbHelpBroker broker, Component component, String helpId) {
358 broker.installUI(component, helpId);
359 }
360
361 @Override
362 public void showHelp(String helpId) {
363 getBroker().showHelp(this, helpId);
364 }
365
366
367
368
369
370 protected JPanel get$JPanel1() {
371 return $JPanel1;
372 }
373
374 protected JPanel get$JPanel2() {
375 return $JPanel2;
376 }
377
378
379
380
381
382 protected void addChildrenToMenuPanel() {
383 if (!allComponentsCreated) {
384 return;
385 }
386 menuPanel.add(selectionPanel);
387 menuPanel.add(selectionButtonsPanel);
388 }
389
390 protected void addChildrenToSelectionButtonsPanel() {
391 if (!allComponentsCreated) {
392 return;
393 }
394 selectionButtonsPanel.add(clearButton);
395 selectionButtonsPanel.add(searchButton);
396 }
397
398 protected void addChildrenToSelectionPanel() {
399 if (!allComponentsCreated) {
400 return;
401 }
402 selectionPanel.add($JPanel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
403 selectionPanel.add($JPanel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
404 }
405
406 protected void createBroker() {
407 $objectMap.put("broker", broker = new ReefDbHelpBroker("reefdb.home.help"));
408 }
409
410 protected void createClearButton() {
411 $objectMap.put("clearButton", clearButton = new JButton());
412
413 clearButton.setName("clearButton");
414 clearButton.setText(t("reefdb.action.search.clear.label"));
415 clearButton.setToolTipText(t("reefdb.action.search.clear.tip"));
416 clearButton.putClientProperty("applicationAction", ClearAction.class);
417 }
418
419 protected ManageFractionsMenuUIHandler createHandler() {
420 return new ManageFractionsMenuUIHandler();
421 }
422
423 protected void createLabelCombo() {
424 $objectMap.put("labelCombo", labelCombo = new ExtendedComboBox<FractionDTO>(this));
425
426 labelCombo.setName("labelCombo");
427 labelCombo.setFilterable(true);
428 labelCombo.setShowDecorator(false);
429 labelCombo.setProperty("fraction");
430 labelCombo.setShowReset(true);
431 }
432
433 protected void createLabelLabel() {
434 $objectMap.put("labelLabel", labelLabel = new JLabel());
435
436 labelLabel.setName("labelLabel");
437 labelLabel.setText(t("reefdb.property.name"));
438 }
439
440 protected void createMenuPanel() {
441 $objectMap.put("menuPanel", menuPanel = new JPanel());
442
443 menuPanel.setName("menuPanel");
444 menuPanel.setLayout(new BoxLayout(menuPanel, BoxLayout.PAGE_AXIS));
445 }
446
447 protected void createModel() {
448 $objectMap.put("model", model = getContextValue(ManageFractionsMenuUIModel.class));
449 }
450
451 protected void createSearchButton() {
452 $objectMap.put("searchButton", searchButton = new JButton());
453
454 searchButton.setName("searchButton");
455 searchButton.setText(t("reefdb.action.search.label"));
456 searchButton.setToolTipText(t("reefdb.action.search.tip"));
457 searchButton.putClientProperty("applicationAction", SearchAction.class);
458 }
459
460 protected void createSelectionButtonsPanel() {
461 $objectMap.put("selectionButtonsPanel", selectionButtonsPanel = new JPanel());
462
463 selectionButtonsPanel.setName("selectionButtonsPanel");
464 selectionButtonsPanel.setLayout(new GridLayout(1,0));
465 }
466
467 protected void createSelectionPanel() {
468 $objectMap.put("selectionPanel", selectionPanel = new Table());
469
470 selectionPanel.setName("selectionPanel");
471 }
472
473 protected void createStatusCombo() {
474 $objectMap.put("statusCombo", statusCombo = new ExtendedComboBox<StatusDTO>(this));
475
476 statusCombo.setName("statusCombo");
477 statusCombo.setFilterable(true);
478 statusCombo.setShowDecorator(false);
479 statusCombo.setProperty("status");
480 statusCombo.setShowReset(true);
481 }
482
483 protected void createStatusLabel() {
484 $objectMap.put("statusLabel", statusLabel = new JLabel());
485
486 statusLabel.setName("statusLabel");
487 statusLabel.setText(t("reefdb.property.status"));
488 }
489
490
491
492
493
494 private void $completeSetup() {
495 allComponentsCreated = true;
496 if (log.isDebugEnabled()) {
497 log.debug(this);
498 }
499
500 add(menuPanel);
501 addChildrenToMenuPanel();
502 addChildrenToSelectionPanel();
503
504 $JPanel1.add(labelLabel, BorderLayout.PAGE_START);
505 $JPanel1.add(labelCombo, BorderLayout.CENTER);
506
507 $JPanel2.add(statusLabel, BorderLayout.PAGE_START);
508 $JPanel2.add(statusCombo, BorderLayout.CENTER);
509 addChildrenToSelectionButtonsPanel();
510
511
512 JAXXUtil.applyDataBinding(this, $bindings.keySet());
513
514
515 labelCombo.setBeanType(FractionDTO.class);
516 statusCombo.setBeanType(StatusDTO.class);
517 clearButton.setAlignmentX(Component.CENTER_ALIGNMENT);
518 searchButton.setAlignmentX(Component.CENTER_ALIGNMENT);
519 selectionPanel.setBorder(BorderFactory.createTitledBorder(t("reefdb.config.menu.title")));
520 labelLabel.setLabelFor(labelCombo);
521 labelCombo.setBean(model);
522 statusLabel.setLabelFor(statusCombo);
523 statusCombo.setBean(model);
524 clearButton.setIcon(SwingUtil.createActionIcon("reset"));
525 searchButton.setIcon(SwingUtil.createActionIcon("find"));
526 }
527
528 private void $initialize() {
529 if (allComponentsCreated) {
530 return;
531 }
532 if (log.isDebugEnabled()) {
533 log.debug(this);
534 }
535 handler.beforeInit(this);
536 $objectMap.put("$JPanel0", $JPanel0);
537 createModel();
538 createBroker();
539 createMenuPanel();
540 createSelectionPanel();
541
542 $objectMap.put("$JPanel1", $JPanel1 = new JPanel());
543
544 $JPanel1.setName("$JPanel1");
545 $JPanel1.setLayout(new BorderLayout());
546 createLabelLabel();
547 createLabelCombo();
548
549 $objectMap.put("$JPanel2", $JPanel2 = new JPanel());
550
551 $JPanel2.setName("$JPanel2");
552 $JPanel2.setLayout(new BorderLayout());
553 createStatusLabel();
554 createStatusCombo();
555 createSelectionButtonsPanel();
556 createClearButton();
557 createSearchButton();
558
559 setName("$JPanel0");
560
561
562 $registerDefaultBindings();
563 $completeSetup();
564 handler.afterInit(this);
565 }
566
567 private void $registerDefaultBindings() {
568
569 registerDataBinding(new DefaultJAXXBinding(this, BINDING_LABEL_COMBO_SELECTED_ITEM, true) {
570
571 @Override
572 public void applyDataBinding() {
573 if (model != null) {
574 model.addPropertyChangeListener("fraction", this);
575 }
576 }
577
578 @Override
579 public void processDataBinding() {
580 if (model != null) {
581 labelCombo.setSelectedItem(model.getFraction());
582 }
583 }
584
585 @Override
586 public void removeDataBinding() {
587 if (model != null) {
588 model.removePropertyChangeListener("fraction", this);
589 }
590 }
591 });
592 registerDataBinding(new DefaultJAXXBinding(this, BINDING_STATUS_COMBO_SELECTED_ITEM, true) {
593
594 @Override
595 public void applyDataBinding() {
596 if (model != null) {
597 model.addPropertyChangeListener("status", this);
598 }
599 }
600
601 @Override
602 public void processDataBinding() {
603 if (model != null) {
604 statusCombo.setSelectedItem(model.getStatus());
605 }
606 }
607
608 @Override
609 public void removeDataBinding() {
610 if (model != null) {
611 model.removePropertyChangeListener("status", this);
612 }
613 }
614 });
615 }
616
617 }