use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class TreeMenuExample method buildTreeMenuWithDecoratedLabel.
/**
* Tree menu containing image in the items. This example demonstrates creating {@link WSubMenu} and
* {@link WMenuItem} components with {@link WDecoratedLabel}.
*
* @return menu with a decorated label
*/
private WMenu buildTreeMenuWithDecoratedLabel() {
WMenu menu = new WMenu(WMenu.MenuType.TREE);
WDecoratedLabel dLabel = new WDecoratedLabel(null, new WText("Settings Menu"), new WImage("/image/settings.png", "settings"));
WSubMenu settings = new WSubMenu(dLabel);
settings.setMode(WSubMenu.MenuMode.LAZY);
settings.setAccessKey('S');
menu.add(settings);
settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Account Settings"), new WImage("/image/user-properties.png", "user properties"))));
settings.add(new WMenuItem(new WDecoratedLabel(null, new WText("Personal Details"), new WImage("/image/user.png", "user"))));
WSubMenu addressSub = new WSubMenu(new WDecoratedLabel(null, new WText("Address Details"), new WImage("/image/address-book-open.png", "address book")));
addressSub.setMode(WSubMenu.MenuMode.LAZY);
settings.add(addressSub);
addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Home Address"), new WImage("/image/home.png", "home"))));
addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Work Address"), new WImage("/image/wrench.png", "work"))));
addressSub.add(new WMenuItem(new WDecoratedLabel(null, new WText("Postal Address"), new WImage("/image/mail-post.png", "postal"))));
WMenuItem itemWithIcon = new WMenuItem("Help");
itemWithIcon.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
// do something
}
});
itemWithIcon.setHtmlClass(HtmlClassProperties.ICON_HELP_BEFORE);
menu.add(itemWithIcon);
return menu;
}
use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class ExampleSection method selectExample.
/**
* Selects an example.
*
* @param example the example to select.
* @param exampleName the name of the example being selected.
*/
public void selectExample(final WComponent example, final String exampleName) {
WComponent currentExample = container.getChildAt(0).getParent();
if (currentExample != null && currentExample.getClass().equals(example.getClass())) {
// Same example selected, do nothing
return;
}
resetExample();
container.removeAll();
this.getDecoratedLabel().setBody(new WText(exampleName));
WApplication app = WebUtilities.getAncestorOfClass(WApplication.class, this);
if (app != null) {
app.setTitle(exampleName);
}
if (example instanceof ErrorComponent) {
tabset.getTab(0).setText("Error");
source.setSource(null);
} else {
String className = example.getClass().getName();
WDefinitionList list = new WDefinitionList(WDefinitionList.Type.COLUMN);
container.add(list);
list.addTerm("Example path", new WText(className.replaceAll("\\.", " / ")));
list.addTerm("Example JavaDoc", new JavaDocText(getSource(className)));
container.add(new WHorizontalRule());
tabset.getTab(0).setText(example.getClass().getSimpleName());
source.setSource(getSource(className));
}
container.add(example);
example.setLocked(true);
}
use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class ExampleSection method buildUI.
/**
* Add the controls to the section in the right order.
*/
private void buildUI() {
add(messages);
add(tabset);
// add(new AccessibilityWarningContainer());
container.add(new WText("Select an example from the menu"));
// Set a static ID on container and it becomes a de-facto naming context.
container.setIdName("eg");
tabset.addTab(container, "(no selection)", WTabSet.TAB_MODE_CLIENT);
WImage srcImage = new WImage(new ImageResource("/image/text-x-source.png", "View Source"));
srcImage.setCacheKey("srcTabImage");
tabset.addTab(source, new WDecoratedLabel(srcImage), WTabSet.TAB_MODE_LAZY).setToolTip("View Source");
// The refresh current view button.
WButton refreshButton = new WButton("\u200b");
refreshButton.setToolTip("Refresh");
refreshButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-refresh"));
// refreshButton.setImage("/image/refresh-w.png");
refreshButton.setRenderAsLink(true);
refreshButton.setAction(new ValidatingAction(messages.getValidationErrors(), refreshButton) {
@Override
public void executeOnValid(final ActionEvent event) {
// Do Nothing
}
});
// The reset example button.
final WButton resetButton = new WButton("\u200b");
resetButton.setToolTip("Reset");
resetButton.setHtmlClass(HtmlIconUtil.getIconClasses("fa-times-circle"));
// resetButton.setImage("/image/cancel-w.png");
resetButton.setRenderAsLink(true);
resetButton.setAction(new ValidatingAction(messages.getValidationErrors(), resetButton) {
@Override
public void executeOnValid(final ActionEvent event) {
resetExample();
}
});
addToTail(refreshButton);
addToTail(new WText("\u2002"));
addToTail(resetButton);
}
use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class SubordinateControlOptionsExample method buildControl.
/**
* Build the subordinate control.
*/
private void buildControl() {
buildControlPanel.reset();
buildTargetPanel.reset();
// Setup Trigger
setupTrigger();
// Create target
SubordinateTarget target = setupTarget();
// Create Actions
com.github.bordertech.wcomponents.subordinate.Action trueAction;
com.github.bordertech.wcomponents.subordinate.Action falseAction;
switch((ControlActionType) drpActionType.getSelected()) {
case ENABLE_DISABLE:
trueAction = new Enable(target);
falseAction = new Disable(target);
break;
case SHOW_HIDE:
trueAction = new Show(target);
falseAction = new Hide(target);
break;
case MAN_OPT:
trueAction = new Mandatory(target);
falseAction = new Optional(target);
break;
case SHOWIN_HIDEIN:
trueAction = new ShowInGroup(target, targetGroup);
falseAction = new HideInGroup(target, targetGroup);
break;
case ENABLEIN_DISABLEIN:
trueAction = new EnableInGroup(target, targetGroup);
falseAction = new DisableInGroup(target, targetGroup);
break;
default:
throw new SystemException("ControlAction type not valid");
}
// Create Condition
Condition condition = createCondition();
if (cbNot.isSelected()) {
condition = new Not(condition);
}
// Create Rule
Rule rule = new Rule(condition, trueAction, falseAction);
// Create Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
buildControlPanel.add(control);
if (targetCollapsible.getDecoratedLabel() != null) {
targetCollapsible.getDecoratedLabel().setTail(new WText(control.toString()));
}
control = new WSubordinateControl();
rule = new Rule(new Equal(cbClientDisableTrigger, true), new Disable((SubordinateTarget) trigger), new Enable((SubordinateTarget) trigger));
control.addRule(rule);
buildControlPanel.add(control);
}
use of com.github.bordertech.wcomponents.WText in project wcomponents by BorderTech.
the class FilterableTableExample method buildFilterSubMenu.
/**
* Creates and populates the sub-menu for each filter menu.
*
* @param menu The WMenu we are currently populating.
* @param column The column index of the table column the menu is in. This is used to get the data off the table's
* Bean to put text content into the menu's items.
*/
private void buildFilterSubMenu(final WMenu menu, final int column) {
List<?> beanList = getFilterableTableModel().getFullBeanList();
int rows = (beanList == null) ? 0 : beanList.size();
if (rows == 0) {
return;
}
final List<String> found = new ArrayList<>();
final WDecoratedLabel filterSubMenuLabel = new WDecoratedLabel(new WText("\u200b"));
filterSubMenuLabel.setToolTip("Filter this column");
filterSubMenuLabel.setHtmlClass(HtmlIconUtil.getIconClasses("fa-filter"));
final WSubMenu submenu = new WSubMenu(filterSubMenuLabel);
submenu.setSelectionMode(SELECTION_MODE);
menu.add(submenu);
WMenuItem item = new WMenuItem(CLEAR_ALL, new ClearFilterAction());
submenu.add(item);
item.setActionObject(item);
item.setSelectability(false);
add(new WAjaxControl(item, table));
Object cellObject;
String cellContent, cellContentMatch;
Object bean;
if (beanList != null) {
for (int i = 0; i < rows; ++i) {
bean = beanList.get(i);
if (bean != null) {
cellObject = getFilterableTableModel().getBeanPropertyValueFullList(BEAN_PROPERTIES[column], bean);
if (cellObject != null) {
if (cellObject instanceof Date) {
cellContent = new SimpleDateFormat(DATE_FORMAT).format((Date) cellObject);
} else {
cellContent = cellObject.toString();
}
if ("".equals(cellContent)) {
cellContent = EMPTY;
}
cellContentMatch = (getFilterableTableModel().isCaseInsensitiveMatch()) ? cellContent.toLowerCase() : cellContent;
if (found.indexOf(cellContentMatch) == -1) {
item = new WMenuItem(cellContent, new FilterAction());
submenu.add(item);
add(new WAjaxControl(item, table));
found.add(cellContentMatch);
}
}
}
}
}
}
Aggregations