Example usage for com.google.gwt.user.client.ui FileUpload getFilename

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

Introduction

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

Prototype

public String getFilename() 

Source Link

Document

Gets the filename selected by the user.

Usage

From source file:com.ikon.frontend.client.widget.form.FormManager.java

License:Open Source License

/**
 * getFilesToUpload/*from w  ww  .  j a v  a  2s.  c om*/
 */
public Collection<FileToUpload> getFilesToUpload(String transition) {
    List<FileToUpload> filesToUpload = new ArrayList<FileToUpload>();
    int rows = 0;

    for (GWTFormElement formElement : formElementList) {
        if (formElement instanceof GWTUpload) {
            HorizontalPanel hPanel = (HorizontalPanel) hWidgetProperties.get(formElement.getName());
            table.setWidget(rows, 1, hPanel);
            FileUpload fileUpload = (FileUpload) hPanel.getWidget(1);

            if (!fileUpload.getFilename().equals("")) {
                hPanel.remove(fileUpload);
                hPanel.add(new HTML(fileUpload.getFilename())); // replace uploadfile widget to text file
                FileToUpload fileToUpload = new FileToUpload();
                GWTUpload upload = (GWTUpload) formElement;

                if (upload.getType().equals(GWTUpload.TYPE_CREATE)) {
                    fileToUpload.setAction(UIFileUploadConstants.ACTION_INSERT);
                } else if (upload.getType().equals(GWTUpload.TYPE_UPDATE)) {
                    fileToUpload.setAction(UIFileUploadConstants.ACTION_UPDATE);
                }

                fileToUpload.setName(formElement.getName());
                fileToUpload.setFileUpload(fileUpload);
                fileToUpload.setSize(upload.getWidth());
                fileToUpload.setFireEvent(false);
                fileToUpload.setPath(upload.getFolderPath());
                fileToUpload.setDesiredDocumentName(upload.getDocumentName());
                fileToUpload.setWorkflow(workflow);
                fileToUpload.setLastToBeUploaded(false);
                fileToUpload.setEnableAddButton(false);
                fileToUpload.setEnableImport(false);
                fileToUpload.setWorkflowTaskId(taskInstance.getId());
                fileToUpload.setWorkflowTransition(transition);
                filesToUpload.add(fileToUpload);
            }
        }

        rows++;
    }

    // Indicates is the last file to be upload in the cycle
    if (filesToUpload.size() > 0) {
        filesToUpload.get(filesToUpload.size() - 1).setLastToBeUploaded(true);
    }

    return filesToUpload;
}

From source file:com.qualogy.qafe.gwt.client.factory.MainFactory.java

License:Apache License

public static void createTryMeWindow(String subwindow) {

    final WindowPanel w = new WindowPanel("Try me!");

    w.setResizable(true);/*from   w w w .j a  v  a  2 s . c om*/

    w.setAnimationEnabled(true);
    w.setSize("800px", "500px");

    VerticalPanel verticalPanel = new VerticalPanel();
    final ScrollLayoutPanel vp = new ScrollLayoutPanel();
    vp.setAlwaysShowScrollBars(false);
    vp.setWidth("800px");
    vp.setHeight("500px");
    w.setWidget(verticalPanel);
    // vp.setSpacing(5);
    // vp.setWidth("100%");
    final TabPanel tabPanel = new TabPanel();
    tabPanel.setAnimationEnabled(true);
    tabPanel.setWidth("580px");
    tabPanel.setHeight("500px");

    DockPanel dockPanel = new DockPanel();
    dockPanel.setWidth("580px");
    dockPanel.setHeight("500px");
    tabPanel.add(dockPanel, "Insert code!");
    final TextArea textArea = new TextArea();
    textArea.setVisibleLines(30);
    textArea.setHeight("auto");
    textArea.setWidth("580px");
    DOM.setElementAttribute(textArea.getElement(), "font-size", "10pt");

    dockPanel.add(textArea, DockPanel.CENTER);
    final MenuBar menu = new MenuBar();
    MenuBar renderMenu = new MenuBar(true);
    w.addResizeHandler(new ResizeHandler() {

        public void onResize(ResizeEvent event) {
            int height = event.getHeight();
            int width = event.getWidth();

            if (w.getWidget() != null) {
                w.setHeight((height) + "px");
                w.setWidth((width) + "px");
                vp.setHeight((height - 20) + "px");
                vp.setWidth((width - 20) + "px");
                tabPanel.setHeight((height - 20) + "px");
                tabPanel.setWidth((width - 20) + "px");
                menu.setWidth((width) + "px");
                textArea.setWidth((width - 20) + "px");
            }

        }
    });

    MenuItem gwtMenuItem = new MenuItem("GWT output", new Command() {

        public void execute() {
            String xml = textArea.getText();
            if (xml == null || xml.length() == 0) {
                MessageBox.error("Try me:Error", "There is no input");
            } else {
                MainFactoryActions.processUIXml(xml);
            }

        }
    });
    MenuItem flexMenuItem = new MenuItem("Flex output", new Command() {

        public void execute() {
            String xml = textArea.getText();
            if (xml == null || xml.length() == 0) {
                MessageBox.error("Try me:Error", "There is no input");
            } else {
                MainFactoryActions.processUIXmlFlex(xml);
            }

        }
    });

    renderMenu.addItem(gwtMenuItem);
    renderMenu.addItem(flexMenuItem);

    MenuBar codeMenu = new MenuBar(true);

    MenuItem clearXmlInput = new MenuItem("Clear", new Command() {

        public void execute() {
            textArea.setText("");

        }
    });

    MenuItem createHeaderButton = new MenuItem("Create Header", new Command() {

        public void execute() {
            final String headerText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
                    + "<application-mapping xmlns=\"http://qafe.com/schema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://qafe.com/schema http://www.qafe.com/schema/2.2/application-mapping.xsd\"> \n"
                    + "  <!-- PLEASE ENTER YOUR CODE HERE --> \n" + "</application-mapping> \n";

            textArea.setText(headerText);

        }
    });

    MenuItem createSampleAppButton = new MenuItem("Create Sample Application", new Command() {

        public void execute() {
            final String sampleText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"
                    + "<application-mapping xmlns=\"http://qafe.com/schema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://qafe.com/schema http://www.qafe.com/schema/2.2/application-mapping.xsd\"> \n"
                    + "<presentation-tier>\n" + "  <view>\n"
                    + "    <window id=\"window1\" displayname=\"Hello World\" width=\"200\" height=\"200\">\n"
                    + "      <rootpanel id=\"myRootPanel\">   \n" + "        <verticallayout>\n\n"
                    + "          <!-- PLEASE ENTER HERE YOUR CODE -->\n\n"
                    + "          <label id=\"mylabel\" displayname=\"Hello World\" />\n\n"
                    + "        </verticallayout>\n" + "      </rootpanel>\n" + "    </window>\n" + " </view>\n"
                    + "</presentation-tier>\n" +

                    "</application-mapping> \n";

            textArea.setText(sampleText);

        }
    });

    codeMenu.addItem(clearXmlInput);
    codeMenu.addItem(createHeaderButton);
    codeMenu.addItem(createSampleAppButton);

    menu.addItem("Render", renderMenu);
    menu.addItem("Code", codeMenu);

    if (menu != null) {
        verticalPanel.add(menu);
    }
    verticalPanel.add(vp);

    // w.setWidget(tabPanel);

    /*
     * FMB Upload
     */
    final FormPanel fmbForm = new FormPanel();
    fmbForm.setAction(GWT.getModuleBaseURL() + "/rpc.fmbupload");

    // 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.
    fmbForm.setEncoding(FormPanel.ENCODING_MULTIPART);
    fmbForm.setMethod(FormPanel.METHOD_POST);
    // Create a panel to hold all of the form widgets.
    VerticalPanel panelFmbUpload = new VerticalPanel();
    panelFmbUpload.setWidth("580px");
    panelFmbUpload.setHeight("500px");
    // panelFmbUpload.setHeight("100%");

    final FileUpload fmbFile = new FileUpload();
    final TextBox emailBox = new TextBox();
    final TextBox phoneBox = new TextBox();
    fmbFile.setName("fmbUploadElement");

    // Add an event handler to the form.
    fmbForm.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {

            if (event.getResults() != null) {
                if (event.getResults().startsWith("Conversion failed")) {
                    ClientApplicationContext.getInstance().log("Conversion failed",
                            "The file doesn't seem to be a valid Oracle Forms file. If you still want it to be converted for demo purpose, you can also send it to info@qafe.com",
                            true);

                } else if (event.getResults().startsWith("UUID")) {

                    String[] split = event.getResults().split("=");
                    if (split.length == 2) {
                        String uuid = split[1];
                        MainFactoryActions.processUIByUUID(uuid, textArea);
                        MainFactoryActions.notify("FMB uploaded with filename [" + fmbFile.getFilename() + "]",
                                "The message was sent by " + emailBox.getText() + " with optional phonenr: "
                                        + phoneBox.getText());
                        tabPanel.selectTab(0);
                    }
                } else {
                    // firefox workaround
                    String[] split = event.getResults().split("=");
                    if (split.length == 2) {
                        String uuid = split[1];

                        uuid = uuid.replaceAll("</pre>", "");
                        MainFactoryActions.processUIByUUID(uuid, textArea);
                        MainFactoryActions.notify("FMB uploaded with filename [" + fmbFile.getFilename() + "]",
                                "The message was sent by " + emailBox.getText() + " with optional phonenr: "
                                        + phoneBox.getText());
                        tabPanel.selectTab(0);
                    } else {
                        ClientApplicationContext.getInstance().log(event.getResults());
                    }
                }

            } else {
                ClientApplicationContext.getInstance().log(
                        "The Forms Conversion process could not handle this file. Please check the file.",
                        "Check whether or not this file is an FMB (not an FMX)", true);
            }
        }
    });

    FlexTable tempFmbPanel = new FlexTable();
    tempFmbPanel.setWidget(0, 1, fmbFile);
    tempFmbPanel.setWidget(0, 0, new Label("Input for FMB"));

    tempFmbPanel.setWidget(1, 0, new HTML(
            "<p>Note: the FMB you are uploading is only for <span style=\"color:red;\">demo</span> purpose.</p>"
                    + "<p>FMB's can have external dependencies like <span style=\"color:red;\">PLL, OLB's, images</span>,etc. Since they are <span style=\"color:red;\">not</span> included in the upload, the output might not appear correct.</p>"
                    + "<p>For a more detailed conversion of your FMB's please contact us at <span style=\"color:red;\">info@qafe.com </span></p> <p/>"
                    + "<p>Please fill in the information below, so that we can contact you for more information</p> "));
    tempFmbPanel.getFlexCellFormatter().setColSpan(1, 0, 2);

    tempFmbPanel.setWidget(2, 0, new Label("E-mail: (required)"));

    emailBox.setName("fmbEmail");
    emailBox.addBlurHandler(new BlurHandler() {

        public void onBlur(BlurEvent event) {
            String textValue = ((TextBoxBase) event.getSource()).getText();
            if (textValue != null) {
                if (textValue.replaceFirst(TextFieldGVO.REGEXP_TYPE_EMAIL_VALUE, "").length() > 0) {
                    ClientApplicationContext.getInstance().log("Email validation error",
                            TextFieldGVO.TYPE_EMAIL_DEFAULT_MESSAGE, true);
                }
            }

        }
    });
    tempFmbPanel.setWidget(2, 1, emailBox);

    tempFmbPanel.setWidget(3, 0, new Label("Phonenr:"));

    phoneBox.setName("fmbPhone");
    phoneBox.addBlurHandler(new BlurHandler() {

        public void onBlur(BlurEvent event) {

        }
    });
    tempFmbPanel.setWidget(3, 1, phoneBox);

    fmbForm.add(tempFmbPanel);

    panelFmbUpload.add(fmbForm);
    // Add a 'submit' button.
    panelFmbUpload.add(new Button("Generate", new ClickHandler() {

        public void onClick(ClickEvent event) {
            fmbForm.submit();

        }
    }));
    // Add an event handler to the form.
    fmbForm.addSubmitHandler(new FormPanel.SubmitHandler() {
        public void onSubmit(SubmitEvent event) {
            // This event is fired just before the form is submitted. We can take
            // this opportunity to perform validation.
            if (emailBox.getText().length() == 0) {
                ClientApplicationContext.getInstance().log("Email validation error",
                        "Please fill in your email address", true);
                event.cancel();
            } else if (fmbFile.getFilename() == null || fmbFile.getFilename().length() == 0) {
                ClientApplicationContext.getInstance().log("Uploaded file validation error",
                        "There is no file selected. Please select one to continue", true);
                event.cancel();
            }
        }
    });

    tabPanel.add(panelFmbUpload, "Forms Conversion");

    vp.add(tabPanel);
    w.center();
    if (QAFEKeywordsGVO.SYSTEM_MENUITEM_TRYME_FORMS.equals(subwindow)) {
        tabPanel.selectTab(1);

    } else {
        tabPanel.selectTab(0);
    }
}

From source file:com.qualogy.qafe.gwt.client.ui.renderer.FileUploadRenderer.java

License:Apache License

public UIObject render(ComponentGVO component, String uuid, String parent, String context) {
    HorizontalPanel uiObject = null;//from  www  .ja  v  a  2 s .c o  m
    final String finalParent = parent;
    if (component != null) {
        if (component instanceof FileUploadGVO) {
            if (component.getMenu() != null) {
                final ComponentGVO finalComponentGVO = component;
                final String finalUuid = uuid;
                uiObject = new HorizontalPanel() {
                    @Override
                    public void onBrowserEvent(Event event) {
                        if (event.getTypeInt() == Event.ONCONTEXTMENU) {
                            DOM.eventPreventDefault(event);
                            applyContextMenu(event, finalComponentGVO, finalUuid, finalParent);
                        }
                        super.onBrowserEvent(event);
                    }

                    @Override
                    protected void setElement(Element elem) {
                        super.setElement(elem);
                        sinkEvents(Event.ONCONTEXTMENU);
                    }
                };
            } else {
                uiObject = new HorizontalPanel();
            }
            final FormPanel formPanel = new FormPanel();
            formPanel.setAction(GWT.getModuleBaseURL() + "/rpc.upload");
            formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
            formPanel.setMethod(FormPanel.METHOD_POST);

            final Button uploadButtonComponent = new Button("Upload");
            uploadButtonComponent.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    formPanel.submit();
                }
            });

            final FileUpload fileUploadComponent = new FileUpload();
            fileUploadComponent.setName("uploadElement");
            fileUploadComponent.addChangeHandler(new ChangeHandler() {
                public void onChange(ChangeEvent event) {
                    String filename = fileUploadComponent.getFilename();
                    boolean enabled = (filename != null) && (filename.length() > 0);
                    uploadButtonComponent.setEnabled(enabled);
                }
            });

            Hidden appId = new Hidden();
            final String appID = ClientApplicationContext.getInstance().getWindowSession();
            appId.setName("APPUUID=" + appID);

            Hidden windowId = new Hidden();
            windowId.setName("WINDOWID=" + parent);

            Grid gridPanel = new Grid(2, 4);
            gridPanel.setWidget(0, 0, fileUploadComponent);
            gridPanel.setWidget(0, 1, uploadButtonComponent);
            gridPanel.setWidget(0, 2, appId);
            gridPanel.setWidget(0, 3, windowId);
            formPanel.add(gridPanel);

            RendererHelper.fillIn(component, formPanel, uuid, parent, context);
            formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

                public void onSubmitComplete(SubmitCompleteEvent event) {
                    String uuId = event.getResults();
                    boolean success = false;
                    if (uuId != null && uuId.indexOf("=") > 0) {
                        uuId = uuId.substring(uuId.indexOf("=") + 1);
                        success = true;
                    }
                    if (formPanel instanceof HasWidgets) {
                        HasWidgets hasWidgets = (HasWidgets) formPanel;
                        Iterator<Widget> itr = hasWidgets.iterator();
                        while (itr.hasNext()) {
                            Widget widget = itr.next();
                            if (widget instanceof Grid) {
                                Grid gridPanel = (Grid) widget;
                                final FileUpload fileUpload = (FileUpload) gridPanel.getWidget(0, 0);
                                final Button uploadButton = (Button) gridPanel.getWidget(0, 1);
                                if (success) {
                                    fileUpload.setVisible(false);
                                    uploadButton.setVisible(false);
                                    String fileName = event.getResults().substring(0,
                                            event.getResults().indexOf("#"));
                                    final String viewUrl = GWT.getModuleBaseURL() + "/rpc.view?APPUUID=" + appID
                                            + "&WINDOWID=" + finalParent + "&VIEW=" + uuId;
                                    final Label fileNameLabel = new Label(fileName);
                                    DOM.setStyleAttribute(fileNameLabel.getElement(), "textDecoration",
                                            "underline");
                                    DOM.setStyleAttribute(fileNameLabel.getElement(), "cursor", "hand");
                                    fileNameLabel.addClickHandler(new ClickHandler() {
                                        public void onClick(ClickEvent event) {
                                            Window.open(viewUrl, "UploadedFile", null);
                                        }
                                    });
                                    fileNameLabel.setVisible(true);

                                    final Label clearLabel = new Label("Clear");
                                    clearLabel.setVisible(true);
                                    final String finalUuId = uuId;

                                    DOM.setStyleAttribute(clearLabel.getElement(), "textDecoration",
                                            "underline");
                                    DOM.setStyleAttribute(clearLabel.getElement(), "cursor", "hand");

                                    clearLabel.addClickHandler(new ClickHandler() {
                                        public void onClick(ClickEvent event) {
                                            MainFactoryActions.removeUploadedFile(appID, finalParent,
                                                    finalUuId);
                                            DOM.setElementAttribute(fileUpload.getElement(), "fu-uuid", "");
                                            fileNameLabel.setVisible(false);
                                            clearLabel.setVisible(false);
                                            fileUpload.setVisible(true);
                                            uploadButton.setVisible(true);
                                            init(fileUpload, uploadButton);
                                        }
                                    });
                                    gridPanel.setWidget(1, 0, fileNameLabel);
                                    gridPanel.setWidget(1, 1, clearLabel);

                                    DOM.setElementAttribute(fileUpload.getElement(), "fu-uuid", uuId);
                                    CallbackHandler.createCallBack(formPanel, "onfinish", null, null);
                                } else {
                                    Hyperlink fileNameLabel = (Hyperlink) gridPanel.getWidget(1, 0);
                                    fileNameLabel.setText("Uploading unsuccessfull.");
                                    fileNameLabel.setVisible(true);
                                }
                            }
                        }
                    }
                }
            });
            uiObject.add(formPanel);

            init(fileUploadComponent, uploadButtonComponent);
        }
    }
    return uiObject;
}

From source file:edu.iastate.airl.semtus.client.SEMTUSWEBAPP.java

License:Open Source License

public FormPanel upload() {

    final FormPanel form = new FormPanel();
    form.setAction(GWT.getModuleBaseURL() + "upload");

    // 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.
    form.setEncoding(FormPanel.ENCODING_MULTIPART);
    form.setMethod(FormPanel.METHOD_POST);

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

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

    panel.add(new HTML("&nbsp;&nbsp;"));

    // Add a 'submit' button.
    panel.add(new Button("Upload", new ClickHandler() {

        public void onClick(ClickEvent event) {

            String filename = upload.getFilename();

            if (filename.length() == 0) {

                Window.alert("No File Specified");

            } else {

                form.submit();
            }
        }
    }));

    panel.add(new HTML("&nbsp;"));

    // Add a 'Done' button.
    panel.add(new Button("Done", new ClickHandler() {
        public void onClick(ClickEvent event) {

            uploadBox.hide();
            tabPanel.selectTab(0);
        }
    }));

    // Add an event handler to the form.
    form.addSubmitHandler(new FormPanel.SubmitHandler() {
        public void onSubmit(SubmitEvent event) {
        }
    });

    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
        public void onSubmitComplete(SubmitCompleteEvent event) {

            // Check if there's been an error in upload
            if (event.getResults() == null) {

                Window.alert(
                        "Ontology Upload Failed. Please give us feedback [sushain.pandit@gmail.com] explaining the parameters of upload (filesize, format, etc) and we'll try to get it resolved asap.");

            } else if (event.getResults().toLowerCase().contains("file already exists")) { // if it's already present on
                // server, then we're just
                // fine.

                Window.alert(
                        "You just uploaded this ontology. Please proceed to the workspace for text input. Thanks !");

            } else if (event.getResults().toLowerCase().contains("error")
                    || event.getResults().toLowerCase().contains("not available")) { // o'wise flag an error

                Window.alert(
                        "Ontology Upload Failed. Please give us feedback [sushain.pandit@gmail.com] explaining the parameters of upload (filesize, format, etc) and we'll try to get it resolved asap.");

            } else {

                Window.alert(event.getResults());
                Window.alert("Ontology Upload Successful");
            }
        }
    });

    return form;
}

From source file:net.s17fabu.vip.gwt.showcase.client.content.widgets.CwFileUpload.java

License:Apache License

/**
 * Initialize this example.//from   www .  j a va 2s  .com
 */
@Override
public Widget onInitialize() {
    // Create a vertical panel to align the content
    VerticalPanel vPanel = new VerticalPanel();

    // Add a label
    vPanel.add(new HTML(constants.cwFileUploadSelectFile()));

    // Add a file upload widget
    final FileUpload fileUpload = new FileUpload();
    fileUpload.ensureDebugId("cwFileUpload");
    vPanel.add(fileUpload);

    // Add a button to upload the file
    Button uploadButton = new Button(constants.cwFileUploadButton());
    uploadButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            String filename = fileUpload.getFilename();
            if (filename.length() == 0) {
                Window.alert(constants.cwFileUploadNoFileError());
            } else {
                Window.alert(constants.cwFileUploadSuccessful());
            }
        }
    });
    vPanel.add(new HTML("<br>"));
    vPanel.add(uploadButton);

    // Return the layout panel
    return vPanel;
}

From source file:net.scran24.admin.client.UserManager.java

public UserManager() {
    FlowPanel contents = new FlowPanel();

    final FormPanel form = new FormPanel();
    form.setAction(GWT.getModuleBaseURL() + "uploadUserInfo");

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

    VerticalPanel panel = new VerticalPanel();
    form.setWidget(panel);//from w ww  .  jav a 2s  .  com

    final FileUpload upload = new FileUpload();
    upload.setName("file");
    panel.add(upload);

    RadioButton append = new RadioButton("mode", "Append to existing user list");
    append.setFormValue("append");

    final RadioButton replace = new RadioButton("mode", "Replace existing user list");
    replace.setFormValue("replace");

    replace.setValue(true);

    panel.add(append);
    panel.add(replace);

    panel.add(WidgetFactory.createButton("Upload", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            form.submit();
        }
    }));

    form.addSubmitHandler(new SubmitHandler() {
        @Override
        public void onSubmit(SubmitEvent event) {
            if (upload.getFilename().isEmpty()) {
                Window.alert("Please choose a .csv file containing user information to upload");
                event.cancel();
            } else if (replace.getValue())
                if (!Window.confirm(
                        "Doing this will delete all user information from the database and replace it with the list you are submitting. Proceed?"))
                    event.cancel();
        }
    });

    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            // This is not a very robust way of detecting the status code,
            // but unfortunately there does not seem to be a better way of doing
            // this
            // that supports IE8 -- Ivan.
            // https://code.google.com/p/google-web-toolkit/issues/detail?id=7365

            String result = event.getResults();

            if (result.equals("OK"))
                Window.alert("User information uploaded.");
            else if (result.startsWith("ERR:")) {
                Window.alert("There was a problem uploading the user information: " + result.substring(4));
            } else if (result.contains("401")) {
                LoginForm.showPopup(new Callback1<UserInfo>() {
                    @Override
                    public void call(UserInfo info) {
                        form.submit();
                    }
                });
            } else if (result.contains("403")) {
                // User is not authorised, e.g. someone has logged on as admin,
                // opened the user upload tab and timed out, then someone else
                // logged on as someone who does not have the right to
                // upload users. In this case, let them know and refresh the page
                // to either show the UI that corresponds to their set of permissions
                // or redirect them to another page.

                Window.alert("You are not authorised to upload user information.");
                Location.reload();
            }
        }
    });
    contents.add(new HTMLPanel("<h2>Staff user accounts</h2>"));
    contents.add(new Button("Add"));

    contents.add(new HTMLPanel("<h2>Respondent user accounts</h2>"));
    contents.add(form);

    initWidget(contents);
}

From source file:net.scran24.common.client.UserInfoUpload.java

public UserInfoUpload(final String surveyId, final String role, final List<String> permissions,
        final Callback1<Option<String>> onUploadComplete) {
    final FormPanel form = new FormPanel();
    form.setAction(GWT.getModuleBaseURL() + "../staff/uploadUserInfo?surveyId=" + surveyId);

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

    VerticalPanel panel = new VerticalPanel();
    form.setWidget(panel);//  w w w.j  a v  a  2s  .c o m

    final Hidden roleField = new Hidden("role", role);
    panel.add(roleField);

    for (String perm : permissions) {
        final Hidden permField = new Hidden("permission", perm);
        panel.add(permField);
    }

    final FileUpload upload = new FileUpload();
    upload.setName("file");
    panel.add(upload);

    Button uploadButton = WidgetFactory.createButton("Upload", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            form.submit();
        }
    });

    uploadButton.getElement().addClassName("scran24-admin-button");

    panel.add(uploadButton);

    form.addSubmitHandler(new SubmitHandler() {
        @Override
        public void onSubmit(SubmitEvent event) {
            if (upload.getFilename().isEmpty()) {
                Window.alert("Please choose a .csv file containing user information to upload");
                event.cancel();
            }
        }
    });

    form.addSubmitCompleteHandler(new SubmitCompleteHandler() {
        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {
            // This is not a very robust way of detecting the status code,
            // but unfortunately there does not seem to be a better way of
            // doing this that supports IE8
            // https://code.google.com/p/google-web-toolkit/issues/detail?id=7365

            String result = event.getResults();

            if (result.equals("OK")) {
                onUploadComplete.call(Option.<String>none());
            } else if (result.startsWith("ERR:")) {
                onUploadComplete.call(
                        Option.some("There was a problem uploading user information: " + result.substring(4)));
            } else if (result.contains("401")) {
                LoginForm.showPopup(new Callback1<UserInfo>() {
                    @Override
                    public void call(UserInfo info) {
                        form.submit();
                    }
                });
            } else if (result.contains("403")) {
                // User is not authorised, e.g. someone has logged on as
                // admin, opened the user upload tab and timed out, then someone
                // else logged on as someone who does not have the right to
                // upload users. In this case, let them know and refresh the
                // page to either show the UI that corresponds to their set of
                // permissions or redirect them to another page.
                onUploadComplete.call(Option.some("You are not authorised to upload user information."));
            } else {
                onUploadComplete
                        .call(Option.some("There was an problem uploading user information: " + result));
            }
        }
    });

    initWidget(form);
}

From source file:org.catrobat.html5player.client.Html5Player.java

License:Open Source License

public void onModuleLoad() {
    mainPanel.add(rotateLeftButton);//from  w w  w. ja va2s.  c om
    mainPanel.add(rotateRightButton);
    final String projectFileUrl = Window.Location.getParameter("projectfileurl");
    final String projectNumber = Window.Location.getParameter("projectnumber");
    if (projectFileUrl != null) {
        mainPanel.add(rePlayButton);
        mainPanel.add(zoomInButton);
        mainPanel.add(zoomOutButton);
        mainPanel.add(screenPanel);
    } else {

        //      String projectPath = Window.Location.getParameter("projectpath");
        //      if(projectPath != null && !projectPath.equals(""))
        //      {
        //         Const.PROJECT_PATH = projectPath;
        //      }

        if (projectNumber == null) {

            //         mainPanel.add(playButton);
            //         playButton.ensureDebugId("playButton");
            //
            //         mainPanel.add(projectListBox);
            //         playButton.ensureDebugId("projectListBox");
            //
            //         mainPanel.add(showLogButton);
            //         showLogButton.ensureDebugId("showLogBox");
            //
            //         mainPanel.add(screenPanel);
            //         screenPanel.add(logBox);
            mainPanel.add(rePlayButton);
            mainPanel.add(zoomInButton);
            mainPanel.add(zoomOutButton);
            VerticalPanel panel = new VerticalPanel();

            //create a file upload widget
            final FileUpload fileUpload = new FileUpload();
            //create upload button

            //pass action to the form to point to service handling file
            //receiving operation.
            form.setAction(GWT.getModuleBaseURL() + "fileupload");
            // set form to use the POST method, and multipart MIME encoding.
            form.setEncoding(FormPanel.ENCODING_MULTIPART);
            form.setMethod(FormPanel.METHOD_POST);
            fileUpload.setName("uploadFormElement");
            panel.add(fileUpload);
            //add a button to upload the file
            panel.add(uploadButton);
            uploadButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    //get the filename to be uploaded
                    String filename = fileUpload.getFilename();
                    if (filename.length() == 0) {
                        Window.alert("No File Specified!");
                    } else {
                        form.submit();
                    }
                }
            });

            form.add(panel);
            mainPanel.add(uploadLabel);
            mainPanel.add(form);
            mainPanel.add(screenPanel);

        } else {
            mainPanel.add(rePlayButton);
            mainPanel.add(zoomInButton);
            mainPanel.add(zoomOutButton);
            mainPanel.add(screenPanel);
        }
    }

    if (Scene.get().createScene() == false) {
        //TODO exception  if canvas not supported?
        CatrobatDebug.error("Canvas not supported");
        return;
    }

    rootCanvas = Scene.get().getCanvas();
    screenPanel.add(rootCanvas);
    rootCanvas.ensureDebugId("rootCanvas");

    //populateProjectsListBox();

    RootPanel.get("firstWindow").add(mainPanel);

    final Stage stage = Stage.getInstance();
    stage.setCanvas(rootCanvas);
    stage.setLogBox(logBox);

    stage.defaultLogBoxSettings();

    server = new ServerConnectionCalls();

    playButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            rotationAngle = 0;
            rotateDirection(0, screenPanel);

            CatrobatDebug.info("Play button was clicked, project: " + projectNumber + " is selected");

            stage.clearStage();

            stage.displayLoadingImage();

            stage.setProjectNumber(projectNumber);

            //get xml-projectfile from server
            server.getXML(projectNumber);
        }
    });

    form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
        @Override
        public void onSubmitComplete(SubmitCompleteEvent event) {

            //Window.alert(event.getResults());
            rotationAngle = 0;
            rotateDirection(0, screenPanel);
            //int selectedIndex = projectListBox.getSelectedIndex();
            //String projectNumber = projectListBox.getValue(selectedIndex);

            stage.clearStage();
            stage.displayLoadingImage();
            stage.setProjectNumber(projectNumber);
            server.getXML();
        }
    });

    //handle click on the log-button
    //
    showLogButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            logBox.setVisible(!logBox.isVisible());
        }
    });

    //handle click on the rotateLeft-button
    //
    rotateLeftButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            rotateLeft(screenPanel);
        }
    });

    //handle click on the rotateRight-button
    //
    rotateRightButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            rotateRight(screenPanel);
        }
    });

    //handle click on the replay-button
    //
    rePlayButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            stage.clearStage();

            stage.displayLoadingImage();

            stage.setProjectNumber(projectNumber);
            if (projectNumber != null) {
                server.getXML(projectNumber);
            } else {
                server.getXML();
            }
        }
    });

    //handle click on the zoomIn-button
    //
    zoomInButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {

            double twice = 2;
            Scene.get().zoomScene(twice);
        }
    });

    //handle click on the zoomOut-button
    //
    zoomOutButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {

            double half = 0.5;
            Scene.get().zoomScene(half);
        }
    });

    //handle click on the canvas
    //
    rootCanvas.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            stage.getSpriteManager().handleScreenClick(
                    getRelativeXforRotation(event.getRelativeX(rootCanvas.getCanvasElement()),
                            event.getRelativeY(rootCanvas.getCanvasElement()), screenPanel),
                    getRelativeYforRotation(event.getRelativeX(rootCanvas.getCanvasElement()),
                            event.getRelativeY(rootCanvas.getCanvasElement()), screenPanel));

        }

    });

    //      if(projectNumber != null)
    //      {
    //         CatrobatDebug.on();
    //         stage.clearStage();
    //
    //         stage.displayLoadingImage();
    //
    //         stage.setProjectNumber(projectNumber);
    //         server.getXML(projectNumber);
    //      }

    if (projectFileUrl != null) {
        stage.clearStage();

        stage.displayLoadingImage();
        server.getXMLFromProjectFileUrl(projectFileUrl);
    }

}

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);/*from   w  w w  .  j  a  v  a 2  s.co 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.drools.brms.client.admin.BackupManager.java

License:Apache License

private Widget newImportWidget() {

    final FormPanel uploadFormPanel = new FormPanel();
    uploadFormPanel.setAction(GWT.getModuleBaseURL() + "backup");
    uploadFormPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
    uploadFormPanel.setMethod(FormPanel.METHOD_POST);

    HorizontalPanel panel = new HorizontalPanel();
    uploadFormPanel.setWidget(panel);//from   ww  w. j  ava  2s .  com

    final FileUpload upload = new FileUpload();
    upload.setName(HTMLFileManagerFields.FILE_UPLOAD_FIELD_NAME_IMPORT);
    panel.add(upload);

    panel.add(new Label("import:"));
    ImageButton ok = new ImageButton("images/upload.gif");
    ok.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            doImportFile(uploadFormPanel);
        }

        private void doImportFile(final FormPanel uploadFormPanel) {
            if (Window.confirm("Are you sure you want to import? this will erase any content in the "
                    + "repository currently?")) {
                LoadingPopup.showMessage("Importing repository, please wait, as this could take some time...");
                uploadFormPanel.submit();
            }
        }
    });

    panel.add(ok);

    uploadFormPanel.addFormHandler(new FormHandler() {
        public void onSubmitComplete(FormSubmitCompleteEvent event) {
            if (event.getResults().indexOf("OK") > -1) {
                Window.alert(
                        "Rules repository imported successfully. Please refresh your browser (F5) to show the new content. ");
            } else {
                ErrorPopup.showMessage(
                        "Unable to import into the repository. Consult the server logs for error messages.");
            }
            LoadingPopup.close();
        }

        public void onSubmit(FormSubmitEvent event) {
            if (upload.getFilename().length() == 0) {
                Window.alert("You did not specify an exported repository filename !");
                event.setCancelled(true);
            } else if (!upload.getFilename().endsWith(".xml")) {
                Window.alert("Please specify a valid repository xml file.");
                event.setCancelled(true);
            }

        }
    });

    return uploadFormPanel;
}