capint
1/12/2016 - 8:52 PM

Eclipse >> SWT >> Checked Tree Selection Dialog

Eclipse >> SWT >> Checked Tree Selection Dialog

public void testCheckedTreeSelectionDialog() throws Exception {
	IJavaProject jproject= JavaProjectHelper.createJavaProject(PROJECT_NAME, "bin");
	JavaProjectHelper.addSourceContainer(jproject, "src1");
	Object initSelection= JavaProjectHelper.addSourceContainer(jproject, "src2");

	StandardJavaElementContentProvider provider= new StandardJavaElementContentProvider();
	ILabelProvider labelProvider= new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
	//*** We need a content provider and a label provider
	CheckedTreeSelectionDialog dialog= new CheckedTreeSelectionDialog(getShell(), labelProvider, provider);
	// A viewer comparator is used by a StructuredViewer to reorder the elements provided by its content provider
	dialog.setComparator(new JavaElementComparator());
	dialog.setTitle("Title"); //$NON-NLS-1$
	dialog.setMessage("Select the elements"); //$NON-NLS-1$

	dialog.setInput(jproject.getJavaModel());
	dialog.setInitialSelection(initSelection);
	dialog.setExpandedElements(new Object[] { initSelection, jproject });

	System.out.println("Result:");
	//*** Result = checked elements
	Object[] checkedElements= dialog.getResult();
	for (int i= 0; i < checkedElements.length; i++) {
		System.out.println(labelProvider.getText(checkedElements[i]));
	}
}