@Theme("mytheme") @Widgetset("com.mycompany.myvaadin.MyAppWidgetset") public class MyUI extends UI { @Override protected void init(VaadinRequest vaadinRequest) { final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); setContent(layout); Button button = new Button("Click Me"); button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { layout.addComponent(new Label("Thank you for clicking")); } }); layout.addComponent(button); } @WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true) @VaadinServletConfiguration(ui = MyUI.class, productionMode = false) public static class MyUIServlet extends VaadinServlet { } }
<div tabindex="0" role="button" class="v-button v-widget"> <span class="v-button-wrap"> <span class="v-button-caption">Click Me</span> </span> </div>
$v-background-color: #000;
$textcolor: red; .v-button-caption { color: $textcolor; }
public class MyUI extends UI { . . . private TreeTable treetable; private void initFileTree(ComponentContainer parentLayout) { // TreeTable treetable = new TreeTable("File System"); treetable.setSelectable(true); treetable.setColumnCollapsingAllowed(true); treetable.setColumnReorderingAllowed(true); treetable.setSizeFull(); parentLayout.addComponent(treetable); } . . . }
private void updateFileTree(File sourcePath) { // FilesystemContainer currentFileSystem = new FilesystemContainer(sourcePath); currentFileSystem.setRecursive(false); // // TreeTable, treetable.setContainerDataSource(currentFileSystem); treetable.setItemIconPropertyId("Icon"); treetable.setVisibleColumns(new Object[]{"Name", "Size", "Last Modified"}); // , }
private File currentPath; // // ~/NetBeansProjects/fileman/target/fileman-1.0-SNAPSHOT/ private void getDefaultDirectory() { UI ui = MyVaadinUI.getCurrent(); VaadinSession session = ui.getSession(); VaadinService service = session.getService(); currentPath = service.getBaseDirectory(); } initAll, : // private void initAll(VerticalLayout layout) { initFileTree(layout); getDefaultDirectory(); updateFileTree(currentPath); }
@Override protected void init(VaadinRequest request) { final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); setContent(layout); initAll(layout); }
// private void updateAll() { updateFileTree(currentPath); updateInfo(); } // / ( /) private void updateInfo() { }
// treetable.addItemClickListener(new ItemClickEvent.ItemClickListener() { @Override public void itemClick(ItemClickEvent itemClickEvent) { String clickedFilename = itemClickEvent.getItemId().toString(); // , System.out.println("ItemClick: pathname:" + clickedFilename); // if (itemClickEvent.isDoubleClick()) { doChangeDir(clickedFilename); } else { doSelectFile(clickedFilename); } } });
private String selectedFilename; // — private void doRefresh() { updateAll(); } // — private void doChangeDir(String path) { currentPath = new File(path); if (currentPath.isDirectory()) { selectedFilename = null; updateAll(); } } // — private void doUpLevel() { currentPath = currentPath.getParentFile(); selectedFilename = null; updateAll(); } // — private void doSelectFile(String filename) { selectedFilename = filename; updateInfo(); }
private void initMenuBar(Layout parentLayout) { // MenuBar // https://vaadin.com/book/-/page/components.menubar.html // MenuBar menuBar = new MenuBar(); // menuBar.setWidth("100%"); // 100% parentLayout.addComponent(menuBar); // layout // File final MenuItem fileMenuItem = menuBar.addItem("File", null, null); // File Refresh fileMenuItem.addItem("Refresh", FontAwesome.REFRESH, new MenuBar.Command() { @Override public void menuSelected(MenuItem selectedItem) { doRefresh(); } }); // File Up Level fileMenuItem.addItem("Up Level", FontAwesome.ARROW_UP, new MenuBar.Command() { @Override public void menuSelected(MenuItem selectedItem) { doUpLevel(); } }); } private void updateMenuBar() { // }
initMenuBar(layout);
updateMenuBar();
private Label labelFileName; // , / private void initTopPanel(Layout parentLayout) { // , HorizontalLayout topPanelLayout = new HorizontalLayout(); // 100% topPanelLayout.setWidth("100%"); // topPanelLayout.setSpacing(true); // parentLayout.addComponent(topPanelLayout); // Refresh // Button button = new Button("Refresh"); // FontAwesome button.setIcon(FontAwesome.REFRESH); // // button.addStyleName(ValoTheme.BUTTON_SMALL); // topPanelLayout.addComponent(button); // button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { doRefresh(); } }); // Up Level // button = new Button("Up Level"); // FontAwesome button.setIcon(FontAwesome.ARROW_UP); // // button.addStyleName(ValoTheme.BUTTON_SMALL); // topPanelLayout.addComponent(button); // button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { doUpLevel(); } }); // // labelFileName = new Label(); // topPanelLayout.addComponent(labelFileName); topPanelLayout.setComponentAlignment(labelFileName, Alignment.MIDDLE_CENTER); // topPanelLayout.setExpandRatio(labelFileName, 1); } // private void updateTopPanel(File currentPath, String selectedFilename) { if (selectedFilename != null) { labelFileName.setValue(selectedFilename); } else { labelFileName.setValue(currentPath.toString()); } }
Label[] bottomLabels; private void initBottomPanel(Layout parentLayout) { final String[] captions = new String[]{ "File Size (Bytes)", "File Date", "Usable Space (Bytes)", "Total Space (Bytes)", "Free Space (Bytes)" }; HorizontalLayout bottomPanelLayout = new HorizontalLayout(); // 100% bottomPanelLayout.setWidth("100%"); parentLayout.addComponent(bottomPanelLayout); // Label bottomLabels = new Label[captions.length]; for (int i = 0; i < captions.length; i++) { bottomLabels[i] = new Label(); bottomLabels[i].setCaption(captions[i]); bottomLabels[i].setValue("NA"); bottomPanelLayout.addComponent(bottomLabels[i]); } } // private void updateBottomPanel(String pathname) { try { File file = new File(pathname); // Label — bottomLabels[0].setValue(Long.toString(file.length())); bottomLabels[1].setValue((new Date(file.lastModified())).toString()); // bottomLabels[2].setValue(Long.toString(file.getUsableSpace())); bottomLabels[3].setValue(Long.toString(file.getTotalSpace())); bottomLabels[4].setValue(Long.toString(file.getFreeSpace())); } catch (Exception e) { // for (Label bottomLabel : bottomLabels) { bottomLabel.setValue("NA"); } } }
private void initAll(VerticalLayout layout) { initMenuBar(layout); initTopPanel(layout); initFileTree(layout); getDefaultDirectory(); updateFileTree(currentPath); initBottomPanel(layout); }
private void updateInfo() { updateMenuBar(); updateTopPanel(currentPath, selectedFilename); updateBottomPanel(selectedFilename); }
private HorizontalLayout previewLayout; private Embedded previewEmbedded; // , private void initMainPanels(VerticalLayout parentLayout) { HorizontalSplitPanel mainPanels = new HorizontalSplitPanel(); mainPanels.setSizeFull(); parentLayout.addComponent(mainPanels); parentLayout.setExpandRatio(mainPanels, 1); initFileTree(mainPanels); initPreview(mainPanels); } // private void initPreview(ComponentContainer parentLayout) { previewLayout = new HorizontalLayout(); previewLayout.setSizeFull(); parentLayout.addComponent(previewLayout); // // Embedded previewEmbedded = new Embedded("Preview area", null); // previewEmbedded.setVisible(true); // previewLayout.addComponent(previewEmbedded); // previewLayout.setComponentAlignment(previewEmbedded, Alignment.MIDDLE_CENTER); } // private void clearPreview() { previewEmbedded.setSource(null); previewEmbedded.setVisible(true); } // private void updatePreview(String pathname) { if (pathname == null || pathname.length() == 0) { clearPreview(); return; } // File file = new File(pathname); int lastIndexOf = pathname.lastIndexOf("."); String extension = (lastIndexOf == -1) ? "" : pathname.substring(lastIndexOf); // — 128 final int PREVIEW_FILE_LIMIT = 128 * 1024; // Embedded (, Flash ) final String[] imageExtensions = new String[]{ ".gif", ".jpeg", ".jpg", ".png", ".bmp", ".ico", ".cur", "swf", "svg" }; // , previewEmbedded.setVisible(false); // , if (file.length() > PREVIEW_FILE_LIMIT) { clearPreview(); return; } // — if (Arrays.asList(imageExtensions).contains(extension)) { Resource resource = new FileResource(file); // previewEmbedded.setSource(resource); // Embedded previewEmbedded.setVisible(true); // previewLayout.setExpandRatio(previewEmbedded, 1.0f); // } }
private void initAll(VerticalLayout layout) { initMenuBar(layout); initTopPanel(layout); // initFileTree(layout); initMainPanels(layout); getDefaultDirectory(); updateFileTree(currentPath); initBottomPanel(layout); }
updatePreview(selectedFilename);
Google Web Toolkit (GWT)
Google Web Toolkit (GWT) is an open source library that provides a set of Java APIs and visual components that allow you to develop Java AJAX applications and then compile their sources into highly optimized JavaScript, running on all major browsers, including Android and mobile browsers. iPhone. Read more - here .
VIDEO
Www
- Details on how to get started are described in the Getting Started with Vaadin section of the Book of Vaadin e-book.
- An excellent addition to the book is Book of Vaadin Examples , with fragments of source code for the vast majority of sections of the book and elements of Vaadin.
- A small sample application sample can be found here .
- More complex demos .
- API documentation is available here .
Vaadin TouchKit
Vaadin TouchKit is designed to develop applications for mobile devices. It includes components optimized for the mobile interface, as well as functions specific to mobile devices. In addition to the usual interface formed on the server, TouchKit supports a special offline mode, in which the client interface is stored in the browser's cache and is turned on automatically when the network is unavailable.
Vaadin TestBench
Based on the Selenium library, which allows you to control the browser directly from Java code.
With the help of Vaadin TestBench, automated testing is implemented at all levels and phases of development, up to a comparison of screenshots. More details can be found here .
Vaadin Add-ons
In the Vaadin Directory at the moment there are almost 500 different add-ons, among which you can, for example, mention the Vaadin Charts component for drawing graphs and charts.
To access the add-ons directory in the context menu of the project there is an Open Add-Ons Browser item.
Source: https://habr.com/ru/post/244477/