summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/DisableEnableCascade.java
blob: cd284224a09158cdf42101319433e61ff926f44e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.vaadin.tests.components;

import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;

public class DisableEnableCascade extends TestBase {

    private Panel outerPanel;
    private TabSheet innerTabsheet;
    private Button button;
    private Button enableDisablePanelButton;
    private Button enableDisableTabSheetButton;
    private Button enableDisableButtonButton;

    @Override
    protected void setup() {

        outerPanel = new Panel("Outer panel, enabled");
        innerTabsheet = new TabSheet();
        innerTabsheet.setCaption("Inner Tabsheet, enabled");

        button = new Button("Button, enabled");

        outerPanel.setContent(innerTabsheet);
        innerTabsheet.addTab(button, "Tab containing button");

        addComponent(outerPanel);

        enableDisablePanelButton = new Button("Disable panel",
                new ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        enableDisable(outerPanel, enableDisablePanelButton);

                    }
                });

        enableDisableTabSheetButton = new Button("Disable TabSheet",
                new ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        enableDisable(innerTabsheet,
                                enableDisableTabSheetButton);

                    }
                });

        enableDisableButtonButton = new Button("Disable Button",
                new ClickListener() {

                    @Override
                    public void buttonClick(ClickEvent event) {
                        enableDisable(button, enableDisableButtonButton);

                    }
                });

        addComponent(enableDisablePanelButton);
        addComponent(enableDisableTabSheetButton);
        addComponent(enableDisableButtonButton);
    }

    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. Disabling a parent should disabled its children aswell. The buttons only toggle the state of the target component.";
    }

    @Override
    protected Integer getTicketNumber() {
        return 8507;
    }

}