Bug 476839 - RequiredSelectionException in requireSelection 

DeleteProjectHandler first checks whether selection is available, if
not it returns without any effect

Change-Id: I812db6f3ff0b3f7502163b44ba60e5d74c58a689
diff --git a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/AbstractEMFStoreHandlerWithResult.java b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/AbstractEMFStoreHandlerWithResult.java
index c6efcf4..12b823e 100644
--- a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/AbstractEMFStoreHandlerWithResult.java
+++ b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/AbstractEMFStoreHandlerWithResult.java
@@ -7,8 +7,8 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- * ovonwesen
- * emueller
+ * Otto von Wesendonk, Edgar Mueller - initial implementation and API
+ * Edgar Mueller - Bug 476839
  ******************************************************************************/
 package org.eclipse.emf.emfstore.internal.client.ui.handlers;
 
@@ -92,6 +92,22 @@
 	}
 
 	/**
+	 * Returns whether an object of the given <code>clazz</code>
+	 * can be extracted from the current selection.
+	 *
+	 * @param clazz
+	 *            the type of the object that is requested to be extracted from the current selection
+	 * @return {@code true}, if an object of type <b>T</b> is contained within the current selection,
+	 *         {@code false} otherwise
+	 *
+	 *
+	 * @param <U> the type of the object to be extracted from the current selection
+	 */
+	public <U> boolean hasSelection(Class<U> clazz) {
+		return EMFStoreHandlerUtil.hasSelection(getEvent(), clazz);
+	}
+
+	/**
 	 * Returns the currently active shell.
 	 *
 	 * @return the active shell
diff --git a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/DeleteProjectHandler.java b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/DeleteProjectHandler.java
index f070081..7248263 100644
--- a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/DeleteProjectHandler.java
+++ b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/handlers/DeleteProjectHandler.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012-2013 EclipseSource Muenchen GmbH and others.
+ * Copyright (c) 2012-2016 EclipseSource Muenchen GmbH and others.
  *
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -7,8 +7,8 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- * ovonwesen
- * emueller
+ * Otto von Wesendonk, Edgar Mueller - initial implementation and API
+ * Edgar Mueller - Bug 476839
  ******************************************************************************/
 package org.eclipse.emf.emfstore.internal.client.ui.handlers;
 
@@ -32,6 +32,9 @@
 	 */
 	@Override
 	public void handle() {
+		if (!hasSelection(ProjectSpace.class)) {
+			return;
+		}
 		new UIDeleteProjectController(getShell(), requireSelection(ProjectSpace.class).toAPI()).execute();
 	}
 }
diff --git a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/util/EMFStoreHandlerUtil.java b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/util/EMFStoreHandlerUtil.java
index 3bc67ac..721aacb 100644
--- a/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/util/EMFStoreHandlerUtil.java
+++ b/bundles/org.eclipse.emf.emfstore.client.ui/src/org/eclipse/emf/emfstore/internal/client/ui/util/EMFStoreHandlerUtil.java
@@ -7,7 +7,8 @@
  * http://www.eclipse.org/legal/epl-v10.html
  *
  * Contributors:
- * ovonwesen
+ * Otto von Wesendonk - initial implementation and API
+ * Edgar Mueller - Bug 476839
  ******************************************************************************/
 package org.eclipse.emf.emfstore.internal.client.ui.util;
 
@@ -86,4 +87,21 @@
 		return selection;
 	}
 
+	/**
+	 * Returns whether an object of the given <code>clazz</code> can be extracted from
+	 * the current selection.
+	 *
+	 * @param event
+	 *            the event from which to extract the selection
+	 * @param clazz
+	 *            the type of the object that is requested to be extracted from the current selection
+	 * @return {@code true} if an object of type <b>T</b> is contained within the current selection,
+	 *         {@code false} otherwise
+	 *
+	 * @param <T> the type of the object to be extracted from the current selection
+	 */
+	public static <T> boolean hasSelection(ExecutionEvent event, Class<T> clazz) {
+		final T selection = getSelection(event, clazz);
+		return selection != null;
+	}
 }