List of usage examples for com.vaadin.ui Window Window
public Window(String caption)
From source file:org.openeos.services.ui.vaadin.internal.UIApplicationImpl.java
License:Apache License
@Override public <U> UIDialog showGenericFormDialog(BForm<U> form, U bean) { Map<String, Object> extraObjects = new HashMap<String, Object>(); extraObjects.put(UIVaadinFormToolkit.EXTRA_OBJECT_APPLICATION, this); VaadinBindingFormInstance formInstance = vaadinToolkit.buildForm(form, commonBindingToolkit, extraObjects, false);/* w w w. j av a 2 s.c o m*/ Window window = new Window(form.getName()); window.setModal(true); window.addComponent((ComponentContainer) formInstance.getImplementation()); formInstance.setValue(bean); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth(100, HorizontalLayout.UNITS_PERCENTAGE); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button buttonOk = new Button("Ok"); buttons.addComponent(buttonOk); Button buttonCancel = new Button("Cancel"); buttons.addComponent(buttonCancel); footer.addComponent(buttons); footer.setComponentAlignment(buttons, Alignment.MIDDLE_RIGHT); window.addComponent(footer); ((VerticalLayout) window.getContent()).setComponentAlignment(footer, Alignment.BOTTOM_CENTER); window.getContent().setSizeFull(); vaadinApplication.getMainWindow().addWindow(window); return new UIDialogImpl(window, buttonOk, buttonCancel, formInstance); }
From source file:org.openeos.services.ui.vaadin.internal.UIApplicationImpl.java
License:Apache License
private <T> UIDialog showFormDialog(Class<T> modelClass, UIBean model, BindingFormCapability capability) { AbstractFormBindingForm<T> form = formRegistryService.getDefaultForm(modelClass, AbstractFormBindingForm.class, capability); Map<String, Object> extraObjects = new HashMap<String, Object>(); extraObjects.put(UIVaadinFormToolkit.EXTRA_OBJECT_APPLICATION, this); VaadinBindingFormInstance formInstance = vaadinToolkit.buildForm(form.getAbstractBForm(), uiBeanBindingToolkit, extraObjects, false); Window window = new Window(form.getAbstractBForm().getName()); window.setModal(true);/*w ww. j av a2 s. c o m*/ window.addComponent((ComponentContainer) formInstance.getImplementation()); formInstance.setValue(model); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth(100, HorizontalLayout.UNITS_PERCENTAGE); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); Button buttonOk = new Button("Ok"); buttons.addComponent(buttonOk); Button buttonCancel = new Button("Cancel"); buttons.addComponent(buttonCancel); footer.addComponent(buttons); footer.setComponentAlignment(buttons, Alignment.MIDDLE_RIGHT); window.addComponent(footer); ((VerticalLayout) window.getContent()).setComponentAlignment(footer, Alignment.BOTTOM_CENTER); window.getContent().setSizeFull(); vaadinApplication.getMainWindow().addWindow(window); return new UIDialogImpl(window, buttonOk, buttonCancel, formInstance); }
From source file:org.openeos.vaadin.main.internal.MainApplication.java
License:Apache License
@Override public void init() { // TODO Make better implementation, not literal if (notificationManager == null) { throw new IllegalStateException(); }/*from w w w.j a v a2 s . com*/ if (applicationLifecycleManager == null) { throw new IllegalStateException(); } logger.info("Initializing Main Application"); // setTheme(Reindeer.THEME_NAME); // setTheme(Runo.THEME_NAME); // setTheme("demo"); setTheme("uno"); main = new Window("Dynamic Vaadin OSGi Demo"); mainLayout = (VerticalLayout) main.getContent(); mainLayout.setMargin(false); //mainLayout.setStyleName(Reindeer.L "blue"); setMainWindow(main); mainLayout.setSizeFull(); mainLayout.addComponent(getMenu()); mainLayout.addComponent(getHeader()); CssLayout margin = new CssLayout(); margin.setMargin(false, true, true, true); margin.setSizeFull(); tabSheet = new TabSheet(); tabSheet.setSizeFull(); tabSheet.setCloseHandler(closeHandler); margin.addComponent(tabSheet); mainLayout.addComponent(margin); mainLayout.setExpandRatio(margin, 1); for (IVaadinMenuContributor contributor : menuContributorsList) { contributor.contribute(menubar, this); } if (getContext() != null) { getContext().addTransactionListener(this); } initialized = true; applicationLifecycleManager.init(this); }
From source file:org.opennms.features.jmxconfiggenerator.webui.JmxConfigGeneratorApplication.java
License:Open Source License
/** * Creates the main window and adds the header, main and button panels to * it.// w w w . j ava 2 s. c om */ private void initMainWindow() { Window window = new Window("JmxConfigGenerator GUI Tool"); VerticalLayout layout = new VerticalLayout(); layout.addComponent(headerPanel); layout.addComponent(contentPanel); // content Panel should use most of the space :) layout.setExpandRatio(contentPanel, 1); window.setContent(layout); window.getContent().setSizeFull(); window.setSizeFull(); addWindow(window); }
From source file:org.opennms.features.topology.app.internal.operations.RemoveVertexFromGroupOperation.java
License:Open Source License
@Override public void execute(final List<VertexRef> targets, final OperationContext operationContext) { if (targets == null || targets.isEmpty() || targets.size() != 1) { return;/*from www. j av a2 s . c om*/ } final Logger log = LoggerFactory.getLogger(this.getClass()); final GraphContainer graphContainer = operationContext.getGraphContainer(); final VertexRef currentGroup = targets.get(0); final Collection<? extends Vertex> children = graphContainer.getBaseTopology().getChildren(currentGroup); for (Vertex child : children) { log.debug("Child ID: {}", child.getId()); } final UI window = operationContext.getMainWindow(); final Window groupNamePrompt = new Window("Remove item from this Group"); groupNamePrompt.setModal(true); groupNamePrompt.setResizable(false); groupNamePrompt.setHeight("180px"); groupNamePrompt.setWidth("300px"); // Define the fields for the form final PropertysetItem item = new PropertysetItem(); item.addItemProperty("Item", new ObjectProperty<String>(null, String.class)); FormFieldFactory fieldFactory = new FormFieldFactory() { private static final long serialVersionUID = 243277720538924081L; @Override public Field<?> createField(Item item, Object propertyId, Component uiContext) { // Identify the fields by their Property ID. String pid = (String) propertyId; if ("Item".equals(pid)) { ComboBox select = new ComboBox("Item"); for (Vertex child : children) { log.debug("Adding child: {}, {}", child.getId(), child.getLabel()); select.addItem(child.getId()); select.setItemCaption(child.getId(), child.getLabel()); } select.setNewItemsAllowed(false); select.setNullSelectionAllowed(false); return select; } return null; // Invalid field (property) name. } }; // TODO Add validator for name value final Form promptForm = new Form() { private static final long serialVersionUID = 2067414790743946906L; @Override public void commit() { super.commit(); String childId = (String) getField("Item").getValue(); log.debug("Field value: {}", childId); LoggerFactory.getLogger(this.getClass()).debug("Removing item from group: {}", childId); Vertex grandParent = graphContainer.getBaseTopology().getParent(currentGroup); GraphProvider topologyProvider = graphContainer.getBaseTopology(); // Relink the child to the grandparent group (or null if it is null) topologyProvider.setParent(graphContainer.getBaseTopology() .getVertex(graphContainer.getBaseTopology().getVertexNamespace(), childId), grandParent); // Save the topology topologyProvider.save(); graphContainer.redoLayout(); } }; // Buffer changes to the datasource promptForm.setBuffered(true); // You must set the FormFieldFactory before you set the data source promptForm.setFormFieldFactory(fieldFactory); promptForm.setItemDataSource(item); Button ok = new Button("OK"); ok.addClickListener(new ClickListener() { private static final long serialVersionUID = 7388841001913090428L; @Override public void buttonClick(ClickEvent event) { promptForm.commit(); // Close the prompt window window.removeWindow(groupNamePrompt); } }); promptForm.getFooter().addComponent(ok); Button cancel = new Button("Cancel"); cancel.addClickListener(new ClickListener() { private static final long serialVersionUID = 8780989646038333243L; @Override public void buttonClick(ClickEvent event) { // Close the prompt window window.removeWindow(groupNamePrompt); } }); promptForm.getFooter().addComponent(cancel); groupNamePrompt.setContent(promptForm); window.addWindow(groupNamePrompt); }
From source file:org.opennms.features.topology.app.internal.operations.RenameGroupOperation.java
License:Open Source License
@Override public void execute(final List<VertexRef> targets, final OperationContext operationContext) { if (targets == null || targets.isEmpty() || targets.size() != 1) { return;/*from ww w .ja v a2 s . c om*/ } final GraphContainer graphContainer = operationContext.getGraphContainer(); final UI window = operationContext.getMainWindow(); final Window groupNamePrompt = new Window("Rename Group"); groupNamePrompt.setModal(true); groupNamePrompt.setResizable(false); groupNamePrompt.setHeight("220px"); groupNamePrompt.setWidth("300px"); // Define the fields for the form final PropertysetItem item = new PropertysetItem(); item.addItemProperty("Group Label", new ObjectProperty<String>("", String.class)); final Form promptForm = new Form() { private static final long serialVersionUID = 9202531175744361407L; @Override public void commit() { // Trim the form value Property<String> field = getField("Group Label"); String groupLabel = field.getValue(); if (groupLabel == null) { throw new InvalidValueException("Group label cannot be null."); } field.setValue(groupLabel.trim()); super.commit(); groupLabel = field.getValue(); //Object parentKey = targets.get(0); //Object parentId = graphContainer.getVertexItemIdForVertexKey(parentKey); VertexRef parentId = targets.get(0); Vertex parentVertex = parentId == null ? null : graphContainer.getBaseTopology().getVertex(parentId, graphContainer.getCriteria()); Item parentItem = parentVertex == null ? null : parentVertex.getItem(); if (parentItem != null) { Property<String> property = parentItem.getItemProperty("label"); if (property != null && !property.isReadOnly()) { property.setValue(groupLabel); // Save the topology graphContainer.getBaseTopology().save(); graphContainer.redoLayout(); } } } }; // Buffer changes to the datasource promptForm.setBuffered(true); // Bind the item to create all of the fields promptForm.setItemDataSource(item); // Add validators to the fields promptForm.getField("Group Label").setRequired(true); promptForm.getField("Group Label").setRequiredError("Group label cannot be blank."); promptForm.getField("Group Label").addValidator( new StringLengthValidator("Label must be at least one character long.", 1, -1, false)); promptForm.getField("Group Label") .addValidator(new AbstractValidator<String>("A group with label \"{0}\" already exists.") { private static final long serialVersionUID = 79618011585921224L; @Override protected boolean isValidValue(String value) { try { final Collection<? extends Vertex> vertexIds = graphContainer.getBaseTopology() .getVertices(); final Collection<String> groupLabels = new ArrayList<String>(); for (Vertex vertexId : vertexIds) { if (vertexId.isGroup()) { groupLabels.add(vertexId.getLabel()); } } for (String label : groupLabels) { LoggerFactory.getLogger(this.getClass()).debug("Comparing {} to {}", value, label); if (label.equals(value)) { return false; } } return true; } catch (Throwable e) { LoggerFactory.getLogger(this.getClass()).error(e.getMessage(), e); return false; } } @Override public Class<String> getType() { return String.class; } }); Button ok = new Button("OK"); ok.addClickListener(new ClickListener() { private static final long serialVersionUID = 7388841001913090428L; @Override public void buttonClick(ClickEvent event) { promptForm.commit(); // Close the prompt window window.removeWindow(groupNamePrompt); } }); promptForm.getFooter().addComponent(ok); Button cancel = new Button("Cancel"); cancel.addClickListener(new ClickListener() { private static final long serialVersionUID = 8780989646038333243L; @Override public void buttonClick(ClickEvent event) { // Close the prompt window window.removeWindow(groupNamePrompt); } }); promptForm.getFooter().addComponent(cancel); groupNamePrompt.setContent(promptForm); window.addWindow(groupNamePrompt); }
From source file:org.opennms.features.topology.app.internal.TopologyWidgetTestApplication.java
License:Open Source License
@SuppressWarnings("serial") @Override//from ww w.j a va2 s . co m public void init() { setTheme("topo_default"); m_rootLayout = new AbsoluteLayout(); m_rootLayout.setSizeFull(); m_window = new Window("OpenNMS Topology"); m_window.setContent(m_rootLayout); setMainWindow(m_window); m_uriFragUtil = new UriFragmentUtility(); m_window.addComponent(m_uriFragUtil); m_uriFragUtil.addListener(this); m_layout = new AbsoluteLayout(); m_layout.setSizeFull(); m_rootLayout.addComponent(m_layout); if (m_showHeader) { HEADER_HEIGHT = 100; Panel header = new Panel("header"); header.setCaption(null); header.setSizeUndefined(); header.addStyleName("onmsheader"); m_rootLayout.addComponent(header, "top: 0px; left: 0px; right:0px;"); try { CustomLayout customLayout = new CustomLayout(getHeaderLayout()); header.setContent(customLayout); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { HEADER_HEIGHT = 0; } Refresher refresher = new Refresher(); refresher.setRefreshInterval(5000); getMainWindow().addComponent(refresher); m_graphContainer.setLayoutAlgorithm(new FRLayoutAlgorithm()); final Property scale = m_graphContainer.getScaleProperty(); m_topologyComponent = new TopologyComponent(m_graphContainer, m_iconRepositoryManager, m_selectionManager, this); m_topologyComponent.setSizeFull(); m_topologyComponent.addMenuItemStateListener(this); m_topologyComponent.addVertexUpdateListener(this); final Slider slider = new Slider(0, 1); slider.setPropertyDataSource(scale); slider.setResolution(1); slider.setHeight("300px"); slider.setOrientation(Slider.ORIENTATION_VERTICAL); slider.setImmediate(true); final Button zoomInBtn = new Button(); zoomInBtn.setIcon(new ThemeResource("images/plus.png")); zoomInBtn.setDescription("Expand Semantic Zoom Level"); zoomInBtn.setStyleName("semantic-zoom-button"); zoomInBtn.addListener(new ClickListener() { public void buttonClick(ClickEvent event) { int szl = (Integer) m_graphContainer.getSemanticZoomLevel(); szl++; m_graphContainer.setSemanticZoomLevel(szl); setSemanticZoomLevel(szl); saveHistory(); } }); Button zoomOutBtn = new Button(); zoomOutBtn.setIcon(new ThemeResource("images/minus.png")); zoomOutBtn.setDescription("Collapse Semantic Zoom Level"); zoomOutBtn.setStyleName("semantic-zoom-button"); zoomOutBtn.addListener(new ClickListener() { public void buttonClick(ClickEvent event) { int szl = (Integer) m_graphContainer.getSemanticZoomLevel(); if (szl > 0) { szl--; m_graphContainer.setSemanticZoomLevel(szl); setSemanticZoomLevel(szl); saveHistory(); } } }); final Button panBtn = new Button(); panBtn.setIcon(new ThemeResource("images/cursor_drag_arrow.png")); panBtn.setDescription("Pan Tool"); panBtn.setStyleName("toolbar-button down"); final Button selectBtn = new Button(); selectBtn.setIcon(new ThemeResource("images/selection.png")); selectBtn.setDescription("Selection Tool"); selectBtn.setStyleName("toolbar-button"); selectBtn.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { selectBtn.setStyleName("toolbar-button down"); panBtn.setStyleName("toolbar-button"); m_topologyComponent.setActiveTool("select"); } }); panBtn.addListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { panBtn.setStyleName("toolbar-button down"); selectBtn.setStyleName("toolbar-button"); m_topologyComponent.setActiveTool("pan"); } }); VerticalLayout toolbar = new VerticalLayout(); toolbar.setWidth("31px"); toolbar.addComponent(panBtn); toolbar.addComponent(selectBtn); HorizontalLayout semanticLayout = new HorizontalLayout(); semanticLayout.addComponent(zoomInBtn); semanticLayout.addComponent(m_zoomLevelLabel); semanticLayout.addComponent(zoomOutBtn); semanticLayout.setComponentAlignment(m_zoomLevelLabel, Alignment.MIDDLE_CENTER); AbsoluteLayout mapLayout = new AbsoluteLayout(); mapLayout.addComponent(m_topologyComponent, "top:0px; left: 0px; right: 0px; bottom: 0px;"); mapLayout.addComponent(slider, "top: 5px; left: 20px; z-index:1000;"); mapLayout.addComponent(toolbar, "top: 324px; left: 12px;"); mapLayout.addComponent(semanticLayout, "top: 380px; left: 2px;"); mapLayout.setSizeFull(); m_treeMapSplitPanel = new HorizontalSplitPanel(); m_treeMapSplitPanel.setFirstComponent(createWestLayout()); m_treeMapSplitPanel.setSecondComponent(mapLayout); m_treeMapSplitPanel.setSplitPosition(222, Sizeable.UNITS_PIXELS); m_treeMapSplitPanel.setSizeFull(); m_commandManager.addCommandUpdateListener(this); menuBarUpdated(m_commandManager); if (m_widgetManager.widgetCount() != 0) { updateWidgetView(m_widgetManager); } else { m_layout.addComponent(m_treeMapSplitPanel, getBelowMenuPosition()); } if (m_treeWidgetManager.widgetCount() != 0) { updateAccordionView(m_treeWidgetManager); } }
From source file:org.opennms.features.topology.plugins.ncs.ShowNCSPathOperation.java
License:Open Source License
@Override public void execute(List<VertexRef> targets, final OperationContext operationContext) { //Get the current NCS criteria from here you can get the foreignIds foreignSource and deviceA and Z for (Criteria criterium : operationContext.getGraphContainer().getCriteria()) { try {/* ww w. j a v a 2 s . c om*/ NCSServiceCriteria ncsCriterium = (NCSServiceCriteria) criterium; if (ncsCriterium.getServiceCount() > 0) { m_storedCriteria = ncsCriterium; break; } } catch (ClassCastException e) { } } final VertexRef defaultVertRef = targets.get(0); final SelectionManager selectionManager = operationContext.getGraphContainer().getSelectionManager(); final Collection<VertexRef> vertexRefs = getVertexRefsForNCSService(m_storedCriteria); //selectionManager.getSelectedVertexRefs(); final UI mainWindow = operationContext.getMainWindow(); final Window ncsPathPrompt = new Window("Show NCS Path"); ncsPathPrompt.setModal(true); ncsPathPrompt.setResizable(false); ncsPathPrompt.setWidth("300px"); ncsPathPrompt.setHeight("220px"); //Items used in form field final PropertysetItem item = new PropertysetItem(); item.addItemProperty("Device A", new ObjectProperty<String>("", String.class)); item.addItemProperty("Device Z", new ObjectProperty<String>("", String.class)); FormFieldFactory fieldFactory = new FormFieldFactory() { private static final long serialVersionUID = 1L; @Override public Field<?> createField(Item item, Object propertyId, Component uiContext) { String pid = (String) propertyId; ComboBox select = new ComboBox(); for (VertexRef vertRef : vertexRefs) { select.addItem(vertRef.getId()); select.setItemCaption(vertRef.getId(), vertRef.getLabel()); } select.setNewItemsAllowed(false); select.setNullSelectionAllowed(false); select.setImmediate(true); select.setScrollToSelectedItem(true); if ("Device A".equals(pid)) { select.setCaption("Device A"); } else { select.setCaption("Device Z"); } return select; } }; final Form promptForm = new Form() { @Override public void commit() { String deviceA = (String) getField("Device A").getValue(); String deviceZ = (String) getField("Device Z").getValue(); if (deviceA.equals(deviceZ)) { Notification.show("Device A and Device Z cannot be the same", Notification.Type.WARNING_MESSAGE); throw new Validator.InvalidValueException("Device A and Device Z cannot be the same"); } OnmsNode nodeA = m_nodeDao.get(Integer.valueOf(deviceA)); String deviceANodeForeignId = nodeA.getForeignId(); //Use nodeA's foreignSource, deviceZ should have the same foreignSource. It's an assumption // which might need to changed in the future. Didn't want to hard code it it "space" if they // change it in the future String nodeForeignSource = nodeA.getForeignSource(); String deviceZNodeForeignId = m_nodeDao.get(Integer.valueOf(deviceZ)).getForeignId(); NCSComponent ncsComponent = m_dao.get(m_storedCriteria.getServiceIds().get(0)); String foreignSource = ncsComponent.getForeignSource(); String foreignId = ncsComponent.getForeignId(); String serviceName = ncsComponent.getName(); try { NCSServicePath path = getNcsPathProvider().getPath(foreignId, foreignSource, deviceANodeForeignId, deviceZNodeForeignId, nodeForeignSource, serviceName); if (path.getStatusCode() == 200) { NCSServicePathCriteria criteria = new NCSServicePathCriteria(path.getEdges()); m_serviceManager.registerCriteria(criteria, operationContext.getGraphContainer().getSessionId()); //Select only the vertices in the path selectionManager.setSelectedVertexRefs(path.getVertices()); } else { LoggerFactory.getLogger(this.getClass()).warn( "An error occured while retrieving the NCS Path, Juniper NetworkAppsApi send error code: " + path.getStatusCode()); mainWindow.showNotification("An error occurred while retrieving the NCS Path\nStatus Code: " + path.getStatusCode(), Notification.TYPE_ERROR_MESSAGE); } } catch (Exception e) { if (e.getCause() instanceof ConnectException) { LoggerFactory.getLogger(this.getClass()) .warn("Connection Exception Occurred while retreiving path {}", e); Notification.show("Connection Refused when attempting to reach the NetworkAppsApi", Notification.Type.TRAY_NOTIFICATION); } else if (e.getCause() instanceof HttpOperationFailedException) { HttpOperationFailedException httpException = (HttpOperationFailedException) e.getCause(); if (httpException.getStatusCode() == 401) { LoggerFactory.getLogger(this.getClass()).warn( "Authentication error when connecting to NetworkAppsApi {}", httpException); Notification.show( "Authentication error when connecting to NetworkAppsApi, please check the username and password", Notification.Type.TRAY_NOTIFICATION); } else { LoggerFactory.getLogger(this.getClass()) .warn("An error occured while retrieving the NCS Path {}", httpException); Notification.show("An error occurred while retrieving the NCS Path\n" + httpException.getMessage(), Notification.Type.TRAY_NOTIFICATION); } } else if (e.getCause() instanceof Validator.InvalidValueException) { Notification.show(e.getMessage(), Notification.Type.ERROR_MESSAGE); } else { LoggerFactory.getLogger(this.getClass()).warn("Exception Occurred while retreiving path {}", e); Notification.show( "An error occurred while calculating the path please check the karaf.log file for the exception: \n" + e.getMessage(), Notification.Type.TRAY_NOTIFICATION); } } } }; promptForm.setBuffered(true); promptForm.setFormFieldFactory(fieldFactory); promptForm.setItemDataSource(item); Button ok = new Button("OK"); ok.addClickListener(new ClickListener() { private static final long serialVersionUID = -2742886456007926688L; @Override public void buttonClick(ClickEvent event) { promptForm.commit(); mainWindow.removeWindow(ncsPathPrompt); } }); promptForm.getFooter().addComponent(ok); Button cancel = new Button("Cancel"); cancel.addClickListener(new ClickListener() { private static final long serialVersionUID = -9026067481179449095L; @Override public void buttonClick(ClickEvent event) { mainWindow.removeWindow(ncsPathPrompt); } }); promptForm.getFooter().addComponent(cancel); ncsPathPrompt.setContent(promptForm); mainWindow.addWindow(ncsPathPrompt); promptForm.getField("Device A").setValue(defaultVertRef.getId()); }
From source file:org.opennms.features.vaadin.app.TopologyWidgetTestApplication.java
License:Open Source License
@Override public void init() { //This timer is a hack at the moment to disable and enable menuItems m_timer.scheduleAtFixedRate(new TimerTask() { @Override// w w w . j av a 2 s . c om public void run() { List<MenuItem> items = m_menuBar.getItems(); for (MenuItem item : items) { if (item.getText().equals("Device")) { List<MenuItem> children = item.getChildren(); for (MenuItem child : children) { if (m_graphContainer.getSelectedVertexIds().size() > 0) { if (!child.isEnabled()) { child.setEnabled(true); } } else { if (child.isEnabled()) { child.setEnabled(false); } } } } } } }, 1000, 1000); m_commandManager.addCommand(new Command("Redo Layout") { ; @Override public void doCommand(Object target) { m_graphContainer.redoLayout(); } @Override public boolean appliesToTarget(Object target) { //Applies to background as a whole return target == null; } }, true); m_commandManager.addCommand(new Command("Open") { @Override public void doCommand(Object target) { m_graphContainer.load("graph.xml"); } }, false, "File"); m_commandManager.addCommand(new Command("Save") { @Override public void doCommand(Object target) { m_graphContainer.save("graph.xml"); } }, false, "File"); m_commandManager.addCommand(new Command("Add Vertex") { @Override public boolean appliesToTarget(Object itemId) { return itemId == null || m_graphContainer.getVertexContainer().containsId(itemId); } @Override public void doCommand(Object vertexId) { if (vertexId == null) { addRandomVertex(); } else { connectNewVertexTo(vertexId.toString(), SERVER_ICON); } m_graphContainer.redoLayout(); } }, true, "File"); m_commandManager.addCommand(new Command("Lock") { @Override public boolean appliesToTarget(Object itemId) { if (m_graphContainer.getVertexContainer().containsId(itemId)) { Item v = m_graphContainer.getVertexContainer().getItem(itemId); return !(Boolean) v.getItemProperty("locked").getValue(); } return false; } @Override public void doCommand(Object vertexId) { Item v = m_graphContainer.getVertexContainer().getItem(vertexId); v.getItemProperty("locked").setValue(true); } }, true); m_commandManager.addCommand(new Command("Unlock") { @Override public boolean appliesToTarget(Object itemId) { if (m_graphContainer.getVertexContainer().containsId(itemId)) { Item v = m_graphContainer.getVertexContainer().getItem(itemId); return (Boolean) v.getItemProperty("locked").getValue(); } return false; } @Override public void doCommand(Object vertexId) { Item v = m_graphContainer.getVertexContainer().getItem(vertexId); v.getItemProperty("locked").setValue(false); } }, true); m_commandManager.addCommand(new Command("Add Switch Vertex") { @Override public boolean appliesToTarget(Object itemId) { return itemId == null || m_graphContainer.getVertexContainer().containsId(itemId); } @Override public void doCommand(Object vertexId) { if (vertexId == null) { addRandomVertex(); } else { connectNewVertexTo(vertexId.toString(), SWITCH_ICON); } m_graphContainer.redoLayout(); } }, true); m_commandManager.addCommand(new Command("Remove Vertex") { @Override public boolean appliesToTarget(Object itemId) { return itemId == null || m_graphContainer.getVertexContainer().containsId(itemId); } @Override public void doCommand(Object vertexId) { if (vertexId == null) { System.err.println("need to handle selection!!!"); } else { m_graphContainer.removeVertex(vertexId.toString()); m_graphContainer.redoLayout(); } } }, true, "File"); m_commandManager.addCommand(new Command("Connect") { @Override public boolean appliesToTarget(Object itemId) { return m_graphContainer.getSelectedVertexIds().size() == 2; } @Override public void doCommand(Object unused) { List<Object> endPoints = new ArrayList<Object>(m_graphContainer.getSelectedVertexIds()); m_graphContainer.connectVertices(m_graphContainer.getNextEdgeId(), (String) endPoints.get(0), (String) endPoints.get(1)); } }, true, "File"); m_commandManager.addCommand(new Command("Create Group") { @Override public boolean appliesToTarget(Object itemId) { return m_graphContainer.getSelectedVertexIds().size() > 0; } @Override public void doCommand(Object vertexId) { String groupId = m_graphContainer.getNextGroupId(); m_graphContainer.addGroup(groupId, GROUP_ICON); m_graphContainer.getVertexContainer().setParent(groupId, ROOT_GROUP_ID); for (Object itemId : m_graphContainer.getSelectedVertexIds()) { m_graphContainer.getVertexContainer().setParent(itemId, groupId); } } }, true, "Edit"); m_commandManager.addCommand(new Command("Manual Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new ManualLayoutAlgorithm()); } }, false, "Edit|Layout"); m_commandManager.addCommand(new Command("Balloon Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new BalloonLayoutAlgorithm(CENTER_VERTEX_ID)); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("Circle Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new CircleLayoutAlgorithm()); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("DAG Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new DAGLayoutAlgorithm(CENTER_VERTEX_ID)); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("Radial Tree Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new RadialTreeLayoutAlgorithm()); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("Tree Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new TreeLayoutAlgorithm()); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("Simple Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new SimpleLayoutAlgorithm()); } }, false, "Edit|Layout"); m_commandManager.addCommand(new Command("Spring Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new SpringLayoutAlgorithm()); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("KK Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new KKLayoutAlgorithm()); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("ISOM Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new ISOMLayoutAlgorithm()); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("FR Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new FRLayoutAlgorithm()); } }, false, "Edit|Layout|JUNG"); m_commandManager.addCommand(new Command("Other Layout") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { m_graphContainer.setLayoutAlgorithm(new AlternativeLayoutAlgorithm()); } }, false, "Edit|Layout"); m_commandManager.addCommand(new Command("Reset") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { resetView(); } }, false, null); m_commandManager.addCommand(new Command("History") { @Override public boolean appliesToTarget(Object target) { return true; } @Override public void doCommand(Object target) { showHistoryList(m_commandManager.getHistoryList()); } }, false, null); m_commandManager.addCommand(new Command("Show Map") { @Override public void doCommand(Object target) { getMainWindow().showNotification("This has not been implemented yet"); } }, false, "View"); m_commandManager.addCommand(new Command("Get Info") { @Override public boolean appliesToTarget(Object itemId) { return itemId == null || m_graphContainer.getEdgeContainer().containsId(itemId); } @Override public void doCommand(Object target) { getMainWindow().showNotification("This has not been implemented yet"); } }, true, "Device"); AbsoluteLayout layout = new AbsoluteLayout(); layout.setSizeFull(); m_window = new Window("Topology Widget Test"); m_window.setContent(layout); setMainWindow(m_window); m_graphContainer.addGroup(ROOT_GROUP_ID, GROUP_ICON); m_graphContainer.addVertex(CENTER_VERTEX_ID, 50, 50, SERVER_ICON); m_graphContainer.getVertexContainer().setParent(CENTER_VERTEX_ID, ROOT_GROUP_ID); m_graphContainer.setLayoutAlgorithm(new KKLayoutAlgorithm()); m_topologyComponent = new TopologyComponent(m_graphContainer); m_commandManager.addActionHandlers(m_topologyComponent); m_topologyComponent.setSizeFull(); final Property scale = m_graphContainer.getProperty("scale"); final Slider slider = new Slider(1, 4); slider.setResolution(2); slider.setHeight("300px"); slider.setOrientation(Slider.ORIENTATION_VERTICAL); slider.addListener(new ValueChangeListener() { public void valueChange(ValueChangeEvent event) { scale.setValue((Double) slider.getValue()); } }); slider.setImmediate(true); m_tree = createTree(); Label semanticZoomLabel = new Label(); final Property zoomLevel = m_graphContainer.getProperty("semanticZoomLevel"); semanticZoomLabel.setPropertyDataSource(zoomLevel); Button zoomInBtn = new Button("Zoom In"); zoomInBtn.addListener(new ClickListener() { public void buttonClick(ClickEvent event) { int szl = (Integer) zoomLevel.getValue(); szl++; zoomLevel.setValue(szl); m_graphContainer.redoLayout(); } }); Button zoomOutBtn = new Button("Zoom Out"); zoomOutBtn.addListener(new ClickListener() { public void buttonClick(ClickEvent event) { int szl = (Integer) zoomLevel.getValue(); szl--; zoomLevel.setValue(szl); m_graphContainer.redoLayout(); } }); VerticalLayout vLayout = new VerticalLayout(); vLayout.setWidth("100%"); vLayout.setHeight("100%"); vLayout.addComponent(m_tree); AbsoluteLayout mapLayout = new AbsoluteLayout(); mapLayout.addComponent(m_topologyComponent, "top:0px; left: 0px; right: 0px; bottom: 0px;"); mapLayout.addComponent(slider, "top: 20px; left: 20px; z-index:1000;"); mapLayout.addComponent(semanticZoomLabel, "bottom: 10px; right: 10px; z-index: 2000;"); mapLayout.setSizeFull(); HorizontalSplitPanel treeMapSplitPanel = new HorizontalSplitPanel(); treeMapSplitPanel.setFirstComponent(vLayout); treeMapSplitPanel.setSecondComponent(mapLayout); treeMapSplitPanel.setSplitPosition(100, Sizeable.UNITS_PIXELS); treeMapSplitPanel.setSizeFull(); VerticalSplitPanel bottomLayoutBar = new VerticalSplitPanel(); bottomLayoutBar.setFirstComponent(treeMapSplitPanel); VerticalLayout zoomLayout = new VerticalLayout(); zoomLayout.addComponent(zoomInBtn); zoomLayout.addComponent(zoomOutBtn); bottomLayoutBar.setSecondComponent(zoomLayout); bottomLayoutBar.setSplitPosition(80, Sizeable.UNITS_PERCENTAGE); bottomLayoutBar.setSizeFull(); m_menuBar = m_commandManager.getMenuBar(); m_menuBar.setWidth("100%"); layout.addComponent(m_menuBar, "top: 0px; left: 0px; right:0px;"); layout.addComponent(bottomLayoutBar, "top: 23px; left: 0px; right:0px; bottom:0px;"); }
From source file:org.opennms.features.vaadin.dashboard.config.ui.HelpClickListener.java
License:Open Source License
@Override public void buttonClick(Button.ClickEvent clickEvent) { final Window window = new Window("Help"); window.setModal(true);/*from w w w . j a v a 2 s. co m*/ window.setClosable(false); window.setResizable(false); window.setWidth("55%"); window.setHeight("80%"); m_component.getUI().addWindow(window); window.setContent(new VerticalLayout() { { setMargin(true); setSpacing(true); setSizeFull(); HorizontalLayout horizontalLayout = new HorizontalLayout(); horizontalLayout.setSizeFull(); horizontalLayout.setSpacing(true); Tree tree = new Tree(); tree.setNullSelectionAllowed(false); tree.setMultiSelect(false); tree.setImmediate(true); tree.addItem("Overview"); tree.setChildrenAllowed("Overview", false); tree.addItem("Installed Dashlets"); tree.setChildrenAllowed("Installed Dashlets", true); final List<DashletFactory> factories = m_dashletSelector.getDashletFactoryList(); for (DashletFactory dashletFactory : factories) { tree.addItem(dashletFactory.getName()); tree.setParent(dashletFactory.getName(), "Installed Dashlets"); tree.setChildrenAllowed(dashletFactory.getName(), false); } horizontalLayout.addComponent(tree); for (final Object id : tree.rootItemIds()) { tree.expandItemsRecursively(id); } final Panel panel = new Panel(); panel.setSizeFull(); horizontalLayout.addComponent(panel); horizontalLayout.setExpandRatio(panel, 1.0f); addComponent(horizontalLayout); setExpandRatio(horizontalLayout, 1.0f); tree.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { String itemId = String.valueOf(valueChangeEvent.getProperty().getValue()); if ("Installed Dashlets".equals(itemId)) { return; } if ("Overview".equals(itemId)) { VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); verticalLayout.addComponent(new Label(getOverviewHelpHTML(), ContentMode.HTML)); panel.setContent(verticalLayout); } else { DashletFactory dashletFactory = m_dashletSelector.getDashletFactoryForName(itemId); if (dashletFactory != null) { if (dashletFactory.providesHelpComponent()) { VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSpacing(true); verticalLayout.setMargin(true); Label helpTitle = new Label( "Help for Dashlet '" + dashletFactory.getName() + "'"); helpTitle.addStyleName("help-title"); verticalLayout.addComponent(helpTitle); verticalLayout.addComponent(dashletFactory.getHelpComponent()); panel.setContent(verticalLayout); } } } } }); tree.select("Overview"); addComponent(new HorizontalLayout() { { setMargin(true); setSpacing(true); setWidth("100%"); Button closeButton = new Button("Close"); addComponent(closeButton); setComponentAlignment(closeButton, Alignment.MIDDLE_RIGHT); closeButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { window.close(); } }); } }); } }); }