Example usage for com.google.gwt.safehtml.shared SafeHtmlUtils fromSafeConstant

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils fromSafeConstant

Introduction

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

Prototype

public static SafeHtml fromSafeConstant(String s) 

Source Link

Document

Returns a SafeHtml constructed from a safe string, i.e., without escaping the string.

Usage

From source file:org.dataconservancy.dcs.access.client.presenter.MediciIngestPresenter.java

License:Apache License

public Widget getFiles(Map<String, CollectionNode> dusMap, Map<String, FileNode> filesMap,
        final String selectedCollection, Boolean valForAll) {

    List<String> files = dusMap.get(selectedCollection).getSub().get(SubType.File);
    final FileTable fileTable = new FileTable();

    CellTable.Resources resource = GWT.create(TableResources.class);
    fileTable.cellTable = new CellTable<FileNode>(files.size(), resource);

    fileTable.cellTable.setWidth("100%", true);
    fileTable.selectionFileModel = new MultiSelectionModel<FileNode>();

    fileTable.cellTable.setSelectionModel(fileTable.selectionFileModel,
            DefaultSelectionEventManager.<FileNode>createCheckboxManager());
    fileTable.selectionFileModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override//  w  ww.jav a 2  s .co  m
        public void onSelectionChange(SelectionChangeEvent event) {
            // TODO Auto-generated method stub
            List<FileNode> nowSelected = new ArrayList<FileNode>(fileTable.selectionFileModel.getSelectedSet());
            List<FileNode> previousSelected;
            List<FileNode> tempSelected;

            if (previousSelectedFiles.containsKey(selectedCollection))
                previousSelected = previousSelectedFiles.get(selectedCollection);
            else
                previousSelected = new ArrayList<FileNode>();

            if (nowSelected.size() > previousSelected.size()) {
                tempSelected = new ArrayList<FileNode>(nowSelected);
                tempSelected.removeAll(previousSelected);
            } else {
                tempSelected = new ArrayList<FileNode>(previousSelected);
                tempSelected.removeAll(nowSelected);
            }

            previousSelectedFiles.put(selectedCollection, nowSelected); //update previous selected files
            //   if(tempSelected.size()==1)//uncomment these 2 statements later
            //   MediciIngestPresenter.EVENT_BUS.fireEvent(new FileSelectEvent(tempSelected.get(0),true));
            //(FileNode)selectionFileModel.getSelectedSet().toArray()[0],true));
        }
    });
    Column<FileNode, Boolean> checkColumn = new Column<FileNode, Boolean>(new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(FileNode object) {
            // Get the value from the selection model.
            return fileTable.selectionFileModel.isSelected(object);
        }

    };

    fileTable.cellTable.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    fileTable.cellTable.setColumnWidth(checkColumn, 40, Unit.PX);

    // First name.
    final Resources resources = GWT.create(Resources.class);

    Column<FileNode, ImageResource> imageColumn = new Column<FileNode, ImageResource>(new ImageResourceCell()) {
        @Override
        public ImageResource getValue(FileNode object) {
            return resources.file();
        }

    };

    fileTable.cellTable.addColumn(imageColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    fileTable.cellTable.setColumnWidth(imageColumn, 40, Unit.PX);

    Column<FileNode, String> firstNameColumn = new Column<FileNode, String>(new EditTextCell()) {
        @Override
        public String getValue(FileNode object) {
            return object.getTitle();
        }

    };

    fileTable.cellTable.addColumn(firstNameColumn);

    List<FileNode> fileNodes = new ArrayList<FileNode>();

    for (String file : files) {
        FileNode node = filesMap.get(file);
        fileNodes.add(node);
        fileTable.selectionFileModel.setSelected(node, valForAll);
    }
    ListDataProvider<FileNode> dataProvider = new ListDataProvider<FileNode>(fileNodes);

    dataProvider.addDataDisplay(fileTable.cellTable);

    existingFileSets.put(selectedCollection, fileTable);
    return fileTable.cellTable;
}

From source file:org.drools.guvnor.client.asseteditor.drools.serviceconfig.KBaseConfigPanel.java

License:Apache License

private void initTableColumns(final CellTable<ServiceKSessionConfig> cellTable) {

    // Add new row
    MyClickableImageCell addRowCell = new MyClickableImageCell(
            new MyClickableImageCell.ImageCellClickHandler() {
                public void onClick(final Cell.Context context) {
                    final ServiceKSessionConfig newKsession = new ServiceKSessionConfig(
                            kbase.getNextKSessionName());
                    kbase.addKsession(newKsession);

                    dataProvider.getList().add(newKsession);
                    dataProvider.refresh();
                    pager.lastPage();/*from   w w w.  ja  v a  2  s  .c  o  m*/
                }
            });

    final Column<ServiceKSessionConfig, ImageResource> imageColumn = new Column<ServiceKSessionConfig, ImageResource>(
            addRowCell) {
        @Override
        public ImageResource getValue(final ServiceKSessionConfig object) {
            return images.itemImages().newItem();
        }
    };
    cellTable.addColumn(imageColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    cellTable.setColumnWidth(imageColumn, "16px");

    // Remove active row
    MyClickableImageCell removeRowCell = new MyClickableImageCell(
            new MyClickableImageCell.ImageCellClickHandler() {
                public void onClick(final Cell.Context context) {
                    if (dataProvider.getList().size() == 1) {
                        Window.alert(Constants.INSTANCE.KBaseNeedsOneKsession());
                    } else {
                        dataProvider.getList().remove(context.getIndex());
                        kbase.removeKsession((String) context.getKey());
                        dataProvider.refresh();
                    }
                }
            });

    final Column<ServiceKSessionConfig, ImageResource> imageColumn2 = new Column<ServiceKSessionConfig, ImageResource>(
            removeRowCell) {
        @Override
        public ImageResource getValue(final ServiceKSessionConfig object) {
            return images.removeItem();
        }
    };
    cellTable.addColumn(imageColumn2, SafeHtmlUtils.fromSafeConstant("<br/>"));
    cellTable.setColumnWidth(imageColumn, "16px");

    // KSession Name
    final EditTextCell textCell = new EditTextCell();
    final Column<ServiceKSessionConfig, String> nameColumn = new Column<ServiceKSessionConfig, String>(
            textCell) {
        @Override
        public String getValue(final ServiceKSessionConfig object) {
            return object.getName();
        }
    };
    cellTable.addColumn(nameColumn, Constants.INSTANCE.Name());
    nameColumn.setFieldUpdater(new FieldUpdater<ServiceKSessionConfig, String>() {
        public void update(int index, ServiceKSessionConfig object, String value) {
            // Called when the user changes the value.
            if (object.getName().equals(value)) {
                return;
            }

            if (kbase.getKsession(value) != null) {
                Window.alert(Constants.INSTANCE.KSessionNameAlreadyExists());
                textCell.clearViewData(KEY_PROVIDER.getKey(object));
                dataProvider.flush();
                dataProvider.refresh();
                cellTable.redraw();
            } else {
                final ServiceKSessionConfig updatedKsession = new ServiceKSessionConfig(value, object);
                kbase.removeKsession(object.getName());
                kbase.addKsession(updatedKsession);
                dataProvider.getList().set(index, updatedKsession);
                dataProvider.refresh();
            }
        }
    });
    cellTable.setColumnWidth(nameColumn, "40%");

    // Type
    final List<String> sessionTypes = new ArrayList<String>(SessionType.values().length);
    for (final SessionType activeType : SessionType.values()) {
        sessionTypes.add(activeType.toString().toLowerCase());
    }

    final SelectionCell typeCell = new SelectionCell(sessionTypes);
    final Column<ServiceKSessionConfig, String> typeColumn = new Column<ServiceKSessionConfig, String>(
            typeCell) {
        @Override
        public String getValue(ServiceKSessionConfig object) {
            return object.getType().toString().toLowerCase();
        }
    };
    cellTable.addColumn(typeColumn, Constants.INSTANCE.Type());
    typeColumn.setFieldUpdater(new FieldUpdater<ServiceKSessionConfig, String>() {
        public void update(int index, ServiceKSessionConfig object, String value) {
            // Called when the user changes the value.
            object.setType(SessionType.valueOf(value.toUpperCase()));
            dataProvider.refresh();
        }
    });
    cellTable.setColumnWidth(typeColumn, "40%");

    //Advanced config
    final Column<ServiceKSessionConfig, String> configAdvanced = new Column<ServiceKSessionConfig, String>(
            new ButtonCell()) {
        @Override
        public String getValue(ServiceKSessionConfig object) {
            return "...";
        }
    };
    cellTable.addColumn(configAdvanced, Constants.INSTANCE.Config());
    configAdvanced.setFieldUpdater(new FieldUpdater<ServiceKSessionConfig, String>() {
        public void update(int index, ServiceKSessionConfig object, String value) {

            final AdvancedKSessionConfigWidget widget = new AdvancedKSessionConfigWidget(object);
            final InternalPopup popup = new InternalPopup(widget.asWidget(),
                    Constants.INSTANCE.KSessionConfiguration());
            popup.addOkButtonClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                    widget.updateKSession();
                    popup.hide();
                }
            });
            popup.show();
        }
    });
    cellTable.setColumnWidth(configAdvanced, "20%");
}

From source file:org.drools.guvnor.client.table.SelectionColumn.java

License:Apache License

public static <T> void createAndAddSelectionColumn(CellTable<T> cellTable) {
    SelectionColumn<T> selectionColumn = new SelectionColumn<T>(cellTable);
    cellTable.addColumn(selectionColumn, SafeHtmlUtils.fromSafeConstant("<br>"));
}

From source file:org.eclipse.che.ide.ext.github.client.importer.page.GithubImporterPageViewImpl.java

License:Open Source License

/**
 * Creates table what contains list of available repositories.
 *
 * @param resources/*  ww  w. j  a v a 2 s  .co m*/
 */
private void createRepositoriesTable(final Resources resources, GitHubLocalizationConstant locale) {
    repositories = new CellTable<>(15, resources);

    Column<ProjectData, ImageResource> iconColumn = new Column<ProjectData, ImageResource>(
            new ImageResourceCell()) {
        @Override
        public ImageResource getValue(ProjectData item) {
            return null;
        }
    };

    Column<ProjectData, SafeHtml> repositoryColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(final ProjectData item) {
            return SafeHtmlUtils.fromString(item.getName());
        }
    };

    Column<ProjectData, SafeHtml> descriptionColumn = new Column<ProjectData, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(final ProjectData item) {
            return new SafeHtmlBuilder().appendHtmlConstant("<span>").appendEscaped(item.getDescription())
                    .appendHtmlConstant("</span>").toSafeHtml();
        }
    };

    repositories.addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    repositories.setColumnWidth(iconColumn, 28, Style.Unit.PX);

    repositories.addColumn(repositoryColumn, locale.samplesListRepositoryColumn());
    repositories.addColumn(descriptionColumn, locale.samplesListDescriptionColumn());

    // don't show loading indicator
    repositories.setLoadingIndicator(null);

    final SingleSelectionModel<ProjectData> selectionModel = new SingleSelectionModel<>();
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            ProjectData selectedObject = selectionModel.getSelectedObject();
            delegate.onRepositorySelected(selectedObject);
        }
    });
    repositories.setSelectionModel(selectionModel);
}

From source file:org.geomajas.gwt2.plugin.editing.example.client.i18n.SafeHtmlMessages.java

License:Open Source License

public SafeHtml explanation() {
    return SafeHtmlUtils.fromSafeConstant(msg.generalExplanation());
}

From source file:org.geomajas.gwt2.plugin.editing.example.client.i18n.SafeHtmlMessages.java

License:Open Source License

public SafeHtml mergeExplanation() {
    return SafeHtmlUtils.fromSafeConstant(msg.mergeCountriesSelect());
}

From source file:org.glom.web.client.ui.cell.NumericCell.java

License:Open Source License

public NumericCell(final String foregroundColor, final String backgroundColor, final NumberFormat numberFormat,
        final boolean useAltColorForNegatives, final String currencyCode) {
    if (!StringUtils.isEmpty(foregroundColor)) {
        colorCSSProp = SafeHtmlUtils.fromString("color:" + foregroundColor + ";");
    } else {/*from  w  ww.jav  a 2 s. c  om*/
        colorCSSProp = SafeHtmlUtils.fromSafeConstant("");
    }
    if (!StringUtils.isEmpty(backgroundColor)) {
        backgroundColorCSSProp = SafeHtmlUtils.fromString("background-color:" + backgroundColor + ";");
    } else {
        backgroundColorCSSProp = SafeHtmlUtils.fromSafeConstant("");
    }
    this.numberFormat = numberFormat;
    this.useAltColorForNegatives = useAltColorForNegatives;
    this.currencyCode = StringUtils.isEmpty(currencyCode) ? "" : currencyCode + " ";
}

From source file:org.glom.web.client.ui.cell.TextCell.java

License:Open Source License

public TextCell(final String foregroundColor, final String backgroundColor) {
    if (!StringUtils.isEmpty(foregroundColor)) {
        colorCSSProp = SafeHtmlUtils.fromString("color:" + foregroundColor + ";");
    } else {//ww  w.  j  a  va2  s .c o m
        colorCSSProp = SafeHtmlUtils.fromSafeConstant("");
    }
    if (!StringUtils.isEmpty(backgroundColor)) {
        backgroundColorCSSProp = SafeHtmlUtils.fromString("background-color:" + backgroundColor + ";");
    } else {
        backgroundColorCSSProp = SafeHtmlUtils.fromSafeConstant("");
    }
}

From source file:org.glom.web.client.ui.details.DetailsCell.java

License:Open Source License

public void setData(final DataItem dataItem) {
    detailsData.clear();/*from  w ww  . j a  v a  2s .c  o  m*/

    if (dataItem == null) {
        return;
    }

    Formatting formatting = layoutItem.getFormatting();

    // FIXME use the cell renderers from the list view to render the information here
    switch (this.dataType) {
    case TYPE_BOOLEAN:
        final CheckBox checkBox = new CheckBox();
        checkBox.setValue(dataItem.getBoolean());
        checkBox.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(final ClickEvent event) {
                // don't let users change the checkbox
                checkBox.setValue(dataItem.getBoolean());
            }
        });
        detailsData.add(checkBox);
        break;
    case TYPE_NUMERIC:
        if (formatting == null) {
            GWT.log("setData(): formatting is null");
            formatting = new Formatting(); // To avoid checks later.
        }
        final NumericFormat numericFormat = formatting.getNumericFormat();
        final NumberFormat gwtNumberFormat = Utils.getNumberFormat(numericFormat);

        // set the foreground color to red if the number is negative and this is requested
        if (numericFormat.getUseAltForegroundColorForNegatives() && dataItem.getNumber() < 0) {
            // The default alternative color in libglom is red.
            detailsData.getElement().getStyle()
                    .setColor(NumericFormat.getAlternativeColorForNegativesAsHTMLColor());
        }

        final String currencyCode = StringUtils.isEmpty(numericFormat.getCurrencySymbol()) ? ""
                : numericFormat.getCurrencySymbol().trim() + " ";
        detailsLabel.setText(currencyCode + gwtNumberFormat.format(dataItem.getNumber()));
        detailsData.add(detailsLabel);
        break;
    case TYPE_DATE:
    case TYPE_TIME:
    case TYPE_TEXT:
        final String text = StringUtils.defaultString(dataItem.getText());

        // Deal with multiline text differently than single line text.
        if ((formatting != null) && (formatting.getTextFormatMultilineHeightLines() > 1)) {
            detailsData.getElement().getStyle().setOverflow(Overflow.AUTO);
            // Convert '\n' to <br/> escaping the data so that it won't be rendered as HTML.
            try {
                // JavaScript requires the charsetName to be "UTF-8". CharsetName values that work in Java (such as
                // "UTF8") will not work when compiled to JavaScript.
                final String utf8NewLine = new String(new byte[] { 0x0A }, "UTF-8");
                final String[] lines = text.split(utf8NewLine);
                final SafeHtmlBuilder sb = new SafeHtmlBuilder();
                for (final String line : lines) {
                    sb.append(SafeHtmlUtils.fromString(line));
                    sb.append(SafeHtmlUtils.fromSafeConstant("<br/>"));
                }

                // Manually add the HTML to the detailsData container.
                final DivElement div = Document.get().createDivElement();
                div.setInnerHTML(sb.toSafeHtml().asString());
                detailsData.getElement().appendChild(div);

                // Expand the width of detailsData if a vertical scrollbar has been placed on the inside of the
                // detailsData container.
                final int scrollBarWidth = detailsData.getOffsetWidth() - div.getOffsetWidth();
                if (scrollBarWidth > 0) {
                    // A vertical scrollbar is on the inside.
                    detailsData.setWidth((detailsData.getOffsetWidth() + scrollBarWidth + 4) + "px");
                }

                // TODO Add horizontal scroll bars when detailsData expands beyond its container.

            } catch (final UnsupportedEncodingException e) {
                // If the new String() line throws an exception, don't try to add the <br/> tags. This is unlikely
                // to happen but we should do something if it does.
                detailsLabel.setText(text);
                detailsData.add(detailsLabel);
            }

        } else {
            final SingleLineText textPanel = new SingleLineText(text);
            detailsData.add(textPanel);
        }
        break;
    case TYPE_IMAGE:
        final Image image = new Image();
        final String imageDataUrl = dataItem.getImageDataUrl();
        if (imageDataUrl != null) {
            image.setUrl(imageDataUrl);

            // Set an arbitrary default size:
            // image.setPixelSize(200, 200);
        }

        detailsData.add(image);
        break;
    default:
        break;
    }

    this.dataItem = dataItem;

    // enable the navigation button if it's safe
    if (openButton != null && openButtonHandlerReg != null && this.dataItem != null) {
        openButton.setEnabled(true);
    }

}

From source file:org.glom.web.client.ui.details.RelatedListTable.java

License:Open Source License

private static int initializeExepectedHeight() {
    // TODO Use a real RelatedListTable instead of building one manually. It's probably better to do this when
    // RelatedListTables are created in Portal instead of DetailsActivity.

    // This table simulates a related list with one row containing a Text cell and a Button cell.
    final SafeHtmlBuilder tableBuilder = new SafeHtmlBuilder();
    tableBuilder.append(SafeHtmlUtils.fromSafeConstant(
            "<table class=\"data-list\"><thead><tr><th>TH</th><th>BH</th></tr></thead><tbody>"));
    for (int i = 0; i < MAX_TABLE_ROWS; i++) {
        tableBuilder.append(SafeHtmlUtils
                .fromSafeConstant("<tr><td>T</td><td><button type=\"button\">B</button></td></tr>"));
    }/*w  w w .ja  v a  2  s.co  m*/
    tableBuilder.append(SafeHtmlUtils.fromSafeConstant("</tbody></head>"));
    final HTML table = new HTML(tableBuilder.toSafeHtml());

    // The pager
    final SimplePager pager = new SimplePager();
    pager.addStyleName("pager");

    // Pack the table and pager as they are found in the details view.
    final FlowPanel group = new FlowPanel();
    group.setStyleName("group");
    final FlowPanel subgroup = new FlowPanel();
    subgroup.setStyleName("portal");
    subgroup.add(table);
    subgroup.add(pager);
    group.add(subgroup);

    // Calculate the height similar to Utils.getWidgetHeight().
    final Document doc = Document.get();
    com.google.gwt.dom.client.Element div = doc.createDivElement();
    div.getStyle().setVisibility(Visibility.HIDDEN);
    div.appendChild(group.getElement().<com.google.gwt.dom.client.Element>cast());
    doc.getBody().appendChild(div);
    final int relatedListTableHeight = group.getElement().getFirstChildElement().getOffsetHeight();

    // remove the div from the from the document
    doc.getBody().removeChild(div);
    div = null;

    return relatedListTableHeight;
}