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