Example usage for com.vaadin.ui Button setEnabled

List of usage examples for com.vaadin.ui Button setEnabled

Introduction

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

Prototype

@Override
    public void setEnabled(boolean enabled) 

Source Link

Usage

From source file:org.metawidget.example.vaadin.addressbook.ContactDialog.java

License:BSD License

public ContactDialog(AddressBook addressBook, final Contact contact) {

    mAddressBook = addressBook;//from ww w.ja v a  2 s  .  c om

    setHeight("600px");
    setWidth("800px");
    ((Layout) getContent()).setMargin(false);

    CustomLayout body = new CustomLayout("contact");
    addComponent(body);

    // Bundle

    ResourceBundle bundle = ResourceBundle
            .getBundle("org.metawidget.example.shared.addressbook.resource.Resources");

    // Title

    StringBuilder builder = new StringBuilder(contact.getFullname());

    if (builder.length() > 0) {
        builder.append(" - ");
    }

    // Personal/business icon

    if (contact instanceof PersonalContact) {
        builder.append(bundle.getString("personalContact"));
        body.addComponent(new Embedded(null, new ThemeResource("../addressbook/img/personal.gif")), "icon");
    } else {
        builder.append(bundle.getString("businessContact"));
        body.addComponent(new Embedded(null, new ThemeResource("../addressbook/img/business.gif")), "icon");
    }

    setCaption(builder.toString());

    // Metawidget

    mContactMetawidget = new VaadinMetawidget();
    mContactMetawidget.setWidth("100%");
    mContactMetawidget.setConfig("org/metawidget/example/vaadin/addressbook/metawidget.xml");
    mContactMetawidget.setReadOnly(contact.getId() != 0);
    mContactMetawidget.setToInspect(contact);

    // Communications override

    final TableDataSource<Communication> tableDataSource = new TableDataSource<Communication>(
            Communication.class, contact.getCommunications(), "type", "value");
    mCommunicationsTable = new Table();
    mCommunicationsTable.setWidth("100%");
    mCommunicationsTable.setHeight("170px");

    final Button deleteButton = new Button("Delete");
    deleteButton.setEnabled(false);
    deleteButton.addListener(new ClickListener() {

        @SuppressWarnings("unchecked")
        public void buttonClick(ClickEvent event) {

            Communication communication = tableDataSource.getDataRow(mCommunicationsTable.getValue());
            contact.removeCommunication(communication);

            ((TableDataSource<Communication>) mCommunicationsTable.getContainerDataSource())
                    .importCollection(contact.getCommunications());
        }
    });

    Button addNewButton = new Button("Add");
    addNewButton.addListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {

            mCommunicationsTable.setValue(null);
            deleteButton.setEnabled(false);

            CommunicationDialog communicationDialog = new CommunicationDialog(ContactDialog.this,
                    new Communication());
            communicationDialog.setModal(true);
            getParent().addWindow(communicationDialog);
        }
    });

    mCommunicationsTable.setSelectable(false);
    mCommunicationsTable.addListener(new ItemClickListener() {

        public void itemClick(ItemClickEvent event) {

            if (!mCommunicationsTable.isSelectable()) {
                return;
            }

            if (!event.isDoubleClick()) {
                deleteButton.setEnabled(true);
                return;
            }

            deleteButton.setEnabled(false);

            Communication communication = tableDataSource.getDataRow(event.getItemId());
            CommunicationDialog communicationDialog = new CommunicationDialog(ContactDialog.this,
                    communication);
            communicationDialog.setModal(true);
            getParent().addWindow(communicationDialog);
        }
    });

    mCommunicationsButtons = new com.vaadin.ui.HorizontalLayout();
    mCommunicationsButtons.setVisible(!mContactMetawidget.isReadOnly());
    mCommunicationsButtons.setMargin(false);
    mCommunicationsButtons.setSpacing(true);
    mCommunicationsButtons.addComponent(addNewButton);
    mCommunicationsButtons.addComponent(deleteButton);

    VerticalLayout wrapper = new VerticalLayout();
    wrapper.setData("communications");
    wrapper.addComponent(mCommunicationsTable);
    wrapper.addComponent(mCommunicationsButtons);
    wrapper.setComponentAlignment(mCommunicationsButtons, Alignment.MIDDLE_CENTER);
    mContactMetawidget.addComponent(wrapper);

    mCommunicationsTable.setContainerDataSource(tableDataSource);
    body.addComponent(mContactMetawidget, "pagebody");

    // Embedded buttons

    Facet facetButtons = new Facet();
    facetButtons.setData("buttons");
    facetButtons.setWidth("100%");
    mContactMetawidget.addComponent(facetButtons);

    mButtonsMetawidget = new VaadinMetawidget();
    mButtonsMetawidget.setWidth(null);
    mButtonsMetawidget.setConfig("org/metawidget/example/vaadin/addressbook/metawidget.xml");
    mButtonsMetawidget.setLayout(new HorizontalLayout());
    mButtonsMetawidget.setToInspect(this);
    facetButtons.addComponent(mButtonsMetawidget);
    ((com.vaadin.ui.VerticalLayout) facetButtons.getContent()).setComponentAlignment(mButtonsMetawidget,
            Alignment.MIDDLE_CENTER);
}

From source file:org.metawidget.vaadin.ui.widgetbuilder.ReadOnlyWidgetBuilder.java

License:LGPL

public Component buildWidget(String elementName, Map<String, String> attributes, VaadinMetawidget metawidget) {

    // Not read-only?

    if (!WidgetBuilderUtils.isReadOnly(attributes)) {
        return null;
    }/*w  ww . j  av  a 2s .  com*/

    // Hidden

    if (TRUE.equals(attributes.get(HIDDEN))) {
        return null;
    }

    // Action

    if (ACTION.equals(elementName)) {
        Button button = new Button(metawidget.getLabelString(attributes));
        button.setEnabled(false);

        return button;
    }

    if (TRUE.equals(attributes.get(MASKED))) {
        return new Panel();
    }

    // Lookups

    String lookup = attributes.get(LOOKUP);

    if (lookup != null && !"".equals(lookup)) {
        // May have alternate labels

        String lookupLabels = attributes.get(LOOKUP_LABELS);

        if (lookupLabels != null && !"".equals(lookupLabels)) {
            return new LookupLabel(CollectionUtils.newHashMap(CollectionUtils.fromString(lookup),
                    CollectionUtils.fromString(lookupLabels)));
        }

        return new Label();
    }

    // Lookup the Class

    Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, String.class);

    if (clazz != null) {
        // Primitives

        if (clazz.isPrimitive()) {
            return new Label();
        }

        if (String.class.equals(clazz)) {
            if (TRUE.equals(attributes.get(LARGE))) {
                TextArea textarea = new TextArea();
                textarea.setReadOnly(true);

                return textarea;
            }

            return new Label();
        }

        if (Character.class.equals(clazz)) {
            return new Label();
        }

        if (Date.class.equals(clazz)) {
            return new Label();
        }

        if (Boolean.class.equals(clazz)) {
            return new Label();
        }

        if (Number.class.isAssignableFrom(clazz)) {
            return new Label();
        }

        // Collections

        if (Collection.class.isAssignableFrom(clazz)) {
            return null;
        }
    }

    // Not simple, but don't expand

    if (TRUE.equals(attributes.get(DONT_EXPAND))) {
        return new Label();
    }

    // Nested Metawidget

    return null;
}

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

License:Open Source License

/**
 * Creates a properly styled button for the given app.<p>
 *
 * @param cms the cms context/*from  w  w  w . jav  a  2s.c  o m*/
 * @param appConfig the app configuration
 * @param locale the locale
 *
 * @return the button component
 */
public static Component createAppButton(CmsObject cms, final I_CmsWorkplaceAppConfiguration appConfig,
        Locale locale) {

    Button button = createAppIconButton(appConfig, locale);
    button.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            if ((appConfig instanceof I_CmsHasAppLaunchCommand)
                    && (((I_CmsHasAppLaunchCommand) appConfig).getAppLaunchCommand() != null)) {
                ((I_CmsHasAppLaunchCommand) appConfig).getAppLaunchCommand().run();
            } else {
                CmsAppWorkplaceUi ui = (CmsAppWorkplaceUi) A_CmsUI.get();
                ui.showApp(appConfig);
            }
        }
    });
    CmsAppVisibilityStatus status = appConfig.getVisibility(cms);
    if (!status.isActive()) {
        button.setEnabled(false);
        button.setDescription(status.getHelpText());
    } else {
        String helpText = appConfig.getHelpText(locale);
        button.setDescription(helpText);
    }
    return button;
}

From source file:org.opencms.ui.components.CmsAppViewLayout.java

License:Open Source License

/**
 * @see org.opencms.ui.apps.I_CmsAppUIContext#addPublishButton(org.opencms.ui.I_CmsUpdateListener)
 *///from   w w  w .  j  av a  2s  .c o m
public Button addPublishButton(final I_CmsUpdateListener<String> updateListener) {

    Button publishButton = CmsToolBar.createButton(FontOpenCms.PUBLISH,
            CmsVaadinUtils.getMessageText(Messages.GUI_PUBLISH_BUTTON_TITLE_0));
    if (CmsAppWorkplaceUi.isOnlineProject()) {
        // disable publishing in online project
        publishButton.setEnabled(false);
        publishButton
                .setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_TOOLBAR_NOT_AVAILABLE_ONLINE_0));
    }
    publishButton.addClickListener(new ClickListener() {

        /** Serial version id. */
        private static final long serialVersionUID = 1L;

        public void buttonClick(ClickEvent event) {

            CmsAppWorkplaceUi.get().disableGlobalShortcuts();
            CmsGwtDialogExtension extension = new CmsGwtDialogExtension(A_CmsUI.get(), updateListener);
            extension.openPublishDialog(A_CmsUI.getCmsObject().getRequestContext().getCurrentProject());
        }
    });

    addToolbarButton(publishButton);
    return publishButton;
}

From source file:org.opencms.ui.dataview.CmsPagingControls.java

License:Open Source License

/**
 * Updates the button state, i.e. enables/disables the buttons depending on whether we are on the first or last page or not.<p>
 *///from ww  w  .  j  a v  a  2  s. c  o m
public void updateButtons() {

    for (Button button : new Button[] { m_forward, m_fastForward }) {
        button.setEnabled(m_page < m_lastPage);
    }
    for (Button button : new Button[] { m_back, m_fastBack }) {
        button.setEnabled(m_page > 0);
    }
}

From source file:org.opencms.ui.editors.messagebundle.CmsMessageBundleEditor.java

License:Open Source License

/** Creates the save button UI Component.
 * @return the save button.//w ww .  ja v a  2  s . co  m
 */
@SuppressWarnings("serial")
private Button createSaveButton() {

    Button saveBtn = CmsToolBar.createButton(FontOpenCms.SAVE, m_messages.key(Messages.GUI_BUTTON_SAVE_0));
    saveBtn.addClickListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {

            saveAction();
        }

    });
    saveBtn.setEnabled(false);
    return saveBtn;
}

From source file:org.opencms.ui.editors.messagebundle.CmsMessageBundleEditor.java

License:Open Source License

/** Creates the save and exit button UI Component.
 * @return the save and exit button./*ww  w.  ja  v a 2 s  .  c om*/
 */
@SuppressWarnings("serial")
private Button createSaveExitButton() {

    Button saveExitBtn = CmsToolBar.createButton(FontOpenCms.SAVE_EXIT,
            m_messages.key(Messages.GUI_BUTTON_SAVE_AND_EXIT_0));
    saveExitBtn.addClickListener(new ClickListener() {

        public void buttonClick(ClickEvent event) {

            saveAction();
            closeAction();

        }
    });
    saveExitBtn.setEnabled(false);
    return saveExitBtn;
}

From source file:org.openeos.services.ui.vaadin.internal.DefaultVaadinERPWindowFactory.java

License:Apache License

protected Component createToolBarButton(final WindowAction action, final IWindow window) {
    final Button button = new Button();
    button.setCaption(action.getCaption());
    button.addListener(new Button.ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override/*  www .j  av a2  s  .c om*/
        public void buttonClick(ClickEvent event) {
            action.run(window);
        }
    });

    button.setEnabled(action.isEnabledForWindow(window));
    window.addSelectionChangeListener(new SelectionChangeListener() {

        @Override
        public void selectionChange(SelectionChangeEvent selectionChangeEvent) {
            button.setEnabled(action.isEnabledForWindow(window));
        }

    });
    window.addTabChangeListener(new TabChangeListener() {

        @Override
        public void tabChange(TabChangeEvent tabChangeEvent) {
            button.setEnabled(action.isEnabledForWindow(window));
        }

    });
    window.addViewChangeListener(new ViewChangeListener() {

        @Override
        public void viewChange(ViewChangeEvent viewChangeEvent) {
            button.setEnabled(action.isEnabledForWindow(window));
        }
    });

    return button;
}

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

License:Open Source License

/**
 * This method updates the criteria components.
 *///  w w w .ja  v a  2  s .  c  o  m
private void renderComponents() {
    m_criteriaLayout.removeAllComponents();

    boolean isFirst = true;
    boolean isLast;

    for (int i = 0; i < m_criteriaRestrictionComponents.size(); i++) {
        final CriteriaRestrictionComponent criteriaRestrictionComponent = m_criteriaRestrictionComponents
                .get(i);
        final int index = i;

        isLast = (i == m_criteriaRestrictionComponents.size() - 1);

        criteriaRestrictionComponent.getRightLayout().removeAllComponents();

        Button plusButton = new Button();
        plusButton.setStyleName("small");
        plusButton.setIcon(new ThemeResource("../runo/icons/16/document-add.png"));
        plusButton.setDescription("Add a new criteria entry");

        Button minusButton = new Button();
        minusButton.setStyleName("small");
        minusButton.setIcon(new ThemeResource("../runo/icons/16/document-delete.png"));
        minusButton.setDescription("Remove this criteria entry");

        Button upButton = new Button();
        upButton.setStyleName("small");
        upButton.setIcon(new ThemeResource("../runo/icons/16/arrow-up.png"));
        upButton.setDescription("Move this a criteria entry one position up");

        Button downButton = new Button();
        downButton.setStyleName("small");
        downButton.setIcon(new ThemeResource("../runo/icons/16/arrow-down.png"));
        downButton.setDescription("Move this a criteria entry one position down");

        criteriaRestrictionComponent.getRightLayout().addComponent(upButton);
        criteriaRestrictionComponent.getRightLayout().addComponent(downButton);
        criteriaRestrictionComponent.getRightLayout().addComponent(plusButton);
        criteriaRestrictionComponent.getRightLayout().addComponent(minusButton);

        if (m_criteriaRestrictionComponents.size() == 1) {
            minusButton.setEnabled(false);
            upButton.setEnabled(false);
            downButton.setEnabled(false);
        } else {
            if (isFirst) {
                upButton.setEnabled(false);
            }

            if (isLast) {
                downButton.setEnabled(false);
            }
        }

        upButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent clickEvent) {
                Collections.swap(m_criteriaRestrictionComponents, index, index - 1);
                renderComponents();
            }
        });

        downButton.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent clickEvent) {
                Collections.swap(m_criteriaRestrictionComponents, index, index + 1);
                renderComponents();
            }
        });

        minusButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent clickEvent) {
                m_criteriaRestrictionComponents.remove(criteriaRestrictionComponent);
                renderComponents();
            }
        });

        plusButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent clickEvent) {
                m_criteriaRestrictionComponents.add(index + 1,
                        new CriteriaRestrictionComponent(m_criteriaBuilderHelper, "Limit(10)"));
                renderComponents();
            }
        });

        isFirst = false;

        m_criteriaLayout.addComponent(criteriaRestrictionComponent);
    }
}

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
 *//*w ww . j  a  v  a2s.c  o m*/
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);
}