summaryrefslogtreecommitdiff
path: root/webapps/qooxdoo-0.6.5-sdk/frontend/application/sample/source/html/example/TreeVirtual_2.html
blob: 843de574777df8a77b7aea856c3e657661074f6b (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>qooxdoo &raquo; Demo &raquo; Sample</title>
  <link type="text/css" rel="stylesheet" href="../../css/layout.css"/>
  <!--[if IE]>
  <link type="text/css" rel="stylesheet" href="../../css/layout_ie.css"/>
  <![endif]-->
  <script type="text/javascript" src="../../script/sample.js"></script>
</head>
<body>
  <script type="text/javascript" src="../../script/layout.js"></script>

  <div id="demoDescription">
    <p>Show use of events upon tree opening and closing, including adding
    nodes dynamically upon tree open and removing the open/close button upon
    tree open if the branch contains no children.
    </p><p>
    Allows controlling selection mode.  Labels of selected items are
    displayed. 
    </p>
  </div>

  <script type="text/javascript">
  qx.core.Init.getInstance().defineMain(function()
  {
    // tree
    var tree = new qx.ui.treevirtual.TreeVirtual("Tree");
    with (tree)
    {
      set({
            left   : 10,
            top    : 30,
            width  : 400,
            bottom : 30,
            border : qx.renderer.border.BorderPresets.getInstance().thinInset
          });
      setColumnWidth(0, 400);
      setAlwaysShowOpenCloseSymbol(true);
    };

    // Add the tree to the document
    tree.addToDocument();

    // tree data model
    var dataModel = tree.getDataModel();

    var te1 = dataModel.addBranch(null, "Desktop", true);

    var te;
    dataModel.addBranch(te1, "Files", true);

    te = dataModel.addBranch(te1, "Workspace", true);
    dataModel.addLeaf(te, "Windows (C:)");
    dataModel.addLeaf(te, "Documents (D:)");

    dataModel.addBranch(te1, "Network", true);
    dataModel.addBranch(te1, "Trash", true);

    var te2 = dataModel.addBranch(null, "Inbox", true);

    te = dataModel.addBranch(te2, "Spam", false);
    for (var i = 1; i < 3000; i++)
    {
      dataModel.addLeaf(te, "Spam Message #" + i);
    }

    dataModel.addBranch(te2, "Sent", false);
    dataModel.addBranch(te2, "Trash", false);
    dataModel.addBranch(te2, "Data", false);
    dataModel.addBranch(te2, "Edit", false);

    dataModel.setData();

    var newItem = 1;

    /*
     * Each time we get a treeOpenWithContent event, add yet another leaf node
     * to the node being opened.
     */
    tree.addEventListener("treeOpenWithContent",
                          function(e)
                          {
                            alert('treeOpenWithContent ');
                            var node = e.getData();
                            dataModel.addLeaf(node.nodeId, newItem.toString());
                            newItem++;
                          });

    tree.addEventListener("treeClose",
                          function(e)
                          {
                            alert('treeClose ');
                          });

    /*
     * We handle opening an empty folder specially.  We demonstrate how to
     * disable the open/close symbol once we've determined there's nothing in
     * it.  This feature might be used to dynamically retrieve the contents of
     * the folder, and if nothing is available, indicate it by removing the
     * open/close symbol.
     */
    tree.addEventListener("treeOpenWhileEmpty",
                          function(e)
                          {
                            alert('treeOpenWhileEmpty');
                            var node = e.getData();
                            tree.setState(node.nodeId,
                                          { bHideOpenClose : true });
                          });


    tree.addEventListener("changeSelection",
                          function(e)
                          {
                            var text = "Selected labels:";
                            var selectedNodes = e.getData();
                            for (i = 0; i < selectedNodes.length; i++)
                            {
                              text += "\n  " + selectedNodes[i].label;
                            }
                            alert('changeSelection: ' + text);
                          });



    var commandFrame = new qx.ui.groupbox.GroupBox("Control");
    commandFrame.set({ top: 48, left: 520, right: 290, height: "auto" });
    commandFrame.addToDocument();

    // Create a combo box for the selection type
    var o = new qx.ui.basic.Atom("Selection Mode: ");
    o.set({ top: 6, left: 0 });
    commandFrame.add(o);

    o = new qx.ui.form.ComboBox();
    o.set({ top: 20, left: 4, width: "100%" });
    o.setEditable(false);

    // Add the various selection types
    var item = new qx.ui.form.ListItem("No Selection");
    o.add(item);
    var item = new qx.ui.form.ListItem("Single Selection");
    o.add(item);
    o.setSelected(item);
    var item = new qx.ui.form.ListItem("Single Interval Selection");
    o.add(item);
    var item = new qx.ui.form.ListItem("Multiple Interval Selection");
    o.add(item);
  
    // We want to be notified if the selection changes
    o.addEventListener(
      "changeSelected",
      function()
      {
        switch(this.getValue())
        {
        case "No Selection":
          tree.setSelectionMode(
            qx.ui.treevirtual.TreeVirtual.SelectionMode.NONE);
          break;

        case "Single Selection":
          tree.setSelectionMode(
            qx.ui.treevirtual.TreeVirtual.SelectionMode.SINGLE);
          break;

        case "Single Interval Selection":
          tree.setSelectionMode(
            qx.ui.treevirtual.TreeVirtual.SelectionMode.SINGLE_INTERVAL);
          break;

        case "Multiple Interval Selection":
          tree.setSelectionMode(
            qx.ui.treevirtual.TreeVirtual.SelectionMode.MULTIPLE_INTERVAL);
          break;
        }
      });

    commandFrame.add(o);

  });
  </script>
</body>
</html>