You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FeatureSet.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. package com.vaadin.demo.sampler;
  2. import java.util.Collections;
  3. import java.util.LinkedList;
  4. import com.vaadin.data.Item;
  5. import com.vaadin.data.Property;
  6. import com.vaadin.data.util.HierarchicalContainer;
  7. import com.vaadin.demo.sampler.features.accordions.AccordionDisabled;
  8. import com.vaadin.demo.sampler.features.accordions.AccordionIcons;
  9. import com.vaadin.demo.sampler.features.blueprints.ProminentPrimaryAction;
  10. import com.vaadin.demo.sampler.features.buttons.ButtonLink;
  11. import com.vaadin.demo.sampler.features.buttons.ButtonPush;
  12. import com.vaadin.demo.sampler.features.buttons.ButtonSwitch;
  13. import com.vaadin.demo.sampler.features.commons.Errors;
  14. import com.vaadin.demo.sampler.features.commons.Icons;
  15. import com.vaadin.demo.sampler.features.commons.Tooltips;
  16. import com.vaadin.demo.sampler.features.commons.Validation;
  17. import com.vaadin.demo.sampler.features.dates.DateInline;
  18. import com.vaadin.demo.sampler.features.dates.DateLocale;
  19. import com.vaadin.demo.sampler.features.dates.DatePopup;
  20. import com.vaadin.demo.sampler.features.dates.DateResolution;
  21. import com.vaadin.demo.sampler.features.form.FormBasic;
  22. import com.vaadin.demo.sampler.features.layouts.ApplicationLayout;
  23. import com.vaadin.demo.sampler.features.layouts.CustomLayouts;
  24. import com.vaadin.demo.sampler.features.layouts.ExpandingComponent;
  25. import com.vaadin.demo.sampler.features.layouts.GridLayoutBasic;
  26. import com.vaadin.demo.sampler.features.layouts.HorizontalLayoutBasic;
  27. import com.vaadin.demo.sampler.features.layouts.LayoutAlignment;
  28. import com.vaadin.demo.sampler.features.layouts.LayoutMargin;
  29. import com.vaadin.demo.sampler.features.layouts.LayoutSpacing;
  30. import com.vaadin.demo.sampler.features.layouts.SplitPanelBasic;
  31. import com.vaadin.demo.sampler.features.layouts.VerticalLayoutBasic;
  32. import com.vaadin.demo.sampler.features.layouts.WebLayout;
  33. import com.vaadin.demo.sampler.features.link.LinkCurrentWindow;
  34. import com.vaadin.demo.sampler.features.link.LinkNoDecorations;
  35. import com.vaadin.demo.sampler.features.link.LinkSizedWindow;
  36. import com.vaadin.demo.sampler.features.notifications.NotificationCustom;
  37. import com.vaadin.demo.sampler.features.notifications.NotificationError;
  38. import com.vaadin.demo.sampler.features.notifications.NotificationHumanized;
  39. import com.vaadin.demo.sampler.features.notifications.NotificationTray;
  40. import com.vaadin.demo.sampler.features.notifications.NotificationWarning;
  41. import com.vaadin.demo.sampler.features.panels.PanelBasic;
  42. import com.vaadin.demo.sampler.features.panels.PanelLight;
  43. import com.vaadin.demo.sampler.features.selects.ComboBoxContains;
  44. import com.vaadin.demo.sampler.features.selects.ComboBoxInputPrompt;
  45. import com.vaadin.demo.sampler.features.selects.ComboBoxNewItems;
  46. import com.vaadin.demo.sampler.features.selects.ComboBoxPlain;
  47. import com.vaadin.demo.sampler.features.selects.ComboBoxStartsWith;
  48. import com.vaadin.demo.sampler.features.selects.ListSelectMultiple;
  49. import com.vaadin.demo.sampler.features.selects.ListSelectSingle;
  50. import com.vaadin.demo.sampler.features.selects.NativeSelection;
  51. import com.vaadin.demo.sampler.features.selects.TwinColumnSelect;
  52. import com.vaadin.demo.sampler.features.table.TableActions;
  53. import com.vaadin.demo.sampler.features.table.TableCellStyling;
  54. import com.vaadin.demo.sampler.features.table.TableColumnAlignment;
  55. import com.vaadin.demo.sampler.features.table.TableColumnCollapsing;
  56. import com.vaadin.demo.sampler.features.table.TableColumnHeaders;
  57. import com.vaadin.demo.sampler.features.table.TableColumnReordering;
  58. import com.vaadin.demo.sampler.features.table.TableHeaderIcons;
  59. import com.vaadin.demo.sampler.features.table.TableLazyLoading;
  60. import com.vaadin.demo.sampler.features.table.TableMouseEvents;
  61. import com.vaadin.demo.sampler.features.table.TableRowHeaders;
  62. import com.vaadin.demo.sampler.features.table.TableRowStyling;
  63. import com.vaadin.demo.sampler.features.table.TableSorting;
  64. import com.vaadin.demo.sampler.features.tabsheets.TabSheetDisabled;
  65. import com.vaadin.demo.sampler.features.tabsheets.TabSheetIcons;
  66. import com.vaadin.demo.sampler.features.tabsheets.TabSheetScrolling;
  67. import com.vaadin.demo.sampler.features.text.LabelPlain;
  68. import com.vaadin.demo.sampler.features.text.LabelPreformatted;
  69. import com.vaadin.demo.sampler.features.text.LabelRich;
  70. import com.vaadin.demo.sampler.features.text.RichTextEditor;
  71. import com.vaadin.demo.sampler.features.text.TextArea;
  72. import com.vaadin.demo.sampler.features.text.TextFieldInputPrompt;
  73. import com.vaadin.demo.sampler.features.text.TextFieldSecret;
  74. import com.vaadin.demo.sampler.features.text.TextFieldSingle;
  75. import com.vaadin.demo.sampler.features.trees.TreeActions;
  76. import com.vaadin.demo.sampler.features.trees.TreeMouseEvents;
  77. import com.vaadin.demo.sampler.features.trees.TreeMultiSelect;
  78. import com.vaadin.demo.sampler.features.trees.TreeSingleSelect;
  79. import com.vaadin.demo.sampler.features.windows.NativeWindow;
  80. import com.vaadin.demo.sampler.features.windows.Subwindow;
  81. import com.vaadin.demo.sampler.features.windows.SubwindowAutoSized;
  82. import com.vaadin.demo.sampler.features.windows.SubwindowClose;
  83. import com.vaadin.demo.sampler.features.windows.SubwindowModal;
  84. import com.vaadin.demo.sampler.features.windows.SubwindowPositioned;
  85. import com.vaadin.demo.sampler.features.windows.SubwindowSized;
  86. /**
  87. * Contains the FeatureSet implementation and the structure for the feature
  88. * 'tree'.
  89. * <p>
  90. * Each set is implemented as it's own class to facilitate linking to sets in
  91. * the same way as linking to individual features.
  92. * </p>
  93. *
  94. */
  95. public class FeatureSet extends Feature {
  96. /*
  97. * MAIN structure; root is always a FeatureSet that is not shown
  98. */
  99. static final FeatureSet FEATURES = new FeatureSet("All", new Feature[] {
  100. // Main sets
  101. // new Blueprints(), disabled for now, until more samples are ready
  102. new Components(), //
  103. });
  104. /*
  105. * TOP LEVEL
  106. */
  107. public static class Blueprints extends FeatureSet {
  108. public Blueprints() {
  109. super("Blueprints", new Feature[] {
  110. // Blueprints
  111. new ProminentPrimaryAction(), //
  112. });
  113. }
  114. }
  115. public static class Components extends FeatureSet {
  116. public Components() {
  117. super("Components", new Feature[] {
  118. //
  119. new Common(), //
  120. new Accordions(), //
  121. new Buttons(), //
  122. new Dates(), //
  123. new Forms(), //
  124. new Layouts(), //
  125. new Links(), //
  126. new Notifications(), //
  127. new Panels(), //
  128. new Selects(), //
  129. new Tables(),//
  130. new Tabsheets(), //
  131. new Texts(), //
  132. new TextFields(), //
  133. new Trees(), //
  134. new Windows(), //
  135. });
  136. }
  137. }
  138. /*
  139. * LEVEL 2
  140. */
  141. public static class Buttons extends FeatureSet {
  142. public Buttons() {
  143. super(
  144. "Buttons",
  145. "Buttons",
  146. "A button is one of the fundamental building blocks of any application.",
  147. new Feature[] {
  148. //
  149. new ButtonPush(), // basic
  150. new ButtonLink(), // link
  151. new ButtonSwitch(), // switch/checkbox
  152. });
  153. }
  154. }
  155. public static class Links extends FeatureSet {
  156. public Links() {
  157. super(
  158. "Links",
  159. "Links",
  160. "An external link. This is the basic HTML-style link, changing the url of the browser w/o triggering a server-side event (like the link-styled Button).",
  161. new Feature[] {
  162. //
  163. new LinkCurrentWindow(), // basic
  164. new LinkNoDecorations(), // new win
  165. new LinkSizedWindow(), // new win
  166. });
  167. }
  168. }
  169. public static class Notifications extends FeatureSet {
  170. public Notifications() {
  171. super(
  172. "Notifications",
  173. "Notifications",
  174. "Notifications are lightweight informational messages, used to inform the user of various events.",
  175. new Feature[] {
  176. //
  177. new NotificationHumanized(), // humanized
  178. new NotificationWarning(), // warning
  179. new NotificationTray(), // tray
  180. new NotificationError(), // error
  181. new NotificationCustom(), // error
  182. });
  183. }
  184. }
  185. public static class Common extends FeatureSet {
  186. public Common() {
  187. super("Common", new Feature[] {
  188. //
  189. new Tooltips(), //
  190. new Icons(), //
  191. new Errors(), //
  192. new Validation(), // TODO this should point to Form instead
  193. });
  194. }
  195. }
  196. public static class Selects extends FeatureSet {
  197. public Selects() {
  198. super("Selects", new Feature[] {
  199. //
  200. new ListSelectSingle(), //
  201. new ListSelectMultiple(), //
  202. new TwinColumnSelect(), //
  203. new NativeSelection(), //
  204. new ComboBoxPlain(), //
  205. new ComboBoxInputPrompt(), //
  206. new ComboBoxStartsWith(), //
  207. new ComboBoxContains(), //
  208. new ComboBoxNewItems(), //
  209. });
  210. }
  211. }
  212. public static class Layouts extends FeatureSet {
  213. public Layouts() {
  214. super(
  215. "Layouts",
  216. "Layouts",
  217. "Making a usable, good looking, dynamic layout can be tricky, but with the right tools almost anything is possible.<br/>",
  218. new Feature[] {
  219. //
  220. new LayoutMargin(), //
  221. new LayoutSpacing(), //
  222. new VerticalLayoutBasic(), //
  223. new HorizontalLayoutBasic(), //
  224. new GridLayoutBasic(), //
  225. new LayoutAlignment(), //
  226. new ExpandingComponent(), //
  227. new SplitPanelBasic(), //
  228. new ApplicationLayout(), //
  229. new WebLayout(), //
  230. new CustomLayouts(), //
  231. });
  232. }
  233. }
  234. public static class Tabsheets extends FeatureSet {
  235. public Tabsheets() {
  236. super(
  237. "Tabsheets",
  238. "Tabsheets",
  239. "A Tabsheet organizes multiple components so that only the one component associated with the currently selected 'tab' is shown. Typically a tab will contain a Layout, which in turn may contain many components.",
  240. new Feature[] {
  241. //
  242. new TabSheetIcons(), //
  243. new TabSheetScrolling(), //
  244. new TabSheetDisabled(), //
  245. });
  246. }
  247. }
  248. public static class Accordions extends FeatureSet {
  249. public Accordions() {
  250. super(
  251. "Accordions",
  252. "Accordions",
  253. "An accordion component is a specialized case of a tabsheet."
  254. + " Within an accordion, the tabs are organized vertically,"
  255. + " and the content will be shown directly below the tab.",
  256. new Feature[] {
  257. //
  258. new AccordionIcons(), //
  259. new AccordionDisabled(), //
  260. });
  261. }
  262. }
  263. public static class Panels extends FeatureSet {
  264. public Panels() {
  265. super(
  266. "Panels",
  267. "Panels",
  268. "Panel is a simple container that supports scrolling.<br/>It's internal layout (by default VerticalLayout) can be configured or exchanged to get desired results. Components that are added to the Panel will in effect be added to the layout.",
  269. new Feature[] {
  270. //
  271. new PanelBasic(), //
  272. new PanelLight(), //
  273. });
  274. }
  275. }
  276. public static class Forms extends FeatureSet {
  277. public Forms() {
  278. super("Forms", "Forms",
  279. "The Form -component provides a convenient way to organize"
  280. + " related fields visually.", new Feature[] {
  281. //
  282. new FormBasic(), //
  283. });
  284. }
  285. }
  286. public static class Windows extends FeatureSet {
  287. public Windows() {
  288. super(
  289. "Windows",
  290. "Windows",
  291. "Windows can (for instance) organize the UI, save space (popup windows), focus attention (modal windows), or provide multiple views for the same data for multitasking or dual screen setups (native browser windows).",
  292. new Feature[] {
  293. //
  294. new Subwindow(), //
  295. new SubwindowModal(), //
  296. new SubwindowAutoSized(), //
  297. new SubwindowSized(), //
  298. new SubwindowPositioned(), //
  299. new SubwindowClose(), //
  300. new NativeWindow(), //
  301. });
  302. }
  303. }
  304. public static class Tables extends FeatureSet {
  305. public Tables() {
  306. super(
  307. "Table (Grid)",
  308. "Table (Grid)",
  309. "A Table, also known as a (Data)Grid, can be used to show data in a tabular fashion. It's well suited for showing large datasets.",
  310. new Feature[] {
  311. //
  312. new TableHeaderIcons(), //
  313. new TableColumnHeaders(), //
  314. new TableColumnReordering(), //
  315. new TableColumnCollapsing(), //
  316. new TableColumnAlignment(), //
  317. new TableCellStyling(), //
  318. new TableSorting(), //
  319. new TableRowHeaders(), //
  320. new TableRowStyling(), //
  321. new TableActions(), //
  322. new TableMouseEvents(), //
  323. new TableLazyLoading(), //
  324. });
  325. }
  326. }
  327. public static class Texts extends FeatureSet {
  328. public Texts() {
  329. super(
  330. "Texts",
  331. "Texts",
  332. "A label is a simple component that allows you to add (optionally formatted) text components to your application.",
  333. new Feature[] {
  334. //
  335. new LabelPlain(), //
  336. new LabelPreformatted(), //
  337. new LabelRich(), //
  338. });
  339. }
  340. }
  341. public static class TextFields extends FeatureSet {
  342. public TextFields() {
  343. super(
  344. "TextFields",
  345. "Text inputs",
  346. "Text inputs are probably the most needed components in any application that require user input or editing.",
  347. new Feature[] {
  348. //
  349. new TextFieldSingle(), //
  350. new TextFieldSecret(), //
  351. new TextFieldInputPrompt(), //
  352. new TextArea(), //
  353. new RichTextEditor(), //
  354. });
  355. }
  356. }
  357. public static class Trees extends FeatureSet {
  358. public Trees() {
  359. super(
  360. "Trees",
  361. "Trees",
  362. "The Tree component provides a natural way to represent data that has hierarchical relationships, such as filesystems or message threads.",
  363. new Feature[] {
  364. //
  365. new TreeSingleSelect(), //
  366. new TreeMultiSelect(), //
  367. new TreeActions(), //
  368. new TreeMouseEvents(), //
  369. });
  370. }
  371. }
  372. public static class Dates extends FeatureSet {
  373. public Dates() {
  374. super(
  375. "Dates",
  376. "Dates",
  377. "The DateField component can be used to produce various date and time input fields with different resolutions. The date and time format used with this component is reported to Vaadin by the browser.",
  378. new Feature[] {
  379. //
  380. new DatePopup(), //
  381. new DateInline(), //
  382. new DateLocale(), //
  383. new DateResolution(), //
  384. });
  385. }
  386. }
  387. // ----------------------------------------------------------
  388. /*
  389. * FeatureSet implementation follows.
  390. */
  391. private String pathname;
  392. private String name;
  393. private String desc;
  394. private String icon = "folder.gif";
  395. private Feature[] content;
  396. private HierarchicalContainer container = null;
  397. private boolean containerRecursive = false;
  398. FeatureSet(String pathname, Feature[] content) {
  399. this(pathname, pathname, "", content);
  400. }
  401. FeatureSet(String pathname, String name, Feature[] content) {
  402. this(pathname, name, "", content);
  403. }
  404. FeatureSet(String pathname, String name, String desc, Feature[] content) {
  405. this.pathname = pathname;
  406. this.name = name;
  407. this.desc = desc;
  408. this.content = content;
  409. }
  410. Feature[] getFeatures() {
  411. return content;
  412. }
  413. Feature getFeatureByPath(String path) {
  414. LinkedList<String> parts = new LinkedList<String>();
  415. Collections.addAll(parts, path.split("/"));
  416. FeatureSet f = this;
  417. while (f != null) {
  418. Feature[] fs = f.getFeatures();
  419. f = null; // break while if no new found
  420. String part = parts.remove(0);
  421. for (int i = 0; i < fs.length; i++) {
  422. if (fs[i].getPathName().equalsIgnoreCase(part)) {
  423. if (parts.isEmpty()) {
  424. return fs[i];
  425. } else if (fs[i] instanceof FeatureSet) {
  426. f = (FeatureSet) fs[i];
  427. break;
  428. } else {
  429. return null;
  430. }
  431. }
  432. }
  433. }
  434. return null;
  435. }
  436. HierarchicalContainer getContainer(boolean recurse) {
  437. if (container == null || containerRecursive != recurse) {
  438. container = new HierarchicalContainer();
  439. container.addContainerProperty(PROPERTY_NAME, String.class, "");
  440. container.addContainerProperty(PROPERTY_DESCRIPTION, String.class,
  441. "");
  442. // fill
  443. addFeatures(this, container, recurse);
  444. }
  445. return container;
  446. }
  447. private void addFeatures(FeatureSet f, HierarchicalContainer c,
  448. boolean recurse) {
  449. Feature[] features = f.getFeatures();
  450. for (int i = 0; i < features.length; i++) {
  451. Item item = c.addItem(features[i]);
  452. Property property = item.getItemProperty(PROPERTY_NAME);
  453. property.setValue(features[i].getName());
  454. property = item.getItemProperty(PROPERTY_DESCRIPTION);
  455. property.setValue(features[i].getDescription());
  456. if (recurse) {
  457. c.setParent(features[i], f);
  458. if (features[i] instanceof FeatureSet) {
  459. addFeatures((FeatureSet) features[i], c, recurse);
  460. }
  461. }
  462. if (!(features[i] instanceof FeatureSet)) {
  463. c.setChildrenAllowed(features[i], false);
  464. }
  465. }
  466. }
  467. @Override
  468. public String getDescription() {
  469. return desc;
  470. }
  471. @Override
  472. public String getPathName() {
  473. return pathname;
  474. }
  475. @Override
  476. public String getName() {
  477. return name;
  478. }
  479. @Override
  480. public String getIconName() {
  481. return icon;
  482. }
  483. @Override
  484. public APIResource[] getRelatedAPI() {
  485. return null;
  486. }
  487. @Override
  488. public Class[] getRelatedFeatures() {
  489. return null;
  490. }
  491. @Override
  492. public NamedExternalResource[] getRelatedResources() {
  493. return null;
  494. }
  495. }