mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 01:35:39 +02:00
Change remote target to new strategy. Allows individual types to reg.
Remote connection type providers must also register as target types if they want to show up in the launch bar. This change eliminates the autoregistering we were doing and instead provides reusable classes to handle the interface. Arduino does that coming up. Change-Id: Iafb9305225f1ba3b97640bb3b15bfb671888a914
This commit is contained in:
parent
302c601bac
commit
32bcbba8bb
10 changed files with 93 additions and 141 deletions
|
@ -10,4 +10,5 @@ Require-Bundle: org.eclipse.ui,
|
|||
org.eclipse.remote.core;bundle-version="2.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.launchbar.remote.core.internal;x-friends:="org.eclipse.launchbar.remote.ui"
|
||||
Export-Package: org.eclipse.launchbar.remote.core,
|
||||
org.eclipse.launchbar.remote.core.internal;x-friends:="org.eclipse.launchbar.remote.ui"
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="org.eclipse.launchbar.core.launchTargetTypes">
|
||||
<launchTargetType
|
||||
id="org.eclipse.launchbar.remote.core.launchTargetType"
|
||||
provider="org.eclipse.launchbar.remote.core.internal.RemoteLaunchTargetProvider">
|
||||
</launchTargetType>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.runtime.adapters">
|
||||
<factory
|
||||
|
|
|
@ -5,29 +5,38 @@
|
|||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*******************************************************************************/
|
||||
package org.eclipse.launchbar.remote.core.internal;
|
||||
package org.eclipse.launchbar.remote.core;
|
||||
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTargetProvider;
|
||||
import org.eclipse.launchbar.core.target.TargetStatus;
|
||||
import org.eclipse.launchbar.core.target.TargetStatus.Code;
|
||||
import org.eclipse.launchbar.remote.core.internal.Activator;
|
||||
import org.eclipse.launchbar.remote.core.internal.Messages;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||
import org.eclipse.remote.core.IRemoteConnectionType;
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||
|
||||
public class RemoteLaunchTargetProvider implements ILaunchTargetProvider {
|
||||
|
||||
public static final String TYPE_ID = "org.eclipse.launchbar.remote.core.launchTargetType"; //$NON-NLS-1$
|
||||
public static final String DELIMITER = "|"; //$NON-NLS-1$
|
||||
public abstract class RemoteLaunchTargetProvider implements ILaunchTargetProvider, IRemoteConnectionChangeListener {
|
||||
|
||||
private static final TargetStatus CLOSED = new TargetStatus(Code.ERROR, Messages.RemoteLaunchTargetProvider_Closed);
|
||||
|
||||
private ILaunchTargetManager targetManager;
|
||||
|
||||
protected abstract String getTypeId();
|
||||
|
||||
@Override
|
||||
public void init(ILaunchTargetManager targetManager) {
|
||||
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
|
||||
this.targetManager = targetManager;
|
||||
String typeId = getTypeId();
|
||||
|
||||
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
|
||||
// Remove missing ones
|
||||
for (ILaunchTarget target : targetManager.getLaunchTargetsOfType(TYPE_ID)) {
|
||||
for (ILaunchTarget target : targetManager.getLaunchTargetsOfType(typeId)) {
|
||||
IRemoteConnection connection = target.getAdapter(IRemoteConnection.class);
|
||||
if (connection == null) {
|
||||
targetManager.removeLaunchTarget(target);
|
||||
|
@ -35,17 +44,15 @@ public class RemoteLaunchTargetProvider implements ILaunchTargetProvider {
|
|||
}
|
||||
|
||||
// Add new ones
|
||||
// TODO filter out the Local connection?
|
||||
for (IRemoteConnection connection : manager.getAllRemoteConnections()) {
|
||||
String id = getTargetId(connection);
|
||||
if (targetManager.getLaunchTarget(TYPE_ID, id) == null) {
|
||||
targetManager.addLaunchTarget(TYPE_ID, id);
|
||||
IRemoteConnectionType remoteType = remoteManager.getConnectionType(typeId);
|
||||
for (IRemoteConnection remote : remoteType.getConnections()) {
|
||||
String id = remote.getName();
|
||||
if (targetManager.getLaunchTarget(typeId, id) == null) {
|
||||
targetManager.addLaunchTarget(typeId, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTargetId(IRemoteConnection connection) {
|
||||
return connection.getConnectionType().getId() + DELIMITER + connection.getName();
|
||||
remoteManager.addRemoteConnectionChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,4 +68,20 @@ public class RemoteLaunchTargetProvider implements ILaunchTargetProvider {
|
|||
return new TargetStatus(Code.ERROR, Messages.RemoteLaunchTargetProvider_Missing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionChanged(RemoteConnectionChangeEvent event) {
|
||||
IRemoteConnection connection = event.getConnection();
|
||||
switch (event.getType()) {
|
||||
case RemoteConnectionChangeEvent.CONNECTION_ADDED:
|
||||
targetManager.addLaunchTarget(getTypeId(), connection.getName());
|
||||
break;
|
||||
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
|
||||
ILaunchTarget target = targetManager.getLaunchTarget(getTypeId(), connection.getName());
|
||||
if (target != null) {
|
||||
targetManager.removeLaunchTarget(target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.launchbar.remote.core.internal;
|
||||
|
||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
@ -23,22 +22,14 @@ public class Activator extends AbstractUIPlugin {
|
|||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
private static RemoteConnectionListener remoteConnectionListener;
|
||||
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
|
||||
remoteConnectionListener = new RemoteConnectionListener();
|
||||
getService(IRemoteServicesManager.class).addRemoteConnectionChangeListener(remoteConnectionListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
getService(IRemoteServicesManager.class).removeRemoteConnectionChangeListener(remoteConnectionListener);
|
||||
remoteConnectionListener = null;
|
||||
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.remote.core.internal;
|
||||
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||
|
||||
public class RemoteConnectionListener implements IRemoteConnectionChangeListener {
|
||||
|
||||
private ILaunchTargetManager targetManager = Activator.getService(ILaunchTargetManager.class);
|
||||
|
||||
@Override
|
||||
public void connectionChanged(RemoteConnectionChangeEvent event) {
|
||||
IRemoteConnection connection = event.getConnection();
|
||||
switch (event.getType()) {
|
||||
case RemoteConnectionChangeEvent.CONNECTION_ADDED:
|
||||
targetManager.addLaunchTarget(RemoteLaunchTargetProvider.TYPE_ID,
|
||||
RemoteLaunchTargetProvider.getTargetId(connection));
|
||||
break;
|
||||
case RemoteConnectionChangeEvent.CONNECTION_REMOVED:
|
||||
ILaunchTarget target = targetManager.getLaunchTarget(RemoteLaunchTargetProvider.TYPE_ID,
|
||||
RemoteLaunchTargetProvider.getTargetId(connection));
|
||||
if (target != null) {
|
||||
targetManager.removeLaunchTarget(target);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -15,21 +15,16 @@ import org.eclipse.remote.core.IRemoteServicesManager;
|
|||
|
||||
public class RemoteTargetAdapterFactory implements IAdapterFactory {
|
||||
|
||||
private static final IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
|
||||
private static final IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
|
||||
if (adaptableObject instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) adaptableObject;
|
||||
if (target.getTypeId().equals(RemoteLaunchTargetProvider.TYPE_ID)) {
|
||||
String[] list = target.getId().split("\\" + RemoteLaunchTargetProvider.DELIMITER); //$NON-NLS-1$
|
||||
if (list.length == 2) {
|
||||
IRemoteConnectionType type = manager.getConnectionType(list[0]);
|
||||
if (type != null) {
|
||||
return (T) type.getConnection(list[1]);
|
||||
}
|
||||
}
|
||||
IRemoteConnectionType remoteType = remoteManager.getConnectionType(target.getTypeId());
|
||||
if (remoteType != null) {
|
||||
return (T) remoteType.getConnection(target.getId());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -14,3 +14,4 @@ Require-Bundle: org.eclipse.ui,
|
|||
org.eclipse.launchbar.remote.core;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: org.eclipse.launchbar.remote.ui
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
<extension
|
||||
point="org.eclipse.launchbar.ui.launchTargetTypeUI">
|
||||
<launchTargetTypeUI
|
||||
id="org.eclipse.launchbar.remote.core.launchTargetType"
|
||||
labelProvider="org.eclipse.launchbar.remote.ui.internal.RemoteLaunchTargetLabelProvider">
|
||||
</launchTargetTypeUI>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.remote.ui;
|
||||
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.ui.IRemoteUIConnectionService;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
public class RemoteLaunchTargetLabelProvider extends LabelProvider {
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
IRemoteConnection connection = ((ILaunchTarget) element).getAdapter(IRemoteConnection.class);
|
||||
if (connection != null) {
|
||||
IRemoteUIConnectionService uiService = connection.getConnectionType()
|
||||
.getService(IRemoteUIConnectionService.class);
|
||||
if (uiService != null) {
|
||||
return uiService.getLabelProvider().getText(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
IRemoteConnection connection = ((ILaunchTarget) element).getAdapter(IRemoteConnection.class);
|
||||
if (connection != null) {
|
||||
IRemoteUIConnectionService uiService = connection.getConnectionType()
|
||||
.getService(IRemoteUIConnectionService.class);
|
||||
if (uiService != null) {
|
||||
return uiService.getLabelProvider().getImage(connection);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.launchbar.remote.ui.internal;
|
||||
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.launchbar.remote.core.internal.RemoteLaunchTargetProvider;
|
||||
import org.eclipse.remote.core.IRemoteConnection;
|
||||
import org.eclipse.remote.ui.IRemoteUIConnectionService;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
public class RemoteLaunchTargetLabelProvider extends LabelProvider {
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
IRemoteConnection connection = getConnection(element);
|
||||
if (connection != null) {
|
||||
IRemoteUIConnectionService uiService = connection.getConnectionType()
|
||||
.getService(IRemoteUIConnectionService.class);
|
||||
if (uiService != null) {
|
||||
return uiService.getLabelProvider().getText(connection);
|
||||
}
|
||||
}
|
||||
return super.getText(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
IRemoteConnection connection = getConnection(element);
|
||||
if (connection != null) {
|
||||
IRemoteUIConnectionService uiService = connection.getConnectionType()
|
||||
.getService(IRemoteUIConnectionService.class);
|
||||
if (uiService != null) {
|
||||
return uiService.getLabelProvider().getImage(connection);
|
||||
}
|
||||
}
|
||||
return super.getImage(element);
|
||||
}
|
||||
|
||||
private IRemoteConnection getConnection(Object element) {
|
||||
if (element instanceof ILaunchTarget) {
|
||||
ILaunchTarget target = (ILaunchTarget) element;
|
||||
if (target.getTypeId().equals(RemoteLaunchTargetProvider.TYPE_ID)) {
|
||||
IRemoteConnection connection = target.getAdapter(IRemoteConnection.class);
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue