Example usage for com.vaadin.ui Tree Tree

List of usage examples for com.vaadin.ui Tree Tree

Introduction

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

Prototype

public Tree(HierarchicalDataProvider<T, ?> dataProvider) 

Source Link

Document

Constructs a new Tree Component with given HierarchicalDataProvider .

Usage

From source file:rs.pupin.jpo.esta_ld.DSDRepoComponent.java

private void refreshContentCreateDSD(DataSet ds) {
    if (ds == null) {
        getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE);
        return;//from   www .java  2s  .c om
    }
    Structure struct = ds.getStructure();
    if (struct != null) {
        contentLayout.addComponent(new Label("The dataset already has a DSD!"));
        return;
    }

    dataset = ds.getUri();
    contentLayout.removeAllComponents();
    dataTree = new Tree("Dataset");
    dataTree.setNullSelectionAllowed(true);
    dataTree.setImmediate(true);
    dataTree.setWidth("500px");
    populateDataTree();
    addDataTreeListenersCreate();
    contentLayout.addComponent(dataTree);
    contentLayout.setExpandRatio(dataTree, 0.0f);

    final VerticalLayout right = new VerticalLayout();
    right.setSpacing(true);
    contentLayout.addComponent(right);
    contentLayout.setExpandRatio(right, 2.0f);
    lblUndefined = new Label("There are still x undefined components", Label.CONTENT_XHTML);
    right.addComponent(lblUndefined);
    lblMissingCodeLists = new Label("There are still y missing code lists", Label.CONTENT_XHTML);
    right.addComponent(lblMissingCodeLists);
    final TextField dsdUri = new TextField("Enter DSD URI");
    dsdUri.setWidth("300px");
    right.addComponent(dsdUri);
    final Button btnCreate = new Button("Create DSD");
    right.addComponent(btnCreate);
    right.addComponent(new Label("<hr/>", Label.CONTENT_XHTML));
    compatibleCodeLists = new Tree("Compatible code lists");
    right.addComponent(compatibleCodeLists);

    updateUndefinedAndMissing();

    compatibleCodeLists.addActionHandler(new Action.Handler() {
        public Action[] getActions(Object target, Object sender) {
            if (target == null)
                return null;
            if (compatibleCodeLists.getParent(target) != null)
                return null;
            return new Action[] { ACTION_SET_AS_CL };
        }

        public void handleAction(Action action, Object sender, Object target) {
            if (action == ACTION_SET_AS_CL) {
                Object item = compatibleCodeLists.getData();
                if (item == null) {
                    getWindow().showNotification(
                            "Error, the component cannot determine where to put the code list",
                            Window.Notification.TYPE_ERROR_MESSAGE);
                    return;
                }
                if (dataTree.getChildren(item).size() == 2) {
                    getWindow().showNotification("The component property already has a code list",
                            Window.Notification.TYPE_ERROR_MESSAGE);
                    return;
                }
                try {
                    RepositoryConnection conn = repository.getConnection();
                    String cl = (String) target;
                    String prop = (String) dataTree.getValue();
                    GraphQuery query = conn.prepareGraphQuery(QueryLanguage.SPARQL,
                            DSDRepoUtils.qPullCodeList(cl, prop, repoGraph, dataGraph));
                    query.evaluate();
                    getWindow().showNotification("Code List set");
                    addCodeListToDataTree();
                    updateUndefinedAndMissing();
                } catch (RepositoryException ex) {
                    Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
                } catch (MalformedQueryException ex) {
                    Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
                } catch (QueryEvaluationException ex) {
                    Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    });
    btnCreate.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            if (numUndefinedComponents > 0) {
                getWindow().showNotification("There can be no undefined components",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }
            if (numMissingCodeLists > 0) {
                getWindow().showNotification("All code lists must first be created or imported",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }
            final String dsd = dsdUri.getValue().toString();
            if (!isUri(dsd)) {
                getWindow().showNotification("Enter a valid URI for the DSD",
                        Window.Notification.TYPE_ERROR_MESSAGE);
            }

            try {
                RepositoryConnection conn = repository.getConnection();
                LinkedList<String> dList = new LinkedList<String>();
                LinkedList<String> mList = new LinkedList<String>();
                LinkedList<String> aList = new LinkedList<String>();
                LinkedList<String> uList = new LinkedList<String>();
                LinkedList<String> propList = new LinkedList<String>();
                LinkedList<String> rangeList = new LinkedList<String>();

                for (Object id : dataTree.rootItemIds()) {
                    Collection<?> children = dataTree.getChildren(id);
                    if (children == null)
                        continue;

                    Collection<String> list = null;
                    if (id.toString().startsWith("D"))
                        list = dList;
                    else if (id.toString().startsWith("M"))
                        list = mList;
                    else if (id.toString().startsWith("A"))
                        list = aList;
                    else if (id.toString().startsWith("U"))
                        list = uList;

                    for (Object prop : dataTree.getChildren(id)) {
                        CountingTreeHeader h = (CountingTreeHeader) dataTree.getChildren(prop).iterator()
                                .next();
                        propList.add(prop.toString());
                        list.add(prop.toString());
                        if (h.toString().startsWith("C")) {
                            rangeList.add("http://www.w3.org/2004/02/skos/core#Concept");
                        } else {
                            rangeList.add(dataTree.getChildren(h).iterator().next().toString());
                        }
                    }
                }
                if (uList.size() > 0) {
                    getWindow().showNotification("There are undefined properties!",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                    return;
                }
                GraphQuery query = conn.prepareGraphQuery(QueryLanguage.SPARQL, DSDRepoUtils.qCreateDSD(dataset,
                        dsd, dList, mList, aList, propList, rangeList, dataGraph));
                query.evaluate();
                getWindow().showNotification("DSD created!");
                DSDRepoComponent.this.ds = new SparqlDataSet(repository, DSDRepoComponent.this.ds.getUri(),
                        dataGraph);
                createDSD();
            } catch (RepositoryException ex) {
                Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedQueryException ex) {
                Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
            } catch (QueryEvaluationException ex) {
                Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:rs.pupin.jpo.esta_ld.InspectComponent.java

private void refreshContentStoreDSD(DataSet ds) {
    if (ds == null) {
        getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE);
        return;//from w  ww .j av a 2  s  .  c  om
    }
    Structure struct = ds.getStructure();
    if (struct == null) {
        contentLayout.addComponent(new Label("The dataset doesn't contain a DSD!"));
        return;
    }

    dataset = ds.getUri();
    contentLayout.removeAllComponents();
    ;
    dataTree = new Tree("Dataset");
    dataTree.setWidth("500px");
    dataTree.setNullSelectionAllowed(true);
    dataTree.setImmediate(true);
    populateStoreTree();
    addDataTreeListenersStore();
    contentLayout.addComponent(dataTree);
    contentLayout.setExpandRatio(dataTree, 0.0f);
    dimTransformLayout = new VerticalLayout();
    dimTransformLayout.setSpacing(true);
    contentLayout.addComponent(dimTransformLayout);
    contentLayout.setExpandRatio(dimTransformLayout, 2.0f);
    repoTree = new Tree("Matching Structures");
    repoTree.setNullSelectionAllowed(true);
    repoTree.setImmediate(true);
}

From source file:rs.pupin.jpo.esta_ld.InspectComponent.java

private void refreshContentCreateDSD(DataSet ds) {
    if (ds == null) {
        getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE);
        return;//from  w w  w. j a  v a2 s. c  o  m
    }
    Structure struct = ds.getStructure();
    if (struct != null) {
        contentLayout.addComponent(new Label("The dataset already has a DSD!"));
        return;
    }

    dataset = ds.getUri();
    contentLayout.removeAllComponents();
    dataTree = new Tree("Dataset");
    dataTree.setNullSelectionAllowed(true);
    dataTree.setImmediate(true);
    dataTree.setWidth("500px");
    populateDataTree();
    addDataTreeListenersCreate();
    contentLayout.addComponent(dataTree);
    contentLayout.setExpandRatio(dataTree, 0.0f);

    final VerticalLayout right = new VerticalLayout();
    right.setSpacing(true);
    contentLayout.addComponent(right);
    contentLayout.setExpandRatio(right, 2.0f);
    lblUndefined = new Label("There are still x undefined components", Label.CONTENT_XHTML);
    right.addComponent(lblUndefined);
    lblMissingCodeLists = new Label("There are still y missing code lists", Label.CONTENT_XHTML);
    right.addComponent(lblMissingCodeLists);
    final TextField dsdUri = new TextField("Enter DSD URI");
    dsdUri.setWidth("300px");
    right.addComponent(dsdUri);
    final Button btnCreate = new Button("Create DSD");
    right.addComponent(btnCreate);
    right.addComponent(new Label("<hr/>", Label.CONTENT_XHTML));
    compatibleCodeLists = new Tree("Compatible code lists");
    right.addComponent(compatibleCodeLists);

    updateUndefinedAndMissing();

    compatibleCodeLists.addActionHandler(new Action.Handler() {
        public Action[] getActions(Object target, Object sender) {
            if (target == null)
                return null;
            if (compatibleCodeLists.getParent(target) != null)
                return null;
            return new Action[] { ACTION_SET_AS_CL };
        }

        public void handleAction(Action action, Object sender, Object target) {
            if (action == ACTION_SET_AS_CL) {
                getWindow().showNotification("Action not available");
            }
        }
    });
    btnCreate.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            if (numUndefinedComponents > 0) {
                getWindow().showNotification("There can be no undefined components",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }
            if (numMissingCodeLists > 0) {
                getWindow().showNotification("All code lists must first be created or imported",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }
            final String dsd = dsdUri.getValue().toString();
            if (!isUri(dsd)) {
                getWindow().showNotification("Enter a valid URI for the DSD",
                        Window.Notification.TYPE_ERROR_MESSAGE);
            }

            try {
                RepositoryConnection conn = repository.getConnection();
                LinkedList<String> dList = new LinkedList<String>();
                LinkedList<String> mList = new LinkedList<String>();
                LinkedList<String> aList = new LinkedList<String>();
                LinkedList<String> uList = new LinkedList<String>();
                LinkedList<String> propList = new LinkedList<String>();
                LinkedList<String> rangeList = new LinkedList<String>();

                for (Object id : dataTree.rootItemIds()) {
                    Collection<?> children = dataTree.getChildren(id);
                    if (children == null)
                        continue;

                    Collection<String> list = null;
                    if (id.toString().startsWith("D"))
                        list = dList;
                    else if (id.toString().startsWith("M"))
                        list = mList;
                    else if (id.toString().startsWith("A"))
                        list = aList;
                    else if (id.toString().startsWith("U"))
                        list = uList;

                    for (Object prop : dataTree.getChildren(id)) {
                        CountingTreeHeader h = (CountingTreeHeader) dataTree.getChildren(prop).iterator()
                                .next();
                        propList.add(prop.toString());
                        list.add(prop.toString());
                        if (h.toString().startsWith("C")) {
                            rangeList.add("http://www.w3.org/2004/02/skos/core#Concept");
                        } else {
                            rangeList.add(dataTree.getChildren(h).iterator().next().toString());
                        }
                    }
                }
                if (uList.size() > 0) {
                    getWindow().showNotification("There are undefined properties!",
                            Window.Notification.TYPE_WARNING_MESSAGE);
                    return;
                }
                GraphQuery query = conn.prepareGraphQuery(QueryLanguage.SPARQL, DSDRepoUtils.qCreateDSD(dataset,
                        dsd, dList, mList, aList, propList, rangeList, dataGraph));
                query.evaluate();
                getWindow().showNotification("DSD created!");
                InspectComponent.this.ds = new SparqlDataSet(repository, InspectComponent.this.ds.getUri(),
                        dataGraph);
                createDSD();
            } catch (RepositoryException ex) {
                logger.log(Level.SEVERE, null, ex);
            } catch (MalformedQueryException ex) {
                logger.log(Level.SEVERE, null, ex);
            } catch (QueryEvaluationException ex) {
                logger.log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:rs.pupin.jpo.validation.gui.ValidationComponent.java

private void createUI() {
    rootLayout.removeAllComponents();/* w  w w .  j  a  v a 2  s .c  o  m*/
    icHash.clear();
    createHeader();

    splitPanel = new HorizontalSplitPanel();
    splitPanel.setSizeFull();
    rootLayout.addComponent(splitPanel);
    rootLayout.setExpandRatio(splitPanel, 2.0f);

    criteriaTree = new Tree("Validation criteria");
    criteriaTree.setNullSelectionAllowed(false);
    criteriaTree.setImmediate(true);
    criteriaTree.setWidth("100%");
    splitPanel.setFirstComponent(criteriaTree);
    createConstraints();
    splitPanel.setSplitPosition(400, Unit.PIXELS);
    contentLayout = new VerticalLayout();
    contentLayout.setSizeUndefined();
    contentLayout.setWidth("100%");
    contentLayout.setSpacing(true);
    contentLayout.addStyleName("content");
    splitPanel.setSecondComponent(contentLayout);
    createListeners();
}

From source file:rs.pupin.jpo.validation.gui.ValidationComponent.java

private void refresh() {
    splitPanel.removeComponent(criteriaTree);
    contentLayout.removeAllComponents();
    for (ICQuery ic : icHash.keySet())
        ic.removeQueryListener(this);
    icHash.clear();/* w  ww .j a  va  2 s. co  m*/
    criteriaTree = new Tree("Validation criteria");
    criteriaTree.setNullSelectionAllowed(false);
    criteriaTree.setImmediate(true);
    criteriaTree.setWidth("100%");
    splitPanel.setFirstComponent(criteriaTree);
    createConstraints();
}

From source file:v7cr.ReviewTab.java

License:Open Source License

private Panel getSVNPanel(V7CR v7, SchemaDefinition sd, SVNLogEntry svn, Project proj) {
    if (svn == null)
        return null;
    Locale l = v7.getLocale();/*from w  w w  .j  a  va2s .com*/
    Panel p = new Panel(v7.getMessage("reviewTab.subversion"));
    p.setWidth("600px");
    GridLayout grid = new GridLayout(4, 4);
    grid.setSizeFull();
    p.setContent(grid);
    grid.setSpacing(true);
    p.addComponent(new Label(sd.getFieldCaption("svn.rev", l)));
    p.addComponent(new Label("" + svn.getRevision()));
    p.addComponent(new Label(DateFormat.getDateTimeInstance().format(svn.getDate())));
    p.addComponent(new Label(svn.getAuthor()));
    Link link = new Link(v7.getMessage("reviewTab.viewChanges"),
            new ExternalResource(proj.getChangesetViewUrl(svn.getRevision())));
    link.setTargetName("_blank");
    link.setIcon(new ThemeResource("../runo/icons/16/arrow-right.png"));
    p.addComponent(link);
    grid.addComponent(new Label(svn.getMessage()), 1, 1, 3, 1);

    Map<String, SVNLogEntryPath> changed = svn.getChangedPaths();

    if (changed != null) {
        Tree changeTree = new Tree(sd.getFieldCaption("svn.changed", l) + "(" + changed.size() + ")");
        Set<String> paths = changed.keySet();
        for (String s : changed.keySet()) {
            changeTree.addItem(s);
            changeTree.setChildrenAllowed(s, false);
            changeTree.setItemCaption(s, changed.get(s).getType() + " " + s);
        }
        if (paths.size() > 5) {
            compressTree(changeTree, paths);
        }

        grid.addComponent(changeTree, 0, 2, 3, 2);
    }
    return p;
}