List of usage examples for com.vaadin.ui VerticalLayout 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 ww. j ava 2 s . c o m*/ 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.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { Panel showcase = new Panel(); showcase.setSizeUndefined();/*from w w w. j a v a 2s .co m*/ navigator = new Navigator(this, showcase); for (DemoView view : views) { navigator.addView(view.getViewPath(), view); } // default openView(views.get(0)); MenuBar demos = new MenuBar(); demos.setStyleName(ValoTheme.MENUBAR_BORDERLESS); for (final DemoView view : views) { demos.addItem(view.getViewCaption(), new Command() { @Override public void menuSelected(MenuItem selectedItem) { openView(view); } }); } VerticalLayout root = new VerticalLayout(demos, showcase); root.setSizeFull(); root.setExpandRatio(showcase, 1); root.setComponentAlignment(showcase, Alignment.MIDDLE_CENTER); setContent(root); HorizontalLayout sourceWrapperLayout = new HorizontalLayout(); Label caption = new Label("Source code for example"); caption.setStyleName("source-caption"); sourceWrapperLayout.addComponent(caption); Panel sourceWrapper = new Panel(codeLabel); sourceWrapper.setStyleName(ValoTheme.PANEL_BORDERLESS); sourceWrapper.setHeight(getPage().getBrowserWindowHeight() + "px"); sourceWrapperLayout.addComponent(sourceWrapper); sourceWrapperLayout.setExpandRatio(sourceWrapper, 1); Toolbox sourceBox = new Toolbox(); sourceBox.setOrientation(ORIENTATION.RIGHT_CENTER); sourceBox.setContent(sourceWrapperLayout); sourceBox.setOverflowSize(30); root.addComponent(sourceBox); }
From source file:fi.jasoft.feedreader.ui.AddFeedWindow.java
License:Apache License
/** * Default constructor/*from ww w.j a v a 2s.c om*/ */ public AddFeedWindow() { setModal(true); setWidth("300px"); setHeight("100px"); setResizable(false); setDraggable(false); setCaption("Add RSS/Atom Feed"); VerticalLayout windowContent = new VerticalLayout(); windowContent.setSpacing(true); windowContent.setMargin(true); windowContent.setSizeFull(); setContent(windowContent); url = new TextField("Feed url"); url.setWidth("100%"); windowContent.addComponent(url); windowContent.setComponentAlignment(url, Alignment.MIDDLE_CENTER); HorizontalLayout buttons = new HorizontalLayout(); buttons.addComponent(new Button("Add", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (validateUrl(url.getValue())) { close(); } else { Notification.show("URL not valid"); } } })); buttons.addComponent(new Button("Cancel", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { url.setValue(null); close(); } })); windowContent.addComponent(buttons); windowContent.setComponentAlignment(buttons, Alignment.BOTTOM_RIGHT); windowContent.setExpandRatio(url, 1); }
From source file:fi.jasoft.qrcode.demo.QRCodeDemo.java
License:Apache License
@Override protected void init(VaadinRequest request) { VerticalLayout content = new VerticalLayout(); content.setSizeFull();/*from w w w . ja v a 2 s . c om*/ setContent(content); Label header = new Label("QR Code Generator"); header.setStyleName(ValoTheme.LABEL_H2); content.addComponent(header); HorizontalSplitPanel root = new HorizontalSplitPanel(); root.setSizeFull(); root.setSplitPosition(50, Unit.PERCENTAGE); root.setLocked(true); Panel panel = new Panel(root); panel.setSizeFull(); content.addComponent(panel); content.setExpandRatio(panel, 1); VerticalLayout first = new VerticalLayout(); first.setSizeFull(); root.setFirstComponent(first); first.addComponent( new HorizontalLayout(createPrimaryColorSelect(), createSecondaryColorSelect(), createSizeSelect())); code = new QRCode(); code.setWidth("100px"); code.setHeight("100px"); final TextArea text = new TextArea("Text embedded in QR Code"); text.setPlaceholder("Type the message of the QR code here"); text.setSizeFull(); text.setValueChangeMode(ValueChangeMode.LAZY); text.addValueChangeListener(e -> { code.setValue(e.getValue()); }); first.addComponent(text); first.setExpandRatio(text, 1); VerticalLayout vl = new VerticalLayout(); vl.setSizeFull(); vl.addComponent(code); vl.setComponentAlignment(code, Alignment.MIDDLE_CENTER); root.setSecondComponent(vl); }
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();//ww w .j a va2 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);/*w w w . j a v a 2 s.c om*/ 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 w w w .ja v a2 s. c o 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 editTextAndId(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 a 2 s .co m*/ subwindow.setWidth("400px"); subwindow.setHeight("500px"); subwindow.setResizable(false); VerticalLayout winLayout = (VerticalLayout) subwindow.getContent(); winLayout.setMargin(true); winLayout.setSpacing(true); final TextField tf = new TextField(); tf.setCaption("Lyhytnimi:"); tf.addStyleName(ValoTheme.TEXTFIELD_SMALL); tf.setValue(container.getId(database)); tf.setWidth("100%"); winLayout.addComponent(tf); final TextArea ta = new TextArea(); ta.setCaption("Teksti:"); ta.setValue(container.getText(database)); ta.setWidth("100%"); ta.setHeight("290px"); winLayout.addComponent(ta); Button save = new Button("Tallenna", new Button.ClickListener() { private static final long serialVersionUID = 6641880870005364983L; public void buttonClick(ClickEvent event) { String idValue = tf.getValue(); String value = ta.getValue(); main.removeWindow(subwindow); container.modifyId(main, idValue); container.modifyText(main, value); Collection<String> tags = Tag.extractTags(value); database.assertTags(tags); ArrayList<Tag> tagObjects = new ArrayList<Tag>(); for (String s : tags) tagObjects.add(database.getOrCreateTag(s)); container.assertRelatedTags(database, tagObjects); Updates.update(main, true); Property emails = Property.find(database, Property.EMAIL); String addr = emails.getPropertyValue(container); if (addr != null && !addr.isEmpty()) { String[] addrs = addr.split(","); if (addrs.length > 0) { try { Email.send(addrs, "Muutos strategiakartassa: " + container.getId(database), "Kyttj " + main.account.getId(database) + " on muuttanut strategiakarttaa.<br/><br/>Lyhytnimi: " + container.getId(database) + "<br/><br/>Teksti: " + container.getText(database)); } catch (MessagingException e) { e.printStackTrace(); } } } } }); Button discard = new Button("Peru muutokset", new Button.ClickListener() { private static final long serialVersionUID = -784522457615993823L; public void buttonClick(ClickEvent event) { Updates.update(main, true); main.removeWindow(subwindow); } }); HorizontalLayout hl2 = new HorizontalLayout(); hl2.setSpacing(true); hl2.addComponent(save); hl2.addComponent(discard); winLayout.addComponent(hl2); winLayout.setComponentAlignment(hl2, Alignment.MIDDLE_CENTER); main.addWindow(subwindow); ta.setCursorPosition(ta.getValue().length()); }
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);// www . ja v a 2 s .c o m 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); }
From source file:fi.semantum.strategia.widget.Indicator.java
License:Open Source License
public static void manageIndicators(final Main main, final Base base) { String currentTime = main.getUIState().time; boolean showYears = currentTime.equals(Property.AIKAVALI_KAIKKI); final Database database = main.getDatabase(); VerticalLayout content = new VerticalLayout(); content.setSizeFull();/*from w ww . j a v a 2 s . c o m*/ content.setSpacing(true); final Table table = new Table(); table.setSelectable(true); table.setMultiSelect(true); table.addStyleName(ValoTheme.TABLE_SMALL); table.addStyleName(ValoTheme.TABLE_COMPACT); table.addContainerProperty("Indikaattori", Label.class, null); if (showYears) table.addContainerProperty("Vuosi", String.class, null); table.setWidth("100%"); table.setHeight("100%"); table.setNullSelectionAllowed(true); table.setEditable(false); table.setColumnExpandRatio("Indikaattori", 2.0f); if (showYears) table.setColumnExpandRatio("Vuosi", 0.0f); makeIndicatorTable(main, base, table); content.addComponent(table); content.setExpandRatio(table, 1.0f); abstract class IndicatorButtonListener implements Button.ClickListener { private static final long serialVersionUID = -7551250112503063540L; protected Indicator getPossibleSelection() { Object selection = table.getValue(); Collection<?> selected = (Collection<?>) selection; if (selected.size() != 1) return null; return (Indicator) selected.iterator().next(); } @SuppressWarnings("unchecked") protected Collection<Indicator> getSelection() { return (Collection<Indicator>) table.getValue(); } protected Map<Base, List<Indicator>> getSelectionByParent(Database database) { return indicatorsByParent(database, getSelection()); } } final Button removeIndicators = new Button("Poista", new IndicatorButtonListener() { private static final long serialVersionUID = -2538054127519468282L; public void buttonClick(ClickEvent event) { Collection<Indicator> selection = getSelection(); for (Indicator i : selection) { Base owner = i.getOwner(database); if (owner == null) continue; owner.removeIndicator(i); } final Set<Base> bases = new HashSet<Base>(); final Strategiakartta map = database.getMap(base); bases.add(map); for (Tavoite t : map.tavoitteet) { bases.add(t); for (Painopiste p : t.painopisteet) { bases.add(p); } } for (Base b : bases) { for (Meter meter : b.getMeters(database)) { Indicator indicator = meter.getPossibleIndicator(database); if (selection.contains(indicator)) { b.removeMeter(meter); } } } makeIndicatorTable(main, base, table); Updates.update(main, true); } }); removeIndicators.addStyleName(ValoTheme.BUTTON_TINY); final Button moveUp = new Button("Siirr ylemms", new IndicatorButtonListener() { private static final long serialVersionUID = -635232943884881464L; public void buttonClick(ClickEvent event) { for (Map.Entry<Base, List<Indicator>> entry : getSelectionByParent(database).entrySet()) { entry.getKey().moveIndicatorsUp(entry.getValue()); } makeIndicatorTable(main, base, table); Updates.update(main, true); } }); moveUp.addStyleName(ValoTheme.BUTTON_TINY); final Button moveDown = new Button("Siirr alemmas", new IndicatorButtonListener() { private static final long serialVersionUID = 2779521990166604444L; public void buttonClick(ClickEvent event) { for (Map.Entry<Base, List<Indicator>> entry : getSelectionByParent(database).entrySet()) { entry.getKey().moveIndicatorsDown(entry.getValue()); } makeIndicatorTable(main, base, table); Updates.update(main, true); } }); moveDown.addStyleName(ValoTheme.BUTTON_TINY); final Button modify = new Button("Mrit"); modify.addClickListener(new IndicatorButtonListener() { private static final long serialVersionUID = 5149432436059288486L; public void buttonClick(ClickEvent event) { Indicator indicator = getPossibleSelection(); if (indicator == null) return; editIndicator(main, base, indicator); } }); modify.addStyleName(ValoTheme.BUTTON_TINY); final TextField indicatorText = new TextField(); indicatorText.setWidth("100%"); indicatorText.addStyleName(ValoTheme.TEXTFIELD_TINY); indicatorText.setCaption("Tunniste"); List<Datatype> types = Datatype.enumerate(database); final ComboBox datatypeSelect = new ComboBox(); datatypeSelect.setWidth("100%"); datatypeSelect.setNullSelectionAllowed(false); datatypeSelect.addStyleName(ValoTheme.COMBOBOX_TINY); datatypeSelect.setCaption("Tietotyyppi"); for (Datatype dt : types) datatypeSelect.addItem(dt); final Button addIndicator = new Button("Lis ptasolle", new Button.ClickListener() { private static final long serialVersionUID = -2395147866745115337L; public void buttonClick(ClickEvent event) { String text = indicatorText.getValue(); Object dt = datatypeSelect.getValue(); if (text.isEmpty() || dt == null || dt.equals(datatypeSelect.getNullSelectionItemId())) return; base.addIndicator(Indicator.create(database, text, (Datatype) dt)); makeIndicatorTable(main, base, table); Updates.update(main, true); } }); addIndicator.addStyleName(ValoTheme.BUTTON_TINY); final Button addSubIndicator = new Button("Lis valitun alle", new IndicatorButtonListener() { private static final long serialVersionUID = -2395147866745115337L; public void buttonClick(ClickEvent event) { Indicator indicator = getPossibleSelection(); if (indicator == null) return; String text = indicatorText.getValue(); Object dt = datatypeSelect.getValue(); if (text.isEmpty() || dt == null || dt.equals(datatypeSelect.getNullSelectionItemId())) return; indicator.addIndicator(Indicator.create(database, text, (Datatype) dt)); makeIndicatorTable(main, base, table); Updates.update(main, true); } }); addSubIndicator.addStyleName(ValoTheme.BUTTON_TINY); final Runnable setStates = new Runnable() { @Override public void run() { Object selection = table.getValue(); Collection<?> selected = (Collection<?>) selection; if (!selected.isEmpty()) { removeIndicators.setEnabled(true); moveUp.setEnabled(true); moveDown.setEnabled(true); if (selected.size() == 1) { modify.setEnabled(true); addSubIndicator.setEnabled(true); } else { addSubIndicator.setEnabled(false); modify.setEnabled(false); } } else { moveUp.setEnabled(false); moveDown.setEnabled(false); removeIndicators.setEnabled(false); addSubIndicator.setEnabled(false); modify.setEnabled(false); } } }; table.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 1188285609779556446L; @Override public void valueChange(ValueChangeEvent event) { setStates.run(); } }); setStates.run(); HorizontalLayout hl2 = new HorizontalLayout(); hl2.setSpacing(true); hl2.setWidthUndefined(); hl2.addComponent(modify); hl2.setComponentAlignment(modify, Alignment.BOTTOM_LEFT); hl2.setExpandRatio(modify, 0.0f); hl2.addComponent(removeIndicators); hl2.setComponentAlignment(removeIndicators, Alignment.BOTTOM_LEFT); hl2.setExpandRatio(removeIndicators, 0.0f); hl2.addComponent(moveUp); hl2.setComponentAlignment(moveUp, Alignment.TOP_LEFT); hl2.setExpandRatio(moveUp, 0.0f); hl2.addComponent(moveDown); hl2.setComponentAlignment(moveDown, Alignment.TOP_LEFT); hl2.setExpandRatio(moveDown, 0.0f); HorizontalLayout hl3 = new HorizontalLayout(); hl3.setSpacing(true); hl3.setWidth("100%"); hl3.addComponent(addIndicator); hl3.setComponentAlignment(addIndicator, Alignment.BOTTOM_LEFT); hl3.setExpandRatio(addIndicator, 0.0f); hl3.addComponent(addSubIndicator); hl3.setComponentAlignment(addSubIndicator, Alignment.BOTTOM_LEFT); hl3.setExpandRatio(addSubIndicator, 0.0f); hl3.addComponent(indicatorText); hl3.setComponentAlignment(indicatorText, Alignment.BOTTOM_LEFT); hl3.setExpandRatio(indicatorText, 1.0f); hl3.addComponent(datatypeSelect); hl3.setComponentAlignment(datatypeSelect, Alignment.BOTTOM_LEFT); hl3.setExpandRatio(datatypeSelect, 2.0f); content.addComponent(hl2); content.setComponentAlignment(hl2, Alignment.BOTTOM_LEFT); content.setExpandRatio(hl2, 0.0f); content.addComponent(hl3); content.setComponentAlignment(hl3, Alignment.BOTTOM_LEFT); content.setExpandRatio(hl3, 0.0f); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.setMargin(false); final Window dialog = Dialogs.makeDialog(main, "650px", "800px", "Hallitse indikaattoreita", "Sulje", content, buttons); }