Search in sources :

Example 1 with FilteredCheckboxTree

use of org.eclipse.egit.ui.internal.components.FilteredCheckboxTree in project egit by eclipse.

the class CommitViewerComparator method createFileSection.

private Section createFileSection(Composite container) {
    Section filesSection = toolkit.createSection(container, ExpandableComposite.TITLE_BAR | ExpandableComposite.CLIENT_INDENT);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(filesSection);
    Composite filesArea = toolkit.createComposite(filesSection);
    filesSection.setClient(filesArea);
    toolkit.paintBordersFor(filesArea);
    GridLayoutFactory.fillDefaults().extendedMargins(2, 2, 2, 2).applyTo(filesArea);
    ToolBar filesToolbar = new ToolBar(filesSection, SWT.FLAT);
    filesSection.setTextClient(filesToolbar);
    PatternFilter patternFilter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(Viewer viewer, Object element) {
            if (element instanceof CommitItem) {
                CommitItem commitItem = (CommitItem) element;
                return wordMatches(commitItem.path);
            }
            return super.isLeafMatch(viewer, element);
        }
    };
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredCheckboxTree resourcesTreeComposite = new FilteredCheckboxTree(filesArea, toolkit, SWT.FULL_SELECTION, patternFilter) {

        @Override
        protected WorkbenchJob doCreateRefreshJob() {
            // workaround for file filter not having an explicit change
            // listener
            WorkbenchJob filterJob = super.doCreateRefreshJob();
            filterJob.addJobChangeListener(new JobChangeAdapter() {

                @Override
                public void done(IJobChangeEvent event) {
                    if (event.getResult().isOK()) {
                        getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                updateFileSectionText();
                            }
                        });
                    }
                }
            });
            return filterJob;
        }
    };
    Tree resourcesTree = resourcesTreeComposite.getViewer().getTree();
    resourcesTree.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
    resourcesTreeComposite.setLayoutData(GridDataFactory.fillDefaults().hint(600, 200).grab(true, true).create());
    resourcesTree.addSelectionListener(new CommitItemSelectionListener());
    resourcesTree.setHeaderVisible(true);
    if (getPreferenceStore().getBoolean(UIPreferences.WARN_BEFORE_COMMITTING) && getPreferenceStore().getBoolean(UIPreferences.BLOCK_COMMIT)) {
        ignoreErrors = new Button(resourcesTreeComposite, SWT.CHECK);
        ignoreErrors.setText(UIText.CommitDialog_IgnoreErrors);
        ignoreErrors.setSelection(false);
        ignoreErrors.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Button button = (Button) e.getSource();
                boolean enable = button.getSelection();
                updateMessage();
                updateCommitButtons(enable);
            }
        });
    }
    TreeColumn statCol = new TreeColumn(resourcesTree, SWT.LEFT);
    statCol.setText(UIText.CommitDialog_Status);
    statCol.setWidth(150);
    statCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByStatus));
    TreeColumn resourceCol = new TreeColumn(resourcesTree, SWT.LEFT);
    resourceCol.setText(UIText.CommitDialog_Path);
    resourceCol.setWidth(415);
    resourceCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByFile));
    filesViewer = resourcesTreeComposite.getCheckboxTreeViewer();
    new TreeViewerColumn(filesViewer, statCol).setLabelProvider(createStatusLabelProvider());
    new TreeViewerColumn(filesViewer, resourceCol).setLabelProvider(new CommitPathLabelProvider());
    ColumnViewerToolTipSupport.enableFor(filesViewer);
    filesViewer.setContentProvider(new CommitFileContentProvider());
    filesViewer.setUseHashlookup(true);
    IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
    if (settings.get(SHOW_UNTRACKED_PREF) != null) {
        // note, no matter how the dialog settings are, if
        // the preferences force us to include untracked files
        // we must show them
        showUntracked = Boolean.valueOf(settings.get(SHOW_UNTRACKED_PREF)).booleanValue() || getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
    }
    filesViewer.addFilter(new CommitItemFilter());
    filesViewer.setInput(items.toArray());
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(createContextMenuListener());
    filesViewer.getTree().setMenu(menuManager.createContextMenu(filesViewer.getTree()));
    filesViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateFileSectionText();
        }
    });
    showUntrackedItem = new ToolItem(filesToolbar, SWT.CHECK);
    Image showUntrackedImage = UIIcons.UNTRACKED_FILE.createImage();
    UIUtils.hookDisposal(showUntrackedItem, showUntrackedImage);
    showUntrackedItem.setImage(showUntrackedImage);
    showUntrackedItem.setToolTipText(UIText.CommitDialog_ShowUntrackedFiles);
    showUntrackedItem.setSelection(showUntracked);
    showUntrackedItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showUntracked = showUntrackedItem.getSelection();
            filesViewer.refresh(true);
            updateFileSectionText();
            updateMessage();
        }
    });
    ToolItem checkAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image checkImage = UIIcons.CHECK_ALL.createImage();
    UIUtils.hookDisposal(checkAllItem, checkImage);
    checkAllItem.setImage(checkImage);
    checkAllItem.setToolTipText(UIText.CommitDialog_SelectAll);
    checkAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(true);
            updateFileSectionText();
            updateMessage();
        }
    });
    ToolItem uncheckAllItem = new ToolItem(filesToolbar, SWT.PUSH);
    Image uncheckImage = UIIcons.UNCHECK_ALL.createImage();
    UIUtils.hookDisposal(uncheckAllItem, uncheckImage);
    uncheckAllItem.setImage(uncheckImage);
    uncheckAllItem.setToolTipText(UIText.CommitDialog_DeselectAll);
    uncheckAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            filesViewer.setAllChecked(false);
            updateFileSectionText();
            updateMessage();
        }
    });
    if (!allowToChangeSelection) {
        amendingItem.setSelection(false);
        amendingItem.setEnabled(false);
        showUntrackedItem.setSelection(false);
        showUntrackedItem.setEnabled(false);
        checkAllItem.setEnabled(false);
        uncheckAllItem.setEnabled(false);
        filesViewer.addCheckStateListener(new ICheckStateListener() {

            @Override
            public void checkStateChanged(CheckStateChangedEvent event) {
                if (!event.getChecked())
                    filesViewer.setAllChecked(true);
                updateFileSectionText();
            }
        });
        filesViewer.setAllChecked(true);
    } else {
        final boolean includeUntracked = getPreferenceStore().getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
        for (CommitItem item : items) {
            if (!preselectAll && !preselectedFiles.contains(item.path))
                continue;
            if (item.status == Status.ASSUME_UNCHANGED)
                continue;
            if (!includeUntracked && item.status == Status.UNTRACKED)
                continue;
            filesViewer.setChecked(item, true);
        }
    }
    statCol.pack();
    resourceCol.pack();
    return filesSection;
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) TreeColumn(org.eclipse.swt.widgets.TreeColumn) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) Tree(org.eclipse.swt.widgets.Tree) ToolItem(org.eclipse.swt.widgets.ToolItem) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Section(org.eclipse.ui.forms.widgets.Section) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ToolBar(org.eclipse.swt.widgets.ToolBar) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 2 with FilteredCheckboxTree

use of org.eclipse.egit.ui.internal.components.FilteredCheckboxTree in project egit by eclipse.

the class RepositorySearchDialog method createControl.

@Override
public void createControl(Composite parent) {
    setMessage(UIText.RepositorySearchDialog_searchRepositoriesMessage);
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(1, false));
    main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    Group searchGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    searchGroup.setText(UIText.RepositorySearchDialog_SearchCriteriaGroup);
    searchGroup.setLayout(new GridLayout(4, false));
    GridDataFactory.fillDefaults().grab(true, false).minSize(SWT.DEFAULT, SWT.DEFAULT).applyTo(searchGroup);
    Label dirLabel = new Label(searchGroup, SWT.NONE);
    dirLabel.setText(UIText.RepositorySearchDialog_directory);
    dir = new Text(searchGroup, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).hint(300, SWT.DEFAULT).minSize(100, SWT.DEFAULT).applyTo(dir);
    dir.setToolTipText(UIText.RepositorySearchDialog_EnterDirectoryToolTip);
    String defaultRepoPath = RepositoryUtil.getDefaultRepositoryDir();
    String initialPath = prefs.get(PREF_PATH, defaultRepoPath);
    dir.setText(initialPath);
    Button browse = new Button(searchGroup, SWT.PUSH);
    browse.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    browse.setText(UIText.RepositorySearchDialog_browse);
    browse.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dd = new DirectoryDialog(getShell());
            dd.setMessage(UIText.RepositorySearchDialog_BrowseDialogMessage);
            dd.setFilterPath(dir.getText());
            String directory = dd.open();
            if (directory != null) {
                dir.setText(directory);
                prefs.put(PREF_PATH, directory);
                try {
                    prefs.flush();
                } catch (BackingStoreException e1) {
                // ignore here
                }
                doSearch();
            }
        }
    });
    searchButton = new Button(searchGroup, SWT.PUSH);
    searchButton.setText(UIText.RepositorySearchDialog_Search);
    searchButton.setToolTipText(UIText.RepositorySearchDialog_SearchTooltip);
    searchButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doSearch();
        }
    });
    lookForNestedButton = new Button(searchGroup, SWT.CHECK);
    lookForNestedButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
    lookForNestedButton.setSelection(prefs.getBoolean(PREF_DEEP_SEARCH, false));
    lookForNestedButton.setText(UIText.RepositorySearchDialog_DeepSearch_button);
    lookForNestedButton.setToolTipText(UIText.RepositorySearchDialog_SearchRecursiveToolTip);
    lookForNestedButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            prefs.putBoolean(PREF_DEEP_SEARCH, lookForNestedButton.getSelection());
            try {
                prefs.flush();
            } catch (BackingStoreException e1) {
            // ignore
            }
            setNeedsSearch();
        }
    });
    skipHiddenButton = new Button(searchGroup, SWT.CHECK);
    skipHiddenButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
    skipHiddenButton.setSelection(prefs.getBoolean(PREF_SKIP_HIDDEN, true));
    skipHiddenButton.setText(UIText.RepositorySearchDialog_SkipHidden);
    skipHiddenButton.setToolTipText(UIText.RepositorySearchDialog_SkipHiddenTooltip);
    skipHiddenButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            prefs.putBoolean(PREF_SKIP_HIDDEN, skipHiddenButton.getSelection());
            try {
                prefs.flush();
            } catch (BackingStoreException e1) {
            // ignore
            }
            setNeedsSearch();
        }
    });
    Group searchResultGroup = new Group(main, SWT.SHADOW_ETCHED_IN);
    searchResultGroup.setText(UIText.RepositorySearchDialog_SearchResultGroup);
    searchResultGroup.setLayout(new GridLayout(2, false));
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 0).applyTo(searchResultGroup);
    PatternFilter filter = new PatternFilter() {

        @Override
        public boolean isElementVisible(Viewer viewer, Object element) {
            if (getCheckedItems().contains(element)) {
                return true;
            }
            return super.isElementVisible(viewer, element);
        }
    };
    fTree = new FilteredCheckboxTree(searchResultGroup, null, SWT.NONE, filter);
    fTreeViewer = fTree.getCheckboxTreeViewer();
    fTreeViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            enableOk();
        }
    });
    fTreeViewer.addDoubleClickListener(event -> {
        Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
        fTreeViewer.setChecked(element, !fTreeViewer.getChecked(element));
        enableOk();
    });
    // Set a reasonable minimum height here; otherwise the dialog comes up
    // with a tree that has only a few rows visible.
    GridDataFactory.fillDefaults().grab(true, true).minSize(0, 300).applyTo(fTree);
    ToolBar toolbar = new ToolBar(searchResultGroup, SWT.FLAT | SWT.VERTICAL);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).applyTo(toolbar);
    checkAllItem = new ToolItem(toolbar, SWT.PUSH);
    checkAllItem.setToolTipText(UIText.RepositorySearchDialog_CheckAllRepositories);
    checkAllItem.setEnabled(false);
    Image checkImage = UIIcons.CHECK_ALL.createImage();
    UIUtils.hookDisposal(checkAllItem, checkImage);
    checkAllItem.setImage(checkImage);
    checkAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fTreeViewer.setAllChecked(true);
            enableOk();
        }
    });
    uncheckAllItem = new ToolItem(toolbar, SWT.PUSH);
    uncheckAllItem.setToolTipText(UIText.RepositorySearchDialog_UncheckAllRepositories);
    uncheckAllItem.setEnabled(false);
    Image uncheckImage = UIIcons.UNCHECK_ALL.createImage();
    UIUtils.hookDisposal(uncheckAllItem, uncheckImage);
    uncheckAllItem.setImage(uncheckImage);
    uncheckAllItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fTreeViewer.setAllChecked(false);
            enableOk();
        }
    });
    // TODO this isn't the most optimal way of handling this... ideally we
    // should have some type of delay
    // if we could use databinding an observeDelayedValue would totally work
    // here
    dir.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            setNeedsSearch();
        }
    });
    fTreeViewer.setContentProvider(new ContentProvider());
    fTreeViewer.setLabelProvider(new RepositoryLabelProvider());
    setControl(main);
    enableOk();
    if (fillSearch)
        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                if (!getControl().isDisposed())
                    doSearch();
            }
        });
}
Also used : Group(org.eclipse.swt.widgets.Group) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) ModifyListener(org.eclipse.swt.events.ModifyListener) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Label(org.eclipse.swt.widgets.Label) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) BackingStoreException(org.osgi.service.prefs.BackingStoreException) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 3 with FilteredCheckboxTree

use of org.eclipse.egit.ui.internal.components.FilteredCheckboxTree in project egit by eclipse.

the class BranchSelectionDialog method createCustomArea.

@Override
protected Control createCustomArea(Composite parent) {
    Composite area = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(area);
    area.setLayout(new GridLayout(1, false));
    if (multiMode) {
        fTree = new FilteredCheckboxTree(area, 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;
            }
        };
        CachedCheckboxTreeViewer viewer = fTree.getCheckboxTreeViewer();
        GridDataFactory.fillDefaults().grab(true, true).applyTo(fTree);
        viewer.setContentProvider(new ITreeContentProvider() {

            @Override
            public void inputChanged(Viewer actViewer, Object oldInput, Object newInput) {
            // nothing
            }

            @Override
            public void dispose() {
            // nothing
            }

            @Override
            public boolean hasChildren(Object element) {
                return false;
            }

            @Override
            public Object getParent(Object element) {
                return null;
            }

            @Override
            public Object[] getElements(Object inputElement) {
                return ((List) inputElement).toArray();
            }

            @Override
            public Object[] getChildren(Object parentElement) {
                return null;
            }
        });
        viewer.addCheckStateListener(new ICheckStateListener() {

            @Override
            public void checkStateChanged(CheckStateChangedEvent event) {
                checkPage();
            }
        });
        viewer.setLabelProvider(new GitLabelProvider());
        viewer.setComparator(new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR));
        viewer.setInput(nodes);
        preselectBranchMultiMode(nodes, fTree);
    } else {
        branchesList = new TableViewer(area, this.style | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        GridDataFactory.fillDefaults().grab(true, true).applyTo(branchesList.getControl());
        branchesList.setContentProvider(ArrayContentProvider.getInstance());
        branchesList.setLabelProvider(new GitLabelProvider());
        branchesList.setComparator(new ViewerComparator(CommonUtils.STRING_ASCENDING_COMPARATOR));
        branchesList.setInput(nodes);
        preselectBranchSingleMode(nodes, branchesList);
        branchesList.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                checkPage();
            }
        });
        branchesList.addDoubleClickListener(new IDoubleClickListener() {

            @Override
            public void doubleClick(DoubleClickEvent event) {
                buttonPressed(OK);
            }
        });
    }
    return area;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GitLabelProvider(org.eclipse.egit.ui.internal.GitLabelProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 4 with FilteredCheckboxTree

use of org.eclipse.egit.ui.internal.components.FilteredCheckboxTree 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();
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) Label(org.eclipse.swt.widgets.Label) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) Composite(org.eclipse.swt.widgets.Composite) WorkbenchJob(org.eclipse.ui.progress.WorkbenchJob) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Ref(org.eclipse.jgit.lib.Ref) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 5 with FilteredCheckboxTree

use of org.eclipse.egit.ui.internal.components.FilteredCheckboxTree 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);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) FilteredCheckboxTree(org.eclipse.egit.ui.internal.components.FilteredCheckboxTree) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) CachedCheckboxTreeViewer(org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

CachedCheckboxTreeViewer (org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer)6 FilteredCheckboxTree (org.eclipse.egit.ui.internal.components.FilteredCheckboxTree)6 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)6 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)6 Composite (org.eclipse.swt.widgets.Composite)6 Viewer (org.eclipse.jface.viewers.Viewer)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)5 PatternFilter (org.eclipse.ui.dialogs.PatternFilter)5 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Button (org.eclipse.swt.widgets.Button)4 Label (org.eclipse.swt.widgets.Label)4 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)3 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)3 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)3 Image (org.eclipse.swt.graphics.Image)3 GridData (org.eclipse.swt.layout.GridData)3 WorkbenchJob (org.eclipse.ui.progress.WorkbenchJob)3 ToolBar (org.eclipse.swt.widgets.ToolBar)2