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

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

Introduction

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

Prototype

private HTMLPanel(Element elem) 

Source Link

Document

Construct a new HTMLPanel with the specified element.

Usage

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 .  ja  v  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%");

}

From source file:org.qipki.clients.web.client.ui.widgets.ExternalResourcePanel.java

License:Open Source License

public void load(final String url, final RequestCallback callback) {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    rb.setCallback(new RequestCallback() {

        @Override// w w  w  .j ava  2  s.  c o m
        public void onResponseReceived(final Request request, final Response response) {
            new Timer() {

                @Override
                public void run() {
                    panel.clear();
                    panel.add(new HTMLPanel(response.getText()));
                    ExternalResourcePanel.this.url = url;
                    callback.onResponseReceived(request, response);
                }

            }.schedule(2000);
        }

        @Override
        public void onError(Request request, Throwable exception) {
            panel.clear();
            panel.add(new Label("Request ERROR: " + exception.getMessage()));
            callback.onError(request, exception);
        }

    });
    panel.clear();
    if (loadingPanel != null) {
        panel.setWidget(loadingPanel);
    }
    try {
        rb.send();
    } catch (RequestException ex) {
        panel.add(new Label("Request EXCEPTION: " + ex.getMessage()));
    }
}

From source file:org.rest.client.ui.desktop.RequestViewImpl.java

License:Apache License

@UiHandler("deleteEndpoint")
void onDeleteEndpoint(ClickEvent e) {
    e.preventDefault();//from w  ww  .ja  v a 2  s . co  m
    final DialogBox dialog = new DialogBox(true);
    dialog.setAnimationEnabled(true);
    dialog.setGlassEnabled(true);
    dialog.setModal(true);

    HTMLPanel wrapper = new HTMLPanel("");
    Label message = new Label("Delete selected endpoint?");
    HTMLPanel buttons = new HTMLPanel("");
    buttons.setStyleName("dialogButtons");
    Button confirm = new Button("Confirm");
    confirm.setStyleName("button");
    Button cancel = new Button("Cancel");
    cancel.setStyleName("button");
    buttons.add(confirm);
    buttons.add(cancel);
    wrapper.add(message);
    wrapper.add(buttons);
    dialog.add(wrapper);
    dialog.show();
    dialog.center();
    cancel.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            dialog.hide();
        }
    });
    confirm.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            dialog.hide();
            listener.deleteCurrentEndpoint();
        }
    });
}

From source file:org.rest.client.ui.desktop.widget.RequestBodyWidget.java

License:Apache License

private void addNewFormRow(String key, String value) {
    final HTMLPanel row = new HTMLPanel("");
    row.setStyleName("Request_Body_Widget_flex");
    TextBox keyBox = new TextBox();
    TextBox valueBox = new TextBox();
    InlineLabel removeButton = new InlineLabel("x");

    final FormInputs inputsListItem = new FormInputs(keyBox, valueBox);
    formInputs.add(inputsListItem);/*from   www  . j  a v a2s . c  om*/

    if (key != null) {
        keyBox.setValue(key);
    }
    if (value != null) {
        valueBox.setValue(value);
    }

    keyBox.getElement().setAttribute("placeholder", "key");
    valueBox.getElement().setAttribute("placeholder", "value");

    valueBox.addStyleName("formValueInput");
    removeButton.addStyleName("removeButton");
    removeButton.setTitle("Remove");
    keyBox.addValueChangeHandler(formRowChange);
    valueBox.addValueChangeHandler(formRowChange);

    final FlowPanel keyContainer = new FlowPanel();
    keyContainer.add(keyBox);
    keyContainer.addStyleName("Request_Body_Widget_flex");

    final FlowPanel valueContainer = new FlowPanel();
    valueContainer.add(valueBox);
    valueContainer.addStyleName("Request_Body_Widget_flex" + " " + "Request_Body_Widget_valueBlock");

    final FlowPanel actionsContainer = new FlowPanel();
    actionsContainer.add(removeButton);
    actionsContainer.addStyleName("Request_Body_Widget_flex");

    row.add(keyContainer);
    row.add(valueContainer);
    row.add(actionsContainer);

    payloadFormPanel.add(row);

    removeButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            formInputs.remove(inputsListItem);
            row.removeFromParent();
            updateRaw();
        }
    });

    keyBox.getElement().focus();
}

From source file:org.rest.client.ui.desktop.widget.RequestBodyWidget.java

License:Apache License

private void addNewFileRow(String key) {
    final HTMLPanel row = new HTMLPanel("");
    final ListPanel listPanel = new ListPanel();
    listPanel.setStyleName("selectedFilesList");

    row.setStyleName("formRow");
    TextBox keyBox = new TextBox();
    final HTML5FileUpload valueBox = new HTML5FileUpload();
    InlineLabel removeButton = new InlineLabel("x");

    fileInputs.add(valueBox);//from  ww w  . j  a v a 2s . co m
    keyBox.getElement().setAttribute("placeholder", "Field name");

    String value = null;
    if (key == null) {
        value = fileFieldName;
        if (fileFieldNumber > 0) {
            value += "" + fileFieldNumber;
        }
    } else {
        value = key;
    }
    keyBox.setValue(value);
    removeButton.addStyleName("removeButton");
    removeButton.setTitle("Remove");

    valueBox.setMultiple(true);
    valueBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            int prevCnt = listPanel.getWidgetCount();
            allFilesCount -= prevCnt;
            listPanel.clear();
            FileList files = valueBox.getFiles();
            int cnt = files.size();
            allFilesCount += cnt;
            filesTab.setText("Files (" + allFilesCount + ")");
            for (int i = 0; i < cnt; i++) {
                File file = files.get(i);
                double sizeLong = file.getSize();
                String fileSize = Units.swithFileSize(sizeLong);

                String html = file.getName() + " ";
                html += "(" + fileSize + ")";
                ListItem li = new ListItem();
                li.setHTML(html);
                listPanel.add(li);
            }
        }
    });
    row.add(valueBox);
    row.add(keyBox);
    row.add(removeButton);
    row.add(listPanel);

    filesFormPanel.add(row);

    removeButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            int cnt = listPanel.getWidgetCount();
            allFilesCount -= cnt;
            filesTab.setText("Files (" + allFilesCount + ")");
            fileInputs.remove(valueBox);
            row.removeFromParent();
        }
    });
    fileFieldNumber++;
    keyBox.selectAll();
    keyBox.getElement().focus();
}

From source file:org.roda.wui.client.browse.BrowseRepresentation.java

public BrowseRepresentation(BrowseRepresentationBundle bundle) {
    this.representation = bundle.getRepresentation();

    this.aipId = representation.getAipId();
    this.repId = representation.getId();
    this.repUUID = representation.getUUID();

    handlers = new ArrayList<>();
    String summary = messages.representationListOfFiles();

    AIPState state = bundle.getAip().getState();
    boolean justActive = AIPState.ACTIVE.equals(state);
    boolean selectable = true;
    boolean showFilesPath = false;

    // FILES//from  w  ww . java  2  s.  c o m

    Filter filter = new Filter(new SimpleFilterParameter(RodaConstants.FILE_REPRESENTATION_UUID, repUUID),
            new EmptyKeyFilterParameter(RodaConstants.FILE_PARENT_UUID));

    filesList = new SearchFileList(filter, justActive, Facets.NONE, summary, selectable, showFilesPath);
    LastSelectedItemsSingleton.getInstance().setSelectedJustActive(justActive);
    filesList.setActionable(FileActions.get(aipId, repId));

    ListSelectionUtils.bindBrowseOpener(filesList);

    filesSearch = new SearchPanel(filter, ALL_FILTER, true, messages.searchPlaceHolder(), false, false, true);
    filesSearch.setList(filesList);

    // DISSEMINATIONS
    disseminationsList = new DIPList(Filter.NULL, Facets.NONE, messages.listOfDisseminations(), true);
    disseminationsList.setActionable(DisseminationActions.get());
    ListSelectionUtils.bindBrowseOpener(disseminationsList);

    disseminationsSearch = new SearchPanel(Filter.NULL, RodaConstants.DIP_SEARCH, true,
            messages.searchPlaceHolder(), false, false, true);
    disseminationsSearch.setList(disseminationsList);

    // INIT
    initWidget(uiBinder.createAndBindUi(this));

    // STATUS
    aipState.setHTML(HtmlSnippetUtils.getAIPStateHTML(state));
    aipState.setVisible(!justActive);

    // IDENTIFICATION

    HTMLPanel representationIconHtmlPanel = new HTMLPanel(
            DescriptionLevelUtils.getRepresentationTypeIcon(representation.getType(), false));
    representationIconHtmlPanel.addStyleName("browseItemIcon-other");
    representationIcon.setWidget(representationIconHtmlPanel);

    String type = representation.getType() != null ? representation.getType() : representation.getId();
    representationType.setHTML(HtmlSnippetUtils.getRepresentationTypeHTML(type, representation.isOriginal()));
    representationId.setText(representation.getId());

    breadcrumb.updatePath(BreadcrumbUtils.getRepresentationBreadcrumbs(bundle));
    breadcrumb.setVisible(true);

    // DESCRIPTIVE METADATA

    final List<Pair<String, HTML>> descriptiveMetadataContainers = new ArrayList<>();
    final Map<String, DescriptiveMetadataViewBundle> bundles = new HashMap<>();
    for (DescriptiveMetadataViewBundle descMetadataBundle : bundle.getRepresentationDescriptiveMetadata()) {
        String title = descMetadataBundle.getLabel() != null ? descMetadataBundle.getLabel()
                : descMetadataBundle.getId();
        HTML container = new HTML();
        container.addStyleName("metadataContent");
        itemMetadata.add(container, title);
        descriptiveMetadataContainers.add(Pair.of(descMetadataBundle.getId(), container));
        bundles.put(descMetadataBundle.getId(), descMetadataBundle);
    }

    HandlerRegistration tabHandler = itemMetadata.addSelectionHandler(new SelectionHandler<Integer>() {

        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() < descriptiveMetadataContainers.size()) {
                Pair<String, HTML> pair = descriptiveMetadataContainers.get(event.getSelectedItem());
                String descId = pair.getFirst();
                final HTML html = pair.getSecond();
                final DescriptiveMetadataViewBundle bundle = bundles.get(descId);
                if (html.getText().length() == 0) {
                    getDescriptiveMetadataHTML(descId, bundle, new AsyncCallback<SafeHtml>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            if (!AsyncCallbackUtils.treatCommonFailures(caught)) {
                                Toast.showError(messages.errorLoadingDescriptiveMetadata(caught.getMessage()));
                            }
                        }

                        @Override
                        public void onSuccess(SafeHtml result) {
                            html.setHTML(result);
                        }
                    });
                }
            }
        }
    });

    final int addTabIndex = itemMetadata.getWidgetCount();
    FlowPanel addTab = new FlowPanel();
    addTab.add(new HTML(SafeHtmlUtils.fromSafeConstant("<i class=\"fa fa-plus-circle\"></i>")));
    itemMetadata.add(new Label(), addTab);
    HandlerRegistration addTabHandler = itemMetadata.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() == addTabIndex) {
                newRepresentationDescriptiveMetadata();
            }
        }
    });
    addTab.addStyleName("addTab");
    addTab.getParent().addStyleName("addTabWrapper");

    handlers.add(tabHandler);
    handlers.add(addTabHandler);

    if (!bundle.getRepresentationDescriptiveMetadata().isEmpty()) {
        newDescriptiveMetadata.setVisible(false);
        itemMetadata.setVisible(true);
        itemMetadata.selectTab(0);
    } else {
        newDescriptiveMetadata.setVisible(true);
        itemMetadata.setVisible(false);
    }

    // DISSEMINATIONS (POST-INIT)
    if (bundle.getDipCount() > 0) {
        Filter disseminationsFilter = new Filter(
                new SimpleFilterParameter(RodaConstants.DIP_REPRESENTATION_UUIDS, repUUID));
        disseminationsList.set(disseminationsFilter, state.equals(AIPState.ACTIVE), Facets.NONE);
        disseminationsSearch.setDefaultFilter(disseminationsFilter, true);
        disseminationsSearch.clearSearchInputBox();
    }
    disseminationsList.getParent().setVisible(bundle.getDipCount() > 0);

    // SIDEBAR
    actionsSidebar.setWidget(RepresentationActions.get(aipId).createActionsLayout(representation,
            new AsyncCallback<Actionable.ActionImpact>() {

                @Override
                public void onFailure(Throwable caught) {
                    AsyncCallbackUtils.defaultFailureTreatment(caught);
                }

                @Override
                public void onSuccess(Actionable.ActionImpact impact) {
                    if (Actionable.ActionImpact.UPDATED.equals(impact)) {
                        BrowserService.Util.getInstance().retrieve(IndexedRepresentation.class.getName(),
                                representation.getUUID(), representationFields,
                                new AsyncCallback<IndexedRepresentation>() {

                                    @Override
                                    public void onFailure(Throwable caught) {
                                        AsyncCallbackUtils.defaultFailureTreatment(caught);
                                    }

                                    @Override
                                    public void onSuccess(IndexedRepresentation rep) {
                                        representation = rep;
                                        representationType.setText(rep.getType());
                                    }
                                });
                    }
                }
            }));

    ListSelectionUtils.bindLayout(representation, searchPrevious, searchNext, keyboardFocus, true, false, false,
            searchSection);

    // CSS
    this.addStyleName("browse");
    this.addStyleName("browse-representation");
    this.addStyleName(state.toString().toLowerCase());

    Element firstElement = this.getElement().getFirstChildElement();
    if ("input".equalsIgnoreCase(firstElement.getTagName())) {
        firstElement.setAttribute("title", "browse input");
    }

    WCAGUtilities.getInstance().makeAccessible(itemMetadata.getElement());
}

From source file:org.roda.wui.common.client.tools.DescriptionLevelUtils.java

public static HTMLPanel getTopIconHTMLPanel() {
    return new HTMLPanel(SafeHtmlUtils.fromSafeConstant(TOP_ICON));
}

From source file:org.roda.wui.common.client.tools.DescriptionLevelUtils.java

public static HTMLPanel getElementLevelIconHTMLPanel(String level) {
    return new HTMLPanel(getElementLevelIconSafeHtml(level, false));
}

From source file:org.rstudio.core.client.widget.FixedRatioWidget.java

License:Open Source License

public FixedRatioWidget(Widget widget, double aspect, int maxWidth) {
    widget_ = widget;/*from   w w w. ja va 2s .  c  o  m*/

    HTMLPanel outer = new HTMLPanel("");
    Style outerStyle = outer.getElement().getStyle();
    outerStyle.setWidth(100, Unit.PCT);
    outerStyle.setProperty("maxWidth", maxWidth + "px");

    HTMLPanel panel = new HTMLPanel("");
    Style panelStyle = panel.getElement().getStyle();
    panelStyle.setPosition(Position.RELATIVE);
    panelStyle.setWidth(100, Unit.PCT);
    panelStyle.setHeight(0, Unit.PX);
    panelStyle.setPaddingBottom((double) 100 * ((double) 1 / aspect), Unit.PCT);
    outer.add(panel);

    Style widgetStyle = widget.getElement().getStyle();
    widgetStyle.setPosition(Position.ABSOLUTE);
    widgetStyle.setWidth(100, Unit.PCT);
    widgetStyle.setHeight(100, Unit.PCT);
    widgetStyle.setLeft(0, Unit.PX);
    widgetStyle.setTop(0, Unit.PX);

    panel.add(widget_);
    initWidget(outer);
}

From source file:org.rstudio.core.client.widget.ProgressSpinner.java

License:Open Source License

public ProgressSpinner(int color) {
    // compute sizes
    outerRadius_ = (COORD_SIZE / 2) - 10;
    innerRadius_ = (outerRadius_ / 2) + 5;
    color_ = color == COLOR_WHITE ? "255, 255, 255" : "0, 0, 0";

    // create canvas host
    canvas_ = Canvas.createIfSupported();
    if (canvas_ == null) {
        Debug.log("Can't create progress spinner (no HTML5 canvas support)");
        initWidget(new HTMLPanel(""));
        return;//from w w w .j  a v  a  2s.c om
    }

    initWidget(canvas_);

    // initialize canvas
    canvas_.setCoordinateSpaceWidth(COORD_SIZE);
    canvas_.setCoordinateSpaceHeight(COORD_SIZE);

    // perform initial draw and start animation
    redraw();
    Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() {
        @Override
        public boolean execute() {
            frame_++;
            redraw();
            return !complete_;
        }
    }, FRAME_RATE_MS);
}