16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 package com.nokia.carbide.remoteconnections.view; |
19 package com.nokia.carbide.remoteconnections.view; |
20 |
20 |
|
21 import java.text.MessageFormat; |
21 import java.util.ArrayList; |
22 import java.util.ArrayList; |
22 import java.util.Collection; |
23 import java.util.Collection; |
23 import java.util.HashMap; |
24 import java.util.HashMap; |
24 import java.util.List; |
25 import java.util.List; |
25 import java.util.Map; |
26 import java.util.Map; |
26 |
27 |
27 import org.eclipse.jface.action.Action; |
28 import org.eclipse.jface.action.Action; |
|
29 import org.eclipse.jface.action.IAction; |
28 import org.eclipse.jface.action.IMenuListener; |
30 import org.eclipse.jface.action.IMenuListener; |
29 import org.eclipse.jface.action.IMenuManager; |
31 import org.eclipse.jface.action.IMenuManager; |
30 import org.eclipse.jface.action.IToolBarManager; |
32 import org.eclipse.jface.action.IToolBarManager; |
31 import org.eclipse.jface.action.LegacyActionTools; |
33 import org.eclipse.jface.action.LegacyActionTools; |
32 import org.eclipse.jface.action.MenuManager; |
34 import org.eclipse.jface.action.MenuManager; |
|
35 import org.eclipse.jface.action.Separator; |
33 import org.eclipse.jface.resource.ImageDescriptor; |
36 import org.eclipse.jface.resource.ImageDescriptor; |
34 import org.eclipse.jface.resource.JFaceResources; |
37 import org.eclipse.jface.resource.JFaceResources; |
35 import org.eclipse.jface.viewers.CellEditor; |
38 import org.eclipse.jface.viewers.CellEditor; |
36 import org.eclipse.jface.viewers.ColumnLabelProvider; |
39 import org.eclipse.jface.viewers.ColumnLabelProvider; |
37 import org.eclipse.jface.viewers.ColumnViewer; |
40 import org.eclipse.jface.viewers.ColumnViewer; |
72 |
75 |
73 import com.nokia.carbide.remoteconnections.Messages; |
76 import com.nokia.carbide.remoteconnections.Messages; |
74 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
77 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
75 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
78 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
76 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
79 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
80 import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; |
77 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
81 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
78 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
82 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
79 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
83 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
80 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
84 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
81 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; |
85 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener; |
587 ISelection selection = viewer.getSelection(); |
591 ISelection selection = viewer.getSelection(); |
588 if (selection.isEmpty()) |
592 if (selection.isEmpty()) |
589 return; |
593 return; |
590 TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
594 TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
591 Object value = node.getValue(); |
595 Object value = node.getValue(); |
592 if (value instanceof IConnectedService) |
596 if (value instanceof IConnectedService) { |
|
597 manager.add(new Separator()); |
593 manager.add(getAction(ENABLE_SERVICE_ACTION)); |
598 manager.add(getAction(ENABLE_SERVICE_ACTION)); |
594 else { |
599 } |
|
600 else if (value instanceof IConnection) { |
|
601 manager.add(new Separator()); |
595 manager.add(getAction(RENAME_ACTION)); |
602 manager.add(getAction(RENAME_ACTION)); |
596 manager.add(getAction(EDIT_ACTION)); |
603 manager.add(getAction(EDIT_ACTION)); |
597 manager.add(getAction(DELETE_ACTION)); |
604 manager.add(getAction(DELETE_ACTION)); |
598 manager.add(getAction(HELP_ACTION)); |
605 IAction helpAction = getAction(HELP_ACTION); |
599 } |
606 if (helpAction.isEnabled()) { |
600 if (value instanceof IConnection) { |
607 helpAction.setText(helpAction.getText()); |
|
608 manager.add(helpAction); |
|
609 } |
601 manager.add(getAction(SET_DEFAULT_ACTION)); |
610 manager.add(getAction(SET_DEFAULT_ACTION)); |
602 } |
611 } |
603 } |
612 } |
604 |
613 |
605 private void fillLocalToolBar(IToolBarManager manager) { |
614 private void fillLocalToolBar(IToolBarManager manager) { |
718 actions.add(action); |
727 actions.add(action); |
719 connectionSelectedActions.add(action); |
728 connectionSelectedActions.add(action); |
720 |
729 |
721 Image image = JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_HELP); |
730 Image image = JFaceResources.getImage(org.eclipse.jface.dialogs.Dialog.DLG_IMG_HELP); |
722 ImageDescriptor desc = ImageDescriptor.createFromImage(image); |
731 ImageDescriptor desc = ImageDescriptor.createFromImage(image); |
723 action = new Action(Messages.getString("ConnectionsView.HelpActionLabel"), desc) { //$NON-NLS-1$ |
732 action = new Action(Messages.getString("ConnectionsView.NoHelpActionLabel"), desc) { //$NON-NLS-1$ |
724 |
733 |
725 private String getHelpContextFromSelection() { |
734 private String getHelpContextFromSelection() { |
726 ISelection selection = viewer.getSelection(); |
735 IConnection connection = getSelectedConnection(); |
727 if (!selection.isEmpty()) { |
736 if (connection != null) { |
728 TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
737 return connection.getConnectionType().getHelpContext(); |
729 Object value = treeNode.getValue(); |
|
730 if (value instanceof IConnection) { |
|
731 return ((IConnection) value).getConnectionType().getHelpContext(); |
|
732 } |
|
733 } |
738 } |
734 return null; |
739 return null; |
|
740 } |
|
741 |
|
742 @Override |
|
743 public String getText() { |
|
744 if (isEnabled()) { |
|
745 IConnection connection = getSelectedConnection(); |
|
746 IConnectionType connectionType = connection.getConnectionType(); |
|
747 String displayName = connectionType.getDisplayName(); |
|
748 String pattern = Messages.getString("ConnectionsView.HelpActionLabel"); //$NON-NLS-1$ |
|
749 return MessageFormat.format(pattern, displayName); |
|
750 } |
|
751 return super.getText(); |
735 } |
752 } |
736 |
753 |
737 @Override |
754 @Override |
738 public boolean isEnabled() { |
755 public boolean isEnabled() { |
739 return getHelpContextFromSelection() != null; |
756 return getHelpContextFromSelection() != null; |
749 connectionSelectedActions.add(action); |
766 connectionSelectedActions.add(action); |
750 |
767 |
751 desc = ConnectionUIUtils.CONNECTION_IMGDESC; |
768 desc = ConnectionUIUtils.CONNECTION_IMGDESC; |
752 action = new Action(Messages.getString("ConnectionsView.SetDefaultActionLabel"), desc) { //$NON-NLS-1$ |
769 action = new Action(Messages.getString("ConnectionsView.SetDefaultActionLabel"), desc) { //$NON-NLS-1$ |
753 |
770 |
754 private IConnection getConnectionFromSelection() { |
|
755 ISelection selection = viewer.getSelection(); |
|
756 if (!selection.isEmpty()) { |
|
757 TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
758 Object value = treeNode.getValue(); |
|
759 if (value instanceof IConnection) { |
|
760 return ((IConnection) value); |
|
761 } |
|
762 } |
|
763 return null; |
|
764 } |
|
765 |
|
766 @Override |
771 @Override |
767 public boolean isEnabled() { |
772 public boolean isEnabled() { |
768 return !ObjectUtils.equals(Registry.instance().getDefaultConnection(), getConnectionFromSelection()); |
773 return !ObjectUtils.equals(Registry.instance().getDefaultConnection(), getSelectedConnection()); |
769 } |
774 } |
770 |
775 |
771 @Override |
776 @Override |
772 public void run() { |
777 public void run() { |
773 Registry.instance().setDefaultConnection(getConnectionFromSelection()); |
778 Registry.instance().setDefaultConnection(getSelectedConnection()); |
774 } |
779 } |
775 }; |
780 }; |
776 action.setId(SET_DEFAULT_ACTION); |
781 action.setId(SET_DEFAULT_ACTION); |
777 actions.add(action); |
782 actions.add(action); |
778 connectionSelectedActions.add(action); |
783 connectionSelectedActions.add(action); |
872 if (selection.isEmpty()) |
877 if (selection.isEmpty()) |
873 return false; |
878 return false; |
874 TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
879 TreeNode node = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
875 return !isDynamicConnection(node.getValue()); |
880 return !isDynamicConnection(node.getValue()); |
876 } |
881 } |
|
882 |
|
883 private IConnection getSelectedConnection() { |
|
884 ISelection selection = viewer.getSelection(); |
|
885 if (!selection.isEmpty()) { |
|
886 TreeNode treeNode = (TreeNode) ((IStructuredSelection) selection).getFirstElement(); |
|
887 Object value = treeNode.getValue(); |
|
888 if (value instanceof IConnection) { |
|
889 return (IConnection) value; |
|
890 } |
|
891 } |
|
892 return null; |
|
893 } |
|
894 |
877 } |
895 } |
878 |
896 |