Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant.

Prototype

public SafeHtmlBuilder appendHtmlConstant(String html) 

Source Link

Document

Appends a compile-time-constant string, which will not be escaped.

Usage

From source file:com.radoslavhusar.tapas.war.client.ui.DynamicSelectionCell.java

License:Apache License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    String viewData = getViewData(key);
    if (viewData != null && viewData.equals(value)) {
        clearViewData(key);/* w w w  .j  av a 2s.  c  o  m*/
        viewData = null;
    }

    int selectedIndex = getSelectedIndex(viewData == null ? value : viewData);
    sb.appendHtmlConstant("<select tabindex=\"-1\">");
    int index = 0;
    for (String option : options) {
        if (index++ == selectedIndex) {
            sb.append(template.selected(option));
        } else {
            sb.append(template.deselected(option));
        }
    }
    sb.appendHtmlConstant("</select>");
}

From source file:com.ritchey.attendance.client.view.SelectionCell.java

License:Apache License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    String viewData = getViewData(key);
    if (viewData != null && viewData.equals(value)) {
        clearViewData(key);/* w w  w.  j av  a  2  s. c o m*/
        viewData = null;
    }

    int selectedIndex = getSelectedIndex(viewData == null ? value : viewData);
    sb.appendHtmlConstant("<select>");
    int index = 0;
    for (String option : options) {
        if (index++ == selectedIndex) {
            sb.append(template.selected(option));
        } else {
            sb.append(template.deselected(option));
        }
    }
    sb.appendHtmlConstant("</select>");
}

From source file:com.ritchey.attendance.client.view.TextInputCell.java

License:Apache License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    ViewData viewData = getViewData(key);
    if (viewData != null && viewData.getCurrentValue().equals(value)) {
        clearViewData(key);/*ww  w.ja v a 2s .c om*/
        viewData = null;
    }

    String s = (viewData != null) ? viewData.getCurrentValue() : value;
    if (s != null) {
        sb.append(template.input(s));
    } else {
        sb.appendHtmlConstant("<input type=\"text\"></input>");
    }
}

From source file:com.roughindustries.commonwealthcocktails.client.application.ApplicationPresenter.java

License:Apache License

@Override
protected void onBind() {

    step.setValue(25);//from  w w w  .j av  a 2 s.  c o m
    current.setValue(25);
    next.setValue(current.intValue() + step.intValue());
    prev.setValue(0);

    lastScrollPos.setValue(0);
    lastMaxScrollTop.setValue(0);

    list.addAll(Collections.nCopies(current.intValue(), new ccCocktail()));

    final HTML f = new HTML("");
    Column<ccCocktail, SafeHtml> text = new Column<ccCocktail, SafeHtml>(new SafeHtmlCell()) {

        public SafeHtml getValue(ccCocktail cocktail) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            if (cocktail == null || cocktail.getCocktailName() == null) {
                sb.appendHtmlConstant("Loading ...");
                return sb.toSafeHtml();
            } else {
                sb.appendHtmlConstant(
                        "<table border='0' cellpadding='1' cellspacing='1' style='width: 100%;'>");
                sb.appendHtmlConstant("<tbody>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant(
                        "<td><img alt='Cocktail' src='https://s3.amazonaws.com/commonwealthcocktailbucket/noun_320760_cc.png' style='border-width: 0px; border-style: solid; margin: 0px; width: 100px; height: 100px;' /></td>");
                sb.appendHtmlConstant(
                        "<td border='0' cellpadding='1' cellspacing='1' style='width: 100%;' table=''>");
                sb.appendHtmlConstant(
                        "<table border='0' cellpadding='1' cellspacing='1' style='width: 100%;'>");
                sb.appendHtmlConstant("<tbody>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant("<td><b>" + cocktail.getCocktailName() + "</b></td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant(
                        "<td><b>Origin: </b>"
                                + ((cocktail.getCocktailOrigin() == null)
                                        || (cocktail.getCocktailOrigin().length() == 0) ? ""
                                                : (cocktail.getCocktailOrigin().substring(0, 150) + "..."))
                                + "</td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("<tr>");
                sb.appendHtmlConstant("<td><b>Method: </b>"
                        + ((cocktail.getCocktailMethod() == null) || (cocktail.getCocktailMethod() == null) ? ""
                                : (cocktail.getCocktailMethod().substring(0, 150) + "..."))
                        + "</td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("</tbody>");
                sb.appendHtmlConstant("</table>");
                sb.appendHtmlConstant("</td>");
                sb.appendHtmlConstant("</tr>");
                sb.appendHtmlConstant("</tbody>");
                sb.appendHtmlConstant("</table>");
                return sb.toSafeHtml();
            }
        }

    };
    getView().getCocktailGrid().addColumn(text);
    data.addAll(list);
    getView().getCocktailGrid().setRowData(0, data);
    getView().getCocktailGrid().setVisibleRange(new Range(0, current.intValue()));
    getView().getCocktailGrid().setHeight(Integer.toString(Window.getClientHeight()) + "px");
    getView().getScroll().setHeight(Integer.toString(Window.getClientHeight()) + "px");
    getView().getScroll().setWidth(Integer.toString(Window.getClientWidth()) + "px");
    if (Window.getClientWidth() <= 768) {
        getView().getBrand().setMarginLeft((Window.getClientWidth() / 2) - 125);
    } else {
        getView().getBrand().setMarginLeft(0);
    }
    if (Window.getClientWidth() > (800)
            && (Window.getClientWidth() <= (800 + NativeVerticalScrollbar.getNativeScrollbarWidth()))) {
        getView().getHeaderContainer()
                .setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
        getView().getCocktailGrid().setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
        if (getView().getLeftBuffer().isVisible()) {
            getView().getLeftBuffer().setVisible(false);
            getView().getRightBuffer().setVisible(false);
        }
    } else if (Window.getClientWidth() <= (800 - NativeVerticalScrollbar.getNativeScrollbarWidth())) {
        getView().getHeaderContainer().setWidth(
                Integer.toString(Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                        + "px");
        getView().getCocktailGrid().setWidth(
                Integer.toString(Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                        + "px");

        if (getView().getLeftBuffer().isVisible()) {
            getView().getLeftBuffer().setVisible(false);
            getView().getRightBuffer().setVisible(false);
        }
    } else {
        getView().getHeaderContainer().setWidth("800px");
        getView().getCocktailGrid().setWidth("800px");
        if (!getView().getLeftBuffer().isVisible()) {
            getView().getLeftBuffer().setVisible(true);
            getView().getRightBuffer().setVisible(true);
        }
        getView().getLeftBuffer()
                .setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
        getView().getRightBuffer()
                .setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
    }
    getView().getScroll().addScrollHandler(new ScrollHandler() {

        @Override
        public void onScroll(ScrollEvent ev) {
            int oldScrollPos = lastScrollPos.intValue();
            lastScrollPos.setValue(getView().getScroll().getVerticalScrollPosition());

            // If scrolling up, ignore the event.
            if (oldScrollPos >= lastScrollPos.intValue()) {
                return;
            }

            // Height of grid contents (including outside the viewable area)
            // - height of the scroll panel
            int maxScrollTop = getView().getScroll().getWidget().getOffsetHeight()
                    - getView().getScroll().getOffsetHeight();
            if (lastScrollPos.intValue() == maxScrollTop) {
                if ((data.size() + step.intValue()) <= queryResultsCount.intValue()) {
                    prev.setValue(current);
                    current.setValue(next);
                    next.setValue(next.intValue() + step.intValue());
                    data.addAll(
                            new ArrayList<ccCocktail>(Collections.nCopies(step.intValue(), new ccCocktail())));
                } else {
                    int diff = queryResultsCount.intValue() - data.size();
                    if (diff > 0) {
                        step.setValue(diff);
                        prev.setValue(current);
                        current.setValue(next);
                        next.setValue(next.intValue() + step.intValue());
                        data.addAll(new ArrayList<ccCocktail>(Collections.nCopies(diff, new ccCocktail())));
                    } else {
                        step.setValue(0);
                    }
                }
                getView().getCocktailGrid().setRowData(0, data);
                getView().getCocktailGrid().setVisibleRange(new Range(0, current.intValue()));
                getView().getCocktailGrid().redraw();
                if (step.intValue() != 0) {
                    cocktailService.cocktailServer("", prev.intValue(), step.intValue(),
                            new AsyncCallback<ccCocktail[]>() {
                                public void onFailure(Throwable caught) {

                                }

                                public void onSuccess(ccCocktail[] result) {
                                    if (result != null) {
                                        for (ccCocktail item : result) {
                                            data.set(item.getPageRefID(), item);
                                        }
                                        getView().getCocktailGrid().setRowData(0, data);
                                        getView().getCocktailGrid()
                                                .setVisibleRange(new Range(0, current.intValue()));
                                        getView().getCocktailGrid().redraw();

                                    }
                                }
                            });
                }
            }
        }
    });
    Window.addWindowScrollHandler(new Window.ScrollHandler() {
        @Override
        public void onWindowScroll(com.google.gwt.user.client.Window.ScrollEvent event) {
            // Window.alert("Scrolling Window");
        }
    });
    cocktailService.getCount("", new AsyncCallback<Integer>() {
        public void onFailure(Throwable caught) {

        }

        public void onSuccess(Integer result) {
            queryResultsCount.setValue(result.intValue());
            cocktailService.cocktailServer("", prev.intValue(), current.intValue(),
                    new AsyncCallback<ccCocktail[]>() {
                        public void onFailure(Throwable caught) {

                        }

                        public void onSuccess(ccCocktail[] result) {
                            ArrayList<ccCocktail> removed = new ArrayList<ccCocktail>();
                            for (ccCocktail item : result) {
                                if (item != null) {
                                    removed.add(item);
                                }
                            }
                            result = removed.toArray(new ccCocktail[0]);
                            if (result != null) {
                                for (ccCocktail item : result) {
                                    data.set(item.getPageRefID(), item);
                                }
                                getView().getCocktailGrid().setRowData(0, data);
                                getView().getCocktailGrid().setVisibleRange(new Range(0, current.intValue()));
                                getView().getCocktailGrid().redraw();
                            }
                        }
                    });
        }
    });
    Window.addResizeHandler(new ResizeHandler() {

        @Override
        public void onResize(ResizeEvent event) {
            getView().getCocktailGrid().setHeight(Integer.toString(Window.getClientHeight()) + "px");
            getView().getScroll().setHeight(Integer.toString(Window.getClientHeight()) + "px");
            getView().getScroll().setWidth(Integer.toString(Window.getClientWidth()) + "px");

            if (Window.getClientWidth() <= 768) {
                getView().getBrand().setMarginLeft((Window.getClientWidth() / 2) - 125);
            } else {
                getView().getBrand().setMarginLeft(0);
            }

            if (Window.getClientWidth() > (800)
                    && (Window.getClientWidth() <= (800 + NativeVerticalScrollbar.getNativeScrollbarWidth()))) {
                getView().getHeaderContainer()
                        .setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
                getView().getCocktailGrid()
                        .setWidth((800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) + "px");
                if (getView().getLeftBuffer().isVisible()) {
                    getView().getLeftBuffer().setVisible(false);
                    getView().getRightBuffer().setVisible(false);
                }
            } else if (Window.getClientWidth() <= (800 + NativeVerticalScrollbar.getNativeScrollbarWidth())) {
                getView().getHeaderContainer()
                        .setWidth(Integer.toString(
                                Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                                + "px");
                getView().getCocktailGrid()
                        .setWidth(Integer.toString(
                                Window.getClientWidth() - NativeVerticalScrollbar.getNativeScrollbarWidth())
                                + "px");
                if (getView().getLeftBuffer().isVisible()) {
                    getView().getLeftBuffer().setVisible(false);
                    getView().getRightBuffer().setVisible(false);
                }
            } else {
                getView().getHeaderContainer().setWidth("800px");
                getView().getCocktailGrid().setWidth("800px");
                if (!getView().getLeftBuffer().isVisible()) {
                    getView().getLeftBuffer().setVisible(true);
                    getView().getRightBuffer().setVisible(true);
                }
                getView().getLeftBuffer().setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
                getView().getRightBuffer().setWidth(Integer.toString(
                        (Window.getClientWidth() - 800 - NativeVerticalScrollbar.getNativeScrollbarWidth()) / 2)
                        + "px");
            }
        }

    });
}

From source file:com.seanchenxi.gwt.serenity.client.view.impl.DiscussionViewImpl.java

License:Apache License

public void setMessage(boolean isPending, String message) {
    SafeHtml shtml;//w  ww.j  a  v  a  2 s . c o  m
    if (isPending) {
        SafeHtmlBuilder shb = new SafeHtmlBuilder();
        shb.appendHtmlConstant("<p class=\"").appendHtmlConstant(getStyle().pendingDiscussion())
                .appendHtmlConstant("\">")
                .appendHtmlConstant(SerenityResources.MSG.msg_yourCommentIsAwaitingMod())
                .appendHtmlConstant("</p>").appendHtmlConstant(message);
        shtml = shb.toSafeHtml();
    } else {
        shtml = SafeHtmlUtils.fromTrustedString(message);
    }
    content.setHTML(shtml);
}

From source file:com.sencha.gxt.explorer.client.grid.WordWrapGridExample.java

License:sencha.com license

@Override
public Widget asWidget() {

    if (fp == null) {
        fp = new FramedPanel();
        fp.setHeadingText("Word Wrap Grid");
        fp.getHeader().setIcon(ExampleImages.INSTANCE.table());
        fp.setPosition(10, 10);//ww w.jav  a  2 s .  co m
        fp.setPixelSize(600, 400);
        new Resizable(fp, Dir.E, Dir.SE, Dir.S);

        ToolButton tb = new ToolButton(ToolButton.QUESTION);
        ToolTipConfig ttc = new ToolTipConfig("Example Info",
                "This example illustrates word wrap in grid headings and rows.");
        ttc.setMaxWidth(225);
        tb.setToolTipConfig(ttc);
        fp.addTool(tb);

        List<ColumnConfig<Row, ?>> ccs = new LinkedList<ColumnConfig<Row, ?>>();

        for (int i = 0; i < COLUMN_COUNT; i++) {
            ValueProvider<Row, String> cvp = rvp.getColumnValueProvider(i);
            SafeHtml sh = wrapString(createDummyText());
            ColumnConfig<Row, String> cc = new ColumnConfig<Row, String>(cvp, 200, sh);
            // Use a custom cell renderer to support word wrap in the grid's cells
            cc.setCell(new AbstractCell<String>() {
                @Override
                public void render(Context context, String value, SafeHtmlBuilder sb) {
                    if (value == null || value.isEmpty()) {
                        sb.appendHtmlConstant("&nbsp;");
                    } else {
                        sb.append(wrapString(value));
                    }
                }
            });
            ccs.add(cc);
        }

        final ColumnModel<Row> cm = new ColumnModel<Row>(ccs);

        final ListStore<Row> ls = new ListStore<Row>(new RowKeyProvider());
        ls.setAutoCommit(true);

        int columnCount = ccs.size();
        for (int i = 0; i < ROW_COUNT; i++) {
            Row row = new Row(columnCount);
            for (int j = 0; j < columnCount; j++) {
                row.setValue(j, createDummyText());
            }
            ls.add(row);
        }

        final Grid<Row> g = new Grid<Row>(ls, cm, new WordWrapGridView());
        g.getView().setColumnHeader(new WordWrapColumnHeader<Row>(g, cm));
        g.getView().setColumnLines(true);

        final GridInlineEditing<Row> gie = new GridInlineEditing<Row>(g) {
            protected void onScroll(ScrollEvent event) {
                // Suppress default action, which may result in canceling edit
            }
        };
        gie.setClicksToEdit(ClicksToEdit.TWO);
        gie.addStartEditHandler(new StartEditHandler<Row>() {
            @Override
            public void onStartEdit(StartEditEvent<Row> event) {
                GridCell cell = event.getEditCell();
                ColumnConfig<Row, ?> cc = cm.getColumn(cell.getCol());
                Field<Object> editor = (Field<Object>) gie.getEditor(cc);
                Element rowElement = g.getView().getRow(cell.getRow());
                // Resize the inline editor to the height of the row and style it to match the text
                int height = rowElement.getOffsetHeight() - 1;
                editor.setHeight(height);
                XElement cellElement = g.getView().getCell(cell.getRow(), cell.getCol()).cast();
                Style style = ((TextAreaAppearance) editor.getCell().getAppearance())
                        .getInputElement(editor.getElement()).getStyle();
                String fontSize = cellElement.getComputedStyle("fontSize");
                if (fontSize != null) {
                    style.setProperty("fontSize", fontSize);
                }
                String fontFamily = cellElement.getComputedStyle("fontFamily");
                if (fontFamily != null) {
                    style.setProperty("fontFamily", fontFamily);
                }
                style.setOverflow(Overflow.HIDDEN);
            }
        });

        for (ColumnConfig<Row, ?> cc : ccs) {
            @SuppressWarnings("unchecked")
            ColumnConfig<Row, String> scc = (ColumnConfig<Row, String>) cc;
            final TextArea ta = new TextArea();
            ta.setPreventScrollbars(true);
            ta.addKeyDownHandler(new KeyDownHandler() {
                @Override
                public void onKeyDown(KeyDownEvent event) {
                    // Allow the enter key to end grid inline editing
                    if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                        Scheduler.get().scheduleFinally(new RepeatingCommand() {
                            @Override
                            public boolean execute() {
                                gie.completeEditing();
                                ta.clear();
                                return false;
                            }
                        });
                    }
                }
            });
            gie.addEditor(scc, ta);
        }

        g.addViewReadyHandler(new ViewReadyHandler() {
            @Override
            public void onViewReady(ViewReadyEvent event) {
                Info.display("onViewReady", "heading width=" + g.getView().getHeader().getOffsetWidth()
                        + ", height=" + g.getView().getHeader().getOffsetHeight());
                g.getView().getHeader().addResizeHandler(new ResizeHandler() {
                    @Override
                    public void onResize(ResizeEvent event) {
                        Info.display("onResize",
                                "heading width=" + event.getWidth() + ", height=" + event.getHeight());
                    }
                });
            }
        });

        fp.setWidget(g);

        fp.addButton(new TextButton("Set Heading Text", new SelectHandler() {
            @Override
            public void onSelect(SelectEvent event) {
                final Window w = new Window();
                w.setHeadingText("Set Heading Text");
                w.setPixelSize(300, 200);
                w.setResizable(false);
                w.setModal(true);
                VerticalLayoutContainer vlc = new VerticalLayoutContainer();
                w.setWidget(vlc);
                final IntegerSpinnerField index = new IntegerSpinnerField();
                index.setMinValue(0);
                index.setMaxValue(COLUMN_COUNT - 1);
                index.setValue(0);
                index.setAllowBlank(false);
                index.setSelectOnFocus(true);
                vlc.add(new FieldLabel(index, "Column Index"), new VerticalLayoutData(1, -1, M1));
                final TextArea text = new TextArea();
                vlc.add(new FieldLabel(text, "Heading Text"), new VerticalLayoutData(1, 1, M2));
                w.addButton(new TextButton("Cancel", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        w.hide();
                    }
                }));
                w.addButton(new TextButton("OK", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        if (index.validate()) {
                            w.hide();
                            SafeHtml newHeading;
                            String newText = text.getValue();
                            if (newText == null) {
                                newHeading = SafeHtmlUtils.fromSafeConstant("&nbsp;");
                            } else {
                                newHeading = wrapString(newText);
                            }
                            ColumnModel<Row> columnModel = g.getColumnModel();
                            columnModel.setColumnHeader(index.getValue(), newHeading);
                        }
                    }
                }));
                w.show();
                w.setFocusWidget(index);
            }
        }));

        fp.addButton(new TextButton("Set Cell Text", new SelectHandler() {
            @Override
            public void onSelect(SelectEvent event) {
                final Window w = new Window();
                w.setHeadingText("Set Cell Text");
                w.setPixelSize(300, 200);
                w.setResizable(false);
                w.setModal(true);
                VerticalLayoutContainer vlc = new VerticalLayoutContainer();
                w.setWidget(vlc);
                final IntegerSpinnerField rowIndex = new IntegerSpinnerField();
                rowIndex.setMinValue(0);
                rowIndex.setMaxValue(ROW_COUNT - 1);
                rowIndex.setValue(0);
                rowIndex.setAllowBlank(false);
                rowIndex.setSelectOnFocus(true);
                vlc.add(new FieldLabel(rowIndex, "Row Index"), new VerticalLayoutData(1, -1, M1));
                final IntegerSpinnerField columnIndex = new IntegerSpinnerField();
                columnIndex.setMinValue(0);
                columnIndex.setMaxValue(COLUMN_COUNT - 1);
                columnIndex.setValue(0);
                columnIndex.setAllowBlank(false);
                columnIndex.setSelectOnFocus(true);
                vlc.add(new FieldLabel(columnIndex, "Column Index"), new VerticalLayoutData(1, -1, M1));
                final TextArea text = new TextArea();
                vlc.add(new FieldLabel(text, "Cell Text"), new VerticalLayoutData(1, 1, M2));
                w.addButton(new TextButton("Cancel", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        w.hide();
                    }
                }));
                w.addButton(new TextButton("OK", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        if (rowIndex.validate() && columnIndex.validate()) {
                            w.hide();
                            String newText = text.getValue();
                            if (newText == null) {
                                newText = "";
                            }
                            Row row = ls.get(rowIndex.getValue());
                            row.setValue(columnIndex.getValue(), newText);
                            ls.update(row);
                        }
                    }
                }));
                w.show();
                w.setFocusWidget(rowIndex);
            }
        }));

        fp.addButton(new TextButton("Set Column Width", new SelectHandler() {
            @Override
            public void onSelect(SelectEvent event) {
                final Window w = new Window();
                w.setHeadingText("Set Column Width");
                w.setPixelSize(300, 150);
                w.setResizable(false);
                w.setModal(true);
                VerticalLayoutContainer vlc = new VerticalLayoutContainer();
                w.setWidget(vlc);
                final IntegerSpinnerField columnIndex = new IntegerSpinnerField();
                columnIndex.setMinValue(0);
                columnIndex.setMaxValue(COLUMN_COUNT - 1);
                columnIndex.setValue(0);
                columnIndex.setAllowBlank(false);
                columnIndex.setSelectOnFocus(true);
                vlc.add(new FieldLabel(columnIndex, "Column Index"), new VerticalLayoutData(1, -1, M1));
                final IntegerSpinnerField width = new IntegerSpinnerField();
                width.setMinValue(0);
                width.setValue(50);
                width.setAllowBlank(false);
                width.setSelectOnFocus(true);
                vlc.add(new FieldLabel(width, "Column Width"), new VerticalLayoutData(1, -1, M2));
                w.addButton(new TextButton("Cancel", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        w.hide();
                    }
                }));
                w.addButton(new TextButton("OK", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        if (columnIndex.validate() && width.validate()) {
                            w.hide();
                            g.getColumnModel().setColumnWidth(columnIndex.getValue(), width.getValue());
                        }
                    }
                }));
                w.show();
                w.setFocusWidget(columnIndex);
            }
        }));

        fp.addButton(new TextButton("Set Heading Height", new SelectHandler() {
            @Override
            public void onSelect(SelectEvent event) {
                final Window w = new Window();
                w.setHeadingText("Set Heading Height");
                w.setPixelSize(300, 250);
                w.setResizable(false);
                w.setModal(true);
                VerticalLayoutContainer vlc = new VerticalLayoutContainer();
                w.setWidget(vlc);
                vlc.add(new HTML(
                        "<span style='font: 12px tahoma,arial,verdana,sans-serif;'>Sets the size of the heading to a fixed height. If this height is less than the height of the heading text, the heading text will be truncated.<br><br>To restore automatic sizing, specify a value of -1.<br><br></span>"),
                        new VerticalLayoutData(1, -1, M1));
                final IntegerSpinnerField height = new IntegerSpinnerField();
                height.setMinValue(-1);
                height.setValue(50);
                height.setAllowBlank(false);
                height.setSelectOnFocus(true);
                vlc.add(new FieldLabel(height, "Heading Height"), new VerticalLayoutData(1, -1, M2));
                w.addButton(new TextButton("Cancel", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        w.hide();
                    }
                }));
                w.addButton(new TextButton("OK", new SelectHandler() {
                    @Override
                    public void onSelect(SelectEvent event) {
                        if (height.validate()) {
                            w.hide();
                            g.getView().getHeader().setHeight(height.getValue());
                        }
                    }
                }));
                w.show();
                w.setFocusWidget(height);
            }
        }));

        fp.addButton(new TextButton("Get Heading Height", new SelectHandler() {
            @Override
            public void onSelect(SelectEvent event) {
                int headerHeight = g.getView().getHeader().getOffsetHeight();
                Info.display("getHeight", "height=" + headerHeight);
            }
        }));

        final ToggleButton fftb = new ToggleButton("Force Fit");
        fftb.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                if (fftb.getValue()) {
                    columnWidths.save(g);
                    g.getView().setForceFit(true);
                } else {
                    g.getView().setForceFit(false);
                    columnWidths.restore(g);
                }
                g.getView().layout();
            }
        });
        fp.addButton(fftb);

        fp.show();
    }

    return fp;
}

From source file:com.sencha.gxt.theme.base.client.button.ButtonCellDefaultAppearance.java

License:sencha.com license

@Override
public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    SafeHtml valueHtml = SafeHtmlUtils.fromTrustedString(hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "");

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String cls = style.button();//w ww  . j ava 2 s. c  o m
    String arrowCls = "";
    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.split();
                break;
            case BOTTOM:
                arrowCls = style.splitBottom();
                break;
            default:
                // empty
            }

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.arrow();
                break;
            case BOTTOM:
                arrowCls = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        cls += " " + style.small();
        break;
    case MEDIUM:
        cls += " " + style.medium();
        break;
    case LARGE:
        cls += " " + style.large();
        break;
    default:
        // empty
    }

    SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();

    int width = -1;

    if (cell.getWidth() != -1) {
        int w = cell.getWidth();
        if (w < cell.getMinWidth()) {
            w = cell.getMinWidth();
        }
        stylesBuilder.appendTrustedString("width:" + w + "px;");
        cls += " " + style.hasWidth() + " x-has-width";
        width = w;
    } else {

        if (cell.getMinWidth() != -1) {
            TextMetrics.get().bind(style.text());
            int length = TextMetrics.get().getWidth(valueHtml);
            length += 6; // frames

            if (icon != null) {
                switch (iconAlign) {
                case LEFT:
                case RIGHT:
                    length += icon.getWidth();
                    break;
                default:
                    // empty
                }
            }

            if (cell.getMinWidth() > length) {
                stylesBuilder.appendTrustedString("width:" + cell.getMinWidth() + "px;");
                cls += " " + style.hasWidth() + " x-has-width";
                width = cell.getMinWidth();
            }
        }
    }

    final int height = cell.getHeight();
    if (height != -1) {
        stylesBuilder.appendTrustedString("height:" + height + "px;");
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            arrowCls += " " + style.iconTop();
            break;
        case BOTTOM:
            arrowCls += " " + style.iconBottom();
            break;
        case LEFT:
            arrowCls += " " + style.iconLeft();
            break;
        case RIGHT:
            arrowCls += " " + style.iconRight();
            break;
        }

    } else {
        arrowCls += " " + style.noIcon();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        cls += " " + frame.pressedClass();
    }

    sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles()));

    SafeHtmlBuilder inside = new SafeHtmlBuilder();

    String innerWrap = arrowCls;

    inside.appendHtmlConstant("<div class='" + innerWrap + "'>");
    inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>");

    boolean hasText = valueHtml != null && !valueHtml.equals("");

    if (icon != null) {
        switch (iconAlign) {
        case LEFT:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeValue(inside, valueHtml, w, height);
            }
            inside.appendHtmlConstant("</tr>");
            break;
        case RIGHT:
            inside.appendHtmlConstant("<tr>");
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeValue(inside, valueHtml, w, height);
            }
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        case TOP:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeValue(inside, valueHtml, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            break;
        case BOTTOM:
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeValue(inside, valueHtml, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        }

    } else {
        inside.appendHtmlConstant("<tr>");
        if (valueHtml != null) {
            writeValue(inside, valueHtml, width, height);
        }
        inside.appendHtmlConstant("</tr>");
    }
    inside.appendHtmlConstant("</table>");
    inside.appendHtmlConstant("</div>");

    frame.render(sb,
            new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()),
            inside.toSafeHtml());

    sb.appendHtmlConstant("</div>");

}

From source file:com.sencha.gxt.theme.base.client.colorpalette.ColorPaletteBaseAppearance.java

License:sencha.com license

@Override
public void render(Context context, String value, String[] colors, String[] labels, SafeHtmlBuilder result) {
    result.appendHtmlConstant("<table class=\"" + style.colorPalette() + "\">");
    int mark = 0;

    int rows = (colors.length + (columnCount - 1)) / columnCount;

    for (int i = 0; i < rows; i++) {
        result.appendHtmlConstant("<tr>");
        for (int j = 0; j < columnCount && mark < colors.length; j++) {
            String c = colors[mark];
            String label = labels[mark];
            SafeHtml cellTemplate = template.cellTemplate(style, label, XDOM.getUniqueId(), i, j, c,
                    SafeStylesUtils/*from  w w  w .  j  a va  2  s. com*/
                            .fromTrustedString("background-color: #" + SafeHtmlUtils.htmlEscape(c) + ";"),
                    c.equals(value) ? style.selected() : "");
            result.append(cellTemplate);
            mark++;
        }
        result.appendHtmlConstant("</tr>");

    }

    result.appendHtmlConstant("</table>");

}

From source file:com.sencha.gxt.theme.base.client.container.BorderLayoutBaseAppearance.java

License:sencha.com license

@Override
public void render(SafeHtmlBuilder sb) {
    sb.appendHtmlConstant("<div class='" + style.container() + "'></div>");
}

From source file:com.sencha.gxt.theme.base.client.field.CheckBoxDefaultAppearance.java

License:sencha.com license

@Override
public void render(SafeHtmlBuilder sb, Boolean value, CheckBoxCellOptions options) {
    String checkBoxId = XDOM.getUniqueId();

    String nameParam = options.getName() != null ? " name='" + options.getName() + "' " : "";
    String disabledParam = options.isDisabled() ? " disabled=true" : "";
    String readOnlyParam = options.isReadonly() ? " readonly" : "";
    String idParam = " id=" + checkBoxId;
    String typeParam = " type=" + type;
    String checkedParam = value ? " checked" : "";

    sb.appendHtmlConstant("<div class=" + style.wrap() + ">");
    sb.appendHtmlConstant(/*  w ww.  j  a  v  a2s.c  o  m*/
            "<input " + typeParam + nameParam + disabledParam + readOnlyParam + idParam + checkedParam + " />");
    sb.appendHtmlConstant("<label for=" + checkBoxId + " class=" + style.checkBoxLabel() + ">");
    sb.append(options.getBoxLabel());
    sb.appendHtmlConstant("</label></div>");

}