summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/demo/reservation/ResourceSelectorPanel.java
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2009-05-11 09:19:03 +0000
committerHenri Sara <henri.sara@itmill.com>2009-05-11 09:19:03 +0000
commitadc8c0ad3573272c236040c3a76005b9e73a5737 (patch)
treea3860704dbd5b82dc6af38684b80f8ef79a32722 /src/com/vaadin/demo/reservation/ResourceSelectorPanel.java
parent5abc870dda584d0c2fc47fd5eec4ae3de3fa240e (diff)
downloadvaadin-framework-adc8c0ad3573272c236040c3a76005b9e73a5737.tar.gz
vaadin-framework-adc8c0ad3573272c236040c3a76005b9e73a5737.zip
#2904: initial bulk rename "com.itmill.toolkit" -> "com.vaadin"
- com.itmill.toolkit.external not yet fully renamed svn changeset:7715/svn branch:6.0
Diffstat (limited to 'src/com/vaadin/demo/reservation/ResourceSelectorPanel.java')
-rw-r--r--src/com/vaadin/demo/reservation/ResourceSelectorPanel.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/com/vaadin/demo/reservation/ResourceSelectorPanel.java b/src/com/vaadin/demo/reservation/ResourceSelectorPanel.java
new file mode 100644
index 0000000000..d52f1ac84a
--- /dev/null
+++ b/src/com/vaadin/demo/reservation/ResourceSelectorPanel.java
@@ -0,0 +1,140 @@
+/*
+@ITMillApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.demo.reservation;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import com.vaadin.data.Container;
+import com.vaadin.data.Item;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.OrderedLayout;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class ResourceSelectorPanel extends Panel implements
+ Button.ClickListener {
+ private final HashMap categoryLayouts = new HashMap();
+ private final HashMap categoryResources = new HashMap();
+
+ // private Container allResources;
+ private LinkedList selectedResources = null;
+
+ public ResourceSelectorPanel(String caption) {
+ super(caption, new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL));
+ addStyleName(Panel.STYLE_LIGHT);
+ setSizeUndefined();
+ setWidth("100%");
+ }
+
+ public void setResourceContainer(Container resources) {
+ removeAllComponents();
+ categoryLayouts.clear();
+ categoryResources.clear();
+ if (resources != null && resources.size() > 0) {
+ for (final Iterator it = resources.getItemIds().iterator(); it
+ .hasNext();) {
+ final Item resource = resources.getItem(it.next());
+ // final Integer id = (Integer) resource.getItemProperty(
+ // SampleDB.Resource.PROPERTY_ID_ID).getValue();
+ final String category = (String) resource.getItemProperty(
+ SampleDB.Resource.PROPERTY_ID_CATEGORY).getValue();
+ final String name = (String) resource.getItemProperty(
+ SampleDB.Resource.PROPERTY_ID_NAME).getValue();
+ final String description = (String) resource.getItemProperty(
+ SampleDB.Resource.PROPERTY_ID_DESCRIPTION).getValue();
+ final Button rButton = new Button(name, this);
+ rButton.setStyleName("link");
+ rButton.setDescription(description);
+ rButton.setData(resource);
+ Layout resourceLayout = (Layout) categoryLayouts.get(category);
+ LinkedList resourceList = (LinkedList) categoryResources
+ .get(category);
+ if (resourceLayout == null) {
+ resourceLayout = new OrderedLayout();
+ resourceLayout.setSizeUndefined();
+ resourceLayout.setMargin(true);
+ addComponent(resourceLayout);
+ categoryLayouts.put(category, resourceLayout);
+ resourceList = new LinkedList();
+ categoryResources.put(category, resourceList);
+ final Button cButton = new Button(category + " (any)", this);
+ cButton.setStyleName("important-link");
+ cButton.setData(category);
+ resourceLayout.addComponent(cButton);
+ }
+ resourceLayout.addComponent(rButton);
+ resourceList.add(resource);
+ }
+ }
+ }
+
+ // Selects one initial categore, inpractice randomly
+ public void selectFirstCategory() {
+ try {
+ final Object catId = categoryResources.keySet().iterator().next();
+ final LinkedList res = (LinkedList) categoryResources.get(catId);
+ final Layout l = (Layout) categoryLayouts.get(catId);
+ final Button catB = (Button) l.getComponentIterator().next();
+ setSelectedResources(res);
+ catB.setStyleName("selected-link");
+ } catch (final Exception e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ private void setSelectedResources(LinkedList resources) {
+ selectedResources = resources;
+ fireEvent(new SelectedResourcesChangedEvent());
+ }
+
+ public LinkedList getSelectedResources() {
+ return selectedResources;
+ }
+
+ public void buttonClick(ClickEvent event) {
+ final Object source = event.getSource();
+ if (source instanceof Button) {
+ final Object data = ((Button) source).getData();
+ resetStyles();
+ if (data instanceof Item) {
+ final LinkedList rlist = new LinkedList();
+ rlist.add(data);
+ setSelectedResources(rlist);
+ } else {
+ final String category = (String) data;
+ final LinkedList resources = (LinkedList) categoryResources
+ .get(category);
+ setSelectedResources(resources);
+ }
+ ((Button) source).setStyleName("selected-link");
+ }
+
+ }
+
+ private void resetStyles() {
+ for (final Iterator it = categoryLayouts.values().iterator(); it
+ .hasNext();) {
+ final Layout lo = (Layout) it.next();
+ for (final Iterator bit = lo.getComponentIterator(); bit.hasNext();) {
+ final Button b = (Button) bit.next();
+ if (b.getData() instanceof Item) {
+ b.setStyleName("link");
+ } else {
+ b.setStyleName("important-link");
+ }
+ }
+ }
+
+ }
+
+ public class SelectedResourcesChangedEvent extends Event {
+ public SelectedResourcesChangedEvent() {
+ super(ResourceSelectorPanel.this);
+ }
+ }
+}