Search in sources :

Example 1 with InfoWindow

use of org.opennms.features.topology.api.support.InfoWindow in project opennms by OpenNMS.

the class AlarmIdColumnLinkGenerator method generateCell.

@Override
public Object generateCell(final Table source, Object itemId, Object columnId) {
    // no source
    if (source == null)
        return null;
    Property<Integer> alarmIdProperty = source.getContainerProperty(itemId, alarmIdPropertyName);
    final Integer alarmId = alarmIdProperty.getValue();
    // no value
    if (alarmId == null)
        return null;
    // create Link
    Button button = new Button("" + alarmId);
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 3698209256202413810L;

        @Override
        public void buttonClick(ClickEvent event) {
            // try if alarm is there, otherwise show information dialog
            OnmsAlarm alarm = alarmDao.get(alarmId);
            if (alarm == null) {
                new DialogWindow(source.getUI(), "Alarm does not exist!", "The alarm information cannot be shown. \nThe alarm does not exist anymore. \n\nPlease refresh the Alarm Table.");
                return;
            }
            // alarm still exists, show alarm details
            final URI currentLocation = Page.getCurrent().getLocation();
            final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath();
            final String redirectFragment = contextRoot + "/alarm/detail.htm?quiet=true&id=" + alarmId;
            LOG.debug("alarm {} clicked, current location = {}, uri = {}", alarmId, currentLocation, redirectFragment);
            try {
                source.getUI().addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new LabelCreator() {

                    @Override
                    public String getLabel() {
                        return "Alarm Info " + alarmId;
                    }
                }));
            } catch (MalformedURLException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    });
    return button;
}
Also used : MalformedURLException(java.net.MalformedURLException) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ClickEvent(com.vaadin.ui.Button.ClickEvent) InfoWindow(org.opennms.features.topology.api.support.InfoWindow) URI(java.net.URI) URL(java.net.URL) Button(com.vaadin.ui.Button) DialogWindow(org.opennms.features.topology.api.support.DialogWindow) ClickListener(com.vaadin.ui.Button.ClickListener) LabelCreator(org.opennms.features.topology.api.support.InfoWindow.LabelCreator)

Aggregations

Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URL (java.net.URL)1 DialogWindow (org.opennms.features.topology.api.support.DialogWindow)1 InfoWindow (org.opennms.features.topology.api.support.InfoWindow)1 LabelCreator (org.opennms.features.topology.api.support.InfoWindow.LabelCreator)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1