List of usage examples for com.google.gwt.user.client.ui FormPanel FormPanel
public FormPanel()
From source file:org.onebusaway.webapp.gwt.oba_application.view.SearchWidget.java
License:Apache License
private void initializeWidget() { addStyleName(_css.SearchWidget());//from w w w . j a v a 2s .com FormPanel form = new FormPanel(); form.setAction("index.html"); add(form); form.addSubmitHandler(new SubmitHandler() { public void onSubmit(SubmitEvent event) { event.cancel(); } }); FlowPanel panel = new FlowPanel(); form.add(panel); DivPanel searchPanel = new DivPanel(); searchPanel.addStyleName(_css.SearchWidgetSearchPanel()); panel.add(searchPanel); DivPanel searchForPanel = new DivPanel(); searchForPanel.addStyleName(_css.SearchWidgetSearchForPanel()); searchPanel.add(searchForPanel); DivWidget queryLabel = new DivWidget("Search for:"); queryLabel.addStyleName(_css.SearchWidgetLabel()); searchForPanel.add(queryLabel); DivPanel queryTextBoxPanel = new DivPanel(); queryTextBoxPanel.addStyleName(_css.SearchWidgetTextBoxPanel()); searchForPanel.add(queryTextBoxPanel); _queryTextBox = new TextBox(); _queryTextBox.addStyleName(_css.SearchWidgetTextBox()); _queryTextBox.setName(ConstraintsParameterMapping.PARAM_QUERY); _queryTextBox.addKeyPressHandler(new QueryTextBoxHandler()); queryTextBoxPanel.add(_queryTextBox); DivPanel searchForExamplePanel = new DivPanel(); searchForExamplePanel.addStyleName(_css.SearchWidgetExamplePanel()); searchForPanel.add(searchForExamplePanel); DivWidget searchForExampleLabel = new DivWidget("(ex. \"restaurants\", \"parks\", \"grocery stores\")"); searchForExampleLabel.addStyleName(_css.SearchWidgetExampleLabel()); searchForExamplePanel.add(searchForExampleLabel); DivPanel addressPanel = new DivPanel(); searchPanel.add(addressPanel); DivPanel addressPanel1 = new DivPanel(); addressPanel.add(addressPanel1); DivWidget addressLabel = new DivWidget("Start Address:"); addressLabel.addStyleName(_css.SearchWidgetLabel()); addressPanel1.add(addressLabel); DivPanel addressTextBoxPanel = new DivPanel(); addressTextBoxPanel.addStyleName(_css.SearchWidgetTextBoxPanel()); addressPanel1.add(addressTextBoxPanel); _addressTextBox = new TextBox(); _addressTextBox.addStyleName(_css.SearchWidgetTextBox()); _addressTextBox.setName(ConstraintsParameterMapping.PARAM_LOCATION); addressTextBoxPanel.add(_addressTextBox); DivPanel addressPanel2 = new DivPanel(); addressPanel2.addStyleName(_css.SearchWidgetExamplePanel()); addressPanel.add(addressPanel2); SpanWidget addressExampleLabel1 = new SpanWidget("(ex. \"3rd and pike\" or "); addressExampleLabel1.addStyleName(_css.SearchWidgetExampleLabel()); addressPanel2.add(addressExampleLabel1); Anchor addressExampleLabel2 = new Anchor("use the map"); addressExampleLabel2.addStyleName(_css.SearchWidgetExampleLabel()); addressExampleLabel2.addClickHandler(new UseTheMapHandler()); addressPanel2.add(addressExampleLabel2); SpanWidget addressExampleLabel3 = new SpanWidget(")"); addressExampleLabel3.addStyleName(_css.SearchWidgetExampleLabel()); addressPanel2.add(addressExampleLabel3); DivPanel buttonPanel = new DivPanel(); buttonPanel.addStyleName(_css.SearchWidgetButtonPanel()); searchPanel.add(buttonPanel); Button button = new Button("Go"); buttonPanel.add(button); button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent widget) { handleQuery(); } }); AddressTextBoxHandler handler = new AddressTextBoxHandler(); _addressTextBox.addKeyPressHandler(handler); _addressTextBox.addFocusHandler(handler); _addressTextBox.addBlurHandler(handler); _optionsButton = new Anchor("Show More Options"); _optionsButton.addStyleName(_css.SearchWidgetShowOptionsButton()); _optionsButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent arg0) { toggleExpansion(); // TODO : Refresh layout } }); buttonPanel.add(_optionsButton); DivPanel clearPanel = new DivPanel(); clearPanel.addStyleName(_css.ClearPanel()); panel.add(clearPanel); Image hiddenPixel = new Image(CommonResources.INSTANCE.getHiddenPixel().getUrl()); clearPanel.add(hiddenPixel); _optionsPanel = new DivPanel(); _optionsPanel.addStyleName(_css.SearchWidgetOptionsPanel()); _optionsPanel.setVisible(false); panel.add(_optionsPanel); Grid optionsGrid = new Grid(2, 4); optionsGrid.addStyleName(_css.SearchWidgetOptionsGrid()); for (int i = 0; i < 4; i++) { optionsGrid.getCellFormatter().addStyleName(0, i, "SearchWidget-OptionsGrid-Column" + i); optionsGrid.getCellFormatter().addStyleName(1, i, "SearchWidget-OptionsGrid-Column" + i); } _optionsPanel.add(optionsGrid); SpanWidget timeLabel = new SpanWidget("Start Time:"); optionsGrid.setWidget(0, 0, timeLabel); DivPanel dateAndTimePanel = new DivPanel(); optionsGrid.setWidget(0, 1, dateAndTimePanel); _dateTextBox = new TextBox(); _dateTextBox.addStyleName(_css.SearchWidgetStartDateTextBox()); dateAndTimePanel.add(_dateTextBox); _timeTextBox = new TextBox(); _timeTextBox.addStyleName(_css.SearchWidgetStartTimeTextBox()); dateAndTimePanel.add(_timeTextBox); SpanWidget maxLengthLabel = new SpanWidget("Trip Time:"); optionsGrid.setWidget(1, 0, maxLengthLabel); _maxTripLengthBox = new ListBox(); _maxTripLengthBox.addItem("10 mins", "10"); _maxTripLengthBox.addItem("15 mins", "15"); _maxTripLengthBox.addItem("20 mins", "20"); _maxTripLengthBox.addItem("30 mins", "30"); _maxTripLengthBox.addItem("45 mins", "45"); _maxTripLengthBox.addItem("1 hour", "60"); _maxTripLengthBox.addStyleName(_css.SearchWidgetTripLengthList()); optionsGrid.setWidget(1, 1, _maxTripLengthBox); SpanWidget maxTransfersLabel = new SpanWidget("Transfers:"); optionsGrid.setWidget(0, 2, maxTransfersLabel); _maxTransfersListBox = new ListBox(); _maxTransfersListBox.addItem("Don't Care", "-1"); _maxTransfersListBox.addItem("0", "0"); _maxTransfersListBox.addItem("1", "1"); _maxTransfersListBox.addItem("2", "2"); optionsGrid.setWidget(0, 3, _maxTransfersListBox); SpanWidget maxWalkLabel = new SpanWidget("Walk at most:"); optionsGrid.setWidget(1, 2, maxWalkLabel); _maxWalkDistance = new ListBox(); _maxWalkDistance.addItem("1/4 mile", "1320"); _maxWalkDistance.addItem("1/2 mile", "2640"); _maxWalkDistance.addItem("3/4 mile", "3960"); _maxWalkDistance.addItem("1 mile", "5280"); optionsGrid.setWidget(1, 3, _maxWalkDistance); DivPanel optionsPanelRowB = new DivPanel(); _optionsPanel.add(optionsPanelRowB); }
From source file:org.opencms.ade.upload.client.ui.CmsUploadDialogImpl.java
License:Open Source License
/** * Creates a form that contains the file input fields and the target folder.<p> * //from w ww. jav a2 s. c o m * @return the form */ private FormPanel createForm() { // create a form using the POST method and multipart MIME encoding FormPanel form = new FormPanel(); form.setAction(getUploadUri()); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); // create a panel that contains the file input fields and the target folder FlowPanel inputFieldsPanel = new FlowPanel(); int count = 0; for (CmsFileInput input : m_inputsToUpload.values()) { String filename = input.getFiles()[0].getFileName(); String fieldName = "file_" + count++; input.setName(fieldName); if (getFilesToUpload().containsKey(filename)) { inputFieldsPanel.add(input); } addHiddenField(inputFieldsPanel, fieldName + I_CmsUploadConstants.UPLOAD_FILENAME_ENCODED_SUFFIX, URL.encode(filename)); } for (String filename : getFilesToUnzip(false)) { addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_UNZIP_FILES_FIELD_NAME, URL.encode(filename)); } addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_TARGET_FOLDER_FIELD_NAME, getTargetFolder()); form.setWidget(inputFieldsPanel); return form; }
From source file:org.opencms.gwt.client.ui.input.upload.impl.CmsUploaderDefault.java
License:Open Source License
/** * Creates a form to submit the upload files.<p> * * @param uploadUri the upload URI/*from w w w .j a v a 2s. c o m*/ * @param targetFolder the target folder * @param isRootPath if the target folder is given as a root path * @param filesToUpload the files to upload * @param filesToUnzip the files to unzip * @return the created form panel */ private FormPanel createForm(String uploadUri, String targetFolder, boolean isRootPath, List<CmsFileInfo> filesToUpload, List<String> filesToUnzip) { // create a form using the POST method and multipart MIME encoding FormPanel form = new FormPanel(); form.setAction(uploadUri); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); // create a panel that contains the file input fields and the target folder FlowPanel inputFieldsPanel = new FlowPanel(); int count = 0; for (CmsFileInfo info : filesToUpload) { InputElement input = info.getInputElement(); String fieldName = "file_" + count++; input.setName(fieldName); inputFieldsPanel.getElement().appendChild(input); addHiddenField(inputFieldsPanel, fieldName + I_CmsUploadConstants.UPLOAD_FILENAME_ENCODED_SUFFIX, URL.encode(info.getOverrideFileName())); } for (String filename : filesToUnzip) { addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_UNZIP_FILES_FIELD_NAME, URL.encode(filename)); } addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_TARGET_FOLDER_FIELD_NAME, targetFolder); addHiddenField(inputFieldsPanel, I_CmsUploadConstants.UPLOAD_IS_ROOT_PATH_FIELD_NAME, "" + isRootPath); form.setWidget(inputFieldsPanel); return form; }
From source file:org.openelis.ui.widget.fileupload.FileLoad.java
License:Open Source License
public FileLoad() { form = new FormPanel(); form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); upload = new FileLoadButton(); // Submit form to server once user has chosen a file upload.addChangeHandler(new ChangeHandler() { @Override/*from w w w . java2 s . c o m*/ public void onChange(ChangeEvent event) { form.submit(); } }); upload.setName("file"); // Hidden fields in form to define service and method to call on upload service = new Hidden("service"); method = new Hidden("method"); panel = new AbsolutePanel(); panel.add(upload); panel.add(service); panel.add(method); form.add(panel); initWidget(form); }
From source file:org.openremote.app.client.widget.FileUploadLabelled.java
License:Open Source License
@Override protected void onAttach() { super.onAttach(); parentForm = getParentForm();//from ww w. ja v a2 s . co m if (parentForm == null) { // wrap the input in a form to allow resetting the input FormPanel form = new FormPanel(); add(form, wrapper); parentForm = form.getElement().cast(); fileUpload.removeFromParent(); form.add(fileUpload); } }
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 w w .j a v a 2 s. c o m*/ 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.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);// w w w .java 2 s . 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 2 s . co 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 *///from w w w . j a v a 2 s . c om 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 w ww. j a va 2 s.c om addContent(); }