Search in sources :

Example 46 with WText

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;
}
Also used : Action(com.github.bordertech.wcomponents.Action) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMenu(com.github.bordertech.wcomponents.WMenu) WImage(com.github.bordertech.wcomponents.WImage) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 47 with WText

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);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WText(com.github.bordertech.wcomponents.WText) WApplication(com.github.bordertech.wcomponents.WApplication) WDefinitionList(com.github.bordertech.wcomponents.WDefinitionList) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule)

Example 48 with WText

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);
}
Also used : ImageResource(com.github.bordertech.wcomponents.ImageResource) WText(com.github.bordertech.wcomponents.WText) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WImage(com.github.bordertech.wcomponents.WImage) WButton(com.github.bordertech.wcomponents.WButton) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Example 49 with WText

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);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) Condition(com.github.bordertech.wcomponents.subordinate.Condition) Optional(com.github.bordertech.wcomponents.subordinate.Optional) HideInGroup(com.github.bordertech.wcomponents.subordinate.HideInGroup) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) EnableInGroup(com.github.bordertech.wcomponents.subordinate.EnableInGroup) ShowInGroup(com.github.bordertech.wcomponents.subordinate.ShowInGroup) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Not(com.github.bordertech.wcomponents.subordinate.Not) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) Enable(com.github.bordertech.wcomponents.subordinate.Enable) Show(com.github.bordertech.wcomponents.subordinate.Show) DisableInGroup(com.github.bordertech.wcomponents.subordinate.DisableInGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WHorizontalRule(com.github.bordertech.wcomponents.WHorizontalRule) Disable(com.github.bordertech.wcomponents.subordinate.Disable) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory)

Example 50 with WText

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);
                    }
                }
            }
        }
    }
}
Also used : WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) ArrayList(java.util.ArrayList) Date(java.util.Date) WSubMenu(com.github.bordertech.wcomponents.WSubMenu) WMenuItem(com.github.bordertech.wcomponents.WMenuItem) WText(com.github.bordertech.wcomponents.WText) SimpleDateFormat(java.text.SimpleDateFormat) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel)

Aggregations

WText (com.github.bordertech.wcomponents.WText)97 Test (org.junit.Test)63 WPanel (com.github.bordertech.wcomponents.WPanel)17 WCollapsible (com.github.bordertech.wcomponents.WCollapsible)10 WDecoratedLabel (com.github.bordertech.wcomponents.WDecoratedLabel)10 UIContext (com.github.bordertech.wcomponents.UIContext)9 WHeading (com.github.bordertech.wcomponents.WHeading)9 WTabSet (com.github.bordertech.wcomponents.WTabSet)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)6 WList (com.github.bordertech.wcomponents.WList)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)6 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)6 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)6 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)5 WComponent (com.github.bordertech.wcomponents.WComponent)5 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)5 WImage (com.github.bordertech.wcomponents.WImage)5 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)5 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)5