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(float width, Unit unit) 

Source Link

Usage

From source file:ch.bfh.ti.soed.hs16.srs.purple.view.ReservationView.java

License:Open Source License

/**
 * Shows the popup window where a reservation can be modified, deleted or inserted
 * @param res The Reservation Object (for a new reservation, fill the startDate with the current Timestamp!)
 *//*from  w w  w . j  a  va 2s. c  o  m*/
@SuppressWarnings("serial")
private void showPopup(Reservation res) {
    this.res = res; //Update the member
    boolean newRes = res.getReservationID() > 0 ? false : true;
    boolean isHost = isHost(actualUser, res.getHostList());
    boolean isParticipant = isHost(actualUser, res.getParticipantList());
    final GridLayout gridLayout = new GridLayout(3, 5);
    ValueChangeListener vcl = new ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            List<Room> roomList = resCont.getAllFreeRooms(new Timestamp(startDate.getValue().getTime()),
                    new Timestamp(endDate.getValue().getTime()));
            if (ReservationView.this.res.getReservationID() > 0) {
                System.out.println("Aktuellen Raum");
                rooms.addItem(ReservationView.this.res.getRoom().getRoomID());
                rooms.setItemCaption(ReservationView.this.res.getRoom().getRoomID(),
                        ReservationView.this.res.getRoom().getName() + " ("
                                + ReservationView.this.res.getRoom().getNumberOfSeats() + " Pltze)");
                rooms.select(ReservationView.this.res.getRoom().getRoomID());
            }
            for (int i = 0; i < roomList.size(); i++) {
                rooms.addItem(roomList.get(i).getRoomID());
                String caption = roomList.get(i).getName() + " (" + roomList.get(i).getNumberOfSeats()
                        + " Pltze)";
                rooms.setItemCaption(roomList.get(i).getRoomID(), caption);
            }
            if (ReservationView.this.res.getReservationID() <= 0 && actualRoom != null)
                rooms.select(actualRoom.getRoomID());
        }
    };
    popUpWindow = new Window();
    popUpWindow.center();
    popUpWindow.setModal(true);
    startDate = new DateField("Startzeit");
    startDate.setLocale(VaadinSession.getCurrent().getLocale());
    startDate.setValue(res.getStart());
    startDate.addValueChangeListener(vcl);
    startDate.setDateFormat("dd.MM.yyyy HH:mm");
    startDate.setResolution(Resolution.HOUR);
    endDate = new DateField("Endzeit");
    endDate.setValue(res.getEnd());
    endDate.addValueChangeListener(vcl);
    endDate.setDateFormat("dd.MM.yyyy HH:mm");
    endDate.setLocale(VaadinSession.getCurrent().getLocale());
    endDate.setResolution(Resolution.HOUR);
    title = new TextField("Titel");
    title.setValue(res.getTitle());
    title.setWidth(100, Unit.PERCENTAGE);
    description = new TextArea("Beschreibung");
    description.setValue(res.getDescription());
    description.setRows(3);
    description.setWidth(100, Unit.PERCENTAGE);
    hosts = new ListSelect("Reservierender");
    hosts.setMultiSelect(true);
    hosts.clear();
    for (int i = 0; i < hostList.size(); i++) {
        hosts.addItem(hostList.get(i).getUserID());
        hosts.setItemCaption(hostList.get(i).getUserID(), hostList.get(i).getUsername());
    }
    //select the hosts in list
    if (!newRes) {
        List<User> resHosts = res.getHostList();
        for (int i = 0; i < resHosts.size(); i++)
            for (int y = 0; y < hostList.size(); y++)
                if (hostList.get(y).getUserID() == resHosts.get(i).getUserID())
                    hosts.select(resHosts.get(i).getUserID());
    } else
        hosts.select(actualUser.getUserID());
    hosts.select(0);
    hosts.setRows(hostList.size() > 5 ? 5 : hostList.size());
    participantList = new ListSelect("Teilnehmer");
    participantList.setMultiSelect(true);
    participantList.clear();

    for (int i = 0; i < participant.size(); i++) {
        participantList.addItem(participant.get(i).getUserID());
        participantList.setItemCaption(participant.get(i).getUserID(), participant.get(i).getUsername());
    }
    //select the participants in list
    if (!newRes) {
        List<User> resPart = res.getParticipantList();
        for (int i = 0; i < resPart.size(); i++)
            for (int y = 0; y < participant.size(); y++)
                if (participant.get(y).getUserID() == resPart.get(i).getUserID())
                    participantList.select(resPart.get(i).getUserID());
    }
    participantList.setRows(participant.size() > 5 ? 5 : participant.size());
    rooms = new NativeSelect("Raum");
    rooms.setNullSelectionAllowed(false);
    rooms.removeAllItems();
    List<Room> roomList = resCont.getAllFreeRooms(new Timestamp(startDate.getValue().getTime()),
            new Timestamp(endDate.getValue().getTime()));
    if (!newRes) {
        rooms.addItem(res.getRoom().getRoomID());
        rooms.setItemCaption(res.getRoom().getRoomID(),
                res.getRoom().getName() + " (" + res.getRoom().getNumberOfSeats() + " Pltze)");
        rooms.select(res.getRoom().getRoomID());
    }
    for (int i = 0; i < roomList.size(); i++) {
        rooms.addItem(roomList.get(i).getRoomID());
        String caption = roomList.get(i).getName() + " (" + roomList.get(i).getNumberOfSeats() + " Pltze)";
        rooms.setItemCaption(roomList.get(i).getRoomID(), caption);
    }
    if (newRes && actualRoom != null)
        rooms.select(actualRoom.getRoomID());
    saveButton = new Button("Speichern");
    saveButton.addClickListener(clButton);
    deleteButton = new Button("Lschen");
    deleteButton.addClickListener(clButton);
    deleteButton.setVisible(res.getReservationID() > 0 ? true : false);
    if (!newRes)
        setEditable(false);
    gridLayout.addComponent(startDate, 0, 0);
    gridLayout.addComponent(endDate, 0, 1);
    gridLayout.addComponent(hosts, 1, 0, 1, 1);
    gridLayout.addComponent(participantList, 2, 0, 2, 1);
    gridLayout.addComponent(title, 0, 2);
    gridLayout.addComponent(rooms, 1, 2, 2, 2);
    gridLayout.addComponent(description, 0, 3, 1, 3);
    if (roomList.size() == 0)
        saveButton.setEnabled(false);
    if (isHost || newRes) //show buttons for edit and delete only if the user is host or its a new reservation
    {
        gridLayout.addComponent(saveButton, 0, 4);
        gridLayout.addComponent(deleteButton, 1, 4);
    }
    if (isParticipant) //show buttons for accept oder decline a reservation
    {
        acceptButton = new Button("Zusagen");
        rejectButton = new Button("Absagen");
        acceptButton.addClickListener(clButton);
        rejectButton.addClickListener(clButton);
        if (isHost(actualUser, res.getAcceptedParticipantsList())) {
            acceptButton.setEnabled(false);
            rejectButton.setEnabled(true);
        } else {
            rejectButton.setEnabled(false);
            acceptButton.setEnabled(true);
        }
        gridLayout.addComponent(acceptButton, 0, 4);
        gridLayout.addComponent(rejectButton, 1, 4);
    }
    gridLayout.setSpacing(true);
    gridLayout.setMargin(new MarginInfo(false, false, false, true));
    gridLayout.setWidth(100, Unit.PERCENTAGE);
    popUpWindow.setContent(gridLayout);
    popUpWindow.setWidth("600px");
    popUpWindow.setHeight("450px");
    popUpWindow.setCaption(res.getReservationID() > 0 ? "Reservierungsdetails" : "Neue Reservierung");
    UI.getCurrent().addWindow(popUpWindow);
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl.AbstractMenuItemFactoryImpl.java

License:Apache License

protected final void createButtonLink(final GridLayout panelContent, final String linkText, final Resource icon,
        final ClickListener command, final String description) {
    final GridLayout grid = new GridLayout(2, 1);
    grid.setWidth(100, Unit.PERCENTAGE);
    grid.setHeight(100, Unit.PERCENTAGE);
    grid.setColumnExpandRatio(0, 1);//w  w  w  .  ja  v  a 2s.c  om
    grid.setColumnExpandRatio(1, 2);

    final Button b = new Button(linkText);
    b.setStyleName("link");
    b.addClickListener(command);
    b.setWidth(100, Unit.PERCENTAGE);

    b.setIcon(icon);
    b.setWidth(100, Unit.PERCENTAGE);

    grid.addComponent(b, 0, 0);
    grid.setComponentAlignment(b, Alignment.MIDDLE_LEFT);

    final Label descriptionLabel = new Label(description);
    descriptionLabel.setWidth(100, Unit.PERCENTAGE);
    grid.addComponent(descriptionLabel, 1, 0);
    grid.setComponentAlignment(descriptionLabel, Alignment.MIDDLE_LEFT);

    panelContent.addComponent(grid);
    panelContent.setComponentAlignment(grid, Alignment.MIDDLE_LEFT);
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl.AbstractMenuItemFactoryImpl.java

License:Apache License

protected final GridLayout createGridLayout(final VerticalLayout panelContent) {
    final GridLayout grid = new GridLayout(2, 1);
    grid.setWidth(100, Unit.PERCENTAGE);
    grid.setHeight(100, Unit.PERCENTAGE);
    grid.setColumnExpandRatio(0, 1);/*from   w  w  w . ja  v  a2 s . c  o  m*/
    grid.setColumnExpandRatio(1, 1);
    grid.setSpacing(true);
    panelContent.addComponent(grid);
    panelContent.setExpandRatio(grid, ContentRatio.LARGE);
    return grid;
}

From source file:com.klwork.explorer.ui.task.HistoricTaskDetailPanel.java

License:Apache License

protected void initHeader() {
    GridLayout taskDetails = new GridLayout(5, 2);
    taskDetails.setWidth(100, UNITS_PERCENTAGE);
    taskDetails.addStyleName(ExplorerLayout.STYLE_TITLE_BLOCK);
    taskDetails.setSpacing(true);//w w w.j  a va  2  s  .c  o m
    taskDetails.setMargin(new MarginInfo(false, false, true, false));

    // Add image
    Embedded image = new Embedded(null, Images.TASK_50);
    taskDetails.addComponent(image, 0, 0, 0, 1);

    // Add task name
    Label nameLabel = new Label(historicTask.getName());
    nameLabel.addStyleName(Reindeer.LABEL_H2);
    taskDetails.addComponent(nameLabel, 1, 0, 4, 0);

    // Add due date
    PrettyTimeLabel dueDateLabel = new PrettyTimeLabel(i18nManager.getMessage(Messages.TASK_DUEDATE_SHORT),
            historicTask.getDueDate(), i18nManager.getMessage(Messages.TASK_DUEDATE_UNKNOWN), false);
    dueDateLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_DUEDATE);
    taskDetails.addComponent(dueDateLabel, 1, 1);

    // Add priority
    Integer lowMedHighPriority = convertPriority(historicTask.getPriority());
    Label priorityLabel = new Label();
    switch (lowMedHighPriority) {
    case 1:
        priorityLabel.setValue(i18nManager.getMessage(Messages.TASK_PRIORITY_LOW));
        priorityLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_PRIORITY_LOW);
        break;
    case 2:
        priorityLabel.setValue(i18nManager.getMessage(Messages.TASK_PRIORITY_MEDIUM));
        priorityLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_PRIORITY_MEDIUM);
        break;
    case 3:
    default:
        priorityLabel.setValue(i18nManager.getMessage(Messages.TASK_PRIORITY_HIGH));
        priorityLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_PRIORITY_HIGH);
    }
    taskDetails.addComponent(priorityLabel, 2, 1);

    // Add create date
    PrettyTimeLabel createLabel = new PrettyTimeLabel(i18nManager.getMessage(Messages.TASK_CREATED_SHORT),
            historicTask.getStartTime(), "", true);
    createLabel.addStyleName(ExplorerLayout.STYLE_TASK_HEADER_CREATE_TIME);
    taskDetails.addComponent(createLabel, 3, 1);

    // Add label to fill excess space
    Label spacer = new Label();
    spacer.setContentMode(Label.CONTENT_XHTML);
    spacer.setValue("&nbsp;");
    spacer.setSizeUndefined();
    taskDetails.addComponent(spacer);

    taskDetails.setColumnExpandRatio(1, 1.0f);
    taskDetails.setColumnExpandRatio(2, 1.0f);
    taskDetails.setColumnExpandRatio(3, 1.0f);
    taskDetails.setColumnExpandRatio(4, 1.0f);
    centralLayout.addComponent(taskDetails);
}

From source file:com.klwork.explorer.ui.task.TaskDetailPanel.java

License:Apache License

protected void initHeader() {
    GridLayout taskDetails = new GridLayout(2, 2);
    taskDetails.setWidth(100, Unit.PERCENTAGE);
    taskDetails.addStyleName(ExplorerLayout.STYLE_TITLE_BLOCK);
    taskDetails.setSpacing(true);/* w w w. j  a v a2 s  .c o  m*/
    taskDetails.setMargin(new MarginInfo(false, false, true, false));
    taskDetails.setColumnExpandRatio(1, 1.0f);
    centralLayout.addComponent(taskDetails);

    // Add image
    Embedded image = new Embedded(null, Images.TASK_50);
    //??
    taskDetails.addComponent(image, 0, 0, 0, 1);

    // Add task name
    Label nameLabel = new Label(task.getName());
    nameLabel.addStyleName(Reindeer.LABEL_H2);
    taskDetails.addComponent(nameLabel, 1, 0);
    taskDetails.setComponentAlignment(nameLabel, Alignment.MIDDLE_LEFT);

    // Properties
    HorizontalLayout propertiesLayout = new HorizontalLayout();//
    propertiesLayout.setSpacing(true);
    taskDetails.addComponent(propertiesLayout);

    propertiesLayout.addComponent(new DueDateComponent(task, i18nManager, taskService));
    propertiesLayout.addComponent(new PriorityComponent(task, i18nManager, taskService));
    //?
    initCreateTime(propertiesLayout);
}

From source file:com.klwork.explorer.ui.user.ProfilePanel.java

License:Apache License

protected GridLayout createInfoSectionLayout(int columns, int rows) {
    GridLayout layout = new GridLayout(columns, rows);
    layout.setSpacing(true);/*  ww w. j  av a 2 s  .  c o  m*/
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setMargin(new MarginInfo(true, false, true, false));
    infoPanelLayout.addComponent(layout);
    return layout;
}

From source file:de.gedoplan.webclients.vaadin.views.CustomerForm.java

protected void buildLayout() {
    GridLayout gridLayout = new GridLayout(4, 4);
    gridLayout.setSpacing(true);//w  w w .jav  a2  s .  c  o  m
    gridLayout.setMargin(true);
    gridLayout.setWidth(100, Unit.PERCENTAGE);
    gridLayout.addComponent(id, 0, 0);
    gridLayout.addComponent(name, 1, 0, 2, 0);
    gridLayout.addComponent(kontakt, 3, 0);
    gridLayout.addComponent(strasse, 0, 1);
    gridLayout.addComponent(plz, 1, 1);
    gridLayout.addComponent(stadt, 2, 1, 3, 1);
    gridLayout.addComponent(region, 0, 2);
    gridLayout.addComponent(land, 1, 2);
    gridLayout.addComponent(telefon, 2, 2);
    gridLayout.addComponent(fax, 3, 2);
    gridLayout.addComponent(speichern, 1, 3);
    gridLayout.addComponent(abbrechen, 2, 3);
    gridLayout.setComponentAlignment(speichern, Alignment.MIDDLE_CENTER);
    gridLayout.setComponentAlignment(abbrechen, Alignment.MIDDLE_CENTER);
    speichern.setWidth(200, Unit.PIXELS);
    abbrechen.setWidth(200, Unit.PIXELS);
    setSpacing(true);
    setWidth(100, Unit.PERCENTAGE);
    addComponent(gridLayout);
}

From source file:dhbw.clippinggorilla.userinterface.windows.ActivateWindow.java

public static Window get() {
    Window window = new Window();
    window.setModal(true);// www  .j  a va 2  s . c  om
    window.setResizable(false);
    window.setDraggable(false);
    window.setCaption(Language.get(Word.ACTIVATION_CODE));
    window.addCloseShortcut(ShortcutAction.KeyCode.ENTER, null);

    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setMargin(false);
    windowLayout.setSizeUndefined();

    FormLayout forms = new FormLayout();
    forms.setMargin(true);
    forms.setSizeUndefined();

    Button save = new Button(Language.get(Word.ACTIVATE));

    TextField activationCode = new TextField(Language.get(Word.ACTIVATION_CODE));
    activationCode.setMaxLength(6);
    activationCode.focus();
    activationCode.addValueChangeListener(e -> {
        if (activationCode.getValue().length() > 5) {
            save.setEnabled(true);
            activationCode.setComponentError(null);
        } else {
            save.setEnabled(false);
            activationCode.setComponentError(new UserError(Language.get(Word.ACTIVATION_CODE_SIX_CHARS),
                    AbstractErrorMessage.ContentMode.HTML, ErrorMessage.ErrorLevel.INFORMATION));
            VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_CODE_SIX_CHARS));
        }
    });
    forms.addComponent(activationCode);

    Button resendMail = new Button(Language.get(Word.RESEND_ACTIVATION_CODE));
    resendMail.addStyleName(ValoTheme.BUTTON_BORDERLESS_COLORED);
    resendMail.addClickListener(ce -> {
        try {
            UserUtils.resendActivationMail(UserUtils.getCurrent());
            VaadinUtils.infoNotification(Language.get(Word.RESEND_ACTIVATION_CODE_SUCCESSFUL));
        } catch (EmailException ex) {
            VaadinUtils.errorNotification(Language.get(Word.RESEND_ACTIVATION_CODE_FAILED));
        }
    });
    forms.addComponent(resendMail);

    GridLayout footer = new GridLayout(3, 1);
    footer.setSpacing(true);
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth(100.0f, Sizeable.Unit.PERCENTAGE);

    Label placeholder = new Label();

    Button cancel = new Button(Language.get(Word.CANCEL));
    cancel.setIcon(VaadinIcons.CLOSE);
    cancel.addClickListener(ce -> {
        window.close();
    });
    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);

    save.setEnabled(false);
    save.setIcon(VaadinIcons.CHECK);
    save.addStyleName(ValoTheme.BUTTON_PRIMARY);
    save.addClickListener(ce -> {
        try {
            String code = activationCode.getValue();
            User user = UserUtils.getCurrent();
            if (UserUtils.activateUser(user, code)) {
                VaadinUtils.infoNotification(Language.get(Word.ACTIVATION_SUCCESSFUL));
                window.close();
            } else {
                activationCode.setValue("");
                VaadinUtils.errorNotification(Language.get(Word.ACTIVATION_FAILED));
            }
        } catch (NumberFormatException e) {
        }
    });
    save.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    footer.setSizeUndefined();
    footer.setWidth("100%");
    footer.addComponents(placeholder, cancel, save);
    footer.setColumnExpandRatio(0, 1);//ExpandRatio(placeholder, 1);
    footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(save, Alignment.MIDDLE_CENTER);

    windowLayout.addComponent(forms);
    windowLayout.addComponent(footer);

    window.setContent(windowLayout);
    return window;
}

From source file:dhbw.clippinggorilla.userinterface.windows.ManageSourcesWindow.java

public Component getSourcesList() {
    VerticalLayout windowLayout = new VerticalLayout();
    windowLayout.setSizeFull();/*www  .  j  a v  a2  s . c  o  m*/
    sourcesLayout = new VerticalLayout();
    sourcesLayout.setWidth("100%");
    Panel sourcesPanel = new Panel(sourcesLayout);

    refreshSources();

    sourcesPanel.setContent(sourcesLayout);
    sourcesPanel.setHeight("100%");
    windowLayout.addComponent(sourcesPanel);
    windowLayout.setExpandRatio(sourcesPanel, 1);
    windowLayout.setSpacing(false);
    windowLayout.setMargin(false);

    TextField textFieldSearch = new TextField();
    textFieldSearch.setPlaceholder(Language.get(Word.SEARCH));
    textFieldSearch.addValueChangeListener(searchValue -> {
        sourceLayouts.forEach((sourceName, sourceLayout) -> {
            if (!sourceName.contains(searchValue.getValue().toLowerCase().replaceAll(" ", "")
                    .replaceAll("-", "").replaceAll("_", ""))) {
                sourcesLayout.removeComponent(sourceLayout);
            } else {
                sourcesLayout.addComponent(sourceLayout);
            }
        });
    });

    Button buttonAddSource = new Button(Language.get(Word.ADD_SOURCE), VaadinIcons.PLUS);
    buttonAddSource.addClickListener(ce -> UI.getCurrent().addWindow(NewSourceWindow.create()));

    Button buttonSave = new Button();
    Language.set(Word.SAVE, buttonSave);
    buttonSave.setIcon(VaadinIcons.CHECK);
    buttonSave.addStyleName(ValoTheme.BUTTON_PRIMARY);
    buttonSave.addClickListener(ce -> {
        close();
    });
    buttonSave.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    Label placeholder = new Label();

    GridLayout footer = new GridLayout(4, 1);
    footer.setSpacing(true);
    footer.setSizeUndefined();
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.addStyleName("menubar");
    footer.setWidth(100.0f, Unit.PERCENTAGE);
    footer.addComponents(textFieldSearch, placeholder, buttonAddSource, buttonSave);
    footer.setComponentAlignment(textFieldSearch, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(buttonAddSource, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(buttonSave, Alignment.MIDDLE_CENTER);
    footer.setColumnExpandRatio(1, 5);

    windowLayout.addComponent(footer);
    return windowLayout;
}

From source file:dhbw.clippinggorilla.userinterface.windows.NewSourceWindow.java

public Component getFooter(Runnable cancelRunnable, Runnable nextRunnable, Component... extraComponents) {
    Label placeholder = new Label();
    Button cancel = new Button(Language.get(Word.CANCEL), VaadinIcons.CLOSE);
    cancel.addClickListener(ce -> cancelRunnable.run());
    Button next = new Button(Language.get(Word.NEXT), VaadinIcons.ARROW_RIGHT);
    next.addClickListener(ce -> nextRunnable.run());
    GridLayout footer = new GridLayout(3 + extraComponents.length, 1);
    footer.setSpacing(true);//from  www.ja  v a  2  s  . c o  m
    footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
    footer.setWidth(100.0f, Sizeable.Unit.PERCENTAGE);
    footer.setSizeUndefined();
    footer.setWidth("100%");
    for (Component extraComponent : extraComponents) {
        footer.addComponent(extraComponent);
        footer.setComponentAlignment(extraComponent, Alignment.MIDDLE_CENTER);
    }
    footer.addComponents(placeholder, cancel, next);
    footer.setColumnExpandRatio(footer.getColumns() - 1 - 2, 1);//ExpandRatio(placeholder, 1);
    footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER);
    footer.setComponentAlignment(next, Alignment.MIDDLE_CENTER);
    return footer;
}