aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2009-01-14 09:39:22 +0000
committerMarc Englund <marc.englund@itmill.com>2009-01-14 09:39:22 +0000
commitd535ab7fcc49cad47e158d72d88455173be29b71 (patch)
tree5ad91b09fe95b04a279719dabaa9fc0091cfe979
parent179b9072aacd61b2345fe1ffdc6c95e2c8cc4c31 (diff)
downloadvaadin-framework-d535ab7fcc49cad47e158d72d88455173be29b71.tar.gz
vaadin-framework-d535ab7fcc49cad47e158d72d88455173be29b71.zip
Table section started in Sampler, not done yet.
svn changeset:6528/svn branch:trunk
-rw-r--r--WebContent/ITMILL/themes/sampler/icons/icon_get_world.gifbin0 -> 189 bytes
-rw-r--r--WebContent/ITMILL/themes/sampler/styles.css2
-rw-r--r--WebContent/ITMILL/themes/sampler/table/styles.css4
-rw-r--r--src/com/itmill/toolkit/demo/sampler/ExampleUtil.java4
-rw-r--r--src/com/itmill/toolkit/demo/sampler/FeatureSet.java11
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/table/TableColumnReordering.java38
-rw-r--r--src/com/itmill/toolkit/demo/sampler/features/table/TableMainFeaturesExample.java119
7 files changed, 178 insertions, 0 deletions
diff --git a/WebContent/ITMILL/themes/sampler/icons/icon_get_world.gif b/WebContent/ITMILL/themes/sampler/icons/icon_get_world.gif
new file mode 100644
index 0000000000..f99a5383b2
--- /dev/null
+++ b/WebContent/ITMILL/themes/sampler/icons/icon_get_world.gif
Binary files differ
diff --git a/WebContent/ITMILL/themes/sampler/styles.css b/WebContent/ITMILL/themes/sampler/styles.css
index cd8b0f5c69..f49de71bda 100644
--- a/WebContent/ITMILL/themes/sampler/styles.css
+++ b/WebContent/ITMILL/themes/sampler/styles.css
@@ -7,3 +7,5 @@
@import url(prominentprimaryaction/styles.css);
@import url(layouts/styles.css);
+
+@import url(table/styles.css);
diff --git a/WebContent/ITMILL/themes/sampler/table/styles.css b/WebContent/ITMILL/themes/sampler/table/styles.css
new file mode 100644
index 0000000000..645d2405fc
--- /dev/null
+++ b/WebContent/ITMILL/themes/sampler/table/styles.css
@@ -0,0 +1,4 @@
+.i-table-iso3166 .i-table-row-marked {
+ color: red;
+ font-style: italic;
+} \ No newline at end of file
diff --git a/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java b/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java
index dc5ee0091c..5dfcdc20d4 100644
--- a/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java
+++ b/src/com/itmill/toolkit/demo/sampler/ExampleUtil.java
@@ -94,11 +94,14 @@ public final class ExampleUtil {
"VI", "WALLIS AND FUTUNA", "WF", "WESTERN SAHARA", "EH", "YEMEN",
"YE", "ZAMBIA", "ZM", "ZIMBABWE", "ZW" };
public static final Object iso3166_PROPERTY_NAME = "name";
+ public static final Object iso3166_PROPERTY_SHORT = "short";
public static final Object iso3166_PROPERTY_FLAG = "flag";
private static final IndexedContainer iso3166Container = new IndexedContainer();
static {
iso3166Container.addContainerProperty(iso3166_PROPERTY_NAME,
String.class, null);
+ iso3166Container.addContainerProperty(iso3166_PROPERTY_SHORT,
+ String.class, null);
iso3166Container.addContainerProperty(iso3166_PROPERTY_FLAG,
Resource.class, null);
for (int i = 0; i < iso3166.length; i++) {
@@ -106,6 +109,7 @@ public final class ExampleUtil {
String id = iso3166[i];
Item item = iso3166Container.addItem(id);
item.getItemProperty(iso3166_PROPERTY_NAME).setValue(name);
+ item.getItemProperty(iso3166_PROPERTY_SHORT).setValue(id);
item.getItemProperty(iso3166_PROPERTY_FLAG).setValue(
new ThemeResource("flags/" + id.toLowerCase() + ".gif"));
}
diff --git a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java
index 97d6137942..b7a4699789 100644
--- a/src/com/itmill/toolkit/demo/sampler/FeatureSet.java
+++ b/src/com/itmill/toolkit/demo/sampler/FeatureSet.java
@@ -39,6 +39,7 @@ import com.itmill.toolkit.demo.sampler.features.selects.ListSelectMultiple;
import com.itmill.toolkit.demo.sampler.features.selects.ListSelectSingle;
import com.itmill.toolkit.demo.sampler.features.selects.NativeSelection;
import com.itmill.toolkit.demo.sampler.features.selects.TwinColumnSelect;
+import com.itmill.toolkit.demo.sampler.features.table.TableColumnReordering;
import com.itmill.toolkit.demo.sampler.features.tabsheets.TabSheetDisabled;
import com.itmill.toolkit.demo.sampler.features.tabsheets.TabSheetIcons;
import com.itmill.toolkit.demo.sampler.features.tabsheets.TabSheetScrolling;
@@ -103,6 +104,7 @@ public class FeatureSet extends Feature {
new Panels(), //
// new Forms(), not done yet
new Windows(), //
+ new Tables(),//
new Texts(), //
});
}
@@ -244,6 +246,15 @@ public class FeatureSet extends Feature {
}
}
+ public static class Tables extends FeatureSet {
+ public Tables() {
+ super("Table (Grid)", new Feature[] {
+ //
+ new TableColumnReordering(), //
+ });
+ }
+ }
+
public static class Texts extends FeatureSet {
public Texts() {
super("Texts", new Feature[] {
diff --git a/src/com/itmill/toolkit/demo/sampler/features/table/TableColumnReordering.java b/src/com/itmill/toolkit/demo/sampler/features/table/TableColumnReordering.java
new file mode 100644
index 0000000000..38701a0845
--- /dev/null
+++ b/src/com/itmill/toolkit/demo/sampler/features/table/TableColumnReordering.java
@@ -0,0 +1,38 @@
+package com.itmill.toolkit.demo.sampler.features.table;
+
+import com.itmill.toolkit.demo.sampler.APIResource;
+import com.itmill.toolkit.demo.sampler.Feature;
+import com.itmill.toolkit.demo.sampler.NamedExternalResource;
+import com.itmill.toolkit.ui.Component;
+
+public class TableColumnReordering extends Feature {
+
+ @Override
+ public Component getExample() {
+ return new TableMainFeaturesExample();
+ }
+
+ @Override
+ public String getDescription() {
+ return "The column headers can be reordered by the user using drag and drop. This feature can be turned on or off.";
+ }
+
+ @Override
+ public APIResource[] getRelatedAPI() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class[] getRelatedFeatures() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public NamedExternalResource[] getRelatedResources() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/com/itmill/toolkit/demo/sampler/features/table/TableMainFeaturesExample.java b/src/com/itmill/toolkit/demo/sampler/features/table/TableMainFeaturesExample.java
new file mode 100644
index 0000000000..49e5c10022
--- /dev/null
+++ b/src/com/itmill/toolkit/demo/sampler/features/table/TableMainFeaturesExample.java
@@ -0,0 +1,119 @@
+package com.itmill.toolkit.demo.sampler.features.table;
+
+import java.util.HashSet;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.demo.sampler.ExampleUtil;
+import com.itmill.toolkit.event.Action;
+import com.itmill.toolkit.terminal.ThemeResource;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Table;
+import com.itmill.toolkit.ui.VerticalLayout;
+import com.itmill.toolkit.ui.Table.CellStyleGenerator;
+
+public class TableMainFeaturesExample extends VerticalLayout {
+
+ Table table = new Table("ISO-3166 Country Codes and flags");
+
+ HashSet<Object> markedRows = new HashSet<Object>();
+
+ static final Action ACTION_MARK = new Action("Mark");
+ static final Action ACTION_UNMARK = new Action("Unmark");
+ static final Action ACTION_LOG = new Action("Log");
+ static final Action[] ACTIONS_UNMARKED = new Action[] { ACTION_MARK,
+ ACTION_LOG };
+ static final Action[] ACTIONS_MARKED = new Action[] { ACTION_UNMARK,
+ ACTION_LOG };
+
+ public TableMainFeaturesExample() {
+ addComponent(table);
+
+ // set a style name, so we can style rows and cells
+ table.setStyleName("iso3166");
+
+ // size
+ table.setWidth("100%");
+ table.setPageLength(7);
+
+ // multiselect mode
+ table.setMultiSelect(true);
+
+ // connect data source
+ table.setContainerDataSource(ExampleUtil.getISO3166Container());
+
+ // turn on column reordering and collapsing
+ table.setColumnReorderingAllowed(true);
+ table.setColumnCollapsingAllowed(true);
+
+ // set column headers
+ table.setColumnHeaders(new String[] { "Country", "Code", "Icon file" });
+
+ // Icons for column headers
+ table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_FLAG,
+ new ThemeResource("icons/action_save.gif"));
+ table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_NAME,
+ new ThemeResource("icons/icon_get_world.gif"));
+ table.setColumnIcon(ExampleUtil.iso3166_PROPERTY_SHORT,
+ new ThemeResource("icons/page_code.gif"));
+
+ // Collapse one column - the user can make it visible again
+ try {
+ table.setColumnCollapsed(ExampleUtil.iso3166_PROPERTY_FLAG, true);
+ } catch (IllegalAccessException e) {
+ // Not critical, but strange
+ System.err.println(e);
+ }
+
+ // show row header w/ icon
+ table.setRowHeaderMode(Table.ROW_HEADER_MODE_ICON_ONLY);
+ table.setItemIconPropertyId(ExampleUtil.iso3166_PROPERTY_FLAG);
+
+ // Actions (a.k.a context menu)
+ table.addActionHandler(new Action.Handler() {
+ public Action[] getActions(Object target, Object sender) {
+ if (markedRows.contains(target)) {
+ return ACTIONS_MARKED;
+ } else {
+ return ACTIONS_UNMARKED;
+ }
+ }
+
+ public void handleAction(Action action, Object sender, Object target) {
+ if (ACTION_MARK.equals(action)) {
+ markedRows.add(target);
+ table.requestRepaint();
+ } else if (ACTION_UNMARK.equals(action)) {
+ markedRows.remove(target);
+ table.requestRepaint();
+ } else if (ACTION_LOG.equals(action)) {
+ Item item = table.getItem(target);
+ addComponent(new Label(target
+ + ", "
+ + item.getItemProperty(
+ ExampleUtil.iso3166_PROPERTY_NAME)
+ .getValue()));
+ }
+
+ }
+
+ });
+
+ // style generator
+ table.setCellStyleGenerator(new CellStyleGenerator() {
+ public String getStyle(Object itemId, Object propertyId) {
+ if (propertyId == null) {
+ // no propertyId, styling row
+ return (markedRows.contains(itemId) ? "marked" : null);
+ } else if (ExampleUtil.iso3166_PROPERTY_NAME.equals(propertyId)) {
+ return "bold";
+ } else {
+ // no style
+ return null;
+ }
+
+ }
+
+ });
+
+ }
+}