aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/demo/sampler/features/layouts/SplitPanelBasicExample.java
blob: 4712fda82a064a8c0f235952bede674c762e70fa (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.itmill.toolkit.demo.sampler.features.layouts;

import java.net.URL;

import com.itmill.toolkit.demo.sampler.ExampleUtil;
import com.itmill.toolkit.terminal.ExternalResource;
import com.itmill.toolkit.ui.AbstractSelect;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.SplitPanel;
import com.itmill.toolkit.ui.TabSheet;
import com.itmill.toolkit.ui.Tree;
import com.itmill.toolkit.ui.VerticalLayout;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;

public class SplitPanelBasicExample extends VerticalLayout {

    private URL nativeWindowURL = null;
    private Button b1;

    public SplitPanelBasicExample() {
        setSpacing(true);

        b1 = new Button("Open a new window with a SplitPanel", this,
                "openButtonClick");
        addComponent(b1);

    }

    public void openButtonClick(ClickEvent event) {
        if (nativeWindowURL == null) {
            getApplication().addWindow(createWindow());
        }
        getApplication().getMainWindow().open(
                new ExternalResource(nativeWindowURL), "_blank");
    }

    /*
     * Create new window which contains the layout obtained from
     * createDemoLayout()
     */
    private Window createWindow() {
        // Create a new window for the SplitPanel
        final Window w = new Window("SplitPanel Demo");
        getApplication().addWindow(w);
        w.setLayout(createDemoLayout());
        nativeWindowURL = w.getURL();
        return w;
    }

    /*
     * Creates the actual Layout with two SplitPanels and some content
     */
    private SplitPanel createDemoLayout() {
        // Create a new SplitPanel
        SplitPanel demoSP = new SplitPanel();
        // Set orientation
        demoSP.setOrientation(SplitPanel.ORIENTATION_HORIZONTAL);
        // Set split position (from left edge) in pixels
        demoSP.setSplitPosition(200, UNITS_PIXELS);

        // Create an example tree component, set to full size
        Tree t = new Tree("Hardware Inventory", ExampleUtil
                .getHardwareContainer());
        t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
        t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
        t.setSizeFull();

        // Add the Tree component to the SplitPanel
        demoSP.addComponent(t);

        // Create a second SplitPanel
        SplitPanel subSP = new SplitPanel();
        // Set orientation
        subSP.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
        // Set split position in percentage
        subSP.setSplitPosition(80);
        // Set the split locked (= not resizeable)
        subSP.setLocked(true);

        // Create an example tabsheet component with some content
        final TabSheet ts = new TabSheet();
        final Label l1 = new Label(
                "This window shows an example of a SplitPanel component."
                        + " A second SplitPanel is inserted into the first one"
                        + " to allow a split into three regions.");
        final Label l2 = new Label(
                "Try resizing the window (horizontally) and you will"
                        + " notice that the leftmost region does not resize because"
                        + " the split position is set in pixels."
                        + " If you resize the window vertically you will see"
                        + " how the split position ratio works.");
        final Label l3 = new Label(
                "You may resize the left and right regions by dragging the"
                        + " vertical split handle left or right. Resizing the"
                        + " upper and lower regions has been disabled.");
        ts.addTab(l1);
        ts.setTabCaption(l1, "SplitPanel demo");
        ts.addTab(l2);
        ts.setTabCaption(l2, "Resizing");
        ts.addTab(l3);
        ts.setTabCaption(l3, "Resizing the regions");
        ts.setSizeFull();

        // Add the components to the sub-SplitPanel
        subSP.addComponent(ts);
        subSP.addComponent(new Label("Comment area"));

        // Add sub-SplitPanel to main SplitPanel
        demoSP.addComponent(subSP);

        return demoSP;
    }
}