List of usage examples for com.vaadin.ui GridLayout addComponent
public void addComponent(Component component, int column, int row) throws OverlapsException, OutOfBoundsException
From source file:lu.uni.lassy.excalibur.examples.icrash.dev.web.java.views.AdminAuthView.java
License:Open Source License
public AdminAuthView() { setSizeFull();// w w w . ja va 2 s. c om VerticalLayout header = new VerticalLayout(); header.setSizeFull(); HorizontalLayout content = new HorizontalLayout(); content.setSizeFull(); addComponents(header, content); setExpandRatio(header, 1); setExpandRatio(content, 6); welcomeText.setValue("<h1>Welcome to the iCrash Administrator console!</h1>"); welcomeText.setContentMode(ContentMode.HTML); welcomeText.setSizeUndefined(); header.addComponent(welcomeText); header.setComponentAlignment(welcomeText, Alignment.MIDDLE_CENTER); Panel controlPanel = new Panel("Administrator control panel"); controlPanel.setSizeUndefined(); Panel addCoordPanel = new Panel("Create a new coordinator"); addCoordPanel.setSizeUndefined(); Panel messagesPanel = new Panel("Administrator messages"); messagesPanel.setWidth("580px"); Table adminMessagesTable = new Table(); adminMessagesTable.setContainerDataSource(actAdmin.getMessagesDataSource()); adminMessagesTable.setColumnWidth("inputEvent", 180); adminMessagesTable.setSizeFull(); VerticalLayout controlLayout = new VerticalLayout(controlPanel); controlLayout.setSizeFull(); controlLayout.setMargin(false); controlLayout.setComponentAlignment(controlPanel, Alignment.TOP_CENTER); VerticalLayout coordOperationsLayout = new VerticalLayout(addCoordPanel); coordOperationsLayout.setSizeFull(); coordOperationsLayout.setMargin(false); coordOperationsLayout.setComponentAlignment(addCoordPanel, Alignment.TOP_CENTER); /******************************************/ coordOperationsLayout.setVisible(true); // main layout in the middle addCoordPanel.setVisible(false); // ...which contains the panel "Create a new coordinator" /******************************************/ HorizontalLayout messagesExternalLayout = new HorizontalLayout(messagesPanel); VerticalLayout messagesInternalLayout = new VerticalLayout(adminMessagesTable); messagesExternalLayout.setSizeFull(); messagesExternalLayout.setMargin(false); messagesExternalLayout.setComponentAlignment(messagesPanel, Alignment.TOP_CENTER); messagesInternalLayout.setMargin(false); messagesInternalLayout.setSizeFull(); messagesInternalLayout.setComponentAlignment(adminMessagesTable, Alignment.TOP_CENTER); messagesPanel.setContent(messagesInternalLayout); TextField idCoordAdd = new TextField(); TextField loginCoord = new TextField(); PasswordField pwdCoord = new PasswordField(); Label idCaptionAdd = new Label("ID"); Label loginCaption = new Label("Login"); Label pwdCaption = new Label("Password"); idCaptionAdd.setSizeUndefined(); idCoordAdd.setSizeUndefined(); loginCaption.setSizeUndefined(); loginCoord.setSizeUndefined(); pwdCaption.setSizeUndefined(); pwdCoord.setSizeUndefined(); Button validateNewCoord = new Button("Validate"); validateNewCoord.setClickShortcut(KeyCode.ENTER); validateNewCoord.setStyleName(ValoTheme.BUTTON_PRIMARY); GridLayout addCoordinatorLayout = new GridLayout(2, 4); addCoordinatorLayout.setSpacing(true); addCoordinatorLayout.setMargin(true); addCoordinatorLayout.setSizeFull(); addCoordinatorLayout.addComponents(idCaptionAdd, idCoordAdd, loginCaption, loginCoord, pwdCaption, pwdCoord); addCoordinatorLayout.addComponent(validateNewCoord, 1, 3); addCoordinatorLayout.setComponentAlignment(idCaptionAdd, Alignment.MIDDLE_LEFT); addCoordinatorLayout.setComponentAlignment(idCoordAdd, Alignment.MIDDLE_LEFT); addCoordinatorLayout.setComponentAlignment(loginCaption, Alignment.MIDDLE_LEFT); addCoordinatorLayout.setComponentAlignment(loginCoord, Alignment.MIDDLE_LEFT); addCoordinatorLayout.setComponentAlignment(pwdCaption, Alignment.MIDDLE_LEFT); addCoordinatorLayout.setComponentAlignment(pwdCoord, Alignment.MIDDLE_LEFT); addCoordPanel.setContent(addCoordinatorLayout); content.addComponents(controlLayout, coordOperationsLayout, messagesExternalLayout); content.setComponentAlignment(messagesExternalLayout, Alignment.TOP_CENTER); content.setComponentAlignment(controlLayout, Alignment.TOP_CENTER); content.setComponentAlignment(messagesExternalLayout, Alignment.TOP_CENTER); content.setExpandRatio(controlLayout, 20); content.setExpandRatio(coordOperationsLayout, 10); content.setExpandRatio(messagesExternalLayout, 28); Button addCoordinator = new Button("Add coordinator"); Button deleteCoordinator = new Button("Delete coordinator"); addCoordinator.addStyleName(ValoTheme.BUTTON_HUGE); deleteCoordinator.addStyleName(ValoTheme.BUTTON_HUGE); logoutBtn.addStyleName(ValoTheme.BUTTON_HUGE); VerticalLayout buttons = new VerticalLayout(); buttons.setMargin(true); buttons.setSpacing(true); buttons.setSizeFull(); buttons.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER); controlPanel.setContent(buttons); buttons.addComponents(addCoordinator, deleteCoordinator, logoutBtn); /******* DELETE COORDINATOR PANEL BEGIN *********/ Label idCaptionDel = new Label("ID"); TextField idCoordDel = new TextField(); Panel delCoordPanel = new Panel("Delete a coordinator"); coordOperationsLayout.addComponent(delCoordPanel); delCoordPanel.setVisible(false); coordOperationsLayout.setComponentAlignment(delCoordPanel, Alignment.TOP_CENTER); delCoordPanel.setSizeUndefined(); GridLayout delCoordinatorLayout = new GridLayout(2, 2); delCoordinatorLayout.setSpacing(true); delCoordinatorLayout.setMargin(true); delCoordinatorLayout.setSizeFull(); Button deleteCoordBtn = new Button("Delete"); deleteCoordBtn.setClickShortcut(KeyCode.ENTER); deleteCoordBtn.setStyleName(ValoTheme.BUTTON_PRIMARY); delCoordinatorLayout.addComponents(idCaptionDel, idCoordDel); delCoordinatorLayout.addComponent(deleteCoordBtn, 1, 1); delCoordinatorLayout.setComponentAlignment(idCaptionDel, Alignment.MIDDLE_LEFT); delCoordinatorLayout.setComponentAlignment(idCoordDel, Alignment.MIDDLE_LEFT); delCoordPanel.setContent(delCoordinatorLayout); /******* DELETE COORDINATOR PANEL END *********/ /************************************************* MAIN BUTTONS LOGIC BEGIN *************************************************/ addCoordinator.addClickListener(event -> { if (!addCoordPanel.isVisible()) { delCoordPanel.setVisible(false); addCoordPanel.setVisible(true); idCoordAdd.focus(); } else addCoordPanel.setVisible(false); }); deleteCoordinator.addClickListener(event -> { if (!delCoordPanel.isVisible()) { addCoordPanel.setVisible(false); delCoordPanel.setVisible(true); idCoordDel.focus(); } else delCoordPanel.setVisible(false); }); /************************************************* MAIN BUTTONS LOGIC END *************************************************/ /************************************************* ADD COORDINATOR FORM LOGIC BEGIN *************************************************/ validateNewCoord.addClickListener(event -> { String currentURL = Page.getCurrent().getLocation().toString(); int strIndexCreator = currentURL.lastIndexOf(AdministratorLauncher.adminPageName); String iCrashURL = currentURL.substring(0, strIndexCreator); String googleShebang = "#!"; String coordURL = iCrashURL + CoordinatorServlet.coordinatorsName + googleShebang; try { sys.oeAddCoordinator(new DtCoordinatorID(new PtString(idCoordAdd.getValue())), new DtLogin(new PtString(loginCoord.getValue())), new DtPassword(new PtString(pwdCoord.getValue()))); // open new browser tab with the newly created coordinator console... // "_blank" instructs the browser to open a new tab instead of a new window... // unhappily not all browsers interpret it correctly, // some versions of some browsers might still open a new window instead (notably Firefox)! Page.getCurrent().open(coordURL + idCoordAdd.getValue(), "_blank"); } catch (Exception e) { e.printStackTrace(); } idCoordAdd.setValue(""); loginCoord.setValue(""); pwdCoord.setValue(""); idCoordAdd.focus(); }); /************************************************* ADD COORDINATOR FORM LOGIC END *************************************************/ /************************************************* DELETE COORDINATOR FORM LOGIC BEGIN *************************************************/ deleteCoordBtn.addClickListener(event -> { IcrashSystem sys = IcrashSystem.getInstance(); try { sys.oeDeleteCoordinator(new DtCoordinatorID(new PtString(idCoordDel.getValue()))); } catch (Exception e) { e.printStackTrace(); } idCoordDel.setValue(""); idCoordDel.focus(); }); /************************************************* DELETE COORDINATOR FORM LOGIC END *************************************************/ }
From source file:net.sourceforge.javydreamercsw.validation.manager.web.ValidationManagerUI.java
License:Apache License
private Component getMenu() { GridLayout gl = new GridLayout(3, 3); gl.addComponent(new Image("", LOGO), 0, 0); Label version = new Label(TRANSLATOR.translate("general.version") + ": " + getVersion()); gl.addComponent(version, 2, 2);//w ww . j a v a 2 s. c om if (getUser() != null) { getUser().update(); //Logout button Button logout = new Button(TRANSLATOR.translate("general.logout")); logout.addClickListener((Button.ClickEvent event) -> { try { user.update(); user.write2DB(); user = null; main = null; setLocale(Locale.ENGLISH); updateScreen(); // Close the session closeSession(); } catch (VMException ex) { LOG.log(Level.SEVERE, null, ex); } }); gl.addComponent(logout, 1, 0); //Notification Button if (getUser().getNotificationList().isEmpty() && DataBaseManager.isDemo()) { //For demo add a notification for users try { Lookup.getDefault().lookup(INotificationManager.class).addNotification( "Welcome to ValidationManager!", NotificationTypes.GENERAL, getUser().getEntity(), new VMUserServer(1).getEntity()); } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); } } Button notification = new Button(); if (getUser().getPendingNotifications().size() > 0) { notification.setCaption("" + getUser().getPendingNotifications().size()); //any number, count, etc } notification.setHtmlContentAllowed(true); notification.setIcon(VaadinIcons.BELL); notification.addClickListener((Button.ClickEvent event) -> { //TODO: Show notifications screen }); gl.addComponent(notification, 2, 0); } gl.setSizeFull(); return gl; }
From source file:org.accelerators.activiti.admin.ui.GroupCreateForm.java
License:Open Source License
/** * //from ww w . j av a 2 s. c om * @param app */ public GroupCreateForm(AdminApp application) { // Set application reference this.app = application; // Enable buffering so that commit() must be called for the form. setWriteThrough(false); // Set the form to act immediately on user input. setImmediate(true); // Set form size setSizeFull(); // Setup footer layout HorizontalLayout footer = new HorizontalLayout(); footer.setSpacing(true); footer.setWidth("100%"); footer.setVisible(true); // Add footer setFooter(footer); // Init buttons create = new Button(app.getMessage(Messages.Create), (ClickListener) this); close = new Button(app.getMessage(Messages.Close), (ClickListener) this); reset = new Button(app.getMessage(Messages.Reset), this, "discard"); // Set button grid GridLayout grid = new GridLayout(3, 1); grid.addComponent(create, 0, 0); grid.addComponent(reset, 1, 0); grid.addComponent(close, 2, 0); grid.setSpacing(true); // Add grid to footer footer.addComponent(grid); // Right align buttons in footer footer.setComponentAlignment(grid, Alignment.BOTTOM_RIGHT); // Init group types types = new String[] { app.getMessage(Messages.Assignment), app.getMessage(Messages.Program), app.getMessage(Messages.Project), app.getMessage(Messages.Role), app.getMessage(Messages.Team), app.getMessage(Messages.Unit) }; // Create combo box for group types groupTypes = new ComboBox("type"); groupTypes.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH); for (int i = 0; i < types.length; i++) { groupTypes.addItem(types[i]); } // Propagate changes directly groupTypes.setImmediate(true); // Allow adding new group types groupTypes.setNewItemsAllowed(true); // Get available users members = new TwinColSelect(app.getMessage(Messages.Members), app.getAdminService().getUsers()); // Set column headers members.setLeftColumnCaption(app.getMessage(Messages.AvailableUsers)); members.setRightColumnCaption(app.getMessage(Messages.GroupMembers)); // Propagate changes directly members.setImmediate(true); // Set max width members.setWidth("100%"); // Field factory for over riding how fields are created setFormFieldFactory(new DefaultFieldFactory() { private static final long serialVersionUID = 1L; @Override public Field createField(Item item, Object propertyId, Component uiContext) { if (propertyId.equals("type")) { groupTypes.setWidth("100%"); groupTypes.setRequired(false); groupTypes.setCaption(app.getMessage(Messages.Types)); return groupTypes; } Field field = super.createField(item, propertyId, uiContext); if (propertyId.equals("id")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field tf.setRequired(true); // Set error message tf.setRequiredError("Id is missing"); // Set read only tf.setReadOnly(false); } else if (propertyId.equals("name")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field tf.setRequired(true); // Set error message tf.setRequiredError(app.getMessage(Messages.GroupNameIsMissing)); } field.setWidth("100%"); return field; } }); }
From source file:org.accelerators.activiti.admin.ui.GroupEditForm.java
License:Open Source License
/** * /*from w w w . j a v a2 s .c o m*/ * @param app */ public GroupEditForm(AdminApp application) { // Set application reference this.app = application; // Enable buffering so that commit() must be called for the form. setWriteThrough(false); // Set the form to act immediately on user input. setImmediate(true); // Set form size setSizeFull(); // Setup footer layout HorizontalLayout footer = new HorizontalLayout(); footer.setSpacing(true); footer.setWidth("100%"); footer.setVisible(true); // Add footer setFooter(footer); // Init buttons save = new Button(app.getMessage(Messages.Save), (ClickListener) this); close = new Button(app.getMessage(Messages.Close), (ClickListener) this); reset = new Button(app.getMessage(Messages.Reset), this, "discard"); // Set button grid GridLayout grid = new GridLayout(3, 1); grid.addComponent(save, 0, 0); grid.addComponent(reset, 1, 0); grid.addComponent(close, 2, 0); grid.setSpacing(true); // Add grid to footer footer.addComponent(grid); // Right align buttons in footer footer.setComponentAlignment(grid, Alignment.BOTTOM_RIGHT); // Init group types types = new String[] { app.getMessage(Messages.Assignment), app.getMessage(Messages.Program), app.getMessage(Messages.Project), app.getMessage(Messages.Role), app.getMessage(Messages.Team), app.getMessage(Messages.Unit) }; // Create combo box for group types groupTypes = new ComboBox("type"); groupTypes.setFilteringMode(Filtering.FILTERINGMODE_STARTSWITH); for (int i = 0; i < types.length; i++) { groupTypes.addItem(types[i]); } // Propagate changes directly groupTypes.setImmediate(true); // Allow adding new group types groupTypes.setNewItemsAllowed(true); // Get available users members = new TwinColSelect(app.getMessage(Messages.Members), app.getAdminService().getUsers()); // Set column headers members.setLeftColumnCaption(app.getMessage(Messages.AvailableUsers)); members.setRightColumnCaption(app.getMessage(Messages.GroupMembers)); // Propagate changes directly members.setImmediate(true); // Set max width members.setWidth("100%"); // Field factory for over riding how fields are created setFormFieldFactory(new DefaultFieldFactory() { private static final long serialVersionUID = 1L; @Override public Field createField(Item item, Object propertyId, Component uiContext) { if (propertyId.equals("type")) { groupTypes.setWidth("100%"); groupTypes.setRequired(false); groupTypes.setCaption(app.getMessage(Messages.Types)); return groupTypes; } Field field = super.createField(item, propertyId, uiContext); if (propertyId.equals("id")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as read-only. Changing the id will create a new // group. tf.setReadOnly(true); // Set as required field // tf.setRequired(true); // Set error message tf.setRequiredError("Id is missing"); } else if (propertyId.equals("name")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field tf.setRequired(true); // Set error message tf.setRequiredError(app.getMessage(Messages.GroupNameIsMissing)); } field.setWidth("100%"); return field; } }); }
From source file:org.accelerators.activiti.admin.ui.GroupTab.java
License:Open Source License
public GroupTab(AdminApp application) { // Set application reference this.app = application; // Set tab name setCaption(app.getMessage(Messages.Groups)); // Add main layout VerticalLayout layout = new VerticalLayout(); layout.setMargin(true);//from w w w. j a v a 2s. c om layout.setSpacing(true); layout.setSizeFull(); // Add toolbar layout GridLayout toolbar = new GridLayout(2, 1); toolbar.setWidth("100%"); layout.addComponent(toolbar); // Add create button create = new Button(app.getMessage(Messages.Create), (ClickListener) this); create.setDescription(app.getMessage(Messages.CreateGroup)); create.setIcon(new ThemeResource("../runo/icons/16/ok.png")); toolbar.addComponent(create, 0, 0); toolbar.setComponentAlignment(create, Alignment.TOP_LEFT); // Add refresh button refresh = new Button(app.getMessage(Messages.Refresh), (ClickListener) this); refresh.setDescription(app.getMessage(Messages.RefreshTable)); refresh.setIcon(new ThemeResource("../runo/icons/16/reload.png")); toolbar.addComponent(refresh, 1, 0); toolbar.setComponentAlignment(refresh, Alignment.TOP_RIGHT); // Add table table = new GroupTable(app); table.setSizeFull(); layout.addComponent(table); // Set table to expand layout.setExpandRatio(table, 1.0f); // Root setCompositionRoot(layout); }
From source file:org.accelerators.activiti.admin.ui.LoginView.java
License:Open Source License
@SuppressWarnings("serial") public LoginView(AdminApp application) { // Set application reference this.app = application; // Init window caption app.getMainWindow().setCaption(app.getMessage(Messages.Title)); // Set layout to full size setSizeFull();/*from w ww . j ava2s .c o m*/ // Set style this.setStyleName("login-background"); // Add header bar final HorizontalLayout header = new HorizontalLayout(); header.setHeight("50px"); header.setWidth("100%"); addComponent(header); setComponentAlignment(header, Alignment.MIDDLE_CENTER); // Setup grid GridLayout loginGrid = new GridLayout(1, 2); loginGrid.setWidth("250px"); addComponent(loginGrid); setComponentAlignment(loginGrid, Alignment.MIDDLE_CENTER); // Add title to header GridLayout logoGrid = new GridLayout(1, 1); loginGrid.addComponent(logoGrid, 0, 0); loginGrid.setComponentAlignment(logoGrid, Alignment.MIDDLE_CENTER); Embedded logoImage = new Embedded(null, new ThemeResource("img/login-logo.png")); logoImage.setType(Embedded.TYPE_IMAGE); logoImage.addStyleName("login-image"); logoGrid.addComponent(logoImage, 0, 0); logoGrid.setComponentAlignment(logoImage, Alignment.MIDDLE_CENTER); // Add field and button layout VerticalLayout buttonLayout = new VerticalLayout(); buttonLayout.setSizeFull(); buttonLayout.setSpacing(true); buttonLayout.setMargin(false); buttonLayout.setStyleName("login-form"); loginGrid.addComponent(buttonLayout, 0, 1); loginGrid.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER); // Add username field username = new TextField(app.getMessage(Messages.Username)); username.setWidth("100%"); buttonLayout.addComponent(username); // Add password field password = new PasswordField(app.getMessage(Messages.Password)); password.setWidth("100%"); buttonLayout.addComponent(password); // Add Login button buttonLayout.addComponent(login); buttonLayout.setComponentAlignment(login, Alignment.BOTTOM_RIGHT); // Set focus to this component username.focus(); // Add shortcut to login button login.setClickShortcut(KeyCode.ENTER); login.addListener(new Button.ClickListener() { public void buttonClick(Button.ClickEvent event) { try { // Athenticate the user authenticate((String) username.getValue(), (String) password.getValue()); // Switch to the main view app.getViewManager().switchScreen(MainView.class.getName(), new MainView(app)); } catch (Exception e) { getWindow().showNotification(e.toString()); } } }); HorizontalLayout footer = new HorizontalLayout(); footer.setHeight("50px"); footer.setWidth("100%"); addComponent(footer); }
From source file:org.accelerators.activiti.admin.ui.MainView.java
License:Open Source License
public MainView(AdminApp application) { // Set application this.app = application; // Setup main layout setStyleName(Reindeer.LAYOUT_WHITE); setMargin(false);//from w w w . j av a2s. c o m setSpacing(false); setSizeFull(); // Add header GridLayout header = new GridLayout(2, 1); header.setWidth("100%"); header.setHeight("34px"); addComponent(header); // Add header styles header.addStyleName(Consts.HEADER); header.addStyleName("header"); header.setSpacing(true); // Add title to header GridLayout logoGrid = new GridLayout(1, 1); header.addComponent(logoGrid, 0, 0); header.setComponentAlignment(logoGrid, Alignment.MIDDLE_LEFT); Embedded logoImage = new Embedded(null, new ThemeResource("img/header-logo.png")); logoImage.setType(Embedded.TYPE_IMAGE); logoImage.addStyleName("header-image"); logoGrid.addComponent(logoImage, 0, 0); logoGrid.setComponentAlignment(logoImage, Alignment.MIDDLE_CENTER); // Add logout button to header GridLayout logoutGrid = new GridLayout(2, 1); Label userLabel = new Label("Signed in as: " + app.getUser().toString()); userLabel.addStyleName("user"); logout.setStyleName(Reindeer.BUTTON_LINK); logout.addStyleName("logout"); logoutGrid.addComponent(userLabel, 0, 0); logoutGrid.addComponent(logout, 1, 0); header.addComponent(logoutGrid, 1, 0); header.setComponentAlignment(logoutGrid, Alignment.TOP_RIGHT); // Create tab sheet TabSheet tabs = new TabSheet(); tabs.setSizeFull(); // Add tab styles tabs.addStyleName(Reindeer.TABSHEET_BORDERLESS); tabs.addStyleName(Reindeer.LAYOUT_WHITE); // Add task view tab tabs.addTab(new UserTab(app)); tabs.addTab(new GroupTab(app)); // Add tab sheet to layout addComponent(tabs); setExpandRatio(tabs, 1.0F); // Add footer text Label footerText = new Label(app.getMessage(Messages.Footer)); footerText.setSizeUndefined(); footerText.setStyleName(Reindeer.LABEL_SMALL); addComponent(footerText); setComponentAlignment(footerText, Alignment.BOTTOM_CENTER); }
From source file:org.accelerators.activiti.admin.ui.UserCreateForm.java
License:Open Source License
public UserCreateForm(AdminApp application) { // Set application reference this.app = application; // Enable buffering so that commit() must be called for the form. setWriteThrough(false);//ww w. j a v a 2 s . co m // Set the form to act immediately on user input. setImmediate(true); // Set form size setSizeFull(); // Setup footer layout HorizontalLayout footer = new HorizontalLayout(); footer.setSpacing(true); footer.setWidth("100%"); footer.setVisible(true); // Add footer setFooter(footer); // Init buttons create = new Button(app.getMessage(Messages.Create), (ClickListener) this); close = new Button(app.getMessage(Messages.Close), (ClickListener) this); reset = new Button(app.getMessage(Messages.Reset), this, "discard"); // Set button grid GridLayout grid = new GridLayout(3, 1); grid.addComponent(create, 0, 0); grid.addComponent(reset, 1, 0); grid.addComponent(close, 2, 0); grid.setSpacing(true); // Add grid to footer footer.addComponent(grid); // Right align buttons in footer footer.setComponentAlignment(grid, Alignment.BOTTOM_RIGHT); // Get all available groups groups = new TwinColSelect(app.getMessage(Messages.Groups), app.getAdminService().getGroups()); // Set column headers groups.setLeftColumnCaption(app.getMessage(Messages.AvailableGroups)); groups.setRightColumnCaption(app.getMessage(Messages.MemberOfGroups)); // Propagate changes directly groups.setImmediate(true); // Max width groups.setWidth("100%"); // Field factory for over riding how fields are created setFormFieldFactory(new DefaultFieldFactory() { private static final long serialVersionUID = 1L; @Override public Field createField(Item item, Object propertyId, Component uiContext) { Field field = super.createField(item, propertyId, uiContext); field.setWidth("100%"); // field.setVisible(false); if (propertyId.equals("id")) { TextField tf = (TextField) field; tf.setVisible(true); // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field tf.setRequired(true); // Set validator example, should not be restricted in the // admin ui // tf.addValidator(new // RegexpValidator("^[a-zA-Z0-9_-]{4,20}", // app.getMessage(Messages.InvalidUsername))); // Set error message tf.setRequiredError(app.getMessage(Messages.UsernameIsMissing)); } else if (propertyId.equals("password")) { TextField tf = (TextField) field; tf.setVisible(true); // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field tf.setRequired(true); // Set as secret (todo: use password field instead of text // field) tf.setSecret(true); // Set error message tf.setRequiredError(app.getMessage(Messages.PasswordIsMissing)); } else if (propertyId.equals("email")) { TextField tf = (TextField) field; tf.setVisible(true); // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field, should not be required by default // in the admin ui // tf.setRequired(true); // Set error message // tf.setRequiredError(application.getMessage(Messages.EmailIsMissing)); /* Add a validator for email and make it required */ field.addValidator(new EmailValidator(app.getMessage(Messages.EmailFormatError))); } else if (propertyId.equals("firstName")) { TextField tf = (TextField) field; tf.setVisible(true); // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); } else if (propertyId.equals("lastName")) { TextField tf = (TextField) field; tf.setVisible(true); // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); } return field; } }); }
From source file:org.accelerators.activiti.admin.ui.UserEditForm.java
License:Open Source License
public UserEditForm(AdminApp application) { // Set application reference this.app = application; // Enable buffering so that commit() must be called for the form. setWriteThrough(false);/*from w w w . j a v a 2s .c o m*/ // Set the form to act immediately on user input. setImmediate(true); // Set form size setSizeFull(); // Setup footer layout HorizontalLayout footer = new HorizontalLayout(); footer.setSpacing(true); footer.setWidth("100%"); footer.setVisible(true); // Add footer setFooter(footer); // Init buttons save = new Button(app.getMessage(Messages.Save), (ClickListener) this); close = new Button(app.getMessage(Messages.Close), (ClickListener) this); reset = new Button(app.getMessage(Messages.Reset), this, "discard"); // Set button grid GridLayout grid = new GridLayout(3, 1); grid.addComponent(save, 0, 0); grid.addComponent(reset, 1, 0); grid.addComponent(close, 2, 0); grid.setSpacing(true); // Add grid to footer footer.addComponent(grid); // Right align buttons in footer footer.setComponentAlignment(grid, Alignment.BOTTOM_RIGHT); // Get all available groups groups = new TwinColSelect(app.getMessage(Messages.Groups), app.getAdminService().getGroups()); // Set column headers groups.setLeftColumnCaption(app.getMessage(Messages.AvailableGroups)); groups.setRightColumnCaption(app.getMessage(Messages.MemberOfGroups)); // Propagate changes directly groups.setImmediate(true); // Max width groups.setWidth("100%"); // Field factory for over riding how fields are created setFormFieldFactory(new DefaultFieldFactory() { private static final long serialVersionUID = 1L; @Override public Field createField(Item item, Object propertyId, Component uiContext) { Field field = super.createField(item, propertyId, uiContext); if (propertyId.equals("id")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as read-only. Changing the id will create a new user. tf.setReadOnly(true); // Set as required field //tf.setRequired(true); // Set validator example, should not be restricted in the // admin ui // tf.addValidator(new // RegexpValidator("^[a-zA-Z0-9_-]{4,20}", // app.getMessage(Messages.InvalidUsername))); // Set error message tf.setRequiredError(app.getMessage(Messages.UsernameIsMissing)); } else if (propertyId.equals("password")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field tf.setRequired(true); // Set as secret (todo: use password field instead of text // field) tf.setSecret(true); // Set error message tf.setRequiredError(app.getMessage(Messages.PasswordIsMissing)); } else if (propertyId.equals("email")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); // Set as required field, should not be required by default // in the admin ui // tf.setRequired(true); // Set error message // tf.setRequiredError(application.getMessage(Messages.EmailIsMissing)); /* Add a validator for email and make it required */ field.addValidator(new EmailValidator(app.getMessage(Messages.EmailFormatError))); } else if (propertyId.equals("firstName")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); } else if (propertyId.equals("lastName")) { TextField tf = (TextField) field; // Do not display "null" to the user when the field is empty tf.setNullRepresentation(""); } field.setWidth("100%"); return field; } }); }
From source file:org.accelerators.activiti.admin.ui.UserTab.java
License:Open Source License
public UserTab(AdminApp application) { // Set application reference this.app = application; // Set tab name setCaption(app.getMessage(Messages.Users)); // Add main layout VerticalLayout layout = new VerticalLayout(); layout.setMargin(true);// w w w . ja v a 2 s .c om layout.setSpacing(true); layout.setSizeFull(); // Add toolbar layout GridLayout toolbar = new GridLayout(2, 1); toolbar.setWidth("100%"); layout.addComponent(toolbar); // Add create button create = new Button(app.getMessage(Messages.Create), (ClickListener) this); create.setDescription(app.getMessage(Messages.CreateUser)); create.setIcon(new ThemeResource("../runo/icons/16/ok.png")); toolbar.addComponent(create, 0, 0); toolbar.setComponentAlignment(create, Alignment.TOP_LEFT); // Add refresh button refresh = new Button(app.getMessage(Messages.Refresh), (ClickListener) this); refresh.setDescription(app.getMessage(Messages.RefreshTable)); refresh.setIcon(new ThemeResource("../runo/icons/16/reload.png")); toolbar.addComponent(refresh, 1, 0); toolbar.setComponentAlignment(refresh, Alignment.TOP_RIGHT); // Add table table = new UserTable(app); table.setSizeFull(); layout.addComponent(table); // Set table to expand layout.setExpandRatio(table, 1.0f); // Root setCompositionRoot(layout); }