Example usage for com.vaadin.ui Alignment TOP_RIGHT

List of usage examples for com.vaadin.ui Alignment TOP_RIGHT

Introduction

In this page you can find the example usage for com.vaadin.ui Alignment TOP_RIGHT.

Prototype

Alignment TOP_RIGHT

To view the source code for com.vaadin.ui Alignment TOP_RIGHT.

Click Source Link

Usage

From source file:org.escidoc.browser.ui.view.WikiPageView.java

License:Open Source License

/**
 * Put ID + Modification and main Operation Icons here
 * /*www.ja  v  a2s .c om*/
 * @param vlContentPanel
 */
private void buildHeaderLayout(VerticalLayout vlContentPanel) {
    HorizontalLayout hl = new HorizontalLayout();
    hl.setWidth("100%");
    Label lblGeneralInfo = new Label(
            "ID: " + resourceProxy.getId() + " " + "Modified on " + resourceProxy.getModifiedOn());
    hl.addComponent(lblGeneralInfo);

    HorizontalLayout mainOperationIcons = buildMainOperationIconsLayout();
    hl.addComponent(mainOperationIcons);

    hl.setComponentAlignment(mainOperationIcons, Alignment.TOP_RIGHT);
    hl.setHeight("20px");

    HorizontalLayout horizontalRuler = new HorizontalLayout();
    horizontalRuler.setWidth("100%");
    horizontalRuler.setHeight("9px");
    horizontalRuler.addComponent(new Label("<hr>", Label.CONTENT_RAW));

    vlContentPanel.addComponent(hl);
    vlContentPanel.addComponent(horizontalRuler);

}

From source file:org.icrisat.gdms.ui.GDMSMain.java

void buildMainView() {
    _mainLayout.setSizeFull();/*from  w w  w .j a v a 2 s .  com*/

    _lblLoginMessage = new Label("");
    _lblLoginMessage.setStyleName(Reindeer.LABEL_H2);

    HorizontalLayout topMenuLayout = getTopMenu();
    CssLayout headerImageLayout = getHeader();

    VerticalLayout topLayout = new VerticalLayout();
    topLayout.addComponent(headerImageLayout);
    topLayout.addComponent(topMenuLayout);
    topLayout.setComponentAlignment(topMenuLayout, Alignment.TOP_RIGHT);
    topLayout.addComponent(_lblLoginMessage);
    topLayout.setComponentAlignment(_lblLoginMessage, Alignment.TOP_RIGHT);
    topLayout.setMargin(false, true, true, true);
    _mainLayout.addComponent(topLayout);

    CssLayout mainCSSLayout = new CssLayout();
    mainCSSLayout.setMargin(false, true, true, true);
    mainCSSLayout.setSizeFull();

    _tabsheet = new TabSheet();
    _tabsheet.setSizeFull();

    mainCSSLayout.addComponent(_tabsheet);
    _mainLayout.addComponent(mainCSSLayout);
    _mainLayout.setExpandRatio(mainCSSLayout, 1);

    buildWelcomeScreen = buildWelcomeScreen();
    buildAboutScreen = buildAboutScreen();
    buildUploadDataWindow = new UploadComponent(this);
    buildUploadDataWindow.setImmediate(true);
    buildUploadDataWindow.setEnabled(false);
    buildUploadDataWindow.addListener(this);
    buildUploadDataWindow.setWidth("100%");

    buildRetrieveWindow = new RetrieveComponent(this);
    buildRetrieveWindow.setImmediate(true);
    buildRetrieveWindow.setEnabled(false);
    buildRetrieveWindow.addListener(this);
    buildRetrieveWindow.setWidth("100%");

    buildDeleteWindow = new DeleteComponent(this);
    buildDeleteWindow.setImmediate(true);
    buildDeleteWindow.setEnabled(false);
    buildDeleteWindow.addListener(this);
    buildRetrieveWindow.setWidth("100%");

    _tabsheet.addComponent(buildWelcomeScreen);
    _tabsheet.addComponent(buildAboutScreen);
    _tabsheet.addComponent(buildUploadDataWindow);
    _tabsheet.addComponent(buildRetrieveWindow);
    _tabsheet.addComponent(buildDeleteWindow);

    /*if (null == _gdmsModel.getLoggedInUser()){
       buildUploadDataWindow.setEnabled(false);
       buildRetrieveWindow.setEnabled(false);
       buildDeleteWindow.setEnabled(false);
    } else {
       buildUploadDataWindow.setEnabled(true);
       buildRetrieveWindow.setEnabled(true);
       buildDeleteWindow.setEnabled(true);
    }*/

    if (null == _gdmsModel.getLoggedInUser()) {
        _tabsheet.getTab(1).setEnabled(false);
        _tabsheet.getTab(2).setEnabled(false);
        _tabsheet.getTab(3).setEnabled(false);
    } else {
        _tabsheet.getTab(1).setEnabled(true);
        _tabsheet.getTab(2).setEnabled(true);
        _tabsheet.getTab(3).setEnabled(true);
    }

    _tabsheet.addListener(new SelectedTabChangeListener() {

        private static final long serialVersionUID = 1L;

        public void selectedTabChange(SelectedTabChangeEvent event) {
            User loggedInUser = _gdmsModel.getLoggedInUser();
            //System.out.println("loggedInUser:"+loggedInUser);
            if (null == loggedInUser) {
                if (!(buildWelcomeScreen == _tabsheet.getSelectedTab())) {
                    getMainWindow().showNotification("Please login inorder to Upload, Retrieve or Delete data.",
                            Notification.TYPE_HUMANIZED_MESSAGE);
                    return;
                }
            } else {
                if (event.getTabSheet().getSelectedTab().getCaption() == "Upload") {
                    updateUploadTabComponent();
                } else if (event.getTabSheet().getSelectedTab().getCaption() == "Retrieve") {
                    updateRetrieveTabComponent();
                } else if (event.getTabSheet().getSelectedTab().getCaption() == "View") {
                    updateDeleteTabComponent();
                }
            }

        }

    });

    CssLayout bottomPanelLayout = getBottomPanelLayout();
    VerticalLayout bottomContactLayout = new VerticalLayout();
    bottomContactLayout.addComponent(bottomPanelLayout);
    bottomContactLayout.setComponentAlignment(bottomPanelLayout, Alignment.BOTTOM_LEFT);
    bottomContactLayout.setMargin(false, true, false, true);
}

From source file:org.iespuigcastellar.attendancemanager.screenlayouts.NoModalWindowTeacherMainLayout.java

License:Open Source License

private void initLayout() {

    datePopupDateField = new PopupDateField("");
    datePopupDateField.setDescription(app.locale.getString("TEACHERMAINLAYOUT_DATEFIELD_DESCRIPTION"));
    datePopupDateField.setValue(new java.util.Date());
    datePopupDateField.setResolution(PopupDateField.RESOLUTION_DAY);
    datePopupDateField.setImmediate(true);
    datePopupDateField.addListener(ValueChangeEvent.class, this, "changedDate");

    classblockComboBox = new ComboBox();
    classblockComboBox.setInputPrompt(app.locale.getString("TEACHERMAINLAYOUT_CLASSBLOCK_INPUTPROMPT"));
    classblockComboBox.setDescription(app.locale.getString("TEACHERMAINLAYOUT_CLASSBLOCK_DESCRIPTION"));
    classblockComboBox.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
    classblockComboBox.setImmediate(true);
    classblockComboBox.addContainerProperty("name", String.class, "");
    classblockComboBox.setItemCaptionPropertyId("name");
    classblockComboBox.addListener(ValueChangeEvent.class, this, "changedClassblock");

    Button logoutButton = new Button(app.locale.getString("TEACHERMAINLAYOUT_LOGOUTBUTTON_CAPTION"));

    logoutButton.addListener(new Button.ClickListener() {

        @Override/*  w  ww.java  2  s . c  o m*/
        public void buttonClick(ClickEvent event) {
            Logger.log("User " + app.user.getLogin() + " closes session");
            app.storage.close();
            getApplication().close();
        }
    });

    GridLayout optionsGridLayout = new GridLayout(2, 1);
    HorizontalLayout haLayout = new HorizontalLayout();

    haLayout.setSpacing(true);
    //haLayout.setWidth("100%"); // Fix layout errors, but bad display
    haLayout.addComponent(new PasswordChangeLayout());
    haLayout.addComponent(datePopupDateField);
    haLayout.addComponent(classblockComboBox);

    optionsGridLayout.addComponent(haLayout);
    optionsGridLayout.addComponent(logoutButton);
    optionsGridLayout.setComponentAlignment(logoutButton, Alignment.TOP_RIGHT);
    optionsGridLayout.setWidth("100%");

    addComponent(optionsGridLayout);

    table.setSizeFull();
    table.setImmediate(true);
    table.setColumnReorderingAllowed(true);
    table.setColumnCollapsingAllowed(true);
    table.addContainerProperty("Name", String.class, null);
    table.addContainerProperty("Surname 1", String.class, null);
    table.addContainerProperty("Surname 2", String.class, null);
    table.addContainerProperty("Miss", CheckBox.class, null);
    table.addContainerProperty("Excused", CheckBox.class, null);
    table.addContainerProperty("Delay", CheckBox.class, null);
    table.addContainerProperty("Expulsion", CheckBox.class, null);

    table.setColumnExpandRatio("Name", 1);
    table.setColumnExpandRatio("Surname 1", 1);
    table.setColumnExpandRatio("Surname 2", 1);

    table.setColumnHeaders(new String[] { app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_NAME"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_SURNAME1"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_SURNAME2"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_MISS"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_EXCUSED"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_DELAY"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_EXPULSION") });
    addComponent(table);
    setExpandRatio(table, 1);
    setSizeFull();
}

From source file:org.iespuigcastellar.attendancemanager.screenlayouts.TeacherMainLayout.java

License:Open Source License

private void initLayout() {

    passwordChangeWindow = new PasswordChangeWindow();
    passwordChangeWindow.setCaption(app.locale.getString("TEACHERMAINLAYOUT_CHANGEMYPASSWORD_BUTTON"));

    datePopupDateField = new PopupDateField("");
    datePopupDateField.setDescription(app.locale.getString("TEACHERMAINLAYOUT_DATEFIELD_DESCRIPTION"));
    datePopupDateField.setValue(new java.util.Date());
    datePopupDateField.setResolution(PopupDateField.RESOLUTION_DAY);
    datePopupDateField.setImmediate(true);
    datePopupDateField.addListener(ValueChangeEvent.class, this, "changedDate");

    classblockComboBox = new ComboBox();
    classblockComboBox.setInputPrompt(app.locale.getString("TEACHERMAINLAYOUT_CLASSBLOCK_INPUTPROMPT"));
    classblockComboBox.setDescription(app.locale.getString("TEACHERMAINLAYOUT_CLASSBLOCK_DESCRIPTION"));
    classblockComboBox.setFilteringMode(Filtering.FILTERINGMODE_CONTAINS);
    classblockComboBox.setImmediate(true);
    classblockComboBox.addContainerProperty("name", String.class, "");
    classblockComboBox.setItemCaptionPropertyId("name");
    classblockComboBox.addListener(ValueChangeEvent.class, this, "changedClassblock");

    Button logoutButton = new Button(app.locale.getString("TEACHERMAINLAYOUT_LOGOUTBUTTON_CAPTION"));

    logoutButton.addListener(new Button.ClickListener() {
        @Override//from w  ww  .ja v  a2 s .com
        public void buttonClick(ClickEvent event) {
            Logger.log("User " + app.user.getLogin() + " closes session");
            app.storage.close();
            getApplication().close();
        }
    });

    Button changePasswordButton = new Button(app.locale.getString("TEACHERMAINLAYOUT_CHANGEMYPASSWORD_BUTTON"));
    changePasswordButton.setIcon(new ThemeResource("../runo/icons/16/user.png"));
    changePasswordButton.setStyleName(Button.STYLE_LINK);
    changePasswordButton.addListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            // Open window if not open already
            if (passwordChangeWindow.getParent() != null) {
                // Window already open
            } else {
                // open window
                getWindow().addWindow(passwordChangeWindow);
            }
        }
    });

    GridLayout optionsGridLayout = new GridLayout(2, 1);
    HorizontalLayout haLayout = new HorizontalLayout();

    haLayout.setSpacing(true);

    haLayout.addComponent(changePasswordButton);
    haLayout.setComponentAlignment(changePasswordButton, Alignment.MIDDLE_LEFT);
    haLayout.addComponent(datePopupDateField);
    haLayout.addComponent(classblockComboBox);

    optionsGridLayout.addComponent(haLayout);
    optionsGridLayout.addComponent(logoutButton);
    optionsGridLayout.setComponentAlignment(logoutButton, Alignment.TOP_RIGHT);
    optionsGridLayout.setWidth("100%");

    addComponent(optionsGridLayout);

    table.setSizeFull();
    table.setImmediate(true);
    table.setColumnReorderingAllowed(true);
    table.setColumnCollapsingAllowed(true);
    table.addContainerProperty("Name", String.class, null);
    table.addContainerProperty("Surname 1", String.class, null);
    table.addContainerProperty("Surname 2", String.class, null);
    table.addContainerProperty("Miss", CheckBox.class, null);
    table.addContainerProperty("Excused", CheckBox.class, null);
    table.addContainerProperty("Delay", CheckBox.class, null);
    table.addContainerProperty("Expulsion", CheckBox.class, null);

    table.setColumnExpandRatio("Name", 1);
    table.setColumnExpandRatio("Surname 1", 1);
    table.setColumnExpandRatio("Surname 2", 1);

    table.setColumnHeaders(new String[] { app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_NAME"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_SURNAME1"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_SURNAME2"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_MISS"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_EXCUSED"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_DELAY"),
            app.locale.getString("TEACHERMAINLAYOUT_TABLECOLUMN_EXPULSION") });
    addComponent(table);
    setExpandRatio(table, 1);
    setSizeFull();
}

From source file:org.ikasan.dashboard.ui.administration.panel.PolicyManagementPanel.java

License:BSD License

@SuppressWarnings({ "serial" })
protected void init() {
    this.setWidth("100%");
    this.setHeight("100%");

    this.createAssociatedRolesPanel();
    this.createPolicyDropPanel();

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);//  w  w w. j  a  va2s .  co  m
    layout.setSpacing(true);
    layout.setWidth("100%");

    Panel policyAdministrationPanel = new Panel();
    policyAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    policyAdministrationPanel.setHeight("100%");
    policyAdministrationPanel.setWidth("100%");

    GridLayout gridLayout = new GridLayout(2, 6);
    gridLayout.setSizeFull();

    Label roleManagementLabel = new Label("Policy Management");
    roleManagementLabel.setStyleName(ValoTheme.LABEL_HUGE);
    gridLayout.addComponent(roleManagementLabel, 0, 0, 1, 0);

    Label roleSearchHintLabel = new Label();
    roleSearchHintLabel.setCaptionAsHtml(true);
    roleSearchHintLabel.setCaption(
            VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Policy Name field to find a policy.");
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleSearchHintLabel, 0, 1, 1, 1);

    Layout controlLayout = this.initControlLayout();

    gridLayout.addComponent(controlLayout, 0, 2, 1, 2);

    GridLayout formLayout = new GridLayout(2, 4);
    formLayout.setWidth("100%");
    formLayout.setSpacing(true);
    formLayout.setColumnExpandRatio(0, 1);
    formLayout.setColumnExpandRatio(1, 5);

    Label policyNameLabel = new Label("Policy Name:");
    policyNameLabel.setSizeUndefined();
    final DragAndDropWrapper policyNameFieldWrap = initPolicyNameField();

    formLayout.addComponent(policyNameLabel, 0, 0);
    formLayout.setComponentAlignment(policyNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(policyNameFieldWrap, 1, 0);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    this.descriptionField = new TextArea();
    this.descriptionField.setWidth("70%");
    this.descriptionField.setHeight("60px");
    formLayout.addComponent(descriptionLabel, 0, 1);
    formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    formLayout.addComponent(this.descriptionField, 1, 1);

    this.linkTypeLabel.setSizeUndefined();
    formLayout.addComponent(this.linkTypeLabel, 0, 2);
    formLayout.setComponentAlignment(this.linkTypeLabel, Alignment.MIDDLE_RIGHT);
    this.linkType.setWidth("70%");
    formLayout.addComponent(this.linkType, 1, 2);
    this.linkTypeLabel.setVisible(false);
    this.linkType.setVisible(false);

    this.linkedEntityLabel.setSizeUndefined();
    this.linkedEntity = new TextArea();
    this.linkedEntity.setWidth("70%");
    this.linkedEntity.setHeight("60px");

    formLayout.addComponent(this.linkedEntityLabel, 0, 3);
    formLayout.setComponentAlignment(this.linkedEntityLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(linkedEntity, 1, 3);
    this.linkedEntityLabel.setVisible(false);
    this.linkedEntity.setVisible(false);

    gridLayout.addComponent(formLayout, 0, 3, 1, 3);

    Label roleTableHintLabel = new Label();
    roleTableHintLabel.setCaptionAsHtml(true);
    roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Roles table below displays the roles that are assigned the current policy.");
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleTableHintLabel, 0, 4, 1, 4);

    gridLayout.addComponent(this.roleTable, 0, 5, 1, 5);

    policyAdministrationPanel.setContent(gridLayout);
    layout.addComponent(policyAdministrationPanel);

    HorizontalLayout roleMemberPanelLayout = new HorizontalLayout();
    roleMemberPanelLayout.setMargin(true);
    roleMemberPanelLayout.addComponent(this.policyDropPanel);
    roleMemberPanelLayout.setSizeFull();

    HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
    hsplit.setFirstComponent(layout);
    hsplit.setSecondComponent(roleMemberPanelLayout);

    // Set the position of the splitter as percentage
    hsplit.setSplitPosition(65, Unit.PERCENTAGE);
    hsplit.setLocked(true);

    this.setContent(hsplit);
}

From source file:org.ikasan.dashboard.ui.administration.panel.PrincipalManagementPanel.java

License:BSD License

@SuppressWarnings("deprecation")
protected void init() {
    this.setWidth("100%");
    this.setHeight("100%");

    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);//from  ww  w. j  av a  2  s  .  c  om
    layout.setSizeFull();

    Panel securityAdministrationPanel = new Panel();
    securityAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    securityAdministrationPanel.setHeight("100%");
    securityAdministrationPanel.setWidth("100%");

    GridLayout gridLayout = new GridLayout(2, 5);
    gridLayout.setWidth("100%");
    gridLayout.setHeight("100%");
    gridLayout.setMargin(true);
    gridLayout.setSizeFull();

    Label groupManagementLabel = new Label("Group Management");
    groupManagementLabel.setStyleName(ValoTheme.LABEL_HUGE);
    gridLayout.addComponent(groupManagementLabel, 0, 0, 1, 0);

    Label groupSearchHintLabel = new Label();
    groupSearchHintLabel.setCaptionAsHtml(true);
    groupSearchHintLabel.setCaption(
            VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Group Name field to find a group.");
    groupSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    groupSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(groupSearchHintLabel, 0, 1, 1, 1);

    Label principalNameLabel = new Label("Group Name:");
    principalNameLabel.setSizeUndefined();

    principalNameField = new AutocompleteField<IkasanPrincipal>();
    principalNameField.setWidth("70%");

    final DragAndDropWrapper principalNameFieldWrap = new DragAndDropWrapper(principalNameField);
    principalNameFieldWrap.setDragStartMode(DragStartMode.COMPONENT);

    principalTypeField.setWidth("70%");
    descriptionField.setWidth("70%");
    descriptionField.setHeight("60px");

    roleTable.addContainerProperty("Role", String.class, null);
    roleTable.addContainerProperty("", Button.class, null);
    roleTable.setHeight("610px");
    roleTable.setWidth("300px");

    userTable.addContainerProperty("Associated Users", String.class, null);
    userTable.setHeight("610px");
    userTable.setWidth("300px");

    principalDropTable.addContainerProperty("Members", String.class, null);
    principalDropTable.addContainerProperty("", Button.class, null);
    principalDropTable.setHeight("700px");
    principalDropTable.setWidth("300px");

    principalNameField.setQueryListener(new AutocompleteQueryListener<IkasanPrincipal>() {
        @Override
        public void handleUserQuery(AutocompleteField<IkasanPrincipal> field, String query) {
            for (IkasanPrincipal principal : securityService.getPrincipalByNameLike(query)) {
                field.addSuggestion(principal, principal.getName());
            }
        }
    });

    principalNameField.setSuggestionPickedListener(new AutocompleteSuggestionPickedListener<IkasanPrincipal>() {
        @Override
        public void onSuggestionPicked(final IkasanPrincipal principal) {
            PrincipalManagementPanel.this.principal = principal;
            PrincipalManagementPanel.this.setValues();
        }
    });

    GridLayout formLayout = new GridLayout(2, 3);
    formLayout.setWidth("100%");
    formLayout.setHeight("135px");
    formLayout.setSpacing(true);

    formLayout.setColumnExpandRatio(0, .1f);
    formLayout.setColumnExpandRatio(1, .8f);

    formLayout.addComponent(principalNameLabel, 0, 0);
    formLayout.setComponentAlignment(principalNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(principalNameFieldWrap, 1, 0);

    Label principalTypeLabel = new Label("Group Type:");
    principalTypeLabel.setSizeUndefined();
    formLayout.addComponent(principalTypeLabel, 0, 1);
    formLayout.setComponentAlignment(principalTypeLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(principalTypeField, 1, 1);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    formLayout.addComponent(descriptionLabel, 0, 2);
    formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    formLayout.addComponent(descriptionField, 1, 2);

    gridLayout.addComponent(formLayout, 0, 2, 1, 2);

    principalDropTable.setDragMode(TableDragMode.ROW);
    principalDropTable.setDropHandler(new DropHandler() {
        @Override
        public void drop(final DragAndDropEvent dropEvent) {
            // criteria verify that this is safe
            logger.info("Trying to drop: " + dropEvent);

            if (rolesCombo.getValue() == null) {
                // Do nothing if there is no role selected
                logger.info("Ignoring drop: " + dropEvent);
                return;
            }

            final WrapperTransferable t = (WrapperTransferable) dropEvent.getTransferable();

            final AutocompleteField sourceContainer = (AutocompleteField) t.getDraggedComponent();
            logger.info("sourceContainer.getText(): " + sourceContainer.getText());

            Button deleteButton = new Button();

            deleteButton.setIcon(VaadinIcons.TRASH);
            deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
            deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

            final IkasanPrincipal principal = securityService.findPrincipalByName(sourceContainer.getText());
            final Role roleToRemove = (Role) rolesCombo.getValue();

            deleteButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    principalDropTable.removeItem(principal.getName());

                    principal.getRoles().remove(roleToRemove);

                    securityService.savePrincipal(principal);

                    if (principalNameField.getText().equals(principal.getName())) {
                        roleTable.removeItem(roleToRemove);
                    }
                }
            });

            principalDropTable.addItem(new Object[] { sourceContainer.getText(), deleteButton },
                    sourceContainer.getText());

            principal.getRoles().add((Role) rolesCombo.getValue());

            securityService.savePrincipal(principal);

            roleTable.removeAllItems();

            for (final Role role : principal.getRoles()) {
                Button roleDeleteButton = new Button();
                roleDeleteButton.setIcon(VaadinIcons.TRASH);
                roleDeleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                roleDeleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

                roleDeleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        roleTable.removeItem(role);

                        principal.getRoles().remove(role);

                        securityService.savePrincipal(principal);

                        principalDropTable.removeItem(principal.getName());
                    }
                });

                roleTable.addItem(new Object[] { role.getName(), roleDeleteButton }, role);
            }
        }

        @Override
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    Label roleTableHintLabel = new Label();
    roleTableHintLabel.setCaptionAsHtml(true);
    roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Roles table below displays the roles that are assigned to the group. Roles can be deleted from this table.");
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleTableHintLabel, 0, 3, 1, 3);

    gridLayout.addComponent(roleTable, 0, 4);
    gridLayout.addComponent(userTable, 1, 4);

    this.rolesCombo = new ComboBox("Roles");
    this.rolesCombo.setWidth("90%");
    this.rolesCombo.addListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            final Role role = (Role) event.getProperty().getValue();

            if (role != null) {
                logger.info("Value changed got Role: " + role);

                List<IkasanPrincipal> principals = securityService.getAllPrincipalsWithRole(role.getName());

                principalDropTable.removeAllItems();

                for (final IkasanPrincipal principal : principals) {
                    Button deleteButton = new Button();

                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            principalDropTable.removeItem(principal.getName());

                            principal.getRoles().remove(role);

                            securityService.savePrincipal(principal);

                            if (principalNameField.getText().equals(principal.getName())) {
                                roleTable.removeItem(role);
                            }
                        }
                    });

                    principalDropTable.addItem(new Object[] { principal.getName(), deleteButton },
                            principal.getName());
                }
            }
        }
    });

    Panel roleMemberPanel = new Panel();

    roleMemberPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    roleMemberPanel.setHeight("100%");
    roleMemberPanel.setWidth("100%");

    GridLayout roleMemberLayout = new GridLayout();
    roleMemberLayout.setSpacing(true);
    roleMemberLayout.setWidth("100%");
    roleMemberLayout.setHeight("100%");

    Label roleGroupLabels = new Label("Role/Group Associations");
    roleGroupLabels.setStyleName(ValoTheme.LABEL_HUGE);
    gridLayout.addComponent(roleGroupLabels);

    Label groupDragHintLabel = new Label();
    groupDragHintLabel.setCaptionAsHtml(true);
    groupDragHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drop groups into the table below to assign them the role.");

    roleMemberLayout.addComponent(roleGroupLabels);
    roleMemberLayout.addComponent(groupDragHintLabel);
    roleMemberLayout.addComponent(this.rolesCombo);
    roleMemberLayout.addComponent(this.principalDropTable);

    roleMemberPanel.setContent(roleMemberLayout);

    securityAdministrationPanel.setContent(gridLayout);
    layout.addComponent(securityAdministrationPanel);

    VerticalLayout roleMemberPanelLayout = new VerticalLayout();
    roleMemberPanelLayout.setWidth("100%");
    roleMemberPanelLayout.setHeight("100%");
    roleMemberPanelLayout.setMargin(true);
    roleMemberPanelLayout.addComponent(roleMemberPanel);
    roleMemberPanelLayout.setSizeFull();

    HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
    hsplit.setFirstComponent(layout);
    hsplit.setSecondComponent(roleMemberPanelLayout);

    // Set the position of the splitter as percentage
    hsplit.setSplitPosition(65, Unit.PERCENTAGE);
    hsplit.setLocked(true);

    this.setContent(hsplit);
}

From source file:org.ikasan.dashboard.ui.administration.panel.RoleManagementPanel.java

License:BSD License

@SuppressWarnings({ "serial" })
protected void init() {
    this.setWidth("100%");
    this.setHeight("100%");

    this.initPolicyNameField();
    this.createPolicyDropPanel();

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();//from   w  ww.  j  a  va2 s. c om

    Panel roleAdministrationPanel = new Panel();
    roleAdministrationPanel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    roleAdministrationPanel.setHeight("100%");
    roleAdministrationPanel.setWidth("100%");

    GridLayout gridLayout = new GridLayout(2, 6);
    gridLayout.setWidth("100%");
    gridLayout.setHeight("100%");
    gridLayout.setMargin(true);
    gridLayout.setSizeFull();

    Label roleManagementLabel = new Label("Role Management");
    roleManagementLabel.setStyleName(ValoTheme.LABEL_HUGE);
    gridLayout.addComponent(roleManagementLabel, 0, 0, 1, 0);

    Label roleSearchHintLabel = new Label();
    roleSearchHintLabel.setCaptionAsHtml(true);
    roleSearchHintLabel.setCaption(
            VaadinIcons.QUESTION_CIRCLE_O.getHtml() + " Type into the Role Name field to find a role.");
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleSearchHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleSearchHintLabel, 0, 1, 1, 1);

    Layout controlLayout = this.initControlLayout();

    gridLayout.addComponent(controlLayout, 0, 2, 1, 2);

    Label roleNameLabel = new Label("Role Name:");
    roleNameLabel.setSizeUndefined();
    initRoleNameField();

    GridLayout formLayout = new GridLayout(2, 2);
    formLayout.setWidth("100%");
    formLayout.setHeight("115px");
    formLayout.setSpacing(true);

    formLayout.setColumnExpandRatio(0, 1);
    formLayout.setColumnExpandRatio(1, 5);

    this.roleNameField.setWidth("70%");
    formLayout.addComponent(roleNameLabel, 0, 0);
    formLayout.setComponentAlignment(roleNameLabel, Alignment.MIDDLE_RIGHT);
    formLayout.addComponent(this.roleNameField, 1, 0);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    this.descriptionField = new TextArea();
    this.descriptionField.setWidth("70%");
    this.descriptionField.setHeight("60px");
    formLayout.addComponent(descriptionLabel, 0, 1);
    formLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    formLayout.addComponent(descriptionField, 1, 1);

    gridLayout.addComponent(formLayout, 0, 3, 1, 3);

    Label roleTableHintLabel = new Label();
    roleTableHintLabel.setCaptionAsHtml(true);
    roleTableHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " The Associated Users/Groups table below displays the users/groups that are assigned the current role.");
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    roleTableHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    gridLayout.addComponent(roleTableHintLabel, 0, 4, 1, 4);

    this.associatedPrincipalsTable = new Table();
    this.associatedPrincipalsTable.addItemClickListener(this.associatedPrincipalItemClickListener);
    this.associatedPrincipalsTable.addContainerProperty("Associated Users/Groups", String.class, null);
    this.associatedPrincipalsTable.addContainerProperty("", Button.class, null);
    this.associatedPrincipalsTable.setHeight("600px");
    this.associatedPrincipalsTable.setWidth("650px");

    gridLayout.addComponent(this.associatedPrincipalsTable, 0, 5, 1, 5);

    roleAdministrationPanel.setContent(gridLayout);
    layout.addComponent(roleAdministrationPanel);

    HorizontalLayout policyDropPanelLayout = new HorizontalLayout();
    policyDropPanelLayout.setMargin(true);
    policyDropPanelLayout.addComponent(this.policyDropPanel);
    policyDropPanelLayout.setSizeFull();

    HorizontalSplitPanel hsplit = new HorizontalSplitPanel();
    hsplit.setFirstComponent(layout);
    hsplit.setSecondComponent(policyDropPanelLayout);

    // Set the position of the splitter as percentage
    hsplit.setSplitPosition(65, Unit.PERCENTAGE);
    hsplit.setLocked(true);

    this.setContent(hsplit);
}

From source file:org.ikasan.dashboard.ui.administration.window.NewPolicyWindow.java

License:BSD License

public void init() {
    this.setModal(true);
    this.setResizable(false);

    this.setWidth("600px");
    this.setHeight("400px");

    GridLayout gridLayout = new GridLayout(2, 8);
    gridLayout.setWidth("100%");
    gridLayout.setMargin(true);// w w w  . j ava  2s.  com
    gridLayout.setSpacing(true);

    gridLayout.setColumnExpandRatio(0, .1f);
    gridLayout.setColumnExpandRatio(1, .9f);

    Label createNewPolicyLabel = new Label("Create a New Policy");
    createNewPolicyLabel.setStyleName(ValoTheme.LABEL_HUGE);

    gridLayout.addComponent(createNewPolicyLabel, 0, 0, 1, 0);

    Label nameLabel = new Label("Name:");
    nameLabel.setSizeUndefined();
    this.policyName = new TextField();
    this.policyName.addValidator(new StringLengthValidator("A name must be entered.", 1, null, false));
    this.policyName.setWidth("80%");

    gridLayout.addComponent(nameLabel, 0, 1);
    gridLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(policyName, 1, 1);

    Label descriptionLabel = new Label("Description");
    descriptionLabel.setSizeUndefined();
    this.policyDescription = new TextArea();
    this.policyDescription
            .addValidator(new StringLengthValidator("A description must be entered.", 1, null, false));
    this.policyDescription.setRows(4);
    this.policyDescription.setWidth("80%");

    this.policyName.setValidationVisible(false);
    this.policyDescription.setValidationVisible(false);

    gridLayout.addComponent(descriptionLabel, 0, 2);
    gridLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    gridLayout.addComponent(policyDescription, 1, 2);

    Button createButton = new Button("Create");
    Button cancelButton = new Button("Cancel");

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(createButton);
    buttonLayout.setComponentAlignment(createButton, Alignment.MIDDLE_CENTER);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER);

    BeanItem<Policy> policyItem = new BeanItem<Policy>(this.policy);

    this.policyName.setPropertyDataSource(policyItem.getItemProperty("name"));
    this.policyDescription.setPropertyDataSource(policyItem.getItemProperty("description"));

    Label linkTypeLabel = new Label("Policy Link Type");
    linkTypeLabel.setSizeUndefined();
    gridLayout.addComponent(linkTypeLabel, 0, 3);
    gridLayout.setComponentAlignment(linkTypeLabel, Alignment.TOP_RIGHT);
    this.linkTypeCombo.setWidth("80%");
    gridLayout.addComponent(this.linkTypeCombo, 1, 3);

    List<PolicyLinkType> policyLinkTypes = this.securityService.getAllPolicyLinkTypes();

    this.linkTypeCombo.removeAllItems();

    for (PolicyLinkType policyLinkType : policyLinkTypes) {
        this.linkTypeCombo.addItem(policyLinkType);
        this.linkTypeCombo.setItemCaption(policyLinkType, policyLinkType.getName());
    }

    policyLinkHintLabel.setCaptionAsHtml(true);
    policyLinkHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " You are linking this policy to an entity. Click link below to search for the entity to link to.");
    policyLinkHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    policyLinkHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    policyLinkHintLabel.setVisible(false);
    gridLayout.addComponent(policyLinkHintLabel, 0, 4, 1, 4);

    linkButton.setStyleName(ValoTheme.BUTTON_LINK);
    linkButton.setVisible(false);
    linkButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            PolicyLinkType policyLinkType = (PolicyLinkType) NewPolicyWindow.this.linkTypeCombo.getValue();

            if (policyLinkType.getName().equals(PolicyLinkTypeConstants.MAPPING_CONFIGURATION_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationMappingSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationMappingSearchWindow);
            } else if (policyLinkType.getName().equals(PolicyLinkTypeConstants.MODULE_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationModuleSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationModuleSearchWindow);
            } else if (policyLinkType.getName().equals(PolicyLinkTypeConstants.FLOW_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationFlowSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationFlowSearchWindow);
            } else if (policyLinkType.getName().equals(PolicyLinkTypeConstants.BUSINESS_STREAM_LINK_TYPE)) {
                NewPolicyWindow.this.policyAssociationBusinessStreamSearchWindow.clear();
                UI.getCurrent().addWindow(NewPolicyWindow.this.policyAssociationBusinessStreamSearchWindow);
            }
        }
    });
    gridLayout.addComponent(this.linkButton, 1, 5);

    final Label linkedEntityLabel = new Label("Linked to");
    linkedEntityLabel.setSizeUndefined();

    this.linkedEntity = new TextArea();
    this.linkedEntity.addValidator(new StringLengthValidator(
            "If a Policy Link Type is selected, you must link to an approptiate entity.", 1, null, false));
    this.linkedEntity.setWidth("80%");
    this.linkedEntity.setValidationVisible(false);
    this.linkedEntity.setHeight("60px");

    gridLayout.addComponent(linkedEntityLabel, 0, 6);
    gridLayout.setComponentAlignment(linkedEntityLabel, Alignment.TOP_RIGHT);
    gridLayout.addComponent(linkedEntity, 1, 6);
    linkedEntityLabel.setVisible(false);
    linkedEntity.setVisible(false);

    this.policyAssociationMappingSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationMappingSearchWindow.getMappingConfiguration() != null) {
                NewPolicyWindow.this.linkedEntity.setValue(
                        policyAssociationMappingSearchWindow.getMappingConfiguration().toStringLite());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationMappingSearchWindow
                        .getMappingConfiguration().getId();
            }
        }
    });

    this.policyAssociationFlowSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationFlowSearchWindow.getFlow() != null) {
                NewPolicyWindow.this.linkedEntity
                        .setValue(policyAssociationFlowSearchWindow.getFlow().toString());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationFlowSearchWindow
                        .getFlow().getId();
            }
        }
    });

    this.policyAssociationModuleSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationModuleSearchWindow.getModule() != null) {
                NewPolicyWindow.this.linkedEntity
                        .setValue(policyAssociationModuleSearchWindow.getModule().toString());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationModuleSearchWindow
                        .getModule().getId();
            }
        }
    });

    this.policyAssociationBusinessStreamSearchWindow.addCloseListener(new Window.CloseListener() {
        // inline close-listener
        public void windowClose(CloseEvent e) {
            if (policyAssociationBusinessStreamSearchWindow.getBusinessStream() != null) {
                NewPolicyWindow.this.linkedEntity
                        .setValue(policyAssociationBusinessStreamSearchWindow.getBusinessStream().toString());
                NewPolicyWindow.this.associatedEntityId = NewPolicyWindow.this.policyAssociationBusinessStreamSearchWindow
                        .getBusinessStream().getId();
            }
        }

    });

    this.linkTypeCombo.addValueChangeListener(new Property.ValueChangeListener() {
        public void valueChange(ValueChangeEvent event) {
            final PolicyLinkType policyLinkType = (PolicyLinkType) event.getProperty().getValue();

            if (policyLinkType != null) {
                linkButton.setVisible(true);
                linkedEntityLabel.setVisible(true);
                linkedEntity.setVisible(true);
                policyLinkHintLabel.setVisible(true);
            } else {
                linkButton.setVisible(false);
                linkedEntityLabel.setVisible(false);
                linkedEntity.setVisible(false);
                policyLinkHintLabel.setVisible(false);
            }
        }
    });

    gridLayout.addComponent(buttonLayout, 0, 7, 1, 7);
    gridLayout.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER);

    createButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                NewPolicyWindow.this.policyName.validate();
                NewPolicyWindow.this.policyDescription.validate();

                if (linkTypeCombo.getValue() != null) {
                    NewPolicyWindow.this.linkedEntity.validate();
                }
            } catch (InvalidValueException e) {
                NewPolicyWindow.this.policyName.setValidationVisible(true);
                NewPolicyWindow.this.policyDescription.setValidationVisible(true);
                NewPolicyWindow.this.linkedEntity.setValidationVisible(true);

                return;
            }

            NewPolicyWindow.this.policyName.setValidationVisible(false);
            NewPolicyWindow.this.policyDescription.setValidationVisible(false);
            NewPolicyWindow.this.linkedEntity.setValidationVisible(false);

            if (linkTypeCombo.getValue() != null) {
                PolicyLinkType policyLinkType = (PolicyLinkType) linkTypeCombo.getValue();
                String linkedEntityName = linkedEntity.getValue();
                PolicyLink policyLink = new PolicyLink(policyLinkType, associatedEntityId, linkedEntityName);

                securityService.savePolicyLink(policyLink);

                policy.setPolicyLink(policyLink);

                try {
                    securityService.savePolicy(policy);
                } catch (DataIntegrityViolationException e) {
                    Notification.show(
                            "Policy name must be unique. Please confirm that this policy does not already exist!",
                            Notification.Type.ERROR_MESSAGE);

                    return;
                } catch (RuntimeException e) {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    e.printStackTrace(pw);

                    Notification.show("Caught exception trying to save a Policy!", sw.toString(),
                            Notification.Type.ERROR_MESSAGE);

                    return;
                }
            } else {
                PolicyLink policyLink = policy.getPolicyLink();
                policy.setPolicyLink(null);

                try {
                    securityService.savePolicy(policy);
                } catch (DataIntegrityViolationException e) {
                    Notification.show(
                            "Policy name must be unique. Please confirm that this policy does not already exist!",
                            Notification.Type.ERROR_MESSAGE);

                    return;
                } catch (RuntimeException e) {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    e.printStackTrace(pw);

                    Notification.show("Caught exception trying to save a Policy!", sw.toString(),
                            Notification.Type.ERROR_MESSAGE);

                    return;
                }

                if (policyLink != null) {
                    securityService.deletePolicyLink(policyLink);
                }
            }

            Notification.show("New policy successfully created!");

            UI.getCurrent().removeWindow(NewPolicyWindow.this);
        }
    });

    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().removeWindow(NewPolicyWindow.this);
        }
    });

    this.setContent(gridLayout);
}

From source file:org.ikasan.dashboard.ui.administration.window.NewRoleWindow.java

License:BSD License

public void init() {
    this.setWidth("550px");
    this.setHeight("240px");
    this.setModal(true);
    this.setResizable(false);

    GridLayout gridLayout = new GridLayout(2, 4);
    gridLayout.setWidth("100%");
    gridLayout.setMargin(true);/*  w  w  w  . j a  v a  2 s . com*/
    gridLayout.setSpacing(true);

    gridLayout.setColumnExpandRatio(0, .1f);
    gridLayout.setColumnExpandRatio(1, .9f);

    Label createNewRoleLabel = new Label("Create a New Role");
    createNewRoleLabel.setStyleName(ValoTheme.LABEL_HUGE);

    gridLayout.addComponent(createNewRoleLabel, 0, 0, 1, 0);

    Label nameLabel = new Label("Name:");
    nameLabel.setSizeUndefined();
    this.roleName = new TextField();
    this.roleName.addValidator(new StringLengthValidator("A name must be entered.", 1, null, false));
    this.roleName.setWidth("80%");

    gridLayout.addComponent(nameLabel, 0, 1);
    gridLayout.setComponentAlignment(nameLabel, Alignment.MIDDLE_RIGHT);
    gridLayout.addComponent(roleName, 1, 1);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    this.roleDescription = new TextArea();
    this.roleDescription
            .addValidator(new StringLengthValidator("A description must be entered.", 1, null, false));
    this.roleDescription.setRows(4);
    roleDescription.setWidth("80%");

    this.roleName.setValidationVisible(false);
    this.roleDescription.setValidationVisible(false);

    gridLayout.addComponent(descriptionLabel, 0, 2);
    gridLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);
    gridLayout.addComponent(roleDescription, 1, 2);

    Button createButton = new Button("Save");
    Button cancelButton = new Button("Cancel");

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(createButton);
    buttonLayout.setComponentAlignment(createButton, Alignment.MIDDLE_CENTER);
    buttonLayout.addComponent(cancelButton);
    buttonLayout.setComponentAlignment(cancelButton, Alignment.MIDDLE_CENTER);

    gridLayout.addComponent(buttonLayout, 0, 3, 1, 3);
    gridLayout.setComponentAlignment(buttonLayout, Alignment.MIDDLE_CENTER);

    BeanItem<Role> policyItem = new BeanItem<Role>(this.role);

    roleName.setPropertyDataSource(policyItem.getItemProperty("name"));
    roleDescription.setPropertyDataSource(policyItem.getItemProperty("description"));

    createButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                NewRoleWindow.this.roleName.validate();
                NewRoleWindow.this.roleDescription.validate();
            } catch (InvalidValueException e) {
                NewRoleWindow.this.roleName.setValidationVisible(true);
                NewRoleWindow.this.roleDescription.setValidationVisible(true);

                return;
            }

            NewRoleWindow.this.roleName.setValidationVisible(false);
            NewRoleWindow.this.roleDescription.setValidationVisible(false);

            UI.getCurrent().removeWindow(NewRoleWindow.this);

            securityService.saveRole(role);

            Notification.show("Role successfully created!");
        }
    });

    cancelButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            UI.getCurrent().removeWindow(NewRoleWindow.this);
        }
    });

    this.setContent(gridLayout);
}

From source file:org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationPanel.java

License:BSD License

/**
 * Helper method to create the form associated with the mapping
 * configuration.//from ww  w  . j  a  va 2  s  . co m
 * 
 * @return the Layout of the form
 */
protected GridLayout createMappingConfigurationForm() {
    Label mappingConfigurationLabel = new Label(this.name);
    mappingConfigurationLabel.setStyleName(ValoTheme.LABEL_HUGE);
    layout.addComponent(mappingConfigurationLabel, 0, 0, 1, 0);

    HorizontalLayout clientLabelLayout = new HorizontalLayout();
    clientLabelLayout.setHeight(25, Unit.PIXELS);
    clientLabelLayout.setWidth(100, Unit.PIXELS);

    Label clientLabel = new Label("Client:");
    clientLabel.setSizeUndefined();
    clientLabelLayout.addComponent(clientLabel);
    clientLabelLayout.setComponentAlignment(clientLabel, Alignment.MIDDLE_RIGHT);

    layout.addComponent(clientLabelLayout, 0, 1);
    layout.setComponentAlignment(clientLabelLayout, Alignment.MIDDLE_RIGHT);

    HorizontalLayout clientComboBoxLayout = new HorizontalLayout();
    clientComboBoxLayout.setHeight(25, Unit.PIXELS);
    clientComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.clientComboBox.setWidth(300, Unit.PIXELS);
    this.clientComboBox.removeAllValidators();
    this.clientComboBox.addValidator(new NullValidator("A client must be selected!", false));
    this.clientComboBox.setValidationVisible(false);
    clientComboBoxLayout.addComponent(this.clientComboBox);
    layout.addComponent(clientComboBoxLayout, 1, 1);

    HorizontalLayout typeLabelLayout = new HorizontalLayout();
    typeLabelLayout.setHeight(25, Unit.PIXELS);
    typeLabelLayout.setWidth(100, Unit.PIXELS);

    Label typeLabel = new Label("Type:");
    typeLabel.setSizeUndefined();
    typeLabelLayout.addComponent(typeLabel);
    typeLabelLayout.setComponentAlignment(typeLabel, Alignment.MIDDLE_RIGHT);

    layout.addComponent(typeLabelLayout, 0, 2);
    layout.setComponentAlignment(typeLabelLayout, Alignment.MIDDLE_RIGHT);

    HorizontalLayout typeComboBoxLayout = new HorizontalLayout();
    typeComboBoxLayout.setHeight(25, Unit.PIXELS);
    typeComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.typeComboBox.setWidth(300, Unit.PIXELS);
    this.typeComboBox.removeAllValidators();
    this.typeComboBox.addValidator(new NullValidator("A type must be selected!", false));
    this.typeComboBox.setValidationVisible(false);
    typeComboBoxLayout.addComponent(this.typeComboBox);
    layout.addComponent(typeComboBoxLayout, 1, 2);

    HorizontalLayout sourceContextLabelLayout = new HorizontalLayout();
    sourceContextLabelLayout.setHeight(25, Unit.PIXELS);
    sourceContextLabelLayout.setWidth(100, Unit.PIXELS);

    Label sourceContextLabel = new Label("Source Context:");
    sourceContextLabel.setSizeUndefined();
    sourceContextLabelLayout.addComponent(sourceContextLabel);
    sourceContextLabelLayout.setComponentAlignment(sourceContextLabel, Alignment.MIDDLE_RIGHT);

    layout.addComponent(sourceContextLabelLayout, 0, 3);
    layout.setComponentAlignment(sourceContextLabelLayout, Alignment.MIDDLE_RIGHT);

    HorizontalLayout sourceContextComboBoxLayout = new HorizontalLayout();
    sourceContextComboBoxLayout.setHeight(25, Unit.PIXELS);
    sourceContextComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.sourceContextComboBox.setWidth(300, Unit.PIXELS);
    this.sourceContextComboBox.removeAllValidators();
    this.sourceContextComboBox.addValidator(new NullValidator("A source context must be selected", false));
    this.sourceContextComboBox.setValidationVisible(false);
    sourceContextComboBoxLayout.addComponent(this.sourceContextComboBox);
    layout.addComponent(sourceContextComboBoxLayout, 1, 3);

    HorizontalLayout targetContextLabelLayout = new HorizontalLayout();
    targetContextLabelLayout.setHeight(25, Unit.PIXELS);
    targetContextLabelLayout.setWidth(100, Unit.PIXELS);

    Label targetContextLabel = new Label("Target Context:");
    targetContextLabel.setSizeUndefined();
    targetContextLabelLayout.addComponent(targetContextLabel);
    targetContextLabelLayout.setComponentAlignment(targetContextLabel, Alignment.MIDDLE_RIGHT);

    layout.addComponent(targetContextLabelLayout, 0, 4);
    layout.setComponentAlignment(targetContextLabelLayout, Alignment.MIDDLE_RIGHT);

    HorizontalLayout targetContextComboBoxLayout = new HorizontalLayout();
    targetContextComboBoxLayout.setHeight(25, Unit.PIXELS);
    targetContextComboBoxLayout.setWidth(350, Unit.PIXELS);
    this.targetContextComboBox.setWidth(300, Unit.PIXELS);
    this.targetContextComboBox.removeAllValidators();
    this.targetContextComboBox.addValidator(new NullValidator("A target context must be selected", false));
    this.targetContextComboBox.setValidationVisible(false);
    targetContextComboBoxLayout.addComponent(this.targetContextComboBox);
    layout.addComponent(this.targetContextComboBox, 1, 4);

    HorizontalLayout descriptionLabelLayout = new HorizontalLayout();
    descriptionLabelLayout.setHeight(25, Unit.PIXELS);
    descriptionLabelLayout.setWidth(100, Unit.PIXELS);

    Label descriptionLabel = new Label("Description:");
    descriptionLabel.setSizeUndefined();
    descriptionLabelLayout.addComponent(descriptionLabel);
    descriptionLabelLayout.setComponentAlignment(descriptionLabel, Alignment.TOP_RIGHT);

    layout.addComponent(descriptionLabelLayout, 0, 5);
    layout.setComponentAlignment(descriptionLabelLayout, Alignment.TOP_RIGHT);

    HorizontalLayout descriptionTextAreaLayout = new HorizontalLayout();
    descriptionTextAreaLayout.setHeight(75, Unit.PIXELS);
    descriptionTextAreaLayout.setWidth(350, Unit.PIXELS);
    this.descriptionTextArea = new TextArea();
    this.descriptionTextArea.setWidth(300, Unit.PIXELS);
    this.descriptionTextArea.setRows(4);
    this.descriptionTextArea
            .addValidator(new StringLengthValidator("A description must be entered.", 1, null, true));
    this.descriptionTextArea.setValidationVisible(false);
    descriptionTextAreaLayout.addComponent(this.descriptionTextArea);
    layout.addComponent(descriptionTextAreaLayout, 1, 5);

    Label numParamsLabel = new Label("Number of source parameters:");
    numParamsLabel.setWidth(175, Unit.PIXELS);

    layout.addComponent(numParamsLabel, 2, 1);
    this.numberOfParametersTextField = new TextField();
    this.numberOfParametersTextField.setWidth(75, Unit.PIXELS);
    this.numberOfParametersTextField.removeAllValidators();
    this.numberOfParametersTextField.addValidator(
            new LongValidator("Number of source parameters " + "and key location queries must be defined."));
    this.numberOfParametersTextField.setValidationVisible(false);
    layout.addComponent(this.numberOfParametersTextField, 3, 1);

    HorizontalLayout queriesLabelLayout = new HorizontalLayout();
    queriesLabelLayout.setHeight(25, Unit.PIXELS);
    queriesLabelLayout.setWidth(250, Unit.PIXELS);

    return layout;
}