List of usage examples for com.google.gwt.user.client.ui FileUpload FileUpload
public FileUpload()
From source file:org.moxieapps.gwt.uploader.client.Uploader.java
License:Apache License
private FileUpload createFileUpload() { fileUpload = new FileUpload(); fileUpload.getElement().getStyle().setDisplay(Style.Display.NONE); if (fileTypes != null) { // Convert the format that the SWFUpload/Flash parameter expects to the W3C DOM standard // See: http://dev.w3.org/html5/spec/states-of-the-type-attribute.html#attr-input-accept // fileUpload.getElement().setAttribute("accept", this.fileTypes.replaceAll("\\;", ",").replaceAll("\\*\\.", ".")); // fileUpload.getElement().setAttribute("type", "file"); fileUpload.getElement().setAttribute("accept", "image/*"); fileUpload.getElement().setAttribute("capture", "camera"); // TODO: Need to consider validation of this in the file queued handler as well, as the browsers don't // appear to consistently support the "accept" attribute }//from www. j a v a 2s .co m final AbsolutePanel panel = this; fileUpload.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { JsArray selectedFiles = nativeGetSelectedFiles(fileUpload.getElement()); // Every time a file is selected replace the FileUpload component running in the DOM so that // the user can continue to attempt uploading the same file multiple times (otherwise the // "ChangeHandler" never fires) panel.remove(fileUpload); panel.add(createFileUpload()); addFilesToQueue(selectedFiles); } }); return fileUpload; }
From source file:org.ned.server.nedadminconsole.client.dialogs.NedAddNewLanguageDialog.java
License:Open Source License
public NedAddNewLanguageDialog(NedLanguageWidget nedLanguageWidget) { this.parent = nedLanguageWidget; VerticalPanel verticalPanelMain = new VerticalPanel(); setWidget(verticalPanelMain);/*from www.ja v a 2 s . co m*/ setHTML(NedRes.instance().userDlgAddNewLanguage()); uploadForm = new FormPanel(); uploadForm.setMethod(FormPanel.METHOD_POST); uploadForm.setAction("NedFileUploadServlet"); //TODO correct upload servlet uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); verticalPanelMain.add(uploadForm); Grid grid = new Grid(4, 2); uploadForm.setWidget(grid); grid.setSize("100%", "100%"); Label labelName = new Label(NedRes.instance().langName()); grid.setWidget(0, 0, labelName); TextBox textBoxName = new TextBox(); textBoxName.setName("languageName"); grid.setWidget(0, 1, textBoxName); Label labelLocale = new Label(NedRes.instance().langLocaleString()); grid.setWidget(1, 0, labelLocale); TextBox textBoxLocale = new TextBox(); textBoxLocale.setName("languageLocale"); grid.setWidget(1, 1, textBoxLocale); Label labelTranslationFile = new Label(NedRes.instance().langTranslationFile()); grid.setWidget(2, 0, labelTranslationFile); HorizontalPanel horizontalPanelUpload = new HorizontalPanel(); grid.setWidget(2, 1, horizontalPanelUpload); fileUpload = new FileUpload(); horizontalPanelUpload.add(fileUpload); fileUpload.setName("fileUpload"); HorizontalPanel horizontalPanel = new HorizontalPanel(); grid.setWidget(3, 1, horizontalPanel); grid.getCellFormatter().setWidth(3, 1, ""); horizontalPanel.setWidth("100%"); Button buttonUpload = new Button(NedRes.instance().add()); buttonUpload.addClickHandler(new ClickUploadHandler()); horizontalPanel.add(buttonUpload); buttonUpload.setWidth("90%"); horizontalPanel.setCellWidth(buttonUpload, "50%"); Button buttonCancel = new Button(NedRes.instance().cancel()); buttonCancel.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { hide(); } }); horizontalPanel.add(buttonCancel); buttonCancel.setWidth("90%"); horizontalPanel.setCellWidth(buttonCancel, "50%"); setPopupPosition(200, 200); uploadForm.addSubmitHandler(new SubmitHandlerUploadFile()); uploadForm.addSubmitCompleteHandler(new SubmitCompleteHandlerUploadFile()); center(); }
From source file:org.ned.server.nedadminconsole.client.dialogs.NedUploadDialog.java
License:Open Source License
public NedUploadDialog(String libId, NedDataModel model) { setSize("395px", "147px"); this.model = model; setHTML(NedRes.instance().uploadDlgUploadFile()); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); setWidget(verticalPanel);//www . j a v a2 s .c om verticalPanel.setSize("386px", "100px"); uploadForm = new FormPanel(); uploadForm.setAction("NedFileUploadServlet"); uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); uploadForm.setMethod(FormPanel.METHOD_POST); verticalPanel.add(uploadForm); uploadForm.setSize("100%", "100%"); VerticalPanel verticalPanel_1 = new VerticalPanel(); uploadForm.setWidget(verticalPanel_1); verticalPanel_1.setSize("100%", "77px"); horizontalPanel_2 = new HorizontalPanel(); verticalPanel_1.add(horizontalPanel_2); horizontalPanel_2.setWidth("100%"); fileUpload = new FileUpload(); horizontalPanel_2.add(fileUpload); horizontalPanel_2.setCellWidth(fileUpload, "100%"); fileUpload.setName("fileUpload"); verticalPanel_1.setCellHorizontalAlignment(fileUpload, HasHorizontalAlignment.ALIGN_CENTER); verticalPanel_1.setCellVerticalAlignment(fileUpload, HasVerticalAlignment.ALIGN_MIDDLE); fileUpload.setSize("100%", "30px"); hiddenLibId = new Hidden("libId"); horizontalPanel_2.add(hiddenLibId); hiddenLibId.setValue(libId); hiddenContentId = new Hidden("contentId"); horizontalPanel_2.add(hiddenContentId); hiddenContentId.setValue(model.getCurrentObject().id); HorizontalPanel horizontalPanel = new HorizontalPanel(); verticalPanel_1.add(horizontalPanel); horizontalPanel.setWidth("100%"); verticalPanel_1.setCellHorizontalAlignment(horizontalPanel, HasHorizontalAlignment.ALIGN_CENTER); Button uploadBtn = new Button(NedRes.instance().uploadDlgUpload()); horizontalPanel.add(uploadBtn); uploadBtn.setWidth("90%"); horizontalPanel.setCellWidth(uploadBtn, "50%"); horizontalPanel.setCellHorizontalAlignment(uploadBtn, HasHorizontalAlignment.ALIGN_CENTER); horizontalPanel.setCellVerticalAlignment(uploadBtn, HasVerticalAlignment.ALIGN_MIDDLE); uploadBtn.addClickHandler(new UploadFileClickHandler()); verticalPanel.setCellVerticalAlignment(uploadBtn, HasVerticalAlignment.ALIGN_MIDDLE); verticalPanel.setCellHorizontalAlignment(uploadBtn, HasHorizontalAlignment.ALIGN_CENTER); closeBtn = new Button(NedRes.instance().close()); horizontalPanel.add(closeBtn); closeBtn.setWidth("90%"); horizontalPanel.setCellWidth(closeBtn, "50%"); horizontalPanel.setCellVerticalAlignment(closeBtn, HasVerticalAlignment.ALIGN_MIDDLE); horizontalPanel.setCellHorizontalAlignment(closeBtn, HasHorizontalAlignment.ALIGN_CENTER); closeBtn.addClickHandler(new CloseClickHandler()); setPopupPosition(200, 200); uploadForm.addSubmitHandler(new SubmitHandlerUploadFile()); uploadForm.addSubmitCompleteHandler(new SubmitCompleteHandlerUploadFile()); center(); }
From source file:org.openremote.app.client.widget.FileUploadLabelled.java
License:Open Source License
public FileUploadLabelled() { wrapper = Document.get().createElement(LabelElement.TAG); setElement(wrapper);/*w w w . j av a 2s. c o m*/ fileUpload = new FileUpload(); add(fileUpload, wrapper); label = new FormInlineLabel(); add(label, wrapper); }
From source file:org.openxdata.sharedlib.client.view.OpenFileDialog.java
/** * Sets up the widgets./*from w ww .j a v a 2 s . c o m*/ * * @param url the url to post to. */ public void initWidgets(String url) { actionUrl = url; form.setAction(actionUrl); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.setSpacing(20); form.add(verticalPanel); fileUpload = new FileUpload(); fileUpload.setName("filecontents"); verticalPanel.add(fileUpload); HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.setWidth("100%"); horizontalPanel.setHeight("100%"); horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); Button button = new Button(constants.open(), new ClickHandler() { public void onClick(ClickEvent event) { String action = actionUrl; if (action.contains("?")) action += "&"; else action += "?"; action += "pathname=" + fileUpload.getFilename(); //action += "&time="+ new java.util.Date().getTime(); form.setAction(action); form.submit(); //hide(); FormUtil.dlg.setText(constants.processingMsg()); FormUtil.dlg.center(); } }); horizontalPanel.add(button); horizontalPanel.setCellHorizontalAlignment(button, HasHorizontalAlignment.ALIGN_LEFT); button = new Button(constants.cancel(), new ClickHandler() { public void onClick(ClickEvent event) { hide(); FormUtil.dlg.hide(); } }); horizontalPanel.add(button); horizontalPanel.setCellHorizontalAlignment(button, HasHorizontalAlignment.ALIGN_RIGHT); verticalPanel.add(horizontalPanel); setWidget(form); form.addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(FormPanel.SubmitCompleteEvent event) { eventListener.onSetFileContents(event.getResults()); hide(); FormUtil.dlg.hide(); } }); setText(constants.openFile()); }
From source file:org.otalo.ao.client.UploadDialog.java
License:Apache License
public UploadDialog() { setText("Record or Upload Content"); outer = new FlexTable(); outer.setSize("100%", "100%"); uploadForm.setAction(JSONRequest.BASE_URL + AoAPI.RECORD_OR_UPLOAD); uploadForm.setMethod(FormPanel.METHOD_POST); uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART); main = new FileUpload(); main.setName("main"); main.setTitle("Content"); mainLabel = new Label("Content:"); number = new TextBox(); number.setName("number"); User moderator = Messages.get().getModerator(); if (moderator != null) // default is the moderator's number number.setValue(moderator.getNumber()); Label numberLabel = new Label("Author Number:"); saveButton = new Button("Save", new ClickHandler() { public void onClick(ClickEvent event) { if (!recorder.isRecorded() && !uploadOpt.getValue()) setErrorMsg("Please either record message or upload it first!"); else { setClickedButton();//w w w. ja va 2 s . c o m if (recordOpt.getValue() == true) { recorder.uploadData(getParams()); } else { uploadForm.submit(); } } } }); cancelButton = new Anchor("Cancel"); cancelButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (recorder.isRecorded()) recorder.stopRecording(); hide(); } }); recordOpt = new RadioButton("options", "Record"); recordOpt.setFormValue("record"); recordOpt.addStyleName("label-txt"); recordOpt.setValue(true); recordOpt.addClickHandler(new OptionClickHandler()); uploadOpt = new RadioButton("options", "Upload"); uploadOpt.setFormValue("upload"); uploadOpt.setValue(false); uploadOpt.addStyleName("label-txt"); uploadOpt.addClickHandler(new OptionClickHandler()); outer.setWidget(1, 0, recordOpt); mainMsgHTML = new HTML("<span id='recordError'></span>"); mainMsgHTML.addStyleName("upload-top-msg"); outer.setWidget(1, 1, mainMsgHTML); outer.getCellFormatter().getElement(1, 1).getStyle().setTextAlign(TextAlign.JUSTIFY); outer.getCellFormatter().getElement(1, 0).getStyle().setTextAlign(TextAlign.LEFT); //creating recorder widget recorder = new AudioRecorderWidget(JSONRequest.BASE_URL + AoAPI.RECORD_OR_UPLOAD, this); outer.setWidget(2, 0, recorder); outer.getFlexCellFormatter().setColSpan(2, 0, 2); outer.setWidget(4, 0, uploadOpt); outer.getFlexCellFormatter().setColSpan(4, 0, 2); outer.getCellFormatter().getElement(4, 0).getStyle().setTextAlign(TextAlign.LEFT); outer.setWidget(5, 0, mainLabel); outer.getCellFormatter().setWordWrap(0, 0, false); outer.getCellFormatter().setStyleName(5, 0, "left-align"); contentPanel.setSpacing(2); DOM.setStyleAttribute(contentPanel.getElement(), "textAlign", "left"); contentPanel.add(main); outer.setWidget(5, 1, contentPanel); outer.getCellFormatter().setStyleName(5, 1, "left-align-no-margin"); main.setEnabled(false); mainLabel.addStyleName("gray-text"); if (Messages.get().canManage()) { // no author number; but future date option is available // Label dateLabel = new Label("Broadcast Time: "); // Note on bcasting date Label dateNote = new Label("Your broadcast will begin 10-15 minutes from the time you specify here"); dateNote.setStyleName("helptext"); // Start now option now = new RadioButton("when", "Now"); now.setFormValue("now"); date = new RadioButton("when"); date.setFormValue("date"); // Date Box dateBox = new DateBox(); dateBox.setFormat(new DateBox.DefaultFormat(dateFormat)); dateBox.addValueChangeHandler(new ValueChangeHandler<Date>() { public void onValueChange(ValueChangeEvent<Date> event) { now.setValue(false); date.setValue(true); Date d = event.getValue(); dateField.setValue(DateTimeFormat.getFormat("MMM-dd-yyyy").format(d)); } }); // Hour box hour = new ListBox(); hour.setName("hour"); for (int i = 0; i < 24; i++) { String hourStr; if (i < 10) hourStr = "0" + String.valueOf(i); else hourStr = String.valueOf(i); hour.addItem(hourStr); } hour.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { now.setValue(false); date.setValue(true); } }); // Minute box min = new ListBox(); min.setName("min"); for (int i = 0; i < 60; i += 5) { String minStr; if (i < 10) minStr = "0" + String.valueOf(i); else minStr = String.valueOf(i); min.addItem(minStr); } min.addChangeHandler(new ChangeHandler() { public void onChange(ChangeEvent event) { now.setValue(false); date.setValue(true); } }); int row = outer.getRowCount(); outer.setWidget(row, 0, dateLabel); outer.getCellFormatter().setWordWrap(1, 0, false); HorizontalPanel nowPanel = new HorizontalPanel(); //nowPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); nowPanel.setSpacing(4); nowPanel.add(now); DOM.setStyleAttribute(nowPanel.getElement(), "textAlign", "left"); outer.setWidget(row, 1, nowPanel); HorizontalPanel datePicker = new HorizontalPanel(); datePicker.setSpacing(4); datePicker.add(date); datePicker.add(dateBox); datePicker.add(hour); datePicker.add(new Label(":")); datePicker.add(min); row = outer.getRowCount(); datePanel = new HorizontalPanel(); outer.setWidget(row, 0, datePanel); DOM.setStyleAttribute(datePicker.getElement(), "textAlign", "left"); outer.setWidget(row, 1, datePicker); row = outer.getRowCount(); outer.setWidget(row, 1, dateNote); outer.getCellFormatter().setWordWrap(row, 1, false); dateField = new Hidden("date"); outer.setWidget(outer.getRowCount(), 0, dateField); } else { outer.setWidget(7, 0, numberLabel); outer.getCellFormatter().setWordWrap(1, 0, false); numberPanel.setSpacing(2); DOM.setStyleAttribute(numberPanel.getElement(), "textAlign", "left"); numberPanel.add(number); outer.setWidget(7, 1, numberPanel); } HorizontalPanel buttons = new HorizontalPanel(); // tables don't obey the setHorizontal of parents, and buttons is a table, // so use float instead DOM.setStyleAttribute(buttons.getElement(), "cssFloat", "right"); buttons.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); buttons.add(cancelButton); buttons.add(saveButton); outer.setWidget(outer.getRowCount(), 1, buttons); outer.setWidget(outer.getRowCount(), 0, forumId); outer.setWidget(outer.getRowCount(), 0, messageForumId); HTML troubleShootLink = new HTML( "<a class='trblLink' target=_blank href='http://awaaz.de/blog/2013/10/record-your-messages-over-web'>Unable to record? Complete the one-time setup instructions</a>"); int trblCell = outer.getRowCount(); outer.setWidget(trblCell, 0, troubleShootLink); outer.getFlexCellFormatter().setColSpan(trblCell, 0, 2); outer.getFlexCellFormatter().addStyleName(trblCell, 0, "left-align"); HTML brodtime_text = new HTML( "<span>Broadcast calls will only be scheduled between 8am and 10pm IST.</span>"); brodtime_text.addStyleName("brodcast-time-text"); outer.setWidget(trblCell + 1, 0, brodtime_text); outer.getFlexCellFormatter().setColSpan(trblCell + 1, 0, 2); outer.getFlexCellFormatter().addStyleName(trblCell + 1, 0, "left-align"); uploadForm.setWidget(outer); setSaveButtonSate(); setWidget(uploadForm); }
From source file:org.ow2.proactive_grid_cloud_portal.common.client.CredentialsWindow.java
License:Open Source License
private void build() { /* smartGWT forms don't allow simple multipart file upload, * so we use a smartGWT form for login/password/checkbox, * a pure GWT form for file upload, and upon submission, * put the fields from the first form as hidden fields of the * pure GWT form. It's a bit convoluted but like this we get * the pretty widgets and the nice features */ TextItem loginField = new TextItem("login", "Login"); loginField.setRequired(true);//from w w w.j av a 2 s . com PasswordItem passwordField = new PasswordItem("password", "Password"); passwordField.setRequired(true); final CheckboxItem moreField = new CheckboxItem("useSSH", "Use SSH private key"); moreField.setValue(false); // smartGWT form: only used to input the data before filling the hidden fields // in the other form with it final DynamicForm form = new DynamicForm(); form.setFields(loginField, passwordField, moreField); // pure GWT form for uploading, will be used to contact the servlet // even if no ssh key is used final FileUpload fileUpload = new FileUpload(); fileUpload.setName("sshkey"); final Hidden hiddenUser = new Hidden("username"); final Hidden hiddenPass = new Hidden("password"); final FormPanel formPanel = new FormPanel(); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setAction(GWT.getModuleBaseURL() + "createcredential"); final VerticalPanel vpan = new VerticalPanel(); vpan.add(hiddenUser); vpan.add(hiddenPass); vpan.add(fileUpload); formPanel.setWidget(vpan); formPanel.setWidth("100%"); formPanel.setHeight("30px"); final HLayout formWrapper = new HLayout(); formWrapper.setAlign(Alignment.CENTER); formWrapper.addChild(formPanel); formWrapper.setWidth100(); formWrapper.addDrawHandler(new DrawHandler() { public void onDraw(DrawEvent event) { // took me half a day to find this hack: // if the form is added to the page in a hidden element, // it is never created and submission fails without callback. // it needs to be visible so that it is created once, then // we can safely hide it and still use it if (disableFormWrapper) { disableFormWrapper = false; formWrapper.setVisible(false); } } }); // hide/show the ssh key upload input moreField.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent event) { if (moreField.getValueAsBoolean()) { formWrapper.setVisible(true); } else { formWrapper.setVisible(false); formPanel.reset(); } } }); // prevent form validation if no ssh key is selected Validator moreVal = new CustomValidator() { @Override protected boolean condition(Object value) { if (moreField.getValueAsBoolean()) { String file = fileUpload.getFilename(); return (file != null && file.length() > 0); } else { return true; } } }; moreVal.setErrorMessage("No file selected"); moreField.setValidators(moreVal); final IButton clearButton = new IButton("Clear"); clearButton.setIcon(Images.instance.clear_16().getSafeUri().asString()); clearButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { form.clearValues(); formPanel.reset(); formWrapper.setVisible(false); } }); final IButton closeButton = new IButton("Close"); final Label label = new Label("A Credential is a file containing all information used" + " for authentication, in an encrypted form. It allows easier authentication and" + " automation."); label.setHeight(50); final HLayout buttonBar = new HLayout(); final IButton okButton = new IButton(); okButton.setShowDisabled(false); okButton.setIcon(Images.instance.ok_16().getSafeUri().asString()); okButton.setTitle("Create"); okButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (!form.validate()) return; String login = form.getValueAsString("login"); String pw = form.getValueAsString("password"); hiddenUser.setValue(login); hiddenPass.setValue(pw); formPanel.submit(); } }); closeButton.setIcon(Images.instance.cancel_16().getSafeUri().asString()); closeButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { CredentialsWindow.this.window.hide(); CredentialsWindow.this.destroy(); } }); formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { /* this happens only on error, if the call succeeds, * the response is relocated so that a 'save file' dialog appears */ String str = event.getResults(); label.setContents("<span style='color:red;'>" + str + "</span>"); } }); Layout formLayout = new VLayout(); formLayout.setHeight100(); formLayout.setWidth100(); formLayout.setMembersMargin(10); formLayout.addMember(form); formLayout.addMember(formWrapper); buttonBar.setWidth100(); buttonBar.setAlign(Alignment.RIGHT); buttonBar.setMembersMargin(5); buttonBar.setMembers(clearButton, okButton, closeButton); formLayout.addMember(buttonBar); VLayout layout = new VLayout(); layout.setMembersMargin(10); layout.setMargin(5); layout.setMembers(label, formLayout, buttonBar); this.window = new Window(); this.window.setTitle("Create Credentials"); this.window.setShowMinimizeButton(false); this.window.setIsModal(true); this.window.setShowModalMask(true); this.window.addItem(layout); this.window.setWidth(370); this.window.setHeight(260); this.window.centerInPage(); }
From source file:org.ow2.proactive_grid_cloud_portal.common.client.LoginPage.java
License:Open Source License
/** * @return the forms and widgets for plain login/password authentication */// ww w .j a v a 2 s. com private Layout getPlainAuth() { /* smartGWT forms don't allow simple multipart file upload, * so we use a smartGWT form for login/password/checkbox, * a pure GWT form for file upload, and upon submission, * put the fields from the first form as hidden fields of the * pure GWT form. It's a bit convoluted but like this we get * the pretty widgets and the nice features */ TextItem loginField = new TextItem("login", "User"); loginField.setRequired(true); PasswordItem passwordField = new PasswordItem("password", "Password"); passwordField.setRequired(true); final CheckboxItem moreField = new CheckboxItem("useSSH", "Use SSH private key"); moreField.setValue(false); // smartGWT form: only used to input the data before filling the hidden fields // in the other form with it final DynamicForm form = new DynamicForm(); form.setFields(loginField, passwordField, moreField); form.hideItem("useSSH"); // pure GWT form for uploading, will be used to contact the servlet // even if no ssh key is used final FileUpload fileUpload = new FileUpload(); fileUpload.setName("sshkey"); final Hidden hiddenUser = new Hidden("username"); final Hidden hiddenPass = new Hidden("password"); final FormPanel formPanel = new FormPanel(); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setAction(GWT.getModuleBaseURL() + "login"); final VerticalPanel vpan = new VerticalPanel(); vpan.add(hiddenUser); vpan.add(hiddenPass); vpan.add(fileUpload); formPanel.setWidget(vpan); formPanel.setWidth("100%"); formPanel.setHeight("30px"); final HLayout formWrapper = new HLayout(); formWrapper.setAlign(Alignment.CENTER); formWrapper.addChild(formPanel); formWrapper.setWidth100(); formWrapper.addDrawHandler(new DrawHandler() { public void onDraw(DrawEvent event) { // took me half a day to find this hack: // if the form is added to the page in a hidden element, // it is never created and submission fails without callback. // it needs to be visible so that it is created once, then // we can safely hide it and still use it if (disableFormWrapper) { disableFormWrapper = false; formWrapper.setVisible(false); } } }); // hide/show the ssh key upload input moreField.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent event) { if (moreField.getValueAsBoolean()) { //formWrapper.setVisible(true); formWrapper.animateShow(AnimationEffect.FLY); } else { //formWrapper.setVisible(false); formWrapper.animateHide(AnimationEffect.FLY); formPanel.reset(); } } }); // prevent form validation if no ssh key is selected Validator moreVal = new CustomValidator() { @Override protected boolean condition(Object value) { if (moreField.getValueAsBoolean()) { String file = fileUpload.getFilename(); return (file != null && file.length() > 0); } else { return true; } } }; moreVal.setErrorMessage("No file selected"); moreField.setValidators(moreVal); final Runnable advancedVisibilityChanged = new Runnable() { @Override public void run() { if (!moreField.getVisible()) { authSelLayout.setVisible(true); form.showItem("useSSH"); optsLabel.setIcon(Images.instance.close_16().getSafeUri().asString()); optsLabel.setContents( "<nobr style='color:#003168;font-size: 1.2em;" + "cursor:pointer'>less options</nobr>"); } else { authTypeSelectForm.setValue("Mode", "Basic"); switchPlainCredForm.run(); authSelLayout.setVisible(false); form.hideItem("useSSH"); formWrapper.animateHide(AnimationEffect.FLY); moreField.setValue(false); formPanel.reset(); optsLabel.setIcon(Images.instance.expand_16().getSafeUri().asString()); optsLabel.setContents( "<nobr style='color:#003168;font-size: 1.2em;" + "cursor:pointer'>more options</nobr>"); } } }; optsLabel.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { advancedVisibilityChanged.run(); } }); String cacheLogin = Settings.get().getSetting(controller.getLoginSettingKey()); if (cacheLogin != null) { form.setValue("login", cacheLogin); } final IButton okButton = new IButton(); okButton.setShowDisabled(false); okButton.setIcon(Images.instance.connect_16().getSafeUri().asString()); okButton.setTitle("Connect"); okButton.setWidth(120); okButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (!form.validate()) return; String login = form.getValueAsString("login"); String pw = form.getValueAsString("password"); hiddenUser.setValue(login); hiddenPass.setValue(pw); okButton.setIcon("loading.gif"); okButton.setTitle("Connecting..."); form.disable(); formWrapper.disable(); authTypeSelectForm.disable(); okButton.disable(); // only submit once the the error message is hidden so we don't try to show it (on form response) // while the effect is played resulting in the message hidden staying hidden if (errorLabel.isDrawn() && errorLabel.isVisible()) { errorLabel.animateHide(AnimationEffect.FLY, new AnimationCallback() { @Override public void execute(boolean earlyFinish) { formPanel.submit(); } }); } else { formPanel.submit(); } } }); formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { String res = new HTML(event.getResults()).getText(); boolean fail = false; try { JSONValue val = controller.parseJSON(res); JSONObject obj = val.isObject(); if (obj != null && obj.containsKey("sessionId")) { String sess = obj.isObject().get("sessionId").isString().stringValue(); controller.login(sess, form.getValueAsString("login")); } else { fail = true; } } catch (Throwable t) { fail = true; } if (fail) { String err = JSONUtils.getJsonErrorMessage(res); int sta = JSONUtils.getJsonErrorCode(res); if (sta != -1) err += " (" + sta + ")"; errorLabel.setContents("<span style='color:red;'>Could not login: " + err + "</span>"); errorLabel.animateShow(AnimationEffect.FLY); okButton.setIcon(Images.instance.connect_16().getSafeUri().asString()); okButton.setTitle("Connect"); formWrapper.enable(); form.enable(); authTypeSelectForm.enable(); okButton.enable(); } } }); form.addItemKeyPressHandler(new ItemKeyPressHandler() { public void onItemKeyPress(ItemKeyPressEvent event) { if ("Enter".equals(event.getKeyName())) { okButton.fireEvent(new ClickEvent(null)); } } }); Layout formLayout = new VLayout(); formLayout.setWidth100(); formLayout.setMembersMargin(10); formLayout.addMember(form); formLayout.addMember(formWrapper); HLayout buttonBar = new HLayout(); buttonBar.setWidth100(); buttonBar.setAlign(Alignment.CENTER); buttonBar.addMember(okButton); formLayout.addMember(buttonBar); return formLayout; }
From source file:org.ow2.proactive_grid_cloud_portal.common.client.LoginPage.java
License:Open Source License
/** * @return the forms and widgets for credentials authentication *//*from w ww . jav a 2s . c o m*/ private Layout getCredAuth() { final FileUpload fileUpload = new FileUpload(); fileUpload.setName("credential"); // actual form final FormPanel formPanel = new FormPanel(); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setAction(GWT.getModuleBaseURL() + "login"); formPanel.add(fileUpload); formPanel.setWidth("100%"); formPanel.setHeight("30px"); // wraps the GWT component so that we may show/hide it final VLayout formWrapper = new VLayout(); formWrapper.setAlign(Alignment.CENTER); formWrapper.addMember(formPanel); formWrapper.setWidth100(); formWrapper.setMargin(10); final IButton okButton = new IButton(); okButton.setShowDisabled(false); okButton.setIcon(Images.instance.connect_16().getSafeUri().asString()); okButton.setTitle("Connect"); okButton.setWidth(120); okButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { errorLabel.animateHide(AnimationEffect.FLY); okButton.setIcon("loading.gif"); okButton.setTitle("Connecting..."); formWrapper.disable(); authTypeSelectForm.disable(); okButton.disable(); // submits the form to LoginServlet formPanel.submit(); } }); formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { String res = event.getResults(); boolean fail = false; try { JSONValue val = controller.parseJSON(res); JSONObject obj = val.isObject(); if (obj != null && obj.containsKey("sessionId")) { String sess = obj.isObject().get("sessionId").isString().stringValue(); controller.login(sess, null); } else { fail = true; } } catch (Throwable t) { fail = true; } if (fail) { String err = JSONUtils.getJsonErrorMessage(res); errorLabel.setContents("<span style='color:red;'>Could not login: " + err + "</span>"); errorLabel.animateShow(AnimationEffect.FLY); okButton.setIcon(Images.instance.connect_16().getSafeUri().asString()); okButton.setTitle("Connect"); formWrapper.enable(); authTypeSelectForm.enable(); okButton.enable(); } } }); Label createCred = new Label( "<nobr style='color:#003168;font-size: 1.2em;cursor:pointer'>" + "Create credentials</nobr>"); createCred.setHeight(20); createCred.setAlign(Alignment.CENTER); createCred.setIcon(Images.instance.key_16().getSafeUri().asString()); createCred.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { CredentialsWindow win = new CredentialsWindow(); win.show(); } }); formWrapper.addMember(createCred); Layout formLayout = new VLayout(); formLayout.setWidth100(); formLayout.setMembersMargin(10); formLayout.addMember(formWrapper); HLayout buttonBar = new HLayout(); buttonBar.setWidth100(); buttonBar.setAlign(Alignment.CENTER); buttonBar.addMember(okButton); formLayout.addMember(buttonBar); return formLayout; }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.ImportFromFilePanel.java
License:Open Source License
private FileUpload getFileUploadItem() { FileUpload fileUpload = new FileUpload(); fileUpload.setName(FILE_OPTION_NAME); fileUpload.addChangeHandler(onFileChosen -> { if (!fileUpload.getFilename().isEmpty()) { submit();/*ww w. java 2 s .co m*/ } }); return fileUpload; }