Search in sources :

Example 1 with DashletComponent

use of org.opennms.features.vaadin.dashboard.model.DashletComponent in project opennms by OpenNMS.

the class DashboardBody method setDashletSpecs.

/**
     * This method sets the {@link List} of {@link DashletSpec} instances.
     *
     * @param dashletSpecs the list of {@link DashletSpec} instances
     */
public void setDashletSpecs(List<DashletSpec> dashletSpecs) {
    m_displayDashlets = new HashMap<Component, DashletComponent>();
    int c = 0;
    List<DashletSpec> dashboardSuitableDashlets = new LinkedList<DashletSpec>();
    if (dashletSpecs.size() == 0) {
        return;
    } else {
        for (DashletSpec dashletSpec : dashletSpecs) {
            if (suitableForDashboard(dashletSpec)) {
                dashboardSuitableDashlets.add(dashletSpec);
            }
        }
    }
    if (dashboardSuitableDashlets.size() == 0) {
        return;
    }
    int columns = (int) Math.ceil(Math.sqrt(dashboardSuitableDashlets.size()));
    int rows = (int) Math.ceil((double) dashboardSuitableDashlets.size() / (double) columns);
    setColumns(columns);
    setRows(rows);
    int i = 0;
    removeAllComponents();
    for (int y = 0; y < rows; y++) {
        for (int x = 0; x < columns; x++) {
            if (i < dashboardSuitableDashlets.size()) {
                Dashlet dashlet = getDashletInstance(dashboardSuitableDashlets.get(i));
                DashletComponent dashletComponent = dashlet.getDashboardComponent();
                m_displayDashlets.put(dashletComponent.getComponent(), dashletComponent);
                dashletComponent.refresh();
                String caption = dashlet.getName();
                if (dashlet.getDashletSpec().getTitle() != null) {
                    if (!"".equals(dashlet.getDashletSpec().getTitle())) {
                        caption += ": " + "" + dashlet.getDashletSpec().getTitle();
                    }
                }
                addComponent(createPanel(dashletComponent.getComponent(), caption), x, y);
                i++;
            }
        }
    }
}
Also used : DashletComponent(org.opennms.features.vaadin.dashboard.model.DashletComponent) Dashlet(org.opennms.features.vaadin.dashboard.model.Dashlet) DashletSpec(org.opennms.features.vaadin.dashboard.model.DashletSpec) DashletComponent(org.opennms.features.vaadin.dashboard.model.DashletComponent) Component(com.vaadin.ui.Component) LinkedList(java.util.LinkedList)

Example 2 with DashletComponent

use of org.opennms.features.vaadin.dashboard.model.DashletComponent in project opennms by OpenNMS.

the class AlarmDetailsDashlet method getDashboardComponent.

@Override
public DashletComponent getDashboardComponent() {
    if (m_dashboardComponent == null) {
        m_dashboardComponent = new AbstractDashletComponent() {

            private AlarmTable m_alarmTable;

            {
                m_alarmTable = new AlarmTable("Alarms", new AlarmDaoContainer(m_alarmDao, m_transactionTemplate), m_alarmRepository);
                m_alarmTable.setSizeFull();
                m_alarmTable.setSortEnabled(false);
                m_alarmTable.addHeaderClickListener(new Table.HeaderClickListener() {

                    @Override
                    public void headerClick(Table.HeaderClickEvent headerClickEvent) {
                        m_alarmTable.setSortContainerPropertyId(headerClickEvent.getPropertyId());
                        m_alarmTable.setSortEnabled(true);
                    }
                });
                final VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
                final UI currentUI = UI.getCurrent();
                context.setSessionId(currentUI.getSession().getSession().getId());
                context.setUiId(currentUI.getUIId());
                m_alarmTable.setVaadinApplicationContext(context);
                final EventProxy eventProxy = new EventProxy() {

                    @Override
                    public <T> void fireEvent(final T eventObject) {
                        System.out.println("got event: {}" + eventObject);
                    }

                    @Override
                    public <T> void addPossibleEventConsumer(final T possibleEventConsumer) {
                        System.out.println("(ignoring) add consumer: {}" + possibleEventConsumer);
                    }
                };
                m_alarmTable.setEventProxy(eventProxy);
                m_alarmTable.setColumnReorderingAllowed(true);
                m_alarmTable.setColumnCollapsingAllowed(true);
                m_alarmTable.setSortContainerPropertyId("id");
                m_alarmTable.setSortAscending(false);
                m_alarmTable.setCellStyleGenerator(new AlarmTableCellStyleGenerator());
                m_alarmTable.addGeneratedColumn("severity", new SeverityGenerator());
                m_alarmTable.addGeneratedColumn("id", new AlarmIdColumnLinkGenerator(m_alarmDao, "id"));
                m_alarmTable.setVisibleColumns("id", "severity", "nodeLabel", "counter", "lastEventTime", "logMsg");
                m_alarmTable.setColumnHeaders("ID", "Severity", "Node", "Count", "Last Event Time", "Log Message");
                refresh();
            }

            @Override
            public void refresh() {
                List<OnmsAlarm> alarms = getAlarms();
                List<Integer> alarmIds = new LinkedList<Integer>();
                if (alarms.size() > 0) {
                    for (OnmsAlarm onmsAlarm : alarms) {
                        alarmIds.add(onmsAlarm.getId());
                    }
                } else {
                    alarmIds.add(0);
                }
                List<Restriction> restrictions = new LinkedList<Restriction>();
                restrictions.add(new InRestriction("id", alarmIds));
                ((OnmsVaadinContainer<?, ?>) m_alarmTable.getContainerDataSource()).setRestrictions(restrictions);
                setBoosted(checkBoosted(alarms));
                m_alarmTable.markAsDirtyRecursive();
            }

            @Override
            public Component getComponent() {
                return m_alarmTable;
            }
        };
    }
    return m_dashboardComponent;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) SeverityGenerator(org.opennms.features.topology.plugins.browsers.SeverityGenerator) AbstractDashletComponent(org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent) InRestriction(org.opennms.core.criteria.restrictions.InRestriction) Restriction(org.opennms.core.criteria.restrictions.Restriction) VaadinApplicationContextImpl(org.opennms.osgi.VaadinApplicationContextImpl) UI(com.vaadin.ui.UI) AlarmTable(org.opennms.features.topology.plugins.browsers.AlarmTable) AlarmTableCellStyleGenerator(org.opennms.features.topology.plugins.browsers.AlarmTableCellStyleGenerator) AlarmIdColumnLinkGenerator(org.opennms.features.topology.plugins.browsers.AlarmIdColumnLinkGenerator) LinkedList(java.util.LinkedList) List(java.util.List) DashletComponent(org.opennms.features.vaadin.dashboard.model.DashletComponent) AbstractDashletComponent(org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent) Component(com.vaadin.ui.Component) EventProxy(org.opennms.osgi.EventProxy) AlarmDaoContainer(org.opennms.features.topology.plugins.browsers.AlarmDaoContainer)

Aggregations

Component (com.vaadin.ui.Component)2 LinkedList (java.util.LinkedList)2 DashletComponent (org.opennms.features.vaadin.dashboard.model.DashletComponent)2 UI (com.vaadin.ui.UI)1 List (java.util.List)1 InRestriction (org.opennms.core.criteria.restrictions.InRestriction)1 Restriction (org.opennms.core.criteria.restrictions.Restriction)1 AlarmDaoContainer (org.opennms.features.topology.plugins.browsers.AlarmDaoContainer)1 AlarmIdColumnLinkGenerator (org.opennms.features.topology.plugins.browsers.AlarmIdColumnLinkGenerator)1 AlarmTable (org.opennms.features.topology.plugins.browsers.AlarmTable)1 AlarmTableCellStyleGenerator (org.opennms.features.topology.plugins.browsers.AlarmTableCellStyleGenerator)1 SeverityGenerator (org.opennms.features.topology.plugins.browsers.SeverityGenerator)1 AbstractDashletComponent (org.opennms.features.vaadin.dashboard.model.AbstractDashletComponent)1 Dashlet (org.opennms.features.vaadin.dashboard.model.Dashlet)1 DashletSpec (org.opennms.features.vaadin.dashboard.model.DashletSpec)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 EventProxy (org.opennms.osgi.EventProxy)1 VaadinApplicationContextImpl (org.opennms.osgi.VaadinApplicationContextImpl)1