Skip to main content
summaryrefslogtreecommitdiffstats
blob: b061f7e36152edec09c083f7c534d7d8f3b42a16 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2005, 2006 committers of openArchitectureWare and others.
 * 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:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/
package org.eclipse.xtend.ui.editor.outline;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.internal.xtend.xtend.ast.CreateExtensionStatement;
import org.eclipse.internal.xtend.xtend.ast.Extension;
import org.eclipse.internal.xtend.xtend.ast.ExtensionFile;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.xtend.shared.ui.editor.AbstractXtendXpandEditor;
import org.eclipse.xtend.shared.ui.editor.outlineview.AbstractExtXptContentOutlinePage;
import org.eclipse.xtend.shared.ui.editor.outlineview.OutlineElement;
import org.eclipse.xtend.shared.ui.expression.editor.EditorImages;
import org.eclipse.xtend.ui.core.IXtendResource;


public class XtendContentOutlinePage extends AbstractExtXptContentOutlinePage {

	public static final int PRIVATE_CREATE_EXTENSION = 2,
			PRIVATE_EXTENSION = 3, CREATE_EXTENSION = 4, EXTENSION = 5;

	public XtendContentOutlinePage(AbstractXtendXpandEditor editor) {
		super(editor);
	}

	@Override
	protected OutlineElement[] getChildren(Object parentElement) {
		if (parentElement instanceof IXtendResource) {
			ExtensionFile xr = (ExtensionFile) ((IXtendResource) parentElement)
					.getExtXptResource();
			if (xr==null)
				return new OutlineElement[0];
			List<OutlineElement> result = new ArrayList<OutlineElement>();
			result.addAll(toOutlineElementsForNamespaceImports(xr
					.getNsImports()));
			result.addAll(toOutlineElementsForExtensionImports(xr
					.getExtImports()));
			result.addAll(toOutlineElements(xr.getExtensions()));
			return result.toArray(new OutlineElement[result.size()]);
		}
		return new OutlineElement[0];
	}

	//Since ImportStatements are used above, we can just use the superclass' methods
	//toOutlineElementsForNamespaceImports and toOutlineElementsForExtensionImports

	private List<OutlineElement> toOutlineElements(List<Extension> extensions) {
		List<OutlineElement> l = new ArrayList<OutlineElement>();
		for (Extension ext : extensions) {
			Image img = null;
			int type = PRIVATE_CREATE_EXTENSION;
			if (ext.isPrivate()) {
				if (ext instanceof CreateExtensionStatement) {
					img = EditorImages
							.getImage(EditorImages.PRIVATE_CREATE_EXTENSION);
				} else {
					img = EditorImages.getImage(EditorImages.PRIVATE_EXTENSION);
					type = PRIVATE_EXTENSION;
				}
			} else {
				if (ext instanceof CreateExtensionStatement) {
					img = EditorImages.getImage(EditorImages.CREATE_EXTENSION);
					type = CREATE_EXTENSION;
				} else {
					img = EditorImages.getImage(EditorImages.EXTENSION);
					type = EXTENSION;
				}
			}
			l.add(new OutlineElement(ext.toOutlineString(), ext.getStart(), ext
					.getEnd()
					- ext.getStart(), img,type));
		}
		return l;
	}

	// let's add a sort feature to this outline...
	@Override
	public void createControl(Composite parent) {
		super.createControl(parent);
		// register global actions (yes global in the meaning of affecting all
		// items in the TreeViewer)
		registerToolbarActions(getSite().getActionBars());
	}

	private void registerToolbarActions(IActionBars actionBars) {
		actionBars.getToolBarManager().add(new LexicalSortingAction());
	}

}

Back to the top