modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/create/BundleUploadDataStep.java | 110 +++++----- modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/upload/BundleFileUploadForm.java | 110 +++++++--- 2 files changed, 150 insertions(+), 70 deletions(-)
New commits: commit 7afbfa9b13b12e4d362c918571a35f88c118b9d9 Author: John Mazzitelli mazz@redhat.com Date: Fri Mar 26 03:43:20 2010 -0400
bundle file upload step in wizard works and looks nicer now
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/create/BundleUploadDataStep.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/create/BundleUploadDataStep.java index 793cd5a..e241771 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/create/BundleUploadDataStep.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/bundle/create/BundleUploadDataStep.java @@ -18,21 +18,22 @@ */ package org.rhq.enterprise.gui.coregui.client.bundle.create;
+import java.util.ArrayList; import java.util.HashMap; import java.util.Map;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; -import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.Label; -import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.events.FormSubmitFailedEvent; import com.smartgwt.client.widgets.form.events.FormSubmitFailedHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout;
import org.rhq.enterprise.gui.coregui.client.CoreGUI; +import org.rhq.enterprise.gui.coregui.client.components.HeaderLabel; import org.rhq.enterprise.gui.coregui.client.components.upload.BundleFileUploadForm; import org.rhq.enterprise.gui.coregui.client.components.upload.DynamicFormHandler; import org.rhq.enterprise.gui.coregui.client.components.upload.DynamicFormSubmitCompleteEvent; @@ -45,25 +46,24 @@ public class BundleUploadDataStep implements WizardStep {
private final AbstractBundleCreateWizard wizard; private final BundleGWTServiceAsync bundleServer = GWTServiceLookup.getBundleService(); - private DynamicForm form; + private ArrayList<BundleFileUploadForm> uploadForms;
public BundleUploadDataStep(AbstractBundleCreateWizard bundleCreationWizard) { this.wizard = bundleCreationWizard; }
public Canvas getCanvas() { - form = new DynamicForm(); - - final VLayout layout = new VLayout(); - layout.setMargin(Integer.valueOf(20)); - layout.setAlign(Alignment.CENTER); + final VLayout mainLayout = new VLayout(); + mainLayout.setMargin(Integer.valueOf(20)); + mainLayout.setWidth100(); + mainLayout.setHeight(10);
bundleServer.getAllBundleVersionFilenames(this.wizard.getBundleVersion().getId(), new AsyncCallback<HashMap<String, Boolean>>() {
public void onSuccess(HashMap<String, Boolean> result) { wizard.setAllBundleFilesStatus(result); - prepareForm(layout); + prepareForm(mainLayout); }
public void onFailure(Throwable caught) { @@ -72,8 +72,7 @@ public class BundleUploadDataStep implements WizardStep { } });
- form.addChild(layout); - return form; + return mainLayout; }
public boolean nextPage() { @@ -88,61 +87,82 @@ public class BundleUploadDataStep implements WizardStep { if (wizard.getAllBundleFilesStatus() == null) { return false; } + + boolean needToUpload = false; + for (BundleFileUploadForm uploadForm : this.uploadForms) { + if (uploadForm.getUploadResults() == null) { + uploadForm.submitForm(); + needToUpload = true; + } + } + if (needToUpload) { + return false; + } + if (wizard.getAllBundleFilesStatus().containsValue(Boolean.FALSE)) { return false; } return true; }
- private void prepareForm(VLayout layout) { + private void prepareForm(VLayout mainLayout) { // if there are no files to upload, immediately skip this step final HashMap<String, Boolean> allFilesStatus = wizard.getAllBundleFilesStatus();
if (allFilesStatus != null && allFilesStatus.size() == 0) { - // TODO: do something to tell the user they don't have to do anything for this step + HeaderLabel label = new HeaderLabel("No files need to be uploaded for this bundle"); + label.setWidth100(); + mainLayout.addMember(label); + uploadForms = null; return; }
- for (Map.Entry<String, Boolean> entry : allFilesStatus.entrySet()) { - HLayout formLayout = new HLayout(); - layout.addMember(formLayout); + uploadForms = new ArrayList<BundleFileUploadForm>();
+ for (Map.Entry<String, Boolean> entry : allFilesStatus.entrySet()) { String fileToBeUploaded = entry.getKey(); Boolean isAlreadyUploaded = entry.getValue();
- if (isAlreadyUploaded) { - Label nameLabel = new Label(fileToBeUploaded + ": "); - formLayout.addMember(nameLabel); - Img img = new Img("/images/icons/availability_green_16.png", 16, 16); - formLayout.addMember(img); - } else { - final BundleFileUploadForm uploadForm = new BundleFileUploadForm(this.wizard.getBundleVersion(), - fileToBeUploaded); - uploadForm.addFormHandler(new DynamicFormHandler() { - public void onSubmitComplete(DynamicFormSubmitCompleteEvent event) { - String results = event.getResults(); - if (!results.contains("Failed to upload bundle file")) { - uploadForm.retrievalStatus(true); - allFilesStatus.put(uploadForm.getName(), Boolean.TRUE); - } else { - uploadForm.retrievalStatus(false); - allFilesStatus.put(uploadForm.getName(), Boolean.FALSE); - CoreGUI.getMessageCenter().notify( - new Message("Failed to upload bundle file", results, Message.Severity.Error)); - } - } - }); - uploadForm.addFormSubmitFailedHandler(new FormSubmitFailedHandler() { - public void onFormSubmitFailed(FormSubmitFailedEvent event) { - uploadForm.retrievalStatus(false); + HLayout indivLayout = new HLayout(); + indivLayout.setWidth100(); + indivLayout.setAutoHeight(); + + Label nameLabel = new Label(fileToBeUploaded + ": "); + nameLabel.setWidth("*"); + nameLabel.setAlign(Alignment.RIGHT); + nameLabel.setLayoutAlign(VerticalAlignment.CENTER); + indivLayout.addMember(nameLabel); + + final BundleFileUploadForm uploadForm = new BundleFileUploadForm(this.wizard.getBundleVersion(), + fileToBeUploaded, false, (isAlreadyUploaded) ? Boolean.TRUE : null); + uploadForm.setWidth("75%"); + indivLayout.addMember(uploadForm); + + uploadForm.addFormHandler(new DynamicFormHandler() { + public void onSubmitComplete(DynamicFormSubmitCompleteEvent event) { + String results = event.getResults(); + if (!results.contains("Failed to upload bundle file")) { + allFilesStatus.put(uploadForm.getName(), Boolean.TRUE); + } else { allFilesStatus.put(uploadForm.getName(), Boolean.FALSE); CoreGUI.getMessageCenter().notify( - new Message("Failed to upload file", null, Message.Severity.Error)); + new Message("Failed to upload bundle file", results, Message.Severity.Error)); } - }); + } + }); + uploadForm.addFormSubmitFailedHandler(new FormSubmitFailedHandler() { + public void onFormSubmitFailed(FormSubmitFailedEvent event) { + allFilesStatus.put(uploadForm.getName(), Boolean.FALSE); + CoreGUI.getMessageCenter().notify( + new Message("Failed to upload file", null, Message.Severity.Error)); + } + });
- formLayout.addMember(uploadForm); - } + uploadForms.add(uploadForm); + + mainLayout.addMember(indivLayout); } + + return; } } diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/upload/BundleFileUploadForm.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/upload/BundleFileUploadForm.java index a0c6add..6f18f04 100644 --- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/upload/BundleFileUploadForm.java +++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/upload/BundleFileUploadForm.java @@ -20,9 +20,12 @@ package org.rhq.enterprise.gui.coregui.client.components.upload;
import com.google.gwt.core.client.GWT; import com.smartgwt.client.types.Encoding; +import com.smartgwt.client.widgets.form.events.FormSubmitFailedEvent; +import com.smartgwt.client.widgets.form.events.FormSubmitFailedHandler; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.smartgwt.client.widgets.form.fields.FormItemIcon; import com.smartgwt.client.widgets.form.fields.HiddenItem; +import com.smartgwt.client.widgets.form.fields.StaticTextItem; import com.smartgwt.client.widgets.form.fields.UploadItem; import com.smartgwt.client.widgets.form.fields.events.ChangeEvent; import com.smartgwt.client.widgets.form.fields.events.ChangeHandler; @@ -36,18 +39,25 @@ import org.rhq.enterprise.gui.coregui.client.util.message.Message.Severity;
public class BundleFileUploadForm extends DynamicCallbackForm {
- private ButtonItem uploadButton; private UploadItem bundleUploadItem; + private ButtonItem uploadButton; + private StaticTextItem icon; + + private Boolean uploadResults;
- private BundleVersion bundleVersion; - private String name; + private final BundleVersion bundleVersion; + private final String name; + private final boolean showNameLabel; + + public BundleFileUploadForm(BundleVersion bundleVersion, String name, boolean showNameLabel, + Boolean isAlreadyUploaded) {
- public BundleFileUploadForm(BundleVersion bundleVersion, String name) { super(name); this.bundleVersion = bundleVersion; this.name = name; + this.showNameLabel = showNameLabel; + this.uploadResults = isAlreadyUploaded; // null if unknown, false if error during previous upload attempt, true if already uploaded before
- setNumCols(8); setEncoding(Encoding.MULTIPART); setAction(GWT.getModuleBaseURL() + "/BundleFileUploadServlet"); } @@ -65,6 +75,23 @@ public class BundleFileUploadForm extends DynamicCallbackForm { return name; }
+ /** + * Returns true if the file was successfully uploaded, false if an error occurred. + * Returns null if this upload form has not be submitted yet (see {@link #submitForm()}). + * @return status of the upload request + */ + public Boolean getUploadResults() { + return uploadResults; + } + + @Override + public void submitForm() { + icon.setShowIcons(true); + uploadButton.setDisabled(true); + markForRedraw(); + super.submitForm(); + } + @Override protected void onDraw() { super.onDraw(); @@ -81,58 +108,91 @@ public class BundleFileUploadForm extends DynamicCallbackForm { HiddenItem versionField = new HiddenItem("version"); versionField.setValue("1.0");
- setNumCols(4); + setNumCols(7);
- bundleUploadItem = new UploadItem("bundleFile", name); + bundleUploadItem = new UploadItem("bundleFileUploadItem", name); bundleUploadItem.setEndRow(false); + bundleUploadItem.setShowTitle(showNameLabel);
uploadButton = new ButtonItem("Upload"); uploadButton.setStartRow(false); + uploadButton.setEndRow(false); uploadButton.setDisabled(true); - - bundleUploadItem.addChangeHandler(new ChangeHandler() { - public void onChange(ChangeEvent changeEvent) { - uploadButton.setDisabled(false); - } - }); - uploadButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent clickEvent) { - uploadButton.setShowIcons(true); - markForRedraw(); submitForm(); } });
+ icon = new StaticTextItem("icon"); + icon.setStartRow(false); + icon.setShowTitle(false); + FormItemIcon loadingIcon = new FormItemIcon(); loadingIcon.setSrc("ajax-loader.gif"); loadingIcon.setWidth(16); loadingIcon.setHeight(16); - uploadButton.setIcons(loadingIcon); - uploadButton.setShowIcons(false); + icon.setIcons(loadingIcon); + icon.setShowIcons(false); + + bundleUploadItem.addChangeHandler(new ChangeHandler() { + public void onChange(ChangeEvent changeEvent) { + if (uploadResults != null) { + retrievalStatus(uploadResults.booleanValue()); + } else { + uploadButton.setDisabled(false); + icon.setShowIcons(false); + } + } + }); + + if (uploadResults != null) { + retrievalStatus(uploadResults.booleanValue()); + }
- setItems(sessionIdField, bundleVersionIdField, nameField, versionField, bundleUploadItem, uploadButton); + setItems(sessionIdField, bundleVersionIdField, nameField, versionField, bundleUploadItem, uploadButton, icon); + + addFormHandler(new DynamicFormHandler() { + public void onSubmitComplete(DynamicFormSubmitCompleteEvent event) { + String results = event.getResults(); + if (!results.contains("Failed to upload bundle file")) { + CoreGUI.getMessageCenter().notify(new Message("Uploaded bundle file successfully", Severity.Info)); + retrievalStatus(true); + } else { + CoreGUI.getMessageCenter().notify(new Message("Bundle file upload failed", Severity.Error)); + retrievalStatus(false); + } + } + }); + + addFormSubmitFailedHandler(new FormSubmitFailedHandler() { + public void onFormSubmitFailed(FormSubmitFailedEvent event) { + CoreGUI.getMessageCenter().notify(new Message("Bundle file upload failed", Severity.Error)); + retrievalStatus(false); + } + }); }
/** - * Call this when the file retrieval finished. <code>true</code> means successful, + * Call this when the last file retrieval status is known. <code>true</code> means successful, * <code>false</code> means an error occurred. * @param ok status */ - public void retrievalStatus(boolean ok) { + private void retrievalStatus(boolean ok) { + uploadResults = Boolean.valueOf(ok); + if (uploadButton != null) { FormItemIcon loadedIcon = new FormItemIcon(); if (ok) { loadedIcon.setSrc("/images/icons/availability_green_16.png"); - CoreGUI.getMessageCenter().notify(new Message("Uploaded bundle file successfully", Severity.Info)); } else { loadedIcon.setSrc("/images/icons/availability_red_16.png"); - CoreGUI.getMessageCenter().notify(new Message("Bundle file upload failed", Severity.Error)); } loadedIcon.setWidth(16); loadedIcon.setHeight(16); - uploadButton.setIcons(loadedIcon); - uploadButton.setShowIcons(true); + icon.setIcons(loadedIcon); + icon.setShowIcons(true); + uploadButton.setDisabled(uploadResults); } } }
rhq-commits@lists.fedorahosted.org