Author: chatellier Date: 2010-11-16 15:25:11 +0000 (Tue, 16 Nov 2010) New Revision: 216 Log: Ajout d'une validation explicite du controle. Added: trunk/coser-ui/src/main/resources/icons/accept.png Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java 2010-11-16 09:32:24 UTC (rev 215) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java 2010-11-16 15:25:11 UTC (rev 216) @@ -41,8 +41,13 @@ /** serialVersionUID. */ private static final long serialVersionUID = 3693938021315541627L; + public static final String PROPERTY_VALIDATED = "validated"; + protected String comment; + /** If control has been explicitly validated. */ + protected boolean validated; + public String getComment() { return comment; } @@ -53,11 +58,22 @@ getPropertyChangeSupport().firePropertyChange("comment", oldValue, comment); } + public boolean isValidated() { + return validated; + } + + public void setValidated(boolean validated) { + boolean oldValue = this.validated; + this.validated = validated; + getPropertyChangeSupport().firePropertyChange(PROPERTY_VALIDATED, oldValue, validated); + } + public Properties toProperties() { Properties props = new Properties(); if (comment != null) { props.setProperty("control.comment", comment); } + props.setProperty("control.validated", String.valueOf(validated)); return props; } @@ -65,5 +81,8 @@ if (props.containsKey("control.comment")) { setComment(props.getProperty("control.comment")); } + if (props.containsKey("control.validated")) { + setValidated(Boolean.parseBoolean(props.getProperty("control.validated"))); + } } } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-16 09:32:24 UTC (rev 215) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-16 15:25:11 UTC (rev 216) @@ -366,11 +366,6 @@ */ public void showSelectionView() { - // verifie que les données sont toutes validée d'abord - if (!checkControlSession()) { - return; - } - // create new selection ProjectService projectService = view.getContextValue(ProjectService.class); Project project = view.getContextValue(Project.class); @@ -404,31 +399,6 @@ } /** - * Cette methode vérifie que si une session de control est en cours on - * verifie que la liste des erreurs ne contient pas d'erreur ou - * de message warning non coché. - * - * @return {@code true} if user confirm selection creation even if there is some errors - */ - protected boolean checkControlSession() { - - boolean result = true; - - // basé sur un hack, car ici, on ne sais pas ce que contient - // le panel principal - // attention, c'est du big hack ;) - if (view.getMainViewContent().getComponentCount() > 0) { - Component comp = view.getMainViewContent().getComponent(0); - if (comp instanceof ControlView) { - ControlView controlView = (ControlView)comp; - result = controlView.getHandler().checkValidationModelErrors(controlView); - } - } - - return result; - } - - /** * Show selection view to open selection. * * @param selectionName selection name to open Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java 2010-11-16 09:32:24 UTC (rev 215) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/SelectionsListMenuItem.java 2010-11-16 15:25:11 UTC (rev 216) @@ -40,6 +40,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import fr.ifremer.coser.bean.Control; import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.bean.Selection; @@ -76,9 +77,11 @@ public void setProject(Project project) { if (this.project != null) { this.project.removePropertyChangeListener(Project.PROPERTY_SELECTIONS, this); + this.project.getControl().removePropertyChangeListener(Control.PROPERTY_VALIDATED, this); } this.project = project; this.project.addPropertyChangeListener(Project.PROPERTY_SELECTIONS, this); + this.project.getControl().addPropertyChangeListener(Control.PROPERTY_VALIDATED, this); updateMenuContent(); } @@ -91,33 +94,41 @@ if (project != null) { - Map<String, Selection> selections = project.getSelections(); - - if (selections == null || selections.isEmpty()) { - JMenuItem menuItem = new JMenuItem(_("coser.ui.mainframe.menu.data.noSelection")); + if (!project.getControl().isValidated()) { + JMenuItem menuItem = new JMenuItem(_("coser.ui.mainframe.menu.data.noValidation")); menuItem.setFont(menuItem.getFont().deriveFont(Font.ITALIC)); menuItem.setEnabled(false); add(menuItem); } else { - for (String selectionName : selections.keySet()) { - // new selection - JMenuItem menuItem = new JMenuItem(selectionName); - menuItem.setActionCommand(selectionName); - menuItem.addActionListener(this); + Map<String, Selection> selections = project.getSelections(); + + if (selections == null || selections.isEmpty()) { + JMenuItem menuItem = new JMenuItem(_("coser.ui.mainframe.menu.data.noSelection")); + menuItem.setFont(menuItem.getFont().deriveFont(Font.ITALIC)); + menuItem.setEnabled(false); add(menuItem); } + else { + for (String selectionName : selections.keySet()) { + // new selection + JMenuItem menuItem = new JMenuItem(selectionName); + menuItem.setActionCommand(selectionName); + menuItem.addActionListener(this); + add(menuItem); + } + } + + // seperator + add(new JSeparator()); + + // new selection + JMenuItem menuItem = new JMenuItem(_("coser.ui.mainframe.menu.data.newSelection")); + menuItem.setActionCommand(""); // peut pas etre null, c'est nul ! + menuItem.addActionListener(this); + add(menuItem); } - - // seperator - add(new JSeparator()); } - - // new selection - JMenuItem menuItem = new JMenuItem(_("coser.ui.mainframe.menu.data.newSelection")); - menuItem.setActionCommand(""); // peut pas etre null, c'est nul ! - menuItem.addActionListener(this); - add(menuItem); } /* @@ -141,6 +152,9 @@ */ @Override public void propertyChange(PropertyChangeEvent evt) { + + // quand la liste de selection change + // ou la validation du controle updateMenuContent(); } } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-16 09:32:24 UTC (rev 215) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-16 15:25:11 UTC (rev 216) @@ -68,7 +68,6 @@ import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserConstants.ValidationLevel; import fr.ifremer.coser.CoserException; -import fr.ifremer.coser.bean.Control; import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.control.ValidationError; import fr.ifremer.coser.data.AbstractDataEntity; @@ -193,6 +192,10 @@ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { + + // disableValidAction + disableValidAction(controlView); + Project project = controlView.getContextValue(Project.class); ProjectService projectService = controlView.getContextValue(ProjectService.class); Category category = (Category)controlView.getCategoryComboBox().getSelectedItem(); @@ -346,7 +349,7 @@ errorFound = true; } } - view.getSaveButton().setEnabled(true); + view.setCanValidControl(!errorFound); } catch (Exception ex) { throw new CoserException("Can't validate data", ex); } @@ -687,64 +690,6 @@ } /** - * Verifie que le modele ne contient pas d'erreur (error/fatal) et - * demande à l'utilisateur s'il confirme vouloir sauver lorsque des warning - * ont été trouvé. - * - * La liste peut être vide, soit parce que le check global n'a pas été - * lancé, soit parce qu'il n'y a réelement pas d'erreur. - * - * @param controlView view - * @return {@code true} if should perform save - */ - public boolean checkValidationModelErrors(ControlView controlView) { - GlobalValidationModel model = controlView.getGlobalValidationModel(); - controlView.getControlDataTableSelectionModel().clearSelection(); - - int errorFound = 0; - int nonCheckedWarningFound = 0; - - int groupCount = model.getChildCount(model.getRoot()); - for (int indexGroup = 0 ; indexGroup < groupCount ; ++indexGroup) { - Object group = model.getChild(model.getRoot(), indexGroup); - - int childCount = model.getChildCount(group); - for (int indexChild = 0 ; indexChild < childCount ; ++indexChild) { - ValidationError validationError = (ValidationError)model.getChild(group, indexChild); - if (validationError.getLevel() == ValidationLevel.ERROR || - validationError.getLevel() == ValidationLevel.FATAL) { - errorFound++; - } - else if (validationError.getLevel() == ValidationLevel.WARNING) { - - // on verifie que le warning est coché ou pas - Boolean checked = (Boolean)model.getValueAt(validationError, 1); - if (!checked) { - nonCheckedWarningFound++; - } - } - } - } - - boolean perform = true; - if (errorFound > 0) { - int response = JOptionPane.showConfirmDialog(controlView, _("coser.ui.control.check.containsError"), - _("coser.ui.control.check.title"), JOptionPane.ERROR_MESSAGE, JOptionPane.YES_NO_OPTION); - if (response == JOptionPane.NO_OPTION) { - perform = false; - } - } - else if (nonCheckedWarningFound > 0) { - int response = JOptionPane.showConfirmDialog(controlView, _("coser.ui.control.check.containsUncheckedWarning", nonCheckedWarningFound), - _("coser.ui.control.check.title"), JOptionPane.WARNING_MESSAGE, JOptionPane.YES_NO_OPTION); - if (response == JOptionPane.NO_OPTION) { - perform = false; - } - } - return perform; - } - - /** * Display data graph, initialized with graph for first specy * selected in specyComboModel. * @@ -796,6 +741,9 @@ */ public void validDataModification(ControlView view) { + // disable valid button + disableValidAction(view); + Project project = view.getContextValue(Project.class); JTable controlDataTable = view.getControlDataTable(); ControlDataTableModel model = (ControlDataTableModel)controlDataTable.getModel(); @@ -849,9 +797,12 @@ */ public void deleteData(ControlView view) { int response = JOptionPane.showConfirmDialog(view, _("coser.ui.control.confirmDeletionMessage"), - _("coser.ui.control.confirmDeletionTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); + _("coser.ui.control.confirmDeletionTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response == JOptionPane.YES_OPTION) { + // disableValidAction + disableValidAction(view); + Project project = view.getContextValue(Project.class); ProjectService projectService = view.getContextValue(ProjectService.class); @@ -871,4 +822,26 @@ } } } + + /** + * Desactive le bouton de validation du control. Positionne également + * le flag "validated" du control a false, pour cohérence, binding et + * en cas de sauvegarde par l'utilisateur. + */ + protected void disableValidAction(ControlView view) { + Project project = view.getContextValue(Project.class); + project.getControl().setValidated(false); + view.setCanValidControl(false); + } + + /** + * Set validated control flag to true and save control. + * + * @param view view + */ + public void validControl(ControlView view) { + Project project = view.getContextValue(Project.class); + project.getControl().setValidated(true); + saveControl(view); + } } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-11-16 09:32:24 UTC (rev 215) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-11-16 15:25:11 UTC (rev 216) @@ -36,12 +36,12 @@ <ControlHandler id="handler" javaBean="null" /> <fr.ifremer.coser.bean.Control id="control" javaBean="null" /> + <Boolean id="canValidControl" javaBean="false" /> <row> <cell fill="horizontal" insets="0" anchor="west" columns="2"> <JToolBar floatable="false"> - <JButton id="saveButton" icon="disk.png" - text="coser.ui.control.save" enabled="false" + <JButton icon="disk.png" text="coser.ui.control.save" onActionPerformed="getHandler().saveControl(this)" /> <JToolBar.Separator /> <JLabel text="coser.ui.control.categorylabel" /> @@ -57,6 +57,10 @@ onActionPerformed="getHandler().displayCompareNumberCatchGraph(this)"/> <JButton icon="chart_bar.png" text="coser.ui.graph.lengthStructure" onActionPerformed="getHandler().displayLengthStructureGraph(this)"/> + <JToolBar.Separator /> + <JButton icon="accept.png" onActionPerformed="getHandler().validControl(this)" + text="coser.ui.control.validcontrol" toolTipText="coser.ui.control.validcontroltip" + enabled="{isCanValidControl()}"/> </JToolBar> </cell> </row> @@ -142,8 +146,8 @@ <JScrollPane constraints="BorderLayout.CENTER"> <JTextArea id="controlComment" rows="3" text="{getControl().getComment()}" /> <javax.swing.text.Document javaBean="controlComment.getDocument()" - onInsertUpdate='getControl().setComment(controlComment.getText()); saveButton.setEnabled(true)' - onRemoveUpdate='getControl().setComment(controlComment.getText()); saveButton.setEnabled(true)' /> + onInsertUpdate='getControl().setComment(controlComment.getText())' + onRemoveUpdate='getControl().setComment(controlComment.getText())' /> </JScrollPane> </JPanel> </JSplitPane> Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties =================================================================== --- trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties 2010-11-16 09:32:24 UTC (rev 215) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties 2010-11-16 15:25:11 UTC (rev 216) @@ -46,6 +46,8 @@ coser.ui.control.replace.replace=Replace \: coser.ui.control.replace.title=Find and replace coser.ui.control.save=Save +coser.ui.control.validcontrol= +coser.ui.control.validcontroltip= coser.ui.error.htmlmessage=An error occurs \: %s coser.ui.error.title=Global application error coser.ui.graph.compareNumberCatchSize= @@ -55,6 +57,7 @@ coser.ui.mainframe.menu.data.control=Control coser.ui.mainframe.menu.data.newSelection=New selection coser.ui.mainframe.menu.data.noSelection=No selection +coser.ui.mainframe.menu.data.noValidation= coser.ui.mainframe.menu.data.selection=S\u00E9lection coser.ui.mainframe.menu.file=File coser.ui.mainframe.menu.locale.fr=Fran\u00E7ais Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties =================================================================== --- trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties 2010-11-16 09:32:24 UTC (rev 215) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties 2010-11-16 15:25:11 UTC (rev 216) @@ -46,6 +46,8 @@ coser.ui.control.replace.replace=Remplacer \: coser.ui.control.replace.title=Chercher et remplacer coser.ui.control.save=Sauvegarder +coser.ui.control.validcontrol=Valider le contr\u00F4le +coser.ui.control.validcontroltip=Marque le contr\u00F4le comme valid\u00E9. Ne peut \u00EAtre effectu\u00E9 qu'apr\u00E8s une v\u00E9rification des donn\u00E9es termin\u00E9e sans erreurs. coser.ui.error.htmlmessage=Une erreur s'est produite \: %s coser.ui.error.title=Erreur globale coser.ui.graph.compareNumberCatchSize=Comparaison Captures/Tailles @@ -55,7 +57,8 @@ coser.ui.mainframe.menu.data.control=Contr\u00F4le coser.ui.mainframe.menu.data.newSelection=Nouvelle s\u00E9lection coser.ui.mainframe.menu.data.noSelection=Aucune s\u00E9lection -coser.ui.mainframe.menu.data.selection=S\u00E9lection +coser.ui.mainframe.menu.data.noValidation=Contr\u00F4le non valid\u00E9 +coser.ui.mainframe.menu.data.selection=S\u00E9lections coser.ui.mainframe.menu.file=Fichier coser.ui.mainframe.menu.locale.fr=Fran\u00E7ais coser.ui.mainframe.menu.locale.uk=English Added: trunk/coser-ui/src/main/resources/icons/accept.png =================================================================== (Binary files differ) Property changes on: trunk/coser-ui/src/main/resources/icons/accept.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream