List of usage examples for com.vaadin.server ExternalResource ExternalResource
public ExternalResource(String sourceURL)
From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsConfigurationWindow.java
License:Open Source License
/** * Constructor for instantiating new objects of this class. * * @param dashletSpec the {@link DashletSpec} to be edited *//* w w w .j a va 2 s .co m*/ public ChartsConfigurationWindow(DashletSpec dashletSpec) { /** * Setting the members */ m_dashletSpec = dashletSpec; /** * Setting up the base layouts */ setHeight(410, Unit.PIXELS); setWidth(40, Unit.PERCENTAGE); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setWidth(100, Unit.PERCENTAGE); horizontalLayout.setSpacing(true); horizontalLayout.setMargin(true); FormLayout formLayout = new FormLayout(); formLayout.setWidth(100, Unit.PERCENTAGE); formLayout.setSpacing(true); formLayout.setMargin(true); /** * Adding the checkboxes */ m_maximizeWidth = new CheckBox(); m_maximizeWidth.setCaption("Maximize width"); m_maximizeWidth.setDescription("Maximize width"); m_maximizeHeight = new CheckBox(); m_maximizeHeight.setCaption("Maximize height"); m_maximizeHeight.setDescription("Maximize height"); String maximizeWidthString = m_dashletSpec.getParameters().get("maximizeWidth"); String maximizeHeightString = m_dashletSpec.getParameters().get("maximizeHeight"); boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString) || "1".equals(maximizeHeightString)); boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString) || "1".equals(maximizeWidthString)); m_maximizeWidth.setValue(maximizeWidth); m_maximizeHeight.setValue(maximizeHeight); m_chartSelect = new NativeSelect(); m_chartSelect.setDescription("Select chart to be displayed"); m_chartSelect.setCaption("Chart"); m_chartSelect.setNullSelectionAllowed(false); m_chartSelect.setInvalidAllowed(false); m_chartSelect.setNewItemsAllowed(false); String firstChartName = null; try { Iterator<BarChart> it = ChartUtils.getChartCollectionIterator(); while (it.hasNext()) { BarChart chartConfig = (BarChart) it.next(); if (firstChartName == null) { firstChartName = chartConfig.getName(); } m_chartSelect.addItem(chartConfig.getName()); } } catch (Exception e) { e.printStackTrace(); } String chartName = m_dashletSpec.getParameters().get("chart"); if (chartName == null || "".equals(chartName)) { chartName = firstChartName; } final Panel panel = new Panel(); panel.setWidth(230, Unit.PIXELS); panel.setCaption("Preview"); formLayout.addComponent(m_chartSelect); Page.getCurrent().getStyles().add(".preview { width:225px; }"); m_chartSelect.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { String newImage = "/opennms/charts?chart-name=" + valueChangeEvent.getProperty().getValue(); Image image = new Image(null, new ExternalResource(newImage)); image.setStyleName("preview"); panel.setContent(image); } }); m_chartSelect.setValue(chartName); m_chartSelect.setImmediate(true); formLayout.addComponent(m_maximizeWidth); formLayout.addComponent(m_maximizeHeight); horizontalLayout.addComponent(formLayout); horizontalLayout.addComponent(panel); /** * Using an additional {@link com.vaadin.ui.HorizontalLayout} for layouting the buttons */ HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setMargin(true); buttonLayout.setSpacing(true); buttonLayout.setWidth("100%"); /** * Adding the cancel button... */ Button cancel = new Button("Cancel"); cancel.setDescription("Cancel editing"); cancel.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { close(); } }); cancel.setClickShortcut(ShortcutAction.KeyCode.ESCAPE, null); buttonLayout.addComponent(cancel); buttonLayout.setExpandRatio(cancel, 1.0f); buttonLayout.setComponentAlignment(cancel, Alignment.TOP_RIGHT); /** * ...and the OK button */ Button ok = new Button("Save"); ok.setDescription("Save properties and close"); ok.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { m_dashletSpec.getParameters().put("maximizeWidth", (m_maximizeWidth.getValue() ? "true" : "false")); m_dashletSpec.getParameters().put("maximizeHeight", (m_maximizeHeight.getValue() ? "true" : "false")); m_dashletSpec.getParameters().put("chart", String.valueOf(m_chartSelect.getValue())); WallboardProvider.getInstance().save(); ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Properties"); close(); } }); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER, null); buttonLayout.addComponent(ok); /** * Adding the layout and setting the content */ //verticalLayout.addComponent(buttonLayout); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.addComponent(horizontalLayout); verticalLayout.addComponent(buttonLayout); setContent(verticalLayout); }
From source file:org.opennms.features.vaadin.dashboard.dashlets.ChartsDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {//from w w w. j ava2 s.c o m m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { String newImage = "/opennms/charts?chart-name=" + getDashletSpec().getParameters().get("chart"); String maximizeHeightString = getDashletSpec().getParameters().get("maximizeHeight"); String maximizeWidthString = getDashletSpec().getParameters().get("maximizeWidth"); boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString) || "1".equals(maximizeHeightString)); boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString) || "1".equals(maximizeWidthString)); if (!newImage.equals(m_imageUrl)) { m_imageUrl = newImage; m_verticalLayout.removeAllComponents(); Image image = new Image(null, new ExternalResource(m_imageUrl)); if (maximizeHeight && maximizeWidth) { image.setSizeFull(); } else { if (maximizeHeight) { image.setHeight(100, Sizeable.Unit.PERCENTAGE); } if (maximizeWidth) { image.setWidth(100, Sizeable.Unit.PERCENTAGE); } } m_verticalLayout.addComponent(image); m_verticalLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER); } } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.ImageDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {//w w w. j av a2s.c om m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { String newImage = getDashletSpec().getParameters().get("imageUrl"); String maximizeHeightString = getDashletSpec().getParameters().get("maximizeHeight"); String maximizeWidthString = getDashletSpec().getParameters().get("maximizeWidth"); boolean maximizeHeight = ("true".equals(maximizeHeightString) || "yes".equals(maximizeHeightString) || "1".equals(maximizeHeightString)); boolean maximizeWidth = ("true".equals(maximizeWidthString) || "yes".equals(maximizeWidthString) || "1".equals(maximizeWidthString)); if (!newImage.equals(m_imageUrl)) { m_imageUrl = newImage; m_verticalLayout.removeAllComponents(); Image image = new Image(null, new ExternalResource(m_imageUrl)); if (maximizeHeight && maximizeWidth) { image.setSizeFull(); } else { if (maximizeHeight) { image.setHeight(100, Sizeable.Unit.PERCENTAGE); } if (maximizeWidth) { image.setWidth(100, Sizeable.Unit.PERCENTAGE); } } m_verticalLayout.addComponent(image); m_verticalLayout.setComponentAlignment(image, Alignment.MIDDLE_CENTER); } } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.MapDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {/*from www. jav a 2 s .c o m*/ m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { m_verticalLayout.removeAllComponents(); String searchString = ""; if (getDashletSpec().getParameters().containsKey("search")) { searchString = getDashletSpec().getParameters().get("search"); } BrowserFrame browserFrame = new BrowserFrame(null, new ExternalResource("/opennms/node-maps#search/" + searchString)); browserFrame.setSizeFull(); m_verticalLayout.addComponent(browserFrame); } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.RtcDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {//w w w . jav a2s. c o m m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { m_verticalLayout.removeAllComponents(); m_browserFrame = new BrowserFrame(null, new ExternalResource("/opennms/rtc/fullscreen-categories-box.jsp")); m_browserFrame.setSizeFull(); m_verticalLayout.addComponent(m_browserFrame); } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.SurveillanceDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {//from www. jav a 2 s. c o m m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { m_verticalLayout.removeAllComponents(); String viewName = "default"; if (getDashletSpec().getParameters().containsKey("viewName")) { viewName = getDashletSpec().getParameters().get("viewName"); } /** * creating browser frame to display node-maps */ BrowserFrame browserFrame = new BrowserFrame(null, new ExternalResource( "/opennms/osgi/vaadin-surveillance-views?dashboard=false&viewName=" + viewName)); browserFrame.setSizeFull(); m_verticalLayout.addComponent(browserFrame); } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.TopologyDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {// w ww . ja v a 2s . com m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { m_verticalLayout.removeAllComponents(); String focusNodes = ""; String szl = ""; String provider = ""; if (getDashletSpec().getParameters().containsKey("focusNodes")) { focusNodes = getDashletSpec().getParameters().get("focusNodes"); } if (getDashletSpec().getParameters().containsKey("szl")) { szl = getDashletSpec().getParameters().get("szl"); } if (getDashletSpec().getParameters().containsKey("provider")) { provider = getDashletSpec().getParameters().get("provider"); } String query = ""; if (!"".equals(focusNodes)) { query += "focusNodes=" + focusNodes + "&"; } if (!"".equals(szl)) { query += "szl=" + szl + "&"; } if (!"".equals(provider)) { query += "provider=" + provider + "&"; } /** * creating browser frame to display the topology */ BrowserFrame browserFrame = new BrowserFrame(null, new ExternalResource("/opennms/topology?" + query)); browserFrame.setSizeFull(); m_verticalLayout.addComponent(browserFrame); } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.features.vaadin.dashboard.dashlets.UrlDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {/*from w w w .ja v a 2 s . co m*/ m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { m_verticalLayout.removeAllComponents(); String url = ""; String username = ""; String password = ""; if (getDashletSpec().getParameters().containsKey("url")) { url = getDashletSpec().getParameters().get("url"); } if (getDashletSpec().getParameters().containsKey("username")) { username = getDashletSpec().getParameters().get("username"); } if (getDashletSpec().getParameters().containsKey("password")) { password = getDashletSpec().getParameters().get("password"); } String usernamePassword = ""; if (!"".equals(username) && !"".equals(password)) { usernamePassword = username + ":" + password; } if (!"".equals(url)) { /** * Try to parse the given URL... */ URL parsedUrl = null; try { parsedUrl = new URL(url); } catch (MalformedURLException e) { m_verticalLayout.addComponent(new Label("MalformedURLException: " + e.getMessage())); return; } /** * If successful, construct a wellformed URL including the basic auth credentials */ URL urlWithAuth = null; try { urlWithAuth = new URI(parsedUrl.getProtocol(), usernamePassword, parsedUrl.getHost(), parsedUrl.getPort() == -1 ? parsedUrl.getDefaultPort() : parsedUrl.getPort(), parsedUrl.getPath(), parsedUrl.getQuery(), parsedUrl.getRef()).toURL(); } catch (MalformedURLException e) { m_verticalLayout.addComponent(new Label("MalformedURLException: " + e.getMessage())); return; } catch (URISyntaxException e) { m_verticalLayout.addComponent(new Label("URISyntaxException: " + e.getMessage())); return; } /** * creating browser frame to display the URL */ BrowserFrame browserFrame = new BrowserFrame(null, new ExternalResource(urlWithAuth)); browserFrame.setSizeFull(); m_verticalLayout.addComponent(browserFrame); } else { m_verticalLayout.addComponent(new Label("No URL specified!")); } } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.features.vaadin.pmatrix.dashlet.PmatrixDashlet.java
License:Open Source License
@Override public DashletComponent getWallboardComponent() { if (m_dashletComponent == null) { m_dashletComponent = new AbstractDashletComponent() { private VerticalLayout m_verticalLayout = new VerticalLayout(); {//w w w . jav a2s . c o m m_verticalLayout.setCaption(getName()); m_verticalLayout.setSizeFull(); } @Override public void refresh() { m_verticalLayout.removeAllComponents(); String searchString = ""; if (getDashletSpec().getParameters().containsKey("uiComponent")) { searchString = getDashletSpec().getParameters().get("uiComponent"); } BrowserFrame browserFrame = new BrowserFrame(null, new ExternalResource("/opennms/vaadin-pmatrix/?uiComponent=" + searchString)); browserFrame.setSizeFull(); m_verticalLayout.addComponent(browserFrame); } @Override public Component getComponent() { return m_verticalLayout; } }; } return m_dashletComponent; }
From source file:org.opennms.netmgt.bsm.vaadin.adminpage.BusinessServiceTreeTable.java
License:Open Source License
public BusinessServiceTreeTable(BusinessServiceManager businessServiceManager) { this.businessServiceManager = Objects.requireNonNull(businessServiceManager); setSizeFull();/*w w w. j a v a 2 s . com*/ setContainerDataSource(new BusinessServiceContainer()); // Add the "LINKS" columns addGeneratedColumn("links", new Table.ColumnGenerator() { private static final long serialVersionUID = 7113848887128656685L; @Override public Object generateCell(Table source, Object itemId, Object columnId) { final HorizontalLayout layout = new HorizontalLayout(); final BusinessServiceStateMachine stateMachine = businessServiceManager.getStateMachine(); final BusinessService businessService = getItem(itemId).getBean().getBusinessService(); final Status status = stateMachine.getOperationalStatus(businessService); if (status != null) { // Build the query string final List<BasicNameValuePair> urlParms = Lists.newArrayList( new BasicNameValuePair("focus-vertices", businessService.getId().toString()), new BasicNameValuePair("szl", "1"), new BasicNameValuePair("layout", "Hierarchy Layout"), new BasicNameValuePair("provider", "Business Services")); final String queryString = URLEncodedUtils.format(urlParms, Charset.forName("UTF-8")); // Generate the link final Link link = new Link("View in Topology UI", new ExternalResource(String.format("/opennms/topology?%s", queryString))); link.setIcon(FontAwesome.EXTERNAL_LINK_SQUARE); // This app is typically access in an iframe, so we open the URL in a new window/tab link.setTargetName("_blank"); layout.addComponent(link); layout.setComponentAlignment(link, Alignment.MIDDLE_CENTER); } else { Label label = new Label("N/A"); label.setDescription("Try reloading the daemon and refreshing the table."); label.setWidth(null); layout.addComponent(label); } return layout; } }); // add edit and delete buttons addGeneratedColumn("edit / delete", new Table.ColumnGenerator() { private static final long serialVersionUID = 7113848887128656685L; @Override public Object generateCell(Table source, Object itemId, Object columnId) { HorizontalLayout layout = new HorizontalLayout(); layout.setSpacing(true); Button editButton = new Button("Edit", FontAwesome.PENCIL_SQUARE_O); editButton.setId("editButton-" + getItem(itemId).getBean().getName()); editButton.addClickListener(UIHelper.getCurrent(TransactionAwareUI.class) .wrapInTransactionProxy((Button.ClickListener) event -> { final Long businessServiceId = getItem(itemId).getBean().getBusinessService().getId(); BusinessService businessService = businessServiceManager .getBusinessServiceById(businessServiceId); final BusinessServiceEditWindow window = new BusinessServiceEditWindow(businessService, businessServiceManager); window.addCloseListener(e -> refresh()); getUI().addWindow(window); })); layout.addComponent(editButton); Button deleteButton = new Button("Delete", FontAwesome.TRASH_O); deleteButton.setId("deleteButton-" + getItem(itemId).getBean().getName()); deleteButton.addClickListener((Button.ClickListener) event -> { final Long businessServiceId = getItem(itemId).getBean().getBusinessService().getId(); BusinessService businessService = businessServiceManager .getBusinessServiceById(businessServiceId); if (businessService.getParentServices().isEmpty() && businessService.getChildEdges().isEmpty()) { UIHelper.getCurrent(TransactionAwareUI.class).runInTransaction(() -> { businessServiceManager.getBusinessServiceById(businessServiceId).delete(); refresh(); }); } else { new org.opennms.netmgt.vaadin.core.ConfirmationDialog() .withOkAction((org.opennms.netmgt.vaadin.core.ConfirmationDialog.Action) UIHelper .getCurrent(TransactionAwareUI.class).wrapInTransactionProxy( new org.opennms.netmgt.vaadin.core.ConfirmationDialog.Action() { @Override public void execute( org.opennms.netmgt.vaadin.core.ConfirmationDialog window) { businessServiceManager .getBusinessServiceById(businessServiceId).delete(); refresh(); } })) .withOkLabel("Delete anyway").withCancelLabel("Cancel").withCaption("Warning") .withDescription( "This entry is referencing or is referenced by other Business Services! Do you really want to delete this entry?") .open(); } }); layout.addComponent(deleteButton); return layout; } }); setColumnExpandRatio("name", 5); setColumnExpandRatio("links", 1); setColumnExpandRatio("edit / delete", 1); }