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.

CommonParts.java 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.themes.valo;
  17. import com.vaadin.event.ShortcutAction.KeyCode;
  18. import com.vaadin.navigator.View;
  19. import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
  20. import com.vaadin.server.AbstractErrorMessage;
  21. import com.vaadin.server.ErrorMessage.ErrorLevel;
  22. import com.vaadin.server.FontAwesome;
  23. import com.vaadin.server.Page;
  24. import com.vaadin.server.UserError;
  25. import com.vaadin.shared.Position;
  26. import com.vaadin.shared.ui.ContentMode;
  27. import com.vaadin.ui.Alignment;
  28. import com.vaadin.ui.Button;
  29. import com.vaadin.ui.Button.ClickEvent;
  30. import com.vaadin.ui.Button.ClickListener;
  31. import com.vaadin.ui.CheckBox;
  32. import com.vaadin.ui.Component;
  33. import com.vaadin.ui.CssLayout;
  34. import com.vaadin.ui.GridLayout;
  35. import com.vaadin.ui.HorizontalLayout;
  36. import com.vaadin.ui.Label;
  37. import com.vaadin.ui.MenuBar;
  38. import com.vaadin.ui.MenuBar.Command;
  39. import com.vaadin.ui.MenuBar.MenuItem;
  40. import com.vaadin.ui.Notification;
  41. import com.vaadin.ui.Panel;
  42. import com.vaadin.ui.TabSheet;
  43. import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
  44. import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
  45. import com.vaadin.ui.TextArea;
  46. import com.vaadin.ui.TextField;
  47. import com.vaadin.ui.VerticalLayout;
  48. import com.vaadin.ui.Window;
  49. import com.vaadin.ui.Window.CloseEvent;
  50. import com.vaadin.ui.Window.CloseListener;
  51. import com.vaadin.ui.themes.ValoTheme;
  52. public class CommonParts extends VerticalLayout implements View {
  53. public CommonParts() {
  54. setSpacing(false);
  55. Label h1 = new Label("Common UI Elements");
  56. h1.addStyleName(ValoTheme.LABEL_H1);
  57. addComponent(h1);
  58. GridLayout row = new GridLayout(2, 3);
  59. row.setWidth("100%");
  60. row.setSpacing(true);
  61. addComponent(row);
  62. row.addComponent(loadingIndicators());
  63. row.addComponent(notifications(), 1, 0, 1, 2);
  64. row.addComponent(windows());
  65. row.addComponent(tooltips());
  66. }
  67. Panel loadingIndicators() {
  68. Panel p = new Panel("Loading Indicator");
  69. VerticalLayout content = new VerticalLayout();
  70. p.setContent(content);
  71. content.addComponent(new Label(
  72. "You can test the loading indicator by pressing the buttons."));
  73. CssLayout group = new CssLayout();
  74. group.setCaption("Show the loading indicator for…");
  75. group.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
  76. content.addComponent(group);
  77. Button loading = new Button("0.8");
  78. loading.addClickListener(new ClickListener() {
  79. @Override
  80. public void buttonClick(ClickEvent event) {
  81. try {
  82. Thread.sleep(800);
  83. } catch (InterruptedException e) {
  84. }
  85. }
  86. });
  87. group.addComponent(loading);
  88. Button delay = new Button("3");
  89. delay.addClickListener(new ClickListener() {
  90. @Override
  91. public void buttonClick(ClickEvent event) {
  92. try {
  93. Thread.sleep(3000);
  94. } catch (InterruptedException e) {
  95. }
  96. }
  97. });
  98. group.addComponent(delay);
  99. Button wait = new Button("15");
  100. wait.addClickListener(new ClickListener() {
  101. @Override
  102. public void buttonClick(ClickEvent event) {
  103. try {
  104. Thread.sleep(15000);
  105. } catch (InterruptedException e) {
  106. }
  107. }
  108. });
  109. wait.addStyleName("last");
  110. group.addComponent(wait);
  111. Label label = new Label("   seconds", ContentMode.HTML);
  112. label.setSizeUndefined();
  113. group.addComponent(label);
  114. Label spinnerDesc = new Label(
  115. "The theme also provides a mixin that you can use to include a spinner anywhere in your application. Below is a Label with a custom style name, for which the spinner mixin is added.");
  116. spinnerDesc.setWidth("100%");
  117. spinnerDesc.addStyleName(ValoTheme.LABEL_SMALL);
  118. spinnerDesc.setCaption("Spinner");
  119. content.addComponent(spinnerDesc);
  120. if (!ValoThemeUI.isTestMode()) {
  121. Label spinner = new Label();
  122. spinner.addStyleName(ValoTheme.LABEL_SPINNER);
  123. content.addComponent(spinner);
  124. }
  125. return p;
  126. }
  127. Panel notifications() {
  128. Panel p = new Panel("Notifications");
  129. VerticalLayout content = new VerticalLayout() {
  130. Notification notification = new Notification("");
  131. TextField title = new TextField("Title");
  132. TextArea description = new TextArea("Description");
  133. MenuBar style = new MenuBar();
  134. MenuBar type = new MenuBar();
  135. String typeString = "";
  136. String styleString = "";
  137. TextField delay = new TextField();
  138. {
  139. title.setPlaceholder("Title for the notification");
  140. title.addValueChangeListener(event -> {
  141. if (title.getValue() == null
  142. || title.getValue().length() == 0) {
  143. notification.setCaption(null);
  144. } else {
  145. notification.setCaption(title.getValue());
  146. }
  147. });
  148. title.setValue("Notification Title");
  149. title.setWidth("100%");
  150. addComponent(title);
  151. description.setPlaceholder("Description for the notification");
  152. description.addStyleName(ValoTheme.TEXTAREA_SMALL);
  153. description.addValueChangeListener(listener -> {
  154. if (description.getValue() == null
  155. || description.getValue().length() == 0) {
  156. notification.setDescription(null);
  157. } else {
  158. notification.setDescription(description.getValue());
  159. }
  160. });
  161. description.setValue(
  162. "A more informative message about what has happened. Nihil hic munitissimus habendi senatus locus, nihil horum? Inmensae subtilitatis, obscuris et malesuada fames. Hi omnes lingua, institutis, legibus inter se differunt.");
  163. description.setWidth("100%");
  164. addComponent(description);
  165. Command typeCommand = new Command() {
  166. @Override
  167. public void menuSelected(MenuItem selectedItem) {
  168. if (selectedItem.getText().equals("Humanized")) {
  169. typeString = "";
  170. notification.setStyleName(styleString.trim());
  171. } else {
  172. typeString = selectedItem.getText().toLowerCase();
  173. notification.setStyleName(
  174. (typeString + " " + styleString.trim())
  175. .trim());
  176. }
  177. for (MenuItem item : type.getItems()) {
  178. item.setChecked(false);
  179. }
  180. selectedItem.setChecked(true);
  181. }
  182. };
  183. type.setCaption("Type");
  184. MenuItem humanized = type.addItem("Humanized", typeCommand);
  185. humanized.setCheckable(true);
  186. humanized.setChecked(true);
  187. type.addItem("Tray", typeCommand).setCheckable(true);
  188. type.addItem("Warning", typeCommand).setCheckable(true);
  189. type.addItem("Error", typeCommand).setCheckable(true);
  190. type.addItem("System", typeCommand).setCheckable(true);
  191. addComponent(type);
  192. type.addStyleName(ValoTheme.MENUBAR_SMALL);
  193. Command styleCommand = new Command() {
  194. @Override
  195. public void menuSelected(MenuItem selectedItem) {
  196. styleString = "";
  197. for (MenuItem item : style.getItems()) {
  198. if (item.isChecked()) {
  199. styleString += " "
  200. + item.getText().toLowerCase();
  201. }
  202. }
  203. if (styleString.trim().length() > 0) {
  204. notification.setStyleName(
  205. (typeString + " " + styleString.trim())
  206. .trim());
  207. } else if (typeString.length() > 0) {
  208. notification.setStyleName(typeString.trim());
  209. } else {
  210. notification.setStyleName(null);
  211. }
  212. }
  213. };
  214. style.setCaption("Additional style");
  215. style.addItem("Dark", styleCommand).setCheckable(true);
  216. style.addItem("Success", styleCommand).setCheckable(true);
  217. style.addItem("Failure", styleCommand).setCheckable(true);
  218. style.addItem("Bar", styleCommand).setCheckable(true);
  219. style.addItem("Small", styleCommand).setCheckable(true);
  220. style.addItem("Closable", styleCommand).setCheckable(true);
  221. addComponent(style);
  222. style.addStyleName(ValoTheme.MENUBAR_SMALL);
  223. CssLayout group = new CssLayout();
  224. group.setCaption("Fade delay");
  225. group.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
  226. addComponent(group);
  227. delay.setPlaceholder("Infinite");
  228. delay.addStyleName(ValoTheme.TEXTFIELD_ALIGN_RIGHT);
  229. delay.addStyleName(ValoTheme.TEXTFIELD_SMALL);
  230. delay.setWidth("7em");
  231. delay.addValueChangeListener(event -> {
  232. try {
  233. notification.setDelayMsec(
  234. Integer.parseInt(delay.getValue()));
  235. } catch (Exception e) {
  236. notification.setDelayMsec(-1);
  237. delay.setValue("");
  238. }
  239. });
  240. delay.setValue("1000");
  241. group.addComponent(delay);
  242. Button clear = new Button(null, new ClickListener() {
  243. @Override
  244. public void buttonClick(ClickEvent event) {
  245. delay.setValue("");
  246. }
  247. });
  248. clear.setIcon(FontAwesome.TIMES_CIRCLE);
  249. clear.addStyleName("last");
  250. clear.addStyleName(ValoTheme.BUTTON_SMALL);
  251. clear.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
  252. group.addComponent(clear);
  253. group.addComponent(new Label("  msec", ContentMode.HTML));
  254. GridLayout grid = new GridLayout(3, 3);
  255. grid.setCaption("Show in position");
  256. addComponent(grid);
  257. grid.setSpacing(true);
  258. Button pos = new Button("", new ClickListener() {
  259. @Override
  260. public void buttonClick(ClickEvent event) {
  261. notification.setPosition(Position.TOP_LEFT);
  262. notification.show(Page.getCurrent());
  263. }
  264. });
  265. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  266. grid.addComponent(pos);
  267. pos = new Button("", new ClickListener() {
  268. @Override
  269. public void buttonClick(ClickEvent event) {
  270. notification.setPosition(Position.TOP_CENTER);
  271. notification.show(Page.getCurrent());
  272. }
  273. });
  274. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  275. grid.addComponent(pos);
  276. pos = new Button("", new ClickListener() {
  277. @Override
  278. public void buttonClick(ClickEvent event) {
  279. notification.setPosition(Position.TOP_RIGHT);
  280. notification.show(Page.getCurrent());
  281. }
  282. });
  283. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  284. grid.addComponent(pos);
  285. pos = new Button("", new ClickListener() {
  286. @Override
  287. public void buttonClick(ClickEvent event) {
  288. notification.setPosition(Position.MIDDLE_LEFT);
  289. notification.show(Page.getCurrent());
  290. }
  291. });
  292. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  293. grid.addComponent(pos);
  294. pos = new Button("", new ClickListener() {
  295. @Override
  296. public void buttonClick(ClickEvent event) {
  297. notification.setPosition(Position.MIDDLE_CENTER);
  298. notification.show(Page.getCurrent());
  299. }
  300. });
  301. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  302. grid.addComponent(pos);
  303. pos = new Button("", new ClickListener() {
  304. @Override
  305. public void buttonClick(ClickEvent event) {
  306. notification.setPosition(Position.MIDDLE_RIGHT);
  307. notification.show(Page.getCurrent());
  308. }
  309. });
  310. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  311. grid.addComponent(pos);
  312. pos = new Button("", new ClickListener() {
  313. @Override
  314. public void buttonClick(ClickEvent event) {
  315. notification.setPosition(Position.BOTTOM_LEFT);
  316. notification.show(Page.getCurrent());
  317. }
  318. });
  319. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  320. grid.addComponent(pos);
  321. pos = new Button("", new ClickListener() {
  322. @Override
  323. public void buttonClick(ClickEvent event) {
  324. notification.setPosition(Position.BOTTOM_CENTER);
  325. notification.show(Page.getCurrent());
  326. }
  327. });
  328. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  329. grid.addComponent(pos);
  330. pos = new Button("", new ClickListener() {
  331. @Override
  332. public void buttonClick(ClickEvent event) {
  333. notification.setPosition(Position.BOTTOM_RIGHT);
  334. notification.show(Page.getCurrent());
  335. }
  336. });
  337. pos.addStyleName(ValoTheme.BUTTON_SMALL);
  338. grid.addComponent(pos);
  339. }
  340. };
  341. p.setContent(content);
  342. return p;
  343. }
  344. Panel tooltips() {
  345. Panel p = new Panel("Tooltips");
  346. HorizontalLayout content = new HorizontalLayout() {
  347. {
  348. setMargin(true);
  349. addStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING);
  350. addComponent(new Label(
  351. "Try out different tooltips/descriptions by hovering over the labels."));
  352. Label label = new Label("Simple");
  353. label.addStyleName(ValoTheme.LABEL_BOLD);
  354. label.setDescription("Simple tooltip message");
  355. addComponent(label);
  356. label = new Label("Long");
  357. label.addStyleName(ValoTheme.LABEL_BOLD);
  358. label.setDescription(
  359. "Long tooltip message. Inmensae subtilitatis, obscuris et malesuada fames. Salutantibus vitae elit libero, a pharetra augue.");
  360. addComponent(label);
  361. label = new Label("HTML tooltip");
  362. label.addStyleName(ValoTheme.LABEL_BOLD);
  363. label.setDescription(
  364. "<div><h1>Ut enim ad minim veniam, quis nostrud exercitation</h1><p><span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>Donec sed odio operae, eu vulputate felis rhoncus.</span> <span>At nos hinc posthac, sitientis piros Afros.</span> <span>Tu quoque, Brute, fili mi, nihil timor populi, nihil!</span></p><p><span>Gallia est omnis divisa in partes tres, quarum.</span> <span>Praeterea iter est quasdam res quas ex communi.</span> <span>Cum ceteris in veneratione tui montes, nascetur mus.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span> <span>Idque Caesaris facere voluntate liceret: sese habere.</span></p></div>");
  365. addComponent(label);
  366. label = new Label("With an error message");
  367. label.addStyleName(ValoTheme.LABEL_BOLD);
  368. label.setDescription("Simple tooltip message");
  369. label.setComponentError(
  370. new UserError("Something terrible has happened"));
  371. addComponent(label);
  372. label = new Label("With a long error message");
  373. label.addStyleName(ValoTheme.LABEL_BOLD);
  374. label.setDescription("Simple tooltip message");
  375. label.setComponentError(new UserError(
  376. "<h2>Contra legem facit qui id facit quod lex prohibet <span>Tityre, tu patulae recubans sub tegmine fagi dolor.</span> <span>Tityre, tu patulae recubans sub tegmine fagi dolor.</span> <span>Prima luce, cum quibus mons aliud consensu ab eo.</span> <span>Quid securi etiam tamquam eu fugiat nulla pariatur.</span> <span>Fabio vel iudice vincam, sunt in culpa qui officia.</span> <span>Nihil hic munitissimus habendi senatus locus, nihil horum?</span></p><p><span>Plura mihi bona sunt, inclinet, amari petere vellent.</span> <span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Nec dubitamus multa iter quae et nos invenerat.</span> <span>Quisque ut dolor gravida, placerat libero vel, euismod.</span> <span>Quae vero auctorem tractata ab fiducia dicuntur.</span></h2>",
  377. AbstractErrorMessage.ContentMode.HTML,
  378. ErrorLevel.CRITICAL));
  379. addComponent(label);
  380. label = new Label("Error message only");
  381. label.addStyleName(ValoTheme.LABEL_BOLD);
  382. label.setComponentError(
  383. new UserError("Something terrible has happened"));
  384. addComponent(label);
  385. }
  386. };
  387. p.setContent(content);
  388. return p;
  389. }
  390. Panel windows() {
  391. Panel p = new Panel("Dialogs");
  392. VerticalLayout content = new VerticalLayout() {
  393. final Window win = new Window("Window Caption");
  394. String prevHeight = "300px";
  395. boolean footerVisible = true;
  396. boolean autoHeight = false;
  397. boolean tabsVisible = false;
  398. boolean toolbarVisible = false;
  399. boolean footerToolbar = false;
  400. boolean toolbarLayout = false;
  401. String toolbarStyle = null;
  402. VerticalLayout windowContent() {
  403. VerticalLayout root = new VerticalLayout();
  404. if (toolbarVisible) {
  405. MenuBar menuBar = MenuBars.getToolBar();
  406. menuBar.setSizeUndefined();
  407. menuBar.setStyleName(toolbarStyle);
  408. Component toolbar = menuBar;
  409. if (toolbarLayout) {
  410. menuBar.setWidth(null);
  411. HorizontalLayout toolbarLayout = new HorizontalLayout();
  412. toolbarLayout.setWidth("100%");
  413. toolbarLayout.setSpacing(true);
  414. Label label = new Label("Tools");
  415. label.setSizeUndefined();
  416. toolbarLayout.addComponents(label, menuBar);
  417. toolbarLayout.setExpandRatio(menuBar, 1);
  418. toolbarLayout.setComponentAlignment(menuBar,
  419. Alignment.TOP_RIGHT);
  420. toolbar = toolbarLayout;
  421. }
  422. toolbar.addStyleName(ValoTheme.WINDOW_TOP_TOOLBAR);
  423. root.addComponent(toolbar);
  424. }
  425. Component content = null;
  426. if (tabsVisible) {
  427. TabSheet tabs = new TabSheet();
  428. tabs.setSizeFull();
  429. VerticalLayout l = new VerticalLayout();
  430. l.addComponent(new Label(
  431. "<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
  432. ContentMode.HTML));
  433. l.setMargin(true);
  434. tabs.addTab(l, "Selected");
  435. tabs.addTab(new Label("&nbsp;", ContentMode.HTML),
  436. "Another");
  437. tabs.addTab(new Label("&nbsp;", ContentMode.HTML),
  438. "One more");
  439. tabs.addStyleName(ValoTheme.TABSHEET_PADDED_TABBAR);
  440. tabs.addSelectedTabChangeListener(
  441. new SelectedTabChangeListener() {
  442. @Override
  443. public void selectedTabChange(
  444. SelectedTabChangeEvent event) {
  445. try {
  446. Thread.sleep(600);
  447. } catch (InterruptedException e) {
  448. e.printStackTrace();
  449. }
  450. }
  451. });
  452. content = tabs;
  453. } else if (!autoHeight) {
  454. Panel p = new Panel();
  455. p.setSizeFull();
  456. p.addStyleName(ValoTheme.PANEL_BORDERLESS);
  457. if (!toolbarVisible || !toolbarLayout) {
  458. p.addStyleName(ValoTheme.PANEL_SCROLL_INDICATOR);
  459. }
  460. VerticalLayout l = new VerticalLayout();
  461. l.addComponent(new Label(
  462. "<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
  463. ContentMode.HTML));
  464. l.setMargin(true);
  465. p.setContent(l);
  466. content = p;
  467. } else {
  468. content = new Label(
  469. "<h2>Subtitle</h2><p>Normal type for plain text. Etiam at risus et justo dignissim congue. Phasellus laoreet lorem vel dolor tempus vehicula.</p><p>Quisque ut dolor gravida, placerat libero vel, euismod. Etiam habebis sem dicantur magna mollis euismod. Nihil hic munitissimus habendi senatus locus, nihil horum? Curabitur est gravida et libero vitae dictum. Ullamco laboris nisi ut aliquid ex ea commodi consequat. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</p>",
  470. ContentMode.HTML);
  471. root.setMargin(true);
  472. }
  473. root.addComponent(content);
  474. if (footerVisible) {
  475. HorizontalLayout footer = new HorizontalLayout();
  476. footer.setWidth("100%");
  477. footer.setSpacing(true);
  478. footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
  479. Label footerText = new Label("Footer text");
  480. footerText.setSizeUndefined();
  481. Button ok = new Button("OK");
  482. ok.addStyleName(ValoTheme.BUTTON_PRIMARY);
  483. Button cancel = new Button("Cancel");
  484. footer.addComponents(footerText, ok, cancel);
  485. footer.setExpandRatio(footerText, 1);
  486. if (footerToolbar) {
  487. MenuBar menuBar = MenuBars.getToolBar();
  488. menuBar.setStyleName(toolbarStyle);
  489. menuBar.setWidth(null);
  490. footer.removeAllComponents();
  491. footer.addComponent(menuBar);
  492. }
  493. root.addComponent(footer);
  494. }
  495. if (!autoHeight) {
  496. root.setSizeFull();
  497. root.setExpandRatio(content, 1);
  498. }
  499. return root;
  500. }
  501. {
  502. setSpacing(true);
  503. setMargin(true);
  504. win.setWidth("380px");
  505. win.setHeight(prevHeight);
  506. win.setClosable(false);
  507. win.setResizable(false);
  508. win.setContent(windowContent());
  509. win.setCloseShortcut(KeyCode.ESCAPE, null);
  510. Command optionsCommand = new Command() {
  511. @Override
  512. public void menuSelected(MenuItem selectedItem) {
  513. if (selectedItem.getText().equals("Footer")) {
  514. footerVisible = selectedItem.isChecked();
  515. }
  516. if (selectedItem.getText().equals("Auto Height")) {
  517. autoHeight = selectedItem.isChecked();
  518. if (!autoHeight) {
  519. win.setHeight(prevHeight);
  520. } else {
  521. prevHeight = win.getHeight()
  522. + win.getHeightUnits().toString();
  523. win.setHeight(null);
  524. }
  525. }
  526. if (selectedItem.getText().equals("Tabs")) {
  527. tabsVisible = selectedItem.isChecked();
  528. }
  529. if (selectedItem.getText().equals("Top Toolbar")) {
  530. toolbarVisible = selectedItem.isChecked();
  531. }
  532. if (selectedItem.getText().equals("Footer Toolbar")) {
  533. footerToolbar = selectedItem.isChecked();
  534. }
  535. if (selectedItem.getText()
  536. .equals("Top Toolbar layout")) {
  537. toolbarLayout = selectedItem.isChecked();
  538. }
  539. if (selectedItem.getText()
  540. .equals("Borderless Toolbars")) {
  541. toolbarStyle = selectedItem.isChecked()
  542. ? ValoTheme.MENUBAR_BORDERLESS : null;
  543. }
  544. win.setContent(windowContent());
  545. }
  546. };
  547. MenuBar options = new MenuBar();
  548. options.setCaption("Content");
  549. options.addItem("Auto Height", optionsCommand)
  550. .setCheckable(true);
  551. options.addItem("Tabs", optionsCommand).setCheckable(true);
  552. MenuItem option = options.addItem("Footer", optionsCommand);
  553. option.setCheckable(true);
  554. option.setChecked(true);
  555. options.addStyleName(ValoTheme.MENUBAR_SMALL);
  556. addComponent(options);
  557. options = new MenuBar();
  558. options.setCaption("Toolbars");
  559. options.addItem("Footer Toolbar", optionsCommand)
  560. .setCheckable(true);
  561. options.addItem("Top Toolbar", optionsCommand)
  562. .setCheckable(true);
  563. options.addItem("Top Toolbar layout", optionsCommand)
  564. .setCheckable(true);
  565. options.addItem("Borderless Toolbars", optionsCommand)
  566. .setCheckable(true);
  567. options.addStyleName(ValoTheme.MENUBAR_SMALL);
  568. addComponent(options);
  569. Command optionsCommand2 = new Command() {
  570. @Override
  571. public void menuSelected(MenuItem selectedItem) {
  572. if (selectedItem.getText().equals("Caption")) {
  573. win.setCaption(selectedItem.isChecked()
  574. ? "Window Caption" : null);
  575. } else if (selectedItem.getText().equals("Closable")) {
  576. win.setClosable(selectedItem.isChecked());
  577. } else if (selectedItem.getText().equals("Resizable")) {
  578. win.setResizable(selectedItem.isChecked());
  579. } else if (selectedItem.getText().equals("Modal")) {
  580. win.setModal(selectedItem.isChecked());
  581. }
  582. }
  583. };
  584. options = new MenuBar();
  585. options.setCaption("Options");
  586. MenuItem caption = options.addItem("Caption", optionsCommand2);
  587. caption.setCheckable(true);
  588. caption.setChecked(true);
  589. options.addItem("Closable", optionsCommand2).setCheckable(true);
  590. options.addItem("Resizable", optionsCommand2)
  591. .setCheckable(true);
  592. options.addItem("Modal", optionsCommand2).setCheckable(true);
  593. options.addStyleName(ValoTheme.MENUBAR_SMALL);
  594. addComponent(options);
  595. final Button show = new Button("Open Window",
  596. new ClickListener() {
  597. @Override
  598. public void buttonClick(ClickEvent event) {
  599. getUI().addWindow(win);
  600. win.center();
  601. win.focus();
  602. event.getButton().setEnabled(false);
  603. }
  604. });
  605. show.addStyleName(ValoTheme.BUTTON_PRIMARY);
  606. addComponent(show);
  607. final CheckBox hidden = new CheckBox("Hidden");
  608. hidden.addValueChangeListener(
  609. event -> win.setVisible(!hidden.getValue()));
  610. addComponent(hidden);
  611. win.addCloseListener(new CloseListener() {
  612. @Override
  613. public void windowClose(CloseEvent e) {
  614. show.setEnabled(true);
  615. }
  616. });
  617. }
  618. };
  619. p.setContent(content);
  620. return p;
  621. }
  622. @Override
  623. public void enter(ViewChangeEvent event) {
  624. // TODO Auto-generated method stub
  625. }
  626. }