blob: 5fc7417b6bd053b6299fe7494a083ae26f07b47c (
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*******************************************************************************
* Copyright (c) 2007 Red Hat, Inc.
* 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:
* Red Hat Incorporated - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.autotools.ui.editors.outline;
import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.cdt.autotools.ui.editors.AutoconfEditor;
import org.eclipse.cdt.autotools.ui.editors.parser.AutoconfElement;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
public class AutoconfContentOutlinePage extends ContentOutlinePage {
private ITextEditor editor;
private IEditorInput input;
public AutoconfContentOutlinePage(AutoconfEditor editor) {
super();
this.editor = editor;
}
public void setInput(IEditorInput editorInput) {
this.input = editorInput;
update();
}
protected ISelection updateSelection(ISelection sel) {
ArrayList<AutoconfElement> newSelection= new ArrayList<AutoconfElement>();
if (sel instanceof IStructuredSelection) {
@SuppressWarnings("unchecked")
Iterator iter= ((IStructuredSelection)sel).iterator();
for (;iter.hasNext();) {
//ICElement elem= fInput.findEqualMember((ICElement)iter.next());
Object o = iter.next();
if (o instanceof AutoconfElement) {
newSelection.add((AutoconfElement)o);
}
}
}
return new StructuredSelection(newSelection);
}
public void update() {
//set the input so that the outlines parse can be called
//update the tree viewer state
final TreeViewer viewer = getTreeViewer();
if (viewer != null)
{
final Control control = viewer.getControl();
if (control != null && !control.isDisposed())
{
control.getDisplay().asyncExec(new Runnable() {
public void run() {
if (!control.isDisposed()) {
// control.setRedraw(false);
// if (input != null)
// viewer.setInput(input);
// viewer.expandAll();
// control.setRedraw(true);
ISelection sel= viewer.getSelection();
viewer.setSelection(updateSelection(sel));
viewer.refresh();
}
}
});
}
}
}
public void createControl(Composite parent) {
super.createControl(parent);
TreeViewer viewer= getTreeViewer();
viewer.setContentProvider(new AutoconfContentProvider(editor));
viewer.setLabelProvider(new AutoconfLabelProvider());
viewer.addSelectionChangedListener(this);
if (input != null)
viewer.setInput(input);
}
/*
* Change in selection
*/
public void selectionChanged(SelectionChangedEvent event)
{
super.selectionChanged(event);
//find out which item in tree viewer we have selected, and set highlight range accordingly
ISelection selection = event.getSelection();
if (selection.isEmpty()) {
editor.resetHighlightRange();
} else {
AutoconfElement element = (AutoconfElement) ((IStructuredSelection) selection)
.getFirstElement();
try {
int offset = element.getStartOffset();
int length = element.getEndOffset() - offset;
editor.setHighlightRange(offset, length, true);
editor.selectAndReveal(offset, length);
} catch (IllegalArgumentException x) {
editor.resetHighlightRange();
}
}
}
}
|