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() 

Source Link

Document

Constructs a new Tree Component.

Usage

From source file:org.lucidj.renderer.treemenu.TreeMenuRenderer.java

License:Apache License

public TreeMenuRenderer() {
    tree_menu = new Tree();
    tree_menu.addStyleName("ui-treemenu");

    tree_menu.addContainerProperty(CP_ENTRY, MenuEntry.class, null);
    tree_menu.addContainerProperty(CP_CAPTION, String.class, null);
    tree_menu.addContainerProperty(CP_ICON, Resource.class, null);
    tree_menu.addContainerProperty(CP_NAVID, String.class, null);

    tree_menu.setItemCaptionPropertyId(CP_CAPTION);
    tree_menu.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    tree_menu.setItemIconPropertyId(CP_ICON);

    tree_menu.addItemClickListener(this);
    tree_menu.setImmediate(true);/*from   w  w  w  .j  av a  2s  .c  om*/
    tree_menu.setSelectable(false);

    tree_menu.addAttachListener(new ClientConnector.AttachListener() {
        @Override
        public void attach(ClientConnector.AttachEvent attachEvent) {
            if (update_on_attach) {
                render_tree_menu();
                update_on_attach = false;
            }
        }
    });

    tree_menu.addDetachListener(new ClientConnector.DetachListener() {
        @Override
        public void detach(ClientConnector.DetachEvent detachEvent) {
            // Nothing for now
        }
    });
}

From source file:org.lunifera.examples.vaaclipse.demo1.e4.views.VirtualFilesystemView.java

License:Open Source License

private void createProjectTree() {
    demoRoot = Demo1Activator.getInstance().getSrcStore();

    tree = new Tree();
    tree.setSizeFull();// ww w.  j  a v a 2  s . com
    tree.setImmediate(true);
    panel.setContent(tree);

    FilesystemContainer fsc = new FilesystemContainer(demoRoot, true);
    FileTypeResolver.addExtension("java", "java");
    FileTypeResolver.addIcon("java",
            BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/java.png"));
    FileTypeResolver.addExtension("xml", "xml");
    FileTypeResolver.addIcon("xml",
            BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/xml.png"));
    FileTypeResolver.addExtension("e4xmi", "e4xmi");
    FileTypeResolver.addIcon("e4xmi",
            BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/xmi.png"));
    FileTypeResolver.addExtension("css", "css");
    FileTypeResolver.addIcon("css",
            BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/css.png"));
    FileTypeResolver.addExtension("html", "html");
    FileTypeResolver.addIcon("html",
            BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/html.png"));

    FileTypeResolver.addIcon("image/png",
            BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/img.png"));

    FileTypeResolver.addIcon("inode/directory",
            BundleResource.valueOf("platform:/plugin/org.lunifera.examples.vaaclipse.demo1.e4/img/folder.png"));

    tree.setContainerDataSource(fsc);

    tree.addListener(new ItemClickEvent.ItemClickListener() {

        long lastTime = 0;
        File lastFile;

        public void itemClick(final ItemClickEvent event) {
            if (event.getButton() == ItemClickEvent.BUTTON_LEFT) {
                long time = System.currentTimeMillis();
                if (lastTime > 0 && time - lastTime < 300) {
                    tree.select(event.getItemId());

                    FileItem fileItem = (FileItem) event.getItem();
                    try {
                        for (Field f : FilesystemContainer.FileItem.class.getDeclaredFields()) {
                            if (f.getName().equals("file")) {
                                f.setAccessible(true);
                                final File file = (File) f.get(fileItem);
                                if (!file.equals(lastFile)) {
                                    eventBroker.send(Demo1Constants.OPEN_FILE, file);
                                    lastFile = file;
                                }
                                break;
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                lastTime = time;
            }
        }
    });

    // Set tree to show the 'name' property as caption for items
    tree.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);
    tree.setItemIconPropertyId(FilesystemContainer.PROPERTY_ICON);

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

    String projectName = "org.lunifera.examples.vaaclipse.demo1.e4";
    File data = FileUtils.getFile(demoRoot, projectName, "data");
    if (data != null)
        tree.expandItem(data);

    File rootPackage = FileUtils.getFile(demoRoot, projectName, "src");
    if (rootPackage != null)
        tree.expandItemsRecursively(rootPackage);
}

From source file:org.lunifera.runtime.web.ecview.presentation.vaadin.internal.TreePresentation.java

License:Open Source License

/**
 * {@inheritDoc}/*from w  ww.  j a v  a  2 s. c  o m*/
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Component doCreateWidget(Object parent) {
    if (componentBase == null) {
        componentBase = new CssLayout();
        componentBase.addStyleName(CSS_CLASS_CONTROL_BASE);
        if (modelAccess.isCssIdValid()) {
            componentBase.setId(modelAccess.getCssID());
        } else {
            componentBase.setId(getEditpart().getId());
        }

        associateWidget(componentBase, modelAccess.yTree);

        tree = new Tree();
        tree.addStyleName(CSS_CLASS_CONTROL);
        tree.setMultiSelect(modelAccess.yTree.getSelectionType() == YSelectionType.MULTI);
        tree.setImmediate(true);

        associateWidget(tree, modelAccess.yTree);

        if (tree.isMultiSelect()) {
            property = new ObjectProperty(new HashSet(), Set.class);
        } else {
            property = new ObjectProperty(null, modelAccess.yTree.getType());
        }
        tree.setPropertyDataSource(property);

        // creates the binding for the field
        createBindings(modelAccess.yTree, tree);

        componentBase.addComponent(tree);

        if (modelAccess.isCssClassValid()) {
            tree.addStyleName(modelAccess.getCssClass());
        }

        applyCaptions();

        initializeField(tree);
    }
    return componentBase;
}

From source file:org.lunifera.vaaclipse.ui.preferences.addon.internal.PreferencesDialog.java

License:Open Source License

private void createTree() {
    tree = new Tree();
    tree.setSizeFull();//from  w  w w . jav a 2s  .c om
    tree.setImmediate(true);
    treePanel.setContent(tree);

    tree.addContainerProperty("name", String.class, "NoName");
    tree.setItemCaptionPropertyId("name");

    ModelHelper.buildChildCategoryListIncludeThisList(app.getPreferencesCategories(), categoryList);

    refreshTree();

    tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        public void itemClick(final ItemClickEvent event) {
            if (event.getButton() == MouseButton.LEFT) {
                PreferencesCategory selectedCat = (PreferencesCategory) event.getItemId();
                if (selectedCat != null) {
                    openPreferencePageForCategory(selectedCat);
                }
            }
        }
    });

    if (selectedCategory != null) {
        tree.select(selectedCategory);
        openPreferencePageForCategory(selectedCategory);
    }
}

From source file:org.opencms.ui.apps.CmsFileExplorer.java

License:Open Source License

/**
 * Constructor.<p>//from   ww w . j av  a2 s .  co  m
 */
public CmsFileExplorer() {
    m_shortcutActions = new HashMap<Action, Runnable>();
    m_shortcutActions.put(ACTION_DELETE, new Runnable() {

        public void run() {

            if (!m_fileTable.getSelectedIds().isEmpty()) {
                I_CmsDialogContext context1 = getDialogContext();
                context1.start("Delete", new CmsDeleteDialog(context1));
            }
        }
    });

    m_shortcutActions.put(ACTION_FOLDER_UP, new Runnable() {

        public void run() {

            showParentFolder();
        }
    });

    m_shortcutActions.put(ACTION_PROPERTIES, new Runnable() {

        public void run() {

            I_CmsWorkplaceAction propAction = new CmsPropertiesDialogAction();
            I_CmsDialogContext context = getDialogContext();
            if (propAction.getVisibility(context).isActive()) {
                propAction.executeAction(context);
            }
        }
    });

    m_shortcutActions.put(ACTION_RENAME, new Runnable() {

        public void run() {

            CmsExplorerDialogContext context = getDialogContext();
            if (context.isPropertyEditable(CmsResourceTableProperty.PROPERTY_RESOURCE_NAME)) {
                context.editProperty(CmsResourceTableProperty.PROPERTY_RESOURCE_NAME);
            }
        }
    });

    m_shortcutActions.put(ACTION_SELECT_ALL, new Runnable() {

        public void run() {

            m_fileTable.selectAll();
        }
    });

    m_shortcutActions.put(ACTION_SWITCH_ONLINE, new Runnable() {

        public void run() {

            toggleOnlineOffline();
        }
    });

    m_fileTable = new CmsFileTable(this);
    m_fileTable.setSizeFull();
    m_fileTable.setMenuBuilder(new CmsResourceContextMenuBuilder());
    m_fileTable.setFolderSelectHandler(this);
    m_uploadArea = new CmsUploadAreaExtension(m_fileTable);
    m_uploadArea.addUploadListener(new I_UploadListener() {

        public void onUploadFinished(List<String> uploadedFiles) {

            updateAll(true);
        }
    });
    m_treeContainer = new HierarchicalContainer();
    addTreeContainerProperties(CmsResourceTableProperty.PROPERTY_RESOURCE_NAME,
            CmsResourceTableProperty.PROPERTY_STATE, CmsResourceTableProperty.PROPERTY_TREE_CAPTION,
            CmsResourceTableProperty.PROPERTY_INSIDE_PROJECT,
            CmsResourceTableProperty.PROPERTY_RELEASED_NOT_EXPIRED, CmsResourceTableProperty.PROPERTY_DISABLED);
    m_fileTree = new Tree();
    m_fileTree.addStyleName(OpenCmsTheme.SIMPLE_DRAG);
    m_fileTree.addStyleName(OpenCmsTheme.FULL_WIDTH_PADDING);
    m_fileTree.setWidth("100%");
    m_fileTree.setContainerDataSource(m_treeContainer);
    //    m_fileTree.setItemIconPropertyId(CmsResourceTableProperty.PROPERTY_TYPE_ICON_RESOURCE);
    m_fileTree.setItemCaptionPropertyId(CmsResourceTableProperty.PROPERTY_TREE_CAPTION);
    //        m_fileTree.setCaptionAsHtml(true);
    m_fileTree.setHtmlContentAllowed(true);
    m_expandListener = new TreeExpandListener();
    m_fileTree.addExpandListener(m_expandListener);
    m_fileTree.addCollapseListener(new CollapseListener() {

        private static final long serialVersionUID = 1L;

        public void nodeCollapse(CollapseEvent event) {

            selectTreeItem((CmsUUID) event.getItemId());
            clearTreeLevel((CmsUUID) event.getItemId());
        }
    });

    m_fileTree.addItemClickListener(new ItemClickListener() {

        private static final long serialVersionUID = 1L;

        public void itemClick(ItemClickEvent event) {

            handleFileTreeClick(event);
        }
    });

    m_fileTree.setItemStyleGenerator(new ItemStyleGenerator() {

        private static final long serialVersionUID = 1L;

        public String getStyle(Tree source, Object itemId) {

            return CmsFileTable.getStateStyle(source.getContainerDataSource().getItem(itemId));
        }
    });
    m_fileTree.addValueChangeListener(new ValueChangeListener() {

        private static final long serialVersionUID = 1L;

        public void valueChange(ValueChangeEvent event) {

            handleFileTreeValueChange();
        }

    });

    m_fileTree.setNullSelectionAllowed(false);

    // init drag and drop
    ExplorerDropHandler handler = new ExplorerDropHandler();
    m_fileTable.setDropHandler(handler);
    m_fileTable.setDragMode(TableDragMode.MULTIROW);
    m_fileTree.setDropHandler(handler);
    m_fileTree.setDragMode(TreeDragMode.NONE);

    m_siteSelector = createSiteSelect(A_CmsUI.getCmsObject());
    m_infoPath = new TextField();
    A_CmsFocusShortcutListener shortcutListener = new A_CmsFocusShortcutListener("Open path", KeyCode.ENTER,
            null) {

        private static final long serialVersionUID = 1L;

        @Override
        public void blur(BlurEvent event) {

            super.blur(event);
            showCrumbs(true);
        }

        @Override
        public void focus(FocusEvent event) {

            super.focus(event);
            showCrumbs(false);
        }

        @Override
        public void handleAction(Object sender, Object target) {

            openPath(m_infoPath.getValue());
        }
    };
    shortcutListener.installOn(m_infoPath);

    m_crumbs = new CssLayout();
    m_crumbs.setPrimaryStyleName(OpenCmsTheme.CRUMBS);
    m_crumbListener = new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            openPath((String) event.getButton().getData());
        }
    };

    m_searchField = new TextField();
    m_searchField.setIcon(FontOpenCms.FILTER);
    m_searchField.setInputPrompt(
            Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_FILTER_0));
    m_searchField.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    m_searchField.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        public void textChange(TextChangeEvent event) {

            filterTable(event.getText());

        }
    });

    m_locationCache = CmsQuickLaunchLocationCache.getLocationCache(CmsAppWorkplaceUi.get().getHttpSession());
    String startSite = CmsAppWorkplaceUi.get().getWorkplaceSettings().getUserSettings().getStartSite();
    // remove trailing slashes
    while (startSite.endsWith("/")) {
        startSite = startSite.substring(0, startSite.length() - 1);
    }
    if (m_locationCache.getFileExplorerLocation(startSite) == null) {
        // add the configured start folder for the start site
        String startFolder = CmsAppWorkplaceUi.get().getWorkplaceSettings().getUserSettings().getStartFolder();
        m_locationCache.setFileExplorerLocation(startSite, startFolder);
    }
}

From source file:org.opennms.features.vaadin.dashboard.config.ui.HelpClickListener.java

License:Open Source License

@Override
public void buttonClick(Button.ClickEvent clickEvent) {
    final Window window = new Window("Help");

    window.setModal(true);//from  ww w . j  a va 2s  . c  o m
    window.setClosable(false);
    window.setResizable(false);

    window.setWidth("55%");
    window.setHeight("80%");

    m_component.getUI().addWindow(window);

    window.setContent(new VerticalLayout() {
        {
            setMargin(true);
            setSpacing(true);
            setSizeFull();

            HorizontalLayout horizontalLayout = new HorizontalLayout();
            horizontalLayout.setSizeFull();
            horizontalLayout.setSpacing(true);

            Tree tree = new Tree();
            tree.setNullSelectionAllowed(false);
            tree.setMultiSelect(false);
            tree.setImmediate(true);

            tree.addItem("Overview");
            tree.setChildrenAllowed("Overview", false);

            tree.addItem("Installed Dashlets");
            tree.setChildrenAllowed("Installed Dashlets", true);

            final List<DashletFactory> factories = m_dashletSelector.getDashletFactoryList();

            for (DashletFactory dashletFactory : factories) {
                tree.addItem(dashletFactory.getName());
                tree.setParent(dashletFactory.getName(), "Installed Dashlets");
                tree.setChildrenAllowed(dashletFactory.getName(), false);
            }
            horizontalLayout.addComponent(tree);

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

            final Panel panel = new Panel();
            panel.setSizeFull();

            horizontalLayout.addComponent(panel);
            horizontalLayout.setExpandRatio(panel, 1.0f);

            addComponent(horizontalLayout);
            setExpandRatio(horizontalLayout, 1.0f);

            tree.addValueChangeListener(new Property.ValueChangeListener() {
                @Override
                public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                    String itemId = String.valueOf(valueChangeEvent.getProperty().getValue());

                    if ("Installed Dashlets".equals(itemId)) {
                        return;
                    }

                    if ("Overview".equals(itemId)) {
                        VerticalLayout verticalLayout = new VerticalLayout();
                        verticalLayout.setSpacing(true);
                        verticalLayout.setMargin(true);

                        verticalLayout.addComponent(new Label(getOverviewHelpHTML(), ContentMode.HTML));

                        panel.setContent(verticalLayout);
                    } else {
                        DashletFactory dashletFactory = m_dashletSelector.getDashletFactoryForName(itemId);

                        if (dashletFactory != null) {
                            if (dashletFactory.providesHelpComponent()) {
                                VerticalLayout verticalLayout = new VerticalLayout();
                                verticalLayout.setSpacing(true);
                                verticalLayout.setMargin(true);

                                Label helpTitle = new Label(
                                        "Help for Dashlet '" + dashletFactory.getName() + "'");
                                helpTitle.addStyleName("help-title");

                                verticalLayout.addComponent(helpTitle);
                                verticalLayout.addComponent(dashletFactory.getHelpComponent());

                                panel.setContent(verticalLayout);
                            }
                        }
                    }
                }
            });

            tree.select("Overview");

            addComponent(new HorizontalLayout() {
                {
                    setMargin(true);
                    setSpacing(true);
                    setWidth("100%");

                    Button closeButton = new Button("Close");

                    addComponent(closeButton);
                    setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT);
                    closeButton.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(Button.ClickEvent clickEvent) {
                            window.close();
                        }
                    });
                }
            });
        }
    });
}

From source file:org.opennms.features.vaadin.dashboard.dashlets.GraphSelectionWindow.java

License:Open Source License

/**
 * Constructor for creating new instances.
 *
 * @param nodeDao        the node dao instance
 * @param rrdGraphHelper the rrd graph helper instance
 * @param rrdGraphEntry  the entry to be edited
 *///from  w  w w.ja  v  a 2s .com
public GraphSelectionWindow(final NodeDao nodeDao, final RrdGraphHelper rrdGraphHelper,
        final RrdGraphEntry rrdGraphEntry) {
    /**
     * Setting the title
     */
    super("Select RRD graph");

    /**
     * setting up the component
     */
    setModal(true);
    setClosable(false);
    setResizable(false);
    setWidth(50, Unit.PERCENTAGE);
    setHeight(70, Unit.PERCENTAGE);

    /**
     * setting up the container
     */
    final HierarchicalContainer hierarchicalContainer = new HierarchicalContainer();

    hierarchicalContainer.addContainerProperty("id", String.class, null);
    hierarchicalContainer.addContainerProperty("label", String.class, null);
    hierarchicalContainer.addContainerProperty("type", String.class, null);

    hierarchicalContainer.addContainerProperty("nodeId", String.class, null);
    hierarchicalContainer.addContainerProperty("nodeLabel", String.class, null);
    hierarchicalContainer.addContainerProperty("resourceId", String.class, null);
    hierarchicalContainer.addContainerProperty("resourceLabel", String.class, null);
    hierarchicalContainer.addContainerProperty("resourceTypeId", String.class, null);
    hierarchicalContainer.addContainerProperty("resourceTypeLabel", String.class, null);
    hierarchicalContainer.addContainerProperty("graphId", String.class, null);
    hierarchicalContainer.addContainerProperty("graphLabel", String.class, null);
    hierarchicalContainer.addContainerProperty("graphUrl", String.class, null);

    /**
     * filling the container with node data
     */
    List<OnmsNode> onmsNodeList = nodeDao.findAll();

    for (OnmsNode onmsNode : onmsNodeList) {
        Item item = hierarchicalContainer.addItem(onmsNode.getId().toString());
        item.getItemProperty("label").setValue(onmsNode.getLabel() + " (" + onmsNode.getId() + ")");
        item.getItemProperty("id").setValue(onmsNode.getId().toString());
        item.getItemProperty("type").setValue("node");
        item.getItemProperty("nodeId").setValue(onmsNode.getId().toString());
    }

    /**
     * creating a panel for the tree component
     */
    Panel panel = new Panel();

    m_tree = new Tree();
    m_tree.setCaption("Graph");
    m_tree.setSizeFull();
    m_tree.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    m_tree.setItemCaptionPropertyId("label");
    m_tree.setContainerDataSource(hierarchicalContainer);
    m_tree.setMultiSelect(false);
    m_tree.setNewItemsAllowed(false);
    m_tree.setImmediate(true);

    /**
     * adding en expand listener for lazy loading the resourceType and resource data
     */
    m_tree.addExpandListener(new Tree.ExpandListener() {
        @Override
        public void nodeExpand(Tree.ExpandEvent expandEvent) {
            String itemToExpandId = String.valueOf(expandEvent.getItemId());

            /**
             * if the data has already been loaded, return
             */
            if (m_tree.hasChildren(itemToExpandId)) {
                return;
            }

            Item itemToExpand = m_tree.getItem(expandEvent.getItemId());
            String type = itemToExpand.getItemProperty("type").getValue().toString();

            /**
             * a node is selected
             */
            if ("node".equals(type)) {
                Map<OnmsResourceType, List<OnmsResource>> resourceTypeMap = rrdGraphHelper
                        .getResourceTypeMapForNodeId(
                                String.valueOf(itemToExpand.getItemProperty("id").getValue()));

                for (Map.Entry<OnmsResourceType, List<OnmsResource>> resourceTypeMapEntry : resourceTypeMap
                        .entrySet()) {
                    String newResourceTypeItemId = "node[" + itemToExpandId + "]."
                            + resourceTypeMapEntry.getKey().getName();

                    Item newResourceTypeItem = hierarchicalContainer.addItem(newResourceTypeItemId);

                    newResourceTypeItem.getItemProperty("label")
                            .setValue(resourceTypeMapEntry.getKey().getLabel());
                    newResourceTypeItem.getItemProperty("type").setValue("resourceType");
                    newResourceTypeItem.getItemProperty("nodeId").setValue(itemToExpandId);
                    newResourceTypeItem.getItemProperty("nodeLabel")
                            .setValue(itemToExpand.getItemProperty("label").getValue());
                    newResourceTypeItem.getItemProperty("resourceTypeId").setValue(newResourceTypeItemId);
                    newResourceTypeItem.getItemProperty("resourceTypeLabel")
                            .setValue(resourceTypeMapEntry.getKey().getLabel());

                    m_tree.setParent(newResourceTypeItemId, itemToExpandId);
                    m_tree.setChildrenAllowed(newResourceTypeItemId, true);

                    for (OnmsResource onmsResource : resourceTypeMapEntry.getValue()) {

                        String newResourceItemId = null;

                        try {
                            newResourceItemId = URLDecoder.decode(onmsResource.getId(), "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }

                        Item newResourceItem = hierarchicalContainer.addItem(newResourceItemId);

                        newResourceItem.getItemProperty("label").setValue(onmsResource.getLabel());
                        newResourceItem.getItemProperty("type").setValue("resource");
                        newResourceItem.getItemProperty("nodeId").setValue(itemToExpandId);
                        newResourceItem.getItemProperty("nodeLabel")
                                .setValue(itemToExpand.getItemProperty("label").getValue());
                        newResourceItem.getItemProperty("resourceId").setValue(newResourceItemId);
                        newResourceItem.getItemProperty("resourceLabel").setValue(onmsResource.getLabel());
                        newResourceItem.getItemProperty("resourceTypeId").setValue(newResourceTypeItemId);
                        newResourceItem.getItemProperty("resourceTypeLabel")
                                .setValue(newResourceTypeItem.getItemProperty("label").getValue());

                        m_tree.setParent(newResourceItemId, newResourceTypeItemId);
                        m_tree.setChildrenAllowed(newResourceItemId, true);
                    }
                }
            }

            /**
             * a resource is selected
             */
            if ("resource".equals(type)) {
                Map<String, String> map = rrdGraphHelper.getGraphResultsForResourceId(itemToExpandId);
                Map<String, String> titleNameMapping = rrdGraphHelper
                        .getGraphTitleNameMappingForResourceId(itemToExpandId);

                for (Map.Entry<String, String> entry : titleNameMapping.entrySet()) {
                    String newGraphItemId = itemToExpandId + "." + entry.getKey();
                    /*
                                            if (hierarchicalContainer.containsId(newGraphItemId)) {
                    continue;
                                            }
                    */
                    Item newGraphItem = hierarchicalContainer.addItem(newGraphItemId);

                    newGraphItem.getItemProperty("label").setValue(entry.getKey());
                    newGraphItem.getItemProperty("type").setValue("graph");
                    newGraphItem.getItemProperty("nodeId")
                            .setValue(String.valueOf(itemToExpand.getItemProperty("nodeId").getValue()));
                    newGraphItem.getItemProperty("nodeLabel")
                            .setValue(String.valueOf(itemToExpand.getItemProperty("nodeLabel").getValue()));
                    newGraphItem.getItemProperty("resourceId")
                            .setValue(String.valueOf(itemToExpand.getItemProperty("resourceId").getValue()));
                    newGraphItem.getItemProperty("resourceLabel")
                            .setValue(String.valueOf(itemToExpand.getItemProperty("resourceLabel").getValue()));
                    newGraphItem.getItemProperty("resourceTypeId").setValue(
                            String.valueOf(itemToExpand.getItemProperty("resourceTypeId").getValue()));
                    newGraphItem.getItemProperty("resourceTypeLabel").setValue(
                            String.valueOf(itemToExpand.getItemProperty("resourceTypeLabel").getValue()));
                    newGraphItem.getItemProperty("graphId").setValue(newGraphItemId);
                    newGraphItem.getItemProperty("graphLabel").setValue(entry.getKey());
                    newGraphItem.getItemProperty("graphUrl").setValue(map.get(entry.getValue()));

                    m_tree.setParent(newGraphItemId, itemToExpandId);
                    m_tree.setChildrenAllowed(newGraphItemId, false);
                }
            }
        }
    });

    /**
     * adding button to a horizontal layout
     */
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");

    final Button cancel = new Button("Cancel");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);

    buttonLayout.addComponent(cancel);
    buttonLayout.setExpandRatio(cancel, 1);
    buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    final Button ok = new Button("Select");

    ok.setEnabled(false);

    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (m_tree.getValue() != null) {
                /**
                 * saving the data
                 */
                Item selectedItem = m_tree.getItem(m_tree.getValue());

                rrdGraphEntry.setGraphId(String.valueOf(selectedItem.getItemProperty("graphId").getValue()));
                rrdGraphEntry.setResourceTypeId(
                        String.valueOf(selectedItem.getItemProperty("resourceTypeId").getValue()));
                rrdGraphEntry
                        .setResourceId(String.valueOf(selectedItem.getItemProperty("resourceId").getValue()));
                rrdGraphEntry.setNodeId(String.valueOf(selectedItem.getItemProperty("nodeId").getValue()));

                rrdGraphEntry
                        .setGraphLabel(String.valueOf(selectedItem.getItemProperty("graphLabel").getValue()));
                rrdGraphEntry.setResourceTypeLabel(
                        String.valueOf(selectedItem.getItemProperty("resourceTypeLabel").getValue()));
                rrdGraphEntry.setResourceLabel(
                        String.valueOf(selectedItem.getItemProperty("resourceLabel").getValue()));
                rrdGraphEntry
                        .setNodeLabel(String.valueOf(selectedItem.getItemProperty("nodeLabel").getValue()));

                rrdGraphEntry.setGraphUrl(String.valueOf(selectedItem.getItemProperty("graphUrl").getValue()));

                rrdGraphEntry.update();
            }
            close();
        }
    });

    ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null);

    buttonLayout.addComponent(ok);

    /**
     * if data is available expand the required nodes
     */
    if (rrdGraphEntry.getNodeId() != null) {
        m_tree.expandItem(rrdGraphEntry.getNodeId());

        if (rrdGraphEntry.getResourceTypeId() != null) {
            m_tree.expandItem(rrdGraphEntry.getResourceTypeId());

            if (rrdGraphEntry.getResourceId() != null) {
                m_tree.expandItem(rrdGraphEntry.getResourceId());

                /**
                 * and select the specified entry
                 */
                if (rrdGraphEntry.getGraphId() != null) {
                    m_tree.select(rrdGraphEntry.getGraphId());
                }
            }
        }
    }

    /**
     * adding a value change listener that checks if leaf node is selected
     */
    m_tree.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
            if (valueChangeEvent.getProperty().getValue() != null) {
                Item selectedItem = m_tree.getItem(valueChangeEvent.getProperty().getValue());
                Object object = selectedItem.getItemProperty("graphId").getValue();

                ok.setEnabled(object != null);
            }
        }
    });

    /**
     * creating the layout and setting the content
     */
    panel.setContent(m_tree);
    panel.setCaption("Graph");
    panel.setSizeFull();

    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSizeFull();
    verticalLayout.setMargin(true);
    verticalLayout.addComponent(panel);
    verticalLayout.setExpandRatio(panel, 1.0f);
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

From source file:org.semanticsoft.vaaclipsedemo.cassandra.app.views.Outline.java

License:Open Source License

@Inject
public Outline(VerticalLayout parent, IEclipseContext context, MApplication app) {
    Class<?> o = Outline.class;
    panel = new Panel();
    panel.setSizeFull();/*from   ww w.j a  v a  2 s.com*/
    tree = new Tree();
    panel.setContent(tree);
    tree.setImmediate(true);

    parent.addComponent(panel);

    tree.addContainerProperty(ICON_PROP, Resource.class, null);
    tree.addContainerProperty(CAPTION_PROP, String.class, "NoName");

    tree.setItemCaptionPropertyId(CAPTION_PROP);
    tree.setItemIconPropertyId(ICON_PROP);

    eventBroker = context.get(IEventBroker.class);
}

From source file:org.semanticsoft.vaaclipsedemo.cassandra.app.views.PackageExplorer.java

License:Open Source License

private void createProjectTree() {
    demoRoot = CassandraActivator.getInstance().getSrcStore();

    tree = new Tree();
    tree.setSizeFull();//from  w ww . j ava 2  s .c  o  m
    tree.setImmediate(true);
    panel.setContent(tree);

    FilesystemContainer fsc = new FilesystemContainer(demoRoot, true);
    FileTypeResolver.addExtension("java", "java");
    FileTypeResolver.addIcon("java", BundleResource
            .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/java.png"));
    FileTypeResolver.addExtension("xml", "xml");
    FileTypeResolver.addIcon("xml", BundleResource
            .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/xml.png"));
    FileTypeResolver.addExtension("e4xmi", "e4xmi");
    FileTypeResolver.addIcon("e4xmi", BundleResource
            .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/xmi.png"));
    FileTypeResolver.addExtension("css", "css");
    FileTypeResolver.addIcon("css", BundleResource
            .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/css.png"));
    FileTypeResolver.addExtension("html", "html");
    FileTypeResolver.addIcon("html", BundleResource
            .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/html.png"));

    FileTypeResolver.addIcon("image/png", BundleResource
            .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/img.png"));

    FileTypeResolver.addIcon("inode/directory", BundleResource
            .valueOf("platform:/plugin/org.semanticsoft.vaaclipsedemo.cassandra.app/img/folder.png"));

    tree.setContainerDataSource(fsc);

    tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        public void itemClick(final ItemClickEvent event) {
            if (event.getButton() == MouseButton.LEFT && event.isDoubleClick()) {
                tree.select(event.getItemId());

                FileItem fileItem = (FileItem) event.getItem();
                try {
                    for (Field f : FileItem.class.getDeclaredFields()) {
                        if (f.getName().equals("file")) {
                            f.setAccessible(true);
                            final File file = (File) f.get(fileItem);
                            eventBroker.send(CassandraConstants.OPEN_FILE, file);
                            break;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    });

    // Set tree to show the 'name' property as caption for items
    tree.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);
    tree.setItemIconPropertyId(FilesystemContainer.PROPERTY_ICON);

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

    String projectName = "org.semanticsoft.vaaclipsedemo.cassandra.app";
    File data = FileUtils.getFile(demoRoot, projectName, "data");
    if (data != null)
        tree.expandItem(data);

    File rootPackage = FileUtils.getFile(demoRoot, projectName, "src");
    if (rootPackage != null)
        tree.expandItemsRecursively(rootPackage);
}

From source file:org.universAAL.ucc.windows.LicenceWindow.java

public LicenceWindow(UccUI app, ArrayList<License> licenses, AALService aal, UAPP installApp)
        throws IOException {
    res = ResourceBundle.getBundle(base);
    setCaption(res.getString("license.capt"));
    this.app = app;
    this.installingApplication = installApp;
    modus = Arrays.asList(new String[] { res.getString("agree.radio"), res.getString("dontAgree.radio") });
    vl = new VerticalLayout();
    vl.setSizeFull();//ww w  . j a v  a  2  s  .co m
    vl.setSpacing(true);
    vl.setMargin(true);
    hp = new HorizontalSplitPanel();
    hp.setSplitPosition(150, Sizeable.UNITS_PIXELS);
    hp.setStyleName(Reindeer.SPLITPANEL_SMALL);
    hp.setLocked(true);

    hp.setSizeFull();
    tree = new Tree();
    tree.setImmediate(true);
    tree.setNullSelectionAllowed(true);
    tree.setNewItemsAllowed(false);
    for (License l : licenses) {
        tree.addItem(l.getAppName());
        tree.setChildrenAllowed(l.getAppName(), true);
        tree.expandItemsRecursively(l.getAppName());
        for (File f : l.getLicense()) {
            tree.addItem(f.getName());
            tree.setParent(f.getName(), l.getAppName());
            tree.setChildrenAllowed(f.getName(), false);
        }
    }
    if (licenses.size() > 0) {
        tree.select(licenses.get(0).getLicense().get(0).getName());
    }
    Panel panel = new Panel();
    panel.setHeight("400px");
    VerticalLayout layout = (VerticalLayout) panel.getContent();
    layout.setSpacing(true);
    layout.setMargin(true);
    for (License l : licenses) {
        if (l.getSlaList().size() > 0) {
            for (File slaFile : l.getSlaList()) {
                FileReader fr = new FileReader(slaFile);
                // SLA makes problems
                BufferedReader reader = new BufferedReader(fr);
                String line = null;
                while ((line = reader.readLine()) != null) {
                    panel.addComponent(new Label(line));
                }
            }
        } else if (l.getLicense().size() > 0) {
            for (File lFile : l.getLicense()) {
                FileReader fr = new FileReader(lFile);
                BufferedReader reader = new BufferedReader(fr);
                String line = null;
                while ((line = reader.readLine()) != null) {
                    panel.addComponent(new Label(line));
                }
            }
        }
    }
    hp.setFirstComponent(tree);
    vl.addComponent(panel);
    setContent(hp);
    op = new OptionGroup("", modus);
    op.setNullSelectionAllowed(false);
    op.select(res.getString("dontAgree.radio"));
    op.setImmediate(true);
    vl.addComponent(op);
    HorizontalLayout hl = new HorizontalLayout();
    hl.setSpacing(true);
    hl.setMargin(true);
    cancel = new Button(res.getString("cancel.button"));
    go = new Button(res.getString("finish.button"));
    go.setEnabled(false);
    hl.addComponent(cancel);
    hl.addComponent(go);
    vl.addComponent(hl);
    vl.setComponentAlignment(hl, Alignment.BOTTOM_RIGHT);
    setWidth("700px");
    setHeight("600px");
    setModal(true);
    center();
    hp.setSecondComponent(vl);
    setClosable(false);
    lic = new LicenseController(app, this, licenses, aal, installingApplication);
    tree.addListener(lic);
    op.addListener(lic);
}