diff options
8 files changed, 502 insertions, 154 deletions
diff --git a/java/distribution/src/main/assembly/management-eclipse-plugin.xml b/java/distribution/src/main/assembly/management-eclipse-plugin.xml index 826128b42f..5c109181ff 100644 --- a/java/distribution/src/main/assembly/management-eclipse-plugin.xml +++ b/java/distribution/src/main/assembly/management-eclipse-plugin.xml @@ -83,9 +83,6 @@ <fileSet> <directory>../management/eclipse-plugin/bin</directory> <outputDirectory>qpidmc/bin</outputDirectory> - <includes> - <include>**</include> - </includes> <fileMode>777</fileMode> </fileSet> <fileSet> @@ -95,6 +92,10 @@ <include>MANIFEST.MF</include> </includes> </fileSet> + <fileSet> + <directory>../management/eclipse-plugin/src/main/resources/org.apache.commons.codec</directory> + <outputDirectory>qpidmc/eclipse/plugins/</outputDirectory> + </fileSet> </fileSets> <dependencySets> diff --git a/java/management/eclipse-plugin/META-INF/MANIFEST.MF b/java/management/eclipse-plugin/META-INF/MANIFEST.MF index a03c35c457..658fa2cb4c 100644 --- a/java/management/eclipse-plugin/META-INF/MANIFEST.MF +++ b/java/management/eclipse-plugin/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.ui.forms, - jmxremote.sasl + jmxremote.sasl, + org.apache.commons.codec Eclipse-LazyStart: true Bundle-Vendor: Apache Software Foundation diff --git a/java/management/eclipse-plugin/pom.xml b/java/management/eclipse-plugin/pom.xml index 6637460822..04ac9b63db 100644 --- a/java/management/eclipse-plugin/pom.xml +++ b/java/management/eclipse-plugin/pom.xml @@ -15,7 +15,7 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ---> + --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> @@ -38,22 +38,28 @@ </properties> <repositories> - <repository> + <repository> <id>repo1.maven.org</id> <name>Maven eclipse Repository</name> <url>http://repo1.maven.org/eclipse</url> - </repository> - <repository> + </repository> + <repository> <id>apache.snapshots</id> <name>Apache SNAPSHOT Repository</name> <url>http://people.apache.org/repo/m2-snapshot-repository</url> <snapshots> - <enabled>true</enabled> + <enabled>true</enabled> </snapshots> </repository> </repositories> <dependencies> + <dependency> + <groupId>commons-codec</groupId> + <artifactId>commons-codec</artifactId> + <version>1.3</version> + <scope>compile</scope> + </dependency> <dependency> <groupId>com.ibm.icu</groupId> <artifactId>com.ibm.icu</artifactId> @@ -197,43 +203,46 @@ <directory>icons/</directory> <targetPath>icons/</targetPath> <includes> - <include>**</include> + <include>**</include> </includes> </resource> <resource> <directory>icons/</directory> <targetPath>/</targetPath> <includes> - <include>splash.bmp</include> + <include>splash.bmp</include> </includes> </resource> <resource> - <directory>${basedir}</directory> - <targetPath>/</targetPath> - <includes> - <include>plugin.xml</include> - <include>plugin.properties</include> - </includes> + <directory>${basedir}</directory> + <targetPath>/</targetPath> + <includes> + <include>plugin.xml</include> + <include>plugin.properties</include> + </includes> </resource> - </resources> + </resources> <plugins> <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> </plugin> + --> + <!-- This is required to identify the JAR to eclipse as a plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> - <archive> - <manifestFile>META-INF/MANIFEST.MF</manifestFile> - </archive> - <finalName>${artifactId}_${version}</finalName> + <archive> + <manifestFile>META-INF/MANIFEST.MF</manifestFile> + </archive> + <finalName>${artifactId}_${version}</finalName> </configuration> - </plugin> + </plugin> + <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java index f5b4a22e03..bc895411d2 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/OperationTabControl.java @@ -64,7 +64,6 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.widgets.Form; import org.eclipse.ui.forms.widgets.FormToolkit; - /** * Control class for the MBean operations tab. It creates the required widgets * for the selected MBean. @@ -519,12 +518,12 @@ public class OperationTabControl extends TabControl private void populateResults(Object result) { Display display = Display.getCurrent(); - int width = 600; - int height = 400; + int width = 610; + int height = 400; Shell shell = ViewUtility.createPopupShell(RESULT, width, height); shell.setImage(ApplicationRegistry.getImage(CONSOLE_IMAGE)); ViewUtility.populateCompositeWithData(_toolkit, shell, result); - + shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java index 4f2b70f869..4a441d3ae5 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/views/ViewUtility.java @@ -20,33 +20,18 @@ */ package org.apache.qpid.management.ui.views; -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.management.openmbean.ArrayType; -import javax.management.openmbean.CompositeData; -import javax.management.openmbean.CompositeDataSupport; -import javax.management.openmbean.CompositeType; -import javax.management.openmbean.OpenType; -import javax.management.openmbean.TabularDataSupport; -import javax.management.openmbean.TabularType; - +import org.apache.commons.codec.binary.Hex; import org.apache.qpid.management.ui.ApplicationWorkbenchAdvisor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.ErrorDialog; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Font; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -55,29 +40,51 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.ScrollBar; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.widgets.FormToolkit; +import javax.management.openmbean.ArrayType; +import javax.management.openmbean.CompositeData; +import javax.management.openmbean.CompositeDataSupport; +import javax.management.openmbean.CompositeType; +import javax.management.openmbean.OpenType; +import javax.management.openmbean.TabularDataSupport; +import javax.management.openmbean.TabularType; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; + + /** * Utility Class for displaying OpenMbean data types by creating required SWT widgets * @author Bhupendra Bhardwaj */ public class ViewUtility { - public static final String OP_NAME = "operation_name"; - public static final String OP_PARAMS = "parameters"; + public static final String OP_NAME = "operation_name"; + public static final String OP_PARAMS = "parameters"; public static final String PARAMS_TEXT = "text"; public static final String FIRST = "First"; - public static final String LAST = "Last"; - public static final String NEXT = "Next"; - public static final String PREV = "Previous"; + public static final String LAST = "Last"; + public static final String NEXT = "Next"; + public static final String PREV = "Previous"; public static final String INDEX = "Index"; - + private static final Comparator tabularDataComparator = new TabularDataComparator(); - + private static List<String> SUPPORTED_ARRAY_DATATYPES = new ArrayList<String>(); + private static final int DEFAULT_CONTENT_SIZE = 198; + static { SUPPORTED_ARRAY_DATATYPES.add("java.lang.String"); @@ -88,7 +95,7 @@ public class ViewUtility SUPPORTED_ARRAY_DATATYPES.add("java.lang.Double"); SUPPORTED_ARRAY_DATATYPES.add("java.util.Date"); } - + /** * Populates the composite with given openmbean data type (TabularType or CompositeType) * @param toolkit @@ -99,14 +106,14 @@ public class ViewUtility { if (data instanceof TabularDataSupport) { - ViewUtility.createTabularDataHolder(toolkit, parent, (TabularDataSupport)data); + ViewUtility.createTabularDataHolder(toolkit, parent, (TabularDataSupport) data); } else if (data instanceof CompositeDataSupport) { - ViewUtility.populateCompositeWithCompositeData(toolkit, parent, (CompositeDataSupport)data); + ViewUtility.populateCompositeWithCompositeData(toolkit, parent, (CompositeDataSupport) data); } } - + @SuppressWarnings("unchecked") private static void createTabularDataHolder(FormToolkit toolkit, Composite parent, TabularDataSupport tabularData) { @@ -127,20 +134,20 @@ public class ViewUtility GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1); text.setLayoutData(layoutData); return; - } - + } + Collections.sort(list, tabularDataComparator); - + // Attach the tabular record to be retrieved and shown later when record is traversed // using first/next/previous/last buttons composite.setData(list); - + // Create button and the composite for CompositeData Composite compositeDataHolder = createCompositeDataHolder(toolkit, composite, - tabularData.getTabularType().getRowType()); + tabularData.getTabularType().getRowType()); // display the first record - CompositeData data = (CompositeData)(list.get(0)).getValue(); + CompositeData data = (CompositeData) (list.get(0)).getValue(); composite.setData(INDEX, 0); populateCompositeWithCompositeData(toolkit, compositeDataHolder, data); enableOrDisableTraversalButtons(composite); @@ -148,23 +155,23 @@ public class ViewUtility private static void enableOrDisableTraversalButtons(Composite composite) { - int index = (Integer)composite.getData(INDEX); - int size = ((List)composite.getData()).size(); + int index = (Integer) composite.getData(INDEX); + int size = ((List) composite.getData()).size(); - ((Button)composite.getData(FIRST)).setEnabled(true); - ((Button)composite.getData(PREV)).setEnabled(true); - ((Button)composite.getData(NEXT)).setEnabled(true); - ((Button)composite.getData(LAST)).setEnabled(true); + ((Button) composite.getData(FIRST)).setEnabled(true); + ((Button) composite.getData(PREV)).setEnabled(true); + ((Button) composite.getData(NEXT)).setEnabled(true); + ((Button) composite.getData(LAST)).setEnabled(true); if (index == 0) { - ((Button)composite.getData(FIRST)).setEnabled(false); - ((Button)composite.getData(PREV)).setEnabled(false); + ((Button) composite.getData(FIRST)).setEnabled(false); + ((Button) composite.getData(PREV)).setEnabled(false); } - if (index == size -1) + if (index == size - 1) { - ((Button)composite.getData(NEXT)).setEnabled(false); - ((Button)composite.getData(LAST)).setEnabled(false); + ((Button) composite.getData(NEXT)).setEnabled(false); + ((Button) composite.getData(LAST)).setEnabled(false); } } @@ -177,34 +184,34 @@ public class ViewUtility * @return */ private static Composite createCompositeDataHolder(final FormToolkit toolkit, final Composite dataHolder, CompositeType compositeType) - { + { String desc = compositeType.getDescription(); Label description = toolkit.createLabel(dataHolder, desc, SWT.CENTER); - description.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false, 4, 1)); + description.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false, 4, 1)); // TODO nameLabel.setFont(font); description.setText(desc); // Add traversal buttons final Button firstRecordButton = toolkit.createButton(dataHolder, FIRST, SWT.PUSH); - GridData layoutData = new GridData (GridData.HORIZONTAL_ALIGN_END); + GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_END); layoutData.widthHint = 80; firstRecordButton.setLayoutData(layoutData); final Button nextRecordButton = toolkit.createButton(dataHolder, NEXT, SWT.PUSH); - layoutData = new GridData (GridData.HORIZONTAL_ALIGN_END); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_END); layoutData.widthHint = 80; nextRecordButton.setLayoutData(layoutData); final Button previousRecordButton = toolkit.createButton(dataHolder, PREV, SWT.PUSH); - layoutData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); layoutData.widthHint = 80; previousRecordButton.setLayoutData(layoutData); final Button lastRecordButton = toolkit.createButton(dataHolder, LAST, SWT.PUSH); - layoutData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); layoutData.widthHint = 80; lastRecordButton.setLayoutData(layoutData); - + // Now create the composite, which will hold the CompositeData final Composite composite = toolkit.createComposite(dataHolder, SWT.NONE); GridLayout layout = new GridLayout(); @@ -228,24 +235,26 @@ public class ViewUtility public void widgetSelected(SelectionEvent e) { if (!(e.widget instanceof Button)) + { return; + } - Button traverseButton =(Button)e.widget; + Button traverseButton = (Button) e.widget; // Get the CompositeData respective to the button selected CompositeData data = getCompositeData(dataHolder, traverseButton.getText()); populateCompositeWithCompositeData(toolkit, composite, data); - enableOrDisableTraversalButtons(dataHolder); + enableOrDisableTraversalButtons(dataHolder); } }; - firstRecordButton.addSelectionListener(listener); + firstRecordButton.addSelectionListener(listener); nextRecordButton.addSelectionListener(listener); previousRecordButton.addSelectionListener(listener); lastRecordButton.addSelectionListener(listener); return composite; } - + /** * The CompositeData is set as data with the Composite and using the index, this method will * return the corresponding CompositeData @@ -255,7 +264,7 @@ public class ViewUtility */ private static CompositeData getCompositeData(Composite compositeHolder, String dataIndex) { - List objectData = (List)compositeHolder.getData(); + List objectData = (List) compositeHolder.getData(); if (objectData == null || objectData.isEmpty()) { // TODO @@ -265,7 +274,7 @@ public class ViewUtility int index = 0; if (compositeHolder.getData(INDEX) != null) { - index = (Integer)compositeHolder.getData(INDEX); + index = (Integer) compositeHolder.getData(INDEX); } if (FIRST.equals(dataIndex)) @@ -282,13 +291,13 @@ public class ViewUtility } else if (LAST.equals(dataIndex)) { - index = objectData.size() -1; + index = objectData.size() - 1; } // Set the index being shown. compositeHolder.setData(INDEX, index); - return (CompositeData)((Map.Entry)objectData.get(index)).getValue(); + return (CompositeData) ((Map.Entry) objectData.get(index)).getValue(); } /** @@ -300,19 +309,18 @@ public class ViewUtility @SuppressWarnings("unchecked") private static void populateCompositeWithCompositeData(FormToolkit toolkit, Composite parent, CompositeData data) { - Control[] oldControls = parent.getChildren(); + Control[] oldControls = parent.getChildren(); for (int i = 0; i < oldControls.length; i++) { oldControls[i].dispose(); } - + Composite compositeHolder = toolkit.createComposite(parent, SWT.NONE); GridLayout layout = new GridLayout(4, false); layout.horizontalSpacing = 10; compositeHolder.setLayout(layout); - compositeHolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - - + compositeHolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + // ItemNames in composite data List<String> itemNames = new ArrayList<String>(data.getCompositeType().keySet()); @@ -326,21 +334,21 @@ public class ViewUtility if (itemType.isArray()) { - OpenType type = ((ArrayType)itemType).getElementOpenType(); + OpenType type = ((ArrayType) itemType).getElementOpenType(); // If Byte array and mimetype is text, convert to text string if (type.getClassName().equals(Byte.class.getName())) { - String mimeType = null; + String mimeType = null; String encoding = null; if (data.containsKey("MimeType")) { - mimeType = (String)data.get("MimeType"); + mimeType = (String) data.get("MimeType"); } if (data.containsKey("Encoding")) { - encoding = (String)data.get("Encoding"); + encoding = (String) data.get("Encoding"); } - + if (encoding == null || encoding.length() == 0) { encoding = Charset.defaultCharset().name(); @@ -352,8 +360,8 @@ public class ViewUtility } else { - setNotSupportedDataType(toolkit, compositeHolder); - } + handleBinaryMessageContent(toolkit, compositeHolder, data, itemName, encoding); + } } // If array of any other supported type, show as a list of String array else if (SUPPORTED_ARRAY_DATATYPES.contains(type.getClassName())) @@ -373,23 +381,23 @@ public class ViewUtility layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); - createTabularDataHolder(toolkit, composite, (TabularDataSupport)data.get(itemName)); + createTabularDataHolder(toolkit, composite, (TabularDataSupport) data.get(itemName)); } else { Text valueText = toolkit.createText(compositeHolder, String.valueOf(data.get(itemName)), SWT.READ_ONLY | SWT.BORDER); valueText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); } - } - + } + // layout the composite after creating new widgets. parent.layout(); } //end of method - - + + private static void convertByteArray(FormToolkit toolkit, Composite compositeHolder, CompositeData data, String itemName, String encoding) { - Byte[] arrayItems = (Byte[])data.get(itemName); + Byte[] arrayItems = (Byte[]) data.get(itemName); byte[] byteArray = new byte[arrayItems.length]; for (int i = 0; i < arrayItems.length; i++) @@ -401,56 +409,384 @@ public class ViewUtility String textMessage = new String(byteArray, encoding); Text valueText = toolkit.createText(compositeHolder, textMessage, SWT.READ_ONLY | SWT.BORDER | - SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); + SWT.MULTI | SWT.WRAP | SWT.V_SCROLL); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1); gridData.heightHint = 300; valueText.setLayoutData(gridData); } - catch(Exception ex) + catch (Exception ex) { ex.printStackTrace(); } } - + + static Button _firstButton, _nextButton, _previousButton, _lastButton; + static Text _hexNumTextToEnd, _hexNumTextToStart; + + /** + * Creates widgets for object messages and populates the content in hexadecimal format. + * @param toolkit + * @param compositeHolder + * @param data + * @param itemName + * @param encoding + */ + private static void handleBinaryMessageContent(FormToolkit toolkit, Composite compositeHolder, CompositeData data, String itemName, String encoding) + { + final String thisEncoding = encoding; + final Byte[] arrayItems = (Byte[]) data.get(itemName); + final byte[] byteArray = new byte[arrayItems.length]; + + for (int i = 0; i < arrayItems.length; i++) + { + byteArray[i] = arrayItems[i]; + } + + try + { + //create a new composite to contain the widgets required to display object messages. + final Composite localComposite = toolkit.createComposite(compositeHolder, SWT.NONE); + localComposite.setData("currentBytePos", 0); + localComposite.setData("startingBytePos", 0); + GridLayout layout = new GridLayout(2, true); + layout.marginWidth = 0; + layout.marginHeight = 0; + localComposite.setLayout(layout); + localComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); + + int startContentSize = DEFAULT_CONTENT_SIZE; // This will fill the 18 rows of the standard size + + if (byteArray.length < DEFAULT_CONTENT_SIZE) + { + startContentSize = byteArray.length; + } + + //create a text to display the hexadecimal views of object messages, it takes more space than ascii view as a hex uses 2 chars + //and 1 space, while ascii only uses 1 char and 1 space. + final Text hexText = toolkit.createText(localComposite, + new String(displayByteFormat(localComposite, byteArray, startContentSize * 2, thisEncoding, "<<", true)), + SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + gridData.widthHint = 144; //set to 222 if not using any fonts + gridData.heightHint = 200; + hexText.setLayoutData(gridData); + + final Text asciiText = toolkit.createText(localComposite, + new String(displayByteFormat(localComposite, byteArray, startContentSize * 2, thisEncoding, "<<", false)), + SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER); + + + gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1); + gridData.widthHint = 52;//set to 98 if not using any fonts + gridData.heightHint = 200; + asciiText.setLayoutData(gridData); + + //use a monospaced font for a better layout + Font font = new Font(compositeHolder.getDisplay(), "Courier", 10, SWT.NORMAL); + hexText.setFont(font); + asciiText.setFont(font); + + final ScrollBar hexScrollBar = hexText.getVerticalBar(); + final ScrollBar asciiScrollBar = asciiText.getVerticalBar(); + + //create a sub composite to contain all the buttons + final Composite buttonComposite = toolkit.createComposite(localComposite, SWT.NONE); + layout = new GridLayout(7, false); + layout.marginWidth = 0; + buttonComposite.setLayout(layout); + buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1)); + + _firstButton = toolkit.createButton(buttonComposite, "<<", SWT.PUSH); + GridData layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _firstButton.setLayoutData(layoutData); + _firstButton.setToolTipText("See the first n bytes"); + + _previousButton = toolkit.createButton(buttonComposite, "<", SWT.PUSH); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _previousButton.setLayoutData(layoutData); + _previousButton.setToolTipText("See the previous n bytes"); + _previousButton.setEnabled(false); + + _hexNumTextToStart = toolkit.createText(buttonComposite, "0"); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _hexNumTextToStart.setLayoutData(layoutData); + _hexNumTextToStart.setEditable(false); + + final Text hexNumText = toolkit.createText(buttonComposite, "" + startContentSize); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + hexNumText.setLayoutData(layoutData); + + _hexNumTextToEnd = toolkit.createText(buttonComposite, "" + (byteArray.length - startContentSize)); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _hexNumTextToEnd.setLayoutData(layoutData); + _hexNumTextToEnd.setEditable(false); + + _nextButton = toolkit.createButton(buttonComposite, ">", SWT.PUSH); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _nextButton.setLayoutData(layoutData); + _nextButton.setToolTipText("See the next n bytes"); + _nextButton.setEnabled(true); + + _lastButton = toolkit.createButton(buttonComposite, ">>", SWT.PUSH); + layoutData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + layoutData.widthHint = 40; + _lastButton.setToolTipText("See the last n bytes"); + _lastButton.setLayoutData(layoutData); + + SelectionListener listener = new SelectionAdapter() + { + public void widgetSelected(SelectionEvent e) + { + if (e.widget instanceof Button) + { + String numOfBytes = hexNumText.getText(); + try + { + int n = Integer.parseInt(numOfBytes); + + //Reset range display if user requests a large value + if (n > byteArray.length) + { + n = (byteArray.length > DEFAULT_CONTENT_SIZE) ? DEFAULT_CONTENT_SIZE : byteArray.length; + hexNumText.setText("" + n); + } + + //rest if the user requests 0 + if (n < 1) + { + n = DEFAULT_CONTENT_SIZE; + hexNumText.setText("" + n); + } + + Button button = (Button) e.widget; + hexText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding, + button.getText(), true)); + asciiText.setText(displayByteFormat(localComposite, byteArray, n * 2, thisEncoding, + button.getText(), false)); + } + catch (NumberFormatException exp) + { + popupErrorMessage("Error", + "Please input the number of bytes you wish to look at"); + } + } + if (e.widget instanceof ScrollBar) + { + //synchronize the movements of the two scrollbars + ScrollBar sb = (ScrollBar) e.widget; + if (sb.getParent().equals(hexText)) + { + asciiScrollBar.setIncrement(sb.getIncrement()); + asciiScrollBar.setSelection(sb.getSelection()); + asciiText.setTopIndex(hexText.getTopIndex()); + } + else if (sb.getParent().equals(asciiText)) + { + hexScrollBar.setSelection(sb.getSelection()); + hexScrollBar.setIncrement(sb.getIncrement()); + hexText.setTopIndex(asciiText.getTopIndex()); + } + } + } + }; + localComposite.addControlListener(new ControlAdapter() + { + public void controlResized(ControlEvent e) + { + //if the control is resized, set different parameters to make a single line displays the same contents. + if (((GridLayout) localComposite.getLayout()).makeColumnsEqualWidth) + { + ((GridLayout) localComposite.getLayout()).makeColumnsEqualWidth = false; + ((GridLayout) localComposite.getLayout()).numColumns = 2; + ((GridData) hexText.getLayoutData()).horizontalSpan = 1; + ((GridData) hexText.getLayoutData()).widthHint = 144; + ((GridData) asciiText.getLayoutData()).horizontalSpan = 1; + ((GridData) asciiText.getLayoutData()).widthHint = 52; + ((GridData) buttonComposite.getLayoutData()).horizontalSpan = 2; + } + else + { + ((GridLayout) localComposite.getLayout()).makeColumnsEqualWidth = true; + ((GridLayout) localComposite.getLayout()).numColumns = 42; //set to 47 if not using any fonts + ((GridData) hexText.getLayoutData()).horizontalSpan = 25; // set to 30 if not using any fonts + ((GridData) asciiText.getLayoutData()).horizontalSpan = 17; // set to 17 if not using any fonts + ((GridData) buttonComposite.getLayoutData()).horizontalSpan = 42; + } + } + }); + + _firstButton.addSelectionListener(listener); + _previousButton.addSelectionListener(listener); + _nextButton.addSelectionListener(listener); + _lastButton.addSelectionListener(listener); + hexScrollBar.addSelectionListener(listener); + asciiScrollBar.addSelectionListener(listener); + //f.dispose(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + /** + * Format object messages to have a hexadecimal view and a ascii view. + * @param numOfBytes + * @param encoding + * @return + */ + private static String displayByteFormat(Composite localComposite, byte[] byteArray, int numOfBytes, String encoding, String direction, boolean isHex) + { + final Hex hexeconder = new Hex(); + final byte[] encoded = hexeconder.encode(byteArray); + + int hexLength = byteArray.length * 2; + StringBuilder sb = new StringBuilder(); + int currentBytePos = (Integer) localComposite.getData("currentBytePos"); + int startingBytePos = (Integer) localComposite.getData("startingBytePos"); + + int strLength = 0; + int offset = 0; + String encStr; + if (isHex) + { + if (direction.equals("<<")) + { + strLength = (numOfBytes > hexLength) ? hexLength : numOfBytes; + offset = 0; + } + else if (direction.equals("<")) + { + strLength = (startingBytePos - numOfBytes < 0) ? startingBytePos + : numOfBytes; + offset = (startingBytePos - numOfBytes < 0) ? 0 + : startingBytePos - numOfBytes; + } + else if (direction.equals(">")) + { + strLength = (numOfBytes > (hexLength - currentBytePos)) ? hexLength + - currentBytePos + : numOfBytes; + offset = currentBytePos; + + } + else if (direction.equals(">>")) + { + strLength = (numOfBytes > hexLength) ? hexLength : numOfBytes; + offset = (hexLength - numOfBytes > 0) ? hexLength - numOfBytes + : 0; + } + else + { + strLength = hexLength; + offset = 0; + } + localComposite.setData("strLength", strLength); + localComposite.setData("currentBytePos", offset + strLength); + localComposite.setData("startingBytePos", offset); + + if (_lastButton != null && !_lastButton.isDisposed()) + { + //Set button state + _previousButton.setEnabled(offset != 0); + _nextButton.setEnabled(offset + strLength != hexLength); + + //set the text fields + _hexNumTextToStart.setText("" + offset / 2); + _hexNumTextToEnd.setText("" + (hexLength - (offset + strLength)) / 2); + } + } + + try + { + if (isHex) + { + encStr = new String(encoded, offset, strLength, encoding); + for (int c = 0; c < strLength; c++) + { + + sb.append(encStr.charAt(c)); + if (c % 2 == 1) + { + sb.append(" "); + } + + } + return sb.toString().toUpperCase(); + } + else + { + strLength = (Integer) localComposite.getData("strLength"); + sb = new StringBuilder(); + encStr = new String(byteArray, startingBytePos / 2, strLength / 2, encoding); + for (int c = 0; c < encStr.length(); c++) + { + char ch = encStr.charAt(c); + if (ch > 31 && ch < 127) + { + sb.append(ch); + } + else + { + sb.append("?"); + } + + sb.append(" "); + } + } + } + catch (UnsupportedEncodingException e) + { + e.printStackTrace(); + } + return sb.toString(); + } + public static int popupInfoMessage(String title, String message) { MessageBox messageBox = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_INFORMATION | SWT.OK); messageBox.setMessage(message); messageBox.setText(title); int response = messageBox.open(); - + return response; } - + public static int popupErrorMessage(String title, String message) { MessageBox messageBox = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_ERROR | SWT.OK); messageBox.setMessage(message); messageBox.setText(title); int response = messageBox.open(); - + return response; } - + public static int popupConfirmationMessage(String title, String message) { - MessageBox messageBox = new MessageBox(Display.getCurrent().getActiveShell(), - SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL); + MessageBox messageBox = new MessageBox(Display.getCurrent().getActiveShell(), + SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL); messageBox.setMessage(message); messageBox.setText(title); int response = messageBox.open(); - + return response; } - + public static void popupError(String title, String message, Throwable ex) { IStatus status = new Status(IStatus.ERROR, ApplicationWorkbenchAdvisor.PERSPECTIVE_ID, - IStatus.ERROR, ex.toString(), ex); + IStatus.ERROR, ex.toString(), ex); ErrorDialog.openError(Display.getCurrent().getActiveShell(), title, message, status); } - + public static void popupError(String errorMsg) { Display display = Display.getCurrent(); @@ -461,12 +797,12 @@ public class ViewUtility int y = display.getBounds().height; int width = 500; int height = 250; - shell.setBounds(x/4, y/4, width, height); - + shell.setBounds(x / 4, y / 4, width, height); + Label label = new Label(shell, SWT.NONE); label.setText(errorMsg); label.setLayoutData(new GridData(SWT.TRAIL, SWT.TOP, false, false)); - + shell.open(); while (!shell.isDisposed()) { @@ -477,20 +813,20 @@ public class ViewUtility } shell.dispose(); } - + public static Shell createPopupShell(String title, int width, int height) { Display display = Display.getCurrent(); - Shell shell = new Shell(display, SWT.BORDER | SWT.CLOSE | SWT.MIN |SWT.MAX); + Shell shell = new Shell(display, SWT.BORDER | SWT.CLOSE | SWT.MIN | SWT.MAX); shell.setText(title); - shell.setLayout(new GridLayout()); + shell.setLayout(new GridLayout()); int x = display.getBounds().width; int y = display.getBounds().height; - shell.setBounds(x/4, y/4, width, height); - + shell.setBounds(x / 4, y / 4, width, height); + return shell; } - + /** * Creates a List widget for displaying array of strings * @param compositeHolder @@ -499,25 +835,25 @@ public class ViewUtility */ private static void convertArrayItemForDisplay(Composite compositeHolder, CompositeData data, String itemName) { - Object[] arrayItems = (Object[])data.get(itemName); + Object[] arrayItems = (Object[]) data.get(itemName); String[] items = new String[arrayItems.length]; for (int i = 0; i < arrayItems.length; i++) { items[i] = String.valueOf(arrayItems[i]); } org.eclipse.swt.widgets.List list = new org.eclipse.swt.widgets.List(compositeHolder, - SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY); + SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY); list.setItems(items); //list.setBackground(compositeHolder.getBackground()); list.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); } - + private static void setNotSupportedDataType(FormToolkit toolkit, Composite compositeHolder) { Text valueText = toolkit.createText(compositeHolder, "--- Content can not be displayed ---", SWT.READ_ONLY); valueText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1)); } - + /** * Converts the input string to displayable format by converting some character case or inserting space * @param input @@ -533,7 +869,7 @@ public class ViewUtility for (int i = 1; i < input.length(); i++) { if (Character.isUpperCase(result.charAt(i)) && !Character.isWhitespace(result.charAt(i - 1)) - && Character.isLowerCase(result.charAt(i - 1))) + && Character.isLowerCase(result.charAt(i - 1))) { result.insert(i, " "); i++; @@ -542,12 +878,12 @@ public class ViewUtility { result.setCharAt(i, Character.toUpperCase(result.charAt(i))); } - + } - + return result.toString(); } - + /** * Disposes the children of given Composite if not null and not already disposed * @param parent composite @@ -555,18 +891,20 @@ public class ViewUtility public static void disposeChildren(Composite parent) { if (parent == null || parent.isDisposed()) + { return; - - Control[] oldControls = parent.getChildren(); + } + + Control[] oldControls = parent.getChildren(); for (int i = 0; i < oldControls.length; i++) { oldControls[i].dispose(); } } - + public static char[] getMD5HashedCharArray(Object text) throws NoSuchAlgorithmException, UnsupportedEncodingException { - byte[] data = ((String)text).getBytes("utf-8"); + byte[] data = ((String) text).getBytes("utf-8"); MessageDigest md = MessageDigest.getInstance("MD5"); @@ -576,16 +914,16 @@ public class ViewUtility } byte[] digest = md.digest(); - + char[] byteArray = new char[digest.length]; int index = 0; for (byte b : digest) { - byteArray[index++] = (char)b; + byteArray[index++] = (char) b; } return byteArray; } - + public static char[] getHash(String text) throws NoSuchAlgorithmException, UnsupportedEncodingException { byte[] data = text.getBytes("utf-8"); @@ -599,32 +937,32 @@ public class ViewUtility byte[] digest = md.digest(); - char[] hash = new char[digest.length ]; + char[] hash = new char[digest.length]; int index = 0; for (byte b : digest) - { + { hash[index++] = (char) b; } return hash; } - + private static class TabularDataComparator implements java.util.Comparator<Map.Entry> { public int compare(Map.Entry data1, Map.Entry data2) { if (data1.getKey() instanceof List) { - Object obj1 = ((List)data1.getKey()).get(0); - Object obj2 = ((List)data2.getKey()).get(0); + Object obj1 = ((List) data1.getKey()).get(0); + Object obj2 = ((List) data2.getKey()).get(0); String str1 = obj1.toString(); String str2 = obj2.toString(); if (obj1 instanceof String) { return str1.compareTo(str2); } - + try { return Long.valueOf(str1).compareTo(Long.valueOf(str2)); @@ -634,7 +972,7 @@ public class ViewUtility return -1; } } - + return -1; } } diff --git a/java/management/eclipse-plugin/src/main/resources/org.apache.commons.codec/org.apache.commons.codec_1.3.0.jar b/java/management/eclipse-plugin/src/main/resources/org.apache.commons.codec/org.apache.commons.codec_1.3.0.jar Binary files differnew file mode 100644 index 0000000000..ae60ce21b7 --- /dev/null +++ b/java/management/eclipse-plugin/src/main/resources/org.apache.commons.codec/org.apache.commons.codec_1.3.0.jar diff --git a/java/management/eclipse-plugin/src/main/resources/unix/configuration/config.ini b/java/management/eclipse-plugin/src/main/resources/unix/configuration/config.ini index aa2d21fd48..b5186ef073 100644 --- a/java/management/eclipse-plugin/src/main/resources/unix/configuration/config.ini +++ b/java/management/eclipse-plugin/src/main/resources/unix/configuration/config.ini @@ -22,6 +22,6 @@ osgi.splashPath=platform:/base/plugins/org.apache.qpid.management.ui
eclipse.product=org.apache.qpid.management.ui.product
eclipse.application=org.apache.qpid.management.ui.application
-osgi.bundles=org.eclipse.equinox.common@2:start,org.eclipse.core.runtime@start,com.ibm.icu,org.apache.qpid.management.ui,org.eclipse.core.commands,org.eclipse.core.contenttype,org.eclipse.core.expressions,org.eclipse.core.jobs,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.help,org.eclipse.jface,org.eclipse.swt,org.eclipse.swt.motif.linux.x86,org.eclipse.swt.gtk.linux.x86_64,org.eclipse.swt.gtk.linux.x86,org.eclipse.swt.gtk.linux.ppc,org.eclipse.swt.motif.hpux.PA_RISC,org.eclipse.swt.gtk.solaris.sparc,org.eclipse.swt.motif.solaris.sparc,org.eclipse.swt.carbon.macocx,org.eclipse.ui,org.eclipse.ui.forms,org.eclipse.ui.workbench
+osgi.bundles=org.eclipse.equinox.common@2:start,org.eclipse.core.runtime@start,com.ibm.icu,org.apache.qpid.management.ui,org.eclipse.core.commands,org.eclipse.core.contenttype,org.eclipse.core.expressions,org.eclipse.core.jobs,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.help,org.eclipse.jface,org.eclipse.swt,org.eclipse.swt.motif.linux.x86,org.eclipse.swt.gtk.linux.x86_64,org.eclipse.swt.gtk.linux.x86,org.eclipse.swt.gtk.linux.ppc,org.eclipse.swt.motif.hpux.PA_RISC,org.eclipse.swt.gtk.solaris.sparc,org.eclipse.swt.motif.solaris.sparc,org.eclipse.swt.carbon.macocx,org.eclipse.ui,org.eclipse.ui.forms,org.eclipse.ui.workbench,org.apache.commons.codec
osgi.bundles.defaultStartLevel=4
-eof=eof
\ No newline at end of file +eof=eof
diff --git a/java/management/eclipse-plugin/src/main/resources/win32/configuration/config.ini b/java/management/eclipse-plugin/src/main/resources/win32/configuration/config.ini index e83321e650..e287f0f4a9 100644 --- a/java/management/eclipse-plugin/src/main/resources/win32/configuration/config.ini +++ b/java/management/eclipse-plugin/src/main/resources/win32/configuration/config.ini @@ -22,5 +22,5 @@ osgi.splashPath=platform:/base/plugins/org.apache.qpid.management.ui
eclipse.product=org.apache.qpid.management.ui.product
eclipse.application=org.apache.qpid.management.ui.application
-osgi.bundles=org.eclipse.equinox.common@2:start,org.eclipse.core.runtime@start,com.ibm.icu,org.apache.qpid.management.ui,org.eclipse.core.commands,org.eclipse.core.contenttype,org.eclipse.core.expressions,org.eclipse.core.jobs,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.help,org.eclipse.jface,org.eclipse.swt,org.eclipse.swt.win32.win32.x86,org.eclipse.ui,org.eclipse.ui.forms,jmxremote.sasl,org.eclipse.ui.workbench
+osgi.bundles=org.eclipse.equinox.common@2:start,org.eclipse.core.runtime@start,com.ibm.icu,org.apache.qpid.management.ui,org.eclipse.core.commands,org.eclipse.core.contenttype,org.eclipse.core.expressions,org.eclipse.core.jobs,org.eclipse.core.runtime.compatibility.auth,org.eclipse.core.runtime.compatibility.registry,org.eclipse.equinox.preferences,org.eclipse.equinox.registry,org.eclipse.help,org.eclipse.jface,org.eclipse.swt,org.eclipse.swt.win32.win32.x86,org.eclipse.ui,org.eclipse.ui.forms,jmxremote.sasl,org.eclipse.ui.workbench,org.apache.commons.codec
osgi.bundles.defaultStartLevel=4
|