From 3dbe7d2781b316ea2af9b13132192862c6455d70 Mon Sep 17 00:00:00 2001
From: Martin Oberhuber < martin.oberhuber@windriver.com>
Date: Fri, 11 May 2007 09:49:26 +0000
Subject: [PATCH] [178201] Telnet subsystem contribution initial checkin
---
.../.classpath | 7 +
.../.cvsignore | 1 +
.../.options | 1 +
.../.project | 28 ++
.../.settings/org.eclipse.jdt.core.prefs | 70 +++
.../META-INF/MANIFEST.MF | 19 +
.../about.html | 28 ++
.../build.properties | 16 +
.../plugin.properties | 17 +
.../connectorservice/telnet/Activator.java | 97 ++++
.../telnet/ITelnetSubSystem.java | 22 +
.../telnet/TelnetConnectorResources.java | 31 ++
.../TelnetConnectorResources.properties | 20 +
.../telnet/TelnetConnectorService.java | 414 ++++++++++++++++++
.../telnet/TelnetConnectorServiceManager.java | 59 +++
15 files changed, 830 insertions(+)
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/.classpath
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/.cvsignore
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/.options
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/.project
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/.settings/org.eclipse.jdt.core.prefs
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/META-INF/MANIFEST.MF
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/about.html
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/build.properties
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/plugin.properties
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/Activator.java
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/ITelnetSubSystem.java
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.java
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.properties
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java
create mode 100644 rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorServiceManager.java
diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/.classpath b/rse/plugins/org.eclipse.rse.connectorservice.telnet/.classpath
new file mode 100644
index 00000000000..ce73933404a
--- /dev/null
+++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/.classpath
@@ -0,0 +1,7 @@
+
+
June 2, 2006
+The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.
+ +If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") 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 http://www.eclipse.org.
+ + + \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/build.properties b/rse/plugins/org.eclipse.rse.connectorservice.telnet/build.properties new file mode 100644 index 00000000000..ca59f60e9c7 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/build.properties @@ -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/ diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/plugin.properties b/rse/plugins/org.eclipse.rse.connectorservice.telnet/plugin.properties new file mode 100644 index 00000000000..1a1cef189c4 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/plugin.properties @@ -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 diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/Activator.java b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/Activator.java new file mode 100644 index 00000000000..eecfe536131 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/Activator.java @@ -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(); + } + } +} diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/ITelnetSubSystem.java b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/ITelnetSubSystem.java new file mode 100644 index 00000000000..de180f2dcb1 --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/ITelnetSubSystem.java @@ -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 { + +} diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.java b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.java new file mode 100644 index 00000000000..11dba76551f --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.java @@ -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; + +} diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.properties b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.properties new file mode 100644 index 00000000000..8ec423216df --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorResources.properties @@ -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 diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java new file mode 100644 index 00000000000..f19deccc82c --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorService.java @@ -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; + } + + + +} diff --git a/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorServiceManager.java b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorServiceManager.java new file mode 100644 index 00000000000..946d621c96a --- /dev/null +++ b/rse/plugins/org.eclipse.rse.connectorservice.telnet/src/org/eclipse/rse/internal/connectorservice/telnet/TelnetConnectorServiceManager.java @@ -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; + } + +}