Author: chatellier Date: 2010-11-04 09:47:44 +0000 (Thu, 04 Nov 2010) New Revision: 161 Log: Ajout d'un check (avec messages d'avertissement) si l'on tente de creer une selection avec des erreurs et warning encore pr?\195?\169sents Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.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-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-03 16:11:15 UTC (rev 160) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-04 09:47:44 UTC (rev 161) @@ -119,12 +119,21 @@ setMainComponent(projectOpenView); } - public void setMainComponent(Component component) { + /** + * Replace window main component. + * + * @param component new component + */ + protected void setMainComponent(Component component) { view.getMainViewContent().removeAll(); view.getMainViewContent().add(component, BorderLayout.CENTER); view.getMainViewContent().validate(); } + /** + * Exit application. + * + */ public void quit() { System.exit(0); } @@ -358,7 +367,7 @@ if (reloadData) { project = projectService.loadControlData(project); } - + ControlView controlView = new ControlView(view); controlView.setHandler(new ControlHandler()); setMainComponent(controlView); @@ -371,7 +380,12 @@ * Show selection view to create new selection. */ 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); @@ -394,7 +408,7 @@ ImageIcon icon = new ImageIcon(file.toURI().toURL()); selectionView.getSelectionDetailsTab().getZonesMap().setIcon(icon); - } catch(Exception e){ + } catch(Exception e) { e.printStackTrace(); }; setMainComponent(selectionView); @@ -406,6 +420,29 @@ } /** + * 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 = false; + + // basé sur un hack, car ici, on ne sais pas ce que contient + // le panel principal + // attention, c'est du big hack ;) + 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 @@ -439,8 +476,10 @@ } /** + * Called by {@link LookAndFeelViewMenuItem} when look and feel selection + * change. * - * @param event + * @param event change event */ public void saveLookAndFeelConfiguration(PropertyChangeEvent event) { if (event.getPropertyName().equals(LookAndFeelViewMenuItem.PROPERTY_LOOK_AND_FEEL)) { 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-03 16:11:15 UTC (rev 160) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-04 09:47:44 UTC (rev 161) @@ -338,9 +338,7 @@ errorFound = true; } } - if (!errorFound) { - view.getSaveButton().setEnabled(true); - } + view.getSaveButton().setEnabled(true); } catch (Exception ex) { throw new CoserException("Can't validate data", ex); } @@ -582,8 +580,12 @@ String headerValue = header[fieldIndex]; String fieldValue = line[fieldIndex]; - final String beanFieldName = Introspector.decapitalize(enHeaders[fieldIndex - 1]); + String beanFieldName = Introspector.decapitalize(enHeaders[fieldIndex - 1]); + // l'ui ne peut utiliser les getter/setter que sur les champs + // xxxAsString + final String stringBeanFieldName = beanFieldName + "AsString"; + JLabel label = new JLabel(headerValue + "\u2009:"); final JTextField fieldTextField = new JTextField(fieldValue); fieldTextField.getDocument().addDocumentListener(new DocumentListener() { @@ -604,10 +606,10 @@ protected void valueChanged(DocumentEvent event) { try { - PropertyUtils.setProperty(finalBean, beanFieldName, fieldTextField.getText()); + PropertyUtils.setProperty(finalBean, stringBeanFieldName, fieldTextField.getText()); } catch (Exception ex) { if (log.isErrorEnabled()) { - log.error("Can't set property value (" + beanFieldName + ")", ex); + log.error("Can't set property value (" + stringBeanFieldName + ")", ex); } } } @@ -620,7 +622,11 @@ GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( 1, 1, 1, 1), 0, 0)); + // permet de dire a jaxx que les erreurs sur les + // champs d'origine, et les champs string pointent sur le + // même composant validator.setFieldRepresentation(beanFieldName, fieldTextField); + validator.setFieldRepresentation(stringBeanFieldName, fieldTextField); } validator.installUIs(); @@ -649,12 +655,16 @@ /** * Save project after control. * + * Can't save if : + * - validation contains error + * - validation contains non checked warning + * * @param view view */ public void saveControl(ControlView view) { Project project = view.getContextValue(Project.class); ProjectService service = view.getContextValue(ProjectService.class); - + try { long before = System.currentTimeMillis(); service.saveProjectControl(project); @@ -669,8 +679,67 @@ } /** - * Display data graph. + * 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. + * * @param view view */ public void displayGraph(ControlView 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-03 16:11:15 UTC (rev 160) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-11-04 09:47:44 UTC (rev 161) @@ -95,8 +95,7 @@ </JScrollPane> </cell> <cell fill="both" weightx="1" weighty="1"> - <jaxx.runtime.validator.swing.SwingValidatorMessageTableModel id='errorsTableModel' - onTableChanged='saveButton.setEnabled(errorsTableModel.getRowCount()==0)'/> + <jaxx.runtime.validator.swing.SwingValidatorMessageTableModel id='errorsTableModel' /> <fr.ifremer.coser.data.Catch id="beanCatch" javaBean="null" /> <fr.ifremer.coser.data.Haul id="beanHaul" javaBean="null" /> <fr.ifremer.coser.data.Strata id="beanStrata" javaBean="null" /> 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-03 16:11:15 UTC (rev 160) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties 2010-11-04 09:47:44 UTC (rev 161) @@ -14,6 +14,9 @@ coser.ui.common.unselectAll=None coser.ui.common.valid=Valid coser.ui.config.title=Configuration +coser.ui.control.check.containsError= +coser.ui.control.check.containsUncheckedWarning= +coser.ui.control.check.title= coser.ui.control.confirmDeletionMessage=Are you sure you want to delete this data ? coser.ui.control.confirmDeletionTitle=Confirm delete coser.ui.control.confirmDeletionsMessage=Are you sure you want to delete %d selected lines ? 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-03 16:11:15 UTC (rev 160) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties 2010-11-04 09:47:44 UTC (rev 161) @@ -14,13 +14,16 @@ coser.ui.common.unselectAll=Aucun coser.ui.common.valid=Valider coser.ui.config.title=Configuration +coser.ui.control.check.containsError=Les donn\u00E9es contiennent encore des erreurs non corrig\u00E9es\npouvant fausser la cr\u00E9ation de la s\u00E9lection.\nVoulez vous poursuivre la cr\u00E9ation de la s\u00E9lection ? +coser.ui.control.check.containsUncheckedWarning=Les donn\u00E9es contiennent encore %d avertissements non coch\uFFFDs pouvant fausser la cr\u00E9ation de la selection.\nVoulez vous poursuivre la cr\u00E9ation de la s\u00E9lection ? +coser.ui.control.check.title=V\u00E9rification des erreurs coser.ui.control.confirmDeletionMessage=\u00CAtes vous s\u00FBr de vouloir supprimer cette donn\u00E9e ? coser.ui.control.confirmDeletionTitle=Confirmation de suppression coser.ui.control.confirmDeletionsMessage=\u00CAtes vous s\u00FBr de vouloir supprimer les %d lignes s\u00E9lectionn\u00E9es ? coser.ui.control.dataMenuDeleteSelected=Supprimer les lignes s\u00E9lectionn\u00E9es coser.ui.control.dataMenuLabel=Menu des donn\u00E9es coser.ui.control.dataMenuReplace=Remplacer dans %s pour la s\u00E9lection -coser.ui.control.dataMenuReplaceAll=Replacer dans %s pour toutes les lignes +coser.ui.control.dataMenuReplaceAll=Remplacer dans %s pour toutes les lignes coser.ui.control.deleteLine=Supprimer la ligne coser.ui.control.global.done=\u2026 coser.ui.control.global.message=Message