use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WFieldErrorIndicator_Test method testIsDefaultState.
@Test
public void testIsDefaultState() {
WPanel root = new WPanel();
WTextField component = new WTextField();
WFieldErrorIndicator indicator = new WFieldErrorIndicator(component);
root.add(indicator);
root.add(component);
root.setLocked(true);
setActiveContext(createUIContext());
Assert.assertTrue("Should be in default state by default", indicator.isDefaultState());
List<Diagnostic> diags = new ArrayList<>();
root.validate(diags);
root.showErrorIndicators(diags);
Assert.assertTrue("Should be in default if there are no errors", indicator.isDefaultState());
// Add an error by making the field mandatory
root.reset();
component.setMandatory(true);
root.validate(diags);
root.showErrorIndicators(diags);
Assert.assertFalse("Should not be in default if there are errors", indicator.isDefaultState());
root.reset();
Assert.assertTrue("Should be in default after reset", indicator.isDefaultState());
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WButtonExample method addDisabledExamples.
/**
* Examples of disabled buttons in various guises.
*/
private void addDisabledExamples() {
add(new WHeading(HeadingLevel.H2, "Examples of disabled buttons"));
WPanel disabledButtonLayoutPanel = new WPanel(WPanel.Type.BOX);
disabledButtonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0, FlowLayout.ContentAlignment.BASELINE));
add(disabledButtonLayoutPanel);
WButton button = new WButton("Disabled button");
button.setDisabled(true);
disabledButtonLayoutPanel.add(button);
button = new WButton("Disabled button as link");
button.setDisabled(true);
button.setRenderAsLink(true);
disabledButtonLayoutPanel.add(button);
add(new WHeading(HeadingLevel.H3, "Examples of disabled buttons displaying only an image"));
disabledButtonLayoutPanel = new WPanel(WPanel.Type.BOX);
disabledButtonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0, FlowLayout.ContentAlignment.BASELINE));
add(disabledButtonLayoutPanel);
button = new WButton("Disabled button");
button.setDisabled(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
disabledButtonLayoutPanel.add(button);
button = new WButton("Disabled button as link");
button.setDisabled(true);
button.setRenderAsLink(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
disabledButtonLayoutPanel.add(button);
add(new WHeading(HeadingLevel.H3, "Examples of disabled buttons displaying an image with imagePosition EAST"));
disabledButtonLayoutPanel = new WPanel(WPanel.Type.BOX);
disabledButtonLayoutPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 6, 0, FlowLayout.ContentAlignment.BASELINE));
add(disabledButtonLayoutPanel);
button = new WButton("Disabled button");
button.setDisabled(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
button.setImagePosition(ImagePosition.EAST);
disabledButtonLayoutPanel.add(button);
button = new WButton("Disabled button as link");
button.setDisabled(true);
button.setRenderAsLink(true);
button.setImage("/image/tick.png");
button.setToolTip("Checking currently disabled");
button.setImagePosition(ImagePosition.EAST);
disabledButtonLayoutPanel.add(button);
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WContentExample method addContentRow.
/**
* Adds components to the given container which demonstrate various ways of acessing the given content.
*
* @param contentDesc the description of the content, used to label the controls.
* @param contentAccess the content which will be displayed.
* @param target the container to add the UI controls to.
*/
private void addContentRow(final String contentDesc, final ContentAccess contentAccess, final MutableContainer target) {
// Demonstrate WButton + WContent, round trip
WButton button = new WButton(contentDesc);
final WContent buttonContent = new WContent();
button.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
buttonContent.setContentAccess(contentAccess);
buttonContent.display();
}
});
WContainer buttonCell = new WContainer();
buttonCell.add(buttonContent);
buttonCell.add(button);
target.add(buttonCell);
// Demonstrate WButton + WContent, using AJAX
WButton ajaxButton = new WButton(contentDesc);
final WContent ajaxContent = new WContent();
ajaxButton.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
ajaxContent.setContentAccess(contentAccess);
ajaxContent.display();
}
});
WContainer ajaxCell = new WContainer();
// The WContent must be wrapped in an AJAX targetable container
WPanel ajaxContentPanel = new WPanel();
ajaxContentPanel.add(ajaxContent);
ajaxCell.add(ajaxButton);
ajaxCell.add(ajaxContentPanel);
ajaxButton.setAjaxTarget(ajaxContentPanel);
target.add(ajaxCell);
// Demonstrate WContentLink - new window
WContentLink contentLinkNewWindow = new WContentLink(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
setContentAccess(contentAccess);
}
};
target.add(contentLinkNewWindow);
// Demonstrate WContentLink - prompt to save
WContentLink contentLinkPromptToSave = new WContentLink(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
setContentAccess(contentAccess);
}
};
contentLinkPromptToSave.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
target.add(contentLinkPromptToSave);
// Demonstrate WContentLink - inline
WContentLink contentLinkInline = new WContentLink(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
setContentAccess(contentAccess);
}
};
contentLinkInline.setDisplayMode(DisplayMode.DISPLAY_INLINE);
target.add(contentLinkInline);
// Demonstrate targeting of content via a URL
WMenu menu = new WMenu(WMenu.MenuType.FLYOUT);
final WContent menuContent = new WContent();
menuContent.setDisplayMode(DisplayMode.PROMPT_TO_SAVE);
WMenuItem menuItem = new WMenuItem(contentDesc) {
@Override
protected void preparePaintComponent(final Request request) {
super.preparePaintComponent(request);
menuContent.setContentAccess(contentAccess);
setUrl(menuContent.getUrl());
}
};
menu.add(menuItem);
WContainer menuCell = new WContainer();
menuCell.add(menuContent);
menuCell.add(menu);
target.add(menuCell);
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WPanelMarginExample method createPanel.
/**
* @param margin the margin to include on the panel.
* @return the panel with a margin.
*/
private WPanel createPanel(final Margin margin) {
WText text = new WText(DUMMY_TEXT);
text.setEncodeText(false);
WPanel panel = new WPanel(WPanel.Type.BOX);
panel.add(text);
panel.setMargin(margin);
return panel;
}
use of com.github.bordertech.wcomponents.WPanel in project wcomponents by BorderTech.
the class WRadioButtonSelectExample method addInsideAFieldLayoutExample.
/**
* When a WRadioButtonSelect is added to a WFieldLayout the legend is moved. The first CheckBoxSelect has a frame,
* the second doesn't
*/
private void addInsideAFieldLayoutExample() {
add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect inside a WFieldLayout"));
add(new ExplanatoryText("When a WRadioButtonSelect is inside a WField its label is exposed in a way which appears and behaves like a regular HTML label." + " This allows WRadioButtonSelects to be used in a layout with simple form controls (such as WTextField) and produce a consistent" + " and predicatable interface.\n" + "The third example in this set uses a null label and a toolTip to hide the labelling element. This can lead to user confusion and" + " is not recommended."));
// Note: the wrapper WPanel here is to work around a bug in validation. See https://github.com/BorderTech/wcomponents/issues/1370
final WPanel wrapper = new WPanel();
add(wrapper);
final WMessages messages = new WMessages();
wrapper.add(messages);
WFieldLayout layout = new WFieldLayout();
layout.setLabelWidth(25);
wrapper.add(layout);
WButton resetThisBit = new WButton("Reset this bit");
resetThisBit.setCancel(true);
resetThisBit.setAjaxTarget(wrapper);
resetThisBit.setAction(new Action() {
@Override
public void execute(final ActionEvent event) {
wrapper.reset();
}
});
layout.addField(resetThisBit);
String[] options = new String[] { "Dog", "Cat", "Bird", "Turtle" };
WRadioButtonSelect select = new WRadioButtonSelect(options);
layout.addField("Select an animal", select);
String[] options2 = new String[] { "Parrot", "Galah", "Cockatoo", "Lyre" };
select = new WRadioButtonSelect(options2);
select.setMandatory(true);
layout.addField("You must select a bird", select);
select.setFrameless(true);
// a tooltip can be used as a label stand-in even in a WField
String[] options3 = new String[] { "Carrot", "Beet", "Brocolli", "Bacon - the perfect vegetable" };
select = new WRadioButtonSelect(options3);
// if you absolutely do not want a WLabel in a WField then it has to be added using null cast to a WLabel.
layout.addField((WLabel) null, select);
select.setToolTip("Veggies");
WButton btnValidate = new WButton("validate");
btnValidate.setAction(new ValidatingAction(messages.getValidationErrors(), layout) {
@Override
public void executeOnValid(final ActionEvent event) {
// do nothing
}
});
layout.addField(btnValidate);
wrapper.add(new WAjaxControl(btnValidate, wrapper));
}
Aggregations