From 5b6800df0b3b72930fba49ecb355994f5f5e441a Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Fri, 25 Oct 2013 16:03:15 +0000 Subject: [PATCH] Fixed the behavior of the user interface git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-csv-import-widget@84374 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/FileUploadPanel.java | 170 ++++---- .../client/general/WizardWindow.java | 383 +++++++++--------- 2 files changed, 283 insertions(+), 270 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/FileUploadPanel.java b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/FileUploadPanel.java index 5d034c3..8842eee 100644 --- a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/FileUploadPanel.java +++ b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/FileUploadPanel.java @@ -3,8 +3,6 @@ */ package org.gcube.portlets.user.td.csvimportwidget.client; - - import org.gcube.portlets.user.td.csvimportwidget.client.general.WizardCard; import org.gcube.portlets.user.td.csvimportwidget.client.progress.FileUploadProgressBarUpdater; import org.gcube.portlets.user.td.csvimportwidget.client.progress.FileUploadProgressListener; @@ -31,15 +29,14 @@ import com.sencha.gxt.widget.core.client.form.FieldLabel; import com.sencha.gxt.widget.core.client.form.FileUploadField; import com.sencha.gxt.widget.core.client.form.FormPanel; - /** * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * */ public class FileUploadPanel extends FormPanel { - + protected static final String UPLOAD_SERVLET = "LocalUploadServlet"; public static final int STATUS_POLLING_DELAY = 1000; @@ -47,38 +44,36 @@ public class FileUploadPanel extends FormPanel { protected ResourceBundle res; protected FileUploadField fileUploadField; protected TextButton uploadButton; - + protected FileUploadProgressUpdater progressUpdater; - + protected ProgressBar uploadProgressBar; protected TextButton cancelButton; - - - public FileUploadPanel(ResourceBundle res, final WizardCard card,final CSVImportSession importSession) - { - this.res=res; - + + public FileUploadPanel(ResourceBundle res, final WizardCard card, + final CSVImportSession importSession) { + this.res = res; + setId("LocalUploadPanel"); setLabelAlign(LabelAlign.TOP); getElement().setPadding(new Padding(5)); - + addShowHandler(new ShowHandler() { - + @Override public void onShow(ShowEvent event) { doLayout(); - + } }); - - - setAction(GWT.getModuleBaseURL()+UPLOAD_SERVLET); + + setAction(GWT.getModuleBaseURL() + UPLOAD_SERVLET); setWidth("100%"); setEncoding(Encoding.MULTIPART); setMethod(Method.POST); - + VerticalLayoutContainer content = new VerticalLayoutContainer(); content.setWidth("100%"); add(content); @@ -86,127 +81,134 @@ public class FileUploadPanel extends FormPanel { fileUploadField = new FileUploadField(); fileUploadField.setName("uploadFormElement"); fileUploadField.setWidth("100%"); - - content.add(new FieldLabel(fileUploadField, "Select the csv file to import"), new VerticalLayoutData(-2, -1)); - + + content.add(new FieldLabel(fileUploadField, + "Select the csv file to import"), + new VerticalLayoutData(-2, -1)); + uploadButton = new TextButton("Upload"); content.add(uploadButton, new VerticalLayoutData(-1, -1)); - + fileUploadField.addChangeHandler(new ChangeHandler() { - + @Override public void onChange(ChangeEvent event) { uploadButton.setEnabled(fileUploadField.isValid()); - String filename=fileUploadField.getValue(); - int punto=filename.lastIndexOf("."); - int slash=filename.lastIndexOf("/"); - int backslash=filename.lastIndexOf("\\"); - if(slash>backslash){ - filename=filename.substring(slash, punto); + String path = fileUploadField.getValue(); + int punto = path.lastIndexOf("."); + int slash = path.lastIndexOf("/"); + int backslash = path.lastIndexOf("\\"); + String filename=""; + if (slash > backslash) { + if (slash != -1) { + filename = path.substring(slash + 1, punto); + } } else { - filename=filename.substring(backslash, punto); + if (backslash != -1) { + filename = path.substring(backslash + 1, punto); + } + + } - importSession.setLocalFileName(filename); } }); - + uploadProgressBar = new ProgressBar(); uploadProgressBar.setHideMode(HideMode.VISIBILITY); - uploadProgressBar.getElement().setPadding(new Padding(3, 0, 5, 0)); + uploadProgressBar.getElement().setPadding(new Padding(3, 0, 5, 0)); content.add(uploadProgressBar, new VerticalLayoutData(-2, -1)); uploadProgressBar.hide(); - - cancelButton = new TextButton("Cancel"); - cancelButton.hide(); - content.add(cancelButton, new VerticalLayoutData(-1, -1)); - - uploadButton.addSelectHandler(new SelectHandler() { - + + cancelButton = new TextButton("Cancel"); + cancelButton.hide(); + content.add(cancelButton, new VerticalLayoutData(-1, -1)); + + uploadButton.addSelectHandler(new SelectHandler() { + @Override public void onSelect(SelectEvent event) { Log.info("request upload"); - - if (fileUploadField.getValue()==null || fileUploadField.getValue().equals("")){ + + if (fileUploadField.getValue() == null + || fileUploadField.getValue().equals("")) { Log.info("fileUploadField is null or empty"); - AlertMessageBox alertMessageBox = new AlertMessageBox("CSV file missing", "Please specify a CSV file."); + AlertMessageBox alertMessageBox = new AlertMessageBox( + "CSV file missing", "Please specify a CSV file."); alertMessageBox.show(); return; } else { Log.info("startUpload call"); startUpload(); } - + } }); - - + progressUpdater = new FileUploadProgressUpdater(); - progressUpdater.addListener(new FileUploadProgressBarUpdater(uploadProgressBar)); - - + progressUpdater.addListener(new FileUploadProgressBarUpdater( + uploadProgressBar)); + progressUpdater.addListener(new FileUploadProgressListener() { - + @Override public void operationUpdate(float elaborated) { // TODO Auto-generated method stub - + } - + @Override public void operationInitializing() { // TODO Auto-generated method stub - + } - + @Override public void operationFailed(Throwable caught, String reason, String failureDetails) { - card.showErrorAndHide("Error uploading the csv file", reason, failureDetails, caught); + card.showErrorAndHide("Error uploading the csv file", reason, + failureDetails, caught); } - + @Override public void operationComplete() { card.setEnableNextButton(true); cancelButton.disable(); - + } }); - } - - protected void startUpload() - { + + protected void startUpload() { disableUpload(); - - //we update the action url with the session id - //this is necessary in order to let the servlet retrieve the session id before the POST request parsing + + // we update the action url with the session id + // this is necessary in order to let the servlet retrieve the session id + // before the POST request parsing StringBuilder actionUrl = new StringBuilder(); actionUrl.append(GWT.getModuleBaseURL()); - //actionUrl.append(UPLOAD_SERVLET+"?sessionId="); + // actionUrl.append(UPLOAD_SERVLET+"?sessionId="); actionUrl.append(UPLOAD_SERVLET); - /*if(session==null){ - Log.info("No valid Session"); - AlertMessageBox alertMessageBox = new AlertMessageBox("No session valid", "Error generating the session"); - alertMessageBox.show(); - return; - }*/ - //actionUrl.append(session.getId()); + /* + * if(session==null){ Log.info("No valid Session"); AlertMessageBox + * alertMessageBox = new AlertMessageBox("No session valid", + * "Error generating the session"); alertMessageBox.show(); return; } + */ + // actionUrl.append(session.getId()); setAction(actionUrl.toString()); - Log.info("Start Upload action Url "+actionUrl.toString()); + Log.info("Start Upload action Url " + actionUrl.toString()); submit(); - + progressUpdater.scheduleRepeating(STATUS_POLLING_DELAY); } - - protected void disableUpload() - { + + protected void disableUpload() { fileUploadField.disable(); uploadButton.disable(); - - uploadProgressBar.show(); - cancelButton.show(); + + uploadProgressBar.show(); + cancelButton.show(); } } diff --git a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/general/WizardWindow.java b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/general/WizardWindow.java index eb169d4..ff3cf04 100644 --- a/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/general/WizardWindow.java +++ b/src/main/java/org/gcube/portlets/user/td/csvimportwidget/client/general/WizardWindow.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import org.gcube.portlets.user.td.csvimportwidget.client.util.ErrorMessageBox; import org.gcube.portlets.user.td.gwtservice.shared.TRId; - import com.allen_sauer.gwt.log.client.Log; import com.google.gwt.core.client.Callback; import com.google.gwt.user.client.Command; @@ -28,17 +27,16 @@ import com.sencha.gxt.widget.core.client.toolbar.ToolBar; /** * - * @author "Giancarlo Panichi" - * g.panichi@isti.cnr.it - * + * @author "Giancarlo Panichi" g.panichi@isti.cnr.it + * */ public class WizardWindow extends Window { - protected final String WIZARDWIDTH="640px"; - protected final String WIZARDHEIGHT="480px"; - protected final boolean WIZARRESIZABLE=false; - - + protected final String WIZARDWIDTH = "640px"; + protected final String WIZARDHEIGHT = "480px"; + protected final boolean WIZARRESIZABLE = false; + protected ArrayList cardStack = new ArrayList(); protected TextButton backButton; @@ -54,51 +52,51 @@ public class WizardWindow extends Window { protected Command nextButtonAction = null; protected Command previousButtonAction = null; - + protected CardLayoutContainer cardContainer; protected ArrayList listeners; - + protected SimpleEventBus eventBus; /** * Create a new Wizard Window with the specified title. - * @param title the wizard window title. + * + * @param title + * the wizard window title. */ - public WizardWindow(String title) - { + public WizardWindow(String title) { super(); - this.eventBus= new SimpleEventBus(); + this.eventBus = new SimpleEventBus(); Log.info(title); - //setModal(true); + // setModal(true); setResizable(WIZARRESIZABLE); setCollapsible(true); setWidth(WIZARDWIDTH); setHeight(WIZARDHEIGHT); - listeners = new ArrayList(); setHeadingText(title); this.originalTitle = title; - + VerticalLayoutContainer container = new VerticalLayoutContainer(); cardContainer = new CardLayoutContainer(); container.add(cardContainer, new VerticalLayoutData(1, 1)); - ToolBar toolbar = new ToolBar(); + ToolBar toolbar = new ToolBar(); toolbar.addStyleName(ThemeStyles.getStyle().borderTop()); - backButton = new TextButton("Back"); + backButton = new TextButton("Back"); backButton.setEnabled(false); backButton.setTabIndex(1001); - toolbar.add(backButton); - toolbar.add(new FillToolItem()); + toolbar.add(backButton); + toolbar.add(new FillToolItem()); - nextButton = new TextButton("Next"); + nextButton = new TextButton("Next"); nextButton.setTabIndex(1000); - toolbar.add(nextButton); + toolbar.add(nextButton); toolbar.setLayoutData(new VerticalLayoutData(1, -1)); container.add(toolbar); @@ -107,152 +105,157 @@ public class WizardWindow extends Window { @Override public void onSelect(SelectEvent event) { - TextButton button = (TextButton)event.getSource(); - String btnID = button.getId(); + TextButton button = (TextButton) event.getSource(); + String btnID = button.getId(); - if (btnID.equals(backButton.getId())) { - - if(previousButtonAction!=null) previousButtonAction.execute(); - else previousCard(); - } else { + if (btnID.equals(backButton.getId())) { - if (nextButtonAction!=null) nextButtonAction.execute(); - else nextCard(); + if (previousButtonAction != null) + previousButtonAction.execute(); + else + previousCard(); + } else { + + if (nextButtonAction != null) + nextButtonAction.execute(); + else + nextCard(); } - } - }; + } + }; backButton.addSelectHandler(selectionHandler); - nextButton.addSelectHandler(selectionHandler); - + nextButton.addSelectHandler(selectionHandler); + + closeBtnHandle(); setWidget(container); } - - + protected void closeBtnHandle() { + closeBtn.addSelectHandler(new SelectHandler() { + + @Override + public void onSelect(SelectEvent event) { + fireAborted(); + } + }); + } + /** * {@inheritDoc} */ @Override protected void initTools() { super.initTools(); - - //we can't distinguish between hide and hide with button - /*closeBtn.removeAllListeners(); - closeBtn.addListener(Events.Select, new Listener() { - public void handleEvent(ComponentEvent ce) { - MessageBox.confirm("Confirm", "Are you sure to cancel the operation?", new Listener() { - - @Override - public void handleEvent(MessageBoxEvent be) { - if (be.getButtonClicked().getItemId().equals(Dialog.YES)) { - hide(); - fireAborted(); - } - } - }); - } - });*/ + + // we can't distinguish between hide and hide with button + /* + * closeBtn.removeAllListeners(); closeBtn.addListener(Events.Select, + * new Listener() { public void + * handleEvent(ComponentEvent ce) { MessageBox.confirm("Confirm", + * "Are you sure to cancel the operation?", new + * Listener() { + * + * @Override public void handleEvent(MessageBoxEvent be) { if + * (be.getButtonClicked().getItemId().equals(Dialog.YES)) { hide(); + * fireAborted(); } } }); } }); + */ } - public void addListener(WizardListener listener) - { + public void addListener(WizardListener listener) { listeners.add(listener); } - - public void removeListener(WizardListener listener) - { + + public void removeListener(WizardListener listener) { listeners.remove(listener); } /** * Shows the next available card. */ - public void nextCard() - { - + public void nextCard() { + Widget activeItem = cardContainer.getActiveWidget(); - if (activeItem instanceof WizardCard) ((WizardCard)activeItem).dispose(); + if (activeItem instanceof WizardCard) + ((WizardCard) activeItem).dispose(); int cardPos = cardStack.indexOf(activeItem); - - //NEXT -> + + // NEXT -> nextButton.setEnabled(true); backButton.setEnabled(true); - int newPos=cardPos+1; - - if (newPos == 0) { - //we are moving forward from the first card + int newPos = cardPos + 1; + + if (newPos == 0) { + // we are moving forward from the first card backButton.setEnabled(false); } - - - nextButtonAction=null; - previousButtonAction=null; - Log.info("cardStack size:"+cardStack.size()); + nextButtonAction = null; + previousButtonAction = null; + Log.info("cardStack size:" + cardStack.size()); WizardCard card = cardStack.get(newPos); cardContainer.setActiveWidget(card); doLayout(); - if (card instanceof WizardCard) ((WizardCard)card).setup(); + if (card instanceof WizardCard) + ((WizardCard) card).setup(); } /** * Shows the previous available card. */ - public void previousCard() - { + public void previousCard() { Widget activeItem = cardContainer.getActiveWidget(); - if (activeItem instanceof WizardCard) ((WizardCard)activeItem).dispose(); + if (activeItem instanceof WizardCard) + ((WizardCard) activeItem).dispose(); int cardPos = cardStack.indexOf(activeItem); - //BACK <- + // BACK <- nextButton.setEnabled(true); backButton.setEnabled(true); - int newPos=cardPos-1; - - - if (newPos == 0) { - backButton.setEnabled(false); - } + int newPos = cardPos - 1; + + if (newPos == 0) { + backButton.setEnabled(false); + } + + nextButtonAction = null; + previousButtonAction = null; - nextButtonAction=null; - previousButtonAction=null; - WizardCard card = cardStack.get(newPos); cardContainer.setActiveWidget(card); doLayout(); - if (card instanceof WizardCard) ((WizardCard)card).setup(); + if (card instanceof WizardCard) + ((WizardCard) card).setup(); } /** * Returns the number of available cards. + * * @return */ - public int getCardStackSize() - { + public int getCardStackSize() { return cardStack.size(); } /** * Returns the current active card. + * * @return */ - public int getCurrentCard() - { + public int getCurrentCard() { return cardStack.indexOf(cardContainer.getActiveWidget()); } - public boolean checkBeforeClose() - { + public boolean checkBeforeClose() { return true; } @@ -262,10 +265,10 @@ public class WizardWindow extends Window { } /** - * Sets the label of next button to "Finish" value and add a close command to it. + * Sets the label of next button to "Finish" value and add a close command + * to it. */ - public void setNextButtonToFinish() - { + public void setNextButtonToFinish() { nextButton.setText("Finish"); nextButtonAction = new Command() { @@ -277,20 +280,21 @@ public class WizardWindow extends Window { /** * Set the command for the next button. - * @param command the command to execute. + * + * @param command + * the command to execute. */ - public void setNextButtonCommand(Command command) - { + public void setNextButtonCommand(Command command) { nextButtonAction = command; } - - + /** * Set the command for the previous button. - * @param command the command to execute. + * + * @param command + * the command to execute. */ - public void setPreviousButtonCommand(Command command) - { + public void setPreviousButtonCommand(Command command) { previousButtonAction = command; } @@ -303,28 +307,28 @@ public class WizardWindow extends Window { Widget activeItem = cardContainer.getActiveWidget(); - if (activeItem instanceof WizardCard) ((WizardCard)activeItem).setup(); + if (activeItem instanceof WizardCard) + ((WizardCard) activeItem).setup(); } - - /** * Set the card list. + * * @param cards */ - public void setCards(ArrayList cards) - { - for (WizardCard card:cards) { + public void setCards(ArrayList cards) { + for (WizardCard card : cards) { addCard(card); } } /** * Adds a card to this wizard. - * @param card the card to add. + * + * @param card + * the card to add. */ - public void addCard(WizardCard card) - { + public void addCard(WizardCard card) { card.setWizardWindow(this); cardContainer.add(card); cardStack.add(card); @@ -332,77 +336,83 @@ public class WizardWindow extends Window { /** * Remove a card to this wizard. - * @param card the card to add. + * + * @param card + * the card to add. */ - public void removeCard(WizardCard card) - { + public void removeCard(WizardCard card) { cardContainer.remove(card); cardStack.remove(card); } - /** * Enables the next button on the wizard. - * @param enable true to enable the next button, false otherwise. + * + * @param enable + * true to enable the next button, + * false otherwise. */ - public void setEnableNextButton(boolean enable) - { + public void setEnableNextButton(boolean enable) { nextButton.setEnabled(enable); } /** * Enables the back button on the wizard. - * @param enable true to enable the back button, false otherwise. + * + * @param enable + * true to enable the back button, + * false otherwise. */ - public void setEnableBackButton(boolean enable) - { + public void setEnableBackButton(boolean enable) { backButton.setEnabled(enable); } /** * Sets the next button label. - * @param text the button label. + * + * @param text + * the button label. */ - protected void setNextButtonText(String text) - { + protected void setNextButtonText(String text) { nextButton.setText(text); - - } - - /** - * Sets the back button label. - * @param text the button label. - */ - protected void setBackButtonText(String text) - { - backButton.setText(text); - } - - /** - * Sets visible next button. - * @param visible - */ - protected void setNextButtonVisible(boolean visible) - { - nextButton.setVisible(visible); - } - - /** - * Sets visible back button. - * @param visible - */ - protected void setBackButtonVisible(boolean visible) - { - backButton.setVisible(visible); + } + /** + * Sets the back button label. + * + * @param text + * the button label. + */ + protected void setBackButtonText(String text) { + backButton.setText(text); + } + + /** + * Sets visible next button. + * + * @param visible + */ + protected void setNextButtonVisible(boolean visible) { + nextButton.setVisible(visible); + } + + /** + * Sets visible back button. + * + * @param visible + */ + protected void setBackButtonVisible(boolean visible) { + backButton.setVisible(visible); + } /** * Add a listener to the next button. - * @param listener the listener to add. + * + * @param listener + * the listener to add. */ - protected void addNextButtonListener(SelectHandler listener) - { + protected void addNextButtonListener(SelectHandler listener) { nextButton.addSelectHandler(listener); } @@ -415,41 +425,42 @@ public class WizardWindow extends Window { /** * Returns the card list. + * * @return teh card list. */ - public ArrayList getCardStack() - { + public ArrayList getCardStack() { return cardStack; } - public void showErrorAndHide(String title, final String failureReason, final String failureDetails, final Throwable throwable) - { - ErrorMessageBox.showError(title, failureReason, failureDetails, new Callback() { - - @Override - public void onSuccess(Dialog result) { - } - - @Override - public void onFailure(Void reason) { - hide(); - fireFailed(throwable, failureReason, failureDetails); - } - }); + public void showErrorAndHide(String title, final String failureReason, + final String failureDetails, final Throwable throwable) { + ErrorMessageBox.showError(title, failureReason, failureDetails, + new Callback() { + + @Override + public void onSuccess(Dialog result) { + } + + @Override + public void onFailure(Void reason) { + hide(); + fireFailed(throwable, failureReason, failureDetails); + } + }); } - public void fireCompleted(TRId id) - { - for (WizardListener listener:listeners) listener.completed(id); + public void fireCompleted(TRId id) { + for (WizardListener listener : listeners) + listener.completed(id); } - public void fireAborted() - { - for (WizardListener listener:listeners) listener.aborted(); + public void fireAborted() { + for (WizardListener listener : listeners) + listener.aborted(); } - public void fireFailed(Throwable throwable, String reason, String details) - { - for (WizardListener listener:listeners) listener.failed(throwable, reason, details); + public void fireFailed(Throwable throwable, String reason, String details) { + for (WizardListener listener : listeners) + listener.failed(throwable, reason, details); } }