Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/PapyrusLinkHelper.java')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/PapyrusLinkHelper.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/PapyrusLinkHelper.java b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/PapyrusLinkHelper.java
new file mode 100644
index 00000000000..22dff1ebe5f
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.onefile/src/org/eclipse/papyrus/infra/onefile/model/adapters/PapyrusLinkHelper.java
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos Origin Integration.
+ *
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tristan Faure (Atos Origin Integration) tristan.faure@atosorigin.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.onefile.model.adapters;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
+import org.eclipse.papyrus.infra.onefile.model.PapyrusModelHelper;
+import org.eclipse.papyrus.infra.onefile.utils.OneFileUtils;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.navigator.ILinkHelper;
+
+/**
+ * Link the Papyrus Editor with {@link IPapyrusFile}
+ *
+ * @author tristan.faure@atosorigin.com
+ *
+ */
+public class PapyrusLinkHelper implements ILinkHelper {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.
+ * IEditorInput)
+ */
+ public IStructuredSelection findSelection(IEditorInput anInput) {
+ List<Object> select = new ArrayList<Object>();
+ if(anInput instanceof IFileEditorInput) {
+ IFileEditorInput input = (IFileEditorInput)anInput;
+ IPapyrusFile papy = PapyrusModelHelper.getPapyrusModelFactory().createIPapyrusFile(input.getFile());
+ select.add(papy);
+ IResource res = papy.getMainFile();
+ while(res.getParent() != null) {
+ select.add(0, res.getParent());
+ res = res.getParent();
+ }
+ return new StructuredSelection(papy);
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.
+ * IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) {
+ if(selection == null || selection.isEmpty())
+ return;
+ Object element = selection.getFirstElement();
+ IEditorPart part = OneFileUtils.isOpenInEditor(element);
+ if(part != null) {
+ page.bringToTop(part);
+ }
+
+ }
+}

Back to the top