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
| public class ExampleView extends ViewPart
{
...
public void createPartControl(Composite parent)
{ // define a grid layout
GridLayout layout = new GridLayout();
layout.numColumns = 1;
layout.marginHeight = 0;
layout.marginWidth = 0; l
ayout.horizontalSpacing = 0;
layout.verticalSpacing = 1;
parent.setLayout(layout);
// create widgets createActionBar(parent);
createTree(parent);
// add context menu and listeners
viewer.addDoubleClickListener(this);
viewer.addSelectionChangedListener(openAction);
// register viewer so actions respond to selection getSite()
// .setSelectionProvider(viewer);
hookContextMenu();
}
private void createTree(Composite parent)
{
viewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL |
SWT.V_SCROLL | SWT.BORDER);
viewer.setContentProvider(new ExampleViewContentProvider());
viewer.setLabelProvider(new ExampleViewLabelProvider());
viewer.setSorter(new ViewerSorter());
viewer.setInput(ModelManager.getExampleModel());
viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
}
...
}
|