Search in sources :

Example 16 with ITreeContentProvider

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]);
            }
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider)

Example 17 with ITreeContentProvider

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);
            }
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) TreeItem(org.eclipse.swt.widgets.TreeItem) HashSet(java.util.HashSet)

Example 18 with ITreeContentProvider

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;
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) RepositoryTreeNode(org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode) IPath(org.eclipse.core.runtime.IPath) File(java.io.File)

Example 19 with ITreeContentProvider

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);
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) IURIEditorInput(org.eclipse.ui.IURIEditorInput) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) Shell(org.eclipse.swt.widgets.Shell) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IWorkspace(org.eclipse.core.resources.IWorkspace) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 20 with ITreeContentProvider

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;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Alias(net.sourceforge.sqlexplorer.dbproduct.Alias) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Aggregations

ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)68 Viewer (org.eclipse.jface.viewers.Viewer)32 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 GridData (org.eclipse.swt.layout.GridData)19 Composite (org.eclipse.swt.widgets.Composite)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 GridLayout (org.eclipse.swt.layout.GridLayout)15 Label (org.eclipse.swt.widgets.Label)13 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)12 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)11 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)11 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)11 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)11 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)11 ArrayList (java.util.ArrayList)10 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)9 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)9 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)8 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7