List of usage examples for com.vaadin.ui TextField getValue
@Override
public String getValue()
From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RegistrationPagePopupSecond.java
License:Open Source License
private String checkValue(TextField tf) { Object o = tf.getValue(); boolean empty = (o == null) || (o.toString().length() <= 0); if (o.toString().equals("optional")) empty = true;//www. ja va2 s .co m return empty ? "" : o.toString(); }
From source file:eu.lod2.DeleteGraphs.java
License:Apache License
public DeleteGraphs(LOD2DemoState st) { // The internal state state = st;/*from w w w .j a v a 2s . c om*/ panel = new VerticalLayout(); Label intro = new Label( "A tabular view to ease the removal of graphs. Note: data is fetched in parts to allow dealing with " + "endpoints that have very many graphs. If the component is fetching data, a spinner is " + "shown below.", Label.CONTENT_XHTML); panel.addComponent(intro); indicator = new ProgressIndicator(); indicator.setIndeterminate(true); indicator.setPollingInterval(200); indicator.setEnabled(false); panel.addComponent(indicator); Button hideButton = new Button("Hide selected graphs", new ClickListener() { public void buttonClick(ClickEvent event) { hidegraphs(event); } }); Button markButton = new Button("Mark selected graphs", new ClickListener() { public void buttonClick(ClickEvent event) { markgraphs(event); } }); Button deleteButton = new Button("Delete marked graphs", new ClickListener() { public void buttonClick(ClickEvent event) { deletegraphs(event); } }); Button invertSelection = new Button("Invert current selection", new ClickListener() { public void buttonClick(ClickEvent clickEvent) { invertSelection(); } }); Button resetButton = new Button("Restore original view", new ClickListener() { public void buttonClick(ClickEvent event) { resetTable(); } }); HorizontalLayout buttons = new HorizontalLayout(); buttons.addComponent(markButton); buttons.addComponent(deleteButton); buttons.addComponent(hideButton); buttons.addComponent(invertSelection); buttons.addComponent(resetButton); buttons.setSpacing(true); buttons.setMargin(true); panel.addComponent(buttons); HorizontalLayout searcher = new HorizontalLayout(); searcher.addComponent(new Label("Filter: ")); final TextField filter = new TextField(); filter.setWidth("400px"); filter.setInputPrompt("Enter a filter"); searcher.addComponent(filter); filter.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.LAZY); filter.setTextChangeTimeout(200); filter.setImmediate(true); filter.addListener(new FieldEvents.TextChangeListener() { public void textChange(FieldEvents.TextChangeEvent event) { String text = event.getText(); filter.setValue(text); } }); Button filterAction = new Button("Apply filter to table"); Button filterFetchAction = new Button("Fetch matching graphs"); filterAction.addListener(new ClickListener() { public void buttonClick(ClickEvent clickEvent) { selectByFilter((String) filter.getValue(), false); } }); filterFetchAction.addListener(new ClickListener() { public void buttonClick(ClickEvent clickEvent) { fetchByFilter((String) filter.getValue()); } }); searcher.addComponent(filterFetchAction); searcher.addComponent(filterAction); searcher.setSpacing(true); searcher.setMargin(true); panel.addComponent(searcher); table = new Table(""); table.setDebugId(this.getClass().getSimpleName() + "_table"); table.setWidth("100%"); table.setSelectable(true); table.setMultiSelect(true); table.setImmediate(true); table.setColumnReorderingAllowed(true); table.setColumnCollapsingAllowed(true); this.resetTable(); panel.addComponent(table); // The composition root MUST be set setCompositionRoot(panel); }
From source file:eu.lod2.stat.dsdrepo.DSDRepoComponent.java
private void refreshContentCreateDSD(DataSet ds) { if (ds == null) { getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE); return;// w ww.j a v a 2 s .com } Structure struct = ds.getStructure(); if (struct != null) { contentLayout.addComponent(new Label("The dataset already has a DSD!")); return; } dataset = ds.getUri(); contentLayout.removeAllComponents(); dataTree = new Tree("Dataset"); dataTree.setNullSelectionAllowed(true); dataTree.setImmediate(true); dataTree.setWidth("500px"); populateDataTree(); addDataTreeListenersCreate(); contentLayout.addComponent(dataTree); contentLayout.setExpandRatio(dataTree, 0.0f); final VerticalLayout right = new VerticalLayout(); right.setSpacing(true); contentLayout.addComponent(right); contentLayout.setExpandRatio(right, 2.0f); lblUndefined = new Label("There are still x undefined components", Label.CONTENT_XHTML); right.addComponent(lblUndefined); lblMissingCodeLists = new Label("There are still y missing code lists", Label.CONTENT_XHTML); right.addComponent(lblMissingCodeLists); final TextField dsdUri = new TextField("Enter DSD URI"); dsdUri.setWidth("300px"); right.addComponent(dsdUri); final Button btnCreate = new Button("Create DSD"); right.addComponent(btnCreate); right.addComponent(new Label("<hr/>", Label.CONTENT_XHTML)); compatibleCodeLists = new Tree("Compatible code lists"); right.addComponent(compatibleCodeLists); updateUndefinedAndMissing(); compatibleCodeLists.addActionHandler(new Action.Handler() { public Action[] getActions(Object target, Object sender) { if (target == null) return null; if (compatibleCodeLists.getParent(target) != null) return null; return new Action[] { ACTION_SET_AS_CL }; } public void handleAction(Action action, Object sender, Object target) { if (action == ACTION_SET_AS_CL) { Object item = compatibleCodeLists.getData(); if (item == null) { getWindow().showNotification( "Error, the component cannot determine where to put the code list", Window.Notification.TYPE_ERROR_MESSAGE); return; } if (dataTree.getChildren(item).size() == 2) { getWindow().showNotification("The component property already has a code list", Window.Notification.TYPE_ERROR_MESSAGE); return; } try { RepositoryConnection conn = repository.getConnection(); String cl = (String) target; String prop = (String) dataTree.getValue(); GraphQuery query = conn.prepareGraphQuery(QueryLanguage.SPARQL, DSDRepoUtils.qPullCodeList(cl, prop, repoGraph, dataGraph)); query.evaluate(); getWindow().showNotification("Code List set"); addCodeListToDataTree(); updateUndefinedAndMissing(); } catch (RepositoryException ex) { Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex); getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); } catch (MalformedQueryException ex) { Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex); getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); } catch (QueryEvaluationException ex) { Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex); getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); } } } }); btnCreate.addListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { if (numUndefinedComponents > 0) { getWindow().showNotification("There can be no undefined components", Window.Notification.TYPE_ERROR_MESSAGE); return; } if (numMissingCodeLists > 0) { getWindow().showNotification("All code lists must first be created or imported", Window.Notification.TYPE_ERROR_MESSAGE); return; } final String dsd = dsdUri.getValue().toString(); if (!isUri(dsd)) { getWindow().showNotification("Enter a valid URI for the DSD", Window.Notification.TYPE_ERROR_MESSAGE); } try { RepositoryConnection conn = repository.getConnection(); LinkedList<String> dList = new LinkedList<String>(); LinkedList<String> mList = new LinkedList<String>(); LinkedList<String> aList = new LinkedList<String>(); LinkedList<String> uList = new LinkedList<String>(); LinkedList<String> propList = new LinkedList<String>(); LinkedList<String> rangeList = new LinkedList<String>(); for (Object id : dataTree.rootItemIds()) { Collection<?> children = dataTree.getChildren(id); if (children == null) continue; Collection<String> list = null; if (id.toString().startsWith("D")) list = dList; else if (id.toString().startsWith("M")) list = mList; else if (id.toString().startsWith("A")) list = aList; else if (id.toString().startsWith("U")) list = uList; for (Object prop : dataTree.getChildren(id)) { CountingTreeHeader h = (CountingTreeHeader) dataTree.getChildren(prop).iterator() .next(); propList.add(prop.toString()); list.add(prop.toString()); if (h.toString().startsWith("C")) { rangeList.add("http://www.w3.org/2004/02/skos/core#Concept"); } else { rangeList.add(dataTree.getChildren(h).iterator().next().toString()); } } } if (uList.size() > 0) { getWindow().showNotification("There are undefined properties!", Window.Notification.TYPE_WARNING_MESSAGE); return; } GraphQuery query = conn.prepareGraphQuery(QueryLanguage.SPARQL, DSDRepoUtils.qCreateDSD(dataset, dsd, dList, mList, aList, propList, rangeList, dataGraph)); query.evaluate(); getWindow().showNotification("DSD created!"); DSDRepoComponent.this.ds = new SparqlDataSet(repository, DSDRepoComponent.this.ds.getUri(), dataGraph); createDSD(); } catch (RepositoryException ex) { Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex); getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); } catch (MalformedQueryException ex) { Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex); getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); } catch (QueryEvaluationException ex) { Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex); getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE); } } }); }
From source file:facs.components.Settings.java
License:Open Source License
private void addNewDevice() { final Window subWindow = new Window("Add Device"); FormLayout form = new FormLayout(); form.setMargin(true);//w w w. j a va2 s . c om final TextField name = new TextField(); name.setImmediate(true); name.addValidator(new StringLengthValidator("The name must be 1-85 letters long (Was {0}).", 1, 85, true)); name.setCaption("Name of new device"); form.addComponent(name); final TextArea description = new TextArea(); description.setImmediate(true); description.addValidator( new StringLengthValidator("The name must be 1-255 letters long (Was {0}).", 1, 255, true)); description.setCaption("Description"); form.addComponent(description); final OptionGroup restricted = new OptionGroup("Is Device restricted by operators?"); restricted.addItem("yes"); restricted.setMultiSelect(true); form.addComponent(restricted); HorizontalLayout buttons = new HorizontalLayout(); Button save = new Button("save"); buttons.addComponent(save); Button discard = new Button("discard"); discard.setDescription("discarding will abort the process of adding a new device into the databse."); buttons.addComponent(discard); buttons.setSpacing(true); form.addComponent(buttons); subWindow.setContent(form); form.setMargin(true); form.setSpacing(true); buttons.setMargin(true); buttons.setSpacing(true); // Center it in the browser window subWindow.center(); subWindow.setModal(true); subWindow.setWidth("50%"); // Open it in the UI UI.getCurrent().addWindow(subWindow); discard.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = -5808910314649620731L; @Override public void buttonClick(ClickEvent event) { subWindow.close(); } }); save.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = 3748395242651585005L; @Override public void buttonClick(ClickEvent event) { if (name.isValid() && description.isValid()) { Set<String> restr = (Set<String>) restricted.getValue(); int deviceId = DBManager.getDatabaseInstance().addDevice(name.getValue(), description.getValue(), (restr.size() == 1)); DeviceBean bean = new DeviceBean(deviceId, name.getValue(), description.getValue(), (restr.size() == 1)); devicesGrid.addRow(bean); } else { Notification.show("Failed to add device to database."); } } }); // DeviceBean db = new DeviceBean(0, "Device 1","some description1", false); // TODO // add to database /* * boolean added = false;//DBManager.getDatabaseInstance().addDevice(db); //TODO test //add to * grid if(added){ devicesGrid.addRow(db); }else{ //TODO log failed operation * Notification.show("Failed to add device to database.", Type.ERROR_MESSAGE); } */ }
From source file:fi.jasoft.remoteconnection.ServerExampleUI.java
License:Apache License
private void buildUI() { FormLayout vl = new FormLayout(); setContent(vl);/*from ww w . j av a 2s .co m*/ // Our id myId = new Label("Connecting..."); myId.setCaption("My id:"); vl.addComponent(myId); // Remote id final TextField remoteId = new TextField(); remoteId.setWidth("100%"); NativeButton connectToRemote = new NativeButton("Connect", new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { final RemoteChannel channel = peer.openChannel(remoteId.getValue()); channel.addConnectedListener(new ConnectedListener() { @Override public void connected(String channelId) { remoteId.setReadOnly(true); event.getButton().setVisible(false); Notification.show("Connected to " + channelId, Type.TRAY_NOTIFICATION); } }); } }); HorizontalLayout hl = new HorizontalLayout(remoteId, connectToRemote); hl.setExpandRatio(remoteId, 1); hl.setWidth("100%"); hl.setCaption("Remote id: "); vl.addComponent(hl); // Message display where messages are displayed messages = new TextArea(); messages.setWidth("100%"); vl.addComponent(messages); // Message field final TextField message = new TextField(); message.setWidth("100%"); NativeButton send = new NativeButton("Send", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { // Show message in message window messages.setValue( messages.getValue() + peer.getConfiguration().getId() + " >> " + message.getValue() + "\n"); // Broadcast the message to all connected peers peer.broadcast(message.getValue()); message.setValue(""); } }); hl = new HorizontalLayout(message, send); hl.setExpandRatio(message, 1); hl.setWidth("100%"); hl.setCaption("Send message: "); vl.addComponent(hl); }
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;/* w w w.j ava2 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.Utils.java
License:Open Source License
public static void modifyAccount(final Main main) { final Database database = main.getDatabase(); FormLayout content = new FormLayout(); content.setSizeFull();/*ww w . j av a 2 s .c o m*/ final Label l = new Label(main.account.getId(database)); l.setCaption("Kyttjn nimi:"); l.setWidth("100%"); content.addComponent(l); final TextField tf = new TextField(); tf.setWidth("100%"); tf.addStyleName(ValoTheme.TEXTFIELD_SMALL); tf.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); tf.setCaption("Kyttjn nimi:"); tf.setId("loginUsernameField"); tf.setValue(main.account.getText(database)); content.addComponent(tf); final TextField tf2 = new TextField(); tf2.setWidth("100%"); tf2.addStyleName(ValoTheme.TEXTFIELD_SMALL); tf2.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); tf2.setCaption("Shkpostiosoite:"); tf2.setId("loginUsernameField"); tf2.setValue(main.account.getEmail()); content.addComponent(tf2); final PasswordField pf = new PasswordField(); pf.setCaption("Vanha salasana:"); pf.addStyleName(ValoTheme.TEXTFIELD_SMALL); pf.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); pf.setWidth("100%"); pf.setId("loginPasswordField"); content.addComponent(pf); final PasswordField pf2 = new PasswordField(); pf2.setCaption("Uusi salasana:"); pf2.addStyleName(ValoTheme.TEXTFIELD_SMALL); pf2.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); pf2.setWidth("100%"); pf2.setId("loginPasswordField"); content.addComponent(pf2); final PasswordField pf3 = new PasswordField(); pf3.setCaption("Uusi salasana uudestaan:"); pf3.addStyleName(ValoTheme.TEXTFIELD_SMALL); pf3.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); pf3.setWidth("100%"); pf3.setId("loginPasswordField"); content.addComponent(pf3); final Label err = new Label("Vr kyttjtunnus tai salasana"); err.addStyleName(ValoTheme.LABEL_FAILURE); err.addStyleName(ValoTheme.LABEL_TINY); err.setVisible(false); content.addComponent(err); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.setMargin(false); Button apply = new Button("Tee muutokset"); buttons.addComponent(apply); final Window dialog = Dialogs.makeDialog(main, "450px", "480px", "Kyttjtilin asetukset", "Poistu", content, buttons); apply.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1992235622970234624L; public void buttonClick(ClickEvent event) { String valueHash = Utils.hash(pf.getValue()); if (!valueHash.equals(main.account.getHash())) { err.setValue("Vr salasana"); err.setVisible(true); return; } if (pf2.isEmpty()) { err.setValue("Tyhj salasana ei kelpaa"); err.setVisible(true); return; } if (!pf2.getValue().equals(pf3.getValue())) { err.setValue("Uudet salasanat eivt tsm"); err.setVisible(true); return; } main.account.text = tf.getValue(); main.account.email = tf2.getValue(); main.account.hash = Utils.hash(pf2.getValue()); Updates.update(main, true); main.removeWindow(dialog); } }); }
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();//from w ww. ja v a2 s.com 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 saveCurrentState(final Main main) { VerticalLayout content = new VerticalLayout(); content.setSizeFull();/* ww w .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 addMap(final Main main, final Strategiakartta parent) { final Database database = main.getDatabase(); FormLayout content = new FormLayout(); content.setSizeFull();/*from w ww .ja v a 2 s . c o m*/ // final TextField tf = new TextField(); // tf.setCaption("Kartan tunniste:"); // tf.setValue("tunniste"); // tf.setWidth("100%"); // content.addComponent(tf); final TextField tf2 = new TextField(); tf2.setCaption("Kartan nimi:"); tf2.setValue("Uusi kartta"); tf2.setWidth("100%"); content.addComponent(tf2); final ComboBox combo = new ComboBox(); combo.setCaption("Kartan tyyppi:"); combo.setNullSelectionAllowed(false); combo.setWidth("100%"); content.addComponent(combo); Collection<Base> subs = Strategiakartta.availableLevels(database); for (Base b : subs) { combo.addItem(b.uuid); combo.setItemCaption(b.uuid, b.getText(database)); combo.select(b.uuid); } HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.setMargin(true); Button ok = new Button("Lis"); buttons.addComponent(ok); final Window dialog = Dialogs.makeDialog(main, "450px", "340px", "Lis alatason kartta", "Peruuta", content, buttons); ok.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 1422158448876521843L; public void buttonClick(ClickEvent event) { String name = tf2.getValue(); String typeUUID = (String) combo.getValue(); Base type = database.find(typeUUID); database.newMap(main, parent, "", name, type); Updates.updateJS(main, true); main.removeWindow(dialog); } }); }