You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2008/12/29 02:10:43 UTC
svn commit: r729821 [4/5] - in
/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon:
./ eclipse/plugin/ eclipse/ui/ idea/plugin/ idea/ui/
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java?rev=729821&r1=729820&r2=729821&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java Sun Dec 28 17:10:41 2008
@@ -1,665 +1,665 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ws.commons.tcpmon.eclipse.ui;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.apache.ws.commons.tcpmon.eclipse.ui.Connection;
-import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.util.Iterator;
-import java.util.Vector;
-
-/**
- * This is similar to the main swing listener but includes SWT components instead of Swing ones
- *
- */
-class Listener {
- public Socket inputSocket = null;
- public Socket outputSocket = null;
- public ServerSocket sSocket = null;
-
- public Composite leftPanel = null;
- public Composite rightPanel = null;
- public Composite textComposite = null;
- public Text portField = null;
- public Text hostField = null;
- public Text tPortField = null;
- public Button isProxyBox = null;
- public Button stopButton = null;
- public Button removeButton = null;
- public Button removeAllButton = null;
- public Button xmlFormatBox = null;
- public Button saveButton = null;
- public Button resendButton = null;
- public Button switchButton = null;
- public Button closeButton = null;
- public Table connectionTable = null;
- public TableEnhancer tableEnhancer = null;
-
- private TabFolder tabFolder;
- private TabItem portTabItem;
-
- public SocketWaiter sw = null;
- public SlowLinkSimulator slowLink;
-
- public final Vector connections = new Vector();
-
- public String HTTPProxyHost = null;
- public int HTTPProxyPort = 80;
- public int delayBytes = 0;
- public int delayTime = 0;
-
- public Listener(TabFolder tabFolder, String name, int listenPort,
- String host, int targetPort, boolean isProxy,
- SlowLinkSimulator slowLink) {
- if (name == null) {
- name = MainView.getMessage("port01", "Port") + " " + listenPort;
- }
- // set the slow link to the passed down link
- if (slowLink != null) {
- this.slowLink = slowLink;
- } else {
- // or make up a no-op one.
- this.slowLink = new SlowLinkSimulator(0, 0);
- }
-
- this.tabFolder = tabFolder;
- createPortTab(isProxy, listenPort, host, targetPort);
-
- }
-
- public void createPortTab(boolean isProxy, int listenPort, String host, int targetPort) {
- portTabItem = new TabItem(tabFolder, SWT.NONE);
-
- final Composite composite = new Composite(tabFolder, SWT.NONE);
- GridLayout gl = new GridLayout();
- gl.numColumns = 8;
- composite.setLayout(gl);
- portTabItem.setControl(composite);
-
- stopButton = new Button(composite, SWT.NONE);
- GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
- gd.widthHint = 71;
- stopButton.setLayoutData(gd);
- final String start = MainView.getMessage("start00", "Start");
- stopButton.setText(start);
-
- final Label listenPortLabel = new Label(composite, SWT.NONE);
- gd = new GridData();
- gd.horizontalIndent = 5;
- listenPortLabel.setLayoutData(gd);
- listenPortLabel.setText(MainView.getMessage("listenPort01", "Listen Port:"));
-
- portField = new Text(composite, SWT.BORDER);
- portField.setText("" + listenPort);
- portField.setTextLimit(4);
- gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
- gd.widthHint = 40;
- portField.setLayoutData(gd);
-
- (new Label(composite, SWT.NONE)).setText(MainView.getMessage("host00", "Host:"));
-
- hostField = new Text(composite, SWT.BORDER);
- hostField.setText(host);
- hostField.setTextLimit(30);
- gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
- gd.widthHint = 202;
- hostField.setLayoutData(gd);
-
- (new Label(composite, SWT.NONE)).setText(MainView.getMessage("port02", "Port:"));
-
- tPortField = new Text(composite, SWT.BORDER);
- tPortField.setText("" + targetPort);
- tPortField.setTextLimit(4);
- gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
- gd.widthHint = 40;
- tPortField.setLayoutData(gd);
-
- isProxyBox = new Button(composite, SWT.LEFT | SWT.CHECK);
- isProxyBox.setAlignment(SWT.LEFT);
- gd = new GridData(64, SWT.DEFAULT);
- gd.verticalIndent = 2;
- gd.horizontalIndent = 10;
- isProxyBox.setLayoutData(gd);
- isProxyBox.setText(MainView.getMessage("proxy00", "Proxy"));
- isProxyBox.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- boolean state = ((Button) e.getSource()).getSelection();
- tPortField.setEnabled(!state);
- hostField.setEnabled(!state);
- }
- });
- isProxyBox.setSelection(isProxy);
- portField.setEditable(false);
- hostField.setEditable(false);
- tPortField.setEditable(false);
- stopButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if (stopButton.getText().equals(MainView.getMessage("stop00", "Stop"))) {
- stop();
- } else {
- start();
- }
- }
- });
-
- connectionTable = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
- connectionTable.setHeaderVisible(true);
- gd = new GridData(SWT.LEFT, SWT.FILL, true, false, 8, 1);
- gd.heightHint = 102;
- connectionTable.setLayoutData(gd);
-
- final TableColumn stateColumn = new TableColumn(connectionTable, SWT.CENTER);
- stateColumn.setWidth(47);
- stateColumn.setText(MainView.getMessage("state00", "State"));
-
- final TableColumn timeColumn = new TableColumn(connectionTable, SWT.CENTER);
- timeColumn.setWidth(100);
- timeColumn.setText(MainView.getMessage("time00", "Time"));
-
- final TableColumn reqHostColumn = new TableColumn(connectionTable, SWT.CENTER);
- reqHostColumn.setWidth(100);
- reqHostColumn.setText(MainView.getMessage("requestHost00", "Request Host"));
-
- final TableColumn targetHostColumn = new TableColumn(connectionTable, SWT.CENTER);
- targetHostColumn.setWidth(100);
- targetHostColumn.setText(MainView.getMessage("targetHost", "Target Host"));
-
- final TableColumn requestColumn = new TableColumn(connectionTable, SWT.CENTER);
- requestColumn.setWidth(100);
- requestColumn.setText(MainView.getMessage("request00", "Request..."));
-
- final TableColumn elapsedTimeColumn = new TableColumn(connectionTable, SWT.CENTER);
- elapsedTimeColumn.setWidth(140);
- elapsedTimeColumn.setText(MainView.getMessage("elapsed00", "Elapsed Time"));
-
- final TableItem headerItem = new TableItem(connectionTable, SWT.BORDER);
- headerItem.setText(new String[]{"--", "Most Recent", "--", "--", "--", "--"});
- tableEnhancer = new TableEnhancer(connectionTable);
-
-// SelectionListener part goes here - I THINK IT'S DONE
-
- connectionTable.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- handleSelection();
- }
- });
-
-
- final Composite buttonComposite = new Composite(composite, SWT.NONE);
- buttonComposite.setLayout(new RowLayout());
- gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
- gd.heightHint = 32;
- gd.widthHint = 59;
- buttonComposite.setLayoutData(gd);
-
- removeButton = new Button(buttonComposite, SWT.NONE);
- RowData rd = new RowData();
- rd.width = 100;
- removeButton.setLayoutData(rd);
- final String removeSelected = MainView.getMessage("removeSelected00", "Remove Selected");
- removeButton.setText(removeSelected);
- removeButton.setEnabled(false);
- removeButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if (removeSelected.equals(((Button) e.getSource()).getText())) {
- remove();
- }
- }
- });
-
- removeAllButton = new Button(buttonComposite, SWT.NONE);
- rd = new RowData();
- rd.width = 100;
- removeAllButton.setLayoutData(rd);
- final String removeAll = MainView.getMessage("removeAll00", "Remove All");
- removeAllButton.setText(removeAll);
- removeAllButton.setEnabled(false);
- removeAllButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if (removeAll.equals(((Button) e.getSource()).getText())) {
- removeAll();
- }
- }
- });
-
- textComposite = new Composite(composite, SWT.NONE);
- textComposite.setLayout(new FillLayout(SWT.VERTICAL));
- gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 8, 1);
- gd.widthHint = 589;
- gd.heightHint = 230;
- textComposite.setLayoutData(gd);
-
- leftPanel = new Composite(textComposite, SWT.BORDER);
- leftPanel.setLayout(new GridLayout(8, true));
-
- rightPanel = new Composite(textComposite, SWT.BORDER);
- rightPanel.setLayout(new GridLayout(8, true));
-
- xmlFormatBox = new Button(composite, SWT.CHECK);
- xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML Format"));
-
- final Composite buttonComposite2 = new Composite(composite, SWT.NONE);
- buttonComposite2.setLayout(new RowLayout());
- gd = new GridData(SWT.FILL, SWT.FILL, false, false, 4, 1);
- gd.heightHint = 27;
- gd.widthHint = 27;
- buttonComposite2.setLayoutData(gd);
-
- saveButton = new Button(buttonComposite2, SWT.NONE);
- rd = new RowData();
- rd.width = 100;
- saveButton.setLayoutData(rd);
- final String save = MainView.getMessage("save00", "Save");
- saveButton.setText(save);
- saveButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if (save.equals(((Button) e.getSource()).getText())) {
- save();
- }
- }
- });
-
- resendButton = new Button(buttonComposite2, SWT.NONE);
- rd = new RowData();
- rd.width = 100;
- resendButton.setLayoutData(rd);
- final String resend = MainView.getMessage("resend00", "Resend");
- resendButton.setText(resend);
- resendButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if (resend.equals(((Button) e.getSource()).getText())) {
- resend();
- }
- }
- });
-
- switchButton = new Button(buttonComposite2, SWT.NONE);
- rd = new RowData();
- rd.width = 100;
- switchButton.setLayoutData(rd);
- final String switchStr = MainView.getMessage("switch00", "Switch Layout");
- switchButton.setText(switchStr);
- switchButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if (switchStr.equals(((Button) e.getSource()).getText())) {
- if (((FillLayout) textComposite.getLayout()).type == SWT.HORIZONTAL) {
- ((FillLayout) textComposite.getLayout()).type = SWT.VERTICAL;
- } else {
- ((FillLayout) textComposite.getLayout()).type = SWT.HORIZONTAL;
- }
- leftPanel.layout();
- rightPanel.layout();
- textComposite.layout();
- }
- }
- });
-
- final Composite buttonComposite3 = new Composite(composite, SWT.NONE);
- buttonComposite3.setLayout(new RowLayout());
- gd = new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1);
- gd.horizontalIndent = 95;
- gd.heightHint = 27;
- gd.widthHint = 27;
- buttonComposite3.setLayoutData(gd);
-
- closeButton = new Button(buttonComposite3, SWT.None);
- rd = new RowData();
- rd.width = 60;
- closeButton.setLayoutData(rd);
- final String close = MainView.getMessage("close00", "Close");
- closeButton.setText(close);
- closeButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
- if (close.equals(((Button) e.getSource()).getText())) {
- close();
- }
- }
- });
- tableEnhancer.setSelectionInterval(0, 0);
- start();
- }
-
- public void handleSelection() {
- if (tableEnhancer.isSelectionEmpty()) {
- setLeft(MainView.SWT_LABEL, " " + MainView.getMessage("wait00",
- "Waiting for Connection..."));
- setRight(MainView.SWT_LABEL, "");
- removeButton.setEnabled(false);
- removeAllButton.setEnabled(false);
- saveButton.setEnabled(false);
- resendButton.setEnabled(false);
- leftPanel.layout();
- rightPanel.layout();
- textComposite.layout();
- } else {
- int row = tableEnhancer.getLeadSelectionIndex();
- if (row != tableEnhancer.getMaxSelectionIndex()) {
- row = tableEnhancer.getMaxSelectionIndex();
- }
- if (row == 0) {
- if (connections.size() == 0) {
- setLeft(MainView.SWT_LABEL, " " + MainView.getMessage("wait00",
- "Waiting for connection..."));
- setRight(MainView.SWT_LABEL, "");
- removeButton.setEnabled(false);
- removeAllButton.setEnabled(false);
- saveButton.setEnabled(false);
- resendButton.setEnabled(false);
- leftPanel.layout();
- rightPanel.layout();
- textComposite.layout();
- } else {
- Connection conn = (Connection) connections.lastElement();
- removeChildren(leftPanel.getChildren());
- removeChildren(rightPanel.getChildren());
- ((GridData) conn.inputText.getLayoutData()).exclude = false;
- conn.inputText.setVisible(true);
- ((GridData) conn.outputText.getLayoutData()).exclude = false;
- conn.outputText.setVisible(true);
- removeButton.setEnabled(false);
- removeAllButton.setEnabled(true);
- saveButton.setEnabled(true);
- resendButton.setEnabled(true);
- leftPanel.layout();
- rightPanel.layout();
- textComposite.layout();
- }
- } else {
- Connection conn = (Connection) connections.get(row - 1);
- removeChildren(leftPanel.getChildren());
- removeChildren(rightPanel.getChildren());
- ((GridData) conn.inputText.getLayoutData()).exclude = false;
- conn.inputText.setVisible(true);
- ((GridData) conn.outputText.getLayoutData()).exclude = false;
- conn.outputText.setVisible(true);
- removeButton.setEnabled(true);
- removeAllButton.setEnabled(true);
- saveButton.setEnabled(true);
- resendButton.setEnabled(true);
- leftPanel.layout();
- rightPanel.layout();
- textComposite.layout();
- }
- }
- }
-
- public void stop() {
- try {
- for (int i = 0; i < connections.size(); i++) {
- Connection conn = (Connection) connections.get(i);
- conn.halt();
- }
- sw.halt();
- stopButton.setText(MainView.getMessage("start00", "Start"));
- portField.setEditable(true);
- hostField.setEditable(true);
- tPortField.setEditable(true);
- isProxyBox.setEnabled(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void start() {
- int port = Integer.parseInt(portField.getText());
- portField.setText("" + port);
- portTabItem.setText(MainView.getMessage("port01", "Port") + " " + port);
- int tmp = Integer.parseInt(tPortField.getText());
- tPortField.setText("" + tmp);
- sw = new SocketWaiter(this, port);
- stopButton.setText(MainView.getMessage("stop00", "Stop"));
- portField.setEditable(false);
- hostField.setEditable(false);
- tPortField.setEditable(false);
- isProxyBox.setEnabled(false);
- }
-
-
- public void remove() {
- int index;
- Connection con;
- int[] selectionIndices = tableEnhancer.getSelectionIndicesWithoutZero();
- for (int i = 0; i < selectionIndices.length; i++) {
- index = selectionIndices[i];
- con = (Connection) connections.get(index - 1 - i);
- if (con.active) {
- MessageBox mb = new MessageBox(MainView.display.getActiveShell(), SWT.ICON_INFORMATION | SWT.OK);
- mb.setMessage(MainView.getMessage("inform00", "Connection can be removed only when its status indicates Done"));
- mb.setText("Connection Active");
- mb.open();
- continue;
- }
- con.halt();
- con.inputText.dispose();
- con.outputText.dispose();
- connections.remove(con);
- tableEnhancer.remove(index - i);
- tableEnhancer.setSelectionInterval(0, 0);
- }
- }
-
-
- public void removeAll() {
- tableEnhancer.selectAll();
- remove();
- }
-
-
- public void close() {
- MessageBox mb = new MessageBox(MainView.display.getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
- mb.setMessage(MainView.getMessage("quit00", "Do you want to remove monitoring") + " " + portTabItem.getText());
- mb.setText("Remove Monitor");
- int response = mb.open();
- if (response == SWT.YES) {
- if (stopButton.getText().equals(MainView.getMessage("stop00", "Stop"))) {
- stop();
- }
- portTabItem.dispose();
- }
- }
-
-
- public void save() {
- FileDialog fd = new FileDialog(MainView.display.getActiveShell(), SWT.SAVE);
- fd.setText("Save");
- fd.setFilterPath(".");
- String path = fd.open();
- if (path == null) {
- return;
- }
- try {
- File file = new File(path);
- FileOutputStream out = new FileOutputStream(file);
- int rc = tableEnhancer.getLeadSelectionIndex();
- int n = 0;
- for (Iterator i = connections.iterator(); i.hasNext();
- n++) {
- Connection conn = (Connection) i.next();
- if (tableEnhancer.isSelectedIndex(n + 1)
- || (!(i.hasNext())
- && (tableEnhancer.getLeadSelectionIndex() == 0))) {
- rc = Integer.parseInt(portField.getText());
- out.write("\n==============\n".getBytes());
- out.write(((MainView.getMessage("listenPort01",
- "Listen Port:")
- + " " + rc + "\n")).getBytes());
- out.write((MainView.getMessage("targetHost01",
- "Target Host:")
- + " " + hostField.getText()
- + "\n").getBytes());
- rc = Integer.parseInt(tPortField.getText());
- out.write(((MainView.getMessage("targetPort01",
- "Target Port:")
- + " " + rc + "\n")).getBytes());
- out.write((("==== "
- + MainView.getMessage("request01", "Request")
- + " ====\n")).getBytes());
- out.write(conn.inputText.getText().getBytes());
- out.write((("==== "
- + MainView.getMessage("response00", "Response")
- + " ====\n")).getBytes());
- out.write(conn.outputText.getText().getBytes());
- out.write("\n==============\n".getBytes());
- }
- }
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void resend() {
- try {
- int rc;
- Connection conn;
- rc = tableEnhancer.getMaxSelectionIndex();
- if (rc == 0) {
- conn = (Connection) connections.lastElement();
- } else {
- conn = (Connection) connections.get(rc - 1);
- }
-
- if (rc > 0) {
- tableEnhancer.clearSelection();
- tableEnhancer.setSelectionInterval(0, 0);
- }
- InputStream in = null;
- String text = conn.inputText.getText();
-
- // Fix Content-Length HTTP headers
- if (text.startsWith("POST ") || text.startsWith("GET ")) {
-
- int pos1, pos2, pos3;
- String headers;
- pos3 = text.indexOf("\n\n");
- if (pos3 == -1) {
- pos3 = text.indexOf("\r\n\r\n");
- if (pos3 != -1) {
- pos3 = pos3 + 4;
- }
- } else {
- pos3 += 2;
- }
- headers = text.substring(0, pos3);
- pos1 = headers.indexOf("Content-Length:");
-
- if (pos1 != -1) {
- int newLen = text.length() - pos3;
- pos2 = headers.indexOf("\n", pos1);
- System.err.println("CL: " + newLen);
- System.err.println("Hdrs: '" + headers + "'");
- System.err.println("subTEXT: '"
- + text.substring(pos3, pos3 + newLen)
- + "'");
- text = headers.substring(0, pos1) + "Content-Length: "
- + newLen + "\n" + headers.substring(pos2 + 1)
- + text.substring(pos3);
- System.err.println("\nTEXT: '" + text + "'");
- }
- }
- in = new ByteArrayInputStream(text.getBytes());
- new Connection(this, in);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-
- public Object setLeft(int type, String text) {
- Control[] children = leftPanel.getChildren();
- removeChildren(children);
- switch (type) {
- case 0:
- Label label = new Label(leftPanel, SWT.NONE);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalSpan = 8;
- gd.exclude = false;
- label.setLayoutData(gd);
- label.setText(text);
- leftPanel.layout();
- textComposite.layout();
- return label;
- case 1:
- Text leftText = new Text(leftPanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- GridData gd1 = new GridData(GridData.FILL_BOTH);
- gd1.grabExcessHorizontalSpace = true;
- gd1.horizontalSpan = 8;
- gd1.exclude = false;
- leftText.setLayoutData(gd1);
- leftText.setText(text);
- leftPanel.layout();
- textComposite.layout();
- return leftText;
- }
- return null;
- }
-
- public void layout() {
- leftPanel.layout();
- rightPanel.layout();
- }
-
-
- public Object setRight(int type, String text) {
- Control[] children = rightPanel.getChildren();
- removeChildren(children);
- switch (type) {
- case 0:
- Label label = new Label(rightPanel, SWT.NONE);
- GridData gd = new GridData(GridData.FILL_BOTH);
- gd.grabExcessHorizontalSpace = true;
- gd.horizontalSpan = 8;
- gd.exclude = false;
- label.setLayoutData(gd);
- label.setText(text);
- rightPanel.layout();
- textComposite.layout();
- return label;
- case 1:
- Text rightText = new Text(rightPanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- GridData gd1 = new GridData(GridData.FILL_BOTH);
- gd1.grabExcessHorizontalSpace = true;
- gd1.horizontalSpan = 8;
- rightText.setLayoutData(gd1);
- rightText.setText(text);
- rightPanel.layout();
- textComposite.layout();
- return rightText;
- }
- return null;
- }
-
- private void removeChildren(Control[] children) {
- for (int i = 0; i < children.length; i++) {
- ((GridData) children[i].getLayoutData()).exclude = true;
- children[i].setVisible(false);
- children[i].getShell().layout(true);
- }
- }
-
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.commons.tcpmon.eclipse.ui;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+import org.apache.ws.commons.tcpmon.eclipse.ui.Connection;
+import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * This is similar to the main swing listener but includes SWT components instead of Swing ones
+ *
+ */
+class Listener {
+ public Socket inputSocket = null;
+ public Socket outputSocket = null;
+ public ServerSocket sSocket = null;
+
+ public Composite leftPanel = null;
+ public Composite rightPanel = null;
+ public Composite textComposite = null;
+ public Text portField = null;
+ public Text hostField = null;
+ public Text tPortField = null;
+ public Button isProxyBox = null;
+ public Button stopButton = null;
+ public Button removeButton = null;
+ public Button removeAllButton = null;
+ public Button xmlFormatBox = null;
+ public Button saveButton = null;
+ public Button resendButton = null;
+ public Button switchButton = null;
+ public Button closeButton = null;
+ public Table connectionTable = null;
+ public TableEnhancer tableEnhancer = null;
+
+ private TabFolder tabFolder;
+ private TabItem portTabItem;
+
+ public SocketWaiter sw = null;
+ public SlowLinkSimulator slowLink;
+
+ public final Vector connections = new Vector();
+
+ public String HTTPProxyHost = null;
+ public int HTTPProxyPort = 80;
+ public int delayBytes = 0;
+ public int delayTime = 0;
+
+ public Listener(TabFolder tabFolder, String name, int listenPort,
+ String host, int targetPort, boolean isProxy,
+ SlowLinkSimulator slowLink) {
+ if (name == null) {
+ name = MainView.getMessage("port01", "Port") + " " + listenPort;
+ }
+ // set the slow link to the passed down link
+ if (slowLink != null) {
+ this.slowLink = slowLink;
+ } else {
+ // or make up a no-op one.
+ this.slowLink = new SlowLinkSimulator(0, 0);
+ }
+
+ this.tabFolder = tabFolder;
+ createPortTab(isProxy, listenPort, host, targetPort);
+
+ }
+
+ public void createPortTab(boolean isProxy, int listenPort, String host, int targetPort) {
+ portTabItem = new TabItem(tabFolder, SWT.NONE);
+
+ final Composite composite = new Composite(tabFolder, SWT.NONE);
+ GridLayout gl = new GridLayout();
+ gl.numColumns = 8;
+ composite.setLayout(gl);
+ portTabItem.setControl(composite);
+
+ stopButton = new Button(composite, SWT.NONE);
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ gd.widthHint = 71;
+ stopButton.setLayoutData(gd);
+ final String start = MainView.getMessage("start00", "Start");
+ stopButton.setText(start);
+
+ final Label listenPortLabel = new Label(composite, SWT.NONE);
+ gd = new GridData();
+ gd.horizontalIndent = 5;
+ listenPortLabel.setLayoutData(gd);
+ listenPortLabel.setText(MainView.getMessage("listenPort01", "Listen Port:"));
+
+ portField = new Text(composite, SWT.BORDER);
+ portField.setText("" + listenPort);
+ portField.setTextLimit(4);
+ gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ gd.widthHint = 40;
+ portField.setLayoutData(gd);
+
+ (new Label(composite, SWT.NONE)).setText(MainView.getMessage("host00", "Host:"));
+
+ hostField = new Text(composite, SWT.BORDER);
+ hostField.setText(host);
+ hostField.setTextLimit(30);
+ gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ gd.widthHint = 202;
+ hostField.setLayoutData(gd);
+
+ (new Label(composite, SWT.NONE)).setText(MainView.getMessage("port02", "Port:"));
+
+ tPortField = new Text(composite, SWT.BORDER);
+ tPortField.setText("" + targetPort);
+ tPortField.setTextLimit(4);
+ gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ gd.widthHint = 40;
+ tPortField.setLayoutData(gd);
+
+ isProxyBox = new Button(composite, SWT.LEFT | SWT.CHECK);
+ isProxyBox.setAlignment(SWT.LEFT);
+ gd = new GridData(64, SWT.DEFAULT);
+ gd.verticalIndent = 2;
+ gd.horizontalIndent = 10;
+ isProxyBox.setLayoutData(gd);
+ isProxyBox.setText(MainView.getMessage("proxy00", "Proxy"));
+ isProxyBox.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ boolean state = ((Button) e.getSource()).getSelection();
+ tPortField.setEnabled(!state);
+ hostField.setEnabled(!state);
+ }
+ });
+ isProxyBox.setSelection(isProxy);
+ portField.setEditable(false);
+ hostField.setEditable(false);
+ tPortField.setEditable(false);
+ stopButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (stopButton.getText().equals(MainView.getMessage("stop00", "Stop"))) {
+ stop();
+ } else {
+ start();
+ }
+ }
+ });
+
+ connectionTable = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
+ connectionTable.setHeaderVisible(true);
+ gd = new GridData(SWT.LEFT, SWT.FILL, true, false, 8, 1);
+ gd.heightHint = 102;
+ connectionTable.setLayoutData(gd);
+
+ final TableColumn stateColumn = new TableColumn(connectionTable, SWT.CENTER);
+ stateColumn.setWidth(47);
+ stateColumn.setText(MainView.getMessage("state00", "State"));
+
+ final TableColumn timeColumn = new TableColumn(connectionTable, SWT.CENTER);
+ timeColumn.setWidth(100);
+ timeColumn.setText(MainView.getMessage("time00", "Time"));
+
+ final TableColumn reqHostColumn = new TableColumn(connectionTable, SWT.CENTER);
+ reqHostColumn.setWidth(100);
+ reqHostColumn.setText(MainView.getMessage("requestHost00", "Request Host"));
+
+ final TableColumn targetHostColumn = new TableColumn(connectionTable, SWT.CENTER);
+ targetHostColumn.setWidth(100);
+ targetHostColumn.setText(MainView.getMessage("targetHost", "Target Host"));
+
+ final TableColumn requestColumn = new TableColumn(connectionTable, SWT.CENTER);
+ requestColumn.setWidth(100);
+ requestColumn.setText(MainView.getMessage("request00", "Request..."));
+
+ final TableColumn elapsedTimeColumn = new TableColumn(connectionTable, SWT.CENTER);
+ elapsedTimeColumn.setWidth(140);
+ elapsedTimeColumn.setText(MainView.getMessage("elapsed00", "Elapsed Time"));
+
+ final TableItem headerItem = new TableItem(connectionTable, SWT.BORDER);
+ headerItem.setText(new String[]{"--", "Most Recent", "--", "--", "--", "--"});
+ tableEnhancer = new TableEnhancer(connectionTable);
+
+// SelectionListener part goes here - I THINK IT'S DONE
+
+ connectionTable.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleSelection();
+ }
+ });
+
+
+ final Composite buttonComposite = new Composite(composite, SWT.NONE);
+ buttonComposite.setLayout(new RowLayout());
+ gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
+ gd.heightHint = 32;
+ gd.widthHint = 59;
+ buttonComposite.setLayoutData(gd);
+
+ removeButton = new Button(buttonComposite, SWT.NONE);
+ RowData rd = new RowData();
+ rd.width = 100;
+ removeButton.setLayoutData(rd);
+ final String removeSelected = MainView.getMessage("removeSelected00", "Remove Selected");
+ removeButton.setText(removeSelected);
+ removeButton.setEnabled(false);
+ removeButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (removeSelected.equals(((Button) e.getSource()).getText())) {
+ remove();
+ }
+ }
+ });
+
+ removeAllButton = new Button(buttonComposite, SWT.NONE);
+ rd = new RowData();
+ rd.width = 100;
+ removeAllButton.setLayoutData(rd);
+ final String removeAll = MainView.getMessage("removeAll00", "Remove All");
+ removeAllButton.setText(removeAll);
+ removeAllButton.setEnabled(false);
+ removeAllButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (removeAll.equals(((Button) e.getSource()).getText())) {
+ removeAll();
+ }
+ }
+ });
+
+ textComposite = new Composite(composite, SWT.NONE);
+ textComposite.setLayout(new FillLayout(SWT.VERTICAL));
+ gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 8, 1);
+ gd.widthHint = 589;
+ gd.heightHint = 230;
+ textComposite.setLayoutData(gd);
+
+ leftPanel = new Composite(textComposite, SWT.BORDER);
+ leftPanel.setLayout(new GridLayout(8, true));
+
+ rightPanel = new Composite(textComposite, SWT.BORDER);
+ rightPanel.setLayout(new GridLayout(8, true));
+
+ xmlFormatBox = new Button(composite, SWT.CHECK);
+ xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML Format"));
+
+ final Composite buttonComposite2 = new Composite(composite, SWT.NONE);
+ buttonComposite2.setLayout(new RowLayout());
+ gd = new GridData(SWT.FILL, SWT.FILL, false, false, 4, 1);
+ gd.heightHint = 27;
+ gd.widthHint = 27;
+ buttonComposite2.setLayoutData(gd);
+
+ saveButton = new Button(buttonComposite2, SWT.NONE);
+ rd = new RowData();
+ rd.width = 100;
+ saveButton.setLayoutData(rd);
+ final String save = MainView.getMessage("save00", "Save");
+ saveButton.setText(save);
+ saveButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (save.equals(((Button) e.getSource()).getText())) {
+ save();
+ }
+ }
+ });
+
+ resendButton = new Button(buttonComposite2, SWT.NONE);
+ rd = new RowData();
+ rd.width = 100;
+ resendButton.setLayoutData(rd);
+ final String resend = MainView.getMessage("resend00", "Resend");
+ resendButton.setText(resend);
+ resendButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (resend.equals(((Button) e.getSource()).getText())) {
+ resend();
+ }
+ }
+ });
+
+ switchButton = new Button(buttonComposite2, SWT.NONE);
+ rd = new RowData();
+ rd.width = 100;
+ switchButton.setLayoutData(rd);
+ final String switchStr = MainView.getMessage("switch00", "Switch Layout");
+ switchButton.setText(switchStr);
+ switchButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (switchStr.equals(((Button) e.getSource()).getText())) {
+ if (((FillLayout) textComposite.getLayout()).type == SWT.HORIZONTAL) {
+ ((FillLayout) textComposite.getLayout()).type = SWT.VERTICAL;
+ } else {
+ ((FillLayout) textComposite.getLayout()).type = SWT.HORIZONTAL;
+ }
+ leftPanel.layout();
+ rightPanel.layout();
+ textComposite.layout();
+ }
+ }
+ });
+
+ final Composite buttonComposite3 = new Composite(composite, SWT.NONE);
+ buttonComposite3.setLayout(new RowLayout());
+ gd = new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1);
+ gd.horizontalIndent = 95;
+ gd.heightHint = 27;
+ gd.widthHint = 27;
+ buttonComposite3.setLayoutData(gd);
+
+ closeButton = new Button(buttonComposite3, SWT.None);
+ rd = new RowData();
+ rd.width = 60;
+ closeButton.setLayoutData(rd);
+ final String close = MainView.getMessage("close00", "Close");
+ closeButton.setText(close);
+ closeButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if (close.equals(((Button) e.getSource()).getText())) {
+ close();
+ }
+ }
+ });
+ tableEnhancer.setSelectionInterval(0, 0);
+ start();
+ }
+
+ public void handleSelection() {
+ if (tableEnhancer.isSelectionEmpty()) {
+ setLeft(MainView.SWT_LABEL, " " + MainView.getMessage("wait00",
+ "Waiting for Connection..."));
+ setRight(MainView.SWT_LABEL, "");
+ removeButton.setEnabled(false);
+ removeAllButton.setEnabled(false);
+ saveButton.setEnabled(false);
+ resendButton.setEnabled(false);
+ leftPanel.layout();
+ rightPanel.layout();
+ textComposite.layout();
+ } else {
+ int row = tableEnhancer.getLeadSelectionIndex();
+ if (row != tableEnhancer.getMaxSelectionIndex()) {
+ row = tableEnhancer.getMaxSelectionIndex();
+ }
+ if (row == 0) {
+ if (connections.size() == 0) {
+ setLeft(MainView.SWT_LABEL, " " + MainView.getMessage("wait00",
+ "Waiting for connection..."));
+ setRight(MainView.SWT_LABEL, "");
+ removeButton.setEnabled(false);
+ removeAllButton.setEnabled(false);
+ saveButton.setEnabled(false);
+ resendButton.setEnabled(false);
+ leftPanel.layout();
+ rightPanel.layout();
+ textComposite.layout();
+ } else {
+ Connection conn = (Connection) connections.lastElement();
+ removeChildren(leftPanel.getChildren());
+ removeChildren(rightPanel.getChildren());
+ ((GridData) conn.inputText.getLayoutData()).exclude = false;
+ conn.inputText.setVisible(true);
+ ((GridData) conn.outputText.getLayoutData()).exclude = false;
+ conn.outputText.setVisible(true);
+ removeButton.setEnabled(false);
+ removeAllButton.setEnabled(true);
+ saveButton.setEnabled(true);
+ resendButton.setEnabled(true);
+ leftPanel.layout();
+ rightPanel.layout();
+ textComposite.layout();
+ }
+ } else {
+ Connection conn = (Connection) connections.get(row - 1);
+ removeChildren(leftPanel.getChildren());
+ removeChildren(rightPanel.getChildren());
+ ((GridData) conn.inputText.getLayoutData()).exclude = false;
+ conn.inputText.setVisible(true);
+ ((GridData) conn.outputText.getLayoutData()).exclude = false;
+ conn.outputText.setVisible(true);
+ removeButton.setEnabled(true);
+ removeAllButton.setEnabled(true);
+ saveButton.setEnabled(true);
+ resendButton.setEnabled(true);
+ leftPanel.layout();
+ rightPanel.layout();
+ textComposite.layout();
+ }
+ }
+ }
+
+ public void stop() {
+ try {
+ for (int i = 0; i < connections.size(); i++) {
+ Connection conn = (Connection) connections.get(i);
+ conn.halt();
+ }
+ sw.halt();
+ stopButton.setText(MainView.getMessage("start00", "Start"));
+ portField.setEditable(true);
+ hostField.setEditable(true);
+ tPortField.setEditable(true);
+ isProxyBox.setEnabled(true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void start() {
+ int port = Integer.parseInt(portField.getText());
+ portField.setText("" + port);
+ portTabItem.setText(MainView.getMessage("port01", "Port") + " " + port);
+ int tmp = Integer.parseInt(tPortField.getText());
+ tPortField.setText("" + tmp);
+ sw = new SocketWaiter(this, port);
+ stopButton.setText(MainView.getMessage("stop00", "Stop"));
+ portField.setEditable(false);
+ hostField.setEditable(false);
+ tPortField.setEditable(false);
+ isProxyBox.setEnabled(false);
+ }
+
+
+ public void remove() {
+ int index;
+ Connection con;
+ int[] selectionIndices = tableEnhancer.getSelectionIndicesWithoutZero();
+ for (int i = 0; i < selectionIndices.length; i++) {
+ index = selectionIndices[i];
+ con = (Connection) connections.get(index - 1 - i);
+ if (con.active) {
+ MessageBox mb = new MessageBox(MainView.display.getActiveShell(), SWT.ICON_INFORMATION | SWT.OK);
+ mb.setMessage(MainView.getMessage("inform00", "Connection can be removed only when its status indicates Done"));
+ mb.setText("Connection Active");
+ mb.open();
+ continue;
+ }
+ con.halt();
+ con.inputText.dispose();
+ con.outputText.dispose();
+ connections.remove(con);
+ tableEnhancer.remove(index - i);
+ tableEnhancer.setSelectionInterval(0, 0);
+ }
+ }
+
+
+ public void removeAll() {
+ tableEnhancer.selectAll();
+ remove();
+ }
+
+
+ public void close() {
+ MessageBox mb = new MessageBox(MainView.display.getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+ mb.setMessage(MainView.getMessage("quit00", "Do you want to remove monitoring") + " " + portTabItem.getText());
+ mb.setText("Remove Monitor");
+ int response = mb.open();
+ if (response == SWT.YES) {
+ if (stopButton.getText().equals(MainView.getMessage("stop00", "Stop"))) {
+ stop();
+ }
+ portTabItem.dispose();
+ }
+ }
+
+
+ public void save() {
+ FileDialog fd = new FileDialog(MainView.display.getActiveShell(), SWT.SAVE);
+ fd.setText("Save");
+ fd.setFilterPath(".");
+ String path = fd.open();
+ if (path == null) {
+ return;
+ }
+ try {
+ File file = new File(path);
+ FileOutputStream out = new FileOutputStream(file);
+ int rc = tableEnhancer.getLeadSelectionIndex();
+ int n = 0;
+ for (Iterator i = connections.iterator(); i.hasNext();
+ n++) {
+ Connection conn = (Connection) i.next();
+ if (tableEnhancer.isSelectedIndex(n + 1)
+ || (!(i.hasNext())
+ && (tableEnhancer.getLeadSelectionIndex() == 0))) {
+ rc = Integer.parseInt(portField.getText());
+ out.write("\n==============\n".getBytes());
+ out.write(((MainView.getMessage("listenPort01",
+ "Listen Port:")
+ + " " + rc + "\n")).getBytes());
+ out.write((MainView.getMessage("targetHost01",
+ "Target Host:")
+ + " " + hostField.getText()
+ + "\n").getBytes());
+ rc = Integer.parseInt(tPortField.getText());
+ out.write(((MainView.getMessage("targetPort01",
+ "Target Port:")
+ + " " + rc + "\n")).getBytes());
+ out.write((("==== "
+ + MainView.getMessage("request01", "Request")
+ + " ====\n")).getBytes());
+ out.write(conn.inputText.getText().getBytes());
+ out.write((("==== "
+ + MainView.getMessage("response00", "Response")
+ + " ====\n")).getBytes());
+ out.write(conn.outputText.getText().getBytes());
+ out.write("\n==============\n".getBytes());
+ }
+ }
+ out.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void resend() {
+ try {
+ int rc;
+ Connection conn;
+ rc = tableEnhancer.getMaxSelectionIndex();
+ if (rc == 0) {
+ conn = (Connection) connections.lastElement();
+ } else {
+ conn = (Connection) connections.get(rc - 1);
+ }
+
+ if (rc > 0) {
+ tableEnhancer.clearSelection();
+ tableEnhancer.setSelectionInterval(0, 0);
+ }
+ InputStream in = null;
+ String text = conn.inputText.getText();
+
+ // Fix Content-Length HTTP headers
+ if (text.startsWith("POST ") || text.startsWith("GET ")) {
+
+ int pos1, pos2, pos3;
+ String headers;
+ pos3 = text.indexOf("\n\n");
+ if (pos3 == -1) {
+ pos3 = text.indexOf("\r\n\r\n");
+ if (pos3 != -1) {
+ pos3 = pos3 + 4;
+ }
+ } else {
+ pos3 += 2;
+ }
+ headers = text.substring(0, pos3);
+ pos1 = headers.indexOf("Content-Length:");
+
+ if (pos1 != -1) {
+ int newLen = text.length() - pos3;
+ pos2 = headers.indexOf("\n", pos1);
+ System.err.println("CL: " + newLen);
+ System.err.println("Hdrs: '" + headers + "'");
+ System.err.println("subTEXT: '"
+ + text.substring(pos3, pos3 + newLen)
+ + "'");
+ text = headers.substring(0, pos1) + "Content-Length: "
+ + newLen + "\n" + headers.substring(pos2 + 1)
+ + text.substring(pos3);
+ System.err.println("\nTEXT: '" + text + "'");
+ }
+ }
+ in = new ByteArrayInputStream(text.getBytes());
+ new Connection(this, in);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public Object setLeft(int type, String text) {
+ Control[] children = leftPanel.getChildren();
+ removeChildren(children);
+ switch (type) {
+ case 0:
+ Label label = new Label(leftPanel, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalSpan = 8;
+ gd.exclude = false;
+ label.setLayoutData(gd);
+ label.setText(text);
+ leftPanel.layout();
+ textComposite.layout();
+ return label;
+ case 1:
+ Text leftText = new Text(leftPanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ GridData gd1 = new GridData(GridData.FILL_BOTH);
+ gd1.grabExcessHorizontalSpace = true;
+ gd1.horizontalSpan = 8;
+ gd1.exclude = false;
+ leftText.setLayoutData(gd1);
+ leftText.setText(text);
+ leftPanel.layout();
+ textComposite.layout();
+ return leftText;
+ }
+ return null;
+ }
+
+ public void layout() {
+ leftPanel.layout();
+ rightPanel.layout();
+ }
+
+
+ public Object setRight(int type, String text) {
+ Control[] children = rightPanel.getChildren();
+ removeChildren(children);
+ switch (type) {
+ case 0:
+ Label label = new Label(rightPanel, SWT.NONE);
+ GridData gd = new GridData(GridData.FILL_BOTH);
+ gd.grabExcessHorizontalSpace = true;
+ gd.horizontalSpan = 8;
+ gd.exclude = false;
+ label.setLayoutData(gd);
+ label.setText(text);
+ rightPanel.layout();
+ textComposite.layout();
+ return label;
+ case 1:
+ Text rightText = new Text(rightPanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+ GridData gd1 = new GridData(GridData.FILL_BOTH);
+ gd1.grabExcessHorizontalSpace = true;
+ gd1.horizontalSpan = 8;
+ rightText.setLayoutData(gd1);
+ rightText.setText(text);
+ rightPanel.layout();
+ textComposite.layout();
+ return rightText;
+ }
+ return null;
+ }
+
+ private void removeChildren(Control[] children) {
+ for (int i = 0; i < children.length; i++) {
+ ((GridData) children[i].getLayoutData()).exclude = true;
+ children[i].setVisible(false);
+ children[i].getShell().layout(true);
+ }
+ }
+
+}
Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java?rev=729821&r1=729820&r2=729821&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java Sun Dec 28 17:10:41 2008
@@ -1,200 +1,200 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ws.commons.tcpmon.eclipse.ui;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.layout.RowData;
-import org.eclipse.swt.layout.RowLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.TabFolder;
-import org.eclipse.swt.widgets.TabItem;
-import org.eclipse.swt.widgets.Text;
-import org.apache.ws.commons.tcpmon.eclipse.ui.MainView;
-
-/**
- * This is similar to the main swing sender but includes SWT components instead of Swing ones
- */
- class Sender {
- private TabFolder tabFolder = null;
-
- public Text endpointField;
- public Text actionField;
- public Text inputText;
- public Text outputText;
- public Button xmlFormatBox;
- public Button sendButton;
- public Button switchButton;
-
- public Sender(TabFolder tabFolder) {
- this.tabFolder = tabFolder;
- }
-
- public void createSenderTab() {
- final TabItem senderTabItem = new TabItem(tabFolder, SWT.NONE);
- senderTabItem.setText("Sender");
-
- final Composite tabComposite = new Composite(tabFolder, SWT.NONE);
- final GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 4;
- tabComposite.setLayout(gridLayout);
- senderTabItem.setControl(tabComposite);
-
- (new Label(tabComposite, SWT.NONE)).setText("Connection Endpoint");
-
- endpointField = new Text(tabComposite, SWT.BORDER);
- endpointField.setText("http://localhost:8080/axis2/services/XYZ");
- endpointField.setLayoutData(new GridData(312, SWT.DEFAULT));
-
- (new Label(tabComposite, SWT.NONE)).setText("SOAP Action");
- ;
-
- actionField = new Text(tabComposite, SWT.BORDER);
-
- final Composite textComposite = new Composite(tabComposite, SWT.NONE);
- textComposite.setLayout(new FillLayout(SWT.VERTICAL));
- final GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
- gd.heightHint = 384;
- gd.widthHint = 611;
- textComposite.setLayoutData(gd);
-
- inputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
-
- outputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
-
- xmlFormatBox = new Button(tabComposite, SWT.CHECK);
- xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML Format"));
-
- final Composite buttonComposite = new Composite(tabComposite, SWT.NONE);
- buttonComposite.setLayout(new RowLayout());
- final GridData buttonGd = new GridData(SWT.FILL, SWT.CENTER, false, false);
- buttonGd.heightHint = 30;
- buttonGd.widthHint = 166;
- buttonComposite.setLayoutData(buttonGd);
-
- sendButton = new Button(buttonComposite, SWT.NONE);
- final RowData rowData = new RowData();
- rowData.width = 100;
- sendButton.setLayoutData(rowData);
- sendButton.setText("Send");
- sendButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(final SelectionEvent e) {
- send();
- }
-
- });
-
- switchButton = new Button(buttonComposite, SWT.NONE);
- final RowData rd = new RowData();
- rd.width = 100;
- switchButton.setLayoutData(rd);
- switchButton.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(final SelectionEvent e) {
- if (((FillLayout) textComposite.getLayout()).type == SWT.HORIZONTAL) {
- ((FillLayout) textComposite.getLayout()).type = SWT.VERTICAL;
- } else {
- ((FillLayout) textComposite.getLayout()).type = SWT.HORIZONTAL;
- }
- textComposite.layout();
- }
- });
-
- switchButton.setText(MainView.getMessage("switch00", "Switch Layout"));
- }
-
- public void send() {
- try {
- URL u = new URL(endpointField.getText());
- URLConnection uc = u.openConnection();
- HttpURLConnection connection = (HttpURLConnection) uc;
- connection.setDoOutput(true);
- connection.setDoInput(true);
- connection.setRequestMethod("POST");
- String action = "\"" + (actionField.getText() == null ? "" : actionField.getText()) + "\"";
- connection.setRequestProperty("SOAPAction", action);
- connection.setRequestProperty("Content-Type", "text/xml");
- connection.setRequestProperty("User-Agent", "Axis/2.0");
- OutputStream out = connection.getOutputStream();
- Writer writer = new OutputStreamWriter(out);
- writer.write(inputText.getText());
- writer.flush();
- writer.close();
- String line;
- InputStream inputStream = null;
- try {
- inputStream = connection.getInputStream();
- } catch (IOException e) {
- inputStream = connection.getErrorStream();
- }
- outputText.setText("");
- BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
- while ((line = rd.readLine()) != null) {
- outputText.append(line);
- }
- if (xmlFormatBox.getSelection()) {
- outputText.setText(prettyXML(outputText.getText()));
- }
- } catch (Exception e) {
- StringWriter w = new StringWriter();
- e.printStackTrace(new PrintWriter(w));
- outputText.setText(w.toString());
- }
- }
-
- public String prettyXML(String input) throws Exception {
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- try {
- transformerFactory.setAttribute("indent-number", new Integer(2));
- } catch (Exception e) {
- }
- Transformer transformer = transformerFactory.newTransformer();
- try {
- transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
- } catch (Exception e) {
- }
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- StringWriter writer = new StringWriter();
- transformer.transform(new StreamSource(new StringReader(input)), new StreamResult(writer));
- return writer.toString();
- }
-
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.commons.tcpmon.eclipse.ui;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.apache.ws.commons.tcpmon.eclipse.ui.MainView;
+
+/**
+ * This is similar to the main swing sender but includes SWT components instead of Swing ones
+ */
+ class Sender {
+ private TabFolder tabFolder = null;
+
+ public Text endpointField;
+ public Text actionField;
+ public Text inputText;
+ public Text outputText;
+ public Button xmlFormatBox;
+ public Button sendButton;
+ public Button switchButton;
+
+ public Sender(TabFolder tabFolder) {
+ this.tabFolder = tabFolder;
+ }
+
+ public void createSenderTab() {
+ final TabItem senderTabItem = new TabItem(tabFolder, SWT.NONE);
+ senderTabItem.setText("Sender");
+
+ final Composite tabComposite = new Composite(tabFolder, SWT.NONE);
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 4;
+ tabComposite.setLayout(gridLayout);
+ senderTabItem.setControl(tabComposite);
+
+ (new Label(tabComposite, SWT.NONE)).setText("Connection Endpoint");
+
+ endpointField = new Text(tabComposite, SWT.BORDER);
+ endpointField.setText("http://localhost:8080/axis2/services/XYZ");
+ endpointField.setLayoutData(new GridData(312, SWT.DEFAULT));
+
+ (new Label(tabComposite, SWT.NONE)).setText("SOAP Action");
+ ;
+
+ actionField = new Text(tabComposite, SWT.BORDER);
+
+ final Composite textComposite = new Composite(tabComposite, SWT.NONE);
+ textComposite.setLayout(new FillLayout(SWT.VERTICAL));
+ final GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
+ gd.heightHint = 384;
+ gd.widthHint = 611;
+ textComposite.setLayoutData(gd);
+
+ inputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+
+ outputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+
+ xmlFormatBox = new Button(tabComposite, SWT.CHECK);
+ xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML Format"));
+
+ final Composite buttonComposite = new Composite(tabComposite, SWT.NONE);
+ buttonComposite.setLayout(new RowLayout());
+ final GridData buttonGd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ buttonGd.heightHint = 30;
+ buttonGd.widthHint = 166;
+ buttonComposite.setLayoutData(buttonGd);
+
+ sendButton = new Button(buttonComposite, SWT.NONE);
+ final RowData rowData = new RowData();
+ rowData.width = 100;
+ sendButton.setLayoutData(rowData);
+ sendButton.setText("Send");
+ sendButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(final SelectionEvent e) {
+ send();
+ }
+
+ });
+
+ switchButton = new Button(buttonComposite, SWT.NONE);
+ final RowData rd = new RowData();
+ rd.width = 100;
+ switchButton.setLayoutData(rd);
+ switchButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(final SelectionEvent e) {
+ if (((FillLayout) textComposite.getLayout()).type == SWT.HORIZONTAL) {
+ ((FillLayout) textComposite.getLayout()).type = SWT.VERTICAL;
+ } else {
+ ((FillLayout) textComposite.getLayout()).type = SWT.HORIZONTAL;
+ }
+ textComposite.layout();
+ }
+ });
+
+ switchButton.setText(MainView.getMessage("switch00", "Switch Layout"));
+ }
+
+ public void send() {
+ try {
+ URL u = new URL(endpointField.getText());
+ URLConnection uc = u.openConnection();
+ HttpURLConnection connection = (HttpURLConnection) uc;
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ connection.setRequestMethod("POST");
+ String action = "\"" + (actionField.getText() == null ? "" : actionField.getText()) + "\"";
+ connection.setRequestProperty("SOAPAction", action);
+ connection.setRequestProperty("Content-Type", "text/xml");
+ connection.setRequestProperty("User-Agent", "Axis/2.0");
+ OutputStream out = connection.getOutputStream();
+ Writer writer = new OutputStreamWriter(out);
+ writer.write(inputText.getText());
+ writer.flush();
+ writer.close();
+ String line;
+ InputStream inputStream = null;
+ try {
+ inputStream = connection.getInputStream();
+ } catch (IOException e) {
+ inputStream = connection.getErrorStream();
+ }
+ outputText.setText("");
+ BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
+ while ((line = rd.readLine()) != null) {
+ outputText.append(line);
+ }
+ if (xmlFormatBox.getSelection()) {
+ outputText.setText(prettyXML(outputText.getText()));
+ }
+ } catch (Exception e) {
+ StringWriter w = new StringWriter();
+ e.printStackTrace(new PrintWriter(w));
+ outputText.setText(w.toString());
+ }
+ }
+
+ public String prettyXML(String input) throws Exception {
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ try {
+ transformerFactory.setAttribute("indent-number", new Integer(2));
+ } catch (Exception e) {
+ }
+ Transformer transformer = transformerFactory.newTransformer();
+ try {
+ transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
+ } catch (Exception e) {
+ }
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ StringWriter writer = new StringWriter();
+ transformer.transform(new StreamSource(new StringReader(input)), new StreamResult(writer));
+ return writer.toString();
+ }
+
+}
Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java?rev=729821&r1=729820&r2=729821&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java Sun Dec 28 17:10:41 2008
@@ -1,164 +1,164 @@
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ws.commons.tcpmon.eclipse.ui;
-
-
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.SWT;
-
-/**
- *
- * A table enhancer class that wraps a table - A 'decorator' :)
- *
- */
-public class TableEnhancer {
- private Table table;
- private int secondArgument;
-
- public TableEnhancer(Table table) {
- this.table = table;
- }
-
- public void setValueAt(String value, int row, int column) {
- TableItem item = table.getItem(row);
- item.setText(column, value);
- }
-
- public int getLeadSelectionIndex() {
- return secondArgument;
- }
-
- public int getMaxSelectionIndex() {
- int[] selectionIndices = table.getSelectionIndices();
- if (selectionIndices.length != 0) {
- int temp = selectionIndices[0];
- for (int i = 1; i < selectionIndices.length; i++) {
- if (temp < selectionIndices[i]) {
- temp = selectionIndices[i];
- }
- }
- return temp;
- }
- return -1;
- }
-
- public int getNearestSelectionToZero() {
- int[] selectionIndices = sortArray(table.getSelectionIndices());
- if (selectionIndices[0] == 0) {
- return selectionIndices[1];
- } else {
- return selectionIndices[0];
- }
- }
-
- public int[] getSelectionIndicesWithoutZero() {
- int[] selectionIndices = sortArray(table.getSelectionIndices());
- if (selectionIndices[0] == 0) {
- int[] tempArray = new int[selectionIndices.length - 1];
- for (int i = 1; i < selectionIndices.length; i++) {
- tempArray[i - 1] = selectionIndices[i];
- }
- return tempArray;
- }
- return selectionIndices;
- }
-
- private int[] sortArray(int[] selectionIndices) {
- if (selectionIndices.length != 0) {
- for (int i = 0; i < selectionIndices.length; i++) {
- int temp = selectionIndices[i];
- int index = i;
- for (int j = i; j < selectionIndices.length; j++) {
- if (temp > selectionIndices[j]) {
- temp = selectionIndices[j];
- index = j;
- }
- }
- int element = selectionIndices[i];
- selectionIndices[i] = selectionIndices[index];
- selectionIndices[index] = element;
- }
- return selectionIndices;
- }
- return null;
- }
-
- public int getMinSelectionIndex() {
- int[] selectionIndices = table.getSelectionIndices();
- if (selectionIndices.length != 0) {
- int temp = selectionIndices[0];
- for (int i = 1; i < selectionIndices.length; i++) {
- if (temp > selectionIndices[i]) {
- temp = selectionIndices[i];
- }
- }
- return temp;
- }
- return -1;
- }
-
- /**
- * @param index0
- * @param index1 Similar to setSelectionInterval(int index0, int index1) in DefaultListSelectionModel of SWING
- * but index0 should be less than index1
- */
- public void setSelectionInterval(int index0, int index1) {
- secondArgument = index1;
- table.setSelection(index0, index1);
- notifyListeners(SWT.Selection, new Event());
- }
-
-
- public boolean isSelectionEmpty() {
- return (table.getSelectionIndices().length == 0);
- }
-
- public void selectAll() {
- table.selectAll();
- }
-
- public void clearSelection() {
- if (table.getSelectionCount() != 0) {
- notifyListeners(SWT.Selection, new Event());
- }
- table.deselectAll();
- }
-
- public int indexOf(TableItem item) {
- return (table.indexOf(item));
- }
-
- public void remove(int index) {
- table.remove(index);
- }
-
-
- public void notifyListeners(int type, Event e) {
- table.notifyListeners(type, e);
- }
-
- public boolean isSelectedIndex(int index) {
- int arr[] = table.getSelectionIndices();
- for (int i = 0; i < arr.length; i++) {
- if (index == arr[i]) {
- return true;
- }
- }
- return false;
- }
-}
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.commons.tcpmon.eclipse.ui;
+
+
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.SWT;
+
+/**
+ *
+ * A table enhancer class that wraps a table - A 'decorator' :)
+ *
+ */
+public class TableEnhancer {
+ private Table table;
+ private int secondArgument;
+
+ public TableEnhancer(Table table) {
+ this.table = table;
+ }
+
+ public void setValueAt(String value, int row, int column) {
+ TableItem item = table.getItem(row);
+ item.setText(column, value);
+ }
+
+ public int getLeadSelectionIndex() {
+ return secondArgument;
+ }
+
+ public int getMaxSelectionIndex() {
+ int[] selectionIndices = table.getSelectionIndices();
+ if (selectionIndices.length != 0) {
+ int temp = selectionIndices[0];
+ for (int i = 1; i < selectionIndices.length; i++) {
+ if (temp < selectionIndices[i]) {
+ temp = selectionIndices[i];
+ }
+ }
+ return temp;
+ }
+ return -1;
+ }
+
+ public int getNearestSelectionToZero() {
+ int[] selectionIndices = sortArray(table.getSelectionIndices());
+ if (selectionIndices[0] == 0) {
+ return selectionIndices[1];
+ } else {
+ return selectionIndices[0];
+ }
+ }
+
+ public int[] getSelectionIndicesWithoutZero() {
+ int[] selectionIndices = sortArray(table.getSelectionIndices());
+ if (selectionIndices[0] == 0) {
+ int[] tempArray = new int[selectionIndices.length - 1];
+ for (int i = 1; i < selectionIndices.length; i++) {
+ tempArray[i - 1] = selectionIndices[i];
+ }
+ return tempArray;
+ }
+ return selectionIndices;
+ }
+
+ private int[] sortArray(int[] selectionIndices) {
+ if (selectionIndices.length != 0) {
+ for (int i = 0; i < selectionIndices.length; i++) {
+ int temp = selectionIndices[i];
+ int index = i;
+ for (int j = i; j < selectionIndices.length; j++) {
+ if (temp > selectionIndices[j]) {
+ temp = selectionIndices[j];
+ index = j;
+ }
+ }
+ int element = selectionIndices[i];
+ selectionIndices[i] = selectionIndices[index];
+ selectionIndices[index] = element;
+ }
+ return selectionIndices;
+ }
+ return null;
+ }
+
+ public int getMinSelectionIndex() {
+ int[] selectionIndices = table.getSelectionIndices();
+ if (selectionIndices.length != 0) {
+ int temp = selectionIndices[0];
+ for (int i = 1; i < selectionIndices.length; i++) {
+ if (temp > selectionIndices[i]) {
+ temp = selectionIndices[i];
+ }
+ }
+ return temp;
+ }
+ return -1;
+ }
+
+ /**
+ * @param index0
+ * @param index1 Similar to setSelectionInterval(int index0, int index1) in DefaultListSelectionModel of SWING
+ * but index0 should be less than index1
+ */
+ public void setSelectionInterval(int index0, int index1) {
+ secondArgument = index1;
+ table.setSelection(index0, index1);
+ notifyListeners(SWT.Selection, new Event());
+ }
+
+
+ public boolean isSelectionEmpty() {
+ return (table.getSelectionIndices().length == 0);
+ }
+
+ public void selectAll() {
+ table.selectAll();
+ }
+
+ public void clearSelection() {
+ if (table.getSelectionCount() != 0) {
+ notifyListeners(SWT.Selection, new Event());
+ }
+ table.deselectAll();
+ }
+
+ public int indexOf(TableItem item) {
+ return (table.indexOf(item));
+ }
+
+ public void remove(int index) {
+ table.remove(index);
+ }
+
+
+ public void notifyListeners(int type, Event e) {
+ table.notifyListeners(type, e);
+ }
+
+ public boolean isSelectedIndex(int index) {
+ int arr[] = table.getSelectionIndices();
+ for (int i = 0; i < arr.length; i++) {
+ if (index == arr[i]) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java?rev=729821&r1=729820&r2=729821&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java Sun Dec 28 17:10:41 2008
@@ -1,69 +1,69 @@
-package org.apache.ws.commons.tcpmon.idea.plugin;
-
-import com.intellij.openapi.components.ProjectComponent;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.wm.ToolWindow;
-import com.intellij.openapi.wm.ToolWindowManager;
-import com.intellij.openapi.wm.ToolWindowAnchor;
-
-import org.apache.ws.commons.tcpmon.idea.ui.ComponentHandler;
-/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-public class IdeaPlugin implements ProjectComponent {
-
- private static final String TCPMON_NAME = "TCPMon";
- private Project project;
-
-
- public IdeaPlugin(Project project) {
- this.project = project;
- }
-
- public void projectOpened() {
- initToolWindow();
- }
-
- public void projectClosed() {
- unregisterToolWindow();
- }
-
- public String getComponentName() {
- return TCPMON_NAME;
- }
-
- public void initComponent() {
- //nothing to do here
- }
-
- public void disposeComponent() {
- //nothing to do here
- }
-
- private void initToolWindow() {
- ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
- toolWindowManager.registerToolWindow(
- TCPMON_NAME,
- ComponentHandler.getTCPMonTabbedPane(),
- ToolWindowAnchor.RIGHT);
-// URL resource = getClass().getClassLoader().getResource("images/tcpmonitor.gif");
-// toolWindow.setIcon(new ImageIcon(resource));
- }
-
- private void unregisterToolWindow() {
- //do nothing
- }
-}
+package org.apache.ws.commons.tcpmon.idea.plugin;
+
+import com.intellij.openapi.components.ProjectComponent;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.openapi.wm.ToolWindowManager;
+import com.intellij.openapi.wm.ToolWindowAnchor;
+
+import org.apache.ws.commons.tcpmon.idea.ui.ComponentHandler;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class IdeaPlugin implements ProjectComponent {
+
+ private static final String TCPMON_NAME = "TCPMon";
+ private Project project;
+
+
+ public IdeaPlugin(Project project) {
+ this.project = project;
+ }
+
+ public void projectOpened() {
+ initToolWindow();
+ }
+
+ public void projectClosed() {
+ unregisterToolWindow();
+ }
+
+ public String getComponentName() {
+ return TCPMON_NAME;
+ }
+
+ public void initComponent() {
+ //nothing to do here
+ }
+
+ public void disposeComponent() {
+ //nothing to do here
+ }
+
+ private void initToolWindow() {
+ ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
+ toolWindowManager.registerToolWindow(
+ TCPMON_NAME,
+ ComponentHandler.getTCPMonTabbedPane(),
+ ToolWindowAnchor.RIGHT);
+// URL resource = getClass().getClassLoader().getResource("images/tcpmonitor.gif");
+// toolWindow.setIcon(new ImageIcon(resource));
+ }
+
+ private void unregisterToolWindow() {
+ //do nothing
+ }
+}
Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native