View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.catches.species.split;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU General Public License as
13   * published by the Free Software Foundation, either version 3 of the
14   * License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU General Public
22   * License along with this program.  If not, see
23   * <http://www.gnu.org/licenses/gpl-3.0.html>.
24   * #L%
25   */
26  
27  import fr.ifremer.tutti.ui.swing.TuttiHelpBroker;
28  import fr.ifremer.tutti.ui.swing.util.TuttiUI;
29  import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
30  import java.awt.BorderLayout;
31  import java.awt.Color;
32  import java.awt.Component;
33  import java.awt.Container;
34  import java.awt.GridBagConstraints;
35  import java.awt.GridLayout;
36  import java.awt.Insets;
37  import java.awt.LayoutManager;
38  import java.util.ArrayList;
39  import java.util.HashMap;
40  import java.util.List;
41  import java.util.Map;
42  import java.util.TreeMap;
43  import javax.swing.JButton;
44  import javax.swing.JComboBox;
45  import javax.swing.JLabel;
46  import javax.swing.JPanel;
47  import javax.swing.JScrollPane;
48  import javax.swing.JSeparator;
49  import javax.swing.JTextField;
50  import javax.swing.ListSelectionModel;
51  import javax.swing.border.TitledBorder;
52  import jaxx.runtime.JAXXBinding;
53  import jaxx.runtime.JAXXContext;
54  import jaxx.runtime.JAXXObject;
55  import jaxx.runtime.JAXXObjectDescriptor;
56  import jaxx.runtime.JAXXUtil;
57  import jaxx.runtime.JAXXValidator;
58  import jaxx.runtime.SwingUtil;
59  import jaxx.runtime.binding.DefaultJAXXBinding;
60  import jaxx.runtime.context.DefaultJAXXContext;
61  import jaxx.runtime.swing.Table;
62  import jaxx.runtime.swing.help.JAXXHelpUI;
63  import jaxx.runtime.validator.swing.SwingValidator;
64  import jaxx.runtime.validator.swing.SwingValidatorUtil;
65  import jaxx.runtime.validator.swing.meta.Validator;
66  import jaxx.runtime.validator.swing.meta.ValidatorField;
67  import jaxx.runtime.validator.swing.ui.ImageValidationUI;
68  import org.apache.commons.logging.Log;
69  import org.apache.commons.logging.LogFactory;
70  import org.jdesktop.swingx.JXTable;
71  import static jaxx.runtime.SwingUtil.getStringValue;
72  import static org.nuiton.i18n.I18n.t;
73  
74  public class SplitSpeciesBatchUI extends JPanel implements JAXXHelpUI<TuttiHelpBroker>, TuttiUI<SplitSpeciesBatchUIModel, SplitSpeciesBatchUIHandler>, JAXXObject, JAXXValidator {
75  
76      /*-----------------------------------------------------------------------*/
77      /*------------------ Constants for all public bindings ------------------*/
78      /*-----------------------------------------------------------------------*/
79  
80      public static final String BINDING_BATCH_WEIGHT_FIELD_TEXT = "batchWeightField.text";
81      public static final String BINDING_CATEGORY_COMBO_BOX_SELECTED_ITEM = "categoryComboBox.selectedItem";
82      public static final String BINDING_SAMPLE_WEIGHT_FIELD_TEXT = "sampleWeightField.text";
83      public static final String BINDING_SAVE_BUTTON_ENABLED = "saveButton.enabled";
84      public static final String BINDING_TABLE_ENABLED = "table.enabled";
85  
86      /*-----------------------------------------------------------------------*/
87      /*------------------------- Other static fields -------------------------*/
88      /*-----------------------------------------------------------------------*/
89  
90      private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAALVXzW8bRRSfuLHTpA1tErW0tKC0pcWGaFJaUCvKR2O3oQlui1iXVs0hjHcn9rTjnWV3tnVlBfEn8CfAnQsSN06IA2cOXBBw5YQQB66IN7PrXa+963WA5rCK573f+/q9eTPz5e+o6Lno1APS7WLXtyXrULy5du/e7eYDaspr1DNd5kjhouBvqoAKW+iAFa17Ep3Zqiv4aghfrYmOI2xqD6Cv1NGcJ59w6rUplRI9n0SYnrdqROIrXcd3+1ajoNKsfv7nH4XPrE+/KCDUdSC6BUhlOQ8VZzJdRwVmSbQInh6RVU7sFoThMrsF8c6rtRonnneLdOjH6BM0U0clh7hgTKLTk6esbWh815HouOdwJg2Hmox6VSLNdkM47xObconu7LiY7bi0Q10sfSkZ9hn2HkM82BS2BPNYONQlkgkbmwpLPewFprC2i41h63c2HEd7L0lU7AhL+bn/VPzcVMZjZ7OPCGcWgUpI9EqCk0gQ+jTU98P+Ymyh1HTFQwrwSna8DfXzBvitat0YvAiZ7LCWH2QRFvhYIo7QAmlyTe9shJ2HnGlLuE/qpKlgi6oVuqH+pl5UmkciwOE+APqgKaqiK9GRBKa/noQdfHHToNBRKu3zEh1NQCLJkKumqvZdylptGUXynNaBwLlauctk+47NZBpknVFuDbtq0G4gSLpa8EjH4XRPvhKYyOa5pOFDUtXcMF3BuWJGomeTqUeSJC9FjZPohHBb+AHMoIdSOAGoizfvRUyuRIgDxBygP8mjXtQOQK8JfRTqReyYxDYpr2qJREsJcLCqNC9EzuY88ojGgsuh1EUnEm0Hww7Hwy6eRlNbqOj6sAx9ujU6Hz8AUTAZjw1NRmVQS/8+uvTjNz9/vT44Do+kqg5McxhTjqu2u2TK9aFgFvqS8dWbxLmyhWY9yuEo0KP+ZEpgRiiG4MDfgoJjBcc3iNcGE8WZn7797uhHP+xDhXU0xwWx1onS34DCt12oguBW13nnqo7o4OP98D2sYpPomW1iWUErqR6DNunpCYZbVMbL5cpuF6pyMqUqUWjN2e//WjK+utqvzBREejxTPa5O8T4qMZszm+qjIjwFUo+GA45HfUvE0z5t/iPHcVK3zlX9vZZWhVJbpypR4fXzXV+p3dAZqP82A4Mj7TvGXHG7DeNSouXe6WCWjhxIWCmc3h31Ne70csLROy6RpnAtNc9f6Nn08XKDSU6tql4r2z7nK8vqW0l1nDLO8zxOS7RfF3pdHUGLveEZvStBBSafROeyCrGjBhjuA+PavZZduyRET8CwnkCTFII3mNPQXlf3YkIyJ60syZNqAg4OBpuZWhuSduAeFm8oIxTUQovldCJGjrq90jB8GMU0VMYXZAAYM3Epj4lhdxlkXNijlQw+Rk7nSapDLRYebMUdwj0aFaTcU7zoCylcj3xajsiqxm7Klcru/1GPGWqrIKx+FHnpafTeyF/qjdwOYvZfHh/3IDJO93JeuiMOM/i/uFczGQ0wemfKK9E+uCpvm/B+8KUq/rR0/bgDKpkdYAz4SbbAv65Jbj4TUV4EnoMhA4O6SsyHLVf4NmRW6qnxvjsohq6gffF8ryY4vAmq9bXae6C134OWSW6L+Qio3hoSne3VmRcOrnCRY2Pj1rv169vG9fr1WmPj9q1Ea58dN++WT72lT6DUQgR3z7zk1bWRvXrZvmnTjrCZKRHO4iK4meLgkok7EWAuEGyolxgqBeKoH85OZC3uBZzdC0n/6bsicyInwbAXgJxtj6lWWdMiiUTvv78yAzfe6Guzph2vhVGoC1YqaYkrfB53MyPcreSkr+77WcxNK2HE25kJLMWsreSypj2nc/bSJFDNWLwtFsJtwTz9DC+rcTLMZ+dp8mlAULlsDryvJrltcvJEgDJ65k2LSLLcZLYFsb49YnlKfedyLarlX9Tn13QLFyeIaZqZwdsww8aliaL4bYyFN8DCPzq5WhfUEwAA";
91      private static final Log log = LogFactory.getLog(SplitSpeciesBatchUI.class);
92      private static final long serialVersionUID = 1L;
93  
94      /*-----------------------------------------------------------------------*/
95      /*--------------------------- Internal states ---------------------------*/
96      /*-----------------------------------------------------------------------*/
97  
98      protected List<Object> $activeBindings = new ArrayList<Object>();
99      protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
100     protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
101     protected Map<String, Object> $objectMap = new HashMap<String, Object>();
102     protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
103     private boolean allComponentsCreated;
104     protected final JAXXContext delegateContext = new DefaultJAXXContext();
105 
106     /*-----------------------------------------------------------------------*/
107     /*------------------------ Protected components  ------------------------*/
108     /*-----------------------------------------------------------------------*/
109 
110     protected JPanel actionPanel;
111     protected JTextField batchWeightField;
112     protected JLabel batchWeightLabel;
113     protected TuttiHelpBroker broker;
114     protected JButton cancelButton;
115     @ValidatorField( validatorId = "validator",  propertyName = "selectedCategory",  editorName = "categoryComboBox")
116     protected JComboBox categoryComboBox;
117     protected JLabel categoryLabel;
118     protected Table configurationPanel;
119     protected final SplitSpeciesBatchUIHandler handler = createHandler();
120     protected SplitSpeciesBatchUIModel model;
121     @ValidatorField( validatorId = "validator",  propertyName = "sampleWeight",  editorName = "sampleWeightField")
122     protected JTextField sampleWeightField;
123     protected JLabel sampleWeightLabel;
124     protected JButton saveButton;
125     protected SplitSpeciesBatchUI splitSpeciesBatchTopPanel = this;
126     protected JXTable table;
127     protected JScrollPane tableScrollPane;
128     @Validator( validatorId = "validator")
129     protected SwingValidator<SplitSpeciesBatchUIModel> validator;
130     protected List<String> validatorIds = new ArrayList<String>();
131 
132     /*-----------------------------------------------------------------------*/
133     /*------------------------- Private components  -------------------------*/
134     /*-----------------------------------------------------------------------*/
135 
136     private JSeparator $JSeparator0;
137 
138     /*-----------------------------------------------------------------------*/
139     /*---------------------- Raw body code from script ----------------------*/
140     /*-----------------------------------------------------------------------*/
141 
142     // Pour savoir sur quel modèle on est (espèce ou benthos)
143     private String speciesOrBenthosContext;
144     
145     
146     public String getSpeciesOrBenthosContext() { return speciesOrBenthosContext; }
147 
148     /*-----------------------------------------------------------------------*/
149     /*---------------------------- Constructors  ----------------------------*/
150     /*-----------------------------------------------------------------------*/
151 
152     public SplitSpeciesBatchUI(TuttiUI parentUI, String speciesOrBenthosContext) {
153         TuttiUIUtil.setParentUI(this, parentUI);
154             this.speciesOrBenthosContext = speciesOrBenthosContext;
155             $initialize();
156     }
157 
158     public SplitSpeciesBatchUI(LayoutManager param0, boolean param1) {
159         super(param0 ,param1);
160         $initialize();
161     }
162 
163     public SplitSpeciesBatchUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
164         super(param1 ,param2);
165         JAXXUtil.initContext(this, parentContext);
166         $initialize();
167     }
168 
169     public SplitSpeciesBatchUI(LayoutManager param0) {
170         super(param0);
171         $initialize();
172     }
173 
174     public SplitSpeciesBatchUI(JAXXContext parentContext, LayoutManager param1) {
175         super(param1);
176         JAXXUtil.initContext(this, parentContext);
177         $initialize();
178     }
179 
180     public SplitSpeciesBatchUI() {
181         $initialize();
182     }
183 
184     public SplitSpeciesBatchUI(JAXXContext parentContext) {
185         JAXXUtil.initContext(this, parentContext);
186         $initialize();
187     }
188 
189     public SplitSpeciesBatchUI(boolean param0) {
190         super(param0);
191         $initialize();
192     }
193 
194     public SplitSpeciesBatchUI(JAXXContext parentContext, boolean param1) {
195         super(param1);
196         JAXXUtil.initContext(this, parentContext);
197         $initialize();
198     }
199 
200     /*-----------------------------------------------------------------------*/
201     /*--------------------------- Statics methods ---------------------------*/
202     /*-----------------------------------------------------------------------*/
203 
204     public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
205         return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
206     }
207 
208     /*-----------------------------------------------------------------------*/
209     /*---------------------- JAXXObject implementation ----------------------*/
210     /*-----------------------------------------------------------------------*/
211 
212     @Override
213     public void applyDataBinding(String $binding) {
214         if (allComponentsCreated && $bindings.containsKey($binding)) {
215             getDataBinding($binding).applyDataBinding();
216         }
217         processDataBinding($binding);
218     }
219 
220     @Override
221     public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
222         super.firePropertyChange(propertyName, oldValue, newValue);
223     }
224 
225     @Override
226     public Map<String, Object> get$objectMap() {
227         return $objectMap;
228     }
229 
230     @Override
231     public JAXXBinding getDataBinding(String bindingId) {
232         return $bindings.get(bindingId);
233     }
234 
235     @Override
236     public JAXXBinding[] getDataBindings() {
237         return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
238     }
239 
240     @Override
241     public Object getObjectById(String id) {
242         return $objectMap.get(id);
243     }
244 
245     @Override
246     public void processDataBinding(String $binding, boolean $force) {
247         if (!$force && $activeBindings.contains($binding)) { 
248             return;
249         }
250         $activeBindings.add($binding);
251         try {
252             if (allComponentsCreated && $bindings.containsKey($binding)) {
253                 getDataBinding($binding).processDataBinding();
254             }
255         } finally {
256             $activeBindings.remove($binding);
257         }
258     }
259 
260     @Override
261     public void processDataBinding(String $binding) {
262         processDataBinding($binding, false);
263     }
264 
265     @Override
266     public void registerDataBinding(JAXXBinding binding) {
267         $bindings.put(binding.getId(), binding);
268     }
269 
270     @Override
271     public void removeDataBinding(String $binding) {
272         if (allComponentsCreated && $bindings.containsKey($binding)) {
273             getDataBinding($binding).removeDataBinding();
274         }
275     }
276 
277     /*-----------------------------------------------------------------------*/
278     /*--------------------- JAXXContext implementation  ---------------------*/
279     /*-----------------------------------------------------------------------*/
280 
281     @Override
282     public <T> T getContextValue(Class<T> clazz) {
283         return delegateContext.getContextValue(clazz, null);
284     }
285 
286     @Override
287     public <T> T getContextValue(Class<T> clazz, String name) {
288         return delegateContext.getContextValue(clazz, name);
289     }
290 
291     @Override
292     public JAXXContext getDelegateContext() {
293         return delegateContext;
294     }
295 
296     @Override
297     public <O extends Container> O getParentContainer(Class<O> clazz) {
298         return SwingUtil.getParentContainer(this, clazz);
299     }
300 
301     @Override
302     public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
303         return SwingUtil.getParentContainer(source, clazz);
304     }
305 
306     @Override
307     public <T> void removeContextValue(Class<T> clazz) {
308         delegateContext.removeContextValue(clazz, null);
309     }
310 
311     @Override
312     public <T> void removeContextValue(Class<T> clazz, String name) {
313         delegateContext.removeContextValue(clazz, name);
314     }
315 
316     @Override
317     public <T> void setContextValue(T o) {
318         delegateContext.setContextValue(o, null);
319     }
320 
321     @Override
322     public <T> void setContextValue(T o, String name) {
323         delegateContext.setContextValue(o, name);
324     }
325 
326     /*-----------------------------------------------------------------------*/
327     /*-------------------- JAXXValidator implementation  --------------------*/
328     /*-----------------------------------------------------------------------*/
329 
330     @Override
331     public SwingValidator<?> getValidator(String validatorId) {
332         return (SwingValidator<?>) (validatorIds.contains(validatorId) ? getObjectById(validatorId) : null);
333     }
334 
335     @Override
336     public List<String> getValidatorIds() {
337         return validatorIds;
338     }
339 
340     @Override
341     public void registerValidatorFields() {
342         SwingValidatorUtil.detectValidatorFields(this);
343     }
344 
345     /*-----------------------------------------------------------------------*/
346     /*----------------------- Public acessor methods  -----------------------*/
347     /*-----------------------------------------------------------------------*/
348 
349     public JPanel getActionPanel() {
350         return actionPanel;
351     }
352 
353     public JTextField getBatchWeightField() {
354         return batchWeightField;
355     }
356 
357     public JLabel getBatchWeightLabel() {
358         return batchWeightLabel;
359     }
360 
361     public TuttiHelpBroker getBroker() {
362         return broker;
363     }
364 
365     public JButton getCancelButton() {
366         return cancelButton;
367     }
368 
369     public JComboBox getCategoryComboBox() {
370         return categoryComboBox;
371     }
372 
373     public JLabel getCategoryLabel() {
374         return categoryLabel;
375     }
376 
377     public Table getConfigurationPanel() {
378         return configurationPanel;
379     }
380 
381     public SplitSpeciesBatchUIHandler getHandler() {
382         return handler;
383     }
384 
385     public SplitSpeciesBatchUIModel getModel() {
386         return model;
387     }
388 
389     public JTextField getSampleWeightField() {
390         return sampleWeightField;
391     }
392 
393     public JLabel getSampleWeightLabel() {
394         return sampleWeightLabel;
395     }
396 
397     public JButton getSaveButton() {
398         return saveButton;
399     }
400 
401     public JXTable getTable() {
402         return table;
403     }
404 
405     public JScrollPane getTableScrollPane() {
406         return tableScrollPane;
407     }
408 
409     public SwingValidator<SplitSpeciesBatchUIModel> getValidator() {
410         return validator;
411     }
412 
413     /*-----------------------------------------------------------------------*/
414     /*---------------------------- Other methods ----------------------------*/
415     /*-----------------------------------------------------------------------*/
416 
417     @Override
418     public void registerHelpId(TuttiHelpBroker broker, Component component, String helpId) {
419         broker.installUI(component, helpId);
420     }
421 
422     @Override
423     public void showHelp(String helpId) {
424         getBroker().showHelp(this, helpId);
425     }
426 
427     /*-----------------------------------------------------------------------*/
428     /*--------------------- Protected acessors methods  ---------------------*/
429     /*-----------------------------------------------------------------------*/
430 
431     protected JSeparator get$JSeparator0() {
432         return $JSeparator0;
433     }
434 
435     /*-----------------------------------------------------------------------*/
436     /*--------------------- Components creation methods ---------------------*/
437     /*-----------------------------------------------------------------------*/
438 
439     protected void addChildrenToActionPanel() {
440         if (!allComponentsCreated) {
441             return;
442         }
443         actionPanel.add(cancelButton);
444         actionPanel.add(saveButton);
445     }
446 
447     protected void addChildrenToConfigurationPanel() {
448         if (!allComponentsCreated) {
449             return;
450         }
451         configurationPanel.add(categoryLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 17, 1, new Insets(3, 3, 3, 3), 0, 0));
452         configurationPanel.add(SwingUtil.boxComponentWithJxLayer(categoryComboBox), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
453         configurationPanel.add($JSeparator0, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
454         configurationPanel.add(batchWeightLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 17, 1, new Insets(3, 3, 3, 3), 0, 0));
455         configurationPanel.add(batchWeightField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
456         configurationPanel.add(sampleWeightLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 17, 1, new Insets(3, 3, 3, 3), 0, 0));
457         configurationPanel.add(SwingUtil.boxComponentWithJxLayer(sampleWeightField), new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
458     }
459 
460     protected void addChildrenToSplitSpeciesBatchTopPanel() {
461         if (!allComponentsCreated) {
462             return;
463         }
464         add(configurationPanel, BorderLayout.NORTH);
465         add(tableScrollPane, BorderLayout.CENTER);
466         add(actionPanel, BorderLayout.SOUTH);
467     }
468 
469     protected void addChildrenToTableScrollPane() {
470         if (!allComponentsCreated) {
471             return;
472         }
473         tableScrollPane.getViewport().add(table);
474     }
475 
476     protected void addChildrenToValidator() {
477         if (!allComponentsCreated) {
478             return;
479         }
480         validator.setUiClass(ImageValidationUI.class);
481         validator.setBean(model);
482     }
483 
484     protected void createActionPanel() {
485         $objectMap.put("actionPanel", actionPanel = new JPanel());
486         
487         actionPanel.setName("actionPanel");
488         actionPanel.setLayout(new GridLayout(1, 0));
489         SwingUtil.setComponentHeight(actionPanel,50);
490     }
491 
492     protected void createBatchWeightField() {
493         $objectMap.put("batchWeightField", batchWeightField = new JTextField());
494         
495         batchWeightField.setName("batchWeightField");
496         batchWeightField.setColumns(15);
497         batchWeightField.setEditable(false);
498         batchWeightField.setEnabled(false);
499         batchWeightField.putClientProperty("help", "tutti.splitSpeciesBatch.field.batchWeightField.help");
500     }
501 
502     protected void createBatchWeightLabel() {
503         $objectMap.put("batchWeightLabel", batchWeightLabel = new JLabel());
504         
505         batchWeightLabel.setName("batchWeightLabel");
506         batchWeightLabel.setText(t("tutti.splitSpeciesBatch.field.batchWeight"));
507         batchWeightLabel.setToolTipText(t("tutti.splitSpeciesBatch.field.batchWeightField.tip"));
508         batchWeightLabel.putClientProperty("help", "tutti.splitSpeciesBatch.field.batchWeightField.help");
509         batchWeightLabel.putClientProperty("addWeightUnit", model.getWeightUnit());
510     }
511 
512     protected void createBroker() {
513         $objectMap.put("broker", broker = new TuttiHelpBroker("tutti.splitSpeciesBatch.help"));
514     }
515 
516     protected void createCancelButton() {
517         $objectMap.put("cancelButton", cancelButton = new JButton());
518         
519         cancelButton.setName("cancelButton");
520         cancelButton.setText(t("tutti.splitSpeciesBatch.action.cancel"));
521         cancelButton.setToolTipText(t("tutti.splitSpeciesBatch.action.cancel.tip"));
522         cancelButton.putClientProperty("help", "tutti.splitSpeciesBatch.action.cancel.help");
523         cancelButton.putClientProperty("simpleAction", fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.actions.SplitSpeciesBatchCancelAction.class);
524     }
525 
526     protected void createCategoryComboBox() {
527         $objectMap.put("categoryComboBox", categoryComboBox = new JComboBox());
528         
529         categoryComboBox.setName("categoryComboBox");
530     }
531 
532     protected void createCategoryLabel() {
533         $objectMap.put("categoryLabel", categoryLabel = new JLabel());
534         
535         categoryLabel.setName("categoryLabel");
536         categoryLabel.setText(t("tutti.splitSpeciesBatch.field.category"));
537         categoryLabel.setToolTipText(t("tutti.splitSpeciesBatch.field.categoryField.tip"));
538         categoryLabel.putClientProperty("help", "tutti.splitSpeciesBatch.field.categoryField.help");
539     }
540 
541     protected void createConfigurationPanel() {
542         $objectMap.put("configurationPanel", configurationPanel = new Table());
543         
544         configurationPanel.setName("configurationPanel");
545     }
546 
547     protected SplitSpeciesBatchUIHandler createHandler() {
548         return new SplitSpeciesBatchUIHandler();
549     }
550 
551     protected void createModel() {
552         $objectMap.put("model", model = getContextValue(SplitSpeciesBatchUIModel.class));
553     }
554 
555     protected void createSampleWeightField() {
556         $objectMap.put("sampleWeightField", sampleWeightField = new JTextField());
557         
558         sampleWeightField.setName("sampleWeightField");
559         sampleWeightField.setColumns(15);
560         sampleWeightField.putClientProperty("help", "tutti.splitSpeciesBatch.field.sampleWeightField.help");
561         sampleWeightField.putClientProperty("computed", true);
562     }
563 
564     protected void createSampleWeightLabel() {
565         $objectMap.put("sampleWeightLabel", sampleWeightLabel = new JLabel());
566         
567         sampleWeightLabel.setName("sampleWeightLabel");
568         sampleWeightLabel.setText(t("tutti.splitSpeciesBatch.field.sampleWeight"));
569         sampleWeightLabel.setToolTipText(t("tutti.splitSpeciesBatch.field.sampleWeightField.tip"));
570         sampleWeightLabel.putClientProperty("help", "tutti.splitSpeciesBatch.field.sampleWeightField.help");
571         sampleWeightLabel.putClientProperty("addWeightUnit", model.getWeightUnit());
572     }
573 
574     protected void createSaveButton() {
575         $objectMap.put("saveButton", saveButton = new JButton());
576         
577         saveButton.setName("saveButton");
578         saveButton.setText(t("tutti.splitSpeciesBatch.action.save"));
579         saveButton.setToolTipText(t("tutti.splitSpeciesBatch.action.save.tip"));
580         saveButton.putClientProperty("help", "tutti.splitSpeciesBatch.action.save.help");
581         saveButton.putClientProperty("simpleAction", fr.ifremer.tutti.ui.swing.content.operation.catches.species.split.actions.SplitSpeciesBatchSaveAction.class);
582     }
583 
584     protected void createTable() {
585         $objectMap.put("table", table = new JXTable());
586         
587         table.setName("table");
588         table.setSortable(false);
589     }
590 
591     protected void createTableScrollPane() {
592         $objectMap.put("tableScrollPane", tableScrollPane = new JScrollPane());
593         
594         tableScrollPane.setName("tableScrollPane");
595     }
596 
597     protected void createValidator() {
598         $objectMap.put("validator", validator = SwingValidator.newValidator(SplitSpeciesBatchUIModel.class, null));
599     }
600 
601     /*-----------------------------------------------------------------------*/
602     /*------------------------ Internal jaxx methods ------------------------*/
603     /*-----------------------------------------------------------------------*/
604 
605     private void $completeSetup() {
606         allComponentsCreated = true;
607         if (log.isDebugEnabled()) {
608             log.debug(this);
609         }
610         addChildrenToSplitSpeciesBatchTopPanel();
611         addChildrenToValidator();
612         addChildrenToConfigurationPanel();
613         addChildrenToTableScrollPane();
614         addChildrenToActionPanel();
615         
616         // apply 5 data bindings
617         JAXXUtil.applyDataBinding(this, $bindings.keySet());
618         
619         // apply 13 property setters
620         configurationPanel.setBorder(new TitledBorder(null, null));
621         categoryLabel.setLabelFor(categoryComboBox);
622         batchWeightLabel.setLabelFor(batchWeightField);
623         sampleWeightLabel.setLabelFor(sampleWeightField);
624         table.setSelectionBackground(null);
625         table.setSelectionForeground(Color.BLACK);
626         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
627         cancelButton.setMnemonic(SwingUtil.getFirstCharAt(t("tutti.splitSpeciesBatch.action.cancel.mnemonic"),'Z'));
628         cancelButton.setIcon(SwingUtil.createActionIcon("cancel"));
629         saveButton.setMnemonic(SwingUtil.getFirstCharAt(t("tutti.splitSpeciesBatch.action.save.mnemonic"),'Z'));
630         saveButton.setIcon(SwingUtil.createActionIcon("save"));
631         // late initializer
632         // help broker setup
633         TuttiHelpBroker _broker = getBroker();
634         registerHelpId(_broker, splitSpeciesBatchTopPanel, "tutti.splitSpeciesBatch.help");
635         registerHelpId(_broker, categoryLabel, "tutti.splitSpeciesBatch.field.categoryField.help");
636         registerHelpId(_broker, batchWeightLabel, "tutti.splitSpeciesBatch.field.batchWeightField.help");
637         registerHelpId(_broker, batchWeightField, "tutti.splitSpeciesBatch.field.batchWeightField.help");
638         registerHelpId(_broker, sampleWeightLabel, "tutti.splitSpeciesBatch.field.sampleWeightField.help");
639         registerHelpId(_broker, sampleWeightField, "tutti.splitSpeciesBatch.field.sampleWeightField.help");
640         registerHelpId(_broker, cancelButton, "tutti.splitSpeciesBatch.action.cancel.help");
641         registerHelpId(_broker, saveButton, "tutti.splitSpeciesBatch.action.save.help");
642         _broker.prepareUI(this);
643         // register 1 validator(s)
644         validatorIds = SwingValidatorUtil.detectValidators(this);
645         SwingValidatorUtil.installUI(this);
646     }
647 
648     private void $initialize() {
649         if (allComponentsCreated) {
650             return;
651         }
652         if (log.isDebugEnabled()) {
653             log.debug(this);
654         }
655         handler.beforeInit(this);
656         $objectMap.put("splitSpeciesBatchTopPanel", splitSpeciesBatchTopPanel);
657         createModel();
658         createValidator();
659         createBroker();
660         createConfigurationPanel();
661         createCategoryLabel();
662         createCategoryComboBox();
663         // inline creation of $JSeparator0
664         $objectMap.put("$JSeparator0", $JSeparator0 = new JSeparator());
665         
666         $JSeparator0.setName("$JSeparator0");
667         createBatchWeightLabel();
668         createBatchWeightField();
669         createSampleWeightLabel();
670         createSampleWeightField();
671         createTableScrollPane();
672         createTable();
673         createActionPanel();
674         createCancelButton();
675         createSaveButton();
676         // inline creation of splitSpeciesBatchTopPanel
677         setName("splitSpeciesBatchTopPanel");
678         setLayout(new BorderLayout());
679         splitSpeciesBatchTopPanel.putClientProperty("help", "tutti.splitSpeciesBatch.help");
680         
681         // registers 5 data bindings
682         $registerDefaultBindings();
683         $completeSetup();
684         handler.afterInit(this);
685     }
686 
687     private void $registerDefaultBindings() {
688         // register 5 data bindings
689         registerDataBinding(new DefaultJAXXBinding(this, BINDING_CATEGORY_COMBO_BOX_SELECTED_ITEM, true) {
690         
691             @Override
692             public void applyDataBinding() {
693                 if (model != null) {
694                     model.addPropertyChangeListener("selectedCategory", this);
695                 }
696             }
697         
698             @Override
699             public void processDataBinding() {
700                 if (model != null) {
701                     categoryComboBox.setSelectedItem(model.getSelectedCategory());
702                 }
703             }
704         
705             @Override
706             public void removeDataBinding() {
707                 if (model != null) {
708                     model.removePropertyChangeListener("selectedCategory", this);
709                 }
710             }
711         });
712         registerDataBinding(new DefaultJAXXBinding(this, BINDING_BATCH_WEIGHT_FIELD_TEXT, true) {
713         
714             @Override
715             public void applyDataBinding() {
716                 if (model != null) {
717                     model.addPropertyChangeListener("batchWeight", this);
718                 }
719             }
720         
721             @Override
722             public void processDataBinding() {
723                 if (model != null) {
724                     SwingUtil.setText(batchWeightField, getStringValue(model.getBatchWeight()));
725                 }
726             }
727         
728             @Override
729             public void removeDataBinding() {
730                 if (model != null) {
731                     model.removePropertyChangeListener("batchWeight", this);
732                 }
733             }
734         });
735         registerDataBinding(new DefaultJAXXBinding(this, BINDING_SAMPLE_WEIGHT_FIELD_TEXT, true) {
736         
737             @Override
738             public void applyDataBinding() {
739                 if (model != null) {
740                     model.addPropertyChangeListener("sampleWeight", this);
741                 }
742             }
743         
744             @Override
745             public void processDataBinding() {
746                 if (model != null) {
747                     SwingUtil.setText(sampleWeightField, getStringValue(model.getSampleWeight()));
748                 }
749             }
750         
751             @Override
752             public void removeDataBinding() {
753                 if (model != null) {
754                     model.removePropertyChangeListener("sampleWeight", this);
755                 }
756             }
757         });
758         registerDataBinding(new DefaultJAXXBinding(this, BINDING_TABLE_ENABLED, true) {
759         
760             @Override
761             public void applyDataBinding() {
762                 if (model != null) {
763                     model.addPropertyChangeListener("selectedCategory", this);
764                 }
765             }
766         
767             @Override
768             public void processDataBinding() {
769                 if (model != null) {
770                     table.setEnabled(model.getSelectedCategory() != null);
771                 }
772             }
773         
774             @Override
775             public void removeDataBinding() {
776                 if (model != null) {
777                     model.removePropertyChangeListener("selectedCategory", this);
778                 }
779             }
780         });
781         registerDataBinding(new DefaultJAXXBinding(this, BINDING_SAVE_BUTTON_ENABLED, true) {
782         
783             @Override
784             public void applyDataBinding() {
785                 if (model != null) {
786                     model.addPropertyChangeListener("valid", this);
787                 }
788             }
789         
790             @Override
791             public void processDataBinding() {
792                 if (model != null) {
793                     saveButton.setEnabled(model.isValid());
794                 }
795             }
796         
797             @Override
798             public void removeDataBinding() {
799                 if (model != null) {
800                     model.removePropertyChangeListener("valid", this);
801                 }
802             }
803         });
804     }
805 
806 }