1 package fr.ifremer.quadrige2.ui.swing.common.content.db;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import fr.ifremer.quadrige2.ui.swing.common.ApplicationUI;
25 import fr.ifremer.quadrige2.ui.swing.common.ApplicationUIContext;
26 import fr.ifremer.quadrige2.ui.swing.common.ApplicationUIUtil;
27 import java.awt.BorderLayout;
28 import java.awt.Container;
29 import java.awt.GridLayout;
30 import java.awt.LayoutManager;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.TreeMap;
36 import javax.swing.JButton;
37 import javax.swing.JPanel;
38 import javax.swing.JTextPane;
39 import javax.swing.border.EmptyBorder;
40 import jaxx.runtime.JAXXBinding;
41 import jaxx.runtime.JAXXContext;
42 import jaxx.runtime.JAXXObject;
43 import jaxx.runtime.JAXXObjectDescriptor;
44 import jaxx.runtime.JAXXUtil;
45 import jaxx.runtime.SwingUtil;
46 import jaxx.runtime.binding.DefaultJAXXBinding;
47 import jaxx.runtime.context.DefaultJAXXContext;
48 import org.apache.commons.logging.Log;
49 import org.apache.commons.logging.LogFactory;
50 import static org.nuiton.i18n.I18n.t;
51
52 public class DbManagerUI extends JPanel implements ApplicationUI<ApplicationUIContext, DbManagerUIHandler>, JAXXObject {
53
54
55
56
57
58 public static final String BINDING_EXPORT_ALL_REFERENTIAL_TO_FILE_BUTTON_VISIBLE = "exportAllReferentialToFileButton.visible";
59 public static final String BINDING_EXPORT_DB_BUTTON_VISIBLE = "exportDbButton.visible";
60 public static final String BINDING_INSTALL_OR_REINSTALL_DB_BUTTON_TEXT = "installOrReinstallDbButton.text";
61 public static final String BINDING_INSTALL_OR_REINSTALL_DB_BUTTON_TOOL_TIP_TEXT = "installOrReinstallDbButton.toolTipText";
62 public static final String BINDING_OPEN_DB_BUTTON_VISIBLE = "openDbButton.visible";
63
64
65
66
67
68 private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAALVXz28bRRSemDiundL8IlF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lBOYdNSVaiWuhoGRGNDUMO7KffII7Q7Ko7WDwt0oxsybYNUxF9mkicqHVilWVUEQ4o0SrrQbmFoP4dSJDwGBuqGG5pCe5Qb3N6pZPPbl0S9W0rYWVeC30HCQQBxRZOg6rULeiI799dmTqxgWO46LPvD0/Lcv9ThNO6iRW8q2SttQJhT7n5eT6AHl0WFjuz0I773gSbg7iKqkbV/tTb6+kemd66n27T/DgxZtU7ddae9quX4UzCkqXN/OcelTL/t1WT3/lb9zIL7RXHxLhwSrhJinDS4JYS6rvQ3oWEtPukHO7LznhIeOpeTPZ8Qxium4t56elnwza15EkYmZaW35y82cDuFPkzLcGoqGfStppDqqS6FjnV0nkepZKum9w56djPTF43N0viaCPWgNdzr1jbjaE044XkNoT7H/j+M5Lnb3D+voArMdWL74P7r4c2BmdkXhzT+oVuJaOMHzsgDG68r6FJc5XKbeAvvWeeEPqmUtEVMtfq8c38QjjF0aYGeBUw9QM/m85A2N2oCx+6INw7cII8xdGeOPCCAuA8B9zFI4OOBEAAA==";
69 private static final Log log = LogFactory.getLog(DbManagerUI.class);
70 private static final long serialVersionUID = 1L;
71
72
73
74
75
76 protected List<Object> $activeBindings = new ArrayList<Object>();
77 protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
78 protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
79 protected Map<String, Object> $objectMap = new HashMap<String, Object>();
80 protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
81 private boolean allComponentsCreated;
82 protected final JAXXContext delegateContext = new DefaultJAXXContext();
83
84
85
86
87
88 protected JPanel actions;
89 protected DbManagerUI dbManagerTopPanel = this;
90 protected JButton exportAllReferentialToFileButton;
91 protected JButton exportDbButton;
92 protected final DbManagerUIHandler handler = createHandler();
93 protected JButton importDbButton;
94 protected JPanel infoPanel;
95 protected JTextPane informationArea;
96 protected JButton installOrReinstallDbButton;
97 protected ApplicationUIContext model;
98 protected JButton openDbButton;
99
100
101
102
103
104 public DbManagerUI(ApplicationUI parentUI) {
105 ApplicationUIUtil.setParentUI(this, parentUI);
106 $initialize();
107 }
108
109 public DbManagerUI(LayoutManager param0, boolean param1) {
110 super(param0 ,param1);
111 $initialize();
112 }
113
114 public DbManagerUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
115 super(param1 ,param2);
116 JAXXUtil.initContext(this, parentContext);
117 $initialize();
118 }
119
120 public DbManagerUI(LayoutManager param0) {
121 super(param0);
122 $initialize();
123 }
124
125 public DbManagerUI(JAXXContext parentContext, LayoutManager param1) {
126 super(param1);
127 JAXXUtil.initContext(this, parentContext);
128 $initialize();
129 }
130
131 public DbManagerUI(boolean param0) {
132 super(param0);
133 $initialize();
134 }
135
136 public DbManagerUI(JAXXContext parentContext, boolean param1) {
137 super(param1);
138 JAXXUtil.initContext(this, parentContext);
139 $initialize();
140 }
141
142 public DbManagerUI() {
143 $initialize();
144 }
145
146 public DbManagerUI(JAXXContext parentContext) {
147 JAXXUtil.initContext(this, parentContext);
148 $initialize();
149 }
150
151
152
153
154
155 public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
156 return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
157 }
158
159
160
161
162
163 @Override
164 public void applyDataBinding(String $binding) {
165 if (allComponentsCreated && $bindings.containsKey($binding)) {
166 getDataBinding($binding).applyDataBinding();
167 }
168 processDataBinding($binding);
169 }
170
171 @Override
172 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
173 super.firePropertyChange(propertyName, oldValue, newValue);
174 }
175
176 @Override
177 public Map<String, Object> get$objectMap() {
178 return $objectMap;
179 }
180
181 @Override
182 public JAXXBinding getDataBinding(String bindingId) {
183 return $bindings.get(bindingId);
184 }
185
186 @Override
187 public JAXXBinding[] getDataBindings() {
188 return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
189 }
190
191 @Override
192 public Object getObjectById(String id) {
193 return $objectMap.get(id);
194 }
195
196 @Override
197 public void processDataBinding(String $binding, boolean $force) {
198 if (!$force && $activeBindings.contains($binding)) {
199 return;
200 }
201 $activeBindings.add($binding);
202 try {
203 if (allComponentsCreated && $bindings.containsKey($binding)) {
204 getDataBinding($binding).processDataBinding();
205 }
206 } finally {
207 $activeBindings.remove($binding);
208 }
209 }
210
211 @Override
212 public void processDataBinding(String $binding) {
213 processDataBinding($binding, false);
214 }
215
216 @Override
217 public void registerDataBinding(JAXXBinding binding) {
218 $bindings.put(binding.getId(), binding);
219 }
220
221 @Override
222 public void removeDataBinding(String $binding) {
223 if (allComponentsCreated && $bindings.containsKey($binding)) {
224 getDataBinding($binding).removeDataBinding();
225 }
226 }
227
228
229
230
231
232 @Override
233 public <T> T getContextValue(Class<T> clazz) {
234 return delegateContext.getContextValue(clazz, null);
235 }
236
237 @Override
238 public <T> T getContextValue(Class<T> clazz, String name) {
239 return delegateContext.getContextValue(clazz, name);
240 }
241
242 @Override
243 public JAXXContext getDelegateContext() {
244 return delegateContext;
245 }
246
247 @Override
248 public <O extends Container> O getParentContainer(Class<O> clazz) {
249 return SwingUtil.getParentContainer(this, clazz);
250 }
251
252 @Override
253 public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
254 return SwingUtil.getParentContainer(source, clazz);
255 }
256
257 @Override
258 public <T> void removeContextValue(Class<T> clazz) {
259 delegateContext.removeContextValue(clazz, null);
260 }
261
262 @Override
263 public <T> void removeContextValue(Class<T> clazz, String name) {
264 delegateContext.removeContextValue(clazz, name);
265 }
266
267 @Override
268 public <T> void setContextValue(T o) {
269 delegateContext.setContextValue(o, null);
270 }
271
272 @Override
273 public <T> void setContextValue(T o, String name) {
274 delegateContext.setContextValue(o, name);
275 }
276
277
278
279
280
281 public JPanel getActions() {
282 return actions;
283 }
284
285 public JButton getExportAllReferentialToFileButton() {
286 return exportAllReferentialToFileButton;
287 }
288
289 public JButton getExportDbButton() {
290 return exportDbButton;
291 }
292
293 public DbManagerUIHandler getHandler() {
294 return handler;
295 }
296
297 public JButton getImportDbButton() {
298 return importDbButton;
299 }
300
301 public JPanel getInfoPanel() {
302 return infoPanel;
303 }
304
305 public JTextPane getInformationArea() {
306 return informationArea;
307 }
308
309 public JButton getInstallOrReinstallDbButton() {
310 return installOrReinstallDbButton;
311 }
312
313 public ApplicationUIContext getModel() {
314 return model;
315 }
316
317 public JButton getOpenDbButton() {
318 return openDbButton;
319 }
320
321
322
323
324
325 protected void addChildrenToActions() {
326 if (!allComponentsCreated) {
327 return;
328 }
329 actions.add(openDbButton);
330 actions.add(installOrReinstallDbButton);
331 actions.add(importDbButton);
332 actions.add(exportDbButton);
333 actions.add(exportAllReferentialToFileButton);
334 }
335
336 protected void addChildrenToDbManagerTopPanel() {
337 if (!allComponentsCreated) {
338 return;
339 }
340 add(infoPanel, BorderLayout.CENTER);
341 add(actions, BorderLayout.SOUTH);
342 }
343
344 protected void addChildrenToInfoPanel() {
345 if (!allComponentsCreated) {
346 return;
347 }
348 infoPanel.add(informationArea, BorderLayout.CENTER);
349 }
350
351 protected void createActions() {
352 $objectMap.put("actions", actions = new JPanel());
353
354 actions.setName("actions");
355 actions.setLayout(new GridLayout(0, 1));
356 }
357
358 protected void createExportAllReferentialToFileButton() {
359 $objectMap.put("exportAllReferentialToFileButton", exportAllReferentialToFileButton = new JButton());
360
361 exportAllReferentialToFileButton.setName("exportAllReferentialToFileButton");
362 exportAllReferentialToFileButton.setText(t("quadrige2.dbManager.action.exportAllReferentialToFile"));
363 exportAllReferentialToFileButton.setToolTipText(t("quadrige2.dbManager.action.exportAllReferentialToFile.tip"));
364 exportAllReferentialToFileButton.putClientProperty("help", "quadrige2.dbManager.action.exportAllReferentialToFile.help");
365 exportAllReferentialToFileButton.putClientProperty("applicationAction", fr.ifremer.quadrige2.ui.swing.common.synchro.action.ExportReferentialToFileAction.class);
366 }
367
368 protected void createExportDbButton() {
369 $objectMap.put("exportDbButton", exportDbButton = new JButton());
370
371 exportDbButton.setName("exportDbButton");
372 exportDbButton.setText(t("quadrige2.dbManager.action.exportDb"));
373 exportDbButton.setToolTipText(t("quadrige2.dbManager.action.exportDb.tip"));
374 exportDbButton.putClientProperty("help", "quadrige2.dbManager.action.exportDb.help");
375 exportDbButton.putClientProperty("applicationAction", ExportDbAction.class);
376 }
377
378 protected DbManagerUIHandler createHandler() {
379 return new DbManagerUIHandler();
380 }
381
382 protected void createImportDbButton() {
383 $objectMap.put("importDbButton", importDbButton = new JButton());
384
385 importDbButton.setName("importDbButton");
386 importDbButton.setText(t("quadrige2.dbManager.action.importDb"));
387 importDbButton.setToolTipText(t("quadrige2.dbManager.action.importDb.tip"));
388 importDbButton.putClientProperty("help", "quadrige2.dbManager.action.importDb.help");
389 importDbButton.putClientProperty("applicationAction", ImportOrReimportDbAction.class);
390 }
391
392 protected void createInfoPanel() {
393 $objectMap.put("infoPanel", infoPanel = new JPanel());
394
395 infoPanel.setName("infoPanel");
396 infoPanel.setLayout(new BorderLayout());
397 }
398
399 protected void createInformationArea() {
400 $objectMap.put("informationArea", informationArea = new JTextPane());
401
402 informationArea.setName("informationArea");
403 informationArea.setEditable(false);
404 informationArea.setFocusable(false);
405 informationArea.setContentType("text/html");
406 }
407
408 protected void createInstallOrReinstallDbButton() {
409 $objectMap.put("installOrReinstallDbButton", installOrReinstallDbButton = new JButton());
410
411 installOrReinstallDbButton.setName("installOrReinstallDbButton");
412 installOrReinstallDbButton.putClientProperty("help", "quadrige2.dbManager.action.installDb.help");
413 installOrReinstallDbButton.putClientProperty("applicationAction", InstallOrReinstallDbAction.class);
414 }
415
416 protected void createModel() {
417 $objectMap.put("model", model = getContextValue(ApplicationUIContext.class));
418 }
419
420 protected void createOpenDbButton() {
421 $objectMap.put("openDbButton", openDbButton = new JButton());
422
423 openDbButton.setName("openDbButton");
424 openDbButton.setText(t("quadrige2.dbManager.action.openDb"));
425 openDbButton.setToolTipText(t("quadrige2.dbManager.action.openDb.tip"));
426 openDbButton.putClientProperty("help", "quadrige2.dbManager.action.openDb.help");
427 openDbButton.putClientProperty("applicationAction", OpenDbAction.class);
428 }
429
430
431
432
433
434 private void $completeSetup() {
435 allComponentsCreated = true;
436 if (log.isDebugEnabled()) {
437 log.debug(this);
438 }
439 addChildrenToDbManagerTopPanel();
440 addChildrenToInfoPanel();
441 addChildrenToActions();
442
443
444 JAXXUtil.applyDataBinding(this, $bindings.keySet());
445
446
447 informationArea.setBorder(new EmptyBorder(5, 5, 5, 5));
448 openDbButton.setMnemonic(SwingUtil.getFirstCharAt(t("quadrige2.dbManager.action.openDb.mnemonic"),'Z'));
449 openDbButton.setIcon(SwingUtil.createActionIcon("open-db"));
450 installOrReinstallDbButton.setMnemonic(SwingUtil.getFirstCharAt(t("quadrige2.dbManager.action.installDb.mnemonic"),'Z'));
451 installOrReinstallDbButton.setIcon(SwingUtil.createActionIcon("install-db"));
452 importDbButton.setMnemonic(SwingUtil.getFirstCharAt(t("quadrige2.dbManager.action.importDb.mnemonic"),'Z'));
453 importDbButton.setIcon(SwingUtil.createActionIcon("install-db"));
454 exportDbButton.setMnemonic(SwingUtil.getFirstCharAt(t("quadrige2.dbManager.action.exportDb.mnemonic"),'Z'));
455 exportDbButton.setIcon(SwingUtil.createActionIcon("export-db"));
456 exportAllReferentialToFileButton.setMnemonic(SwingUtil.getFirstCharAt(t("quadrige2.dbManager.action.exportAllReferentialToFile.mnemonic"),'Z'));
457 exportAllReferentialToFileButton.setIcon(SwingUtil.createActionIcon("export-db"));
458 }
459
460 private void $initialize() {
461 if (allComponentsCreated) {
462 return;
463 }
464 if (log.isDebugEnabled()) {
465 log.debug(this);
466 }
467 handler.beforeInit(this);
468 $objectMap.put("dbManagerTopPanel", dbManagerTopPanel);
469 createModel();
470 createInfoPanel();
471 createInformationArea();
472 createActions();
473 createOpenDbButton();
474 createInstallOrReinstallDbButton();
475 createImportDbButton();
476 createExportDbButton();
477 createExportAllReferentialToFileButton();
478
479 setName("dbManagerTopPanel");
480 setLayout(new BorderLayout());
481 dbManagerTopPanel.putClientProperty("help", "quadrige2.dbManager.help");
482
483
484 $registerDefaultBindings();
485 $completeSetup();
486 handler.afterInit(this);
487 }
488
489 private void $registerDefaultBindings() {
490
491 registerDataBinding(new DefaultJAXXBinding(this, BINDING_OPEN_DB_BUTTON_VISIBLE, true, true) {
492
493 @Override
494 public void applyDataBinding() {
495 if (model != null) {
496 model.addPropertyChangeListener("dbExist", this);
497 }
498 if (model != null) {
499 model.addPropertyChangeListener("persistenceLoaded", this);
500 }
501 }
502
503 @Override
504 public void processDataBinding() {
505 if (model != null) {
506 openDbButton.setVisible(model.isDbExist() && !model.isPersistenceLoaded());
507 }
508 }
509
510 @Override
511 public void removeDataBinding() {
512 if (model != null) {
513 model.removePropertyChangeListener("dbExist", this);
514 }
515 if (model != null) {
516 model.removePropertyChangeListener("persistenceLoaded", this);
517 }
518 }
519 });
520 registerDataBinding(new DefaultJAXXBinding(this, BINDING_INSTALL_OR_REINSTALL_DB_BUTTON_TEXT, true) {
521
522 @Override
523 public void applyDataBinding() {
524 if (model != null) {
525 model.addPropertyChangeListener("dbExist", this);
526 }
527 }
528
529 @Override
530 public void processDataBinding() {
531 if (model != null) {
532 installOrReinstallDbButton.setText(t(handler.getInstallButtonText(model.isDbExist())));
533 }
534 }
535
536 @Override
537 public void removeDataBinding() {
538 if (model != null) {
539 model.removePropertyChangeListener("dbExist", this);
540 }
541 }
542 });
543 registerDataBinding(new DefaultJAXXBinding(this, BINDING_INSTALL_OR_REINSTALL_DB_BUTTON_TOOL_TIP_TEXT, true) {
544
545 @Override
546 public void applyDataBinding() {
547 if (model != null) {
548 model.addPropertyChangeListener("dbExist", this);
549 }
550 }
551
552 @Override
553 public void processDataBinding() {
554 if (model != null) {
555 installOrReinstallDbButton.setToolTipText(t(handler.getInstallButtonTip(model.isDbExist())));
556 }
557 }
558
559 @Override
560 public void removeDataBinding() {
561 if (model != null) {
562 model.removePropertyChangeListener("dbExist", this);
563 }
564 }
565 });
566 registerDataBinding(new DefaultJAXXBinding(this, BINDING_EXPORT_DB_BUTTON_VISIBLE, true) {
567
568 @Override
569 public void applyDataBinding() {
570 if (model != null) {
571 model.addPropertyChangeListener("persistenceLoaded", this);
572 }
573 }
574
575 @Override
576 public void processDataBinding() {
577 if (model != null) {
578 exportDbButton.setVisible(model.isPersistenceLoaded());
579 }
580 }
581
582 @Override
583 public void removeDataBinding() {
584 if (model != null) {
585 model.removePropertyChangeListener("persistenceLoaded", this);
586 }
587 }
588 });
589 registerDataBinding(new DefaultJAXXBinding(this, BINDING_EXPORT_ALL_REFERENTIAL_TO_FILE_BUTTON_VISIBLE, true) {
590
591 @Override
592 public void applyDataBinding() {
593 if (model != null) {
594 model.addPropertyChangeListener("persistenceLoaded", this);
595 }
596 }
597
598 @Override
599 public void processDataBinding() {
600 if (model != null) {
601 exportAllReferentialToFileButton.setVisible(model.isPersistenceLoaded());
602 }
603 }
604
605 @Override
606 public void removeDataBinding() {
607 if (model != null) {
608 model.removePropertyChangeListener("persistenceLoaded", this);
609 }
610 }
611 });
612 }
613
614 }