--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,150 @@
+/**
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.carbide.remoteconnections.tests.discovery;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+
+import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionType;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
+import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
+import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent;
+import com.nokia.carbide.remoteconnections.tests.extensions.IntervalConnectionType;
+import com.nokia.carbide.remoteconnections.tests.extensions.TestFilter;
+
+public class RandomDiscoveryAgent implements IDeviceDiscoveryAgent {
+ public class RandomPrerequisiteStatus implements IPrerequisiteStatus {
+
+ private boolean ok;
+
+ RandomPrerequisiteStatus() {
+ ok = true; // modify to test
+ }
+ public String getErrorText() {
+ return "Test error text";
+ }
+
+ public URL getURL() {
+ try {
+ return new URL("http://www.yahoo.com");
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public boolean isOK() {
+ return ok;
+ }
+
+ }
+
+ private static final String CONNECTION_TYPE =
+ "com.nokia.carbide.remoteconnections.tests.extensions.IntervalConnectionType";
+ private Random random = new Random();
+ private Set<IConnection2> connections = new HashSet<IConnection2>();
+ private IConnectionsManager manager = RemoteConnectionsActivator.getConnectionsManager();
+
+ private final class DiscoveryThread extends Thread {
+ private static final int MAX = 60000;
+ private static final int MIN = 10000;
+ private volatile boolean keepRunning;
+
+ public void run() {
+ keepRunning = true;
+ while (keepRunning) {
+ try {
+ sleep(getRandomCreationIntervalMs());
+ } catch (InterruptedException e) {
+ keepRunning = false;
+ }
+ if (getRandomIntBetween(0, connections.size() + 1) == 0) {
+ createNewConnection();
+ }
+ else if (!connections.isEmpty()) {
+ IConnection2 connection = connections.iterator().next();
+ connections.remove(connection);
+ manager.disconnect(connection);
+ }
+ }
+ }
+
+ private int getRandomCreationIntervalMs() {
+ return getRandomIntBetween(MIN, MAX);
+ }
+
+ public void stopRunning() {
+ keepRunning = false;
+ }
+ }
+
+ private DiscoveryThread thread = new DiscoveryThread();
+
+ public URL getInformation() {
+ return null;
+ }
+
+ private void createNewConnection() {
+ IConnectionType connectionType =
+ RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionType(CONNECTION_TYPE);
+ IConnectionFactory factory = connectionType.getConnectionFactory();
+ Map<String, String> settings = factory.getSettingsFromUI();
+ String val = getRandomIntervalString();
+ settings.put(IntervalConnectionType.KEY, val);
+ IConnection2 connection = (IConnection2) factory.createConnection(settings);
+ connection.setDisplayName(connection.getConnectionType().getDisplayName() + " " + val + " ms");
+ connection.setDynamic(true);
+ connections.add(connection);
+ manager.addConnection(connection);
+ }
+
+ private String getRandomIntervalString() {
+ int r = getRandomIntBetween(1000, 30000);
+ return Integer.toString(r);
+ }
+
+ private int getRandomIntBetween(int min, int max) {
+ return (Math.abs(random.nextInt()) % (max - min)) + min;
+ }
+
+ public void start() throws CoreException {
+ if (TestFilter.isTest)
+ thread.start();
+ }
+
+ public void stop() throws CoreException {
+ thread.stopRunning();
+ }
+
+ public String getDisplayName() {
+ return "Random Test Discovery Agent";
+ }
+
+ public IPrerequisiteStatus getPrerequisiteStatus() {
+ return (new RandomPrerequisiteStatus());
+ }
+
+}
Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusInUse.png has changed
Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusInUseDisconnected.png has changed
Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusNotReady.png has changed
Binary file connectivity/com.nokia.carbide.remoteConnections/icons/connectionStatusReady.png has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/schema/deviceDiscoveryAgent.exsd Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="com.nokia.carbide.remoteConnections" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="com.nokia.carbide.remoteConnections" id="deviceDiscoveryAgent" name="Device Discovery Agent"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="deviceDiscoveryAgent"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="deviceDiscoveryAgent">
+ <complexType>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/interfaces/IClientServiceSiteUI2.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,95 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+
+package com.nokia.carbide.remoteconnections.interfaces;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * The user interface for picking or defining a connection to use that can be added to client service user interfaces.
+ * <p>
+ * This variant allows selecting a "default connection" which will map to the currently selected default at runtime.
+ * <p>
+ * This requires that you use {@link IConnectionsManager#ensureConnection(String, IService)}
+ * to map from a persisted connection identifier to an IConnection. Do not rely on "validating"
+ * the identifier manually by iterating the {@link IConnectionsManager#getConnections()}!
+ * @noimplement
+ * @noextend
+ * @since 3.0
+ */
+public interface IClientServiceSiteUI2 {
+
+ /**
+ * A listener interface to allow client sites to be notified when a new connection is selected
+ */
+ public interface IListener {
+ void connectionSelected();
+ }
+
+ /**
+ * Create the composite with the client site UI for IService
+ * @param parent Composite
+ */
+ void createComposite(Composite parent);
+
+ /**
+ * Select a specific connection object - must be called after create composite
+ * @param connection the connection id or <code>null</code>
+ */
+ void selectConnection(String connection);
+
+ /**
+ * Return the selected connection object - may be called after UI is disposed.
+ * <p>
+ * Do not expect to find this identifier in the {@link IConnectionsManager#getConnections()} list.
+ * Instead, use {@link IConnectionsManager#ensureConnection(String, IService)} to find
+ * the actual IConnection at runtime.
+ * @return the connection id, which may represent a "default".
+ */
+ String getSelectedConnection();
+
+ /**
+ * Adds a listener to the client site UI
+ * @param listener IListener
+ */
+ void addListener(IListener listener);
+
+ /**
+ * Removes a listener from the client site UI
+ * @param listener IListener
+ */
+ void removeListener(IListener listener);
+
+ /**
+ * Validate the selected connection and return a status.
+ * <p>
+ * @return IStatus for the state of the selection:
+ * <ol>
+ * <li>If a connection is selected and it's compatible, return OK.
+ * <li>If no connection is selected, return ERROR.
+ * <li>If selected connection is a default, but the current default is incompatible,
+ * return WARNING.
+ * (Normally, the concrete connections are already filtered to show only
+ * compatible ones, but the default may be anything.) This is only a warning
+ * because the default connection can be changed externally to this UI, thus
+ * isn't a fatal error.
+ * </ol>
+ */
+ IStatus getSelectionStatus();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IConnectedService2.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,35 @@
+/**
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.carbide.remoteconnections.internal.api;
+
+import java.util.Map;
+
+import com.nokia.carbide.remoteconnections.interfaces.IConnectedService;
+
+/**
+ * An extended interface to a connected service
+ * @since 3.0
+ */
+public interface IConnectedService2 extends IConnectedService {
+
+ /**
+ * Return the properties for this connected service
+ * @return Map
+ */
+ Map<String, String> getProperties();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IConnection2.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,105 @@
+/**
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.carbide.remoteconnections.internal.api;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+
+import com.nokia.carbide.remoteconnections.interfaces.IConnection;
+
+/**
+ * An extended interface to a connection
+ * @since 3.0
+ */
+public interface IConnection2 extends IConnection {
+
+ /**
+ * Whether this connection is dynamic (managed by an automated process)
+ * Dynamic connections are not persisted or user editable.
+ * @return boolean
+ */
+ boolean isDynamic();
+
+ /**
+ * Sets this connection's dynamic attribute.
+ * @see IConnection2#isDynamic()
+ * @param dynamic boolean
+ */
+ void setDynamic(boolean dynamic);
+
+ /**
+ * The status of a connection
+ */
+ public interface IConnectionStatus {
+ enum EConnectionStatus {
+ READY, NOT_READY, IN_USE, IN_USE_DISCONNECTED, NONE
+ };
+
+ EConnectionStatus getEConnectionStatus();
+
+ String getShortDescription();
+
+ String getLongDescription();
+ }
+
+ /**
+ * Gets this connection's status
+ * @return IStatus
+ */
+ IConnectionStatus getStatus();
+
+ /**
+ * Sets this connection's status
+ * @see IConnection2#getStatus()
+ * @param status IStatus
+ */
+ void setStatus(IConnectionStatus status);
+
+ /**
+ * A listener for status changes
+ */
+ public interface IConnectionStatusChangedListener {
+ void statusChanged(IConnectionStatus status);
+ }
+
+ /**
+ * Adds a listener for status changes
+ * @param listener IStatusChangedListener
+ */
+ void addStatusChangedListener(IConnectionStatusChangedListener listener);
+
+ /**
+ * Removes a listener for status changes
+ * @param listener IStatusChangedListener
+ */
+ void removeStatusChangedListener(IConnectionStatusChangedListener listener);
+
+ /**
+ * An optional icon representing this connection.
+ * If none is set, the default icon is used.
+ * @return ImageDescriptor
+ */
+ ImageDescriptor getImageDescriptor();
+
+ /**
+ * Set the image descriptor for this connection.
+ * @see IConnection2#getImageDescriptor()
+ * @param imageDescriptor
+ */
+ void setImageDescriptor(ImageDescriptor imageDescriptor);
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/api/IDeviceDiscoveryAgent.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,96 @@
+/**
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.carbide.remoteconnections.internal.api;
+
+import java.net.URL;
+
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * An interface to a device discovery agent
+ * @since 3.0
+ */
+public interface IDeviceDiscoveryAgent {
+
+ /**
+ * An interface for discovery agents to implement that the manager uses
+ * before loading the agent to get errors about required components.
+ * <p>
+ * Every discovery agent must implement this interface.
+ */
+ public interface IPrerequisiteStatus {
+ /**
+ * Is the status OK?
+ * @return boolean
+ */
+ boolean isOK();
+ /**
+ * If status is not OK, return error message text.
+ * @return String
+ */
+ String getErrorText();
+ /**
+ * Optionally return a URL for user to browse to for more information on error.
+ * @return URL
+ */
+ URL getURL();
+
+ }
+
+ /**
+ * Starts agent. Once started, runs until stopped.
+ * @throws CoreException
+ */
+ void start() throws CoreException;
+
+ /**
+ * Stops agent.
+ * @throws CoreException
+ */
+ void stop() throws CoreException;
+
+ /**
+ * Returns a URL to specific information about this discovery mechanism,
+ * troubleshooting, etc.
+ * @return URL
+ */
+ URL getInformation();
+
+ /**
+ * Returns a display name for the particular discovery agent in case we need to
+ * let the user know errors from the agents.
+ * @return String
+ */
+ String getDisplayName();
+
+ /**
+ * Manager will call this to get any status of prerequisites not satisfied before
+ * the manager calls start(). The agent should check its prerequisites at this time.
+ * <p>
+ * If the agent has no prerequisites return a status of OK.
+ * @return IPrerequisiteStatus
+ */
+ IPrerequisiteStatus getPrerequisiteStatus();
+
+ // In addition, there may need to be an additional API to do a deeper form of discovery for
+ // connection mechanisms that require pairing (like BT or Wifi). In these cases, normal discovery
+ // will probably be for already paired devices, however, the user will want to discover all
+ // potential devices from some UI in order to set up a paired device.
+ // A method for doing this will need to be added.
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ClientServiceSiteUI2.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,446 @@
+/*
+* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+
+package com.nokia.carbide.remoteconnections.internal.ui;
+
+import com.nokia.carbide.remoteconnections.Messages;
+import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
+import com.nokia.carbide.remoteconnections.interfaces.*;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
+import com.nokia.carbide.remoteconnections.internal.registry.Registry;
+import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard;
+import com.nokia.cpp.internal.api.utils.core.Check;
+import com.nokia.cpp.internal.api.utils.core.ListenerList;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.*;
+
+import java.text.MessageFormat;
+import java.util.*;
+import java.util.List;
+
+/**
+ * Implementation of IClientServiceSiteUI2
+ */
+@SuppressWarnings("deprecation")
+public class ClientServiceSiteUI2 implements IClientServiceSiteUI2, IConnectionListener, IConnectionsManagerListener {
+
+ private IService service;
+ private ComboViewer viewer;
+ private FontMetrics fm;
+ private Set<IConnectionType> compatibleConnectionTypes;
+ private Button editButton;
+ private Button newButton;
+ private String connection;
+ private ListenerList<IListener> listenerList;
+ private static final String UID = ".uid"; //$NON-NLS-1$
+ private Map<String, String> connectionNames;
+
+ public ClientServiceSiteUI2(IService service) {
+ Check.checkArg(service);
+ this.service = service;
+ }
+
+ public void createComposite(Composite parent) {
+ initializeDialogUnits(parent);
+ Group group = new Group(parent, SWT.NONE);
+ group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+ group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$
+
+ viewer = new ComboViewer(group, SWT.READ_ONLY);
+ viewer.setLabelProvider(new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ Check.checkContract(element instanceof String);
+ String id = (String) element;
+ return connectionNames.get(id);
+ }
+ });
+ viewer.setContentProvider(new ArrayContentProvider());
+ GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ viewer.getCombo().setLayoutData(gd);
+ viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
+ viewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ String connection = (String) selection.getFirstElement();
+ if (!connection.equals(ClientServiceSiteUI2.this.connection)) {
+ ClientServiceSiteUI2.this.connection = connection;
+ fireConnectionSelected();
+ }
+ }
+ });
+
+ final Composite composite = new Composite(group, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.makeColumnsEqualWidth = true;
+ layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
+ layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
+ layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
+ layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
+ composite.setLayout(layout);
+ gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
+ composite.setLayoutData(gd);
+ composite.setFont(parent.getFont());
+
+ newButton = new Button(composite, SWT.PUSH);
+ newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$
+ newButton.setFont(JFaceResources.getDialogFont());
+ gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
+ Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ gd.widthHint = Math.max(widthHint, minSize.x);
+ newButton.setLayoutData(gd);
+ newButton.setData(UID, "newButton"); //$NON-NLS-1$
+ newButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ SettingsWizard wizard = new SettingsWizard(null, service);
+ wizard.open(composite.getShell());
+ IConnection connection = wizard.getConnectionToEdit();
+ // note: refresh ASAP so the selection will be valid; but endure a listener event
+ // which will redo this
+ refreshUI();
+ setViewerInput(connection);
+ }
+ });
+
+ editButton = new Button(composite, SWT.PUSH);
+ editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$
+ editButton.setFont(JFaceResources.getDialogFont());
+ gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
+ widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
+ minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
+ gd.widthHint = Math.max(widthHint, minSize.x);
+ editButton.setLayoutData(gd);
+ editButton.setData(UID, "editButton"); //$NON-NLS-1$
+ editButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
+ Object value = selection.getFirstElement();
+ if (value instanceof String) {
+ IConnection editConnection = getActualConnection((String) value);
+ SettingsWizard wizard = new SettingsWizard(editConnection, service);
+ wizard.open(composite.getShell());
+
+ // leave the viewer the same, callback will refresh anything needed
+ }
+ }
+ });
+
+ // attach listeners
+ RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(this);
+ RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(this);
+
+ // remove listeners on dispose
+ group.addDisposeListener(new DisposeListener() {
+
+ public void widgetDisposed(DisposeEvent e) {
+ RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(ClientServiceSiteUI2.this);
+ RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(ClientServiceSiteUI2.this);
+ }
+ });
+
+ setViewerInput(null);
+ }
+
+ /**
+ * Get the actual connection for an identifier.
+ * This is not {@link IConnectionsManager#ensureConnection(String, IService)} because we don't
+ * want to actually validate the connection now.
+ * @param id
+ * @return {@link IConnection} or <code>null</code>
+ */
+ protected IConnection getActualConnection(String id) {
+ if (id == null) {
+ return null;
+ }
+ if (id.equals(Registry.CURRENT_CONNECTION_ID)) {
+ return RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection();
+ }
+ for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
+ if (connection.getIdentifier().equals(id)) {
+ return connection;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Set the selected input.
+ * @param connection existing connection or <code>null</code> for the current
+ */
+ private void setViewerInput(IConnection connection) {
+ List<IConnection> compatible = getCompatibleConnections();
+ connectionNames = new LinkedHashMap<String, String>();
+
+ // update the current
+ IConnection currentConnection = RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection();
+
+ connectionNames.put(Registry.CURRENT_CONNECTION_ID, createCurrentConnectionName(currentConnection));
+
+ for (IConnection conn : compatible) {
+ connectionNames.put(conn.getIdentifier(), conn.getDisplayName());
+ }
+
+ viewer.setInput(connectionNames.keySet());
+
+ if (connectionNames.isEmpty())
+ viewer.getCombo().setEnabled(false);
+ else {
+ viewer.getCombo().setEnabled(true);
+ if (connection == null) {
+ viewer.getCombo().select(0);
+ viewer.setSelection(viewer.getSelection());
+ }
+ else
+ selectConnection(connection.getIdentifier());
+ }
+ editButton.setEnabled(!viewer.getSelection().isEmpty());
+
+ // fire listener in case we selected anew or the current connection changed
+ fireConnectionSelected();
+ }
+
+ private void refreshUI() {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ if (viewer != null && viewer.getContentProvider() != null) {
+
+ // try to preserve the currently selected item, if it's a concrete
+ // connection; if it's current, allow for the new current to be chosen.
+ IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
+ Object value = selection.getFirstElement();
+ String current = null;
+ if (value instanceof String) {
+ current = (String) value;
+ }
+ if (Registry.CURRENT_CONNECTION_ID.equals(current)) {
+ current = null;
+ }
+ setViewerInput(getActualConnection(current));
+ }
+ }
+ });
+ }
+
+ /**
+ * @param currentConnection
+ * @return
+ */
+ private String createCurrentConnectionName(IConnection currentConnection) {
+ return MessageFormat.format(Messages.getString("ClientServiceSiteUI2.CurrentConnectionFormat"), //$NON-NLS-1$
+ currentConnection != null ? currentConnection.getDisplayName() :
+ Messages.getString("ClientServiceSiteUI2.CurrentConnection_NoneDetected")); //$NON-NLS-1$
+ }
+
+ private void initializeDialogUnits(Composite parent) {
+ GC gc = new GC(parent);
+ gc.setFont(JFaceResources.getDialogFont());
+ fm = gc.getFontMetrics();
+ gc.dispose();
+ }
+
+ private List<IConnection> getCompatibleConnections() {
+ getCompatibleConnectionTypes();
+
+ List<IConnection> compatibleConnections = new ArrayList<IConnection>();
+ for (IConnection connection : Registry.instance().getConnections()) {
+ if (isCompatibleConnection(connection))
+ compatibleConnections.add(connection);
+ }
+ return compatibleConnections;
+ }
+
+ private boolean isCompatibleConnection(IConnection connection) {
+ return compatibleConnectionTypes.contains(connection.getConnectionType());
+ }
+
+ private void getCompatibleConnectionTypes() {
+ compatibleConnectionTypes = new HashSet<IConnectionType>();
+ Collection<String> compatibleTypeIds =
+ Registry.instance().getCompatibleConnectionTypeIds(service);
+ for (String typeId : compatibleTypeIds) {
+ compatibleConnectionTypes.add(
+ Registry.instance().getConnectionType(typeId));
+ }
+ }
+
+ public void selectConnection(String connection) {
+ viewer.setSelection(new StructuredSelection(connection));
+ }
+
+ public String getSelectedConnection() {
+ return connection;
+ }
+
+ public IStatus getSelectionStatus() {
+ String requiredConnectionTypes = getAllowedConnectionTypesString();
+
+ // no selection yet...?
+ if (connection == null) {
+ return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID,
+ MessageFormat.format(
+ Messages.getString("ClientServiceSiteUI2.NoConnectionError"), //$NON-NLS-1$
+ service.getDisplayName(),
+ requiredConnectionTypes));
+ }
+
+ // check whether the current is compatible with the service and connection type
+ if (Registry.CURRENT_CONNECTION_ID.equals(connection)) {
+ IConnection actual = getActualConnection(connection);
+ if (actual == null) {
+ return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID,
+ MessageFormat.format(
+ Messages.getString("ClientServiceSiteUI2.NoCurrentConnection"), //$NON-NLS-1$
+ service.getDisplayName(),
+ requiredConnectionTypes));
+ }
+
+ // is the service supported?
+ boolean found = false;
+ for (IConnectedService aService : Registry.instance().getConnectedServices(actual)) {
+ if (service.getIdentifier().equals(aService.getService().getIdentifier())) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID,
+ MessageFormat.format(
+ Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionService") //$NON-NLS-1$
+ + "\n" //$NON-NLS-1$
+ + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$
+ actual.getDisplayName(),
+ service.getDisplayName()));
+ }
+
+ // is the hardware type supported by the service?
+ if (!isCompatibleConnection(actual)) {
+ return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID,
+ MessageFormat.format(
+ Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionType") //$NON-NLS-1$
+ + "\n" //$NON-NLS-1$
+ + Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$
+ actual.getDisplayName(),
+ requiredConnectionTypes));
+
+ }
+ }
+
+ // otherwise, it's okay!
+ return Status.OK_STATUS;
+ }
+
+ private String getAllowedConnectionTypesString() {
+ StringBuilder requiredConnectionTypes = new StringBuilder();
+ IConnectionType[] connectionTypes =
+ (IConnectionType[]) compatibleConnectionTypes.toArray(new IConnectionType[compatibleConnectionTypes.size()]);
+ for (int i = 0; i < connectionTypes.length; i++) {
+ IConnectionType type = connectionTypes[i];
+ if (requiredConnectionTypes.length() > 0)
+ requiredConnectionTypes.append(", "); //$NON-NLS-1$
+ if (i == connectionTypes.length - 1)
+ requiredConnectionTypes.append(Messages.getString("ClientServiceSiteUI2.Or")); //$NON-NLS-1$
+ requiredConnectionTypes.append(type.getDisplayName());
+ }
+ return requiredConnectionTypes.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2#getConnectionDisplayName(java.lang.String)
+ */
+ public String getConnectionDisplayName(String connection) {
+ String display = connectionNames.get(connection);
+ if (display == null)
+ display = MessageFormat.format(Messages.getString("ClientServiceSiteUI2.DeletedConnectionDisplayName"), connection); //$NON-NLS-1$
+ return display;
+ }
+
+ public void addListener(IListener listener) {
+ if (listenerList == null)
+ listenerList = new ListenerList<IListener>();
+ listenerList.add(listener);
+ }
+
+ public void removeListener(IListener listener) {
+ if (listenerList != null)
+ listenerList.remove(listener);
+ }
+
+ private void fireConnectionSelected() {
+ if (listenerList != null) {
+ for (IListener listener : listenerList) {
+ listener.connectionSelected();
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection)
+ */
+ public void connectionAdded(IConnection connection) {
+ refreshUI();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection)
+ */
+ public void connectionRemoved(IConnection connection) {
+ refreshUI();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#currentConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection)
+ */
+ public void currentConnectionSet(IConnection connection) {
+ refreshUI();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#connectionStoreChanged()
+ */
+ public void connectionStoreChanged() {
+ refreshUI();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#displayChanged()
+ */
+ public void displayChanged() {
+ refreshUI();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,551 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.carbide.remoteconnections.internal.ui;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.layout.GridLayoutFactory;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.ToolTip;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.menus.CommandContributionItem;
+import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
+
+import com.nokia.carbide.remoteconnections.Messages;
+import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
+import com.nokia.carbide.remoteconnections.interfaces.IConnection;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
+import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
+import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus;
+import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener;
+import com.nokia.carbide.remoteconnections.internal.registry.Registry;
+import com.nokia.carbide.remoteconnections.view.ConnectionsView;
+import com.nokia.cpp.internal.api.utils.core.TextUtils;
+import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
+
+
+/**
+ * This widget appears in the Eclipse trim and allows the user to select the
+ * "current" device connection and also see its status at a glance.
+ * <p>
+ * Note: the UI for this control should behave similarly to that of the News Reader
+ * trim. Due to the way we're modifying the icon and the state dynamically
+ * for this contribution, they can't be implemented the same way, however.
+ */
+@SuppressWarnings("deprecation")
+public class ConnectionStatusSelectorContribution extends WorkbenchWindowControlContribution {
+
+ /**
+ * This is the id on the command in the toolbar contribution associated with this
+ * widget. Keep this in sync with the extension point!
+ */
+ private static final String OPEN_REMOTE_CONNECTIONS_VIEW_COMMAND_ID = "openRemoteConnectionsView"; //$NON-NLS-1$
+ private Composite container;
+ private CLabel connectionInfo;
+ private ToolItem connectionIcon;
+ private IConnectionsManager manager;
+ private IConnection currentConnection;
+ private ListenerBlock listenerBlock;
+ private ToolTip tooltip;
+ private MouseAdapter toolbarListener;
+ private ToolBar toolbar;
+
+ /**
+ * Contains all the listeners. In most cases we just recreate the contribution status item.
+ */
+ class ListenerBlock implements IConnectionListener, IConnectionsManagerListener, IConnectionStatusChangedListener {
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection)
+ */
+ public void connectionAdded(IConnection connection) {
+ updateUI();
+ boolean display = (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic());
+ if (display)
+ launchBubble(MessageFormat.format(
+ Messages.getString("ConnectionStatusSelectorContribution.AddedConnectionFormat"), //$NON-NLS-1$
+ connection.getDisplayName()));
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection)
+ */
+ public void connectionRemoved(IConnection connection) {
+ updateUI();
+ boolean display = (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic());
+ if (display)
+ launchBubble(MessageFormat.format(
+ Messages.getString("ConnectionStatusSelectorContribution.RemovedConnectionFormat"), //$NON-NLS-1$
+ connection.getDisplayName()));
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#currentConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection)
+ */
+ public void currentConnectionSet(IConnection connection) {
+ updateUI();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#connectionStoreChanged()
+ */
+ public void connectionStoreChanged() {
+ updateUI();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#displayChanged()
+ */
+ public void displayChanged() {
+ updateUI();
+ }
+
+ /* (non-Javadoc)
+ * @see com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener#statusChanged(com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus)
+ */
+ public void statusChanged(IConnectionStatus status) {
+ updateConnectionStatus(status);
+ }
+
+ }
+
+ public ConnectionStatusSelectorContribution() {
+ manager = RemoteConnectionsActivator.getConnectionsManager();
+ listenerBlock = new ListenerBlock();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createControl(Composite parent) {
+
+ // This UI is recreated whenever the current connection changes.
+
+ // This is gross. The normal parent of this is a toolbar,
+ // but we cannot add arbitrary stuff to the toolbar besides
+ // this control. (If you try, it will usually show up
+ // out of order!)
+ //
+ // But we want to have a toolbar button for the connection icon
+ // for which we can change the tooltip and image, and attach
+ // a mouse listener responds to left and right clicking.
+ //
+ // In order to do this, we need to poke around in the widget tree
+ // to find the expected Eclipse-generated toolitem. Unfortunately,
+ // controlling all this ourselves is even uglier (I tried).
+
+ if (parent instanceof ToolBar) {
+ toolbar = (ToolBar) parent;
+ ToolItem[] items = toolbar.getItems();
+ for (ToolItem item : items) {
+ Object data = item.getData();
+ if (data instanceof CommandContributionItem &&
+ ((CommandContributionItem) data).getId().contains(OPEN_REMOTE_CONNECTIONS_VIEW_COMMAND_ID)) {
+ connectionIcon = item;
+ break;
+ }
+ }
+ } else {
+ toolbar = null;
+ }
+
+ container = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().margins(2, 0).applyTo(container);
+
+ // Create a label for the trim, outside the toolbar.
+ connectionInfo = new CLabel(container, SWT.NONE);
+ GridDataFactory.fillDefaults().grab(false, true).applyTo(connectionInfo);
+
+ String text = Messages.getString("ConnectionStatusSelectorContribution_NoCurrentConnectionMessage"); //$NON-NLS-1$
+ currentConnection = manager.getCurrentConnection();
+ if (currentConnection != null)
+ text = currentConnection.getDisplayName();
+
+ connectionInfo.setText(text);
+
+ attachListeners();
+
+ updateConnectionStatus(getConnectionStatus(currentConnection));
+
+
+ // Yuck, toolbars and items have a wonky UI. We need to do these events on the parent,
+ // since the ToolItem itself is just an area inside the parent. (#getControl() is only for separators ?!)
+
+ // On icon: left click = open view, right click = menu
+
+ if (toolbar != null) {
+ if (toolbarListener != null)
+ toolbar.removeMouseListener(toolbarListener);
+
+ toolbarListener = new MouseAdapter() {
+ /* (non-Javadoc)
+ * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
+ */
+ @Override
+ public void mouseDown(MouseEvent event) {
+ ToolItem item = toolbar.getItem(new Point(event.x, event.y));
+ if (item == connectionIcon) {
+ if (event.button == 1) {
+ openConnectionsView();
+ } else if (event.button == 3) {
+ Point screenLoc = toolbar.toDisplay(event.x, event.y);
+ handleConnectionMenu(screenLoc);
+ }
+ }
+ }
+ };
+ toolbar.addMouseListener(toolbarListener);
+
+ // On label: left or right click = menu
+ connectionInfo.addMouseListener(new MouseAdapter() {
+ public void mouseDown(MouseEvent event) {
+ if (event.button == 1 || event.button == 3) {
+ Point screenLoc = toolbar.toDisplay(event.x, event.y);
+ handleConnectionMenu(screenLoc);
+ }
+ }
+ });
+ }
+
+ RemoteConnectionsActivator.setHelp(container, "ConnectionStatusSelector"); //$NON-NLS-1$
+ return container;
+ }
+
+ private void handleConnectionMenu(Point screenLoc) {
+ Shell shell = connectionInfo.getParent().getShell();
+ final Display display = shell.getDisplay();
+
+ final Menu menu = new Menu(shell, SWT.POP_UP);
+ populateConnectionMenu(menu);
+
+ menu.setLocation(screenLoc.x, screenLoc.y);
+ menu.setVisible(true);
+
+ while (!menu.isDisposed() && menu.isVisible()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ menu.dispose();
+
+ }
+
+ /**
+ * @return
+ */
+ protected void populateConnectionMenu(Menu menu) {
+ // Display the connections with dynamic ones first,
+ // then static ones, separated by a separator
+
+ List<IConnection> dynamicConnections = new ArrayList<IConnection>();
+ List<IConnection> staticConnections = new ArrayList<IConnection>();
+ for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
+ if (connection instanceof IConnection2 && ((IConnection2)connection).isDynamic())
+ dynamicConnections.add(connection);
+ else
+ staticConnections.add(connection);
+ }
+
+
+ Comparator<IConnection> connectionComparator = new Comparator<IConnection>() {
+ public int compare(IConnection o1, IConnection o2) {
+ return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
+ }
+ };
+ Collections.sort(dynamicConnections, connectionComparator);
+ Collections.sort(staticConnections, connectionComparator);
+
+ MenuItem label = new MenuItem(menu, SWT.NONE);
+ label.setEnabled(false);
+
+ int number = 1;
+ if (dynamicConnections.size() + staticConnections.size() == 0) {
+ label.setText(Messages.getString("ConnectionStatusSelectorContribution.NoConnectionsDefinedOrDetected")); //$NON-NLS-1$
+ } else {
+ label.setText(Messages.getString("ConnectionStatusSelectorContribution_SelectTheCurrentConnectionMessage")); //$NON-NLS-1$
+
+ for (IConnection connection : dynamicConnections) {
+ createConnectionMenuItem(menu, connection, currentConnection, number++);
+ }
+
+ if (!staticConnections.isEmpty())
+ new MenuItem(menu, SWT.SEPARATOR);
+
+ for (IConnection connection : staticConnections) {
+ createConnectionMenuItem(menu, connection, currentConnection, number++);
+ }
+ }
+
+ new MenuItem(menu, SWT.SEPARATOR);
+
+ MenuItem openView = new MenuItem(menu, SWT.PUSH);
+ openView.setText(Messages.getString("ConnectionStatusSelectorContribution.OpenRemoteConnectionsView")); //$NON-NLS-1$
+ openView.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ openConnectionsView();
+ }
+ });
+ }
+
+ /**
+ * @param menu
+ * @param connection
+ * @param currentConnection
+ */
+ private MenuItem createConnectionMenuItem(Menu menu,
+ final IConnection connection,
+ IConnection currentConnection,
+ int number) {
+ MenuItem item = new MenuItem(menu, SWT.CHECK);
+
+ boolean isCurrent = false;
+ isCurrent = connection.equals(currentConnection);
+
+ item.setSelection(isCurrent);
+
+ item.setText(MessageFormat.format("&{0} - {1}", number, connection.getDisplayName())); //$NON-NLS-1$
+
+ item.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ manager.setCurrentConnection(connection);
+ }
+ });
+
+ return item;
+ }
+
+ private void attachListeners() {
+ manager.addConnectionListener(listenerBlock);
+ Registry.instance().addConnectionStoreChangedListener(listenerBlock);
+
+ if (currentConnection != null) {
+ if (currentConnection instanceof IConnection2) {
+ ((IConnection2) currentConnection).addStatusChangedListener(listenerBlock);
+ }
+ }
+ }
+
+ private void removeListeners() {
+ if (currentConnection != null) {
+ if (currentConnection instanceof IConnection2) {
+ ((IConnection2) currentConnection).removeStatusChangedListener(listenerBlock);
+ }
+ }
+ manager.removeConnectionListener(listenerBlock);
+ Registry.instance().removeConnectionStoreChangedListener(listenerBlock);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.ContributionItem#dispose()
+ */
+ public void dispose() {
+ removeListeners();
+ if (connectionIcon != null)
+ connectionIcon.dispose();
+ if (toolbarListener != null && !toolbar.isDisposed())
+ toolbar.removeMouseListener(toolbarListener);
+ if (connectionInfo != null)
+ connectionInfo.dispose();
+
+ super.dispose();
+ }
+
+ /**
+ * @param ev
+ */
+ protected void openConnectionsView() {
+ try {
+ IViewPart view = WorkbenchUtils.getView(ConnectionsView.VIEW_ID);
+ if (currentConnection != null && view instanceof ConnectionsView) {
+ ((ConnectionsView) view).setSelectedConnection(currentConnection);
+ }
+ }
+ catch (PartInitException e) {
+ RemoteConnectionsActivator.logError(e);
+ }
+ }
+
+ /**
+ * @param currentConnection
+ * @param status
+ * @return
+ */
+ private String createConnectionStatusTooltip(IConnection currentConnection,
+ IConnectionStatus status) {
+ if (currentConnection == null) {
+ return Messages.getString("ConnectionStatusSelectorContribution.NoDynamicOrManualConnectionsTooltip"); //$NON-NLS-1$
+ }
+
+ String statusString = null;
+ if (status != null) {
+ statusString = createStatusString(status);
+ }
+
+ if (TextUtils.isEmpty(statusString)) {
+ // fallback string; the status should not be empty
+ if (ConnectionUIUtils.isSomeServiceInUse(currentConnection))
+ statusString = Messages.getString("ConnectionStatusSelectorContribution.InUse"); //$NON-NLS-1$
+ else
+ statusString = Messages.getString("ConnectionStatusSelectorContribution.NotInUse"); //$NON-NLS-1$
+ }
+
+ return MessageFormat.format(Messages.getString("ConnectionStatusSelectorContribution.ConnectionStatusFormat"), currentConnection.getDisplayName(), statusString); //$NON-NLS-1$
+ }
+
+ private String createStatusString(IConnectionStatus status) {
+ String shortDescription = status.getShortDescription();
+ if (shortDescription == null || shortDescription.length() == 0)
+ return ""; //$NON-NLS-1$
+ String pattern = Messages.getString("ConnectionStatusSelectorContribution.StatusFormat"); //$NON-NLS-1$
+ if (shortDescription != null)
+ shortDescription = shortDescription.toLowerCase();
+ return MessageFormat.format(pattern, shortDescription, status.getLongDescription());
+ }
+
+ /**
+ * Get the image representing the connection status.
+ * @param connection
+ * @return Image, to be disposed
+ */
+ private IConnectionStatus getConnectionStatus(IConnection connection) {
+ if (!(connection instanceof IConnection2)) {
+ return null;
+ } else {
+ return ((IConnection2) connection).getStatus();
+ }
+ }
+
+ /**
+ * @param status
+ */
+ private void updateConnectionStatus(final IConnectionStatus status) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (connectionIcon == null || connectionIcon.isDisposed())
+ return;
+
+ Image statusImage;
+ if (status != null)
+ statusImage = ConnectionUIUtils.getConnectionStatusImage(status);
+ else
+ statusImage = ConnectionUIUtils.getConnectionImage(currentConnection);
+
+ connectionIcon.setImage(statusImage);
+ String tip = createConnectionStatusTooltip(currentConnection, status);
+ connectionInfo.setToolTipText(tip);
+
+ String preamble = Messages.getString("ConnectionStatusSelectorContribution.IconTooltipPrefixMessage"); //$NON-NLS-1$
+ connectionIcon.setToolTipText(preamble + tip);
+ }
+ });
+
+ }
+
+ /**
+ *
+ */
+ private void updateUI() {
+ // perform update in UI thread
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ workbench.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window != null) {
+ update();
+ }
+ }
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.ContributionItem#isDynamic()
+ */
+ @Override
+ public boolean isDynamic() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.ContributionItem#update()
+ */
+ @Override
+ public void update() {
+ getParent().update(true);
+ }
+
+ /**
+ * Show a status bubble for important changes.
+ * @param string
+ */
+ public void launchBubble(final String string) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ if (tooltip != null)
+ tooltip.dispose();
+
+ if (connectionInfo == null || connectionInfo.isDisposed())
+ return;
+
+ tooltip = new ToolTip(connectionInfo.getParent().getShell(), SWT.BALLOON | SWT.ICON_INFORMATION);
+ tooltip.setMessage(string);
+ Rectangle bounds = connectionInfo.getBounds();
+ Point center = new Point(bounds.x + bounds.width / 2,
+ bounds.y + bounds.height);
+ Point location = connectionInfo.getParent().toDisplay(center);
+ //System.out.println(connectionInfo.hashCode() + ": " + connectionInfo.getLocation() + " : " + location);
+ tooltip.setLocation(location);
+ tooltip.setVisible(true);
+ }
+ });
+ }
+
+
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionUIUtils.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,162 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.carbide.remoteconnections.internal.ui;
+
+import java.util.Collection;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+
+import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectedService;
+import com.nokia.carbide.remoteconnections.interfaces.IConnection;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
+import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
+import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus;
+import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus;
+import com.nokia.carbide.remoteconnections.internal.registry.Registry;
+
+/**
+ *
+ */
+public class ConnectionUIUtils {
+
+ private static final ImageDescriptor STATUS_AVAIL_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/statusAvailable.png"); //$NON-NLS-1$
+ private static final ImageDescriptor STATUS_UNAVAIL_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/statusUnavailable.png"); //$NON-NLS-1$
+ private static final ImageDescriptor STATUS_UNK_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/statusUnknown.png"); //$NON-NLS-1$
+ private static final ImageDescriptor STATUS_INUSE_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/statusInUse.png"); //$NON-NLS-1$
+
+ private static final ImageDescriptor CONNECTION_READY_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusReady.png"); //$NON-NLS-1$
+ private static final ImageDescriptor CONNECTION_IN_USE_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUse.png"); //$NON-NLS-1$
+ private static final ImageDescriptor CONNECTION_NOT_READY_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusNotReady.png"); //$NON-NLS-1$
+ private static final ImageDescriptor CONNECTION_IN_USE_DISCONNECTED_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/connectionStatusInUseDisconnected.png"); //$NON-NLS-1$
+
+ public static final ImageDescriptor CONNECTION_IMGDESC =
+ RemoteConnectionsActivator.getImageDescriptor("icons/connection.png"); //$NON-NLS-1$
+
+ private static final Image STATUS_AVAIL_IMG = STATUS_AVAIL_IMGDESC.createImage();
+ private static final Image STATUS_UNAVAIL_IMG = STATUS_UNAVAIL_IMGDESC.createImage();
+ private static final Image STATUS_INUSE_IMG = STATUS_INUSE_IMGDESC.createImage();
+ private static final Image STATUS_UNK_IMG = STATUS_UNK_IMGDESC.createImage();
+
+ private static final Image CONNECTION_READY_IMG = CONNECTION_READY_IMGDESC.createImage();
+ private static final Image CONNECTION_IN_USE_IMG = CONNECTION_IN_USE_IMGDESC.createImage();
+ private static final Image CONNECTION_NOT_READY_IMG = CONNECTION_NOT_READY_IMGDESC.createImage();
+ private static final Image CONNECTION_IN_USE_DISCONNECTED_IMG = CONNECTION_IN_USE_DISCONNECTED_IMGDESC.createImage();
+
+ private static final Image CONNECTION_IMG = CONNECTION_IMGDESC.createImage();
+
+ public static final Color COLOR_RED = new Color(Display.getDefault(), 192, 0, 0);
+ public static final Color COLOR_GREEN = new Color(Display.getDefault(), 0, 128, 0);
+ public static final Color COLOR_ELECTRIC = new Color(Display.getDefault(), 0, 0, 255);
+ public static final Color COLOR_GREY = new Color(Display.getDefault(), 96, 96, 96);
+
+ /**
+ * Get the image representing the connection status.
+ * @param connection
+ * @return Image, not to be disposed
+ */
+ public static Image getConnectionStatusImage(IConnectionStatus status) {
+ if (status != null) {
+ EConnectionStatus severity = status.getEConnectionStatus();
+
+ switch (severity) {
+ case READY:
+ return CONNECTION_READY_IMG;
+ case IN_USE:
+ return CONNECTION_IN_USE_IMG;
+ case NOT_READY:
+ return CONNECTION_NOT_READY_IMG;
+ case IN_USE_DISCONNECTED:
+ return CONNECTION_IN_USE_DISCONNECTED_IMG;
+ }
+ }
+ return ConnectionUIUtils.CONNECTION_IMG;
+ }
+
+ /**
+ * Get the image representing the connection status.
+ * @param connection
+ * @return Image, not to be disposed
+ */
+ public static Image getConnectionImage(IConnection connection) {
+ // TODO: remove this when we have real statuses from a connection
+ if (isSomeServiceInUse(connection)) {
+ return ConnectionUIUtils.STATUS_INUSE_IMG;
+ }
+ if (connection instanceof IConnection2) {
+ IConnectionStatus status = ((IConnection2) connection).getStatus();
+ return getConnectionStatusImage(status);
+ } else {
+ // old connection logic
+ if (isSomeServiceInUse(connection)) {
+ return ConnectionUIUtils.STATUS_INUSE_IMG;
+ }
+ return ConnectionUIUtils.CONNECTION_IMG;
+ }
+ }
+
+ /**
+ * @param status
+ * @return
+ */
+ public static Image getConnectedServiceStatusImage(IConnectedService.IStatus.EStatus status) {
+ switch (status) {
+ case DOWN:
+ return ConnectionUIUtils.STATUS_UNAVAIL_IMG;
+ case UP:
+ return ConnectionUIUtils.STATUS_AVAIL_IMG;
+ case IN_USE:
+ return ConnectionUIUtils.CONNECTION_IMG;
+ case UNKNOWN:
+ return ConnectionUIUtils.STATUS_UNK_IMG;
+ }
+ return null;
+ }
+
+ public static IStatus getFirstInUseServiceStatus(IConnection connection) {
+ Collection<IConnectedService> connectedServices =
+ Registry.instance().getConnectedServices(connection);
+ // if any service is in-use, then connection is in-use
+ if (connectedServices == null)
+ return null;
+
+ for (IConnectedService connectedService : connectedServices) {
+ IStatus status = connectedService.getStatus();
+ if (status.getEStatus().equals(EStatus.IN_USE))
+ return status;
+ }
+
+ return null;
+ }
+
+ public static boolean isSomeServiceInUse(IConnection connection) {
+ return getFirstInUseServiceStatus(connection) != null;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/DeviceDiscoveryPrequisiteErrorDialog.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,223 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+package com.nokia.carbide.remoteconnections.internal.ui;
+
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.IShellProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Link;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.browser.IWebBrowser;
+
+import com.nokia.carbide.remoteconnections.Messages;
+import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
+
+public class DeviceDiscoveryPrequisiteErrorDialog extends TrayDialog {
+
+ private class AgentItem {
+ public String agentName;
+ public String agentErrorText;
+ public URL agentLocation;
+
+ AgentItem(String name, String text, URL location) {
+ agentName = name;
+ agentErrorText = text;
+ agentLocation = location;
+ // if location is not null and error text doesn't contain href
+ // then do it here
+ if (agentLocation != null && !agentErrorText.contains("href")) { //$NON-NLS-1$
+ String msg = MessageFormat.format(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ErrorFormatWithURL"), //$NON-NLS-1$
+ agentErrorText, location, location);
+ agentErrorText = msg;
+ }
+ }
+ }
+
+ private Collection<AgentItem> agentList = new ArrayList<AgentItem>();
+ private boolean dontAskAgain;
+ private ListViewer agentListViewer;
+ private Link errorText;
+ private Button dontAskAgainCheckBox;
+
+ /**
+ * @param parentShell
+ */
+ public DeviceDiscoveryPrequisiteErrorDialog(Shell parentShell) {
+ super(parentShell);
+ agentList.clear();
+ }
+
+ /**
+ * @param parentShell
+ */
+ public DeviceDiscoveryPrequisiteErrorDialog(IShellProvider parentShell) {
+ super(parentShell);
+ agentList.clear();
+ }
+
+ public void addAgentData(String name, String errorText, URL location) {
+ agentList.add(new AgentItem(name, errorText, location));
+ }
+
+ public boolean isDontAskAgainChecked() {
+ return dontAskAgain;
+ }
+
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ // OK button == "Close"
+ // no Cancel button
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL, true);
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite container = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, true);
+ container.setLayout(layout);
+ container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ // Message at top
+ Text topMessage = new Text(container, SWT.MULTI | SWT.WRAP);
+ topMessage.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_Description")); //$NON-NLS-1$
+ topMessage.setEditable(false);
+ topMessage.setDoubleClickEnabled(false);
+ GridData topMsgData = new GridData(SWT.LEFT, SWT.CENTER, true, false);
+ topMsgData.heightHint = 48;
+ topMessage.setLayoutData(topMsgData);
+ topMessage.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ToolTipText")); //$NON-NLS-1$
+
+ // next two panes can be resized with a sash form
+ SashForm sashForm = new SashForm(container, SWT.VERTICAL);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ sashForm.setLayoutData(gridData);
+
+ // this pane lists all the agent display names
+ agentListViewer = new ListViewer(sashForm, SWT.V_SCROLL | SWT.BORDER);
+ agentListViewer.setContentProvider(new ArrayContentProvider());
+ agentListViewer.setLabelProvider(new LabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ return ((AgentItem)element).agentName;
+ }
+
+ });
+ agentListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ AgentItem item = (AgentItem) selection.getFirstElement();
+ errorText.setText(item.agentErrorText);
+ }
+
+ });
+ agentListViewer.setInput(agentList);
+
+ // pane to view the information about the selected agent
+ errorText = new Link(sashForm, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
+ errorText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
+ errorText.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ErrorTextToolTipText")); //$NON-NLS-1$
+ errorText.addListener(SWT.Selection, new Listener() {
+
+ public void handleEvent(Event event) {
+ // Launch an external browser
+ String siteText = event.text;
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ try {
+ IWebBrowser browser = workbench.getBrowserSupport().getExternalBrowser();
+ browser.openURL(new URL(siteText));
+ } catch (Exception e) {
+ RemoteConnectionsActivator.logError(e);
+ }
+ }
+
+ });
+
+ // add initial weights to the above two panes
+ sashForm.setWeights(new int[] {150,200});
+
+ // now the don't ask again check box
+ dontAskAgainCheckBox = new Button(container, SWT.CHECK);
+ dontAskAgainCheckBox.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
+ dontAskAgainCheckBox.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainLabel")); //$NON-NLS-1$
+ dontAskAgainCheckBox.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainToolTipText")); //$NON-NLS-1$
+ dontAskAgainCheckBox.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ dontAskAgain = dontAskAgainCheckBox.getSelection();
+ }
+
+ });
+
+ // now finish by selecting the top most agent in the list
+ // and bringing it into view
+ Object o = agentListViewer.getElementAt(0);
+ if (o != null)
+ agentListViewer.setSelection(new StructuredSelection(o));
+
+ ISelection selection = agentListViewer.getSelection();
+ if (selection != null && !selection.isEmpty()) {
+ agentListViewer.reveal(selection);
+ }
+
+ return container;
+ }
+
+ @Override
+ protected Point getInitialSize() {
+ return new Point(400,400);
+ }
+
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ // set our title to the dialog
+ newShell.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_Title")); //$NON-NLS-1$
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/OpenConnectionViewCommandHandler.java Mon Feb 01 13:30:39 2010 -0600
@@ -0,0 +1,46 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+package com.nokia.carbide.remoteconnections.internal.ui;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.PartInitException;
+
+import com.nokia.carbide.remoteconnections.Messages;
+import com.nokia.carbide.remoteconnections.view.ConnectionsView;
+import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
+
+/**
+ *
+ */
+public class OpenConnectionViewCommandHandler extends AbstractHandler {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ try {
+ WorkbenchUtils.getView(ConnectionsView.VIEW_ID);
+ } catch (PartInitException e) {
+ throw new ExecutionException(Messages.getString("OpenConnectionViewCommandHandler_FailedToOpenMsg"), e); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+}