List of usage examples for com.vaadin.ui TextField addFocusListener
@Override
public Registration addFocusListener(FocusListener listener)
From source file:com.esofthead.mycollab.vaadin.ui.ShortcutExtension.java
License:Open Source License
public static TextField installShortcutAction(final TextField textField, final ShortcutListener listener) { textField.addFocusListener(new FieldEvents.FocusListener() { @Override/* www . jav a2 s. com*/ public void focus(FieldEvents.FocusEvent focusEvent) { textField.addShortcutListener(listener); } }); textField.addBlurListener(new FieldEvents.BlurListener() { @Override public void blur(FieldEvents.BlurEvent blurEvent) { textField.removeShortcutListener(listener); } }); return textField; }
From source file:com.mycollab.vaadin.web.ui.ShortcutExtension.java
License:Open Source License
public static TextField installShortcutAction(final TextField textField, final ShortcutListener listener) { textField.addFocusListener(focusEvent -> textField.addShortcutListener(listener)); textField.addBlurListener(blurEvent -> textField.removeShortcutListener(listener)); return textField; }
From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java
License:Apache License
@Override public void build() { setEditable(true);/*from w ww . jav a 2 s . co m*/ setSizeFull(); // retrieve the rows to display final List<V> parentCollection = getParentCollection(); addContainerProperties(); int nrOfProperties = getContainerPropertyIds().size(); String[] sumColumns = getSumColumns(); // adds a style generator that highlights the parent rows in bold setCellStyleGenerator(new CellStyleGenerator() { @Override public String getStyle(Table source, Object itemId, Object propertyId) { if (itemId.toString().startsWith(PREFIX_PARENTROW)) { return "parentRow"; } else { return getCustomStyle(itemId, propertyId); } } }); // custom field factory for creating editable fields for certain // properties this.setTableFieldFactory(new TableFieldFactory() { private boolean editAllowed = isEditAllowed(); @Override public Field<?> createField(Container container, Object itemId, final Object propertyId, Component uiContext) { if (!isViewMode() && editAllowed && isEditable(propertyId.toString()) && itemId.toString().startsWith(PREFIX_CHILDROW)) { final TextField tf = new TextField(); tf.setData(itemId); tf.setNullRepresentation(""); tf.setNullSettingAllowed(true); // set the appropriate converter tf.setConverter(createConverter(propertyId.toString())); tf.addFocusListener(new FocusListener() { @Override public void focus(FocusEvent event) { clickedColumn = propertyId.toString(); } }); // add a value change listener (for responding to paste // events and normal changes) tf.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) { if (propagateChanges) { handleChange(tf, propertyId.toString(), (String) event.getProperty().getValue()); } } }); // align all text field to the right tf.setStyleName(DynamoConstants.CSS_NUMERICAL); postProcessField(propertyId, itemId, tf); return tf; } return null; } }); int parentCounter = 0; int childCounter = 0; // footer sums Map<String, BigDecimal> totalSumMap = new HashMap<>(); for (String s : sumColumns) { totalSumMap.put(s, BigDecimal.ZERO); } for (V v : parentCollection) { // sum on the parent level Map<String, BigDecimal> sumMap = new HashMap<>(); for (String s : sumColumns) { sumMap.put(s, BigDecimal.ZERO); } Object[] parentRow = new Object[nrOfProperties]; fillParentRow(parentRow, v); Object parentId = this.addItem(parentRow, PREFIX_PARENTROW + parentCounter); this.setChildrenAllowed(parentId, true); this.setCollapsed(parentId, false); List<U> rowCollection = getRowCollection(v); for (U u : rowCollection) { Object[] childRow = new Object[nrOfProperties]; fillChildRow(childRow, u, v); // add the child and set the connection to the parent Object childId = this.addItem(childRow, PREFIX_CHILDROW + childCounter); this.setParent(childId, parentId); this.setChildrenAllowed(childId, false); // update the sum columns on the parent level for (String column : sumColumns) { Number value = (Number) this.getItem(childId).getItemProperty(column).getValue(); BigDecimal sum = sumMap.get(column); sumMap.put(column, sum.add(value == null ? BigDecimal.ZERO : toBigDecimal(value))); } childCounter++; } // set the sum on the parent level and update the grand total for (String s : sumColumns) { BigDecimal sum = sumMap.get(s); this.getItem(parentId).getItemProperty(s).setValue(convertNumber(sum, s)); BigDecimal totalSum = totalSumMap.get(s); totalSumMap.put(s, totalSum.add(sum)); } parentCounter++; } // update the footer sums for (String column : sumColumns) { BigDecimal bd = totalSumMap.get(column); this.setColumnFooter(column, convertToString(bd, column)); } setFooterVisible(true); // right align certain columns for (Object propertyId : this.getContainerPropertyIds()) { if (isRightAligned(propertyId.toString())) { this.setColumnAlignment(propertyId, Table.Align.RIGHT); } } // respond to a click by storing the column ID this.addItemClickListener(new ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { if (MouseButton.RIGHT.equals(event.getButton())) { clickedColumn = (String) event.getPropertyId(); } } }); if (isShowActionMenu()) { constructActionMenu(parentCollection); } }
From source file:com.peergreen.example.webconsole.extensions.NotifierExtension.java
License:Open Source License
@PostConstruct public void init() { HorizontalLayout row = new HorizontalLayout(); row.setWidth("100%"); Button simpleButton = new Button("Click to create a notification !"); final Random random = new Random(); simpleButton.addClickListener(new Button.ClickListener() { @Override/*from w w w. j a va 2s. c o m*/ public void buttonClick(Button.ClickEvent clickEvent) { notifierService.addNotification(MESSAGES[random.nextInt(MESSAGES.length)]); } }); simpleButton.setWidth("400px"); row.addComponent(simpleButton); row.setComponentAlignment(simpleButton, Alignment.BOTTOM_LEFT); final TextField customNotification = new TextField(); customNotification.setCaption("Write something and type enter"); final ShortcutListener addNotification = new ShortcutListener("Execute", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object o, Object o2) { notifierService.addNotification(customNotification.getValue()); customNotification.setValue(""); } }; customNotification.addFocusListener(new FieldEvents.FocusListener() { @Override public void focus(FieldEvents.FocusEvent focusEvent) { customNotification.addShortcutListener(addNotification); } }); customNotification.addBlurListener(new FieldEvents.BlurListener() { @Override public void blur(FieldEvents.BlurEvent blurEvent) { customNotification.removeShortcutListener(addNotification); } }); customNotification.setWidth("400px"); row.addComponent(customNotification); addComponent(row); setExpandRatio(row, 1.5f); }
From source file:com.peergreen.webconsole.scope.system.internal.shell.ShellConsoleView.java
License:Open Source License
private void initConsole() { Table table = new Table(); table.addStyleName("console-font"); table.addStyleName("borderless"); table.setColumnHeaderMode(Table.ColumnHeaderMode.HIDDEN); IndexedContainer container = new IndexedContainer(); table.setContainerDataSource(container); table.setImmediate(true);// w ww . j a v a2 s. c o m table.setSizeFull(); table.addContainerProperty("line", Label.class, null); addComponent(table); // Magic number: use all the empty space setExpandRatio(table, 1.5f); OutputStream out = new HtmlAnsiOutputStream(new WebConsoleOutputStream(table, container)); this.printStream = new PrintStream(out); session = processor.createSession(new ByteArrayInputStream("".getBytes()), printStream, printStream); final TextField input = new TextField(); input.setWidth("100%"); input.setInputPrompt(">$ "); final ShortcutListener shortcut = new ShortcutListener("Execute", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { try { String value = input.getValue(); printStream.printf(">$ %s\n", value); Object result = session.execute(value); //session.put(Constants.LAST_RESULT_VARIABLE, result); if (result != null) { session.getConsole().println(session.format(result, Converter.INSPECT)); } } catch (Exception e) { printException(printStream, e); } input.setValue(""); } }; // Install the shortcut listener only when the input text-field has the focus input.addFocusListener(new FieldEvents.FocusListener() { @Override public void focus(final FieldEvents.FocusEvent event) { input.addShortcutListener(shortcut); } }); input.addBlurListener(new FieldEvents.BlurListener() { @Override public void blur(final FieldEvents.BlurEvent event) { input.removeShortcutListener(shortcut); } }); addComponent(input); doSessionBranding(printStream); }
From source file:cz.zcu.pia.social.network.frontend.handlers.OnEnterKeyHandler.java
public void installOn(final TextField component) { component.addFocusListener(new FieldEvents.FocusListener() { @Override//from ww w .j a va 2s . c o m public void focus(FieldEvents.FocusEvent event) { component.addShortcutListener(enterShortCut); } }); component.addBlurListener(new FieldEvents.BlurListener() { @Override public void blur(FieldEvents.BlurEvent event) { component.removeShortcutListener(enterShortCut); } }); }
From source file:de.metas.ui.web.vaadin.listeners.OnEnterKeyHandler.java
License:Open Source License
public void installOn(final TextField component) { component.addFocusListener(new FieldEvents.FocusListener() { private static final long serialVersionUID = 1L; @Override/*from w ww . java2s. co m*/ public void focus(FieldEvents.FocusEvent event) { component.addShortcutListener(enterShortCut); } }); component.addBlurListener(new FieldEvents.BlurListener() { private static final long serialVersionUID = 1L; @Override public void blur(FieldEvents.BlurEvent event) { component.removeShortcutListener(enterShortCut); } }); }
From source file:dhbw.clippinggorilla.userinterface.views.GroupView.java
public GroupView() { User user = UserUtils.getCurrent();//from ww w . j a va 2s.c o m Set<Group> groups = UserUtils.getAllGroups(user); CssLayout newGroupGroup = new CssLayout(); newGroupGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldNewGroupName = new TextField(); Language.setCustom(Word.GROUP_NAME, s -> textFieldNewGroupName.setPlaceholder(s)); textFieldNewGroupName.setWidth("260px"); textFieldNewGroupName.setMaxLength(255); newGroupGroup.addComponent(textFieldNewGroupName); Button buttonNewGroup = new Button(); buttonNewGroup.setIcon(VaadinIcons.PLUS); buttonNewGroup.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonNewGroup.addClickListener(e -> { TabSheet.Tab newTab = accordion.addTab(createTab(createEmptyGroup(textFieldNewGroupName.getValue())), textFieldNewGroupName.getValue()); accordion.setSelectedTab(newTab); accordion.setWidth("100%"); textFieldNewGroupName.clear(); }); newGroupGroup.addComponent(buttonNewGroup); textFieldNewGroupName .addFocusListener(f -> buttonNewGroup.setClickShortcut(ShortcutAction.KeyCode.ENTER, null)); textFieldNewGroupName.addBlurListener(f -> buttonNewGroup.removeClickShortcut()); groups.forEach(g -> { accordion.addTab(createTab(g), g.getName()); }); addComponents(newGroupGroup, accordion); //SESSIONS.put(user, this); }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
public InterestProfileView() { User user = UserUtils.getCurrent();/* w w w .j av a 2 s. c o m*/ Set<InterestProfile> profiles = UserUtils.getAllInterestProfiles(user); CssLayout newProfileGroup = new CssLayout(); newProfileGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldNewProfileName = new TextField(); Language.setCustom(Word.PROFILE_NAME, s -> textFieldNewProfileName.setPlaceholder(s)); textFieldNewProfileName.setWidth("260px"); textFieldNewProfileName.setMaxLength(255); newProfileGroup.addComponent(textFieldNewProfileName); Button buttonNewProfile = new Button(); buttonNewProfile.setIcon(VaadinIcons.PLUS); buttonNewProfile.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonNewProfile.addClickListener(e -> { Tab newTab = accordion.addTab(createTab(createEmptyProfile(textFieldNewProfileName.getValue())), textFieldNewProfileName.getValue()); accordion.setSelectedTab(newTab); accordion.setWidth("100%"); textFieldNewProfileName.clear(); }); newProfileGroup.addComponent(buttonNewProfile); textFieldNewProfileName .addFocusListener(f -> buttonNewProfile.setClickShortcut(ShortcutAction.KeyCode.ENTER, null)); textFieldNewProfileName.addBlurListener(f -> buttonNewProfile.removeClickShortcut()); profiles.forEach((InterestProfile profile) -> { accordion.addTab(createTab(profile), profile.getName()); }); addComponents(newProfileGroup, accordion); SESSIONS.put(user, this); }
From source file:dhbw.clippinggorilla.userinterface.views.InterestProfileView.java
private Component getAddTagGroup(InterestProfile profile, boolean included) { CssLayout newTagGroup = new CssLayout(); newTagGroup.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP); TextField textFieldTag = new TextField(); textFieldTag.setWidth("325px"); textFieldTag.setMaxLength(255);//w w w . ja v a2 s.com Language.setCustom(Word.NEW_TAG, s -> textFieldTag.setPlaceholder(s)); Button buttonAddTag = new Button(VaadinIcons.PLUS); buttonAddTag.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonAddTag.addClickListener(event -> { addRow(profile, included, textFieldTag.getValue()); profile.getTags().put(textFieldTag.getValue(), included); textFieldTag.clear(); }); textFieldTag.addFocusListener(f -> buttonAddTag.setClickShortcut(ShortcutAction.KeyCode.ENTER, null)); textFieldTag.addBlurListener(f -> buttonAddTag.removeClickShortcut()); newTagGroup.addComponents(textFieldTag, buttonAddTag); newTagGroup.setWidth("100%"); return newTagGroup; }