Mercurial > hg > release > thermostat-0.7
changeset 46:dae9f5d6c90b
improve host names and vm names shown in the tree and add tooltips
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Tue, 17 Jan 2012 16:56:55 -0500 |
parents | 23515a4050af |
children | f0f6c2e90f50 |
files | src/com/redhat/thermostat/client/HostRef.java src/com/redhat/thermostat/client/MainWindowFacadeImpl.java src/com/redhat/thermostat/client/VmRef.java src/com/redhat/thermostat/client/strings.properties src/com/redhat/thermostat/client/ui/HtmlTextBuilder.java src/com/redhat/thermostat/client/ui/MainWindow.java |
diffstat | 6 files changed, 77 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/com/redhat/thermostat/client/HostRef.java Tue Jan 17 15:37:30 2012 -0500 +++ b/src/com/redhat/thermostat/client/HostRef.java Tue Jan 17 16:56:55 2012 -0500 @@ -19,7 +19,11 @@ return uid; } - public String getName() { + public String getHostName() { return name; } + + public boolean matches(String filter) { + return getHostName().contains(filter) || getAgentId().contains(filter); + } }
--- a/src/com/redhat/thermostat/client/MainWindowFacadeImpl.java Tue Jan 17 15:37:30 2012 -0500 +++ b/src/com/redhat/thermostat/client/MainWindowFacadeImpl.java Tue Jan 17 16:56:55 2012 -0500 @@ -18,11 +18,13 @@ private DB db; private DBCollection agentConfigCollection; + private DBCollection hostInfoCollection; private DBCollection vmInfoCollection; public MainWindowFacadeImpl(DB db) { this.db = db; this.agentConfigCollection = db.getCollection("agent-config"); + this.hostInfoCollection = db.getCollection("host-info"); this.vmInfoCollection = db.getCollection("vm-info"); } @@ -35,7 +37,9 @@ DBObject doc = cursor.next(); String id = (String) doc.get("agent-id"); if (id != null) { - HostRef agent = new HostRef(id, id); + DBObject hostInfo = hostInfoCollection.findOne(new BasicDBObject("agent-id", id)); + String hostName = (String) hostInfo.get("hostname"); + HostRef agent = new HostRef(id, hostName); hostRefs.add(agent); } } @@ -50,7 +54,9 @@ while (cursor.hasNext()) { DBObject vmObject = cursor.next(); String id = (String) vmObject.get("vm-id"); - VmRef ref = new VmRef(hostRef, id, id); + // TODO can we do better than the main class? + String mainClass = (String) vmObject.get("main-class"); + VmRef ref = new VmRef(hostRef, id, mainClass); vmRefs.add(ref); }
--- a/src/com/redhat/thermostat/client/VmRef.java Tue Jan 17 15:37:30 2012 -0500 +++ b/src/com/redhat/thermostat/client/VmRef.java Tue Jan 17 16:56:55 2012 -0500 @@ -28,4 +28,8 @@ public String getName() { return name; } + + public boolean matches(String filter) { + return getName().contains(filter) || getId().contains(filter); + } }
--- a/src/com/redhat/thermostat/client/strings.properties Tue Jan 17 15:37:30 2012 -0500 +++ b/src/com/redhat/thermostat/client/strings.properties Tue Jan 17 16:56:55 2012 -0500 @@ -45,6 +45,11 @@ STARTUP_MODE_SELECTION_TYPE_CLUSTER = Cluster STARTUP_MODE_SELECTION_URL_LABEL = Host Location +TREE_HOST_TOOLTIP_HOST_NAME = Host Name: {0} +TREE_HOST_TOOLTIP_AGENT_ID = Agent Id: {0} +TREE_HOST_TOOLTIP_VM_NAME = Vm Name: {0} +TREE_HOST_TOOLTIP_VM_ID = Vm Id: {0} + ABOUT_DIALOG_VERSION_AND_RELEASE = Version {0} (released {1}) ABOUT_DIALOG_LICENSE = Licensed under the {0} license. ABOUT_DIALOG_EMAIL = Email: {0}
--- a/src/com/redhat/thermostat/client/ui/HtmlTextBuilder.java Tue Jan 17 15:37:30 2012 -0500 +++ b/src/com/redhat/thermostat/client/ui/HtmlTextBuilder.java Tue Jan 17 16:56:55 2012 -0500 @@ -55,13 +55,18 @@ return text.toString(); } - private static String escape(String text) { + private static String escape(String toEscape) { // FIXME implement this - return text; + return toEscape; } - public HtmlTextBuilder append(String value) { - text.append(value); + public HtmlTextBuilder append(String toAppend) { + text.append(escape(toAppend)); + return this; + } + + public HtmlTextBuilder appendRaw(String toAppend) { + text.append(toAppend); return this; } @@ -69,4 +74,9 @@ return new HtmlTextBuilder().bold(toBold).toHtml(); } + public HtmlTextBuilder newLine() { + text.append("<br>"); + return this; + } + }
--- a/src/com/redhat/thermostat/client/ui/MainWindow.java Tue Jan 17 15:37:30 2012 -0500 +++ b/src/com/redhat/thermostat/client/ui/MainWindow.java Tue Jan 17 16:56:55 2012 -0500 @@ -4,6 +4,7 @@ import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.Insets; import java.awt.event.ActionEvent; @@ -27,6 +28,7 @@ import javax.swing.JTree; import javax.swing.KeyStroke; import javax.swing.ScrollPaneConstants; +import javax.swing.ToolTipManager; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.event.TreeSelectionEvent; @@ -34,6 +36,7 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeModel; import javax.swing.tree.TreeNode; @@ -70,6 +73,8 @@ searchField = new JTextField(); agentVmTree = new AgentVmTree(treeModel); + agentVmTree.setCellRenderer(new AgentVmTreeCellRenderer()); + ToolTipManager.sharedInstance().registerComponent(agentVmTree); contentArea = new VerticalOnlyScrollingPanel(); contentArea.setLayout(new BorderLayout()); @@ -249,7 +254,7 @@ } else { DefaultMutableTreeNode agentNode; for (HostRef hostRef : facade.getHosts()) { - if (hostRef.getName().contains(filter) || hostRef.getAgentId().contains(filter)) { + if (hostRef.matches(filter)) { agentNode = new DefaultMutableTreeNode(hostRef); root.add(agentNode); VmRef[] vmRefs = facade.getVms(hostRef); @@ -259,7 +264,7 @@ } else { agentNode = null; for (VmRef vmRef : facade.getVms(hostRef)) { - if (vmRef.getName().contains(filter) || vmRef.getId().contains(filter)) { + if (vmRef.matches(filter)) { if (agentNode == null) { agentNode = new DefaultMutableTreeNode(hostRef); root.add(agentNode); @@ -305,6 +310,40 @@ } } + private static class AgentVmTreeCellRenderer extends DefaultTreeCellRenderer { + private static final long serialVersionUID = 4444642511815252481L; + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { + setToolTipText(createToolTipText(((DefaultMutableTreeNode) value).getUserObject())); + return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + } + + private String createToolTipText(Object value) { + if (value instanceof HostRef) { + HostRef hostRef = (HostRef) value; + String hostNameHtml = new HtmlTextBuilder().bold(hostRef.getHostName()).toPartialHtml(); + String agentIdHtml = new HtmlTextBuilder().bold(hostRef.getAgentId()).toPartialHtml(); + HtmlTextBuilder builder = new HtmlTextBuilder() + .appendRaw(_("TREE_HOST_TOOLTIP_HOST_NAME", hostNameHtml)) + .newLine() + .appendRaw(_("TREE_HOST_TOOLTIP_AGENT_ID", agentIdHtml)); + return builder.toHtml(); + } else if (value instanceof VmRef) { + VmRef vmRef = (VmRef) value; + String vmNameHtml= new HtmlTextBuilder().bold(vmRef.getName()).toPartialHtml(); + String vmIdHtml = new HtmlTextBuilder().bold(vmRef.getId()).toPartialHtml(); + HtmlTextBuilder builder = new HtmlTextBuilder() + .appendRaw(_("TREE_HOST_TOOLTIP_VM_NAME", vmNameHtml)) + .newLine() + .appendRaw(_("TREE_HOST_TOOLTIP_VM_ID", vmIdHtml)); + return builder.toHtml(); + } else { + return null; + } + } + } + private static class Separator extends JPopupMenu.Separator { @Override public Dimension getPreferredSize() {