From 8ad7699e2e19539c2691631a57cd0233ec378d77 Mon Sep 17 00:00:00 2001
From: Kisslinger <kisslinger@fortiss.org>
Date: Tue, 6 Mar 2012 12:10:20 +0000
Subject: [PATCH] Small enhancement to allow subclasses to limit accepted
 selections. Hope this is OK, else please contact me refs 692

---
 .../ui/dialog/ElementTreeSingleSelectDialog.java | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java
index f9069e228..b49234ea1 100644
--- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java
+++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/dialog/ElementTreeSingleSelectDialog.java
@@ -306,7 +306,8 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
 		// find the path to the element
 		ITreeSelection selection = (ITreeSelection) gui.getElementTreeViewer()
 				.getSelection();
-		if (selection.getPaths() == null || selection.getPaths().length != 1) {
+		if (selection.getPaths() == null || selection.getPaths().length != 1
+				|| !acceptElement(selection.getPaths()[0].getLastSegment())) {
 			selectedPath = null;
 			getButton(OK_ID).setEnabled(false);
 		} else {
@@ -315,6 +316,19 @@ public class ElementTreeSingleSelectDialog extends TitleAreaDialog {
 		}
 	}
 
+	/**
+	 * This method can be overwritten by subclasses to accept only elements of a
+	 * certain kind. For not-accepted elements the OK-field is disabled.
+	 * 
+	 * The default implementation accepts all elements.
+	 * 
+	 * @param element
+	 *            the element which is currently selected
+	 */
+	public boolean acceptElement(Object element) {
+		return true;
+	}
+
 	/**
 	 * Create the tree path from one of the given root elements to the child
 	 * element. The content provider will be used to compute the direct parent
-- 
GitLab