View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.config;
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.reefdb.ui.swing.ReefDbHelpBroker;
30  import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
31  import fr.ifremer.reefdb.ui.swing.content.ReefDbMainUI;
32  import fr.ifremer.reefdb.ui.swing.util.ReefDbUI;
33  import java.awt.BorderLayout;
34  import java.awt.Component;
35  import java.awt.Container;
36  import java.awt.LayoutManager;
37  import java.util.ArrayList;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Map;
41  import java.util.TreeMap;
42  import javax.swing.JPanel;
43  import jaxx.runtime.JAXXBinding;
44  import jaxx.runtime.JAXXContext;
45  import jaxx.runtime.JAXXObject;
46  import jaxx.runtime.JAXXObjectDescriptor;
47  import jaxx.runtime.JAXXUtil;
48  import jaxx.runtime.SwingUtil;
49  import jaxx.runtime.context.DefaultJAXXContext;
50  import jaxx.runtime.swing.help.JAXXHelpUI;
51  import org.apache.commons.logging.Log;
52  import org.apache.commons.logging.LogFactory;
53  
54  public class ReefDbConfigUI extends JPanel implements JAXXHelpUI<ReefDbHelpBroker>, ReefDbUI<ReefDbUIContext, ReefDbConfigUIHandler>, JAXXObject {
55  
56      /*-----------------------------------------------------------------------*/
57      /*------------------------- Other static fields -------------------------*/
58      /*-----------------------------------------------------------------------*/
59  
60      private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAI1TPW8TQRAdX7CDHQgfESYoQSSmA2ndIhlBwJEVI/OhmEgRLmDPt7Y3nG+X3T1yEQLxE/gJ0NMg0VEhCmoKGsRfQIiCFjF7PvsSchBcrOydeW/fvHl+/Q3yWsHyFo0iosLA8CEjN65tbt52t1jXrDLdVVwaoWD0yTngdGDGm9xrA+c7LQuvJvBqXQylCFiwC11rQUmbHZ/pAWPGwNm9iK7W1fakXItkqMasE1FZrC9/fHdeeM9fOQCRRHVTOMrSQah0kkMtcLhn4CS+9JhWfRr0UYbiQR/1HrV3dZ9qfYsO2SN4BtMtKEiqkMxA5f9HjjlifCQNzHZF0OP9u0LeoQHzDVzqKcJ7ig2ZIoqxnueSkBO9jSoI9hokJSMMWcfyqluPf2w0pYxZCwbyQ+FZqgv/oBphN5p1SxmZFFxwlXjIlIGLB6LXmC+vx90IV7Cwx2ncIUl3mJqc60BehXhtYL6zf+3rWBotfP6PhVvCuPqrPPf53de3jfGWHXz7VGbrrpCi+1IJiYNx+/Sx0YpDw/3qTSprHShq5mPC4wQvZghrJ2UUh++dsHBi4WSN6gFS5Ke/vP9QfvBpCpwGlHxBvQa1/U0omoFCF4TvRfLqSqzoyPZhPI9bbbiu+wM00kD5SSXxOdmvva48jdCLxQwvJoLc4sefc+03K2M/cqjvzF/bU0/y96DAA58HLM59EunMnM9IzUJPpNHNCjPsS7NMYnU6Pheyhi/4dEeE+A+avexRQ5dcHniYsCtRaCHn4nHst+WcPUvI+BuDX5GpowQAAA==";
61      private static final Log log = LogFactory.getLog(ReefDbConfigUI.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 ReefDbHelpBroker broker;
81      protected ReefDbConfigUI configTopPanel = this;
82      protected final ReefDbConfigUIHandler handler = createHandler();
83      protected ReefDbUIContext model;
84  
85      /*-----------------------------------------------------------------------*/
86      /*---------------------------- Constructors  ----------------------------*/
87      /*-----------------------------------------------------------------------*/
88  
89      public ReefDbConfigUI(ReefDbMainUI parentUI) {
90          ApplicationUIUtil.setParentUI(this, parentUI);
91              $initialize();
92      }
93  
94      public ReefDbConfigUI(LayoutManager param0, boolean param1) {
95          super(param0 ,param1);
96          $initialize();
97      }
98  
99      public ReefDbConfigUI(JAXXContext parentContext, LayoutManager param1, boolean param2) {
100         super(param1 ,param2);
101         JAXXUtil.initContext(this, parentContext);
102         $initialize();
103     }
104 
105     public ReefDbConfigUI(boolean param0) {
106         super(param0);
107         $initialize();
108     }
109 
110     public ReefDbConfigUI(JAXXContext parentContext, boolean param1) {
111         super(param1);
112         JAXXUtil.initContext(this, parentContext);
113         $initialize();
114     }
115 
116     public ReefDbConfigUI() {
117         $initialize();
118     }
119 
120     public ReefDbConfigUI(JAXXContext parentContext) {
121         JAXXUtil.initContext(this, parentContext);
122         $initialize();
123     }
124 
125     public ReefDbConfigUI(LayoutManager param0) {
126         super(param0);
127         $initialize();
128     }
129 
130     public ReefDbConfigUI(JAXXContext parentContext, LayoutManager param1) {
131         super(param1);
132         JAXXUtil.initContext(this, parentContext);
133         $initialize();
134     }
135 
136     /*-----------------------------------------------------------------------*/
137     /*--------------------------- Statics methods ---------------------------*/
138     /*-----------------------------------------------------------------------*/
139 
140     public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
141         return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
142     }
143 
144     /*-----------------------------------------------------------------------*/
145     /*---------------------- JAXXObject implementation ----------------------*/
146     /*-----------------------------------------------------------------------*/
147 
148     @Override
149     public void applyDataBinding(String $binding) {
150         if (allComponentsCreated && $bindings.containsKey($binding)) {
151             getDataBinding($binding).applyDataBinding();
152         }
153         processDataBinding($binding);
154     }
155 
156     @Override
157     public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
158         super.firePropertyChange(propertyName, oldValue, newValue);
159     }
160 
161     @Override
162     public Map<String, Object> get$objectMap() {
163         return $objectMap;
164     }
165 
166     @Override
167     public JAXXBinding getDataBinding(String bindingId) {
168         return $bindings.get(bindingId);
169     }
170 
171     @Override
172     public JAXXBinding[] getDataBindings() {
173         return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
174     }
175 
176     @Override
177     public Object getObjectById(String id) {
178         return $objectMap.get(id);
179     }
180 
181     @Override
182     public void processDataBinding(String $binding, boolean $force) {
183         if (!$force && $activeBindings.contains($binding)) { 
184             return;
185         }
186         $activeBindings.add($binding);
187         try {
188             if (allComponentsCreated && $bindings.containsKey($binding)) {
189                 getDataBinding($binding).processDataBinding();
190             }
191         } finally {
192             $activeBindings.remove($binding);
193         }
194     }
195 
196     @Override
197     public void processDataBinding(String $binding) {
198         processDataBinding($binding, false);
199     }
200 
201     @Override
202     public void registerDataBinding(JAXXBinding binding) {
203         $bindings.put(binding.getId(), binding);
204     }
205 
206     @Override
207     public void removeDataBinding(String $binding) {
208         if (allComponentsCreated && $bindings.containsKey($binding)) {
209             getDataBinding($binding).removeDataBinding();
210         }
211     }
212 
213     /*-----------------------------------------------------------------------*/
214     /*--------------------- JAXXContext implementation  ---------------------*/
215     /*-----------------------------------------------------------------------*/
216 
217     @Override
218     public <T> T getContextValue(Class<T> clazz) {
219         return delegateContext.getContextValue(clazz, null);
220     }
221 
222     @Override
223     public <T> T getContextValue(Class<T> clazz, String name) {
224         return delegateContext.getContextValue(clazz, name);
225     }
226 
227     @Override
228     public JAXXContext getDelegateContext() {
229         return delegateContext;
230     }
231 
232     @Override
233     public <O extends Container> O getParentContainer(Class<O> clazz) {
234         return SwingUtil.getParentContainer(this, clazz);
235     }
236 
237     @Override
238     public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
239         return SwingUtil.getParentContainer(source, clazz);
240     }
241 
242     @Override
243     public <T> void removeContextValue(Class<T> clazz) {
244         delegateContext.removeContextValue(clazz, null);
245     }
246 
247     @Override
248     public <T> void removeContextValue(Class<T> clazz, String name) {
249         delegateContext.removeContextValue(clazz, name);
250     }
251 
252     @Override
253     public <T> void setContextValue(T o) {
254         delegateContext.setContextValue(o, null);
255     }
256 
257     @Override
258     public <T> void setContextValue(T o, String name) {
259         delegateContext.setContextValue(o, name);
260     }
261 
262     /*-----------------------------------------------------------------------*/
263     /*----------------------- Public acessor methods  -----------------------*/
264     /*-----------------------------------------------------------------------*/
265 
266     public ReefDbHelpBroker getBroker() {
267         return broker;
268     }
269 
270     public ReefDbConfigUIHandler getHandler() {
271         return handler;
272     }
273 
274     public ReefDbUIContext getModel() {
275         return model;
276     }
277 
278     /*-----------------------------------------------------------------------*/
279     /*---------------------------- Other methods ----------------------------*/
280     /*-----------------------------------------------------------------------*/
281 
282     @Override
283     public void registerHelpId(ReefDbHelpBroker broker, Component component, String helpId) {
284         broker.installUI(component, helpId);
285     }
286 
287     @Override
288     public void showHelp(String helpId) {
289         getBroker().showHelp(this, helpId);
290     }
291 
292     /*-----------------------------------------------------------------------*/
293     /*--------------------- Components creation methods ---------------------*/
294     /*-----------------------------------------------------------------------*/
295 
296     protected void createBroker() {
297         $objectMap.put("broker", broker = new ReefDbHelpBroker("reefdb.config.help"));
298     }
299 
300     protected ReefDbConfigUIHandler createHandler() {
301         return new ReefDbConfigUIHandler();
302     }
303 
304     protected void createModel() {
305         $objectMap.put("model", model = getContextValue(ReefDbUIContext.class));
306     }
307 
308     /*-----------------------------------------------------------------------*/
309     /*------------------------ Internal jaxx methods ------------------------*/
310     /*-----------------------------------------------------------------------*/
311 
312     private void $completeSetup() {
313         allComponentsCreated = true;
314         if (log.isDebugEnabled()) {
315             log.debug(this);
316         }
317         // late initializer
318         // help broker setup
319         ReefDbHelpBroker _broker = getBroker();
320         registerHelpId(_broker, configTopPanel, "reefdb.config.help");
321         _broker.prepareUI(this);
322     }
323 
324     private void $initialize() {
325         if (allComponentsCreated) {
326             return;
327         }
328         if (log.isDebugEnabled()) {
329             log.debug(this);
330         }
331         handler.beforeInit(this);
332         $objectMap.put("configTopPanel", configTopPanel);
333         createModel();
334         createBroker();
335         // inline creation of configTopPanel
336         setName("configTopPanel");
337         setLayout(new BorderLayout());
338         configTopPanel.putClientProperty("help", "reefdb.config.help");
339         
340         $completeSetup();
341         handler.afterInit(this);
342     }
343 
344 }