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

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

Introduction

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

Prototype

public void addAndReplaceElement(Widget widget, String id) 

Source Link

Document

Adds a child widget to the panel, replacing the HTML element specified by a given id.

Usage

From source file:com.arcbees.chosen.integrationtest.client.testcases.TabNavigation.java

License:Apache License

@Override
public void run() {
    ChosenValueListBox<CarBrand> chosenValueListBox = new ChosenValueListBox<CarBrand>(RENDERER);
    chosenValueListBox.setAcceptableValues(Lists.newArrayList(CarBrand.values()));

    Binder binder = GWT.create(Binder.class);
    HTMLPanel panel = binder.createAndBindUi(this);
    panel.addAndReplaceElement(chosenValueListBox, getPlaceHolderId());

    RootPanel.get().add(panel);//from www .j av  a2  s  .  co m
}

From source file:com.google.livingstories.client.lsp.ContentRenderer.java

License:Apache License

/**
 * Find the custom tags in the HTML and process them.
 *///from ww w .  jav a2s . c om
private HTMLPanel processTagsInChunk(String chunk) {
    HTMLPanel contentPanel = new HTMLPanel(chunk);

    try {
        // Process each type of tag
        for (ContentTag tag : contentTags) {
            NodeList<Element> tagNodeList = contentPanel.getElement().getElementsByTagName(tag.getTagName());
            List<Element> tagElements = new ArrayList<Element>();
            for (int i = 0; i < tagNodeList.getLength(); i++) {
                // First iterate over the node list and copy all the elements into a new list. Can't 
                // iterate and modify them at the same time because the list changes dynamically.
                tagElements.add(tagNodeList.getItem(i));
            }

            for (Element tagElement : tagElements) {
                Widget widget = tag.createWidgetToReplaceTag(tagElement);

                if (widget != null) {
                    // To replace the existing tag with the widget created above, the HTMLPanel needs
                    // to have the id of the element being replaced. Since we can't expect users to assign
                    // unique ids in every tag, we do this here automatically.
                    String uniqueId = HTMLPanel.createUniqueId();
                    tagElement.setId(uniqueId);
                    contentPanel.addAndReplaceElement(widget, uniqueId);
                }
            }
        }
    } catch (Exception e) {
        // Just return the panel with the original content
    }

    return contentPanel;
}

From source file:com.gwtmodel.table.view.binder.impl.CreateBinderWidget.java

License:Apache License

private void buildWidget(Widget w, BinderWidget bw) {
    setWAttribute(w, bw);//from w w w . ja va 2s . c om
    if (bw.getwList().isEmpty())
        return;
    if (!(w instanceof HasWidgets))
        Utils.errAlertB(LogT.getT().BinderCannotHaveWidgets(bw.getType().name()));
    HTMLPanel h;
    HasWidgets hw;
    if (w instanceof HTMLPanel) {
        h = (HTMLPanel) w;
        hw = null;
    } else {
        hw = (HasWidgets) w;
        h = null;
    }

    bw.getwList().forEach(c -> {
        Widget child = constructEmptyWidget(c);
        buildWidget(child, c);
        Element ee = h.getElementById(c.getId());
        if (ee == null)
            Utils.errAlert(LogT.getT().BinderCannotFindWidget(c.getId()));

        if (h != null) {
            // String html = h.toString();
            try {
                h.addAndReplaceElement(child, ee);
            } catch (NoSuchElementException e) {
                Utils.errAlert(c.getId(), bw.getContentHtml(), e);
            }
        } else
            hw.add(child);
    });

}

From source file:com.gwtmodel.table.view.util.CreateFormView.java

License:Apache License

private static void replaceId(HTMLPanel ha, String htmlId, Widget w, boolean addId) {
    try {//w w  w  .  j av a 2s  . co m
        if (addId)
            w.getElement().setId(htmlId);
        // ha.add(w, htmlId);
        ha.addAndReplaceElement(w, htmlId);
    } catch (NoSuchElementException e) {
        // expected
    }

}

From source file:com.jawspeak.gwt.verysimpletemplate.client.template.VerySimpleGwtTemplate.java

License:Apache License

public HTMLPanel toHTMLPanel() {
    Map<String, Widget> idToWidget = new HashMap<String, Widget>();
    for (Entry<String, Widget> entryByToken : widgets.entrySet()) {
        String id = DOM.createUniqueId();
        htmlTemplate = htmlTemplate.replace(entryByToken.getKey(), "<span id='" + id + "'></span>");
        idToWidget.put(id, entryByToken.getValue());
    }//  w w  w  .j a v a2s . co m
    widgets = null; // finally all done using it
    HTMLPanel panel = new HTMLPanel(htmlTemplate);
    for (Entry<String, Widget> entryById : idToWidget.entrySet()) {
        panel.addAndReplaceElement(entryById.getValue(), entryById.getKey());
    }
    verifyTemplateCompletelyFilledOut();
    return panel;
}

From source file:com.palantir.gerrit.gerritci.ui.client.JobPanels.java

License:Apache License

private static HTMLPanel getCronPanel() {
    HTMLPanel cronPanel = new HTMLPanel(GerritCiPlugin.cronPanel.toString());
    TextBox cronCommand = new TextBox();
    cronCommand.setName("cronCommand");
    cronCommand.setText("./scripts/cron.sh");
    TextBox cronSchedule = new TextBox();
    cronSchedule.setName("cronJob");
    TextBox jobType = new TextBox();
    jobType.setText("cron");
    jobType.setName("jobType");
    jobType.setVisible(false);/*from w w w. ja v a2 s  . c  o  m*/
    cronPanel.add(jobType);
    cronPanel.addAndReplaceElement(cronCommand, "cronCommand");
    cronPanel.addAndReplaceElement(cronSchedule, "cronJob");
    addCommonFields(cronPanel);
    return cronPanel;
}

From source file:com.palantir.gerrit.gerritci.ui.client.JobPanels.java

License:Apache License

private static HTMLPanel getPublishPanel() {
    HTMLPanel publishPanel = new HTMLPanel(GerritCiPlugin.publishJobPanel.toString());
    TextBox publishCommand = new TextBox();
    publishCommand.setName("publishCommand");
    publishCommand.setText("./scripts/publish.sh");
    TextBox publishBranchRegex = new TextBox();
    publishBranchRegex.setName("publishBranchRegex");
    publishBranchRegex.setText("refs/heads/(develop|master)");
    TextBox jobType = new TextBox();
    jobType.setText("publish");
    jobType.setName("jobType");
    jobType.setVisible(false);/*w  w w. j a  v  a  2 s  .  c  o m*/
    publishPanel.add(jobType);
    publishPanel.addAndReplaceElement(publishCommand, "publishCommand");
    publishPanel.addAndReplaceElement(publishBranchRegex, "publishBranchRegex");
    addCommonFields(publishPanel);
    return publishPanel;
}

From source file:com.palantir.gerrit.gerritci.ui.client.JobPanels.java

License:Apache License

private static HTMLPanel getVerifyPanel() {
    HTMLPanel verifyPanel = new HTMLPanel(GerritCiPlugin.verifyJobPanel.toString());
    TextBox verifyCommand = new TextBox();
    verifyCommand.setName("verifyCommand");
    verifyCommand.setText("./scripts/verify.sh");
    TextBox verifyBranchRegex = new TextBox();
    verifyBranchRegex.setName("verifyBranchRegex");
    verifyBranchRegex.setText(".*");
    TextBox jobType = new TextBox();
    jobType.setText("verify");
    jobType.setName("jobType");
    jobType.setVisible(false);/*from  w w w. j av  a  2  s. c  o  m*/
    verifyPanel.add(jobType);
    verifyPanel.addAndReplaceElement(verifyCommand, "verifyCommand");
    verifyPanel.addAndReplaceElement(verifyBranchRegex, "verifyBranchRegex");
    addCommonFields(verifyPanel);
    return verifyPanel;
}

From source file:com.palantir.gerrit.gerritci.ui.client.JobPanels.java

License:Apache License

public static void addCommonFields(HTMLPanel p) {
    CheckBox junitEnabled = new CheckBox();
    junitEnabled.setName("junitEnabled");
    junitEnabled.setValue(true);/*from  ww w. j a  v  a  2s  . com*/
    TextBox junitPath = new TextBox();
    junitPath.setText("build/test-results/*.xml");
    junitPath.setName("junitPath");
    TextBox timeoutMinutes = new TextBox();
    timeoutMinutes.setText("30");
    timeoutMinutes.setName("timeoutMinutes");
    p.addAndReplaceElement(junitEnabled, "junitEnabled");
    p.addAndReplaceElement(junitPath, "junitPath");
    p.addAndReplaceElement(timeoutMinutes, "timeoutMinutes");
}

From source file:com.palantir.gerrit.gerritci.ui.client.JobPanels.java

License:Apache License

public static HTMLPanel showJob(JenkinsJob j) {
    String name = j.getName();/*from w w w  .  j  a  va 2s. c  o  m*/
    HTMLPanel p = new HTMLPanel("");
    if (j.getType().equals("cron"))
        p = new HTMLPanel(GerritCiPlugin.cronPanel.toString());
    else if (j.getType().equals("publish"))
        p = new HTMLPanel(GerritCiPlugin.publishJobPanel.toString());
    else if (j.getType().equals("verify"))
        p = new HTMLPanel(GerritCiPlugin.verifyJobPanel.toString());
    else
        return null;
    TextBox jobName = new TextBox();
    jobName.setName("jobName");
    jobName.setText(name);
    jobName.setVisible(false);
    Label jobNameLabel = new Label("Job Id: " + name);
    p.addAndReplaceElement(jobNameLabel, "jobIdLabel");
    p.add(jobName);
    TextBox jobType = new TextBox();
    jobType.setName("jobType");
    jobType.setText(j.getType());
    jobType.setVisible(false);
    p.add(jobType);

    int numOfParams = j.getItems().length();

    for (int i = 0; i < numOfParams; i++) {
        JobParam jp = j.getItems().get(i);
        String field = jp.getField();
        String value = jp.getVal();
        if (field.endsWith("Enabled")) {
            CheckBox cb = new CheckBox();
            cb.setName(field);
            cb.setValue(Boolean.valueOf(value));
            if (p.getElementById(field) != null)
                p.addAndReplaceElement(cb, field);
            else {
                cb.setVisible(false);
                p.add(cb);
            }
        } else {
            TextBox tb = new TextBox();
            tb.setName(field);
            tb.setText(makeXMLReadeable(value));
            if (p.getElementById(field) != null)
                p.addAndReplaceElement(tb, field);
            else {
                tb.setVisible(false);
                p.add(tb);
            }
        }
    }
    p.setVisible(true);
    return p;
}