aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2009-02-06 13:55:07 +0000
committerMarc Englund <marc.englund@itmill.com>2009-02-06 13:55:07 +0000
commit344cdb628e0b45c71409347f343a9798bd16b7df (patch)
treeea15950fee23551c0e447187066dd2a86b7b924e
parent0dea02074775cc4c5eaa347253ff1446302abf3e (diff)
downloadvaadin-framework-344cdb628e0b45c71409347f343a9798bd16b7df.tar.gz
vaadin-framework-344cdb628e0b45c71409347f343a9798bd16b7df.zip
Sampler; sample modifications
svn changeset:6751/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java8
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEvents.java3
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEventsExample.java32
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/trees/TreeMultiSelect.java3
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelect.java3
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelectExample.java102
6 files changed, 89 insertions, 62 deletions
diff --git a/src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java b/src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java
index c031e499bf..fbf9e15c53 100644
--- a/src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java
+++ b/src/com/itmill/toolkit/demo/sampler/features/text/TextAreaExample.java
@@ -19,13 +19,15 @@ public class TextAreaExample extends HorizontalLayout implements
setSpacing(true);
editor = new TextField("", initialText);
+ editor.setRows(20); // this will make it an 'area', i.e multiline
+ editor.setColumns(20);
editor.addListener(this);
editor.setImmediate(true);
- editor.setColumns(20);
- editor.setRows(20);
addComponent(editor);
- addComponent(new Button(">>"));
+ // the TextArea is immediate, and it's valueCahnge updates the Label,
+ // so this button actually does nothing
+ addComponent(new Button(">"));
plainText = new Label(initialText);
plainText.setContentMode(Label.CONTENT_XHTML);
diff --git a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEvents.java b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEvents.java
index a10d197628..646fe60870 100644
--- a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEvents.java
+++ b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEvents.java
@@ -21,7 +21,8 @@ public class TreeMouseEvents extends Feature {
+ " is used. Through ItemClickEvent we can update the"
+ " label showing the selection."
+ "<br>Try to click your left, right and middle mouse"
- + "buttons on the tree items.";
+ + "buttons on the tree items. Any modifier keys will"
+ + " also be detected.";
}
@Override
diff --git a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEventsExample.java b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEventsExample.java
index ad012b83db..42cd0117ab 100644
--- a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEventsExample.java
+++ b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMouseEventsExample.java
@@ -5,7 +5,6 @@ import com.itmill.toolkit.demo.sampler.ExampleUtil;
import com.itmill.toolkit.event.ItemClickEvent;
import com.itmill.toolkit.event.ItemClickEvent.ItemClickListener;
import com.itmill.toolkit.ui.AbstractSelect;
-import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Tree;
import com.itmill.toolkit.ui.VerticalLayout;
@@ -14,7 +13,6 @@ public class TreeMouseEventsExample extends VerticalLayout implements
private Tree t;
private int itemId;
- private Label l;
public TreeMouseEventsExample() {
setSpacing(true);
@@ -43,21 +41,40 @@ public class TreeMouseEventsExample extends VerticalLayout implements
// Disallow selecting items from the tree
t.setSelectable(false);
- l = new Label();
addComponent(t);
- addComponent(l);
}
public void itemClick(ItemClickEvent event) {
+ // Indicate which modifier keys are pressed
+ String modifiers = "";
+ if (event.isAltKey()) {
+ modifiers += "Alt ";
+ }
+ if (event.isCtrlKey()) {
+ modifiers += "Ctrl ";
+ }
+ if (event.isMetaKey()) {
+ modifiers += "Meta ";
+ }
+ if (event.isShiftKey()) {
+ modifiers += "Shift ";
+ }
+ if (modifiers.length() > 0) {
+ modifiers = "Modifiers: " + modifiers;
+ } else {
+ modifiers = "Modifiers: none";
+ }
switch (event.getButton()) {
case ItemClickEvent.BUTTON_LEFT:
// Left button click updates the 'selected' Label
- l.setValue("Selected item: " + event.getItem());
+ getWindow().showNotification("Selected item: " + event.getItem(),
+ modifiers);
break;
case ItemClickEvent.BUTTON_MIDDLE:
// Middle button click removes the item
Object parent = t.getParent(event.getItemId());
- l.setValue("Removed item: " + event.getItem());
+ getWindow().showNotification("Removed item: " + event.getItem(),
+ modifiers);
t.removeItem(event.getItemId());
if (parent != null && t.getChildren(parent).size() == 0) {
t.setChildrenAllowed(parent, false);
@@ -65,7 +82,8 @@ public class TreeMouseEventsExample extends VerticalLayout implements
break;
case ItemClickEvent.BUTTON_RIGHT:
// Right button click creates a new child item
- l.setValue("Added item: New Item # " + itemId);
+ getWindow().showNotification("Added item: New Item # " + itemId,
+ modifiers);
t.setChildrenAllowed(event.getItemId(), true);
Item i = t.addItem(itemId);
t.setChildrenAllowed(itemId, false);
diff --git a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMultiSelect.java b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMultiSelect.java
index 0ee7518fa0..cd85db5644 100644
--- a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMultiSelect.java
+++ b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeMultiSelect.java
@@ -17,8 +17,7 @@ public class TreeMultiSelect extends Feature {
+ " data that has hierarchical relationships, such as"
+ " filesystems or message threads."
+ "<br>In this example, you can select multiple tree nodes"
- + " and delete your selection. You can also click your"
- + " selections again, and have no selections made.";
+ + " and delete your selection. Click a selected item again to de-select it.";
}
@Override
diff --git a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelect.java b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelect.java
index ff5f916f36..09eff2247a 100644
--- a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelect.java
+++ b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelect.java
@@ -17,8 +17,7 @@ public class TreeSingleSelect extends Feature {
+ " data that has hierarchical relationships, such as"
+ " filesystems or message threads."
+ "<br>In this example, you can select any single tree node"
- + " and modify its 'name' property. You can also click your"
- + " selection again, and have no selections made.";
+ + " and modify its 'name' property. Click again to de-select.";
}
@Override
diff --git a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelectExample.java b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelectExample.java
index 021bf12aec..5d1aa6767b 100644
--- a/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelectExample.java
+++ b/src/com/itmill/toolkit/demo/sampler/features/trees/TreeSingleSelectExample.java
@@ -10,72 +10,77 @@ import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.HorizontalLayout;
import com.itmill.toolkit.ui.TextField;
import com.itmill.toolkit.ui.Tree;
-import com.itmill.toolkit.ui.VerticalLayout;
import com.itmill.toolkit.ui.Button.ClickEvent;
-public class TreeSingleSelectExample extends VerticalLayout implements
+public class TreeSingleSelectExample extends HorizontalLayout implements
Property.ValueChangeListener, Button.ClickListener, Action.Handler {
+ // Actions for the context menu
private static final Action ACTION_ADD = new Action("Add child item");
private static final Action ACTION_DELETE = new Action("Delete");
private static final Action[] ACTIONS = new Action[] { ACTION_ADD,
ACTION_DELETE };
- private Tree t;
+ private Tree tree;
+
+ HorizontalLayout editBar;
private TextField editor;
private Button change;
- private int itemId;
public TreeSingleSelectExample() {
setSpacing(true);
- // Create new Tree object using a hierarchical container from
- // ExampleUtil class
- t = new Tree("Hardware Inventory", ExampleUtil.getHardwareContainer());
+ // Create the Tree,a dd to layout
+ tree = new Tree("Hardware Inventory");
+ addComponent(tree);
+
+ // Contents from a (prefilled example) hierarchical container:
+ tree.setContainerDataSource(ExampleUtil.getHardwareContainer());
// Add Valuechangelistener and Actionhandler
- t.addListener(this);
- t.addActionHandler(this);
+ tree.addListener(this);
- t.setImmediate(true);
+ // Add actions (context menu)
+ tree.addActionHandler(this);
- // Set tree to show the 'name' property as caption for items
- t.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
- t.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
+ // Cause valueChange immediately when the user selects
+ tree.setImmediate(true);
- // Starting itemId # for new items
- itemId = t.getContainerDataSource().size();
+ // Set tree to show the 'name' property as caption for items
+ tree.setItemCaptionPropertyId(ExampleUtil.hw_PROPERTY_NAME);
+ tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
// Expand whole tree
- for (int i = 0; i < itemId; i++) {
- t.expandItemsRecursively(i);
+ for (Object id : tree.rootItemIds()) {
+ tree.expandItemsRecursively(id);
}
// Create the 'editor bar' (textfield and button in a horizontallayout)
- editor = new TextField();
+ editBar = new HorizontalLayout();
+ editBar.setMargin(false, false, false, true);
+ editBar.setEnabled(false);
+ addComponent(editBar);
+ // textfield
+ editor = new TextField("Item name");
editor.setImmediate(true);
- change = new Button("Apply", this, "buttonClick");
- change.setEnabled(false);
- HorizontalLayout editBar = new HorizontalLayout();
editBar.addComponent(editor);
+ // apply-button
+ change = new Button("Apply", this, "buttonClick");
editBar.addComponent(change);
-
- addComponent(editBar);
- addComponent(t);
-
+ editBar.setComponentAlignment(change, "bottom");
}
public void valueChange(ValueChangeEvent event) {
if (event.getProperty().getValue() != null) {
// If something is selected from the tree, get it's 'name' and
// insert it into the textfield
- editor.setValue(t.getItem(event.getProperty().getValue())
+ editor.setValue(tree.getItem(event.getProperty().getValue())
.getItemProperty(ExampleUtil.hw_PROPERTY_NAME));
editor.requestRepaint();
- change.setEnabled(true);
+ editBar.setEnabled(true);
} else {
editor.setValue("");
- change.setEnabled(false);
+ editBar.setEnabled(false);
}
}
@@ -83,8 +88,9 @@ public class TreeSingleSelectExample extends VerticalLayout implements
// If the edited value contains something, set it to be the item's new
// 'name' property
if (!editor.getValue().equals("")) {
- t.getItem(t.getValue()).getItemProperty(
- ExampleUtil.hw_PROPERTY_NAME).setValue(editor.getValue());
+ Item item = tree.getItem(tree.getValue());
+ Property name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME);
+ name.setValue(editor.getValue());
}
}
@@ -100,25 +106,27 @@ public class TreeSingleSelectExample extends VerticalLayout implements
*/
public void handleAction(Action action, Object sender, Object target) {
if (action == ACTION_ADD) {
- // Allow children for the target item
- t.setChildrenAllowed(target, true);
-
- // Create new item, disallow children, add name, set parent
- Item i = t.addItem(itemId);
- t.setChildrenAllowed(itemId, false);
- String newItemName = "New Item # " + itemId;
- i.getItemProperty(ExampleUtil.hw_PROPERTY_NAME).setValue(
- newItemName);
- t.setParent(itemId, target);
- t.expandItem(target);
- itemId++;
+ // Allow children for the target item, and expand it
+ tree.setChildrenAllowed(target, true);
+ tree.expandItem(target);
+
+ // Create new item, set parent, disallow children (= leaf node)
+ Object itemId = tree.addItem();
+ tree.setParent(itemId, target);
+ tree.setChildrenAllowed(itemId, false);
+
+ // Set the name for this item (we use it as item caption)
+ Item item = tree.getItem(itemId);
+ Property name = item.getItemProperty(ExampleUtil.hw_PROPERTY_NAME);
+ name.setValue("New Item");
+
} else if (action == ACTION_DELETE) {
- Object parent = t.getParent(target);
- t.removeItem(target);
+ Object parent = tree.getParent(target);
+ tree.removeItem(target);
// If the deleted object's parent has no more children, set it's
- // childrenallowed property to false
- if (parent != null && t.getChildren(parent).size() == 0) {
- t.setChildrenAllowed(parent, false);
+ // childrenallowed property to false (= leaf node)
+ if (parent != null && tree.getChildren(parent).size() == 0) {
+ tree.setChildrenAllowed(parent, false);
}
}
}