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)); } ... } |
1 | public class ExampleViewContentprovide implements ITreeContentProvide { |
1 2 3 4 5 6 7 8 9 | /** * Register content provider with model. */ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (newInput != null) { this.viewer = viewer; this.model = (ExampleDelegate)newInput; this.model.addModelListener(this); } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |