List of usage examples for com.google.gwt.user.client.ui FormPanel setAction
public void setAction(SafeUri url)
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 . ja v a 2 s. 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 w w . ja v a 2 s .c om*/ * @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/* w w w .j av a 2 s .c om*/ * @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.opencms.ui.client.login.CmsLoginTargetOpener.java
License:Open Source License
/** * Opens the login target for the given user name and password.<p> * * @param target the login target/*w w w . ja v a 2 s. c o m*/ * @param user the user * @param password the password */ public void openTarget(final String target, final String user, final String password) { // Post a hidden form with user name and password fields, // to hopefully trigger the browser's password manager final FormPanel form = new FormPanel("_self"); Document doc = Document.get(); InputElement userField = doc.createTextInputElement(); userField.setName("ocUname"); InputElement passwordField = doc.createPasswordInputElement(); passwordField.setName("ocPword"); userField.setValue(user); passwordField.setValue(password); form.getElement().appendChild(userField); form.getElement().appendChild(passwordField); form.setMethod("post"); form.setAction(target); form.setVisible(false); add(form); form.submit(); }
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 ww w . ja va2s. co 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 w w . ja v a2s . c om*/ 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 *///w w w . jav a 2s . co 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.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()); }
From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SubmitWindow.java
License:Open Source License
/** * internal layout creation// www .java 2 s . c o m * * <pre> * +- Window ------------------+ * |+- VLayout ---------------+| * ||+- Label --------+ || <-- error messages * ||+----------------+ || when applicable * ||+- Layout --------------+|| * |||+- FormPanel ---------+||| * ||||+- VerticalPanel ---+|||| * ||||| form fields ||||| <-- GWT form wrapped * ||||+-------------------+|||| in SmartGWT layout * |||+---------------------+||| * ||+-----------------------+|| * ||+- DynamicForm ---------+|| SmartGWT form, check * ||| form fields ||| <-- to enable variable edition * ||+-----------------------+|| * || +- IButton --+|| <-- submit button * || +------------+|| * |+-------------------------+| * +---------------------------+ * </pre> * * If the <code>Edit variables</code> checkbox is checked, * the {@link UploadServlet} called by the GWT form will return the content * of the job descriptor, and we will create a new form to edit the * variables so that we may submit the job to a second servlet, {@link SubmitEditServlet}. * If the {@link SubmitEditServlet} submission fails, we get back in the same state * as before the first click to Submit * * */ private void build() { /* mixing GWT's native FormPanel with SmartGWT containers, * because SmartGWT's form somehow sucks when not using the datasource stuff * as a result the layout is a bit messy */ // root page of the window final VLayout layout = new VLayout(); layout.setMargin(10); layout.setWidth100(); layout.setHeight100(); // buttons final HLayout buttons = new HLayout(); buttons.setMembersMargin(5); buttons.setHeight(20); buttons.setWidth100(); buttons.setAlign(Alignment.RIGHT); final IButton uploadButton = new IButton("Submit"); uploadButton.setIcon(Images.instance.ok_16().getSafeUri().asString()); final IButton cancelButton = new IButton("Cancel"); cancelButton.setIcon(Images.instance.cancel_16().getSafeUri().asString()); cancelButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { SubmitWindow.this.window.hide(); SubmitWindow.this.destroy(); } }); buttons.setMembers(uploadButton, cancelButton); // holds the form fields VerticalPanel formContent = new VerticalPanel(); Hidden hiddenField = new Hidden(); hiddenField.setName("sessionId"); hiddenField.setValue(LoginModel.getInstance().getSessionId()); formContent.add(hiddenField); final FileUpload fileUpload = new FileUpload(); fileUpload.setName("job"); final Hidden editField = new Hidden("edit"); editField.setValue("0"); formContent.add(fileUpload); formContent.add(editField); // actual form final FormPanel formPanel = new FormPanel(); formPanel.setEncoding(FormPanel.ENCODING_MULTIPART); formPanel.setMethod(FormPanel.METHOD_POST); formPanel.setAction(GWT.getModuleBaseURL() + "uploader"); formPanel.add(formContent); formPanel.setWidth("350px"); formPanel.setHeight("30px"); // wraps the GWT component so that we may show/hide it final HLayout formWrapper = new HLayout(); formWrapper.setAlign(Alignment.CENTER); formWrapper.setHeight(30); formWrapper.addChild(formPanel); // error messages when applicable final Label label = new Label("Submit an XML Job Descriptor:"); label.setHeight(30); label.setWidth100(); // shown during submission final Label waitLabel = new Label("Please wait..."); waitLabel.setHeight(30); waitLabel.setIcon("loading.gif"); waitLabel.setWidth100(); waitLabel.setAlign(Alignment.CENTER); final CheckboxItem edit = new CheckboxItem("edit", "Edit variables definitions"); final DynamicForm editForm = new DynamicForm(); editForm.setHeight100(); editForm.setColWidths(20, "*"); editForm.setFields(edit); layout.addMember(label); layout.addMember(formWrapper); layout.addMember(editForm); layout.addMember(buttons); this.window = new Window(); this.window.setTitle("Submit Job"); this.window.setShowMinimizeButton(false); this.window.setIsModal(true); this.window.setShowModalMask(true); this.window.addItem(layout); this.window.setWidth(420); this.window.setHeight(180); this.window.centerInPage(); this.window.setCanDragResize(true); // click the upload button : // hide the form, show a 'please wait' label, // wait for the form's callback uploadButton.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() { public void onClick(ClickEvent e) { editField.setValue(edit.getValueAsBoolean() ? "1" : "0"); formPanel.submit(); layout.removeMember(label); layout.removeMember(formWrapper); layout.removeMember(editForm); layout.removeMember(buttons); layout.addMember(waitLabel); } }); // form callback : silently close the window if no error, // else display message and allow new submission formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { String fn = fileUpload.getFilename(); // chrome workaround final String fileName = fn.replace("C:\\fakepath\\", ""); String res = event.getResults(); boolean isError = false; try { JSONValue js = JSONParser.parseStrict(res); JSONObject obj = js.isObject(); /* * submission with no edition successful, result is the job id */ if (obj.get("id") != null && obj.get("id").isNumber() != null) { int id = (int) obj.get("id").isNumber().doubleValue(); SubmitWindow.this.destroy(); LogModel.getInstance().logMessage("Successfully submitted job " + fileName + ": " + id); controller.getExecutionController().getJobsController().addSubmittingJob(id, fileName); } /* * submission with edition: */ else if (obj.get("jobEdit") != null && obj.get("jobEdit").isString() != null) { String val = obj.get("jobEdit").isString().stringValue(); String job = new String( org.ow2.proactive_grid_cloud_portal.common.shared.Base64Utils.fromBase64(val)); final Map<String, String> variables = readVars(job); // presentation form final DynamicForm varForm = new DynamicForm(); final FormItem[] fields = new FormItem[variables.size()]; final Hidden[] _fields = new Hidden[variables.size()]; int i = 0; final VerticalPanel hiddenPane = new VerticalPanel(); for (Entry<String, String> var : variables.entrySet()) { TextItem t = new TextItem(var.getKey(), var.getKey()); t.setValue(var.getValue()); t.setWidth(240); _fields[i] = new Hidden("var_" + var.getKey()); hiddenPane.add(_fields[i]); fields[i] = t; i++; } varForm.setFields(fields); varForm.setWidth100(); varForm.setHeight100(); // actual form used to POST final FormPanel fpanel = new FormPanel(); fpanel.setMethod(FormPanel.METHOD_POST); fpanel.setAction(GWT.getModuleBaseURL() + "submitedit"); hiddenPane.add(new Hidden("job", job)); hiddenPane.add(new Hidden("sessionId", LoginModel.getInstance().getSessionId())); fpanel.setWidget(hiddenPane); final Layout fpanelWrapper = new Layout(); fpanelWrapper.addMember(fpanel); label.setContents( "Edit the variable definitions for job <strong>" + fileName + "</strong>"); final HLayout buttons2 = new HLayout(); buttons2.setWidth100(); buttons2.setHeight(20); buttons2.setAlign(Alignment.RIGHT); buttons2.setMembersMargin(5); final IButton reset = new IButton("Reset"); reset.setIcon(Images.instance.clear_16().getSafeUri().asString()); reset.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { for (FormItem it : fields) { String key = it.getName(); String val = variables.get(key); it.setValue(val); } } }); final IButton submit2 = new IButton("Submit"); submit2.setIcon(Images.instance.ok_16().getSafeUri().asString()); submit2.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { for (int i = 0; i < fields.length; i++) { String val = ""; if (fields[i].getValue() != null) { val = fields[i].getValue().toString(); } _fields[i].setValue(val); } fpanel.submit(); layout.removeMember(label); layout.removeMember(varForm); layout.removeMember(buttons2); layout.removeMember(fpanelWrapper); layout.addMember(waitLabel); layout.reflow(); } }); final IButton cancel2 = new IButton("Cancel"); cancel2.setIcon(Images.instance.cancel_16().getSafeUri().asString()); cancel2.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { SubmitWindow.this.window.hide(); SubmitWindow.this.destroy(); } }); buttons2.setMembers(reset, submit2, cancel2); fpanel.addSubmitCompleteHandler(new SubmitCompleteHandler() { public void onSubmitComplete(SubmitCompleteEvent event) { String res = event.getResults(); boolean failure = false; try { JSONValue val = controller.parseJSON(res); if (val.isObject() != null && val.isObject().containsKey("id")) { int id = (int) val.isObject().get("id").isNumber().doubleValue(); SubmitWindow.this.destroy(); LogModel.getInstance() .logMessage("Successfully submitted job " + fileName + ": " + id); controller.getExecutionController().getJobsController().addSubmittingJob(id, fileName); } else { failure = true; } } catch (JSONException e) { failure = true; } if (failure) { String msg = JSONUtils.getJsonErrorMessage(res); layout.removeMember(waitLabel); label.setContents( "<span style='color:red; font-weight:bold'>Job submission failed:</span><br>" + "<span style=''>" + msg + "</span>"); layout.addMember(label); layout.addMember(formWrapper); layout.addMember(editForm); layout.addMember(buttons); layout.reflow(); LogModel.getInstance().logImportantMessage("Failed to submit job: " + msg); } } }); layout.removeMember(waitLabel); layout.addMember(label); layout.addMember(varForm); layout.addMember(fpanelWrapper); layout.addMember(buttons2); layout.setMargin(10); layout.reflow(); } else { isError = true; } } catch (JSONException t) { isError = true; } /* * submission failure */ if (isError) { String msg = JSONUtils.getJsonErrorMessage(res); layout.removeMember(waitLabel); label.setContents("<span style='color:red; font-weight:bold'>Job submission failed:</span><br>" + "<span style=''>" + msg + "</span>"); layout.addMember(label); layout.addMember(formWrapper); layout.addMember(editForm); layout.addMember(buttons); layout.reflow(); LogModel.getInstance().logImportantMessage("Failed to submit job: " + msg); } } }); }
From source file:org.pentaho.mantle.client.commands.ExecuteUrlInNewTabCommand.java
License:Open Source License
protected void performOperation() { MantleTabPanel contentTabPanel = SolutionBrowserPanel.getInstance().getContentTabPanel(); contentTabPanel.showNewURLTab(this.tabName, this.tabToolTip, "about:blank", false); //$NON-NLS-1$ NamedFrame namedFrame = ((IFrameTabPanel) contentTabPanel.getSelectedTab().getContent()).getFrame(); final FormPanel form = new FormPanel(namedFrame); RootPanel.get().add(form);//ww w .j a va 2 s . c o m form.setMethod(FormPanel.METHOD_POST); form.setAction(url); form.add(new Hidden("reportXml", URL.encode(xml))); //$NON-NLS-1$ form.submit(); ((IFrameTabPanel) contentTabPanel.getSelectedTab().getContent()).setForm(form); }