Example usage for com.vaadin.ui GridLayout setColumns

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

Introduction

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

Prototype

public void setColumns(int columns) 

Source Link

Document

Sets the number of columns in the grid.

Usage

From source file:com.mymita.vaadlets.VaadletsBuilder.java

License:Apache License

private static void setLayoutAttributes(final com.vaadin.ui.Component vaadinComponent,
        final com.mymita.vaadlets.core.Component vaadletsComponent) {
    if (vaadletsComponent instanceof com.mymita.vaadlets.layout.AbstractLayout) {
        final Boolean margin = ((com.mymita.vaadlets.layout.AbstractLayout) vaadletsComponent).isMargin();
        if (margin != null) {
            ((com.vaadin.ui.AbstractLayout) vaadinComponent).setMargin(margin);
        }//from ww w  .java  2  s.  com
        final Boolean marginTop = ((com.mymita.vaadlets.layout.AbstractLayout) vaadletsComponent).isMarginTop();
        final Boolean marginRight = ((com.mymita.vaadlets.layout.AbstractLayout) vaadletsComponent)
                .isMarginRight();
        final Boolean marginBottom = ((com.mymita.vaadlets.layout.AbstractLayout) vaadletsComponent)
                .isMarginBottom();
        final Boolean marginLeft = ((com.mymita.vaadlets.layout.AbstractLayout) vaadletsComponent)
                .isMarginLeft();
        if (marginTop != null || marginRight != null || marginBottom != null || marginLeft != null) {
            ((com.vaadin.ui.AbstractLayout) vaadinComponent).setMargin(
                    firstNonNull(marginTop, firstNonNull(margin, FALSE)),
                    firstNonNull(marginRight, firstNonNull(margin, FALSE)),
                    firstNonNull(marginBottom, firstNonNull(margin, FALSE)),
                    firstNonNull(marginLeft, firstNonNull(margin, FALSE)));
        }
    }
    if (vaadletsComponent instanceof com.mymita.vaadlets.layout.OrderedLayout) {
        final Boolean spacing = ((com.mymita.vaadlets.layout.OrderedLayout) vaadletsComponent).isSpacing();
        if (spacing != null) {
            ((com.vaadin.ui.AbstractOrderedLayout) vaadinComponent).setSpacing(spacing);
        }
    }
    if (vaadletsComponent instanceof com.mymita.vaadlets.layout.GridLayout) {
        final com.vaadin.ui.GridLayout vaadinGridLayout = (com.vaadin.ui.GridLayout) vaadinComponent;
        final com.mymita.vaadlets.layout.GridLayout vaadletsGridLayout = (com.mymita.vaadlets.layout.GridLayout) vaadletsComponent;
        vaadinGridLayout.setColumns(vaadletsGridLayout.getColumns());
        vaadinGridLayout.setRows(vaadletsGridLayout.getRows());
        for (final Object object : vaadletsGridLayout.getColumnExpandRatioOrRowExpandRatio()) {
            if (object instanceof GridLayoutColumExpandRatio) {
                final GridLayoutColumExpandRatio cr = (GridLayoutColumExpandRatio) object;
                vaadinGridLayout.setColumnExpandRatio(cr.getColumnIndex(), cr.getRatio());
            }
            if (object instanceof GridLayoutRowExpandRatio) {
                final GridLayoutRowExpandRatio rr = (GridLayoutRowExpandRatio) object;
                vaadinGridLayout.setRowExpandRatio(rr.getRowIndex(), rr.getRatio());
            }
        }
        final Boolean spacing = ((com.mymita.vaadlets.layout.GridLayout) vaadletsComponent).isSpacing();
        if (spacing != null) {
            ((com.vaadin.ui.GridLayout) vaadinComponent).setSpacing(spacing);
        }
    }
}

From source file:de.metas.ui.web.vaadin.window.editor.FieldEditorsContainer.java

License:Open Source License

private void addChildEditor(final Label label, final Component editorComp,
        final PropertyLayoutInfo layoutInfo) {
    final GridLayout content = getContent();
    int labelColumn = contentNextColumn * 2;
    int labelRow = contentNextRow;

    if (layoutInfo.isNextColumn()) {
        labelColumn = content.getColumns();
        labelRow = 0;/*w w  w .  j  ava2  s.c  o  m*/
    }

    final int editorRowsSpan = layoutInfo.getRowsSpan();
    final int editorColumnFrom = labelColumn + 1;
    final int editorColumnTo = editorColumnFrom;
    final int editorRowFrom = labelRow;
    final int editorRowTo = editorRowFrom + (editorRowsSpan - 1);
    if (editorColumnTo >= content.getColumns()) {
        content.setColumns(editorColumnTo + 1);
    }
    if (editorRowTo >= content.getRows()) {
        content.setRows(editorRowTo + 1);
    }

    //
    //
    if (label != null) {
        content.addComponent(label, labelColumn, labelRow);
        content.setComponentAlignment(label, Alignment.MIDDLE_RIGHT);
    }
    content.addComponent(editorComp, editorColumnFrom, editorRowFrom, editorColumnTo, editorRowTo);
    content.setComponentAlignment(editorComp, Alignment.MIDDLE_LEFT);
    editorComp.setSizeFull();

    //
    //
    // contentNextColumn;
    contentNextRow = editorRowTo + 1;
}

From source file:edu.nps.moves.mmowgli.export.BaseExporter.java

License:Open Source License

protected void getMetaStringOrCancel(final MetaListener lis, String title, final Map<String, String> params) {
    final Window dialog = new Window(title);
    final TextField[] parameterFields;

    dialog.setModal(true);/*from  w  w w  .  j a  v a  2  s. c o m*/

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setSizeFull();
    dialog.setContent(layout);

    final TextArea ta = new TextArea();
    ta.setWidth("100%");
    ta.setInputPrompt("Type a description of this data, or the game which generated this data (optional)");

    ta.setImmediate(true);
    layout.addComponent(ta);

    Set<String> keySet = params.keySet();
    parameterFields = new TextField[keySet.size()];
    int i = 0;
    GridLayout pGL = new GridLayout();
    pGL.addStyleName("m-greyborder");
    pGL.setColumns(2);
    Label hdr = new HtmlLabel("<b>Parameters</b>");
    hdr.addStyleName("m-textaligncenter");
    pGL.addComponent(hdr, 0, 0, 1, 0); // top row
    pGL.setComponentAlignment(hdr, Alignment.MIDDLE_CENTER);
    pGL.setSpacing(false);
    for (String key : keySet) {
        pGL.addComponent(new HtmlLabel("&nbsp;" + key + "&nbsp;&nbsp;"));
        pGL.addComponent(parameterFields[i] = new TextField());
        parameterFields[i++].setValue(params.get(key));
    }
    if (i > 0) {
        layout.addComponent(pGL);
        layout.setComponentAlignment(pGL, Alignment.TOP_CENTER);
    }

    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    @SuppressWarnings("serial")
    Button cancelButt = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();
            lis.continueOrCancel(null);
        }
    });

    @SuppressWarnings("serial")
    Button exportButt = new Button("Export", new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            dialog.close();

            Set<String> keySet = params.keySet();
            int i = 0;
            for (String key : keySet)
                params.put(key, parameterFields[i++].getValue().toString());

            lis.continueOrCancel(ta.getValue().toString());
        }
    });
    hl.addComponent(cancelButt);
    hl.addComponent(exportButt);
    hl.setComponentAlignment(cancelButt, Alignment.MIDDLE_RIGHT);
    hl.setExpandRatio(cancelButt, 1.0f);

    // The components added to the window are actually added to the window's
    // layout; you can use either. Alignments are set using the layout
    layout.addComponent(hl);
    dialog.setWidth("385px");
    dialog.setHeight("310px");
    hl.setWidth("100%");
    ta.setWidth("100%");
    ta.setHeight("100%");
    layout.setExpandRatio(ta, 1.0f);

    UI.getCurrent().addWindow(dialog);
}

From source file:edu.nps.moves.mmowgli.modules.actionplans.ActionPlanPageTabImages.java

License:Open Source License

@Override
public void initGui() {
    setSizeUndefined();// w ww .j  a  v a  2  s  . co m
    VerticalLayout leftLay = getLeftLayout();
    leftLay.setSpacing(false);
    leftLay.setMargin(false);

    VerticalLayout flowLay = new VerticalLayout();
    flowLay.setWidth("100%");
    leftLay.addComponent(flowLay);
    flowLay.setSpacing(true);

    Label missionLab = new Label("Authors, add some images!");
    flowLay.addComponent(missionLab);
    flowLay.setComponentAlignment(missionLab, Alignment.TOP_LEFT);
    missionLab.addStyleName("m-actionplan-mission-title-text");

    ActionPlan ap = ActionPlan.getTL(apId);

    Label missionContentLab;
    if (!isMockup)
        missionContentLab = new HtmlLabel(ap.getImagesInstructions());
    else {
        Game g = Game.getTL();
        missionContentLab = new HtmlLabel(g.getDefaultActionPlanImagesText());
    }
    flowLay.addComponent(missionContentLab);
    flowLay.setComponentAlignment(missionContentLab, Alignment.TOP_LEFT);
    flowLay.addStyleName("m-actionplan-mission-content-text");

    MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals();
    flowLay.addComponent(addImageButt);
    addImageButt.addStyleName("m-actionplan-addimage-butt");
    addImageButt.addStyleName("borderless");
    addImageButt.setIcon(globs.getMediaLocator().getActionPlanAddImageButt());
    addImageButt.addClickListener(new ImageAdder());
    addImageButt.setEnabled(!isReadOnly);

    flowLay.addComponent(nonAuthorLabel = new Label("Authors may add images when editing the plan."));
    nonAuthorLabel.setVisible(false);

    VerticalLayout rightLay = getRightLayout();
    rightLay.setSpacing(false);
    rightLay.setMargin(false);

    imageScroller = new Panel();
    GridLayout gridL = new GridLayout();
    gridL.setColumns(2);
    gridL.setSpacing(true);
    gridL.setMargin(new MarginInfo(true));
    imageScroller.setContent(gridL);
    imageScroller.setStyleName(Reindeer.PANEL_LIGHT); // make a transparent scroller
    imageScroller.setWidth("100%");
    imageScroller.setHeight("99%");
    setUpIndexListener(imageScroller);

    rightLay.addComponent(imageScroller);
    fillWithImagesTL();
}

From source file:edu.nps.moves.mmowgli.modules.actionplans.ActionPlanPageTabVideos.java

License:Open Source License

@Override
public void initGui() {
    setSizeUndefined();/*from  w ww  .ja  v a  2 s  . c  o m*/
    VerticalLayout leftLay = getLeftLayout();
    leftLay.setSpacing(false);
    leftLay.setMargin(false);

    VerticalLayout flowLay = new VerticalLayout();
    flowLay.setWidth("100%");
    leftLay.addComponent(flowLay);
    flowLay.setSpacing(true);

    Label missionLab = new Label("Authors, add some videos!");
    flowLay.addComponent(missionLab);
    flowLay.setComponentAlignment(missionLab, Alignment.TOP_LEFT);
    missionLab.addStyleName("m-actionplan-mission-title-text");

    ActionPlan ap = ActionPlan.getTL(apId);

    Label missionContentLab;
    if (!isMockup)
        missionContentLab = new HtmlLabel(ap.getVideosInstructions());
    else {
        Game g = Game.getTL();
        missionContentLab = new HtmlLabel(g.getDefaultActionPlanVideosText());
    }
    flowLay.addComponent(missionContentLab);
    flowLay.setComponentAlignment(missionContentLab, Alignment.TOP_LEFT);
    flowLay.addStyleName("m-actionplan-mission-content-text");

    MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals();
    flowLay.addComponent(addVideoButt);
    addVideoButt.addStyleName("m-actionplan-addimage-butt");
    addVideoButt.addStyleName("borderless");
    addVideoButt.setIcon(globs.getMediaLocator().getActionPlanAddVideoButt());
    addVideoButt.addClickListener(new VideoAdder());
    addVideoButt.setEnabled(!isReadOnly);

    flowLay.addComponent(nonAuthorLabel = new Label("Authors may add videos when editing the plan."));
    nonAuthorLabel.setVisible(false);

    VerticalLayout rightLay = getRightLayout();
    rightLay.setSpacing(false);
    rightLay.setMargin(false);

    rightScroller = new Panel();
    GridLayout gridL = new GridLayout();
    gridL.setColumns(2);
    gridL.setSpacing(true);
    gridL.setMargin(new MarginInfo(true));
    rightScroller.setContent(gridL);
    rightScroller.setStyleName(Reindeer.PANEL_LIGHT); // make a transparent scroller
    rightScroller.setWidth("100%");
    rightScroller.setHeight("99%");
    setUpIndexListener(rightScroller);

    rightLay.addComponent(rightScroller);
    ;
    fillWithVideosTL();
}

From source file:edu.nps.moves.mmowgli.modules.userprofile.UserProfileMyIdeasPanel2.java

License:Open Source License

@SuppressWarnings("unchecked")
private Component createProfileTL() {
    VerticalLayout lay = new VerticalLayout();
    lay.setWidth("670px");
    Label lab;//from   w w w .  ja  va2  s.co  m
    lay.addComponent(lab = new Label());
    lab.setHeight("10px");

    VerticalLayout innerVL = new VerticalLayout();
    innerVL.setSpacing(true);
    innerVL.setMargin(true);
    innerVL.setWidth("100%"); //"90%");   
    innerVL.addStyleName("m-myideaprofile-table");
    lay.addComponent(innerVL);

    GridLayout gridL = new GridLayout();
    gridL.setColumns(2);
    gridL.addStyleName("m-userprofile-text");
    gridL.setSpacing(true);

    CardType ct;
    int count = 0;
    int largest = -1;

    List<Card> lisPos = commonCriteria()
            .add(Restrictions.eq("cardType",
                    ct = CardType
                            .getCurrentPositiveIdeaCardTypeTL()/*CardTypeManager.getPositiveIdeaCardTypeTL()*/))
            .list();
    count += lisPos.size();
    largest = Math.max(largest, lisPos.size());

    List<Card> lisNeg = commonCriteria()
            .add(Restrictions.eq("cardType", ct = CardType.getCurrentNegativeIdeaCardTypeTL())).list(); //CardTypeManager.getNegativeIdeaCardTypeTL())).list();
    count += lisNeg.size();
    largest = Math.max(largest, lisNeg.size());

    List<Card> lisExpand = commonCriteria().add(Restrictions.eq("cardType", ct = CardType.getExpandTypeTL()))
            .list();//CardTypeManager.getExpandTypeTL())).list();
    count += lisExpand.size();
    largest = Math.max(largest, lisExpand.size());

    List<Card> lisAdapt = commonCriteria().add(Restrictions.eq("cardType", ct = CardType.getAdaptTypeTL()))
            .list();//CardTypeManager.getAdaptTypeTL())).list();
    count += lisAdapt.size();
    largest = Math.max(largest, lisAdapt.size());

    List<Card> lisCounter = commonCriteria().add(Restrictions.eq("cardType", ct = CardType.getCounterTypeTL()))
            .list();//CardTypeManager.getCounterTypeTL())).list();
    count += lisCounter.size();
    largest = Math.max(largest, lisCounter.size());

    List<Card> lisExplore = commonCriteria().add(Restrictions.eq("cardType", ct = CardType.getExploreTypeTL()))
            .list();//CardTypeManager.getExploreTypeTL())).list();
    count += lisExplore.size();
    largest = Math.max(largest, lisExplore.size());

    ct = CardType.getCurrentPositiveIdeaCardTypeTL(); //CardTypeManager.getPositiveIdeaCardTypeTL();
    row(ct.getSummaryHeader(), largest, lisPos.size(), ct, gridL);
    ct = CardType.getCurrentNegativeIdeaCardTypeTL(); //CardTypeManager.getNegativeIdeaCardTypeTL();
    row(ct.getSummaryHeader(), largest, lisNeg.size(), ct, gridL);
    ct = CardType.getExpandTypeTL(); //CardTypeManager.getExpandTypeTL();
    row(ct.getSummaryHeader(), largest, lisExpand.size(), ct, gridL);
    ct = CardType.getAdaptTypeTL(); //CardTypeManager.getAdaptTypeTL();
    row(ct.getSummaryHeader(), largest, lisAdapt.size(), ct, gridL);
    ct = CardType.getCounterTypeTL(); //CardTypeManager.getCounterTypeTL();
    row(ct.getSummaryHeader(), largest, lisCounter.size(), ct, gridL);
    ct = CardType.getExploreTypeTL(); //CardTypeManager.getExploreTypeTL();
    row(ct.getSummaryHeader(), largest, lisExplore.size(), ct, gridL);

    gridL.addComponent(new Label(""));
    gridL.addComponent(new Label(""));
    gridL.addComponent(new Label("TOTAL"));
    gridL.addComponent(new Label("" + count));

    innerVL.addComponent(gridL);

    lay.addComponent(lab = new Label());
    lab.setHeight("1px");
    lay.setExpandRatio(lab, 1.0f);
    return lay;
}

From source file:edu.nps.moves.mmowgliMobile.ui.UserRenderer2.java

License:Open Source License

public void setMessage(FullEntryView2 mView, ListEntry message, ListView2 messageList,
        AbstractOrderedLayout layout) {//from   www.  j  a v a  2 s  . co m
    // messageList can be null if coming in from ActionPlan
    Object key = HSess.checkInit();
    UserListEntry wu = (UserListEntry) message;
    User u = wu.getUser();
    layout.removeAllComponents();

    HorizontalLayout hlay = new HorizontalLayout();
    layout.addComponent(hlay);
    hlay.addStyleName("m-userview-top");
    hlay.setWidth("100%");
    hlay.setMargin(true);
    hlay.setSpacing(true);

    Image img = new Image();
    img.addStyleName("m-ridgeborder");
    img.setSource(mediaLocator.locate(u.getAvatar().getMedia()));
    img.setWidth("90px");
    img.setHeight("90px");
    hlay.addComponent(img);
    hlay.setComponentAlignment(img, Alignment.MIDDLE_CENTER);

    Label lab;
    hlay.addComponent(lab = new Label());
    lab.setWidth("5px");

    VerticalLayout vlay = new VerticalLayout();
    vlay.setSpacing(true);
    hlay.addComponent(vlay);
    hlay.setComponentAlignment(vlay, Alignment.MIDDLE_LEFT);
    vlay.setWidth("100%");
    hlay.setExpandRatio(vlay, 1.0f);
    HorizontalLayout horl = new HorizontalLayout();
    horl.setSpacing(false);
    vlay.addComponent(horl);
    vlay.setComponentAlignment(horl, Alignment.BOTTOM_LEFT);
    horl.addComponent(lab = new Label("name"));
    lab.addStyleName("m-user-top-label"); //light-text");
    horl.addComponent(lab = new HtmlLabel("&nbsp;&nbsp;" + u.getUserName()));
    lab.addStyleName("m-user-top-value");
    horl = new HorizontalLayout();
    horl.setSpacing(false);
    vlay.addComponent(horl);
    vlay.setComponentAlignment(horl, Alignment.TOP_LEFT);

    horl.addComponent(lab = new Label("level"));
    lab.addStyleName("m-user-top-label"); //light-text");
    Level lev = u.getLevel();
    if (u.isGameMaster()) {
        Level l = Level.getLevelByOrdinal(Level.GAME_MASTER_ORDINAL, HSess.get());
        if (l != null)
            lev = l;
    }
    horl.addComponent(lab = new HtmlLabel("&nbsp;&nbsp;&nbsp;" + lev.getDescription()));
    lab.addStyleName("m-user-top-value");

    GridLayout gLay = new GridLayout();
    // gLay.setHeight("155px");  // won't size properly
    gLay.setMargin(true);
    gLay.addStyleName("m-userview-mid");
    gLay.setColumns(2);
    gLay.setRows(11);
    gLay.setSpacing(true);
    gLay.setWidth("100%");
    gLay.setColumnExpandRatio(1, 1.0f);
    layout.addComponent(gLay);

    addRow(gLay, "user ID:", "" + getPojoId(message));
    addRow(gLay, "location:", u.getLocation());
    addRow(gLay, "expertise:", u.getExpertise());
    addRow(gLay, "affiliation:", u.getAffiliation());
    addRow(gLay, "date registered:", formatter.format(u.getRegisterDate()));

    gLay.addComponent(new Hr(), 0, 5, 1, 5);

    Container cntr = new CardsByUserContainer<Card>(u); // expects ThreadLocal session to be setup
    numCards = cntr.size();
    addRow(gLay, "cards played:", "" + numCards);
    cntr = new ActionPlansByUserContainer<Card>(u); // expects ThreadLocal session to be setup
    numAps = cntr.size();
    addRow(gLay, "action plans:", "" + numAps);

    gLay.addComponent(new Hr(), 0, 8, 1, 8);

    addRow(gLay, "exploration points:", "" + u.getBasicScore());
    addRow(gLay, "innovation points:", "" + u.getInnovationScore());

    cardListener = new CardLis(u, mView);
    apListener = new AppLis(u, mView);

    layout.addComponent(makeButtons());

    HSess.checkClose(key);
}

From source file:org.activiti.explorer.ui.management.identity.UserDetailPanel.java

License:Apache License

protected void loadUserDetails() {
    // Grid of details
    GridLayout detailGrid = new GridLayout();
    detailGrid.setColumns(2);
    detailGrid.setSpacing(true);//from  w w  w .  j av  a 2 s. co m
    detailGrid.setMargin(true, true, false, true);
    userDetailsLayout.addComponent(detailGrid);

    // Details
    addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_ID), new Label(user.getId())); // details are non-editable
    if (!editingDetails) {
        addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_FIRSTNAME),
                new Label(user.getFirstName()));
        addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_LASTNAME),
                new Label(user.getLastName()));
        addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_EMAIL), new Label(user.getEmail()));
    } else {
        firstNameField = new TextField(null, user.getFirstName() != null ? user.getFirstName() : "");
        addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_FIRSTNAME), firstNameField);
        firstNameField.focus();

        lastNameField = new TextField(null, user.getLastName() != null ? user.getLastName() : "");
        addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_LASTNAME), lastNameField);

        emailField = new TextField(null, user.getEmail() != null ? user.getEmail() : "");
        addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_EMAIL), emailField);

        passwordField = new PasswordField();
        Label cautionLabel = new Label(i18nManager.getMessage(Messages.USER_RESET_PASSWORD));
        cautionLabel.addStyleName(Reindeer.LABEL_SMALL);
        HorizontalLayout passwordLayout = new HorizontalLayout();
        passwordLayout.setSpacing(true);
        passwordLayout.addComponent(passwordField);
        passwordLayout.addComponent(cautionLabel);
        passwordLayout.setComponentAlignment(cautionLabel, Alignment.MIDDLE_LEFT);
        addUserDetail(detailGrid, i18nManager.getMessage(Messages.USER_PASSWORD), passwordLayout);
    }
}

From source file:org.agocontrol.site.viewlet.dashboard.BuildingControlPanel.java

License:Apache License

/**
 * Invoked when view is entered./* w  w  w .j  av a 2  s .c o m*/
 * @param parameters the parameters
 */
public final synchronized void enter(final String parameters) {
    if (recordReaderThread != null) {
        recordReaderExitRequested = true;
        recordReaderThread.interrupt();
        try {
            recordReaderThread.join();
        } catch (final InterruptedException e) {
            LOGGER.debug("Record reader thread death wait interrupted.");
        }
    }
    elementLayout.removeAllComponents();
    recordsLayouts.clear();
    recordsQueue.clear();
    recordReaderExitRequested = false;

    final Company company = siteContext.getObject(Company.class);
    if (company == null || parameters == null || parameters.length() == 0) {
        return;
    }

    final String buildingId = parameters;
    final List<Element> elements = ElementDao.getElements(entityManager, company);

    boolean started = false;
    for (final Element element : elements) {
        if (element.getElementId().equals(buildingId)) {
            started = true;
            continue;
        }
        if (!started) {
            continue;
        }
        if (element.getTreeDepth() == 0) {
            break;
        }

        final HorizontalLayout elementLayout = new HorizontalLayout();
        this.elementLayout.addComponent(elementLayout);
        elementLayout.setSpacing(true);

        final Resource elementIcon;
        switch (element.getType()) {
        case ROOM:
            elementIcon = roomIcon;
            break;
        case DEVICE:
            elementIcon = deviceIcon;
            break;
        default:
            elementIcon = deviceIcon;
            break;
        }

        final Embedded embedded = new Embedded(null, elementIcon);
        elementLayout.addComponent(embedded);
        elementLayout.setExpandRatio(embedded, 0.1f);
        embedded.setWidth(32, Unit.PIXELS);
        embedded.setHeight(32, Unit.PIXELS);

        final Label label = new Label();
        elementLayout.addComponent(label);
        elementLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
        label.setValue(element.toString());

        final GridLayout recordLayout = new GridLayout();
        recordLayout.setSpacing(true);
        recordLayout.setColumns(4);
        recordLayout.setRows(1);

        this.elementLayout.addComponent(recordLayout);
        recordsLayouts.put(element.getElementId(), recordLayout);

    }

    recordReaderThread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                final EntityManager threadEntityManager = ((EntityManagerFactory) getSite().getSiteContext()
                        .getObject(EntityManagerFactory.class)).createEntityManager();
                for (final Element element : elements) {
                    final List<RecordSet> recordSets = RecordSetDao.getRecordSets(threadEntityManager, element);
                    if (recordsLayouts.containsKey(element.getElementId())) {
                        for (final RecordSet recordSet : recordSets) {
                            recordsQueue.put(RecordDao.getRecords(threadEntityManager, recordSet, 1));
                            if (recordReaderExitRequested) {
                                break;
                            }
                        }
                    }
                }

                Thread.sleep(10);
            } catch (InterruptedException e) {
            }
        }
    });
    recordReaderThread.start();

}

From source file:org.agocontrol.site.viewlet.dashboard.DashboardViewlet.java

License:Apache License

/**
 * Default constructor which constructs component hierarchy.
 *///from w  ww  . j a va2s.  co m
public DashboardViewlet() {
    site = ((AgoControlSiteUI) UI.getCurrent()).getSite();
    siteContext = getSite().getSiteContext();
    entityManager = siteContext.getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout();
    gridLayout.setSizeFull();
    gridLayout.setRows(3);
    gridLayout.setColumns(2);
    gridLayout.setSpacing(true);
    gridLayout.setColumnExpandRatio(0, 1);
    gridLayout.setColumnExpandRatio(1, 0);
    gridLayout.setRowExpandRatio(0, 0);
    gridLayout.setRowExpandRatio(1, 0);
    gridLayout.setRowExpandRatio(2, 1);

    buildingSelectPanel = new BuildingSelectPanel();
    //buildingSelectPanel.setCaption("Building Selection");
    //buildingSelectPanel.setSizeFull();
    gridLayout.addComponent(buildingSelectPanel, 0, 0, 1, 0);

    buildingControlPanel = new BuildingControlPanel();
    //buildingControlPanel.setCaption("Control Panel");
    //buildingControlPanel.setHeight(200, Unit.PIXELS);
    buildingControlPanel.setSizeFull();
    gridLayout.addComponent(buildingControlPanel, 0, 1, 0, 2);

    chartPanel = new ChartPanel();
    chartPanel.setSizeFull();
    chartPanel.setWidth(700, Unit.PIXELS);
    chartPanel.setHeight(400, Unit.PIXELS);
    gridLayout.addComponent(chartPanel, 1, 1);

    eventPanel = new EventPanel();
    //eventPanel.setCaption("Bus Events");
    //ventPanel.setHeight(200, Unit.PIXELS);
    eventPanel.setSizeFull();
    gridLayout.addComponent(eventPanel, 1, 2);

    setCompositionRoot(gridLayout);
}