Use StructuredSelection directly.

Change-Id: I6b438e6199237ad0c23ce15b24bafd3bd2ec50d7
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclInterpretersBlock.java b/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclInterpretersBlock.java
index f4f2ffe..6503590 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclInterpretersBlock.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclInterpretersBlock.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2017 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -57,7 +57,7 @@
 		fetchInterpreterInformation.addSelectionListener(new SelectionListener() {
 			@Override
 			public void widgetSelected(SelectionEvent e) {
-				IStructuredSelection selection = (IStructuredSelection) fInterpreterList.getSelection();
+				IStructuredSelection selection = fInterpreterList.getStructuredSelection();
 				final IInterpreterInstall install = (IInterpreterInstall) selection.getFirstElement();
 				fetchInterpreterInformation(install);
 			}
@@ -73,7 +73,7 @@
 	protected void enableButtons() {
 		super.enableButtons();
 		if (fetchInterpreterInformation != null) {
-			IStructuredSelection selection = (IStructuredSelection) fInterpreterList.getSelection();
+			IStructuredSelection selection = fInterpreterList.getStructuredSelection();
 			int selectionCount = selection.size();
 			if (selectionCount == 1) {
 				fetchInterpreterInformation.setEnabled(true);
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclPackagesContainerPage.java b/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclPackagesContainerPage.java
index dacd301..1034cb6 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclPackagesContainerPage.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.debug.ui/src/org/eclipse/dltk/tcl/internal/debug/ui/interpreters/TclPackagesContainerPage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2016, 2017 xored software, Inc.  and others.
+ * Copyright (c) 2016, 2018 xored software, Inc.  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
@@ -200,30 +200,24 @@
 		this.fElements.setLabelProvider(new PackagesLabelProvider());
 		this.fElements.setInput(this.packages);
 		this.fElements.addSelectionChangedListener(event -> {
-			ISelection selection = event.getSelection();
-			if (selection instanceof IStructuredSelection) {
-				IStructuredSelection sel = (IStructuredSelection) selection;
-				remove.setEnabled(!sel.isEmpty());
-			}
+			ISelection selection = event.getStructuredSelection();
+			remove.setEnabled(!selection.isEmpty());
 		});
 		remove.setEnabled(false);
 	}
 
 	protected void removePackage() {
-		ISelection selection = this.fElements.getSelection();
-		if (selection instanceof IStructuredSelection) {
-			IStructuredSelection sel = (IStructuredSelection) selection;
-			boolean update = false;
-			for (Iterator iterator = sel.iterator(); iterator.hasNext();) {
-				String pkg = (String) iterator.next();
-				boolean res = this.packages.remove(pkg);
-				if (res) {
-					update = res;
-				}
+		IStructuredSelection sel = this.fElements.getStructuredSelection();
+		boolean update = false;
+		for (Iterator iterator = sel.iterator(); iterator.hasNext();) {
+			String pkg = (String) iterator.next();
+			boolean res = this.packages.remove(pkg);
+			if (res) {
+				update = res;
 			}
-			if (update) {
-				refreshView();
-			}
+		}
+		if (update) {
+			refreshView();
 		}
 	}
 
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.tclchecker/src/org/eclipse/dltk/tcl/internal/tclchecker/ui/preferences/TclCheckerInstanceBlock.java b/tcl/plugins/org.eclipse.dltk.tcl.tclchecker/src/org/eclipse/dltk/tcl/internal/tclchecker/ui/preferences/TclCheckerInstanceBlock.java
index 65b376f..d5b46d2 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.tclchecker/src/org/eclipse/dltk/tcl/internal/tclchecker/ui/preferences/TclCheckerInstanceBlock.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.tclchecker/src/org/eclipse/dltk/tcl/internal/tclchecker/ui/preferences/TclCheckerInstanceBlock.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2017 xored software, Inc. and others.
+ * Copyright (c) 2009, 2018 xored software, Inc. and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -358,14 +358,12 @@
 				if (environmentInstance == null) {
 					return;
 				}
-				final ISelection selection = pcxList.getSelection();
-				if (selection instanceof IStructuredSelection) {
-					for (Iterator<?> i = ((IStructuredSelection) selection).iterator(); i.hasNext();) {
-						final String path = (String) i.next();
-						environmentInstance.getPcxFileFolders().remove(path);
-						pcxList.remove(path);
-						validate();
-					}
+				final IStructuredSelection selection = pcxList.getStructuredSelection();
+				for (Iterator<?> i = selection.iterator(); i.hasNext();) {
+					final String path = (String) i.next();
+					environmentInstance.getPcxFileFolders().remove(path);
+					pcxList.remove(path);
+					validate();
 				}
 			}
 		});
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/GlobalVariableBlock.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/GlobalVariableBlock.java
index fce4d5f..798f186 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/GlobalVariableBlock.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/GlobalVariableBlock.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009 xored software, Inc.
+ * Copyright (c) 2009, 2018 xored software, Inc. and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -44,7 +44,7 @@
 /**
  * Control used to edit the environment variables associated with a Interpreter
  * install
- * 
+ *
  * @since 2.0
  */
 public class GlobalVariableBlock
@@ -70,7 +70,7 @@
 	 * Creates and returns the source lookup control.
 	 *
 	 * @param parent
-	 *            the parent widget of this control
+	 *                   the parent widget of this control
 	 */
 	public void createControlsIn(Composite parent) {
 		Font font = parent.getFont();
@@ -112,9 +112,9 @@
 	 * Creates and returns a button
 	 *
 	 * @param parent
-	 *            parent widget
+	 *                   parent widget
 	 * @param label
-	 *            label
+	 *                   label
 	 * @return Button
 	 */
 	protected Button createPushButton(Composite parent, String label) {
@@ -147,12 +147,11 @@
 		Object source = e.getSource();
 		if (source == fRemoveButton) {
 			fContentProvider.remove(
-					((IStructuredSelection) fVariablesViewer.getSelection())
-							.toList());
+					(fVariablesViewer.getStructuredSelection()).toList());
 		} else if (source == fAddButton) {
 			handleAdd();
 		} else if (source == fEditButton) {
-			edit((IStructuredSelection) fVariablesViewer.getSelection());
+			edit(fVariablesViewer.getStructuredSelection());
 		}
 		update();
 	}
@@ -231,8 +230,8 @@
 	 * Refresh the enable/disable state for the buttons.
 	 */
 	private void updateButtons() {
-		IStructuredSelection selection = (IStructuredSelection) fVariablesViewer
-				.getSelection();
+		IStructuredSelection selection = fVariablesViewer
+				.getStructuredSelection();
 		fRemoveButton.setEnabled(!selection.isEmpty());
 		fEditButton.setEnabled(selection.size() == 1);
 	}
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java
index 89c17ab..bc25b87 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2017 IBM Corporation and others.
+ * Copyright (c) 2005, 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
@@ -191,7 +191,7 @@
 	 * Creates and returns the source lookup control.
 	 *
 	 * @param parent
-	 *            the parent widget of this control
+	 *                   the parent widget of this control
 	 */
 	public Control createControl(Composite parent) {
 		Composite comp = new Composite(parent, SWT.NONE);
@@ -289,9 +289,9 @@
 	 * Creates and returns a button
 	 *
 	 * @param parent
-	 *            parent widget
+	 *                   parent widget
 	 * @param label
-	 *            label
+	 *                   label
 	 * @return Button
 	 */
 	protected Button createPushButton(Composite parent, String label) {
@@ -441,7 +441,7 @@
 	}
 
 	protected IStructuredSelection getSelection() {
-		return (IStructuredSelection) fLocationsViewer.getSelection();
+		return fLocationsViewer.getStructuredSelection();
 	}
 
 }
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsDialog.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsDialog.java
index 92fe7b2..a4e23d8 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsDialog.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsDialog.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2009, 2017 xored software, Inc. and others.
+ * Copyright (c) 2009, 2018 xored software, Inc. and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -349,7 +349,7 @@
 	}
 
 	protected IStructuredSelection getSelection() {
-		return (IStructuredSelection) pathViewer.getSelection();
+		return pathViewer.getStructuredSelection();
 	}
 
 	protected boolean canRemove(IStructuredSelection selection) {