use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.
the class SourceBranchPage method createControl.
@Override
public void createControl(final Composite parent) {
final Composite panel = new Composite(parent, SWT.NULL);
final GridLayout layout = new GridLayout();
layout.numColumns = 1;
panel.setLayout(layout);
label = new Label(panel, SWT.NONE);
label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
FilteredCheckboxTree fTree = new FilteredCheckboxTree(panel, null, SWT.NONE, new PatternFilter()) {
/*
* Overridden to check page when refreshing is done.
*/
@Override
protected WorkbenchJob doCreateRefreshJob() {
WorkbenchJob refreshJob = super.doCreateRefreshJob();
refreshJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
checkPage();
}
});
}
}
});
return refreshJob;
}
};
refsViewer = fTree.getCheckboxTreeViewer();
ITreeContentProvider provider = new ITreeContentProvider() {
@Override
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// nothing
}
@Override
public void dispose() {
// nothing
}
@Override
public Object[] getElements(Object input) {
return ((List) input).toArray();
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public Object[] getChildren(Object parentElement) {
return null;
}
};
refsViewer.setContentProvider(provider);
refsViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (((Ref) element).getName().startsWith(Constants.R_HEADS))
return ((Ref) element).getName().substring(Constants.R_HEADS.length());
return ((Ref) element).getName();
}
@Override
public Image getImage(Object element) {
return RepositoryTreeNodeType.REF.getIcon();
}
});
refsViewer.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
checkPage();
}
});
final Composite bPanel = new Composite(panel, SWT.NONE);
bPanel.setLayout(new RowLayout());
selectB = new Button(bPanel, SWT.PUSH);
selectB.setText(UIText.SourceBranchPage_selectAll);
selectB.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
refsViewer.setAllChecked(true);
checkPage();
}
});
unselectB = new Button(bPanel, SWT.PUSH);
unselectB.setText(UIText.SourceBranchPage_selectNone);
unselectB.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
refsViewer.setAllChecked(false);
checkPage();
}
});
bPanel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
Dialog.applyDialogFont(panel);
setControl(panel);
checkPage();
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.
the class GitProjectsImportPage method createProjectsList.
/**
* Create the checkbox list for the found projects.
*
* @param workArea
*/
private void createProjectsList(Composite workArea) {
Label title = new Label(workArea, SWT.NONE);
title.setText(UIText.WizardProjectsImportPage_ProjectsListTitle);
Composite listComposite = new Composite(workArea, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
layout.makeColumnsEqualWidth = false;
listComposite.setLayout(layout);
listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
PatternFilter filter = new PatternFilter() {
@Override
public boolean isElementVisible(Viewer viewer, Object element) {
if (getCheckedProjects().contains(element))
return true;
if (element instanceof ProjectRecord) {
ProjectRecord p = (ProjectRecord) element;
if (wordMatches(p.getProjectName()))
return true;
String projectPath = p.getProjectSystemFile().getParent();
if (projectPath.startsWith(lastPath)) {
String distinctPath = projectPath.substring(lastPath.length());
return wordMatches(distinctPath);
} else {
return wordMatches(projectPath);
}
}
return false;
}
};
filter.setIncludeLeadingWildcard(true);
FilteredCheckboxTree filteredTree = new FilteredCheckboxTree(listComposite, null, SWT.NONE, filter);
filteredTree.setInitialText(UIText.WizardProjectsImportPage_filterText);
projectsList = filteredTree.getCheckboxTreeViewer();
GridData listData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
projectsList.getControl().setLayoutData(listData);
projectsList.addCheckStateListener(new ICheckStateListener() {
@Override
public void checkStateChanged(CheckStateChangedEvent event) {
ProjectRecord element = (ProjectRecord) event.getElement();
if (isProjectInWorkspace(element.getProjectName())) {
projectsList.setChecked(element, false);
}
enableSelectAllButtons();
}
});
// a bug in the CachedCheckboxTreeView requires us to not return null
final Object[] children = new Object[0];
projectsList.setContentProvider(new ITreeContentProvider() {
@Override
public Object[] getChildren(Object parentElement) {
return children;
}
@Override
public Object[] getElements(Object inputElement) {
return selectedProjects;
}
@Override
public boolean hasChildren(Object element) {
return false;
}
@Override
public Object getParent(Object element) {
return null;
}
@Override
public void dispose() {
// ignore
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// ignore
}
});
projectsList.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
checkPageComplete();
}
});
projectsList.setLabelProvider(new ProjectLabelProvider());
projectsList.setInput(this);
projectsList.setComparator(new ViewerComparator());
createSelectionButtons(listComposite);
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.
the class LinkRequirementsCheckStateListener method updateAllChildrenAndGrayWhenAppropriate.
/**
* Checks all the children of {@code element} in {@code checkboxTreeViewer}.
* Grays those that may have children. Then apply this behavior on its
* grandchildren.
*
* @param checkboxTreeViewer
* @param element
*/
private static void updateAllChildrenAndGrayWhenAppropriate(CheckboxTreeViewer checkboxTreeViewer, Object element, boolean newValue) {
ITreeContentProvider contentProvider = getTreeContentProvider(checkboxTreeViewer);
for (Object child : Arrays.asList(contentProvider.getChildren(element))) {
checkboxTreeViewer.setChecked(child, newValue);
if (isOfContainerType(child)) {
checkboxTreeViewer.setGrayed(child, newValue);
updateAllChildrenAndGrayWhenAppropriate(checkboxTreeViewer, child, newValue);
}
}
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.
the class LinkRequirementsDialog method expandTreeViewerUpToCheckedElements.
/**
* Expands a {@link TreeViewer} up to all the given elements.
*
* @param treeViewer
* @param checkedElements
*/
private static void expandTreeViewerUpToCheckedElements(TreeViewer treeViewer, List<Requirement> checkedElements) {
ITreeContentProvider contentProvider = (ITreeContentProvider) treeViewer.getContentProvider();
// We need the unicity because there may be common ancestors in the tree
// of several checked elements. We also need the insertion order because
// we need to expand the higher nodes first.
LinkedHashSet<Object> treeOfElements = new LinkedHashSet<Object>();
for (Requirement checkedElement : checkedElements) {
Object element = checkedElement;
while (contentProvider.getParent(element) != null) {
treeOfElements.add(element);
element = contentProvider.getParent(element);
}
}
// Reverse the order to start with the root element (the EMF Resource).
List<Object> elementsToExpand = new ArrayList<Object>(treeOfElements);
Collections.reverse(elementsToExpand);
treeViewer.setExpandedElements(elementsToExpand.toArray());
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.
the class TreeMapper method resolveTreeViewerItem.
/**
* @param treeViewer
* @param treeItem
* @return
*/
private Object resolveTreeViewerItem(TreeViewer treeViewer, TreeItem treeItem) {
// return treeItem.getData();
ITreeContentProvider contentProvider = (ITreeContentProvider) treeViewer.getContentProvider();
List<Integer> locations = new ArrayList<Integer>();
TreeItem parentTreeItem = treeItem.getParentItem();
while (parentTreeItem != null) {
int index = Arrays.asList(parentTreeItem.getItems()).indexOf(treeItem);
locations.add(index);
treeItem = parentTreeItem;
parentTreeItem = treeItem.getParentItem();
}
// root
if (treeItem != null) {
int rootIndex = Arrays.asList(treeViewer.getTree().getItems()).indexOf(treeItem);
locations.add(rootIndex);
}
Collections.reverse(locations);
Object current = contentProvider.getElements(treeViewer.getInput())[locations.get(0)];
locations.remove(0);
for (int index : locations) {
current = contentProvider.getChildren(current)[index];
}
return current;
}
Aggregations