mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +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:
parent
ba531e74d3
commit
2f5b387647
35 changed files with 304 additions and 95 deletions
|
@ -16,3 +16,4 @@
|
|||
###############################################################################
|
||||
pluginName = Target Management Terminal Serial Connector
|
||||
providerName = Eclipse.org
|
||||
serialConnection = Serial
|
|
@ -14,6 +14,6 @@
|
|||
<plugin>
|
||||
<extension
|
||||
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>
|
||||
</plugin>
|
||||
|
|
|
@ -22,7 +22,7 @@ public interface ISerialSettings {
|
|||
int getParity();
|
||||
int getFlowControl();
|
||||
int getTimeout();
|
||||
String getStatusString(String strConnected);
|
||||
String getSummary();
|
||||
void load(ISettingsStore store);
|
||||
void save(ISettingsStore store);
|
||||
}
|
|
@ -52,7 +52,10 @@ public class SerialConnector implements ITerminalConnector {
|
|||
fSettings=settins;
|
||||
}
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
return null;
|
||||
}
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
public boolean isInstalled() {
|
||||
// check if serial is installed
|
||||
|
@ -191,8 +194,8 @@ public class SerialConnector implements ITerminalConnector {
|
|||
public ISettingsPage makeSettingsPage() {
|
||||
return new SerialSettingsPage(fSettings);
|
||||
}
|
||||
public String getStatusString(String strConnected) {
|
||||
return fSettings.getStatusString(strConnected);
|
||||
public String getSettingsSummary() {
|
||||
return fSettings.getSummary();
|
||||
}
|
||||
public void load(ISettingsStore store) {
|
||||
fSettings.load(store);
|
||||
|
|
|
@ -21,7 +21,6 @@ public class SerialMessages extends NLS {
|
|||
static {
|
||||
NLS.initializeMessages(SerialMessages.class.getName(), SerialMessages.class);
|
||||
}
|
||||
public static String CONNTYPE_SERIAL;
|
||||
public static String PROP_TITLE;
|
||||
public static String PORT;
|
||||
public static String BAUDRATE;
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
# 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?
|
||||
CONNTYPE_SERIAL = Serial
|
||||
PROP_TITLE = Terminal
|
||||
PORT = Port
|
||||
BAUDRATE = Baud Rate
|
||||
|
|
|
@ -144,15 +144,13 @@ public class SerialSettings implements ISerialSettings {
|
|||
fFlowControl = strFlow;
|
||||
}
|
||||
|
||||
public String getStatusString(String strConnected) {
|
||||
return " (" + //$NON-NLS-1$
|
||||
getSerialPort() + ", " + //$NON-NLS-1$
|
||||
public String getSummary() {
|
||||
return getSerialPort() + ", " + //$NON-NLS-1$
|
||||
getBaudRateString() + ", " + //$NON-NLS-1$
|
||||
getDataBitsString() + ", " + //$NON-NLS-1$
|
||||
getStopBitsString() + ", " + //$NON-NLS-1$
|
||||
getParityString() + ", " + //$NON-NLS-1$
|
||||
getFlowControlString() + " - " + //$NON-NLS-1$
|
||||
strConnected + ")"; //$NON-NLS-1$
|
||||
getFlowControlString();
|
||||
}
|
||||
|
||||
public void load(ISettingsStore store) {
|
||||
|
|
|
@ -134,8 +134,4 @@ public class SerialSettingsPage implements ISettingsPage {
|
|||
ctlCombo.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return SerialMessages.CONNTYPE_SERIAL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,3 +10,4 @@
|
|||
###############################################################################
|
||||
pluginName = Target Management Terminal SSH Connector
|
||||
providerName = Eclipse.org
|
||||
sshConnection = SSH
|
|
@ -14,7 +14,7 @@
|
|||
<plugin>
|
||||
<extension
|
||||
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>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -19,7 +19,7 @@ public interface ISshSettings {
|
|||
String getPassword();
|
||||
int getTimeout();
|
||||
int getPort();
|
||||
String getStatusString(String strConnected);
|
||||
String getSummary();
|
||||
void load(ISettingsStore store);
|
||||
void save(ISettingsStore store);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,10 @@ public class SshConnector implements ITerminalConnector {
|
|||
fSettings=settings;
|
||||
}
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
return null;
|
||||
}
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
public boolean isInstalled() {
|
||||
return fJsch!=null;
|
||||
|
@ -111,8 +114,8 @@ public class SshConnector implements ITerminalConnector {
|
|||
public ISettingsPage makeSettingsPage() {
|
||||
return new SshSettingsPage(fSettings);
|
||||
}
|
||||
public String getStatusString(String strConnected) {
|
||||
return fSettings.getStatusString(strConnected);
|
||||
public String getSettingsSummary() {
|
||||
return fSettings.getSummary();
|
||||
}
|
||||
public void load(ISettingsStore store) {
|
||||
fSettings.load(store);
|
||||
|
|
|
@ -17,7 +17,6 @@ public class SshMessages extends NLS {
|
|||
static {
|
||||
NLS.initializeMessages(SshMessages.class.getName(), SshMessages.class);
|
||||
}
|
||||
public static String CONNTYPE;
|
||||
public static String USER;
|
||||
public static String HOST;
|
||||
public static String PORT;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
# Michael Scharf (Wind River) - initial API and implementation
|
||||
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
||||
###############################################################################
|
||||
CONNTYPE = SSH
|
||||
HOST = Host
|
||||
USER = User
|
||||
PORT = Port
|
||||
|
|
|
@ -27,11 +27,9 @@ public class SshSettings implements ISshSettings {
|
|||
fHost = strHost;
|
||||
}
|
||||
|
||||
public String getStatusString(String strConnected) {
|
||||
return " (" + //$NON-NLS-1$
|
||||
getHost() + ":" + //$NON-NLS-1$
|
||||
getUser() + " - " + //$NON-NLS-1$
|
||||
strConnected + ")"; //$NON-NLS-1$
|
||||
public String getSummary() {
|
||||
return getHost() + ":" + getUser(); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
public void load(ISettingsStore store) {
|
||||
|
|
|
@ -86,8 +86,4 @@ public class SshSettingsPage implements ISettingsPage {
|
|||
return createTextField(composite, labelTxt, 0);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return SshMessages.CONNTYPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,15 +18,19 @@ package org.eclipse.tm.internal.terminal.view;
|
|||
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Group;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
|
||||
|
@ -35,6 +39,11 @@ class TerminalSettingsDlg extends Dialog {
|
|||
private Combo fCtlConnTypeCombo;
|
||||
private final ITerminalConnector[] fConnectors;
|
||||
private final ISettingsPage[] fPages;
|
||||
/**
|
||||
* Maps the fConnectors index to the fPages index
|
||||
*/
|
||||
private final int[] fPageIndex;
|
||||
private int fNPages;
|
||||
private int fSelectedConnector;
|
||||
private PageBook fPageBook;
|
||||
private IDialogSettings fDialogSettings;
|
||||
|
@ -43,17 +52,66 @@ class TerminalSettingsDlg extends Dialog {
|
|||
super(shell);
|
||||
fConnectors=connectors;
|
||||
fPages=new ISettingsPage[fConnectors.length];
|
||||
fPageIndex=new int[fConnectors.length];
|
||||
fSelectedConnector=-1;
|
||||
for (int i = 0; i < fConnectors.length; i++) {
|
||||
fPages[i]=fConnectors[i].makeSettingsPage();
|
||||
if(fConnectors[i]==connector)
|
||||
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() {
|
||||
if (!validateSettings())
|
||||
return;
|
||||
if(fSelectedConnector>=0) {
|
||||
fPages[fSelectedConnector].saveSettings();
|
||||
getPage(fSelectedConnector).saveSettings();
|
||||
}
|
||||
super.okPressed();
|
||||
}
|
||||
|
@ -80,8 +138,8 @@ class TerminalSettingsDlg extends Dialog {
|
|||
}
|
||||
private void initFields() {
|
||||
// Load controls
|
||||
for (int i = 0; i < fPages.length; i++) {
|
||||
String name=fPages[i].getName();
|
||||
for (int i = 0; i < fConnectors.length; i++) {
|
||||
String name=fConnectors[i].getName();
|
||||
fCtlConnTypeCombo.add(name);
|
||||
if(fSelectedConnector==i) {
|
||||
fCtlConnTypeCombo.select(i);
|
||||
|
@ -92,7 +150,7 @@ class TerminalSettingsDlg extends Dialog {
|
|||
private boolean validateSettings() {
|
||||
if(fSelectedConnector<0)
|
||||
return true;
|
||||
return fPages[fSelectedConnector].validateSettings();
|
||||
return getPage(fSelectedConnector).validateSettings();
|
||||
}
|
||||
private void setupPanel(Composite wndParent) {
|
||||
setupConnTypePanel(wndParent);
|
||||
|
@ -123,11 +181,6 @@ class TerminalSettingsDlg extends Dialog {
|
|||
group.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
fPageBook=new PageBook(group,SWT.NONE);
|
||||
fPageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
|
||||
for (int i = 0; i < fPages.length; i++) {
|
||||
fPages[i].createControl(fPageBook);
|
||||
}
|
||||
}
|
||||
private void setupListeners() {
|
||||
fCtlConnTypeCombo.addSelectionListener(new SelectionAdapter() {
|
||||
|
@ -143,8 +196,9 @@ class TerminalSettingsDlg extends Dialog {
|
|||
}
|
||||
private void selectPage(int index) {
|
||||
fSelectedConnector=index;
|
||||
getPage(index);
|
||||
Control[] pages=fPageBook.getChildren();
|
||||
fPageBook.showPage(pages[fSelectedConnector]);
|
||||
fPageBook.showPage(pages[fPageIndex[fSelectedConnector]]);
|
||||
}
|
||||
protected IDialogSettings getDialogBoundsSettings() {
|
||||
IDialogSettings ds=TerminalViewPlugin.getDefault().getDialogSettings();
|
||||
|
|
|
@ -67,7 +67,9 @@ import org.eclipse.ui.part.ViewPart;
|
|||
public class TerminalView extends ViewPart implements ITerminalView, ITerminalListener {
|
||||
private static final String STORE_CONNECTION_TYPE = "ConnectionType"; //$NON-NLS-1$
|
||||
|
||||
private static final String STORE_HAS_COMMAND_INPUT_FIELD = "HasCommandInputField"; //$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_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
|
||||
// TerminalText when it processes an ANSI OSC escape sequence that commands
|
||||
// the terminal to display text in its title bar.
|
||||
} else if(fCtlTerminal.getTerminalConnection()==null){
|
||||
strTitle=ViewMessages.NO_CONNECTION_SELECTED;
|
||||
} else {
|
||||
// When parameter 'data' is null, we construct a descriptive string to
|
||||
// display in the content description line.
|
||||
String strConnected = getStateDisplayName(fCtlTerminal.getState());
|
||||
String status=fCtlTerminal.getStatusString(strConnected);
|
||||
if(status.length()>0)
|
||||
status=": "+status; //$NON-NLS-1$
|
||||
strTitle = ViewMessages.PROP_TITLE + status;
|
||||
String summary = getSettingsSummary();
|
||||
if(summary.length()>0)
|
||||
summary=summary+" - "; //$NON-NLS-1$
|
||||
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);
|
||||
getViewSite().getActionBars().getStatusLineManager().setMessage(
|
||||
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() {
|
||||
setTerminalTitle(null);
|
||||
}
|
||||
|
@ -417,10 +440,11 @@ public class TerminalView extends ViewPart implements ITerminalView, ITerminalLi
|
|||
if(fCommandInputField!=null)
|
||||
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_SETTING_SUMMARY, getSettingsSummary());
|
||||
fStore.saveState(memento);
|
||||
}
|
||||
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() {
|
||||
|
|
|
@ -22,6 +22,7 @@ public class ViewMessages extends NLS {
|
|||
static {
|
||||
NLS.initializeMessages(ViewMessages.class.getName(), ViewMessages.class);
|
||||
}
|
||||
public static String NO_CONNECTION_SELECTED;
|
||||
public static String PROP_TITLE;
|
||||
public static String SETTINGS;
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
# Michael Scharf (Wind River) - split into core, view and connector plugins
|
||||
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
||||
###############################################################################
|
||||
NO_CONNECTION_SELECTED = No Connection Selected
|
||||
PROP_TITLE = Terminal
|
||||
SETTINGS = Settings
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
pluginName = Target Management Terminal Widget
|
||||
providerName = Eclipse.org
|
||||
|
||||
telnetConnection = Telnet
|
||||
|
||||
terminal.context.name=Terminal widget context
|
||||
terminal.context.description=Override ALT+x menu access keys
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<extension-point id="terminalConnector" name="Terminal Connector" schema="schema/terminalConnector.exsd"/>
|
||||
<extension
|
||||
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 point="org.eclipse.ui.contexts">
|
||||
|
|
|
@ -54,6 +54,23 @@
|
|||
</appInfo>
|
||||
</annotation>
|
||||
</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>
|
||||
</element>
|
||||
|
||||
|
@ -107,7 +124,6 @@ http://www.eclipse.org/legal/epl-v10.html
|
|||
Contributors:
|
||||
Michael Scharf (Wind River) - initial API and implementation
|
||||
Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
||||
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public interface ITerminalViewControl {
|
|||
Clipboard getClipboard();
|
||||
void disconnectTerminal();
|
||||
void disposeTerminal();
|
||||
String getStatusString(String status);
|
||||
String getSettingsSummary();
|
||||
ITerminalConnector[] getConnectors();
|
||||
void setFocus();
|
||||
ITerminalConnector getTerminalConnection();
|
||||
|
|
|
@ -811,10 +811,10 @@ public class TerminalControl implements ITerminalControlForText, ITerminalContro
|
|||
fTerminalListener.setState(state);
|
||||
}
|
||||
|
||||
public String getStatusString(String strConnected) {
|
||||
public String getSettingsSummary() {
|
||||
if(fConnector!=null)
|
||||
return fConnector.getStatusString(strConnected);
|
||||
return strConnected;
|
||||
return fConnector.getSettingsSummary();
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void setConnector(ITerminalConnector connector) {
|
||||
|
|
|
@ -47,11 +47,5 @@ public interface ISettingsPage {
|
|||
* @return true if the
|
||||
*/
|
||||
boolean validateSettings();
|
||||
|
||||
/**
|
||||
* @return a name of the connection type. Used in a tab page title or drop
|
||||
* down to select the connection.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
}
|
||||
|
|
|
@ -28,10 +28,21 @@ import java.io.OutputStream;
|
|||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* @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
|
||||
* installed). This was added for the serial support, because it requires the java comm
|
||||
|
@ -73,7 +84,7 @@ public interface ITerminalConnector {
|
|||
* {@link #connect(ITerminalControl)}.
|
||||
*
|
||||
* @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);
|
||||
|
||||
|
@ -91,11 +102,9 @@ public interface ITerminalConnector {
|
|||
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.
|
||||
* TODO: Michael Scharf:
|
||||
*/
|
||||
String getStatusString(String connectedLabel);
|
||||
String getSettingsSummary();
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.provisional.api;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -33,6 +34,138 @@ import org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin;
|
|||
* </p>
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
|
@ -40,18 +173,7 @@ public class TerminalConnectorExtension {
|
|||
IConfigurationElement[] config=RegistryFactory.getRegistry().getConfigurationElementsFor("org.eclipse.tm.terminal.terminalConnector"); //$NON-NLS-1$
|
||||
List result=new ArrayList();
|
||||
for (int i = 0; i < config.length; i++) {
|
||||
try {
|
||||
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);
|
||||
}
|
||||
result.add(new TerminalConnectorProxy(config[i]));
|
||||
}
|
||||
return (ITerminalConnector[]) result.toArray(new ITerminalConnector[result.size()]);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public interface ITelnetSettings {
|
|||
String getHost();
|
||||
int getNetworkPort();
|
||||
int getTimeout();
|
||||
String getStatusString(String strConnected);
|
||||
String getSummary();
|
||||
void load(ISettingsStore store);
|
||||
void save(ISettingsStore store);
|
||||
}
|
||||
|
|
|
@ -392,12 +392,12 @@ public class TelnetConnection extends Thread implements TelnetCodes {
|
|||
* because a multi-byte TELNET command might be split between two (or more)
|
||||
* calls to this function. The state is preserved in field <i>telnetState</i>.
|
||||
* This function implements an FSA that recognizes TELNET option codes.
|
||||
* TELNET option state is stored in instances of {@link TelnetOption}.
|
||||
* TELNET option subnegotiation is delegated to instances of TelnetOption.
|
||||
* TELNET option sub-negotiation is delegated to instances of TelnetOption.
|
||||
*
|
||||
* @return The number of bytes remaining in the buffer after removing all
|
||||
* TELNET protocol bytes.
|
||||
*/
|
||||
//TELNET option state is stored in instances of TelnetOption.
|
||||
protected int processTelnetProtocol(int count) {
|
||||
// This is too noisy to leave on all the time.
|
||||
// Logger.log("Processing " + count + " bytes of data.");
|
||||
|
|
|
@ -42,7 +42,10 @@ public class TelnetConnector implements ITerminalConnector {
|
|||
this(new TelnetSettings());
|
||||
}
|
||||
public String getId() {
|
||||
return getClass().getName();
|
||||
return null;
|
||||
}
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
public TelnetConnector(TelnetSettings settings) {
|
||||
fSettings=settings;
|
||||
|
@ -152,8 +155,8 @@ public class TelnetConnector implements ITerminalConnector {
|
|||
public ISettingsPage makeSettingsPage() {
|
||||
return new TelnetSettingsPage(fSettings);
|
||||
}
|
||||
public String getStatusString(String strConnected) {
|
||||
return fSettings.getStatusString(strConnected);
|
||||
public String getSettingsSummary() {
|
||||
return fSettings.getSummary();
|
||||
}
|
||||
public void load(ISettingsStore store) {
|
||||
fSettings.load(store);
|
||||
|
|
|
@ -17,7 +17,6 @@ public class TelnetMessages extends NLS {
|
|||
static {
|
||||
NLS.initializeMessages(TelnetMessages.class.getName(), TelnetMessages.class);
|
||||
}
|
||||
public static String CONNTYPE_NETWORK;
|
||||
public static String PORT;
|
||||
public static String HOST;
|
||||
public static String CONNECTION_CLOSED_BY_FOREIGN_HOST;
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# Michael Scharf (Wind River) - split into core, view and connector plugins
|
||||
# Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
||||
###############################################################################
|
||||
CONNTYPE_NETWORK = Telnet
|
||||
PORT = Port
|
||||
HOST = Host
|
||||
CONNECTION_CLOSED_BY_FOREIGN_HOST= Connection closed by foreign host.
|
||||
|
|
|
@ -47,11 +47,8 @@ public class TelnetSettings implements ITelnetSettings {
|
|||
fNetworkPort = strNetworkPort;
|
||||
}
|
||||
|
||||
public String getStatusString(String strConnected) {
|
||||
return " (" + //$NON-NLS-1$
|
||||
getHost() + ":" + //$NON-NLS-1$
|
||||
getNetworkPortString() + " - " + //$NON-NLS-1$
|
||||
strConnected + ")"; //$NON-NLS-1$
|
||||
public String getSummary() {
|
||||
return getHost() + ":" + getNetworkPortString(); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void load(ISettingsStore store) {
|
||||
|
|
|
@ -134,8 +134,4 @@ public class TelnetSettingsPage implements ISettingsPage {
|
|||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return TelnetMessages.CONNTYPE_NETWORK;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue