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

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

Introduction

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

Prototype

public FormPanel() 

Source Link

Document

Creates a new FormPanel.

Usage

From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.export.file.ExportToFileHandler.java

License:Open Source License

private void createSubmitWindow() {
    this.exportToFileWindow = new Window();
    this.exportToFileFormPanel = new FormPanel();
    configureFormPanel(this.exportToFileFormPanel);
    VerticalPanel panel = new VerticalPanel();

    this.fileContentItem = new Hidden(FILE_CONTENT_PARAM);
    this.fileSuffixItem = new Hidden(FILE_SUFFIX_PARAM);
    this.nodeSourceNameItem = new Hidden(NODE_SOURCE_NAME_PARAM);

    panel.add(this.fileContentItem);
    panel.add(this.fileSuffixItem);
    panel.add(this.nodeSourceNameItem);
    this.exportToFileFormPanel.setWidget(panel);
    this.exportToFileWindow.addChild(this.exportToFileFormPanel);
    this.exportToFileWindow.show();
}

From source file:org.ow2.proactive_grid_cloud_portal.scheduler.client.SubmitWindow.java

License:Open Source License

/**
 * internal layout creation/*from   ww w. j a v a  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.dialogs.ImportDialog.java

License:Open Source License

/**
 * @param repositoryFile/*  w  w  w.  j av  a  2 s . c o  m*/
 */
public ImportDialog(RepositoryFile repositoryFile, boolean allowAdvancedDialog) {
    super(Messages.getString("import"), Messages.getString("ok"), Messages.getString("cancel"), false, true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    form = new FormPanel();
    form.addSubmitHandler(new SubmitHandler() {
        @Override
        public void onSubmit(SubmitEvent se) {
            // if no file is selected then do not proceed
            okButton.setEnabled(false);
            cancelButton.setEnabled(false);
            MantleApplication.showBusyIndicator(Messages.getString("pleaseWait"),
                    Messages.getString("importInProgress"));
        }
    });
    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
        @Override
        public void onSubmitComplete(SubmitCompleteEvent sce) {
            MantleApplication.hideBusyIndicator();
            okButton.setEnabled(false);
            cancelButton.setEnabled(true);
            ImportDialog.this.hide();
            String result = sce.getResults();
            if (result.length() > 5) {
                HTML messageTextBox = null;
                if (result.contains("INVALID_MIME_TYPE") == true) {
                    messageTextBox = new HTML(Messages.getString("uploadInvalidFileTypeQuestion", result));
                } else {
                    logWindow(result, Messages.getString("importLogWindowTitle"));
                }

                if (messageTextBox != null) {
                    PromptDialogBox dialogBox = new PromptDialogBox(Messages.getString("uploadUnsuccessful"),
                            Messages.getString("close"), null, true, true);
                    dialogBox.setContent(messageTextBox);
                    dialogBox.center();
                }
            }

            // if mantle_isBrowseRepoDirty=true: do getChildren call
            // if mantle_isBrowseRepoDirty=false: use stored fileBrowserModel in myself.get("cachedData")
            setBrowseRepoDirty(Boolean.TRUE);

            // BISERVER-9319 Refresh browse perspective after import
            final GenericEvent event = new GenericEvent();
            event.setEventSubType("ImportDialogEvent");
            EventBusUtil.EVENT_BUS.fireEvent(event);
        }
    });

    VerticalPanel rootPanel = new VerticalPanel();

    VerticalPanel spacer = new VerticalPanel();
    spacer.setHeight("10px");
    rootPanel.add(spacer);

    Label fileLabel = new Label(Messages.getString("file") + ":");
    final TextBox importDir = new TextBox();
    rootPanel.add(fileLabel);

    okButton.setEnabled(false);

    final TextBox fileTextBox = new TextBox();
    fileTextBox.setEnabled(false);

    //We use an fileNameOverride because FileUpload can only handle US character set reliably.
    final Hidden fileNameOverride = new Hidden("fileNameOverride");

    final FileUpload upload = new FileUpload();
    upload.setName("fileUpload");
    ChangeHandler fileUploadHandler = new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            fileTextBox.setText(upload.getFilename());
            if (!"".equals(importDir.getValue())) {
                //Set the fileNameOverride because the fileUpload object can only reliably transmit US-ASCII
                //character set.  See RFC283 section 2.3 for details
                String fileNameValue = upload.getFilename().replaceAll("\\\\", "/");
                fileNameValue = fileNameValue.substring(fileNameValue.lastIndexOf("/") + 1);
                fileNameOverride.setValue(fileNameValue);
                okButton.setEnabled(true);
            } else {
                okButton.setEnabled(false);
            }
        }
    };
    upload.addChangeHandler(fileUploadHandler);
    upload.setVisible(false);

    HorizontalPanel fileUploadPanel = new HorizontalPanel();
    fileUploadPanel.add(fileTextBox);
    fileUploadPanel.add(new HTML("&nbsp;"));

    Button browseButton = new Button(Messages.getString("browse") + "...");
    browseButton.setStyleName("pentaho-button");
    fileUploadPanel.add(browseButton);
    browseButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            setRetainOwnershipState();
            jsClickUpload(upload.getElement());
        }
    });

    rootPanel.add(fileUploadPanel);
    rootPanel.add(upload);

    applyAclPermissions.setName("applyAclPermissions");
    applyAclPermissions.setValue(Boolean.FALSE);
    applyAclPermissions.setFormValue("false");
    applyAclPermissions.setEnabled(true);
    applyAclPermissions.setVisible(false);

    final CheckBox overwriteAclPermissions = new CheckBox(Messages.getString("overwriteAclPermissions"), true);
    overwriteAclPermissions.setName("overwriteAclPermissions");
    applyAclPermissions.setValue(Boolean.FALSE);
    applyAclPermissions.setFormValue("false");
    overwriteAclPermissions.setEnabled(true);
    overwriteAclPermissions.setVisible(false);

    final Hidden overwriteFile = new Hidden("overwriteFile");
    overwriteFile.setValue("true");

    final Hidden logLevel = new Hidden("logLevel");
    logLevel.setValue("ERROR");

    final Hidden retainOwnership = new Hidden("retainOwnership");
    retainOwnership.setValue("true");

    rootPanel.add(applyAclPermissions);
    rootPanel.add(overwriteAclPermissions);
    rootPanel.add(overwriteFile);
    rootPanel.add(logLevel);
    rootPanel.add(retainOwnership);
    rootPanel.add(fileNameOverride);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    rootPanel.add(spacer);

    DisclosurePanel disclosurePanel = new DisclosurePanel(Messages.getString("advancedOptions"));
    disclosurePanel.getHeader().setStyleName("gwt-Label");
    disclosurePanel.setVisible(allowAdvancedDialog);
    HorizontalPanel mainPanel = new HorizontalPanel();
    mainPanel.add(new HTML("&nbsp;"));
    VerticalPanel disclosureContent = new VerticalPanel();

    HTML replaceLabel = new HTML(Messages.getString("fileExists"));
    replaceLabel.setStyleName("gwt-Label");
    disclosureContent.add(replaceLabel);

    final CustomListBox overwriteFileDropDown = new CustomListBox();
    final CustomListBox filePermissionsDropDown = new CustomListBox();

    DefaultListItem replaceListItem = new DefaultListItem(Messages.getString("replaceFile"));
    replaceListItem.setValue("true");
    overwriteFileDropDown.addItem(replaceListItem);
    DefaultListItem doNotImportListItem = new DefaultListItem(Messages.getString("doNotImport"));
    doNotImportListItem.setValue("false");
    overwriteFileDropDown.addItem(doNotImportListItem);
    overwriteFileDropDown.setVisibleRowCount(1);
    disclosureContent.add(overwriteFileDropDown);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    disclosureContent.add(spacer);

    HTML filePermissionsLabel = new HTML(Messages.getString("filePermissions"));
    filePermissionsLabel.setStyleName("gwt-Label");
    disclosureContent.add(filePermissionsLabel);

    DefaultListItem usePermissionsListItem = new DefaultListItem(Messages.getString("usePermissions"));
    usePermissionsListItem.setValue("false");
    filePermissionsDropDown.addItem(usePermissionsListItem); // If selected set "overwriteAclPermissions" to
    // false.
    DefaultListItem retainPermissionsListItem = new DefaultListItem(Messages.getString("retainPermissions"));
    retainPermissionsListItem.setValue("true");
    filePermissionsDropDown.addItem(retainPermissionsListItem); // If selected set "overwriteAclPermissions" to
    // true.

    final ChangeListener filePermissionsHandler = new ChangeListener() {
        @Override
        public void onChange(Widget sender) {
            String value = filePermissionsDropDown.getSelectedItem().getValue().toString();

            applyAclPermissions.setValue(Boolean.valueOf(value));
            applyAclPermissions.setFormValue(value);
            overwriteAclPermissions.setFormValue(value);
            overwriteAclPermissions.setValue(Boolean.valueOf(value));
            setRetainOwnershipState();
        }
    };
    filePermissionsDropDown.addChangeListener(filePermissionsHandler);
    filePermissionsDropDown.setVisibleRowCount(1);
    disclosureContent.add(filePermissionsDropDown);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    disclosureContent.add(spacer);

    HTML fileOwnershipLabel = new HTML(Messages.getString("fileOwnership"));
    fileOwnershipLabel.setStyleName("gwt-Label");
    disclosureContent.add(fileOwnershipLabel);

    retainOwnershipDropDown.addChangeListener(new ChangeListener() {
        @Override
        public void onChange(Widget sender) {
            String value = retainOwnershipDropDown.getSelectedItem().getValue().toString();
            retainOwnership.setValue(value);
        }
    });
    DefaultListItem keepOwnershipListItem = new DefaultListItem(Messages.getString("keepOwnership"));
    keepOwnershipListItem.setValue("true");
    retainOwnershipDropDown.addItem(keepOwnershipListItem);
    DefaultListItem assignOwnershipListItem = new DefaultListItem(Messages.getString("assignOwnership"));
    assignOwnershipListItem.setValue("false");
    retainOwnershipDropDown.addItem(assignOwnershipListItem);

    retainOwnershipDropDown.setVisibleRowCount(1);
    disclosureContent.add(retainOwnershipDropDown);

    spacer = new VerticalPanel();
    spacer.setHeight("4px");
    disclosureContent.add(spacer);

    ChangeListener overwriteFileHandler = new ChangeListener() {
        @Override
        public void onChange(Widget sender) {
            String value = overwriteFileDropDown.getSelectedItem().getValue().toString();
            overwriteFile.setValue(value);
        }
    };
    overwriteFileDropDown.addChangeListener(overwriteFileHandler);

    HTML loggingLabel = new HTML(Messages.getString("logging"));
    loggingLabel.setStyleName("gwt-Label");
    disclosureContent.add(loggingLabel);

    final CustomListBox loggingDropDown = new CustomListBox();
    loggingDropDown.addChangeListener(new ChangeListener() {
        public void onChange(Widget sender) {
            String value = loggingDropDown.getSelectedItem().getValue().toString();
            logLevel.setValue(value);
        }
    });
    DefaultListItem noneListItem = new DefaultListItem(Messages.getString("none"));
    noneListItem.setValue("ERROR");
    loggingDropDown.addItem(noneListItem);
    DefaultListItem shortListItem = new DefaultListItem(Messages.getString("short"));
    shortListItem.setValue("WARN");
    loggingDropDown.addItem(shortListItem);
    DefaultListItem debugListItem = new DefaultListItem(Messages.getString("verbose"));
    debugListItem.setValue("TRACE");
    loggingDropDown.addItem(debugListItem);
    loggingDropDown.setVisibleRowCount(1);
    disclosureContent.add(loggingDropDown);

    mainPanel.add(disclosureContent);
    disclosurePanel.setContent(mainPanel);
    rootPanel.add(disclosurePanel);

    importDir.setName("importDir");
    importDir.setText(repositoryFile.getPath());
    importDir.setVisible(false);

    rootPanel.add(importDir);

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

    setFormAction();

    form.add(rootPanel);

    setContent(form);
}

From source file:org.pentaho.pat.client.ui.panels.PropertiesPanel.java

License:Open Source License

/**
 * PropertiesPanel Constructor.//from   w  w  w .  ja  v a 2  s.c  om
 * 
 * @param dPanel
 * 
 */
public PropertiesPanel(final DataPanel dPanel, PanelUtil.PanelType pType) {
    super();
    this.dataPanel = dPanel;
    this.queryId = Pat.getCurrQuery();

    EventFactory.getQueryInstance().addQueryListener(this);

    final LayoutPanel rootPanel = getLayoutPanel();

    final ScrollLayoutPanel mainPanel = new ScrollLayoutPanel();
    mainPanel.addStyleName("pat-propertiesPanel"); //$NON-NLS-1$
    mainPanel.setLayout(new BoxLayout(Orientation.HORIZONTAL));

    final FormPanel formPanel = new FormPanel();
    formPanel.setAction(FORM_ACTION);
    formPanel.setMethod(FORM_METHOD);
    //formPanel.setEncoding(FORM_ENCODING);

    Hidden curQuery = new Hidden(FORM_NAME_QUERY);
    curQuery.setName(FORM_NAME_QUERY);
    curQuery.setValue(queryId);
    formPanel.add(curQuery);

    executeButton = new Button(Pat.IMAGES.execute_no_ds().getHTML());
    executeButton.setTitle(Pat.CONSTANTS.executeQuery());
    executeButton.addClickHandler(new ClickHandler() {

        public void onClick(final ClickEvent arg0) {
            if (executemode == false) {
                Pat.executeQuery(PropertiesPanel.this, queryId);
                setExecuteButton(true);
                dPanel.swapWindows();
            } else {
                setExecuteButton(false);
                dPanel.swapWindows();
            }
        }

    });

    exportButton = new ToolButton(Pat.CONSTANTS.export());
    exportButton.setTitle(Pat.CONSTANTS.export());

    exportButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent arg0) {
            formPanel.submit();
        }
    });

    exportButton.setEnabled(false);

    exportCdaButton = new ToolButton("CDA");
    exportCdaButton.setTitle(Pat.CONSTANTS.export() + " as CDA");

    exportCdaButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent arg0) {
            SaveWindow.displayCDA();
        }
    });

    exportCdaButton.setEnabled(false);

    mdxButton = new ToolButton(Pat.CONSTANTS.mdx());
    mdxButton.setTitle(Pat.CONSTANTS.showMDX());
    mdxButton.addClickHandler(new ClickHandler() {

        public void onClick(final ClickEvent arg0) {
            ServiceFactory.getQueryInstance().getMdxForQuery(Pat.getSessionID(), queryId,
                    new AsyncCallback<String>() {

                        public void onFailure(final Throwable arg0) {
                            MessageBox.error(Pat.CONSTANTS.error(), arg0.getLocalizedMessage());
                        }

                        public void onSuccess(final String mdx) {
                            final WindowPanel winPanel = new WindowPanel(Pat.CONSTANTS.mdx());
                            final LayoutPanel wpLayoutPanel = new LayoutPanel(
                                    new BoxLayout(Orientation.VERTICAL));
                            wpLayoutPanel.setSize("450px", "200px"); //$NON-NLS-1$ //$NON-NLS-2$
                            final MDXRichTextArea mdxArea = new MDXRichTextArea();

                            mdxArea.setText(mdx);

                            wpLayoutPanel.add(mdxArea, new BoxLayoutData(1, 0.9));
                            final ToolButton closeBtn = new ToolButton(Pat.CONSTANTS.close());
                            closeBtn.addClickHandler(new ClickHandler() {
                                public void onClick(final ClickEvent arg0) {
                                    winPanel.hide();
                                }

                            });
                            final ToolButton mdxBtn = new ToolButton(Pat.CONSTANTS.newMdxQuery());
                            mdxBtn.addClickHandler(new ClickHandler() {
                                public void onClick(final ClickEvent arg0) {

                                    final Widget widget = MainTabPanel.getSelectedWidget();
                                    if (widget instanceof OlapPanel) {
                                        ((OlapPanel) widget).getCubeItem();
                                        final MdxPanel mdxpanel = new MdxPanel(
                                                ((OlapPanel) widget).getCubeItem(), Pat.getCurrConnection(),
                                                mdxArea.getText(), null);
                                        MainTabPanel.displayContentWidget(mdxpanel);
                                    }

                                    winPanel.hide();

                                }
                            });
                            final LayoutPanel wpButtonPanel = new LayoutPanel(
                                    new BoxLayout(Orientation.HORIZONTAL));

                            wpButtonPanel.add(mdxBtn);
                            wpButtonPanel.add(closeBtn);
                            wpLayoutPanel.add(wpButtonPanel);
                            wpLayoutPanel.layout();
                            winPanel.add(wpLayoutPanel);
                            winPanel.layout();
                            winPanel.pack();
                            winPanel.setSize("500px", "320px"); //$NON-NLS-1$ //$NON-NLS-2$
                            winPanel.center();

                        }

                    });

        }
    });

    hideBlanksButton = new ToolButton(Pat.IMAGES.zero().getHTML());
    hideBlanksButton.setTitle(Pat.CONSTANTS.showBlankCells());
    hideBlanksButton.setStyle(ToolButtonStyle.CHECKBOX);
    hideBlanksButton.setChecked(true);
    hideBlanksButton.addClickHandler(new ClickHandler() {

        public void onClick(final ClickEvent arg0) {
            EventFactory.getQueryInstance().getQueryListeners().fireQueryStartsExecution(PropertiesPanel.this,
                    queryId);
            ServiceFactory.getQueryInstance().setNonEmpty(Pat.getSessionID(), queryId,
                    hideBlanksButton.isChecked(), new AsyncCallback<CellDataSet>() {

                        public void onFailure(final Throwable arg0) {
                            EventFactory.getQueryInstance().getQueryListeners()
                                    .fireQueryFailedExecution(PropertiesPanel.this, queryId);
                            MessageBox.error(Pat.CONSTANTS.error(),
                                    MessageFactory.getInstance().failedNonEmpty());

                        }

                        public void onSuccess(final CellDataSet arg0) {

                            if (hideBlanksButton.isChecked()) {
                                hideBlanksButton.setTitle(Pat.CONSTANTS.showBlankCells());

                            } else {
                                hideBlanksButton.setTitle(Pat.CONSTANTS.hideBlankCells());
                            }
                            EventFactory.getQueryInstance().getQueryListeners()
                                    .fireQueryExecuted(PropertiesPanel.this, queryId, arg0);
                        }

                    });

        }

    });

    hideBlanksButton.setEnabled(false);

    final ToolButton createScenarioButton = new ToolButton("Create Scenario");
    createScenarioButton.setStyle(ToolButtonStyle.CHECKBOX);
    createScenarioButton.setEnabled(false);
    createScenarioButton.addClickHandler(new ClickHandler() {

        public void onClick(final ClickEvent arg0) {

            ServiceFactory.getQueryInstance().alterCell(queryId, Pat.getSessionID(), Pat.getCurrScenario(),
                    Pat.getCurrConnectionId(), "123", new AsyncCallback<CellDataSet>() {

                        public void onFailure(Throwable arg0) {
                            // TODO Auto-generated method stub

                        }

                        public void onSuccess(CellDataSet arg0) {
                            Pat.executeQuery(PropertiesPanel.this, queryId);
                        }

                    });

            /*ServiceFactory.getSessionInstance().createNewScenario(Pat.getSessionID(), Pat.getCurrConnection(), new AsyncCallback<String>(){
            public void onFailure(final Throwable arg0){
               MessageBox.error(Pat.CONSTANTS.error(), "Failed to set scenario");
            }
                    
            public void onSuccess(String scenario){
               createScenarioButton.setText(scenario);
               Pat.setCurrScenario(scenario);
            }
            });*/
        }
    });

    pivotButton = new ToolButton(Pat.CONSTANTS.pivot());
    pivotButton.setTitle(Pat.CONSTANTS.pivot());
    pivotButton.setStyle(ToolButtonStyle.CHECKBOX);
    pivotButton.addClickHandler(new ClickHandler() {

        public void onClick(final ClickEvent arg0) {
            EventFactory.getQueryInstance().getQueryListeners().fireQueryStartsExecution(PropertiesPanel.this,
                    queryId);

            ServiceFactory.getQueryInstance().swapAxis(Pat.getSessionID(), queryId,
                    new AsyncCallback<CellDataSet>() {

                        public void onFailure(final Throwable arg0) {

                            EventFactory.getQueryInstance().getQueryListeners()
                                    .fireQueryFailedExecution(PropertiesPanel.this, queryId);
                            MessageBox.error(Pat.CONSTANTS.error(),
                                    MessageFactory.getInstance().failedPivot(arg0.getLocalizedMessage()));
                        }

                        public void onSuccess(final CellDataSet arg0) {

                            EventFactory.getQueryInstance().getQueryListeners()
                                    .fireQueryExecuted(PropertiesPanel.this, queryId, arg0);

                        }

                    });

        }
    });
    pivotButton.setEnabled(false);

    layoutMenuButton = new ToolButton(Pat.IMAGES.chart_pie().getHTML());
    layoutMenuButton.setTitle(Pat.CONSTANTS.chart());
    layoutMenuButton.setStyle(ToolButtonStyle.MENU);
    layoutMenuButton.setEnabled(false);

    final PopupMenu layoutMenuBtnMenu = new PopupMenu();
    layoutMenuBtnMenu.addItem(Pat.CONSTANTS.grid(), new LayoutCommand(null));
    layoutMenuBtnMenu.addItem(Pat.CONSTANTS.chart(), new LayoutCommand(Region.CENTER));
    layoutMenuBtnMenu.addItem(Pat.CONSTANTS.top(), new LayoutCommand(Region.NORTH));
    layoutMenuBtnMenu.addItem(Pat.CONSTANTS.bottom(), new LayoutCommand(Region.SOUTH));
    layoutMenuBtnMenu.addItem(Pat.CONSTANTS.left(), new LayoutCommand(Region.WEST));
    layoutMenuBtnMenu.addItem(Pat.CONSTANTS.right(), new LayoutCommand(Region.EAST));

    layoutMenuButton.setMenu(layoutMenuBtnMenu);

    drillPositionButton = new ToolButton(
            ButtonHelper.createButtonLabel(Pat.IMAGES.drill(), "", ButtonLabelType.NO_TEXT));
    drillPositionButton.setTitle(Pat.CONSTANTS.drillPosition());
    drillPositionButton.setStyle(ToolButtonStyle.RADIO);
    drillPositionButton.setEnabled(false);
    drillPositionButton.setChecked(true);
    drillPositionButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {
            drillReplaceButton.setChecked(false);
            drillUpButton.setChecked(false);
            drillNoneButton.setChecked(false);
            drillPositionButton.setChecked(true);

            (new DrillCommand(DrillType.POSITION)).execute();
            EventFactory.getOperationInstance().getOperationListeners()
                    .fireDrillStyleChanged(PropertiesPanel.this, queryId, DrillType.POSITION);
        }
    });

    drillReplaceButton = new ToolButton(
            ButtonHelper.createButtonLabel(Pat.IMAGES.arrow_down(), "", ButtonLabelType.NO_TEXT));
    drillReplaceButton.setTitle(Pat.CONSTANTS.drillReplace());
    drillReplaceButton.setStyle(ToolButtonStyle.RADIO);
    drillReplaceButton.setEnabled(false);
    drillReplaceButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {
            drillPositionButton.setChecked(false);
            drillUpButton.setChecked(false);
            drillNoneButton.setChecked(false);
            drillReplaceButton.setChecked(true);

            (new DrillCommand(DrillType.REPLACE)).execute();
            EventFactory.getOperationInstance().getOperationListeners()
                    .fireDrillStyleChanged(PropertiesPanel.this, queryId, DrillType.REPLACE);
        }
    });

    drillUpButton = new ToolButton(
            ButtonHelper.createButtonLabel(Pat.IMAGES.arrow_up(), "", ButtonLabelType.NO_TEXT));
    drillUpButton.setTitle(Pat.CONSTANTS.drillUp());
    drillUpButton.setStyle(ToolButtonStyle.RADIO);
    drillUpButton.setEnabled(false);
    drillUpButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {
            drillPositionButton.setChecked(false);
            drillReplaceButton.setChecked(false);
            drillNoneButton.setChecked(false);
            drillUpButton.setChecked(true);

            (new DrillCommand(DrillType.UP)).execute();
            EventFactory.getOperationInstance().getOperationListeners()
                    .fireDrillStyleChanged(PropertiesPanel.this, queryId, DrillType.UP);
        }
    });

    drillNoneButton = new ToolButton(Pat.CONSTANTS.drillNone());
    drillNoneButton.setStyle(ToolButtonStyle.RADIO);
    drillNoneButton.setEnabled(false);
    drillNoneButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {
            drillPositionButton.setChecked(false);
            drillReplaceButton.setChecked(false);
            drillUpButton.setChecked(false);
            drillNoneButton.setChecked(true);

            (new DrillCommand(DrillType.NONE)).execute();
            EventFactory.getOperationInstance().getOperationListeners()
                    .fireDrillStyleChanged(PropertiesPanel.this, queryId, DrillType.NONE);
        }
    });

    drillThroughButton = new ToolButton(Pat.CONSTANTS.drillThrough());
    drillThroughButton.setTitle(Pat.CONSTANTS.drillThrough());
    drillThroughButton.setEnabled(false);
    drillThroughButton.setStyle(ToolButtonStyle.CHECKBOX);

    drillThroughButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {
            if (drillThroughButton.isChecked()) {
                EventFactory.getOperationInstance().getOperationListeners()
                        .fireOperationExecuted(PropertiesPanel.this, queryId, Operation.ENABLE_DRILLTHROUGH);
            } else {
                EventFactory.getOperationInstance().getOperationListeners()
                        .fireOperationExecuted(PropertiesPanel.this, queryId, Operation.DISABLE_DRILLTHROUGH);
            }

        }
    });

    ToolButton syncButton = new ToolButton(Pat.IMAGES.arrow_refresh().getHTML());
    syncButton.setTitle("Refresh Query");
    syncButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {
            ServiceFactory.getQueryInstance().getSelections(Pat.getSessionID(), queryId,
                    new AsyncCallback<Map<IAxis, PatQueryAxis>>() {

                        public void onFailure(Throwable arg0) {
                            MessageBox.alert("ERROR", "ERROR");

                        }

                        public void onSuccess(Map<IAxis, PatQueryAxis> arg0) {
                            Integer rows = arg0.get(IAxis.ROWS) != null
                                    ? arg0.get(IAxis.ROWS).getDimensions().size()
                                    : 0;
                            Integer cols = arg0.get(IAxis.COLUMNS) != null
                                    ? arg0.get(IAxis.COLUMNS).getDimensions().size()
                                    : 0;
                            Integer filter = arg0.get(IAxis.FILTER) != null
                                    ? arg0.get(IAxis.FILTER).getDimensions().size()
                                    : 0;
                            MessageBox.alert("OK", "rows: " + rows + " cols:" + cols + " filter:" + filter);
                        }

                    });

        }
    });

    if (pType == PanelUtil.PanelType.MDX) {
        mainPanel.add(exportButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(layoutMenuButton, new BoxLayoutData(FillStyle.HORIZONTAL));
    }
    if (pType == PanelUtil.PanelType.QM) {
        mainPanel.add(executeButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        // TODO enable sync button when implemented routines
        //            mainPanel.add(syncButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(exportButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(layoutMenuButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(drillPositionButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(drillReplaceButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(drillUpButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(drillNoneButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(mdxButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(hideBlanksButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        mainPanel.add(pivotButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        //            mainPanel.add(drillThroughButton, new BoxLayoutData(FillStyle.HORIZONTAL));
        //            mainPanel.add(createScenarioButton, new BoxLayoutData(FillStyle.HORIZONTAL));
    }
    if (Pat.isPlugin()) {
        mainPanel.add(exportCdaButton, new BoxLayoutData(FillStyle.HORIZONTAL));
    }
    mainPanel.add(formPanel, new BoxLayoutData(FillStyle.HORIZONTAL));
    rootPanel.add(mainPanel);

}

From source file:org.pentaho.pat.client.ui.panels.windows.ConnectMondrianPanel.java

License:Open Source License

/**
 * Run on panel initialize.//from ww  w  . j  a v  a  2 s  .c  om
 */
private void init() {

    final FormPanel formPanel = new FormPanel();
    formPanel.setAction(FORM_ACTION);
    formPanel.setMethod(FORM_METHOD);
    formPanel.setEncoding(FORM_ENCODING);
    formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(final SubmitCompleteEvent arg0) {
            if (arg0 != null && arg0.getResults() != null && arg0.getResults().length() > 0) {
                if (arg0.getResults().contains(VALIDATION_START)) {
                    final String tmp = arg0.getResults().substring(
                            arg0.getResults().indexOf(VALIDATION_START) + VALIDATION_START.length(),
                            arg0.getResults().indexOf(VALIDATION_END));
                    if (tmp != null && tmp.length() > 0) {
                        if (schemaValCheckbox.getValue()) {
                            MessageBox.info(Pat.CONSTANTS.warning(),
                                    MessageFactory.getInstance().schemaFileInvalid() + "<br>" + tmp); //$NON-NLS-1$
                        }
                    }
                }
                if (arg0.getResults().contains(SCHEMA_START)) {
                    final String tmp = arg0.getResults().substring(
                            arg0.getResults().indexOf(SCHEMA_START) + SCHEMA_START.length(),
                            arg0.getResults().indexOf(SCHEMA_END));
                    schemaData = decode(tmp);
                    saveButton.setEnabled(true);
                    viewSchemaButton.setEnabled(true);
                    viewSchemaButton.setText(Pat.CONSTANTS.viewSchema());
                    // TODO remove this later

                    Application.INSTANCE.showInfoPanel(Pat.CONSTANTS.fileUpload(), Pat.CONSTANTS.success());
                } else {
                    MessageBox.error(Pat.CONSTANTS.error(), Pat.CONSTANTS.fileUploadFailed());
                }
            } else {
                MessageBox.error(Pat.CONSTANTS.error(), Pat.CONSTANTS.checkErrorLog());
            }
        }
    });
    final FormLayout layout = new FormLayout("right:[40dlu,pref], 3dlu, 70dlu, 7dlu, " //$NON-NLS-1$
            + "right:[40dlu,pref], 3dlu, 70dlu", //$NON-NLS-1$
            "p, 3dlu, p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p, 3dlu,p"); //$NON-NLS-1$
    final PanelBuilder builder = new PanelBuilder(layout);
    builder.addLabel(Pat.CONSTANTS.name() + LABEL_SUFFIX, CellConstraints.xy(1, 1));
    builder.add(nameTextBox, CellConstraints.xyw(3, 1, 5));
    builder.addLabel(Pat.CONSTANTS.jdbcDriver() + LABEL_SUFFIX, CellConstraints.xy(1, 3));
    builder.add(driverListBox, CellConstraints.xyw(3, 3, 5));
    builder.addLabel(Pat.CONSTANTS.jdbcUrl() + LABEL_SUFFIX, CellConstraints.xy(1, 5));
    builder.add(urlTextBox, CellConstraints.xyw(3, 5, 5));
    builder.addLabel(Pat.CONSTANTS.username() + LABEL_SUFFIX, CellConstraints.xy(1, 7));
    builder.add(userTextBox, CellConstraints.xy(3, 7));
    builder.addLabel(Pat.CONSTANTS.password() + LABEL_SUFFIX, CellConstraints.xy(5, 7));
    builder.add(passwordTextBox, CellConstraints.xy(7, 7));
    builder.addLabel(Pat.CONSTANTS.schemaFile() + LABEL_SUFFIX, CellConstraints.xy(1, 9));
    fileUpload.setName(FORM_NAME_FILE);
    builder.add(fileUpload, CellConstraints.xyw(3, 9, 5));
    builder.add(schemaValCheckbox, CellConstraints.xyw(3, 11, 5));
    uploadButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            final String filename = fileUpload.getFilename();
            if (filename == null || filename.length() == 0) {
                MessageBox.error(Pat.CONSTANTS.error(), Pat.CONSTANTS.fileUploadNoFile());
            } else {
                formPanel.submit();
            }
        }
    });

    builder.add(uploadButton, CellConstraints.xy(3, 13));

    viewSchemaButton.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent arg0) {

            final WindowPanel winPanel = new WindowPanel(Pat.CONSTANTS.schemaFile());
            final LayoutPanel wpLayoutPanel = new LayoutPanel(new BoxLayout(Orientation.VERTICAL));
            wpLayoutPanel.setSize("450px", "200px"); //$NON-NLS-1$ //$NON-NLS-2$
            final RichTextArea schemaArea = new RichTextArea();
            String newStr = schemaData + "";
            newStr = newStr.replaceAll("\\<", "&lt;").replaceAll("\\>", "&gt;").replaceAll(" ", "&nbsp;");
            newStr = newStr.replaceAll("\t", "&nbsp;&nbsp;&nbsp;");
            newStr = newStr.replaceAll("(\r\n)", "<br>"); //$NON-NLS-1$ //$NON-NLS-2$
            //                newStr = newStr.replaceAll("[\r\n\t\f]", "<br>"); //$NON-NLS-1$ //$NON-NLS-2$
            schemaArea.setHTML(newStr + "");

            wpLayoutPanel.add(schemaArea, new BoxLayoutData(1, 0.9));
            final ToolButton saveBtn = new ToolButton(Pat.CONSTANTS.save());
            saveBtn.addClickHandler(new ClickHandler() {
                public void onClick(final ClickEvent arg0) {
                    String newStr = schemaArea.getHTML();
                    newStr = newStr.replaceAll("&lt;", "\\<").replaceAll("&gt;", "\\>").replaceAll("&nbsp;",
                            " ");
                    newStr = newStr.replaceAll("&nbsp;&nbsp;&nbsp;", "\t");
                    newStr = newStr.replaceAll("<br>", "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$
                    schemaData = newStr;
                    winPanel.hide();
                    ConnectionManagerWindow.display(false);
                }

            });

            final ToolButton closeBtn = new ToolButton(Pat.CONSTANTS.close());
            closeBtn.addClickHandler(new ClickHandler() {
                public void onClick(final ClickEvent arg0) {
                    winPanel.hide();
                    ConnectionManagerWindow.display(false);
                }

            });
            final LayoutPanel wpButtonPanel = new LayoutPanel(new BoxLayout(Orientation.HORIZONTAL));

            wpButtonPanel.add(saveBtn);
            wpButtonPanel.add(closeBtn);
            wpLayoutPanel.add(wpButtonPanel);
            wpLayoutPanel.layout();
            winPanel.add(wpLayoutPanel);
            winPanel.layout();
            winPanel.pack();
            winPanel.setSize("700px", "520px"); //$NON-NLS-1$ //$NON-NLS-2$

            ConnectionManagerWindow.close();
            winPanel.center();

        }
    });
    viewSchemaButton.setEnabled(false);
    viewSchemaButton.setText(Pat.CONSTANTS.noSchema());
    builder.add(viewSchemaButton, CellConstraints.xy(7, 13));

    builder.addLabel(Pat.CONSTANTS.role() + LABEL_SUFFIX, CellConstraints.xy(1, 15));
    builder.add(roleTextBox, CellConstraints.xyw(3, 15, 5));

    builder.add(startupCheckbox, CellConstraints.xy(3, 17));

    saveButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            final CubeConnection cc = getCubeConnection();
            if (validateConnection(cc)) {

                saveButton.setEnabled(false);
                ServiceFactory.getSessionInstance().saveConnection(Pat.getSessionID(), cc,
                        new AsyncCallback<String>() {
                            public void onFailure(final Throwable arg0) {
                                MessageBox.error(Pat.CONSTANTS.error(), MessageFactory.getInstance()
                                        .failedLoadConnection(arg0.getLocalizedMessage()));
                                saveButton.setEnabled(true);
                            }

                            public void onSuccess(final String id) {
                                if (cc.isConnectOnStartup()) {
                                    ConnectionManagerPanel.connectEvent(id, cc.isConnected(), true);
                                }
                                ConnectionManagerWindow.closeTabs();
                            }
                        });

            }
        }
    });

    saveButton.setEnabled(false);

    builder.add(saveButton, CellConstraints.xy(3, 19));

    cancelButton.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent event) {
            ConnectionManagerWindow.closeTabs();
        }
    });
    builder.add(cancelButton, CellConstraints.xy(7, 19));
    final LayoutPanel layoutPanel = builder.getPanel();
    layoutPanel.setPadding(15);
    formPanel.add(layoutPanel);
    this.getLayoutPanel().add(formPanel);
}

From source file:org.pentaho.platform.dataaccess.datasource.ui.importing.AnalysisImportDialogController.java

License:Open Source License

private void createWorkingForm() {
    if (formPanel == null) {
        formPanel = new FormPanel();
        formPanel.setMethod(FormPanel.METHOD_POST);
        formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
        formPanel.setAction(MONDRIAN_POSTANALYSIS_URL);
        formPanel.getElement().getStyle().setProperty("position", "absolute");
        formPanel.getElement().getStyle().setProperty("visibility", "hidden");
        formPanel.getElement().getStyle().setProperty("overflow", "hidden");
        formPanel.getElement().getStyle().setProperty("clip", "rect(0px,0px,0px,0px)");
        mainFormPanel = new FlowPanel();
        formPanel.add(mainFormPanel);/*from w  w w  .jav  a2 s . c o m*/
        analysisFileUpload = new FileUpload();
        analysisFileUpload.setName("uploadAnalysis");
        analysisFileUpload.getElement().setId("analysisFileUpload");
        analysisFileUpload.addChangeHandler(new ChangeHandler() {
            @Override
            public void onChange(ChangeEvent event) {
                schemaNameLabel.setValue(((FileUpload) event.getSource()).getFilename());
                importDialogModel.setUploadedFile(((FileUpload) event.getSource()).getFilename());
                acceptButton.setDisabled(!isValid());
            }
        });

        mainFormPanel.add(analysisFileUpload);

        VerticalPanel vp = (VerticalPanel) hiddenArea.getManagedObject();
        vp.add(formPanel);
        //addSubmitHandler(); moved to GwtDataSourceEditorEntryPoint
    }
}

From source file:org.pentaho.platform.dataaccess.datasource.ui.importing.MetadataImportDialogController.java

License:Open Source License

private void createWorkingForm() {
    String importURL = METADATA_IMPORT_URL;

    formPanel = new FormPanel();
    formPanel.setMethod(FormPanel.METHOD_POST);
    formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    formPanel.setAction(importURL);//ww  w  .ja  va2 s .  c  om
    formPanel.getElement().getStyle().setProperty("position", "absolute");
    formPanel.getElement().getStyle().setProperty("visibility", "hidden");
    formPanel.getElement().getStyle().setProperty("overflow", "hidden");
    formPanel.getElement().getStyle().setProperty("clip", "rect(0px,0px,0px,0px)");
    mainFormPanel = new FlowPanel();
    propertiesFileImportPanel = new FlowPanel();
    mainFormPanel.add(propertiesFileImportPanel);
    formPanel.add(mainFormPanel);
    formDomainIdText = new TextBox();
    formDomainIdText.setName("domainId");
    mainFormPanel.add(formDomainIdText);
    metadataFileUpload = new FileUpload();
    metadataFileUpload.setName("metadataFile");
    metadataFileUpload.getElement().setId("metaFileUpload");
    metadataFileUpload.addChangeHandler(new ChangeHandler() {
        @Override
        public void onChange(ChangeEvent event) {
            metaFileLocation.setValue(((FileUpload) event.getSource()).getFilename());
            importDialogModel.setUploadedFile(((FileUpload) event.getSource()).getFilename());
        }
    });
    mainFormPanel.add(metadataFileUpload);
    VerticalPanel vp = (VerticalPanel) hiddenArea.getManagedObject();
    vp.add(formPanel);
}

From source file:org.pentaho.platform.dataaccess.datasource.wizard.UploadFile.java

License:Open Source License

public void onModuleLoad() {
    // Create a FormPanel and point it at a service.
    final FormPanel uploadForm = new FormPanel();
    uploadForm.setAction(GWT.getModuleBaseURL() + "/UploadService");

    // Because we're going to add a FileUpload widget, we'll need to set the
    // form to use the POST method, and multipart MIME encoding.
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);

    // Create a panel to hold all of the form widgets.
    VerticalPanel panel = new VerticalPanel();
    uploadForm.setWidget(panel);//from w ww  . ja va  2  s  . co m

    // Create a TextBox, giving it a name so that it will be submitted.
    final TextBox tb = new TextBox();
    tb.setName("textBoxFormElement");
    panel.add(tb);

    // Create a FileUpload widget.
    FileUpload upload = new FileUpload();
    upload.setName("uploadFormElement");
    panel.add(upload);

    // Add a 'Upload' button.
    Button uploadSubmitButton = new Button("Upload");
    panel.add(uploadSubmitButton);

    uploadSubmitButton.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            uploadForm.submit();
        }
    });

    uploadForm.addFormHandler(new FormHandler() {
        public void onSubmit(FormSubmitEvent event) {
        }

        public void onSubmitComplete(FormSubmitCompleteEvent event) {
            Window.alert(event.getResults());
        }
    });

    RootPanel.get().add(uploadForm);
}

From source file:org.pentaho.ui.xul.gwt.tags.GwtFileDialog.java

License:Open Source License

public GwtFileDialog() {
    super("filedialog");
    uploadForm = new FormPanel();
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);
    // Create a panel to hold all of the form widgets.
    VerticalPanel panel = new VerticalPanel();
    uploadForm.setWidget(panel);/*w ww  .ja va2s  .c o m*/
    uploadForm.setVisible(false);
    // Create a FileUpload widget.
    upload = new FileUpload();
    upload.setName("uploadFormElement"); //$NON-NLS-1$
    panel.add(upload);
    RootPanel.get().add(uploadForm);
    setManagedObject(uploadForm);
}

From source file:org.pentaho.ui.xul.gwt.tags.GwtFileUpload.java

License:Open Source License

@SuppressWarnings("deprecation")
public void init(com.google.gwt.xml.client.Element srcEle, XulDomContainer container) {
    mainPanel = new VerticalPanel();
    setManagedObject(mainPanel);//  w  ww. jav a  2s  .  c o  m

    super.init(srcEle, container);
    if (!StringUtils.isEmpty(srcEle.getAttribute("action"))) {
        setAction(buildActionUrl(GWT.getModuleBaseURL(), srcEle.getAttribute("action")));
    }
    if (!StringUtils.isEmpty(srcEle.getAttribute("onuploadsuccess"))) {
        setOnUploadSuccess(srcEle.getAttribute("onuploadsuccess"));
    }
    if (!StringUtils.isEmpty(srcEle.getAttribute("onuploadfailure"))) {
        setOnUploadFailure(srcEle.getAttribute("onuploadfailure"));
    }

    uploadForm = new FormPanel();
    uploadForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadForm.setMethod(FormPanel.METHOD_POST);
    uploadForm.setHeight(getHeight() + "px");
    uploadForm.setWidth(getWidth() + "px");
    // Create a panel to hold all of the form widgets.
    HorizontalPanel panel = new HorizontalPanel();
    uploadForm.setWidget(panel);
    uploadForm.setVisible(true);
    // Create a FileUpload widget.
    upload = new FileUpload();
    upload.setStylePrimaryName("gwt-StyledFileUpload");
    upload.setName("uploadFormElement"); //$NON-NLS-1$
    upload.getElement().setId("uploadFormElement");
    upload.setVisible(true);
    upload.setHeight(getHeight() + "px");
    upload.setWidth(getWidth() + "px");
    upload.addChangeHandler(new ChangeHandler() {
        public void onChange(ChangeEvent event) {
            setSelectedFile(upload.getFilename());
        }
    });
    uploadPanel = new VerticalPanel();

    // -- upload styling -- //
    String uploadButtonImage = srcEle.getAttribute("image");
    String uploadButtonDisabledImage = srcEle.getAttribute("disabledimage");

    hiddenPanel = new HTMLPanel("<div id='hidden_div' class='gwt_file_upload_hidden_div'></div>");
    uploadTextBox = new GwtLabel();
    uploadTextBox.setId("gwt_FileUpload_uploadTextBox");

    GwtButton uploadButton = new GwtButton();
    uploadButton.setId("gwt_FileUpload_uploadButton");
    uploadButton.setHeight(22);

    final LabelWidget label = new LabelWidget("uploadFormElement");
    label.setStyleName("gwt_file_upload_label");
    // If "image" attribute has been defined in the fileupload control do not display the file textfield AND do not
    // set the button label.
    if (StringUtils.isEmpty(uploadButtonImage)) {
        uploadButton.setLabel("...");
        final Widget labelWidget = (Widget) uploadTextBox.getManagedObject();
        label.add(labelWidget);
        uploadTextBox.layout();
        labelWidget.setHeight(getHeight() + "px");
        labelWidget.setWidth((getWidth() - 55) + "px");
        DOM.setStyleAttribute(labelWidget.getElement(), "lineHeight", getHeight() + "px");
    } else {
        uploadButton.setImage(uploadButtonImage);
        uploadButton.setDisabledImage(uploadButtonDisabledImage);
    }

    label.add((Widget) uploadButton.getManagedObject());
    uploadButton.layout();
    hiddenPanel.add(upload, "hidden_div");
    hiddenPanel.add(label, "hidden_div");
    // -- upload styling -- //

    uploadPanel.add(hiddenPanel);
    panel.add(uploadPanel);
    mainPanel.add(uploadForm);
    if (getHeight() >= 0) {
        mainPanel.setHeight(getHeight() + "px");
    }
    if (getWidth() >= 0) {
        mainPanel.setWidth(getWidth() + "px");
    }

    uploadForm.addFormHandler(new FormHandler() {
        public void onSubmit(FormSubmitEvent event) {
            if (upload.getFilename() == null) {
                try {
                    GwtFileUpload.this.getXulDomContainer().invoke(getOnUploadFailure(), new Object[] {
                            new Throwable("No file has been selected. Please select the file to upload") });
                    return;
                } catch (XulException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }

        public void onSubmitComplete(FormSubmitCompleteEvent event) {
            String results = event.getResults();
            try {
                if (results != null && results.indexOf(ERROR) >= 0) {
                    if (results.indexOf(ERROR) + ERROR.length() < results.length()) {
                        String result = results.replaceAll("\\<.*?>", "");
                        GwtFileUpload.this.getXulDomContainer().invoke(getOnUploadFailure(),
                                new Object[] { new Throwable(result) });
                    }
                } else {
                    if (results != null) {
                        String result = results.replaceAll("\\<.*?>", "");
                        GwtFileUpload.this.getXulDomContainer().invoke(getOnUploadSuccess(),
                                new Object[] { result });
                    } else {
                        GwtFileUpload.this.getXulDomContainer().invoke(getOnUploadFailure(),
                                new Object[] { new Throwable("Unable to find upload service or "
                                        + "Upload service returned nothing") });
                    }
                }
            } catch (XulException xule) {
                xule.printStackTrace();
            }
        }
    });

    uploadForm.setWidth("100%");

}