1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

Initial contribution of Wind River's terminal view.

This commit is contained in:
Ted Williams 2006-10-04 01:28:30 +00:00
commit f1f305dbc1
48 changed files with 9682 additions and 0 deletions

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.tm.terminal</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
#Mon Jul 31 14:55:18 CEST 2006
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.source=1.4

View file

@ -0,0 +1,3 @@
#Mon Jul 31 14:55:17 CEST 2006
eclipse.preferences.version=1
internal.default.compliance=user

View file

@ -0,0 +1,18 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.tm.terminal; singleton:=true
Bundle-Version: 2.6.0
Bundle-Activator: org.eclipse.tm.terminal.TerminalPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.ui.views,
org.eclipse.ui.workbench.texteditor,
org.eclipse.ui.editors,
org.eclipse.core.resources,
org.eclipse.ui,
org.eclipse.jface.text
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.4

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 874 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

View file

@ -0,0 +1,17 @@
##########################################################################
# Copyright 2004 Wind River Systems, Inc. All rights reserved.
##########################################################################
pluginName = Terminal
providerName = Eclipse.org
terminal.views.category.name = Device Debug
terminal.views.view.name = Terminal
terminal.views.view.font.description = The font for the terminal console.
terminal.views.view.font.label = Terminal Console Font
terminal.view.context.name=Terminal view context
terminal.view.context.description=control-q override
terminal.view.insertion.description=Terminal view insertion
terminal.view.insertion.name=Terminal view insert
terminal.view.insertion.category.name=Terminal view commands

View file

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="%terminal.views.category.name"
id="Terminal">
</category>
<view
allowMultiple="true"
class="org.eclipse.tm.terminal.TerminalView"
icon="icons/cview16/terminal_view.gif"
category="Terminal"
name="%terminal.views.view.name"
id="org.eclipse.tm.terminal.TerminalView">
</view>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="Terminal">
<viewShortcut id="org.eclipse.tm.terminal.TerminalView"/>
<view id="org.eclipse.tm.terminal.TerminalView"
relationship="stack">
</view>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
name="%terminal.views.view.name"
class="org.eclipse.tm.terminal.TerminalPreferencePage"
id="org.eclipse.tm.terminal.TerminalPreferencePage">
</page>
</extension>
<extension
point="org.eclipse.ui.fontDefinitions">
<fontDefinition
label="%terminal.views.view.font.label"
defaultsTo="org.eclipse.jface.textfont"
id="terminal.views.view.font.definition">
<description>
%terminal.views.view.font.description
</description>
</fontDefinition>
</extension>
<extension point="org.eclipse.ui.contexts">
<context
name="%terminal.view.context.name"
description="%terminal.view.context.description"
id="org.eclipse.tm.terminal.TerminalContext"
/>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
categoryId="org.eclipse.tm.terminal.category1"
id="org.eclipse.tm.terminal.command1"
name="%terminal.view.insertion.name"/>
<category
description="%terminal.view.insertion.description"
id="org.eclipse.tm.terminal.category1"
name="%terminal.view.insertion.category.name"/>
</extension>
<extension
point="org.eclipse.ui.bindings">
<!--
These keybindings are needed to disable the menu-activation keys (e.g.,
Alt-F for the File menu, etc.). The code in method
TerminalCtrl.TerminalFocusListener.focusGained() disables the Eclipse key
binding service, but it doesn't disable the global menu-activation
keys.
-->
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+A"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+E"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+F"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+G"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+H"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+N"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+P"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+R"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+T"/>
<key
commandId="org.eclipse.tm.terminal.command1"
contextId="org.eclipse.tm.terminal.TerminalContext"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="Alt+W"/>
</extension>
</plugin>

View file

@ -0,0 +1,117 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
/**
* A simple logger class. Every method in this class is static, so they can be called
* from both class and instance methods. To use this class, write code like this: <p>
*
* <pre>
* Logger.log("something has happened");
* Logger.log("counter is " + counter);
* </pre>
*
* @author Fran Litterio <francis.litterio@windriver.com>
*/
public final class Logger
{
/**
* UNDER CONSTRUCTION
*/
private static PrintStream logStream;
static
{
String logFile = null;
File logDirWindows = new File("C:\\wblogs"); //$NON-NLS-1$
File logDirUNIX = new File("/tmp/wblogs"); //$NON-NLS-1$
if (logDirWindows.isDirectory())
{
logFile = logDirWindows + "\\wbterminal.log"; //$NON-NLS-1$
}
else if (logDirUNIX.isDirectory())
{
logFile = logDirUNIX + "/wbterminal.log"; //$NON-NLS-1$
}
if (logFile != null)
{
try
{
logStream = new PrintStream(new FileOutputStream(logFile, true));
}
catch (Exception ex)
{
logStream = System.err;
logStream.println("Exception when opening log file -- logging to stderr!"); //$NON-NLS-1$
ex.printStackTrace(logStream);
}
}
}
/**
* Logs the specified message. Do not append a newline to parameter
* <i>message</i>. This method does that for you.
*
* @param message A String containing the message to log.
*/
public static final void log(String message)
{
if (logStream != null)
{
// Read my own stack to get the class name, method name, and line number of
// where this method was called.
StackTraceElement caller = new Throwable().getStackTrace()[1];
int lineNumber = caller.getLineNumber();
String className = caller.getClassName();
String methodName = caller.getMethodName();
className = className.substring(className.lastIndexOf('.') + 1);
logStream.println(className + "." + methodName + ":" + lineNumber + ": " + message); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
logStream.flush();
}
}
/**
* Writes a stack trace for an exception to both Standard Error and to the log file.
*/
public static final void logException(Exception ex)
{
// Read my own stack to get the class name, method name, and line number of
// where this method was called.
StackTraceElement caller = new Throwable().getStackTrace()[1];
int lineNumber = caller.getLineNumber();
String className = caller.getClassName();
String methodName = caller.getMethodName();
className = className.substring(className.lastIndexOf('.') + 1);
PrintStream tmpStream = System.err;
if (logStream != null)
{
tmpStream = logStream;
}
tmpStream.println(className + "." + methodName + ":" + lineNumber + ": " + //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
"Caught exception: " + ex); //$NON-NLS-1$
ex.printStackTrace(tmpStream);
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages
{
private static final String BUNDLE_NAME = "org.eclipse.tm.terminal.Messages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
private Messages()
{
// Empty.
}
public static String getString(String key)
{
try
{
return RESOURCE_BUNDLE.getString(key);
}
catch (MissingResourceException e)
{
return '!' + key + '!';
}
}
}

View file

@ -0,0 +1,33 @@
TerminalConsts.Terminal_7=Terminal
TerminalConsts.Limit_terminal_output_16=Limit terminal output
TerminalConsts.Terminal_buffer_lines__17=Terminal buffer lines:
TerminalConsts.Serial_timeout_(seconds)__18=Serial timeout (seconds):
TerminalConsts.Network_timeout_(seconds)__19=Network timeout (seconds):
TerminalConsts.Terminal_Settings_1=Terminal Settings
TerminalConsts.Connection_Type_2=Connection Type
TerminalConsts.Settings_3=Settings
TerminalConsts.Port_4=Port
TerminalConsts.Baud_Rate_5=Baud Rate
TerminalConsts.Data_Bits_6=Data Bits
TerminalConsts.Stop_Bits_7=Stop Bits
TerminalConsts.Parity_8=Parity
TerminalConsts.Flow_Out_10=Flow Out
TerminalConsts.Host_11=Host
TerminalConsts.Terminal_Error_12=Terminal Error
TerminalConsts.Socket_Error_13=Socket Error
TerminalConsts.IO_Error_14=IO Error
TerminalConsts.Serial_port___{0}___is_currently_in_use_!_nDo_you_want_to_close_the_port__15=Serial port \''{0}\'' is currently in use\!\nDo you want to close the port?
TerminalConsts.Error_16=Error
TerminalConsts.Emulator_is_not_supported._17=Emulator is not supported.
TerminalConsts.New_terminal=New Terminal
TerminalConsts.Connect_2=Connect
TerminalConsts.Disconnect_3=Disconnect
TerminalConsts.Settings..._4=Settings...
TerminalConsts.Copy_5=Copy
TerminalConsts.0=Cut
TerminalConsts.1=Flow Control
TerminalConsts.Paste_6=Paste
TerminalConsts.Select_All_7=Select All
TerminalConsts.Clear_All_8=Clear All
TerminalConsts.Break_9=Break

View file

@ -0,0 +1,92 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
/**
* This interface defines symbolic constants for numeric TELNET protocol command and
* option codes. Any class that needs to use these constants must implement this
* interface. The meanings of these constants are defined in the various TELNET RFCs
* (RFC 854 to RFC 861, and others).
*/
interface TelnetCodes
{
/** Command code: Subnegotiation End. */
static final byte TELNET_SE = (byte)240;
/** Command code: No-op. */
static final byte TELNET_NOP = (byte)241;
/** Command code: Data Mark. */
static final byte TELNET_DM = (byte)242;
/** Command code: Break. */
static final byte TELNET_BREAK = (byte)243;
/** Command code: Interrupt Process. */
static final byte TELNET_IP = (byte)244;
/** Command code: Abort Output. */
static final byte TELNET_AO = (byte)245;
/** Command code: Are You There. */
static final byte TELNET_AYT = (byte)246;
/** Command code: Erase Character. */
static final byte TELNET_EC = (byte)247;
/** Command code: Erase Line. */
static final byte TELNET_EL = (byte)248;
/** Command code: Go Ahead. */
static final byte TELNET_GA = (byte)249;
/** Command code: Subnegotiation Begin. */
static final byte TELNET_SB = (byte)250;
/** Command code: Will. */
static final byte TELNET_WILL = (byte)251;
/** Command code: Won't. */
static final byte TELNET_WONT = (byte)252;
/** Command code: Do. */
static final byte TELNET_DO = (byte)253;
/** Command code: Don't. */
static final byte TELNET_DONT = (byte)254;
/** Command code: Interpret As Command. */
static final byte TELNET_IAC = (byte)255;
/** Command code: IS. */
static final byte TELNET_IS = 0;
/** Command code: SEND. */
static final byte TELNET_SEND = 1;
/** Option code: Transmit Binary option. */
static final byte TELNET_OPTION_TRANSMIT_BINARY = 0;
/** Option code: Echo option. */
static final byte TELNET_OPTION_ECHO = 1;
/** Option code: Suppress Go Ahead option. */
static final byte TELNET_OPTION_SUPPRESS_GA = 3;
/** Option code: Terminal Type */
static final byte TELNET_OPTION_TERMINAL_TYPE = 24;
/** Option code: Negotitate About Window Size (NAWS) */
static final byte TELNET_OPTION_NAWS = 31;
}

View file

@ -0,0 +1,796 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketException;
import org.eclipse.swt.widgets.Display;
/**
* This class encapsulates a TELNET connection to a remote server. It processes
* incoming TELNET protocol data and generates outbound TELNET protocol data. It also
* manages two sets of TelnetOption objects: one for the local endpoint and one for the
* remote endpoint. <p>
*
* IMPORTANT: Understanding this code requires understanding the TELNET protocol and
* TELNET option processing, as defined in the RFCs listed below. <p>
*
* @author Fran Litterio (francis.litterio@windriver.com)
*
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc854.txt">RFC 854</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc855.txt">RFC 855</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc856.txt">RFC 856</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc857.txt">RFC 857</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc858.txt">RFC 858</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc859.txt">RFC 859</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc860.txt">RFC 860</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc861.txt">RFC 861</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc1091.txt">RFC 1091</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc1096.txt">RFC 1096</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc1073.txt">RFC 1073</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc1079.txt">RFC 1079</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc1143.txt">RFC 1143</a>
* @see <a href="ftp://ftp.rfc-editor.org/in-notes/rfc1572.txt">RFC 1572</a>
*/
class TelnetConnection extends Thread implements TelnetCodes, TerminalMsg
{
/**
* TELNET connection state: Initial state.
*/
protected static final int STATE_INITIAL = 0;
/**
* TELNET connection state: Last byte processed was IAC code.
* code.
*/
protected static final int STATE_IAC_RECEIVED = 1;
/**
* TELNET connection state: Last byte processed was WILL code.
* code.
*/
protected static final int STATE_WILL_RECEIVED = 2;
/**
* TELNET connection state: Last byte processed was WONT code.
*/
protected static final int STATE_WONT_RECEIVED = 3;
/**
* TELNET connection state: Last byte processed was DO code.
*/
protected static final int STATE_DO_RECEIVED = 4;
/**
* TELNET connection state: Last byte processed was DONT code.
*/
protected static final int STATE_DONT_RECEIVED = 5;
/**
* TELNET connection state: Last byte processed was SB.
*/
protected static final int STATE_SUBNEGOTIATION_STARTED = 6;
/**
* TELNET connection state: Currently receiving sub-negotiation data.
*/
protected static final int STATE_RECEIVING_SUBNEGOTIATION = 7;
/**
* Size of buffer for processing data received from remote endpoint.
*/
protected static final int BUFFER_SIZE = 2048;
/**
* Holds raw bytes received from the remote endpoint, prior to any TELNET protocol
* processing.
*/
protected byte[] rawBytes = new byte[BUFFER_SIZE];
/**
* Holds incoming network data after the TELNET protocol bytes have been
* processed and removed.
*/
protected byte[] processedBytes = new byte[BUFFER_SIZE];
/**
* This field holds a StringBuffer containing text recently received from the
* remote endpoint (after all TELNET protocol bytes have been processed and
* removed).
*/
protected StringBuffer processedStringBuffer = new StringBuffer(BUFFER_SIZE);
/**
* Holds the current state of the TELNET protocol processor.
*/
protected int telnetState = STATE_INITIAL;
/**
* This field is true if the remote endpoint is a TELNET server, false if not. We
* set this to true if and only if the remote endpoint sends recognizable TELNET
* protocol data. We do not assume that the remote endpoint is a TELNET server
* just because it is listening on port 23. This allows us to successfully connect
* to a TELNET server listening on a port other than 23. <p>
*
* When this field first changes from false to true, we send all WILL or DO
* commands to the remote endpoint. <p>
*
* @see #telnetServerDetected()
*/
protected boolean remoteIsTelnetServer = false;
/**
* An array of TelnetOption objects representing the local endpoint's TELNET
* options. The array is indexed by the numeric TELNET option code.
*/
protected TelnetOption[] localOptions = new TelnetOption[256];
/**
* An array of TelnetOption objects representing the remote endpoint's TELNET
* options. The array is indexed by the numeric TELNET option code.
*/
protected TelnetOption[] remoteOptions = new TelnetOption[256];
/**
* An array of bytes that holds the TELNET subnegotiation command most recently
* received from the remote endpoint. This array does _not_ include the leading
* IAC SB bytes, nor does it include the trailing IAC SE bytes. The first byte of
* this array is always a TELNET option code.
*/
protected byte[] receivedSubnegotiation = new byte[128];
/**
* This field holds the index into array {@link receivedSubnegotiation} of the next
* unused byte. This is used by method {@link #processTelnetProtocol(int)} when
* the state machine is in states {@link #STATE_SUBNEGOTIATION_STARTED} and {@link
* STATE_RECEIVING_SUBNEGOTIATION}.
*/
protected int nextSubnegotiationByteIndex = 0;
/**
* This field is true if an error occurs while processing a subnegotiation
* command.
*
* @see #processTelnetProtocol(int)
*/
protected boolean ignoreSubnegotiation = false;
/**
* This field holds the width of the Terminal screen in columns.
*/
protected int width = 0;
/**
* This field holds the height of the Terminal screen in rows.
*/
protected int height = 0;
/**
* This field holds a reference to the {@link TerminalCtrl} singleton.
*/
protected TerminalCtrl terminalControl;
/**
* This method holds the Socket object for the TELNET connection.
*/
protected Socket socket;
/**
* This field holds a reference to a {@link TerminalText} object, which displays
* text to the user.
*/
protected TerminalText terminalText;
/**
* This field holds a reference to an {@link InputStream} object used to receive
* data from the remote endpoint.
*/
protected InputStream inputStream;
/**
* This field holds a reference to an {@link OutputStream} object used to send data
* to the remote endpoint.
*/
protected OutputStream outputStream;
/**
* This field holds the SWT Display object for the GUI. We use this to execute a
* TerminalText method on the display thread, so that it can draw text in the view.
*/
protected Display display;
/**
* UNDER CONSTRUCTION
*/
protected boolean localEcho = true;
/**
* This constructor just initializes some internal object state from its
* arguments.
*/
public TelnetConnection(TerminalCtrl terminalControl, Socket socket,
TerminalText terminalText)
throws IOException
{
super();
Logger.log("entered"); //$NON-NLS-1$
this.terminalControl = terminalControl;
this.socket = socket;
this.terminalText = terminalText;
inputStream = socket.getInputStream();
outputStream = socket.getOutputStream();
display = terminalControl.getTextWidget().getDisplay();
initializeOptions();
}
/**
* Returns true if the TCP connection represented by this object is connected,
* false otherwise.
*/
public boolean isConnected()
{
return socket != null && socket.isConnected();
}
/**
* Returns true if the TCP connection represented by this object is connected and
* the remote endpoint is a TELNET server, false otherwise.
*/
public boolean isRemoteTelnetServer()
{
return remoteIsTelnetServer;
}
/**
* This method sets the terminal width and height to the supplied values. If
* either new value differs from the corresponding old value, we initiate a NAWS
* subnegotiation to inform the remote endpoint of the new terminal size.
*/
public void setTerminalSize(int newWidth, int newHeight)
{
Logger.log("Setting new size: width = " + newWidth + ", height = " + newHeight); //$NON-NLS-1$ //$NON-NLS-2$
boolean sizeChanged = false;
if (newWidth != width || newHeight != height)
sizeChanged = true;
width = newWidth;
height = newHeight;
if (sizeChanged && remoteIsTelnetServer && localOptions[TELNET_OPTION_NAWS].isEnabled())
{
Integer[] sizeData = { new Integer(width), new Integer(height) };
localOptions[TELNET_OPTION_NAWS].sendSubnegotiation(sizeData);
}
}
/**
* Returns true if local echoing is enabled for this TCP connection, false otherwise.
*/
public boolean localEcho()
{
return localEcho;
}
/**
* This method runs in its own thread. It reads raw bytes from the TELNET
* connection socket, processes any TELNET protocol bytes (and removes them), and
* passes the remaining bytes to a TerminalDisplay object for display.
*/
public void run()
{
Logger.log("Entered"); //$NON-NLS-1$
try
{
while (socket.isConnected())
{
int nRawBytes = inputStream.read(rawBytes);
if (nRawBytes == -1)
{
// End of input on inputStream.
Logger.log("End of input reading from socket!"); //$NON-NLS-1$
// Announce to the user that the remote endpoint has closed the
// connection.
processedStringBuffer.replace(0, processedStringBuffer.length(),
"\rConnection closed by foreign host.\r\n"); //$NON-NLS-1$
terminalText.setNewText(processedStringBuffer);
// See the large comment below for an explaination of why we must
// call Display.syncExec() instead of Display.asyncExec().
display.syncExec(terminalText);
// Tell the TerminalCtrl object that the connection is closed.
terminalControl.setOpened(false);
terminalControl.setConnected(false);
// Update the Terminal view UI to show a disconnected state. This
// ugliness involving Display.asyncExec() is forced on us by the
// bad design of class TerminalCtrl, which requires in certain
// cases (maybe all?) that TerminalCtrl.execute() is called only
// from the display thread.
Runnable disconnectNotifier = new Thread()
{
public void run()
{
terminalControl.execute(ON_TERMINAL_DISCONNECT, null);
}
};
display.asyncExec(disconnectNotifier);
break;
}
else
{
Logger.log("Received " + nRawBytes + " bytes: '" + //$NON-NLS-1$ //$NON-NLS-2$
new String(rawBytes, 0, nRawBytes) + "'"); //$NON-NLS-1$
// Process any TELNET protocol data that we receive. Don't send
// any TELNET protocol data until we are sure the remote endpoint
// is a TELNET server.
int nProcessedBytes = processTelnetProtocol(nRawBytes);
if (nProcessedBytes > 0)
{
String strBuffer = new String(processedBytes, 0, nProcessedBytes);
// An earlier version of this code created a new StringBuffer
// object here, but that was unnecessary. Instead, we reuse an
// existing object (processedStringBuffer).
processedStringBuffer.replace(0, processedStringBuffer.length(),
strBuffer);
// Use the TerminalText object to display the text to the
// user.
terminalText.setNewText(processedStringBuffer);
// Now make the TerminalText object display the processesed
// bytes. Its code has to run in the display thread, so we
// call syncExec() to do that. We do _not_ call asyncExec()
// because asyncExec() does not wait for the Runnable
// (TerminalText) to finish. If we were to call asynchExec(),
// this loop might race around and call setNewText() on the
// terminalText object again before the Display thread gets to
// display the previous buffer held by that object. By
// blocking here, we avoid that race and also delay the next
// call to read(), which keeps the unread data in the kernel,
// where it belongs (i.e., we don't have to manage it).
//
// <soapbox>
// The original implementation of this package used asyncExec()
// and created a new TerminalText object for each trip through
// this loop. Yes, that allowed this thread to speed ahead of
// the Display thread. But that only served to make the
// Display thread queue all unexecuted TerminalText objects
// until they could be executed. That was simply buffering the
// undisplayed data in the Display thread instead of in the
// kernel, where it belongs. It also rapidly consumed JVM heap
// space with all those TerminalText objects waiting to be
// garbage collected.
// </soapbox>
display.syncExec(terminalText);
}
}
}
}
catch (SocketException ex)
{
String message = ex.getMessage();
// A "socket closed" exception is normal here. It's caused by the user
// clicking the disconnect button on the Terminal view toolbar.
if (message != null && !message.equals("socket closed")) //$NON-NLS-1$
{
Logger.logException(ex);
}
}
catch (Exception ex)
{
Logger.logException(ex);
}
}
/**
* This method initializes the localOptions[] and remoteOptions[] arrays so that
* they contain references to TelnetOption objects representing our desired state
* for each option. The goal is to achieve server-side echoing, suppression of Go
* Aheads, and to send the local terminal type and size to the remote endpoint.
*/
protected void initializeOptions()
{
// First, create all the TelnetOption objects in the "undesired" state.
for (int i = 0; i < localOptions.length; ++i)
{
localOptions[i] = new TelnetOption((byte)i, false, true, outputStream);
}
for (int i = 0; i < localOptions.length; ++i)
{
remoteOptions[i] = new TelnetOption((byte)i, false, false, outputStream);
}
// Next, set some of the options to the "desired" state. The options we desire
// to be enabled are as follows:
//
// TELNET Option Desired for Desired for
// Name and Code Local Endpoint Remote Endpoint
// --------------------- -------------- ---------------
// Echo (1) No Yes
// Suppress Go Ahead (3) Yes Yes
// Terminal Type (24) Yes Yes
// NAWS (31) Yes Yes
//
// All other options remain in the "undesired" state, and thus will be disabled
// (since either endpoint can force any option to be disabled by simply
// answering WILL with DONT and DO with WONT).
localOptions[TELNET_OPTION_ECHO].setDesired(false);
remoteOptions[TELNET_OPTION_ECHO].setDesired(true);
localOptions[TELNET_OPTION_SUPPRESS_GA].setDesired(true);
remoteOptions[TELNET_OPTION_SUPPRESS_GA].setDesired(true);
localOptions[TELNET_OPTION_TERMINAL_TYPE].setDesired(true);
remoteOptions[TELNET_OPTION_TERMINAL_TYPE].setDesired(true);
localOptions[TELNET_OPTION_NAWS].setDesired(true);
remoteOptions[TELNET_OPTION_NAWS].setDesired(true);
}
/**
* Process TELNET protocol data contained in the first <i>count</i> bytes of
* <i>rawBytes</i>. This function preserves its state between calls, because a
* multi-byte TELNET command might be split between two (or more) calls to this
* function. The state is preserved in field <i>telnetState</i>. This function
* implements an FSA that recognizes TELNET option codes. TELNET option state is
* stored in instances of {@link TelnetOption}. TELNET option subnegotiation is
* delegated to instances of TelnetOption.
*
* @return The number of bytes remaining in the buffer after removing all TELNET
* protocol bytes.
*/
protected int processTelnetProtocol(int count)
{
// This is too noisy to leave on all the time.
// Logger.log("Processing " + count + " bytes of data.");
int nextProcessedByte = 0;
for (int byteIndex = 0; byteIndex < count; ++byteIndex)
{
// It is possible for control to flow through the below code such that
// nothing happens. This happens when array rawBytes[] contains no TELNET
// protocol data.
byte inputByte = rawBytes[byteIndex];
switch (telnetState)
{
case STATE_INITIAL:
if (inputByte == TELNET_IAC)
{
telnetState = STATE_IAC_RECEIVED;
}
else
{
// It's not an IAC code, so just append it to processedBytes.
processedBytes[nextProcessedByte++] = rawBytes[byteIndex];
}
break;
case STATE_IAC_RECEIVED:
switch (inputByte)
{
case TELNET_IAC:
// Two IAC bytes in a row are translated into one byte with the
// value 0xff.
processedBytes[nextProcessedByte++] = (byte)0xff;
telnetState = STATE_INITIAL;
break;
case TELNET_WILL:
telnetState = STATE_WILL_RECEIVED;
break;
case TELNET_WONT:
telnetState = STATE_WONT_RECEIVED;
break;
case TELNET_DO:
telnetState = STATE_DO_RECEIVED;
break;
case TELNET_DONT:
telnetState = STATE_DONT_RECEIVED;
break;
case TELNET_SB:
telnetState = STATE_SUBNEGOTIATION_STARTED;
break;
// Commands to consume and ignore.
// Data Mark (DM). This is sent by a TELNET server following an
// IAC sent as TCP urgent data. It should cause the client to skip
// all not yet processed non-TELNET-protocol data preceding the DM
// byte. However, Java 1.4.x has no way to inform clients of class
// Socket that urgent data is available, so we simply ignore the
// "IAC DM" command. Since the IAC is sent as TCP urgent data, the
// Socket must be put into OOB-inline mode via a call to
// setOOBInline(true), otherwise the IAC is silently dropped by
// Java and only the DM arrives (leaving the user to see a spurious
// ISO Latin-1 character).
case TELNET_DM:
case TELNET_NOP: // No-op.
case TELNET_GA: // Go Ahead command. Meaningless on a full-duplex link.
case TELNET_IP: // Interupt Process command. Server should never send this.
case TELNET_AO: // Abort Output command. Server should never send this.
case TELNET_AYT: // Are You There command. Server should never send this.
case TELNET_EC: // Erase Character command. Server should never send this.
case TELNET_EL: // Erase Line command. Server should never send this.
telnetState = STATE_INITIAL;
break;
default:
// Unrecognized command! This should never happen.
Logger.log("processTelnetProtocol: UNRECOGNIZED TELNET PROTOCOL COMMAND: " + //$NON-NLS-1$
inputByte);
telnetState = STATE_INITIAL;
assert false;
break;
}
break;
// For the next four cases, WILL and WONT commands affect the state of
// remote options, and DO and DONT commands affect the state of local
// options.
case STATE_WILL_RECEIVED:
Logger.log("Received WILL " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
remoteOptions[inputByte].handleWill();
telnetState = STATE_INITIAL;
telnetServerDetected();
break;
case STATE_WONT_RECEIVED:
Logger.log("Received WONT " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
remoteOptions[inputByte].handleWont();
telnetState = STATE_INITIAL;
telnetServerDetected();
break;
case STATE_DO_RECEIVED:
Logger.log("Received DO " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
localOptions[inputByte].handleDo();
telnetState = STATE_INITIAL;
telnetServerDetected();
break;
case STATE_DONT_RECEIVED:
Logger.log("Received DONT " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
localOptions[inputByte].handleDont();
telnetState = STATE_INITIAL;
telnetServerDetected();
break;
case STATE_SUBNEGOTIATION_STARTED:
Logger.log("Starting subnegotiation for option " + //$NON-NLS-1$
localOptions[inputByte].optionName() + "."); //$NON-NLS-1$
// First, zero out the array of received subnegotiation butes.
for (int i = 0; i < receivedSubnegotiation.length; ++i)
receivedSubnegotiation[i] = 0;
// Forget about any previous subnegotiation errors.
ignoreSubnegotiation = false;
// Then insert this input byte into the array and enter state
// STATE_RECEIVING_SUBNEGOTIATION, where we will gather the remaining
// subnegotiation bytes.
nextSubnegotiationByteIndex = 0;
receivedSubnegotiation[nextSubnegotiationByteIndex++] = inputByte;
telnetState = STATE_RECEIVING_SUBNEGOTIATION;
break;
case STATE_RECEIVING_SUBNEGOTIATION:
if (inputByte == TELNET_IAC)
{
// Handle double IAC bytes. From RFC 855: "if parameters
// in an option 'subnegotiation' include a byte with a value of
// 255, it is necessary to double this byte in accordance the
// general TELNET rules."
if (nextSubnegotiationByteIndex > 0 &&
receivedSubnegotiation[nextSubnegotiationByteIndex - 1] == TELNET_IAC)
{
// The last input byte we received in this subnegotiation was
// IAC, so this is a double IAC. Leave the previous IAC in the
// receivedSubnegotiation[] array and drop the current one
// (thus translating a double IAC into a single IAC).
Logger.log("Double IAC in subnegotiation translated into single IAC."); //$NON-NLS-1$
break;
}
// Append the IAC byte to receivedSubnegotiation[]. If there is no
// room for the IAC byte, it overwrites the last byte, because we
// need to know when the subnegotiation ends, and that is marked by
// an "IAC SE" command.
if (nextSubnegotiationByteIndex < receivedSubnegotiation.length)
{
receivedSubnegotiation[nextSubnegotiationByteIndex++] = inputByte;
}
else
{
receivedSubnegotiation[receivedSubnegotiation.length - 1] = inputByte;
}
break;
}
// Handle an "IAC SE" command, which marks the end of the
// subnegotiation. An SE byte by itself might be a legitimate part of
// the subnegotiation data, so don't do anything unless the SE is
// immediately preceded by an IAC.
if (inputByte == TELNET_SE &&
receivedSubnegotiation[nextSubnegotiationByteIndex - 1] == TELNET_IAC)
{
Logger.log("Found SE code marking end of subnegotiation."); //$NON-NLS-1$
// We are done receiving the subnegotiation command. Now process
// it. We always use the option object stored in array
// localOptions[] to process the received subnegotiation. This is
// an arbitrary decision, but it is sufficient for handling options
// TERMINAL-TYPE and NAWS, which are the only options that we
// subnegotiate (presently). If, in the future, subnegotiations
// need to be handled by option objects stored in both
// localOptions[] and remoteOptions[], then some mechanism to
// choose the correct option object must be implemented.
//
// Also, if ignoreSubnegotiation is true, there was an error while
// receiving the subnegotiation, so we must not process the
// command, and instead just return to the initial state.
if (!ignoreSubnegotiation)
{
// Remove the trailing IAC byte from receivedSubnegotiation[].
receivedSubnegotiation[nextSubnegotiationByteIndex - 1] = 0;
int subnegotiatedOption = receivedSubnegotiation[0];
localOptions[subnegotiatedOption].
handleSubnegotiation(receivedSubnegotiation,
nextSubnegotiationByteIndex);
}
else
{
Logger.log("NOT CALLING handleSubnegotiation() BECAUSE OF ERRORS!"); //$NON-NLS-1$
}
// Return to the initial state.
telnetState = STATE_INITIAL;
}
// Check whether the receivedSubnegotiation[] array is full.
if (nextSubnegotiationByteIndex >= receivedSubnegotiation.length)
{
// This should not happen. Array receivedSubnegotiation can hold
// 128 bytes, and no TELNET option that we perform subnegotiation
// for requires that many bytes in a subnegotiation command. In
// the interest of robustness, we handle this case by ignoring all
// remaining subnegotiation bytes until we receive the IAC SE
// command that ends the subnegotiation. Also, we set
// ignoreSubnegotiation to true to prevent a call to
// handleSubnegotiation() when the IAC SE command arrives.
Logger.log("SUBNEGOTIATION BUFFER FULL!"); //$NON-NLS-1$
ignoreSubnegotiation = true;
}
else
{
Logger.log("Recording subnegotiation byte " + (inputByte & 0xff)); //$NON-NLS-1$
receivedSubnegotiation[nextSubnegotiationByteIndex++] = inputByte;
}
break;
default:
// This should _never_ happen! If it does, it means there is a bug in
// this FSA. For robustness, we return to the initial state.
Logger.log("INVALID TELNET STATE: " + telnetState); //$NON-NLS-1$
telnetState = STATE_INITIAL;
assert false;
break;
}
}
// Return the number of bytes of processed data (i.e., number of bytes of
// raw data minus TELNET control bytes). This value can be zero.
return nextProcessedByte;
}
/**
* This method is called whenever we receive a valid TELNET protocol command from
* the remote endpoint. When it is called for the first time for this connection,
* we negotiate all options that we desire to be enabled. <p>
*
* This method does not negotiate options that we do not desire to be enabled,
* because all options are initially disabled. <p>
*/
protected void telnetServerDetected()
{
if (!remoteIsTelnetServer)
{
// This block only executes once per TelnetConnection instance.
localEcho = false;
Logger.log("Detected TELNET server."); //$NON-NLS-1$
remoteIsTelnetServer = true;
for (int i = 0; i < localOptions.length; ++i)
{
if (localOptions[i].isDesired())
{
localOptions[i].negotiate();
}
}
for (int i = 0; i < remoteOptions.length; ++i)
{
if (remoteOptions[i].isDesired())
{
remoteOptions[i].negotiate();
}
}
}
}
}

View file

@ -0,0 +1,756 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
/**
* This class represents a single TELNET protocol option at one endpoint of a TELNET
* connection. This class encapsulates the endpoint associated with the option (local
* or remote), the current state of the option (enabled or disabled), the desired state
* of the option, the current state of the negotiation, an OutputStream that allows
* communication with the remote endpoint, and the number of negotiations that have
* started within this connection. <p>
*
* In addition to encapsulating the above state, this class performs option negotiation
* to attempt to achieve the desired option state. For some options, this class also
* performs option sub-negotiation. <p>
*
* IMPORTANT: Understanding this code requires understanding the TELNET protocol and
* TELNET option processing. <p>
*
* @author Fran Litterio (francis.litterio@windriver.com)
*/
class TelnetOption implements TelnetCodes
{
/**
* This array of Strings maps an integer TELNET option code value to the symbolic
* name of the option. Array elements of the form "?" represent unassigned option
* values.
*/
protected static final String[] optionNames =
{
"BINARY", // 0 //$NON-NLS-1$
"ECHO", // 1 //$NON-NLS-1$
"RECONNECTION", // 2 //$NON-NLS-1$
"SUPPRESS GO AHEAD", // 3 //$NON-NLS-1$
"MSG SIZE NEGOTIATION", // 4 //$NON-NLS-1$
"STATUS", // 5 //$NON-NLS-1$
"TIMING MARK", // 6 //$NON-NLS-1$
"REMOTE CTRL TRANS+ECHO", // 7 //$NON-NLS-1$
"OUTPUT LINE WIDTH", // 8 //$NON-NLS-1$
"OUTPUT PAGE SIZE", // 9 //$NON-NLS-1$
"OUTPUT CR DISPOSITION", // 10 //$NON-NLS-1$
"OUTPUT HORIZ TABSTOPS", // 11 //$NON-NLS-1$
"OUTPUT HORIZ TAB DISPOSITION", // 12 //$NON-NLS-1$
"OUTPUT FORMFEED DISPOSITION", // 13 //$NON-NLS-1$
"OUTPUT VERTICAL TABSTOPS", // 14 //$NON-NLS-1$
"OUTPUT VT DISPOSITION", // 15 //$NON-NLS-1$
"OUTPUT LF DISPOSITION", // 16 //$NON-NLS-1$
"EXTENDED ASCII", // 17 //$NON-NLS-1$
"LOGOUT", // 18 //$NON-NLS-1$
"BYTE MACRO", // 19 //$NON-NLS-1$
"DATA ENTRY TERMINAL", // 20 //$NON-NLS-1$
"SUPDUP", // 21 //$NON-NLS-1$
"SUPDUP OUTPUT", // 22 //$NON-NLS-1$
"SEND LOCATION", // 23 //$NON-NLS-1$
"TERMINAL TYPE", // 24 //$NON-NLS-1$
"END OF RECORD", // 25 //$NON-NLS-1$
"TACACS USER IDENTIFICATION", // 26 //$NON-NLS-1$
"OUTPUT MARKING", // 27 //$NON-NLS-1$
"TERMINAL LOCATION NUMBER", // 28 //$NON-NLS-1$
"3270 REGIME", // 29 //$NON-NLS-1$
"X.3 PAD", // 30 //$NON-NLS-1$
"NEGOTIATE ABOUT WINDOW SIZE", // 31 //$NON-NLS-1$
"TERMINAL SPEED", // 32 //$NON-NLS-1$
"REMOTE FLOW CONTROL", // 33 //$NON-NLS-1$
"LINEMODE", // 34 //$NON-NLS-1$
"X DISPLAY LOCATION", // 35 //$NON-NLS-1$
"ENVIRONMENT OPTION", // 36 //$NON-NLS-1$
"AUTHENTICATION OPTION", // 37 //$NON-NLS-1$
"ENCRYPTION OPTION", // 38 //$NON-NLS-1$
"NEW ENVIRONMENT OPTION", // 39 //$NON-NLS-1$
"TN3270E", // 40 //$NON-NLS-1$
"XAUTH", // 41 //$NON-NLS-1$
"CHARSET", // 42 //$NON-NLS-1$
"REMOTE SERIAL PORT", // 43 //$NON-NLS-1$
"COM PORT CONTROL OPTION", // 44 //$NON-NLS-1$
"SUPPRESS LOCAL ECHO", // 45 //$NON-NLS-1$
"START TLS", // 46 //$NON-NLS-1$
"KERMIT", // 47 //$NON-NLS-1$
"SEND URL", // 48 //$NON-NLS-1$
"FORWARD X", // 49 //$NON-NLS-1$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", // 50 ... //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", // ... 137 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
"TELOPT PRAGMA LOGON", // 138 //$NON-NLS-1$
"TELOPT SSPI LOGON", // 139 //$NON-NLS-1$
"TELOPT PRAGMA HEARTBEAT", // 140 //$NON-NLS-1$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", // 141 ... //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", "?", "?", "?", "?", "?", "?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$
"?", "?", "?", "?", // ... 254 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"EXTENDED OPTIONS LIST" // 255 //$NON-NLS-1$
};
/**
* Negotiation state: Negotiation not yet started for this option. <p>
*
* This constant and the others having similar names represent the states of a
* finite state automaton (FSA) that tracks the negotiation state of this option.
* The initial state is NEGOTIATION_NOT_STARTED. The state machine is as follows
* (with transitions labelled with letters in parentheses): <p>
*
* <pre>
* NEGOTIATION_NOT_STARTED -----> {@link #NEGOTIATION_IN_PROGRESS}
* | (A) | ^
* (C)| (B)| |(D)
* | V |
* +--------> {@link #NEGOTIATION_DONE}
* </pre> <p>
*
* Once the FSA leaves state NEGOTIATION_NOT_STARTED, it never returns to that
* state. Transition A happens when the local endpoint sends an option command
* before receiving a command for the same option from the remote endpoint. <p>
*
* Transition B happens when the local endpoint receives a reply to an option
* command sent earlier by the local endpoint. Receipt of that reply terminates
* the negotiation. <p>
*
* Transition D happens after negotiation is done and "something changes" (see the
* RFCs for the definition of "something changes"). Either endpoint can
* re-negotiate an option after a previous negotiation, but only if some external
* influence (such as the user or the OS) causes it to do so. Re-negotiation must
* start more than {@link #NEGOTIATION_IGNORE_DURATION} milliseconds after the FSA
* enters state NEGOTIATION_DONE or it will be ignored. This is how this client
* prevents negotiation loops. <p>
*
* Transition C happens when the local endpoint receives an option command from the
* remote endpoint before sending a command for the same option. In that case, the
* local endpoint replies immediately with an option command and the negotitation
* terminates. <p>
*
* Some TELNET servers (e.g., the Solaris server), after sending WILL and receiving
* DONT, will reply with a superfluous WONT. Any such superfluous option command
* received from the remote endpoint while the option's FSA is in state
* {@link #NEGOTIATION_DONE} will be ignored by the local endpoint.
*/
protected static final int NEGOTIATION_NOT_STARTED = 0;
/** Negotiation state: Negotiation is in progress for this option. */
protected static final int NEGOTIATION_IN_PROGRESS = 1;
/** Negotiation state: Negotiation has terminated for this option. */
protected static final int NEGOTIATION_DONE = 2;
/**
* The number of milliseconds following the end of negotiation of this option
* before which the remote endpoint can re-negotiate the option. Any option
* command received from the remote endpoint before this time passes is ignored.
* This is used to prevent option negotiation loops.
*
* @see #ignoreNegotiation()
* @see #negotiationCompletionTime
*/
protected static final int NEGOTIATION_IGNORE_DURATION = 30000;
/**
* This field holds the current negotiation state for this option.
*/
protected int negotiationState = NEGOTIATION_NOT_STARTED;
/**
* This field holds the time when negotiation of this option most recently
* terminated (i.e., entered state {@link #NEGOTIATION_DONE}). This is used to
* determine whether an option command received from the remote endpoint after
* negotiation has terminated for this option is to be ignored or interpreted as
* the start of a new negotiation.
*
* @see #NEGOTIATION_IGNORE_DURATION
*/
protected Date negotiationCompletionTime = new Date(0);
/**
* Holds the total number of negotiations that have completed for this option.
*/
protected int negotiationCount = 0;
/**
* Holds the integer code representing the option.
*/
protected byte option = 0;
/**
* Holds the OutputStream object that allows data to be sent to the remote endpoint
* of the TELNET connection.
*/
protected OutputStream outputStream;
/**
* True if this option is for the local endpoint, false for the remote endpoint.
*/
protected boolean local = true;
/**
* This field is true if the option is enabled, false if it is disabled. All
* options are initially disabled until they are negotiated to be enabled. <p>
*/
protected boolean enabled = false;
/**
* This field is true if the client desires the option to be enabled, false if the
* client desires the option to be disabled. This field does not represent the
* remote's endpoints desire (as expressed via WILL and WONT commands) -- it
* represnet the local endpoint's desire. <p>
*
* @see #setDesired(boolean)
*/
protected boolean desired = false;
/**
* Constructor. <p>
*
* @param option The integer code of this option.
* @param desired Whether we desire this option to be enabled.
* @param local Whether this option is for the local or remote endpoint.
* @param outputStream A stream used to negotiate with the remote endpoint.
*/
TelnetOption(byte option, boolean desired, boolean local, OutputStream outputStream)
{
this.option = option;
this.desired = desired;
this.local = local;
this.outputStream = outputStream;
}
/**
* @return Returns a String containing the name of the TELNET option specified in
* parameter <i>option</i>.
*/
public String optionName()
{
return optionNames[option];
}
/**
* Returns true if this option is enabled, false if it is disabled. <p>
*
* @return Returns true if this option is enabled, false if it is disabled.
*/
public boolean isEnabled()
{
return enabled;
}
/**
* Enables this option if <i>newValue</i> is true, otherwise disables this
* option. <p>
*
* @param newValue True if this option is to be enabled, false otherwise.
*/
public void setEnabled(boolean newValue)
{
Logger.log("Enabling " + (local ? "local" : "remote") + " option " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
optionName());
enabled = newValue;
}
/**
* Returns true if the local endpoint desires this option to be enabled, false if
* not. It is not an error for the value returned by this method to differ from
* the value returned by isEnabled(). The value returned by this method can change
* over time, reflecting the local endpoint's changing desire regarding the
* option. <p>
*
* NOTE: Even if this option represents a remote endpoint option, the return value
* of this method represents the local endpint's desire regarding the remote
* option. <p>
*
* @return Returns true if the local endpoint desires this option to be enabled,
* false if not.
*/
public boolean isDesired()
{
return desired;
}
/**
* Sets our desired value for this option. Note that the option can be desired
* when <i>enabled</i> is false, and the option can be undesired when
* <i>enabled</i> is true, though the latter state should not persist, since either
* endpoint can disable any option at any time. <p>
*
* @param newValue True if we desire this option to be enabled, false if
* we desire this option to be disabled.
*/
public void setDesired(boolean newValue)
{
if (newValue)
Logger.log("Setting " + (local ? "local" : "remote") + " option " + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
optionName() + " as desired."); //$NON-NLS-1$
desired = newValue;
}
/**
* Call this method to request that negotiation begin for this option. This method
* does nothing if negotiation for this option has already started or is already
* complete. If negotiation has not yet started for this option and the local
* endpoint desires this option to be enabled, then we send a WILL or DO command to
* the remote endpoint.
*/
public void negotiate()
{
if (negotiationState == NEGOTIATION_NOT_STARTED && desired)
{
if (local)
{
Logger.log("Starting negotiation for local option " + optionName()); //$NON-NLS-1$
sendWill();
}
else
{
Logger.log("Starting negotiation for remote option " + optionName()); //$NON-NLS-1$
sendDo();
}
negotiationState = NEGOTIATION_IN_PROGRESS;
}
}
/**
* This method is called whenever we receive a WILL command from the remote
* endpoint.
*/
public void handleWill()
{
if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation())
{
Logger.log("Ignoring superfluous WILL command from remote endpoint."); //$NON-NLS-1$
return;
}
if (negotiationState == NEGOTIATION_IN_PROGRESS)
{
if (desired)
{
// We sent DO and server replied with WILL. Enable the option, and end
// this negotiation.
enabled = true;
Logger.log("Enabling remote option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
else
{
// This should never happen! We sent DONT and the server replied with
// WILL. Bad server. No soup for you. Disable the option, and end
// this negotiation.
Logger.log("Server answered DONT with WILL!"); //$NON-NLS-1$
enabled = false;
Logger.log("Disabling remote option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
}
else
{
if (desired)
{
// Server sent WILL, so we reply with DO. Enable the option, and end
// this negotiation.
sendDo();
enabled = true;
Logger.log("Enabling remote option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
else
{
// Server sent WILL, so we reply with DONT. Disable the option, and
// end this negotiation.
sendDont();
enabled = false;
Logger.log("Disabling remote option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
}
}
/**
* Handles a WONT command sent by the remote endpoint for this option. The value
* of <i>desired</i> doesn't matter in this method, because the remote endpoint is
* forcing the option to be disabled.
*/
public void handleWont()
{
if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation())
{
Logger.log("Ignoring superfluous WONT command from remote endpoint."); //$NON-NLS-1$
return;
}
if (negotiationState == NEGOTIATION_IN_PROGRESS)
{
// We sent DO or DONT and server replied with WONT. Disable the
// option, and end this negotiation.
enabled = false;
Logger.log("Disabling remote option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
else
{
// Server sent WONT, so we reply with DONT. Disable the option, and
// end this negotiation.
sendDont();
enabled = false;
Logger.log("Disabling remote option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
}
/**
* Handles a DO command sent by the remote endpoint for this option.
*/
public void handleDo()
{
if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation())
{
Logger.log("Ignoring superfluous DO command from remote endpoint."); //$NON-NLS-1$
return;
}
if (negotiationState == NEGOTIATION_IN_PROGRESS)
{
if (desired)
{
// We sent WILL and server replied with DO. Enable the option, and end
// this negotiation.
enabled = true;
Logger.log("Enabling local option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
else
{
// We sent WONT and server replied with DO. This should never happen!
// Bad server. No soup for you. Disable the option, and end this
// negotiation.
Logger.log("Server answered WONT with DO!"); //$NON-NLS-1$
enabled = false;
Logger.log("Disabling local option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
}
else
{
if (desired)
{
// Server sent DO, so we reply with WILL. Enable the option, and end
// this negotiation.
sendWill();
enabled = true;
Logger.log("Enabling local option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
else
{
// Server sent DO, so we reply with WONT. Disable the option, and end
// this negotiation.
sendWont();
enabled = false;
Logger.log("Disabling local option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
}
}
/**
* Handles a DONT command sent by the remote endpoint for this option. The value
* of <i>desired</i> doesn't matter in this method, because the remote endpoint is
* forcing the option to be disabled.
*/
public void handleDont()
{
if (negotiationState == NEGOTIATION_DONE && ignoreNegotiation())
{
Logger.log("Ignoring superfluous DONT command from remote endpoint."); //$NON-NLS-1$
return;
}
if (negotiationState == NEGOTIATION_IN_PROGRESS)
{
// We sent WILL or WONT and server replied with DONT. Disable the
// option, and end this negotiation.
enabled = false;
Logger.log("Disabling local option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
else
{
// Server sent DONT, so we reply with WONT. Disable the option, and end
// this negotiation.
sendWont();
enabled = false;
Logger.log("Disabling local option " + optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
endNegotiation();
}
}
/**
* This method handles a subnegotiation command received from the remote endpoint.
* Currently, the only subnegotiation we handle is when the remote endpoint
* commands us to send our terminal type (which is "ansi").
*
* @param subnegotiationData An array of bytes containing a TELNET
* subnegotiation command received from the
* remote endpoint.
* @param count The number of bytes in array
* subnegotiationData to examine.
*/
public void handleSubnegotiation(byte[] subnegotiationData, int count)
{
switch (option)
{
case TELNET_OPTION_TERMINAL_TYPE:
if (subnegotiationData[1] != TELNET_SEND)
{
// This should never happen!
Logger.log("Invalid TERMINAL-TYPE subnegotiation command from remote endpoint: " + //$NON-NLS-1$
(subnegotiationData[1] & 0xff));
break;
}
// Tell the remote endpoint our terminal type is "ansi" using this sequence
// of TELNET protocol bytes:
//
// IAC SB TERMINAL-TYPE IS a n s i IAC SE
byte[] terminalTypeData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_TERMINAL_TYPE,
TELNET_IS, (byte)'a', (byte)'n', (byte)'s', (byte)'i',
TELNET_IAC, TELNET_SE };
try
{
outputStream.write(terminalTypeData);
}
catch (IOException ex)
{
Logger.log("IOException sending TERMINAL-TYPE subnegotiation!"); //$NON-NLS-1$
Logger.logException(ex);
}
break;
default:
// This should never happen!
Logger.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$
assert false;
break;
}
}
/**
* This method sends a subnegotiation command to the remote endpoint.
*
* @param subnegotiationData An array of Objects holding data to be used
* when generating the outbound subnegotiation
* command.
*/
public void sendSubnegotiation(Object[] subnegotiationData)
{
switch (option)
{
case TELNET_OPTION_NAWS:
// Get the width and height of the view and send it to the remote
// endpoint using this sequence of TELNET protocol bytes:
//
// IAC SB NAWS <width-highbyte> <width-lowbyte> <height-highbyte>
// <height-lowbyte> IAC SE
byte[] NAWSData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_NAWS,
0, 0, 0, 0, TELNET_IAC, TELNET_SE };
int width = ((Integer)subnegotiationData[0]).intValue();
int height = ((Integer)subnegotiationData[1]).intValue();
NAWSData[3] = (byte)((width >>> 8) & 0xff); // High order byte of width.
NAWSData[4] = (byte)(width & 0xff); // Low order byte of width.
NAWSData[5] = (byte)((height >>> 8) & 0xff); // High order byte of height.
NAWSData[6] = (byte)(height & 0xff); // Low order byte of height.
Logger.log("sending terminal size to remote endpoint: width = " + width + //$NON-NLS-1$
", height = " + height + "."); //$NON-NLS-1$ //$NON-NLS-2$
// This final local variable is a hack to get around the fact that inner
// classes cannot reference a non-final local variable in a lexically
// enclosing scope.
final byte[] NAWSDataFinal = NAWSData;
// Send the NAWS data in a new thread. The current thread is the display
// thread, and calls to write() can block, but blocking the display thread
// is _bad_ (it hangs the GUI).
new Thread()
{
public void run()
{
try
{
outputStream.write(NAWSDataFinal);
}
catch (IOException ex)
{
Logger.log("IOException sending NAWS subnegotiation!"); //$NON-NLS-1$
Logger.logException(ex);
}
}
}.start();
break;
default:
// This should never happen!
Logger.log("SHOULD NOT BE REACHED: Called for option " + optionName()); //$NON-NLS-1$
assert false;
break;
}
}
/**
* This method returns true if there has not yet been any negotiation of this
* option.
*
* @return Returns true if there has not yet been any negotiation of this option.
*/
protected boolean notYetNegotiated()
{
return negotiationState == NEGOTIATION_NOT_STARTED;
}
/**
* This method terminates the current negotiation and records the time at which the
* negotiation terminated.
*/
protected void endNegotiation()
{
Logger.log("Ending negotiation #" + negotiationCount + " for " + //$NON-NLS-1$ //$NON-NLS-2$
(local ? "local" : "remote") + " option " + optionName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
negotiationState = NEGOTIATION_DONE;
negotiationCompletionTime.setTime(System.currentTimeMillis());
++negotiationCount;
}
/**
* This method determines whether or not to ignore what appears to be a new
* negotiation initiated by the remote endpoint. This is needed because some
* TELNET servers send superfluous option commands that a naive client might
* interpret as the start of a new negotiation. If the superfluous command is not
* ignored, an option negotiation loop can result (which is bad). For details
* about the superfluous commands sent by some servers, see the documentation for
* {@link #NEGOTIATION_NOT_STARTED}. <p>
*
* The current implementation of this method returns true if the new negotiation
* starts within NEGOTIATION_IGNORE_DURATION seconds of the end of the previous
* negotiation of this option. <p>
*
* @return Returns true if the new negotiation should be ignored, false if not.
*/
protected boolean ignoreNegotiation()
{
return (System.currentTimeMillis() - negotiationCompletionTime.getTime()) >
NEGOTIATION_IGNORE_DURATION;
}
/**
* Sends a DO command to the remote endpoint for this option.
*/
protected void sendDo()
{
Logger.log("Sending DO " + optionName()); //$NON-NLS-1$
sendCommand(TELNET_DO);
}
/**
* Sends a DONT command to the remote endpoint for this option.
*/
protected void sendDont()
{
Logger.log("Sending DONT " + optionName()); //$NON-NLS-1$
sendCommand(TELNET_DONT);
}
/**
* Sends a WILL command to the remote endpoint for this option.
*/
protected void sendWill()
{
Logger.log("Sending WILL " + optionName()); //$NON-NLS-1$
sendCommand(TELNET_WILL);
}
/**
* Sends a WONT command to the remote endpoint for this option.
*/
protected void sendWont()
{
Logger.log("Sending WONT " + optionName()); //$NON-NLS-1$
sendCommand(TELNET_WONT);
}
/**
* This method sends a WILL/WONT/DO/DONT command to the remote endpoint for this
* option.
*/
protected void sendCommand(byte command)
{
byte[] data = { TELNET_IAC, 0, 0 };
data[1] = command;
data[2] = option;
try
{
outputStream.write(data);
}
catch (IOException ex)
{
Logger.log("IOException sending command " + command); //$NON-NLS-1$
Logger.logException(ex);
}
}
}

View file

@ -0,0 +1,119 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
public class TerminalAction extends Action
implements TerminalMsg, TerminalConsts
{
/**
*
*/
protected TerminalTarget m_Target;
protected String m_strMsg;
/**
*
*/
public TerminalAction(TerminalTarget target,
String strMsg,
String strId)
{
super(""); //$NON-NLS-1$
m_Target = target;
m_strMsg = strMsg;
setId(strId);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Action interface
//
/**
*
*/
public void run()
{
m_Target.execute(m_strMsg,this);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Operations
//
/**
*
*/
protected void setupAction(String strText,
String strToolTip,
String strImage,
String strEnabledImage,
String strDisabledImage,
boolean bEnabled)
{
TerminalPlugin plugin;
ImageRegistry imageRegistry;
plugin = TerminalPlugin.getDefault();
imageRegistry = plugin.getImageRegistry();
setupAction(strText,
strToolTip,
strImage,
strEnabledImage,
strDisabledImage,
bEnabled,
imageRegistry);
}
/**
*
*/
protected void setupAction(String strText,
String strToolTip,
String strImage,
String strEnabledImage,
String strDisabledImage,
boolean bEnabled,
ImageRegistry imageRegistry)
{
ImageDescriptor imageDescriptor;
setText(strText);
setToolTipText(strToolTip);
setEnabled(bEnabled);
imageDescriptor = imageRegistry.getDescriptor(strEnabledImage);
if (imageDescriptor != null)
{
setImageDescriptor(imageDescriptor);
}
imageDescriptor = imageRegistry.getDescriptor(strDisabledImage);
if (imageDescriptor != null)
{
setDisabledImageDescriptor(imageDescriptor);
}
imageDescriptor = imageRegistry.getDescriptor(strImage);
if (imageDescriptor != null)
{
setHoverImageDescriptor(imageDescriptor);
}
}
}

View file

@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public class TerminalActionClearAll extends TerminalAction
{
protected TerminalActionClearAll(TerminalTarget target)
{
super(target,
ON_EDIT_CLEARALL,
TerminalActionClearAll.class.getName());
setupAction(TERMINAL_TEXT_CLEARALL,
TERMINAL_TEXT_CLEARALL,
null,
null,
null,
false);
}
}

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public class TerminalActionConnect extends TerminalAction
{
protected TerminalActionConnect(TerminalTarget target)
{
super(target,
ON_TERMINAL_CONNECT,
TerminalActionConnect.class.getName());
setupAction(TERMINAL_TEXT_CONNECT,
TERMINAL_TEXT_CONNECT,
TERMINAL_IMAGE_CLCL_CONNECT,
TERMINAL_IMAGE_ELCL_CONNECT,
TERMINAL_IMAGE_DLCL_CONNECT,
true);
}
}

View file

@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.internal.WorkbenchImages;
public class TerminalActionCopy extends TerminalAction
{
protected TerminalActionCopy(TerminalTarget target)
{
super(target,
ON_EDIT_COPY,
TerminalActionCopy.class.getName());
ImageRegistry imageRegistry;
imageRegistry = WorkbenchImages.getImageRegistry();
setupAction(TERMINAL_TEXT_COPY,
TERMINAL_TEXT_COPY,
ISharedImages.IMG_TOOL_COPY,
ISharedImages.IMG_TOOL_COPY,
ISharedImages.IMG_TOOL_COPY_DISABLED,
true,
imageRegistry);
}
}

View file

@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.internal.WorkbenchImages;
public class TerminalActionCut extends TerminalAction
{
protected TerminalActionCut(TerminalTarget target)
{
super(target,
ON_EDIT_CUT,
TerminalActionCut.class.getName());
ImageRegistry imageRegistry;
imageRegistry = WorkbenchImages.getImageRegistry();
setupAction(TERMINAL_TEXT_CUT,
TERMINAL_TEXT_CUT,
ISharedImages.IMG_TOOL_CUT,
ISharedImages.IMG_TOOL_CUT,
ISharedImages.IMG_TOOL_CUT_DISABLED,
true,
imageRegistry);
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public class TerminalActionDisconnect extends TerminalAction
{
/**
*
*/
protected TerminalActionDisconnect(TerminalTarget target)
{
super(target,
ON_TERMINAL_DISCONNECT,
TerminalActionDisconnect.class.getName());
setupAction(TERMINAL_TEXT_DISCONNECT,
TERMINAL_TEXT_DISCONNECT,
TERMINAL_IMAGE_CLCL_DISCONNECT,
TERMINAL_IMAGE_ELCL_DISCONNECT,
TERMINAL_IMAGE_DLCL_DISCONNECT,
false);
}
}

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
/**
* UNDER CONSTRUCTION
*
* @author Fran Litterio <francis.litterio@windriver.com>
*/
public class TerminalActionNewTerminal extends TerminalAction
{
/**
* UNDER CONSTRUCTION
*/
protected TerminalActionNewTerminal(TerminalTarget target)
{
super(target, ON_TERMINAL_NEW_TERMINAL, TerminalActionNewTerminal.class.getName());
setupAction(TERMINAL_TEXT_NEW_TERMINAL,
TERMINAL_TEXT_NEW_TERMINAL,
TERMINAL_IMAGE_NEW_TERMINAL,
TERMINAL_IMAGE_NEW_TERMINAL,
TERMINAL_IMAGE_NEW_TERMINAL,
true);
}
}

View file

@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.internal.WorkbenchImages;
public class TerminalActionPaste extends TerminalAction
{
protected TerminalActionPaste(TerminalTarget target)
{
super(target,
ON_EDIT_PASTE,
TerminalActionPaste.class.getName());
ImageRegistry imageRegistry;
imageRegistry = WorkbenchImages.getImageRegistry();
setupAction(TERMINAL_TEXT_PASTE,
TERMINAL_TEXT_PASTE,
ISharedImages.IMG_TOOL_PASTE,
ISharedImages.IMG_TOOL_PASTE_DISABLED,
ISharedImages.IMG_TOOL_PASTE,
false,
imageRegistry);
}
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public class TerminalActionSelectAll extends TerminalAction
{
protected TerminalActionSelectAll(TerminalTarget target)
{
super(target,
ON_EDIT_SELECTALL,
TerminalActionSelectAll.class.getName());
setupAction(TERMINAL_TEXT_SELECTALL,
TERMINAL_TEXT_SELECTALL,
null,
null,
null,
false);
}
}

View file

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public class TerminalActionSettings extends TerminalAction
{
protected TerminalActionSettings(TerminalTarget target)
{
super(target,
ON_TERMINAL_SETTINGS,
TerminalActionSettings.class.getName());
setupAction(TERMINAL_TEXT_SETTINGS_ELLIPSE,
TERMINAL_TEXT_SETTINGS,
TERMINAL_IMAGE_CLCL_SETTINGS,
TERMINAL_IMAGE_ELCL_SETTINGS,
TERMINAL_IMAGE_DLCL_SETTINGS,
true);
}
}

View file

@ -0,0 +1,114 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public interface TerminalConsts
{
public static final String TERMINAL_CONNTYPE_SERIAL = "Serial"; //$NON-NLS-1$
public static final String TERMINAL_CONNTYPE_NETWORK = "Network"; //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_ROOT = "icons/"; //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_CTOOL = "ctool16/"; // basic colors - size 16x16 //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_LOCALTOOL = "clcl16/"; // basic colors - size 16x16 //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_DLCL = "dlcl16/"; // disabled - size 16x16 //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_ELCL = "elcl16/"; // enabled - size 16x16 //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_OBJECT = "obj16/"; // basic colors - size 16x16 //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_WIZBAN = "wizban/"; // basic colors - size 16x16 //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_OVR = "ovr16/"; // basic colors - size 7x8 //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_VIEW = "cview16/"; // views //$NON-NLS-1$
public final static String TERMINAL_IMAGE_DIR_EVIEW = "eview16/"; // views //$NON-NLS-1$
public static final String TERMINAL_IMAGE_NEW_TERMINAL = "TerminalViewNewTerminal"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_CLCL_CONNECT = "ImageClclConnect"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_CLCL_DISCONNECT = "ImageClclDisconnect"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_CLCL_SETTINGS = "ImageClclSettings"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_DLCL_CONNECT = "ImageDlclConnect"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_DLCL_DISCONNECT = "ImageDlclDisconnect"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_DLCL_SETTINGS = "ImageDlclSettings"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_ELCL_CONNECT = "ImageElclConnect"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_ELCL_DISCONNECT = "ImageElclDisconnect"; //$NON-NLS-1$
public static final String TERMINAL_IMAGE_ELCL_SETTINGS = "ImageElclSettings"; //$NON-NLS-1$
public static final String TERMINAL_PROP_TITLE = Messages.getString("TerminalConsts.Terminal_7"); //$NON-NLS-1$
public static final String TERMINAL_PROP_NAMENET = "net"; //$NON-NLS-1$
public static final String TERMINAL_PROP_NAMETGTCONST = "tgtcons"; //$NON-NLS-1$
public static final String TERMINAL_PROP_NAMETELNET = "telnet"; //$NON-NLS-1$
public static final String TERMINAL_PROP_VALUENET = "1233"; //$NON-NLS-1$
public static final String TERMINAL_PROP_VALUETGTCONST = "1232"; //$NON-NLS-1$
public static final String TERMINAL_PROP_VALUETELNET = "23"; //$NON-NLS-1$
public static final String TERMINAL_PREF_LIMITOUTPUT = "TerminalPrefLimitOutput"; //$NON-NLS-1$
public static final String TERMINAL_PREF_BUFFERLINES = "TerminalPrefBufferLines"; //$NON-NLS-1$
public static final String TERMINAL_PREF_TIMEOUT_SERIAL = "TerminalPrefTimeoutSerial"; //$NON-NLS-1$
public static final String TERMINAL_PREF_TIMEOUT_NETWORK = "TerminalPrefTimeoutNetwork"; //$NON-NLS-1$
public static final String PLUGIN_HOME = "org.eclipse.tm.terminal"; //$NON-NLS-1$
public static final String HELP_VIEW = PLUGIN_HOME + ".terminal_view"; //$NON-NLS-1$
public static final String TERMINAL_TEXT_NEW_TERMINAL = Messages.getString("TerminalConsts.New_terminal"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_CONNECT = Messages.getString("TerminalConsts.Connect_2"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_DISCONNECT = Messages.getString("TerminalConsts.Disconnect_3"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_SETTINGS_ELLIPSE = Messages.getString("TerminalConsts.Settings..._4"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_COPY = Messages.getString("TerminalConsts.Copy_5"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_CUT = Messages.getString("TerminalConsts.0"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_PASTE = Messages.getString("TerminalConsts.Paste_6"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_SELECTALL = Messages.getString("TerminalConsts.Select_All_7"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_CLEARALL = Messages.getString("TerminalConsts.Clear_All_8"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_TERMINALSETTINGS = Messages.getString("TerminalConsts.Terminal_Settings_1"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_CONNECTIONTYPE = Messages.getString("TerminalConsts.Connection_Type_2"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_SETTINGS = Messages.getString("TerminalConsts.Settings_3"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_PORT = Messages.getString("TerminalConsts.Port_4"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_BAUDRATE = Messages.getString("TerminalConsts.Baud_Rate_5"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_DATABITS = Messages.getString("TerminalConsts.Data_Bits_6"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_STOPBITS = Messages.getString("TerminalConsts.Stop_Bits_7"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_PARITY = Messages.getString("TerminalConsts.Parity_8"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_FLOWCONTROL = Messages.getString("TerminalConsts.1"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_HOST = Messages.getString("TerminalConsts.Host_11"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_LIMITOUTPUT = Messages.getString("TerminalConsts.Limit_terminal_output_16"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_BUFFERLINES = Messages.getString("TerminalConsts.Terminal_buffer_lines__17"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_SERIALTIMEOUT = Messages.getString("TerminalConsts.Serial_timeout_(seconds)__18"); //$NON-NLS-1$
public static final String TERMINAL_TEXT_NETWORKTIMEOUT = Messages.getString("TerminalConsts.Network_timeout_(seconds)__19"); //$NON-NLS-1$
public static final String TERMINAL_MSG_ERROR_1 = Messages.getString("TerminalConsts.Terminal_Error_12"); //$NON-NLS-1$
public static final String TERMINAL_MSG_ERROR_2 = Messages.getString("TerminalConsts.Socket_Error_13"); //$NON-NLS-1$
public static final String TERMINAL_MSG_ERROR_3 = Messages.getString("TerminalConsts.IO_Error_14"); //$NON-NLS-1$
public static final String TERMINAL_MSG_ERROR_4 = Messages.getString("TerminalConsts.Serial_port___{0}___is_currently_in_use_!_nDo_you_want_to_close_the_port__15"); //$NON-NLS-1$
public static final String TERMINAL_MSG_ERROR_5 = Messages.getString("TerminalConsts.Error_16"); //$NON-NLS-1$
public static final String TERMINAL_MSG_ERROR_6 = Messages.getString("TerminalConsts.Emulator_is_not_supported._17"); //$NON-NLS-1$
public static final String TERMINAL_FONT_DEFINITION = "terminal.views.view.font.definition"; //$NON-NLS-1$
public static final String TERMINAL_TRACE_DEBUG_LOG = "org.eclipse.tm.terminal/debug/log"; //$NON-NLS-1$
public static final String TERMINAL_TRACE_DEBUG_LOG_ERROR = "org.eclipse.tm.terminal/debug/log/error"; //$NON-NLS-1$
public static final String TERMINAL_TRACE_DEBUG_LOG_INFO = "org.eclipse.tm.terminal/debug/log/info"; //$NON-NLS-1$
public static final String TERMINAL_TRACE_DEBUG_LOG_CHAR = "org.eclipse.tm.terminal/debug/log/char"; //$NON-NLS-1$
public static final String TERMINAL_TRACE_DEBUG_LOG_BUFFER_SIZE = "org.eclipse.tm.terminal/debug/log/buffer/size"; //$NON-NLS-1$
public static final boolean TERMINAL_DEFAULT_LIMITOUTPUT = true;
public static final int TERMINAL_DEFAULT_BUFFERLINES = 1000;
public static final int TERMINAL_DEFAULT_TIMEOUT_SERIAL = 5;
public static final int TERMINAL_DEFAULT_TIMEOUT_NETWORK = 5;
public static final int TERMINAL_ID_OK = 0;
public static final int TERMINAL_ID_CANCEL = 1;
public static final int TERMINAL_ID_CONNECT = 2;
public static final int TERMINAL_KEY_ESCAPE = 27;
public static final int TERMINAL_KEY_H = 104;
public static final int TERMINAL_KEY_J = 106;
public static final int TERMINAL_KEY_K = 107;
public static final int TERMINAL_KEY_L = 108;
public static final int TERMINAL_KEY_CR = 13;
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public interface TerminalMsg
{
public static final String ON_TERMINAL_FOCUS = "OnTerminalFocus"; //$NON-NLS-1$
public static final String ON_TERMINAL_NEW_TERMINAL = "OnTerminalNew"; //$NON-NLS-1$
public static final String ON_TERMINAL_CONNECT = "OnTerminalConnect"; //$NON-NLS-1$
public static final String ON_TERMINAL_CONNECTING = "OnTerminalConnecting"; //$NON-NLS-1$
public static final String ON_TERMINAL_DISCONNECT = "OnTerminalDisconnect"; //$NON-NLS-1$
public static final String ON_TERMINAL_SETTINGS = "OnTerminalSettings"; //$NON-NLS-1$
public static final String ON_TERMINAL_STATUS = "OnTerminalStatus"; //$NON-NLS-1$
public static final String ON_TERMINAL_DATAAVAILABLE = "OnTerminalDataAvailable"; //$NON-NLS-1$
public static final String ON_TERMINAL_FONTCHANGED = "OnTerminalFontChanged"; //$NON-NLS-1$
public static final String ON_EDIT_COPY = "OnEditCopy"; //$NON-NLS-1$
public static final String ON_EDIT_CUT = "OnEditCut"; //$NON-NLS-1$
public static final String ON_EDIT_PASTE = "OnEditPaste"; //$NON-NLS-1$
public static final String ON_EDIT_CLEARALL = "OnEditClearAll"; //$NON-NLS-1$
public static final String ON_EDIT_SELECTALL = "OnEditSelectAll"; //$NON-NLS-1$
public static final String ON_UPDATE_TERMINAL_CONNECT = "OnUpdateTerminalConnect"; //$NON-NLS-1$
public static final String ON_UPDATE_TERMINAL_DISCONNECT = "OnUpdateTerminalDisconnect"; //$NON-NLS-1$
public static final String ON_UPDATE_TERMINAL_SETTINGS = "OnUpdateTerminalSettings"; //$NON-NLS-1$
public static final String ON_UPDATE_EDIT_COPY = "OnUpdateEditCopy"; //$NON-NLS-1$
public static final String ON_UPDATE_EDIT_CUT = "OnUpdateEditCut"; //$NON-NLS-1$
public static final String ON_UPDATE_EDIT_PASTE = "OnUpdateEditPaste"; //$NON-NLS-1$
public static final String ON_UPDATE_EDIT_CLEARALL = "OnUpdateEditClearAll"; //$NON-NLS-1$
public static final String ON_UPDATE_EDIT_SELECTALL = "OnUpdateEditSelectAll"; //$NON-NLS-1$
public static final String ON_CONNTYPE_SELECTED = "OnConnTypeSelected"; //$NON-NLS-1$
public static final String ON_LIMITOUTPUT_SELECTED = "OnLimitOutputSelected"; //$NON-NLS-1$
public static final String ON_OK = "OnOK"; //$NON-NLS-1$
public static final String ON_CANCEL = "OnCancel"; //$NON-NLS-1$
public static final String ON_HELP = "OnHelp"; //$NON-NLS-1$
}

View file

@ -0,0 +1,104 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import java.util.Vector;
public class TerminalNetworkPortMap extends HashMap
implements TerminalConsts
{
static final long serialVersionUID = 0;
public TerminalNetworkPortMap()
{
super();
setupMap();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Operations
//
/**
*
*/
public String getDefaultNetworkPort()
{
return (String) get(TERMINAL_PROP_NAMETELNET);
}
/**
*
*/
public String findPortName(String strPort)
{
Collection values;
Vector portTable;
Vector nameTable;
String strPortName;
int nIndex;
values = values();
portTable = new Vector(values);
nIndex = portTable.indexOf(strPort);
nameTable = getNameTable();
if (nIndex == -1)
return strPort;
strPortName = (String) nameTable.get(nIndex);
return strPortName;
}
/**
*
*/
public String findPort(String strPortName)
{
String strPort;
strPort = (String) get(strPortName);
if (strPort == null)
return strPortName;
return strPort;
}
/**
*
*/
public Vector getNameTable()
{
Set keySet;
Vector nameTable;
keySet = keySet();
nameTable = new Vector(keySet);
return nameTable;
}
/**
*
*/
protected void setupMap()
{
put(TERMINAL_PROP_NAMETGTCONST, TERMINAL_PROP_VALUETGTCONST);
put(TERMINAL_PROP_NAMETELNET, TERMINAL_PROP_VALUETELNET);
}
}

View file

@ -0,0 +1,294 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
public class TerminalPlugin extends AbstractUIPlugin
implements TerminalConsts
{
protected static TerminalPlugin m_Default;
protected TerminalProperties m_Properties;
protected ResourceBundle m_ResourceBundle;
/**
* The constructor.
*/
public TerminalPlugin()
{
super();
m_Default = this;
setupPlugin();
}
public void start(BundleContext context) throws Exception
{
super.start(context);
}
public void stop(BundleContext context) throws Exception
{
super.stop(context);
}
// AbstractUIPlugin interface
/**
*
*/
protected void initializeImageRegistry(ImageRegistry imageRegistry)
{
HashMap map;
map = new HashMap();
try
{
// Local toolbars
map.put(TERMINAL_IMAGE_NEW_TERMINAL, "newterminal.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_CLCL_CONNECT, "connect_co.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_CLCL_DISCONNECT, "disconnect_co.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_CLCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$
loadImageRegistry(imageRegistry, TERMINAL_IMAGE_DIR_LOCALTOOL, map);
map.clear();
// Enabled local toolbars
map.put(TERMINAL_IMAGE_NEW_TERMINAL, "newterminal.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_ELCL_CONNECT, "connect_co.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_ELCL_DISCONNECT, "disconnect_co.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_ELCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$
loadImageRegistry(imageRegistry, TERMINAL_IMAGE_DIR_ELCL, map);
map.clear();
// Disabled local toolbars
map.put(TERMINAL_IMAGE_NEW_TERMINAL, "newterminal.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_DLCL_CONNECT, "connect_co.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_DLCL_DISCONNECT, "disconnect_co.gif"); //$NON-NLS-1$
map.put(TERMINAL_IMAGE_DLCL_SETTINGS, "properties_tsk.gif"); //$NON-NLS-1$
loadImageRegistry(imageRegistry, TERMINAL_IMAGE_DIR_DLCL, map);
map.clear();
}
catch(MalformedURLException malformedURLException)
{
malformedURLException.printStackTrace();
}
}
/**
*
*/
protected void initializeDefaultPreferences(IPreferenceStore store)
{
store.setDefault(TERMINAL_PREF_LIMITOUTPUT, TERMINAL_DEFAULT_LIMITOUTPUT);
store.setDefault(TERMINAL_PREF_BUFFERLINES, TERMINAL_DEFAULT_BUFFERLINES);
store.setDefault(TERMINAL_PREF_TIMEOUT_SERIAL, TERMINAL_DEFAULT_TIMEOUT_SERIAL);
store.setDefault(TERMINAL_PREF_TIMEOUT_NETWORK, TERMINAL_DEFAULT_TIMEOUT_NETWORK);
}
// Operations
/**
* Returns the shared instance.
*/
public static TerminalPlugin getDefault()
{
return m_Default;
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace()
{
return ResourcesPlugin.getWorkspace();
}
/**
* Returns the string from the plugin's resource bundle, or 'key' if not found.
*/
public static String getResourceString(String strKey)
{
ResourceBundle resourceBundle;
resourceBundle = m_Default.getResourceBundle();
try
{
return resourceBundle.getString(strKey);
}
catch(MissingResourceException missingResourceException)
{
return strKey;
}
}
/**
*
*/
public static boolean isLogInfoEnabled()
{
return isOptionEnabled(TERMINAL_TRACE_DEBUG_LOG_INFO);
}
/**
*
*/
public static boolean isLogErrorEnabled()
{
return isOptionEnabled(TERMINAL_TRACE_DEBUG_LOG_ERROR);
}
/**
*
*/
public static boolean isLogEnabled()
{
return isOptionEnabled(TERMINAL_TRACE_DEBUG_LOG);
}
/**
*
*/
public static boolean isOptionEnabled(String strOption)
{
String strEnabled;
Boolean boolEnabled;
boolean bEnabled;
strEnabled = Platform.getDebugOption(strOption);
if (strEnabled == null)
return false;
boolEnabled = new Boolean(strEnabled);
bEnabled = boolEnabled.booleanValue();
return bEnabled;
}
/**
*
*/
public TerminalProperties getTerminalProperties()
{
return m_Properties;
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle()
{
return m_ResourceBundle;
}
/**
*
*/
protected void loadImageRegistry(ImageRegistry imageRegistry,
String strDir,
HashMap map)
throws MalformedURLException
{
URL url;
ImageDescriptor imageDescriptor;
Iterator keys;
String strKey;
String strFile;
keys = map.keySet().iterator();
while(keys.hasNext())
{
strKey = (String) keys.next();
strFile = (String) map.get(strKey);
if (strFile != null)
{
url = TerminalPlugin.getDefault().getBundle().getEntry(TERMINAL_IMAGE_DIR_ROOT + strDir + strFile);
imageDescriptor = ImageDescriptor.createFromURL(url);
imageRegistry.put(strKey,imageDescriptor);
}
}
}
/**
*
*/
protected void setupPlugin()
{
setupData();
setupLog();
setupResources();
}
/**
*
*/
protected void setupData()
{
m_Properties = new TerminalProperties();
}
/**
*
*/
protected void setupLog()
{
}
/**
*
*/
protected void setupResources()
{
Package pkg;
String strPkg;
String strBundle;
pkg = TerminalPlugin.class.getPackage();
strPkg = pkg.getName();
strBundle = strPkg + ".PluginResources"; //$NON-NLS-1$
try
{
m_ResourceBundle = ResourceBundle.getBundle(strBundle);
}
catch(MissingResourceException missingResourceException)
{
m_ResourceBundle = null;
}
}
}

View file

@ -0,0 +1,265 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
public class TerminalPreferencePage extends FieldEditorPreferencePage
implements IWorkbenchPreferencePage,
TerminalTarget,
TerminalConsts
{
/**
*
*/
protected TerminalBooleanFieldEditor m_editorLimitOutput;
protected IntegerFieldEditor m_editorBufferSize;
protected IntegerFieldEditor m_editorSerialTimeout;
protected IntegerFieldEditor m_editorNetworkTimeout;
/**
*
*/
public TerminalPreferencePage()
{
super(GRID);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TerminalTarget interface
//
/**
*
*/
public void execute(String strMsg,Object data)
{
if (strMsg.equals(ON_LIMITOUTPUT_SELECTED))
{
onLimitOutputSelected(data);
}
else
{
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Message handlers
//
/**
*
*/
protected void onLimitOutputSelected(Object data)
{
Button ctlButton;
Text ctlText;
Label ctlLabel;
boolean bEnabled;
ctlButton = m_editorLimitOutput.getChangeControl(getFieldEditorParent());
ctlText = m_editorBufferSize.getTextControl(getFieldEditorParent());
ctlLabel = m_editorBufferSize.getLabelControl(getFieldEditorParent());
bEnabled = ctlButton.getSelection();
ctlText.setEnabled(bEnabled);
ctlLabel.setEnabled(bEnabled);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FieldEditorPreferencePage interface
//
/**
*
*/
protected void createFieldEditors()
{
setupPage();
}
/**
*
*/
protected void initialize()
{
super.initialize();
execute(ON_LIMITOUTPUT_SELECTED,null);
}
/**
*
*/
protected void performDefaults()
{
super.performDefaults();
execute(ON_LIMITOUTPUT_SELECTED,null);
}
/**
*
*/
public void init(IWorkbench workbench)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Operations
//
/**
*
*/
protected void setupPage()
{
setupData();
setupEditors();
setupListeners();
}
/**
*
*/
protected void setupData()
{
TerminalPlugin plugin;
IPreferenceStore preferenceStore;
plugin = TerminalPlugin.getDefault();
preferenceStore = plugin.getPreferenceStore();
setPreferenceStore(preferenceStore);
}
/**
*
*/
protected void setupEditors()
{
m_editorLimitOutput = new TerminalBooleanFieldEditor(TERMINAL_PREF_LIMITOUTPUT,
TERMINAL_TEXT_LIMITOUTPUT,
getFieldEditorParent());
m_editorBufferSize = new IntegerFieldEditor(TERMINAL_PREF_BUFFERLINES,
TERMINAL_TEXT_BUFFERLINES,
getFieldEditorParent());
m_editorSerialTimeout = new IntegerFieldEditor(TERMINAL_PREF_TIMEOUT_SERIAL,
TERMINAL_TEXT_SERIALTIMEOUT,
getFieldEditorParent());
m_editorNetworkTimeout = new IntegerFieldEditor(TERMINAL_PREF_TIMEOUT_NETWORK,
TERMINAL_TEXT_NETWORKTIMEOUT,
getFieldEditorParent());
m_editorBufferSize.setValidRange(0,Integer.MAX_VALUE);
m_editorSerialTimeout.setValidRange(0,Integer.MAX_VALUE);
m_editorNetworkTimeout.setValidRange(0,Integer.MAX_VALUE);
addField(m_editorLimitOutput);
addField(m_editorBufferSize);
addField(m_editorSerialTimeout);
addField(m_editorNetworkTimeout);
}
/**
*
*/
protected void setupListeners()
{
TerminalSelectionHandler selectionHandler;
Button ctlButton;
selectionHandler = new TerminalSelectionHandler();
ctlButton = m_editorLimitOutput.getChangeControl(getFieldEditorParent());
ctlButton.addSelectionListener(selectionHandler);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Inner classes
//
/**
*
*/
public class TerminalBooleanFieldEditor extends BooleanFieldEditor
{
/**
*
*/
public TerminalBooleanFieldEditor(String strName,
String strLabel,
Composite ctlParent)
{
super(strName,strLabel,ctlParent);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// BooleanFieldEditor interface
//
/**
*
*/
public Button getChangeControl(Composite parent)
{
return super.getChangeControl(parent);
}
}
/**
*
*/
protected class TerminalSelectionHandler extends SelectionAdapter
{
/**
*
*/
protected TerminalSelectionHandler()
{
super();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SelectionAdapter interface
//
/**
*
*/
public void widgetSelected(SelectionEvent event)
{
Object source;
Button ctlButton;
source = event.getSource();
ctlButton = m_editorLimitOutput.getChangeControl(getFieldEditorParent());
if (source == ctlButton)
{
execute(ON_LIMITOUTPUT_SELECTED,null);
}
}
}
}

View file

@ -0,0 +1,278 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
import javax.comm.CommPortIdentifier;
public class TerminalProperties implements TerminalConsts
{
protected TerminalNetworkPortMap m_NetworkPortMap;
protected Vector m_ConnTypeTable;
protected Vector m_SerialPortTable;
protected Vector m_BaudRateTable;
protected Vector m_DataBitsTable;
protected Vector m_StopBitsTable;
protected Vector m_ParityTable;
protected Vector m_FlowControlTable;
protected String m_strDefaultConnType;
protected String m_strDefaultSerialPort;
protected String m_strDefaultBaudRate;
protected String m_strDefaultDataBits;
protected String m_strDefaultStopBits;
protected String m_strDefaultParity;
protected String m_strDefaultFlowControl;
protected String m_strDefaultHost;
protected String m_strDefaultNetworkPort;
/**
*
*/
public TerminalProperties()
{
super();
setupProperties();
}
////////////////////////////////////////////////////////////////////////////
// Operations
//
/**
*
*/
public Vector getConnTypeTable()
{
return m_ConnTypeTable;
}
/**
*
*/
public Vector getSerialPortTable()
{
return m_SerialPortTable;
}
/**
*
*/
public Vector getBaudRateTable()
{
return m_BaudRateTable;
}
/**
*
*/
public Vector getDataBitsTable()
{
return m_DataBitsTable;
}
/**
*
*/
public Vector getStopBitsTable()
{
return m_StopBitsTable;
}
/**
*
*/
public Vector getParityTable()
{
return m_ParityTable;
}
/**
*
*/
public Vector getFlowControlTable()
{
return m_FlowControlTable;
}
/**
*
*/
public TerminalNetworkPortMap getNetworkPortMap()
{
return m_NetworkPortMap;
}
/**
*
*/
public String getDefaultConnType()
{
return m_strDefaultConnType;
}
/**
*
*/
public String getDefaultSerialPort()
{
return m_strDefaultSerialPort;
}
/**
*
*/
public String getDefaultBaudRate()
{
return m_strDefaultBaudRate;
}
/**
*
*/
public String getDefaultDataBits()
{
return m_strDefaultDataBits;
}
/**
*
*/
public String getDefaultStopBits()
{
return m_strDefaultStopBits;
}
/**
*
*/
public String getDefaultParity()
{
return m_strDefaultParity;
}
/**
*
*/
public String getDefaultFlowControl()
{
return m_strDefaultFlowControl;
}
/**
*
*/
public String getDefaultHost()
{
return m_strDefaultHost;
}
/**
*
*/
public String getDefaultNetworkPort()
{
return m_strDefaultNetworkPort;
}
/**
*
*/
protected void setupProperties()
{
Enumeration portIdEnum;
CommPortIdentifier identifier;
String strName;
int nPortType;
portIdEnum = CommPortIdentifier.getPortIdentifiers();
m_NetworkPortMap = new TerminalNetworkPortMap();
m_ConnTypeTable = new Vector();
m_SerialPortTable = new Vector();
m_BaudRateTable = new Vector();
m_DataBitsTable = new Vector();
m_StopBitsTable = new Vector();
m_ParityTable = new Vector();
m_FlowControlTable = new Vector();
m_strDefaultConnType = ""; //$NON-NLS-1$
m_strDefaultSerialPort = ""; //$NON-NLS-1$
m_strDefaultBaudRate = ""; //$NON-NLS-1$
m_strDefaultDataBits = ""; //$NON-NLS-1$
m_strDefaultStopBits = ""; //$NON-NLS-1$
m_strDefaultParity = ""; //$NON-NLS-1$
m_strDefaultFlowControl = ""; //$NON-NLS-1$
m_strDefaultHost = ""; //$NON-NLS-1$
m_strDefaultNetworkPort = ""; //$NON-NLS-1$
m_ConnTypeTable.add(TERMINAL_CONNTYPE_SERIAL);
m_ConnTypeTable.add(TERMINAL_CONNTYPE_NETWORK);
m_BaudRateTable.add("300"); //$NON-NLS-1$
m_BaudRateTable.add("1200"); //$NON-NLS-1$
m_BaudRateTable.add("2400"); //$NON-NLS-1$
m_BaudRateTable.add("4800"); //$NON-NLS-1$
m_BaudRateTable.add("9600"); //$NON-NLS-1$
m_BaudRateTable.add("19200"); //$NON-NLS-1$
m_BaudRateTable.add("38400"); //$NON-NLS-1$
m_BaudRateTable.add("57600"); //$NON-NLS-1$
m_BaudRateTable.add("115200"); //$NON-NLS-1$
m_DataBitsTable.add("5"); //$NON-NLS-1$
m_DataBitsTable.add("6"); //$NON-NLS-1$
m_DataBitsTable.add("7"); //$NON-NLS-1$
m_DataBitsTable.add("8"); //$NON-NLS-1$
m_StopBitsTable.add("1"); //$NON-NLS-1$
m_StopBitsTable.add("1_5"); //$NON-NLS-1$
m_StopBitsTable.add("2"); //$NON-NLS-1$
m_ParityTable.add("None"); //$NON-NLS-1$
m_ParityTable.add("Even"); //$NON-NLS-1$
m_ParityTable.add("Odd"); //$NON-NLS-1$
m_ParityTable.add("Mark"); //$NON-NLS-1$
m_ParityTable.add("Space"); //$NON-NLS-1$
m_FlowControlTable.add("None"); //$NON-NLS-1$
m_FlowControlTable.add("RTS/CTS"); //$NON-NLS-1$
m_FlowControlTable.add("Xon/Xoff"); //$NON-NLS-1$
m_strDefaultNetworkPort = m_NetworkPortMap.getDefaultNetworkPort();
m_strDefaultConnType = (String) m_ConnTypeTable.get(0);
m_strDefaultBaudRate = (String) m_BaudRateTable.get(4);
m_strDefaultDataBits = (String) m_DataBitsTable.get(3);
m_strDefaultStopBits = (String) m_StopBitsTable.get(0);
m_strDefaultParity = (String) m_ParityTable.get(0);
m_strDefaultFlowControl = (String) m_FlowControlTable.get(0);
m_strDefaultHost = ""; //$NON-NLS-1$
while(portIdEnum.hasMoreElements())
{
identifier = (CommPortIdentifier)portIdEnum.nextElement();
strName = identifier.getName();
nPortType = identifier.getPortType();
if (nPortType == CommPortIdentifier.PORT_SERIAL)
m_SerialPortTable.addElement(strName);
}
Collections.sort(m_SerialPortTable);
if (!m_SerialPortTable.isEmpty())
{
m_strDefaultSerialPort = (String) m_SerialPortTable.get(0);
}
}
}

View file

@ -0,0 +1,425 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import javax.comm.SerialPort;
import org.eclipse.jface.dialogs.IDialogSettings;
public class TerminalSettings
implements TerminalConsts
{
protected String m_strConnType;
protected String m_strSerialPort;
protected String m_strBaudRate;
protected String m_strDataBits;
protected String m_strStopBits;
protected String m_strParity;
protected String m_strFlowControl;
protected String m_strHost;
protected String m_strNetworkPort;
/**
*
*/
public TerminalSettings(String terminalPartName)
{
importSettings(terminalPartName);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Operations
//
/**
*
*/
public String getConnType()
{
return m_strConnType;
}
/**
*
*/
public void setConnType(String strConnType)
{
m_strConnType = strConnType;
}
/**
*
*/
public String getSerialPort()
{
return m_strSerialPort;
}
/**
*
*/
public void setSerialPort(String strSerialPort)
{
m_strSerialPort = strSerialPort;
}
/**
*
*/
public String getBaudRate()
{
return m_strBaudRate;
}
/**
*
*/
public int getBaudRateValue()
{
int nBaudRate;
try
{
nBaudRate = Integer.parseInt(m_strBaudRate);
}
catch(NumberFormatException numberFormatException)
{
nBaudRate = 9600;
}
return nBaudRate;
}
/**
*
*/
public void setBaudRate(String strBaudRate)
{
m_strBaudRate = strBaudRate;
}
/**
*
*/
public String getDataBits()
{
return m_strDataBits;
}
/**
*
*/
public int getDataBitsValue()
{
if (m_strDataBits.equals("5")) //$NON-NLS-1$
{
return SerialPort.DATABITS_5;
}
else if (m_strDataBits.equals("6")) //$NON-NLS-1$
{
return SerialPort.DATABITS_6;
}
else if (m_strDataBits.equals("7")) //$NON-NLS-1$
{
return SerialPort.DATABITS_7;
}
else // 8
{
return SerialPort.DATABITS_8;
}
}
/**
*
*/
public void setDataBits(String strDataBits)
{
m_strDataBits = strDataBits;
}
/**
*
*/
public String getStopBits()
{
return m_strStopBits;
}
/**
*
*/
public int getStopBitsValue()
{
if (m_strStopBits.equals("1_5")) //$NON-NLS-1$
{
return SerialPort.STOPBITS_1_5;
}
else if (m_strStopBits.equals("2")) //$NON-NLS-1$
{
return SerialPort.STOPBITS_2;
}
else // 1
{
return SerialPort.STOPBITS_1;
}
}
/**
*
*/
public void setStopBits(String strStopBits)
{
m_strStopBits = strStopBits;
}
/**
*
*/
public String getParity()
{
return m_strParity;
}
/**
*
*/
public int getParityValue()
{
if (m_strParity.equals("Even")) //$NON-NLS-1$
{
return SerialPort.PARITY_EVEN;
}
else if (m_strParity.equals("Odd")) //$NON-NLS-1$
{
return SerialPort.PARITY_ODD;
}
else if (m_strParity.equals("Mark")) //$NON-NLS-1$
{
return SerialPort.PARITY_MARK;
}
else if (m_strParity.equals("Space")) //$NON-NLS-1$
{
return SerialPort.PARITY_SPACE;
}
else // None
{
return SerialPort.PARITY_NONE;
}
}
/**
*
*/
public void setParity(String strParity)
{
m_strParity = strParity;
}
/**
*
*/
public String getFlowControl()
{
return m_strFlowControl;
}
/**
*
*/
public int getFlowControlValue()
{
if (m_strFlowControl.equals("RTS/CTS")) //$NON-NLS-1$
{
return SerialPort.FLOWCONTROL_RTSCTS_IN;
}
else if (m_strFlowControl.equals("Xon/Xoff")) //$NON-NLS-1$
{
return SerialPort.FLOWCONTROL_XONXOFF_IN;
}
else // None
{
return SerialPort.FLOWCONTROL_NONE;
}
}
/**
*
*/
public void setFlowControl(String strFlow)
{
m_strFlowControl = strFlow;
}
/**
*
*/
public String getHost()
{
return m_strHost;
}
/**
*
*/
public void setHost(String strHost)
{
m_strHost = strHost;
}
/**
*
*/
public String getNetworkPort()
{
return m_strNetworkPort;
}
/**
*
*/
public int getNetworkPortValue()
{
int nNetworkPort;
try
{
nNetworkPort = Integer.parseInt(m_strNetworkPort);
}
catch(NumberFormatException numberFormatException)
{
nNetworkPort = 1313;
}
return nNetworkPort;
}
/**
*
*/
public void setNetworkPort(String strNetworkPort)
{
m_strNetworkPort = strNetworkPort;
}
/**
*
*/
public void importSettings(String terminalPartName)
{
TerminalPlugin plugin;
TerminalProperties properties;
plugin = TerminalPlugin.getDefault();
properties = plugin.getTerminalProperties();
m_strConnType = importSetting(terminalPartName, "ConnType", //$NON-NLS-1$
properties.getDefaultConnType());
m_strSerialPort = importSetting(terminalPartName, "SerialPort", //$NON-NLS-1$
properties.getDefaultSerialPort());
m_strBaudRate = importSetting(terminalPartName, "BaudRate", //$NON-NLS-1$
properties.getDefaultBaudRate());
m_strDataBits = importSetting(terminalPartName, "DataBits", //$NON-NLS-1$
properties.getDefaultDataBits());
m_strStopBits = importSetting(terminalPartName, "StopBits", //$NON-NLS-1$
properties.getDefaultStopBits());
m_strParity = importSetting(terminalPartName, "Parity", //$NON-NLS-1$
properties.getDefaultParity());
m_strFlowControl = importSetting(terminalPartName, "FlowControl", //$NON-NLS-1$
properties.getDefaultFlowControl());
m_strHost = importSetting(terminalPartName, "Host", //$NON-NLS-1$
properties.getDefaultHost());
m_strNetworkPort = importSetting(terminalPartName, "NetworkPort", //$NON-NLS-1$
properties.getDefaultNetworkPort());
}
/**
*
*/
public void exportSettings(String terminalPartName)
{
TerminalPlugin plugin;
TerminalProperties properties;
plugin = TerminalPlugin.getDefault();
properties = plugin.getTerminalProperties();
exportSetting(terminalPartName, "ConnType", m_strConnType, //$NON-NLS-1$
properties.getDefaultConnType());
exportSetting(terminalPartName, "SerialPort", m_strSerialPort, //$NON-NLS-1$
properties.getDefaultSerialPort());
exportSetting(terminalPartName, "BaudRate", m_strBaudRate, //$NON-NLS-1$
properties.getDefaultBaudRate());
exportSetting(terminalPartName, "DataBits", m_strDataBits, //$NON-NLS-1$
properties.getDefaultDataBits());
exportSetting(terminalPartName, "StopBits", m_strStopBits, //$NON-NLS-1$
properties.getDefaultStopBits());
exportSetting(terminalPartName, "Parity", m_strParity, //$NON-NLS-1$
properties.getDefaultParity());
exportSetting(terminalPartName, "FlowControl", m_strFlowControl, //$NON-NLS-1$
properties.getDefaultFlowControl());
exportSetting(terminalPartName, "Host", m_strHost, //$NON-NLS-1$
properties.getDefaultHost());
exportSetting(terminalPartName, "NetworkPort", m_strNetworkPort, //$NON-NLS-1$
properties.getDefaultNetworkPort());
}
/**
*
*/
protected String importSetting(String terminalPartName, String strName, String strDefault)
{
TerminalPlugin plugin;
IDialogSettings settings;
String strPrefix;
String strKey;
String strValue;
plugin = TerminalPlugin.getDefault();
settings = plugin.getDialogSettings();
strPrefix = TerminalSettings.class.getName() + "."; //$NON-NLS-1$
strKey = strPrefix + terminalPartName + "." + strName; //$NON-NLS-1$
strValue = settings.get(strKey);
if ((strValue == null) ||
(strValue.equals(""))) //$NON-NLS-1$
return strDefault;
return strValue;
}
/**
*
*/
protected void exportSetting(String terminalPartName, String strName, String strValue,
String strDefault)
{
TerminalPlugin plugin;
IDialogSettings settings;
String strPrefix;
String strKey;
plugin = TerminalPlugin.getDefault();
settings = plugin.getDialogSettings();
strPrefix = TerminalSettings.class.getName() + "."; //$NON-NLS-1$
strKey = strPrefix + terminalPartName + "." + strName; //$NON-NLS-1$
if ((strValue == null) ||
(strValue.equals(""))) //$NON-NLS-1$
{
settings.put(strKey,strDefault);
}
else
{
settings.put(strKey,strValue);
}
}
}

View file

@ -0,0 +1,911 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;
import javax.comm.CommPortIdentifier;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class TerminalSettingsDlg extends org.eclipse.jface.dialogs.Dialog
implements TerminalTarget,
TerminalConsts
{
protected static final String m_strHelpID = "hid_db_terminal"; //$NON-NLS-1$
protected Combo m_ctlConnTypeCombo;
protected Combo m_ctlSerialPortCombo;
protected Combo m_ctlBaudRateCombo;
protected Combo m_ctlDataBitsCombo;
protected Combo m_ctlStopBitsCombo;
protected Combo m_ctlParityCombo;
protected Combo m_ctlFlowControlCombo;
protected Text m_ctlHostText;
protected Combo m_ctlNetworkPortCombo;
protected Group m_wndSettingsGroup;
protected Composite m_wndSettingsPanel;
protected TerminalSettings m_TerminalSettings;
protected String m_strConnType;
protected int m_nStatus;
/**
*
*/
public TerminalSettingsDlg(Shell wndParent)
{
super(wndParent);
m_nStatus = TERMINAL_ID_CANCEL;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TerminalTarget interface
//
/**
*
*/
public void execute(String strMsg,Object data)
{
if (strMsg.equals(ON_CONNTYPE_SELECTED))
{
onConnTypeSelected(data);
}
else if (strMsg.equals(ON_OK))
{
onOk(data);
}
else if (strMsg.equals(ON_CANCEL))
{
onCancel(data);
}
else if (strMsg.equals(ON_HELP))
{
onHelp(data);
}
else
{
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Message handlers
//
/**
*
*/
protected void onConnTypeSelected(Object data)
{
String strConnType;
strConnType = m_ctlConnTypeCombo.getText();
if (m_strConnType.equals(strConnType))
return;
m_strConnType = strConnType;
if (strConnType.equals(TERMINAL_CONNTYPE_SERIAL))
{
setupSerialPanel();
}
else if (strConnType.equals(TERMINAL_CONNTYPE_NETWORK))
{
setupNetworkPanel();
}
else
{
setupConnTypeNotSupportedPanel();
}
}
/**
*
*/
protected void onOk(Object data)
{
if (!validateSettings())
return;
saveSettings();
m_nStatus = TERMINAL_ID_CONNECT;
}
/**
*
*/
protected void onCancel(Object data)
{
m_nStatus = TERMINAL_ID_CANCEL;
}
/**
*
*/
protected void onHelp(Object data)
{
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Dialog interface
//
/**
*
*/
protected void okPressed()
{
execute(ON_OK,null);
super.okPressed();
}
/**
*
*/
protected void cancelPressed()
{
execute(ON_CANCEL,null);
super.cancelPressed();
}
/**
*
*/
public int open()
{
int nShellStyle;
nShellStyle = getShellStyle();
nShellStyle = nShellStyle|SWT.RESIZE;
setShellStyle(nShellStyle);
return super.open();
}
/**
*
*/
protected void configureShell(Shell newShell)
{
super.configureShell(newShell);
newShell.setText(TERMINAL_TEXT_TERMINALSETTINGS);
}
/**
*
*/
protected Control createDialogArea(Composite parent)
{
Composite ctlComposite;
ctlComposite = (Composite)super.createDialogArea(parent);
createDialog(ctlComposite);
return ctlComposite;
}
/**
*
*/
protected void initializeBounds()
{
setConnType(TERMINAL_CONNTYPE_SERIAL);
execute(ON_CONNTYPE_SELECTED,null);
super.initializeBounds();
setConnType(m_TerminalSettings.getConnType());
execute(ON_CONNTYPE_SELECTED,null);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Operations
//
/**
*
*/
public void loadSettings(TerminalSettings terminalSettings)
{
m_TerminalSettings = terminalSettings;
}
/**
*
*/
public void saveSettings()
{
String strConnType;
strConnType = getConnType();
if (strConnType.equals(TERMINAL_CONNTYPE_SERIAL))
{
m_TerminalSettings.setConnType(getConnType());
m_TerminalSettings.setSerialPort(getSerialPort());
m_TerminalSettings.setBaudRate(getBaudRate());
m_TerminalSettings.setDataBits(getDataBits());
m_TerminalSettings.setStopBits(getStopBits());
m_TerminalSettings.setParity(getParity());
m_TerminalSettings.setFlowControl(getFlowControl());
}
else if (strConnType.equals(TERMINAL_CONNTYPE_NETWORK))
{
m_TerminalSettings.setConnType(getConnType());
m_TerminalSettings.setHost(getHost());
m_TerminalSettings.setNetworkPort(getNetworkPort());
}
}
/**
*
*/
public int getStatus()
{
return m_nStatus;
}
/**
*
*/
protected void setConnType(String strConnType)
{
int nIndex;
nIndex = m_ctlConnTypeCombo.indexOf(strConnType);
if (nIndex == -1)
return;
m_ctlConnTypeCombo.select(nIndex);
}
/**
*
*/
protected void setSerialPort(String strSerialPort)
{
int nIndex;
nIndex = m_ctlSerialPortCombo.indexOf(strSerialPort);
if (nIndex == -1)
return;
m_ctlSerialPortCombo.select(nIndex);
}
/**
*
*/
protected void setBaudRate(String strBaudRate)
{
int nIndex;
nIndex = m_ctlBaudRateCombo.indexOf(strBaudRate);
if (nIndex == -1)
return;
m_ctlBaudRateCombo.select(nIndex);
}
/**
*
*/
protected void setDataBits(String strDataBits)
{
int nIndex;
nIndex = m_ctlDataBitsCombo.indexOf(strDataBits);
if (nIndex == -1)
return;
m_ctlDataBitsCombo.select(nIndex);
}
/**
*
*/
protected void setStopBits(String strStopBits)
{
int nIndex;
nIndex = m_ctlStopBitsCombo.indexOf(strStopBits);
if (nIndex == -1)
return;
m_ctlStopBitsCombo.select(nIndex);
}
/**
*
*/
protected void setParity(String strParity)
{
int nIndex;
nIndex = m_ctlParityCombo.indexOf(strParity);
if (nIndex == -1)
return;
m_ctlParityCombo.select(nIndex);
}
/**
*
*/
protected void setFlowIn(String strFlowIn)
{
int nIndex;
nIndex = m_ctlFlowControlCombo.indexOf(strFlowIn);
if (nIndex == -1)
return;
m_ctlFlowControlCombo.select(nIndex);
}
/**
*
*/
protected void setHost(String strHost)
{
m_ctlHostText.setText(strHost);
}
/**
*
*/
protected void setNetworkPort(String strNetworkPort)
{
TerminalPlugin plugin;
TerminalProperties properties;
TerminalNetworkPortMap networkPortMap;
String strPortName;
int nIndex;
plugin = TerminalPlugin.getDefault();
properties = plugin.getTerminalProperties();
networkPortMap = properties.getNetworkPortMap();
strPortName = networkPortMap.findPortName(strNetworkPort);
nIndex = m_ctlNetworkPortCombo.indexOf(strPortName);
if (nIndex == -1)
{
m_ctlNetworkPortCombo.setText(strNetworkPort);
}
else
{
m_ctlNetworkPortCombo.select(nIndex);
}
}
/**
*
*/
protected String getConnType()
{
int nIndex;
nIndex = m_ctlConnTypeCombo.getSelectionIndex();
if (nIndex == -1)
return ""; //$NON-NLS-1$
return m_ctlConnTypeCombo.getItem(nIndex);
}
/**
*
*/
protected String getSerialPort()
{
int nIndex;
nIndex = m_ctlSerialPortCombo.getSelectionIndex();
if (nIndex == -1)
return ""; //$NON-NLS-1$
return m_ctlSerialPortCombo.getItem(nIndex);
}
/**
*
*/
protected String getBaudRate()
{
int nIndex;
nIndex = m_ctlBaudRateCombo.getSelectionIndex();
if (nIndex == -1)
return ""; //$NON-NLS-1$
return m_ctlBaudRateCombo.getItem(nIndex);
}
/**
*
*/
protected String getDataBits()
{
int nIndex;
nIndex = m_ctlDataBitsCombo.getSelectionIndex();
if (nIndex == -1)
return ""; //$NON-NLS-1$
return m_ctlDataBitsCombo.getItem(nIndex);
}
/**
*
*/
protected String getStopBits()
{
int nIndex;
nIndex = m_ctlStopBitsCombo.getSelectionIndex();
if (nIndex == -1)
return ""; //$NON-NLS-1$
return m_ctlStopBitsCombo.getItem(nIndex);
}
/**
*
*/
protected String getParity()
{
int nIndex;
nIndex = m_ctlParityCombo.getSelectionIndex();
if (nIndex == -1)
return ""; //$NON-NLS-1$
return m_ctlParityCombo.getItem(nIndex);
}
/**
*
*/
protected String getFlowControl()
{
int nIndex;
nIndex = m_ctlFlowControlCombo.getSelectionIndex();
if (nIndex == -1)
return ""; //$NON-NLS-1$
return m_ctlFlowControlCombo.getItem(nIndex);
}
/**
*
*/
protected String getHost()
{
return m_ctlHostText.getText();
}
/**
*
*/
protected String getNetworkPort()
{
TerminalPlugin plugin;
TerminalProperties properties;
TerminalNetworkPortMap networkPortMap;
String strPortName;
String strPort;
plugin = TerminalPlugin.getDefault();
properties = plugin.getTerminalProperties();
networkPortMap = properties.getNetworkPortMap();
strPortName = m_ctlNetworkPortCombo.getText();
strPort = networkPortMap.findPort(strPortName);
return strPort;
}
/**
*
*/
protected boolean validateSettings()
{
return true;
}
/**
*
*/
protected void createDialog(Composite ctlComposite)
{
setupData();
setupPanel(ctlComposite);
setupListeners();
}
/**
*
*/
protected void setupData()
{
m_strConnType = ""; //$NON-NLS-1$
}
/**
*
*/
protected void setupPanel(Composite wndParent)
{
setupConnTypePanel(wndParent);
setupSettingsGroup(wndParent);
}
/**
*
*/
protected void setupConnTypePanel(Composite wndParent)
{
Group wndGroup;
GridLayout gridLayout;
GridData gridData;
wndGroup = new Group(wndParent,SWT.NONE);
gridLayout = new GridLayout(1,true);
gridData = new GridData(GridData.FILL_HORIZONTAL);
wndGroup.setLayout(gridLayout);
wndGroup.setLayoutData(gridData);
wndGroup.setText(TERMINAL_TEXT_CONNECTIONTYPE + ":"); //$NON-NLS-1$
m_ctlConnTypeCombo = new Combo(wndGroup,SWT.DROP_DOWN|SWT.READ_ONLY);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 200;
m_ctlConnTypeCombo.setLayoutData(gridData);
// Load controls
m_ctlConnTypeCombo.add(TERMINAL_CONNTYPE_SERIAL);
m_ctlConnTypeCombo.add(TERMINAL_CONNTYPE_NETWORK);
}
/**
*
*/
protected void setupSettingsGroup(Composite parent)
{
m_wndSettingsGroup = new Group(parent,SWT.NONE);
GridLayout gridLayout = new GridLayout();
GridData gridData = new GridData(GridData.FILL_BOTH);
m_wndSettingsGroup.setText(TERMINAL_TEXT_SETTINGS + ":"); //$NON-NLS-1$
m_wndSettingsGroup.setLayout(gridLayout);
m_wndSettingsGroup.setLayoutData(gridData);
}
/**
*
*/
protected void setupSerialPanel()
{
TerminalPlugin plugin;
TerminalProperties properties;
Label ctlLabel;
GridLayout gridLayout;
GridData gridData;
Vector table;
if (m_wndSettingsPanel != null)
{
m_wndSettingsPanel.setVisible(false);
m_wndSettingsPanel.dispose();
}
plugin = TerminalPlugin.getDefault();
properties = plugin.getTerminalProperties();
m_wndSettingsPanel = new Composite(m_wndSettingsGroup,SWT.NONE);
gridLayout = new GridLayout(2,false);
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_wndSettingsPanel.setLayout(gridLayout);
m_wndSettingsPanel.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_PORT + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlSerialPortCombo = new Combo(m_wndSettingsPanel,SWT.DROP_DOWN|SWT.READ_ONLY);
m_ctlSerialPortCombo.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_BAUDRATE + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlBaudRateCombo = new Combo(m_wndSettingsPanel,SWT.DROP_DOWN|SWT.READ_ONLY);
m_ctlBaudRateCombo.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_DATABITS + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlDataBitsCombo = new Combo(m_wndSettingsPanel,SWT.DROP_DOWN|SWT.READ_ONLY);
m_ctlDataBitsCombo.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_STOPBITS + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlStopBitsCombo = new Combo(m_wndSettingsPanel,SWT.DROP_DOWN|SWT.READ_ONLY);
m_ctlStopBitsCombo.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_PARITY + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlParityCombo = new Combo(m_wndSettingsPanel,SWT.DROP_DOWN|SWT.READ_ONLY);
m_ctlParityCombo.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_FLOWCONTROL + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlFlowControlCombo = new Combo(m_wndSettingsPanel,SWT.DROP_DOWN|SWT.READ_ONLY);
m_ctlFlowControlCombo.setLayoutData(gridData);
// Load controls
table = properties.getSerialPortTable();
loadCombo(m_ctlSerialPortCombo,table);
table = properties.getBaudRateTable();
loadCombo(m_ctlBaudRateCombo,table);
table = properties.getDataBitsTable();
loadCombo(m_ctlDataBitsCombo,table);
table = properties.getStopBitsTable();
loadCombo(m_ctlStopBitsCombo,table);
table = properties.getParityTable();
loadCombo(m_ctlParityCombo,table);
table = properties.getFlowControlTable();
loadCombo(m_ctlFlowControlCombo,table);
setSerialPort(m_TerminalSettings.getSerialPort());
setBaudRate(m_TerminalSettings.getBaudRate());
setDataBits(m_TerminalSettings.getDataBits());
setStopBits(m_TerminalSettings.getStopBits());
setParity(m_TerminalSettings.getParity());
setFlowIn(m_TerminalSettings.getFlowControl());
m_wndSettingsGroup.layout(true);
}
/**
*
*/
protected void setupNetworkPanel()
{
TerminalPlugin plugin;
TerminalProperties properties;
TerminalNetworkPortMap networkPortMap;
Label ctlLabel;
GridLayout gridLayout;
GridData gridData;
Vector table;
if (m_wndSettingsPanel != null)
{
m_wndSettingsPanel.setVisible(false);
m_wndSettingsPanel.dispose();
}
plugin = TerminalPlugin.getDefault();
properties = plugin.getTerminalProperties();
m_wndSettingsPanel = new Composite(m_wndSettingsGroup,SWT.NONE);
gridLayout = new GridLayout(2,false);
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_wndSettingsPanel.setLayout(gridLayout);
m_wndSettingsPanel.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_HOST + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlHostText = new Text(m_wndSettingsPanel,SWT.BORDER);
m_ctlHostText.setLayoutData(gridData);
// Add label
ctlLabel = new Label(m_wndSettingsPanel,SWT.RIGHT);
ctlLabel.setText(TERMINAL_TEXT_PORT + ":"); //$NON-NLS-1$
// Add control
gridData = new GridData(GridData.FILL_HORIZONTAL);
m_ctlNetworkPortCombo = new Combo(m_wndSettingsPanel,SWT.DROP_DOWN);
m_ctlNetworkPortCombo.setLayoutData(gridData);
networkPortMap = properties.getNetworkPortMap();
table = networkPortMap.getNameTable();
Collections.sort(table);
loadCombo(m_ctlNetworkPortCombo,table);
setHost(m_TerminalSettings.getHost());
setNetworkPort(m_TerminalSettings.getNetworkPort());
m_wndSettingsGroup.layout(true);
}
/**
*
*/
protected void setupConnTypeNotSupportedPanel()
{
MessageDialog dlgError;
Shell parentShell;
Image imgTitle;
String labels[];
String strTitle;
String strMessage;
int nImage;
int nIndex;
if (m_wndSettingsPanel != null)
{
m_wndSettingsPanel.setVisible(false);
m_wndSettingsPanel.dispose();
}
m_wndSettingsPanel = new Composite(m_wndSettingsGroup,SWT.NONE);
parentShell = getShell();
strTitle = TERMINAL_MSG_ERROR_5;
imgTitle = null;
strMessage = TERMINAL_MSG_ERROR_6;
nImage = SWT.ICON_ERROR;
labels = new String[]{"OK"}; //$NON-NLS-1$
nIndex = 0;
dlgError = new MessageDialog(parentShell,
strTitle,
imgTitle,
strMessage,
nImage,
labels,
nIndex);
m_wndSettingsGroup.layout(true);
dlgError.open();
}
/**
*
*/
protected void setupListeners()
{
TerminalSettingsSelectionHandler selectionHandler;
selectionHandler = new TerminalSettingsSelectionHandler();
m_ctlConnTypeCombo.addSelectionListener(selectionHandler);
}
/**
*
*/
protected void loadCombo(Combo ctlCombo,Vector table)
{
String strData;
for(int i=0;i<table.size();i++)
{
strData = (String)table.get(i);
ctlCombo.add(strData);
}
}
/**
*
*/
protected Vector getPorts()
{
Enumeration portIdEnum;
Vector ports;
CommPortIdentifier identifier;
String strName;
int nPortType;
portIdEnum = CommPortIdentifier.getPortIdentifiers();
ports = new Vector();
while(portIdEnum.hasMoreElements())
{
identifier = (CommPortIdentifier)portIdEnum.nextElement();
strName = identifier.getName();
nPortType = identifier.getPortType();
if (nPortType == CommPortIdentifier.PORT_SERIAL)
ports.addElement(strName);
}
Collections.sort(ports);
return ports;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Inner classes
//
/**
*
*/
protected class TerminalSettingsSelectionHandler extends SelectionAdapter
{
/**
*
*/
protected TerminalSettingsSelectionHandler()
{
super();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SelectionAdapter interface
//
/**
*
*/
public void widgetSelected(SelectionEvent event)
{
Object source;
source = event.getSource();
if (source == m_ctlConnTypeCombo)
{
execute(ON_CONNTYPE_SELECTED,null);
}
else
{
}
}
}
}

View file

@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems, Inc. - initial implementation
*
*******************************************************************************/
package org.eclipse.tm.terminal;
public interface TerminalTarget
extends TerminalMsg
{
public void execute(String strMsg,Object data);
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff