View Javadoc
1   package fr.ifremer.tutti.ui.swing.content.operation.fishing;
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.referential.Caracteristic;
28  import fr.ifremer.tutti.ui.swing.content.operation.EditFishingOperationUI;
29  import fr.ifremer.tutti.ui.swing.util.TuttiUI;
30  import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
31  import java.awt.Color;
32  import java.awt.Container;
33  import java.awt.GridBagConstraints;
34  import java.awt.Insets;
35  import java.awt.event.KeyEvent;
36  import java.awt.event.KeyListener;
37  import java.awt.event.MouseEvent;
38  import java.awt.event.MouseListener;
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.JButton;
45  import javax.swing.JMenuItem;
46  import javax.swing.JPopupMenu;
47  import javax.swing.JScrollPane;
48  import javax.swing.ListSelectionModel;
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.Table;
58  import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
59  import org.apache.commons.logging.Log;
60  import org.apache.commons.logging.LogFactory;
61  import org.jdesktop.swingx.JXTable;
62  import static org.nuiton.i18n.I18n.t;
63  
64  public class VesselUseFeatureTabUI extends Table implements TuttiUI<VesselUseFeatureTabUIModel, VesselUseFeatureTabUIHandler>, JAXXObject {
65  
66      /*-----------------------------------------------------------------------*/
67      /*------------------ Constants for all public bindings ------------------*/
68      /*-----------------------------------------------------------------------*/
69  
70      public static final String BINDING_ADD_ROW_ENABLED = "addRow.enabled";
71      public static final String BINDING_NEW_ROW_KEY_ENABLED = "newRowKey.enabled";
72      public static final String BINDING_REMOVE_CARACTERISTIC_MENU_ENABLED = "removeCaracteristicMenu.enabled";
73  
74      /*-----------------------------------------------------------------------*/
75      /*------------------------- Other static fields -------------------------*/
76      /*-----------------------------------------------------------------------*/
77  
78      private static final String $jaxxObjectDescriptor = "H4sIAAAAAAAAAK1WzW8bRRSfOLHz6RaIkrRKkRIoVYvEJByKEAHaxMTg1EmrOKEROaTj3Yk96XhnmHmbbGQV8SfwJ8CdCxI3TogDZw5cEP8CQhy4VrzZdfyBN3UU1YeVNe+93/uY9/vtfv8XyVpDFo9YFFETBiAanG6s7u09rB5xDz7h1jNCgzIk+Q1lSGafTPrtcwvkzf2yC19qhS8VVEOrgAdd0StlMmHhVHJb5xyAvN4b4Vm7VGmbVyIdmjPUdlFpqN/+83fmG//r7zKERBqrG8NWFgZFdToZKZOM8IG8hpmO2ZJkQQ3LMCKoYb15d1aQzNot1uBfkq/IaJnkNDMIBuSNi7ccY8TxkQYyenOHVSVfBlI6NFQcGt7ghkIIIGgoqD3B7NRTASAYVZobBkIF9FDYurN8zq3lctfyImcQGo5guyWtY/wckGxD+VwC2Xpp2JsOsJNgAlz1j5QOsZdZN6KohbsRH27yIOx4z2EF6pgXmGEecCMsCM95AJnpCXVnJeANF3a1HT0e8JNtdfKAnwK523OrSRj3Bc6ZVjkL6Bo+ikJiElcfXkdVranIAY238XLM9xEPyHRP8jWcjwp6XfM3NyqeUVI+YoG7q7meiI6pN2rmuH+CkgOZV6ZGj5AzT0HpBCSiG3ux1YXOa9zb+Z4OkRG0w4jOyg7tk6wJ8RjItf1+Em2jKaHPtf/RxwHG1uez07//9OePxTPOTGDumVTXLsrjLmvjNgaES301IUwIQi5tMr2yT8axb9SLWA9upBRWaZmxOMz3qgunLpx+xmwdIbKjf/z8y+yT34ZJpkgmpGJ+kTn/EhmHusEpKOlH+t79uKKpkzF8vuJqwy1B28k2t05WRsCEPMLub6R03y6hOv7rv9OVH+6fTWAIK7p+rntnCtkvSE4EUgQ81o2WJKTqxKS2PPRVh/ppYkAchdIXt0WhW/Hz7bS2rxzgNj/molaH3UBg73PNmPu0xqFzfPvOsyh0GDTu0/1bJlpj4rxkVS4fC6g7v0HZcvUYEkjm7vI5gJPVmEeOFfKFcBkgY61lQmLPJIvD/R6RQJ3kgRsIqvNsc7EtBFTY9YaG09S+uhVDD5jgMEoZpkP5KzlBJMM4ze6kbzU7OXGilVaRTqRu31lY/GghCKV8hmM8sKKhJV+NsYA8aV5GeZNKbJ8Cr8aClWBTz61OatstYRvU8wgqXzJthFtj3tOaUWGAzeaarW465qIy/MycbxaURKFdK68WHqDXmFUGEmXLHjKJzCP5dqB7X7jxlfEeK92HklZKW5+W1w8q6+X1wk7p4VZqL+kaOqg1FN8p8e77wWaAL5zA7c+9ZPipaK1505S3E220EXr2Y6rKwKu/g21w4E5oeIRseO9ySZAsoJTcEXonhvngkrWC0N07e6ulAMJu9zuvJ15InP6l9V7q0ibJL7K3530eDLptFKQx99bfOdV4F1c+9BmwhaoIfCzr475EQ+45ewHMEeEl3wHH6RjTAzHccfMFCNcR4T95NzbRcgsAAA==";
79      private static final Log log = LogFactory.getLog(VesselUseFeatureTabUI.class);
80      private static final long serialVersionUID = 1L;
81  
82      /*-----------------------------------------------------------------------*/
83      /*--------------------------- Internal states ---------------------------*/
84      /*-----------------------------------------------------------------------*/
85  
86      protected List<Object> $activeBindings = new ArrayList<Object>();
87      protected Map<String, Object> $bindingSources = new HashMap<String, Object>();
88      protected final Map<String, JAXXBinding> $bindings = new TreeMap<String, JAXXBinding>();
89      protected Map<String, Object> $objectMap = new HashMap<String, Object>();
90      protected Map<?, ?> $previousValues = new HashMap<Object, Object>();
91      private boolean allComponentsCreated;
92      protected final JAXXContext delegateContext = new DefaultJAXXContext();
93  
94      /*-----------------------------------------------------------------------*/
95      /*------------------------ Protected components  ------------------------*/
96      /*-----------------------------------------------------------------------*/
97  
98      protected JButton addRow;
99      protected final VesselUseFeatureTabUIHandler handler = createHandler();
100     protected VesselUseFeatureTabUIModel model;
101     protected BeanFilterableComboBox<Caracteristic> newRowKey;
102     protected JMenuItem removeCaracteristicMenu;
103     protected JPopupMenu tablePopup;
104     protected JXTable vesselUseFeatureTable;
105 
106     /*-----------------------------------------------------------------------*/
107     /*------------------------- Private components  -------------------------*/
108     /*-----------------------------------------------------------------------*/
109 
110     private JScrollPane $JScrollPane0;
111     private VesselUseFeatureTabUI $Table0 = this;
112 
113     /*-----------------------------------------------------------------------*/
114     /*---------------------------- Constructors  ----------------------------*/
115     /*-----------------------------------------------------------------------*/
116 
117     public VesselUseFeatureTabUI(EditFishingOperationUI parentUI) {
118         TuttiUIUtil.setParentUI(this, parentUI);
119             $initialize();
120     }
121 
122     public VesselUseFeatureTabUI() {
123         $initialize();
124     }
125 
126     public VesselUseFeatureTabUI(JAXXContext parentContext) {
127         JAXXUtil.initContext(this, parentContext);
128         $initialize();
129     }
130 
131     /*-----------------------------------------------------------------------*/
132     /*--------------------------- Statics methods ---------------------------*/
133     /*-----------------------------------------------------------------------*/
134 
135     public static JAXXObjectDescriptor $getJAXXObjectDescriptor() {
136         return JAXXUtil.decodeCompressedJAXXObjectDescriptor($jaxxObjectDescriptor);
137     }
138 
139     /*-----------------------------------------------------------------------*/
140     /*---------------------- JAXXObject implementation ----------------------*/
141     /*-----------------------------------------------------------------------*/
142 
143     @Override
144     public void applyDataBinding(String $binding) {
145         if (allComponentsCreated && $bindings.containsKey($binding)) {
146             getDataBinding($binding).applyDataBinding();
147         }
148         processDataBinding($binding);
149     }
150 
151     @Override
152     public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
153         super.firePropertyChange(propertyName, oldValue, newValue);
154     }
155 
156     @Override
157     public Map<String, Object> get$objectMap() {
158         return $objectMap;
159     }
160 
161     @Override
162     public JAXXBinding getDataBinding(String bindingId) {
163         return $bindings.get(bindingId);
164     }
165 
166     @Override
167     public JAXXBinding[] getDataBindings() {
168         return $bindings.values().toArray(new JAXXBinding[$bindings.size()]);
169     }
170 
171     @Override
172     public Object getObjectById(String id) {
173         return $objectMap.get(id);
174     }
175 
176     @Override
177     public void processDataBinding(String $binding, boolean $force) {
178         if (!$force && $activeBindings.contains($binding)) { 
179             return;
180         }
181         $activeBindings.add($binding);
182         try {
183             if (allComponentsCreated && $bindings.containsKey($binding)) {
184                 getDataBinding($binding).processDataBinding();
185             }
186         } finally {
187             $activeBindings.remove($binding);
188         }
189     }
190 
191     @Override
192     public void processDataBinding(String $binding) {
193         processDataBinding($binding, false);
194     }
195 
196     @Override
197     public void registerDataBinding(JAXXBinding binding) {
198         $bindings.put(binding.getId(), binding);
199     }
200 
201     @Override
202     public void removeDataBinding(String $binding) {
203         if (allComponentsCreated && $bindings.containsKey($binding)) {
204             getDataBinding($binding).removeDataBinding();
205         }
206     }
207 
208     /*-----------------------------------------------------------------------*/
209     /*--------------------- JAXXContext implementation  ---------------------*/
210     /*-----------------------------------------------------------------------*/
211 
212     @Override
213     public <T> T getContextValue(Class<T> clazz) {
214         return delegateContext.getContextValue(clazz, null);
215     }
216 
217     @Override
218     public <T> T getContextValue(Class<T> clazz, String name) {
219         return delegateContext.getContextValue(clazz, name);
220     }
221 
222     @Override
223     public JAXXContext getDelegateContext() {
224         return delegateContext;
225     }
226 
227     @Override
228     public <O extends Container> O getParentContainer(Class<O> clazz) {
229         return SwingUtil.getParentContainer(this, clazz);
230     }
231 
232     @Override
233     public <O extends Container> O getParentContainer(Object source, Class<O> clazz) {
234         return SwingUtil.getParentContainer(source, clazz);
235     }
236 
237     @Override
238     public <T> void removeContextValue(Class<T> clazz) {
239         delegateContext.removeContextValue(clazz, null);
240     }
241 
242     @Override
243     public <T> void removeContextValue(Class<T> clazz, String name) {
244         delegateContext.removeContextValue(clazz, name);
245     }
246 
247     @Override
248     public <T> void setContextValue(T o) {
249         delegateContext.setContextValue(o, null);
250     }
251 
252     @Override
253     public <T> void setContextValue(T o, String name) {
254         delegateContext.setContextValue(o, name);
255     }
256 
257     /*-----------------------------------------------------------------------*/
258     /*---------------------------- Event methods ----------------------------*/
259     /*-----------------------------------------------------------------------*/
260 
261     public void doKeyPressed__on__vesselUseFeatureTable(KeyEvent event) {
262         if (log.isDebugEnabled()) {
263             log.debug(event);
264         }
265         handler.openRowMenu(event, tablePopup);
266     }
267 
268     public void doMouseClicked__on__vesselUseFeatureTable(MouseEvent event) {
269         if (log.isDebugEnabled()) {
270             log.debug(event);
271         }
272         handler.autoSelectRowInTable(event, tablePopup);
273     }
274 
275     /*-----------------------------------------------------------------------*/
276     /*----------------------- Public acessor methods  -----------------------*/
277     /*-----------------------------------------------------------------------*/
278 
279     public JButton getAddRow() {
280         return addRow;
281     }
282 
283     public VesselUseFeatureTabUIHandler getHandler() {
284         return handler;
285     }
286 
287     public VesselUseFeatureTabUIModel getModel() {
288         return model;
289     }
290 
291     public BeanFilterableComboBox<Caracteristic> getNewRowKey() {
292         return newRowKey;
293     }
294 
295     public JMenuItem getRemoveCaracteristicMenu() {
296         return removeCaracteristicMenu;
297     }
298 
299     public JPopupMenu getTablePopup() {
300         return tablePopup;
301     }
302 
303     public JXTable getVesselUseFeatureTable() {
304         return vesselUseFeatureTable;
305     }
306 
307     /*-----------------------------------------------------------------------*/
308     /*--------------------- Protected acessors methods  ---------------------*/
309     /*-----------------------------------------------------------------------*/
310 
311     protected JScrollPane get$JScrollPane0() {
312         return $JScrollPane0;
313     }
314 
315     /*-----------------------------------------------------------------------*/
316     /*--------------------- Components creation methods ---------------------*/
317     /*-----------------------------------------------------------------------*/
318 
319     protected void addChildrenToTablePopup() {
320         if (!allComponentsCreated) {
321             return;
322         }
323         tablePopup.add(removeCaracteristicMenu);
324     }
325 
326     protected void createAddRow() {
327         $objectMap.put("addRow", addRow = new JButton());
328         
329         addRow.setName("addRow");
330         addRow.putClientProperty("simpleAction", fr.ifremer.tutti.ui.swing.content.operation.fishing.actions.VesselUseFeatureAddRowAction.class);
331     }
332 
333     protected VesselUseFeatureTabUIHandler createHandler() {
334         return new VesselUseFeatureTabUIHandler();
335     }
336 
337     protected void createModel() {
338         $objectMap.put("model", model = getContextValue(VesselUseFeatureTabUIModel.class));
339     }
340 
341     protected void createNewRowKey() {
342         $objectMap.put("newRowKey", newRowKey = new BeanFilterableComboBox<Caracteristic>(this));
343         
344         newRowKey.setName("newRowKey");
345         newRowKey.setProperty("selectedCaracteristic");
346         newRowKey.setShowReset(true);
347     }
348 
349     protected void createRemoveCaracteristicMenu() {
350         $objectMap.put("removeCaracteristicMenu", removeCaracteristicMenu = new JMenuItem());
351         
352         removeCaracteristicMenu.setName("removeCaracteristicMenu");
353         removeCaracteristicMenu.setText(t("tutti.vesselUseFeatureTable.action.removeCaracteristic"));
354         removeCaracteristicMenu.setToolTipText(t("tutti.vesselUseFeatureTable.action.removeCaracteristic.tip"));
355         removeCaracteristicMenu.putClientProperty("simpleAction", fr.ifremer.tutti.ui.swing.content.operation.fishing.actions.VesselUseFeatureRemoveRowAction.class);
356     }
357 
358     protected void createTablePopup() {
359         $objectMap.put("tablePopup", tablePopup = new JPopupMenu());
360         
361         tablePopup.setName("tablePopup");
362     }
363 
364     protected void createVesselUseFeatureTable() {
365         $objectMap.put("vesselUseFeatureTable", vesselUseFeatureTable = new JXTable());
366         
367         vesselUseFeatureTable.setName("vesselUseFeatureTable");
368         vesselUseFeatureTable.setSortable(false);
369         vesselUseFeatureTable.addKeyListener(JAXXUtil.getEventListener(KeyListener.class, "keyPressed", this, "doKeyPressed__on__vesselUseFeatureTable"));
370         vesselUseFeatureTable.addMouseListener(JAXXUtil.getEventListener(MouseListener.class, "mouseClicked", this, "doMouseClicked__on__vesselUseFeatureTable"));
371     }
372 
373     /*-----------------------------------------------------------------------*/
374     /*------------------------ Internal jaxx methods ------------------------*/
375     /*-----------------------------------------------------------------------*/
376 
377     private void $completeSetup() {
378         allComponentsCreated = true;
379         if (log.isDebugEnabled()) {
380             log.debug(this);
381         }
382         // inline complete setup of $Table0
383         add(newRowKey, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
384         add(addRow, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
385         add($JScrollPane0, new GridBagConstraints(0, 1, 2, 1, 0.0, 1.0, 10, 1, new Insets(3, 3, 3, 3), 0, 0));
386         addChildrenToTablePopup();
387         // inline complete setup of $JScrollPane0
388         $JScrollPane0.getViewport().add(vesselUseFeatureTable);
389         
390         // apply 3 data bindings
391         JAXXUtil.applyDataBinding(this, $bindings.keySet());
392         
393         // apply 7 property setters
394         newRowKey.setBeanType(Caracteristic.class);
395         removeCaracteristicMenu.setMnemonic(SwingUtil.getFirstCharAt(t("tutti.vesselUseFeatureTable.action.removeCaracteristic.mnemonic"),'Z'));
396         removeCaracteristicMenu.setIcon(SwingUtil.createActionIcon("batch-delete"));
397         addRow.setIcon(SwingUtil.createActionIcon("add"));
398         vesselUseFeatureTable.setSelectionBackground(null);
399         vesselUseFeatureTable.setSelectionForeground(Color.BLACK);
400         vesselUseFeatureTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
401     }
402 
403     private void $initialize() {
404         if (allComponentsCreated) {
405             return;
406         }
407         if (log.isDebugEnabled()) {
408             log.debug(this);
409         }
410         handler.beforeInit(this);
411         $objectMap.put("$Table0", $Table0);
412         createModel();
413         createTablePopup();
414         createRemoveCaracteristicMenu();
415         createNewRowKey();
416         createAddRow();
417         // inline creation of $JScrollPane0
418         $objectMap.put("$JScrollPane0", $JScrollPane0 = new JScrollPane());
419         
420         $JScrollPane0.setName("$JScrollPane0");
421         createVesselUseFeatureTable();
422         // inline creation of $Table0
423         setName("$Table0");
424         
425         // registers 3 data bindings
426         $registerDefaultBindings();
427         $completeSetup();
428         handler.afterInit(this);
429     }
430 
431     private void $registerDefaultBindings() {
432         // register 3 data bindings
433         registerDataBinding(new DefaultJAXXBinding(this, BINDING_REMOVE_CARACTERISTIC_MENU_ENABLED, true) {
434         
435             @Override
436             public void applyDataBinding() {
437                 if (model != null) {
438                     model.addPropertyChangeListener("removeCaracteristicEnabled", this);
439                 }
440             }
441         
442             @Override
443             public void processDataBinding() {
444                 if (model != null) {
445                     removeCaracteristicMenu.setEnabled(model.isRemoveCaracteristicEnabled());
446                 }
447             }
448         
449             @Override
450             public void removeDataBinding() {
451                 if (model != null) {
452                     model.removePropertyChangeListener("removeCaracteristicEnabled", this);
453                 }
454             }
455         });
456         registerDataBinding(new DefaultJAXXBinding(this, BINDING_NEW_ROW_KEY_ENABLED, true) {
457         
458             @Override
459             public void applyDataBinding() {
460                 if (newRowKey != null) {
461                     newRowKey.addPropertyChangeListener("empty", this);
462                 }
463             }
464         
465             @Override
466             public void processDataBinding() {
467                 if (newRowKey != null) {
468                     newRowKey.setEnabled(!newRowKey.isEmpty());
469                 }
470             }
471         
472             @Override
473             public void removeDataBinding() {
474                 if (newRowKey != null) {
475                     newRowKey.removePropertyChangeListener("empty", this);
476                 }
477             }
478         });
479         registerDataBinding(new DefaultJAXXBinding(this, BINDING_ADD_ROW_ENABLED, true) {
480         
481             @Override
482             public void applyDataBinding() {
483                 if (newRowKey != null) {
484                     newRowKey.addPropertyChangeListener("selectedItem", this);
485                 }
486             }
487         
488             @Override
489             public void processDataBinding() {
490                 if (newRowKey != null) {
491                     addRow.setEnabled(newRowKey.getSelectedItem() != null);
492                 }
493             }
494         
495             @Override
496             public void removeDataBinding() {
497                 if (newRowKey != null) {
498                     newRowKey.removePropertyChangeListener("selectedItem", this);
499                 }
500             }
501         });
502     }
503 
504 }