blob: 8cee453617d6db3e547779dab5ac14b41599aba8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*****************************************************************************
* 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.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.onefile.model.IPapyrusFile;
import org.eclipse.papyrus.onefile.model.PapyrusModelHelper;
import org.eclipse.papyrus.onefile.utils.Utils;
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 = Utils.isOpenInEditor(element);
if (part != null) {
page.bringToTop(part);
}
}
}
|