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:be.rvponp.build.CommitViewerUI.java

License:Apache License

private Tree createTreeComponent() {
    Tree tree = new Tree("Projects and components");
    tree.setMultiSelect(true);//from  w  ww. jav  a2 s . c o m
    List<JiraProject> projects = new ArrayList<JiraProject>();
    projects.add(new JiraProject("PRODUCTION"));
    projects.add(new JiraProject("VAAD"));
    projects.add(new JiraProject("ID"));
    projects.add(new JiraProject("PAYTWO"));
    try {
        SOAPSession jiraWebService = Jira.getJiraWebService();

        for (JiraProject project : projects) {
            tree.addItem(project);
            RemoteComponent[] components = jiraWebService.getJiraSoapService()
                    .getComponents(jiraWebService.getAuthenticationToken(), project.getName());
            if (components.length == 0) {
                tree.setChildrenAllowed(project, false);
            } else {
                for (RemoteComponent component : components) {
                    JiraComponent jiraComponent = new JiraComponent(project, component.getName());
                    project.addComponent(jiraComponent);
                    tree.addItem(jiraComponent);
                    tree.setParent(jiraComponent, project);
                    tree.setChildrenAllowed(jiraComponent, false);
                }
            }
        }
    } catch (RemoteException e) {
        log.error("Error when retrieving the components", e);
        tree.removeAllItems();
        for (JiraProject project : projects) {
            tree.addItem(project);
            tree.setChildrenAllowed(project, false);
        }
    }
    return tree;
}

From source file:com.cms.component.TreeCommon.java

public void setDataSource(String treeName, Object rootTree, List<?> lstTree, List<String> lstDefaul,
        boolean viewRoot, String name, String code, String parent) {
    if (!DataUtil.isStringNullOrEmpty(treeName)) {
        tree = new Tree(treeName);
    } else {//  w ww  .j  a v  a2  s .  co  m
        tree = new Tree();
    }

    layout.removeAllComponents();
    tree.addStyleName("checkboxed");
    //        tree.setImmediate(true);
    // Only allow clicks
    tree.setSelectable(false);
    layout.addComponent(tree);
    tree.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
    tree.setItemCaptionPropertyId("caption");
    checkedParent = new HashSet<>();
    checked = new HashSet<>();
    lstDefaulNote = new HashMap<>();
    lstTreeInput = lstTree;
    createTreeContentDemo = new HierarchicalContainer();

    this.viewRoot = viewRoot;
    convertListDefaultToHasmap(lstDefaul);
    TreeNote treenote = new TreeNote();
    treeModel = new BuildTreeModel(name, code, parent);
    try {
        treeModel.setRootForTree(rootTree);
        treenote = treeModel.setContainerDataSource(lstTree);
    } catch (NoSuchMethodException ex) {
        System.out.println(" set container has errors");
    }

    setValueTree(treenote);
    markParentDefault();
    for (Object item : tree.getItemIds()) {
        tree.expandItem(item);
    }
}

From source file:com.invient.vaadin.InvientChartsDemoWin.java

License:Apache License

private Tree createChartsTree() {
    final Tree tree = new Tree("Chart Type");
    tree.setContainerDataSource(getContainer());
    tree.setImmediate(true);/*from   w w w  .ja  v  a2  s.  com*/
    tree.setItemCaptionPropertyId(TREE_ITEM_CAPTION_PROP_ID);
    tree.setItemCaptionMode(Tree.ITEM_CAPTION_MODE_PROPERTY);
    tree.setNullSelectionAllowed(false);

    for (Object id : tree.rootItemIds()) {
        tree.expandItemsRecursively(id);
    }

    tree.addListener(new Tree.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            try {
                Object selectedId = event.getProperty().getValue();
                if (tree.getParent(selectedId) != null) {
                    Object parentId = tree.getParent(selectedId);
                    String demoSeriesTypeName = (String) tree
                            .getContainerProperty(parentId, TREE_ITEM_CAPTION_PROP_ID).getValue();
                    String seriesInstanceName = (String) tree
                            .getContainerProperty(selectedId, TREE_ITEM_CAPTION_PROP_ID).getValue();

                    System.out.println("parent : " + demoSeriesTypeName + ", selected : " + seriesInstanceName);
                    showChart(demoSeriesTypeName, seriesInstanceName);
                } else {
                    String demoSeriesTypeName = (String) tree
                            .getContainerProperty(selectedId, TREE_ITEM_CAPTION_PROP_ID).getValue();
                    System.out.println("Selected " + demoSeriesTypeName);
                    showChartInstancesForSeriesType(demoSeriesTypeName);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    return tree;
}

From source file:com.mycompany.filmupo.Graficos.java

/**
 * Metodo de inicializacion de la clase//  www  . j  av  a  2 s . c  om
 *
 * @param vaadinRequest VaadinRequest
 */
@Override
protected void init(VaadinRequest vaadinRequest) {
    try {

        HorizontalLayout v2h2 = new HorizontalLayout();
        v2h2.setMargin(true);

        final VerticalLayout v2h1 = new VerticalLayout();
        v2h1.setMargin(true);

        final VerticalSplitPanel v2 = new VerticalSplitPanel();
        v2.addComponent(v2h2);
        v2.addComponent(v2h1);
        v2.setSplitPosition(22, Unit.PERCENTAGE);
        v2.setLocked(true);

        VerticalLayout v1 = new VerticalLayout();
        v1.setMargin(true);

        HorizontalSplitPanel layout = new HorizontalSplitPanel();
        layout.addComponent(v1);
        layout.addComponent(v2);
        layout.setSplitPosition(28, Unit.PERCENTAGE);

        setContent(layout);

        //Creamos los 3 links de navegacion de la aplicacion y loa aadimos al layout declarado al principio del codigo
        Link pri = new Link("Principal", new ExternalResource("/Principal"));
        Link est = new Link("Graficos", new ExternalResource("/Graficos"));
        Link adm = new Link("Administracin", new ExternalResource("/Admin"));
        v2h2.addComponent(pri);
        v2h2.addComponent(new Label(" / "));
        v2h2.addComponent(est);
        v2h2.addComponent(new Label(" / "));
        v2h2.addComponent(adm);

        final DAO dao = new DAO();
        dao.abrirConexion();

        final List<Pelicula> listaPeliculas = dao.consultarPeliculas();
        final List<Director> listaDirectores = dao.consultarDirectores();
        final List<Actor> listaActores = dao.consultarActores();

        //Creamos un unico arbol que contiene el acceso a las 4 graficas que hemos creado:
        //  - Peliculas segun su duracion
        //  - Peliculas segun su genero
        //  - Numero de peliculas segun actor
        //  - Numero de peliculas segun director
        Tree tree = new Tree("");
        String a = "Estadisticas";
        tree.addItem(a);
        String aa = "Peliculas segn su duracin";
        tree.addItem(aa);
        tree.setParent(aa, a);
        tree.setChildrenAllowed(aa, false);
        String ab = "Peliculas segn su gnero";
        tree.addItem(ab);
        tree.setParent(ab, a);
        tree.setChildrenAllowed(ab, false);
        String ac = "Numero de peliculas segn actor";
        tree.addItem(ac);
        tree.setParent(ac, a);
        tree.setChildrenAllowed(ac, false);
        String ad = "Numero de peliculas segn director";
        tree.addItem(ad);
        tree.setParent(ad, a);
        tree.setChildrenAllowed(ad, false);

        tree.setSelectable(true);
        tree.addValueChangeListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                v2h1.removeAllComponents();
                //Grafica de las peliculas segun su duracion
                if (event.getProperty().getValue().toString().contains("duracin")) {
                    Chart chart = new Chart(ChartType.PIE);
                    Configuration conf = chart.getConfiguration();
                    conf.setTitle("Peliculas");
                    conf.setSubTitle("Segn su duracin en minutos");

                    PlotOptionsPie options = new PlotOptionsPie();
                    options.setInnerSize(0);
                    options.setSize("75%");
                    options.setCenter("50%", "50%");
                    conf.setPlotOptions(options);

                    DataSeries series = new DataSeries();
                    for (Pelicula p : listaPeliculas) {
                        series.add(new DataSeriesItem(p.getTitulo(), p.getDuracion()));
                    }
                    conf.addSeries(series);
                    v2h1.addComponent(chart);
                    //Grafica de las peliculas segun su genero
                } else if (event.getProperty().getValue().toString().contains("gnero")) {
                    Chart chart = new Chart(ChartType.COLUMN);
                    chart.setWidth("400px");
                    chart.setHeight("300px");
                    Configuration conf = chart.getConfiguration();
                    conf.setTitle("Peliculas");
                    conf.setSubTitle("Agrupadas segn su gnero");

                    PlotOptionsLine plotOptions = new PlotOptionsLine();
                    plotOptions.setMarker(new Marker(false));
                    conf.setPlotOptions(plotOptions);

                    ListSeries series = new ListSeries("Numero de peliculas");
                    int i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0;
                    try {
                        dao.abrirConexion();
                        i1 = dao.numGeneros("Accin");
                        i2 = dao.numGeneros("Ciencia Ficcin");
                        i3 = dao.numGeneros("Drama");
                        i4 = dao.numGeneros("Romance");
                        i5 = dao.numGeneros("Novela de Suspense");
                    } catch (IllegalAccessException ex) {
                        Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (SQLException ex) {
                        Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (InstantiationException ex) {
                        Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    series.addData(i1);
                    series.addData(i2);
                    series.addData(i3);
                    series.addData(i4);
                    series.addData(i5);

                    conf.addSeries(series);

                    XAxis xaxis = new XAxis();
                    xaxis.setTitle("Gnero");
                    xaxis.setCategories("Accin", "Ciencia Ficcin", "Drama", "Romance",
                            "Novela de suspense");
                    conf.addxAxis(xaxis);

                    YAxis yayis = new YAxis();
                    yayis.setTitle("Nmero de peliculas");
                    conf.addyAxis(yayis);

                    v2h1.addComponent(chart);

                    //Grafica de las peliculas segun actor
                } else if (event.getProperty().getValue().toString().contains("actor")) {
                    Chart chart = new Chart(ChartType.PIE);
                    Configuration conf = chart.getConfiguration();
                    conf.setTitle("Actores");
                    conf.setSubTitle("Nmero de peliculas que tienen");

                    PlotOptionsPie options = new PlotOptionsPie();
                    options.setInnerSize(0);
                    options.setSize("75%");
                    options.setCenter("50%", "50%");
                    conf.setPlotOptions(options);

                    DataSeries series = new DataSeries();
                    for (Actor a : listaActores) {
                        int i = 0;
                        try {
                            dao.abrirConexion();
                            i = dao.numPeliculasA(a.getIdActor());
                        } catch (InstantiationException ex) {
                            Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IllegalAccessException ex) {
                            Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (SQLException ex) {
                            Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        series.add(new DataSeriesItem(a.getNombreCompleto(), i));
                    }
                    conf.addSeries(series);

                    v2h1.addComponent(chart);

                    //Grafica del numero de peliculas segun director
                } else if (event.getProperty().getValue().toString().contains("director")) {
                    Chart chart = new Chart(ChartType.PIE);
                    Configuration conf = chart.getConfiguration();
                    conf.setTitle("Directores");
                    conf.setSubTitle("Nmero de peliculas que tienen");

                    PlotOptionsPie options = new PlotOptionsPie();
                    options.setInnerSize(0);
                    options.setSize("75%");
                    options.setCenter("50%", "50%");
                    conf.setPlotOptions(options);

                    DataSeries series = new DataSeries();
                    for (Director d : listaDirectores) {
                        int i = 0;
                        try {
                            dao.abrirConexion();
                            i = dao.numPeliculasD(d.getIdDirector());
                        } catch (InstantiationException ex) {
                            Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IllegalAccessException ex) {
                            Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (SQLException ex) {
                            Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
                        }
                        series.add(new DataSeriesItem(d.getNombreCompleto(), i));
                    }
                    conf.addSeries(series);

                    v2h1.addComponent(chart);
                }
            }
        });

        v1.addComponent(tree);

        dao.cerrarConexion();
    } catch (SQLException ex) {
        Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Graficos.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:de.catma.ui.repository.wizard.FileTypePanel.java

License:Open Source License

private void initComponents() {
    setSpacing(true);//from w  ww .ja v a 2s. c  om
    setSizeFull();
    setMargin(true, false, false, false);

    cbFileType = new ComboBox("File type");
    for (FileType ft : FileType.values()) {
        cbFileType.addItem(ft);
    }
    cbFileType.setNullSelectionAllowed(false);
    cbFileType.setImmediate(true);

    addComponent(cbFileType, 0, 0);

    fileEncodingTree = new Tree("File encoding");
    fileEncodingTree.setImmediate(true);

    Map<String, Map<String, List<Charset>>> regionLanguageCharsetMapping = CharsetLanguageInfo.SINGLETON
            .getRegionLanguageCharsetMapping();

    for (String region : regionLanguageCharsetMapping.keySet()) {
        fileEncodingTree.addItem(region);
        Map<String, List<Charset>> languages = regionLanguageCharsetMapping.get(region);
        for (String language : languages.keySet()) {
            fileEncodingTree.addItem(language);
            fileEncodingTree.setParent(language, region);
            for (Charset charset : languages.get(language)) {
                fileEncodingTree.addItem(charset);
                fileEncodingTree.setParent(charset, language);
                fileEncodingTree.setChildrenAllowed(charset, false);
            }
        }
    }

    Map<String, List<Charset>> categoryCharsetMapping = CharsetLanguageInfo.SINGLETON
            .getCategoryCharsetMapping();

    for (String category : categoryCharsetMapping.keySet()) {
        fileEncodingTree.addItem(category);
        for (Charset charset : categoryCharsetMapping.get(category)) {
            fileEncodingTree.addItem(charset);
            fileEncodingTree.setParent(charset, category);
            fileEncodingTree.setChildrenAllowed(charset, false);
        }
    }

    previewPanel = new Panel("Preview");
    previewPanel.getContent().setSizeUndefined();
    previewPanel.setHeight("300px");

    this.taPreview = new Label();
    this.taPreview.setContentMode(Label.CONTENT_XHTML);
    previewPanel.addComponent(taPreview);

    addComponent(fileEncodingTree, 0, 1);
    addComponent(previewPanel, 1, 1);

    this.uploadLabel = new Label("Upload the corresponding XSLT file:");
    this.uploadPanel = new UploadPanel();
    addComponent(uploadLabel, 0, 2, 1, 2);
    addComponent(uploadPanel, 0, 3, 1, 3);

    progressIndicator = new ProgressIndicator();
    progressIndicator.setEnabled(false);
    progressIndicator.setIndeterminate(true);
    progressIndicator.setWidth("100%");
    progressIndicator.setPollingInterval(500);

    addComponent(progressIndicator, 1, 0);
    setColumnExpandRatio(1, 1);

}

From source file:edu.kit.dama.ui.admin.workflow.DataWorkflowTaskConfigurationTab.java

License:Apache License

public final Tree getElementTree() {
    if (elementTree == null) {
        String id = "elementList";
        LOGGER.debug("Building " + DEBUG_ID_PREFIX + id + " ...");

        elementTree = new Tree("AVAILABLE ELEMENTS");
        elementTree.setId(DEBUG_ID_PREFIX + id);
        HierarchicalContainer container = new HierarchicalContainer();
        container.addContainerProperty("caption", String.class, null);
        elementTree.setContainerDataSource(container);
        elementTree.setItemCaptionPropertyId("caption");
        elementTree.setHeight("100%");
        elementTree.setWidth("300px");
        elementTree.setNullSelectionAllowed(false);
        elementTree.setImmediate(true);/*  ww  w  .  ja va2s  . c  o m*/
        elementTree.addStyleName(CSSTokenContainer.BOLD_CAPTION);

        elementTree.addValueChangeListener(new Property.ValueChangeListener() {

            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                Object value = event.getProperty().getValue();
                String selection;
                if (value instanceof Long) {
                    selection = Long.toString((Long) value);
                } else {
                    selection = (String) value;
                }

                ListSelection listSelection = validateListSelection(selection);

                switch (listSelection) {
                case NO:
                    fireNoListEntrySelected();
                    break;
                case NEW:
                    fireNewInstanceSelected();
                    break;
                case VALID:
                    fireValidListEntrySelected();
                    break;
                case INVALID:
                    fireInvalidListEntrySelected();
                    break;
                default:
                    UIComponentTools.showError("ERROR", "Unknown error occurred while updating "
                            + "element selection. " + NoteBuilder.CONTACT, -1);
                    LOGGER.error("Failed to update " + this.getClass().getSimpleName()
                            + ". Cause: Undefined enum constant detected, namely '" + listSelection.name()
                            + "'.");
                    break;
                }
            }

        });
    }
    return elementTree;
}

From source file:eu.lod2.stat.dsdrepo.DSDRepoComponent.java

private void refreshContentFindDSDs(DataSet ds) {
    if (ds == null) {
        getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE);
        return;/*  w  w w  . ja  v  a 2 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.setWidth("500px");
    dataTree.setNullSelectionAllowed(true);
    dataTree.setImmediate(true);
    populateDataTree();
    addDataTreeListenersFind();
    contentLayout.addComponent(dataTree);
    contentLayout.setExpandRatio(dataTree, 0.0f);
    repoTree = new Tree("Matching Structures");
    repoTree.setNullSelectionAllowed(true);
    repoTree.setImmediate(true);
    repoTreeItems = new LinkedList<Structure>();
    populateRepoTree();
    VerticalLayout v = new VerticalLayout();
    contentLayout.addComponent(v);
    contentLayout.setExpandRatio(v, 2.0f);
    v.addComponent(repoTree);
    v.setExpandRatio(repoTree, 2.0f);
}

From source file:eu.lod2.stat.dsdrepo.DSDRepoComponent.java

private void refreshContentStoreDSD(DataSet ds) {
    if (ds == null) {
        getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE);
        return;/*ww w  . ja v  a 2s  . c  o  m*/
    }
    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);
    repoTree = new Tree("Matching Structures");
    repoTree.setNullSelectionAllowed(true);
    repoTree.setImmediate(true);
    repoTreeItems = new LinkedList<Structure>();
}

From source file:eu.lod2.stat.dsdrepo.DSDRepoComponent.java

private void refreshContentCreateDSD(DataSet ds) {
    if (ds == null) {
        getWindow().showNotification("No dataset selected", Window.Notification.TYPE_ERROR_MESSAGE);
        return;/*from   w  w  w .java2  s .  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);
                    getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                } catch (MalformedQueryException ex) {
                    Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
                    getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                } catch (QueryEvaluationException ex) {
                    Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
                    getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
                }
            }
        }
    });
    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);
                getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
            } catch (MalformedQueryException ex) {
                Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
                getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
            } catch (QueryEvaluationException ex) {
                Logger.getLogger(DSDRepoComponent.class.getName()).log(Level.SEVERE, null, ex);
                getWindow().showNotification(ex.getMessage(), Window.Notification.TYPE_ERROR_MESSAGE);
            }
        }
    });
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.admin.AdminScreenProvider.java

License:Apache License

private Component getEmailSettingTab() {
    VerticalLayout s2 = new VerticalLayout();
    HorizontalSplitPanel split2 = new HorizontalSplitPanel();
    s2.addComponent(split2);//from   w  w  w.j  ava2s .  co  m
    Tree sTree2 = new Tree(TRANSLATOR.translate("general.email.settings"));
    sTree2.addValueChangeListener((Property.ValueChangeEvent event) -> {
        if (sTree2.getValue() instanceof VmSetting) {
            VmSetting vmSetting = (VmSetting) sTree2.getValue();
            split2.setSecondComponent(displaySetting(vmSetting, !vmSetting.getSetting().equals("mail.enable")));
        }
    });
    split2.setFirstComponent(sTree2);
    VMSettingServer.getSettings().forEach(s -> {
        if (s.getSetting().startsWith("mail")) {
            sTree2.addItem(s);
            sTree2.setChildrenAllowed(s, false);
            sTree2.setItemCaption(s, TRANSLATOR.translate(s.getSetting()));
        }
    });
    Button testEmail = new Button(TRANSLATOR.translate("general.email.settings.test"), listener -> {
        //Show a window to test email settings
        VMWindow w = new VMWindow(TRANSLATOR.translate("general.email.settings.test"));
        VerticalLayout vl = new VerticalLayout();
        TextField to = new TextField(TRANSLATOR.translate("general.email.to"));
        TextField from = new TextField(TRANSLATOR.translate("general.email.from"));
        TextField subject = new TextField(TRANSLATOR.translate("general.email.subject"));
        TextArea mess = new TextArea(TRANSLATOR.translate("general.email.message"));
        mess.setSizeFull();
        TextArea output = new TextArea(TRANSLATOR.translate("general.output"));
        output.setReadOnly(true);
        output.setSizeFull();
        Button send = new Button(TRANSLATOR.translate("general.email.send"), l -> {
            try {
                Lookup.getDefault().lookup(IEmailManager.class).sendEmail(to.getValue(), null, from.getValue(),
                        subject.getValue(), mess.getValue());
                output.setValue(TRANSLATOR.translate("general.email.settings.test.success"));
                //Successful, update the enable setting.
                VMSettingServer enable = new VMSettingServer("mail.enable");
                enable.setBoolVal(true);
                enable.write2DB();
            } catch (Exception ex) {
                LOG.log(Level.SEVERE, null, ex);
                StringWriter sw = new StringWriter();
                ex.printStackTrace(new PrintWriter(sw));
                output.setReadOnly(false);
                output.setValue(sw.toString());
                output.setReadOnly(true);
            }
        });
        vl.addComponent(to);
        vl.addComponent(from);
        vl.addComponent(subject);
        vl.addComponent(mess);
        vl.addComponent(send);
        vl.addComponent(output);
        w.setContent(vl);
        w.setHeight(75, Sizeable.Unit.PERCENTAGE);
        w.setWidth(75, Sizeable.Unit.PERCENTAGE);
        ValidationManagerUI.getInstance().addWindow(w);
    });
    s2.addComponent(testEmail);
    return s2;
}