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)); } ... }
新闻热点
疑难解答