1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-27 10:55:33 +02:00

[186136] [terminal] Terminal activates extensions too early

Now the plugins are activated only when they are really needed:
- when a connection is made
- when the user selects the connection in the settings dialog
This commit is contained in:
Michael Scharf 2007-05-16 20:38:23 +00:00
parent ba531e74d3
commit 2f5b387647
35 changed files with 304 additions and 95 deletions

View file

@ -16,3 +16,4 @@
############################################################################### ###############################################################################
pluginName = Target Management Terminal Serial Connector pluginName = Target Management Terminal Serial Connector
providerName = Eclipse.org providerName = Eclipse.org
serialConnection = Serial

View file

@ -14,6 +14,6 @@
<plugin> <plugin>
<extension <extension
point="org.eclipse.tm.terminal.terminalConnector"> point="org.eclipse.tm.terminal.terminalConnector">
<connector class="org.eclipse.tm.internal.terminal.serial.SerialConnector"/> <connector name="%serialConnection" class="org.eclipse.tm.internal.terminal.serial.SerialConnector"/>
</extension> </extension>
</plugin> </plugin>

View file

@ -22,7 +22,7 @@ public interface ISerialSettings {
int getParity(); int getParity();
int getFlowControl(); int getFlowControl();
int getTimeout(); int getTimeout();
String getStatusString(String strConnected); String getSummary();
void load(ISettingsStore store); void load(ISettingsStore store);
void save(ISettingsStore store); void save(ISettingsStore store);
} }

View file

@ -52,7 +52,10 @@ public class SerialConnector implements ITerminalConnector {
fSettings=settins; fSettings=settins;
} }
public String getId() { public String getId() {
return getClass().getName(); return null;
}
public String getName() {
return null;
} }
public boolean isInstalled() { public boolean isInstalled() {
// check if serial is installed // check if serial is installed
@ -191,8 +194,8 @@ public class SerialConnector implements ITerminalConnector {
public ISettingsPage makeSettingsPage() { public ISettingsPage makeSettingsPage() {
return new SerialSettingsPage(fSettings); return new SerialSettingsPage(fSettings);
} }
public String getStatusString(String strConnected) { public String getSettingsSummary() {
return fSettings.getStatusString(strConnected); return fSettings.getSummary();
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fSettings.load(store); fSettings.load(store);

View file

@ -21,7 +21,6 @@ public class SerialMessages extends NLS {
static { static {
NLS.initializeMessages(SerialMessages.class.getName(), SerialMessages.class); NLS.initializeMessages(SerialMessages.class.getName(), SerialMessages.class);
} }
public static String CONNTYPE_SERIAL;
public static String PROP_TITLE; public static String PROP_TITLE;
public static String PORT; public static String PORT;
public static String BAUDRATE; public static String BAUDRATE;

View file

@ -15,7 +15,6 @@
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Martin Oberhuber (Wind River) - fixed copyright headers and beautified
############################################################################### ###############################################################################
PORT_IN_USE = Serial port \''{0}\'' is currently in use\!\nDo you want to close the port? PORT_IN_USE = Serial port \''{0}\'' is currently in use\!\nDo you want to close the port?
CONNTYPE_SERIAL = Serial
PROP_TITLE = Terminal PROP_TITLE = Terminal
PORT = Port PORT = Port
BAUDRATE = Baud Rate BAUDRATE = Baud Rate

View file

@ -144,15 +144,13 @@ public class SerialSettings implements ISerialSettings {
fFlowControl = strFlow; fFlowControl = strFlow;
} }
public String getStatusString(String strConnected) { public String getSummary() {
return " (" + //$NON-NLS-1$ return getSerialPort() + ", " + //$NON-NLS-1$
getSerialPort() + ", " + //$NON-NLS-1$
getBaudRateString() + ", " + //$NON-NLS-1$ getBaudRateString() + ", " + //$NON-NLS-1$
getDataBitsString() + ", " + //$NON-NLS-1$ getDataBitsString() + ", " + //$NON-NLS-1$
getStopBitsString() + ", " + //$NON-NLS-1$ getStopBitsString() + ", " + //$NON-NLS-1$
getParityString() + ", " + //$NON-NLS-1$ getParityString() + ", " + //$NON-NLS-1$
getFlowControlString() + " - " + //$NON-NLS-1$ getFlowControlString();
strConnected + ")"; //$NON-NLS-1$
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {

View file

@ -134,8 +134,4 @@ public class SerialSettingsPage implements ISettingsPage {
ctlCombo.add(label); ctlCombo.add(label);
} }
} }
public String getName() {
return SerialMessages.CONNTYPE_SERIAL;
}
} }

View file

@ -10,3 +10,4 @@
############################################################################### ###############################################################################
pluginName = Target Management Terminal SSH Connector pluginName = Target Management Terminal SSH Connector
providerName = Eclipse.org providerName = Eclipse.org
sshConnection = SSH

View file

@ -14,7 +14,7 @@
<plugin> <plugin>
<extension <extension
point="org.eclipse.tm.terminal.terminalConnector"> point="org.eclipse.tm.terminal.terminalConnector">
<connector class="org.eclipse.tm.internal.terminal.ssh.SshConnector"/> <connector name="%sshConnection" class="org.eclipse.tm.internal.terminal.ssh.SshConnector"/>
</extension> </extension>
</plugin> </plugin>

View file

@ -19,7 +19,7 @@ public interface ISshSettings {
String getPassword(); String getPassword();
int getTimeout(); int getTimeout();
int getPort(); int getPort();
String getStatusString(String strConnected); String getSummary();
void load(ISettingsStore store); void load(ISettingsStore store);
void save(ISettingsStore store); void save(ISettingsStore store);
} }

View file

@ -47,7 +47,10 @@ public class SshConnector implements ITerminalConnector {
fSettings=settings; fSettings=settings;
} }
public String getId() { public String getId() {
return getClass().getName(); return null;
}
public String getName() {
return null;
} }
public boolean isInstalled() { public boolean isInstalled() {
return fJsch!=null; return fJsch!=null;
@ -111,8 +114,8 @@ public class SshConnector implements ITerminalConnector {
public ISettingsPage makeSettingsPage() { public ISettingsPage makeSettingsPage() {
return new SshSettingsPage(fSettings); return new SshSettingsPage(fSettings);
} }
public String getStatusString(String strConnected) { public String getSettingsSummary() {
return fSettings.getStatusString(strConnected); return fSettings.getSummary();
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fSettings.load(store); fSettings.load(store);

View file

@ -17,7 +17,6 @@ public class SshMessages extends NLS {
static { static {
NLS.initializeMessages(SshMessages.class.getName(), SshMessages.class); NLS.initializeMessages(SshMessages.class.getName(), SshMessages.class);
} }
public static String CONNTYPE;
public static String USER; public static String USER;
public static String HOST; public static String HOST;
public static String PORT; public static String PORT;

View file

@ -9,7 +9,6 @@
# Michael Scharf (Wind River) - initial API and implementation # Michael Scharf (Wind River) - initial API and implementation
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Martin Oberhuber (Wind River) - fixed copyright headers and beautified
############################################################################### ###############################################################################
CONNTYPE = SSH
HOST = Host HOST = Host
USER = User USER = User
PORT = Port PORT = Port

View file

@ -27,11 +27,9 @@ public class SshSettings implements ISshSettings {
fHost = strHost; fHost = strHost;
} }
public String getStatusString(String strConnected) { public String getSummary() {
return " (" + //$NON-NLS-1$ return getHost() + ":" + getUser(); //$NON-NLS-1$
getHost() + ":" + //$NON-NLS-1$
getUser() + " - " + //$NON-NLS-1$
strConnected + ")"; //$NON-NLS-1$
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {

View file

@ -86,8 +86,4 @@ public class SshSettingsPage implements ISettingsPage {
return createTextField(composite, labelTxt, 0); return createTextField(composite, labelTxt, 0);
} }
public String getName() {
return SshMessages.CONNTYPE;
}
} }

View file

@ -18,15 +18,19 @@ package org.eclipse.tm.internal.terminal.view;
import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings; import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage; import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
@ -35,6 +39,11 @@ class TerminalSettingsDlg extends Dialog {
private Combo fCtlConnTypeCombo; private Combo fCtlConnTypeCombo;
private final ITerminalConnector[] fConnectors; private final ITerminalConnector[] fConnectors;
private final ISettingsPage[] fPages; private final ISettingsPage[] fPages;
/**
* Maps the fConnectors index to the fPages index
*/
private final int[] fPageIndex;
private int fNPages;
private int fSelectedConnector; private int fSelectedConnector;
private PageBook fPageBook; private PageBook fPageBook;
private IDialogSettings fDialogSettings; private IDialogSettings fDialogSettings;
@ -43,17 +52,66 @@ class TerminalSettingsDlg extends Dialog {
super(shell); super(shell);
fConnectors=connectors; fConnectors=connectors;
fPages=new ISettingsPage[fConnectors.length]; fPages=new ISettingsPage[fConnectors.length];
fPageIndex=new int[fConnectors.length];
fSelectedConnector=-1;
for (int i = 0; i < fConnectors.length; i++) { for (int i = 0; i < fConnectors.length; i++) {
fPages[i]=fConnectors[i].makeSettingsPage();
if(fConnectors[i]==connector) if(fConnectors[i]==connector)
fSelectedConnector=i; fSelectedConnector=i;
} }
} }
ISettingsPage getPage(int i) {
if(fPages[i]==null) {
try {
fPages[i]=fConnectors[i].makeSettingsPage();
// TODO: what happens if an error occurs while
// the control is partly created?
fPages[i].createControl(fPageBook);
} catch (final Exception e) {
// create a error message
fPages[i]=new ISettingsPage(){
public void createControl(Composite parent) {
Label l=new Label(parent,SWT.WRAP);
l.setText("Error"); //$NON-NLS-1$
l.setForeground(l.getDisplay().getSystemColor(SWT.COLOR_RED));
MessageDialog.openError(getShell(), "Initialization Problems!", e.getLocalizedMessage()); //$NON-NLS-1$
}
public void loadSettings() {}
public void saveSettings() {}
public boolean validateSettings() {return false;}
};
fPages[i].createControl(fPageBook);
}
fPageIndex[i]=fNPages++;
resize();
}
return fPages[i];
}
void resize() {
Point size=getShell().getSize();
Point newSize=getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT,true);
newSize.x=Math.max(newSize.x,size.x);
newSize.y=Math.max(newSize.y,size.y);
if(newSize.x!=size.x || newSize.y!=size.y) {
setShellSize(newSize);
} else {
fPageBook.getParent().layout();
}
}
/**
* Increase the size of this dialog's <code>Shell</code> by the specified amounts.
* Do not increase the size of the Shell beyond the bounds of the Display.
*/
protected void setShellSize(Point size) {
Rectangle bounds = getShell().getMonitor().getClientArea();
getShell().setSize(Math.min(size.x, bounds.width), Math.min(size.y, bounds.height));
}
protected void okPressed() { protected void okPressed() {
if (!validateSettings()) if (!validateSettings())
return; return;
if(fSelectedConnector>=0) { if(fSelectedConnector>=0) {
fPages[fSelectedConnector].saveSettings(); getPage(fSelectedConnector).saveSettings();
} }
super.okPressed(); super.okPressed();
} }
@ -80,8 +138,8 @@ class TerminalSettingsDlg extends Dialog {
} }
private void initFields() { private void initFields() {
// Load controls // Load controls
for (int i = 0; i < fPages.length; i++) { for (int i = 0; i < fConnectors.length; i++) {
String name=fPages[i].getName(); String name=fConnectors[i].getName();
fCtlConnTypeCombo.add(name); fCtlConnTypeCombo.add(name);
if(fSelectedConnector==i) { if(fSelectedConnector==i) {
fCtlConnTypeCombo.select(i); fCtlConnTypeCombo.select(i);
@ -92,7 +150,7 @@ class TerminalSettingsDlg extends Dialog {
private boolean validateSettings() { private boolean validateSettings() {
if(fSelectedConnector<0) if(fSelectedConnector<0)
return true; return true;
return fPages[fSelectedConnector].validateSettings(); return getPage(fSelectedConnector).validateSettings();
} }
private void setupPanel(Composite wndParent) { private void setupPanel(Composite wndParent) {
setupConnTypePanel(wndParent); setupConnTypePanel(wndParent);
@ -123,11 +181,6 @@ class TerminalSettingsDlg extends Dialog {
group.setLayoutData(new GridData(GridData.FILL_BOTH)); group.setLayoutData(new GridData(GridData.FILL_BOTH));
fPageBook=new PageBook(group,SWT.NONE); fPageBook=new PageBook(group,SWT.NONE);
fPageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); fPageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
for (int i = 0; i < fPages.length; i++) {
fPages[i].createControl(fPageBook);
}
} }
private void setupListeners() { private void setupListeners() {
fCtlConnTypeCombo.addSelectionListener(new SelectionAdapter() { fCtlConnTypeCombo.addSelectionListener(new SelectionAdapter() {
@ -143,8 +196,9 @@ class TerminalSettingsDlg extends Dialog {
} }
private void selectPage(int index) { private void selectPage(int index) {
fSelectedConnector=index; fSelectedConnector=index;
getPage(index);
Control[] pages=fPageBook.getChildren(); Control[] pages=fPageBook.getChildren();
fPageBook.showPage(pages[fSelectedConnector]); fPageBook.showPage(pages[fPageIndex[fSelectedConnector]]);
} }
protected IDialogSettings getDialogBoundsSettings() { protected IDialogSettings getDialogBoundsSettings() {
IDialogSettings ds=TerminalViewPlugin.getDefault().getDialogSettings(); IDialogSettings ds=TerminalViewPlugin.getDefault().getDialogSettings();

View file

@ -67,6 +67,8 @@ import org.eclipse.ui.part.ViewPart;
public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener { public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener {
private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$ private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$
private static final String STORE_SETTING_SUMMARY = "SettingSummary"; //$NON-NLS-1$
private static final String STORE_HAS_COMMAND_INPUT_FIELD = "HasCommandInputField"; //$NON-NLS-1$ private static final String STORE_HAS_COMMAND_INPUT_FIELD = "HasCommandInputField"; //$NON-NLS-1$
private static final String STORE_COMMAND_INPUT_FIELD_HISTORY = "CommandInputFieldHistory"; //$NON-NLS-1$ private static final String STORE_COMMAND_INPUT_FIELD_HISTORY = "CommandInputFieldHistory"; //$NON-NLS-1$
@ -244,20 +246,41 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
// display in the view's content description line. This is used by class // display in the view's content description line. This is used by class
// TerminalText when it processes an ANSI OSC escape sequence that commands // TerminalText when it processes an ANSI OSC escape sequence that commands
// the terminal to display text in its title bar. // the terminal to display text in its title bar.
} else if(fCtlTerminal.getTerminalConnection()==null){
strTitle=ViewMessages.NO_CONNECTION_SELECTED;
} else { } else {
// When parameter 'data' is null, we construct a descriptive string to // When parameter 'data' is null, we construct a descriptive string to
// display in the content description line. // display in the content description line.
String strConnected = getStateDisplayName(fCtlTerminal.getState()); String strConnected = getStateDisplayName(fCtlTerminal.getState());
String status=fCtlTerminal.getStatusString(strConnected); String summary = getSettingsSummary();
if(status.length()>0) if(summary.length()>0)
status=": "+status; //$NON-NLS-1$ summary=summary+" - "; //$NON-NLS-1$
strTitle = ViewMessages.PROP_TITLE + status; String name=fCtlTerminal.getTerminalConnection().getName();
if(name.length()>0) {
name+=": "; //$NON-NLS-1$
}
strTitle = name + "("+ summary + strConnected + ")"; //$NON-NLS-1$ //$NON-NLS-2$
} }
setContentDescription(strTitle); setContentDescription(strTitle);
getViewSite().getActionBars().getStatusLineManager().setMessage( getViewSite().getActionBars().getStatusLineManager().setMessage(
strTitle); strTitle);
} }
/**
* @return the setting summary. If there is no connection, or the connection
* has not been initialized, use the last stored state.
*/
private String getSettingsSummary() {
// TODO: use another mechanism than "?" for the magic non initialized state
// see TerminalConnectorProxy.getSettingsSummary
String summary="?"; //$NON-NLS-1$
if(fCtlTerminal.getTerminalConnection()!=null)
summary=fCtlTerminal.getSettingsSummary();
if("?".equals(summary)) { //$NON-NLS-1$
summary=fStore.get(STORE_SETTING_SUMMARY, ""); //$NON-NLS-1$
}
return summary;
}
public void onTerminalStatus() { public void onTerminalStatus() {
setTerminalTitle(null); setTerminalTitle(null);
} }
@ -417,10 +440,11 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
if(fCommandInputField!=null) if(fCommandInputField!=null)
fStore.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fCommandInputField.getHistory()); fStore.put(STORE_COMMAND_INPUT_FIELD_HISTORY, fCommandInputField.getHistory());
fStore.put(STORE_HAS_COMMAND_INPUT_FIELD,hasCommandInputField()?"true":"false"); //$NON-NLS-1$//$NON-NLS-2$ fStore.put(STORE_HAS_COMMAND_INPUT_FIELD,hasCommandInputField()?"true":"false"); //$NON-NLS-1$//$NON-NLS-2$
fStore.put(STORE_SETTING_SUMMARY, getSettingsSummary());
fStore.saveState(memento); fStore.saveState(memento);
} }
private ISettingsStore getStore(ITerminalConnector connector) { private ISettingsStore getStore(ITerminalConnector connector) {
return new SettingStorePrefixDecorator(fStore,connector.getClass().getName()+"."); //$NON-NLS-1$ return new SettingStorePrefixDecorator(fStore,connector.getId()+"."); //$NON-NLS-1$
} }
protected void setupActions() { protected void setupActions() {

View file

@ -22,6 +22,7 @@ public class ViewMessages extends NLS {
static { static {
NLS.initializeMessages(ViewMessages.class.getName(), ViewMessages.class); NLS.initializeMessages(ViewMessages.class.getName(), ViewMessages.class);
} }
public static String NO_CONNECTION_SELECTED;
public static String PROP_TITLE; public static String PROP_TITLE;
public static String SETTINGS; public static String SETTINGS;

View file

@ -14,6 +14,7 @@
# Michael Scharf (Wind River) - split into core, view and connector plugins # Michael Scharf (Wind River) - split into core, view and connector plugins
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Martin Oberhuber (Wind River) - fixed copyright headers and beautified
############################################################################### ###############################################################################
NO_CONNECTION_SELECTED = No Connection Selected
PROP_TITLE = Terminal PROP_TITLE = Terminal
SETTINGS = Settings SETTINGS = Settings

View file

@ -17,6 +17,8 @@
pluginName = Target Management Terminal Widget pluginName = Target Management Terminal Widget
providerName = Eclipse.org providerName = Eclipse.org
telnetConnection = Telnet
terminal.context.name=Terminal widget context terminal.context.name=Terminal widget context
terminal.context.description=Override ALT+x menu access keys terminal.context.description=Override ALT+x menu access keys

View file

@ -15,7 +15,7 @@
<extension-point id="terminalConnector" name="Terminal Connector" schema="schema/terminalConnector.exsd"/> <extension-point id="terminalConnector" name="Terminal Connector" schema="schema/terminalConnector.exsd"/>
<extension <extension
point="org.eclipse.tm.terminal.terminalConnector"> point="org.eclipse.tm.terminal.terminalConnector">
<connector class="org.eclipse.tm.internal.terminal.telnet.TelnetConnector"/> <connector name="%telnetConnection" class="org.eclipse.tm.internal.terminal.telnet.TelnetConnector"/>
</extension> </extension>
<extension point="org.eclipse.ui.contexts"> <extension point="org.eclipse.ui.contexts">

View file

@ -54,6 +54,23 @@
</appInfo> </appInfo>
</annotation> </annotation>
</attribute> </attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
The name of the connection (used in the UI)
</documentation>
<appInfo>
<meta.attribute translatable="true"/>
</appInfo>
</annotation>
</attribute>
</complexType> </complexType>
</element> </element>
@ -107,7 +124,6 @@ http://www.eclipse.org/legal/epl-v10.html
Contributors: Contributors:
Michael Scharf (Wind River) - initial API and implementation Michael Scharf (Wind River) - initial API and implementation
Martin Oberhuber (Wind River) - fixed copyright headers and beautified Martin Oberhuber (Wind River) - fixed copyright headers and beautified
</documentation> </documentation>
</annotation> </annotation>

View file

@ -35,7 +35,7 @@ public interface ITerminalViewControl {
Clipboard getClipboard(); Clipboard getClipboard();
void disconnectTerminal(); void disconnectTerminal();
void disposeTerminal(); void disposeTerminal();
String getStatusString(String status); String getSettingsSummary();
ITerminalConnector[] getConnectors(); ITerminalConnector[] getConnectors();
void setFocus(); void setFocus();
ITerminalConnector getTerminalConnection(); ITerminalConnector getTerminalConnection();

View file

@ -811,10 +811,10 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
fTerminalListener.setState(state); fTerminalListener.setState(state);
} }
public String getStatusString(String strConnected) { public String getSettingsSummary() {
if(fConnector!=null) if(fConnector!=null)
return fConnector.getStatusString(strConnected); return fConnector.getSettingsSummary();
return strConnected; return ""; //$NON-NLS-1$
} }
public void setConnector(ITerminalConnector connector) { public void setConnector(ITerminalConnector connector) {

View file

@ -48,10 +48,4 @@ public interface ISettingsPage {
*/ */
boolean validateSettings(); boolean validateSettings();
/**
* @return a name of the connection type. Used in a tab page title or drop
* down to select the connection.
*/
String getName();
} }

View file

@ -28,10 +28,21 @@ import java.io.OutputStream;
*/ */
public interface ITerminalConnector { public interface ITerminalConnector {
/** /**
* @return an ID of this connector. Typically <code>getClass().getName()</code> * @return an ID of this connector. The id from the plugin.xml.
* <p>Note: return <code>null</code> because the framework takes
* care to get the value from the plugin.xml
*/ */
// TODO: eliminate the need of implementing this NOOP method for extensions
String getId(); String getId();
/**
* @return <code>null</code> the name (as specified in the plugin.xml)
* <p>Note: return <code>null</code> because the framework takes
* care to get the value from the plugin.xml
*/
// TODO: eliminate the need of implementing this NOOP method for extensions
String getName();
/** /**
* @return true if the contribution is functioning (e.g. all external libraries are * @return true if the contribution is functioning (e.g. all external libraries are
* installed). This was added for the serial support, because it requires the java comm * installed). This was added for the serial support, because it requires the java comm
@ -73,7 +84,7 @@ public interface ITerminalConnector {
* {@link #connect(ITerminalControl)}. * {@link #connect(ITerminalControl)}.
* *
* @param store a string based data store. Short keys like "foo" can be used to * @param store a string based data store. Short keys like "foo" can be used to
* store the state of the connectio. * store the state of the connection.
*/ */
void load(ISettingsStore store); void load(ISettingsStore store);
@ -91,11 +102,9 @@ public interface ITerminalConnector {
ISettingsPage makeSettingsPage(); ISettingsPage makeSettingsPage();
/** /**
* @param connectedLabel a String with the connected state {@link TerminalState}.
* Like "CONNECTED", "CLOSED". Can be used to build up the status string.
* @return A string that represents the state of the connection. * @return A string that represents the state of the connection.
* TODO: Michael Scharf: * TODO: Michael Scharf:
*/ */
String getStatusString(String connectedLabel); String getSettingsSummary();
} }

View file

@ -11,6 +11,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.provisional.api; package org.eclipse.tm.internal.terminal.provisional.api;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,6 +34,138 @@ import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;
* </p> * </p>
*/ */
public class TerminalConnectorExtension { public class TerminalConnectorExtension {
/**
* A placeholder for the ITerminalConnector. It gets initialized when
* the real connector is needed.
* The following methods can be called without initializing
* the contributed class: {@link #getId()}, {@link #getName()},
* {@link #getSettingsSummary()},{@link #load(ISettingsStore)},
* {@link #setTerminalSize(int, int)}, {@link #save(ISettingsStore)}
*
*/
static public class TerminalConnectorProxy implements ITerminalConnector {
/**
* The connector
*/
private ITerminalConnector fConnector;
/**
* The plugin contribution, needed for lazy initialization
* of {@link #fConnector}
*/
private final IConfigurationElement fConfig;
/**
* If the initialization of the class specified in the extension fails,
* this variable contains the error
*/
private Exception fException;
/**
* The store might be set before the real connector is initialized.
* This keeps the value until the connector is created.
*/
private ISettingsStore fStore;
TerminalConnectorProxy(IConfigurationElement config) {
fConfig=config;
}
public String getId() {
String id = fConfig.getAttribute("id"); //$NON-NLS-1$
if(id==null || id.length()==0)
id=fConfig.getAttribute("class"); //$NON-NLS-1$
return id;
}
public String getName() {
String name= fConfig.getAttribute("name"); //$NON-NLS-1$
if(name==null || name.length()==0) {
name=getId();
}
return name;
}
private ITerminalConnector getConnector() {
if(!isInitialized()) {
try {
fConnector=createConnector(fConfig);
if(!fConnector.isInstalled())
throw new RuntimeException(getName()+ " is not properly installed!"); //$NON-NLS-1$
} catch (Exception e) {
fException=e;
}
if(fConnector!=null && fStore!=null)
fConnector.load(fStore);
}
if(fConnector==null) {
throw new RuntimeException(fException);
}
return fConnector;
}
private boolean isInitialized() {
return fConnector!=null || fException!=null;
}
public void connect(ITerminalControl control) {
getConnector().connect(control);
}
public void disconnect() {
getConnector().disconnect();
}
public OutputStream getOutputStream() {
return getConnector().getOutputStream();
}
public String getSettingsSummary() {
if(fConnector!=null)
return getConnector().getSettingsSummary();
else
// TODO: see TerminalView.getSettingsSummary
return "?"; //$NON-NLS-1$
}
public boolean isInstalled() {
if(isInitialized() && fConnector==null)
return false;
return getConnector().isInstalled();
}
public boolean isLocalEcho() {
return getConnector().isLocalEcho();
}
public void load(ISettingsStore store) {
if(fConnector==null) {
fStore=store;
} else {
getConnector().load(store);
}
}
public ISettingsPage makeSettingsPage() {
return getConnector().makeSettingsPage();
}
public void save(ISettingsStore store) {
// no need to save the settings: it cannot have changed
// because we are not initialized....
if(!isInstalled())
getConnector().save(store);
}
public void setTerminalSize(int newWidth, int newHeight) {
// we assume that setTerminalSize is called also after
// the terminal has been initialized. Else we would have to cache
// the values....
if(fConnector!=null) {
fConnector.setTerminalSize(newWidth, newHeight);
}
}
}
/**
* @return null or a new connector created from the extension
*/
static private ITerminalConnector createConnector(IConfigurationElement config) throws Exception {
try {
Object obj=config.createExecutableExtension("class"); //$NON-NLS-1$
if(obj instanceof ITerminalConnector) {
ITerminalConnector conn=(ITerminalConnector) obj;
if(conn.isInstalled())
return conn;
}
} catch (Exception e) {
log(e);
throw e;
}
return null;
}
/** /**
* @return a new list of ITerminalConnectors. * @return a new list of ITerminalConnectors.
*/ */
@ -40,18 +173,7 @@ public class TerminalConnectorExtension {
IConfigurationElement[] config=RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.tm.terminal.terminalConnector"); //$NON-NLS-1$ IConfigurationElement[] config=RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.tm.terminal.terminalConnector"); //$NON-NLS-1$
List result=new ArrayList(); List result=new ArrayList();
for (int i = 0; i < config.length; i++) { for (int i = 0; i < config.length; i++) {
try { result.add(new TerminalConnectorProxy(config[i]));
Object obj=config[i].createExecutableExtension("class"); //$NON-NLS-1$
if(obj instanceof ITerminalConnector) {
ITerminalConnector conn=(ITerminalConnector) obj;
if(conn.isInstalled())
result.add(conn);
}
} catch (NoClassDefFoundError e) {
log(e);
} catch (Exception e) {
log(e);
}
} }
return (ITerminalConnector[]) result.toArray(new ITerminalConnector[result.size()]); return (ITerminalConnector[]) result.toArray(new ITerminalConnector[result.size()]);
} }

View file

@ -17,7 +17,7 @@ public interface ITelnetSettings {
String getHost(); String getHost();
int getNetworkPort(); int getNetworkPort();
int getTimeout(); int getTimeout();
String getStatusString(String strConnected); String getSummary();
void load(ISettingsStore store); void load(ISettingsStore store);
void save(ISettingsStore store); void save(ISettingsStore store);
} }

View file

@ -392,12 +392,12 @@ public class TelnetConnection extends Thread implements TelnetCodes {
* because a multi-byte TELNET command might be split between two (or more) * 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>. * calls to this function. The state is preserved in field <i>telnetState</i>.
* This function implements an FSA that recognizes TELNET option codes. * This function implements an FSA that recognizes TELNET option codes.
* TELNET option state is stored in instances of {@link TelnetOption}. * TELNET option sub-negotiation is delegated to instances of TelnetOption.
* TELNET option subnegotiation is delegated to instances of TelnetOption.
* *
* @return The number of bytes remaining in the buffer after removing all * @return The number of bytes remaining in the buffer after removing all
* TELNET protocol bytes. * TELNET protocol bytes.
*/ */
//TELNET option state is stored in instances of TelnetOption.
protected int processTelnetProtocol(int count) { protected int processTelnetProtocol(int count) {
// This is too noisy to leave on all the time. // This is too noisy to leave on all the time.
// Logger.log("Processing " + count + " bytes of data."); // Logger.log("Processing " + count + " bytes of data.");

View file

@ -42,7 +42,10 @@ public class TelnetConnector implements ITerminalConnector {
this(new TelnetSettings()); this(new TelnetSettings());
} }
public String getId() { public String getId() {
return getClass().getName(); return null;
}
public String getName() {
return null;
} }
public TelnetConnector(TelnetSettings settings) { public TelnetConnector(TelnetSettings settings) {
fSettings=settings; fSettings=settings;
@ -152,8 +155,8 @@ public class TelnetConnector implements ITerminalConnector {
public ISettingsPage makeSettingsPage() { public ISettingsPage makeSettingsPage() {
return new TelnetSettingsPage(fSettings); return new TelnetSettingsPage(fSettings);
} }
public String getStatusString(String strConnected) { public String getSettingsSummary() {
return fSettings.getStatusString(strConnected); return fSettings.getSummary();
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fSettings.load(store); fSettings.load(store);

View file

@ -17,7 +17,6 @@ public class TelnetMessages extends NLS {
static { static {
NLS.initializeMessages(TelnetMessages.class.getName(), TelnetMessages.class); NLS.initializeMessages(TelnetMessages.class.getName(), TelnetMessages.class);
} }
public static String CONNTYPE_NETWORK;
public static String PORT; public static String PORT;
public static String HOST; public static String HOST;
public static String CONNECTION_CLOSED_BY_FOREIGN_HOST; public static String CONNECTION_CLOSED_BY_FOREIGN_HOST;

View file

@ -14,7 +14,6 @@
# Michael Scharf (Wind River) - split into core, view and connector plugins # Michael Scharf (Wind River) - split into core, view and connector plugins
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified # Martin Oberhuber (Wind River) - fixed copyright headers and beautified
############################################################################### ###############################################################################
CONNTYPE_NETWORK = Telnet
PORT = Port PORT = Port
HOST = Host HOST = Host
CONNECTION_CLOSED_BY_FOREIGN_HOST= Connection closed by foreign host. CONNECTION_CLOSED_BY_FOREIGN_HOST= Connection closed by foreign host.

View file

@ -47,11 +47,8 @@ public class TelnetSettings implements ITelnetSettings {
fNetworkPort = strNetworkPort; fNetworkPort = strNetworkPort;
} }
public String getStatusString(String strConnected) { public String getSummary() {
return " (" + //$NON-NLS-1$ return getHost() + ":" + getNetworkPortString(); //$NON-NLS-1$
getHost() + ":" + //$NON-NLS-1$
getNetworkPortString() + " - " + //$NON-NLS-1$
strConnected + ")"; //$NON-NLS-1$
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {

View file

@ -134,8 +134,4 @@ public class TelnetSettingsPage implements ISettingsPage {
} }
} }
public String getName() {
return TelnetMessages.CONNTYPE_NETWORK;
}
} }