Bug 530749 - Model Fragment Editor should propose the 'xpath:/' value
when Application is selected

Change-Id: I556f61a518d1b65c0b526c02b436dd8dc68c00ba
Signed-off-by: Olivier Prouvost <olivier.prouvost@opcoach.com>
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
index 3c8a96a..9148771 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java
@@ -613,6 +613,7 @@
 	public String FindParentReferenceElementDialog_NoId;
 	public String FindParentReferenceElementDialog_ClearCache;
 	public String FindParentReferenceElementDialog_NoReferenceId;
+	public String FindParentReferenceElementDialog_AnyApplication;
 
 	public String HandledMenuItemCommandSelectionDialog_ShellTitle;
 	public String HandledMenuItemCommandSelectionDialog_DialogTitle;
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
index 555e793..5189766 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties
@@ -620,6 +620,7 @@
 FindParentReferenceElementDialog_ClearCache=Clear Cache
 FindParentReferenceElementDialog_NoReferenceId=You can not reference an element without an ID
 FindParentReferenceElementDialog_NoId=no ID
+FindParentReferenceElementDialog_AnyApplication=Any Application
 
 HandledMenuItemCommandSelectionDialog_ShellTitle=MenuItem Command
 HandledMenuItemCommandSelectionDialog_DialogTitle=MenuItem-Command
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FindParentReferenceElementDialog.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FindParentReferenceElementDialog.java
index 4920e5c..b1c38f5 100644
--- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FindParentReferenceElementDialog.java
+++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/component/dialogs/FindParentReferenceElementDialog.java
@@ -9,7 +9,7 @@
  * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
  * Steven Spungin <steven@spungin.tv> - Bug 437469
  * Patrik Suzzi <psuzzi@gmail.com> - Bug 467262
- * Olivier Prouvost <olivier.prouvost@opcoach.com> - Bug 509488, 509551
+ * Olivier Prouvost <olivier.prouvost@opcoach.com> - Bug 509488, 509551, 530749
  ******************************************************************************/
 package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;
 
@@ -24,7 +24,9 @@
 import org.eclipse.e4.tools.emf.ui.common.component.AbstractComponentEditor;
 import org.eclipse.e4.tools.emf.ui.internal.Messages;
 import org.eclipse.e4.tools.emf.ui.internal.common.ClassContributionCollector;
+import org.eclipse.e4.ui.model.application.MApplication;
 import org.eclipse.e4.ui.model.application.MApplicationElement;
+import org.eclipse.e4.ui.model.application.MApplicationFactory;
 import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
 import org.eclipse.e4.ui.model.fragment.MStringModelFragment;
 import org.eclipse.e4.ui.model.fragment.impl.FragmentPackageImpl;
@@ -66,6 +68,9 @@
 import org.osgi.framework.ServiceReference;
 
 public class FindParentReferenceElementDialog extends TitleAreaDialog {
+
+	private static final String XPATH_URI = "xpath:/"; //$NON-NLS-1$
+
 	private final MStringModelFragment fragment;
 	private final AbstractComponentEditor editor;
 	private TableViewer viewer;
@@ -206,7 +211,9 @@
 					styledString.append(" - " + detailLabel, StyledString.DECORATIONS_STYLER); //$NON-NLS-1$
 				}
 
-				styledString.append(" - " + o.eResource().getURI(), StyledString.COUNTER_STYLER); //$NON-NLS-1$
+				String resName = (o.eResource() == null ? Messages.FindParentReferenceElementDialog_AnyApplication
+						: o.eResource().getURI().toString());
+				styledString.append(" - " + resName, StyledString.COUNTER_STYLER); //$NON-NLS-1$
 				cell.setStyleRanges(styledString.getStyleRanges());
 				cell.setText(styledString.getString());
 			}
@@ -270,8 +277,16 @@
 		}
 		list.clear();
 
+		// Fix bug 530749 : add xpath:/ for application.
+		EClass selectedEClass = (EClass) ((IStructuredSelection) eClassViewer.getSelection()).getFirstElement();
+		if (selectedEClass.getName().equals("Application")) { //$NON-NLS-1$
+			MApplication anyAppli = MApplicationFactory.INSTANCE.createApplication();
+			anyAppli.setElementId(XPATH_URI);
+			list.add(anyAppli);
+		}
+
 		final Filter filter = new Filter(
-				(EClass) ((IStructuredSelection) eClassViewer.getSelection()).getFirstElement(), searchText.getText());
+				selectedEClass, searchText.getText());
 
 		currentResultHandler = new ModelResultHandlerImpl(list, filter, editor, ((EObject) fragment).eResource());
 		collector.findModelElements(filter, currentResultHandler);