Author: kmorin Date: 2013-02-07 23:26:31 +0100 (Thu, 07 Feb 2013) New Revision: 2560 Url: http://nuiton.org/projects/jaxx/repository/revisions/2560 Log: resolves #2504 Create a button to show a popup with a validation table Added: trunk/jaxx-validator/src/main/resources/icons/action-alert-error.png trunk/jaxx-validator/src/main/resources/icons/action-alert-info.png trunk/jaxx-validator/src/main/resources/icons/action-alert-none.png trunk/jaxx-validator/src/main/resources/icons/action-alert-warning.png Removed: trunk/jaxx-validator/src/main/resources/icons/action-table-error.png Modified: trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageWidget.java trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_en_GB.properties trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_es_ES.properties trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_fr_FR.properties Modified: trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageWidget.java =================================================================== --- trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageWidget.java 2013-02-07 22:08:45 UTC (rev 2559) +++ trunk/jaxx-validator/src/main/java/jaxx/runtime/validator/swing/SwingValidatorMessageWidget.java 2013-02-07 22:26:31 UTC (rev 2560) @@ -25,6 +25,8 @@ * #L% */ +import java.awt.Component; +import java.awt.Point; import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,10 +42,23 @@ import javax.swing.ListSelectionModel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.HierarchyBoundsAdapter; +import java.awt.event.HierarchyEvent; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import jaxx.runtime.swing.ComponentMover; +import jaxx.runtime.swing.ComponentResizer; +import org.jdesktop.swingx.JXTitledPanel; +import org.nuiton.validator.NuitonValidatorScope; +import static org.nuiton.i18n.I18n._; +import static org.nuiton.i18n.I18n.n_; + /** * Button which opens a popup containing a table with the errors found * by registered validators. @@ -53,7 +68,8 @@ */ public class SwingValidatorMessageWidget extends JToggleButton { - private static final Log log = LogFactory.getLog(SwingValidatorMessageWidget.class); + private static final Log log = + LogFactory.getLog(SwingValidatorMessageWidget.class); private static final long serialVersionUID = 1L; @@ -63,9 +79,60 @@ protected JTable errorTable = new JTable(); + protected Point popupPosition = null; + public SwingValidatorMessageWidget() { - super(SwingUtil.createActionIcon("table-error")); + super(SwingUtil.createActionIcon("alert-none")); + setToolTipText(_("tutti.validator.alert.none")); + errorTableModel.addTableModelListener(new TableModelListener() { + + public void tableChanged(TableModelEvent e) { + int alerts = errorTableModel.getRowCount(); + String label; + switch (alerts) { + case 0: + label = n_("validator.messageWidget.alert.none"); + break; + case 1: + label = n_("validator.messageWidget.alert.one"); + break; + default: + label = n_("validator.messageWidget.alert.several"); + } + + NuitonValidatorScope maxScope; + String icon; + if (alerts == 0) { + icon = "alert-none"; + + } else { + maxScope = NuitonValidatorScope.INFO; + for (int i = 0; i < alerts; i++) { + NuitonValidatorScope scope = errorTableModel.getRow(i).getScope(); + int diff = scope.compareTo(maxScope); + if (diff < 0) { + maxScope = scope; + } + } + switch (maxScope) { + case INFO: + icon = "alert-info"; + break; + case WARNING: + icon = "alert-warning"; + break; + default: + icon = "alert-error"; + + } + } + + setToolTipText(_(label, alerts)); + setIcon(SwingUtil.createActionIcon(icon)); + } + }); + errorTable.setModel(errorTableModel); errorTable.setRowSelectionAllowed(true); errorTable.setAutoCreateRowSorter(true); @@ -79,9 +146,41 @@ JScrollPane scrollPanel = new JScrollPane(errorTable); scrollPanel.setColumnHeaderView(errorTable.getTableHeader()); - popup.add(scrollPanel); + + JXTitledPanel titledPanel = new JXTitledPanel(_("validator.messageWidget.title"), scrollPanel); + popup.add(titledPanel); + popup.setTitle(_("validator.messageWidget.title")); popup.setSize(800, 300); + popup.setAlwaysOnTop(true); + popup.setUndecorated(true); + ComponentResizer cr = new ComponentResizer(); + cr.registerComponent(popup); + ComponentMover cm = new ComponentMover(); + cm.setDragInsets(cr.getDragInsets()); + cm.registerComponent(popup); + + popup.addWindowListener(new WindowAdapter() { + + @Override + public void windowClosing(WindowEvent e) { + setSelected(false); + } + + }); + + popup.addComponentListener(new ComponentAdapter() { + + @Override + public void componentMoved(ComponentEvent e) { + Component component = e.getComponent(); + if (component.isShowing()) { + popupPosition = component.getLocationOnScreen(); + } + } + + }); + addActionListener(new ActionListener() { @Override @@ -93,13 +192,17 @@ } } }); - popup.addWindowListener(new WindowAdapter() { + addHierarchyBoundsListener(new HierarchyBoundsAdapter() { + @Override - public void windowClosing(WindowEvent e) { - setSelected(false); + public void ancestorMoved(HierarchyEvent e) { + if (popupPosition == null && isShowing()) { + Point point = new Point(getLocationOnScreen()); + point.translate(-popup.getWidth() + getWidth(), -popup.getHeight()); + popup.setLocation(point); + } } - }); // add a auto-close action @@ -118,14 +221,23 @@ setSelected(false); } }); + } + /** + * Registers a validator. + * + * @param validator + */ public void registerValidator(SwingValidator validator) { errorTableModel.registerValidator(validator); + validator.reloadBean(); } + /** Clears all the validators. */ public void clearValidators() { errorTableModel.clearValidators(); + errorTableModel.clear(); } } Modified: trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_en_GB.properties =================================================================== --- trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_en_GB.properties 2013-02-07 22:08:45 UTC (rev 2559) +++ trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_en_GB.properties 2013-02-07 22:26:31 UTC (rev 2560) @@ -1,3 +1,4 @@ +tutti.validator.alert.none= validator.bean.header=Object validator.bean.header.tip=Object on which message occurs validator.bean.tip= @@ -7,6 +8,10 @@ validator.message.header=Message validator.message.header.tip=Message validator.message.tip=Message \: %1$s +validator.messageWidget.alert.none=No report +validator.messageWidget.alert.one=1 report +validator.messageWidget.alert.several=%s reports +validator.messageWidget.title=Control report validator.scope.header=... validator.scope.header.tip=Severity of the message validator.scope.tip=Message scope \: '%1$s' Modified: trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_es_ES.properties =================================================================== --- trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_es_ES.properties 2013-02-07 22:08:45 UTC (rev 2559) +++ trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_es_ES.properties 2013-02-07 22:26:31 UTC (rev 2560) @@ -1,3 +1,4 @@ +tutti.validator.alert.none= validator.bean.header= validator.bean.header.tip= validator.bean.tip= @@ -7,6 +8,10 @@ validator.message.header=Mensaje validator.message.header.tip=El texto del mensaje validator.message.tip=Mensaje \: %1$s +validator.messageWidget.alert.none=No alertar +validator.messageWidget.alert.one=1 alertar +validator.messageWidget.alert.several=%s alertas +validator.messageWidget.title=Informe de prueba validator.row.header= validator.row.header.tip= validator.row.tip= Modified: trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_fr_FR.properties =================================================================== --- trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_fr_FR.properties 2013-02-07 22:08:45 UTC (rev 2559) +++ trunk/jaxx-validator/src/main/resources/i18n/jaxx-validator_fr_FR.properties 2013-02-07 22:26:31 UTC (rev 2560) @@ -1,3 +1,4 @@ +tutti.validator.alert.none= validator.bean.header=Objet validator.bean.header.tip=L'objet validator.bean.tip= @@ -7,6 +8,10 @@ validator.message.header=Message validator.message.header.tip=Le texte du message validator.message.tip=Message \: %1$s +validator.messageWidget.alert.none=Aucune alerte +validator.messageWidget.alert.one=1 alerte +validator.messageWidget.alert.several=%s alertes +validator.messageWidget.title=Rapport de contrôles validator.scope.header=... validator.scope.header.tip=Le type de message validator.scope.tip=Type de message \: '%1$s' Added: trunk/jaxx-validator/src/main/resources/icons/action-alert-error.png =================================================================== (Binary files differ) Property changes on: trunk/jaxx-validator/src/main/resources/icons/action-alert-error.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jaxx-validator/src/main/resources/icons/action-alert-info.png =================================================================== (Binary files differ) Property changes on: trunk/jaxx-validator/src/main/resources/icons/action-alert-info.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jaxx-validator/src/main/resources/icons/action-alert-none.png =================================================================== (Binary files differ) Property changes on: trunk/jaxx-validator/src/main/resources/icons/action-alert-none.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jaxx-validator/src/main/resources/icons/action-alert-warning.png =================================================================== (Binary files differ) Property changes on: trunk/jaxx-validator/src/main/resources/icons/action-alert-warning.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: trunk/jaxx-validator/src/main/resources/icons/action-table-error.png =================================================================== (Binary files differ)
participants (1)
-
kmorin@users.nuiton.org