diff options
author | Max Weninger | 2012-02-22 09:42:36 +0000 |
---|---|---|
committer | Uwe Stieber | 2012-02-22 09:44:53 +0000 |
commit | 483c5c411400c4768017192423968a8a9d17d95a (patch) | |
tree | 1fd6dbe7b5660286d5a3ce79708cff39e8c26b51 /target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src | |
parent | 57adb617750c286abc4432ea03009cf2eb543fb3 (diff) | |
download | org.eclipse.tcf-483c5c411400c4768017192423968a8a9d17d95a.tar.gz org.eclipse.tcf-483c5c411400c4768017192423968a8a9d17d95a.tar.xz org.eclipse.tcf-483c5c411400c4768017192423968a8a9d17d95a.zip |
Target Explorer: Bug 370524 - [TERMINALS][Serial] Add serial line support
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src')
6 files changed, 480 insertions, 0 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/activator/UIPlugin.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/activator/UIPlugin.java new file mode 100644 index 000000000..f7d0a979e --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/activator/UIPlugin.java @@ -0,0 +1,111 @@ +/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.terminals.serial.activator;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tcf.te.runtime.tracing.TraceHandler;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class UIPlugin extends AbstractUIPlugin {
+ // The shared instance
+ private static UIPlugin plugin;
+ // The trace handler instance
+ private static TraceHandler traceHandler;
+
+ /**
+ * The constructor
+ */
+ public UIPlugin() {
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static UIPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Convenience method which returns the unique identifier of this plugin.
+ */
+ public static String getUniqueIdentifier() {
+ if (getDefault() != null && getDefault().getBundle() != null) {
+ return getDefault().getBundle().getSymbolicName();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the bundles trace handler.
+ *
+ * @return The bundles trace handler.
+ */
+ public static TraceHandler getTraceHandler() {
+ if (traceHandler == null) {
+ traceHandler = new TraceHandler(getUniqueIdentifier());
+ }
+ return traceHandler;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ @Override
+ 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)
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
+ */
+ @Override
+ protected void initializeImageRegistry(ImageRegistry registry) {
+ }
+
+ /**
+ * Loads the image registered under the specified key from the image
+ * registry and returns the <code>Image</code> object instance.
+ *
+ * @param key The key the image is registered with.
+ * @return The <code>Image</code> object instance or <code>null</code>.
+ */
+ public static Image getImage(String key) {
+ return getDefault().getImageRegistry().get(key);
+ }
+
+ /**
+ * Loads the image registered under the specified key from the image
+ * registry and returns the <code>ImageDescriptor</code> object instance.
+ *
+ * @param key The key the image is registered with.
+ * @return The <code>ImageDescriptor</code> object instance or <code>null</code>.
+ */
+ public static ImageDescriptor getImageDescriptor(String key) {
+ return getDefault().getImageRegistry().getDescriptor(key);
+ }
+}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/controls/SerialWizardConfigurationPanel.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/controls/SerialWizardConfigurationPanel.java new file mode 100644 index 000000000..bbb49ad98 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/controls/SerialWizardConfigurationPanel.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.terminals.serial.controls; + +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.TypedEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants; +import org.eclipse.tcf.te.ui.controls.BaseDialogPageControl; +import org.eclipse.tcf.te.ui.controls.wire.serial.SerialLinePanel; +import org.eclipse.tcf.te.ui.interfaces.data.IDataExchangeNode; +import org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * Serial wizard configuration panel implementation. + */ +public class SerialWizardConfigurationPanel extends AbstractConfigurationPanel implements IDataExchangeNode { + + private SerialLinePanel serialSettingsPage; + + /** + * Constructor. + * + * @param parentControl The parent control. Must not be <code>null</code>! + */ + public SerialWizardConfigurationPanel(BaseDialogPageControl parentControl) { + super(parentControl); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.controls.interfaces.IWizardConfigurationPanel#setupPanel(org.eclipse.swt.widgets.Composite, org.eclipse.ui.forms.widgets.FormToolkit) + */ + @Override + public void setupPanel(Composite parent, FormToolkit toolkit) { + Composite panel = new Composite(parent, SWT.NONE); + panel.setLayout(new GridLayout()); + GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); + panel.setLayoutData(data); + + if(isWithoutSelection()){ + createHostsUI(panel); + } + + serialSettingsPage = new SerialLinePanel(new BaseDialogPageControl(), true, true, true); + serialSettingsPage.setupPanel(panel, toolkit); + + setControl(panel); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.controls.interfaces.IWizardConfigurationPanel#dataChanged(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.swt.events.TypedEvent) + */ + @Override + public boolean dataChanged(IPropertiesContainer data, TypedEvent e) { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.wizards.interfaces.ISharedDataWizardPage#setupData(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer) + */ + @Override + public void setupData(IPropertiesContainer data) { + } + + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.wizards.interfaces.ISharedDataWizardPage#extractData(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer) + */ + @Override + public void extractData(IPropertiesContainer data) { + // set the terminal connector id for serial + data.setProperty(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID, "org.eclipse.tm.internal.terminal.serial.SerialConnector"); + + // set the connector type for serial + data.setProperty(ITerminalsConnectorConstants.PROP_CONNECTOR_TYPE_ID, "org.eclipse.tcf.te.ui.terminals.type.serial"); + + serialSettingsPage.extractData(data); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#fillSettingsForHost(java.lang.String) + */ + @Override + protected void fillSettingsForHost(String host){ + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#saveSettingsForHost(boolean) + */ + @Override + protected void saveSettingsForHost(boolean add){ + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.controls.panels.AbstractWizardConfigurationPanel#isValid() + */ + @Override + public boolean isValid(){ + return serialSettingsPage.isValid(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#doSaveWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) + */ + @Override + public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) { + serialSettingsPage.doSaveWidgetValues(settings, idPrefix); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#doRestoreWidgetValues(org.eclipse.jface.dialogs.IDialogSettings, java.lang.String) + */ + @Override + public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) { + serialSettingsPage.doRestoreWidgetValues(settings, idPrefix); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#getHostFromSettings() + */ + @Override + protected String getHostFromSettings() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.panels.AbstractConfigurationPanel#isWithHostList() + */ + @Override + public boolean isWithHostList() { + return false; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/launcher/SerialLauncherDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/launcher/SerialLauncherDelegate.java new file mode 100644 index 000000000..eb03def86 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/launcher/SerialLauncherDelegate.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.terminals.serial.launcher; + +import java.text.DateFormat; +import java.util.Date; + +import org.eclipse.osgi.util.NLS; +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.services.ServiceManager; +import org.eclipse.tcf.te.runtime.services.interfaces.ITerminalService; +import org.eclipse.tcf.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants; +import org.eclipse.tcf.te.ui.controls.BaseDialogPageControl; +import org.eclipse.tcf.te.ui.terminals.interfaces.IConfigurationPanel; +import org.eclipse.tcf.te.ui.terminals.launcher.AbstractLauncherDelegate; +import org.eclipse.tcf.te.ui.terminals.serial.controls.SerialWizardConfigurationPanel; +import org.eclipse.tcf.te.ui.terminals.serial.nls.Messages; + +/** + * Serial launcher delegate implementation. + */ +public class SerialLauncherDelegate extends AbstractLauncherDelegate { + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#needsUserConfiguration() + */ + @Override + public boolean needsUserConfiguration() { + return true; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#getPanel(org.eclipse.tcf.te.ui.controls.BaseDialogPageControl) + */ + @Override + public IConfigurationPanel getPanel(BaseDialogPageControl parentControl) { + return new SerialWizardConfigurationPanel(parentControl); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate#execute(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) + */ + @Override + public void execute(IPropertiesContainer properties, ICallback callback) { + // Set the terminal tab title + String terminalTitle = getTerminalTitle(properties); + if (terminalTitle != null) { + properties.setProperty(ITerminalsConnectorConstants.PROP_TITLE, terminalTitle); + } + + // Get the terminal service + ITerminalService terminal = ServiceManager.getInstance().getService(ITerminalService.class); + // If not available, we cannot fulfill this request + if (terminal != null) { + terminal.openConsole(properties, callback); + } + } + + /** + * Returns the terminal title string. + * <p> + * The default implementation constructs a title like "Serial <port> (Start time) ". + * + * @return The terminal title string or <code>null</code>. + */ + private String getTerminalTitle(IPropertiesContainer properties) { + String port = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_DEVICE); + + if (port != null) { + DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); + String date = format.format(new Date(System.currentTimeMillis())); + return NLS.bind(Messages.SerialLauncherDelegate_terminalTitle, new String[]{port, date}); + } + return Messages.SerialLauncherDelegate_terminalTitle_default; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/nls/Messages.java new file mode 100644 index 000000000..474a0367f --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/nls/Messages.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.tcf.te.ui.terminals.serial.nls; + +import org.eclipse.osgi.util.NLS; + +/** + * Externalized strings management. + */ +public class Messages extends NLS { + + // The plug-in resource bundle name + private static final String BUNDLE_NAME = "org.eclipse.tcf.te.ui.terminals.serial.nls.Messages"; //$NON-NLS-1$ + + /** + * Static constructor. + */ + static { + // Load message values from bundle file + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + // **** Declare externalized string id's down here ***** + + public static String SerialLauncherDelegate_terminalTitle; + public static String SerialLauncherDelegate_terminalTitle_default; +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/nls/Messages.properties new file mode 100644 index 000000000..06ae9fbc0 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/nls/Messages.properties @@ -0,0 +1,7 @@ +# +# org.eclipse.tcf.te.ui.terminals.serial +# Externalized Strings. +# + +SerialLauncherDelegate_terminalTitle=Serial {0} ({1}) +SerialLauncherDelegate_terminalTitle_default=Serial Terminal diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/types/SerialConnectorType.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/types/SerialConnectorType.java new file mode 100644 index 000000000..fb9891b7f --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals.serial/src/org/eclipse/tcf/te/ui/terminals/serial/types/SerialConnectorType.java @@ -0,0 +1,99 @@ +/*******************************************************************************
+ * Copyright (c) 2012 Wind River Systems, Inc. and others. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tcf.te.ui.terminals.serial.types;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer;
+import org.eclipse.tcf.te.runtime.services.interfaces.constants.ITerminalsConnectorConstants;
+import org.eclipse.tcf.te.ui.terminals.internal.SettingsStore;
+import org.eclipse.tcf.te.ui.terminals.types.AbstractConnectorType;
+import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
+import org.eclipse.tm.internal.terminal.provisional.api.ITerminalConnector;
+import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorExtension;
+import org.eclipse.tm.internal.terminal.serial.SerialSettings;
+
+/**
+ * Serial terminal connector type implementation.
+ */
+@SuppressWarnings("restriction")
+public class SerialConnectorType extends AbstractConnectorType {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.tcf.te.ui.terminals.interfaces.IConnectorType#createTerminalConnector(org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer)
+ */
+ @Override
+ public ITerminalConnector createTerminalConnector(IPropertiesContainer properties) {
+ Assert.isNotNull(properties);
+
+ // Check for the terminal connector id
+ String connectorId = properties.getStringProperty(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID);
+
+ String port = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_DEVICE);
+ String baud = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_BAUD_RATE);
+ String timeout = properties.getStringProperty(ITerminalsConnectorConstants.PROP_TIMEOUT);
+ String databits = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_DATA_BITS);
+ String stopbits = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_STOP_BITS);
+ String parity = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_PARITY);
+ String flowcontrol = properties.getStringProperty(ITerminalsConnectorConstants.PROP_SERIAL_FLOW_CONTROL);
+
+ return createSerialConnector(connectorId, new String[] { port, baud, timeout, databits, stopbits, parity, flowcontrol }, 0);
+ }
+
+ /**
+ * Creates a terminal connector object based on the given serial attributes.
+ * <p>
+ *
+ * @param connectorId The terminal connector id or <code>null</code>.
+ * @param attributes The serial attributes. Must not be <code>null</code> and must have at least two elements.
+ * @param portOffset Offset to add to the port.
+ *
+ * @return The terminal connector object instance or <code>null</code>.
+ */
+ protected ITerminalConnector createSerialConnector(String connectorId, String[] attributes, int portOffset) {
+ Assert.isNotNull(attributes);
+
+ if (connectorId == null) connectorId = "org.eclipse.tm.internal.terminal.serial.SerialConnector"; //$NON-NLS-1$
+
+ final String port = attributes[0];
+ final String baud = attributes[1];
+ final String timeout = attributes[2];
+ final String databits = attributes[3];
+ final String stopbits = attributes[4];
+ final String parity = attributes[5];
+ final String flowcontrol = attributes[6];
+
+ // Construct the terminal settings store
+ ISettingsStore store = new SettingsStore();
+
+ // Construct the serial settings
+ SerialSettings serialSettings = new SerialSettings();
+ serialSettings.setSerialPort(port);
+ serialSettings.setBaudRate(baud);
+ serialSettings.setTimeout(timeout);
+ serialSettings.setDataBits(databits);
+ serialSettings.setStopBits(stopbits);
+ serialSettings.setParity(parity);
+ serialSettings.setFlowControl(flowcontrol);
+
+ // And save the settings to the store
+ serialSettings.save(store);
+
+ // Construct the terminal connector instance
+ ITerminalConnector connector = TerminalConnectorExtension.makeTerminalConnector(connectorId);
+ if (connector != null) {
+ // Apply default settings
+ connector.makeSettingsPage();
+ // And load the real settings
+ connector.load(store);
+ }
+
+ return connector;
+ }
+}
|