com.squadd.UI.GroupParticipantsLayout.java Source code

Java tutorial

Introduction

Here is the source code for com.squadd.UI.GroupParticipantsLayout.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.squadd.UI;

import com.squadd.javaBeans.Group;
import com.squadd.javaBeans.UserInfoBean;
import com.squadd.managers.DBManager;
import com.squadd.technical.Display;
import com.squadd.technical.ImageGetter;
import com.vaadin.event.MouseEvents;
import com.vaadin.server.Resource;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Image;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.renderers.ImageRenderer;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author SharkNado
 */
public class GroupParticipantsLayout extends HorizontalLayout {
    private Panel name;
    private VerticalLayout participants;
    private boolean isClicked = false;

    public GroupParticipantsLayout(Group group) {
        name = new Panel();
        participants = new VerticalLayout();
        buildLayout(group);
        configureActions();
    }

    private void buildLayout(Group group) {
        Label label = new Label("Participants");
        label.setSizeUndefined();
        HorizontalLayout hor = new HorizontalLayout();
        hor.setWidth(0.67 * Display.width + "px");
        hor.addComponent(label);
        hor.setComponentAlignment(label, Alignment.TOP_CENTER);
        name.setWidth(0.68 * Display.width + "px");
        name.setContent(hor);
        name.setStyleName("backColorGrey");
        DBManager db = new DBManager();
        List<UserInfoBean> users = (ArrayList) db.getUsersForGroup(group);
        participants.setVisible(false);

        fillGrid(users);
        VerticalLayout vert = new VerticalLayout(name, participants);

        addComponents(vert);
    }

    private void fillGrid(List<UserInfoBean> users) {
        participants = new VerticalLayout();
        participants.setVisible(false);
        for (int i = 0; i < users.size(); ++i) {
            participants.addComponent(new OneParticipant(users.get(i)));
        }
    }

    private void configureActions() {
        name.addClickListener(new MouseEvents.ClickListener() {
            @Override
            public void click(MouseEvents.ClickEvent event) {
                if (!isClicked) {
                    isClicked = true;
                    participants.setVisible(isClicked);
                } else {
                    isClicked = false;
                    participants.setVisible(isClicked);
                }
            }

        });
    }
}