/******************************************************************************* * Copyright (c) 2015 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 *******************************************************************************/ package org.eclipse.cdt.arduino.ui.internal.remote; import java.lang.reflect.InvocationTargetException; import org.eclipse.cdt.arduino.ui.internal.Activator; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.jface.operation.IRunnableContext; import org.eclipse.jface.operation.IRunnableWithProgress; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.remote.core.IRemoteConnection; import org.eclipse.remote.core.IRemoteConnectionType; import org.eclipse.remote.core.IRemoteConnectionType.Service; import org.eclipse.remote.core.exception.RemoteConnectionException; import org.eclipse.remote.ui.AbstractRemoteUIConnectionService; import org.eclipse.remote.ui.IRemoteUIConnectionService; import org.eclipse.remote.ui.IRemoteUIConnectionWizard; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Shell; public class ArduinoRemoteServicesUI extends AbstractRemoteUIConnectionService { private final IRemoteConnectionType connectionType; public ArduinoRemoteServicesUI(IRemoteConnectionType connectionType) { this.connectionType = connectionType; } @Override public void openConnectionWithProgress(Shell shell, IRunnableContext context, final IRemoteConnection connection) { try { context.run(false, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { connection.open(monitor); } catch (RemoteConnectionException e) { Activator.getDefault().getLog().log(e.getStatus()); } } }); } catch (InvocationTargetException | InterruptedException e) { Activator.getDefault().getLog() .log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage(), e)); } } @Override public IRemoteConnectionType getConnectionType() { return connectionType; } @Override public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) { return new NewArduinoTargetWizard(); } @Override public ILabelProvider getLabelProvider() { return new DefaultLabelProvider() { @Override public Image getImage(Object element) { return Activator.getDefault().getImageRegistry().get(Activator.IMG_CONNECTION_TYPE); } }; } public static class Factory implements IRemoteConnectionType.Service.Factory { @SuppressWarnings("unchecked") @Override public <T extends Service> T getService(IRemoteConnectionType connectionType, Class<T> service) { if (IRemoteUIConnectionService.class.equals(service)) { return (T) new ArduinoRemoteServicesUI(connectionType); } return null; } } }