1 package fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.local;
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.quadrige3.ui.swing.table.SwingTable;
30 import fr.ifremer.reefdb.ui.swing.ReefDbHelpBroker;
31 import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
32 import fr.ifremer.reefdb.ui.swing.content.manage.referential.unit.menu.ReferentialUnitsMenuUI;
33 import fr.ifremer.reefdb.ui.swing.util.ReefDbUI;
34 import java.awt.BorderLayout;
35 import java.awt.Component;
36 import java.awt.Container;
37 import java.awt.FlowLayout;
38 import java.awt.LayoutManager;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.util.ArrayList;
42 import java.util.HashMap;
43 import java.util.List;
44 import java.util.Map;
45 import java.util.TreeMap;
46 import javax.swing.Box;
47 import javax.swing.BoxLayout;
48 import javax.swing.JButton;
49 import javax.swing.JPanel;
50 import javax.swing.JScrollPane;
51 import jaxx.runtime.JAXXBinding;
52 import jaxx.runtime.JAXXContext;
53 import jaxx.runtime.JAXXObject;
54 import jaxx.runtime.JAXXObjectDescriptor;
55 import jaxx.runtime.JAXXUtil;
56 import jaxx.runtime.SwingUtil;
57 import jaxx.runtime.binding.DefaultJAXXBinding;
58 import jaxx.runtime.context.DefaultJAXXContext;
59 import org.apache.commons.logging.Log;
60 import org.apache.commons.logging.LogFactory;
61 import static org.nuiton.i18n.I18n.t;
62
63 public class ReferentialUnitsLocalUI extends JPanel implements ReefDbUI<ReferentialUnitsLocalUIModel, ReferentialUnitsLocalUIHandler>, JAXXObject {
64
65
66
67
68
69 public static final String BINDING_REFERENTIAL_UNITS_LOCAL_TABLE_DELETE_BOUTON_ENABLED = "referentialUnitsLocalTableDeleteBouton.enabled";
70 public static final String BINDING_REFERENTIAL_UNITS_LOCAL_TABLE_REPLACE_BOUTON_ENABLED = "referentialUnitsLocalTableReplaceBouton.enabled";
71
72
73
74
75
76 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAALVVQW8bRRQeO7HTOClQQtIUCiQllERF41a9VIRCm4aoiZwW2QmKsAod706caWdnprOzzaZRq/4EfgLcuSBx44Q4cObABfEXEOLAFfFm197NNmvHwiJSVut5733fe9/MfPvtH6jkazT/gIQh1oEwzKN44+bOzt3WA+qYVeo7mikjNYr/CkVUbKIJN1n3DXqnWbPl1U559Zb0lBRUHKlerqGKbw449fcoNQa9ma1wfL/aSMLLoQp0FzVpKg/167/+LH7lPv+miFCooLsJGGXupKp0ktEaKjLXoFeB6TGpciLa0IZmog39nrZrtzjx/TvEo4/QMzRWQ2VFNIAZdGHwkSOMqD5UBp1a2PiUCMovG7SzqzHb1dSjGmtKd90WDhj294EfO1IYgMMeEaRNIbxLLTEjHAeCGcylA6/1dHkbVv2aXd1eVyriKxtU8qRLuUH3/i+qTYuf8pVbWj6k2qBLfQjr8Hu1dRvqVqLsI+UeFcH2ukGfDdGvxTjW7mYEbGnGE7buVlyBE2A3O+wQxKvZ3NMLGw1HS85tDPbubKYgDdn06aTqdZ2n2hZpcWoQPjLjo4C4mrXp1XRMY7Nww75HBRZyNkGebAXGSOEnrZ7NMr/Xm/mODB5TEqzIAAAMmspMshLBWpC3EqyLvbFWKUxCYyibfSFb2aeLOlWcODmlGr2RucHgDTj1hvTyFpqopANYNmi2edxO6hCKjWT2BSOxgFH0n5mpX3/4/fu1rntMAvd0buoR84NbrbRUcMaZpX45to7AMF7dJGq5icZ90MSJnfF8TmONThiaA74zthzbcnyb+HsAURr77cefZu7/MoKKa6jCJXHXiM1fR+NmT4MKkruh+vhG1NHk/il4vgL/IwZVII9JsW4vCBohLjjbqKEhuNWZzh1ypOdJgQXdN2jCSMm3mNrqkRGCdOdzpEv6b43//PdU47sbXfkKMM65numphKXPUZkJzgSN7LfjrLl2O6F8GrgyddA8T0WDn3bVsZr3o+flYyKWwAm+JEpx5hAr5c1IUPhcHd5VVHSOrCWIA9ixbTx9QfkxHecl6k9ntU3C2R3olTVGhZ0DNvPdw8jNcZuaWFXq1uW+v7iEffaELi7NXb8+d+VpGNjZrkUbYt8+6K9P5h7+V31mD2MjOEmashulJcq8lp25G80K0yMp1WXhcL6XMMz/xFPmYHEpV5YBje0kVQowGCcHkGvQSx+6xJC5FhMu+OlHx1gL9lk5EdEu37OPL/IRZoZGeHuAqSqEs7aA76nZ6YM0P1AvD/sgLAyNcHGAaUaZE39phpojHHqOfgh2jn8Bud9kjpMLAAA=";
77 private static final Log log = LogFactory.getLog(ReferentialUnitsLocalUI.class);
78 private static final long serialVersionUID = 1L;
79
80
81
82
83
84 protected List<Object> $activeBindings = new ArrayList<Object>();
85 protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
86 protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
87 protected Map<String, Object> $objectMap = new HashMap<String, Object>();
88 protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
89 private boolean allComponentsCreated;
90 protected final JAXXContext delegateContext = new DefaultJAXXContext();
91
92
93
94
95
96 protected ReefDbHelpBroker broker;
97 protected JPanel buttonsPanel;
98 protected final ReferentialUnitsLocalUIHandler handler = createHandler();
99 protected ReferentialUnitsMenuUI menuUI;
100 protected ReferentialUnitsLocalUIModel model;
101 protected SwingTable referentialUnitsLocalTable;
102 protected JButton referentialUnitsLocalTableDeleteBouton;
103 protected JButton referentialUnitsLocalTableNouveauBouton;
104 protected JButton referentialUnitsLocalTableReplaceBouton;
105
106
107
108
109
110 private ReferentialUnitsLocalUI $JPanel0 = this;
111 private JPanel $JPanel1;
112 private JScrollPane $JScrollPane0;
113
114
115
116
117
118 public ReferentialUnitsLocalUI(ApplicationUI parentUI) {
119 ApplicationUIUtil.setParentUI(this, parentUI);
120 $initialize();
121 }
122
123 public ReferentialUnitsLocalUI(LayoutManager param0, boolean param1) {
124 super(param0 ,param1);
125 $initialize();
126 }
127
128 public ReferentialUnitsLocalUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
129 super(param1 ,param2);
130 JAXXUtil.initContext(this, parentContext);
131 $initialize();
132 }
133
134 public ReferentialUnitsLocalUI(boolean param0) {
135 super(param0);
136 $initialize();
137 }
138
139 public ReferentialUnitsLocalUI(JAXXContext parentContext, boolean param1) {
140 super(param1);
141 JAXXUtil.initContext(this, parentContext);
142 $initialize();
143 }
144
145 public ReferentialUnitsLocalUI() {
146 $initialize();
147 }
148
149 public ReferentialUnitsLocalUI(JAXXContext parentContext) {
150 JAXXUtil.initContext(this, parentContext);
151 $initialize();
152 }
153
154 public ReferentialUnitsLocalUI(LayoutManager param0) {
155 super(param0);
156 $initialize();
157 }
158
159 public ReferentialUnitsLocalUI(JAXXContext parentContext, LayoutManager param1) {
160 super(param1);
161 JAXXUtil.initContext(this, parentContext);
162 $initialize();
163 }
164
165
166
167
168
169 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
170 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
171 }
172
173
174
175
176
177 @Override
178 public void applyDataBinding(String $binding) {
179 if (allComponentsCreated && $bindings.containsKey($binding)) {
180 getDataBinding($binding).applyDataBinding();
181 }
182 processDataBinding($binding);
183 }
184
185 @Override
186 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
187 super.firePropertyChange(propertyName, oldValue, newValue);
188 }
189
190 @Override
191 public Map<String, Object> get$objectMap() {
192 return $objectMap;
193 }
194
195 @Override
196 public JAXXBinding getDataBinding(String bindingId) {
197 return $bindings.get(bindingId);
198 }
199
200 @Override
201 public JAXXBinding[] getDataBindings() {
202 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
203 }
204
205 @Override
206 public Object getObjectById(String id) {
207 return $objectMap.get(id);
208 }
209
210 @Override
211 public void processDataBinding(String $binding, boolean $force) {
212 if (!$force && $activeBindings.contains($binding)) {
213 return;
214 }
215 $activeBindings.add($binding);
216 try {
217 if (allComponentsCreated && $bindings.containsKey($binding)) {
218 getDataBinding($binding).processDataBinding();
219 }
220 } finally {
221 $activeBindings.remove($binding);
222 }
223 }
224
225 @Override
226 public void processDataBinding(String $binding) {
227 processDataBinding($binding, false);
228 }
229
230 @Override
231 public void registerDataBinding(JAXXBinding binding) {
232 $bindings.put(binding.getId(), binding);
233 }
234
235 @Override
236 public void removeDataBinding(String $binding) {
237 if (allComponentsCreated && $bindings.containsKey($binding)) {
238 getDataBinding($binding).removeDataBinding();
239 }
240 }
241
242
243
244
245
246 @Override
247 public <T> T getContextValue(Class<T> clazz) {
248 return delegateContext.getContextValue(clazz, null);
249 }
250
251 @Override
252 public <T> T getContextValue(Class<T> clazz, String name) {
253 return delegateContext.getContextValue(clazz, name);
254 }
255
256 @Override
257 public JAXXContext getDelegateContext() {
258 return delegateContext;
259 }
260
261 @Override
262 public <O extends Container> O getParentContainer(Class<O> clazz) {
263 return SwingUtil.getParentContainer(this, clazz);
264 }
265
266 @Override
267 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
268 return SwingUtil.getParentContainer(source, clazz);
269 }
270
271 @Override
272 public <T> void removeContextValue(Class<T> clazz) {
273 delegateContext.removeContextValue(clazz, null);
274 }
275
276 @Override
277 public <T> void removeContextValue(Class<T> clazz, String name) {
278 delegateContext.removeContextValue(clazz, name);
279 }
280
281 @Override
282 public <T> void setContextValue(T o) {
283 delegateContext.setContextValue(o, null);
284 }
285
286 @Override
287 public <T> void setContextValue(T o, String name) {
288 delegateContext.setContextValue(o, name);
289 }
290
291
292
293
294
295 public void doActionPerformed__on__referentialUnitsLocalTableNouveauBouton(ActionEvent event) {
296 if (log.isDebugEnabled()) {
297 log.debug(event);
298 }
299 model.addNewRow();
300 }
301
302
303
304
305
306 public ReefDbHelpBroker getBroker() {
307 return broker;
308 }
309
310 public JPanel getButtonsPanel() {
311 return buttonsPanel;
312 }
313
314 public ReferentialUnitsLocalUIHandler getHandler() {
315 return handler;
316 }
317
318 public ReferentialUnitsMenuUI getMenuUI() {
319 return menuUI;
320 }
321
322 public ReferentialUnitsLocalUIModel getModel() {
323 return model;
324 }
325
326 public SwingTable getReferentialUnitsLocalTable() {
327 return referentialUnitsLocalTable;
328 }
329
330 public JButton getReferentialUnitsLocalTableDeleteBouton() {
331 return referentialUnitsLocalTableDeleteBouton;
332 }
333
334 public JButton getReferentialUnitsLocalTableNouveauBouton() {
335 return referentialUnitsLocalTableNouveauBouton;
336 }
337
338 public JButton getReferentialUnitsLocalTableReplaceBouton() {
339 return referentialUnitsLocalTableReplaceBouton;
340 }
341
342
343
344
345
346 protected JPanel get$JPanel1() {
347 return $JPanel1;
348 }
349
350 protected JScrollPane get$JScrollPane0() {
351 return $JScrollPane0;
352 }
353
354
355
356
357
358 protected void addChildrenToButtonsPanel() {
359 if (!allComponentsCreated) {
360 return;
361 }
362 buttonsPanel.add(referentialUnitsLocalTableNouveauBouton);
363 buttonsPanel.add(referentialUnitsLocalTableDeleteBouton);
364 buttonsPanel.add(referentialUnitsLocalTableReplaceBouton);
365 }
366
367 protected void createBroker() {
368 $objectMap.put("broker", broker = new ReefDbHelpBroker("reefdb.home.help"));
369 }
370
371 protected void createButtonsPanel() {
372 $objectMap.put("buttonsPanel", buttonsPanel = new JPanel());
373
374 buttonsPanel.setName("buttonsPanel");
375 buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
376 }
377
378 protected ReferentialUnitsLocalUIHandler createHandler() {
379 return new ReferentialUnitsLocalUIHandler();
380 }
381
382 protected void createMenuUI() {
383 $objectMap.put("menuUI", menuUI = new ReferentialUnitsMenuUI(this));
384
385 menuUI.setName("menuUI");
386 }
387
388 protected void createModel() {
389 $objectMap.put("model", model = getContextValue(ReferentialUnitsLocalUIModel.class));
390 }
391
392 protected void createReferentialUnitsLocalTable() {
393 $objectMap.put("referentialUnitsLocalTable", referentialUnitsLocalTable = new SwingTable());
394
395 referentialUnitsLocalTable.setName("referentialUnitsLocalTable");
396 }
397
398 protected void createReferentialUnitsLocalTableDeleteBouton() {
399 $objectMap.put("referentialUnitsLocalTableDeleteBouton", referentialUnitsLocalTableDeleteBouton = new JButton());
400
401 referentialUnitsLocalTableDeleteBouton.setName("referentialUnitsLocalTableDeleteBouton");
402 referentialUnitsLocalTableDeleteBouton.setText(t("reefdb.common.delete"));
403 referentialUnitsLocalTableDeleteBouton.setToolTipText(t("reefdb.common.delete"));
404 referentialUnitsLocalTableDeleteBouton.putClientProperty("applicationAction", DeleteUnitAction.class);
405 }
406
407 protected void createReferentialUnitsLocalTableNouveauBouton() {
408 $objectMap.put("referentialUnitsLocalTableNouveauBouton", referentialUnitsLocalTableNouveauBouton = new JButton());
409
410 referentialUnitsLocalTableNouveauBouton.setName("referentialUnitsLocalTableNouveauBouton");
411 referentialUnitsLocalTableNouveauBouton.setText(t("reefdb.common.new"));
412 referentialUnitsLocalTableNouveauBouton.setToolTipText(t("reefdb.common.new"));
413 referentialUnitsLocalTableNouveauBouton.addActionListener(JAXXUtil.getEventListener(ActionListener.class, "actionPerformed", this, "doActionPerformed__on__referentialUnitsLocalTableNouveauBouton"));
414 }
415
416 protected void createReferentialUnitsLocalTableReplaceBouton() {
417 $objectMap.put("referentialUnitsLocalTableReplaceBouton", referentialUnitsLocalTableReplaceBouton = new JButton());
418
419 referentialUnitsLocalTableReplaceBouton.setName("referentialUnitsLocalTableReplaceBouton");
420 referentialUnitsLocalTableReplaceBouton.setText(t("reefdb.common.replace"));
421 referentialUnitsLocalTableReplaceBouton.setToolTipText(t("reefdb.common.replace"));
422 referentialUnitsLocalTableReplaceBouton.putClientProperty("applicationAction", OpenReplaceUnitAction.class);
423 }
424
425
426
427
428
429 private void $completeSetup() {
430 allComponentsCreated = true;
431 if (log.isDebugEnabled()) {
432 log.debug(this);
433 }
434
435 add(menuUI, BorderLayout.LINE_START);
436 add($JPanel1, BorderLayout.CENTER);
437
438 $JPanel1.add($JScrollPane0);
439 $JPanel1.add(buttonsPanel, BorderLayout.PAGE_END);
440
441 $JScrollPane0.getViewport().add(referentialUnitsLocalTable);
442 addChildrenToButtonsPanel();
443
444
445 JAXXUtil.applyDataBinding(this, $bindings.keySet());
446
447
448 referentialUnitsLocalTableNouveauBouton.setAlignmentX(Component.CENTER_ALIGNMENT);
449 referentialUnitsLocalTableDeleteBouton.setAlignmentX(Component.CENTER_ALIGNMENT);
450 referentialUnitsLocalTableReplaceBouton.setAlignmentX(Component.CENTER_ALIGNMENT);
451 referentialUnitsLocalTableNouveauBouton.setIcon(SwingUtil.createActionIcon("add"));
452 referentialUnitsLocalTableDeleteBouton.setIcon(SwingUtil.createActionIcon("delete"));
453 referentialUnitsLocalTableReplaceBouton.setIcon(SwingUtil.createActionIcon("replace"));
454 }
455
456 private void $initialize() {
457 if (allComponentsCreated) {
458 return;
459 }
460 if (log.isDebugEnabled()) {
461 log.debug(this);
462 }
463 handler.beforeInit(this);
464 $objectMap.put("$JPanel0", $JPanel0);
465 createModel();
466 createBroker();
467 createMenuUI();
468
469 $objectMap.put("$JPanel1", $JPanel1 = new JPanel());
470
471 $JPanel1.setName("$JPanel1");
472 $JPanel1.setLayout(new BorderLayout());
473
474 $objectMap.put("$JScrollPane0", $JScrollPane0 = new JScrollPane());
475
476 $JScrollPane0.setName("$JScrollPane0");
477 createReferentialUnitsLocalTable();
478 createButtonsPanel();
479 createReferentialUnitsLocalTableNouveauBouton();
480 createReferentialUnitsLocalTableDeleteBouton();
481 createReferentialUnitsLocalTableReplaceBouton();
482
483 setName("$JPanel0");
484 setLayout(new BorderLayout());
485
486
487 $registerDefaultBindings();
488 $completeSetup();
489 handler.afterInit(this);
490 }
491
492 private void $registerDefaultBindings() {
493
494 registerDataBinding(new DefaultJAXXBinding(this, BINDING_REFERENTIAL_UNITS_LOCAL_TABLE_DELETE_BOUTON_ENABLED, true) {
495
496 @Override
497 public void applyDataBinding() {
498 if (model != null) {
499 model.addPropertyChangeListener("selectedRows", this);
500 }
501 }
502
503 @Override
504 public void processDataBinding() {
505 if (model != null && model.getSelectedRows() != null) {
506 referentialUnitsLocalTableDeleteBouton.setEnabled(!model.getSelectedRows().isEmpty());
507 }
508 }
509
510 @Override
511 public void removeDataBinding() {
512 if (model != null) {
513 model.removePropertyChangeListener("selectedRows", this);
514 }
515 }
516 });
517 registerDataBinding(new DefaultJAXXBinding(this, BINDING_REFERENTIAL_UNITS_LOCAL_TABLE_REPLACE_BOUTON_ENABLED, true) {
518
519 @Override
520 public void applyDataBinding() {
521 if (model != null) {
522 model.addPropertyChangeListener("selectedRows", this);
523 }
524 }
525
526 @Override
527 public void processDataBinding() {
528 if (model != null && model.getSelectedRows() != null) {
529 referentialUnitsLocalTableReplaceBouton.setEnabled(model.getSelectedRows().size() == 1);
530 }
531 }
532
533 @Override
534 public void removeDataBinding() {
535 if (model != null) {
536 model.removePropertyChangeListener("selectedRows", this);
537 }
538 }
539 });
540 }
541
542 }