Example usage for com.vaadin.server VaadinServlet getCurrent

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

Introduction

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

Prototype

public static VaadinServlet getCurrent() 

Source Link

Document

Gets the currently used Vaadin servlet.

Usage

From source file:org.jumpmind.vaadin.ui.common.CommonUiUtils.java

License:Open Source License

public static AceEditor createAceEditor() {
    AceEditor editor = new AceEditor();
    editor.setSizeFull();/*  ww  w . ja  va  2 s .  c o  m*/
    editor.setImmediate(true);
    ServletContext context = VaadinServlet.getCurrent().getServletContext();
    if (context.getRealPath("/ace") != null) {
        String acePath = context.getContextPath() + "/ace";
        editor.setThemePath(acePath);
        editor.setModePath(acePath);
        editor.setWorkerPath(acePath);
    } else {
        log.warn("Could not find a local version of the ace editor.  "
                + "You might want to consider installing the ace web artifacts at " + context.getRealPath(""));
    }
    editor.setTextChangeEventMode(TextChangeEventMode.EAGER);
    editor.setHighlightActiveLine(true);
    editor.setShowPrintMargin(false);
    return editor;
}

From source file:org.opencms.ui.A_CmsCustomComponent.java

License:Open Source License

/**
 * Returns the current cms context.<p>
 *
 * @return the current cms context/*from   w  w  w  .  j  a v  a2  s  .c o m*/
 */
public CmsObject getCmsObject() {

    return ((CmsUIServlet) VaadinServlet.getCurrent()).getCmsObject();
}

From source file:org.opencms.ui.A_CmsUI.java

License:Open Source License

/**
 * Returns the current cms context.<p>
 *
 * @return the current cms context/*w w w.ja va2s .  c o  m*/
 */
public static CmsObject getCmsObject() {

    return ((CmsUIServlet) VaadinServlet.getCurrent()).getCmsObject();
}

From source file:org.opencms.ui.editors.messagebundle.CmsMessageBundleEditor.java

License:Open Source License

/**
 * @see org.opencms.ui.editors.I_CmsEditor#initUI(org.opencms.ui.apps.I_CmsAppUIContext, org.opencms.file.CmsResource, java.lang.String)
 *///  w  ww.j  a  v  a  2s .c  o m
public void initUI(I_CmsAppUIContext context, CmsResource resource, String backLink) {

    m_cms = ((CmsUIServlet) VaadinServlet.getCurrent()).getCmsObject();
    m_messages = Messages.get().getBundle(UI.getCurrent().getLocale());
    m_resource = resource;
    m_backLink = backLink;
    m_context = context;

    try {
        m_model = new CmsMessageBundleEditorModel(m_cms, m_resource);
        m_options = new CmsMessageBundleEditorOptions(m_model.getLocales(), m_model.getLocale(),
                m_model.getEditMode(), this);
        m_options.setEditedFilePath(m_model.getEditedFilePath());
        m_configurableMessages = m_model.getConfigurableMessages(m_messages, UI.getCurrent().getLocale());

        fillToolBar(context);
        context.showInfoArea(false);

        Component main = createMainComponent();

        initFieldFactories();
        initStyleGenerators();

        m_table.setTableFieldFactory(m_fieldFactories.get(m_model.getEditMode()));
        m_table.setCellStyleGenerator(m_styleGenerators.get(m_model.getEditMode()));

        m_optionsColumn.registerItemDeletionListener(this);

        adjustVisibleColumns();

        context.setAppContent(main);

        adjustFocus();

        if (m_model.getSwitchedLocaleOnOpening()) {
            CmsMessageBundleEditorTypes.showWarning(
                    m_messages.key(Messages.GUI_NOTIFICATION_MESSAGEBUNDLEEDITOR_SWITCHED_LOCALE_CAPTION_0),
                    m_messages
                            .key(Messages.GUI_NOTIFICATION_MESSAGEBUNDLEEDITOR_SWITCHED_LOCALE_DESCRIPTION_0));
        }

    } catch (IOException | CmsException e) {
        LOG.error(m_messages.key(Messages.ERR_LOADING_RESOURCES_0), e);
        Notification.show(m_messages.key(Messages.ERR_LOADING_RESOURCES_0), Type.ERROR_MESSAGE);
        closeAction();
    }

}

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 {//from   www  .j  a v  a  2  s.c o  m
        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.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   w ww .ja  va2  s  .c o m
        return new URL(currentLocation.toURL(), redirectFragment);
    } catch (MalformedURLException e) {
        throw Throwables.propagate(e);
    }
}

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  w w. jav  a  2  s.  com*/
        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;
}

From source file:org.opennms.features.vaadin.nodemaps.internal.NodeMapQueryLink.java

License:Open Source License

@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
    final Collection<VertexRef> availableNodes = m_geoAssetProvider.getNodesWithCoordinates();

    final StringBuilder sb = new StringBuilder();
    sb.append(VaadinServlet.getCurrent().getServletContext().getContextPath());
    sb.append("/node-maps#search/nodeId%20in%20");

    final List<String> nodeIds = new ArrayList<String>();
    for (final VertexRef ref : targets) {
        if (availableNodes.contains(ref)) {
            nodeIds.add(ref.getId());//from   w  w  w  .  j  a v  a2 s . com
        }
    }

    final Iterator<String> i = nodeIds.iterator();
    while (i.hasNext()) {
        sb.append(i.next());
        if (i.hasNext()) {
            sb.append(",");
        }
    }

    final String redirectUrl = sb.toString();
    LOG.info("redirecting to: " + redirectUrl);
    final UI ui = operationContext.getMainWindow();
    ui.getPage().getJavaScript().execute("window.location = '" + redirectUrl + "';");
}

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?
 */// w w  w.j av a  2s  .c  om
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?
 *///from   w w w. j a v  a2  s. c o  m
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" });
}