123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package com.vaadin.tests.components;
-
- import java.util.Iterator;
-
- import com.vaadin.ui.Button;
- import com.vaadin.ui.Component;
- import com.vaadin.ui.NativeButton;
- import com.vaadin.ui.Panel;
- import com.vaadin.ui.TabSheet;
- import com.vaadin.ui.VerticalLayout;
- import com.vaadin.v7.ui.TextArea;
- import com.vaadin.v7.ui.TextField;
-
- public class DisableEnableCascadeStyles extends TestBase {
-
- private Panel outerPanel;
- private TabSheet innerTabsheet;
- private Button button;
- private TextArea textArea;
- private TextField textField;
- private VerticalLayout layout;
- private NativeButton nativeButton;
- private Button enableDisablePanelButton;
- private Button enableDisableTabSheetButton;
- private Button enableDisableLayoutButton;
- private Button enableDisableComponentsButton;
-
- @Override
- protected void setup() {
-
- outerPanel = new Panel("Outer panel, enabled");
- innerTabsheet = new TabSheet();
- innerTabsheet.setCaption("Inner Tabsheet, enabled");
-
- button = new Button("Button, enabled");
- nativeButton = new NativeButton("NativeButton, enabled");
- textField = new TextField("TextField with caption and value, enabled");
- textField.setValue("Text");
- textArea = new TextArea("TextArea with caption and value, enabled");
- textArea.setValue("Text");
- layout = new VerticalLayout();
- layout.setCaption("VerticalLayout, enabled");
- layout.addComponent(button);
- layout.addComponent(nativeButton);
- layout.addComponent(textField);
- layout.addComponent(textArea);
-
- outerPanel.setContent(innerTabsheet);
- innerTabsheet.addTab(layout, "Tab containing layout");
-
- addComponent(outerPanel);
-
- enableDisablePanelButton = new Button("Disable panel",
- event -> enableDisable(outerPanel, enableDisablePanelButton));
-
- enableDisableTabSheetButton = new Button("Disable TabSheet",
- event -> enableDisable(innerTabsheet,
- enableDisableTabSheetButton));
-
- enableDisableLayoutButton = new Button("Disable Tab content (Layout)",
- event -> enableDisable(layout, enableDisableLayoutButton));
- enableDisableComponentsButton = new Button("Disable Layout Components",
- event -> {
- for (Iterator<Component> i = layout
- .getComponentIterator(); i.hasNext();) {
- final Component c = i.next();
- if (c.isEnabled()) {
- c.setEnabled(false);
- c.setCaption(c.getCaption().replace("enabled",
- "disabled"));
- } else {
- c.setEnabled(true);
- c.setCaption(c.getCaption().replace("disabled",
- "enabled"));
- }
- }
- if (layout.getComponent(0).isEnabled()) {
- enableDisableComponentsButton.setCaption(
- enableDisableComponentsButton.getCaption()
- .replace("Enable", "Disable"));
- } else {
- enableDisableComponentsButton.setCaption(
- enableDisableComponentsButton.getCaption()
- .replace("Disable", "Enable"));
- }
- });
- addComponent(enableDisablePanelButton);
- addComponent(enableDisableTabSheetButton);
- addComponent(enableDisableLayoutButton);
- addComponent(enableDisableComponentsButton);
- }
-
- protected void enableDisable(Component target, Button button) {
- if (target.isEnabled()) {
- target.setEnabled(false);
- button.setCaption(button.getCaption().replace("Disable", "Enable"));
- target.setCaption(
- target.getCaption().replace("enabled", "disabled"));
- } else {
- target.setEnabled(true);
- button.setCaption(button.getCaption().replace("Enable", "Disable"));
- target.setCaption(
- target.getCaption().replace("disabled", "enabled"));
- }
- }
-
- @Override
- protected String getDescription() {
- return "Tests the disable state is cascaded correctly to children components that can be disabled. The children and their captions must get the v-disabled style name.";
- }
-
- @Override
- protected Integer getTicketNumber() {
- return 8708;
- }
-
- }
|