viewpart中GridLayout及GridData的使用

public void createPartControl(Composite parent) {
	Composite composite = new Composite(parent, SWT.NONE);
	composite.setLayout(new GridLayout(2, false));//设置为两格
	{
		Group grpPythonlist = new Group(composite, SWT.NONE);
		{//水平,竖直填充且抢占
			GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
			gridData.widthHint = 363;
			gridData.heightHint = 440;
			grpPythonlist.setLayoutData(gridData);
		}
		grpPythonlist.setText("python List");
		grpPythonlist.setLayout(new GridLayout(1,true));//设置1格,否则直接加内容,上不去
		
		makeAction();//初始化各类Action 
		{
			ToolBar toolBar = new ToolBar(grpPythonlist, SWT.FLAT | SWT.RIGHT);
			ToolBarManager toolManager = new ToolBarManager(toolBar);
			toolManager.add(addAction);
			toolManager.add(clearAction);
			toolManager.add(deleteAction);
			toolManager.update(true);
		} 
		
		{
		//CheckboxTableViewer.newCheckList(parent, style)
			viewer = new CheckboxTreeViewer(grpPythonlist, SWT.MULTI | SWT.H_SCROLL
					| SWT.V_SCROLL | SWT.BORDER);
			Tree tree = viewer.getTree();
			tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
			viewer.setContentProvider(new ViewContentProvider());
			viewer.setLabelProvider(new ViewLabelProvider());
			viewer.setInput(createDummyModel());
			viewer.addSelectionChangedListener(new ExecuteTreeSelectionChangeListener());
			viewer.expandAll();
		}
		}
		{
		Group grpVm = new Group(composite, SWT.NONE);
		{//同上
			GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
			gridData.widthHint = 282;
			grpVm.setLayoutData(gridData);
		}
		grpVm.setLayout(new GridLayout(1, true));
		grpVm.setText("VM");
		{
			{
				ToolBar toolBar = new ToolBar(grpVm, SWT.FLAT | SWT.RIGHT);
				toolBar.setBounds(10, 22, 212, 22);
				ToolBarManager toolManager = new ToolBarManager(toolBar);
				toolManager.add(addVmAction); 
				toolManager.add(modifyVmAction);
				toolManager.add(deleteVmAction);
				toolManager.update(true);
			}
			ipViewer = new CheckboxTreeViewer(grpVm, SWT.BORDER);
			Tree tree = ipViewer.getTree();
			tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
			ipViewer.setContentProvider(new ViewContentProvider());
			ipViewer.setLabelProvider(new IpViewLabelProvider());
			ipViewer.addCheckStateListener(new IPCheckStateListener()); 
			ipViewer.setInput(getIpViewerInputData());
			ipViewer.addSelectionChangedListener(new IpViewerSelectionChangeListener());
			ipViewer.addDoubleClickListener(new IpViewerDoubleClickListener());
			ipViewer.expandAll();
				 
		} 
	} 
}   

你可能感兴趣的:(python)