Example usage for com.vaadin.ui Panel setSizeFull

List of usage examples for com.vaadin.ui Panel setSizeFull

Introduction

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

Prototype

@Override
    public void setSizeFull() 

Source Link

Usage

From source file:org.opennms.features.jmxconfiggenerator.webui.ui.mbeans.MBeansView.java

License:Open Source License

private Panel wrapToPanel(Component component) {
    Panel panel = new Panel(component.getCaption());
    panel.setSizeFull();

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(false);//from   w  w w  . j a va2 s .  com
    layout.setSpacing(false);
    layout.setSizeFull();
    layout.addComponent(component);

    panel.setContent(layout);
    component.setCaption(null);
    return panel;
}

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 w w w . j  av  a 2 s.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.BSMConfigurationWindow.java

License:Open Source License

/**
 * Constructor for instantiating new objects of this class.
 *
 * @param dashletSpec the {@link DashletSpec} to be edited
 *///from ww w  .  j a va 2 s  .  co  m
public BSMConfigurationWindow(DashletSpec dashletSpec) {
    /**
     * Setting the members
     */
    m_dashletSpec = dashletSpec;

    /**
     * Setting up the base layouts
     */

    setHeight(91, Unit.PERCENTAGE);
    setWidth(60, Unit.PERCENTAGE);

    /**
     * Retrieve the config...
     */

    boolean filterByName = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(), "filterByName");
    String nameValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "nameValue", "");
    boolean filterByAttribute = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(),
            "filterByAttribute");
    String attributeKey = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeKey", "");
    String attributeValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "attributeValue",
            "");
    boolean filterBySeverity = BSMConfigHelper.getBooleanForKey(getDashletSpec().getParameters(),
            "filterBySeverity");
    String severityValue = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "severityValue",
            Status.WARNING.name());
    String severityCompareOperator = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(),
            "severityCompareOperator",
            BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name());
    String orderBy = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderBy",
            BusinessServiceSearchCriteriaBuilder.Order.Name.name());
    String orderSequence = BSMConfigHelper.getStringForKey(getDashletSpec().getParameters(), "orderSequence",
            BusinessServiceSearchCriteriaBuilder.Sequence.Ascending.name());
    int resultsLimit = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "resultsLimit", 10);
    int columnCountBoard = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountBoard",
            10);
    int columnCountPanel = BSMConfigHelper.getIntForKey(getDashletSpec().getParameters(), "columnCountPanel",
            5);

    /**
     * Adding the "Filter By Name" panel
     */

    m_filterByNameCheckBox = new CheckBox();
    m_filterByNameCheckBox.setCaption("Enable");
    m_filterByNameCheckBox.setDescription("Filter by Business Service name");

    VerticalLayout nameLayout = new VerticalLayout();
    nameLayout.setSpacing(true);
    nameLayout.setMargin(true);
    nameLayout.setSizeFull();

    m_nameTextField = new TextField("Name (REGEXP)");
    m_nameTextField.setEnabled(false);

    addToComponent(nameLayout, m_filterByNameCheckBox);
    addToComponent(nameLayout, m_nameTextField);

    Panel namePanel = new Panel();
    namePanel.setCaption("Filter by Name");
    namePanel.setContent(nameLayout);

    m_filterByNameCheckBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            m_nameTextField.setEnabled(m_filterByNameCheckBox.getValue());
        }
    });

    m_nameTextField.setValue(nameValue);
    m_filterByNameCheckBox.setValue(filterByName);

    /**
     * Adding the "Filter By Attribute" panel
     */

    m_filterByAttributeCheckBox = new CheckBox();
    m_filterByAttributeCheckBox.setCaption("Enable");
    m_filterByAttributeCheckBox.setDescription("Filter by Business Service attribute");

    VerticalLayout attributeLayout = new VerticalLayout();
    attributeLayout.setSpacing(true);
    attributeLayout.setMargin(true);
    attributeLayout.setSizeFull();

    m_attributeKeyTextField = new TextField("Key");
    m_attributeKeyTextField.setEnabled(false);
    m_attributeValueTextField = new TextField("Value (REGEXP)");
    m_attributeValueTextField.setEnabled(false);
    addToComponent(attributeLayout, m_filterByAttributeCheckBox);
    addToComponent(attributeLayout, m_attributeKeyTextField);
    addToComponent(attributeLayout, m_attributeValueTextField);

    Panel attributePanel = new Panel();
    attributePanel.setCaption("Filter by Attribute");
    attributePanel.setContent(attributeLayout);

    m_filterByAttributeCheckBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            m_attributeKeyTextField.setEnabled(m_filterByAttributeCheckBox.getValue());
            m_attributeValueTextField.setEnabled(m_filterByAttributeCheckBox.getValue());
        }
    });

    m_attributeKeyTextField.setValue(attributeKey);
    m_attributeValueTextField.setValue(attributeValue);
    m_filterByAttributeCheckBox.setValue(filterByAttribute);

    /**
     * Adding the "Filter By Severity" panel
     */

    m_filterBySeverityCheckBox = new CheckBox();
    m_filterBySeverityCheckBox.setCaption("Enable");
    m_filterBySeverityCheckBox.setDescription("Filter by Business Service severity");

    VerticalLayout severityLayout = new VerticalLayout();
    severityLayout.setSpacing(true);
    severityLayout.setMargin(true);
    severityLayout.setSizeFull();

    m_severitySelect = new NativeSelect("Severity");
    m_severitySelect.setEnabled(false);
    m_severitySelect.setNullSelectionAllowed(false);
    m_severitySelect.setMultiSelect(false);

    for (Status eachStatus : Status.values()) {
        m_severitySelect.addItem(eachStatus.name());
    }

    m_compareOperatorSelect = new NativeSelect("Comparator");
    m_compareOperatorSelect.setEnabled(false);
    m_compareOperatorSelect.setNullSelectionAllowed(false);
    m_compareOperatorSelect.setMultiSelect(false);

    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Lower.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.LowerOrEqual.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Equal.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name());
    m_compareOperatorSelect.addItem(BusinessServiceSearchCriteriaBuilder.CompareOperator.Greater.name());

    addToComponent(severityLayout, m_filterBySeverityCheckBox);
    addToComponent(severityLayout, m_severitySelect);
    addToComponent(severityLayout, m_compareOperatorSelect);

    Panel severityPanel = new Panel();
    severityPanel.setCaption("Filter by Severity");
    severityPanel.setContent(severityLayout);

    m_filterBySeverityCheckBox.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            m_severitySelect.setEnabled(m_filterBySeverityCheckBox.getValue());
            m_compareOperatorSelect.setEnabled(m_filterBySeverityCheckBox.getValue());
        }
    });

    m_severitySelect.setValue(severityValue);
    m_compareOperatorSelect.setValue(severityCompareOperator);
    m_filterBySeverityCheckBox.setValue(filterBySeverity);

    /**
     * Adding the "Results" panel
     */

    VerticalLayout limitLayout = new VerticalLayout();
    limitLayout.setSpacing(true);
    limitLayout.setMargin(true);
    limitLayout.setSizeFull();

    m_limitTextField = new TextField("Limit");

    m_orderBy = new NativeSelect("Order by");
    m_orderBy.setNullSelectionAllowed(false);
    m_orderBy.setMultiSelect(false);

    m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Name.name());
    m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Severity.name());
    m_orderBy.addItem(BusinessServiceSearchCriteriaBuilder.Order.Level.name());

    m_orderSequence = new NativeSelect("Asc/Desc ");
    m_orderSequence.setNullSelectionAllowed(false);
    m_orderSequence.setMultiSelect(false);

    m_orderSequence.addItem("Ascending");
    m_orderSequence.addItem("Descending");

    m_columnCountBoardTextField = new TextField("Ops Board Column Count");
    m_columnCountBoardTextField.addValidator(new AbstractStringValidator("Number greater zero expected") {
        @Override
        protected boolean isValidValue(String value) {
            try {
                int i = Integer.parseInt(value);
                return i > 0;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    m_columnCountPanelTextField = new TextField("Ops Panel Column Count");
    m_columnCountPanelTextField.addValidator(new AbstractStringValidator("Number greater zero expected") {
        @Override
        protected boolean isValidValue(String value) {
            try {
                int i = Integer.parseInt(value);
                return i > 0;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    addToComponent(limitLayout, m_limitTextField);
    addToComponent(limitLayout, m_orderBy);
    addToComponent(limitLayout, m_orderSequence);
    addToComponent(limitLayout, m_columnCountBoardTextField);
    addToComponent(limitLayout, m_columnCountPanelTextField);

    Panel limitPanel = new Panel();
    limitPanel.setSizeFull();
    limitPanel.setCaption("Results");
    limitPanel.setContent(limitLayout);

    m_limitTextField.setValue(String.valueOf(resultsLimit));
    m_orderBy.setValue(orderBy);
    m_orderSequence.setValue(orderSequence);
    m_columnCountBoardTextField.setValue(String.valueOf(columnCountBoard));
    m_columnCountPanelTextField.setValue(String.valueOf(columnCountPanel));

    m_limitTextField.addValidator(new AbstractStringValidator("Number greater or equal zero expected") {
        @Override
        protected boolean isValidValue(String value) {
            try {
                int i = Integer.parseInt(value);
                return i >= 0;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    });

    /**
     * Create the main layout...
     */

    VerticalLayout verticalLayout = new VerticalLayout();

    verticalLayout.setWidth(100, Unit.PERCENTAGE);
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);

    verticalLayout.addComponent(namePanel);
    verticalLayout.addComponent(attributePanel);

    HorizontalLayout bottomLayout = new HorizontalLayout(severityPanel, limitPanel);
    bottomLayout.setSpacing(true);
    bottomLayout.setSizeFull();
    bottomLayout.setWidth(100, Unit.PERCENTAGE);

    verticalLayout.addComponent(bottomLayout);

    /**
     * Using an additional {@link HorizontalLayout} for layouting the buttons
     */
    HorizontalLayout buttonLayout = new HorizontalLayout();

    buttonLayout.setMargin(true);
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth("100%");

    Label label = new Label("Note: Multiple enabled filter constraints will be combined by a logical AND.");
    buttonLayout.addComponent(label);
    buttonLayout.setExpandRatio(label, 1.0f);

    /**
     * Adding the cancel button...
     */
    Button cancel = new Button("Cancel");
    cancel.setDescription("Cancel editing");
    cancel.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });

    cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null);
    buttonLayout.addComponent(cancel);
    buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT);

    /**
     * ...and the OK button
     */
    Button ok = new Button("Save");
    ok.setDescription("Save properties and close");
    ok.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (!m_limitTextField.isValid() || !m_columnCountPanelTextField.isValid()
                    || !m_columnCountBoardTextField.isValid()) {
                return;
            }

            m_dashletSpec.getParameters().put("filterByName",
                    (m_filterByNameCheckBox.getValue() ? "true" : "false"));

            if (m_filterByNameCheckBox.getValue()) {
                m_dashletSpec.getParameters().put("nameValue", m_nameTextField.getValue());
            } else {
                m_dashletSpec.getParameters().put("nameValue", "");
            }

            m_dashletSpec.getParameters().put("filterByAttribute",
                    (m_filterByAttributeCheckBox.getValue() ? "true" : "false"));

            if (m_filterByAttributeCheckBox.getValue()) {
                m_dashletSpec.getParameters().put("attributeKey", m_attributeKeyTextField.getValue());
                m_dashletSpec.getParameters().put("attributeValue", m_attributeValueTextField.getValue());
            } else {
                m_dashletSpec.getParameters().put("attributeKey", "");
                m_dashletSpec.getParameters().put("attributeValue", "");
            }

            m_dashletSpec.getParameters().put("filterBySeverity",
                    (m_filterBySeverityCheckBox.getValue() ? "true" : "false"));

            if (m_filterBySeverityCheckBox.getValue() && m_severitySelect.getValue() != null) {
                m_dashletSpec.getParameters().put("severityValue", m_severitySelect.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("severityValue", Status.WARNING.getLabel());
            }

            if (m_filterBySeverityCheckBox.getValue() && m_compareOperatorSelect.getValue() != null) {
                m_dashletSpec.getParameters().put("severityCompareOperator",
                        m_compareOperatorSelect.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("severityCompareOperator",
                        BusinessServiceSearchCriteriaBuilder.CompareOperator.GreaterOrEqual.name());
            }

            if (m_orderBy.getValue() != null) {
                m_dashletSpec.getParameters().put("orderBy", m_orderBy.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("orderBy",
                        BusinessServiceSearchCriteriaBuilder.Order.Name.name());
            }

            if (m_orderSequence.getValue() != null) {
                m_dashletSpec.getParameters().put("orderSequence", m_orderSequence.getValue().toString());
            } else {
                m_dashletSpec.getParameters().put("orderSequence", "Ascending");
            }

            m_dashletSpec.getParameters().put("resultsLimit", m_limitTextField.getValue().toString());
            m_dashletSpec.getParameters().put("columnCountBoard",
                    m_columnCountBoardTextField.getValue().toString());
            m_dashletSpec.getParameters().put("columnCountPanel",
                    m_columnCountPanelTextField.getValue().toString());

            WallboardProvider.getInstance().save();
            ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties");

            close();
        }
    });

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

    /**
     * Adding the layout and setting the content
     */
    verticalLayout.addComponent(buttonLayout);

    setContent(verticalLayout);
}

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  ww  w  . ja v a  2  s.  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.opennms.features.vaadin.dashboard.ui.dashboard.DashboardBody.java

License:Open Source License

private Panel createPanel(Component content, String caption) {
    Panel panel = new Panel();
    panel.setSizeFull();
    panel.setCaption(caption);//from ww w  .  j a  v a 2  s  . c o  m
    panel.setContent(content);
    panel.addStyleName("novscroll");

    return panel;
}

From source file:org.opennms.features.vaadin.dashboard.ui.wallboard.WallboardBody.java

License:Open Source License

private void advanceTimer() {

    if (paused) {
        return;/*from w w  w  .j  ava2  s  . c  om*/
    }

    waitFor = (waitFor > 250 ? waitFor - 250 : 0);

    if (dashletSpecs.size() > 0) {
        if (waitFor <= 0) {

            int next = next();

            contentLayout.removeAllComponents();

            if (next != -1) {
                waitFor = oldDurationMap.get(next) * 1000;

                if (!dashlets.get(next).getName().equals(dashletSpecs.get(next).getDashletName())) {
                    dashlets.put(next, getDashletInstance(dashletSpecs.get(next)));
                }

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

                String caption = dashlets.get(next).getName();

                if (dashlets.get(next).getDashletSpec().getTitle() != null) {
                    if (!"".equals(dashlets.get(next).getDashletSpec().getTitle())) {
                        caption += ": " + "" + dashlets.get(next).getDashletSpec().getTitle();
                    }
                }

                panel.setCaption(caption);

                Component component = dashlets.get(next).getWallboardComponent().getComponent();

                VerticalLayout verticalLayout = new VerticalLayout(component);
                verticalLayout.setSizeFull();
                verticalLayout.setMargin(true);

                panel.setContent(verticalLayout);

                contentLayout.addComponent(panel);

                if (!progressIndicator.isVisible()) {
                    progressIndicator.setVisible(true);
                }

            } else {
                contentLayout.addComponent(new Label("Nothing to display"));
                progressIndicator.setVisible(false);
            }
        }
    } else {
        contentLayout.removeAllComponents();
        contentLayout.addComponent(new Label("Nothing to display"));
        progressIndicator.setVisible(false);
    }

    if (durationMap.containsKey(index)) {
        float x = 1 - ((float) waitFor / (float) (durationMap.get(index) * 1000));
        progressIndicator.setValue(x);
    }

    debug();
}

From source file:org.semanticsoft.vaaclipse.presentation.renderers.WorkbenchWindowRenderer.java

License:Open Source License

@Override
public void createWidget(MUIElement element, MElementContainer<MUIElement> parent) {
    if (element instanceof MWindow) {
        final MWindow mWindow = (MWindow) element;
        Component currentMainWindow = vaadinUI.getContent();
        if (element.getTags().contains(Tags.MAIN_WINDOW)) {
            Panel window = new Panel();
            window.setContent(new TrimmedWindowContent());
            vaadinUI.getPage().setTitle(mWindow.getLocalizedLabel());
            element.setWidget(window);/*from   ww w.  j  a  va  2s. co  m*/
            ((MWindow) element).getContext().set(Panel.class, window);
            window.setSizeFull();

            vaadinUI.setContent(window);

            app.setSelectedElement(mWindow);
            mWindow.getContext().activate();
        } else {// case child windows
            if (currentMainWindow != null) {
                Window window = new Window();
                window.setContent(new TrimmedWindowContent());
                window.setImmediate(true);
                window.setPositionX(mWindow.getX());
                window.setPositionY(mWindow.getY());
                window.setWidth(mWindow.getWidth(), Unit.PIXELS);
                window.setHeight(mWindow.getHeight(), Unit.PIXELS);
                window.setCaption(mWindow.getLocalizedLabel());
                element.setWidget(window);
                ((MWindow) element).getContext().set(Panel.class, window);
                vaadinUI.addWindow(window);
            } else {
                throw new IllegalStateException(
                        "Can not add child window because application has not main window");
            }
        }

        IEclipseContext localContext = getContext(element);
        localContext.set(ISaveHandler.class, new ISaveHandler() {
            public Save promptToSave(MPart dirtyPart) {
                // Object[] elements =
                // promptForSave(Collections.singleton(dirtyPart));
                // if (elements == null) {
                // return Save.CANCEL;
                // }
                // return elements.length == 0 ? Save.NO : Save.YES;

                if (saveCandidate == null) {
                    saveCandidate = dirtyPart;

                    PartRenderer partRenderer = (PartRenderer) saveCandidate.getRenderer();
                    SavePromptSetup setup = partRenderer.getSavePromptSetup(saveCandidate);
                    String caption = setup.getCaption() != null ? setup.getCaption() : "Save";
                    String msg = setup.getMessage() != null ? setup.getMessage()
                            : String.format("%s has been modified. Save changes?",
                                    saveCandidate instanceof MInputPart
                                            ? ((MInputPart) saveCandidate).getInputURI()
                                            : "Data");

                    OptionDialog.show(vaadinUI, caption, msg, new String[] { "Yes", "No", "Cancel" }, 400, 80,
                            Component.UNITS_PIXELS, new OptionDialog.OptionListener() {

                                @Override
                                public void optionSelected(OptionDialog dlg, int optionId) {
                                    switch (optionId) {
                                    case 0:
                                        s = Save.YES;
                                        break;
                                    case 1:
                                        s = Save.NO;
                                        break;
                                    case 2:
                                        s = Save.CANCEL;
                                        break;

                                    default:
                                        s = null;
                                    }

                                    if (partService.savePart(saveCandidate, true)) {
                                        partService.hidePart(saveCandidate);
                                    }
                                    saveCandidate = null;
                                    dlg.close();
                                }
                            });

                    return Save.CANCEL;
                } else {
                    return s;
                }

            }

            public Save[] promptToSave(Collection<MPart> dirtyParts) {
                // List<MPart> parts = new ArrayList<MPart>(dirtyParts);
                //
                // Save[] response = new Save[dirtyParts.size()];
                // Object[] elements = promptForSave(parts);
                // if (elements == null) {
                // Arrays.fill(response, Save.CANCEL);
                // } else {
                // Arrays.fill(response, Save.NO);
                // for (int i = 0; i < elements.length; i++) {
                // response[parts.indexOf(elements[i])] = Save.YES;
                // }
                // }
                // return response;

                throw new RuntimeException("Multiple saving is not implemented yet");
            }
        });
    }
}

From source file:org.vaadin.artur.declarative.DeclarativeEditor.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    main = new HorizontalSplitPanel();
    editor = new TextArea();
    editor.setSizeFull();//  w w w  . ja  v  a2s .c o m
    getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() {

        @Override
        public void uriFragmentChanged(UriFragmentChangedEvent event) {
            loadFile(getPage().getUriFragment());
            editorChanged(editor.getValue());
        }
    });
    loadFile(getPage().getUriFragment());
    editor.addTextChangeListener(new TextChangeListener() {

        @Override
        public void textChange(TextChangeEvent event) {
            editorChanged(event.getText());
        }
    });

    Panel editorPanel = new Panel(editor);
    editorPanel.setSizeFull();
    treeHolder = new VerticalLayout();
    treeHolder.setSizeFull();

    main.addComponents(editorPanel, treeHolder);
    main.setSizeFull();

    setContent(main);
    updateTree(editor.getValue());
}

From source file:org.vaadin.spring.samples.navigation.NavigationUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout root = new VerticalLayout();
    root.setSizeFull();/*from   w ww  . j ava 2  s .co m*/
    root.setMargin(true);
    root.setSpacing(true);
    setContent(root);

    final CssLayout navigationBar = new CssLayout();
    navigationBar.addStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP);
    navigationBar.addComponent(createNavigationButton("Prototype Scoped View", PrototypeScopedView.VIEW_NAME));
    navigationBar.addComponent(createNavigationButton("UI Scoped View", UIScopedView.VIEW_NAME));
    navigationBar.addComponent(createNavigationButton("View Scoped View", ViewScopedView.VIEW_NAME));
    navigationBar.addComponent(createNavigationButton("Access Control", AccessControlView.VIEW_NAME));
    root.addComponent(navigationBar);

    final Panel viewContainer = new Panel();
    viewContainer.setSizeFull();
    root.addComponent(viewContainer);
    root.setExpandRatio(viewContainer, 1.0f);

    viewProvider.setAccessDeniedViewClass(AccessDeniedView.class);

    Navigator navigator = new Navigator(this, viewContainer);
    navigator.setErrorView(new ErrorView()); // You can still create the error view yourself if you want to.
    navigator.addProvider(viewProvider);
}

From source file:org.vaadin.tori.view.listing.thread.ThreadMoveComponent.java

License:Apache License

public ThreadMoveComponent(final long threadId, final Long currentCategoryId,
        final List<Category> allCategories, final ThreadMoveComponentListener listener) {
    addStyleName("threadmove");
    setClosable(false);//from ww w .  ja v a  2 s .c  o m
    setResizable(false);
    setModal(true);

    setContent(layout);
    layout.setSizeFull();
    layout.setMargin(true);

    setCaption("Move Thread to Category...");
    setWidth("300px");
    setHeight("300px");

    categoriesTree = createCategories(allCategories, threadId, currentCategoryId);
    final Panel panel = new Panel(categoriesTree);
    panel.setStyleName(Reindeer.PANEL_LIGHT);
    panel.setSizeFull();
    layout.addComponent(panel);
    layout.setExpandRatio(panel, 1.0f);

    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSpacing(true);
    layout.addComponent(horizontalLayout);

    final Component moveButton = new Button("Move Thread", new Button.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            final Long newCategoryId = (Long) categoriesTree.getValue();
            listener.commit(threadId, newCategoryId);
            close();
        }
    });
    moveButton.setEnabled(false);
    horizontalLayout.addComponent(moveButton);
    categoriesTree.addValueChangeListener(new ValueChangeListener() {
        @Override
        public void valueChange(final ValueChangeEvent event) {
            moveButton.setEnabled(event.getProperty().getValue() == null
                    || !event.getProperty().getValue().equals(currentCategoryId));
        }
    });

    horizontalLayout.addComponent(ComponentUtil.getSecondaryButton("Cancel", new NativeButton.ClickListener() {
        @Override
        public void buttonClick(final ClickEvent event) {
            close();
        }
    }));
}