Bug 491192 - Add SerialPortConnectionPropertyPage
Change-Id: If95f04b716e7e861bfebc010ba2d580457d4e5dd
Signed-off-by: Jonathan Williams <jonwilliams@qnx.com>
diff --git a/bundles/org.eclipse.remote.serial.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.serial.ui/META-INF/MANIFEST.MF
index c34fe7e..78fb0ea 100644
--- a/bundles/org.eclipse.remote.serial.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.remote.serial.ui/META-INF/MANIFEST.MF
@@ -10,9 +10,11 @@
Bundle-Localization: plugin
Export-Package: org.eclipse.remote.serial.ui
Import-Package: org.eclipse.cdt.serial,
+ org.eclipse.core.expressions,
org.eclipse.core.runtime,
org.eclipse.jface.dialogs,
org.eclipse.jface.operation,
+ org.eclipse.jface.preference,
org.eclipse.jface.resource,
org.eclipse.jface.viewers,
org.eclipse.jface.window,
@@ -27,5 +29,7 @@
org.eclipse.swt.graphics,
org.eclipse.swt.layout,
org.eclipse.swt.widgets,
+ org.eclipse.ui,
+ org.eclipse.ui.dialogs,
org.eclipse.ui.plugin,
org.osgi.framework
diff --git a/bundles/org.eclipse.remote.serial.ui/plugin.xml b/bundles/org.eclipse.remote.serial.ui/plugin.xml
index ce978ae..2026497 100644
--- a/bundles/org.eclipse.remote.serial.ui/plugin.xml
+++ b/bundles/org.eclipse.remote.serial.ui/plugin.xml
@@ -9,5 +9,31 @@
service="org.eclipse.remote.ui.IRemoteUIConnectionService">
</connectionTypeService>
</extension>
-
+ <extension
+ point="org.eclipse.core.expressions.propertyTesters">
+ <propertyTester
+ class="org.eclipse.remote.serial.internal.ui.SerialPortConnectionPropertyTester"
+ id="remoteTester"
+ namespace="org.eclipse.remote.serial.ui"
+ properties="isSerialRemote"
+ type="org.eclipse.remote.core.IRemoteConnection">
+ </propertyTester>
+ </extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ class="org.eclipse.remote.serial.ui.SerialPortConnectionPropertyPage"
+ id="org.eclipse.remote.serial.ui.targetPropertyPage"
+ name="Serial Port Settings"
+ selectionFilter="single">
+ <enabledWhen>
+ <adapt type="org.eclipse.remote.core.IRemoteConnection">
+ <test
+ forcePluginActivation="false"
+ property="org.eclipse.remote.serial.ui.isSerialRemote">
+ </test>
+ </adapt>
+ </enabledWhen>
+ </page>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/internal/ui/SerialPortConnectionPropertyTester.java b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/internal/ui/SerialPortConnectionPropertyTester.java
new file mode 100644
index 0000000..ef20b70
--- /dev/null
+++ b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/internal/ui/SerialPortConnectionPropertyTester.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems, 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:
+ * QNX Software Systems - initial contribution
+ *******************************************************************************/
+package org.eclipse.remote.serial.internal.ui;
+
+import org.eclipse.core.expressions.PropertyTester;
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.serial.core.ISerialPortService;
+
+public class SerialPortConnectionPropertyTester extends PropertyTester {
+
+ @Override
+ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
+ if (receiver instanceof IRemoteConnection) {
+ IRemoteConnection remote = (IRemoteConnection) receiver;
+ return remote.hasService(ISerialPortService.class);
+ } else {
+ return false;
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizard.java b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizard.java
index 8f84cf2..c5948fa 100644
--- a/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizard.java
+++ b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizard.java
@@ -69,7 +69,7 @@
public IRemoteConnectionWorkingCopy getConnection() {
if (workingCopy == null) {
try {
- workingCopy = connectionType.newConnection(page.getName());
+ workingCopy = connectionType.newConnection(page.getConnectionName());
} catch (RemoteConnectionException e) {
Activator.log(e.getStatus());
}
diff --git a/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizardPage.java b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizardPage.java
index ee80654..1ef2c22 100644
--- a/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizardPage.java
+++ b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/NewSerialPortConnectionWizardPage.java
@@ -10,200 +10,61 @@
*******************************************************************************/
package org.eclipse.remote.serial.ui;
-import java.io.IOException;
-
-import org.eclipse.cdt.serial.BaudRate;
-import org.eclipse.cdt.serial.ByteSize;
-import org.eclipse.cdt.serial.Parity;
-import org.eclipse.cdt.serial.SerialPort;
-import org.eclipse.cdt.serial.StopBits;
import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.remote.serial.internal.ui.Activator;
import org.eclipse.remote.serial.internal.ui.Messages;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-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.Label;
-import org.eclipse.swt.widgets.Text;
public class NewSerialPortConnectionWizardPage extends WizardPage {
-
- private String name;
- private String portName;
- private int baudRateIndex;
- private int byteSizeIndex;
- private int parityIndex;
- private int stopBitsIndex;
-
- private String[] portNames;
-
- private Text nameText;
- private Combo portCombo;
- private Combo baudRateCombo;
- private Combo byteSizeCombo;
- private Combo parityCombo;
- private Combo stopBitsCombo;
+
+ SerialPortConnectionBlock block;
public NewSerialPortConnectionWizardPage() {
super(NewSerialPortConnectionWizardPage.class.getName());
setDescription(Messages.NewSerialPortConnectionWizardPage_Description);
setTitle(Messages.NewSerialPortConnectionWizardPage_Title);
+ block = new SerialPortConnectionBlock();
+ block.addUpdateListener(block.new SerialBlockUpdateListener() {
+
+ @Override
+ public void update() {
+ setPageComplete(block.isComplete());
+ }
+
+ });
}
@Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
- comp.setLayout(new GridLayout(2, false));
-
- Label nameLabel = new Label(comp, SWT.NONE);
- nameLabel.setText(Messages.NewSerialPortConnectionWizardPage_NameLabel);
-
- nameText = new Text(comp, SWT.BORDER | SWT.SINGLE);
- nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- nameText.setText(""); //$NON-NLS-1$
- nameText.addKeyListener(new KeyListener() {
- @Override
- public void keyReleased(KeyEvent e) {
- updateStatus();
- }
-
- @Override
- public void keyPressed(KeyEvent e) {
- }
- });
-
- Label portLabel = new Label(comp, SWT.NONE);
- portLabel.setText(Messages.NewSerialPortConnectionWizardPage_PortLabel);
-
- portCombo = new Combo(comp, SWT.READ_ONLY);
- portCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- try {
- portNames = SerialPort.list();
- } catch (IOException e) {
- Activator.log(e);
- }
- for (String portName : portNames) {
- portCombo.add(portName);
- }
- portCombo.select(0);
- portCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateStatus();
- }
- });
-
- Label baudRateLabel = new Label(comp, SWT.NONE);
- baudRateLabel.setText(Messages.NewSerialPortConnectionWizardPage_BaudRateLabel);
-
- baudRateCombo = new Combo(comp, SWT.READ_ONLY);
- baudRateCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- for (String baudRateStr : BaudRate.getStrings()) {
- baudRateCombo.add(baudRateStr);
- }
- // TODO remember the last one
- baudRateCombo.select(BaudRate.getStringIndex(BaudRate.getDefault()));
- baudRateCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateStatus();
- }
- });
-
- Label byteSizeLabel = new Label(comp, SWT.NONE);
- byteSizeLabel.setText(Messages.NewSerialPortConnectionWizardPage_ByteSizeLabel);
-
- byteSizeCombo = new Combo(comp, SWT.READ_ONLY);
- byteSizeCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- for (String byteSizeStr : ByteSize.getStrings()) {
- byteSizeCombo.add(byteSizeStr);
- }
- byteSizeCombo.select(ByteSize.getStringIndex(ByteSize.getDefault()));
- byteSizeCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateStatus();
- }
- });
-
- Label parityLabel = new Label(comp, SWT.NONE);
- parityLabel.setText(Messages.NewSerialPortConnectionWizardPage_ParityLabel);
-
- parityCombo = new Combo(comp, SWT.READ_ONLY);
- parityCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- for (String parityStr : Parity.getStrings()) {
- parityCombo.add(parityStr);
- }
- parityCombo.select(Parity.getStringIndex(Parity.getDefault()));
- parityCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateStatus();
- }
- });
-
- Label stopBitsLabel = new Label(comp, SWT.NONE);
- stopBitsLabel.setText(Messages.NewSerialPortConnectionWizardPage_StopBitsLabel);
-
- stopBitsCombo = new Combo(comp, SWT.READ_ONLY);
- stopBitsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- for (String stopBitsStr : StopBits.getStrings()) {
- stopBitsCombo.add(stopBitsStr);
- }
- stopBitsCombo.select(StopBits.getStringIndex(StopBits.getDefault()));
- stopBitsCombo.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateStatus();
- }
- });
-
+ comp.setLayout(new GridLayout(2, false));
+ block.createBlock(comp, null);
setControl(comp);
- updateStatus();
}
- private void updateStatus() {
- name = nameText.getText();
-
- int portIndex = portCombo.getSelectionIndex();
- portName = portIndex < 0 ? null : portNames[portIndex];
-
- baudRateIndex = baudRateCombo.getSelectionIndex();
- byteSizeIndex = byteSizeCombo.getSelectionIndex();
- parityIndex = parityCombo.getSelectionIndex();
- stopBitsIndex = stopBitsCombo.getSelectionIndex();
-
- setPageComplete(!name.isEmpty() && portName != null);
- }
-
- public String getName() {
- return name;
+ public String getConnectionName() {
+ return block.getConnectionName();
}
public String getPortName() {
- return portName;
+ return block.getPortName();
}
public int getBaudRateIndex() {
- return baudRateIndex;
+ return block.getBaudRateIndex();
}
public int getByteSizeIndex() {
- return byteSizeIndex;
+ return block.getByteSizeIndex();
}
public int getParityIndex() {
- return parityIndex;
+ return block.getParityIndex();
}
public int getStopBitsIndex() {
- return stopBitsIndex;
+ return block.getStopBitsIndex();
}
}
diff --git a/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/SerialPortConnectionBlock.java b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/SerialPortConnectionBlock.java
new file mode 100644
index 0000000..c5a0de7
--- /dev/null
+++ b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/SerialPortConnectionBlock.java
@@ -0,0 +1,253 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems, 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:
+ * QNX Software Systems - initial contribution
+ *******************************************************************************/
+package org.eclipse.remote.serial.ui;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.serial.BaudRate;
+import org.eclipse.cdt.serial.ByteSize;
+import org.eclipse.cdt.serial.Parity;
+import org.eclipse.cdt.serial.SerialPort;
+import org.eclipse.cdt.serial.StopBits;
+import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
+import org.eclipse.remote.serial.core.ISerialPortService;
+import org.eclipse.remote.serial.internal.ui.Activator;
+import org.eclipse.remote.serial.internal.ui.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class SerialPortConnectionBlock {
+
+ private String name;
+ private String portName;
+ private int baudRateIndex;
+ private int byteSizeIndex;
+ private int parityIndex;
+ private int stopBitsIndex;
+
+ private String[] portNames;
+
+ private Text nameText;
+ private Combo portCombo;
+ private Combo baudRateCombo;
+ private Combo byteSizeCombo;
+ private Combo parityCombo;
+ private Combo stopBitsCombo;
+
+ private boolean isComplete;
+ private List<SerialBlockUpdateListener> listeners = new ArrayList<>();
+
+
+ /**
+ * Creates the UI elements for the SerialPortConnectionBlock
+ *
+ * @param comp - parent composite
+ * @param wc - an IRemoteConnectionWorkingCopy to populate the default values from. Can be null.
+ */
+ public void createBlock(Composite comp, IRemoteConnectionWorkingCopy wc) {
+
+ String name = "";
+ String connectionPortName = "";
+ int baudRateStringIndex = BaudRate.getStringIndex(BaudRate.getDefault());
+ int byteSizeStringIndex = ByteSize.getStringIndex(ByteSize.getDefault());
+ int parityStringIndex = Parity.getStringIndex(Parity.getDefault());
+ int stopBitsStringIndex = StopBits.getStringIndex(StopBits.getDefault());
+
+ if (wc != null) {
+ name = wc.getName();
+ connectionPortName = wc.getAttribute(ISerialPortService.PORT_NAME_ATTR);
+ baudRateStringIndex = Integer.parseInt(wc.getAttribute(ISerialPortService.BAUD_RATE_ATTR));
+ byteSizeStringIndex = Integer.parseInt(wc.getAttribute(ISerialPortService.BYTE_SIZE_ATTR));
+ parityStringIndex = Integer.parseInt(wc.getAttribute(ISerialPortService.PARITY_ATTR));
+ stopBitsStringIndex = Integer.parseInt(wc.getAttribute(ISerialPortService.STOP_BITS_ATTR));
+ }
+
+ Label nameLabel = new Label(comp, SWT.NONE);
+ nameLabel.setText(Messages.NewSerialPortConnectionWizardPage_NameLabel);
+
+ nameText = new Text(comp, SWT.BORDER | SWT.SINGLE);
+ nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ nameText.setText(name); //$NON-NLS-1$
+ nameText.addKeyListener(new KeyListener() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ updateStatus();
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ }
+ });
+
+ Label portLabel = new Label(comp, SWT.NONE);
+ portLabel.setText(Messages.NewSerialPortConnectionWizardPage_PortLabel);
+
+ portCombo = new Combo(comp, SWT.READ_ONLY);
+ portCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ try {
+ portNames = SerialPort.list();
+ } catch (IOException e) {
+ Activator.log(e);
+ }
+ int index = 0;
+ int portNameIndex = 0;
+ for (String portName : portNames) {
+ portCombo.add(portName);
+ if (portName.equals(connectionPortName))
+ portNameIndex = index;
+ index++;
+ }
+ portCombo.select(portNameIndex);
+ portCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateStatus();
+ }
+ });
+
+ Label baudRateLabel = new Label(comp, SWT.NONE);
+ baudRateLabel.setText(Messages.NewSerialPortConnectionWizardPage_BaudRateLabel);
+
+ baudRateCombo = new Combo(comp, SWT.READ_ONLY);
+ baudRateCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ for (String baudRateStr : BaudRate.getStrings()) {
+ baudRateCombo.add(baudRateStr);
+ }
+
+ baudRateCombo.select(baudRateStringIndex);
+ baudRateCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateStatus();
+ }
+ });
+
+ Label byteSizeLabel = new Label(comp, SWT.NONE);
+ byteSizeLabel.setText(Messages.NewSerialPortConnectionWizardPage_ByteSizeLabel);
+
+ byteSizeCombo = new Combo(comp, SWT.READ_ONLY);
+ byteSizeCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ for (String byteSizeStr : ByteSize.getStrings()) {
+ byteSizeCombo.add(byteSizeStr);
+ }
+ byteSizeCombo.select(byteSizeStringIndex);
+ byteSizeCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateStatus();
+ }
+ });
+
+ Label parityLabel = new Label(comp, SWT.NONE);
+ parityLabel.setText(Messages.NewSerialPortConnectionWizardPage_ParityLabel);
+
+ parityCombo = new Combo(comp, SWT.READ_ONLY);
+ parityCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ for (String parityStr : Parity.getStrings()) {
+ parityCombo.add(parityStr);
+ }
+ parityCombo.select(parityStringIndex);
+ parityCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateStatus();
+ }
+ });
+
+ Label stopBitsLabel = new Label(comp, SWT.NONE);
+ stopBitsLabel.setText(Messages.NewSerialPortConnectionWizardPage_StopBitsLabel);
+
+ stopBitsCombo = new Combo(comp, SWT.READ_ONLY);
+ stopBitsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ for (String stopBitsStr : StopBits.getStrings()) {
+ stopBitsCombo.add(stopBitsStr);
+ }
+ stopBitsCombo.select(stopBitsStringIndex);
+ stopBitsCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateStatus();
+ }
+ });
+
+
+ updateStatus();
+ }
+
+ private void updateStatus() {
+ name = nameText.getText();
+
+ int portIndex = portCombo.getSelectionIndex();
+ portName = portIndex < 0 ? null : portNames[portIndex];
+
+ baudRateIndex = baudRateCombo.getSelectionIndex();
+ byteSizeIndex = byteSizeCombo.getSelectionIndex();
+ parityIndex = parityCombo.getSelectionIndex();
+ stopBitsIndex = stopBitsCombo.getSelectionIndex();
+
+ isComplete = (!name.isEmpty() && portName != null);
+
+ for(SerialBlockUpdateListener listener : listeners) {
+ listener.update();
+ }
+ }
+
+ public String getConnectionName() {
+ return name;
+ }
+
+ public String getPortName() {
+ return portName;
+ }
+
+ public int getBaudRateIndex() {
+ return baudRateIndex;
+ }
+
+ public int getByteSizeIndex() {
+ return byteSizeIndex;
+ }
+
+ public int getParityIndex() {
+ return parityIndex;
+ }
+
+ public int getStopBitsIndex() {
+ return stopBitsIndex;
+ }
+
+ public boolean isComplete() {
+ return isComplete;
+ }
+
+ public void addUpdateListener(SerialBlockUpdateListener listener) {
+ if (listener != null && !listeners.contains(listener))
+ listeners.add(listener);
+ }
+
+ public void removeUpdateListener(SerialBlockUpdateListener listener) {
+ listeners.remove(listener);
+ }
+
+ public abstract class SerialBlockUpdateListener {
+ public abstract void update();
+ }
+}
diff --git a/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/SerialPortConnectionPropertyPage.java b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/SerialPortConnectionPropertyPage.java
new file mode 100644
index 0000000..2d6ed88
--- /dev/null
+++ b/bundles/org.eclipse.remote.serial.ui/src/org/eclipse/remote/serial/ui/SerialPortConnectionPropertyPage.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems, 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:
+ * QNX Software Systems - initial contribution
+ *******************************************************************************/
+package org.eclipse.remote.serial.ui;
+
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
+import org.eclipse.remote.serial.core.ISerialPortService;
+import org.eclipse.remote.serial.internal.ui.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbenchPropertyPage;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+
+public class SerialPortConnectionPropertyPage extends PropertyPage implements IWorkbenchPropertyPage {
+
+ private SerialPortConnectionBlock block;
+ private IRemoteConnectionWorkingCopy workingCopy;
+
+ public SerialPortConnectionPropertyPage() {
+ super();
+ block = new SerialPortConnectionBlock();
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ Composite comp = new Composite(parent, SWT.NONE);
+ comp.setLayout(new GridLayout(2, false));
+
+ block.addUpdateListener(block.new SerialBlockUpdateListener() {
+
+ @Override
+ public void update() {
+ setValid(block.isComplete());
+ }
+
+ });
+
+ IRemoteConnection remoteConnection = getElement().getAdapter(IRemoteConnection.class);
+ if (remoteConnection != null)
+ workingCopy = remoteConnection.getWorkingCopy();
+ else
+ workingCopy = null;
+
+
+ block.createBlock(comp, workingCopy);
+ return comp;
+ }
+
+ @Override
+ public boolean performOk() {
+ if (workingCopy != null) {
+
+ workingCopy.setName(block.getConnectionName());
+ workingCopy.setAttribute(ISerialPortService.PORT_NAME_ATTR, block.getPortName());
+ workingCopy.setAttribute(ISerialPortService.BAUD_RATE_ATTR, Integer.toString(block.getBaudRateIndex()));
+ workingCopy.setAttribute(ISerialPortService.BYTE_SIZE_ATTR, Integer.toString(block.getByteSizeIndex()));
+ workingCopy.setAttribute(ISerialPortService.PARITY_ATTR, Integer.toString(block.getParityIndex()));
+ workingCopy.setAttribute(ISerialPortService.STOP_BITS_ATTR, Integer.toString(block.getStopBitsIndex()));
+ try {
+ workingCopy.save();
+ } catch (RemoteConnectionException e) {
+ Activator.log(e);
+ return false;
+ }
+
+ }
+
+ return true;
+ }
+
+}