Search in sources :

Example 1 with HorizontalLayout

use of com.vaadin.ui.HorizontalLayout in project vaadin-samples by xpoft.

the class ChooseLanguage method PostConstruct.

@PostConstruct
public void PostConstruct() {
    setCaption(messageSource.getMessage("choose_language.select_lang"));
    setWidth(-1, Unit.PIXELS);
    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setWidth(-1, Unit.PIXELS);
    buttons.setSpacing(true);
    Button russian = new Button(messageSource.getMessage("choose_language.russian"), new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().getSession().setLocale(new Locale("ru"));
            // Reload page
            UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
        }
    });
    russian.setIcon(new ExternalResource("static/img/ru_flag.png"));
    buttons.addComponent(russian);
    Button english = new Button(messageSource.getMessage("choose_language.english"), new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().getSession().setLocale(Locale.ENGLISH);
            // Reload page
            UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
        }
    });
    english.setIcon(new ExternalResource("static/img/uk_flag.png"));
    buttons.addComponent(english);
    Button german = new Button(messageSource.getMessage("choose_language.german"), new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().getSession().setLocale(Locale.GERMAN);
            // Reload page
            UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
        }
    });
    german.setIcon(new ExternalResource("static/img/de_flag.png"));
    buttons.addComponent(german);
    Button finnish = new Button(messageSource.getMessage("choose_language.finnish"), new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            UI.getCurrent().getSession().setLocale(new Locale("fi"));
            // Reload page
            UI.getCurrent().getPage().setUriFragment(UI.getCurrent().getPage().getUriFragment() + "/");
        }
    });
    finnish.setIcon(new ExternalResource("static/img/fi_flag.png"));
    buttons.addComponent(finnish);
    setContent(buttons);
}
Also used : Locale(java.util.Locale) Button(com.vaadin.ui.Button) ExternalResource(com.vaadin.server.ExternalResource) HorizontalLayout(com.vaadin.ui.HorizontalLayout) PostConstruct(javax.annotation.PostConstruct)

Example 2 with HorizontalLayout

use of com.vaadin.ui.HorizontalLayout in project opennms by OpenNMS.

the class NodeInfoPanelItemProvider method createComponent.

private Component createComponent(AbstractVertex ref) {
    Preconditions.checkState(ref.getNodeID() != null, "no Node ID defined.");
    OnmsNode node = nodeDao.get(ref.getNodeID());
    FormLayout formLayout = new FormLayout();
    formLayout.setSpacing(false);
    formLayout.setMargin(false);
    formLayout.addComponent(createLabel("Node ID", "" + node.getId()));
    final HorizontalLayout nodeButtonLayout = new HorizontalLayout();
    Button nodeButton = createButton(node.getLabel(), null, null, event -> new NodeInfoWindow(ref.getNodeID()).open());
    nodeButton.setStyleName(BaseTheme.BUTTON_LINK);
    nodeButtonLayout.addComponent(nodeButton);
    nodeButtonLayout.setCaption("Node Label");
    formLayout.addComponent(nodeButtonLayout);
    if (!Strings.isNullOrEmpty(node.getSysObjectId())) {
        formLayout.addComponent(createLabel("Enterprise OID", node.getSysObjectId()));
    }
    return formLayout;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) OnmsNode(org.opennms.netmgt.model.OnmsNode) Button(com.vaadin.ui.Button) UIHelper.createButton(org.opennms.netmgt.vaadin.core.UIHelper.createButton) NodeInfoWindow(org.opennms.features.topology.app.internal.ui.NodeInfoWindow) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 3 with HorizontalLayout

use of com.vaadin.ui.HorizontalLayout in project opennms by OpenNMS.

the class EventAdminApplication method init.

/* (non-Javadoc)
     * @see com.vaadin.Application#init()
     */
@Override
public void init(VaadinRequest request) {
    if (eventProxy == null)
        throw new RuntimeException("eventProxy cannot be null.");
    if (eventConfDao == null)
        throw new RuntimeException("eventConfDao cannot be null.");
    final VerticalLayout layout = new VerticalLayout();
    final HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setMargin(true);
    final Label comboLabel = new Label("Select Events Configuration File");
    toolbar.addComponent(comboLabel);
    toolbar.setComponentAlignment(comboLabel, Alignment.MIDDLE_LEFT);
    final File eventsDir = new File(ConfigFileConstants.getFilePathString(), "events");
    final XmlFileContainer container = new XmlFileContainer(eventsDir, true);
    // This is a protected file, should not be updated.
    container.addExcludeFile("default.events.xml");
    final ComboBox eventSource = new ComboBox();
    toolbar.addComponent(eventSource);
    eventSource.setImmediate(true);
    eventSource.setNullSelectionAllowed(false);
    eventSource.setContainerDataSource(container);
    eventSource.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);
    eventSource.addValueChangeListener(new ComboBox.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            final File file = (File) event.getProperty().getValue();
            if (file == null)
                return;
            try {
                LOG.info("Loading events from {}", file);
                final Events events = JaxbUtils.unmarshal(Events.class, file);
                addEventPanel(layout, file, events);
            } catch (Exception e) {
                LOG.error("an error ocurred while saving the event configuration {}: {}", file, e.getMessage(), e);
                Notification.show("Can't parse file " + file + " because " + e.getMessage());
            }
        }
    });
    final Button add = new Button("Add New Events File");
    toolbar.addComponent(add);
    add.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            PromptWindow w = new PromptWindow("New Events Configuration", "Events File Name") {

                @Override
                public void textFieldChanged(String fieldValue) {
                    final File file = new File(eventsDir, normalizeFilename(fieldValue));
                    LOG.info("Adding new events file {}", file);
                    final Events events = new Events();
                    addEventPanel(layout, file, events);
                }
            };
            addWindow(w);
        }
    });
    final Button remove = new Button("Remove Selected Events File");
    toolbar.addComponent(remove);
    remove.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            if (eventSource.getValue() == null) {
                Notification.show("Please select an event configuration file.");
                return;
            }
            final File file = (File) eventSource.getValue();
            ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to remove the file " + file.getName() + "?\nThis cannot be undone and OpenNMS won't be able to handle the events configured on this file.", "Yes", "No", new ConfirmDialog.Listener() {

                public void onClose(ConfirmDialog dialog) {
                    if (dialog.isConfirmed()) {
                        LOG.info("deleting file {}", file);
                        if (file.delete()) {
                            try {
                                // Updating eventconf.xml
                                boolean modified = false;
                                File configFile = ConfigFileConstants.getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME);
                                Events config = JaxbUtils.unmarshal(Events.class, configFile);
                                for (Iterator<String> it = config.getEventFiles().iterator(); it.hasNext(); ) {
                                    String fileName = it.next();
                                    if (file.getAbsolutePath().contains(fileName)) {
                                        it.remove();
                                        modified = true;
                                    }
                                }
                                if (modified) {
                                    JaxbUtils.marshal(config, new FileWriter(configFile));
                                    EventBuilder eb = new EventBuilder(EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "WebUI");
                                    eventProxy.send(eb.getEvent());
                                }
                                // Updating UI Components
                                eventSource.select(null);
                                if (layout.getComponentCount() > 1)
                                    layout.removeComponent(layout.getComponent(1));
                            } catch (Exception e) {
                                LOG.error("an error ocurred while saving the event configuration: {}", e.getMessage(), e);
                                Notification.show("Can't save event configuration. " + e.getMessage(), Notification.Type.ERROR_MESSAGE);
                            }
                        } else {
                            Notification.show("Cannot delete file " + file, Notification.Type.WARNING_MESSAGE);
                        }
                    }
                }
            });
        }
    });
    layout.addComponent(toolbar);
    layout.addComponent(new Label(""));
    layout.setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT);
    setContent(layout);
}
Also used : ComboBox(com.vaadin.ui.ComboBox) ClickEvent(com.vaadin.ui.Button.ClickEvent) FileWriter(java.io.FileWriter) Label(com.vaadin.ui.Label) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Events(org.opennms.netmgt.xml.eventconf.Events) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) File(java.io.File) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog)

Example 4 with HorizontalLayout

use of com.vaadin.ui.HorizontalLayout in project opennms by OpenNMS.

the class PluginManagerAdminApplication method init.

/* (non-Javadoc)
	 * @see com.vaadin.ui.UI#init(com.vaadin.server.VaadinRequest)
	 */
@Override
public void init(VaadinRequest request) {
    m_rootLayout = new VerticalLayout();
    m_rootLayout.setSizeFull();
    m_rootLayout.addStyleName("root-layout");
    setContent(m_rootLayout);
    // dynamically inject style for non write borders - avoids changing themes css
    // Get the stylesheet of the page
    Styles styles = Page.getCurrent().getStyles();
    // inject the new font size as a style. We need .v-app to override Vaadin's default styles here
    styles.add(".v-app .v-textfield-readonly {border: 1px solid #b6b6b6!important;" + " border-top-color: #9d9d9d!important;" + "border-bottom-color: #d6d6d6!important;" + "border-right-color: #d6d6d6!important;" + " opacity: 1.0!important;" + "filter: none;  }");
    styles.add(".v-app .v-textarea-readonly {border: 1px solid #b6b6b6!important;" + " border-top-color: #9d9d9d!important;" + "border-bottom-color: #d6d6d6!important;" + "border-right-color: #d6d6d6!important;" + " opacity: 1.0!important;" + "filter: none;  }");
    addHeader(request);
    //add diagnostic page links
    if (headerLinks != null) {
        // defining 2 horizontal layouts to force links to stay together
        HorizontalLayout horizontalLayout1 = new HorizontalLayout();
        horizontalLayout1.setWidth("100%");
        horizontalLayout1.setDefaultComponentAlignment(Alignment.TOP_RIGHT);
        HorizontalLayout horizontalLayout2 = new HorizontalLayout();
        horizontalLayout1.addComponent(horizontalLayout2);
        for (String name : headerLinks.keySet()) {
            String urlStr = headerLinks.get(name);
            ExternalResource urlResource = new ExternalResource(urlStr);
            Link link = new Link(name, urlResource);
            // adds space between links
            Label label = new Label("&nbsp;&nbsp;&nbsp;", ContentMode.HTML);
            horizontalLayout2.addComponent(link);
            horizontalLayout2.addComponent(label);
        }
        m_rootLayout.addComponent(horizontalLayout1);
    }
    PluginManagerUIMainPanel pluginManagerUIMainPanel = new PluginManagerUIMainPanel(sessionPluginManager);
    m_rootLayout.addComponent(pluginManagerUIMainPanel);
    // this forces the UI panel to use up all the available space below the header
    m_rootLayout.setExpandRatio(pluginManagerUIMainPanel, 1.0f);
}
Also used : Label(com.vaadin.ui.Label) VerticalLayout(com.vaadin.ui.VerticalLayout) PluginManagerUIMainPanel(org.opennms.features.pluginmgr.vaadin.pluginmanager.PluginManagerUIMainPanel) ExternalResource(com.vaadin.server.ExternalResource) Link(com.vaadin.ui.Link) Styles(com.vaadin.server.Page.Styles) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 5 with HorizontalLayout

use of com.vaadin.ui.HorizontalLayout in project opennms by OpenNMS.

the class BreadcrumbComponent method graphChanged.

@Override
public void graphChanged(GraphContainer graphContainer) {
    final BreadcrumbCriteria criteria = Criteria.getSingleCriteriaForGraphContainer(graphContainer, BreadcrumbCriteria.class, true);
    final HorizontalLayout breadcrumbLayout = (HorizontalLayout) getCompositionRoot();
    breadcrumbLayout.removeAllComponents();
    // Verify that breadcrumbs are enabled
    if (graphContainer.getTopologyServiceClient().getBreadcrumbStrategy() == BreadcrumbStrategy.SHORTEST_PATH_TO_ROOT) {
        final Collection<Vertex> displayVertices = graphContainer.getGraph().getDisplayVertices();
        if (!displayVertices.isEmpty()) {
            final PathTree pathTree = BreadcrumbPathCalculator.findPath(graphContainer.getTopologyServiceClient(), displayVertices.stream().map(v -> (VertexRef) v).collect(Collectors.toSet()));
            final List<Breadcrumb> breadcrumbs = pathTree.toBreadcrumbs();
            criteria.setBreadcrumbs(breadcrumbs);
        }
        for (Breadcrumb eachBreadcrumb : criteria.getBreadcrumbs()) {
            if (breadcrumbLayout.getComponentCount() >= 1) {
                breadcrumbLayout.addComponent(new Label(" > "));
            }
            breadcrumbLayout.addComponent(createButton(graphContainer, eachBreadcrumb));
        }
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) Label(com.vaadin.ui.Label) Breadcrumb(org.opennms.features.topology.api.support.breadcrumbs.Breadcrumb) BreadcrumbCriteria(org.opennms.features.topology.api.support.breadcrumbs.BreadcrumbCriteria) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

HorizontalLayout (com.vaadin.ui.HorizontalLayout)85 Label (com.vaadin.ui.Label)45 Button (com.vaadin.ui.Button)26 VerticalLayout (com.vaadin.ui.VerticalLayout)20 Embedded (com.vaadin.ui.Embedded)19 ClickEvent (com.vaadin.ui.Button.ClickEvent)17 ClickListener (com.vaadin.ui.Button.ClickListener)15 ExternalResource (com.vaadin.terminal.ExternalResource)7 GridLayout (com.vaadin.ui.GridLayout)7 TextField (com.vaadin.ui.TextField)6 PrettyTimeLabel (org.activiti.explorer.ui.custom.PrettyTimeLabel)6 StreamResource (com.vaadin.terminal.StreamResource)5 Link (com.vaadin.ui.Link)5 Panel (com.vaadin.ui.Panel)5 InputStream (java.io.InputStream)4 URL (java.net.URL)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)3 ExternalResource (com.vaadin.server.ExternalResource)3