1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

Bug 539328 - Fix NPE in NewArduinoTargetWizard

Arduino-Connections can be created and edited using Preferences->Remote
Development->Remote Connections.

Change-Id: Ie92330689bdad4987c12d2bd17828dbe5e862b90
Signed-off-by: Lutz Hamann <lhamann@planettime.de>
This commit is contained in:
Lutz Hamann 2018-12-11 08:50:11 +01:00 committed by Doug Schaefer
parent 0f75bfc383
commit c78246edea
4 changed files with 106 additions and 10 deletions

View file

@ -63,7 +63,7 @@ public class ArduinoRemoteServicesUI extends AbstractRemoteUIConnectionService {
@Override @Override
public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) { public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) {
return new NewArduinoTargetWizard(); return new NewArduinoTargetWizard(shell, connectionType);
} }
@Override @Override

View file

@ -167,7 +167,7 @@ public class BoardPropertyControl extends Composite {
HierarchicalProperties programmers = board.getPlatform().getProgrammers(); HierarchicalProperties programmers = board.getPlatform().getProgrammers();
if (programmers != null && programmers.getChildren() != null) { if (programmers != null && programmers.getChildren() != null) {
programmerLabel = new Label(this, SWT.NONE); programmerLabel = new Label(this, SWT.NONE);
programmerLabel.setText("Programmer:"); programmerLabel.setText("Programmer:"); //$NON-NLS-1$
programmerCombo = new Combo(this, SWT.READ_ONLY); programmerCombo = new Combo(this, SWT.READ_ONLY);
programmerCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); programmerCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
@ -243,4 +243,44 @@ public class BoardPropertyControl extends Composite {
} }
} }
public void updateFromOriginal(ArduinoRemoteConnection arduinoService) throws CoreException {
// Set and select the portname
portCombo.setText(arduinoService.getPortName());
portName = arduinoService.getPortName();
// Set and select the board
boardCombo.setText(arduinoService.getBoard().getName());
boardChanged();
// Lock changing of board
boardCombo.setEnabled(false);
// Set the programmer
if (!arduinoService.getProgrammer().isEmpty() && programmerCombo != null && !programmerCombo.isDisposed()) {
programmerCombo.setText(board.getPlatform().getProgrammers().getChild(arduinoService.getProgrammer())
.getChild("name").getValue()); //$NON-NLS-1$
}
// Set all properties based on the displayed Controls.
String key = null;
// Loop over all controls. Labels and corresponding combos are saved in order
for (Control control : menuControls) {
if (control instanceof Label) {
// the label is the key
key = (String) control.getData();
} else if (control instanceof Combo) {
if (key != null && !arduinoService.getMenuValue(key).isEmpty()) {
String selectableValue = board.getMenus().getChild(key).getChild(arduinoService.getMenuValue(key))
.getValue();
((Combo) control).setText(selectableValue);
}
// reset key
key = null;
} else {
// unexpected order - reset key
key = null;
}
}
}
} }

View file

@ -16,11 +16,13 @@ import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.cdt.arduino.ui.internal.Activator; import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionType;
import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
import org.eclipse.remote.core.IRemoteServicesManager; import org.eclipse.remote.core.IRemoteServicesManager;
import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.core.exception.RemoteConnectionException;
import org.eclipse.remote.ui.IRemoteUIConnectionWizard; import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.INewWizard; import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbench;
@ -29,6 +31,18 @@ public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectio
private NewArduinoTargetWizardPage page; private NewArduinoTargetWizardPage page;
private IRemoteConnectionWorkingCopy workingCopy; private IRemoteConnectionWorkingCopy workingCopy;
private boolean isNewWizard; private boolean isNewWizard;
private Shell shell;
private IRemoteConnectionType connectionType;
public NewArduinoTargetWizard(Shell shell, IRemoteConnectionType connectionType) {
this.shell = shell;
this.connectionType = connectionType;
}
public NewArduinoTargetWizard() {
this.connectionType = Activator.getService(IRemoteServicesManager.class)
.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
}
@Override @Override
public void init(IWorkbench workbench, IStructuredSelection selection) { public void init(IWorkbench workbench, IStructuredSelection selection) {
@ -38,6 +52,10 @@ public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectio
@Override @Override
public void addPages() { public void addPages() {
page = new NewArduinoTargetWizardPage(); page = new NewArduinoTargetWizardPage();
// Editing an existing Connection
if (workingCopy != null) {
page.setWorkingCopy(workingCopy);
}
addPage(page); addPage(page);
} }
@ -63,16 +81,19 @@ public class NewArduinoTargetWizard extends Wizard implements IRemoteUIConnectio
@Override @Override
public IRemoteConnectionWorkingCopy open() { public IRemoteConnectionWorkingCopy open() {
return getConnection(); WizardDialog dialog = new WizardDialog(shell, this);
dialog.setBlockOnOpen(true);
if (dialog.open() == WizardDialog.OK) {
return getConnection();
}
return null;
} }
@Override @Override
public IRemoteConnectionWorkingCopy getConnection() { public IRemoteConnectionWorkingCopy getConnection() {
if (workingCopy == null) { if (workingCopy == null) {
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
IRemoteConnectionType connectionType = remoteManager.getConnectionType(ArduinoRemoteConnection.TYPE_ID);
try { try {
workingCopy = connectionType.newConnection(page.name); workingCopy = connectionType.newConnection(page.getConnectionName());
} catch (RemoteConnectionException e) { } catch (RemoteConnectionException e) {
Activator.getDefault().getLog().log(e.getStatus()); Activator.getDefault().getLog().log(e.getStatus());
return null; return null;

View file

@ -10,7 +10,10 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.remote; package org.eclipse.cdt.arduino.ui.internal.remote;
import org.eclipse.cdt.arduino.core.internal.remote.ArduinoRemoteConnection;
import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.cdt.arduino.ui.internal.Messages; import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.remote.core.IRemoteConnectionWorkingCopy; import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -26,8 +29,9 @@ import org.eclipse.swt.widgets.Text;
public class NewArduinoTargetWizardPage extends WizardPage { public class NewArduinoTargetWizardPage extends WizardPage {
String name; private String connectionName;
private Text nameText; private Text nameText;
private IRemoteConnectionWorkingCopy workingCopy;
BoardPropertyControl boardControl; BoardPropertyControl boardControl;
@ -55,7 +59,7 @@ public class NewArduinoTargetWizardPage extends WizardPage {
nameText.addKeyListener(new KeyListener() { nameText.addKeyListener(new KeyListener() {
@Override @Override
public void keyReleased(KeyEvent e) { public void keyReleased(KeyEvent e) {
name = nameText.getText(); connectionName = nameText.getText();
updateStatus(); updateStatus();
} }
@ -73,12 +77,18 @@ public class NewArduinoTargetWizardPage extends WizardPage {
} }
}); });
try {
updateFromWorkingCopy();
} catch (CoreException e) {
Activator.log(e);
}
setControl(comp); setControl(comp);
setPageComplete(false); updateStatus();
} }
private void updateStatus() { private void updateStatus() {
setPageComplete(name != null && !name.isEmpty() && boardControl.getPortName() != null setPageComplete(connectionName != null && !connectionName.isEmpty() && boardControl.getPortName() != null
&& boardControl.getSelectedBoard() != null); && boardControl.getSelectedBoard() != null);
} }
@ -86,4 +96,29 @@ public class NewArduinoTargetWizardPage extends WizardPage {
boardControl.apply(workingCopy); boardControl.apply(workingCopy);
} }
public String getConnectionName() {
return connectionName;
}
public void setWorkingCopy(IRemoteConnectionWorkingCopy workingCopy) {
this.workingCopy = workingCopy;
}
private void updateFromWorkingCopy() throws CoreException {
if (null == workingCopy || null == workingCopy.getOriginal())
return;
ArduinoRemoteConnection arduinoService = workingCopy.getService(ArduinoRemoteConnection.class);
if (null == arduinoService)
return;
// Set the originalName and lock control for it
nameText.setText(workingCopy.getOriginal().getName());
nameText.setEnabled(false);
connectionName = workingCopy.getOriginal().getName();
// Set all other fields with existing data
boardControl.updateFromOriginal(arduinoService);
}
} }