56 import org.eclipse.jface.viewers.ViewerSorter; |
56 import org.eclipse.jface.viewers.ViewerSorter; |
57 import org.eclipse.swt.SWT; |
57 import org.eclipse.swt.SWT; |
58 import org.eclipse.swt.events.KeyAdapter; |
58 import org.eclipse.swt.events.KeyAdapter; |
59 import org.eclipse.swt.events.KeyEvent; |
59 import org.eclipse.swt.events.KeyEvent; |
60 import org.eclipse.swt.graphics.Color; |
60 import org.eclipse.swt.graphics.Color; |
|
61 import org.eclipse.swt.graphics.Font; |
61 import org.eclipse.swt.graphics.Image; |
62 import org.eclipse.swt.graphics.Image; |
62 import org.eclipse.swt.widgets.Composite; |
63 import org.eclipse.swt.widgets.Composite; |
63 import org.eclipse.swt.widgets.Display; |
64 import org.eclipse.swt.widgets.Display; |
64 import org.eclipse.swt.widgets.Menu; |
65 import org.eclipse.swt.widgets.Menu; |
65 import org.eclipse.swt.widgets.TreeColumn; |
66 import org.eclipse.swt.widgets.TreeColumn; |
75 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
76 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
76 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
77 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
77 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
78 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
78 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
79 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
79 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
80 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
81 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; |
80 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; |
82 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener; |
81 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
83 import com.nokia.carbide.remoteconnections.internal.api.IConnection2; |
82 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
84 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
83 import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils; |
85 import com.nokia.carbide.remoteconnections.internal.ui.ConnectionUIUtils; |
84 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
86 import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard; |
|
87 import com.nokia.cpp.internal.api.utils.core.ObjectUtils; |
85 import com.nokia.cpp.internal.api.utils.core.TextUtils; |
88 import com.nokia.cpp.internal.api.utils.core.TextUtils; |
86 |
89 |
87 |
90 |
88 /** |
91 /** |
89 * The view part for Remote connections |
92 * The view part for Remote connections |
92 public class ConnectionsView extends ViewPart { |
95 public class ConnectionsView extends ViewPart { |
93 public static final String VIEW_ID = "com.nokia.carbide.remoteconnections.view.ConnectionsView"; //$NON-NLS-1$ |
96 public static final String VIEW_ID = "com.nokia.carbide.remoteconnections.view.ConnectionsView"; //$NON-NLS-1$ |
94 |
97 |
95 private TreeViewer viewer; |
98 private TreeViewer viewer; |
96 private IConnectionsManagerListener connectionStoreChangedListener; |
99 private IConnectionsManagerListener connectionStoreChangedListener; |
|
100 private IConnectionListener connectionListener; |
97 private Map<IConnectedService, IStatusChangedListener> serviceToListenerMap; |
101 private Map<IConnectedService, IStatusChangedListener> serviceToListenerMap; |
98 private List<Action> actions; |
102 private List<Action> actions; |
99 private List<Action> connectionSelectedActions; |
103 private List<Action> connectionSelectedActions; |
100 private List<Action> serviceSelectedActions; |
104 private List<Action> serviceSelectedActions; |
101 private static final String UID = ".uid"; //$NON-NLS-1$ |
105 private static final String UID = ".uid"; //$NON-NLS-1$ |
110 private static final String RENAME_ACTION = "ConnectionsView.rename"; //$NON-NLS-1$ |
114 private static final String RENAME_ACTION = "ConnectionsView.rename"; //$NON-NLS-1$ |
111 private static final String ENABLE_SERVICE_ACTION = "ConnectionsView.enableService"; //$NON-NLS-1$ |
115 private static final String ENABLE_SERVICE_ACTION = "ConnectionsView.enableService"; //$NON-NLS-1$ |
112 private static final String REFRESH_ACTION = "ConnectionsView.refresh"; //$NON-NLS-1$ |
116 private static final String REFRESH_ACTION = "ConnectionsView.refresh"; //$NON-NLS-1$ |
113 private static final String DELETE_ACTION = "ConnectionsView.delete"; //$NON-NLS-1$ |
117 private static final String DELETE_ACTION = "ConnectionsView.delete"; //$NON-NLS-1$ |
114 private static final String HELP_ACTION = "ConnectionsView.help"; //$NON-NLS-1$ |
118 private static final String HELP_ACTION = "ConnectionsView.help"; //$NON-NLS-1$ |
|
119 private static final String SET_DEFAULT_ACTION = "ConnectionsView.makeDefault"; //$NON-NLS-1$ |
115 private KeyAdapter keyListener; |
120 private KeyAdapter keyListener; |
116 private boolean isDisposed; |
121 private boolean isDisposed; |
|
122 |
|
123 // handle, do not dispose |
|
124 private Font boldViewerFont; |
117 |
125 |
118 private TreeNode[] loadConnections() { |
126 private TreeNode[] loadConnections() { |
119 if (serviceToListenerMap == null) |
127 if (serviceToListenerMap == null) |
120 serviceToListenerMap = new HashMap<IConnectedService, IStatusChangedListener>(); |
128 serviceToListenerMap = new HashMap<IConnectedService, IStatusChangedListener>(); |
121 removeServiceListeners(); |
129 removeServiceListeners(); |
199 private class NameLabelProvider extends ColumnLabelProvider { |
207 private class NameLabelProvider extends ColumnLabelProvider { |
200 |
208 |
201 public String getText(Object obj) { |
209 public String getText(Object obj) { |
202 return getNodeDisplayName(obj); |
210 return getNodeDisplayName(obj); |
203 } |
211 } |
|
212 |
|
213 /* (non-Javadoc) |
|
214 * @see org.eclipse.jface.viewers.ColumnLabelProvider#getFont(java.lang.Object) |
|
215 */ |
|
216 @Override |
|
217 public Font getFont(Object element) { |
|
218 if (element instanceof TreeNode) { |
|
219 if (((TreeNode)element).getValue().equals(Registry.instance().getDefaultConnection())) { |
|
220 return boldViewerFont; |
|
221 } |
|
222 } |
|
223 return super.getFont(element); |
|
224 } |
204 |
225 |
205 public Image getImage(Object obj) { |
226 public Image getImage(Object obj) { |
206 TreeNode node = (TreeNode) obj; |
227 TreeNode node = (TreeNode) obj; |
207 Object value = node.getValue(); |
228 Object value = node.getValue(); |
208 if (value instanceof IConnection) { |
229 if (value instanceof IConnection) { |
367 protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { |
388 protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) { |
368 return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; |
389 return event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC; |
369 } |
390 } |
370 }; |
391 }; |
371 TreeViewerEditor.create(viewer, activationStrategy, ColumnViewerEditor.DEFAULT); |
392 TreeViewerEditor.create(viewer, activationStrategy, ColumnViewerEditor.DEFAULT); |
|
393 |
|
394 boldViewerFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT); |
372 |
395 |
373 TreeViewerColumn typeColumn = new TreeViewerColumn(viewer, SWT.LEFT); |
396 TreeViewerColumn typeColumn = new TreeViewerColumn(viewer, SWT.LEFT); |
374 typeColumn.setLabelProvider(new TypeLabelProvider()); |
397 typeColumn.setLabelProvider(new TypeLabelProvider()); |
375 typeColumn.getColumn().setText(Messages.getString("ConnectionsView.TypeColumnHeader")); //$NON-NLS-1$ |
398 typeColumn.getColumn().setText(Messages.getString("ConnectionsView.TypeColumnHeader")); //$NON-NLS-1$ |
376 |
399 |
465 } |
488 } |
466 }); |
489 }); |
467 } |
490 } |
468 }; |
491 }; |
469 Registry.instance().addConnectionStoreChangedListener(connectionStoreChangedListener); |
492 Registry.instance().addConnectionStoreChangedListener(connectionStoreChangedListener); |
|
493 |
|
494 connectionListener = new IConnectionListener() { |
|
495 |
|
496 public void defaultConnectionSet(IConnection connection) { |
|
497 Display.getDefault().asyncExec(new Runnable() { |
|
498 public void run() { |
|
499 viewer.refresh(true); |
|
500 } |
|
501 }); |
|
502 } |
|
503 |
|
504 public void connectionRemoved(IConnection connection) { |
|
505 // presumably the viewer itself handles this... |
|
506 } |
|
507 |
|
508 public void connectionAdded(IConnection connection) { |
|
509 // presumably the viewer itself handles this... |
|
510 } |
|
511 }; |
|
512 Registry.instance().addConnectionListener(connectionListener); |
470 |
513 |
471 RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$ |
514 RemoteConnectionsActivator.setHelp(parent, ".connections_view"); //$NON-NLS-1$ |
472 } |
515 } |
473 |
516 |
474 private void packColumns() { |
517 private void packColumns() { |
524 manager.add(getAction(RENAME_ACTION)); |
567 manager.add(getAction(RENAME_ACTION)); |
525 manager.add(getAction(EDIT_ACTION)); |
568 manager.add(getAction(EDIT_ACTION)); |
526 manager.add(getAction(DELETE_ACTION)); |
569 manager.add(getAction(DELETE_ACTION)); |
527 manager.add(getAction(HELP_ACTION)); |
570 manager.add(getAction(HELP_ACTION)); |
528 } |
571 } |
|
572 if (value instanceof IConnection) { |
|
573 manager.add(getAction(SET_DEFAULT_ACTION)); |
|
574 } |
529 } |
575 } |
530 |
576 |
531 private void fillLocalToolBar(IToolBarManager manager) { |
577 private void fillLocalToolBar(IToolBarManager manager) { |
532 manager.add(getAction(REFRESH_ACTION)); |
578 manager.add(getAction(REFRESH_ACTION)); |
533 manager.add(getAction(NEW_ACTION)); |
579 manager.add(getAction(NEW_ACTION)); |
671 } |
717 } |
672 }; |
718 }; |
673 action.setId(HELP_ACTION); |
719 action.setId(HELP_ACTION); |
674 actions.add(action); |
720 actions.add(action); |
675 connectionSelectedActions.add(action); |
721 connectionSelectedActions.add(action); |
|
722 |
|
723 desc = ConnectionUIUtils.CONNECTION_IMGDESC; |
|
724 action = new Action(Messages.getString("ConnectionsView.SetDefaultActionLabel"), desc) { //$NON-NLS-1$ |
|
725 |
|
726 private IConnection getConnectionFromSelection() { |
|
727 ISelection selection = viewer.getSelection(); |
|
728 if (!selection.isEmpty()) { |
|
729 TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
730 Object value = treeNode.getValue(); |
|
731 if (value instanceof IConnection) { |
|
732 return ((IConnection) value); |
|
733 } |
|
734 } |
|
735 return null; |
|
736 } |
|
737 |
|
738 @Override |
|
739 public boolean isEnabled() { |
|
740 return !ObjectUtils.equals(Registry.instance().getDefaultConnection(), getConnectionFromSelection()); |
|
741 } |
|
742 |
|
743 @Override |
|
744 public void run() { |
|
745 Registry.instance().setDefaultConnection(getConnectionFromSelection()); |
|
746 } |
|
747 }; |
|
748 action.setId(SET_DEFAULT_ACTION); |
|
749 actions.add(action); |
|
750 connectionSelectedActions.add(action); |
|
751 |
676 enableConnectionSelectedActions(false); |
752 enableConnectionSelectedActions(false); |
677 enableServiceSelectedActions(false); |
753 enableServiceSelectedActions(false); |
678 } |
754 } |
679 |
755 |
680 private void enableConnectionSelectedActions(boolean enable) { |
756 private void enableConnectionSelectedActions(boolean enable) { |