Example usage for com.vaadin.ui HorizontalSplitPanel setSplitPosition

List of usage examples for com.vaadin.ui HorizontalSplitPanel setSplitPosition

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalSplitPanel setSplitPosition.

Prototype

public void setSplitPosition(float pos) 

Source Link

Document

Moves the position of the splitter.

Usage

From source file:ru.codeinside.adm.ui.TreeTableOrganization.java

License:Mozilla Public License

public TreeTableOrganization() {
    setSizeFull();//  ww  w  .  ja  v a  2s . c om
    treetable = new TreeTable();
    treetable.setSizeFull();
    treetable.setSelectable(true);
    treetable.setMultiSelect(false);
    treetable.addListener(this);
    treetable.setImmediate(true);
    treetable.setValue(null);
    setMargin(true);
    // Add Table columns
    treetable.addContainerProperty(NAME_PROPERTY, String.class, "");

    fillTable(treetable);

    treetable.addListener(new ExpandListener() {

        private static final long serialVersionUID = 1L;

        public void nodeExpand(ExpandEvent event) {
            if (lockExpandListener) {
                return;
            }
            Object valuePropertyEvent = event.getItemId();
            Organization org = AdminServiceProvider.get().findOrganizationById((Long) valuePropertyEvent);
            Set<Organization> childs = org.getOrganizations();
            if (!(childs.isEmpty())) {
                treetable.setChildrenAllowed((Long) valuePropertyEvent, true);

                for (Organization o : childs) {
                    treetable.addItem(new Object[] { o.getName() }, o.getId());
                    treetable.setCollapsed(o.getId(), true);
                }

                for (Organization o : childs) {
                    treetable.setParent(o.getId(), (Long) valuePropertyEvent);
                }

                for (Organization o : childs) {
                    treetable.setChildrenAllowed(o.getId(), !(o.getOrganizations().isEmpty()));
                }
            }

        }
    });

    treetable.addListener(new CollapseListener() {

        private static final long serialVersionUID = 1L;

        public void nodeCollapse(CollapseEvent event) {
            if (lockExpandListener) {
                return;
            }
            Set<Object> delete = new HashSet<Object>();
            Collection<?> children = treetable.getChildren(event.getItemId());
            if (children != null) {
                for (Object child : children) {
                    removeRecursively(child, delete);
                }
            }
            for (Object o : delete) {
                treetable.setCollapsed(o, true);
                treetable.removeItem(o);
            }
        }

        private void removeRecursively(Object object, Set<Object> delete) {
            Collection<?> children = treetable.getChildren(object);
            if (children != null) {
                for (Object child : children) {
                    removeRecursively(child, delete);
                }
            }
            delete.add(object);
        }
    });

    panel.setStyleName(Reindeer.PANEL_LIGHT);
    panel.setSizeFull();
    panel.addComponent(new ButtonCreateOrganization(treetable));

    final HorizontalSplitPanel horiz = new HorizontalSplitPanel();
    horiz.setSplitPosition(25); // percent
    horiz.setSizeFull();
    addComponent(horiz);
    TextField orgFilter = new TextField();
    orgFilter.setImmediate(true);
    orgFilter.setWidth(100, UNITS_PERCENTAGE);
    orgFilter.setInputPrompt("  ");
    orgFilter.addListener(new FieldEvents.TextChangeListener() {

        List<Organization> organizations;
        List<Long> organizationIds;

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            String name = StringUtils.trimToNull(event.getText());
            if (name != null) {
                lockExpandListener = true;
                organizations = AdminServiceProvider.get().findOrganizationIdsByName(name);
                treetable.removeAllItems();
                organizationIds = new ArrayList<Long>();
                for (Organization org : organizations) {
                    for (Organization o1 : getPath(org)) {
                        if (!treetable.containsId(o1.getId())) {
                            treetable.addItem(new Object[] { o1.getName() }, o1.getId());
                            if (o1.getParent() != null) {
                                treetable.setParent(o1.getId(), o1.getParent().getId());
                            }
                            treetable.setChildrenAllowed(o1.getId(), !(o1.getOrganizations().isEmpty()));
                            treetable.setCollapsed(o1.getId(), false);
                        }
                    }
                    organizationIds.add(org.getId());
                }

                treetable.setCellStyleGenerator(new Table.CellStyleGenerator() {
                    @Override
                    public String getStyle(Object itemId, Object propertyId) {
                        if (propertyId == null) {
                            if (!organizationIds.contains(itemId)) {
                                return "gray";
                            }
                        }
                        return null;
                    }
                });

            } else {
                lockExpandListener = false;
                treetable.removeAllItems();
                fillTable(treetable);
                treetable.setCellStyleGenerator(new Table.CellStyleGenerator() {
                    @Override
                    public String getStyle(Object itemId, Object propertyId) {
                        return null;
                    }
                });
            }
        }

        private List<Organization> getPath(Organization org) {
            List<Organization> list = new LinkedList<Organization>();
            while (org != null) {
                list.add(0, org);
                org = org.getParent();
            }
            return list;
        }
    });
    VerticalLayout vl = new VerticalLayout();
    vl.setSpacing(true);
    vl.setSizeFull();
    vl.addComponent(orgFilter);
    vl.addComponent(treetable);
    vl.setExpandRatio(treetable, 0.9f);
    horiz.addComponent(vl);
    horiz.addComponent(panel);
}

From source file:ru.codeinside.gses.webui.executor.ExecutorFactory.java

License:Mozilla Public License

public static Component create(final Changer changer, final TabSheet tabs) {

    final ItemBuilder<Task> assigneeBuilder = new BatchItemBuilder<Task>() {
        private static final long serialVersionUID = 1L;

        transient Durations durations;

        @Override//from  w  w w .j ava2 s.com
        public void batchStart() {
            durations = new Durations();
        }

        @Override
        public void batchFinish() {
            durations = null;
        }

        @Override
        public Item createItem(final Task task) {
            final String taskId = task.getId();
            final ProcessDefinition def = ActivitiBean.get().getProcessDefinition(task.getProcessDefinitionId(),
                    Flash.login());
            String procedureName = Flash.flash().getExecutorService()
                    .getProcedureNameByDefinitionId(def.getId());
            final PropertysetItem item = new PropertysetItem();
            final Bid bid = getBid(task);
            final String bidId = bid.getId() == null ? "" : bid.getId().toString();
            item.addItemProperty("id", buttonProperty(bidId, new TaskGraphListener(changer, task)));
            item.addItemProperty("name", stringProperty(task.getName()));
            item.addItemProperty("startDate", stringProperty(formatter.format(bid.getDateCreated())));
            item.addItemProperty("declarant", stringProperty(bid.getDeclarant()));
            if (bid.getTag() == null || bid.getTag().isEmpty()) {
                item.addItemProperty("process", stringProperty(procedureName));
            } else {
                item.addItemProperty("process", stringProperty(bid.getTag() + " - " + procedureName));
            }
            item.addItemProperty("version", stringProperty(bid.getVersion()));
            final Button b = new Button("", new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    try {
                        showForm(tabs, taskId);
                    } catch (Exception e) {
                        Components.showException(event.getButton().getWindow(), e);
                    }
                }
            });
            b.setStyleName(Reindeer.BUTTON_SMALL);
            item.addItemProperty("claim", new ObjectProperty<Component>(b));
            item.addItemProperty("priority", stringProperty(String.valueOf(task.getPriority())));
            TaskDates td = AdminServiceProvider.get().getTaskDatesByTaskId(taskId);
            durations.fillBidAndTask(bid, td, item);
            return item;
        }

        private Bid getBid(final Task task) {
            Bid bid = AdminServiceProvider.get().getBidByTask(task.getId());

            if (bid == null) {
                bid = new Bid();
                bid.setDeclarant("");
                bid.setVersion("");
                bid.setStatus(BidStatus.Execute);
            }
            return bid;
        }

    };
    final AssigneeTaskListQuery assigneeTaskQuery = new AssigneeTaskListQuery(assigneeBuilder);
    final TableForExecutor assignee = new TableForExecutor(assigneeTaskQuery);
    assignee.setCaption("?? ?");
    assignee.addContainerProperty("id", Component.class, null);
    assignee.addContainerProperty("name", String.class, null);
    assignee.addContainerProperty("startDate", String.class, null);
    assignee.addContainerProperty("declarant", String.class, null);
    assignee.addContainerProperty("process", String.class, null);
    assignee.addContainerProperty("version", String.class, null);
    assignee.addContainerProperty("status", String.class, null);
    assignee.addContainerProperty("claim", Component.class, null);
    assignee.addContainerProperty("priority", String.class, null);
    assignee.addContainerProperty("bidDays", String.class, null);
    assignee.addContainerProperty("taskDays", String.class, null);
    assignee.setVisibleColumns(new Object[] { "id", "name", "startDate", "declarant", "process", "version",
            "claim", "bidDays", "taskDays" });
    assignee.setColumnHeaders(new String[] { "?", "", "  ?",
            "?", "", "v", "", "..", ".?." });
    assignee.setSelectable(false);
    assignee.setSortDisabled(true);

    assignee.setColumnAlignment("id", Table.ALIGN_RIGHT);
    assignee.setColumnExpandRatio("id", 0.3f);
    assignee.setColumnExpandRatio("name", 1f);
    assignee.setColumnExpandRatio("process", 1.2f);
    assignee.setColumnExpandRatio("bidDays", 0.2f);
    assignee.setColumnExpandRatio("taskDays", 0.2f);

    assignee.setCellStyleGenerator(new TaskStylist(assignee));

    final ItemBuilder<Task> claimBuilder = new BatchItemBuilder<Task>() {
        private static final long serialVersionUID = 1L;

        Durations durations;

        @Override
        public void batchStart() {
            durations = new Durations();
        }

        @Override
        public void batchFinish() {
            durations = null;
        }

        @Override
        public Item createItem(final Task task) {
            final String taskId = task.getId();
            final ProcessDefinition def = ActivitiBean.get().getProcessDefinition(task.getProcessDefinitionId(),
                    Flash.login());
            String procedureName = Flash.flash().getExecutorService()
                    .getProcedureNameByDefinitionId(def.getId());
            PropertysetItem item = new PropertysetItem();
            final Bid bid = getBid(task);
            ObjectProperty idProperty;
            if (bid.getId() == null) {
                idProperty = new ObjectProperty<String>("");
            } else {
                idProperty = buttonProperty(bid.getId().toString(), new TaskGraphListener(changer, task));
            }
            item.addItemProperty("id", idProperty);
            item.addItemProperty("name", stringProperty(task.getName()));
            item.addItemProperty("startDate", stringProperty(formatter.format(bid.getDateCreated())));
            item.addItemProperty("declarant", stringProperty(bid.getDeclarant()));
            if (bid.getTag() == null || bid.getTag().isEmpty()) {
                item.addItemProperty("process", stringProperty(procedureName));
            } else {
                item.addItemProperty("process", stringProperty(bid.getTag() + " - " + procedureName));
            }
            item.addItemProperty("version", stringProperty(bid.getVersion()));
            item.addItemProperty("status", stringProperty(bid.getStatus().getName()));
            final Button b = new Button("", new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    final String login = Flash.login();
                    final String errMessage = ActivitiBean.get().claim(taskId, login, login, false);
                    if (!StringUtils.isEmpty(errMessage)) {
                        event.getButton().getWindow().showNotification("", errMessage,
                                Notification.TYPE_ERROR_MESSAGE);
                    }
                    fireTaskChangedEvent(taskId, this);
                }
            });
            b.setStyleName(Reindeer.BUTTON_SMALL);
            item.addItemProperty("claim", new ObjectProperty<Component>(b));
            item.addItemProperty("priority", stringProperty(String.valueOf(task.getPriority())));
            TaskDates td = AdminServiceProvider.get().getTaskDatesByTaskId(taskId);
            durations.fillBidAndTask(bid, td, item);
            return item;
        }

        private Bid getBid(final Task task) {
            Bid bid = AdminServiceProvider.get().getBidByTask(task.getId());

            if (bid == null) {
                bid = new Bid();
                bid.setDeclarant("");
                bid.setVersion("");
                bid.setStatus(BidStatus.Execute);
            }
            return bid;
        }

    };
    final CandidateTaskListQuery candidateTaskQuery = new CandidateTaskListQuery(claimBuilder, Flash.login());
    final TableForExecutor candidate = new TableForExecutor(candidateTaskQuery);
    candidate.setCaption(" ?");
    candidate.addContainerProperty("id", Component.class, null);
    candidate.addContainerProperty("name", String.class, null);
    candidate.addContainerProperty("startDate", String.class, null);
    candidate.addContainerProperty("declarant", String.class, null);
    candidate.addContainerProperty("process", String.class, null);
    candidate.addContainerProperty("version", String.class, null);
    candidate.addContainerProperty("status", String.class, null);
    candidate.addContainerProperty("claim", Component.class, null);
    candidate.addContainerProperty("priority", String.class, null);
    candidate.addContainerProperty("bidDays", String.class, null);
    candidate.addContainerProperty("taskDays", String.class, null);
    candidate.setVisibleColumns(new Object[] { "id", "name", "startDate", "declarant", "process", "version",
            "status", "claim", "bidDays", "taskDays" });
    candidate.setColumnHeaders(new String[] { "?", "", "  ?",
            "?", "", "v", "?", "", "..", ".?." });
    candidate.setSelectable(false);
    candidate.setSortDisabled(true);

    candidate.setColumnAlignment("id", Table.ALIGN_RIGHT);
    candidate.setColumnExpandRatio("name", 1f);
    candidate.setColumnExpandRatio("process", 1f);

    candidate.setCellStyleGenerator(new TaskStylist(candidate));

    final Form filter = new TaskFilter(candidateTaskQuery, candidate, assigneeTaskQuery, assignee,
            TaskFilter.Mode.Executor);

    HorizontalLayout asigneeLayout = new HorizontalLayout();
    asigneeLayout.setSizeFull();
    asigneeLayout.setMargin(true);
    asigneeLayout.setSpacing(true);
    asigneeLayout.addComponent(assignee);

    Panel filterPanel = new Panel();
    filterPanel.setHeight("100%");
    filterPanel.addComponent(filter);
    final HorizontalSplitPanel hSplitter = new HorizontalSplitPanel();
    hSplitter.setSizeFull();
    hSplitter.setFirstComponent(filterPanel);
    hSplitter.setSecondComponent(asigneeLayout);
    hSplitter.setSplitPosition(35);

    VerticalLayout candidateLayout = new VerticalLayout();
    candidateLayout.setSizeFull();
    candidateLayout.setMargin(true);
    candidateLayout.addComponent(candidate);

    final TasksSplitter vSplitter = new TasksSplitter(assignee, candidate);
    vSplitter.setSizeFull();
    vSplitter.setFirstComponent(hSplitter);
    vSplitter.setSecondComponent(candidateLayout);
    vSplitter.setSplitPosition(57);
    return vSplitter;
}

From source file:ru.codeinside.gses.webui.manager.DirectoryPanel.java

License:Mozilla Public License

static Component createDirectoryPanel() {
    HorizontalSplitPanel horSplit = new HorizontalSplitPanel();
    horSplit.setSizeFull();/*from www . jav  a  2  s .c  o m*/
    horSplit.setMargin(true);

    Panel panel00 = new Panel();
    Panel panel01 = new Panel();

    Panel panel10 = new Panel();

    horSplit.setFirstComponent(panel00);

    VerticalLayout vl = new VerticalLayout();
    horSplit.setSecondComponent(vl);

    vl.addComponent(panel01);
    vl.addComponent(panel10);

    vl.setSpacing(true);

    horSplit.setWidth("100%");
    vl.setHeight("100%");

    panel00.setHeight("100%");
    panel00.setWidth("100%");

    panel01.setWidth("100%");
    panel01.setHeight("100%");
    panel10.setHeight("100%");
    horSplit.setSplitPosition(35);
    vl.setExpandRatio(panel01, 0.25f);
    vl.setExpandRatio(panel10, 0.75f);

    final Table dirMapTable = ManagerWorkplace.createDirectoryMapTable();
    final FilterTable directoryTable = ManagerWorkplace.createDirectoryTable();
    dirMapTable.setVisible(false);

    final Form createFieldForm = new Form();
    createFieldForm.setCaption(" ?  ?");

    final TextField keyField = new TextField("");
    keyField.setRequired(true);
    keyField.setMaxLength(254);
    createFieldForm.addField("key", keyField);

    final TextField valField = new TextField("");
    valField.setRequired(true);
    valField.setMaxLength(1022);
    createFieldForm.addField("val", valField);
    createFieldForm.setVisible(false);

    Button addButton = new Button("",
            new AddTupleButtonListener(createFieldForm, directoryTable, keyField, valField, dirMapTable));
    createFieldForm.addField("submit", addButton);

    directoryTable.addListener(new DirectoryTableChangeListener(createFieldForm, directoryTable, dirMapTable));

    ManagerWorkplace.buildContainer(directoryTable, createFieldForm, dirMapTable);
    directoryTable.setColumnHeaders(new String[] { "?", "", "" });

    final Form createDirectory = new Form();
    createDirectory.setCaption(" ?");
    final TextField field = new TextField("?");
    field.setRequired(true);
    field.setMaxLength(255);
    field.setRequiredError("  ?");
    createDirectory.addField("name", field);
    Button createButton = new Button("",
            new CreateDirectoryButtonListener(field, createDirectory, directoryTable));
    createDirectory.addField("submit", createButton);

    Panel loadPanel = new Panel();
    loadPanel.setCaption(" ?");

    UploadDirectory events = new UploadDirectory(directoryTable, dirMapTable);

    Upload c = new Upload("", events);
    c.addListener(events);

    c.setButtonCaption("");
    loadPanel.addComponent(c);

    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSizeFull();
    verticalLayout.setSpacing(true);
    verticalLayout.addComponent(loadPanel);
    verticalLayout.addComponent(createDirectory);
    verticalLayout.addComponent(directoryTable);

    panel00.addComponent(verticalLayout);

    panel01.addComponent(createFieldForm);

    dirMapTable.setSizeFull();
    dirMapTable.setPageLength(13);
    panel10.addComponent(dirMapTable);

    return horSplit;
}