Example usage for com.vaadin.ui GridLayout setWidth

List of usage examples for com.vaadin.ui GridLayout setWidth

Introduction

In this page you can find the example usage for com.vaadin.ui GridLayout setWidth.

Prototype

@Override
    public void setWidth(String width) 

Source Link

Usage

From source file:org.balisunrise.vaadin.components.user.UserPanel.java

License:Open Source License

private void init() {

    model = new CreateUserModel();
    BeanItem<CreateUserModel> item = new BeanItem<>(model);
    FieldGroup fg = new FieldGroup(item);

    nome = new TextField("Nome");
    nome.setWidth("100%");
    nome.setMaxLength(50);/*from w  w w. j ava 2 s .co m*/
    fg.bind(nome, "nome");

    login = new TextField("Login");
    login.setWidth("100%");
    login.setMaxLength(32);
    fg.bind(login, "login");

    senha = new PasswordField("Senha");
    senha.setWidth("100%");
    senha.setMaxLength(32);
    fg.bind(senha, "senha");

    repita = new PasswordField("Repita a senha");
    repita.setWidth("100%");
    repita.setMaxLength(32);
    fg.bind(repita, "repita");

    GridLayout grid = new GridLayout(20, 1);
    grid.setWidth("100%");
    grid.setHeightUndefined();
    grid.setSpacing(true);

    grid.addComponent(nome, 0, 0, 9, 0);
    grid.addComponent(login, 10, 0, 19, 0);
    grid.setRows(2);
    grid.addComponent(senha, 0, 1, 9, 1);
    grid.addComponent(repita, 10, 1, 19, 1);

    addComponent(grid);
    setSpacing(true);

    repita.addBlurListener((e) -> {
        try {
            fg.commit();
            Notification.show("Changes committed!\n" + model.toString(), Notification.Type.TRAY_NOTIFICATION);
        } catch (final FieldGroup.CommitException ex) {
            Notification.show("Commit failed: " + ex.getCause().getMessage(),
                    Notification.Type.TRAY_NOTIFICATION);
        }
    });
}

From source file:org.diretto.web.richwebclient.view.windows.UploadSettingsWindow.java

/**
 * Constructs an {@link UploadSettingsWindow}.
 * /* ww w . j ava 2 s .com*/
 * @param mainWindow The corresponding {@code MainWindow}
 * @param uploadSection The corresponding {@code UploadSection}
 * @param fileInfo The {@code FileInfo} object
 * @param mediaType The {@code MediaType} of the file
 * @param uploadSettings The corresponding {@code UploadSettings}
 * @param otherFiles The names of the other upload files
 */
public UploadSettingsWindow(final MainWindow mainWindow, final UploadSection uploadSection, FileInfo fileInfo,
        MediaType mediaType, UploadSettings uploadSettings, List<String> otherFiles) {
    super("Upload Settings");

    this.mainWindow = mainWindow;

    setModal(true);
    setStyleName(Reindeer.WINDOW_BLACK);
    setWidth("940px");
    setHeight((((int) mainWindow.getHeight()) - 160) + "px");
    setResizable(false);
    setClosable(false);
    setDraggable(false);
    setPositionX((int) (mainWindow.getWidth() / 2.0f) - 470);
    setPositionY(126);

    wrapperLayout = new HorizontalLayout();
    wrapperLayout.setSizeFull();
    wrapperLayout.setMargin(true, true, true, true);
    addComponent(wrapperLayout);

    mainLayout = new VerticalLayout();
    mainLayout.setSizeFull();
    mainLayout.setSpacing(true);

    HorizontalLayout titleLayout = new HorizontalLayout();
    titleLayout.setWidth("100%");
    mainLayout.addComponent(titleLayout);

    HorizontalLayout leftTitleLayout = new HorizontalLayout();
    titleLayout.addComponent(leftTitleLayout);
    titleLayout.setComponentAlignment(leftTitleLayout, Alignment.MIDDLE_LEFT);

    Label fileNameLabel = StyleUtils.getLabelH2(fileInfo.getName());
    leftTitleLayout.addComponent(fileNameLabel);
    leftTitleLayout.setComponentAlignment(fileNameLabel, Alignment.MIDDLE_LEFT);

    Label bullLabel = StyleUtils.getLabelHTML(
            "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&bull;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    leftTitleLayout.addComponent(bullLabel);
    leftTitleLayout.setComponentAlignment(bullLabel, Alignment.MIDDLE_LEFT);

    Label titleLabel = StyleUtils.getLabelHTML("<b>Title</b>&nbsp;&nbsp;&nbsp;");
    leftTitleLayout.addComponent(titleLabel);
    leftTitleLayout.setComponentAlignment(titleLabel, Alignment.MIDDLE_LEFT);

    final TextField titleField = new TextField();
    titleField.setMaxLength(50);
    titleField.setWidth("100%");
    titleField.setImmediate(true);

    if (uploadSettings != null && uploadSettings.getTitle() != null) {
        titleField.setValue(uploadSettings.getTitle());
    }

    titleField.focus();
    titleField.setCursorPosition(((String) titleField.getValue()).length());

    titleLayout.addComponent(titleField);
    titleLayout.setComponentAlignment(titleField, Alignment.MIDDLE_RIGHT);

    titleLayout.setExpandRatio(leftTitleLayout, 0);
    titleLayout.setExpandRatio(titleField, 1);

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    GridLayout topGridLayout = new GridLayout(2, 3);
    topGridLayout.setColumnExpandRatio(0, 1.0f);
    topGridLayout.setColumnExpandRatio(1, 0.0f);
    topGridLayout.setWidth("100%");
    topGridLayout.setSpacing(true);
    mainLayout.addComponent(topGridLayout);

    Label descriptionLabel = StyleUtils.getLabelBold("Description");
    topGridLayout.addComponent(descriptionLabel, 0, 0);

    final TextArea descriptionArea = new TextArea();
    descriptionArea.setSizeFull();
    descriptionArea.setImmediate(true);

    if (uploadSettings != null && uploadSettings.getDescription() != null) {
        descriptionArea.setValue(uploadSettings.getDescription());
    }

    topGridLayout.addComponent(descriptionArea, 0, 1);

    VerticalLayout tagsWrapperLayout = new VerticalLayout();
    tagsWrapperLayout.setHeight("30px");
    tagsWrapperLayout.setSpacing(false);
    topGridLayout.addComponent(tagsWrapperLayout, 0, 2);

    HorizontalLayout tagsLayout = new HorizontalLayout();
    tagsLayout.setWidth("100%");
    tagsLayout.setSpacing(true);

    Label tagsLabel = StyleUtils.getLabelBoldHTML("Tags&nbsp;");
    tagsLabel.setSizeUndefined();
    tagsLayout.addComponent(tagsLabel);
    tagsLayout.setComponentAlignment(tagsLabel, Alignment.MIDDLE_LEFT);

    addTagField = new TextField();
    addTagField.setImmediate(true);
    addTagField.setInputPrompt("Enter new Tag");

    addTagField.addShortcutListener(new ShortcutListener(null, KeyCode.ENTER, new int[0]) {
        private static final long serialVersionUID = -4767515198819351723L;

        @Override
        public void handleAction(Object sender, Object target) {
            if (target == addTagField) {
                addTag();
            }
        }
    });

    tagsLayout.addComponent(addTagField);
    tagsLayout.setComponentAlignment(addTagField, Alignment.MIDDLE_LEFT);

    tabSheet = new TabSheet();

    tabSheet.setStyleName(Reindeer.TABSHEET_SMALL);
    tabSheet.addStyleName("view");

    tabSheet.addListener(new ComponentDetachListener() {
        private static final long serialVersionUID = -657657505471281795L;

        @Override
        public void componentDetachedFromContainer(ComponentDetachEvent event) {
            tags.remove(tabSheet.getTab(event.getDetachedComponent()).getCaption());
        }
    });

    Button addTagButton = new Button("Add", new Button.ClickListener() {
        private static final long serialVersionUID = 5914473126402594623L;

        @Override
        public void buttonClick(ClickEvent event) {
            addTag();
        }
    });

    addTagButton.setStyleName(Reindeer.BUTTON_DEFAULT);

    tagsLayout.addComponent(addTagButton);
    tagsLayout.setComponentAlignment(addTagButton, Alignment.MIDDLE_LEFT);

    Label spaceLabel = StyleUtils.getLabelHTML("");
    spaceLabel.setSizeUndefined();
    tagsLayout.addComponent(spaceLabel);
    tagsLayout.setComponentAlignment(spaceLabel, Alignment.MIDDLE_LEFT);

    tagsLayout.addComponent(tabSheet);
    tagsLayout.setComponentAlignment(tabSheet, Alignment.MIDDLE_LEFT);
    tagsLayout.setExpandRatio(tabSheet, 1.0f);

    tagsWrapperLayout.addComponent(tagsLayout);
    tagsWrapperLayout.setComponentAlignment(tagsLayout, Alignment.TOP_LEFT);

    if (uploadSettings != null && uploadSettings.getTags() != null && uploadSettings.getTags().size() > 0) {
        for (String tag : uploadSettings.getTags()) {
            addTagField.setValue(tag);

            addTag();
        }
    }

    Label presettingLabel = StyleUtils.getLabelBold("Presetting");
    topGridLayout.addComponent(presettingLabel, 1, 0);

    final TwinColSelect twinColSelect;

    if (otherFiles != null && otherFiles.size() > 0) {
        twinColSelect = new TwinColSelect(null, otherFiles);
    } else {
        twinColSelect = new TwinColSelect();
    }

    twinColSelect.setWidth("400px");
    twinColSelect.setRows(10);
    topGridLayout.addComponent(twinColSelect, 1, 1);
    topGridLayout.setComponentAlignment(twinColSelect, Alignment.TOP_RIGHT);

    Label otherFilesLabel = StyleUtils
            .getLabelSmallHTML("Select the files which should get the settings of this file as presetting.");
    otherFilesLabel.setSizeUndefined();
    topGridLayout.addComponent(otherFilesLabel, 1, 2);
    topGridLayout.setComponentAlignment(otherFilesLabel, Alignment.MIDDLE_CENTER);

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    final UploadGoogleMap googleMap;

    if (uploadSettings != null && uploadSettings.getTopographicPoint() != null) {
        googleMap = new UploadGoogleMap(mediaType, 12, uploadSettings.getTopographicPoint().getLatitude(),
                uploadSettings.getTopographicPoint().getLongitude(), MapType.HYBRID);
    } else {
        googleMap = new UploadGoogleMap(mediaType, 12, 48.42255269321401d, 9.956477880477905d, MapType.HYBRID);
    }

    googleMap.setWidth("100%");
    googleMap.setHeight("300px");
    mainLayout.addComponent(googleMap);

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    GridLayout bottomGridLayout = new GridLayout(3, 3);
    bottomGridLayout.setSizeFull();
    bottomGridLayout.setSpacing(true);
    mainLayout.addComponent(bottomGridLayout);

    Label licenseLabel = StyleUtils.getLabelBold("License");
    bottomGridLayout.addComponent(licenseLabel, 0, 0);

    final TextArea licenseArea = new TextArea();
    licenseArea.setWidth("320px");
    licenseArea.setHeight("175px");
    licenseArea.setImmediate(true);

    if (uploadSettings != null && uploadSettings.getLicense() != null) {
        licenseArea.setValue(uploadSettings.getLicense());
    }

    bottomGridLayout.addComponent(licenseArea, 0, 1);

    final Label startTimeLabel = StyleUtils.getLabelBold("Earliest possible Start Date");
    startTimeLabel.setSizeUndefined();
    bottomGridLayout.setComponentAlignment(startTimeLabel, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(startTimeLabel, 1, 0);

    final InlineDateField startTimeField = new InlineDateField();
    startTimeField.setImmediate(true);
    startTimeField.setResolution(InlineDateField.RESOLUTION_SEC);

    boolean currentTimeAdjusted = false;

    if (uploadSettings != null && uploadSettings.getTimeRange() != null
            && uploadSettings.getTimeRange().getStartDateTime() != null) {
        startTimeField.setValue(uploadSettings.getTimeRange().getStartDateTime().toDate());
    } else {
        currentTimeAdjusted = true;

        startTimeField.setValue(new Date());
    }

    bottomGridLayout.setComponentAlignment(startTimeField, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(startTimeField, 1, 1);

    final CheckBox exactTimeCheckBox = new CheckBox("This is the exact point in time.");
    exactTimeCheckBox.setImmediate(true);
    bottomGridLayout.setComponentAlignment(exactTimeCheckBox, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(exactTimeCheckBox, 1, 2);

    final Label endTimeLabel = StyleUtils.getLabelBold("Latest possible Start Date");
    endTimeLabel.setSizeUndefined();
    bottomGridLayout.setComponentAlignment(endTimeLabel, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(endTimeLabel, 2, 0);

    final InlineDateField endTimeField = new InlineDateField();
    endTimeField.setImmediate(true);
    endTimeField.setResolution(InlineDateField.RESOLUTION_SEC);

    if (uploadSettings != null && uploadSettings.getTimeRange() != null
            && uploadSettings.getTimeRange().getEndDateTime() != null) {
        endTimeField.setValue(uploadSettings.getTimeRange().getEndDateTime().toDate());
    } else {
        endTimeField.setValue(startTimeField.getValue());
    }

    bottomGridLayout.setComponentAlignment(endTimeField, Alignment.TOP_CENTER);
    bottomGridLayout.addComponent(endTimeField, 2, 1);

    if (!currentTimeAdjusted && ((Date) startTimeField.getValue()).equals((Date) endTimeField.getValue())) {
        exactTimeCheckBox.setValue(true);

        endTimeLabel.setEnabled(false);
        endTimeField.setEnabled(false);
    }

    exactTimeCheckBox.addListener(new ValueChangeListener() {
        private static final long serialVersionUID = 7193545421803538364L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if ((Boolean) event.getProperty().getValue()) {
                endTimeLabel.setEnabled(false);
                endTimeField.setEnabled(false);
            } else {
                endTimeLabel.setEnabled(true);
                endTimeField.setEnabled(true);
            }
        }
    });

    mainLayout.addComponent(StyleUtils.getHorizontalLine());

    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setMargin(true, false, false, false);
    buttonLayout.setSpacing(false);

    HorizontalLayout uploadButtonLayout = new HorizontalLayout();
    uploadButtonLayout.setMargin(false, true, false, false);

    uploadButton = new Button("Upload File", new Button.ClickListener() {
        private static final long serialVersionUID = 8013811216568950479L;

        @Override
        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {
            String titleValue = titleField.getValue().toString().trim();
            Date startTimeValue = (Date) startTimeField.getValue();
            Date endTimeValue = (Date) endTimeField.getValue();
            boolean exactTimeValue = (Boolean) exactTimeCheckBox.getValue();

            if (titleValue.equals("")) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Title Field",
                        StyleUtils.getLabelHTML("A title entry is required."));

                mainWindow.addWindow(confirmWindow);
            } else if (titleValue.length() < 5 || titleValue.length() > 50) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Title Field", StyleUtils
                        .getLabelHTML("The number of characters of the title has to be between 5 and 50."));

                mainWindow.addWindow(confirmWindow);
            } else if (!exactTimeValue && startTimeValue.after(endTimeValue)) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Date Entries",
                        StyleUtils.getLabelHTML("The second date has to be after the first date."));

                mainWindow.addWindow(confirmWindow);
            } else if (startTimeValue.after(new Date())
                    || (!exactTimeValue && endTimeValue.after(new Date()))) {
                ConfirmWindow confirmWindow = new ConfirmWindow(mainWindow, "Date Entries",
                        StyleUtils.getLabelHTML("The dates are not allowed to be in the future."));

                mainWindow.addWindow(confirmWindow);
            } else {
                disableButtons();

                String descriptionValue = descriptionArea.getValue().toString().trim();
                String licenseValue = licenseArea.getValue().toString().trim();
                TopographicPoint topographicPointValue = googleMap.getMarkerPosition();
                Collection<String> presettingValues = (Collection<String>) twinColSelect.getValue();

                if (exactTimeValue) {
                    endTimeValue = startTimeValue;
                }

                TimeRange timeRange = new TimeRange(new DateTime(startTimeValue), new DateTime(endTimeValue));

                UploadSettings uploadSettings = new UploadSettings(titleValue, descriptionValue, licenseValue,
                        new Vector<String>(tags), topographicPointValue, timeRange);

                mainWindow.removeWindow(event.getButton().getWindow());

                requestRepaint();

                uploadSection.upload(uploadSettings, new Vector<String>(presettingValues));
            }
        }
    });

    uploadButton.setStyleName(Reindeer.BUTTON_DEFAULT);
    uploadButtonLayout.addComponent(uploadButton);
    buttonLayout.addComponent(uploadButtonLayout);

    HorizontalLayout cancelButtonLayout = new HorizontalLayout();
    cancelButtonLayout.setMargin(false, true, false, false);

    cancelButton = new Button("Cancel", new Button.ClickListener() {
        private static final long serialVersionUID = -2565870159504952913L;

        @Override
        public void buttonClick(ClickEvent event) {
            disableButtons();

            mainWindow.removeWindow(event.getButton().getWindow());

            requestRepaint();

            uploadSection.cancelUpload();
        }
    });

    cancelButton.setStyleName(Reindeer.BUTTON_DEFAULT);
    cancelButtonLayout.addComponent(cancelButton);
    buttonLayout.addComponent(cancelButtonLayout);

    cancelAllButton = new Button("Cancel All", new Button.ClickListener() {
        private static final long serialVersionUID = -8578124709201789182L;

        @Override
        public void buttonClick(ClickEvent event) {
            disableButtons();

            mainWindow.removeWindow(event.getButton().getWindow());

            requestRepaint();

            uploadSection.cancelAllUploads();
        }
    });

    cancelAllButton.setStyleName(Reindeer.BUTTON_DEFAULT);
    buttonLayout.addComponent(cancelAllButton);

    mainLayout.addComponent(buttonLayout);
    mainLayout.setComponentAlignment(buttonLayout, Alignment.BOTTOM_CENTER);

    wrapperLayout.addComponent(mainLayout);
}

From source file:org.hip.vif.forum.usersettings.ui.ShowCompletedRatingView.java

License:Open Source License

/** Constructor for view to display the completed ratings given.
 *
 * @param inRatings {@link QueryResult} the participants involved in the review and rating process
 * @param inQuestions {@link QueryResult} the reviewed questions
 * @param inCompletions {@link QueryResult} the reviewed completions
 * @param inTexts {@link QueryResult} the reviewed texts
 * @param inTask {@link IPluggableWithLookup} the controlling task
 * @throws VException/*from  ww w.ja v  a2s . co m*/
 * @throws SQLException */
public ShowCompletedRatingView(final QueryResult inRatings, final QueryResult inQuestions,
        final QueryResult inCompletions, final QueryResult inTexts, final IPluggableWithLookup inTask)
        throws VException, SQLException {
    final VerticalLayout lLayout = new VerticalLayout();
    setCompositionRoot(lLayout);

    final IMessages lMessages = Activator.getMessages();
    lLayout.setStyleName("vif-view"); //$NON-NLS-1$
    lLayout.addComponent(new Label(String.format(VIFViewHelper.TMPL_TITLE, "vif-title", //$NON-NLS-1$
            lMessages.getMessage("ratings.completed.title")), ContentMode.HTML)); //$NON-NLS-1$

    lLayout.addComponent(new Label(lMessages.getMessage("ui.rated.subtitle"), ContentMode.HTML)); //$NON-NLS-1$
    listContributions(inQuestions, inCompletions, inTexts, inTask, lLayout, lMessages);
    lLayout.addComponent(RiplaViewHelper.createSpacer());

    final GridLayout lRatings = new GridLayout(5, 3);
    lRatings.setStyleName("vif-rating"); //$NON-NLS-1$
    lRatings.setWidth("100%"); //$NON-NLS-1$
    lRatings.setColumnExpandRatio(4, 1);
    lLayout.addComponent(lRatings);

    // headers
    lRatings.addComponent(new Label("")); //$NON-NLS-1$
    addComponentSized(new Label(lMessages.getMessage("ui.rated.column.correctness"), ContentMode.HTML), //$NON-NLS-1$
            lRatings);
    addComponentSized(new Label(lMessages.getMessage("ui.rated.column.efficiency"), ContentMode.HTML), //$NON-NLS-1$
            lRatings);
    addComponentSized(new Label(lMessages.getMessage("ui.rated.column.etiquette"), ContentMode.HTML), lRatings); //$NON-NLS-1$
    Label lRemark = new Label(lMessages.getMessage("ui.rated.column.remark"), ContentMode.HTML); //$NON-NLS-1$
    lRemark.setStyleName("vif-colhead vif-padding-left"); //$NON-NLS-1$
    lRatings.addComponent(lRemark);
    lRatings.getComponent(0, 0).setWidth(350, Unit.PIXELS);

    // ratings
    final Map<Long, String> lParticipants = new HashMap<Long, String>();
    final List<Line> lLines = new Vector<ShowCompletedRatingView.Line>();
    while (inRatings.hasMoreElements()) {
        final GeneralDomainObject lRating = inRatings.nextAsDomainObject();
        setParticipant(lRating, lParticipants);
        lLines.add(new Line(lRating));
    }

    for (final Line lLine : lLines) {
        lRatings.addComponent(new Label(lLine.getInvolved(lParticipants, lMessages), ContentMode.HTML));
        addComponentAligened(lLine.getCorrectness(), lRatings);
        addComponentAligened(lLine.getEfficiency(), lRatings);
        addComponentAligened(lLine.getEtiquette(), lRatings);
        lRemark = new Label(lLine.getRemark(), ContentMode.HTML);
        lRemark.setStyleName("vif-padding-left"); //$NON-NLS-1$
        lRatings.addComponent(lRemark);
    }
}

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/*ww  w.  java  2s  .  co  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/*w  w  w  . j a v  a2 s.  c o  m*/
        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.PlatformConfigurationPanel.java

License:BSD License

protected Panel createMapPanel(final ConfigurationParameterMapImpl parameter) {
    Panel paramPanel = new Panel();
    paramPanel.setStyleName("dashboard");
    paramPanel.setWidth("100%");

    GridLayout paramLayout = new GridLayout(2, 3);
    paramLayout.setSpacing(true);//from   w w  w .j av  a  2s  .c om
    paramLayout.setSizeFull();
    paramLayout.setMargin(true);
    paramLayout.setColumnExpandRatio(0, .25f);
    paramLayout.setColumnExpandRatio(1, .75f);

    Label label = new Label("Platform Configuration");
    label.addStyleName(ValoTheme.LABEL_HUGE);
    label.setSizeUndefined();
    paramLayout.addComponent(label, 0, 0, 1, 0);
    paramLayout.setComponentAlignment(label, Alignment.TOP_LEFT);

    final Map<String, String> valueMap = parameter.getValue();

    final GridLayout mapLayout = new GridLayout(5, (valueMap.size() != 0 ? valueMap.size() : 1) + 1);
    mapLayout.setColumnExpandRatio(0, .05f);
    mapLayout.setColumnExpandRatio(1, .425f);
    mapLayout.setColumnExpandRatio(2, .05f);
    mapLayout.setColumnExpandRatio(3, .425f);
    mapLayout.setColumnExpandRatio(4, .05f);

    mapLayout.setMargin(true);
    mapLayout.setSpacing(true);
    mapLayout.setWidth("100%");

    int i = 0;

    for (final String key : valueMap.keySet()) {
        final Label keyLabel = new Label("Name:");
        final Label valueLabel = new Label("Value:");

        final TextField keyField = new TextField();
        keyField.setValue(key);
        keyField.setWidth("100%");
        keyField.setNullSettingAllowed(false);
        keyField.addValidator(
                new NonZeroLengthStringValidator("Then configuration value name cannot be empty!"));
        keyField.setValidationVisible(false);

        final TextField valueField = new TextField();
        valueField.setWidth("100%");
        valueField.setValue(valueMap.get(key));
        valueField.setNullSettingAllowed(false);
        valueField.addValidator(new NonZeroLengthStringValidator("Then configuration value cannot be empty!"));
        valueField.setValidationVisible(false);

        mapLayout.addComponent(keyLabel, 0, i);
        mapLayout.setComponentAlignment(keyLabel, Alignment.MIDDLE_RIGHT);
        mapLayout.addComponent(keyField, 1, i);
        mapLayout.addComponent(valueLabel, 2, i);
        mapLayout.setComponentAlignment(valueLabel, Alignment.MIDDLE_RIGHT);
        mapLayout.addComponent(valueField, 3, i);
        final String mapKey = parameter.getName() + i;
        TextFieldKeyValuePair pair = new TextFieldKeyValuePair();
        pair.key = keyField;
        pair.value = valueField;

        this.mapTextFields.put(mapKey, pair);

        final Button removeButton = new Button("remove");
        removeButton.setStyleName(ValoTheme.BUTTON_LINK);
        removeButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                valueMap.remove(key);
                mapLayout.removeComponent(keyLabel);
                mapLayout.removeComponent(valueLabel);
                mapLayout.removeComponent(keyField);
                mapLayout.removeComponent(valueField);
                mapLayout.removeComponent(removeButton);

                mapTextFields.remove(mapKey);
            }
        });

        mapLayout.addComponent(removeButton, 4, i);

        i++;
    }

    final Button addButton = new Button("add");
    addButton.setStyleName(ValoTheme.BUTTON_LINK);
    addButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            final Label keyLabel = new Label("Name:");
            final Label valueLabel = new Label("Value:");

            final TextField keyField = new TextField();
            keyField.setWidth("100%");
            keyField.setNullSettingAllowed(false);
            keyField.addValidator(
                    new NonZeroLengthStringValidator("Then configuration value name cannot be empty!"));
            keyField.setValidationVisible(false);

            final TextField valueField = new TextField();
            valueField.setWidth("100%");
            valueField.setNullSettingAllowed(false);
            valueField.addValidator(
                    new NonZeroLengthStringValidator("Then configuration value cannot be empty!"));
            valueField.setValidationVisible(false);

            mapLayout.insertRow(mapLayout.getRows());

            mapLayout.removeComponent(addButton);
            mapLayout.addComponent(keyLabel, 0, mapLayout.getRows() - 2);
            mapLayout.setComponentAlignment(keyLabel, Alignment.MIDDLE_RIGHT);
            mapLayout.addComponent(keyField, 1, mapLayout.getRows() - 2);
            mapLayout.addComponent(valueLabel, 2, mapLayout.getRows() - 2);
            mapLayout.setComponentAlignment(valueLabel, Alignment.MIDDLE_RIGHT);
            mapLayout.addComponent(valueField, 3, mapLayout.getRows() - 2);

            final String mapKey = parameter.getName() + mapTextFields.size();
            TextFieldKeyValuePair pair = new TextFieldKeyValuePair();
            pair.key = keyField;
            pair.value = valueField;

            mapTextFields.put(mapKey, pair);

            final Button removeButton = new Button("remove");
            removeButton.setStyleName(ValoTheme.BUTTON_LINK);
            removeButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    mapLayout.removeComponent(keyLabel);
                    mapLayout.removeComponent(valueLabel);
                    mapLayout.removeComponent(keyField);
                    mapLayout.removeComponent(valueField);

                    mapLayout.removeComponent(removeButton);

                    mapTextFields.remove(mapKey);
                }
            });

            mapLayout.addComponent(removeButton, 4, mapLayout.getRows() - 2);

            mapLayout.addComponent(addButton, 0, mapLayout.getRows() - 1);
        }
    });

    mapLayout.addComponent(addButton, 0, mapLayout.getRows() - 1);

    Panel mapPanel = new Panel();
    mapPanel.setStyleName(ValoTheme.PANEL_BORDERLESS);
    mapPanel.setContent(mapLayout);

    Button saveButton = new Button("Save");
    saveButton.addStyleName(ValoTheme.BUTTON_SMALL);
    saveButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            try {
                for (TextFieldKeyValuePair textField : mapTextFields.values()) {
                    textField.key.validate();
                    textField.value.validate();
                }
            } catch (InvalidValueException e) {
                for (TextFieldKeyValuePair textField : mapTextFields.values()) {
                    textField.key.setValidationVisible(true);
                    textField.value.setValidationVisible(true);
                }

                Notification.show("Validation errors have occurred!", Type.ERROR_MESSAGE);

                return;
            }

            HashMap<String, String> map = new HashMap<String, String>();

            logger.info("Saving map: " + mapTextFields.size());

            for (String key : mapTextFields.keySet()) {
                if (key.startsWith(parameter.getName())) {
                    TextFieldKeyValuePair pair = mapTextFields.get(key);

                    logger.info("Saving for key: " + key);

                    if (pair.key.getValue() != "") {
                        map.put(pair.key.getValue(), pair.value.getValue());
                    }
                }
            }

            parameter.setValue(map);

            PlatformConfigurationPanel.this.configurationManagement.saveConfiguration(platformConfiguration);

            Notification notification = new Notification("Saved",
                    "The configuration has been saved successfully!", Type.HUMANIZED_MESSAGE);
            notification.setStyleName(ValoTheme.NOTIFICATION_CLOSABLE);
            notification.show(Page.getCurrent());
        }
    });

    paramLayout.addComponent(mapPanel, 0, 1, 1, 1);
    paramLayout.setComponentAlignment(mapPanel, Alignment.TOP_CENTER);
    paramLayout.addComponent(saveButton, 0, 2, 1, 2);
    paramLayout.setComponentAlignment(saveButton, Alignment.TOP_CENTER);
    paramPanel.setContent(paramLayout);

    return paramPanel;
}

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);//from  w  w w .  java 2s. com
    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.PolicyManagementPanel.java

License:BSD License

/**
 * //from  ww w. ja v a 2s. c o  m
 */
protected void createPolicyDropPanel() {
    this.policyDropPanel = new Panel();

    Label rolePoliciesLabel = new Label("Role/Policy Associations");
    rolePoliciesLabel.setStyleName(ValoTheme.LABEL_HUGE);

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

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

            if (role != null) {
                List<Policy> policies = securityService.getAllPoliciesWithRole(role.getName());

                PolicyManagementPanel.this.policyDropTable.removeAllItems();

                for (final Policy policy : policies) {
                    Button deleteButton = new Button();
                    deleteButton.setIcon(VaadinIcons.TRASH);
                    deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                    deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                    deleteButton.setDescription("Remove Policy from this Role");

                    deleteButton.addClickListener(new Button.ClickListener() {
                        public void buttonClick(ClickEvent event) {
                            role.getPolicies().remove(policy);
                            PolicyManagementPanel.this.saveRole(role);

                            PolicyManagementPanel.this.policyDropTable.removeItem(policy.getName());
                            PolicyManagementPanel.this.roleTable.removeItem(role);
                        }
                    });

                    PolicyManagementPanel.this.policyDropTable
                            .addItem(new Object[] { policy.getName(), deleteButton }, policy.getName());
                }
            }
        }
    });

    this.policyDropTable = new Table();
    this.policyDropTable.addContainerProperty("Role Policies", String.class, null);
    this.policyDropTable.addContainerProperty("", Button.class, null);
    this.policyDropTable.setHeight("700px");
    this.policyDropTable.setWidth("300px");

    this.policyDropTable.setDragMode(TableDragMode.ROW);
    this.policyDropTable.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);
            deleteButton.setDescription("Remove Policy from this Role");

            final Policy policy = PolicyManagementPanel.this.securityService
                    .findPolicyByName(sourceContainer.getText());

            final Role selectedRole = PolicyManagementPanel.this.securityService
                    .findRoleByName(((Role) rolesCombo.getValue()).getName());

            deleteButton.addClickListener(new Button.ClickListener() {
                public void buttonClick(ClickEvent event) {
                    selectedRole.getPolicies().remove(policy);
                    PolicyManagementPanel.this.saveRole(selectedRole);

                    policyDropTable.removeItem(policy.getName());
                    roleTable.removeItem(selectedRole);
                }
            });

            PolicyManagementPanel.this.policyDropTable.addItem(
                    new Object[] { sourceContainer.getText(), deleteButton }, sourceContainer.getText());

            selectedRole.getPolicies().add(policy);

            PolicyManagementPanel.this.saveRole(selectedRole);
            policy.getRoles().add(selectedRole);

            PolicyManagementPanel.this.roleTable.removeAllItems();

            for (final Role role : policy.getRoles()) {
                Button roleDeleteButton = new Button();
                roleDeleteButton.setIcon(VaadinIcons.TRASH);
                roleDeleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
                deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);
                deleteButton.setDescription("Remove Policy from this Role");

                roleDeleteButton.addClickListener(new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        selectedRole.getPolicies().remove(policy);
                        PolicyManagementPanel.this.saveRole(selectedRole);

                        PolicyManagementPanel.this.roleTable.removeItem(role);
                        PolicyManagementPanel.this.policyDropTable.removeItem(policy.getName());
                    }
                });

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

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

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

    layout.addComponent(rolePoliciesLabel);
    layout.addComponent(this.rolesCombo);

    Label policyDropHintLabel = new Label();
    policyDropHintLabel.setCaptionAsHtml(true);
    policyDropHintLabel.setCaption(VaadinIcons.QUESTION_CIRCLE_O.getHtml()
            + " Drop a policy into the table below to associate with a role.");
    policyDropHintLabel.addStyleName(ValoTheme.LABEL_TINY);
    policyDropHintLabel.addStyleName(ValoTheme.LABEL_LIGHT);
    layout.addComponent(policyDropHintLabel);

    layout.addComponent(this.policyDropTable);

    this.policyDropPanel.setContent(layout);
}

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  w w  w  .ja  v  a2s.c o m*/
    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();/*w  w w. j av  a  2  s. co  m*/

    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);
}