39 |
39 |
40 import org.eclipse.core.runtime.CoreException; |
40 import org.eclipse.core.runtime.CoreException; |
41 import org.eclipse.core.runtime.IPath; |
41 import org.eclipse.core.runtime.IPath; |
42 import org.eclipse.core.runtime.IStatus; |
42 import org.eclipse.core.runtime.IStatus; |
43 import org.eclipse.jface.dialogs.Dialog; |
43 import org.eclipse.jface.dialogs.Dialog; |
44 import org.eclipse.jface.dialogs.IDialogConstants; |
|
45 import org.eclipse.jface.dialogs.IMessageProvider; |
|
46 import org.eclipse.jface.dialogs.TitleAreaDialog; |
44 import org.eclipse.jface.dialogs.TitleAreaDialog; |
47 import org.eclipse.jface.viewers.IFilter; |
45 import org.eclipse.jface.viewers.IFilter; |
48 import org.eclipse.swt.widgets.Composite; |
|
49 import org.eclipse.swt.widgets.Control; |
|
50 import org.eclipse.swt.widgets.Display; |
46 import org.eclipse.swt.widgets.Display; |
51 import org.eclipse.swt.widgets.Shell; |
|
52 |
47 |
53 import com.nokia.carbide.remoteconnections.Messages; |
48 import com.nokia.carbide.remoteconnections.Messages; |
54 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
49 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
55 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; |
50 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI; |
56 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; |
51 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2; |
61 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; |
56 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; |
62 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
57 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
63 import com.nokia.carbide.remoteconnections.interfaces.IExtensionFilter; |
58 import com.nokia.carbide.remoteconnections.interfaces.IExtensionFilter; |
64 import com.nokia.carbide.remoteconnections.interfaces.IService; |
59 import com.nokia.carbide.remoteconnections.interfaces.IService; |
65 import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection.ConnectionStatus; |
60 import com.nokia.carbide.remoteconnections.interfaces.AbstractConnection.ConnectionStatus; |
66 import com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2.IListener; |
|
67 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
61 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
68 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
62 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus; |
69 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener; |
63 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener; |
70 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; |
64 import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus.EConnectionStatus; |
71 import com.nokia.carbide.remoteconnections.internal.ui.ClientServiceSiteUI2; |
65 import com.nokia.carbide.remoteconnections.internal.ui.ClientServiceSiteUI2; |
72 import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils; |
66 import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils; |
|
67 import com.nokia.carbide.remoteconnections.internal.ui.SelectConnectionDialog; |
73 import com.nokia.carbide.remoteconnections.ui.ClientServiceSiteUI; |
68 import com.nokia.carbide.remoteconnections.ui.ClientServiceSiteUI; |
74 import com.nokia.cpp.internal.api.utils.core.Check; |
69 import com.nokia.cpp.internal.api.utils.core.Check; |
75 import com.nokia.cpp.internal.api.utils.core.ListenerList; |
70 import com.nokia.cpp.internal.api.utils.core.ListenerList; |
76 import com.nokia.cpp.internal.api.utils.core.Logging; |
71 import com.nokia.cpp.internal.api.utils.core.Logging; |
77 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
72 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
90 private static final String NAME_SUFFIX_PATTERN = "(.+) \\((\\d+)\\)"; //$NON-NLS-1$ |
85 private static final String NAME_SUFFIX_PATTERN = "(.+) \\((\\d+)\\)"; //$NON-NLS-1$ |
91 private static final String NAME_FMT = "{0} ({1})"; //$NON-NLS-1$ |
86 private static final String NAME_FMT = "{0} ({1})"; //$NON-NLS-1$ |
92 |
87 |
93 // this is exposed to other clients inside this plugin but it is not public knowledge |
88 // this is exposed to other clients inside this plugin but it is not public knowledge |
94 public static final String CURRENT_CONNECTION_ID = RemoteConnectionsActivator.PLUGIN_ID + ".currentConnection"; //$NON-NLS-1$ |
89 public static final String CURRENT_CONNECTION_ID = RemoteConnectionsActivator.PLUGIN_ID + ".currentConnection"; //$NON-NLS-1$ |
|
90 |
|
91 private static final String LAST_CONNECTION_ID = "last_connection_id"; //$NON-NLS-1$ |
95 |
92 |
96 private static Registry instance = new Registry(); |
93 private static Registry instance = new Registry(); |
97 |
94 |
98 private List<IExtensionFilter> extensionFilters; |
95 private List<IExtensionFilter> extensionFilters; |
99 private Map<String, IConnectionType> connectionTypeIdMap; |
96 private Map<String, IConnectionType> connectionTypeIdMap; |
333 ensureUniqueName(connection); |
330 ensureUniqueName(connection); |
334 List<IConnectedService> connectedServices = createConnectedServicesForConnection(connection); |
331 List<IConnectedService> connectedServices = createConnectedServicesForConnection(connection); |
335 connectionToConnectedServices.put(connection, connectedServices); |
332 connectionToConnectedServices.put(connection, connectedServices); |
336 fireConnectionStoreChanged(); |
333 fireConnectionStoreChanged(); |
337 fireConnectionAdded(connection); |
334 fireConnectionAdded(connection); |
|
335 |
|
336 setLastConnectionId(connection.getIdentifier()); |
338 } |
337 } |
339 |
338 |
340 private void ensureUniqueId(IConnection connection) { |
339 private void ensureUniqueId(IConnection connection) { |
341 String id = connection.getIdentifier(); |
340 String id = connection.getIdentifier(); |
342 if (id == null || id.length() == 0 || findConnection(id) != null) |
341 if (id == null || id.length() == 0 || findConnection(id) != null) |
522 final String[] storableIdHolder = { id }; |
521 final String[] storableIdHolder = { id }; |
523 if (!isCompatibleConnection(connectionHolder[0], service)) { |
522 if (!isCompatibleConnection(connectionHolder[0], service)) { |
524 connectionHolder[0] = getCompatibleConnectionFromUser(service, storableIdHolder); |
523 connectionHolder[0] = getCompatibleConnectionFromUser(service, storableIdHolder); |
525 if (connectionHolder[0] == null) { |
524 if (connectionHolder[0] == null) { |
526 throw new CoreException( |
525 throw new CoreException( |
527 Logging.newStatus(RemoteConnectionsActivator.getDefault(), IStatus.ERROR, |
526 Logging.newStatus(RemoteConnectionsActivator.getDefault(), IStatus.CANCEL, |
528 Messages.getString("Registry.NoCompatibleConnectionMsg"))); //$NON-NLS-1$ |
527 Messages.getString("Registry.NoCompatibleConnectionMsg"))); //$NON-NLS-1$ |
529 } |
528 } |
530 else if (wasCurrentConnection && !connectionHolder[0].getIdentifier().equals(CURRENT_CONNECTION_ID)) { |
529 else if (wasCurrentConnection && !connectionHolder[0].getIdentifier().equals(CURRENT_CONNECTION_ID)) { |
531 setCurrentConnection(connectionHolder[0]); |
530 setCurrentConnection(connectionHolder[0]); |
532 storableIdHolder[0] = CURRENT_CONNECTION_ID; |
531 storableIdHolder[0] = CURRENT_CONNECTION_ID; |
546 private IConnection getCompatibleConnectionFromUser(final IService service, final String[] storableIdHolder) { |
545 private IConnection getCompatibleConnectionFromUser(final IService service, final String[] storableIdHolder) { |
547 final IConnection[] connectionHolder = { null }; |
546 final IConnection[] connectionHolder = { null }; |
548 if (!WorkbenchUtils.isJUnitRunning()) { |
547 if (!WorkbenchUtils.isJUnitRunning()) { |
549 Display.getDefault().syncExec(new Runnable() { |
548 Display.getDefault().syncExec(new Runnable() { |
550 public void run() { |
549 public void run() { |
|
550 // First, see if any connections could possibly be selected. |
|
551 // If not, immediately offer to create a new connection. |
|
552 |
551 final IClientServiceSiteUI2 ui = getClientSiteUI2(service); |
553 final IClientServiceSiteUI2 ui = getClientSiteUI2(service); |
552 final TitleAreaDialog dialog = new TitleAreaDialog(WorkbenchUtils.getSafeShell()) { |
554 final TitleAreaDialog dialog = new SelectConnectionDialog(WorkbenchUtils.getSafeShell(), ui); |
553 @Override |
|
554 protected Control createDialogArea(Composite parent) { |
|
555 final Composite c = (Composite) super.createDialogArea(parent); |
|
556 ui.createComposite(c); |
|
557 ui.addListener(new IListener() { |
|
558 public void connectionSelected() { |
|
559 updateStatus(ui.getSelectionStatus()); |
|
560 } |
|
561 |
|
562 }); |
|
563 |
|
564 return c; |
|
565 } |
|
566 |
|
567 private void updateStatus(IStatus selectionStatus) { |
|
568 setTitle(Messages.getString("Registry.EnsureConnection.TitleLabel")); //$NON-NLS-1$ |
|
569 setMessage(Messages.getString("Registry.EnsureConnection.Description")); //$NON-NLS-1$ |
|
570 switch (selectionStatus.getSeverity()) { |
|
571 case IStatus.ERROR: |
|
572 setMessage(selectionStatus.getMessage(), IMessageProvider.ERROR); |
|
573 getButton(IDialogConstants.OK_ID).setEnabled(false); |
|
574 break; |
|
575 case IStatus.WARNING: |
|
576 setMessage(selectionStatus.getMessage(), IMessageProvider.WARNING); |
|
577 getButton(IDialogConstants.OK_ID).setEnabled(true); |
|
578 break; |
|
579 case IStatus.INFO: |
|
580 setMessage(selectionStatus.getMessage(), IMessageProvider.INFORMATION); |
|
581 getButton(IDialogConstants.OK_ID).setEnabled(true); |
|
582 break; |
|
583 default: |
|
584 getButton(IDialogConstants.OK_ID).setEnabled(true); |
|
585 } |
|
586 } |
|
587 |
|
588 @Override |
|
589 public void create() { |
|
590 super.create(); |
|
591 updateStatus(ui.getSelectionStatus()); |
|
592 } |
|
593 |
|
594 @Override |
|
595 protected void configureShell(Shell newShell) { |
|
596 super.configureShell(newShell); |
|
597 newShell.setText(Messages.getString("Registry.EnsureConnection.DialogTitle")); //$NON-NLS-1$ |
|
598 } |
|
599 |
|
600 @Override |
|
601 protected boolean isResizable() { |
|
602 return true; |
|
603 } |
|
604 }; |
|
605 dialog.setBlockOnOpen(true); |
555 dialog.setBlockOnOpen(true); |
606 if (dialog.open() == Dialog.OK) { |
556 if (dialog.open() == Dialog.OK) { |
607 storableIdHolder[0] = ui.getSelectedConnection(); |
557 storableIdHolder[0] = ui.getSelectedConnection(); |
608 connectionHolder[0] = findConnection(storableIdHolder[0]); |
558 connectionHolder[0] = findConnection(storableIdHolder[0]); |
609 } |
559 } |
698 else // connection is not disconnected |
648 else // connection is not disconnected |
699 return true; |
649 return true; |
700 |
650 |
701 return false; |
651 return false; |
702 } |
652 } |
|
653 |
|
654 /** |
|
655 * Internal method: get the last id of a connection created or selected in UI. |
|
656 * Used to prepopulate UI for selecting connections. |
|
657 * @return connection id (not "current") or <code>null</code> |
|
658 */ |
|
659 public String getLastConnectionId() { |
|
660 return RemoteConnectionsActivator.getDefault().getPreferenceStore().getString(LAST_CONNECTION_ID); |
|
661 } |
|
662 |
|
663 /** |
|
664 * Internal method: remember the last id of a connection created or selected in UI. |
|
665 * @param id connection id. Current connection is converted to an actual connection id. |
|
666 */ |
|
667 public void setLastConnectionId(String id) { |
|
668 if (CURRENT_CONNECTION_ID.equals(id)) |
|
669 id = currentConnection != null ? currentConnection.getIdentifier() : null; |
|
670 if (id == null) |
|
671 return; |
|
672 RemoteConnectionsActivator.getDefault().getPreferenceStore().setValue(LAST_CONNECTION_ID, id); |
|
673 } |
703 } |
674 } |