View Javadoc
1   package fr.ifremer.tutti.ui.swing.util.comment;
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.persistence.entities.CommentAware;
28  import fr.ifremer.tutti.ui.swing.TuttiUIContext;
29  import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
30  import java.awt.BorderLayout;
31  import java.awt.Container;
32  import java.awt.Dialog;
33  import java.awt.Dialog.ModalityType;
34  import java.awt.Frame;
35  import java.awt.GraphicsConfiguration;
36  import java.awt.Window;
37  import java.awt.event.KeyEvent;
38  import java.awt.event.KeyListener;
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.JComponent;
45  import javax.swing.JDialog;
46  import javax.swing.JScrollPane;
47  import javax.swing.JTextArea;
48  import jaxx.runtime.JAXXBinding;
49  import jaxx.runtime.JAXXContext;
50  import jaxx.runtime.JAXXObject;
51  import jaxx.runtime.JAXXObjectDescriptor;
52  import jaxx.runtime.JAXXUtil;
53  import jaxx.runtime.SwingUtil;
54  import jaxx.runtime.context.DefaultJAXXContext;
55  import org.apache.commons.logging.Log;
56  import org.apache.commons.logging.LogFactory;
57  import org.jdesktop.swingx.JXTitledPanel;
58  import static org.nuiton.i18n.I18n.t;
59  
60  public class CommentEditorUI extends JDialog implements JAXXObject {
61  
62      /*-----------------------------------------------------------------------*/
63      /*---------------- Constants for all javaBean properties ----------------*/
64      /*-----------------------------------------------------------------------*/
65  
66      public static final String PROPERTY_BEAN = "bean";
67  
68      /*-----------------------------------------------------------------------*/
69      /*------------------------- Other static fields -------------------------*/
70      /*-----------------------------------------------------------------------*/
71  
72      private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAI1UzU8TQRR/rbQIFVAIXxES8CPqZUtM9IJRCEqEoBiBQOxBp92hHZzujDNv7RKj8U/wT9C7FxNvnowHzx68GP8FYzx4Nb7ZlrbQFdnD7Gbee7/3ex+/ffsDMtbA9A6LIs+EAYoq95bnt7ZWizu8hDe5LRmhURmoP6k0pAuQ85v3FuFsYcWF5xvh+QVV1SrgQVv07Ar0WtyV3FY4R4TJ/REla/NrTfNspEOzh9oklYT6+tfP9Cv/5Zs0QKSJnStl6n9RrUq6ViAtfIRByvSU5SULykTDiKBMfPvc3YJk1t5lVf4EXkD3CmQ1MwSGcOboJccYcXykEfpKqlp1joJJVUa4um08sW14lRsPQ0ThhcKzNeLghSik13B3hbj3LV8Q9saS1jFkFqGryFmAcLkDR3NjhUUelLhHkQIFt3sw8zWqo4UxXGpHX1f6Hgu4RJhWpuzt0LAfo9J1VpG3vLUuUHI/9nEAPU2cvnPLayWjpHS2GYRR18OoUU6bybkPNKNyyCNcUAHGnR3eF7NOpnnDmXMd1DTe0/vGS4vjtRanNdlUATImpGuEsULnrt0nU33Lxg5smQOMrX9Ghr5++P5+sX21hhNd25RBI9dGUeNdrxEG6nvl5pi/w/RsAXoslySrWDYTCcTWGmYiR/lOufD6GtxmtkIQme5vHz+NPPpyDNKL0CsV8xeZ81+CHqwY6oKSfqRvzMWMTtSO03nScUPof8h8f5OLcgU3AkF9Hn1WVT6XXplj6/ripecRdWUioStNasWez7+H1t7N7XUmRUzH/+ne6k7mAWRFIEXAY9k1FJUos5y2PPRVSzlJWgKtnZ4kK3K5KbDi+Me2yficTupCthKXipC+MhOFzu18XIH7ulAHzBVJPSqIt/tQuDT5hoHPS8ow5PQb6UIT0hLmmKyxXbsakI4al52pDv4IdEOMh3DPoJMdwnhd3vsk68W2pDTJ0j5Cuqxku4oyQf81nyGbKorAJ0le70iScmcvIf4FY60NBUwGAAA=";
73      private static final Log log = LogFactory.getLog(CommentEditorUI.class);
74      private static final long serialVersionUID = 1L;
75  
76      /*-----------------------------------------------------------------------*/
77      /*--------------------------- Internal states ---------------------------*/
78      /*-----------------------------------------------------------------------*/
79  
80      protected List<Object> $activeBindings = new ArrayList<Object>();
81      protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
82      protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
83      protected Map<String, Object> $objectMap = new HashMap<String, Object>();
84      protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
85      private boolean allComponentsCreated;
86      protected final JAXXContext delegateContext = new DefaultJAXXContext();
87  
88      /*-----------------------------------------------------------------------*/
89      /*------------------------ Protected components  ------------------------*/
90      /*-----------------------------------------------------------------------*/
91  
92      protected CommentAware bean;
93      protected CommentEditorUI commentDialog = this;
94      protected JXTitledPanel commentEditorTopPanel;
95      protected final CommentEditorUIHandler handler = createHandler();
96      protected JTextArea textContent;
97  
98      /*-----------------------------------------------------------------------*/
99      /*------------------------- Private components  -------------------------*/
100     /*-----------------------------------------------------------------------*/
101 
102     private JScrollPane $JScrollPane0;
103 
104     /*-----------------------------------------------------------------------*/
105     /*---------------------- Raw body code from script ----------------------*/
106     /*-----------------------------------------------------------------------*/
107     
108     
109     public void openEditor(JComponent component) {
110        handler.openEditor(component);
111     }
112     
113     public void closeEditor() {
114        handler.closeEditor();
115     }
116 
117     /*-----------------------------------------------------------------------*/
118     /*---------------------------- Constructors  ----------------------------*/
119     /*-----------------------------------------------------------------------*/
120 
121     public CommentEditorUI(TuttiUIContext context) {
122         super(context.getMainUI());
123             TuttiUIUtil.setApplicationContext(this, context);
124             $initialize();
125     }
126 
127     public CommentEditorUI(Frame param0, String param1, boolean param2, GraphicsConfiguration param3) {
128         super(param0 ,param1 ,param2 ,param3);
129         $initialize();
130     }
131 
132     public CommentEditorUI(JAXXContext parentContext, Frame param1, String param2, boolean param3, GraphicsConfiguration param4) {
133         super(param1 ,param2 ,param3 ,param4);
134         JAXXUtil.initContext(this, parentContext);
135         $initialize();
136     }
137 
138     public CommentEditorUI(Dialog param0) {
139         super(param0);
140         $initialize();
141     }
142 
143     public CommentEditorUI(JAXXContext parentContext, Dialog param1) {
144         super(param1);
145         JAXXUtil.initContext(this, parentContext);
146         $initialize();
147     }
148 
149     public CommentEditorUI(Frame param0, String param1, boolean param2) {
150         super(param0 ,param1 ,param2);
151         $initialize();
152     }
153 
154     public CommentEditorUI(JAXXContext parentContext, Frame param1, String param2, boolean param3) {
155         super(param1 ,param2 ,param3);
156         JAXXUtil.initContext(this, parentContext);
157         $initialize();
158     }
159 
160     public CommentEditorUI() {
161         $initialize();
162     }
163 
164     public CommentEditorUI(JAXXContext parentContext) {
165         JAXXUtil.initContext(this, parentContext);
166         $initialize();
167     }
168 
169     public CommentEditorUI(Frame param0) {
170         super(param0);
171         $initialize();
172     }
173 
174     public CommentEditorUI(JAXXContext parentContext, Frame param1) {
175         super(param1);
176         JAXXUtil.initContext(this, parentContext);
177         $initialize();
178     }
179 
180     public CommentEditorUI(Frame param0, boolean param1) {
181         super(param0 ,param1);
182         $initialize();
183     }
184 
185     public CommentEditorUI(JAXXContext parentContext, Frame param1, boolean param2) {
186         super(param1 ,param2);
187         JAXXUtil.initContext(this, parentContext);
188         $initialize();
189     }
190 
191     public CommentEditorUI(Frame param0, String param1) {
192         super(param0 ,param1);
193         $initialize();
194     }
195 
196     public CommentEditorUI(JAXXContext parentContext, Frame param1, String param2) {
197         super(param1 ,param2);
198         JAXXUtil.initContext(this, parentContext);
199         $initialize();
200     }
201 
202     public CommentEditorUI(Window param0) {
203         super(param0);
204         $initialize();
205     }
206 
207     public CommentEditorUI(JAXXContext parentContext, Window param1) {
208         super(param1);
209         JAXXUtil.initContext(this, parentContext);
210         $initialize();
211     }
212 
213     public CommentEditorUI(Window param0, ModalityType param1) {
214         super(param0 ,param1);
215         $initialize();
216     }
217 
218     public CommentEditorUI(JAXXContext parentContext, Window param1, ModalityType param2) {
219         super(param1 ,param2);
220         JAXXUtil.initContext(this, parentContext);
221         $initialize();
222     }
223 
224     public CommentEditorUI(Window param0, String param1) {
225         super(param0 ,param1);
226         $initialize();
227     }
228 
229     public CommentEditorUI(JAXXContext parentContext, Window param1, String param2) {
230         super(param1 ,param2);
231         JAXXUtil.initContext(this, parentContext);
232         $initialize();
233     }
234 
235     public CommentEditorUI(Window param0, String param1, ModalityType param2) {
236         super(param0 ,param1 ,param2);
237         $initialize();
238     }
239 
240     public CommentEditorUI(JAXXContext parentContext, Window param1, String param2, ModalityType param3) {
241         super(param1 ,param2 ,param3);
242         JAXXUtil.initContext(this, parentContext);
243         $initialize();
244     }
245 
246     public CommentEditorUI(Window param0, String param1, ModalityType param2, GraphicsConfiguration param3) {
247         super(param0 ,param1 ,param2 ,param3);
248         $initialize();
249     }
250 
251     public CommentEditorUI(JAXXContext parentContext, Window param1, String param2, ModalityType param3, GraphicsConfiguration param4) {
252         super(param1 ,param2 ,param3 ,param4);
253         JAXXUtil.initContext(this, parentContext);
254         $initialize();
255     }
256 
257     public CommentEditorUI(Dialog param0, boolean param1) {
258         super(param0 ,param1);
259         $initialize();
260     }
261 
262     public CommentEditorUI(JAXXContext parentContext, Dialog param1, boolean param2) {
263         super(param1 ,param2);
264         JAXXUtil.initContext(this, parentContext);
265         $initialize();
266     }
267 
268     public CommentEditorUI(Dialog param0, String param1) {
269         super(param0 ,param1);
270         $initialize();
271     }
272 
273     public CommentEditorUI(JAXXContext parentContext, Dialog param1, String param2) {
274         super(param1 ,param2);
275         JAXXUtil.initContext(this, parentContext);
276         $initialize();
277     }
278 
279     public CommentEditorUI(Dialog param0, String param1, boolean param2) {
280         super(param0 ,param1 ,param2);
281         $initialize();
282     }
283 
284     public CommentEditorUI(JAXXContext parentContext, Dialog param1, String param2, boolean param3) {
285         super(param1 ,param2 ,param3);
286         JAXXUtil.initContext(this, parentContext);
287         $initialize();
288     }
289 
290     public CommentEditorUI(Dialog param0, String param1, boolean param2, GraphicsConfiguration param3) {
291         super(param0 ,param1 ,param2 ,param3);
292         $initialize();
293     }
294 
295     public CommentEditorUI(JAXXContext parentContext, Dialog param1, String param2, boolean param3, GraphicsConfiguration param4) {
296         super(param1 ,param2 ,param3 ,param4);
297         JAXXUtil.initContext(this, parentContext);
298         $initialize();
299     }
300 
301     /*-----------------------------------------------------------------------*/
302     /*--------------------------- Statics methods ---------------------------*/
303     /*-----------------------------------------------------------------------*/
304 
305     public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
306         return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
307     }
308 
309     /*-----------------------------------------------------------------------*/
310     /*---------------------- JAXXObject implementation ----------------------*/
311     /*-----------------------------------------------------------------------*/
312 
313     @Override
314     public void applyDataBinding(String $binding) {
315         if (allComponentsCreated && $bindings.containsKey($binding)) {
316             getDataBinding($binding).applyDataBinding();
317         }
318         processDataBinding($binding);
319     }
320 
321     @Override
322     public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
323         super.firePropertyChange(propertyName, oldValue, newValue);
324     }
325 
326     @Override
327     public Map<String, Object> get$objectMap() {
328         return $objectMap;
329     }
330 
331     @Override
332     public JAXXBinding getDataBinding(String bindingId) {
333         return $bindings.get(bindingId);
334     }
335 
336     @Override
337     public JAXXBinding[] getDataBindings() {
338         return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
339     }
340 
341     @Override
342     public Object getObjectById(String id) {
343         return $objectMap.get(id);
344     }
345 
346     @Override
347     public void processDataBinding(String $binding, boolean $force) {
348         if (!$force && $activeBindings.contains($binding)) { 
349             return;
350         }
351         $activeBindings.add($binding);
352         try {
353             if (allComponentsCreated && $bindings.containsKey($binding)) {
354                 getDataBinding($binding).processDataBinding();
355             }
356         } finally {
357             $activeBindings.remove($binding);
358         }
359     }
360 
361     @Override
362     public void processDataBinding(String $binding) {
363         processDataBinding($binding, false);
364     }
365 
366     @Override
367     public void registerDataBinding(JAXXBinding binding) {
368         $bindings.put(binding.getId(), binding);
369     }
370 
371     @Override
372     public void removeDataBinding(String $binding) {
373         if (allComponentsCreated && $bindings.containsKey($binding)) {
374             getDataBinding($binding).removeDataBinding();
375         }
376     }
377 
378     /*-----------------------------------------------------------------------*/
379     /*--------------------- JAXXContext implementation  ---------------------*/
380     /*-----------------------------------------------------------------------*/
381 
382     @Override
383     public <T> T getContextValue(Class<T> clazz) {
384         return delegateContext.getContextValue(clazz, null);
385     }
386 
387     @Override
388     public <T> T getContextValue(Class<T> clazz, String name) {
389         return delegateContext.getContextValue(clazz, name);
390     }
391 
392     @Override
393     public JAXXContext getDelegateContext() {
394         return delegateContext;
395     }
396 
397     @Override
398     public <O extends Container> O getParentContainer(Class<O> clazz) {
399         return SwingUtil.getParentContainer(this, clazz);
400     }
401 
402     @Override
403     public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
404         return SwingUtil.getParentContainer(source, clazz);
405     }
406 
407     @Override
408     public <T> void removeContextValue(Class<T> clazz) {
409         delegateContext.removeContextValue(clazz, null);
410     }
411 
412     @Override
413     public <T> void removeContextValue(Class<T> clazz, String name) {
414         delegateContext.removeContextValue(clazz, name);
415     }
416 
417     @Override
418     public <T> void setContextValue(T o) {
419         delegateContext.setContextValue(o, null);
420     }
421 
422     @Override
423     public <T> void setContextValue(T o, String name) {
424         delegateContext.setContextValue(o, name);
425     }
426 
427     /*-----------------------------------------------------------------------*/
428     /*---------------------------- Event methods ----------------------------*/
429     /*-----------------------------------------------------------------------*/
430 
431     public void doKeyReleased__on__textContent(KeyEvent event) {
432         if (log.isDebugEnabled()) {
433             log.debug(event);
434         }
435         handler.setText(((JTextArea)event.getSource()).getText());
436     }
437 
438     /*-----------------------------------------------------------------------*/
439     /*----------------------- Public acessor methods  -----------------------*/
440     /*-----------------------------------------------------------------------*/
441 
442     public CommentAware getBean() {
443         return bean;
444     }
445 
446     public JXTitledPanel getCommentEditorTopPanel() {
447         return commentEditorTopPanel;
448     }
449 
450     public CommentEditorUIHandler getHandler() {
451         return handler;
452     }
453 
454     public JTextArea getTextContent() {
455         return textContent;
456     }
457 
458     /*-----------------------------------------------------------------------*/
459     /*----------------------- Public mutator methods  -----------------------*/
460     /*-----------------------------------------------------------------------*/
461 
462     public void setBean(CommentAware bean) {
463         CommentAware oldValue = this.bean;
464         this.bean = bean;
465         firePropertyChange(PROPERTY_BEAN, oldValue, bean);
466     }
467 
468     /*-----------------------------------------------------------------------*/
469     /*--------------------- Protected acessors methods  ---------------------*/
470     /*-----------------------------------------------------------------------*/
471 
472     protected JScrollPane get$JScrollPane0() {
473         return $JScrollPane0;
474     }
475 
476     /*-----------------------------------------------------------------------*/
477     /*--------------------- Components creation methods ---------------------*/
478     /*-----------------------------------------------------------------------*/
479 
480     protected void addChildrenToCommentDialog() {
481         if (!allComponentsCreated) {
482             return;
483         }
484         add(commentEditorTopPanel, BorderLayout.CENTER);
485     }
486 
487     protected void addChildrenToCommentEditorTopPanel() {
488         if (!allComponentsCreated) {
489             return;
490         }
491         commentEditorTopPanel.add($JScrollPane0);
492     }
493 
494     protected void createBean() {
495         $objectMap.put("bean", bean = null);
496     }
497 
498     protected void createCommentEditorTopPanel() {
499         $objectMap.put("commentEditorTopPanel", commentEditorTopPanel = new JXTitledPanel());
500         
501         commentEditorTopPanel.setName("commentEditorTopPanel");
502         commentEditorTopPanel.setTitle(t("tutti.commentEditor.title"));
503     }
504 
505     protected CommentEditorUIHandler createHandler() {
506         return new CommentEditorUIHandler();
507     }
508 
509     protected void createTextContent() {
510         $objectMap.put("textContent", textContent = new JTextArea());
511         
512         textContent.setName("textContent");
513         textContent.setColumns(15);
514         textContent.setLineWrap(true);
515         textContent.setWrapStyleWord(true);
516         textContent.addKeyListener(JAXXUtil.getEventListener(KeyListener.class, "keyReleased", this, "doKeyReleased__on__textContent"));
517     }
518 
519     /*-----------------------------------------------------------------------*/
520     /*------------------------ Internal jaxx methods ------------------------*/
521     /*-----------------------------------------------------------------------*/
522 
523     private void $completeSetup() {
524         allComponentsCreated = true;
525         if (log.isDebugEnabled()) {
526             log.debug(this);
527         }
528         addChildrenToCommentDialog();
529         addChildrenToCommentEditorTopPanel();
530         // inline complete setup of $JScrollPane0
531         $JScrollPane0.getViewport().add(textContent);
532         // late initializer
533         commentDialog.pack();
534     }
535 
536     private void $initialize() {
537         if (allComponentsCreated) {
538             return;
539         }
540         if (log.isDebugEnabled()) {
541             log.debug(this);
542         }
543         handler.beforeInit(this);
544         $objectMap.put("commentDialog", commentDialog);
545         createBean();
546         createCommentEditorTopPanel();
547         // inline creation of $JScrollPane0
548         $objectMap.put("$JScrollPane0", $JScrollPane0 = new JScrollPane());
549         
550         $JScrollPane0.setName("$JScrollPane0");
551         createTextContent();
552         // inline creation of commentDialog
553         setName("commentDialog");
554         commentDialog.getContentPane().setLayout(new BorderLayout());
555         setUndecorated(true);
556         setAlwaysOnTop(true);
557         
558         $completeSetup();
559         handler.afterInit(this);
560     }
561 
562 }