Author: chatellier Date: 2009-06-02 14:21:12 +0000 (Tue, 02 Jun 2009) New Revision: 2306 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/GearUI.jaxx isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputSaveVerifier.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/OpenMapEvents.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyTabUI.jaxx isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyUI.jaxx Log: Update cancel refreshAll UI. Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/GearUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/GearUI.jaxx 2009-06-02 14:14:55 UTC (rev 2305) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/GearUI.jaxx 2009-06-02 14:21:12 UTC (rev 2306) @@ -15,7 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ --> + *##%*/ +--> <fr.ifremer.isisfish.ui.input.InputContentUI> <script><![CDATA[ Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputSaveVerifier.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputSaveVerifier.java 2009-06-02 14:14:55 UTC (rev 2305) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputSaveVerifier.java 2009-06-02 14:21:12 UTC (rev 2306) @@ -41,9 +41,6 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; -import jaxx.runtime.JAXXAction; -import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXInitialContext; import jaxx.runtime.swing.ErrorDialogUI; import jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode; @@ -69,14 +66,18 @@ * Last update: $Date: 2008-08-28 10:21:07 +0200 (jeu, 28 aoû 2008) $ * by : $Author: sletellier $ */ -public class InputSaveVerifier implements JAXXAction, SaveVerifier { +public class InputSaveVerifier implements SaveVerifier { /** Class logger. */ - private static Log log = LogFactory.getLog(InputAction.class); - + private static Log log = LogFactory.getLog(InputSaveVerifier.class); + + /** New button. Used to create new {@link #type} component. */ protected JButton currentNewButton = null; + /** Delete button. */ protected JButton currentDeleteButton = null; + /** Save button. */ protected JButton currentSaveButton = null; + /** Cancel button. */ protected JButton currentCancelButton = null; protected ActionListener saveListener = new ActionListener() { @@ -85,21 +86,21 @@ topiaSave(); } }; - + protected ActionListener cancelListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { topiaCancel(); } }; - + protected ActionListener newListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { topiaCreate(); } }; - + protected ActionListener deleteListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -107,6 +108,7 @@ } }; + /** Entity type for new creation. */ protected String type = null; protected boolean editable = false; @@ -116,21 +118,17 @@ protected String currentOnglet = null; protected TopiaContext isisContext = null; - protected Map<String, TopiaEntity> currentEntities = new HashMap <String, TopiaEntity>(); - protected List<InputContentUI> currentPanels = new ArrayList <InputContentUI>(); + + /** + * Map entity key to {@link TopiaEntity}. + */ + protected Map<String, TopiaEntity> currentEntities = new HashMap<String, TopiaEntity>(); + protected ArrayList<InputContentUI> currentPanels = new ArrayList<InputContentUI>(); protected InputUI rootUI; protected SensitivityTabUI sensUI; - public InputSaveVerifier() { - } - @Override - public JAXXInitialContext init(JAXXContext parentContent, Object... datas) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override public int checkEdit() { int response = JOptionPane.NO_OPTION; if (editable) { @@ -198,26 +196,34 @@ * Refresh all ui component where name match "input<entity type without * package >.*" */ - public void topiaRemove() { + protected void topiaRemove() { if (log.isTraceEnabled()) { log.trace("remove called"); } String msg = ""; try { boolean doDelete; - TopiaEntity topiaEntity = (TopiaEntity) currentNode.getJAXXContextValue(rootUI); + TopiaEntity topiaEntity = (TopiaEntity) currentNode + .getJAXXContextValue(rootUI); List<TopiaEntity> allWillBeRemoved = topiaEntity.getComposite(); if (allWillBeRemoved.size() > 0) { - String label = _("isisfish.message.delete.object", topiaEntity.toString()); + String label = _("isisfish.message.delete.object", topiaEntity + .toString()); String text = ""; for (TopiaEntity e : allWillBeRemoved) { - text += ClassUtils.getShortClassName(e.getClass()) + " - " + e.toString() + "\n"; + text += ClassUtils.getShortClassName(e.getClass()) + " - " + + e.toString() + "\n"; } - int resp = showTextAreaConfirmationMessage(null, label, text, _("isisfish.message.delete.entities"), JOptionPane.YES_NO_OPTION); + int resp = showTextAreaConfirmationMessage(null, label, text, + _("isisfish.message.delete.entities"), + JOptionPane.YES_NO_OPTION); doDelete = resp == JOptionPane.YES_OPTION; } else { - String text = _("isisfish.message.confirm.delete.object", topiaEntity.toString()); - int resp = JOptionPane.showConfirmDialog(null, text, _("isisfish.message.delete.entity"), JOptionPane.YES_NO_OPTION); + String text = _("isisfish.message.confirm.delete.object", + topiaEntity.toString()); + int resp = JOptionPane.showConfirmDialog(null, text, + _("isisfish.message.delete.entity"), + JOptionPane.YES_NO_OPTION); doDelete = resp == JOptionPane.YES_OPTION; } @@ -230,7 +236,8 @@ } } catch (Exception eee) { if (log.isErrorEnabled()) { - log.error("Can't remove entity: " + currentEntities.get(0), eee); + log.error("Can't remove entity: " + + currentEntities.get(0), eee); } ErrorDialogUI.showError(eee); } @@ -251,15 +258,17 @@ * @param option * @return user response */ - protected int showTextAreaConfirmationMessage(Component parent, String labelMessage, String textMessage, String title, int option) { + protected int showTextAreaConfirmationMessage(Component parent, + String labelMessage, String textMessage, String title, int option) { JLabel labelForMessage = new JLabel(labelMessage); JTextArea areaForMessage = new JTextArea(textMessage); areaForMessage.setEditable(false); areaForMessage.setAutoscrolls(true); JScrollPane spMessage = new JScrollPane(areaForMessage); spMessage.setPreferredSize(new Dimension(500, 100)); // don't remove popup is huge - - int response = JOptionPane.showConfirmDialog(parent, new Object[]{labelForMessage, spMessage}, title, option); + + int response = JOptionPane.showConfirmDialog(parent, new Object[] { + labelForMessage, spMessage }, title, option); return response; } @@ -302,10 +311,16 @@ } } - public void topiaSave() { + /** + * Save all non saved entities. + * + * Change registred button states. + * Commi opened topia context. + */ + protected void topiaSave() { try { noModif(); - for (TopiaEntity t : currentEntities.values()){ + for (TopiaEntity t : currentEntities.values()) { t.update(); if (log.isDebugEnabled()) { log.debug("updating : " + t); @@ -326,28 +341,34 @@ * Cancel all modification on entity (rollback), and force reload it and * refresh all ui component that name match 'type'Tab */ - public void topiaCancel() { + protected void topiaCancel() { try { noModif(); isisContext.rollbackTransaction(); Map<String, TopiaEntity> canceledEntity = new HashMap<String, TopiaEntity>(); - for (Entry<String, TopiaEntity> currentEntity : currentEntities.entrySet()) { - TopiaEntity t = isisContext.findByTopiaId(currentEntity.getValue().getTopiaId()); - - // TODO a quoi ca sert de recharger les entités ? - // desynchronise la précédente - // fix : org.hibernate.NonUniqueObjectException: a different object with the - // same identifier value was already associated with the session - //((TopiaContextImpl)isisContext).getHibernate().evict(t2); - //t.setTopiaId(null); + for (Entry<String, TopiaEntity> currentEntity : currentEntities + .entrySet()) { + TopiaEntity t = isisContext.findByTopiaId(currentEntity + .getValue().getTopiaId()); - rootUI.repaintNode(currentNode.getContextPath()); - rootUI.setTreeSelection(currentNode.getContextPath()); + // TODO a quoi ca sert de recharger les entités ? + // desynchronise la précédente + // fix : org.hibernate.NonUniqueObjectException: a different object with the + // same identifier value was already associated with the session + //((TopiaContextImpl)isisContext).getHibernate().evict(t2); + //t.setTopiaId(null); - String key = currentEntity.getKey(); - canceledEntity.put(key, t); - addCurrentEntity(t); - } + rootUI.repaintNode(currentNode.getContextPath()); + rootUI.setTreeSelection(currentNode.getContextPath()); + + String key = currentEntity.getKey(); + canceledEntity.put(key, t); + addCurrentEntity(t); + } + + // refresh all registred panel + // to discard modification in UI + refreshAll(); rootUI.setInfoText(_("isisfish.message.cancel.finished")); } catch (Exception eee) { if (log.isErrorEnabled()) { @@ -357,55 +378,98 @@ } } - protected void showMsgBox(Exception eee) { - ErrorDialogUI.showError(eee); + /** + * Display exception into jaxx error dialog component. + * + * @param e exception to display + */ + protected void showMsgBox(Exception e) { + ErrorDialogUI.showError(e); } protected void setPanelsActifs() { - if (!currentPanels.isEmpty()) { - for (InputContentUI panel : currentPanels) { - panel.setActif(editable); - } + for (InputContentUI panel : currentPanels) { + panel.setActif(editable); } } + /** + * Refresh all registred {@link InputContentUI} component. + * + * Call {@link InputContentUI#refresh()} method on each component. + */ public void refreshAll() { - for (InputContentUI panel : currentPanels) { + + // chatellier 20090602 refresh() call addCurrentPanel + // and cause ConcurentModificationException. + List<InputContentUI> panelsToRefresh = (ArrayList<InputContentUI>)currentPanels.clone(); + for (InputContentUI panel : panelsToRefresh) { panel.refresh(); panel.setActif(editable); } } + /** + * Add entity to check for modification. + * + * The verifier register to entity using {@link TopiaEntity#addPropertyChangeListener(PropertyChangeListener)}. + * So modification have to be done on current entity. + * + * To check for embedded entity, add it too. + * + * Remove all entity with key + * + * @param currentEntity entity to check + * @param key specific key (defaut to topiaId) + */ public void addCurrentEntity(TopiaEntity currentEntity, String key) { if (currentEntity != null) { editable = true; isisContext = currentEntity.getTopiaContext(); - currentEntity.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (log.isDebugEnabled()) { - log.debug("PropertyChanged : " - + evt.getPropertyName() - + " New Value : " + evt.getNewValue()); - } - topiaChanged(); - } - }); - TopiaEntity entity = getEntity(currentEntity.getClass()); - if (entity != null) { - currentEntities.remove(entity); - } + currentEntity + .addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (log.isDebugEnabled()) { + log.debug("PropertyChanged : " + + evt.getPropertyName() + + " New Value : " + evt.getNewValue()); + } + topiaChanged(); + } + }); + // chatellier 20090602 , pas sur du code suivant + // plutot ne rien faire, si une autre entite de la meme + // clé est ajoutée, elle sera ecrasée + //TopiaEntity entity = getEntity(currentEntity.getClass()); + //if (entity != null) { + // currentEntities.remove(entity); + //} + this.currentEntities.put(key, currentEntity); setPanelsActifs(); } } + /** + * Add entity to check for modification. + * + * The verifier register to entity using {@link TopiaEntity#addPropertyChangeListener(PropertyChangeListener)}. + * So modification have to be done on current entity. + * + * To check for embedded entity, add it too. + * + * Remove all entity with key + * + * @param currentEntity entity to check + */ public void addCurrentEntity(TopiaEntity currentEntity) { - if (currentEntity != null){ + if (currentEntity != null) { addCurrentEntity(currentEntity, currentEntity.getTopiaId()); } } - public void reset(){ + + public void reset() { removeAllEntity(); removeAllPanels(); this.currentCancelButton = null; @@ -415,7 +479,8 @@ this.currentOnglet = null; this.currentNode = null; } - public void removeAllEntity(){ + + public void removeAllEntity() { currentEntities.clear(); editable = false; noModif(); @@ -449,6 +514,7 @@ public void setSaveButton(JButton saveButton, Boolean listener) { if (listener) { + // TODO what is it for (remove/readd) ? saveButton.removeActionListener(saveListener); saveButton.addActionListener(saveListener); } @@ -463,6 +529,7 @@ public void setNewButton(JButton newButton, String t, Boolean listener) { if (listener) { + // TODO what is it for (remove/readd) ? newButton.removeActionListener(newListener); newButton.addActionListener(newListener); } @@ -502,13 +569,13 @@ return currentEntities.values(); } - public <E extends TopiaEntity> E getEntity(Class<E> clazz, String key){ - return (E)currentEntities.get(key); + public <E extends TopiaEntity> E getEntity(Class<E> clazz, String key) { + return (E) currentEntities.get(key); } - - public <E extends TopiaEntity> E getEntity(Class<E> clazz){ - for (TopiaEntity te : currentEntities.values()){ - if (clazz.isInstance(te)){ + + public <E extends TopiaEntity> E getEntity(Class<E> clazz) { + for (TopiaEntity te : currentEntities.values()) { + if (clazz.isInstance(te)) { return (E) te; } } @@ -543,7 +610,7 @@ this.currentNode = currentNode; } - void setRootPanel(InputUI inputUI) { + protected void setRootPanel(InputUI inputUI) { this.rootUI = inputUI; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/OpenMapEvents.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/OpenMapEvents.java 2009-06-02 14:14:55 UTC (rev 2305) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/OpenMapEvents.java 2009-06-02 14:21:12 UTC (rev 2306) @@ -20,9 +20,6 @@ import java.awt.event.MouseEvent; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import com.bbn.openmap.Layer; import com.bbn.openmap.event.MapMouseListener; import com.bbn.openmap.event.MapMouseMode; Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyTabUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyTabUI.jaxx 2009-06-02 14:14:55 UTC (rev 2305) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyTabUI.jaxx 2009-06-02 14:21:12 UTC (rev 2306) @@ -39,6 +39,10 @@ getVerifier().setNewButton(create, "Strategy"); getVerifier().setDeleteButton(remove); Strategy strategy = (Strategy)getVerifier().getEntity(Strategy.class); + + // add null before, for second to be considered as a changed event + // otherwize, setBean has no effect + setBean(null); setBean((StrategyImpl) strategy); if (getBean() != null) { Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyUI.jaxx 2009-06-02 14:14:55 UTC (rev 2305) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/StrategyUI.jaxx 2009-06-02 14:21:12 UTC (rev 2306) @@ -23,14 +23,12 @@ import fr.ifremer.isisfish.ui.sensitivity.SensitivityTabbedPaneListener; getVerifier().addCurrentPanel(this); - public void refresh() { if (isSens()){ strategyTab.addChangeListener(new SensitivityTabbedPaneListener()); } else { strategyTab.addChangeListener(new InputTabbedPaneListener()); } - getVerifier().addCurrentPanel(strategyMonthInfoUI, strategyTabUI); } ]]></script> <JPanel id='body' layout='{new BorderLayout()}'>