Example usage for com.google.gwt.user.client.ui Hidden Hidden

List of usage examples for com.google.gwt.user.client.ui Hidden Hidden

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Hidden Hidden.

Prototype

protected Hidden(Element element) 

Source Link

Document

This constructor may be used by subclasses to explicitly use an existing element.

Usage

From source file:org.dataconservancy.dcs.ingest.ui.client.Application.java

License:Apache License

private void displayUploadFileDialog() {
    final DialogBox db = new DialogBox(false, true);

    Panel panel = new FlowPanel();

    db.setAnimationEnabled(true);/*w  w w . jav  a  2s .  c  o m*/
    db.setText("Upload local file");
    db.setWidget(panel);
    db.center();

    final HorizontalPanel buttons = new HorizontalPanel();
    buttons.setSpacing(5);

    Button upload = new Button("Upload");
    Button cancel = new Button("Cancel");

    buttons.add(upload);
    buttons.add(cancel);

    final FormPanel form = new FormPanel();
    FlowPanel formcontents = new FlowPanel();
    form.add(formcontents);

    final FileUpload upfile = new FileUpload();
    upfile.setName("file");

    Hidden depositurl = new Hidden("depositurl");
    depositurl.setValue(depositConfig.fileUploadUrl());

    formcontents.add(upfile);
    formcontents.add(depositurl);

    form.setMethod(FormPanel.METHOD_POST);
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setAction(FILE_UPLOAD_URL);

    panel.add(new Label("Uploaded files will be included in the SIP."));
    panel.add(form);
    panel.add(buttons);

    upload.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            form.submit();
        }
    });

    cancel.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            db.hide();
        }
    });

    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            if (event.getResults() == null) {
                Window.alert("File upload failed");
                db.hide();
                return;
            }

            String[] parts = event.getResults().split("\\^");

            if (parts.length != 4) {
                Window.alert("File upload failed: " + event.getResults());
                db.hide();
                return;
            }

            String filesrc = parts[1].trim();
            // TODO String fileatomurl = parts[2].trim();

            files.setVisible(true);
            String id = nextFileId();
            fileids.add(id);
            files.add(new FileEditor(id, upfile.getFilename(), filesrc), id);
            files.selectTab(files.getWidgetCount() - 1);

            db.hide();
        }
    });
}

From source file:org.geomajas.plugin.deskmanager.client.gwt.manager.datalayer.panels.UploadShapefileForm.java

License:Open Source License

public UploadShapefileForm() {
    form = new FormPanel();
    form.setAction(SERVICE_NAME);/*from  w w  w .j a  v  a 2  s  . c om*/
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

    // Create a panel to hold all of the form widgets.
    VerticalPanel panel = new VerticalPanel();
    hiddenLayerName = new Hidden("layername");
    panel.add(hiddenLayerName);
    hiddenToken = new Hidden(URL_TOKEN);
    panel.add(hiddenToken);
    form.setWidget(panel);

    // Create a FileUpload widget.
    upload = new FileUpload();
    upload.setName("uploadFormElement");
    upload.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            for (ItemChangedHandler item : handlers) {
                ItemChangedEvent ice = new ItemChangedEvent(null);
                item.onItemChanged(ice);
            }
        }
    });
    HorizontalPanel hp = new HorizontalPanel();
    hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    hp.setSpacing(3);
    com.google.gwt.user.client.ui.Label lblUpload = new com.google.gwt.user.client.ui.Label(
            MESSAGES.uploadShapefileLabelText() + " : ");
    lblUpload.setStyleName("formTitle");
    hp.add(lblUpload);
    hp.add(upload);
    panel.add(hp);

    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            String res = event.getResults().trim();
            if (res.startsWith("<")) {
                int start = res.indexOf(">") + 1;
                int end = res.indexOf("<", start);
                res = res.substring(start, end);
            }
            uploadFinished(res);
        }
    });

    // -------------------------------------------------

    addMember(form);
}

From source file:org.jbpm.formbuilder.client.RestyFormBuilderModel.java

License:Apache License

@Override
public void loadFormTemplate(final FormRepresentation form, String language) {
    final String url = URLBuilder.loadFormTemplateURL(this.contextPath, language);
    Resource resource = new Resource(url);
    try {/* w  ww  .j a  v a  2s.  c  o m*/
        String xml = helper.asXml(form, null);
        resource.post().xml(XMLParser.parse(xml)).send(new SimpleTextCallback(i18n.CouldntExportTemplate()) {
            @Override
            public void onSuccess(Method method, String response) {
                String fileName = helper.getFileName(response);
                FormPanel auxiliarForm = new FormPanel();
                auxiliarForm.setMethod(FormPanel.METHOD_GET);
                auxiliarForm.setAction(url);
                Hidden hidden1 = new Hidden("fileName");
                hidden1.setValue(fileName);
                Hidden hidden2 = new Hidden("formName");
                hidden2.setValue(
                        form.getName() == null || "".equals(form.getName()) ? "template" : form.getName());
                VerticalPanel vPanel = new VerticalPanel();
                vPanel.add(hidden1);
                vPanel.add(hidden2);
                auxiliarForm.add(vPanel);
                RootPanel.get().add(auxiliarForm);
                auxiliarForm.submit();
            }
        });
    } catch (FormEncodingException e) {
        bus.fireEvent(new NotificationEvent(Level.ERROR, i18n.CouldntDecodeForm(), e));
    }
}

From source file:org.ned.server.nedadminconsole.client.dialogs.NedUploadDialog.java

License:Open Source License

public NedUploadDialog(String libId, NedDataModel model) {
    setSize("395px", "147px");

    this.model = model;
    setHTML(NedRes.instance().uploadDlgUploadFile());

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    setWidget(verticalPanel);//from   w ww . ja  va  2  s . co m
    verticalPanel.setSize("386px", "100px");

    uploadForm = new FormPanel();
    uploadForm.setAction("NedFileUploadServlet");
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);
    verticalPanel.add(uploadForm);
    uploadForm.setSize("100%", "100%");

    VerticalPanel verticalPanel_1 = new VerticalPanel();
    uploadForm.setWidget(verticalPanel_1);
    verticalPanel_1.setSize("100%", "77px");

    horizontalPanel_2 = new HorizontalPanel();
    verticalPanel_1.add(horizontalPanel_2);
    horizontalPanel_2.setWidth("100%");

    fileUpload = new FileUpload();
    horizontalPanel_2.add(fileUpload);
    horizontalPanel_2.setCellWidth(fileUpload, "100%");
    fileUpload.setName("fileUpload");
    verticalPanel_1.setCellHorizontalAlignment(fileUpload, HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel_1.setCellVerticalAlignment(fileUpload, HasVerticalAlignment.ALIGN_MIDDLE);
    fileUpload.setSize("100%", "30px");

    hiddenLibId = new Hidden("libId");
    horizontalPanel_2.add(hiddenLibId);
    hiddenLibId.setValue(libId);

    hiddenContentId = new Hidden("contentId");
    horizontalPanel_2.add(hiddenContentId);
    hiddenContentId.setValue(model.getCurrentObject().id);

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    verticalPanel_1.add(horizontalPanel);
    horizontalPanel.setWidth("100%");
    verticalPanel_1.setCellHorizontalAlignment(horizontalPanel, HasHorizontalAlignment.ALIGN_CENTER);

    Button uploadBtn = new Button(NedRes.instance().uploadDlgUpload());
    horizontalPanel.add(uploadBtn);
    uploadBtn.setWidth("90%");
    horizontalPanel.setCellWidth(uploadBtn, "50%");
    horizontalPanel.setCellHorizontalAlignment(uploadBtn, HasHorizontalAlignment.ALIGN_CENTER);
    horizontalPanel.setCellVerticalAlignment(uploadBtn, HasVerticalAlignment.ALIGN_MIDDLE);
    uploadBtn.addClickHandler(new UploadFileClickHandler());
    verticalPanel.setCellVerticalAlignment(uploadBtn, HasVerticalAlignment.ALIGN_MIDDLE);
    verticalPanel.setCellHorizontalAlignment(uploadBtn, HasHorizontalAlignment.ALIGN_CENTER);

    closeBtn = new Button(NedRes.instance().close());
    horizontalPanel.add(closeBtn);
    closeBtn.setWidth("90%");
    horizontalPanel.setCellWidth(closeBtn, "50%");
    horizontalPanel.setCellVerticalAlignment(closeBtn, HasVerticalAlignment.ALIGN_MIDDLE);
    horizontalPanel.setCellHorizontalAlignment(closeBtn, HasHorizontalAlignment.ALIGN_CENTER);
    closeBtn.addClickHandler(new CloseClickHandler());

    setPopupPosition(200, 200);

    uploadForm.addSubmitHandler(new SubmitHandlerUploadFile());

    uploadForm.addSubmitCompleteHandler(new SubmitCompleteHandlerUploadFile());

    center();
}

From source file:org.opencms.ade.sitemap.client.alias.CmsImportView.java

License:Open Source License

/**
 * Initializes the form used for submitting the alias CSV file to the server.<p>
 *//*from w  w w . j  a v a 2  s  .co  m*/
protected void initializeForm() {

    String target = CmsSitemapView.getInstance().getController().getData().getAliasImportUrl();
    m_formPanel.setAction(target);
    m_formPanel.setMethod(FormPanel.METHOD_POST);
    m_formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    Hidden siteRootField = new Hidden(I_CmsAliasConstants.PARAM_SITEROOT);
    siteRootField.setValue(CmsCoreProvider.get().getSiteRoot());
    m_formPanelContents.add(siteRootField);
    m_formPanelContents.add(m_separatorField);
    m_formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {

            final String formPostResults = event.getResults();
            final I_CmsSitemapServiceAsync service = CmsSitemapView.getInstance().getController().getService();
            CmsRpcAction<List<CmsAliasImportResult>> action = new CmsRpcAction<List<CmsAliasImportResult>>() {

                @Override
                public void execute() {

                    start(200, false);
                    service.getAliasImportResult(formPostResults.trim(), this);
                }

                @Override
                public void onResponse(List<CmsAliasImportResult> result) {

                    stop(false);
                    handleImportResults(result);
                    Timer resizeTimer = new Timer() {

                        @Override
                        public void run() {

                            m_scrollPanel.onResizeDescendant();
                        }
                    };
                    resizeTimer.schedule(100);
                }
            };
            action.execute();
        }
    });
}

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   ww  w .  ja v a  2  s . co  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.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  . j  av 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.otalo.ao.client.MessageList.java

License:Apache License

private void update() {
    // Update the older/newer buttons & label.
    int max = startIndex + VISIBLE_MESSAGE_COUNT;
    if (max > count) {
        max = count;/*from  w w  w  .  j  a  va  2s  . c  om*/
    }

    newerButton.setVisible(startIndex != 0);
    olderButton.setVisible(startIndex + VISIBLE_MESSAGE_COUNT < count);

    if (newButtonReg != null) {
        newButtonReg.removeHandler();
        newButtonReg = null;
    }
    if (oldButtonReg != null) {
        oldButtonReg.removeHandler();
        oldButtonReg = null;
    }

    if (count > 0) {
        BaseModel message = messages.get(0);
        newButtonReg = newerButton.addClickHandler(new PageOverHandler("newer", message));
        oldButtonReg = olderButton.addClickHandler(new PageOverHandler("older", message));

    }

    countLabel.setText("" + (startIndex + 1) + " - " + max + " of " + count);

    // Show the selected messages.
    int i = 0;
    for (; i < VISIBLE_MESSAGE_COUNT; ++i) {
        // Don't read past the end.
        if (i >= messages.size()) {
            break;
        }

        BaseModel message = messages.get(i);

        if (MessageForum.isMessageForum(message)) {
            MessageForum mf = new MessageForum(message);
            // Add a new row to the table, then set each of its columns
            table.setText(i + 1, 0, mf.getDate());
            User user = mf.getAuthor();
            String callerText = ("".equals(user.getName()) || "null".equals(user.getName())) ? user.getNumber()
                    : user.getName() + " (" + user.getNumber() + ")";
            table.setText(i + 1, 1, callerText);

            if (forum != null && forum.moderated()) {
                AbstractImagePrototype approveHTML = AbstractImagePrototype.create(images.approve());
                HTML approveButton = new HTML(approveHTML.getHTML());
                approveButton.addClickHandler(new MessageApproveHandler(AoAPI.APPROVE, mf));

                AbstractImagePrototype rejectHTML = AbstractImagePrototype.create(images.reject());
                HTML rejectButton = new HTML(rejectHTML.getHTML());
                rejectButton.addClickHandler(new MessageApproveHandler(AoAPI.REJECT, mf));

                switch (mf.getStatus()) {
                case APPROVED:
                    table.setWidget(i + 1, 3, rejectButton);
                    table.setHTML(i + 1, 4, "&nbsp");
                    break;
                case REJECTED:
                    table.setWidget(i + 1, 3, approveButton);
                    table.setHTML(i + 1, 4, "&nbsp");
                    break;
                case PENDING:
                    table.setWidget(i + 1, 3, approveButton);
                    table.setWidget(i + 1, 4, rejectButton);
                }
            } else {
                table.setHTML(i + 1, 3, "&nbsp");
                table.setHTML(i + 1, 4, "&nbsp");
            }
        } else if (SurveyInput.isSurveyInput(message)) {
            SurveyInput input = new SurveyInput(message);
            Call call = input.getCall();

            // Add a new row to the table, then set each of its columns
            table.setText(i + 1, 0, call.getDate());
            Subject subject = call.getSubject();
            String callerText = ("".equals(subject.getName()) || "null".equals(subject.getName()))
                    ? subject.getNumber()
                    : subject.getName() + " (" + subject.getNumber() + ")";
            table.setText(i + 1, 1, callerText);

            // TODO: add download link
            Anchor downloadLink = new Anchor("Download", AoAPI.DOWNLOAD_SURVEY_INPUT + input.getId());
            table.setWidget(i + 1, 3, downloadLink);
            table.setHTML(i + 1, 4, "&nbsp");
        }
        table.setHTML(i + 1, 2, "");
    }

    // Clear any remaining slots.
    for (; i < VISIBLE_MESSAGE_COUNT; ++i) {
        table.setHTML(i + 1, 0, "&nbsp;");
        table.setHTML(i + 1, 1, "&nbsp;");
        table.setHTML(i + 1, 2, "&nbsp;");
        table.setHTML(i + 1, 3, "&nbsp;");
        table.setHTML(i + 1, 4, "&nbsp;");
        table.setHTML(i + 1, 5, "&nbsp;");

    }
    // set the hidden field in the last row
    messageForumId = new Hidden("messageforumid");
    table.setWidget(VISIBLE_MESSAGE_COUNT + 1, 0, messageForumId);

    // Select the first row if none is selected.
    if (selectedRow == -1 && count > 0) {
        selectRow(0);
    }
}

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();//ww  w  . j  av  a  2s.c  o m
                if (recordOpt.getValue() == true) {
                    recorder.uploadData(getParams());
                } else {
                    uploadForm.submit();
                }
            }
        }
    });

    cancelButton = new Anchor("Cancel");
    cancelButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (recorder.isRecorded())
                recorder.stopRecording();
            hide();
        }
    });

    recordOpt = new RadioButton("options", "Record");
    recordOpt.setFormValue("record");
    recordOpt.addStyleName("label-txt");
    recordOpt.setValue(true);
    recordOpt.addClickHandler(new OptionClickHandler());

    uploadOpt = new RadioButton("options", "Upload");
    uploadOpt.setFormValue("upload");
    uploadOpt.setValue(false);
    uploadOpt.addStyleName("label-txt");
    uploadOpt.addClickHandler(new OptionClickHandler());

    outer.setWidget(1, 0, recordOpt);
    mainMsgHTML = new HTML("<span id='recordError'></span>");
    mainMsgHTML.addStyleName("upload-top-msg");
    outer.setWidget(1, 1, mainMsgHTML);
    outer.getCellFormatter().getElement(1, 1).getStyle().setTextAlign(TextAlign.JUSTIFY);
    outer.getCellFormatter().getElement(1, 0).getStyle().setTextAlign(TextAlign.LEFT);
    //creating recorder widget
    recorder = new AudioRecorderWidget(JSONRequest.BASE_URL + AoAPI.RECORD_OR_UPLOAD, this);
    outer.setWidget(2, 0, recorder);
    outer.getFlexCellFormatter().setColSpan(2, 0, 2);

    outer.setWidget(4, 0, uploadOpt);
    outer.getFlexCellFormatter().setColSpan(4, 0, 2);
    outer.getCellFormatter().getElement(4, 0).getStyle().setTextAlign(TextAlign.LEFT);

    outer.setWidget(5, 0, mainLabel);
    outer.getCellFormatter().setWordWrap(0, 0, false);
    outer.getCellFormatter().setStyleName(5, 0, "left-align");
    contentPanel.setSpacing(2);
    DOM.setStyleAttribute(contentPanel.getElement(), "textAlign", "left");
    contentPanel.add(main);
    outer.setWidget(5, 1, contentPanel);
    outer.getCellFormatter().setStyleName(5, 1, "left-align-no-margin");
    main.setEnabled(false);
    mainLabel.addStyleName("gray-text");

    if (Messages.get().canManage()) {
        // no author number; but future date option is available

        // Label
        dateLabel = new Label("Broadcast Time: ");
        // Note on bcasting date
        Label dateNote = new Label("Your broadcast will begin 10-15 minutes from the time you specify here");
        dateNote.setStyleName("helptext");

        // Start now option
        now = new RadioButton("when", "Now");
        now.setFormValue("now");

        date = new RadioButton("when");
        date.setFormValue("date");

        // Date Box

        dateBox = new DateBox();
        dateBox.setFormat(new DateBox.DefaultFormat(dateFormat));
        dateBox.addValueChangeHandler(new ValueChangeHandler<Date>() {

            public void onValueChange(ValueChangeEvent<Date> event) {
                now.setValue(false);
                date.setValue(true);
                Date d = event.getValue();
                dateField.setValue(DateTimeFormat.getFormat("MMM-dd-yyyy").format(d));
            }
        });

        // Hour box
        hour = new ListBox();
        hour.setName("hour");
        for (int i = 0; i < 24; i++) {
            String hourStr;
            if (i < 10)
                hourStr = "0" + String.valueOf(i);
            else
                hourStr = String.valueOf(i);

            hour.addItem(hourStr);
        }
        hour.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                now.setValue(false);
                date.setValue(true);

            }
        });

        // Minute box
        min = new ListBox();
        min.setName("min");
        for (int i = 0; i < 60; i += 5) {
            String minStr;
            if (i < 10)
                minStr = "0" + String.valueOf(i);
            else
                minStr = String.valueOf(i);

            min.addItem(minStr);
        }
        min.addChangeHandler(new ChangeHandler() {

            public void onChange(ChangeEvent event) {
                now.setValue(false);
                date.setValue(true);

            }
        });

        int row = outer.getRowCount();
        outer.setWidget(row, 0, dateLabel);
        outer.getCellFormatter().setWordWrap(1, 0, false);

        HorizontalPanel nowPanel = new HorizontalPanel();
        //nowPanel.setHorizontalAlignment(HasAlignment.ALIGN_LEFT);
        nowPanel.setSpacing(4);
        nowPanel.add(now);
        DOM.setStyleAttribute(nowPanel.getElement(), "textAlign", "left");
        outer.setWidget(row, 1, nowPanel);

        HorizontalPanel datePicker = new HorizontalPanel();
        datePicker.setSpacing(4);
        datePicker.add(date);
        datePicker.add(dateBox);
        datePicker.add(hour);
        datePicker.add(new Label(":"));
        datePicker.add(min);
        row = outer.getRowCount();

        datePanel = new HorizontalPanel();
        outer.setWidget(row, 0, datePanel);
        DOM.setStyleAttribute(datePicker.getElement(), "textAlign", "left");
        outer.setWidget(row, 1, datePicker);

        row = outer.getRowCount();
        outer.setWidget(row, 1, dateNote);
        outer.getCellFormatter().setWordWrap(row, 1, false);
        dateField = new Hidden("date");
        outer.setWidget(outer.getRowCount(), 0, dateField);
    } else {
        outer.setWidget(7, 0, numberLabel);
        outer.getCellFormatter().setWordWrap(1, 0, false);
        numberPanel.setSpacing(2);
        DOM.setStyleAttribute(numberPanel.getElement(), "textAlign", "left");
        numberPanel.add(number);
        outer.setWidget(7, 1, numberPanel);
    }

    HorizontalPanel buttons = new HorizontalPanel();
    // tables don't obey the setHorizontal of parents, and buttons is a table,
    // so use float instead
    DOM.setStyleAttribute(buttons.getElement(), "cssFloat", "right");
    buttons.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    buttons.add(cancelButton);
    buttons.add(saveButton);

    outer.setWidget(outer.getRowCount(), 1, buttons);

    outer.setWidget(outer.getRowCount(), 0, forumId);
    outer.setWidget(outer.getRowCount(), 0, messageForumId);

    HTML troubleShootLink = new HTML(
            "<a class='trblLink' target=_blank  href='http://awaaz.de/blog/2013/10/record-your-messages-over-web'>Unable to record? Complete the one-time setup instructions</a>");
    int trblCell = outer.getRowCount();
    outer.setWidget(trblCell, 0, troubleShootLink);
    outer.getFlexCellFormatter().setColSpan(trblCell, 0, 2);
    outer.getFlexCellFormatter().addStyleName(trblCell, 0, "left-align");

    HTML brodtime_text = new HTML(
            "<span>Broadcast calls will only be scheduled between 8am and 10pm IST.</span>");
    brodtime_text.addStyleName("brodcast-time-text");
    outer.setWidget(trblCell + 1, 0, brodtime_text);
    outer.getFlexCellFormatter().setColSpan(trblCell + 1, 0, 2);
    outer.getFlexCellFormatter().addStyleName(trblCell + 1, 0, "left-align");

    uploadForm.setWidget(outer);

    setSaveButtonSate();

    setWidget(uploadForm);
}

From source file:org.ow2.proactive_grid_cloud_portal.common.client.CredentialsWindow.java

License:Open Source License

private void build() {
    /* smartGWT forms don't allow simple multipart file upload,
     * so we use a smartGWT form for login/password/checkbox,
     * a pure GWT form for file upload, and upon submission,
     * put the fields from the first form as hidden fields of the
     * pure GWT form. It's a bit convoluted but like this we get
     * the pretty widgets and the nice features       */

    TextItem loginField = new TextItem("login", "Login");
    loginField.setRequired(true);/* ww  w .  j a  v  a  2s .  c  om*/

    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();
}