Bug 533758 - Direct use of IStructuredSelection

Instead of getSelection and cast. Enable save actions to auto remove
useless casts.

Change-Id: Ie9fd9546ac74d146a9fa219e37d012d7a3e79415
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.p2.ui.admin/.settings/org.eclipse.jdt.ui.prefs
index c94f559..cd99f0d 100644
--- a/bundles/org.eclipse.equinox.p2.ui.admin/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.equinox.p2.ui.admin/.settings/org.eclipse.jdt.ui.prefs
@@ -1,4 +1,3 @@
-#Sun Sep 23 11:59:19 EDT 2007
 eclipse.preferences.version=1
 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
 formatter_profile=_core
@@ -12,22 +11,29 @@
 sp_cleanup.add_generated_serial_version_id=false
 sp_cleanup.add_missing_annotations=true
 sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
 sp_cleanup.add_missing_nls_tags=false
 sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=false
 sp_cleanup.add_serial_version_id=false
 sp_cleanup.always_use_blocks=true
 sp_cleanup.always_use_parentheses_in_expressions=false
 sp_cleanup.always_use_this_for_non_static_field_access=false
 sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_functional_interfaces=false
 sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=false
 sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.insert_inferred_type_arguments=false
 sp_cleanup.make_local_variable_final=false
 sp_cleanup.make_parameters_final=false
 sp_cleanup.make_private_fields_final=true
-sp_cleanup.make_variable_declarations_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
 sp_cleanup.never_use_blocks=false
 sp_cleanup.never_use_parentheses_in_expressions=true
-sp_cleanup.on_save_use_additional_actions=false
+sp_cleanup.on_save_use_additional_actions=true
 sp_cleanup.organize_imports=true
 sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
 sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
@@ -35,6 +41,7 @@
 sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
 sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
 sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_type_arguments=true
 sp_cleanup.remove_trailing_whitespaces=false
 sp_cleanup.remove_trailing_whitespaces_all=true
 sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
@@ -48,8 +55,10 @@
 sp_cleanup.remove_unused_private_types=true
 sp_cleanup.sort_members=false
 sp_cleanup.sort_members_all=false
+sp_cleanup.use_anonymous_class_creation=false
 sp_cleanup.use_blocks=false
 sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_lambda=false
 sp_cleanup.use_parentheses_in_expressions=false
 sp_cleanup.use_this_for_non_static_field_access=false
 sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProfilesView.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProfilesView.java
index ff801c7..7ac5ff7 100644
--- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProfilesView.java
+++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProfilesView.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2007, 2017 IBM Corporation and others.
+ *  Copyright (c) 2007, 2018 IBM Corporation and others.
  *  All rights reserved. This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
@@ -154,7 +154,7 @@
 		});
 
 		// prime the action validation
-		selectionChanged((IStructuredSelection) viewer.getSelection());
+		selectionChanged(viewer.getStructuredSelection());
 	}
 
 	@Override
diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProvView.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProvView.java
index 3006594..49b95db 100644
--- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProvView.java
+++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/ProvView.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2007, 2017 IBM Corporation and others.
+ * Copyright (c) 2007, 2018 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -174,7 +174,7 @@
 	}
 
 	protected IStructuredSelection getSelection() {
-		return (IStructuredSelection) viewer.getSelection();
+		return viewer.getStructuredSelection();
 	}
 
 	protected void run(ProvisioningJob job) {
diff --git a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/RepositoriesView.java b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/RepositoriesView.java
index 6a926e5..d1b3a7e 100644
--- a/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/RepositoriesView.java
+++ b/bundles/org.eclipse.equinox.p2.ui.admin/src/org/eclipse/equinox/internal/p2/ui/admin/RepositoriesView.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2007, 2017 IBM Corporation and others.
+ *  Copyright (c) 2007, 2018 IBM Corporation and others.
  *  All rights reserved. This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
@@ -156,7 +156,7 @@
 			removeRepositoryAction.setEnabled(false);
 		}
 		viewer.addSelectionChangedListener(event -> {
-			IStructuredSelection ss = (IStructuredSelection) event.getSelection();
+			IStructuredSelection ss = event.getStructuredSelection();
 			RepositoriesView.this.selectionChanged(ss);
 		});
 	}
diff --git a/bundles/org.eclipse.equinox.p2.ui/.settings/org.eclipse.jdt.ui.prefs b/bundles/org.eclipse.equinox.p2.ui/.settings/org.eclipse.jdt.ui.prefs
index dbe72f1..cd99f0d 100644
--- a/bundles/org.eclipse.equinox.p2.ui/.settings/org.eclipse.jdt.ui.prefs
+++ b/bundles/org.eclipse.equinox.p2.ui/.settings/org.eclipse.jdt.ui.prefs
@@ -1,4 +1,3 @@
-#Sun Sep 23 11:59:14 EDT 2007
 eclipse.preferences.version=1
 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
 formatter_profile=_core
@@ -12,22 +11,29 @@
 sp_cleanup.add_generated_serial_version_id=false
 sp_cleanup.add_missing_annotations=true
 sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
 sp_cleanup.add_missing_nls_tags=false
 sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=false
 sp_cleanup.add_serial_version_id=false
 sp_cleanup.always_use_blocks=true
 sp_cleanup.always_use_parentheses_in_expressions=false
 sp_cleanup.always_use_this_for_non_static_field_access=false
 sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_functional_interfaces=false
 sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=false
 sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.insert_inferred_type_arguments=false
 sp_cleanup.make_local_variable_final=false
 sp_cleanup.make_parameters_final=false
 sp_cleanup.make_private_fields_final=true
-sp_cleanup.make_variable_declarations_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
 sp_cleanup.never_use_blocks=false
 sp_cleanup.never_use_parentheses_in_expressions=true
-sp_cleanup.on_save_use_additional_actions=false
+sp_cleanup.on_save_use_additional_actions=true
 sp_cleanup.organize_imports=true
 sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
 sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
@@ -35,6 +41,7 @@
 sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
 sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
 sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_redundant_type_arguments=true
 sp_cleanup.remove_trailing_whitespaces=false
 sp_cleanup.remove_trailing_whitespaces_all=true
 sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
@@ -48,8 +55,10 @@
 sp_cleanup.remove_unused_private_types=true
 sp_cleanup.sort_members=false
 sp_cleanup.sort_members_all=false
+sp_cleanup.use_anonymous_class_creation=false
 sp_cleanup.use_blocks=false
 sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_lambda=false
 sp_cleanup.use_parentheses_in_expressions=false
 sp_cleanup.use_this_for_non_static_field_access=false
 sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUGroup.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUGroup.java
index 664b1a7..2b89697 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUGroup.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUGroup.java
@@ -291,7 +291,7 @@
 	// overridden to weed out non-IU elements, such as repositories or empty explanations
 	@Override
 	public Object[] getSelectedIUElements() {
-		Object[] elements = ((IStructuredSelection) viewer.getSelection()).toArray();
+		Object[] elements = viewer.getStructuredSelection().toArray();
 		ArrayList<Object> list = new ArrayList<>(elements.length);
 		for (int i = 0; i < elements.length; i++)
 			if (ElementUtils.getIU(elements[i]) != null)
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java
index 1e41172..a2e7760 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/AvailableIUsPage.java
@@ -30,7 +30,6 @@
 import org.eclipse.jface.layout.GridLayoutFactory;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.viewers.IContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.SashForm;
@@ -603,7 +602,7 @@
 
 	void updateDetails() {
 		// First look for an empty explanation.
-		Object[] elements = ((IStructuredSelection) availableIUGroup.getStructuredViewer().getSelection()).toArray();
+		Object[] elements = availableIUGroup.getStructuredViewer().getStructuredSelection().toArray();
 		if (elements.length == 1 && elements[0] instanceof EmptyElementExplanation) {
 			String description = ((EmptyElementExplanation) elements[0]).getDescription();
 			if (description != null) {
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionResultsWizardPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionResultsWizardPage.java
index 5bb486d..336c9a8 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionResultsWizardPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/ResolutionResultsWizardPage.java
@@ -227,7 +227,7 @@
 
 	@Override
 	protected Object[] getSelectedElements() {
-		return ((IStructuredSelection) treeViewer.getSelection()).toArray();
+		return treeViewer.getStructuredSelection().toArray();
 	}
 
 	@Override
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java
index d1934c6..291362f 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/SelectableIUsPage.java
@@ -25,7 +25,6 @@
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.SashForm;
@@ -215,12 +214,12 @@
 
 	@Override
 	public Object[] getSelectedIUElements() {
-		return ((IStructuredSelection) tableViewer.getSelection()).toArray();
+		return tableViewer.getStructuredSelection().toArray();
 	}
 
 	@Override
 	protected Object[] getSelectedElements() {
-		return ((IStructuredSelection) tableViewer.getSelection()).toArray();
+		return tableViewer.getStructuredSelection().toArray();
 	}
 
 	protected IInstallableUnit[] elementsToIUs(Object[] elements) {
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java
index 72a89e5..cc4ad3e 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/internal/p2/ui/dialogs/StructuredIUGroup.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- *  Copyright (c) 2008, 2011 IBM Corporation and others.
+ *  Copyright (c) 2008, 2018 IBM Corporation and others.
  *  All rights reserved. This program and the accompanying materials
  *  are made available under the terms of the Eclipse Public License v1.0
  *  which accompanies this distribution, and is available at
@@ -20,7 +20,6 @@
 import org.eclipse.equinox.p2.ui.Policy;
 import org.eclipse.equinox.p2.ui.ProvisioningUI;
 import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.StructuredViewer;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.*;
@@ -110,7 +109,7 @@
 	}
 
 	public Object[] getSelectedIUElements() {
-		return ((IStructuredSelection) viewer.getSelection()).toArray();
+		return viewer.getStructuredSelection().toArray();
 	}
 
 	protected int convertHorizontalDLUsToPixels(int dlus) {
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/AcceptLicensesWizardPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/AcceptLicensesWizardPage.java
index 48c3bba..462631c 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/AcceptLicensesWizardPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/AcceptLicensesWizardPage.java
@@ -217,7 +217,7 @@
 		iuViewer.setComparator(new ViewerComparator());
 		iuViewer.setInput(licensesToIUs);
 
-		iuViewer.addSelectionChangedListener(event -> handleSelectionChanged((IStructuredSelection) event.getSelection()));
+		iuViewer.addSelectionChangedListener(event -> handleSelectionChanged(event.getStructuredSelection()));
 		gd = new GridData(GridData.FILL_BOTH);
 		gd.widthHint = convertWidthInCharsToPixels(ILayoutConstants.DEFAULT_PRIMARY_COLUMN_WIDTH);
 		gd.heightHint = convertHeightInCharsToPixels(ILayoutConstants.DEFAULT_TABLE_HEIGHT);
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java
index 38532af..05c6340 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RepositoryManipulationPage.java
@@ -506,7 +506,7 @@
 	}
 
 	MetadataRepositoryElement[] getSelectedElements() {
-		Object[] items = ((IStructuredSelection) repositoryViewer.getSelection()).toArray();
+		Object[] items = repositoryViewer.getStructuredSelection().toArray();
 		ArrayList<Object> list = new ArrayList<>(items.length);
 		for (int i = 0; i < items.length; i++) {
 			if (items[i] instanceof MetadataRepositoryElement)
diff --git a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RevertProfilePage.java b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RevertProfilePage.java
index ef058c3..b8ef51b 100644
--- a/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RevertProfilePage.java
+++ b/bundles/org.eclipse.equinox.p2.ui/src/org/eclipse/equinox/p2/ui/RevertProfilePage.java
@@ -207,7 +207,7 @@
 		});
 		configsViewer.setInput(getInput());
 
-		configsViewer.addSelectionChangedListener(event -> handleSelectionChanged((IStructuredSelection) event.getSelection()));
+		configsViewer.addSelectionChangedListener(event -> handleSelectionChanged(event.getStructuredSelection()));
 		CopyUtils.activateCopy(this, configsViewer.getControl());
 		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
 		configsViewer.getControl().setLayoutData(gd);
@@ -333,7 +333,7 @@
 	boolean computeDeleteEnablement() {
 		// delete is permitted if none of the selected elements are the current profile
 		boolean okToDelete = true;
-		Iterator<?> iter = ((IStructuredSelection) configsViewer.getSelection()).iterator();
+		Iterator<?> iter = configsViewer.getStructuredSelection().iterator();
 		while (iter.hasNext()) {
 			Object selected = iter.next();
 			// If it's not a recognized element or if it is the current profile, we can't delete.  Stop iterating.
@@ -358,7 +358,7 @@
 	}
 
 	private IProfile getSelectedSnapshot() {
-		Object selected = ((IStructuredSelection) configsViewer.getSelection()).getFirstElement();
+		Object selected = configsViewer.getStructuredSelection().getFirstElement();
 		if (selected != null && selected instanceof RollbackProfileElement)
 			return ((RollbackProfileElement) selected).getProfileSnapshot(new NullProgressMonitor());
 		return null;
@@ -412,9 +412,9 @@
 	public void copyToClipboard(Control activeControl) {
 		String text = ""; //$NON-NLS-1$
 		if (activeControl == configContentsViewer.getControl()) {
-			text = CopyUtils.getIndentedClipboardText(((IStructuredSelection) configContentsViewer.getSelection()).toArray(), labelProvider);
+			text = CopyUtils.getIndentedClipboardText(configContentsViewer.getStructuredSelection().toArray(), labelProvider);
 		} else if (activeControl == configsViewer.getControl()) {
-			Object[] elements = ((IStructuredSelection) configsViewer.getSelection()).toArray();
+			Object[] elements = configsViewer.getStructuredSelection().toArray();
 			StringBuffer buffer = new StringBuffer();
 			for (int i = 0; i < elements.length; i++) {
 				if (elements[i] instanceof RollbackProfileElement) {
@@ -434,7 +434,7 @@
 	}
 
 	void deleteSelectedSnapshots() {
-		IStructuredSelection selection = (IStructuredSelection) configsViewer.getSelection();
+		IStructuredSelection selection = configsViewer.getStructuredSelection();
 		if (selection.isEmpty())
 			return;
 		String title = selection.size() == 1 ? ProvUIMessages.RevertProfilePage_DeleteSingleConfigurationTitle : ProvUIMessages.RevertProfilePage_DeleteMultipleConfigurationsTitle;
@@ -472,7 +472,7 @@
 	}
 
 	protected IStructuredSelection getSelection() {
-		return (IStructuredSelection) configsViewer.getSelection();
+		return configsViewer.getStructuredSelection();
 	}
 
 	/**