View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.observation.survey.measurement.ungrouped;
2   
3   /*-
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2022 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (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 Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
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.plaf.WaitBlockingLayerUI;
30  import fr.ifremer.quadrige3.ui.swing.table.SwingTable;
31  import fr.ifremer.reefdb.ui.swing.ReefDbHelpBroker;
32  import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
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.util.ArrayList;
40  import java.util.HashMap;
41  import java.util.List;
42  import java.util.Map;
43  import java.util.TreeMap;
44  import javax.swing.BorderFactory;
45  import javax.swing.Box;
46  import javax.swing.BoxLayout;
47  import javax.swing.JPanel;
48  import javax.swing.JScrollPane;
49  import jaxx.runtime.JAXXBinding;
50  import jaxx.runtime.JAXXContext;
51  import jaxx.runtime.JAXXObject;
52  import jaxx.runtime.JAXXObjectDescriptor;
53  import jaxx.runtime.JAXXUtil;
54  import jaxx.runtime.SwingUtil;
55  import jaxx.runtime.binding.DefaultJAXXBinding;
56  import jaxx.runtime.context.DefaultJAXXContext;
57  import jaxx.runtime.swing.help.JAXXHelpUI;
58  import org.apache.commons.logging.Log;
59  import org.apache.commons.logging.LogFactory;
60  import static org.nuiton.i18n.I18n.t;
61  
62  public class SurveyMeasurementsUngroupedTableUI extends JPanel implements JAXXHelpUI<ReefDbHelpBroker>, ReefDbUI<SurveyMeasurementsUngroupedTableUIModel, SurveyMeasurementsUngroupedTableUIHandler>, JAXXObject {
63  
64      /*-----------------------------------------------------------------------*/
65      /*------------------ Constants for all public bindings ------------------*/
66      /*-----------------------------------------------------------------------*/
67  
68      public static final String BINDING_TABLE_BLOCK_LAYER_BLOCK = "tableBlockLayer.block";
69  
70      /*-----------------------------------------------------------------------*/
71      /*------------------------- Other static fields -------------------------*/
72      /*-----------------------------------------------------------------------*/
73  
74      private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAL1UyW5TMRS9SUmgZaYqgwBRCkKMzgKJTRFDJzUoLRVJxZBF8ctzUhfn2dh+5UUViE/gE2DPBokdK8SCNQs2iF9AiAVbxLWT5qU0DCsq9cnx9Tn3+Pje+/IL5IyG4ys0SYiOI8ubjNy4fufOzWCF1ewUMzXNlZUa2n+ZLGSrsD3s7hsLJ6olBy904IVJ2VQyYlEPerwEQ8a2BDPLjFkLRzciasYUyt3weKJivc7aFdWP9fm3r9ln4dMXWYBEobo8XmX0b6j0JltKkOWhhX2YaZUWBI0aKEPzqIF6d7q9SUGNmadN9hCewNYS5BXVSGZh7N+v7Dk8PlEW9lgaCEbjWRrbBRoxYSGqa8LrmjWZJpqxehiQmBPzCHWQmows0hIZGKZXqeUyIibWq6xFmoziClEYjqOGlrFiISn74FwaM4vrsYrLvFhUyqvJW8g1ZegEmP8rYM5lTVXkAy0fMG3h3B9k3MLfU8Es4ib86RS+2xs6IWTtQYm2HM+lHp6HMQ01b7CLKZUStE5uU249Bnc8rNeXkZ43Kte0FMK9lIUDriSSDs2NNOJgg130sbY93Vv3WOENsED+LNBnJ2W39gDHO6KwtA9vKG1sGpI2TVrVmSrkdIzbFg5WN/fZLQy1O+zgLx3mCH30x/7hj28+v55Zb6sBzD3S92jPVMByV1oqfADuUu9u91RsuSjMUTVehUHDBI4UPzKO9BFW7oRRHObb6+DEwcksNctIkdv66e27/fc/DEB2BoaEpOEMdeeLMGiXNbogRZioq9e8oh2PtuF3D/5nXYVJHbrKOLU24VdtYIvUNKOWVbgVLGxHTo+NnXlsYWhJud6stBQ6e3StXX2LRTI9VawUb84vLVyfny4tVe4uTD9O0MkjfZzsXicYfP99uPzq2rqbGbzdod8eTx3N3YM8jwSPmB9TnQnUdyxtV4bFoUwnTb/ZA32Gj+oU/aj/nuxnXi5wbWJheM1PC8JNCa3H2jztjNoZdJpoUgqJDl9YW6ZRKLCwG8xOyqjO8Vx7jfENHYf4JHZpz3pT3Oo8bO7nv0nM4PsK2pIxTuVdl0Nq6WjAIyfwyib6jPsOIeNPJR6pGfcGAAA=";
75      private static final Log log = LogFactory.getLog(SurveyMeasurementsUngroupedTableUI.class);
76      private static final long serialVersionUID = 1L;
77  
78      /*-----------------------------------------------------------------------*/
79      /*--------------------------- Internal states ---------------------------*/
80      /*-----------------------------------------------------------------------*/
81  
82      protected List<Object> $activeBindings = new ArrayList<Object>();
83      protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
84      protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
85      protected Map<String, Object> $objectMap = new HashMap<String, Object>();
86      protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
87      private boolean allComponentsCreated;
88      protected final JAXXContext delegateContext = new DefaultJAXXContext();
89  
90      /*-----------------------------------------------------------------------*/
91      /*------------------------ Protected components  ------------------------*/
92      /*-----------------------------------------------------------------------*/
93  
94      protected ReefDbHelpBroker broker;
95      protected final SurveyMeasurementsUngroupedTableUIHandler handler = createHandler();
96      protected SurveyMeasurementsUngroupedTableUIModel model;
97      protected SwingTable surveyUngroupedMeasurementTable;
98      protected WaitBlockingLayerUI tableBlockLayer;
99      protected SurveyMeasurementsUngroupedTableUI tableauHautPanel = this;
100     protected JScrollPane tableauHautScrollPane;
101 
102     /*-----------------------------------------------------------------------*/
103     /*---------------------------- Constructors  ----------------------------*/
104     /*-----------------------------------------------------------------------*/
105 
106     public SurveyMeasurementsUngroupedTableUI(ApplicationUI parentUI) {
107         ApplicationUIUtil.setParentUI(this, parentUI);
108             $initialize();
109     }
110 
111     public SurveyMeasurementsUngroupedTableUI(LayoutManager param0, boolean param1) {
112         super(param0 ,param1);
113         $initialize();
114     }
115 
116     public SurveyMeasurementsUngroupedTableUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
117         super(param1 ,param2);
118         JAXXUtil.initContext(this, parentContext);
119         $initialize();
120     }
121 
122     public SurveyMeasurementsUngroupedTableUI(boolean param0) {
123         super(param0);
124         $initialize();
125     }
126 
127     public SurveyMeasurementsUngroupedTableUI(JAXXContext parentContext, boolean param1) {
128         super(param1);
129         JAXXUtil.initContext(this, parentContext);
130         $initialize();
131     }
132 
133     public SurveyMeasurementsUngroupedTableUI() {
134         $initialize();
135     }
136 
137     public SurveyMeasurementsUngroupedTableUI(JAXXContext parentContext) {
138         JAXXUtil.initContext(this, parentContext);
139         $initialize();
140     }
141 
142     public SurveyMeasurementsUngroupedTableUI(LayoutManager param0) {
143         super(param0);
144         $initialize();
145     }
146 
147     public SurveyMeasurementsUngroupedTableUI(JAXXContext parentContext, LayoutManager param1) {
148         super(param1);
149         JAXXUtil.initContext(this, parentContext);
150         $initialize();
151     }
152 
153     /*-----------------------------------------------------------------------*/
154     /*--------------------------- Statics methods ---------------------------*/
155     /*-----------------------------------------------------------------------*/
156 
157     public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
158         return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
159     }
160 
161     /*-----------------------------------------------------------------------*/
162     /*---------------------- JAXXObject implementation ----------------------*/
163     /*-----------------------------------------------------------------------*/
164 
165     @Override
166     public void applyDataBinding(String $binding) {
167         if (allComponentsCreated && $bindings.containsKey($binding)) {
168             getDataBinding($binding).applyDataBinding();
169         }
170         processDataBinding($binding);
171     }
172 
173     @Override
174     public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
175         super.firePropertyChange(propertyName, oldValue, newValue);
176     }
177 
178     @Override
179     public Map<String, Object> get$objectMap() {
180         return $objectMap;
181     }
182 
183     @Override
184     public JAXXBinding getDataBinding(String bindingId) {
185         return $bindings.get(bindingId);
186     }
187 
188     @Override
189     public JAXXBinding[] getDataBindings() {
190         return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
191     }
192 
193     @Override
194     public Object getObjectById(String id) {
195         return $objectMap.get(id);
196     }
197 
198     @Override
199     public void processDataBinding(String $binding, boolean $force) {
200         if (!$force && $activeBindings.contains($binding)) { 
201             return;
202         }
203         $activeBindings.add($binding);
204         try {
205             if (allComponentsCreated && $bindings.containsKey($binding)) {
206                 getDataBinding($binding).processDataBinding();
207             }
208         } finally {
209             $activeBindings.remove($binding);
210         }
211     }
212 
213     @Override
214     public void processDataBinding(String $binding) {
215         processDataBinding($binding, false);
216     }
217 
218     @Override
219     public void registerDataBinding(JAXXBinding binding) {
220         $bindings.put(binding.getId(), binding);
221     }
222 
223     @Override
224     public void removeDataBinding(String $binding) {
225         if (allComponentsCreated && $bindings.containsKey($binding)) {
226             getDataBinding($binding).removeDataBinding();
227         }
228     }
229 
230     /*-----------------------------------------------------------------------*/
231     /*--------------------- JAXXContext implementation  ---------------------*/
232     /*-----------------------------------------------------------------------*/
233 
234     @Override
235     public <T> T getContextValue(Class<T> clazz) {
236         return delegateContext.getContextValue(clazz, null);
237     }
238 
239     @Override
240     public <T> T getContextValue(Class<T> clazz, String name) {
241         return delegateContext.getContextValue(clazz, name);
242     }
243 
244     @Override
245     public JAXXContext getDelegateContext() {
246         return delegateContext;
247     }
248 
249     @Override
250     public <O extends Container> O getParentContainer(Class<O> clazz) {
251         return SwingUtil.getParentContainer(this, clazz);
252     }
253 
254     @Override
255     public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
256         return SwingUtil.getParentContainer(source, clazz);
257     }
258 
259     @Override
260     public <T> void removeContextValue(Class<T> clazz) {
261         delegateContext.removeContextValue(clazz, null);
262     }
263 
264     @Override
265     public <T> void removeContextValue(Class<T> clazz, String name) {
266         delegateContext.removeContextValue(clazz, name);
267     }
268 
269     @Override
270     public <T> void setContextValue(T o) {
271         delegateContext.setContextValue(o, null);
272     }
273 
274     @Override
275     public <T> void setContextValue(T o, String name) {
276         delegateContext.setContextValue(o, name);
277     }
278 
279     /*-----------------------------------------------------------------------*/
280     /*----------------------- Public acessor methods  -----------------------*/
281     /*-----------------------------------------------------------------------*/
282 
283     public ReefDbHelpBroker getBroker() {
284         return broker;
285     }
286 
287     public SurveyMeasurementsUngroupedTableUIHandler getHandler() {
288         return handler;
289     }
290 
291     public SurveyMeasurementsUngroupedTableUIModel getModel() {
292         return model;
293     }
294 
295     public SwingTable getSurveyUngroupedMeasurementTable() {
296         return surveyUngroupedMeasurementTable;
297     }
298 
299     public WaitBlockingLayerUI getTableBlockLayer() {
300         return tableBlockLayer;
301     }
302 
303     public JScrollPane getTableauHautScrollPane() {
304         return tableauHautScrollPane;
305     }
306 
307     /*-----------------------------------------------------------------------*/
308     /*---------------------------- Other methods ----------------------------*/
309     /*-----------------------------------------------------------------------*/
310 
311     @Override
312     public void registerHelpId(ReefDbHelpBroker broker, Component component, String helpId) {
313         broker.installUI(component, helpId);
314     }
315 
316     @Override
317     public void showHelp(String helpId) {
318         getBroker().showHelp(this, helpId);
319     }
320 
321     /*-----------------------------------------------------------------------*/
322     /*--------------------- Components creation methods ---------------------*/
323     /*-----------------------------------------------------------------------*/
324 
325     protected void addChildrenToTableauHautPanel() {
326         if (!allComponentsCreated) {
327             return;
328         }
329         add(SwingUtil.boxComponentWithJxLayer(tableauHautScrollPane));
330     }
331 
332     protected void addChildrenToTableauHautScrollPane() {
333         if (!allComponentsCreated) {
334             return;
335         }
336         tableauHautScrollPane.getViewport().add(surveyUngroupedMeasurementTable);
337     }
338 
339     protected void createBroker() {
340         $objectMap.put("broker", broker = new ReefDbHelpBroker("reefdb.home.help"));
341     }
342 
343     protected SurveyMeasurementsUngroupedTableUIHandler createHandler() {
344         return new SurveyMeasurementsUngroupedTableUIHandler();
345     }
346 
347     protected void createModel() {
348         $objectMap.put("model", model = getContextValue(SurveyMeasurementsUngroupedTableUIModel.class));
349     }
350 
351     protected void createSurveyUngroupedMeasurementTable() {
352         $objectMap.put("surveyUngroupedMeasurementTable", surveyUngroupedMeasurementTable = new SwingTable());
353         
354         surveyUngroupedMeasurementTable.setName("surveyUngroupedMeasurementTable");
355     }
356 
357     protected void createTableBlockLayer() {
358         $objectMap.put("tableBlockLayer", tableBlockLayer = new WaitBlockingLayerUI());
359     }
360 
361     protected void createTableauHautScrollPane() {
362         $objectMap.put("tableauHautScrollPane", tableauHautScrollPane = new JScrollPane());
363         
364         tableauHautScrollPane.setName("tableauHautScrollPane");
365     }
366 
367     /*-----------------------------------------------------------------------*/
368     /*------------------------ Internal jaxx methods ------------------------*/
369     /*-----------------------------------------------------------------------*/
370 
371     private void $completeSetup() {
372         allComponentsCreated = true;
373         if (log.isDebugEnabled()) {
374             log.debug(this);
375         }
376         addChildrenToTableauHautPanel();
377         addChildrenToTableauHautScrollPane();
378         
379         // apply 1 data bindings
380         JAXXUtil.applyDataBinding(this, $bindings.keySet());
381         
382         // apply 3 property setters
383         setBorder(BorderFactory.createTitledBorder(""));
384         tableBlockLayer.setBlockingColor(handler.getConfig().getColorBlockingLayer());
385     }
386 
387     private void $initialize() {
388         if (allComponentsCreated) {
389             return;
390         }
391         if (log.isDebugEnabled()) {
392             log.debug(this);
393         }
394         handler.beforeInit(this);
395         $objectMap.put("tableauHautPanel", tableauHautPanel);
396         createModel();
397         createBroker();
398         createTableBlockLayer();
399         createTableauHautScrollPane();
400         createSurveyUngroupedMeasurementTable();
401         // inline creation of tableauHautPanel
402         setName("tableauHautPanel");
403         setLayout(new BorderLayout());
404         tableauHautPanel.putClientProperty("panelType", ReefDbUI.EDITION_PANEL_TYPE);
405         
406         // registers 1 data bindings
407         $registerDefaultBindings();
408         $completeSetup();
409         handler.afterInit(this);
410     }
411 
412     private void $registerDefaultBindings() {
413         // register 1 data bindings
414         registerDataBinding(new DefaultJAXXBinding(this, BINDING_TABLE_BLOCK_LAYER_BLOCK, true) {
415         
416             @Override
417             public void applyDataBinding() {
418                 if (model != null) {
419                     model.addPropertyChangeListener("loading", this);
420                 }
421             }
422         
423             @Override
424             public void processDataBinding() {
425                 if (model != null) {
426                     tableBlockLayer.setBlock(model.isLoading());
427                 }
428             }
429         
430             @Override
431             public void removeDataBinding() {
432                 if (model != null) {
433                     model.removePropertyChangeListener("loading", this);
434                 }
435             }
436         });
437     }
438 
439 }