1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

[178201] Telnet subsystem contribution initial checkin

This commit is contained in:
Martin Oberhuber 2007-05-11 09:49:26 +00:00
parent 22ae382e1c
commit 3dbe7d2781
15 changed files with 830 additions and 0 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1 @@
bin

View file

@ -0,0 +1 @@
org.eclipse.rse.connectorservice.telnet/debug = true

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.rse.connectorservice.telnet</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,70 @@
#Tue Jan 30 22:33:44 CET 2007
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
org.eclipse.jdt.core.compiler.compliance=1.4
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=error
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=public
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=error
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.3

View file

@ -0,0 +1,19 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.rse.connectorservice.telnet;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: org.eclipse.rse.internal.connectorservice.telnet.Activator
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.rse.services.telnet,
org.eclipse.rse.services,
org.eclipse.rse.core,
org.eclipse.rse.ui,
org.eclipse.ui,
org.apache.commons.net
Eclipse-LazyStart: true
Export-Package: org.eclipse.rse.internal.connectorservice.telnet;x-friends:="org.eclipse.rse.subsystems.shells.telnet"
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: J2SE-1.4

View file

@ -0,0 +1,28 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>About</title>
</head>
<body lang="EN-US">
<h2>About This Content</h2>
<p>June 2, 2006</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
</body>
</html>

View file

@ -0,0 +1,16 @@
###############################################################################
# Copyright (c) 2005, 2006 IBM Corporation 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:
# IBM Corporation - initial API and implementation
###############################################################################
bin.includes = .,\
META-INF/,\
about.html,\
plugin.properties
source.. = src/
output.. = bin/

View file

@ -0,0 +1,17 @@
################################################################################
# Copyright (c) 2006, 2007 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:
# Martin Oberhuber - initial API and implementation
# Sheldon D'souza - String modifications
################################################################################
# NLS_MESSAGEFORMAT_NONE
# NLS_ENCODING=UTF-8
pluginName = RSE Telnet Connector Service
providerName = Eclipse.org

View file

@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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:
* Martin Oberhuber (Wind River) - initial API and implementation
* Sheldon D'souza (Celunite) - adapted from connectorservice.ssh/Activator
*******************************************************************************/
package org.eclipse.rse.internal.connectorservice.telnet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.rse.connectorservice.telnet"; //$NON-NLS-1$
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
private static Boolean fTracingOn = null;
public static boolean isTracingOn() {
if (fTracingOn==null) {
String id = plugin.getBundle().getSymbolicName();
String val = Platform.getDebugOption(id + "/debug"); //$NON-NLS-1$
if ("true".equals(val)) { //$NON-NLS-1$
fTracingOn = Boolean.TRUE;
} else {
fTracingOn = Boolean.FALSE;
}
}
return fTracingOn.booleanValue();
}
public static String getTimestamp() {
try {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); //$NON-NLS-1$
return formatter.format(new Date());
} catch (Exception e) {
// If there were problems writing out the date, ignore and
// continue since that shouldn't stop us from logging the rest
// of the information
}
return Long.toString(System.currentTimeMillis());
}
public static void trace(String msg) {
if (isTracingOn()) {
String fullMsg = getTimestamp() + " | " + Thread.currentThread().getName() + " | " + msg; //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(fullMsg);
System.out.flush();
}
}
}

View file

@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Celunite, Inc.
* 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:
* Sheldon D'souza (Celunite) - initial API and implementation
*******************************************************************************/
package org.eclipse.rse.internal.connectorservice.telnet;
/**
* Markup Interface for subsystems using the TelnetConnectorService.
*
* By implementing this interface, subsystems can be recognized
* as being able to share a single telnet connector service between
* multiple different subsystems.
*/
public interface ITelnetSubSystem {
}

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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:
* Martin Oberhuber (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - copy dialogs from team.cvs.ui
* Sheldon D'souza (Celunite) - adapted from SshConnectorResources
*******************************************************************************/
package org.eclipse.rse.internal.connectorservice.telnet;
import org.eclipse.osgi.util.NLS;
public class TelnetConnectorResources extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.rse.internal.connectorservice.telnet.TelnetConnectorResources"; //$NON-NLS-1$
static {
NLS.initializeMessages(BUNDLE_NAME, TelnetConnectorResources.class);
}
private TelnetConnectorResources() {
}
public static String TelnetConnectorService_Name;
public static String TelnetConnectorService_Description;
public static String TelnetConnectorService_ErrorDisconnecting;
}

View file

@ -0,0 +1,20 @@
################################################################################
# Copyright (c) 2006, 2007 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:
# Martin Oberhuber (Wind River) - initial API and implementation
# Martin Oberhuber (Wind River) - copy dialogs from team.cvs.ui
# Sheldon D'souza (Celunite) - adapted from SshConnectorResources.properties
################################################################################
# NLS_MESSAGEFORMAT_VAR
# NLS_ENCODING=UTF-8
TelnetConnectorService_Name=Telnet Connector Service
TelnetConnectorService_Description=Telnet Connector Service Description
TelnetConnectorService_ErrorDisconnecting=ConnectionStatusListener: Error disconnecting

View file

@ -0,0 +1,414 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 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:
* Martin Oberhuber (Wind River) - initial API and implementation
* David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies
* Sheldon D'souza (Celunite) - adapted from SshConnectorService
*******************************************************************************/
package org.eclipse.rse.internal.connectorservice.telnet;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.net.SocketException;
import org.apache.commons.net.telnet.TelnetClient;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.rse.core.SystemBasePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.core.model.SystemSignonInformation;
import org.eclipse.rse.core.subsystems.AbstractConnectorService;
import org.eclipse.rse.core.subsystems.CommunicationsEvent;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.rse.core.subsystems.ICredentialsProvider;
import org.eclipse.rse.core.subsystems.SubSystemConfiguration;
import org.eclipse.rse.internal.services.telnet.ITelnetSessionProvider;
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
import org.eclipse.rse.ui.ISystemMessages;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.messages.SystemMessageDialog;
import org.eclipse.rse.ui.subsystems.StandardCredentialsProvider;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
public class TelnetConnectorService extends AbstractConnectorService implements ITelnetSessionProvider {
private static final int TELNET_DEFAULT_PORT = 23;
private static final int CONNECT_DEFAULT_TIMEOUT = 60; //seconds
private static TelnetClient fTelnetClient = new TelnetClient();
private SessionLostHandler fSessionLostHandler;
private InputStream in;
private PrintStream out;
private static final String PROMPT = "$"; //$NON-NLS-1$
private static final String ARM_PROMT = "#"; //$NON-NLS-1$
private static final boolean arm_flag = true;
private ICredentialsProvider credentialsProvider = null;
public TelnetConnectorService(IHost host) {
super(TelnetConnectorResources.TelnetConnectorService_Name, TelnetConnectorResources.TelnetConnectorService_Description, host, 0);
fSessionLostHandler = null;
}
public static void checkCanceled(IProgressMonitor monitor) {
if (monitor.isCanceled())
throw new OperationCanceledException();
}
protected void internalConnect(IProgressMonitor monitor) throws Exception {
String host = getHostName();
String user = getUserId();
String password = ""; //$NON-NLS-1$
try {
Activator.trace("Telnet Service: Connecting....."); //$NON-NLS-1$
fTelnetClient.connect(host,TELNET_DEFAULT_PORT );
SystemSignonInformation ssi = getPasswordInformation();
if (ssi!=null) {
password = getPasswordInformation().getPassword();
}
in = fTelnetClient.getInputStream();
out = new PrintStream( fTelnetClient.getOutputStream() );
if( !arm_flag ) {
readUntil( "login: "); //$NON-NLS-1$
write( user );
readUntil( "Password: "); //$NON-NLS-1$
write( password );
readUntil( PROMPT );
}else {
readUntil( ARM_PROMT );
}
Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
}catch( SocketException se) {
Activator.trace("Telnet Service failed: "+se.toString()); //$NON-NLS-1$
if (fTelnetClient.isConnected())
fTelnetClient.disconnect();
}catch( IOException ioe ) {
Activator.trace("Telnet Service failed: "+ioe.toString()); //$NON-NLS-1$
if (fTelnetClient.isConnected())
fTelnetClient.disconnect();
}
fSessionLostHandler = new SessionLostHandler( this );
notifyConnection();
}
public String readUntil( String pattern ) {
try {
char lastChar = pattern.charAt( pattern.length() - 1 );
StringBuffer sb = new StringBuffer();
boolean found = false;
char ch = ( char )in.read();
while( true ) {
System.out.print( ch );
sb.append( ch );
if( ch == lastChar ) {
if( sb.toString().endsWith( pattern ) ) {
return sb.toString();
}
}
ch = ( char )in.read();
}
}
catch( Exception e ) {
e.printStackTrace();
}
return null;
}
public void write( String value ) {
try {
out.println( value );
out.flush();
Activator.trace("write: "+value ); //$NON-NLS-1$
}
catch( Exception e ) {
e.printStackTrace();
}
}
protected void internalDisconnect(IProgressMonitor monitor) throws Exception {
Activator.trace("Telnet Service: Disconnecting ....."); //$NON-NLS-1$
boolean sessionLost = (fSessionLostHandler!=null && fSessionLostHandler.isSessionLost());
// no more interested in handling session-lost, since we are disconnecting anyway
fSessionLostHandler = null;
// handle events
if (sessionLost) {
notifyError();
}
else {
// Fire comm event to signal state about to change
fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT);
}
if( fTelnetClient.isConnected() ) {
fTelnetClient.disconnect();
}
// Fire comm event to signal state changed
notifyDisconnection();
}
protected ICredentialsProvider getCredentialsProvider() {
if (credentialsProvider == null) {
credentialsProvider = new StandardCredentialsProvider(this);
}
return credentialsProvider;
}
public TelnetClient getTelnetClient() {
return fTelnetClient;
}
/**
* Handle session-lost events.
* This is generic for any sort of connector service.
* Most of this is extracted from dstore's ConnectionStatusListener.
*
* TODO should be refactored to make it generally available, and allow
* dstore to derive from it.
*/
public static class SessionLostHandler implements Runnable, IRunnableWithProgress
{
private IConnectorService _connection;
private boolean fSessionLost;
public SessionLostHandler(IConnectorService cs)
{
_connection = cs;
fSessionLost = false;
}
/**
* Notify that the connection has been lost. This may be called
* multiple times from multiple subsystems. The SessionLostHandler
* ensures that actual user feedback and disconnect actions are
* done only once, on the first invocation.
*/
public void sessionLost()
{
//avoid duplicate execution of sessionLost
boolean showSessionLostDlg=false;
synchronized(this) {
if (!fSessionLost) {
fSessionLost = true;
showSessionLostDlg=true;
}
}
if (showSessionLostDlg) {
//invokes this.run() on dispatch thread
Display.getDefault().asyncExec(this);
}
}
public synchronized boolean isSessionLost() {
return fSessionLost;
}
public void run()
{
Shell shell = getShell();
//TODO need a more correct message for "session lost"
//TODO allow users to reconnect from this dialog
//SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_UNKNOWNHOST);
SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_CONNECT_CANCELLED);
msg.makeSubstitution(_connection.getPrimarySubSystem().getHost().getAliasName());
SystemMessageDialog dialog = new SystemMessageDialog(getShell(), msg);
dialog.open();
try
{
//TODO I think we should better use a Job for disconnecting?
//But what about error messages?
IRunnableContext runnableContext = getRunnableContext(getShell());
// will do this.run(IProgressMonitor mon)
//runnableContext.run(false,true,this); // inthread, cancellable, IRunnableWithProgress
runnableContext.run(true,true,this); // fork, cancellable, IRunnableWithProgress
_connection.reset();
ISystemRegistry sr = RSEUIPlugin.getDefault().getSystemRegistry();
sr.connectedStatusChange(_connection.getPrimarySubSystem(), false, true, true);
}
catch (InterruptedException exc) // user cancelled
{
if (shell != null)
showDisconnectCancelledMessage(shell, _connection.getHostName(), _connection.getPort());
}
catch (java.lang.reflect.InvocationTargetException invokeExc) // unexpected error
{
Exception exc = (Exception)invokeExc.getTargetException();
if (shell != null)
showDisconnectErrorMessage(shell, _connection.getHostName(), _connection.getPort(), exc);
}
catch (Exception e)
{
SystemBasePlugin.logError(TelnetConnectorResources.TelnetConnectorService_ErrorDisconnecting, e);
}
}
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException
{
String message = null;
message = SubSystemConfiguration.getDisconnectingMessage(
_connection.getHostName(), _connection.getPort());
monitor.beginTask(message, IProgressMonitor.UNKNOWN);
try {
_connection.disconnect(monitor);
} catch (Exception exc) {
if (exc instanceof java.lang.reflect.InvocationTargetException)
throw (java.lang.reflect.InvocationTargetException) exc;
if (exc instanceof java.lang.InterruptedException)
throw (java.lang.InterruptedException) exc;
throw new java.lang.reflect.InvocationTargetException(exc);
} finally {
monitor.done();
}
}
public Shell getShell() {
Shell activeShell = SystemBasePlugin.getActiveWorkbenchShell();
if (activeShell != null) {
return activeShell;
}
IWorkbenchWindow window = null;
try {
window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
} catch (Exception e) {
return null;
}
if (window == null) {
IWorkbenchWindow[] windows = PlatformUI.getWorkbench()
.getWorkbenchWindows();
if (windows != null && windows.length > 0) {
return windows[0].getShell();
}
} else {
return window.getShell();
}
return null;
}
/**
* Get the progress monitor dialog for this operation. We try to use one
* for all phases of a single operation, such as connecting and
* resolving.
*/
protected IRunnableContext getRunnableContext(Shell rshell) {
Shell shell = getShell();
// for other cases, use statusbar
IWorkbenchWindow win = SystemBasePlugin.getActiveWorkbenchWindow();
if (win != null) {
Shell winShell = RSEUIPlugin.getDefault().getWorkbench()
.getActiveWorkbenchWindow().getShell();
if (winShell != null && !winShell.isDisposed()
&& winShell.isVisible()) {
SystemBasePlugin
.logInfo("Using active workbench window as runnable context"); //$NON-NLS-1$
shell = winShell;
return win;
} else {
win = null;
}
}
if (shell == null || shell.isDisposed() || !shell.isVisible()) {
SystemBasePlugin
.logInfo("Using progress monitor dialog with given shell as parent"); //$NON-NLS-1$
shell = rshell;
}
IRunnableContext dlg = new ProgressMonitorDialog(rshell);
return dlg;
}
/**
* Show an error message when the disconnection fails. Shows a common
* message by default. Overridable.
*/
protected void showDisconnectErrorMessage(Shell shell, String hostName, int port, Exception exc)
{
//SystemMessage.displayMessage(SystemMessage.MSGTYPE_ERROR,shell,RSEUIPlugin.getResourceBundle(),
// ISystemMessages.MSG_DISCONNECT_FAILED,
// hostName, exc.getMessage());
//RSEUIPlugin.logError("Disconnect failed",exc); // temporary
SystemMessageDialog msgDlg = new SystemMessageDialog(shell,
RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_DISCONNECT_FAILED).makeSubstitution(hostName,exc));
msgDlg.setException(exc);
msgDlg.open();
}
/**
* Show an error message when the user cancels the disconnection.
* Shows a common message by default.
* Overridable.
*/
protected void showDisconnectCancelledMessage(Shell shell, String hostName, int port)
{
//SystemMessage.displayMessage(SystemMessage.MSGTYPE_ERROR, shell, RSEUIPlugin.getResourceBundle(),
// ISystemMessages.MSG_DISCONNECT_CANCELLED, hostName);
SystemMessageDialog msgDlg = new SystemMessageDialog(shell,
RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_DISCONNECT_CANCELLED).makeSubstitution(hostName));
msgDlg.open();
}
}
/* Notification from sub-services that our session was lost.
* Notify all subsystems properly.
* TODO allow user to try and reconnect?
*/
public void handleSessionLost() {
Activator.trace("TelnetConnectorService: handleSessionLost"); //$NON-NLS-1$
if (fSessionLostHandler!=null) {
fSessionLostHandler.sessionLost();
}
}
protected static Display getStandardDisplay() {
Display display = Display.getCurrent();
if( display==null ) {
display = Display.getDefault();
}
return display;
}
public boolean isConnected() {
if (fTelnetClient.isConnected()) {
return true;
} else if (fSessionLostHandler!=null) {
Activator.trace("TelnetConnectorService.isConnected: false -> sessionLost"); //$NON-NLS-1$
fSessionLostHandler.sessionLost();
}
return false;
}
/**
* @return false
* @see org.eclipse.rse.core.subsystems.AbstractConnectorService#requiresPassword()
*/
public boolean requiresPassword() {
return false;
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 IBM Corporation 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
*
* Initial Contributors:
* The following IBM employees contributed to the Remote System Explorer
* component that contains this file: David McKnight, Kushal Munir,
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
*
* Contributors:
* Martin Oberhuber (Wind River) - Adapted from LocalConnectorServiceManager.
* Sheldon D'souza (Celunite) - Adapted from SshConnectorServiceManager
*******************************************************************************/
package org.eclipse.rse.internal.connectorservice.telnet;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.subsystems.AbstractConnectorServiceManager;
import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.rse.core.subsystems.ISubSystem;
public class TelnetConnectorServiceManager extends
AbstractConnectorServiceManager {
private static TelnetConnectorServiceManager fInstance;
private TelnetConnectorServiceManager() {
super();
}
/**
* Return singleton instance of this class
* @return the singleton instance
*/
public static TelnetConnectorServiceManager getInstance()
{
if (fInstance == null)
fInstance = new TelnetConnectorServiceManager();
return fInstance;
}
public Class getSubSystemCommonInterface(ISubSystem subsystem) {
return ITelnetSubSystem.class;
}
public boolean sharesSystem(ISubSystem otherSubSystem) {
return (otherSubSystem instanceof ITelnetSubSystem);
}
public IConnectorService createConnectorService(IHost host) {
IConnectorService service = new TelnetConnectorService(host);
return service;
}
}