View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.program;
2   
3   import fr.ifremer.dali.ui.swing.DaliHelpBroker;
4   import fr.ifremer.dali.ui.swing.DaliUIContext;
5   import fr.ifremer.dali.ui.swing.content.manage.program.locations.LocationsTableUI;
6   import fr.ifremer.dali.ui.swing.content.manage.program.menu.ProgramsMenuUI;
7   import fr.ifremer.dali.ui.swing.content.manage.program.pmfms.PmfmsTableUI;
8   import fr.ifremer.dali.ui.swing.content.manage.program.programs.ProgramsTableUI;
9   import fr.ifremer.dali.ui.swing.content.manage.program.strategies.StrategiesTableUI;
10  import fr.ifremer.dali.ui.swing.util.DaliUI;
11  import fr.ifremer.quadrige3.ui.swing.ApplicationUI;
12  import fr.ifremer.quadrige3.ui.swing.ApplicationUIUtil;
13  import java.awt.BorderLayout;
14  import java.awt.Component;
15  import java.awt.Container;
16  import java.awt.GridBagConstraints;
17  import java.awt.GridLayout;
18  import java.awt.Insets;
19  import java.awt.LayoutManager;
20  import java.util.ArrayList;
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.TreeMap;
25  import javax.swing.Box;
26  import javax.swing.BoxLayout;
27  import javax.swing.JButton;
28  import javax.swing.JPanel;
29  import jaxx.runtime.JAXXBinding;
30  import jaxx.runtime.JAXXContext;
31  import jaxx.runtime.JAXXObject;
32  import jaxx.runtime.JAXXObjectDescriptor;
33  import jaxx.runtime.JAXXUtil;
34  import jaxx.runtime.JAXXValidator;
35  import jaxx.runtime.SwingUtil;
36  import jaxx.runtime.binding.DefaultJAXXBinding;
37  import jaxx.runtime.context.DefaultJAXXContext;
38  import jaxx.runtime.swing.Table;
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 ProgramsUI extends JPanel implements DaliUI<ProgramsUIModel, ProgramsUIHandler>, JAXXObject, JAXXValidator {
49  
50      /*-----------------------------------------------------------------------*/
51      /*------------------ Constants for all public bindings ------------------*/
52      /*-----------------------------------------------------------------------*/
53  
54      public static final String BINDING_SAVE_BUTTON_ENABLED = "saveButton.enabled";
55  
56      /*-----------------------------------------------------------------------*/
57      /*------------------------- Other static fields -------------------------*/
58      /*-----------------------------------------------------------------------*/
59  
60      private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAK1WS29bRRSeGNupnT6SRq0SWlAaqpJSdVxAsGhQmsRNlASnjeq0ivCijO+dONPeF3fG6bWsIlZs4SfAng0SO1aIBWsWbBB/ASEWbKuemfuOr18tWUx855zznfOdmflmfvgbFbiLrjwhnofdtiWYSfHO2sHB/eYTqom7lGsuc4TtIv9vIodyDTSlR/NcoHcaNRleCcIrVdt0bItaiejlGipz0TEoP6JUCPRWOkLjvFKPzMue03ZD1KioLNTv/v0n963+1fc5hDwHqjsLVBaGRcVM8jWUY7pA5yHTMakYxGpBGS6zWlDvGTlXNQjn94hJv0BfoskaKjrEBTCBFkenrDBUvOcIdOrqzh6xqHFLoNuHLmaHLjWpi3ViMNxmmD+D7FizLQFg2CQWaVHsuHbLJSbe8//zh9uOoxCLAhVMW6eGQHdeHWxXIsSIxaZrP6WuQO/2hbwLX1sQs64849DSMRh0AuwFupFah8gQINTl+CicTCQ3qdV+uC1QdVw+MjAitatQJGYpgg47/z4suFxbL8DzZ9O+k1f3SdOgsEhzKRp+hLJJz7ko4FxQBlc2SWBrXAIhQkQigJIZLkWJZrhwiaAtRuNUtXFTxRi4fhIunW7asDUimG3F2XbGzRZB4NoJsHSu0455mGjg+tgNlOF4LwGSxg83wAfy+830+k1phs3pelsIwEazqf3hz0rH9yL/MifHNDbgwOqiS6n9AsKGY2GLlWeigQpuG6ZhgzV6tfABmHwVnDuhghJQWV9cnP3j579+2gyl7wzkvpDpmlBukCRolgOHm8nU53zdawtmVHaJs9xAJU4NkH0l65czCqsHZigO8s3IcCzD8RbhRwBRmPzzl18vfv77Gyi3icqGTfRNIv23UUkcudAF29A9586qquj0s1MwTsvaoJbHkUTUSFMq2pWuWFpUC3/ihGDBhEEXrz/3oEGXMxoUVdks/fbfbP3H1bBJE1D0fF/3uFGFz1CRWQazqLohAvHPvBGmHE7buh2LfJbso16BcALN+1iNt0dryWJPS4KT3En0ROKtKLLy1yrK0oz/KXt4sgdm75GQV0r+du9ugIM+MHFKT4YlzcOt8Jg4jsH8Ytc0OYIUdKtSGfxPrMlFfQ7Hn6jvbalEqKgRS5M1XugF+JR2BPqo21fK1OGR1yk4ghTDdcpxde1edaMGWfKCevDWmFEhmm2aqgKoJottUsGGkS32IXu+WwdZG8Q1L3WvP9MPx2NaX3u0EfOcTvL080wJ2zb2mbOvHOaVg1+OcojuTLixqSUXGl5zK131JMKMw8OGHXaWri9cu7YQzqk3R3pKct7wo5eyd1JC7UfYvEWDdGxwRmc/gR1MFprM0qEDKz3IE3IsD0WU054cOtkI86+NcGMEVmVoXMuCV5Y4GIB0c6Ravh6AcGuEWvJM8+/d16rimyFVvARotDqLHA0AAA==";
61      private static final Log log = LogFactory.getLog(ProgramsUI.class);
62      private static final long serialVersionUID = 1L;
63  
64      /*-----------------------------------------------------------------------*/
65      /*--------------------------- Internal states ---------------------------*/
66      /*-----------------------------------------------------------------------*/
67  
68      protected List<Object> $activeBindings = new ArrayList<Object>();
69      protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
70      protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
71      protected Map<String, Object> $objectMap = new HashMap<String, Object>();
72      protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
73      private boolean allComponentsCreated;
74      protected final JAXXContext delegateContext = new DefaultJAXXContext();
75  
76      /*-----------------------------------------------------------------------*/
77      /*------------------------ Protected components  ------------------------*/
78      /*-----------------------------------------------------------------------*/
79  
80      protected DaliHelpBroker broker;
81      protected JButton closeButton;
82      protected final ProgramsUIHandler handler = createHandler();
83      @ValidatorField( validatorId = "validator",  propertyName = "locationsUIModel",  editorName = "locationsTableUI")
84      protected LocationsTableUI locationsTableUI;
85      protected ProgramsMenuUI menuUI;
86      protected ProgramsUIModel model;
87      @ValidatorField( validatorId = "validator",  propertyName = "pmfmsUIModel",  editorName = "pmfmsTableUI")
88      protected PmfmsTableUI pmfmsTableUI;
89      @ValidatorField( validatorId = "validator",  propertyName = "programsUIModel",  editorName = "programsTableUI")
90      protected ProgramsTableUI programsTableUI;
91      protected JButton saveButton;
92      @ValidatorField( validatorId = "validator",  propertyName = "strategiesUIModel",  editorName = "strategiesTableUI")
93      protected StrategiesTableUI strategiesTableUI;
94      @Validator( validatorId = "validator")
95      protected SwingValidator<ProgramsUIModel> validator;
96      protected List<String> validatorIds = new ArrayList<String>();
97  
98      /*-----------------------------------------------------------------------*/
99      /*------------------------- Private components  -------------------------*/
100     /*-----------------------------------------------------------------------*/
101 
102     private ProgramsUI $JPanel0 = this;
103     private JPanel $JPanel1;
104     private JPanel $JPanel2;
105     private Table $Table0;
106 
107     /*-----------------------------------------------------------------------*/
108     /*---------------------------- Constructors  ----------------------------*/
109     /*-----------------------------------------------------------------------*/
110 
111     public ProgramsUI(ApplicationUI parentUI) {
112         ApplicationUIUtil.setParentUI(this, parentUI);
113             $initialize();
114     }
115 
116     public ProgramsUI() {
117         $initialize();
118     }
119 
120     public ProgramsUI(JAXXContext parentContext) {
121         JAXXUtil.initContext(this, parentContext);
122         $initialize();
123     }
124 
125     public ProgramsUI(boolean param0) {
126         super(param0);
127         $initialize();
128     }
129 
130     public ProgramsUI(JAXXContext parentContext, boolean param1) {
131         super(param1);
132         JAXXUtil.initContext(this, parentContext);
133         $initialize();
134     }
135 
136     public ProgramsUI(LayoutManager param0) {
137         super(param0);
138         $initialize();
139     }
140 
141     public ProgramsUI(JAXXContext parentContext, LayoutManager param1) {
142         super(param1);
143         JAXXUtil.initContext(this, parentContext);
144         $initialize();
145     }
146 
147     public ProgramsUI(LayoutManager param0, boolean param1) {
148         super(param0 ,param1);
149         $initialize();
150     }
151 
152     public ProgramsUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
153         super(param1 ,param2);
154         JAXXUtil.initContext(this, parentContext);
155         $initialize();
156     }
157 
158     /*-----------------------------------------------------------------------*/
159     /*--------------------------- Statics methods ---------------------------*/
160     /*-----------------------------------------------------------------------*/
161 
162     public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
163         return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
164     }
165 
166     /*-----------------------------------------------------------------------*/
167     /*---------------------- JAXXObject implementation ----------------------*/
168     /*-----------------------------------------------------------------------*/
169 
170     @Override
171     public void applyDataBinding(String $binding) {
172         if (allComponentsCreated && $bindings.containsKey($binding)) {
173             getDataBinding($binding).applyDataBinding();
174         }
175         processDataBinding($binding);
176     }
177 
178     @Override
179     public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
180         super.firePropertyChange(propertyName, oldValue, newValue);
181     }
182 
183     @Override
184     public Map<String, Object> get$objectMap() {
185         return $objectMap;
186     }
187 
188     @Override
189     public JAXXBinding getDataBinding(String bindingId) {
190         return $bindings.get(bindingId);
191     }
192 
193     @Override
194     public JAXXBinding[] getDataBindings() {
195         return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
196     }
197 
198     @Override
199     public Object getObjectById(String id) {
200         return $objectMap.get(id);
201     }
202 
203     @Override
204     public void processDataBinding(String $binding, boolean $force) {
205         if (!$force && $activeBindings.contains($binding)) { 
206             return;
207         }
208         $activeBindings.add($binding);
209         try {
210             if (allComponentsCreated && $bindings.containsKey($binding)) {
211                 getDataBinding($binding).processDataBinding();
212             }
213         } finally {
214             $activeBindings.remove($binding);
215         }
216     }
217 
218     @Override
219     public void processDataBinding(String $binding) {
220         processDataBinding($binding, false);
221     }
222 
223     @Override
224     public void registerDataBinding(JAXXBinding binding) {
225         $bindings.put(binding.getId(), binding);
226     }
227 
228     @Override
229     public void removeDataBinding(String $binding) {
230         if (allComponentsCreated && $bindings.containsKey($binding)) {
231             getDataBinding($binding).removeDataBinding();
232         }
233     }
234 
235     /*-----------------------------------------------------------------------*/
236     /*--------------------- JAXXContext implementation  ---------------------*/
237     /*-----------------------------------------------------------------------*/
238 
239     @Override
240     public <T> T getContextValue(Class<T> clazz) {
241         return delegateContext.getContextValue(clazz, null);
242     }
243 
244     @Override
245     public <T> T getContextValue(Class<T> clazz, String name) {
246         return delegateContext.getContextValue(clazz, name);
247     }
248 
249     @Override
250     public JAXXContext getDelegateContext() {
251         return delegateContext;
252     }
253 
254     @Override
255     public <O extends Container> O getParentContainer(Class<O> clazz) {
256         return SwingUtil.getParentContainer(this, clazz);
257     }
258 
259     @Override
260     public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
261         return SwingUtil.getParentContainer(source, clazz);
262     }
263 
264     @Override
265     public <T> void removeContextValue(Class<T> clazz) {
266         delegateContext.removeContextValue(clazz, null);
267     }
268 
269     @Override
270     public <T> void removeContextValue(Class<T> clazz, String name) {
271         delegateContext.removeContextValue(clazz, name);
272     }
273 
274     @Override
275     public <T> void setContextValue(T o) {
276         delegateContext.setContextValue(o, null);
277     }
278 
279     @Override
280     public <T> void setContextValue(T o, String name) {
281         delegateContext.setContextValue(o, name);
282     }
283 
284     /*-----------------------------------------------------------------------*/
285     /*-------------------- JAXXValidator implementation  --------------------*/
286     /*-----------------------------------------------------------------------*/
287 
288     @Override
289     public SwingValidator<?> getValidator(String validatorId) {
290         return (SwingValidator<?>) (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);
291     }
292 
293     @Override
294     public List<String> getValidatorIds() {
295         return validatorIds;
296     }
297 
298     @Override
299     public void registerValidatorFields() {
300         SwingValidatorUtil.detectValidatorFields(this);
301     }
302 
303     /*-----------------------------------------------------------------------*/
304     /*----------------------- Public acessor methods  -----------------------*/
305     /*-----------------------------------------------------------------------*/
306 
307     public DaliHelpBroker getBroker() {
308         return broker;
309     }
310 
311     public JButton getCloseButton() {
312         return closeButton;
313     }
314 
315     public ProgramsUIHandler getHandler() {
316         return handler;
317     }
318 
319     public LocationsTableUI getLocationsTableUI() {
320         return locationsTableUI;
321     }
322 
323     public ProgramsMenuUI getMenuUI() {
324         return menuUI;
325     }
326 
327     public ProgramsUIModel getModel() {
328         return model;
329     }
330 
331     public PmfmsTableUI getPmfmsTableUI() {
332         return pmfmsTableUI;
333     }
334 
335     public ProgramsTableUI getProgramsTableUI() {
336         return programsTableUI;
337     }
338 
339     public JButton getSaveButton() {
340         return saveButton;
341     }
342 
343     public StrategiesTableUI getStrategiesTableUI() {
344         return strategiesTableUI;
345     }
346 
347     public SwingValidator<ProgramsUIModel> getValidator() {
348         return validator;
349     }
350 
351     /*-----------------------------------------------------------------------*/
352     /*--------------------- Protected acessors methods  ---------------------*/
353     /*-----------------------------------------------------------------------*/
354 
355     protected JPanel get$JPanel1() {
356         return $JPanel1;
357     }
358 
359     protected JPanel get$JPanel2() {
360         return $JPanel2;
361     }
362 
363     protected Table get$Table0() {
364         return $Table0;
365     }
366 
367     /*-----------------------------------------------------------------------*/
368     /*--------------------- Components creation methods ---------------------*/
369     /*-----------------------------------------------------------------------*/
370 
371     protected void addChildrenToValidator() {
372         if (!allComponentsCreated) {
373             return;
374         }
375         validator.setUiClass(ImageValidationUI.class);
376         validator.setBean(model);
377     }
378 
379     protected void createBroker() {
380         $objectMap.put("broker", broker = new DaliHelpBroker("dali.home.help"));
381     }
382 
383     protected void createCloseButton() {
384         $objectMap.put("closeButton", closeButton = new JButton());
385         
386         closeButton.setName("closeButton");
387         closeButton.setText(t("dali.common.close"));
388         closeButton.putClientProperty("applicationActionKey", fr.ifremer.dali.ui.swing.util.DaliKeyStrokes.CANCEL);
389         closeButton.putClientProperty("applicationAction", CloseAction.class);
390     }
391 
392     protected ProgramsUIHandler createHandler() {
393         return new ProgramsUIHandler();
394     }
395 
396     protected void createLocationsTableUI() {
397         $objectMap.put("locationsTableUI", locationsTableUI = new LocationsTableUI(this));
398         
399         locationsTableUI.setName("locationsTableUI");
400         locationsTableUI.putClientProperty("validatorLabel", t("dali.program.location.title"));
401     }
402 
403     protected void createMenuUI() {
404         $objectMap.put("menuUI", menuUI = new ProgramsMenuUI(this));
405         
406         menuUI.setName("menuUI");
407     }
408 
409     protected void createModel() {
410         $objectMap.put("model", model = getContextValue(ProgramsUIModel.class));
411     }
412 
413     protected void createPmfmsTableUI() {
414         $objectMap.put("pmfmsTableUI", pmfmsTableUI = new PmfmsTableUI(this));
415         
416         pmfmsTableUI.setName("pmfmsTableUI");
417         pmfmsTableUI.putClientProperty("validatorLabel", t("dali.program.pmfm.title"));
418     }
419 
420     protected void createProgramsTableUI() {
421         $objectMap.put("programsTableUI", programsTableUI = new ProgramsTableUI(this));
422         
423         programsTableUI.setName("programsTableUI");
424         programsTableUI.putClientProperty("validatorLabel", t("dali.program.program.title"));
425     }
426 
427     protected void createSaveButton() {
428         $objectMap.put("saveButton", saveButton = new JButton());
429         
430         saveButton.setName("saveButton");
431         saveButton.setText(t("dali.common.save"));
432         saveButton.setToolTipText(t("dali.action.save.programs"));
433         saveButton.putClientProperty("applicationActionKey", fr.ifremer.dali.ui.swing.util.DaliKeyStrokes.SAVE);
434         saveButton.putClientProperty("applicationAction", SaveAction.class);
435     }
436 
437     protected void createStrategiesTableUI() {
438         $objectMap.put("strategiesTableUI", strategiesTableUI = new StrategiesTableUI(this));
439         
440         strategiesTableUI.setName("strategiesTableUI");
441         strategiesTableUI.putClientProperty("validatorLabel", t("dali.program.strategy.title"));
442     }
443 
444     protected void createValidator() {
445         $objectMap.put("validator", validator = SwingValidator.newValidator(ProgramsUIModel.class, null));
446     }
447 
448     /*-----------------------------------------------------------------------*/
449     /*------------------------ Internal jaxx methods ------------------------*/
450     /*-----------------------------------------------------------------------*/
451 
452     private void $completeSetup() {
453         allComponentsCreated = true;
454         if (log.isDebugEnabled()) {
455             log.debug(this);
456         }
457         // inline complete setup of $JPanel0
458         add(menuUI, BorderLayout.LINE_START);
459         add($JPanel1, BorderLayout.CENTER);
460         addChildrenToValidator();
461         // inline complete setup of $JPanel1
462         $JPanel1.add($Table0);
463         $JPanel1.add($JPanel2, BorderLayout.PAGE_END);
464         // inline complete setup of $Table0
465         $Table0.add(SwingUtil.boxComponentWithJxLayer(programsTableUI), new GridBagConstraints(0, 0, 2, 1, 1.0, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
466         $Table0.add(SwingUtil.boxComponentWithJxLayer(strategiesTableUI), new GridBagConstraints(0, 1, 1, 1, 0.3, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
467         $Table0.add(SwingUtil.boxComponentWithJxLayer(locationsTableUI), new GridBagConstraints(1, 1, 1, 1, 0.7, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
468         $Table0.add(SwingUtil.boxComponentWithJxLayer(pmfmsTableUI), new GridBagConstraints(0, 2, 2, 1, 1.0, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
469         // inline complete setup of $JPanel2
470         $JPanel2.add(closeButton);
471         $JPanel2.add(saveButton);
472         
473         // apply 1 data bindings
474         JAXXUtil.applyDataBinding(this, $bindings.keySet());
475         
476         // apply 7 property setters
477         closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
478         saveButton.setAlignmentX(Component.CENTER_ALIGNMENT);
479         closeButton.setIcon(SwingUtil.createActionIcon("cancel"));
480         saveButton.setIcon(SwingUtil.createActionIcon("save"));
481         // late initializer
482         // register 1 validator(s)
483         validatorIds = SwingValidatorUtil.detectValidators(this);
484         SwingValidatorUtil.installUI(this);
485     }
486 
487     private void $initialize() {
488         if (allComponentsCreated) {
489             return;
490         }
491         if (log.isDebugEnabled()) {
492             log.debug(this);
493         }
494         handler.beforeInit(this);
495         $objectMap.put("$JPanel0", $JPanel0);
496         createModel();
497         createBroker();
498         createValidator();
499         createMenuUI();
500         // inline creation of $JPanel1
501         $objectMap.put("$JPanel1", $JPanel1 = new JPanel());
502         
503         $JPanel1.setName("$JPanel1");
504         $JPanel1.setLayout(new BorderLayout());
505         // inline creation of $Table0
506         $objectMap.put("$Table0", $Table0 = new Table());
507         
508         $Table0.setName("$Table0");
509         createProgramsTableUI();
510         createStrategiesTableUI();
511         createLocationsTableUI();
512         createPmfmsTableUI();
513         // inline creation of $JPanel2
514         $objectMap.put("$JPanel2", $JPanel2 = new JPanel());
515         
516         $JPanel2.setName("$JPanel2");
517         $JPanel2.setLayout(new GridLayout(1,0));
518         createCloseButton();
519         createSaveButton();
520         // inline creation of $JPanel0
521         setName("$JPanel0");
522         setLayout(new BorderLayout());
523         
524         // registers 1 data bindings
525         $registerDefaultBindings();
526         $completeSetup();
527         handler.afterInit(this);
528     }
529 
530     private void $registerDefaultBindings() {
531         // register 1 data bindings
532         registerDataBinding(new DefaultJAXXBinding(this, BINDING_SAVE_BUTTON_ENABLED, true, true) {
533         
534             @Override
535             public void applyDataBinding() {
536                 if (model != null) {
537                     model.addPropertyChangeListener("modify", this);
538                 }
539                 if (model != null) {
540                     model.addPropertyChangeListener("valid", this);
541                 }
542                 if (model != null) {
543                     model.addPropertyChangeListener("saveEnabled", this);
544                 }
545             }
546         
547             @Override
548             public void processDataBinding() {
549                 if (model != null) {
550                     saveButton.setEnabled(model.isModify() && model.isValid() && model.isSaveEnabled());
551                 }
552             }
553         
554             @Override
555             public void removeDataBinding() {
556                 if (model != null) {
557                     model.removePropertyChangeListener("modify", this);
558                 }
559                 if (model != null) {
560                     model.removePropertyChangeListener("valid", this);
561                 }
562                 if (model != null) {
563                     model.removePropertyChangeListener("saveEnabled", this);
564                 }
565             }
566         });
567     }
568 
569 }