Bug 578091 - The TrustCertificateDialog's Details... button is never
enabled

In the chain viewer,  set the selection when the input changes so that
the details button enables according to that selection and properly
update the Details... button when the selection is a tree node with a
certificate.

Change the menu item to copy the fingerprint from "Copy fingerprint" to
"Copy Fingerprint" (because it should be title case).

Use SWT.FULL_SELECTION for the checkbox table viewer so that selecting
in any column selects the row.

Properly enable/disable the Trust button depending on whether at least
one item is check marked (rather than based on whether the selected item
is check marked).

Change-Id: I932fbba94ea93691317845efd7ab454d509bd87d
Signed-off-by: Ed Merks <ed.merks@gmail.com>
Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.p2/+/189410
Tested-by: Equinox Bot <equinox-bot@eclipse.org>
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/TrustCertificateDialog.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/TrustCertificateDialog.java
index f81e31e..5ffad2e 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/TrustCertificateDialog.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/TrustCertificateDialog.java
@@ -133,20 +133,19 @@
 		certificateChainViewer.setContentProvider(new TreeNodeContentProvider());
 		certificateChainViewer.setLabelProvider(new CertificateLabelProvider());
 		certificateChainViewer.addSelectionChangedListener(getChainSelectionListener());
+		listViewer.addDoubleClickListener(getDoubleClickListener());
+		listViewer.addSelectionChangedListener(getParentSelectionListener());
+		createButtons(composite);
 		if (inputElement instanceof Object[]) {
 			ISelection selection = null;
 			Object[] nodes = (Object[]) inputElement;
 			if (nodes.length > 0) {
 				selection = new StructuredSelection(nodes[0]);
 				certificateChainViewer.setInput(new TreeNode[] { (TreeNode) nodes[0] });
-				selectedCertificate = nodes[0];
+				certificateChainViewer.setSelection(selection);
 			}
 			listViewer.setSelection(selection);
 		}
-		listViewer.addDoubleClickListener(getDoubleClickListener());
-		listViewer.addSelectionChangedListener(getParentSelectionListener());
-		createButtons(composite);
-		detailsButton.setEnabled(selectedCertificate instanceof X509Certificate);
 		return composite;
 	}
 
@@ -241,7 +240,7 @@
 		initializeDialogUnits(composite);
 		createMessageArea(composite);
 
-		listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
+		listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
 		GridData data = new GridData(GridData.FILL_BOTH);
 		data.heightHint = SIZING_SELECTION_WIDGET_HEIGHT;
 		data.widthHint = SIZING_SELECTION_WIDGET_WIDTH;
@@ -352,7 +351,8 @@
 			ISelection selection = event.getSelection();
 			if (selection instanceof StructuredSelection) {
 				selectedCertificate = ((StructuredSelection) selection).getFirstElement();
-				detailsButton.setEnabled(selectedCertificate instanceof X509Certificate);
+				detailsButton.setEnabled(selectedCertificate instanceof TreeNode
+						&& ((TreeNode) selectedCertificate).getValue() instanceof X509Certificate);
 			}
 		};
 	}
@@ -383,8 +383,13 @@
 			if (selection instanceof StructuredSelection) {
 				TreeNode firstElement = (TreeNode) ((StructuredSelection) selection).getFirstElement();
 				getCertificateChainViewer().setInput(new TreeNode[] { firstElement });
-				getOkButton().setEnabled(listViewer.getChecked(firstElement));
-				getCertificateChainViewer().refresh();
+				if (firstElement.getValue() instanceof X509Certificate) {
+					getCertificateChainViewer().setSelection(new StructuredSelection(firstElement));
+				}
+				Button okButton = getOkButton();
+				if (okButton != null) {
+					okButton.setEnabled(listViewer.getCheckedElements().length > 0);
+				}
 			}
 		};
 	}
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties
index 8d84b0c..a26826e 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/messages.properties
@@ -288,7 +288,7 @@
 TrustCertificateDialog_ObjectType=Type
 TrustCertificateDialog_Id=Id/Fingerprint
 TrustCertificateDialog_Name=Name \u26A0\uFE0F This is not trustworthy until key/certificate is verified
-TrustCertificateDialog_CopyFingerprint=Copy fingerprint
+TrustCertificateDialog_CopyFingerprint=Copy Fingerprint
 TrustCertificateDialog_dates=Validity Dates
 TrustCertificateDialog_NotYetValidStartDate=\u274C Not yet valid, starts {0}
 TrustCertificateDialog_expiredSince=\u274C Expired since {0}