Directory

← Back

AdvancedTokenField Add-on

An advanced and modern looking Tokenfield.

Author

Rating

Popularity

<100

This Tokenfield can be used to display the user informations via "Tags/Tokens". Today this is commonly used to show categories or "buzzwords/keywords".

It has a simple API and everything important is not restricted to be modified or used.

Have Fun! :-)

Sample code

public class DemoUI extends UI {

	@WebServlet(value = "/*", asyncSupported = true)
	@VaadinServletConfiguration(productionMode = false, ui = DemoUI.class)
	public static class Servlet extends VaadinServlet {
	}

	private VerticalLayout root;
	private AdvancedTokenField tokenField;
	private VerticalLayout debugLayout;

	@Override
	protected void init(VaadinRequest request) {
		tokenField = new AdvancedTokenField();
		// allow new items to be added to layout-tokens and combobox
		tokenField.setAllowNewItems(true);

		root = new VerticalLayout();
		root.addComponent(tokenField);
		setContent(root);

		// clearing visible token in layout
		tokenField.clearTokens();
		// clearing tokens in combobox
		tokenField.getTokensOfInputField().clear();

		// adding tokens to combobox
		tokenField.addTokenToInputField(new Token("Token1"));
		tokenField.addTokensToInputField(Arrays.asList(new Token[] { new Token("Token2"), new Token("Token3") }));

		// adding tokens to layout directly (adding to combobox cache too, if
		// not existing)
		tokenField.addToken(new Token("token4", "green"));
		tokenField.addTokens(Arrays.asList(new Token[] { new Token("Token5"), new Token("Token6") }));

		// to override defaults
		tokenField.addTokenAddInterceptor(token -> {
			Notification.show(token.getClass().getSimpleName(), "Adding Token: " + token, Type.HUMANIZED_MESSAGE);
			return token;
		});

		// to override defaults
		tokenField.addTokenAddNewItemInterceptor((TokenNewItemInterceptor) value -> {
			Token token = new Token(value);
			Notification.show(value.getClass().getSimpleName(), "Add New Token: " + token, Type.TRAY_NOTIFICATION);
			return token;
		});

		// to override defaults
		tokenField.addTokenRemoveInterceptor((TokenRemoveInterceptor) removeEvent -> {
			Notification.show(removeEvent.getClass().getSimpleName(), "Removing Token: " + removeEvent.getToken(),
					Type.HUMANIZED_MESSAGE);
			return removeEvent;
		});

		debugLayout = new VerticalLayout();
		root.addComponent(debugLayout);

		tokenField.addTokenAddListener(add -> {
			addDebugLog();
		});

		tokenField.addTokenRemoveListener(remove -> {
			addDebugLog();
		});

		addDebugLog();
	}

	public void addDebugLog() {
		debugLayout.removeAllComponents();
		debugLayout.addComponent(new Label("------added-------"));

		// output of visible _added_ tokens
		tokenField.getTokens().forEach(e -> debugLayout.addComponent(new Label(e.toString())));
		debugLayout.addComponent(new Label());
		debugLayout.addComponent(new Label("------inputfield-------"));

		// output of available tokens in inputfield
		tokenField.getTokensOfInputField().forEach(e -> debugLayout.addComponent(new Label(e.toString())));
	}
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

  • removed buggy and deprecated drag&drop layout (v7)
  • removed v7 dependencies
  • refactor and minor fixes
Released
2018-12-29
Maturity
STABLE
License
MIT License

Compatibility

Framework
Vaadin 8.0+
Browser
N/A

AdvancedTokenField Add-on - Vaadin Add-on Directory

An advanced and modern looking Tokenfield. AdvancedTokenField Add-on - Vaadin Add-on Directory
This Tokenfield can be used to display the user informations via "Tags/Tokens". Today this is commonly used to show categories or "buzzwords/keywords". It has a simple API and everything important is not restricted to be modified or used. Have Fun! :-)
Source Code
Issue Tracker
Author Homepage
Demo
Discussion Forum

AdvancedTokenField Add-on version 0.0.4

AdvancedTokenField Add-on version 0.0.6

AdvancedTokenField Add-on version 0.1.0
- changed listener api - added interceptors and listeners

AdvancedTokenField Add-on version 0.1.01
- fixed bad input values

AdvancedTokenField Add-on version 0.1.2
- Some bug fixes - added more listeners and interceptors

AdvancedTokenField Add-on version 0.1.3
- fixed tokenAddinterceptor only intercepting after , now intercepting addToken() api

AdvancedTokenField Add-on version 0.1.4
- add support for drag and drop detection between layouts - bug fix listeners

AdvancedTokenField Add-on version 0.1.5
- fixed bug in removing tokens from layout

AdvancedTokenField Add-on version 0.1.7
- replaced inputfield with searchfield "searchdropdown"

AdvancedTokenField Add-on version 0.1.91
- added api for remove close button at tokens

AdvancedTokenField Add-on version 0.3.0
- added listener for clicking on tokens: addTokenClickListener - bufix for: allowEmptyValues doesn't work properly #7

AdvancedTokenField Add-on version 0.3.2
- added fix for detecting only token-close-clicks and not layout clicks

AdvancedTokenField Add-on version 0.3.3
- fixed log messages

AdvancedTokenField Add-on version 0.4.0
- Token has builder pattern now - Token has internal id, can be overwritten! - changed api to change allowNewToken

AdvancedTokenField Add-on version 0.4.1
- added empty fallback token value, configure via api - added description field for tokens - set token constructor to deprecated as of 4.0 - replaced by builder

AdvancedTokenField Add-on version 0.5.1
- removed buggy and deprecated drag&drop layout (v7) - removed v7 dependencies - refactor and minor fixes

Online