[Mc4j-cvs] mc4j/src/org/mc4j/console/dashboard/components AttributeTreeTableExplorer.java,NONE,1.1
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2004-04-02 03:44:42
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17437/src/org/mc4j/console/dashboard/components Added Files: AttributeTreeTableExplorer.java Log Message: A new dashboard component to display mbean attributes in a table with their descriptions, types and values. --- NEW FILE: AttributeTreeTableExplorer.java --- /* * Author: Greg Hinkle * * The contents of this file are subject to the Sapient Public License Version 1.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy of the * License at http://mc4j.sf.net/License-SPL.html. * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, * either express or implied. See the License for the specific language governing rights and limitations * under the License. * * The Original Code is The MC4J Management Console * The Initial Developer of the Original Code is Greg Hinkle (gh...@us...) * Copyright (C) 2004 Greg Hinkle. All Rights Reserved. * * Redistributions of code or binary files using or based on this code must reproduce the * above copyright and disclaimer. For more information see <http://mc4j.sourceforge.net>. */ package org.mc4j.console.dashboard.components; import java.awt.BorderLayout; import java.awt.Dimension; import java.util.Map; import javax.swing.ActionMap; import javax.swing.SwingUtilities; import javax.swing.text.DefaultEditorKit; import org.openide.explorer.ExplorerManager; import org.openide.explorer.ExplorerUtils; import org.openide.explorer.view.TreeTableView; import org.openide.nodes.Node; import org.openide.nodes.PropertySupport; import org.openide.util.Lookup; import org.openide.windows.TopComponent; import org.mc4j.console.Refreshable; import org.mc4j.console.bean.MBeanNode; import org.mc4j.console.dashboard.Dashboard; import org.mc4j.console.dashboard.DashboardComponent; /** * * * @author Greg Hinkle (gh...@us...), February 2004 * @version $Revision: 1.1 $($Author: ghinkl $ / $Date: 2004/04/02 03:32:38 $) */ public class AttributeTreeTableExplorer extends TopComponent implements DashboardComponent, Refreshable, ExplorerManager.Provider, Lookup.Provider { private ExplorerManager manager; private Lookup lookup; private MBeanNode beanNode; private TreeTableView treeView; private static AttributeTreeTableExplorer instance; public static final String COMPONENT_NAME = "attribute_tree_table_component"; public AttributeTreeTableExplorer() { // same as before... manager = new ExplorerManager(); ActionMap map = getActionMap(); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete(manager, true)); // or false /* // ...but add e.g.: InputMap keys = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); keys.put(KeyStroke.getKeyStroke("control c"), DefaultEditorKit.copyAction); keys.put(KeyStroke.getKeyStroke("control x"), DefaultEditorKit.cutAction); keys.put(KeyStroke.getKeyStroke("control v"), DefaultEditorKit.pasteAction); keys.put(KeyStroke.getKeyStroke("DELETE"), "delete"); // ...and initialization of lookup variable lookup = ExplorerUtils.createLookup (manager, map); */ associateLookup (ExplorerUtils.createLookup (manager, map)); //open(); //requestActive(); } public int getPersistenceType() { return TopComponent.PERSISTENCE_NEVER; } public String getName() { return COMPONENT_NAME; } private void createComponents() { setLayout(new BorderLayout()); this.treeView = new TreeTableView(); /* treeView.getAccessibleContext().setAccessibleName( FormUtils.getBundleString("ACS_ComponentTree")); // NOI18N treeView.getAccessibleContext().setAccessibleDescription( FormUtils.getBundleString("ACSD_ComponentTree")); // NOI18N */ add(BorderLayout.CENTER, this.treeView); //setPreferredSize(new Dimension(Integer.MAX_VALUE, (int) this.treeView.getPreferredSize().getHeight())); //setMaximumSize(new Dimension(Integer.MAX_VALUE, (int) this.treeView.getMaximumSize().getHeight())); } public TreeTableView getBeanTreeView() { return this.treeView; } // ...method as before and getLookup public ExplorerManager getExplorerManager() { return manager; } public void setContext(Map context) { this.beanNode = (MBeanNode) context.get(Dashboard.CONTEXT_MBEAN_NODE); createComponents(); this.treeView.setPreferredSize(new Dimension(400, 150)); this.treeView.setProperties( new Node.Property[]{ /*new PropertySupport.ReadOnly( "attributeName", // NOI18N String.class, "bar", "foo") { public Object getValue () { return null; } },*/ new PropertySupport.ReadOnly ( "description", // NOI18N String.class, "Description", "The description as provided in the MBeanInfo") { public Object getValue () { return null; } }, new PropertySupport.ReadOnly ( "className", // NOI18N String.class, "Type", "The type as provided in the MBeanInfo") { public Object getValue () { return null; } }, new PropertySupport.ReadOnly ( "valueAsText", // NOI18N String.class, "Value", "The value of the attribute") { public Object getValue () { return null; } //public void setValue(Object val) { } } } ); this.treeView.setTreePreferredWidth(200); this.treeView.setTableColumnPreferredWidth(0, 230); this.treeView.setTableColumnPreferredWidth(1, 80); this.treeView.setTableColumnPreferredWidth(2, 150); this.manager.setRootContext(this.beanNode.getAttributesNode()); SwingUtilities.invokeLater(new Runnable() { public void run() { setDisplayName(AttributeTreeTableExplorer.this.beanNode.getName()); } }); // TODO GH: This is just a rough guestimate... can we determine font-heights or maximum node-line heights? int heightNeeded = (18 * this.beanNode.getAttributesNode().getChildren().getNodes().length) + 50; setPreferredSize(new Dimension(getWidth(), heightNeeded)); setMaximumSize(new Dimension(Integer.MAX_VALUE, heightNeeded)); } public void refresh() { this.beanNode.retrieveData(); } //public Lookup getLookup() { // return lookup; //} // ...methods as before, but replace componentActivated and // componentDeactivated with e.g.: public void addNotify() { super.addNotify(); ExplorerUtils.activateActions(manager, true); } public void removeNotify() { ExplorerUtils.activateActions(manager, false); super.removeNotify(); } } |