List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils fromString
public static SafeHtml fromString(String s)
From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.grid.AbstractGridEditingExample.java
License:sencha.com license
@Override public Widget asWidget() { ColumnConfig<Plant, String> cc1 = new ColumnConfig<Plant, String>(properties.name(), 220, "Name"); ColumnConfig<Plant, String> cc2 = new ColumnConfig<Plant, String>(properties.light(), 130, "Light"); DateCell dateCell = new DateCell(DateTimeFormat.getFormat("yyyy MMM dd")); ColumnConfig<Plant, Date> cc3 = new ColumnConfig<Plant, Date>(properties.available(), 95, "Date"); cc3.setCell(dateCell);/* w ww . j a v a2 s .co m*/ ColumnConfig<Plant, Boolean> cc4 = new ColumnConfig<Plant, Boolean>(properties.indoor(), 55, "Indoor"); cc4.setCell(new SimpleSafeHtmlCell<Boolean>(new AbstractSafeHtmlRenderer<Boolean>() { @Override public SafeHtml render(Boolean object) { return SafeHtmlUtils.fromString(object ? "True" : "False"); } })); ColumnConfig<Plant, Double> cc5 = new ColumnConfig<Plant, Double>(properties.price(), 100, "Price"); cc5.setAlignment(HasHorizontalAlignment.ALIGN_RIGHT); cc5.setCell(new SimpleSafeHtmlCell<Double>(new AbstractSafeHtmlRenderer<Double>() { @Override public SafeHtml render(Double object) { return SafeHtmlUtils.fromString(NumberFormat.getCurrencyFormat().format(object)); } })); List<ColumnConfig<Plant, ?>> l = new ArrayList<ColumnConfig<Plant, ?>>(); l.add(cc1); l.add(cc2); l.add(cc5); l.add(cc3); l.add(cc4); ColumnModel<Plant> cm = new ColumnModel<Plant>(l); final ListStore<Plant> store = new ListStore<Plant>(properties.key()); store.addAll(TestData.getPlants()); grid = new Grid<Plant>(store, cm); grid.getView().setAutoExpandColumn(cc1); // EDITING// final GridEditing<Plant> editing = createGridEditing(grid); editing.addEditor(cc1, new TextField()); SimpleComboBox<Light> combo = new SimpleComboBox<Light>(new StringLabelProvider<Light>()); combo.setPropertyEditor(new PropertyEditor<Light>() { @Override public Light parse(CharSequence text) throws ParseException { return Light.parseString(text.toString()); } @Override public String render(Light object) { return object == null ? Light.SUNNY.toString() : object.toString(); } }); combo.setTriggerAction(TriggerAction.ALL); combo.add(Light.SUNNY); combo.add(Light.MOSTLYSUNNY); combo.add(Light.SUNORSHADE); combo.add(Light.MOSTLYSHADY); combo.add(Light.SHADE); combo.setForceSelection(true); editing.addEditor(cc2, new Converter<String, Light>() { @Override public String convertFieldValue(Light object) { return object == null ? Light.SUNNY.toString() : object.toString(); } @Override public Light convertModelValue(String object) { return Light.parseString(object); } }, combo); DateField dateField = new DateField( new DateTimePropertyEditor(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT))); dateField.setClearValueOnParseError(false); editing.addEditor(cc3, dateField); CheckBox checkField = new CheckBox(); editing.addEditor(cc4, checkField); // column 5 is not editable // EDITING// FramedPanel cp = new FramedPanel(); cp.setHeadingText("Editable Grid Example"); cp.setPixelSize(600, 400); cp.addStyleName("margin-10"); ToolBar toolBar = new ToolBar(); TextButton add = new TextButton("Add Plant"); add.addSelectHandler(new SelectHandler() { @Override public void onSelect(SelectEvent event) { Plant plant = new Plant(); plant.setName("New Plant 1"); plant.setLight("Mostly Shady"); plant.setPrice(0); plant.setAvailable(new DateWrapper().clearTime().asDate()); plant.setIndoor(false); editing.cancelEditing(); store.add(0, plant); editing.startEditing(new GridCell(0, 0)); } }); toolBar.add(add); VerticalLayoutContainer con = new VerticalLayoutContainer(); con.setBorders(true); con.add(toolBar, new VerticalLayoutData(1, -1)); con.add(grid, new VerticalLayoutData(1, 1)); cp.setWidget(con); cp.setButtonAlign(BoxLayoutPack.CENTER); cp.addButton(new TextButton("Reset", new SelectHandler() { @Override public void onSelect(SelectEvent event) { store.rejectChanges(); } })); cp.addButton(new TextButton("Save", new SelectHandler() { @Override public void onSelect(SelectEvent event) { store.commitChanges(); } })); return cp; }
From source file:com.msco.mil.client.com.sencha.gxt.explorer.client.treegrid.EditableTreeGridExample.java
License:sencha.com license
@Override public Widget asWidget() { FramedPanel panel = new FramedPanel(); panel.setHeadingText("TreeGrid Editing"); panel.addStyleName("margin-10"); panel.setPixelSize(600, 300);//from ww w .j av a 2 s . c om VerticalLayoutContainer v = new VerticalLayoutContainer(); v.setBorders(true); panel.add(v); TreeStore<BaseDto> store = new TreeStore<BaseDto>(new KeyProvider()); FolderDto root = TestData.getMusicRootFolder(); for (BaseDto base : root.getChildren()) { store.add(base); if (base instanceof FolderDto) { processFolder(store, (FolderDto) base); } } ColumnConfig<BaseDto, String> cc1 = new ColumnConfig<BaseDto, String>(new ValueProvider<BaseDto, String>() { @Override public String getValue(BaseDto object) { return object.getName(); } @Override public void setValue(BaseDto object, String value) { object.setName(value); } @Override public String getPath() { return "name"; } }); cc1.setHeader(SafeHtmlUtils.fromString("Name")); ColumnConfig<BaseDto, String> cc2 = new ColumnConfig<BaseDto, String>(new ValueProvider<BaseDto, String>() { @Override public String getValue(BaseDto object) { return object instanceof MusicDto ? ((MusicDto) object).getAuthor() : ""; } @Override public void setValue(BaseDto object, String value) { if (object instanceof MusicDto) { ((MusicDto) object).setAuthor(value); } } @Override public String getPath() { return "author"; } }); cc2.setHeader(SafeHtmlUtils.fromString("Author")); ColumnConfig<BaseDto, String> cc3 = new ColumnConfig<BaseDto, String>(new ValueProvider<BaseDto, String>() { @Override public String getValue(BaseDto object) { return object instanceof MusicDto ? ((MusicDto) object).getGenre() : ""; } @Override public void setValue(BaseDto object, String value) { if (object instanceof MusicDto) { ((MusicDto) object).setGenre(value); } } @Override public String getPath() { return "genre"; } }); cc3.setHeader("Genre"); cc3.setCell(new TextCell()); List<ColumnConfig<BaseDto, ?>> l = new ArrayList<ColumnConfig<BaseDto, ?>>(); l.add(cc1); l.add(cc2); l.add(cc3); ColumnModel<BaseDto> cm = new ColumnModel<BaseDto>(l); final TreeGrid<BaseDto> tree = new TreeGrid<BaseDto>(store, cm, cc1); tree.getStyle().setLeafIcon(ExampleImages.INSTANCE.music()); tree.getView().setAutoExpandColumn(cc1); // EDITING// GridInlineEditing<BaseDto> editing = new GridInlineEditing<BaseDto>(tree); editing.addEditor(cc1, new TextField()); editing.addEditor(cc2, new TextField()); editing.addEditor(cc3, new TextField()); // EDITING// ToolBar buttonBar = new ToolBar(); buttonBar.add(new TextButton("Expand All", new SelectHandler() { @Override public void onSelect(SelectEvent event) { tree.expandAll(); } })); buttonBar.add(new TextButton("Collapse All", new SelectHandler() { @Override public void onSelect(SelectEvent event) { tree.collapseAll(); } })); v.add(buttonBar, new VerticalLayoutData(1, -1)); v.add(tree, new VerticalLayoutData(1, 1)); return panel; }
From source file:com.ponysdk.core.terminal.ui.PTTreeItem.java
License:Apache License
@Override protected TreeItem createUIObject() { return text != null ? new TreeItem(SafeHtmlUtils.fromString(text)) : new TreeItem(); }
From source file:com.sencha.gxt.cell.core.client.ButtonCell.java
License:sencha.com license
/** * Sets the item's text.//from w w w .j a v a2s. c o m * * Text that contains reserved html characters will be escaped. * * @param text the text */ @Override public void setText(String text) { setHTML(SafeHtmlUtils.fromString(text)); }
From source file:com.sencha.gxt.cell.core.client.form.CheckBoxCell.java
License:sencha.com license
/** * The text that appears beside the checkbox (defaults to null). * * Text that contains reserved html characters will be escaped. * * @param text the box label text/*from w ww .j a v a2s . c o m*/ */ public void setBoxLabel(XElement parent, String text) { setBoxLabel(parent, SafeHtmlUtils.fromString(text)); }
From source file:com.sencha.gxt.core.client.dom.XElement.java
License:sencha.com license
/** * Retrieves the data using the request builder and updates the element's contents. * <p/>/*from www. j av a 2s .c o m*/ * Please note that the <code>Response</code> from the <code>RequestBuilder</code> is treated as raw html * without any sanitizing. If is up to the caller to ensure that the call does not return unsafe html. * <p/> * This method is subject to change. * * @param builder the request builder */ public final Request load(RequestBuilder builder) { try { builder.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { setInnerSafeHtml(exception != null && exception.getMessage() != null ? SafeHtmlUtils.fromString(exception.getMessage()) : SafeHtmlUtils.EMPTY_SAFE_HTML); } public void onResponseReceived(Request request, Response response) { setInnerSafeHtml(response != null && response.getText() != null ? SafeHtmlUtils.fromString(response.getText()) : SafeHtmlUtils.EMPTY_SAFE_HTML); } }); return builder.send(); } catch (Exception e) { setInnerSafeHtml(e != null && e.getMessage() != null ? SafeHtmlUtils.fromString(e.getMessage()) : SafeHtmlUtils.EMPTY_SAFE_HTML); return null; } }
From source file:com.sencha.gxt.dnd.core.client.GridDragSource.java
License:sencha.com license
@Override protected void onDragStart(DndDragStartEvent event) { Element r = grid.getView().findRow(event.getDragStartEvent().getStartElement()).cast(); if (r == null) { event.setCancelled(true);/*from www .java 2s . c om*/ return; } List<M> sel = grid.getSelectionModel().getSelectedItems(); if (sel.size() > 0) { event.setCancelled(false); event.setData(sel); if (getStatusText() == null) { event.getStatusProxy().update(SafeHtmlUtils.fromString(getMessages().itemsSelected(sel.size()))); } else { event.getStatusProxy() .update(SafeHtmlUtils.fromString(Format.substitute(getStatusText(), sel.size()))); } } }
From source file:com.sencha.gxt.dnd.core.client.ListViewDragSource.java
License:sencha.com license
@Override protected void onDragStart(DndDragStartEvent event) { Element r = listView.findElement(event.getDragStartEvent().getStartElement()); if (r == null) { event.setCancelled(true);/*from w w w .j a va 2s. c om*/ return; } List<M> sel = listView.getSelectionModel().getSelectedItems(); if (sel.size() > 0) { event.setCancelled(false); event.setData(sel); if (getStatusText() == null) { event.getStatusProxy().update(SafeHtmlUtils.fromString(getMessages().itemsSelected(sel.size()))); } else { event.getStatusProxy() .update(SafeHtmlUtils.fromString(Format.substitute(getStatusText(), sel.size()))); } } }
From source file:com.sencha.gxt.dnd.core.client.TreeDragSource.java
License:sencha.com license
@Override protected void onDragStart(DndDragStartEvent event) { Element startTarget = event.getDragStartEvent().getStartElement().<Element>cast(); Tree.TreeNode<M> start = getWidget().findNode(startTarget); if (start == null || !getWidget().getView().isSelectableTarget(start.getModel(), startTarget)) { event.setCancelled(true);/* w w w.ja va 2 s . c o m*/ return; } List<M> selected = getWidget().getSelectionModel().getSelectedItems(); if (selected.size() == 0) { event.setCancelled(true); return; } List<TreeNode<M>> selectedSubTrees = new ArrayList<TreeNode<M>>(); if (getTreeSource() == TreeSource.LEAF) { for (M item : selected) { if (getWidget().isLeaf(item)) { selectedSubTrees.add(getWidget().getStore().getSubTree(item)); } else { // forget it, we've got a non-leaf event.setCancelled(true); return; } } } else { // If allowed to drop only nodes or both, then we need to remove items from the list // that also have their parents being dragged ModelKeyProvider<? super M> kp = getWidget().getStore().getKeyProvider(); // Start by looking for all selected non-leaf items FastSet nonLeafKeys = new FastSet(); for (M item : selected) { if (getWidget().isLeaf(item)) { // While we're at it, if we're only allowed nodes, cancel if we see a leaf if (treeSource == TreeSource.NODE) { event.setCancelled(true); return; } } else { nonLeafKeys.add(kp.getKey(item)); } } // Walking backward (so we can remove as we go) through the list of all selected items, for // each item, check if it has a parent already in the list. // Clearly that parent is a non-leaf, so will be in the set we established in the last loop // Note: see TreeGridDragSource it's similar for (int i = selected.size() - 1; i >= 0; i--) { // TODO consider tracking these parents, and if they are part of another // parent, adding them to the keyset M parent = selected.get(i); while ((parent = getWidget().getStore().getParent(parent)) != null) { // If we find that this item's parent is also selected, then we can skip this item if (nonLeafKeys.contains(kp.getKey(parent))) { selected.remove(i); break; } } } for (M item : selected) { selectedSubTrees.add(getWidget().getStore().getSubTree(item)); } } if (selectedSubTrees.size() > 0) { event.setData(selectedSubTrees); } else { event.setCancelled(true); } if (selected.size() > 0) { event.setCancelled(false); if (getStatusText() == null) { event.getStatusProxy().update(SafeHtmlUtils .fromString(DefaultMessages.getMessages().listField_itemsSelected(selected.size()))); } else { event.getStatusProxy() .update(SafeHtmlUtils.fromString(Format.substitute(getStatusText(), selected.size()))); } } }
From source file:com.sencha.gxt.dnd.core.client.TreeGridDragSource.java
License:sencha.com license
@Override protected void onDragStart(DndDragStartEvent event) { Element startTarget = event.getDragStartEvent().getStartElement().<Element>cast(); Tree.TreeNode<M> start = getWidget().findNode(startTarget); if (start == null || !getWidget().getTreeView().isSelectableTarget(startTarget)) { event.setCancelled(true);/*from ww w .jav a 2s. c o m*/ return; } List<M> selected = getWidget().getSelectionModel().getSelectedItems(); if (selected.size() == 0) { event.setCancelled(true); return; } // The goal of this method is to find out which subtrees have been selected so we can // use them throughout this drag/drop process List<TreeNode<M>> selectedSubTrees = new ArrayList<TreeNode<M>>(); if (getTreeGridSource() == TreeSource.LEAF) { // If only allowed to drop leaf items, check for non-leaf items for (M item : selected) { if (getWidget().isLeaf(item)) { selectedSubTrees.add(getWidget().getTreeStore().getSubTree(item)); } else { // forget it, we've got a non-leaf event.setCancelled(true); return; } } } else { // If allowed to drop only nodes or both, then we need to remove items from the list // that also have their parents being dragged ModelKeyProvider<? super M> kp = getWidget().getTreeStore().getKeyProvider(); // Start by looking for all selected non-leaf items FastSet nonLeafKeys = new FastSet(); for (M item : selected) { if (getWidget().isLeaf(item)) { // While we're at it, if we're only allowed nodes, cancel if we see a leaf if (treeGridSource == TreeSource.NODE) { event.setCancelled(true); return; } } else { nonLeafKeys.add(kp.getKey(item)); } } // Walking backward (so we can remove as we go) through the list of all selected items, for // each item, check if it has a parent already in the list. // Clearly that parent is a non-leaf, so will be in the set we established in the last loop for (int i = selected.size() - 1; i >= 0; i--) { // TODO consider tracking these parents, and if they are part of another // parent, adding them to the keyset M parent = selected.get(i); if (parent == null) { // EXTGWT-2692 selected.remove(i); } else { while ((parent = getWidget().getTreeStore().getParent(parent)) != null) { // If we find that this item's parent is also selected, then we can skip this item if (nonLeafKeys.contains(kp.getKey(parent))) { selected.remove(i); break; } } } } // Finally, collect all subtrees of the items that are left for (M item : selected) { selectedSubTrees.add(getWidget().getTreeStore().getSubTree(item)); } } if (selectedSubTrees.size() > 0) { event.setData(selectedSubTrees); } else { event.setCancelled(true); } if (selected.size() > 0) { event.setCancelled(false); if (getStatusText() == null) { event.getStatusProxy().update(SafeHtmlUtils .fromString(DefaultMessages.getMessages().listField_itemsSelected(selected.size()))); } else { event.getStatusProxy() .update(SafeHtmlUtils.fromString(Format.substitute(getStatusText(), selected.size()))); } } }