List of usage examples for com.vaadin.server Page getCurrent
public static Page getCurrent()
From source file:org.opennms.features.vaadin.dashboard.dashlets.SummaryDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_wallboardComponent == null) { m_wallboardComponent = new AbstractDashletComponent() { private HorizontalLayout m_horizontalLayout = new HorizontalLayout(); {// w ww .ja v a 2s. c o m m_horizontalLayout.setCaption(getName()); m_horizontalLayout.setSizeFull(); } /** * Injects CSS styles in the current page */ private void injectWallboardStyles() { Page.getCurrent().getStyles() .add(".summary.cleared { background: #000000; border-left: 15px solid #858585; }"); Page.getCurrent().getStyles() .add(".summary.normal { background: #000000; border-left: 15px solid #336600; }"); Page.getCurrent().getStyles() .add(".summary.indeterminate { background: #000000; border-left: 15px solid #999; }"); Page.getCurrent().getStyles() .add(".summary.warning { background: #000000; border-left: 15px solid #FFCC00; }"); Page.getCurrent().getStyles() .add(".summary.minor { background: #000000; border-left: 15px solid #FF9900; }"); Page.getCurrent().getStyles() .add(".summary.major { background: #000000; border-left: 15px solid #FF3300; }"); Page.getCurrent().getStyles() .add(".summary.critical { background: #000000; border-left: 15px solid #CC0000; }"); Page.getCurrent().getStyles() .add(".summary.global { background: #000000; border-left: 15px solid #000000; }"); Page.getCurrent().getStyles().add(".summary { padding: 5px 5px; margin: 1px; }"); Page.getCurrent().getStyles().add( ".summary-font { font-size: 24px; line-height: normal; text-align: right; color: #3ba300; }"); Page.getCurrent().getStyles().add( ".summary-font-legend { font-size: 16px; line-height: normal; text-align: right; color: #3ba300; }"); } @Override public void refresh() { m_timeslot = 3600; try { m_timeslot = Math.max(1, Integer.parseInt(getDashletSpec().getParameters().get("timeslot"))); } catch (NumberFormatException numberFormatException) { /** * Just ignore */ } m_horizontalLayout.removeAllComponents(); injectWallboardStyles(); Component severity = getComponentSeverity(32); Component uei = getComponentUei(32); m_horizontalLayout.addComponent(severity); m_horizontalLayout.addComponent(uei); m_horizontalLayout.setSizeFull(); m_horizontalLayout.setComponentAlignment(severity, Alignment.TOP_CENTER); m_horizontalLayout.setComponentAlignment(uei, Alignment.TOP_CENTER); } @Override public Component getComponent() { return m_horizontalLayout; } @Override public boolean isBoosted() { return SummaryDashlet.this.m_boosted; } }; } return m_wallboardComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.SummaryDashlet.java
License:Open Source License
@Override public DashletComponent getDashboardComponent() { if (m_dashboardComponent == null) { m_dashboardComponent = new AbstractDashletComponent() { private HorizontalLayout m_horizontalLayout = new HorizontalLayout(); {// w w w . j a va 2 s . c o m m_horizontalLayout.setCaption(getName()); m_horizontalLayout.setSizeFull(); } /** * Injects CSS styles in the current page */ private void injectDashboardStyles() { Page.getCurrent().getStyles() .add(".summary.cleared { background: #000000; border-left: 8px solid #858585; }"); Page.getCurrent().getStyles() .add(".summary.normal { background: #000000; border-left: 8px solid #336600; }"); Page.getCurrent().getStyles() .add(".summary.indeterminate { background: #000000; border-left: 8px solid #999; }"); Page.getCurrent().getStyles() .add(".summary.warning { background: #000000; border-left: 8px solid #FFCC00; }"); Page.getCurrent().getStyles() .add(".summary.minor { background: #000000; border-left: 8px solid #FF9900; }"); Page.getCurrent().getStyles() .add(".summary.major { background: #000000; border-left: 8px solid #FF3300; }"); Page.getCurrent().getStyles() .add(".summary.critical { background: #000000; border-left: 8px solid #CC0000; }"); Page.getCurrent().getStyles() .add(".summary.global { background: #000000; border-left: 8px solid #000000; }"); Page.getCurrent().getStyles().add(".summary { padding: 5px 5px; margin: 1px; }"); Page.getCurrent().getStyles().add( ".summary-font { font-size: 17px; line-height: normal; text-align: right; color: #3ba300; }"); Page.getCurrent().getStyles().add( ".summary-font-legend { font-size: 9px; line-height: normal; text-align: right; color: #3ba300; }"); } @Override public void refresh() { m_timeslot = 3600; try { m_timeslot = Math.max(1, Integer.parseInt(getDashletSpec().getParameters().get("timeslot"))); } catch (NumberFormatException numberFormatException) { /** * Just ignore */ } m_horizontalLayout.removeAllComponents(); Accordion accordion = new Accordion(); accordion.setSizeFull(); injectDashboardStyles(); Component severity = getComponentSeverity(16); Component uei = getComponentUei(16); VerticalLayout v1 = new VerticalLayout(severity); v1.setSizeFull(); v1.setComponentAlignment(severity, Alignment.MIDDLE_CENTER); v1.setMargin(true); accordion.addTab(v1, "by Severity"); VerticalLayout v2 = new VerticalLayout(uei); v2.setSizeFull(); v2.setComponentAlignment(uei, Alignment.MIDDLE_CENTER); v2.setMargin(true); accordion.addTab(v2, "by Uei"); m_horizontalLayout.addComponent(accordion); } @Override public Component getComponent() { return m_horizontalLayout; } @Override public boolean isBoosted() { return SummaryDashlet.this.m_boosted; } }; } return m_dashboardComponent; }
From source file:org.opennms.features.vaadin.jmxconfiggenerator.ui.UIHelper.java
License:Open Source License
public static void showNotification(String title, String message, Type type, int delayMsec) { Notification notification = new Notification(title, message, type, true); notification.setDelayMsec(delayMsec); notification.show(Page.getCurrent()); }
From source file:org.opennms.features.vaadin.nodemaps.internal.NodeMapsApplication.java
License:Open Source License
private void addHeader() { if (m_headerProvider != null) { try {/*from w w w . ja v a 2 s.c o m*/ URL pageUrl = Page.getCurrent().getLocation().toURL(); setHeaderHtml(m_headerProvider.getHeaderHtml(new HttpServletRequestVaadinImpl(m_request, pageUrl))); } catch (final Exception e) { LOG.error("failed to get header HTML for request " + m_request.getPathInfo(), e.getCause()); } } if (m_headerHtml != null) { InputStream is = null; try { is = new ByteArrayInputStream(m_headerHtml.getBytes()); final CustomLayout headerLayout = new CustomLayout(is); headerLayout.setWidth("100%"); headerLayout.addStyleName("onmsheader"); m_rootLayout.addComponent(headerLayout); } catch (final IOException e) { closeQuietly(is); LOG.debug("failed to get header layout data", e); } } }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.dashboard.SurveillanceViewAlarmTable.java
License:Open Source License
/** * Constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used * @param enabled the flag should links be enabled? *///from ww w.j ava 2 s .c o m public SurveillanceViewAlarmTable(SurveillanceViewService surveillanceViewService, boolean enabled) { /** * calling the super constructor */ super("Alarms", surveillanceViewService, enabled); /** * set the datasource */ setContainerDataSource(m_beanItemContainer); /** * the base stylename */ addStyleName("surveillance-view"); /** * add node column */ addGeneratedColumn("nodeLabel", new ColumnGenerator() { @Override public Object generateCell(final Table table, final Object itemId, final Object propertyId) { final Alarm alarm = (Alarm) itemId; Button icon = getClickableIcon("glyphicon glyphicon-warning-sign", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/alarm/detail.htm?quiet=true&id=" + alarm.getId(); LOG.debug("alarm {} clicked, current location = {}, uri = {}", alarm.getId(), currentLocation, redirectFragment); try { SurveillanceViewAlarmTable.this.getUI() .addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new InfoWindow.LabelCreator() { @Override public String getLabel() { return "Alarm Info " + alarm.getId(); } })); } catch (MalformedURLException e) { LOG.error(e.getMessage(), e); } } }); Button button = new Button(alarm.getNodeLabel()); button.setPrimaryStyleName(BaseTheme.BUTTON_LINK); button.setEnabled(m_enabled); button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/element/node.jsp?quiet=true&node=" + alarm.getNodeId(); LOG.debug("node {} clicked, current location = {}, uri = {}", alarm.getNodeId(), currentLocation, redirectFragment); try { SurveillanceViewAlarmTable.this.getUI() .addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new InfoWindow.LabelCreator() { @Override public String getLabel() { return "Node Info " + alarm.getNodeId(); } })); } catch (MalformedURLException e) { LOG.error(e.getMessage(), e); } } }); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.addComponent(icon); horizontalLayout.addComponent(button); horizontalLayout.setSpacing(true); return horizontalLayout; } }); /** * add severity column */ addGeneratedColumn("severity", new ColumnGenerator() { @Override public Object generateCell(Table table, Object itemId, Object propertyId) { Alarm alarm = (Alarm) itemId; return getImageSeverityLayout(alarm.getSeverity()); } }); /** * set a cell style generator that handles the severity column */ setCellStyleGenerator(new CellStyleGenerator() { @Override public String getStyle(final Table source, final Object itemId, final Object propertyId) { Alarm alarm = ((Alarm) itemId); String style = alarm.getSeverity().toLowerCase(); if ("severity".equals(propertyId)) { style += "-image"; } return style; } }); /** * set column headers */ setColumnHeader("nodeLabel", "Node"); setColumnHeader("severity", "Severity"); setColumnHeader("uei", "UEI"); setColumnHeader("counter", "Count"); setColumnHeader("lastEventTime", "Last Time"); setColumnHeader("logMsg", "Log Msg"); setColumnExpandRatio("nodeLabel", 2.25f); setColumnExpandRatio("severity", 1.0f); setColumnExpandRatio("uei", 3.0f); setColumnExpandRatio("counter", 0.5f); setColumnExpandRatio("lastEventTime", 1.5f); setColumnExpandRatio("logMsg", 4.0f); /** * set visible columns */ setVisibleColumns("nodeLabel", "severity", "uei", "counter", "lastEventTime", "logMsg"); }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.dashboard.SurveillanceViewNodeRtcTable.java
License:Open Source License
/** * Constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used * @param enabled the flag should links be enabled? *///ww w .ja v a 2 s . c om public SurveillanceViewNodeRtcTable(SurveillanceViewService surveillanceViewService, boolean enabled) { /** * call the super constructor */ super("Outages", surveillanceViewService, enabled); /** * set the datasource */ setContainerDataSource(m_beanItemContainer); /** * set the base style name */ addStyleName("surveillance-view"); /** * add node column */ addGeneratedColumn("node", new ColumnGenerator() { @Override public Object generateCell(Table table, Object itemId, Object propertyId) { final SurveillanceViewService.NodeRtc nodeRtc = (SurveillanceViewService.NodeRtc) itemId; Button button = new Button(nodeRtc.getNode().getLabel()); button.setPrimaryStyleName(BaseTheme.BUTTON_LINK); button.setEnabled(m_enabled); button.addStyleName("white"); button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/element/node.jsp?quiet=true&node=" + nodeRtc.getNode().getId(); LOG.debug("node {} clicked, current location = {}, uri = {}", nodeRtc.getNode().getId(), currentLocation, redirectFragment); try { SurveillanceViewNodeRtcTable.this.getUI() .addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new InfoWindow.LabelCreator() { @Override public String getLabel() { return "Node Info " + nodeRtc.getNode().getId(); } })); } catch (MalformedURLException e) { LOG.error(e.getMessage(), e); } } }); return button; } }); /** * add currentOutages column */ addGeneratedColumn("currentOutages", new ColumnGenerator() { @Override public Object generateCell(Table table, final Object itemId, Object columnId) { SurveillanceViewService.NodeRtc nodeRtc = (SurveillanceViewService.NodeRtc) itemId; return getImageSeverityLayout(nodeRtc.getDownServiceCount() + " of " + nodeRtc.getServiceCount()); } }); /** * add availability column */ addGeneratedColumn("availability", new ColumnGenerator() { @Override public Object generateCell(Table table, final Object itemId, Object propertyId) { SurveillanceViewService.NodeRtc nodeRtc = (SurveillanceViewService.NodeRtc) itemId; return getImageSeverityLayout(nodeRtc.getAvailabilityAsString()); } }); /** * set cell style generator that handles the two severities for RTC calculations */ setCellStyleGenerator(new CellStyleGenerator() { @Override public String getStyle(Table table, Object itemId, Object propertyId) { String style = null; SurveillanceViewService.NodeRtc nodeRtc = (SurveillanceViewService.NodeRtc) itemId; if (!"node".equals(propertyId)) { if (nodeRtc.getAvailability() == 1.0) { style = "rtc-normal"; } else { style = "rtc-critical"; } } return style; } }); /** * set the column headers */ setColumnHeader("node", "Node"); setColumnHeader("currentOutages", "Current Outages"); setColumnHeader("availability", "24 Hour Availability"); setColumnExpandRatio("node", 1.0f); setColumnExpandRatio("currentOutages", 1.0f); setColumnExpandRatio("availability", 1.0f); /** * define the visible columns */ setVisibleColumns(new Object[] { "node", "currentOutages", "availability" }); }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.dashboard.SurveillanceViewNotificationTable.java
License:Open Source License
/** * Constructor for instantiating this component. * * @param surveillanceViewService the surveillance view service to be used * @param enabled the flag should links be enabled? *///from w w w . jav a 2 s . c o m public SurveillanceViewNotificationTable(SurveillanceViewService surveillanceViewService, boolean enabled) { /** * calling the super constructor */ super("Notifications", surveillanceViewService, enabled); /** * set the datasource */ setContainerDataSource(m_beanItemContainer); /** * set the base style name */ addStyleName("surveillance-view"); /** * add node column */ addGeneratedColumn("nodeLabel", new ColumnGenerator() { @Override public Object generateCell(final Table table, final Object itemId, final Object propertyId) { final Notification notification = (Notification) itemId; Button icon = getClickableIcon("glyphicon glyphicon-bell", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/notification/detail.jsp?quiet=true¬ice=" + notification.getId(); LOG.debug("notification {} clicked, current location = {}, uri = {}", notification.getId(), currentLocation, redirectFragment); try { SurveillanceViewNotificationTable.this.getUI() .addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new InfoWindow.LabelCreator() { @Override public String getLabel() { return "Notification Info " + notification.getId(); } })); } catch (MalformedURLException e) { LOG.error(e.getMessage(), e); } } }); Button button = new Button(notification.getNodeLabel()); button.setPrimaryStyleName(BaseTheme.BUTTON_LINK); button.setEnabled(m_enabled); button.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { final URI currentLocation = Page.getCurrent().getLocation(); final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath(); final String redirectFragment = contextRoot + "/element/node.jsp?quiet=true&node=" + notification.getNodeId(); ; LOG.debug("node {} clicked, current location = {}, uri = {}", notification.getNodeId(), currentLocation, redirectFragment); try { SurveillanceViewNotificationTable.this.getUI() .addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new InfoWindow.LabelCreator() { @Override public String getLabel() { return "Node Info " + notification.getNodeId(); } })); } catch (MalformedURLException e) { LOG.error(e.getMessage(), e); } } }); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.addComponent(icon); horizontalLayout.addComponent(button); horizontalLayout.setSpacing(true); return horizontalLayout; } }); /** * set the cell style generator */ setCellStyleGenerator(new CellStyleGenerator() { @Override public String getStyle(final Table source, final Object itemId, final Object propertyId) { Notification notification = ((Notification) itemId); return notification.getSeverity().toLowerCase(); } }); /** * set column headers */ setColumnHeader("nodeLabel", "Node"); setColumnHeader("serviceType", "Service"); setColumnHeader("textMsg", "Message"); setColumnHeader("pageTime", "Sent Time"); setColumnHeader("answeredBy", "Responder"); setColumnHeader("respondTime", "Respond Time"); setColumnExpandRatio("nodeLabel", 2.0f); setColumnExpandRatio("serviceType", 1.0f); setColumnExpandRatio("textMsg", 4.0f); setColumnExpandRatio("pageTime", 2.0f); setColumnExpandRatio("answeredBy", 1.0f); setColumnExpandRatio("respondTime", 2.0f); /** * define visible columns */ setVisibleColumns("nodeLabel", "serviceType", "textMsg", "pageTime", "answeredBy", "respondTime"); }
From source file:org.opennms.features.vaadin.surveillanceviews.ui.SurveillanceViewsUI.java
License:Open Source License
/** * {@inheritDoc}/*www .java 2 s .com*/ */ @Override protected void init(VaadinRequest request) { /** * Force the reload of the configuration */ SurveillanceViewProvider.getInstance().load(); /** * create a layout */ VerticalLayout rootLayout = new VerticalLayout(); rootLayout.setSpacing(true); /** * check query parameters for viewName, dashboard */ String viewName = request.getParameter("viewName"); boolean dashboard = request.getParameter("dashboard") != null && "true".equals(request.getParameter("dashboard")); /** * retrieve the username */ String username = request.getRemoteUser(); /** * now select the right view */ View view; if (viewName == null) { view = m_surveillanceViewService.selectDefaultViewForUsername(username); } else { view = SurveillanceViewProvider.getInstance().getView(viewName); } /** * set the poll interval */ setPollInterval(1000); /** * check for dashboard role */ boolean isDashboardRole = true; SecurityContext context = SecurityContextHolder.getContext(); if ((context != null) && !(context.toString().contains(org.opennms.web.api.Authentication.ROLE_DASHBOARD))) { isDashboardRole = false; } LOG.debug("User {} is in dashboard role? {}", username, isDashboardRole); /** * now construct the surveillance view/dashboard */ rootLayout.addComponent(new SurveillanceView(view, m_surveillanceViewService, dashboard, !isDashboardRole)); setContent(rootLayout); Page.getCurrent().getJavaScript().execute("function receiveMessage(event){\n" + "if(event.origin !== window.location.origin){ return; }\n" + "\n" + "event.source.postMessage( (document.getElementById('surveillance-window').offsetHeight + 17) + 'px', window.location.origin )\n" + "}\n" + "window.addEventListener(\"message\", receiveMessage, false);"); }
From source file:org.ripla.web.controllers.AbstractController.java
License:Open Source License
private void checkRoles() throws PermissionsNotSufficientException { if (userAdmin == null) { return;/*from w w w . java2s . c o m*/ } final Authorization lAuthorization = userAdmin.getAuthorization(getUser()); if (lAuthorization == null) { return; } if (needsPermission().isEmpty()) { return; } if (!lAuthorization.hasRole(needsPermission())) { final StringBuilder lLogMsg = new StringBuilder( "Note: The user has not sufficient permissions for the requested task.\n"); //$NON-NLS-1$ lLogMsg.append(" User: ").append(getUser().getName()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ lLogMsg.append(" IP number: ").append(Page.getCurrent().getWebBrowser().getAddress()).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ LOG.warn(new String(lLogMsg)); throw new PermissionsNotSufficientException(); } }
From source file:org.ripla.web.controllers.RiplaBody.java
License:Open Source License
/** * Arranges the body window's views (i.e. <code>header</code>, * <code>footer</code>, <code>toolbar</code>, <code>menubar</code>, * <code>sidebar</code>, <code>content</code>).<br /> * Subclasses may override for a different arrangement of the views. *//*from ww w . j a v a2 s . c o m*/ protected void initializeLayout() { Page.getCurrent().setTitle(application.getAppName()); if (skin.hasHeader()) { final Component lHeader = skin.getHeader(application.getAppName()); layout.addComponent(lHeader); layout.setExpandRatio(lHeader, 0); } if (skin.hasToolBar()) { final Component lToolbar = createToolbar(skin.getToolbarSeparator()); layout.addComponent(lToolbar); } if (skin.hasMenuBar()) { final Component lMenubar = createMenubar(skin.getMenuBarMedium(), skin.getMenuBar(), skin.getSubMenuIcon()); layout.addComponent(lMenubar); } final HorizontalSplitPanel lPanel = new HorizontalSplitPanel(); layout.addComponent(lPanel); layout.setExpandRatio(lPanel, 1); lPanel.setSplitPosition(10, Unit.PERCENTAGE); // lPanel.setHeight(SIZE_UNDEFINED, Unit.PIXELS); lPanel.setStyleName("ripla-split"); //$NON-NLS-1$ sidebar = new VerticalLayout(); sidebar.setStyleName("ripla-sidebar"); sidebar.setSizeFull(); lPanel.setFirstComponent(sidebar); content = new VerticalLayout(); content.setStyleName("ripla-content"); lPanel.setSecondComponent(content); content.setMargin(true); lPanel.setSizeFull(); layout.setSizeFull(); }