Author: rob.stryker(a)jboss.com
Date: 2007-09-18 22:32:12 -0400 (Tue, 18 Sep 2007)
New Revision: 3701
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/AttributeGroup.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXLabelProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXPropertySheetPage.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXTreeContentProvider.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXViewProvider.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/JMXViewProvider.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/JBossServerView.java
Log:
Separated out JMX addition into several classes
Finished implementing attribute editor
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java 2007-09-18
20:22:36 UTC (rev 3700)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/ExtensionTableViewer.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -339,9 +339,9 @@
IPropertySheetPage page = null;
if( selected instanceof ContentWrapper ) {
page = getDelegatePage(((ContentWrapper)selected).getProvider());
- } else if( selected instanceof ServerViewProvider ) {
+ } else /*if( selected instanceof ServerViewProvider ) {
page = getDelegatePage((ServerViewProvider)selected);
- } else if( page == null ) {
+ } else if( page == null ) */ {
page = topLevelPropertiesPage;
}
page.selectionChanged(part, sel);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/JBossServerView.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/JBossServerView.java 2007-09-18
20:22:36 UTC (rev 3700)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/JBossServerView.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -43,7 +43,20 @@
if( getDefault() != null )
getDefault().getExtensionFrame().getViewer().addSelectionChangedListener(listener);
}
-
+
+ public static void removeServerFrameListener(ISelectionChangedListener listener) {
+ if( serverFrameListeners.contains(listener))
+ serverFrameListeners.remove(listener);
+ if( getDefault() != null )
+ getDefault().getServerFrame().getViewer().removeSelectionChangedListener(listener);
+ }
+ public static void removeExtensionFrameListener(ISelectionChangedListener listener) {
+ if( extensionFrameListeners.contains(listener))
+ extensionFrameListeners.remove(listener);
+ if( getDefault() != null )
+ getDefault().getExtensionFrame().getViewer().removeSelectionChangedListener(listener);
+ }
+
public static interface IServerViewFrame {
public IAction[] getActionBarActions();
public int getDefaultSize();
Deleted:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/JMXViewProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/JMXViewProvider.java 2007-09-18
20:22:36 UTC (rev 3700)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/JMXViewProvider.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -1,537 +0,0 @@
-package org.jboss.ide.eclipse.as.ui.views.server.providers;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-
-import org.eclipse.jdt.internal.ui.JavaPluginImages;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Group;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.PageBook;
-import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.IServerLifecycleListener;
-import org.eclipse.wst.server.core.IServerListener;
-import org.eclipse.wst.server.core.ServerCore;
-import org.eclipse.wst.server.core.ServerEvent;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXClassLoaderRepository;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXAttributesWrapper;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXBean;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXDomain;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXException;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.WrappedMBeanOperationInfo;
-import org.jboss.ide.eclipse.as.ui.views.server.JBossServerView;
-import org.jboss.ide.eclipse.as.ui.views.server.ExtensionTableViewer.ContentWrapper;
-import org.jboss.ide.eclipse.as.ui.views.server.extensions.JBossServerViewExtension;
-import org.jboss.ide.eclipse.as.ui.views.server.extensions.ServerViewProvider;
-import org.jboss.ide.eclipse.as.ui.views.server.util.ViewUtilityMethods;
-
-public class JMXViewProvider extends JBossServerViewExtension {
- protected static final Object LOADING = new Object();
- protected static final String[] LOADING_STRING_ARRAY = new String[] {
"Loading..." };
- protected static final String ATTRIBUTES_STRING = "Attributes...";
-
- protected JMXPropertySheetPage propertyPage;
- protected JMXServerLifecycleListener lcListener;
- protected JMXServerListener serverListener;
- protected JMXTreeContentProvider contentProvider;
- protected JMXLabelProvider labelProvider;
- protected IServer server;
- protected JMXModel model;
-
- public JMXViewProvider() {
- model = new JMXModel();
- addListeners();
- }
-
- protected void addListeners() {
- JBossServerView.addExtensionFrameListener(
- new ISelectionChangedListener() {
- public void selectionChanged(SelectionChangedEvent event) {
- Object o = JBossServerView.getDefault()
- .getExtensionFrame().getViewer()
- .getSelectedElement();
- if (o instanceof JMXBean) {
- ViewUtilityMethods.activatePropertiesView(null);
- }
- }
- });
-
- // make sure we know about server events
- serverListener = new JMXServerListener();
- lcListener = new JMXServerLifecycleListener();
- ServerCore.addServerLifecycleListener(lcListener);
- IServer[] servers = ServerCore.getServers();
- for (int i = 0; i < servers.length; i++) {
- servers[i].addServerListener(serverListener);
- }
-
- }
-
- protected class JMXServerLifecycleListener implements
- IServerLifecycleListener {
- public void serverAdded(IServer server) {
- server.addServerListener(serverListener);
- }
-
- public void serverChanged(IServer server) {
- }
-
- public void serverRemoved(IServer server) {
- server.removeServerListener(serverListener);
- JMXClassLoaderRepository.getDefault()
- .removeConcerned(server, model);
- }
- }
-
- protected class JMXServerListener implements IServerListener {
- public void serverChanged(ServerEvent event) {
- if ((event.getKind() & ServerEvent.SERVER_CHANGE) != 0) {
- if ((event.getKind() & ServerEvent.STATE_CHANGE) != 0) {
- if (event.getState() == IServer.STATE_STARTED) {
- JMXClassLoaderRepository.getDefault().addConcerned(
- event.getServer(), model);
- } else {
- JMXClassLoaderRepository.getDefault().removeConcerned(
- event.getServer(), model);
- }
- }
- }
- }
- }
-
- public IPropertySheetPage getPropertySheetPage() {
- if (propertyPage == null) {
- propertyPage = new JMXPropertySheetPage(this);
- }
- return propertyPage;
- }
-
- public ITreeContentProvider getContentProvider() {
- if (contentProvider == null)
- contentProvider = new JMXTreeContentProvider();
- return contentProvider;
- }
-
- public LabelProvider getLabelProvider() {
- if (labelProvider == null)
- labelProvider = new JMXLabelProvider();
- return labelProvider;
- }
-
- class JMXLabelProvider extends LabelProvider {
- public String getText(Object obj) {
- if (obj instanceof JMXDomain)
- return ((JMXDomain) obj).getName();
- if (obj instanceof JMXBean) {
- return ((JMXBean) obj).getName().substring(
- ((JMXBean) obj).getDomain().length() + 1);
- }
- if (obj instanceof WrappedMBeanOperationInfo) {
- return ((WrappedMBeanOperationInfo) obj).getInfo().getName();
- }
-
- if (obj instanceof JMXException) {
- String message = "";
- message += ((JMXException) obj).getException().getClass()
- .getName()
- + ": ";
- message += ((JMXException) obj).getException().getMessage();
- return message;
- }
- if (obj instanceof JMXAttributesWrapper) {
- return "Attributes";
- }
- if (obj == LOADING)
- return "loading...";
- return "not sure yet: " + obj.getClass().getName();
- }
-
- public Image getImage(Object obj) {
- if (obj instanceof JMXException) {
- return PlatformUI.getWorkbench().getSharedImages().getImage(
- ISharedImages.IMG_OBJS_ERROR_TSK);
- }
- if (obj instanceof WrappedMBeanOperationInfo)
- return JavaPluginImages.get(JavaPluginImages.IMG_MISC_PUBLIC);
- if (obj instanceof JMXAttributesWrapper) {
- return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC);
- }
-
- return null;
- }
-
- }
-
- public class JMXTreeContentProvider implements ITreeContentProvider {
-
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof ServerViewProvider) {
- if (server == null)
- return new Object[] {};
- if (server.getServerState() != IServer.STATE_STARTED) {
- model.clearModel(server);
- return new Object[] {};
- }
- JMXDomain[] domains = model.getModel(server).getDomains();
- if (domains == null
- && model.getModel(server).getException() == null) {
- loadChildrenRefreshViewer(parentElement);
- return new Object[] { LOADING };
- } else if (domains == null
- && model.getModel(server).getException() != null) {
- return new Object[] { model.getModel(server).getException() };
- }
- return domains;
- }
- if (parentElement instanceof JMXDomain) {
- JMXBean[] beans = ((JMXDomain) parentElement).getBeans();
- if (beans == null
- && ((JMXDomain) parentElement).getException() == null) {
- loadChildrenRefreshViewer(parentElement);
- return new Object[] { LOADING };
- } else if (beans == null
- && ((JMXDomain) parentElement).getException() != null) {
- return new Object[] { ((JMXDomain) parentElement)
- .getException() };
- }
- return beans;
- }
- if (parentElement instanceof JMXBean) {
- WrappedMBeanOperationInfo[] operations = ((JMXBean) parentElement)
- .getOperations();
- if (operations == null
- && ((JMXBean) parentElement).getException() == null) {
- loadChildrenRefreshViewer(parentElement);
- return new Object[] { LOADING };
- } else if (operations == null
- && ((JMXBean) parentElement).getException() != null) {
- return new Object[] { ((JMXBean) parentElement)
- .getException() };
- }
- // add the Attributes element
- ArrayList<Object> list = new ArrayList<Object>();
- list.add(new JMXAttributesWrapper((JMXBean) parentElement));
- list.addAll(Arrays.asList(operations));
- return (Object[]) list.toArray(new Object[list.size()]);
- }
- return new Object[0];
- }
-
- public Object getParent(Object element) {
- return null; // unused
- }
-
- public boolean hasChildren(Object element) {
- if (element instanceof ServerViewProvider) {
- if (server == null
- || server.getServerState() != IServer.STATE_STARTED) {
- return false;
- }
- return true;
- }
- if (element instanceof JMXException)
- return false;
- if (element instanceof WrappedMBeanOperationInfo)
- return false;
- if (element instanceof JMXAttributesWrapper)
- return false;
- return true; // always true?
- }
-
- public Object[] getElements(Object inputElement) {
- return null; // unused here
- }
-
- public void dispose() {
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- if (oldInput != newInput) {
- server = (IServer) newInput;
- }
- }
- }
-
- protected void loadChildrenRefreshViewer(final Object parent) {
- new Thread() {
- public void run() {
- loadChildren(parent);
- refreshViewerAsync(parent);
- }
- }.start();
- }
-
- protected void loadChildren(Object parent) {
- if (parent instanceof ServerViewProvider)
- model.getModel(server).loadDomains();
- else if (parent instanceof JMXDomain)
- ((JMXDomain) parent).loadBeans();
- else if (parent instanceof JMXBean)
- ((JMXBean) parent).loadInfo();
- }
-
- protected void refreshViewerAsync(final Object parent) {
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- refreshViewer(parent);
- }
- });
- }
-
- public void refreshModel(Object object) {
- if( object instanceof ContentWrapper )
- object = ((ContentWrapper)object).getElement();
- if (object instanceof ServerViewProvider) {
- model.clearModel(server);
- } else if (object instanceof JMXDomain) {
- ((JMXDomain) object).resetChildren();
- } else if (object instanceof JMXBean) {
- ((JMXBean) object).resetChildren();
- }
- }
-
- public class JMXPropertySheetPage implements IPropertySheetPage {
-
- // data
- protected JMXViewProvider provider;
- protected JMXBean bean;
- protected WrappedMBeanOperationInfo[] operations;
-
- // ui pieces
- protected Composite main;
- protected Combo pulldown;
- protected PageBook book;
- protected ErrorGroup errorGroup;
- protected OperationGroup operationGroup;
- protected AttributeGroup attributeGroup;
-
- public JMXPropertySheetPage(JMXViewProvider provider) {
- this.provider = provider;
- }
-
- public void createControl(Composite parent) {
- main = new Composite(parent, SWT.NONE);
- main.setLayout(new FormLayout());
-
- pulldown = new Combo(main, SWT.READ_ONLY);
- FormData pulldownData = new FormData();
- pulldownData.left = new FormAttachment(0, 10);
- // pulldownData.right = new FormAttachment(0,300);
- pulldownData.top = new FormAttachment(0, 10);
- pulldown.setLayoutData(pulldownData);
-
-
- Listener listener = new Listener() {
- public void handleEvent(Event event) {
- switch(event.type) {
- case SWT.Selection:
- case SWT.Modify:
- pulldownSelectionChanged();
- break;
- }
- }
- };
- pulldown.addListener(SWT.Selection, listener);
- pulldown.addListener(SWT.Modify, listener);
-
- book = new PageBook(main, SWT.NONE);
- FormData bookData = new FormData();
- bookData.top = new FormAttachment(pulldown, 10);
- bookData.left = new FormAttachment(0,5);
- bookData.right = new FormAttachment(100,-5);
- bookData.bottom = new FormAttachment(100, -5);
- book.setLayoutData(bookData);
-
- errorGroup = new ErrorGroup(book, SWT.NONE);
- operationGroup = new OperationGroup(book, SWT.NONE);
- attributeGroup = new AttributeGroup(book, SWT.NONE);
- }
-
- public void dispose() {
- }
-
- public Control getControl() {
- return main;
- }
-
- public void setActionBars(IActionBars actionBars) {
- }
-
- public void setFocus() {
- }
-
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- if (selection instanceof IStructuredSelection) {
- Object obj = ((IStructuredSelection) selection)
- .getFirstElement();
- if (obj instanceof ContentWrapper)
- obj = ((ContentWrapper) obj).getElement();
-
- if (obj == null)
- return;
- setInputObject(obj);
- }
- }
-
- protected void setInputObject(Object obj) {
- if (obj instanceof JMXDomain) {
- showDomainComposite((JMXDomain) obj);
- } else if (obj instanceof JMXBean) {
- setBean((JMXBean) obj);
- } else if (obj instanceof JMXAttributesWrapper
- || obj instanceof WrappedMBeanOperationInfo) {
- setBean(getBeanFromInput(obj));
- setComboSelectionFromInput(obj);
- }
- }
-
- protected void setBean(JMXBean bean) {
- if (bean != null ) {
- boolean requiresLoading = bean.getOperations() == null && bean.getException()
== null;
- boolean hasError = bean.getOperations() == null && bean.getException() !=
null;
- boolean currentBeanLoading = bean == this.bean && pulldown.getItems().length
== 1 && pulldown.getItems()[0].equals(LOADING_STRING_ARRAY[0]);
- boolean finishedLoading = bean.getOperations() != null;
-
- this.bean = bean;
- if( requiresLoading ) {
- pulldown.setItems(LOADING_STRING_ARRAY);
- pulldown.select(0); // select Loading...
- loadChildrenRefreshProperties(bean);
- } else if( hasError ) {
- // some error
- showErrorComposite();
- } else if( finishedLoading ) {
- // finished loading
- operations = bean.getOperations();
- pulldown.setItems(pulldownItems());
- pulldown.select(0); // select Loading...
- }
- main.layout();
- }
- }
-
- protected JMXBean getBeanFromInput(Object obj) {
- return obj instanceof JMXAttributesWrapper ?
- ((JMXAttributesWrapper) obj).getBean() :
- ((WrappedMBeanOperationInfo) obj).getBean();
- }
-
- protected void setComboSelectionFromInput(Object obj) {
- int index = -1;
- if (obj instanceof WrappedMBeanOperationInfo)
- index = pulldown
- .indexOf(getStringForOperation(((WrappedMBeanOperationInfo) obj)));
- if (index == -1)
- index = 0;
- pulldown.select(index);
- }
-
- // get the list of combo items based on the bean
- // The list should be Two larger than the number of operations
- // ex: {Attributes..., ------, op1, op2, op3... etc}
- protected String[] pulldownItems() {
- WrappedMBeanOperationInfo[] ops = bean.getOperations();
- String[] vals = null;
- if (ops != null) {
- if( ops.length == 0 ) return new String[]{ATTRIBUTES_STRING};
- vals = new String[ops.length + 2];
- vals[0] = ATTRIBUTES_STRING;
- vals[1] = "---------------";
- for (int i = 0; i < ops.length; i++) {
- vals[i + 2] = getStringForOperation(ops[i]);
- }
- }
- return vals;
- }
-
- protected String getStringForOperation(WrappedMBeanOperationInfo op) {
- return op.getInfo().getReturnType() + " " + op.getInfo().getName();
- }
-
- protected void loadChildrenRefreshProperties(final Object bean) {
- new Thread() {
- public void run() {
- loadChildren(bean);
- Display.getDefault().asyncExec(new Runnable() { public void run() {
- setInputObject(bean);
- }});
- }
- }.start();
- }
-
- protected void showDomainComposite(JMXDomain domain) {
- // nothing
- }
- protected void showErrorComposite() {
- book.showPage(errorGroup);
- }
-
- protected void pulldownSelectionChanged() {
- if( pulldown.getSelectionIndex() != -1 ) {
- int index = pulldown.getSelectionIndex();
- if( index == 0 && pulldown.getItem(0).equals(ATTRIBUTES_STRING)) {
- book.showPage(attributeGroup);
- } else if( index != 1 && index <= operations.length) {
- book.showPage(operationGroup);
- }
- String selected = pulldown.getItem(pulldown.getSelectionIndex());
- System.out.println(selected);
- }
- }
-
- }
-
- protected static class ErrorGroup extends Composite {
- protected Group group;
- public ErrorGroup(Composite parent, int style) {
- super(parent, style);
- setLayout(new FillLayout());
- group = new Group(this, SWT.NONE);
- group.setText("Error");
- }
- }
-
- protected static class OperationGroup extends Composite {
- protected Group group;
- public OperationGroup(Composite parent, int style) {
- super(parent, style);
- setLayout(new FillLayout());
- group = new Group(this, SWT.NONE);
- group.setText("Operation");
- }
- }
-
- protected static class AttributeGroup extends Composite {
- protected Group group;
- public AttributeGroup(Composite parent, int style) {
- super(parent, style);
- setLayout(new FillLayout());
- group = new Group(this, SWT.NONE);
- group.setText("Attributes");
- }
- }
-
-}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/AttributeGroup.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/AttributeGroup.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/AttributeGroup.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -0,0 +1,300 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.jmx;
+
+import javax.management.Attribute;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.TreeEditor;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXBean;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXRunnable;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXSafeRunner;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.WrappedMBeanAttributeInfo;
+import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
+
+public class AttributeGroup extends Composite {
+
+ protected Group group;
+ protected Tree tree;
+ protected TreeColumn nameColumn, typeColumn, accessColumn, valueColumn,
+ descriptionColumn;
+ protected TreeViewer treeViewer;
+ protected JMXPropertySheetPage page;
+
+ public AttributeGroup(Composite parent, int style, JMXPropertySheetPage page) {
+ super(parent, style);
+ this.page = page;
+ setLayout(new FillLayout());
+// group = new Group(this, SWT.NONE);
+// group.setText("Attributes");
+// group.setLayout(new FillLayout());
+
+ tree = new Tree(this, SWT.BORDER | SWT.FULL_SELECTION);
+
+ nameColumn = new TreeColumn(tree, SWT.NONE);
+ typeColumn = new TreeColumn(tree, SWT.NONE);
+ accessColumn = new TreeColumn(tree, SWT.NONE);
+ valueColumn = new TreeColumn(tree, SWT.NONE);
+ descriptionColumn = new TreeColumn(tree, SWT.NONE);
+
+ nameColumn.setWidth(100);
+ typeColumn.setWidth(150);
+ accessColumn.setWidth(50);
+ valueColumn.setWidth(200);
+ descriptionColumn.setWidth(300);
+
+ nameColumn.setText("Name");
+ typeColumn.setText("Type");
+ accessColumn.setText("Access");
+ valueColumn.setText("Value");
+ descriptionColumn.setText("Description");
+
+ tree.setHeaderVisible(true);
+ tree.setLinesVisible(true);
+
+ treeViewer = new TreeViewer(tree);
+ treeViewer.setContentProvider(new AttributeViewerContentProvider());
+ treeViewer.setLabelProvider(new AttributeViewerLabelProvider());
+
+ JMXAttributePropertySelListener selListener = new JMXAttributePropertySelListener();
+ tree.addListener(SWT.MouseDoubleClick, selListener);
+ }
+
+ public void setBean(JMXBean bean) {
+ treeViewer.setInput(bean);
+ }
+
+ protected class JMXAttributePropertySelListener implements Listener {
+ private final Color black;
+ private final TreeEditor editor;
+
+ public JMXAttributePropertySelListener() {
+ black = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
+ editor = new TreeEditor(tree);
+ }
+
+ public void handleEvent(Event event) {
+ TreeItem[] selectedItems = tree.getSelection();
+ if (selectedItems.length != 1)
+ return;
+ final TreeItem item = selectedItems[0];
+
+ if (!(item.getData() instanceof WrappedMBeanAttributeInfo))
+ return;
+ if (!((WrappedMBeanAttributeInfo) item.getData()).getInfo()
+ .isWritable())
+ return;
+
+ final WrappedMBeanAttributeInfo attInfo = (WrappedMBeanAttributeInfo) item
+ .getData();
+
+ final int column = 3;
+ boolean isCarbon = SWT.getPlatform().equals("carbon");
+ final Composite composite = new Composite(tree, SWT.NONE);
+ if (!isCarbon)
+ composite.setBackground(black);
+ final Text text = new Text(composite, SWT.NONE);
+ final int inset = isCarbon ? 0 : 1;
+ composite.addListener(SWT.Resize, new Listener() {
+ public void handleEvent(Event e) {
+ Rectangle rect = composite.getClientArea();
+ text.setBounds(rect.x + inset, rect.y + inset, rect.width
+ - inset * 2, rect.height - inset * 2);
+ }
+ });
+ Listener textListener = new Listener() {
+ public void handleEvent(final Event e) {
+ switch (e.type) {
+ case SWT.FocusOut:
+ composite.dispose();
+ break;
+ case SWT.Verify:
+ String newText = text.getText();
+ String leftText = newText.substring(0, e.start);
+ String rightText = newText.substring(e.end, newText
+ .length());
+ GC gc = new GC(text);
+ Point size = gc.textExtent(leftText + e.text
+ + rightText);
+ gc.dispose();
+ size = text.computeSize(size.x, SWT.DEFAULT);
+ editor.horizontalAlignment = SWT.LEFT;
+ Rectangle itemRect = item.getBounds(),
+ rect = tree.getClientArea();
+ editor.minimumWidth = Math.max(size.x, itemRect.width)
+ + inset * 2;
+ int left = itemRect.x,
+ right = rect.x + rect.width;
+ editor.minimumWidth = Math.min(editor.minimumWidth,
+ right - left);
+ editor.minimumHeight = size.y + inset * 2;
+ editor.setColumn(column);
+ editor.layout();
+ break;
+ case SWT.Traverse:
+ switch (e.detail) {
+ case SWT.TRAVERSE_RETURN:
+ saveAttributeChange(attInfo, text);
+ // FALL THROUGH
+ case SWT.TRAVERSE_ESCAPE:
+ composite.dispose();
+ e.doit = false;
+ }
+ break;
+ }
+ }
+ };
+ text.addListener(SWT.FocusOut, textListener);
+ text.addListener(SWT.Traverse, textListener);
+ text.addListener(SWT.Verify, textListener);
+ editor.setEditor(composite, item);
+ text.setText(item.getText(column));
+ text.selectAll();
+ text.setFocus();
+
+ }
+ }
+
+ protected void saveAttributeChange(final WrappedMBeanAttributeInfo attInfo, Text text)
{
+ if (text.isDisposed())
+ return;
+ final String text2 = text.getText();
+ final Attribute att = createAttribute(attInfo, text2);
+ final Boolean[] errorBool = new Boolean[1];
+ if( att == null ) {
+ // throw up a message box and say no can do, for now
+ MessageBox messageBox = new MessageBox (new Shell(), SWT.OK);
+ messageBox.setText ("Cannot update bean");
+ messageBox.setMessage ("Bean update cannot proceed. Plug-in cannot convert "
+ text2 + " into " + attInfo.getInfo().getType());
+ messageBox.open();
+ return;
+ }
+
+ final JMXRunnable run = new JMXRunnable() {
+ public void run(MBeanServerConnection connection) {
+ try {
+ connection.setAttribute(new ObjectName(
+ attInfo.getBean().getName()), att);
+ } catch (final Exception e) {
+ Display.getDefault().asyncExec(new Runnable() { public void run() {
+ IStatus status = new Status(IStatus.ERROR, JBossServerUIPlugin.PLUGIN_ID,
e.getMessage(), e);
+ JBossServerUIPlugin.getDefault().getLog().log(status);
+ errorBool[0] = new Boolean(true);
+ }});
+ }
+ }
+ };
+
+ new Thread() { public void run() {
+ JMXSafeRunner.run(attInfo.getBean().getServer(), run);
+ if( errorBool[0] == null ) {
+ page.provider.loadChildren(attInfo.getBean());
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ page.setInputObject(attInfo.getBean());
+ }
+ });
+ }
+ }}.start();
+ }
+
+ protected Attribute createAttribute(WrappedMBeanAttributeInfo attInfo, String text) {
+ String type = attInfo.getInfo().getType();
+ Object val = null;
+
+ try {
+ if( type.equals("java.lang.String")) val = text;
+ else if( type.equals("boolean")) val = new Boolean(text);
+ else if( type.equals("int")) val = new Integer(text);
+ else if( type.equals("long")) val = new Long(text);
+ } catch( Exception e ) {}
+
+ return val == null ? null :
+ new Attribute(attInfo.getInfo().getName(), val);
+ }
+
+ protected class AttributeViewerContentProvider implements
+ ITreeContentProvider {
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof JMXBean)
+ return ((JMXBean) parentElement).getAttributes();
+ return new Object[] {};
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof JMXBean)
+ return ((JMXBean) inputElement).getAttributes();
+ return new Object[] {};
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ protected class AttributeViewerLabelProvider extends LabelProvider
+ implements ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof WrappedMBeanAttributeInfo) {
+ WrappedMBeanAttributeInfo element2 = (WrappedMBeanAttributeInfo) element;
+ if (columnIndex == 0)
+ return element2.getInfo().getName();
+ if (columnIndex == 1)
+ return element2.getInfo().getType();
+ if (columnIndex == 3)
+ return (element2.getValue() != null ? element2.getValue()
+ .toString() : "");
+ if (columnIndex == 4)
+ return element2.getInfo().getDescription();
+ if (columnIndex == 2) {
+ String ret = element2.getInfo().isReadable() ? "R" : "";
+ ret += element2.getInfo().isWritable() ? "W" : "";
+ return ret;
+ }
+
+ }
+ return null;
+ }
+
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXLabelProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXLabelProvider.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXLabelProvider.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -0,0 +1,56 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.jmx;
+
+import org.eclipse.jdt.internal.ui.JavaPluginImages;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXAttributesWrapper;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXBean;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXDomain;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXException;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.WrappedMBeanOperationInfo;
+
+class JMXLabelProvider extends LabelProvider {
+ public String getText(Object obj) {
+ if (obj instanceof JMXDomain)
+ return ((JMXDomain) obj).getName();
+ if (obj instanceof JMXBean) {
+ return ((JMXBean) obj).getName().substring(
+ ((JMXBean) obj).getDomain().length() + 1);
+ }
+ if (obj instanceof WrappedMBeanOperationInfo) {
+ return ((WrappedMBeanOperationInfo) obj).getInfo().getName();
+ }
+
+ if (obj instanceof JMXException) {
+ String message = "";
+ message += ((JMXException) obj).getException().getClass()
+ .getName()
+ + ": ";
+ message += ((JMXException) obj).getException().getMessage();
+ return message;
+ }
+ if (obj instanceof JMXAttributesWrapper) {
+ return "Attributes";
+ }
+ if (obj == JMXViewProvider.LOADING)
+ return "loading...";
+ return "not sure yet: " + obj.getClass().getName();
+ }
+
+ public Image getImage(Object obj) {
+ if (obj instanceof JMXException) {
+ return PlatformUI.getWorkbench().getSharedImages().getImage(
+ ISharedImages.IMG_OBJS_ERROR_TSK);
+ }
+ if (obj instanceof WrappedMBeanOperationInfo)
+ return JavaPluginImages.get(JavaPluginImages.IMG_MISC_PUBLIC);
+ if (obj instanceof JMXAttributesWrapper) {
+ return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PUBLIC);
+ }
+
+ return null;
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXPropertySheetPage.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXPropertySheetPage.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXPropertySheetPage.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -0,0 +1,247 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.jmx;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.part.PageBook;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXAttributesWrapper;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXBean;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXDomain;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.WrappedMBeanOperationInfo;
+import org.jboss.ide.eclipse.as.ui.views.server.ExtensionTableViewer.ContentWrapper;
+import
org.jboss.ide.eclipse.as.ui.views.server.providers.jmx.JMXViewProvider.ErrorGroup;
+import
org.jboss.ide.eclipse.as.ui.views.server.providers.jmx.JMXViewProvider.OperationGroup;
+
+public class JMXPropertySheetPage implements IPropertySheetPage {
+
+ // data
+ protected JMXViewProvider provider;
+ protected JMXBean bean;
+ protected WrappedMBeanOperationInfo[] operations;
+
+ // ui pieces
+ protected Composite main;
+ protected Combo pulldown;
+ protected Label beanLabel;
+ protected PageBook book;
+ protected ErrorGroup errorGroup;
+ protected OperationGroup operationGroup;
+ protected AttributeGroup attributeGroup;
+
+ public JMXPropertySheetPage(JMXViewProvider provider) {
+ this.provider = provider;
+ }
+
+ public void createControl(Composite parent) {
+ main = new Composite(parent, SWT.NONE);
+ main.setLayout(new FormLayout());
+
+ pulldown = new Combo(main, SWT.READ_ONLY);
+ FormData pulldownData = new FormData();
+ pulldownData.left = new FormAttachment(0, 10);
+ pulldownData.right = new FormAttachment(0,400);
+ pulldownData.top = new FormAttachment(0, 10);
+ pulldown.setLayoutData(pulldownData);
+
+ beanLabel = new Label(main, SWT.NONE);
+ FormData beanLabelData = new FormData();
+ beanLabelData.left = new FormAttachment(0, 10);
+ beanLabelData.top = new FormAttachment(pulldown, 3);
+ beanLabel.setLayoutData(beanLabelData);
+
+ // small font size
+ Font initialFont = beanLabel.getFont();
+ FontData[] fontData = initialFont.getFontData();
+ for (int i = 0; i < fontData.length; i++) {
+ fontData[i].setHeight(7);
+ }
+ Font newFont = new Font(Display.getDefault(), fontData);
+ beanLabel.setFont(newFont);
+
+ Listener listener = new Listener() {
+ public void handleEvent(Event event) {
+ switch (event.type) {
+ case SWT.Selection:
+ case SWT.Modify:
+ pulldownSelectionChanged();
+ break;
+ }
+ }
+ };
+ pulldown.addListener(SWT.Selection, listener);
+ pulldown.addListener(SWT.Modify, listener);
+
+ book = new PageBook(main, SWT.NONE);
+ FormData bookData = new FormData();
+ bookData.top = new FormAttachment(beanLabel, 5);
+ bookData.left = new FormAttachment(0, 5);
+ bookData.right = new FormAttachment(100, -5);
+ bookData.bottom = new FormAttachment(100, -5);
+ book.setLayoutData(bookData);
+
+ errorGroup = new ErrorGroup(book, SWT.NONE);
+ operationGroup = new OperationGroup(book, SWT.NONE);
+ attributeGroup = new AttributeGroup(book, SWT.NONE, this);
+ }
+
+ public void dispose() {
+ }
+
+ public Control getControl() {
+ return main;
+ }
+
+ public void setActionBars(IActionBars actionBars) {
+ }
+
+ public void setFocus() {
+ }
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ Object obj = ((IStructuredSelection) selection).getFirstElement();
+ if (obj instanceof ContentWrapper)
+ obj = ((ContentWrapper) obj).getElement();
+
+ if (obj == null)
+ return;
+ setInputObject(obj);
+ }
+ }
+
+ protected void setInputObject(Object obj) {
+ if (obj instanceof JMXDomain) {
+ showDomainComposite((JMXDomain) obj);
+ } else if (obj instanceof JMXBean) {
+ setBean((JMXBean) obj);
+ } else if (obj instanceof JMXAttributesWrapper
+ || obj instanceof WrappedMBeanOperationInfo) {
+ setBean(getBeanFromInput(obj));
+ setComboSelectionFromInput(obj);
+ }
+ }
+
+ protected void setBean(JMXBean bean) {
+ if (bean != null) {
+ boolean requiresLoading = bean.getOperations() == null
+ && bean.getException() == null;
+ boolean hasError = bean.getOperations() == null
+ && bean.getException() != null;
+ boolean currentBeanLoading = bean == this.bean
+ && pulldown.getItems().length == 1
+ && pulldown.getItems()[0].equals(JMXViewProvider.LOADING_STRING_ARRAY[0]);
+ boolean finishedLoading = bean.getOperations() != null;
+
+ this.bean = bean;
+ beanLabel.setText("for MBean " + bean.getName());
+ if (requiresLoading) {
+ pulldown.setItems(JMXViewProvider.LOADING_STRING_ARRAY);
+ pulldown.select(0); // select Loading...
+ loadChildrenRefreshProperties(bean);
+ return; // do not re-layout during loading
+ } else if (hasError) {
+ // some error
+ showErrorComposite();
+ } else if (finishedLoading) {
+ // finished loading
+ operations = bean.getOperations();
+ pulldown.setItems(pulldownItems());
+ pulldown.select(0); // select Loading...
+ beanLabel.setText("for MBean " + bean.getName() + " ("
+ + operations.length + " operations, "
+ + bean.getAttributes().length + " attributes)");
+ }
+ main.layout();
+ }
+ }
+
+ protected JMXBean getBeanFromInput(Object obj) {
+ return obj instanceof JMXAttributesWrapper ? ((JMXAttributesWrapper) obj)
+ .getBean() : ((WrappedMBeanOperationInfo) obj).getBean();
+ }
+
+ protected void setComboSelectionFromInput(Object obj) {
+ int index = -1;
+ if (obj instanceof WrappedMBeanOperationInfo)
+ index = pulldown
+ .indexOf(getStringForOperation(((WrappedMBeanOperationInfo) obj)));
+ if (index == -1)
+ index = 0;
+ pulldown.select(index);
+ }
+
+ // get the list of combo items based on the bean
+ // The list should be Two larger than the number of operations
+ // ex: {Attributes..., ------, op1, op2, op3... etc}
+ protected String[] pulldownItems() {
+ WrappedMBeanOperationInfo[] ops = bean.getOperations();
+ String[] vals = null;
+ if (ops != null) {
+ if (ops.length == 0)
+ return new String[] { JMXViewProvider.ATTRIBUTES_STRING };
+ vals = new String[ops.length + 2];
+ vals[0] = JMXViewProvider.ATTRIBUTES_STRING;
+ vals[1] = "---------------";
+ for (int i = 0; i < ops.length; i++) {
+ vals[i + 2] = getStringForOperation(ops[i]);
+ }
+ }
+ return vals;
+ }
+
+ protected String getStringForOperation(WrappedMBeanOperationInfo op) {
+ return op.getInfo().getReturnType() + " " + op.getInfo().getName();
+ }
+
+ public void loadChildrenRefreshProperties(final Object bean) {
+ new Thread() {
+ public void run() {
+ provider.loadChildren(bean);
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ setInputObject(bean);
+ }
+ });
+ }
+ }.start();
+ }
+
+ protected void showDomainComposite(JMXDomain domain) {
+ // nothing
+ }
+
+ protected void showErrorComposite() {
+ book.showPage(errorGroup);
+ }
+
+ protected void pulldownSelectionChanged() {
+ if (pulldown.getSelectionIndex() != -1) {
+ int index = pulldown.getSelectionIndex();
+ if (index == 0 &&
pulldown.getItem(0).equals(JMXViewProvider.ATTRIBUTES_STRING)) {
+ attributeGroup.setBean(bean);
+ book.showPage(attributeGroup);
+ } else if (index >= 2 && operations != null
+ && index <= operations.length + 1) {
+ String selected = pulldown
+ .getItem(pulldown.getSelectionIndex());
+ book.showPage(operationGroup);
+ }
+ }
+ }
+
+}
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXTreeContentProvider.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXTreeContentProvider.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXTreeContentProvider.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -0,0 +1,121 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.jmx;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXAttributesWrapper;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXBean;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXDomain;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXException;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.WrappedMBeanOperationInfo;
+import org.jboss.ide.eclipse.as.ui.views.server.extensions.ServerViewProvider;
+
+public class JMXTreeContentProvider implements ITreeContentProvider {
+
+ protected JMXViewProvider provider;
+ public JMXTreeContentProvider(JMXViewProvider provider) {
+ this.provider = provider;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof ServerViewProvider) {
+ if (provider.getServer() == null)
+ return new Object[] {};
+ if (provider.getServer().getServerState() != IServer.STATE_STARTED) {
+ JMXModel.getDefault().clearModel(provider.getServer());
+ return new Object[] {};
+ }
+ JMXDomain[] domains =
JMXModel.getDefault().getModel(provider.getServer()).getDomains();
+ if (domains == null
+ && JMXModel.getDefault().getModel(provider.getServer()).getException() ==
null) {
+ loadChildrenRefreshViewer(parentElement);
+ return new Object[] { JMXViewProvider.LOADING };
+ } else if (domains == null
+ && JMXModel.getDefault().getModel(provider.getServer()).getException() !=
null) {
+ return new Object[] {
JMXModel.getDefault().getModel(provider.getServer()).getException() };
+ }
+ return domains;
+ }
+ if (parentElement instanceof JMXDomain) {
+ JMXBean[] beans = ((JMXDomain) parentElement).getBeans();
+ if (beans == null
+ && ((JMXDomain) parentElement).getException() == null) {
+ loadChildrenRefreshViewer(parentElement);
+ return new Object[] { JMXViewProvider.LOADING };
+ } else if (beans == null
+ && ((JMXDomain) parentElement).getException() != null) {
+ return new Object[] { ((JMXDomain) parentElement)
+ .getException() };
+ }
+ return beans;
+ }
+ if (parentElement instanceof JMXBean) {
+ WrappedMBeanOperationInfo[] operations = ((JMXBean) parentElement)
+ .getOperations();
+ if (operations == null
+ && ((JMXBean) parentElement).getException() == null) {
+ loadChildrenRefreshViewer(parentElement);
+ return new Object[] { JMXViewProvider.LOADING };
+ } else if (operations == null
+ && ((JMXBean) parentElement).getException() != null) {
+ return new Object[] { ((JMXBean) parentElement)
+ .getException() };
+ }
+ // add the Attributes element
+ ArrayList<Object> list = new ArrayList<Object>();
+ list.add(new JMXAttributesWrapper((JMXBean) parentElement));
+ list.addAll(Arrays.asList(operations));
+ return (Object[]) list.toArray(new Object[list.size()]);
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ return null; // unused
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof ServerViewProvider) {
+ if (provider.getServer() == null ||
+ provider.getServer().getServerState() != IServer.STATE_STARTED) {
+ return false;
+ }
+ return true;
+ }
+ if (element instanceof JMXException)
+ return false;
+ if (element instanceof WrappedMBeanOperationInfo)
+ return false;
+ if (element instanceof JMXAttributesWrapper)
+ return false;
+ return true; // always true?
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return null; // unused here
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (oldInput != newInput) {
+ provider.setServer((IServer) newInput);
+ }
+ }
+
+ protected void loadChildrenRefreshViewer(final Object parent) {
+ new Thread() {
+ public void run() {
+ provider.loadChildren(parent);
+ provider.refreshViewerAsync(parent);
+ }
+ }.start();
+ }
+
+
+}
Copied:
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXViewProvider.java
(from rev 3672,
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/JMXViewProvider.java)
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXViewProvider.java
(rev 0)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/views/server/providers/jmx/JMXViewProvider.java 2007-09-19
02:32:12 UTC (rev 3701)
@@ -0,0 +1,205 @@
+package org.jboss.ide.eclipse.as.ui.views.server.providers.jmx;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerLifecycleListener;
+import org.eclipse.wst.server.core.IServerListener;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.ServerEvent;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXClassLoaderRepository;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXBean;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXModel.JMXDomain;
+import org.jboss.ide.eclipse.as.ui.views.server.JBossServerView;
+import org.jboss.ide.eclipse.as.ui.views.server.ExtensionTableViewer.ContentWrapper;
+import org.jboss.ide.eclipse.as.ui.views.server.extensions.JBossServerViewExtension;
+import org.jboss.ide.eclipse.as.ui.views.server.extensions.ServerViewProvider;
+import org.jboss.ide.eclipse.as.ui.views.server.util.ViewUtilityMethods;
+
+public class JMXViewProvider extends JBossServerViewExtension {
+ public static final Object LOADING = new Object();
+ public static final String[] LOADING_STRING_ARRAY = new String[] {
"Loading..." };
+ public static final String ATTRIBUTES_STRING = "Attributes...";
+
+ public static final Object CLASSLOADING_TOKEN = new Object();
+
+ protected JMXPropertySheetPage propertyPage;
+ protected JMXServerLifecycleListener lcListener;
+ protected JMXServerListener serverListener;
+ protected ISelectionChangedListener jbossServerViewSelectionListener;
+ protected JMXTreeContentProvider contentProvider;
+ protected JMXLabelProvider labelProvider;
+ protected IServer server;
+
+ public JMXViewProvider() {
+ }
+
+ public void setServer(IServer server) {
+ this.server = server;
+ }
+
+ public IServer getServer() {
+ return this.server;
+ }
+
+ public void enable() {
+ addListeners();
+ }
+ public void disable() {
+ removeListeners();
+ }
+
+
+ protected void addListeners() {
+ jbossServerViewSelectionListener = new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ Object o = JBossServerView.getDefault()
+ .getExtensionFrame().getViewer()
+ .getSelectedElement();
+ if (o instanceof JMXBean) {
+ Display.getDefault().asyncExec(new Runnable() { public void run() {
+ ViewUtilityMethods.activatePropertiesView(null);
+ }});
+ }
+ }
+ };
+
+ JBossServerView.addExtensionFrameListener(jbossServerViewSelectionListener);
+
+ // make sure we know about server events
+ serverListener = new JMXServerListener();
+ lcListener = new JMXServerLifecycleListener();
+ ServerCore.addServerLifecycleListener(lcListener);
+ IServer[] servers = ServerCore.getServers();
+ for (int i = 0; i < servers.length; i++) {
+ servers[i].addServerListener(serverListener);
+ if( servers[i].getServerState() == IServer.STATE_STARTED )
+ JMXClassLoaderRepository.getDefault().addConcerned(
+ servers[i], CLASSLOADING_TOKEN);
+ }
+ }
+
+ protected void removeListeners() {
+ ServerCore.removeServerLifecycleListener(lcListener);
+ IServer[] servers = ServerCore.getServers();
+ for (int i = 0; i < servers.length; i++) {
+ servers[i].removeServerListener(serverListener);
+ JMXClassLoaderRepository.getDefault().removeConcerned(
+ servers[i], CLASSLOADING_TOKEN);
+ }
+ JBossServerView.removeExtensionFrameListener(jbossServerViewSelectionListener);
+ }
+
+ protected class JMXServerLifecycleListener implements
+ IServerLifecycleListener {
+ public void serverAdded(IServer server) {
+ server.addServerListener(serverListener);
+ }
+
+ public void serverChanged(IServer server) {
+ }
+
+ public void serverRemoved(IServer server) {
+ server.removeServerListener(serverListener);
+ JMXClassLoaderRepository.getDefault()
+ .removeConcerned(server, JMXModel.getDefault());
+ }
+ }
+
+ protected class JMXServerListener implements IServerListener {
+ public void serverChanged(ServerEvent event) {
+ if ((event.getKind() & ServerEvent.SERVER_CHANGE) != 0) {
+ if ((event.getKind() & ServerEvent.STATE_CHANGE) != 0) {
+ if (event.getState() == IServer.STATE_STARTED) {
+ JMXClassLoaderRepository.getDefault().addConcerned(
+ event.getServer(), CLASSLOADING_TOKEN);
+ } else {
+ JMXClassLoaderRepository.getDefault().removeConcerned(
+ event.getServer(), CLASSLOADING_TOKEN);
+ }
+ }
+ }
+ }
+ }
+
+ public IPropertySheetPage getPropertySheetPage() {
+ if (propertyPage == null) {
+ propertyPage = new JMXPropertySheetPage(this);
+ }
+ return propertyPage;
+ }
+
+ public ITreeContentProvider getContentProvider() {
+ if (contentProvider == null)
+ contentProvider = new JMXTreeContentProvider(this);
+ return contentProvider;
+ }
+
+ public LabelProvider getLabelProvider() {
+ if (labelProvider == null)
+ labelProvider = new JMXLabelProvider();
+ return labelProvider;
+ }
+
+
+ protected void loadChildren(Object parent) {
+ if (parent instanceof ServerViewProvider)
+ JMXModel.getDefault().getModel(server).loadDomains();
+ else if (parent instanceof JMXDomain)
+ ((JMXDomain) parent).loadBeans();
+ else if (parent instanceof JMXBean)
+ ((JMXBean) parent).loadInfo();
+ }
+
+ public void refreshViewerAsync(final Object parent) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ refreshViewer(parent);
+ }
+ });
+ }
+
+ public void refreshModel(Object object) {
+ if( object instanceof ContentWrapper )
+ object = ((ContentWrapper)object).getElement();
+ if (object instanceof ServerViewProvider) {
+ JMXModel.getDefault().clearModel(server);
+ } else if (object instanceof JMXDomain) {
+ ((JMXDomain) object).resetChildren();
+ } else if (object instanceof JMXBean) {
+ ((JMXBean) object).resetChildren();
+ }
+ }
+
+ protected static class ErrorGroup extends Composite {
+ protected Group group;
+ public ErrorGroup(Composite parent, int style) {
+ super(parent, style);
+ setLayout(new FillLayout());
+ group = new Group(this, SWT.NONE);
+ group.setText("Error");
+ }
+ }
+
+ protected static class OperationGroup extends Composite {
+ protected Group group;
+ public OperationGroup(Composite parent, int style) {
+ super(parent, style);
+ setLayout(new FillLayout());
+ group = new Group(this, SWT.NONE);
+ group.setText("Operation");
+ }
+ }
+
+
+}