001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.examples.features;
039:
040: import org.millstone.base.ui.*;
041: import org.millstone.base.event.Action;
042:
043: public class FeatureTable extends Feature implements Action.Handler {
044:
045: private static final String[] firstnames = new String[] { "John",
046: "Mary", "Joe", "Sarah", "Jeff", "Jane", "Peter", "Marc",
047: "Josie", "Linus" };
048: private static final String[] lastnames = new String[] {
049: "Torvalds", "Smith", "Jones", "Beck", "Sheridan", "Picard",
050: "Hill", "Fielding", "Einstein" };
051: private static final String[] eyecolors = new String[] { "Blue",
052: "Green", "Brown" };
053: private static final String[] haircolors = new String[] { "Brown",
054: "Black", "Red", "Blonde" };
055:
056: private Table t;
057: private boolean actionsActive = false;
058: private Button actionHandlerSwitch = new Button("Activate actions",
059: this , "toggleActions");
060:
061: public void toggleActions() {
062: if (actionsActive) {
063: t.removeActionHandler(this );
064: actionsActive = false;
065: actionHandlerSwitch.setCaption("Activate Actions");
066: } else {
067: t.addActionHandler(this );
068: actionsActive = true;
069: actionHandlerSwitch.setCaption("Deactivate Actions");
070: }
071: }
072:
073: protected Component getDemoComponent() {
074:
075: OrderedLayout l = new OrderedLayout();
076:
077: // Sample table
078: t = new Table("Most Wanted Persons List");
079: t.setPageLength(10);
080: l.addComponent(t);
081:
082: // Add columns to table
083: t.addContainerProperty("Firstname", String.class, "");
084: t.addContainerProperty("Lastname", String.class, "");
085: t.addContainerProperty("Age", String.class, "");
086: t.addContainerProperty("Eyecolor", String.class, "");
087: t.addContainerProperty("Haircolor", String.class, "");
088:
089: // Add random rows to table
090: for (int j = 0; j < 50; j++) {
091: Object id = t
092: .addItem(
093: new Object[] {
094: firstnames[(int) (Math.random() * (firstnames.length - 1))],
095: lastnames[(int) (Math.random() * (lastnames.length - 1))],
096: new Integer(
097: (int) (Math.random() * 80)),
098: eyecolors[(int) (Math.random() * 3)],
099: haircolors[(int) (Math.random() * 4)] },
100: new Integer(j));
101: t.setItemIcon(id, getSampleIcon());
102: }
103:
104: // Actions
105: l.addComponent(this .actionHandlerSwitch);
106:
107: // Properties
108: PropertyPanel p = new PropertyPanel(t);
109: Form ap = p.createBeanPropertySet(new String[] { "pageLength",
110: "rowHeaderMode", "selectable", "columnHeaderMode",
111: "columnCollapsingAllowed", "columnReorderingAllowed" });
112: ap.replaceWithSelect("columnHeaderMode", new Object[] {
113: new Integer(Table.COLUMN_HEADER_MODE_EXPLICIT),
114: new Integer(
115: Table.COLUMN_HEADER_MODE_EXPLICIT_DEFAULTS_ID),
116: new Integer(Table.COLUMN_HEADER_MODE_HIDDEN),
117: new Integer(Table.COLUMN_HEADER_MODE_ID) },
118: new Object[] { "Explicit", "Explicit defaults ID",
119: "Hidden", "ID" });
120: ap
121: .replaceWithSelect(
122: "rowHeaderMode",
123: new Object[] {
124: new Integer(
125: Table.ROW_HEADER_MODE_EXPLICIT),
126: new Integer(
127: Table.ROW_HEADER_MODE_EXPLICIT_DEFAULTS_ID),
128: new Integer(
129: Table.ROW_HEADER_MODE_HIDDEN),
130: new Integer(
131: Table.ROW_HEADER_MODE_ICON_ONLY),
132: new Integer(Table.ROW_HEADER_MODE_ID),
133: new Integer(Table.ROW_HEADER_MODE_INDEX),
134: new Integer(Table.ROW_HEADER_MODE_ITEM),
135: new Integer(
136: Table.ROW_HEADER_MODE_PROPERTY) },
137: new Object[] { "Explicit",
138: "Explicit defaults ID", "Hidden",
139: "Icon only", "ID", "Index", "Item",
140: "Property" });
141: Select themes = (Select) p.getField("style");
142: themes.addItem("list").getItemProperty(
143: themes.getItemCaptionPropertyId()).setValue("list");
144: p.addProperties("Table Properties", ap);
145: l.addComponent(p);
146:
147: return l;
148: }
149:
150: protected String getExampleSrc() {
151: return "// Sample table\n"
152: + "t = new Table(\"Most Wanted Persons List\");\n"
153: + "t.setPageLength(10);\n\n"
154: + "// Add columns to table\n"
155: + "t.addContainerProperty(\"Firstname\", String.class, \"\");\n"
156: + "t.addContainerProperty(\"Lastname\", String.class, \"\");\n"
157: + "t.addContainerProperty(\"Age\", String.class, \"\");\n"
158: + "t.addContainerProperty(\"Eyecolor\", String.class, \"\");\n"
159: + "t.addContainerProperty(\"Haircolor\", String.class, \"\");\n\n"
160: + "// Add random rows to table\n"
161: + "for (int j = 0; j < 50; j++) {\n" + " t.addItem(\n"
162: + " new Object[] {\n"
163: + " firstnames[(int) (Math.random() * 9)],\n"
164: + " lastnames[(int) (Math.random() * 9)],\n"
165: + " new Integer((int) (Math.random() * 80)),\n"
166: + " eyecolors[(int) (Math.random() * 3)],\n"
167: + " haircolors[(int) (Math.random() * 4)] },\n"
168: + " new Integer(j));\n" + "}\n";
169: }
170:
171: protected String getDescriptionXHTML() {
172:
173: return "<p>The Table component is designed for displaying large volumes of tabular data, "
174: + "in multiple pages whenever needed.</p> "
175: + "<p>Selection of the displayed data is supported both in selecting exclusively one row "
176: + "or multiple rows at the same time. For each row, there may be a set of actions associated, "
177: + "depending on the theme these actions may be displayed either as a drop-down "
178: + "menu for each row or a set of command buttons.</p><p>"
179: + "Table may be connected to any datasource implementing the <code>Container</code> interface."
180: + "This way data found in external datasources can be directly presented in the table component."
181: + "</p><p>"
182: + "Table implements a number of features and you can test most of them in the table demo tab.</p>";
183: }
184:
185: protected String getImage() {
186: return "table.jpg";
187: }
188:
189: protected String getTitle() {
190: return "Table";
191: }
192:
193: private Action ACTION1 = new Action("Action 1");
194: private Action ACTION2 = new Action("Action 2");
195: private Action ACTION3 = new Action("Action 3");
196:
197: private Action[] actions = new Action[] { ACTION1, ACTION2, ACTION3 };
198:
199: public Action[] getActions(Object target, Object sender) {
200: return actions;
201: }
202:
203: public void handleAction(Action action, Object sender, Object target) {
204: t.setDescription("Last action clicked was '"
205: + action.getCaption() + "' on item '"
206: + t.getItem(target).toString() + "'");
207: }
208:
209: }
|