Author: chatellier Date: 2010-11-03 11:12:04 +0000 (Wed, 03 Nov 2010) New Revision: 152 Log: Ajout du groupement des erreurs de controle par type Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java Removed: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/control/ValidationError.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties 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/control/ValidationError.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/control/ValidationError.java 2010-11-03 10:04:10 UTC (rev 151) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/control/ValidationError.java 2010-11-03 11:12:04 UTC (rev 152) @@ -27,6 +27,7 @@ import java.io.Serializable; +import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserConstants.ValidationLevel; /** @@ -50,11 +51,14 @@ /** Message explicitant l'erreur de validation. */ protected String message; + + /** Message donnant plus de précision sur l'erreur. */ + protected String detailMessage; /** * Numero de la ligne dans le fichier CSV. * - * Peut être {@code null} si l'erreur n'est pas associéa a une ligne specifiques. + * Peut être {@code null} si l'erreur n'est pas associé à une ligne specifiques. */ protected String lineNumber; @@ -99,9 +103,27 @@ } /** + * Message donnant plus de précision sur l'erreur. + * + * @return detail message + */ + public String getDetailMessage() { + return detailMessage; + } + + /** + * Message donnant plus de précision sur l'erreur. + * + * @param detailMessage detail message + */ + public void setDetailMessage(String detailMessage) { + this.detailMessage = detailMessage; + } + + /** * Numero de la ligne dans le fichier CSV. * - * Peut être {@code null} si l'erreur n'est pas associéa a une ligne specifiques. + * Peut être {@code null} si l'erreur n'est pas associé a une ligne specifiques. * * @return line number */ @@ -112,7 +134,7 @@ /** * Numero de la ligne dans le fichier CSV. * - * Peut être {@code null} si l'erreur n'est pas associéa a une ligne specifiques. + * Peut être {@code null} si l'erreur n'est pas associé a une ligne specifiques. * * @param lineNumber line number */ Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java 2010-11-03 10:04:10 UTC (rev 151) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ValidationService.java 2010-11-03 11:12:04 UTC (rev 152) @@ -450,7 +450,8 @@ ValidationError error = new ValidationError(); error.setLevel(ValidationLevel.WARNING); error.setLineNumber(lineNumber); - error.setMessage(_("coser.business.control.error.minObservationCount", key, value)); + error.setMessage(_("coser.business.control.error.minObservationCount")); + error.setDetailMessage(_("coser.business.control.error.minObservationCountDetail", key, value)); validationErrors.add(error); } } Modified: trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties 2010-11-03 10:04:10 UTC (rev 151) +++ trunk/coser-business/src/main/resources/i18n/coser-business-en_GB.properties 2010-11-03 11:12:04 UTC (rev 152) @@ -33,6 +33,7 @@ coser.business.category.strata=Stata coser.business.control.error.duplicatedLine= coser.business.control.error.minObservationCount= +coser.business.control.error.minObservationCountDetail= coser.business.control.error.noCatchNumberWithWeight= coser.business.control.step.observation= coser.business.control.step.xworks= Modified: trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties 2010-11-03 10:04:10 UTC (rev 151) +++ trunk/coser-business/src/main/resources/i18n/coser-business-fr_FR.properties 2010-11-03 11:12:04 UTC (rev 152) @@ -32,7 +32,8 @@ coser.business.category.reftax.species=Reftax (esp\u00E8ce) coser.business.category.strata=Strates coser.business.control.error.duplicatedLine=Ligne en doublon -coser.business.control.error.minObservationCount=Nombre minimal d'observation non atteint (%s) \: %.2f +coser.business.control.error.minObservationCount=Nombre minimal d'observation non atteint +coser.business.control.error.minObservationCountDetail=Nombre minimal d'observation non atteint (%s) \: %.2f coser.business.control.error.noCatchNumberWithWeight=Poids renseign\u00E9, mais capture non pr\u00E9sente coser.business.control.step.observation=V\u00E9rification du nombre d'observation (%d%%) coser.business.control.step.xworks=Validation par lignes (%d%%) 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 10:04:10 UTC (rev 151) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-03 11:12:04 UTC (rev 152) @@ -245,6 +245,10 @@ List<ValidationError> errors = get(); view.getGlobalValidationModel().setValidationErrors(errors); + // hack parce que impossible de faire un fire + // sans que les colonnes soit redimentionnées + SwingUtil.fixTableColumnWidth(view.getValidationGlobalErrorsTable(), 1, 25); + // active le bouton de sauvegarde si la liste d'erreur // ne contient pas de message d'erreur // warning, c'est ok @@ -335,7 +339,7 @@ public void showSelectedError(ControlView view, ListSelectionEvent event) { int selectedError = view.getValidationGlobalErrorsTable().getSelectedRow(); if (selectedError != -1) { - ValidationError error = view.getGlobalValidationModel().getErrorAt(selectedError); + /*ValidationError error = view.getGlobalValidationModel().getErrorAt(selectedError); String errorLineNumber = error.getLineNumber(); // peut être null, si l'erreur ne porte pas sur un bean en particulier @@ -343,7 +347,7 @@ int errorLineIndex = view.getControlDataTableModel().getRealIndexOfLine(errorLineNumber); view.getControlDataTableSelectionModel().setSelectionInterval(errorLineIndex, errorLineIndex); scrollToVisible(view.getControlDataTable(), errorLineIndex, 0); - } + }*/ } } Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java 2010-11-03 10:04:10 UTC (rev 151) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java 2010-11-03 11:12:04 UTC (rev 152) @@ -1,105 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.ui.control; - -import static org.nuiton.i18n.I18n._; - -import java.awt.Component; - -import javax.swing.ImageIcon; -import javax.swing.JLabel; -import javax.swing.JTable; -import javax.swing.table.DefaultTableCellRenderer; - -import jaxx.runtime.validator.swing.SwingValidatorUtil; -import fr.ifremer.coser.CoserConstants.ValidationLevel; - -/** - * Renderer pour le table des erreurs globales. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class ControlValidationRenderer extends DefaultTableCellRenderer { - - /** serialVersionUID. */ - private static final long serialVersionUID = -6423364126451874968L; - - protected ImageIcon fatalIcon = null; - protected ImageIcon errorIcon = null; - protected ImageIcon warningIcon = null; - protected ImageIcon infoIcon = null; - - public ControlValidationRenderer() { - // use icon in jaxx - fatalIcon = SwingValidatorUtil.getFatalIcon(); - errorIcon = SwingValidatorUtil.getErrorIcon(); - warningIcon = SwingValidatorUtil.getWarningIcon(); - infoIcon = SwingValidatorUtil.getInfoIcon(); - } - - @Override - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { - - JLabel component = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - - ImageIcon icon = null; - String text = null; - - switch (column) { - case 0: - ValidationLevel level = (ValidationLevel)value; - switch (level) { - case FATAL: - icon = fatalIcon; - break; - case ERROR: - icon = errorIcon; - break; - case WARNING: - icon = warningIcon; - break; - case INFO: - icon = infoIcon; - break; - } - break; - case 1: - String message = (String)value; - text = _(message); - break; - } - - component.setIcon(icon); - component.setText(text); - - return component; - } - - -} Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlValidationRenderer.java 2010-11-03 11:12:04 UTC (rev 152) @@ -0,0 +1,127 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.control; + +import static org.nuiton.i18n.I18n._; + +import java.awt.Component; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeCellRenderer; + +import jaxx.runtime.validator.swing.SwingValidatorUtil; +import fr.ifremer.coser.CoserConstants.ValidationLevel; +import fr.ifremer.coser.control.ValidationError; + +/** + * Renderer pour le table des erreurs globales. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ControlValidationRenderer extends DefaultTreeCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = -6423364126451874968L; + + protected ImageIcon fatalIcon = null; + protected ImageIcon errorIcon = null; + protected ImageIcon warningIcon = null; + protected ImageIcon infoIcon = null; + + public ControlValidationRenderer() { + // use icon in jaxx + fatalIcon = SwingValidatorUtil.getFatalIcon(); + errorIcon = SwingValidatorUtil.getErrorIcon(); + warningIcon = SwingValidatorUtil.getWarningIcon(); + infoIcon = SwingValidatorUtil.getInfoIcon(); + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, + boolean sel, boolean expanded, boolean leaf, int row, + boolean hasFocus) { + + JLabel component = (JLabel)super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + + ImageIcon icon = null; + String text = null; + + if (value instanceof GlobalValidationGroup) { + GlobalValidationGroup validationErrorGroup = (GlobalValidationGroup)value; + ValidationLevel level = validationErrorGroup.getValidationLevel(); + switch (level) { + case FATAL: + icon = fatalIcon; + break; + case ERROR: + icon = errorIcon; + break; + case WARNING: + icon = warningIcon; + break; + case INFO: + icon = infoIcon; + break; + } + + String message = validationErrorGroup.getMessage(); + text = _(message); + } + else if (value instanceof ValidationError) { + ValidationError validationError = (ValidationError)value; + ValidationLevel level = validationError.getLevel(); + switch (level) { + case FATAL: + icon = fatalIcon; + break; + case ERROR: + icon = errorIcon; + break; + case WARNING: + icon = warningIcon; + break; + case INFO: + icon = infoIcon; + break; + } + + String message = validationError.getDetailMessage(); + if (message == null) { + message = validationError.getMessage(); + } + text = _(message); + } + + component.setText(text); + component.setIcon(icon); + + return component; + } +} 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 10:04:10 UTC (rev 151) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-11-03 11:12:04 UTC (rev 152) @@ -30,9 +30,7 @@ new jaxx.runtime.validator.swing.SwingValidatorMessageTableRenderer()); // global validation - SwingUtil.fixTableColumnWidth(validationGlobalErrorsTable, 0, 25); - validationGlobalErrorsTable.getRowSorter().setSortKeys(Arrays.asList(new RowSorter.SortKey(0, SortOrder.DESCENDING))); - validationGlobalErrorsTable.setDefaultRenderer(Object.class, new ControlValidationRenderer()); + SwingUtil.fixTableColumnWidth(validationGlobalErrorsTable, 1, 25); } ]]></script> @@ -52,7 +50,7 @@ </cell> </row> <row> - <cell fill="both" weightx="1" weighty="2" columns="2"> + <cell fill="both" weightx="1" weighty="1" columns="2"> <JScrollPane> <fr.ifremer.coser.ui.control.ControlDataTableModel id="controlDataTableModel" constructorParams="this" /> <JTable id='controlDataTable' model="{controlDataTableModel}" @@ -122,9 +120,9 @@ <cell fill="both" weightx="1" weighty="1"> <JScrollPane> <GlobalValidationModel id="globalValidationModel" /> - <JTable id='validationGlobalErrorsTable' model="{globalValidationModel}" - autoCreateRowSorter="true" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}"/> + <JXTreeTable id='validationGlobalErrorsTable' treeTableModel="{globalValidationModel}" + rootVisible="false" showsRootHandles="true" + treeCellRenderer="{new ControlValidationRenderer()}" /> <ListSelectionModel id="globalValidationTableSelectionModel" javaBean="validationGlobalErrorsTable.getSelectionModel()" onValueChanged="getHandler().showSelectedError(this, event)" /> Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java 2010-11-03 11:12:04 UTC (rev 152) @@ -0,0 +1,116 @@ +/* + * #%L + * + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.control; + +import fr.ifremer.coser.CoserConstants.ValidationLevel; + +/** + * Global validation group node. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class GlobalValidationGroup implements Comparable<GlobalValidationGroup> { + + protected ValidationLevel validationLevel; + + protected String message; + + /** + * @param validationLevel + * @param message + */ + public GlobalValidationGroup(ValidationLevel validationLevel, String message) { + super(); + this.validationLevel = validationLevel; + this.message = message; + } + + public ValidationLevel getValidationLevel() { + return validationLevel; + } + + public void setValidationLevel(ValidationLevel validationLevel) { + this.validationLevel = validationLevel; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + /* + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(GlobalValidationGroup o) { + int compare = o.getValidationLevel().compareTo(validationLevel); + if (compare == 0) { + compare = o.getMessage().compareTo(message); + } + return compare; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((message == null) ? 0 : message.hashCode()); + result = prime * result + ((validationLevel == null) ? 0 : validationLevel.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + GlobalValidationGroup other = (GlobalValidationGroup) obj; + if (message == null) { + if (other.message != null) { + return false; + } + } else if (!message.equals(other.message)) { + return false; + } + if (validationLevel != other.validationLevel) { + return false; + } + return true; + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationGroup.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Deleted: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java 2010-11-03 10:04:10 UTC (rev 151) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java 2010-11-03 11:12:04 UTC (rev 152) @@ -1,144 +0,0 @@ -/* - * #%L - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package fr.ifremer.coser.ui.control; - -import static org.nuiton.i18n.I18n._; - -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import fr.ifremer.coser.CoserConstants.ValidationLevel; -import fr.ifremer.coser.control.ValidationError; - -/** - * Global validation table model. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class GlobalValidationModel extends AbstractTableModel { - - /** serialVersionUID. */ - private static final long serialVersionUID = -32286733264427664L; - - protected List<ValidationError> validationErrors; - - public GlobalValidationModel() { - super(); - } - - public void setValidationErrors(List<ValidationError> validationErrors) { - this.validationErrors = validationErrors; - fireTableDataChanged(); - } - - /* - * @see javax.swing.table.TableModel#getRowCount() - */ - @Override - public int getRowCount() { - int result = 0; - if (validationErrors != null) { - result = validationErrors.size(); - } - return result; - } - - /* - * @see javax.swing.table.TableModel#getColumnCount() - */ - @Override - public int getColumnCount() { - return 2; - } - - - @Override - public String getColumnName(int columnIndex) { - - String result = null; - - switch (columnIndex) { - case 0: - result = _("coser.ui.control.global.level"); - break; - case 1: - result = _("coser.ui.control.global.message"); - break; - } - return result; - } - - @Override - public Class<?> getColumnClass(int columnIndex) { - Class<?> result = null; - - switch (columnIndex) { - case 0: - result = ValidationLevel.class; - break; - case 1: - result = String.class; - break; - } - return result; - } - - /* - * @see javax.swing.table.TableModel#getValueAt(int, int) - */ - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - - ValidationError validationError = getErrorAt(rowIndex); - - Object result = null; - - switch (columnIndex) { - case 0: - result = validationError.getLevel(); - break; - case 1: - result = validationError.getMessage(); - break; - } - return result; - } - - /** - * Get error a specified row index. - * - * @param rowIndex row index - * @return error - */ - public ValidationError getErrorAt(int rowIndex) { - ValidationError validationError = validationErrors.get(rowIndex); - return validationError; - } - -} Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalValidationModel.java 2010-11-03 11:12:04 UTC (rev 152) @@ -0,0 +1,237 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.control; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.jdesktop.swingx.treetable.AbstractTreeTableModel; + +import fr.ifremer.coser.CoserConstants.ValidationLevel; +import fr.ifremer.coser.control.ValidationError; + +/** + * Global validation table model. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class GlobalValidationModel extends AbstractTreeTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = -32286733264427664L; + + protected List<GlobalValidationGroup> validationErrorsGroups; + protected SortedMap<GlobalValidationGroup, List<ValidationError>> validationErrorsChilds; + protected Set<ValidationError> checkedValidationErrors; + + public GlobalValidationModel() { + super(1); + } + + public void setValidationErrors(List<ValidationError> validationErrors) { + getValidationErrorAsMaps(validationErrors); + modelSupport.fireNewRoot(); + } + + /** + * Convert error list to tree structure. + * + * @param validationErrors list to convert + */ + protected void getValidationErrorAsMaps(List<ValidationError> validationErrors) { + + validationErrorsChilds = new TreeMap<GlobalValidationGroup, List<ValidationError>>(); + + for (ValidationError validationError : validationErrors) { + GlobalValidationGroup group = new GlobalValidationGroup(validationError.getLevel(), validationError.getMessage()); + + List<ValidationError> childErrors = validationErrorsChilds.get(group); + if (childErrors == null) { + childErrors = new ArrayList<ValidationError>(); + } + + childErrors.add(validationError); + validationErrorsChilds.put(group, childErrors); + } + + validationErrorsGroups = new ArrayList<GlobalValidationGroup>(validationErrorsChilds.keySet()); + Collections.sort(validationErrorsGroups); + + checkedValidationErrors = new HashSet<ValidationError>(); + } + + /* + * @see javax.swing.table.TableModel#getColumnCount() + */ + @Override + public int getColumnCount() { + return 2; + } + + + @Override + public String getColumnName(int columnIndex) { + + String result = null; + + switch (columnIndex) { + case 0: + result = _("coser.ui.control.global.message"); + break; + case 1: + result = _("coser.ui.control.global.done"); + break; + } + return result; + } + + @Override + public Class<?> getColumnClass(int columnIndex) { + Class<?> result = null; + + switch (columnIndex) { + case 0: + result = ValidationLevel.class; + break; + case 1: + result = Boolean.class; + break; + } + return result; + } + + /* + * @see org.jdesktop.swingx.treetable.TreeTableModel#getValueAt(java.lang.Object, int) + */ + @Override + public Object getValueAt(Object node, int column) { + + Object result = null; + + if (node instanceof ValidationError) { + + switch (column) { + case 0: + result = node; + break; + default: + result = checkedValidationErrors.contains(node); + break; + } + } + return result; + } + + /* + * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int) + */ + @Override + public Object getChild(Object parent, int index) { + + Object result = null; + + if (parent == getRoot()) { + result = validationErrorsGroups.get(index); + } + else if (parent instanceof GlobalValidationGroup) { + List<ValidationError> childError = validationErrorsChilds.get(parent); + result = childError.get(index); + } + + return result; + } + + /* + * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object) + */ + @Override + public int getChildCount(Object parent) { + int result = 0; + + if (parent == getRoot()) { + if (validationErrorsGroups != null) { + result = validationErrorsGroups.size(); + } + } + else if (parent instanceof GlobalValidationGroup) { + List<ValidationError> childError = validationErrorsChilds.get(parent); + result = childError.size(); + } + + return result; + } + + /* + * @see javax.swing.tree.TreeModel#getIndexOfChild(java.lang.Object, java.lang.Object) + */ + @Override + public int getIndexOfChild(Object parent, Object child) { + int result = -1; + + if (parent == getRoot()) { + result = validationErrorsGroups.indexOf(child); + } + else if (parent instanceof GlobalValidationGroup) { + List<ValidationError> childError = validationErrorsChilds.get(parent); + result = childError.indexOf(child); + } + + return result; + } + + @Override + public boolean isCellEditable(Object node, int column) { + boolean result = false; + if (column == 1) { + result = true; + } + return result; + } + + @Override + public void setValueAt(Object value, Object node, int column) { + + if (node instanceof ValidationError) { + Boolean booleanValue = (Boolean)value; + ValidationError validationError = (ValidationError)node; + if (booleanValue.booleanValue()) { + checkedValidationErrors.add(validationError); + } + else { + checkedValidationErrors.remove(validationError); + } + } + } +} 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 10:04:10 UTC (rev 151) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-en_GB.properties 2010-11-03 11:12:04 UTC (rev 152) @@ -20,6 +20,7 @@ coser.ui.control.dataMenuLabel=Data menu coser.ui.control.dataMenuReplace=Replace in %s coser.ui.control.deleteLine=Delete line +coser.ui.control.global.done=\u2026 coser.ui.control.global.level=Type coser.ui.control.global.message=Message coser.ui.control.graphtitle=Graph 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 10:04:10 UTC (rev 151) +++ trunk/coser-ui/src/main/resources/i18n/coser-ui-fr_FR.properties 2010-11-03 11:12:04 UTC (rev 152) @@ -20,6 +20,7 @@ coser.ui.control.dataMenuLabel=Menu des donn\u00E9es coser.ui.control.dataMenuReplace=Remplacer dans %s coser.ui.control.deleteLine=Supprimer la ligne +coser.ui.control.global.done=\u2026 coser.ui.control.global.level=Type coser.ui.control.global.message=Message coser.ui.control.graphtitle=Graphique