Example usage for com.vaadin.ui GridLayout setSpacing

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

Introduction

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

Prototype

@Override
    public void setSpacing(boolean spacing) 

Source Link

Usage

From source file:org.activiti.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);
    taskDetails.setMargin(false, false, true, false);

    // Add image// w w w. j av a  2s . c o m
    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(" ");
    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:org.activiti.explorer.ui.task.TaskDetailPanel.java

License:Apache License

protected void initHeader() {
    GridLayout taskDetails = new GridLayout(2, 2);
    taskDetails.setWidth(100, UNITS_PERCENTAGE);
    taskDetails.addStyleName(ExplorerLayout.STYLE_TITLE_BLOCK);
    taskDetails.setSpacing(true);
    taskDetails.setMargin(false, false, true, false);
    taskDetails.setColumnExpandRatio(1, 1.0f);
    centralLayout.addComponent(taskDetails);

    // Add image/*from  w w w  .j a va2  s  .  co  m*/
    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:org.activiti.kickstart.ui.panel.KickstartWorkflowPanel.java

License:Apache License

protected void initUi() {
    initTitle();// w  w  w  .  j a v a  2  s  . c om

    GridLayout layout = new GridLayout(2, 7);
    layout.setSizeFull();
    layout.setColumnExpandRatio(0, 1.0f);
    layout.setColumnExpandRatio(1, 9.0f);
    layout.setSpacing(true);
    addComponent(layout);

    initNameField(layout);
    initDescriptionField(layout);
    initTaskTable(layout);
    initButtons(layout);
}

From source file:org.activiti.kickstart.ui.popup.FormPopupWindow.java

License:Apache License

protected void initUi() {
    GridLayout layout = new GridLayout(2, 4);
    layout.setSpacing(true);
    addComponent(layout);/*  w ww.  j ava  2 s.c om*/

    // Title
    layout.addComponent(new Label(FORM_TITLE));
    titleField = new TextField();
    layout.addComponent(titleField);

    // Description
    layout.addComponent(new Label(DESCRIPTION));
    descriptionField = new TextField();
    descriptionField.setRows(2);
    descriptionField.setColumns(25);
    layout.addComponent(descriptionField);

    // Property table
    propertyTable = new PropertyTable();
    layout.addComponent(new Label(DATA));
    layout.addComponent(propertyTable);
    fillFormFields();

    // Buttons
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);

    // Save button
    Button saveButton = new Button("Save");
    buttons.addComponent(saveButton);
    saveButton.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = -2906886872414089331L;

        public void buttonClick(ClickEvent event) {
            FormDto form = createForm();
            formModel.addForm(taskItemId, form);
            close();
        }
    });

    // Delete button
    Button deleteButton = new Button("Delete");
    buttons.addComponent(deleteButton);
    deleteButton.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = 5267967369680365653L;

        public void buttonClick(ClickEvent event) {
            formModel.removeForm(taskItemId);
            close();
        }
    });

    layout.addComponent(new Label(""));
    layout.addComponent(buttons);
}

From source file:org.agocontrol.site.viewlet.bus.BusesFlowlet.java

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDescriptors = AgoControlSiteFields.getFieldDescriptors(Bus.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new EntityContainer<Bus>(entityManager, true, true, false, Bus.class, 1000,
            new String[] { "name" }, new boolean[] { true }, "busId");

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();/* w  w  w  .j  av a2s  .  com*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setSizeUndefined();
    gridLayout.addComponent(buttonLayout, 0, 0);

    final Table table = new FormattingTable();
    grid = new Grid(table, container);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);

    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    gridLayout.addComponent(grid, 0, 1);

    final Button addButton = getSite().getButton("add");
    buttonLayout.addComponent(addButton);
    addButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Bus bus = new Bus();
            bus.setCreated(new Date());
            bus.setModified(bus.getCreated());
            bus.setInventorySynchronized(new Date(0L));
            bus.setConnectionStatus(BusConnectionStatus.Disconnected);
            bus.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final BusFlowlet busView = getViewSheet().forward(BusFlowlet.class);
            busView.edit(bus, true);
        }
    });

    final Button editButton = getSite().getButton("edit");
    buttonLayout.addComponent(editButton);
    editButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Bus entity = container.getEntity(grid.getSelectedItemId());
            final BusFlowlet busView = getViewSheet().forward(BusFlowlet.class);
            busView.edit(entity, false);
        }
    });

    final Button removeButton = getSite().getButton("remove");
    buttonLayout.addComponent(removeButton);
    removeButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            container.removeItem(grid.getSelectedItemId());
            container.commit();
        }
    });

    final Company company = getSite().getSiteContext().getObject(Company.class);
    container.removeDefaultFilters();
    container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId()));
    grid.refresh();
}

From source file:org.agocontrol.site.viewlet.bus.BusFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();/*from  w  w w  . j av  a 2s .c  o m*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    busEditor = new ValidatingEditor(AgoControlSiteFields.getFieldDescriptors(Bus.class));
    busEditor.setCaption("Bus");
    busEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(busEditor, 0, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    gridLayout.addComponent(buttonLayout, 0, 1);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    buttonLayout.addComponent(saveButton);
    saveButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            busEditor.commit();
            entityManager.getTransaction().begin();
            try {
                entity = entityManager.merge(entity);
                entityManager.persist(entity);
                entityManager.getTransaction().commit();
                entityManager.detach(entity);
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + entity, t);
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    buttonLayout.addComponent(discardButton);
    discardButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            busEditor.discard();
        }
    });

}

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

License:Apache License

/**
 * Invoked when view is entered./*from   w  w  w  . ja va  2  s .  com*/
 * @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.
 */// w ww .  j av  a2  s. c o 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);
}

From source file:org.agocontrol.site.viewlet.element.ElementFlowlet.java

License:Apache License

@Override
public void initialize() {
    entityManager = getSite().getSiteContext().getObject(EntityManager.class);

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();//from  ww w  .j av  a 2s  .  co  m
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    elementEditor = new ValidatingEditor(AgoControlSiteFields.getFieldDescriptors(Element.class));
    elementEditor.setCaption("Element");
    elementEditor.addListener((ValidatingEditorStateListener) this);
    gridLayout.addComponent(elementEditor, 0, 0);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    gridLayout.addComponent(buttonLayout, 0, 1);

    saveButton = new Button("Save");
    saveButton.setImmediate(true);
    buttonLayout.addComponent(saveButton);
    saveButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            elementEditor.commit();
            entityManager.getTransaction().begin();
            try {
                entity = entityManager.merge(entity);
                entityManager.persist(entity);
                entityManager.getTransaction().commit();
                entityManager.detach(entity);
            } catch (final Throwable t) {
                if (entityManager.getTransaction().isActive()) {
                    entityManager.getTransaction().rollback();
                }
                throw new RuntimeException("Failed to save entity: " + entity, t);
            }
            final BusClient busClient = ((AgoControlSiteUI) UI.getCurrent()).getBusClient(entity.getBus());
            if (busClient != null) {
                if (busClient.saveElement(entity) && busClient.synchronizeInventory()) {
                    Notification.show("Element save sent to bus.", Notification.Type.HUMANIZED_MESSAGE);
                } else {
                    Notification.show("Element save bus error.", Notification.Type.ERROR_MESSAGE);
                }
            }
        }
    });

    discardButton = new Button("Discard");
    discardButton.setImmediate(true);
    buttonLayout.addComponent(discardButton);
    discardButton.addListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            elementEditor.discard();
        }
    });

}

From source file:org.agocontrol.site.viewlet.element.ElementsFlowlet.java

License:Apache License

@Override
public void initialize() {
    final List<FieldDescriptor> fieldDescriptors = AgoControlSiteFields.getFieldDescriptors(Element.class);

    final List<FilterDescriptor> filterDefinitions = new ArrayList<FilterDescriptor>();

    final EntityManager entityManager = getSite().getSiteContext().getObject(EntityManager.class);
    container = new EntityContainer<Element>(entityManager, true, true, false, Element.class, 1000,
            new String[] { "treeIndex" }, new boolean[] { true }, "elementId");

    ContainerUtil.addContainerProperties(container, fieldDescriptors);

    final GridLayout gridLayout = new GridLayout(1, 2);
    gridLayout.setSizeFull();/*w  ww  . j a  v a2s .co  m*/
    gridLayout.setMargin(false);
    gridLayout.setSpacing(true);
    gridLayout.setRowExpandRatio(1, 1f);
    setViewContent(gridLayout);

    final HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setSizeUndefined();
    gridLayout.addComponent(buttonLayout, 0, 0);

    final Table table = new FormattingTable();
    grid = new Grid(table, container);
    grid.setFields(fieldDescriptors);
    grid.setFilters(filterDefinitions);

    table.setColumnCollapsed("elementId", true);
    table.setColumnCollapsed("bus", true);
    table.setColumnCollapsed("created", true);
    table.setColumnCollapsed("modified", true);
    gridLayout.addComponent(grid, 0, 1);

    final Button addButton = getSite().getButton("add");
    buttonLayout.addComponent(addButton);
    addButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Element element = new Element();
            element.setCreated(new Date());
            element.setModified(element.getCreated());
            element.setOwner((Company) getSite().getSiteContext().getObject(Company.class));
            final ElementFlowlet elementView = getViewSheet().forward(ElementFlowlet.class);
            elementView.edit(element, true);
        }
    });

    final Button editButton = getSite().getButton("edit");
    buttonLayout.addComponent(editButton);
    editButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Element entity = container.getEntity(grid.getSelectedItemId());
            final ElementFlowlet elementView = getViewSheet().forward(ElementFlowlet.class);
            elementView.edit(entity, false);
        }
    });

    final Button removeButton = getSite().getButton("remove");
    buttonLayout.addComponent(removeButton);
    removeButton.addClickListener(new ClickListener() {
        /** Serial version UID. */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final ClickEvent event) {
            final Element element = container.getEntity(grid.getSelectedItemId());

            container.removeItem(grid.getSelectedItemId());
            container.commit();

            final BusClient busClient = ((AgoControlSiteUI) UI.getCurrent()).getBusClient(element.getBus());
            if (busClient != null) {
                if (busClient.removeElement(element)) {
                    Notification.show("Element removal sent to bus.", Notification.Type.HUMANIZED_MESSAGE);
                } else {
                    Notification.show("Element removal bus error.", Notification.Type.ERROR_MESSAGE);
                }
            }
        }
    });

    final Company company = getSite().getSiteContext().getObject(Company.class);
    container.removeDefaultFilters();
    container.addDefaultFilter(new Compare.Equal("owner.companyId", company.getCompanyId()));
    grid.refresh();
}