List of usage examples for com.google.gwt.user.client.ui FileUpload wrap
public static FileUpload wrap(Element element)
From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java
License:Apache License
/** preserves event handlers on element to be wrapped */ public static Widget elementToWidget(Element e, String typ) { Widget result = null;/*from ww w . j a v a 2 s . c o m*/ if (e != null) { int eventsSunk = DOM.getEventsSunk(e); EventListener el = DOM.getEventListener(e); if (typ == TEXT) result = TextBox.wrap(e); else if (typ == TEXT_AREA) result = TextArea.wrap(e); else if (typ == PASSWORD) result = PasswordTextBox.wrap(e); else if (typ == LABEL) result = Label.wrap(e); else if (typ == A) result = Anchor.wrap(e); else if (typ == IMAGE) result = Image.wrap(e); else if (typ == SELECT) result = ListBox.wrap(e); else if (typ == HIDDEN) result = Hidden.wrap(e); else if (typ == FILE) result = FileUpload.wrap(e); else if (typ == FORM) result = FormPanel.wrap(e, true); else if (typ == FRAME) result = Frame.wrap(e); else if (typ == SUBMIT) result = SubmitButton.wrap(e); else if (typ == BUTTON) result = Button.wrap(e); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); DOM.sinkEvents(e, eventsSunk); DOM.setEventListener(e, el); } else { if (typ == TEXT) result = new TextBox(); else if (typ == TEXT_AREA) result = new TextArea(); else if (typ == PASSWORD) result = new PasswordTextBox(); else if (typ == LABEL) result = new Label(); else if (typ == A) result = new Anchor(); else if (typ == SELECT) result = new ListBox(); else if (typ == IMAGE) result = new Image(); else if (typ == HIDDEN) result = new Hidden(); else if (typ == FILE) result = new FileUpload(); else if (typ == FORM) result = new FormPanel(); else if (typ == FRAME) result = new Frame(); else if (typ == SUBMIT) result = new SubmitButton(); else if (typ == BUTTON) result = new Button(); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); } return result; }
From source file:com.eduworks.gwt.client.pagebuilder.PageAssembler.java
License:Apache License
/** preserves event handlers on element to be wrapped */ public static Widget elementToWidget(String elementName, String typ) { Widget result = null;/* w w w . j av a 2 s. co m*/ Element e = DOM.getElementById(elementName); if (e != null) { int eventsSunk = DOM.getEventsSunk(e); EventListener el = DOM.getEventListener(e); if (typ == TEXT) result = TextBox.wrap(e); else if (typ == TEXT_AREA) result = TextArea.wrap(e); else if (typ == PASSWORD) result = PasswordTextBox.wrap(e); else if (typ == LABEL) result = Label.wrap(e); else if (typ == A) result = Anchor.wrap(e); else if (typ == SELECT) result = ListBox.wrap(e); else if (typ == IMAGE) result = Image.wrap(e); else if (typ == HIDDEN) result = Hidden.wrap(e); else if (typ == FILE) result = FileUpload.wrap(e); else if (typ == FORM) result = FormPanel.wrap(e, true); else if (typ == FRAME) result = Frame.wrap(e); else if (typ == SUBMIT) result = SubmitButton.wrap(e); else if (typ == BUTTON) result = Button.wrap(e); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); DOM.sinkEvents(e, eventsSunk); DOM.setEventListener(e, el); } else { if (typ == TEXT) result = new TextBox(); else if (typ == TEXT_AREA) result = new TextArea(); else if (typ == PASSWORD) result = new PasswordTextBox(); else if (typ == LABEL) result = new Label(); else if (typ == A) result = new Anchor(); else if (typ == IMAGE) result = new Image(); else if (typ == SELECT) result = new ListBox(); else if (typ == HIDDEN) result = new Hidden(); else if (typ == FILE) result = new FileUpload(); else if (typ == FORM) result = new FormPanel(); else if (typ == FRAME) result = new Frame(); else if (typ == SUBMIT) result = new SubmitButton(); else if (typ == BUTTON) result = new Button(); else if (typ == CHECK_BOX) result = SimpleCheckBox.wrap(e); } return result; }
From source file:fr.gael.dhus.gwt.client.page.UploadPage.java
License:Open Source License
private static void init() { showUpload();/* ww w .j a v a2 s. c o m*/ uploadProductFile = FileUpload.wrap(RootPanel.get("upload_productFile").getElement()); final Hidden collectionsField = Hidden.wrap(RootPanel.get("upload_collections").getElement()); uploadButton = RootPanel.get("upload_uploadButton"); url = TextBox.wrap(RootPanel.get("upload_url").getElement()); username = TextBox.wrap(RootPanel.get("upload_username").getElement()); pattern = TextBox.wrap(RootPanel.get("upload_pattern").getElement()); patternResult = RootPanel.get("upload_patternResult"); password = PasswordTextBox.wrap(RootPanel.get("upload_password").getElement()); scanButton = RootPanel.get("upload_scanButton"); stopButton = RootPanel.get("upload_stopButton"); addButton = RootPanel.get("upload_addButton"); cancelButton = RootPanel.get("upload_cancelButton"); deleteButton = RootPanel.get("upload_deleteButton"); saveButton = RootPanel.get("upload_saveButton"); status = RootPanel.get("upload_status"); refreshButton = RootPanel.get("upload_refreshButton"); scannerInfos = RootPanel.get("upload_scannerInfos"); uploadForm = new FormPanel(); uploadForm.setAction(GWT.getHostPageBaseURL() + "/api/upload"); uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); uploadForm.setMethod(FormPanel.METHOD_POST); uploadForm.setWidget(RootPanel.get("upload_form")); RootPanel.get("upload_product").add(uploadForm); selectedCollections = new ArrayList<Long>(); uploadButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (uploadButton.getElement().getClassName().contains("disabled")) { return; } String filename = uploadProductFile.getFilename(); if (filename.length() == 0) { Window.alert("No file selected!"); } else { DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "wait"); String collections = ""; if (selectedCollections != null && !selectedCollections.isEmpty()) { for (Long cId : selectedCollections) { collections += cId + ","; } collections = collections.substring(0, collections.length() - 1); } collectionsField.setValue(collections); uploadForm.submit(); setState(State.UPLOADING); } } }, ClickEvent.getType()); uploadForm.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent event) { RegExp regexp = RegExp.compile(".*HTTP Status ([0-9]+).*"); Integer errCode = null; try { errCode = new Integer(regexp.exec(event.getResults()).getGroup(1)); } catch (Exception e) { } if (errCode == null) { Window.alert("Your product has been successfully uploaded."); } else { switch (errCode) { case 400: Window.alert("Your request is missing a product file to upload."); break; case 403: Window.alert("You are not allowed to upload a file on Sentinel Data Hub."); break; case 406: Window.alert("Your product was not added. It can not be read by the system."); break; case 415: Window.alert("Request contents type is not supported by the servlet."); break; case 500: Window.alert("An error occurred while creating the file."); break; default: Window.alert("There was an untraceable error while uploading your product."); break; } } DOM.setStyleAttribute(RootPanel.getBodyElement(), "cursor", "default"); setState(State.DEFAULT); } }); addButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (addButton.getElement().getClassName().contains("disabled")) { return; } uploadService.addFileScanner(url.getValue(), username.getValue(), password.getValue(), pattern.getValue(), selectedCollections, new AccessDeniedRedirectionCallback<Long>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error during adding '" + url.getValue() + "' to your file scanners.\n" + caught.getMessage()); } @Override public void onSuccess(Long result) { setState(State.ADDING_FILESCANNER); setState(State.DEFAULT); } }); } }, ClickEvent.getType()); scanButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (scanButton.getElement().getClassName().contains("disabled")) { return; } if (state == State.EDIT_FILESCANNER && editedScannerId != null) { uploadService.updateFileScanner(new Long(editedScannerId.longValue()), url.getValue(), username.getValue(), password.getValue(), pattern.getValue(), selectedCollections, new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error during adding '" + url.getValue() + "' to your file scanners.\n" + caught.getMessage()); } @Override public void onSuccess(Void scanId) { // final String sUrl = url.getValue(); setState(State.DEFAULT); uploadService.processScan(new Long(editedScannerId.longValue()), new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { } @Override public void onSuccess(Void result) { } }); } }); } else { uploadService.addFileScanner(url.getValue(), username.getValue(), password.getValue(), pattern.getValue(), selectedCollections, new AccessDeniedRedirectionCallback<Long>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error during adding '" + url.getValue() + "' to your file scanners.\n" + caught.getMessage()); } @Override public void onSuccess(Long scanId) { // final String sUrl = url.getValue(); setState(State.ADDING_FILESCANNER); setState(State.DEFAULT); uploadService.processScan(scanId, new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { } @Override public void onSuccess(Void result) { } }); } }); } } }, ClickEvent.getType()); stopButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (stopButton.getElement().getClassName().contains("disabled")) { return; } uploadService.stopScan(new Long(editedScannerId.longValue()), new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { } @Override public void onSuccess(Void result) { setState(State.ADDING_FILESCANNER); setState(State.DEFAULT); } }); } }, ClickEvent.getType()); cancelButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (cancelButton.getElement().getClassName().contains("disabled")) { return; } setDefaultState(); } }, ClickEvent.getType()); refreshButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (refreshButton.getElement().getClassName().contains("disabled")) { return; } refreshScanners(); } }, ClickEvent.getType()); deleteButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (deleteButton.getElement().getClassName().contains("disabled") && editedScannerId != null) { return; } removeScanner(editedScannerId); } }, ClickEvent.getType()); saveButton.addDomHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (saveButton.getElement().getClassName().contains("disabled")) { return; } uploadService.updateFileScanner(new Long(editedScannerId), url.getValue(), username.getValue(), password.getValue(), pattern.getValue(), selectedCollections, new AccessDeniedRedirectionCallback<Void>() { @Override public void _onFailure(Throwable caught) { Window.alert("There was an error while updating your file scanner.\n" + caught.getMessage()); } @Override public void onSuccess(Void result) { setDefaultState(); } }); } }, ClickEvent.getType()); refresh(); }