From 2b8d24a9c1a77c02d4e015fc33f8aca1916b066e Mon Sep 17 00:00:00 2001 From: gpawel <gpawel> Date: Wed, 4 May 2011 09:08:39 +0000 Subject: [PATCH] [LMS-2227] DSS Swing Uploader: improvement of validation handling SVN: 21128 --- datastore_server/.classpath | 1 + datastore_server/build/build.xml | 5 + datastore_server/resource/ok.png | Bin 0 -> 400 bytes datastore_server/resource/wait.gif | Bin 0 -> 673 bytes datastore_server/resource/wrong.png | Bin 0 -> 256 bytes .../client/api/gui/DataSetMetadataPanel.java | 97 ++++++---- .../api/gui/DataSetUploadClientModel.java | 2 +- .../client/api/gui/ErrorMessageDialog.java | 148 +++++++++++++++ .../dss/client/api/gui/ErrorsPanel.java | 171 ++++++++++++++++++ .../dss/client/api/gui/UiUtilities.java | 14 +- 10 files changed, 393 insertions(+), 45 deletions(-) create mode 100644 datastore_server/resource/ok.png create mode 100644 datastore_server/resource/wait.gif create mode 100644 datastore_server/resource/wrong.png create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorMessageDialog.java create mode 100644 datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorsPanel.java diff --git a/datastore_server/.classpath b/datastore_server/.classpath index 8027142a2ec..6f8cb8ff036 100644 --- a/datastore_server/.classpath +++ b/datastore_server/.classpath @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="source/java"/> + <classpathentry kind="src" path="resource"/> <classpathentry kind="src" path="sourceTest/java"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="lib" path="/libraries/jython/standalone/jython.jar" sourcepath="/Users/gpawel/Downloads/jython_installer-2.2.1.jar"/> diff --git a/datastore_server/build/build.xml b/datastore_server/build/build.xml index 1d1e0d2de31..4a0833783ea 100644 --- a/datastore_server/build/build.xml +++ b/datastore_server/build/build.xml @@ -314,6 +314,11 @@ <include name="ch/systemsx/cisd/openbis/dss/generic/shared/api/**/*.class" /> <include name="org/python/core/SyspathArchiveHack.class" /> <include name="${build.info.filename}" /> + </fileset> + <fileset dir="resource"> + <include name="wait.gif" /> + <include name="wrong.png" /> + <include name="ok.png" /> </fileset> <manifest> <attribute name="Main-Class" value="ch.systemsx.cisd.openbis.dss.client.api.gui.DataSetUploadClient" /> diff --git a/datastore_server/resource/ok.png b/datastore_server/resource/ok.png new file mode 100644 index 0000000000000000000000000000000000000000..37f668e270eb93778f13a53f52eff954c1938382 GIT binary patch literal 400 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmSN`?>!lvI6;x#X;^) z4C~IxyaaL-l0AZa85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YPV z+ueoXKL{?^yL>WGgtNdSvY3H^TNs2H8D`Cq017_$ba4!^I6e1*p}upX#L<uOOT(4a zv{%n<S;@V*KS^<4n}5LOgDFCb&nHaTkl~fTwKq)pmWg@)(j`}p?oF@yyzhDayw7%` zsaKE9zFqX;#IAWCa&}wDWU(DO;V4-V?k-`a&6mDyiIaQyW{W*4qCtu(uGy1M*>DM0 ze{SoPT^rBz>y^}@?$7gi*Xw<4U6^cWzW0@5M(57$`MO#2mK|%{l~Z-U_)*-8+vlCN zjTN`VO5YAJ6%?DfE+;hg*iTpP`O8_d%~bt*RgO8erMg!Z{JSQtcZc)r{(tk9YnN=@ myF;_N-Xv0x?=<_L;P+N4(Jy9w4Lk|-GJ~h9pUXO@geCz0!<Wwh literal 0 HcmV?d00001 diff --git a/datastore_server/resource/wait.gif b/datastore_server/resource/wait.gif new file mode 100644 index 0000000000000000000000000000000000000000..d0bce1542342e912da81a2c260562df172f30d73 GIT binary patch literal 673 zcmZ?wbhEHb6krfw_{6~Q|Nnmm28Kh24mmkF0U1e2Nli^nlO|14{Lk&@8WQa67~pE8 zXTZz|lvDgC<y@4SSdyBeP@Y+mp^%uBSdo*Tn4*`NmzK|<_>+Z`3#dv5h=E26FfcG1 zbL_hF&)}42ws10s6^G;;cE1^EoUR)U5A70}d2pLv!jVIT7j&Z~EblI3x0K*v_sV|m z0kj3v921Z^em#l`(k(o@H$3ZdDRc@9NidXDNbqrumReCGv$gd8+e8WW28HVqkJ_9i zH>s*<31KtHjANIPvi2#*6BEu%3Dak5O_t&NBI)<h(<yPr>H?V$TxT}#l{vOTn<?_G z_#ejR!~8}oQ>5naXTfF^&~Hhq+NX@#Ccc>y7T?;vjI&jdhsDsPJyAw*m0Qz>i}K7# zL9w50<qa%!r20=RDYEpz>Ng{fT}A5JUe8lRK1h7_Y2;BWJDd=c6f&i?Wv5(5q?6|P zQw{>maxZP<537OA37Uk}7@%_$4o$EWe_Zl>&#id|lE-BpDC#+Fn|msJ%_2h{Hg1vP z#N8WAzfWasG}yq|xqE)DrWaOofX=z|?*pgc%{ig5vl!pqDlC|q&~Z0$&Rvsft&VO- z4MZj+%-+Vx%W}v;V76hyp=;+R;x+~t^Q%*xuFTQAF2})fSfTHDAs>sO!OBw`)&)o$ c0!CNZt))x~rAZP^^P&YOFfdqy5)K#u0POD40{{R3 literal 0 HcmV?d00001 diff --git a/datastore_server/resource/wrong.png b/datastore_server/resource/wrong.png new file mode 100644 index 0000000000000000000000000000000000000000..0b30e99e6b85076f897e60cad458af39309e87d3 GIT binary patch literal 256 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt^zJzX3_ zEP8t<8FC#q;Bl2-I$@=Ao1Eel9>tOuf2Z?Fa-9u$!E2OqinmUD<}8J1!-@@0zq9;f zif-DyKsBOib;6B!JC@lGLMKc75nR(`_<j#(%I&Es1y$R*s#w-KYI({;G%bHHNlrvn zaZc$+mCX;N4>dlK*faSIpH1b5lZA5{kL}D~6ZZC9ZG_=m<qs+q?USNH9?p?Dxl>D! z$86fw6*4E4UIZ1Ic$z-<*~F3eJ4v4JWc;P2pZT8)G4`e3T+t2m0E4HipUXO@geCyK Ct!1eI literal 0 HcmV?d00001 diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetMetadataPanel.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetMetadataPanel.java index cec1a638511..0a36623eb92 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetMetadataPanel.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetMetadataPanel.java @@ -21,10 +21,8 @@ import static ch.systemsx.cisd.openbis.dss.client.api.gui.DataSetUploadClient.BU import static ch.systemsx.cisd.openbis.dss.client.api.gui.DataSetUploadClient.LABEL_WIDTH; import java.awt.CardLayout; -import java.awt.Color; import java.awt.Component; import java.awt.Dimension; -import java.awt.Font; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -40,9 +38,10 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.List; +import java.util.concurrent.BlockingDeque; +import java.util.concurrent.LinkedBlockingDeque; import javax.swing.AbstractButton; -import javax.swing.BorderFactory; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JComboBox; @@ -51,10 +50,7 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; import javax.swing.JTextField; -import javax.swing.ScrollPaneConstants; import ch.systemsx.cisd.openbis.dss.client.api.gui.DataSetUploadClientModel.NewDataSetInfo; import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.NewDataSetDTO.DataSetOwnerType; @@ -67,10 +63,36 @@ import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.DataSetType; */ public class DataSetMetadataPanel extends JPanel { + private class AsynchronousValidator implements Runnable + { + public void run() + { + while (true) + { + try + { + if (validationQueue.take() != null) + { + // empty the queue + validationQueue.clear(); + + // perform the validation + validateAndNotifyObserversOfChanges(); + } + } catch (Throwable t) + { + // ignore the error, thread cannot die + } + } + } + } + private static final String EMPTY_FILE_SELECTION = ""; private static final long serialVersionUID = 1L; + private final BlockingDeque<Boolean> validationQueue = new LinkedBlockingDeque<Boolean>(); + private final JFrame mainWindow; private final DataSetUploadClientModel clientModel; @@ -98,15 +120,16 @@ public class DataSetMetadataPanel extends JPanel private final HashMap<String, DataSetPropertiesPanel> propertiesPanels = new HashMap<String, DataSetPropertiesPanel>(); - private final JTextArea validationErrors = new JTextArea("Błędy"); - - private final JScrollPane validationErrorsPane = new JScrollPane(validationErrors); + private final ErrorsPanel validationErrors; private NewDataSetInfo newDataSetInfo; public DataSetMetadataPanel(DataSetUploadClientModel clientModel, JFrame mainWindow) { super(); + + new Thread(new AsynchronousValidator()).start(); + setLayout(new GridBagLayout()); // Initialize internal state @@ -131,15 +154,7 @@ public class DataSetMetadataPanel extends JPanel dataSetFileButton = new JButton("Browse..."); dataSetFileLabel = new JLabel("File:", JLabel.TRAILING); - validationErrors.setEditable(false); - validationErrors.setBackground(getBackground()); - validationErrors.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize())); - validationErrors.setForeground(Color.RED); - validationErrors.setLineWrap(true); - validationErrors.setWrapStyleWord(true); - validationErrorsPane.setBorder(BorderFactory.createEmptyBorder()); - validationErrorsPane - .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + validationErrors = new ErrorsPanel(mainWindow); createGui(); } @@ -241,15 +256,18 @@ public class DataSetMetadataPanel extends JPanel } Object selectedItem = e.getItem(); - if (null == selectedItem || EMPTY_FILE_SELECTION == selectedItem) + if (selectedItem != newDataSetInfo.getNewDataSetBuilder().getFile()) { - newDataSetInfo.getNewDataSetBuilder().setFile(null); - } else - { - newDataSetInfo.getNewDataSetBuilder().setFile((File) selectedItem); + if (null == selectedItem || EMPTY_FILE_SELECTION == selectedItem) + { + newDataSetInfo.getNewDataSetBuilder().setFile(null); + } else + { + newDataSetInfo.getNewDataSetBuilder().setFile((File) selectedItem); + } + + validationQueue.add(Boolean.TRUE); } - - validateAndNotifyObserversOfChanges(); } }); @@ -273,7 +291,7 @@ public class DataSetMetadataPanel extends JPanel clientModel.userDidSelectFile(newDirOrNull); updateFileComboBoxList(); updateFileLabel(); - validateAndNotifyObserversOfChanges(); + validationQueue.add(Boolean.TRUE); } } @@ -349,7 +367,8 @@ public class DataSetMetadataPanel extends JPanel createDataSetTypePanel(); addRow(4, dataSetTypePanel); - addRow(5, validationErrorsPane); + + addRow(5, validationErrors); } private void setDataSetType(String dataSetType) @@ -493,8 +512,10 @@ public class DataSetMetadataPanel extends JPanel private void validateAndNotifyObserversOfChanges() { + validationErrors.waitCard(); clientModel.validateNewDataSetInfoAndNotifyObservers(newDataSetInfo); syncErrors(); + validationErrors.showResult(); } private void setOwnerType(DataSetOwnerType type) @@ -505,9 +526,11 @@ public class DataSetMetadataPanel extends JPanel } NewDataSetDTOBuilder builder = newDataSetInfo.getNewDataSetBuilder(); - builder.setDataSetOwnerType(type); - - validateAndNotifyObserversOfChanges(); + if (builder.getDataSetOwnerType() != type) + { + builder.setDataSetOwnerType(type); + validationQueue.add(Boolean.TRUE); + } } protected void setOwnerId(String text) @@ -518,11 +541,15 @@ public class DataSetMetadataPanel extends JPanel } NewDataSetDTOBuilder builder = newDataSetInfo.getNewDataSetBuilder(); - builder.setDataSetOwnerIdentifier(text); - validateAndNotifyObserversOfChanges(); + + if (false == text.equals(builder.getDataSetOwnerIdentifier())) + { + builder.setDataSetOwnerIdentifier(text); + validationQueue.add(Boolean.TRUE); + } } - public void syncErrors() + public synchronized void syncErrors() { // Clear all errors first clearError(ownerIdLabel, ownerIdText, null); @@ -557,7 +584,7 @@ public class DataSetMetadataPanel extends JPanel } } - private void displayError(JLabel label, JComponent component, JTextArea errorAreaOrNull, + private void displayError(JLabel label, JComponent component, ErrorsPanel errorAreaOrNull, ValidationError error) { // Not all errors are applicable to this panel @@ -568,7 +595,7 @@ public class DataSetMetadataPanel extends JPanel UiUtilities.displayError(label, component, errorAreaOrNull, error); } - private void clearError(JLabel label, JComponent component, JTextArea errorAreaOrNull) + private void clearError(JLabel label, JComponent component, ErrorsPanel errorAreaOrNull) { UiUtilities.clearError(label, component, errorAreaOrNull); component.setToolTipText(label.getToolTipText()); diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java index cddaa1761f4..1861daaa54a 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/DataSetUploadClientModel.java @@ -417,7 +417,7 @@ public class DataSetUploadClientModel /** * Validate a new data set info and update the validation errors. */ - public final void validateNewDataSetInfo(NewDataSetInfo newDataSetInfo) + private final void validateNewDataSetInfo(NewDataSetInfo newDataSetInfo) { ArrayList<ValidationError> errors = new ArrayList<ValidationError>(); validateNewDataSetInfo(newDataSetInfo, errors); diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorMessageDialog.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorMessageDialog.java new file mode 100644 index 00000000000..59073ab15df --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorMessageDialog.java @@ -0,0 +1,148 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.dss.client.api.gui; + +import java.awt.Point; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import javax.swing.JDialog; +import javax.swing.JFrame; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +/** + * @author Pawel Glyzewski + */ +public class ErrorMessageDialog extends JDialog +{ + + private static final long serialVersionUID = 2915724575615063627L; + + private final JTextArea errorArea = new JTextArea(); + + private final JFrame mainWindow; + + public JPopupMenu popup; + + // An inner class to check whether mouse events are the popup trigger + class MousePopupListener extends MouseAdapter + { + @Override + public void mousePressed(MouseEvent e) + { + checkPopup(e); + } + + @Override + public void mouseClicked(MouseEvent e) + { + checkPopup(e); + } + + @Override + public void mouseReleased(MouseEvent e) + { + checkPopup(e); + } + + private void checkPopup(MouseEvent e) + { + if (e.isPopupTrigger()) + { + popup.show(ErrorMessageDialog.this.errorArea, e.getX(), e.getY()); + } + } + } + + public ErrorMessageDialog(JFrame mainWindow) + { + super(mainWindow, true); + + this.mainWindow = mainWindow; + JScrollPane scrollPane = new JScrollPane(this.errorArea); + Object[] objects = + { "Validation error occured: ", scrollPane }; + + final JOptionPane optionPane = + new JOptionPane(objects, JOptionPane.ERROR_MESSAGE, JOptionPane.DEFAULT_OPTION, + null); + + this.setContentPane(optionPane); + this.errorArea.setEditable(false); + + popup = new JPopupMenu(); + JMenuItem menuItem = new JMenuItem("Copy"); + popup.add(menuItem); + menuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + errorArea.copy(); + } + }); + + optionPane.addPropertyChangeListener(new PropertyChangeListener() + { + public void propertyChange(PropertyChangeEvent evt) + { + + if (evt.getPropertyName() != null + && evt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY)) + { + + if (evt.getNewValue() != null) + { + if (((Integer) evt.getNewValue()) == JOptionPane.OK_OPTION) + { + optionPane.setValue(optionPane.getInitialValue()); + + ErrorMessageDialog.this.dispose(); + } + } + } + } + + }); + errorArea.addMouseListener(new MousePopupListener()); + } + + public void showErrorMessage(String errorMessage) + { + errorArea.setText(errorMessage); + this.pack(); + + int height = this.getHeight() > 500 ? 500 : this.getHeight(); + int width = this.getWidth() > 600 ? 600 : this.getWidth(); + this.setSize(width, height); + + Point mwLocation = mainWindow.getLocationOnScreen(); + int x = mwLocation.x + (mainWindow.getWidth() / 2) - (this.getWidth() / 2); + int y = mwLocation.y + (mainWindow.getHeight() / 2) - (this.getHeight() / 2); + + this.setLocation(x > 0 ? x : 0, y > 0 ? y : 0); + + this.setVisible(true); + } +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorsPanel.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorsPanel.java new file mode 100644 index 00000000000..f22564ac6c9 --- /dev/null +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/ErrorsPanel.java @@ -0,0 +1,171 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.dss.client.api.gui; + +import java.awt.CardLayout; +import java.awt.Color; +import java.awt.Font; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JEditorPane; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.event.HyperlinkEvent; +import javax.swing.event.HyperlinkEvent.EventType; +import javax.swing.event.HyperlinkListener; + +import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.validation.ValidationError; + +/** + * @author Pawel Glyzewski + */ +public class ErrorsPanel extends JPanel implements HyperlinkListener +{ + private static final long serialVersionUID = 5932698456919803620L; + + private static final String VALIDATION_ERRORS_CARD = "Errors"; + + private static final String VALIDATION_WAIT_CARD = "Wait"; + + private static final String VALIDATION_SUCCESS_CARD = "Success"; + + private static final String WRONG_ICON_URL = ErrorsPanel.class.getResource("/wrong.png") + .toString(); + + private static final ImageIcon OK_ICON = + new ImageIcon(ErrorsPanel.class.getResource("/ok.png")); + + private static final ImageIcon WAIT_ICON = new ImageIcon( + ErrorsPanel.class.getResource("/wait.gif")); + + private final List<ValidationError> errors = new ArrayList<ValidationError>(); + + private final ErrorMessageDialog errorMessageDialog; + + private final JEditorPane errorsArea; + + private final JScrollPane errorsAreaScroll; + + public ErrorsPanel(JFrame mainWindow) + { + super(new CardLayout()); + + errorMessageDialog = new ErrorMessageDialog(mainWindow); + + errorsArea = new JEditorPane("text/html", ""); + errorsArea.addHyperlinkListener(this); + errorsArea.setEditable(false); + errorsArea.setBackground(getBackground()); + errorsArea.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize())); + errorsArea.setForeground(Color.RED); + errorsAreaScroll = new JScrollPane(errorsArea); + errorsAreaScroll.setBorder(BorderFactory.createEmptyBorder()); + errorsAreaScroll + .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + + this.add(errorsAreaScroll, VALIDATION_ERRORS_CARD); + this.add(new JLabel("Validating, please wait...", WAIT_ICON, JLabel.CENTER), + VALIDATION_WAIT_CARD); + this.add(new JLabel("Validated successfully.", OK_ICON, JLabel.CENTER), + VALIDATION_SUCCESS_CARD); + } + + public void clear() + { + errorsArea.setText(""); + errorsArea.setToolTipText(""); + this.errors.clear(); + } + + public void reportError(ValidationError error) + { + errors.add(error); + displayErrors(); + } + + private void displayErrors() + { + StringBuilder sb = new StringBuilder(); + + int counter = 0; + for (ValidationError error : errors) + { + sb.append( + "<center><div style='align: center' ><a href='http://openbis.ch/" + + (counter++) + + "' style='color: black; text-decoration: none; font-style: normal; vertical-align: middle' ><img border='0' hspace='10' src='") + .append(WRONG_ICON_URL).append("' />") + .append(truncateErrorMessage(error.getErrorMessage())) + .append(" [...]</a></div></center>"); + } + + errorsArea.setText(sb.toString()); + } + + private String truncateErrorMessage(String errorMessage) + { + int truncIndex = 80; + + int indexOfCR = errorMessage.indexOf('\r'); + if (indexOfCR > -1 && indexOfCR < truncIndex) + { + truncIndex = indexOfCR; + } + + int indexOfLF = errorMessage.indexOf('\n'); + if (indexOfLF > -1 && indexOfLF < truncIndex) + { + truncIndex = indexOfLF; + } + + return errorMessage.length() > truncIndex ? errorMessage.substring(0, truncIndex) + : errorMessage; + } + + public void hyperlinkUpdate(HyperlinkEvent event) + { + if (event.getEventType() == EventType.ACTIVATED) + { + URL url = event.getURL(); + int idx = Integer.parseInt(url.getPath().substring(1)); + errorMessageDialog.showErrorMessage(errors.get(idx).getErrorMessage()); + } + } + + public void waitCard() + { + ((CardLayout) this.getLayout()).show(this, VALIDATION_WAIT_CARD); + } + + public void showResult() + { + if (errors.isEmpty()) + { + ((CardLayout) this.getLayout()).show(this, VALIDATION_SUCCESS_CARD); + } else + { + ((CardLayout) this.getLayout()).show(this, VALIDATION_ERRORS_CARD); + } + } +} diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UiUtilities.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UiUtilities.java index 988ace56119..620ca3acd84 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UiUtilities.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/gui/UiUtilities.java @@ -20,7 +20,6 @@ import java.awt.Color; import javax.swing.JComponent; import javax.swing.JLabel; -import javax.swing.JTextArea; import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.validation.ValidationError; @@ -30,27 +29,24 @@ import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.validation.ValidationE public class UiUtilities { - public static void displayError(JLabel label, JComponent component, JTextArea errorAreaOrNull, - ValidationError error) + public static void displayError(JLabel label, JComponent component, + ErrorsPanel errorAreaOrNull, ValidationError error) { component.setToolTipText(error.getErrorMessage()); label.setForeground(Color.RED); if (errorAreaOrNull != null) { - errorAreaOrNull.setText("File validation error: " + error.getErrorMessage()); - errorAreaOrNull.setToolTipText(error.getErrorMessage()); + errorAreaOrNull.reportError(error); } } - public static void clearError(JLabel label, JComponent component, JTextArea errorAreaOrNull) + public static void clearError(JLabel label, JComponent component, ErrorsPanel errorAreaOrNull) { component.setToolTipText(null); label.setForeground(Color.BLACK); if (errorAreaOrNull != null) { - errorAreaOrNull.setText(null); - errorAreaOrNull.setToolTipText(null); + errorAreaOrNull.clear(); } } - } -- GitLab