List of usage examples for com.vaadin.ui HorizontalLayout setComponentAlignment
@Override public void setComponentAlignment(Component childComponent, Alignment alignment)
From source file:eu.maxschuster.vaadin.signaturefield.demo.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { getPage().setTitle(pageTitle);// w w w . ja va 2s . c om final VerticalLayout margin = new VerticalLayout(); setContent(margin); final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true); layout.setWidth("658px"); margin.addComponent(layout); margin.setComponentAlignment(layout, Alignment.TOP_CENTER); final Label header1 = new Label(pageTitle); header1.addStyleName("h1"); header1.setSizeUndefined(); layout.addComponent(header1); layout.setComponentAlignment(header1, Alignment.TOP_CENTER); final TabSheet tabSheet = new TabSheet(); tabSheet.setWidth("100%"); layout.addComponent(tabSheet); layout.setComponentAlignment(tabSheet, Alignment.TOP_CENTER); final Panel signaturePanel = new Panel(); signaturePanel.addStyleName("signature-panel"); signaturePanel.setWidth("100%"); tabSheet.addTab(signaturePanel, "Demo"); final VerticalLayout signatureLayout = new VerticalLayout(); signatureLayout.setMargin(true); signatureLayout.setSpacing(true); signatureLayout.setSizeFull(); signaturePanel.setContent(signatureLayout); final SignatureField signatureField = new SignatureField(); signatureField.setWidth("100%"); signatureField.setHeight("318px"); signatureField.setPenColor(Color.ULTRAMARINE); signatureField.setBackgroundColor("white"); signatureField.setConverter(new StringToDataUrlConverter()); signatureField.setPropertyDataSource(dataUrlProperty); signatureField.setVelocityFilterWeight(0.7); signatureLayout.addComponent(signatureField); signatureLayout.setComponentAlignment(signatureField, Alignment.MIDDLE_CENTER); final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); signatureLayout.addComponent(buttonLayout); final Button clearButton = new Button("Clear", new ClickListener() { @Override public void buttonClick(ClickEvent event) { signatureField.clear(); } }); buttonLayout.addComponent(clearButton); buttonLayout.setComponentAlignment(clearButton, Alignment.MIDDLE_LEFT); final Label message = new Label("Sign above"); message.setSizeUndefined(); buttonLayout.addComponent(message); buttonLayout.setComponentAlignment(message, Alignment.MIDDLE_CENTER); final ButtonLink saveButtonLink = new ButtonLink("Save", null); saveButtonLink.setTargetName("_blank"); buttonLayout.addComponent(saveButtonLink); buttonLayout.setComponentAlignment(saveButtonLink, Alignment.MIDDLE_RIGHT); final Panel optionsPanel = new Panel(); optionsPanel.setSizeFull(); tabSheet.addTab(optionsPanel, "Options"); final FormLayout optionsLayout = new FormLayout(); optionsLayout.setMargin(true); optionsLayout.setSpacing(true); optionsPanel.setContent(optionsLayout); final ComboBox mimeTypeComboBox = new ComboBox(null, mimeTypeContainer); optionsLayout.addComponent(mimeTypeComboBox); mimeTypeComboBox.setItemCaptionPropertyId("mimeType"); mimeTypeComboBox.setNullSelectionAllowed(false); mimeTypeComboBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { MimeType mimeType = (MimeType) event.getProperty().getValue(); signatureField.setMimeType(mimeType); } }); mimeTypeComboBox.setValue(MimeType.PNG); mimeTypeComboBox.setCaption("Result MIME-Type"); final CheckBox immediateCheckBox = new CheckBox("immediate", false); optionsLayout.addComponent(immediateCheckBox); immediateCheckBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean immediate = (Boolean) event.getProperty().getValue(); signatureField.setImmediate(immediate); } }); final CheckBox readOnlyCheckBox = new CheckBox("readOnly", false); optionsLayout.addComponent(readOnlyCheckBox); readOnlyCheckBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean readOnly = (Boolean) event.getProperty().getValue(); signatureField.setReadOnly(readOnly); mimeTypeComboBox.setReadOnly(readOnly); clearButton.setEnabled(!readOnly); } }); final CheckBox requiredCheckBox = new CheckBox("required (causes bug that clears field)", false); optionsLayout.addComponent(requiredCheckBox); requiredCheckBox.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean required = (Boolean) event.getProperty().getValue(); signatureField.setRequired(required); } }); final CheckBox clearButtonEnabledButton = new CheckBox("clearButtonEnabled", false); optionsLayout.addComponent(clearButtonEnabledButton); clearButtonEnabledButton.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean clearButtonEnabled = (Boolean) event.getProperty().getValue(); signatureField.setClearButtonEnabled(clearButtonEnabled); } }); final Panel resultPanel = new Panel("Results:"); resultPanel.setWidth("100%"); layout.addComponent(resultPanel); final VerticalLayout resultLayout = new VerticalLayout(); resultLayout.setMargin(true); resultPanel.setContent(resultLayout); final Image stringPreviewImage = new Image("String preview image:"); stringPreviewImage.setWidth("500px"); resultLayout.addComponent(stringPreviewImage); final Image dataUrlPreviewImage = new Image("DataURL preview image:"); dataUrlPreviewImage.setWidth("500px"); resultLayout.addComponent(dataUrlPreviewImage); final TextArea textArea = new TextArea("DataURL:"); textArea.setWidth("100%"); textArea.setHeight("300px"); resultLayout.addComponent(textArea); final Label emptyLabel = new Label(); emptyLabel.setCaption("Is Empty:"); emptyLabel.setValue(String.valueOf(signatureField.isEmpty())); resultLayout.addComponent(emptyLabel); signatureField.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { String signature = (String) event.getProperty().getValue(); stringPreviewImage.setSource(signature != null ? new ExternalResource(signature) : null); textArea.setValue(signature); emptyLabel.setValue(String.valueOf(signatureField.isEmpty())); } }); dataUrlProperty.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { try { final DataUrl signature = (DataUrl) event.getProperty().getValue(); dataUrlPreviewImage.setSource( signature != null ? new ExternalResource(serializer.serialize(signature)) : null); StreamResource streamResource = null; if (signature != null) { StreamSource streamSource = new StreamSource() { @Override public InputStream getStream() { return new ByteArrayInputStream(signature.getData()); } }; MimeType mimeType = MimeType.valueOfMimeType(signature.getMimeType()); String extension = null; switch (mimeType) { case JPEG: extension = "jpg"; break; case PNG: extension = "png"; break; } streamResource = new StreamResource(streamSource, "signature." + extension); streamResource.setMIMEType(signature.getMimeType()); streamResource.setCacheTime(0); } saveButtonLink.setResource(streamResource); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } } }); }
From source file:fi.jasoft.draganddrop.demos.DragDemo.java
License:Apache License
@Override protected Component getDemoContent() { HorizontalLayout hl = new HorizontalLayout(); hl.setSizeFull();/*w ww . j a v a 2 s . com*/ // source-start // Create image Image image = new Image(null, new ThemeResource("graphics/bin.jpg")); // Enable dropping items on image DragAndDrop.enable(image, DragAndDropOperation.DROP) // Set custom drop handler .onDrop(new DropHandler<Image>() { @Override protected void onDrop(Component component) { // Restor trash bin getSource().setSource(new ThemeResource("graphics/bin.jpg")); // Remove item ((ComponentContainer) component.getParent()).removeComponent(component); } }) // Set custom over handler .onOver(new DragOverHandler<Image>() { @Override protected void onOver(Component component) { // Add color to trash bin getSource().setSource(new ThemeResource("graphics/bin2.jpg")); } }) // Set custom out handler .onOut(new DragOutHandler<Image>() { @Override protected void onOut(Component component) { // Restore trash bin getSource().setSource(new ThemeResource("graphics/bin.jpg")); } }); // source-end hl.addComponent(image); hl.setComponentAlignment(image, Alignment.TOP_CENTER); VerticalLayout vl = new VerticalLayout(); vl.setSizeUndefined(); vl.setSpacing(true); hl.addComponent(vl); hl.setComponentAlignment(vl, Alignment.TOP_CENTER); // source-start /* * Create item list to drag from */ for (int i = 0; i < 5; i++) { Label item = new Label("Item " + (i + 1)); item.setStyleName("item"); item.setSizeUndefined(); // Enable dragging the items DragAndDrop.enable(item, DragAndDropOperation.DRAG); vl.addComponent(item); } // source-end return hl; }
From source file:fi.semantum.strategia.Main.java
License:Open Source License
@Override protected void init(VaadinRequest request) { getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { public void uriFragmentChanged(UriFragmentChangedEvent source) { applyFragment(source.getUriFragment(), true); }// w ww.j a v a 2 s. c om }); String pathInfo = request.getPathInfo(); if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1); if (pathInfo.endsWith("/")) pathInfo = pathInfo.substring(0, pathInfo.length() - 1); String databaseId = validatePathInfo(pathInfo); setWindowWidth(Page.getCurrent().getBrowserWindowWidth(), Page.getCurrent().getBrowserWindowHeight()); // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource redResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_red.png")); greenResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_green.png")); blackResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_black.png")); mapMagnify = new FileResource(new File(basepath + "/WEB-INF/images/map_magnify.png")); abs = new AbsoluteLayout(); final VerticalLayout vs = new VerticalLayout(); vs.setSizeFull(); abs.addComponent(vs); setContent(abs); // This will set the login cookie Wiki.login(this); // Make sure that the printing directory exists new File(Main.baseDirectory(), "printing").mkdirs(); database = Database.load(this, databaseId); database.getOrCreateTag("Tavoite"); database.getOrCreateTag("Painopiste"); for (Strategiakartta map : Strategiakartta.enumerate(database)) { Strategiakartta parent = map.getPossibleParent(database); if (parent == null) uiState.setCurrentMap(parent); } if (uiState.getCurrentMap() == null) uiState.setCurrentMap(database.getRoot()); uiState.currentPosition = uiState.getCurrentMap(); uiState.currentItem = uiState.getCurrentMap(); setPollInterval(10000); addPollListener(new PollListener() { @Override public void poll(PollEvent event) { if (database.checkChanges()) { String curr = uiState.getCurrentMap().uuid; database = Database.load(Main.this, database.getDatabaseId()); uiState.setCurrentMap((Strategiakartta) database.find(curr)); Updates.updateJS(Main.this, false); } } }); js.addListener(new MapListener(this, false)); js2.addListener(new MapListener(this, true)); browser_.addListener(new BrowserListener() { @Override public void select(double x, double y, String uuid) { Base b = database.find(uuid); Actions.selectAction(Main.this, x, y, null, b); } @Override public void save(String name, Map<String, BrowserNodeState> states) { UIState state = getUIState().duplicate(name); state.browserStates = states; account.uiStates.add(state); Updates.update(Main.this, true); } }); Page.getCurrent().addBrowserWindowResizeListener(new BrowserWindowResizeListener() { @Override public void browserWindowResized(BrowserWindowResizeEvent event) { setWindowWidth(event.getWidth(), event.getHeight()); Updates.updateJS(Main.this, false); } }); modeLabel = new Label("Katselutila"); modeLabel.setWidth("95px"); modeLabel.addStyleName("viewMode"); mode = new Button(); mode.setDescription("Siirry tiedon sytttilaan"); mode.setIcon(FontAwesome.EYE); mode.addStyleName(ValoTheme.BUTTON_TINY); mode.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if ("Siirry tiedon sytttilaan".equals(mode.getDescription())) { mode.setDescription("Siirry katselutilaan"); mode.setIcon(FontAwesome.PENCIL); modeLabel.setValue("Sytttila"); modeLabel.removeStyleName("viewMode"); modeLabel.addStyleName("editMode"); UIState s = uiState.duplicate(Main.this); s.input = true; setFragment(s, true); } else { mode.setDescription("Siirry tiedon sytttilaan"); mode.setIcon(FontAwesome.EYE); modeLabel.setValue("Katselutila"); modeLabel.removeStyleName("editMode"); modeLabel.addStyleName("viewMode"); UIState s = uiState.duplicate(Main.this); s.input = false; setFragment(s, true); } } }); meterMode = new Button(); meterMode.setDescription("Vaihda toteumamittareihin"); meterMode.setCaption("Ennuste"); meterMode.addStyleName(ValoTheme.BUTTON_TINY); meterMode.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if ("Vaihda toteumamittareihin".equals(meterMode.getDescription())) { meterMode.setDescription("Vaihda ennustemittareihin"); meterMode.setCaption("Toteuma"); UIState s = uiState.duplicate(Main.this); s.setActualMeters(); setFragment(s, true); } else { meterMode.setDescription("Vaihda toteumamittareihin"); meterMode.setCaption("Ennuste"); UIState s = uiState.duplicate(Main.this); s.setForecastMeters(); setFragment(s, true); } } }); pdf = new PDFButton(); pdf.setDescription("Tallenna kartta PDF-muodossa"); pdf.setIcon(FontAwesome.PRINT); pdf.addStyleName(ValoTheme.BUTTON_TINY); pdf.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Utils.print(Main.this); } }); propertyExcelButton = new Button(); propertyExcelButton.setDescription("Tallenna tiedot Excel-tiedostona"); propertyExcelButton.setIcon(FontAwesome.PRINT); propertyExcelButton.addStyleName(ValoTheme.BUTTON_TINY); OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() { private static final long serialVersionUID = 981769438054780731L; File f; Date date = new Date(); @Override public InputStream getStream() { String uuid = UUID.randomUUID().toString(); File printing = new File(Main.baseDirectory(), "printing"); f = new File(printing, uuid + ".xlsx"); Workbook w = new XSSFWorkbook(); Sheet sheet = w.createSheet("Sheet1"); int row = 1; for (List<String> cells : propertyCells) { Row r = sheet.createRow(row++); for (int i = 0; i < cells.size(); i++) { String value = cells.get(i); r.createCell(i).setCellValue(value); } } try { FileOutputStream s = new FileOutputStream(f); w.write(s); s.close(); } catch (Exception e) { e.printStackTrace(); } try { return new FileInputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } throw new IllegalStateException(); } @Override public void onRequest() { } @Override public long getFileSize() { return f.length(); } @Override public String getFileName() { return "Strategiakartta_" + Utils.dateString(date) + ".xlsx"; } }); dl.getResource().setCacheTime(0); dl.extend(propertyExcelButton); states = new ComboBox(); states.setWidth("250px"); states.addStyleName(ValoTheme.COMBOBOX_TINY); states.setInvalidAllowed(false); states.setNullSelectionAllowed(false); states.addValueChangeListener(statesListener); saveState = new Button(); saveState.setEnabled(false); saveState.setDescription("Tallenna nykyinen nkym"); saveState.setIcon(FontAwesome.BOOKMARK); saveState.addStyleName(ValoTheme.BUTTON_TINY); saveState.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Utils.saveCurrentState(Main.this); } }); class SearchTextField extends TextField { public boolean hasFocus = false; } final SearchTextField search = new SearchTextField(); search.setWidth("100%"); search.addStyleName(ValoTheme.TEXTFIELD_TINY); search.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); search.setInputPrompt("hae vapaasanahaulla valitun asian alta"); search.setId("searchTextField"); search.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { if (!search.hasFocus) return; String text = search.getValue().toLowerCase(); try { Map<String, String> content = new HashMap<String, String>(); List<String> hits = Lucene.search(database.getDatabaseId(), text + "*"); for (String uuid : hits) { Base b = database.find(uuid); if (b != null) { String report = ""; Map<String, String> map = b.searchMap(database); for (Map.Entry<String, String> e : map.entrySet()) { if (e.getValue().contains(text)) { if (!report.isEmpty()) report += ", "; report += e.getKey(); } } if (!report.isEmpty()) content.put(uuid, report); } } uiState.setCurrentFilter(new SearchFilter(Main.this, content)); Updates.updateJS(Main.this, false); switchToBrowser(); } catch (IOException e) { e.printStackTrace(); } } }); search.addFocusListener(new FocusListener() { @Override public void focus(FocusEvent event) { search.hasFocus = true; } }); search.addBlurListener(new BlurListener() { @Override public void blur(BlurEvent event) { search.hasFocus = false; } }); hallinnoi = new Button("Hallinnoi"); hallinnoi.setWidthUndefined(); hallinnoi.setVisible(false); hallinnoi.addStyleName(ValoTheme.BUTTON_TINY); hallinnoi.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { if (account.isAdmin()) { Utils.manage(Main.this); } } } }); tili = new Button("Kyttjtili"); tili.setWidthUndefined(); tili.setVisible(false); tili.addStyleName(ValoTheme.BUTTON_TINY); tili.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { Utils.modifyAccount(Main.this); } } }); duplicate = new Button("Avaa ikkunassa"); duplicate2 = new Button("Avaa alas"); duplicate.setWidthUndefined(); duplicate.addStyleName(ValoTheme.BUTTON_TINY); duplicate.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { MapVis model = js2.getModel(); if (model == null) { UIState s = uiState.duplicate(Main.this); s.reference = s.current; mapDialog = new Window(s.reference.getText(database), new VerticalLayout()); mapDialog.setWidth(dialogWidth()); mapDialog.setHeight(dialogHeight()); mapDialog.setResizable(true); mapDialog.setContent(js2Container); mapDialog.setVisible(true); mapDialog.setResizeLazy(false); mapDialog.addCloseListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { duplicate.setCaption("Avaa ikkunassa"); duplicate2.setVisible(true); UIState s = uiState.duplicate(Main.this); mapDialog.close(); mapDialog = null; s.reference = null; setFragment(s, true); } }); mapDialog.addResizeListener(new ResizeListener() { @Override public void windowResized(ResizeEvent e) { Updates.updateJS(Main.this, false); } }); setFragment(s, true); addWindow(mapDialog); duplicate.setCaption("Sulje referenssi"); duplicate2.setVisible(false); } else { UIState s = uiState.duplicate(Main.this); if (mapDialog != null) { mapDialog.close(); mapDialog = null; } panelLayout.removeComponent(js2Container); s.reference = null; setFragment(s, true); duplicate.setCaption("Avaa ikkunassa"); duplicate2.setVisible(true); } } }); duplicate2.setWidthUndefined(); duplicate2.addStyleName(ValoTheme.BUTTON_TINY); duplicate2.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { MapVis model = js2.getModel(); assert (model == null); UIState s = uiState.duplicate(Main.this); s.reference = s.current; setFragment(s, true); panelLayout.addComponent(js2Container); duplicate.setCaption("Sulje referenssi"); duplicate2.setVisible(false); } }); login = new Button("Kirjaudu"); login.setWidthUndefined(); login.addStyleName(ValoTheme.BUTTON_TINY); login.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { account = null; hallinnoi.setVisible(false); tili.setVisible(false); Updates.update(Main.this, true); login.setCaption("Kirjaudu"); } else { Login.login(Main.this); } } }); times = new ComboBox(); times.setWidth("130px"); times.addStyleName(ValoTheme.COMBOBOX_SMALL); times.addItem(Property.AIKAVALI_KAIKKI); times.addItem("2016"); times.addItem("2017"); times.addItem("2018"); times.addItem("2019"); times.select("2016"); times.setInvalidAllowed(false); times.setNullSelectionAllowed(false); times.addValueChangeListener(timesListener); final HorizontalLayout hl0 = new HorizontalLayout(); hl0.setWidth("100%"); hl0.setHeight("32px"); hl0.setSpacing(true); hl0.addComponent(pdf); hl0.setComponentAlignment(pdf, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(pdf, 0.0f); hl0.addComponent(propertyExcelButton); hl0.setComponentAlignment(propertyExcelButton, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(propertyExcelButton, 0.0f); hl0.addComponent(states); hl0.setComponentAlignment(states, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(states, 0.0f); hl0.addComponent(saveState); hl0.setComponentAlignment(saveState, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(saveState, 0.0f); hl0.addComponent(times); hl0.setComponentAlignment(times, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(times, 0.0f); hl0.addComponent(search); hl0.setComponentAlignment(search, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(search, 1.0f); hl0.addComponent(modeLabel); hl0.setComponentAlignment(modeLabel, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(modeLabel, 0.0f); hl0.addComponent(mode); hl0.setComponentAlignment(mode, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(mode, 0.0f); hl0.addComponent(meterMode); hl0.setComponentAlignment(meterMode, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(meterMode, 0.0f); hl0.addComponent(hallinnoi); hl0.setComponentAlignment(hallinnoi, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(hallinnoi, 0.0f); hl0.addComponent(tili); hl0.setComponentAlignment(tili, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(tili, 0.0f); hl0.addComponent(duplicate); hl0.setComponentAlignment(duplicate, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(duplicate, 0.0f); hl0.addComponent(duplicate2); hl0.setComponentAlignment(duplicate2, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(duplicate2, 0.0f); hl0.addComponent(login); hl0.setComponentAlignment(login, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(login, 0.0f); propertiesPanel = new Panel(); propertiesPanel.setSizeFull(); properties = new VerticalLayout(); properties.setSpacing(true); properties.setMargin(true); propertiesPanel.setContent(properties); propertiesPanel.setVisible(false); tags = new VerticalLayout(); tags.setSpacing(true); Updates.updateTags(this); AbsoluteLayout tabs = new AbsoluteLayout(); tabs.setSizeFull(); { panel = new Panel(); panel.addStyleName(ValoTheme.PANEL_BORDERLESS); panel.setSizeFull(); panel.setId("mapContainer1"); panelLayout = new VerticalLayout(); panelLayout.addComponent(js); panelLayout.setHeight("100%"); js2Container = new VerticalLayout(); js2Container.setHeight("100%"); js2Container.addComponent(new Label("<hr />", ContentMode.HTML)); js2Container.addComponent(js2); panel.setContent(panelLayout); tabs.addComponent(panel); } wiki = new BrowserFrame(); wiki.setSource(new ExternalResource(Wiki.wikiAddress() + "/")); wiki.setWidth("100%"); wiki.setHeight("100%"); { wiki_ = new VerticalLayout(); wiki_.setSizeFull(); Button b = new Button("Palaa sovellukseen"); b.setWidth("100%"); b.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { applyFragment(backFragment, true); String content = Wiki.get(wikiPage); if (content == null) return; int first = content.indexOf("<rev contentformat"); if (first == -1) return; content = content.substring(first); int term = content.indexOf(">"); content = content.substring(term + 1); int end = content.indexOf("</rev>"); content = content.substring(0, end); if (wikiBase.modifyMarkup(Main.this, content)) { Updates.update(Main.this, true); } } }); wiki_.addComponent(b); wiki_.addComponent(wiki); wiki_.setVisible(false); wiki_.setExpandRatio(b, 0.0f); wiki_.setExpandRatio(wiki, 1.0f); tabs.addComponent(wiki_); } hs = new HorizontalSplitPanel(); hs.setSplitPosition(0, Unit.PIXELS); hs.setHeight("100%"); hs.setWidth("100%"); browser = new VerticalLayout(); browser.setSizeFull(); HorizontalLayout browserWidgets = new HorizontalLayout(); browserWidgets.setWidth("100%"); hori = new Button(); hori.setDescription("Nyt asiat taulukkona"); hori.setEnabled(true); hori.setIcon(FontAwesome.ARROW_RIGHT); hori.addStyleName(ValoTheme.BUTTON_TINY); hori.addClickListener(new ClickListener() { boolean right = false; @Override public void buttonClick(ClickEvent event) { if (right) { hs.setSplitPosition(0, Unit.PIXELS); hori.setIcon(FontAwesome.ARROW_RIGHT); hori.setDescription("Nyt asiat taulukkona"); right = false; } else { hs.setSplitPosition(windowWidth / 2, Unit.PIXELS); hori.setIcon(FontAwesome.ARROW_LEFT); hori.setDescription("Piilota taulukko"); right = true; } } }); more = new Button(); more.setDescription("Laajenna nytettvien asioiden joukkoa"); more.setIcon(FontAwesome.PLUS_SQUARE); more.addStyleName(ValoTheme.BUTTON_TINY); more.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { uiState.level++; Updates.updateJS(Main.this, false); if (uiState.level >= 2) less.setEnabled(true); } }); less = new Button(); less.setDescription("Supista nytettvien asioiden joukkoa"); less.setIcon(FontAwesome.MINUS_SQUARE); less.addStyleName(ValoTheme.BUTTON_TINY); less.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (uiState.level > 1) { uiState.level--; Updates.updateJS(Main.this, false); } if (uiState.level <= 1) less.setEnabled(false); } }); reportAllButton = new Button(); reportAllButton.setCaption("Nkyvt tulokset"); reportAllButton.addStyleName(ValoTheme.BUTTON_TINY); reportAllButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (uiState.reportAll) { reportAllButton.setCaption("Nkyvt tulokset"); uiState.reportAll = false; } else { reportAllButton.setCaption("Kaikki tulokset"); uiState.reportAll = true; } Updates.updateJS(Main.this, false); } }); reportStatus = new Label("0 tulosta."); reportStatus.setWidth("100px"); filter = new ComboBox(); filter.setWidth("100%"); filter.addStyleName(ValoTheme.COMBOBOX_SMALL); filter.setInvalidAllowed(false); filter.setNullSelectionAllowed(false); filter.addValueChangeListener(filterListener); browserWidgets.addComponent(hori); browserWidgets.setComponentAlignment(hori, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(hori, 0.0f); browserWidgets.addComponent(more); browserWidgets.setComponentAlignment(more, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(more, 0.0f); browserWidgets.addComponent(less); browserWidgets.setComponentAlignment(less, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(less, 0.0f); browserWidgets.addComponent(reportAllButton); browserWidgets.setComponentAlignment(reportAllButton, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(reportAllButton, 0.0f); browserWidgets.addComponent(reportStatus); browserWidgets.setComponentAlignment(reportStatus, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(reportStatus, 0.0f); browserWidgets.addComponent(filter); browserWidgets.setComponentAlignment(filter, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(filter, 1.0f); browser.addComponent(browserWidgets); browser.addComponent(hs); browser.setExpandRatio(browserWidgets, 0.0f); browser.setExpandRatio(hs, 1.0f); browser.setVisible(false); tabs.addComponent(browser); { gridPanelLayout = new VerticalLayout(); gridPanelLayout.setMargin(false); gridPanelLayout.setSpacing(false); gridPanelLayout.setSizeFull(); hs.addComponent(gridPanelLayout); } CssLayout browserLayout = new CssLayout(); browserLayout.setSizeFull(); browserLayout.addComponent(browser_); hs.addComponent(browserLayout); tabs.addComponent(propertiesPanel); vs.addComponent(hl0); vs.addComponent(tabs); vs.setExpandRatio(hl0, 0.0f); vs.setExpandRatio(tabs, 1.0f); // Ground state fragments.put("", uiState); setCurrentItem(uiState.currentItem, (Strategiakartta) uiState.currentItem); }
From source file:fi.semantum.strategia.Updates.java
License:Open Source License
private static void updateQueryGrid(final Main main, final FilterState state) { main.gridPanelLayout.removeAllComponents(); main.gridPanelLayout.setMargin(false); final List<String> keys = state.reportColumns; if (keys.isEmpty()) { Label l = new Label("Kysely ei tuottanut yhtn tulosta."); l.addStyleName(ValoTheme.LABEL_BOLD); l.addStyleName(ValoTheme.LABEL_HUGE); main.gridPanelLayout.addComponent(l); return;//www .j a v a 2 s . c o m } final IndexedContainer container = new IndexedContainer(); for (String key : keys) { container.addContainerProperty(key, String.class, ""); } rows: for (Map<String, ReportCell> map : state.report) { Object item = container.addItem(); for (String key : keys) if (map.get(key) == null) continue rows; for (Map.Entry<String, ReportCell> entry : map.entrySet()) { @SuppressWarnings("unchecked") com.vaadin.data.Property<String> p = container.getContainerProperty(item, entry.getKey()); p.setValue(entry.getValue().get()); } } HorizontalLayout hl = new HorizontalLayout(); hl.setWidth("100%"); final TextField filter = new TextField(); filter.addStyleName(ValoTheme.TEXTFIELD_TINY); filter.setInputPrompt("rajaa hakutuloksia - kirjoitetun sanan tulee lyty rivin teksteist"); filter.setWidth("100%"); final Image clipboard = new Image(); clipboard.setSource(new ThemeResource("page_white_excel.png")); clipboard.setHeight("24px"); clipboard.setWidth("24px"); hl.addComponent(filter); hl.setExpandRatio(filter, 1.0f); hl.setComponentAlignment(filter, Alignment.BOTTOM_CENTER); hl.addComponent(clipboard); hl.setComponentAlignment(clipboard, Alignment.BOTTOM_CENTER); hl.setExpandRatio(clipboard, 0.0f); main.gridPanelLayout.addComponent(hl); main.gridPanelLayout.setExpandRatio(hl, 0f); filter.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 3033918399018888150L; @Override public void valueChange(ValueChangeEvent event) { container.removeAllContainerFilters(); container.addContainerFilter(new QueryFilter(filter.getValue(), true, false)); } }); AbsoluteLayout abs = new AbsoluteLayout(); abs.setSizeFull(); final Grid queryGrid = new Grid(container); queryGrid.setSelectionMode(SelectionMode.NONE); queryGrid.setHeightMode(HeightMode.CSS); queryGrid.setHeight("100%"); queryGrid.setWidth("100%"); for (String key : keys) { Column col = queryGrid.getColumn(key); col.setExpandRatio(1); } abs.addComponent(queryGrid); OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() { private static final long serialVersionUID = 981769438054780731L; File f; Date date = new Date(); @Override public InputStream getStream() { String uuid = UUID.randomUUID().toString(); File printing = new File(Main.baseDirectory(), "printing"); f = new File(printing, uuid + ".xlsx"); Workbook w = new XSSFWorkbook(); Sheet sheet = w.createSheet("Sheet1"); Row header = sheet.createRow(0); for (int i = 0; i < keys.size(); i++) { Cell cell = header.createCell(i); cell.setCellValue(keys.get(i)); } int row = 1; rows: for (Map<String, ReportCell> map : state.report) { for (String key : keys) if (map.get(key) == null) continue rows; Row r = sheet.createRow(row++); int column = 0; for (int i = 0; i < keys.size(); i++) { Cell cell = r.createCell(column++); ReportCell rc = map.get(keys.get(i)); cell.setCellValue(rc.getLong()); } } try { FileOutputStream s = new FileOutputStream(f); w.write(s); s.close(); } catch (Exception e) { e.printStackTrace(); } try { return new FileInputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } throw new IllegalStateException(); } @Override public void onRequest() { // TODO Auto-generated method stub } @Override public long getFileSize() { return f.length(); } @Override public String getFileName() { return "Strategiakartta_" + Utils.dateString(date) + ".xlsx"; } }); dl.getResource().setCacheTime(0); dl.extend(clipboard); main.gridPanelLayout.addComponent(abs); main.gridPanelLayout.setExpandRatio(abs, 1f); }
From source file:fi.semantum.strategia.Updates.java
License:Open Source License
public static void updateTags(final Main main) { final Database database = main.getDatabase(); main.tags.removeAllComponents();/* w w w . j av a2 s. c o m*/ main.tags.setMargin(true); ArrayList<Tag> sorted = new ArrayList<Tag>(Tag.enumerate(database)); Collections.sort(sorted, new Comparator<Tag>() { @Override public int compare(Tag arg0, Tag arg1) { return arg0.getId(database).compareTo(arg1.getId(database)); } }); for (final Tag t : sorted) { final HorizontalLayout hl = new HorizontalLayout(); hl.setSpacing(true); Label l = new Label(t.getId(database)); l.setSizeUndefined(); l.addStyleName(ValoTheme.LABEL_HUGE); hl.addComponent(l); hl.setComponentAlignment(l, Alignment.BOTTOM_LEFT); final Image select = new Image("", new ThemeResource("cursor.png")); select.setHeight("24px"); select.setWidth("24px"); select.setDescription("Valitse"); select.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = 3734678948272593793L; @Override public void click(com.vaadin.event.MouseEvents.ClickEvent event) { main.setCurrentItem(t, main.getUIState().currentPosition); Utils.loseFocus(select); } }); hl.addComponent(select); hl.setComponentAlignment(select, Alignment.BOTTOM_LEFT); final Image edit = new Image("", new ThemeResource("table_edit.png")); edit.setHeight("24px"); edit.setWidth("24px"); edit.setDescription("Muokkaa"); edit.addClickListener(new MouseEvents.ClickListener() { private static final long serialVersionUID = -3792353723974454702L; @Override public void click(com.vaadin.event.MouseEvents.ClickEvent event) { Utils.editTextAndId(main, "Muokkaa aihetunnistetta", t); updateTags(main); } }); hl.addComponent(edit); hl.setComponentAlignment(edit, Alignment.BOTTOM_LEFT); main.tags.addComponent(hl); main.tags.setComponentAlignment(hl, Alignment.MIDDLE_CENTER); Label l2 = new Label(t.getText(database)); l2.addStyleName(ValoTheme.LABEL_LIGHT); l2.setSizeUndefined(); main.tags.addComponent(l2); main.tags.setComponentAlignment(l2, Alignment.MIDDLE_CENTER); } }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void manage(final Main main) { final Database database = main.getDatabase(); VerticalLayout content = new VerticalLayout(); content.setSizeFull();//w w w .jav a 2 s .c o m content.setSpacing(true); HorizontalLayout hl1 = new HorizontalLayout(); hl1.setSpacing(true); hl1.setWidth("100%"); final ComboBox users = new ComboBox(); users.setWidth("100%"); users.setNullSelectionAllowed(false); users.addStyleName(ValoTheme.COMBOBOX_SMALL); users.setCaption("Valitse kyttj:"); final Map<String, Account> accountMap = new HashMap<String, Account>(); makeAccountCombo(main, accountMap, users); for (Account a : Account.enumerate(database)) { accountMap.put(a.getId(database), a); users.addItem(a.getId(database)); users.select(a.getId(database)); } final Table table = new Table(); table.setSelectable(true); table.setMultiSelect(true); table.addStyleName(ValoTheme.TABLE_SMALL); table.addStyleName(ValoTheme.TABLE_SMALL); table.addStyleName(ValoTheme.TABLE_COMPACT); users.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 5036991262418844060L; @Override public void valueChange(ValueChangeEvent event) { users.removeValueChangeListener(this); makeAccountCombo(main, accountMap, users); makeAccountTable(database, users, accountMap, table); users.addValueChangeListener(this); } }); final TextField tf = new TextField(); Validator nameValidator = new Validator() { private static final long serialVersionUID = -4779239111120669168L; @Override public void validate(Object value) throws InvalidValueException { String s = (String) value; if (s.isEmpty()) throw new InvalidValueException("Nimi ei saa olla tyhj"); if (accountMap.containsKey(s)) throw new InvalidValueException("Nimi on jo kytss"); } }; final Button save = new Button("Luo", new Button.ClickListener() { private static final long serialVersionUID = -6053708137324681886L; public void buttonClick(ClickEvent event) { if (!tf.isValid()) return; String pass = Long.toString(Math.abs(UUID.randomUUID().getLeastSignificantBits()), 36); Account.create(database, tf.getValue(), "", Utils.hash(pass)); Updates.update(main, true); makeAccountCombo(main, accountMap, users); makeAccountTable(database, users, accountMap, table); Dialogs.infoDialog(main, "Uusi kyttj '" + tf.getValue() + "' luotu", "Kyttjn salasana on " + pass + "", null); } }); save.addStyleName(ValoTheme.BUTTON_SMALL); final Button remove = new Button("Poista", new Button.ClickListener() { private static final long serialVersionUID = -5359199320445328801L; public void buttonClick(ClickEvent event) { Object selection = users.getValue(); Account state = accountMap.get(selection); // System cannot be removed if ("System".equals(state.getId(database))) return; state.remove(database); Updates.update(main, true); makeAccountCombo(main, accountMap, users); makeAccountTable(database, users, accountMap, table); } }); remove.addStyleName(ValoTheme.BUTTON_SMALL); tf.setWidth("100%"); tf.addStyleName(ValoTheme.TEXTFIELD_SMALL); tf.setCaption("Luo uusi kyttj nimell:"); tf.setValue(findFreshUserName(nameValidator)); tf.setCursorPosition(tf.getValue().length()); tf.setValidationVisible(true); tf.setInvalidCommitted(true); tf.setImmediate(true); tf.addTextChangeListener(new TextChangeListener() { private static final long serialVersionUID = -8274588731607481635L; @Override public void textChange(TextChangeEvent event) { tf.setValue(event.getText()); try { tf.validate(); } catch (InvalidValueException e) { save.setEnabled(false); return; } save.setEnabled(true); } }); tf.addValidator(nameValidator); if (!tf.isValid()) save.setEnabled(false); hl1.addComponent(users); hl1.setExpandRatio(users, 1.0f); hl1.setComponentAlignment(users, Alignment.BOTTOM_CENTER); hl1.addComponent(tf); hl1.setExpandRatio(tf, 1.0f); hl1.setComponentAlignment(tf, Alignment.BOTTOM_CENTER); hl1.addComponent(save); hl1.setExpandRatio(save, 0.0f); hl1.setComponentAlignment(save, Alignment.BOTTOM_CENTER); hl1.addComponent(remove); hl1.setExpandRatio(remove, 0.0f); hl1.setComponentAlignment(remove, Alignment.BOTTOM_CENTER); content.addComponent(hl1); content.setExpandRatio(hl1, 0.0f); table.addContainerProperty("Kartta", String.class, null); table.addContainerProperty("Oikeus", String.class, null); table.addContainerProperty("Laajuus", String.class, null); table.setWidth("100%"); table.setHeight("100%"); table.setNullSelectionAllowed(true); table.setMultiSelect(true); table.setCaption("Kyttjn oikeudet"); makeAccountTable(database, users, accountMap, table); content.addComponent(table); content.setExpandRatio(table, 1.0f); final Button removeRights = new Button("Poista valitut rivit", new Button.ClickListener() { private static final long serialVersionUID = 4699670345358079045L; public void buttonClick(ClickEvent event) { Object user = users.getValue(); Account state = accountMap.get(user); Object selection = table.getValue(); Collection<?> sel = (Collection<?>) selection; List<Right> toRemove = new ArrayList<Right>(); for (Object s : sel) { Integer index = (Integer) s; toRemove.add(state.rights.get(index - 1)); } for (Right r : toRemove) state.rights.remove(r); Updates.update(main, true); makeAccountTable(database, users, accountMap, table); } }); removeRights.addStyleName(ValoTheme.BUTTON_SMALL); table.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1188285609779556446L; @Override public void valueChange(ValueChangeEvent event) { Object selection = table.getValue(); Collection<?> sel = (Collection<?>) selection; if (sel.isEmpty()) removeRights.setEnabled(false); else removeRights.setEnabled(true); } }); final ComboBox mapSelect = new ComboBox(); mapSelect.setWidth("100%"); mapSelect.setNullSelectionAllowed(false); mapSelect.addStyleName(ValoTheme.COMBOBOX_SMALL); mapSelect.setCaption("Valitse kartta:"); for (Strategiakartta a : Strategiakartta.enumerate(database)) { mapSelect.addItem(a.uuid); mapSelect.setItemCaption(a.uuid, a.getText(database)); mapSelect.select(a.uuid); } final ComboBox rightSelect = new ComboBox(); rightSelect.setWidth("100px"); rightSelect.setNullSelectionAllowed(false); rightSelect.addStyleName(ValoTheme.COMBOBOX_SMALL); rightSelect.setCaption("Valitse oikeus:"); rightSelect.addItem("Muokkaus"); rightSelect.addItem("Luku"); rightSelect.select("Luku"); final ComboBox propagateSelect = new ComboBox(); propagateSelect.setWidth("130px"); propagateSelect.setNullSelectionAllowed(false); propagateSelect.addStyleName(ValoTheme.COMBOBOX_SMALL); propagateSelect.setCaption("Valitse laajuus:"); propagateSelect.addItem(VALITTU_KARTTA); propagateSelect.addItem(ALATASON_KARTAT); propagateSelect.select(VALITTU_KARTTA); final Button addRight = new Button("Lis rivi", new Button.ClickListener() { private static final long serialVersionUID = -4841787792917761055L; public void buttonClick(ClickEvent event) { Object user = users.getValue(); Account state = accountMap.get(user); String mapUUID = (String) mapSelect.getValue(); Strategiakartta map = database.find(mapUUID); String right = (String) rightSelect.getValue(); String propagate = (String) propagateSelect.getValue(); Right r = new Right(map, right.equals("Muokkaus"), propagate.equals(ALATASON_KARTAT)); state.rights.add(r); Updates.update(main, true); makeAccountTable(database, users, accountMap, table); } }); addRight.addStyleName(ValoTheme.BUTTON_SMALL); table.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 6439090862804667322L; @Override public void valueChange(ValueChangeEvent event) { Object selection = table.getValue(); Collection<?> selected = (Collection<?>) selection; if (!selected.isEmpty()) { removeRights.setEnabled(true); } else { removeRights.setEnabled(false); } } }); HorizontalLayout hl2 = new HorizontalLayout(); hl2.setSpacing(true); hl2.setWidth("100%"); hl2.addComponent(removeRights); hl2.setComponentAlignment(removeRights, Alignment.TOP_LEFT); hl2.setExpandRatio(removeRights, 0.0f); hl2.addComponent(addRight); hl2.setComponentAlignment(addRight, Alignment.BOTTOM_LEFT); hl2.setExpandRatio(addRight, 0.0f); hl2.addComponent(mapSelect); hl2.setComponentAlignment(mapSelect, Alignment.BOTTOM_LEFT); hl2.setExpandRatio(mapSelect, 1.0f); hl2.addComponent(rightSelect); hl2.setComponentAlignment(rightSelect, Alignment.BOTTOM_LEFT); hl2.setExpandRatio(rightSelect, 0.0f); hl2.addComponent(propagateSelect); hl2.setComponentAlignment(propagateSelect, Alignment.BOTTOM_LEFT); hl2.setExpandRatio(propagateSelect, 0.0f); content.addComponent(hl2); content.setComponentAlignment(hl2, Alignment.BOTTOM_LEFT); content.setExpandRatio(hl2, 0.0f); final VerticalLayout vl = new VerticalLayout(); final Panel p = new Panel(); p.setWidth("100%"); p.setHeight("200px"); p.setContent(vl); final TimeConfiguration tc = TimeConfiguration.getInstance(database); final TextField tf2 = new TextField(); tf2.setWidth("200px"); tf2.addStyleName(ValoTheme.TEXTFIELD_SMALL); tf2.setCaption("Strategiakartan mritysaika:"); tf2.setValue(tc.getRange()); tf2.setCursorPosition(tf.getValue().length()); tf2.setValidationVisible(true); tf2.setInvalidCommitted(true); tf2.setImmediate(true); tf2.addTextChangeListener(new TextChangeListener() { private static final long serialVersionUID = -8274588731607481635L; @Override public void textChange(TextChangeEvent event) { tf2.setValue(event.getText()); try { tf2.validate(); tc.setRange(event.getText()); updateYears(database, vl); Updates.update(main, true); } catch (InvalidValueException e) { return; } } }); tf2.addValidator(new Validator() { private static final long serialVersionUID = -4779239111120669168L; @Override public void validate(Object value) throws InvalidValueException { String s = (String) value; TimeInterval ti = TimeInterval.parse(s); long start = ti.startYear; long end = ti.endYear; if (start < 2015) throw new InvalidValueException("Alkuvuosi ei voi olla aikaisempi kuin 2015."); if (end > 2025) throw new InvalidValueException("Pttymisvuosi ei voi olla myhisempi kuin 2025."); if (end - start > 9) throw new InvalidValueException("Strategiakartta ei tue yli 10 vuoden tarkasteluja."); } }); content.addComponent(tf2); content.setComponentAlignment(tf2, Alignment.BOTTOM_LEFT); content.setExpandRatio(tf2, 0.0f); updateYears(database, vl); content.addComponent(p); content.setComponentAlignment(p, Alignment.BOTTOM_LEFT); content.setExpandRatio(p, 0.0f); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.setMargin(false); Dialogs.makeDialog(main, main.dialogWidth(), main.dialogHeight(0.8), "Hallinnoi strategiakarttaa", "Sulje", content, buttons); }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void setUserMeter(final Main main, final Base base, final Meter m) { final Database database = main.getDatabase(); final Window subwindow = new Window("Aseta mittarin arvo", new VerticalLayout()); subwindow.setModal(true);//from w w w . j ava 2 s. co m subwindow.setWidth("350px"); subwindow.setResizable(false); final VerticalLayout winLayout = (VerticalLayout) subwindow.getContent(); winLayout.setMargin(true); winLayout.setSpacing(true); String caption = m.getCaption(database); if (caption != null && !caption.isEmpty()) { final Label header = new Label(caption); header.addStyleName(ValoTheme.LABEL_LARGE); winLayout.addComponent(header); } final Indicator indicator = m.getPossibleIndicator(database); if (indicator == null) return; Datatype dt = indicator.getDatatype(database); if (!(dt instanceof EnumerationDatatype)) return; final Label l = new Label("Selite: " + indicator.getValueShortComment()); AbstractField<?> forecastField = dt.getEditor(main, base, indicator, true, new CommentCallback() { @Override public void runWithComment(String shortComment, String comment) { l.setValue("Selite: " + indicator.getValueShortComment()); } @Override public void canceled() { } }); forecastField.setWidth("100%"); forecastField.setCaption("Ennuste"); winLayout.addComponent(forecastField); AbstractField<?> currentField = dt.getEditor(main, base, indicator, false, new CommentCallback() { @Override public void runWithComment(String shortComment, String comment) { l.setValue("Selite: " + indicator.getValueShortComment()); } @Override public void canceled() { } }); currentField.setWidth("100%"); currentField.setCaption("Toteuma"); winLayout.addComponent(currentField); winLayout.addComponent(l); l.setWidth("100%"); winLayout.setComponentAlignment(l, Alignment.BOTTOM_CENTER); HorizontalLayout hl = new HorizontalLayout(); winLayout.addComponent(hl); winLayout.setComponentAlignment(hl, Alignment.BOTTOM_CENTER); Button ok = new Button("Sulje", new Button.ClickListener() { private static final long serialVersionUID = 1364802814012491490L; public void buttonClick(ClickEvent event) { main.removeWindow(subwindow); } }); Button define = new Button("Mrit", new Button.ClickListener() { private static final long serialVersionUID = 1364802814012491490L; public void buttonClick(ClickEvent event) { Meter.editMeter(main, base, m); } }); hl.addComponent(ok); hl.setComponentAlignment(ok, Alignment.BOTTOM_LEFT); hl.addComponent(define); hl.setComponentAlignment(define, Alignment.BOTTOM_LEFT); main.addWindow(subwindow); }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void saveCurrentState(final Main main) { VerticalLayout content = new VerticalLayout(); content.setSizeFull();/*from www.j a v a 2 s .co m*/ HorizontalLayout hl1 = new HorizontalLayout(); hl1.setSpacing(true); hl1.setWidth("100%"); final Map<String, UIState> stateMap = new HashMap<String, UIState>(); for (UIState s : main.account.uiStates) stateMap.put(s.name, s); final TextField tf = new TextField(); final Button save = new Button("Tallenna nkym", new Button.ClickListener() { private static final long serialVersionUID = 2449606920686729881L; public void buttonClick(ClickEvent event) { if (!tf.isValid()) return; String name = tf.getValue(); Page.getCurrent().getJavaScript().execute("doSaveBrowserState('" + name + "');"); } }); tf.setWidth("100%"); tf.addStyleName(ValoTheme.TEXTFIELD_SMALL); tf.setCaption("Tallenna nykyinen nkym nimell:"); tf.setValue("Uusi nkym"); tf.setCursorPosition(tf.getValue().length()); tf.setValidationVisible(true); tf.setInvalidCommitted(true); tf.setImmediate(true); tf.addTextChangeListener(new TextChangeListener() { private static final long serialVersionUID = -8274588731607481635L; @Override public void textChange(TextChangeEvent event) { tf.setValue(event.getText()); try { tf.validate(); } catch (InvalidValueException e) { save.setEnabled(false); return; } save.setEnabled(true); } }); tf.addValidator(new Validator() { private static final long serialVersionUID = -4779239111120669168L; @Override public void validate(Object value) throws InvalidValueException { String s = (String) value; if (s.isEmpty()) throw new InvalidValueException("Nimi ei saa olla tyhj"); if (stateMap.containsKey(s)) throw new InvalidValueException("Nimi on jo kytss"); } }); if (!tf.isValid()) save.setEnabled(false); hl1.addComponent(tf); hl1.setExpandRatio(tf, 1.0f); hl1.addComponent(save); hl1.setExpandRatio(save, 0.0f); hl1.setComponentAlignment(save, Alignment.BOTTOM_CENTER); content.addComponent(hl1); content.setExpandRatio(hl1, 0.0f); final ListSelect table = new ListSelect(); table.setWidth("100%"); table.setHeight("100%"); table.setNullSelectionAllowed(true); table.setMultiSelect(true); table.setCaption("Tallennetut nkymt"); for (UIState state : main.account.uiStates) { table.addItem(state.name); } content.addComponent(table); content.setExpandRatio(table, 1.0f); final Button remove = new Button("Poista valitut nkymt"); table.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 6439090862804667322L; @Override public void valueChange(ValueChangeEvent event) { Object selection = table.getValue(); Collection<?> selected = (Collection<?>) selection; if (!selected.isEmpty()) { remove.setEnabled(true); } else { remove.setEnabled(false); } } }); remove.setEnabled(false); content.addComponent(remove); content.setComponentAlignment(remove, Alignment.MIDDLE_LEFT); content.setExpandRatio(remove, 0.0f); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.setMargin(false); final Window dialog = Dialogs.makeDialog(main, "Nkymien hallinta", "Sulje", content, buttons); remove.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -4680588998085550908L; public void buttonClick(ClickEvent event) { Object selection = table.getValue(); Collection<?> selected = (Collection<?>) selection; if (!selected.isEmpty()) { for (Object o : selected) { UIState state = stateMap.get(o); if (state != null) main.account.uiStates.remove(state); } Updates.update(main, true); } main.removeWindow(dialog); } }); }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void fillTagEditor(final Database database, final AbstractLayout layout, final List<String> tags, final boolean allowRemove) { layout.removeAllComponents();//from ww w .j a v a 2s .co m for (int i = 0; i < tags.size(); i++) { String tag = tags.get(i); HorizontalLayout hl = new HorizontalLayout(); if (allowRemove) { final int index = i; Button b = new Button(); b.addStyleName(ValoTheme.BUTTON_BORDERLESS); b.setIcon(FontAwesome.TIMES_CIRCLE); b.addClickListener(new ClickListener() { private static final long serialVersionUID = -4473258383318654850L; @Override public void buttonClick(ClickEvent event) { tags.remove(index); fillTagEditor(database, layout, tags, allowRemove); } }); hl.addComponent(b); } Button tagButton = tagButton(database, "dialog", tag, i); hl.addComponent(tagButton); hl.setComponentAlignment(tagButton, Alignment.MIDDLE_LEFT); layout.addComponent(hl); } }
From source file:fi.semantum.strategia.Utils.java
License:Open Source License
public static void editTags(final Main main, String title, final Base container) { final Database database = main.getDatabase(); final Window subwindow = new Window(title, new VerticalLayout()); subwindow.setModal(true);// w ww .j a v a2 s .c om subwindow.setWidth("400px"); subwindow.setHeight("360px"); subwindow.setResizable(true); VerticalLayout winLayout = (VerticalLayout) subwindow.getContent(); winLayout.setMargin(true); winLayout.setSpacing(true); // Add some content; a label and a close-button final List<String> tags = new ArrayList<String>(); for (Tag t : container.getRelatedTags(database)) tags.add(t.getId(database)); final CssLayout vl = new CssLayout(); vl.setCaption("Kytss olevat aihetunnisteet:"); fillTagEditor(database, vl, tags, Account.canWrite(main, container)); winLayout.addComponent(vl); HorizontalLayout hl = new HorizontalLayout(); hl.setWidth("100%"); hl.setSpacing(true); final TagCombo combo = new TagCombo(); final CustomLazyContainer comboContainer = new CustomLazyContainer(database, combo, Tag.enumerate(database)); combo.setWidth("100%"); combo.setCaption("Uusi aihetunniste:"); combo.setInputPrompt("valitse listasta tai kirjoita"); combo.setFilteringMode(FilteringMode.STARTSWITH); combo.setTextInputAllowed(true); combo.setImmediate(true); combo.setNullSelectionAllowed(false); combo.setInvalidAllowed(true); combo.setInvalidCommitted(true); combo.setItemCaptionMode(ItemCaptionMode.PROPERTY); combo.setItemCaptionPropertyId("id"); //should set combo.setContainerDataSource(comboContainer); hl.addComponent(combo); hl.setExpandRatio(combo, 1.0f); Button add = new Button("Lis", new Button.ClickListener() { private static final long serialVersionUID = -2848576385076605664L; public void buttonClick(ClickEvent event) { String filter = (String) combo.getValue(); if (filter != null && filter.length() > 0) { Tag t = database.getOrCreateTag(filter); if (tags.contains(t.getId(database))) return; tags.add(t.getId(database)); fillTagEditor(database, vl, tags, main.account != null); combo.clear(); } } }); hl.addComponent(add); hl.setComponentAlignment(add, Alignment.BOTTOM_LEFT); hl.setExpandRatio(add, 0.0f); winLayout.addComponent(hl); Button close = new Button("Tallenna", new Button.ClickListener() { private static final long serialVersionUID = -451523776456589591L; public void buttonClick(ClickEvent event) { main.removeWindow(subwindow); List<Tag> newTags = new ArrayList<Tag>(); for (String s : tags) newTags.add(database.getOrCreateTag(s)); container.setRelatedTags(database, newTags); Updates.update(main, true); } }); Button discard = new Button("Peru muutokset", new Button.ClickListener() { private static final long serialVersionUID = -2387057110951581993L; public void buttonClick(ClickEvent event) { main.removeWindow(subwindow); } }); HorizontalLayout hl2 = new HorizontalLayout(); hl2.setSpacing(true); hl2.addComponent(close); hl2.addComponent(discard); winLayout.addComponent(hl2); winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER); main.addWindow(subwindow); }