Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

In this page you can find the example usage for com.vaadin.server Page getCurrent.

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

From source file:org.opencms.ui.report.CmsReportOverlay.java

License:Open Source License

/**
 * Constructor.<p>/*from w w w .j a  va 2 s.  co m*/
 *
 * @param thread the report thread
 */
public CmsReportOverlay(A_CmsReportThread thread) {
    setId(RandomStringUtils.randomAlphabetic(8));

    try {
        @SuppressWarnings("resource")
        InputStream layoutStream = CmsVaadinUtils.readCustomLayout(getClass(), "reportoverlay.html");
        initTemplateContentsFromInputStream(layoutStream);
    } catch (IOException e) {
        LOG.error(e.getLocalizedMessage(), e);
    }

    m_report = new CmsReportWidget(thread);
    m_report.setWidth("100%");
    m_report.setHeight((Page.getCurrent().getBrowserWindowHeight() - 200) + "px");
    CmsBasicDialog dialogContent = new CmsBasicDialog();
    dialogContent.setContent(m_report);
    addComponent(dialogContent, "content");

    m_report.addReportFinishedHandler(new Runnable() {

        public void run() {

            setVisible(false);
        }
    });
    // add a timeout to show the report window
    JavaScript.eval("setTimeout(function(){ " + "var el= document.getElementById('" + getId()
            + "'); if (el!=null) el.classList.add('o-report-show'); }," + REPORT_VIEW_DELAY + ")");
}

From source file:org.opennms.features.pluginmgr.vaadin.config.karaf.PluginManagerAdminApplication.java

License:Apache License

@Override
public void init(VaadinRequest request) {

    m_request = request;/*  w w w . j  a v  a2 s  . co m*/

    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;  }");

    // add header if provided
    if (headerComponent != null)
        m_rootLayout.addComponent(headerComponent);

    //add additional header page links if provided
    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);
            Label label = new Label("&nbsp;&nbsp;&nbsp;", ContentMode.HTML); // adds space between links
            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);

}

From source file:org.opennms.features.pluginmgr.vaadin.config.opennms.PluginManagerAdminApplication.java

License:Open Source License

@Override
public void init(VaadinRequest request) {

    m_rootLayout = new VerticalLayout();
    m_rootLayout.setSizeFull();/*from   w w w  . j  a v a 2s. c  o  m*/
    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);
            Label label = new Label("&nbsp;&nbsp;&nbsp;", ContentMode.HTML); // adds space between links
            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);

}

From source file:org.opennms.features.topology.api.AbstractOperation.java

License:Open Source License

protected String getFullUrl(final String urlFragment) {
    final URI currentLocation = Page.getCurrent().getLocation();
    final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath();
    try {//w  w w  .j a  v a 2  s . c  om
        return new URL(currentLocation.toURL(), contextRoot + "/" + urlFragment).toString();
    } catch (final MalformedURLException e) {
        throw new RuntimeException("Failed to create full URL from current location: " + currentLocation
                + ", context root: " + contextRoot + ", url: " + urlFragment);
    }
}

From source file:org.opennms.features.topology.app.internal.support.IconRepositoryManager.java

License:Open Source License

@Override
public List<String> getSVGIconFiles() {
    List<String> svgUrls = Lists.newArrayList();
    try {/*from ww w.  j  a v  a  2  s.  c om*/
        URI location = Page.getCurrent().getLocation();
        URL url = new URL(location.getScheme(), location.getHost(), location.getPort(), "/opennms");
        Path path = Paths.get(System.getProperty("opennms.home", ""), "jetty-webapps", "opennms", "svg");
        File[] files = path.toFile().listFiles((file) -> file.isFile() && file.getName().endsWith(".svg"));
        for (File eachFile : files) {
            svgUrls.add(String.format("%s/svg/%s", url, eachFile.getName()));
        }
    } catch (MalformedURLException e) {
        LoggerFactory.getLogger(this.getClass()).error("Error while loading SVG definitions", e);
    }
    return svgUrls;
}

From source file:org.opennms.features.topology.app.internal.ui.NodeInfoWindow.java

License:Open Source License

private static URL getURL(int nodeId) {
    final URI currentLocation = Page.getCurrent().getLocation();
    final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath();
    final String redirectFragment = contextRoot + "/element/node.jsp?node=" + nodeId;
    try {//from  ww  w.  j a  v a2s.com
        return new URL(currentLocation.toURL(), redirectFragment);
    } catch (MalformedURLException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.opennms.features.topology.netutils.internal.operations.EventsAlarmsOperation.java

License:Open Source License

@Override
public Undoer execute(final List<VertexRef> targets, final OperationContext operationContext) {
    String label = "";
    int nodeID = -1;

    try {//from   w  w w  .j  a  va2  s .c  o m
        if (targets != null) {
            for (final VertexRef target : targets) {
                final String labelValue = getLabelValue(operationContext, target);
                final Integer nodeValue = getNodeIdValue(operationContext, target);

                if (nodeValue != null && nodeValue > 0) {
                    label = labelValue == null ? "" : labelValue;
                    nodeID = nodeValue;
                }
            }
        }

        final Node node = new Node(nodeID, null, label);

        final URL baseURL = Page.getCurrent().getLocation().toURL();

        final URL eventsURL;
        final URL alarmsURL;
        if (node.getNodeID() >= 0) {
            eventsURL = new URL(baseURL, getEventsURL() + "?filter=node%3D" + node.getNodeID());
            alarmsURL = new URL(baseURL,
                    getAlarmsURL() + "?sortby=id&acktype=unacklimit=20&filter=node%3D" + node.getNodeID());
        } else {
            eventsURL = new URL(baseURL, getEventsURL());
            alarmsURL = new URL(baseURL, getAlarmsURL());
        }

        operationContext.getMainWindow().addWindow(new EventsAlarmsWindow(node, eventsURL, alarmsURL));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.opennms.features.topology.netutils.internal.operations.NodeInfoOperation.java

License:Open Source License

@Override
public Undoer execute(final List<VertexRef> targets, final OperationContext operationContext) {
    String label = "";
    int nodeID = -1;

    try {//from  www  .  ja  v a2  s. c om
        if (targets != null) {
            for (final VertexRef target : targets) {
                final String labelValue = getLabelValue(operationContext, target);
                final Integer nodeValue = getNodeIdValue(operationContext, target);

                if (nodeValue != null && nodeValue > 0) {
                    label = labelValue == null ? "" : labelValue;
                    nodeID = nodeValue.intValue();
                }
            }
        }

        final Node node = new Node(nodeID, null, label);

        final URL baseURL = Page.getCurrent().getLocation().toURL();

        final URL nodeURL;
        if (node.getNodeID() >= 0) {
            nodeURL = new URL(baseURL, getNodePageURL() + "" + node.getNodeID());
        } else {
            nodeURL = new URL(baseURL, getNodeListURL());
        }

        operationContext.getMainWindow().addWindow(new NodeInfoWindow(node, nodeURL));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.opennms.features.topology.netutils.internal.operations.ResourceGraphsOperation.java

License:Open Source License

@Override
public Undoer execute(final List<VertexRef> targets, final OperationContext operationContext) {
    String label = "";
    int nodeID = -1;

    try {//from  w  w w. java2  s.  c  o m
        if (targets != null) {
            for (final VertexRef target : targets) {
                final String labelValue = getLabelValue(operationContext, target);
                final Integer nodeValue = getNodeIdValue(operationContext, target);

                if (nodeValue != null && nodeValue > 0) {
                    label = labelValue == null ? "" : labelValue;
                    nodeID = nodeValue.intValue();
                }
            }
        }
        final Node node = new Node(nodeID, null, label);

        final URL baseURL = Page.getCurrent().getLocation().toURL();

        final URL nodeURL;

        if (node.getNodeID() >= 0) {
            nodeURL = new URL(baseURL, getResourceGraphNodeURL() + "[" + node.getNodeID() + "]");
        } else {
            nodeURL = new URL(baseURL, getResourceGraphListURL());
        }

        operationContext.getMainWindow().addWindow(new ResourceGraphsWindow(node, nodeURL));
    } catch (final Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.opennms.features.topology.plugins.browsers.AlarmIdColumnLinkGenerator.java

License:Open Source License

@Override
public Object generateCell(final Table source, Object itemId, Object columnId) {
    if (source == null)
        return null; // no source
    Property<Integer> alarmIdProperty = source.getContainerProperty(itemId, alarmIdPropertyName);
    final Integer alarmId = alarmIdProperty.getValue();
    if (alarmId == null)
        return null; // no value

    // create Link
    Button button = new Button("" + alarmId);
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new ClickListener() {
        private static final long serialVersionUID = 3698209256202413810L;

        @Override//from w ww .j ava 2s  .  c o  m
        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;
}