use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.
the class CachedCheckboxTreeViewer method setCheckedElements.
@Override
public void setCheckedElements(Object[] elements) {
super.setCheckedElements(elements);
checkState.clear();
ITreeContentProvider contentProvider = null;
if (getContentProvider() instanceof ITreeContentProvider) {
contentProvider = (ITreeContentProvider) getContentProvider();
}
for (int i = 0; i < elements.length; i++) {
Object[] children = contentProvider != null ? contentProvider.getChildren(elements[i]) : null;
if (!getGrayed(elements[i]) && (children == null || children.length == 0)) {
if (!checkState.contains(elements[i])) {
checkState.add(elements[i]);
}
}
}
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.
the class CachedCheckboxTreeViewer method setAllChecked.
@Override
public void setAllChecked(boolean state) {
for (TreeItem item : super.getTree().getItems()) item.setChecked(state);
if (state) {
// Find all visible children, add only the visible leaf nodes to the check state cache
Object[] visible = getFilteredChildren(getRoot());
ITreeContentProvider contentProvider = null;
if (getContentProvider() instanceof ITreeContentProvider) {
contentProvider = (ITreeContentProvider) getContentProvider();
}
if (contentProvider == null) {
for (Object element : visible) {
checkState.add(element);
}
} else {
Set<Object> toCheck = new HashSet<>();
for (Object element : visible) {
addFilteredChildren(element, contentProvider, toCheck);
}
checkState.addAll(toCheck);
}
} else {
// Remove any item in the check state that is visible (passes the filters)
if (checkState != null) {
Object[] visible = filter(checkState.toArray());
for (Object element : visible) {
checkState.remove(element);
}
}
}
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project egit by eclipse.
the class RepositoriesView method getNodeForPath.
private RepositoryTreeNode getNodeForPath(Repository repository, String repoRelativePath) {
RepositoryTreeNode currentNode = null;
ITreeContentProvider cp = (ITreeContentProvider) getCommonViewer().getContentProvider();
for (Object repo : cp.getElements(getCommonViewer().getInput())) {
RepositoryTreeNode node = (RepositoryTreeNode) repo;
// TODO equals implementation of Repository?
if (repository.getDirectory().equals(((Repository) node.getObject()).getDirectory())) {
for (Object child : cp.getChildren(node)) {
RepositoryTreeNode childNode = (RepositoryTreeNode) child;
if (childNode.getType() == RepositoryTreeNodeType.WORKINGDIR) {
currentNode = childNode;
break;
}
}
break;
}
}
IPath relPath = new Path(repoRelativePath);
for (String segment : relPath.segments()) for (Object child : cp.getChildren(currentNode)) {
@SuppressWarnings("unchecked") RepositoryTreeNode<File> childNode = (RepositoryTreeNode<File>) child;
if (childNode.getObject().getName().equals(segment)) {
currentNode = childNode;
break;
}
}
return currentNode;
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project tdq-studio-se by Talend.
the class SQLTextEditor method performSaveAs.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.ui.texteditor.AbstractDecoratedTextEditor#performSaveAs(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
// PTODO qzhang correct save the sql file. for bug 3860.
Shell shell = getSite().getShell();
final IEditorInput input = getEditorInput();
IDocumentProvider provider = getDocumentProvider();
IEditorInput newInput;
if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
super.performSaveAs(progressMonitor);
return;
}
ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp = new WorkbenchContentProvider();
FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp);
if (dialog.open() == Window.CANCEL) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
}
return;
}
Object elements = dialog.getResult()[0];
// ADD xqliu 2010-03-08 feature 10675
IResource elem = (IResource) elements;
if (elem instanceof IFolder) {
IPath filePath = ((IFolder) elem).getFullPath();
filePath = filePath.append(dialog.getFileName() + DEFAULT_FILE_EXTENSION);
if (filePath == null) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
}
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFile file = workspace.getRoot().getFile(filePath);
newInput = new FileEditorInput(file);
if (provider == null) {
// editor has programmatically been closed while the dialog was open
return;
}
boolean success = false;
try {
provider.aboutToChange(newInput);
// MOD qiongli 2011-4-21 bug 20205.after creating property file,file name is changed(contain version
// info),so reset'newInput'.
file = createIFile(file, getViewer().getDocument().get());
newInput = new FileEditorInput(file);
success = true;
} catch (CoreException x) {
final IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
String title = "The file save failure.";
String msg = "The file save failure.";
MessageDialog.openError(shell, title, msg);
}
} finally {
provider.changed(newInput);
if (success) {
setInput(newInput);
}
}
if (progressMonitor != null) {
progressMonitor.setCanceled(!success);
}
}
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project tdq-studio-se by Talend.
the class ConnectionsView method getDefaultAlias.
private Alias getDefaultAlias() {
IStructuredSelection selection = (IStructuredSelection) _treeViewer.getSelection();
if (selection == null) {
return null;
}
Object element = selection.getFirstElement();
if (element instanceof Alias) {
return (Alias) element;
} else if (element instanceof Session) {
ITreeContentProvider provider = (ITreeContentProvider) _treeViewer.getContentProvider();
return (Alias) provider.getParent(element);
}
return null;
}
Aggregations