List of usage examples for com.google.gwt.user.client.ui FormPanel METHOD_POST
String METHOD_POST
To view the source code for com.google.gwt.user.client.ui FormPanel METHOD_POST.
Click Source Link
From source file:org.openxdata.sharedlib.client.view.SaveFileDialog.java
public void initWidgets(String url, String data, String fileName) { actionUrl = url;/*from w w w . j ava 2 s. co m*/ form.setAction(actionUrl); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); VerticalPanel verticalPanel = new VerticalPanel(); verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); verticalPanel.setSpacing(10); form.add(verticalPanel); txtArea = new TextArea(); txtArea.setText(data); txtArea.setName("filecontents"); txtArea.setVisible(false); txtName = new TextBox(); txtName.setText(fileName); txtName.setName("filename"); txtName.setWidth("250" + OpenXdataConstants.UNITS); verticalPanel.add(txtName); verticalPanel.add(txtArea); HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.setWidth("100%"); horizontalPanel.setHeight("100%"); horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); Button button = new Button(constants.save(), new ClickHandler() { public void onClick(ClickEvent event) { String fileName = txtName.getText(); if (fileName != null && fileName.trim().length() > 0) { String action = actionUrl; if (action.contains("?")) action += "&"; else action += "?"; action += "filename=" + fileName; form.setAction(action); ((VerticalPanel) txtName.getParent()).add(txtArea); 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) { hide(); FormUtil.dlg.hide(); Window.Location.replace(form.getAction()); } }); setText(constants.saveFileAs()); }
From source file:org.otalo.ao.client.MessageDetail.java
License:Apache License
public MessageDetail() { outer = new HorizontalPanel(); outer.setSize("100%", "100%"); detailsForm = new FormPanel(); detailsForm.setWidget(outer);/*from w ww .ja va 2s .c om*/ detailsForm.setMethod(FormPanel.METHOD_POST); detailsForm.setEncoding(FormPanel.ENCODING_MULTIPART); // TODO if needed //detailsForm.addSubmitHandler(new CallerDetailsUpdate()); detailsForm.addSubmitCompleteHandler(new MessageDetailsUpdate()); threadPanel = new DockPanel(); controls = new VerticalPanel(); detailsTable = new FlexTable(); metadata = new VerticalPanel(); metadata.setHeight("100%"); tags = new AutoCompleteTagWidget(true, true); tags.setWidth("300px"); routing = new AORoutingWidget(); metadata.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); metadata.add(tags); metadata.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); metadata.add(routing); outer.setSpacing(3); outer.add(detailsTable); outer.add(threadPanel); outer.add(metadata); outer.add(controls); controls.setSize("100%", "100%"); Label detailsTitle = new Label("Caller Details"); detailsTitle.setStyleName("gwt-Label"); detailsTable.setWidget(0, 0, detailsTitle); detailsTable.getFlexCellFormatter().setColSpan(0, 0, 2); addCallerDetailsField(detailsTable, "Number", "number"); addCallerDetailsField(detailsTable, "Name", "name"); addCallerDetailsField(detailsTable, "District", "district"); addCallerDetailsField(detailsTable, "Taluka", "taluka"); addCallerDetailsField(detailsTable, "Village", "village"); userId = new Hidden("userid"); detailsTable.setWidget(detailsTable.getRowCount(), 0, userId); messageForumId = new Hidden("messageforumid"); detailsTable.setWidget(detailsTable.getRowCount(), 0, messageForumId); threadPanel.setSize("100%", "100%"); Label threadTitle = new Label("Thread"); threadTitle.setStyleName("gwt-Label"); threadPanel.add(threadTitle, DockPanel.NORTH); threadPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); uploadDlg = new UploadDialog(); uploadDlg.setCompleteHandler(new UploadComplete()); Button uploadResponse = new Button("Record/Upload Response", new ClickHandler() { public void onClick(ClickEvent event) { uploadDlg.reset(); uploadDlg.center(); } }); threadPanel.add(uploadResponse, DockPanel.SOUTH); thread = new VerticalPanel(); thread.setSize("100%", "100%"); thread.setSpacing(3); threadPanel.add(thread, DockPanel.NORTH); saveButton = new Button("Save", new ClickHandler() { public void onClick(ClickEvent event) { //calling setSelectedTagData so that selected tags can be collected and set as value to selectedTags input. tags.setSelectedTagData(); setClickedButton(saveButton); detailsForm.setAction(JSONRequest.BASE_URL + AoAPI.UPDATE_MESSAGE); detailsForm.submit(); } }); moveDirection = new Hidden("direction"); detailsTable.setWidget(detailsTable.getRowCount(), 0, moveDirection); moveUpButton = new Button("Move Up", new ClickHandler() { public void onClick(ClickEvent event) { setClickedButton(moveUpButton); moveDirection.setValue("up"); detailsForm.setAction(JSONRequest.BASE_URL + AoAPI.MOVE); detailsForm.submit(); } }); moveDownButton = new Button("Move Down", new ClickHandler() { public void onClick(ClickEvent event) { setClickedButton(moveDownButton); moveDirection.setValue("down"); detailsForm.setAction(JSONRequest.BASE_URL + AoAPI.MOVE); detailsForm.submit(); } }); controls.setHorizontalAlignment(HasAlignment.ALIGN_RIGHT); controls.setSpacing(5); // to snap the button to the bottom of the panel controls.setVerticalAlignment(HasAlignment.ALIGN_BOTTOM); VerticalPanel buttons = new VerticalPanel(); buttons.setSize("100%", "100%"); buttons.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); buttons.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); moveButtons = new VerticalPanel(); moveButtons.setSize("100%", "100%"); moveButtons.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); // To center the movebuttons in the panel when no moderation moveButtons.setHorizontalAlignment(HasAlignment.ALIGN_CENTER); moveButtons.add(moveUpButton); moveButtons.add(moveDownButton); moveButtons.setSpacing(5); VerticalPanel linksPanel = new VerticalPanel(); if (Messages.get().getLine().bcastingAllowed()) { broadcastLink = new Anchor("Broadcast"); linksPanel.add(broadcastLink); } downloadLink = new Anchor("Download", AoAPI.DOWNLOAD); linksPanel.add(downloadLink); buttons.add(linksPanel); buttons.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); buttons.add(moveButtons); buttons.add(saveButton); controls.add(buttons); outer.setStyleName("mail-Detail"); initWidget(detailsForm); }
From source file:org.otalo.ao.client.MessageList.java
License:Apache License
public MessageList(Images images) { this.images = images; detailsForm.setWidget(table);/* w w w. ja va2s . co m*/ detailsForm.setMethod(FormPanel.METHOD_POST); detailsForm.addSubmitCompleteHandler(new MessageStatusUpdated()); // Setup the table. table.setCellSpacing(0); table.setCellPadding(0); table.setWidth("100%"); // Hook up events. table.addClickHandler(this); // Create the 'navigation' bar at the upper-right. HorizontalPanel innerNavBar = new HorizontalPanel(); navBar.setStyleName("mail-ListNavBar"); innerNavBar.add(newerButton); innerNavBar.add(countLabel); innerNavBar.add(olderButton); navBar.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT); navBar.add(innerNavBar); navBar.setWidth("100%"); initWidget(detailsForm); setStyleName("mail-List"); initTable(); }
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();/*from w ww. jav a2s . co 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.overlord.sramp.ui.client.widgets.ArtifactUploadForm.java
License:Apache License
/** * Constructor./*from w ww. j a v a 2 s . com*/ * @param url */ public ArtifactUploadForm(String url) { ILocalizationService i18n = Services.getServices().getService(ILocalizationService.class); this.setAction(url); this.setEncoding(FormPanel.ENCODING_MULTIPART); this.setMethod(FormPanel.METHOD_POST); // Create a panel to hold all of the form widgets. VerticalPanel vpanel = new VerticalPanel(); final ListBox artifactType = new ListBox(); final Button submitButton = new Button(i18n.translate("widgets.artifact-upload.submit")); // Populate the type list box with options artifactType.setName("artifactType"); artifactType.addItem(i18n.translate("widgets.artifact-upload.please-choose"), ""); artifactType.addItem(i18n.translate("widgets.artifact-upload.choice.doc"), "Document"); artifactType.addItem(i18n.translate("widgets.artifact-upload.choice.xml"), "XmlDocument"); artifactType.addItem(i18n.translate("widgets.artifact-upload.choice.xsd"), "XsdDocument"); artifactType.addItem(i18n.translate("widgets.artifact-upload.choice.wsdl"), "WsdlDocument"); artifactType.addItem(i18n.translate("widgets.artifact-upload.choice.policy"), "PolicyDocument"); artifactType.setSelectedIndex(0); // Configure the file upload widget upload.getElement().setClassName("file"); upload.setName("artifact"); // Hook into the submit button submitButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { submit(); } }); submitButton.setEnabled(false); // Add all the widgets to the form. vpanel.add(upload); vpanel.add(artifactType); vpanel.add(submitButton); // Create a change handler that will enable/disable the Submit button. ChangeHandler changeHandler = new ChangeHandler() { @Override public void onChange(ChangeEvent event) { boolean validSelection = !"".equals(artifactType.getValue(artifactType.getSelectedIndex())); boolean validFile = upload.getFilename() != null && upload.getFilename().trim().length() > 0; submitButton.setEnabled(validSelection && validFile); } }; upload.addChangeHandler(changeHandler); upload.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { String filename = upload.getFilename().toLowerCase(); if (filename.endsWith(".xml")) { artifactType.setSelectedIndex(2); } else if (filename.endsWith(".xsd")) { artifactType.setSelectedIndex(3); } else if (filename.endsWith(".wsdl")) { artifactType.setSelectedIndex(4); } else if (filename.endsWith(".wspolicy")) { artifactType.setSelectedIndex(5); } else { artifactType.setSelectedIndex(1); } submitButton.setEnabled(true); } }); artifactType.addChangeHandler(changeHandler); setWidget(vpanel); }
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 ava2s . c o m 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 *//* w ww .ja v a 2s. c o m*/ 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 */// ww w . ja va2 s . 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.export.catalog.ExportToCatalogConfirmWindow.java
License:Open Source License
public ExportToCatalogConfirmWindow(String nodeSourceName, CatalogKind kind, RMController rmController) { this.catalogObjectNameConverter = new CatalogObjectNameConverter(nodeSourceName); this.catalogObjectName = this.catalogObjectNameConverter.convertFromKind(kind); this.kind = kind; this.rmController = rmController; this.parser = new NodeSourceConfigurationParser(); this.catalogObjectRevised = false; this.exportToCatalogForm = new FormPanel(); this.exportToCatalogForm.setEncoding(FormPanel.ENCODING_MULTIPART); this.exportToCatalogForm.setMethod(FormPanel.METHOD_POST); this.exportToCatalogForm .setAction(GWT.getModuleBaseURL() + SerializationType.EXPORT_TO_CATALOG.getFormTarget()); configureWindow();//from ww w .ja va 2 s .c om addContent(); }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.export.file.ExportToFileHandler.java
License:Open Source License
private void configureFormPanel(FormPanel formPanel) { formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setAction(GWT.getModuleBaseURL() + getFormTarget()); }