Search in sources :

Example 26 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener 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 27 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project tdq-studio-se by Talend.

the class TablesSelectionDialog method addCheckedListener.

@Override
protected void addCheckedListener() {
    // When user checks a checkbox in the tree, check all its children
    getTreeViewer().addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            TreePath treePath = new TreePath(new Object[] { event.getElement() });
            getTreeViewer().setSelection(new TreeSelection(treePath));
            if (event.getChecked()) {
                Object element = event.getElement();
                getTreeViewer().setSubtreeChecked(element, true);
                if (element instanceof IRepositoryNode) {
                    setOutput(element);
                    handleTablesChecked((IRepositoryNode) element, true);
                }
            } else {
                Object element = event.getElement();
                getTreeViewer().setSubtreeChecked(element, false);
                if (element instanceof IRepositoryNode) {
                    setOutput(element);
                    handleTablesChecked((IRepositoryNode) element, false);
                }
            }
            updateOKStatus();
        }
    });
    getTableViewer().addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            Object element = event.getElement();
            if (element instanceof DBTableRepNode || element instanceof DBViewRepNode) {
                handleTableChecked((IRepositoryNode) element, event.getChecked());
            }
        }
    });
}
Also used : DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) TreePath(org.eclipse.jface.viewers.TreePath) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TreeSelection(org.eclipse.jface.viewers.TreeSelection) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode)

Example 28 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project tdq-studio-se by Talend.

the class AbstractJarSelectDialog method createManageTreeViewer.

/**
 * DOC msjian Comment method "createManageTreeViewer".
 *
 * @param parent
 * @return
 */
protected CheckboxTreeViewer createManageTreeViewer(Composite parent) {
    if (fContainerMode) {
        fManageViewer = new ContainerCheckedTreeViewer(parent, SWT.BORDER);
    } else {
        fManageViewer = new CheckboxTreeViewer(parent, SWT.BORDER);
    }
    fManageViewer.setContentProvider(fContentProvider);
    fManageViewer.setLabelProvider(fLabelProvider);
    fManageViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            updateOKStatus();
        }
    });
    fManageViewer.setComparator(fComparator);
    if (fFilters != null) {
        for (int i = 0; i != fFilters.size(); i++) {
            fManageViewer.addFilter((ViewerFilter) fFilters.get(i));
        }
    }
    fManageViewer.setInput(fInput);
    return fManageViewer;
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 29 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project tdq-studio-se by Talend.

the class ColumnsSelectionDialog method addCheckedListener.

/*
     * (non-Javadoc)
     * 
     * @seeorg.talend.dataprofiler.core.ui.dialog.TwoPartCheckSelectionDialog# addCheckedListener()
     */
@Override
protected void addCheckedListener() {
    // When user checks a checkbox in the tree, check all its children
    getTreeViewer().addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            // Added TDQ-8718 20140506 yyin: should not load from db when checking
            DQDBFolderRepositoryNode.setCallingFromColumnDialog(true);
            DQDBFolderRepositoryNode.setLoadDBFromDialog(false);
            try {
                ColumnSelectionViewer columnViewer = (ColumnSelectionViewer) event.getSource();
                TreePath treePath = new TreePath(new Object[] { event.getElement() });
                columnViewer.setSelection(new TreeSelection(treePath));
                setOutput(event.getElement());
                RepositoryNode selectedNode = (RepositoryNode) event.getElement();
                if (selectedNode instanceof DBTableRepNode || selectedNode instanceof DBViewRepNode || selectedNode instanceof DFTableRepNode) {
                    handleTreeElementsChecked(selectedNode, event.getChecked());
                } else {
                    checkChildrenElements(selectedNode, event.getChecked());
                }
                getTreeViewer().setSubtreeChecked(event.getElement(), event.getChecked());
                updateStatusBySelection();
            } finally {
                // Added TDQ-8718 20140506 yyin
                DQDBFolderRepositoryNode.setCallingFromColumnDialog(false);
                DQDBFolderRepositoryNode.setLoadDBFromDialog(true);
            }
        }

        private void checkChildrenElements(RepositoryNode repNode, Boolean checkedFlag) {
            Set<?> keySet = modelElementCheckedMap.keySet();
            RepositoryNode[] repNodeArray = (RepositoryNode[]) modelElementCheckedMap.keySet().toArray(new RepositoryNode[keySet.size()]);
            for (RepositoryNode reposNode : repNodeArray) {
                RepositoryNode parentNode = reposNode.getParent();
                while (parentNode != null) {
                    if (repNode.equals(parentNode)) {
                        handleTreeElementsChecked(reposNode, checkedFlag);
                        break;
                    } else {
                        parentNode = parentNode.getParent();
                    }
                }
            }
        }
    });
    getTableViewer().addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            handleTableElementsChecked((RepositoryNode) event.getElement(), event.getChecked());
            updateStatusBySelection();
        }
    });
}
Also used : DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) Set(java.util.Set) TreePath(org.eclipse.jface.viewers.TreePath) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TreeSelection(org.eclipse.jface.viewers.TreeSelection) DFTableRepNode(org.talend.dq.nodes.DFTableRepNode) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) RepositoryNode(org.talend.repository.model.RepositoryNode) DQDBFolderRepositoryNode(org.talend.dq.nodes.DQDBFolderRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode)

Example 30 with ICheckStateListener

use of org.eclipse.jface.viewers.ICheckStateListener in project tdq-studio-se by Talend.

the class TwoPartCheckSelectionDialog method createFirstPart.

/**
 * Creates the tree viewer.
 *
 * @param parent the parent composite
 * @return the tree viewer
 */
protected CheckboxTreeViewer createFirstPart(Composite parent) {
    if (fContainerMode) {
        if (DIALOG_TYPE_TABLE == this.getDialogType()) {
            fViewer = new TableSelectionViewer(parent, SWT.BORDER);
        } else if (!this.addConnFilter) {
            fViewer = new MatchColumnSelectionViewer(parent, SWT.BORDER);
        } else {
            fViewer = new ColumnSelectionViewer(parent, SWT.BORDER);
        }
    // {
    // 
    // protected void handleTreeExpand(TreeEvent event) {
    // super.handleTreeExpand(event);
    // checkElementChecked();
    // }
    // };
    } else {
        fViewer = new CheckboxTreeViewer(parent, SWT.BORDER) {

            @Override
            protected void handleTreeExpand(TreeEvent event) {
                super.handleTreeExpand(event);
            // checkElementChecked();
            }
        };
    }
    fViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    applyDialogFont(fViewer.getTree());
    fViewer.setContentProvider(fContentProvider);
    // mod gdbu 2011-7-25 bug 23220
    ((ResourceViewContentProvider) fContentProvider).setTreeViewer(fViewer);
    // ~23220
    fViewer.setLabelProvider(fLabelProvider);
    fViewer.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            updateOKStatus();
        }
    });
    fViewer.setComparator(fComparator);
    if (fFilters != null) {
        for (int i = 0; i != fFilters.size(); i++) {
            fViewer.addFilter(fFilters.get(i));
        }
    }
    fViewer.setInput(fInput);
    // fViewer.
    fViewer.addSelectionChangedListener(this);
    return fViewer;
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) TreeEvent(org.eclipse.swt.events.TreeEvent) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) GridData(org.eclipse.swt.layout.GridData) ResourceViewContentProvider(org.talend.dataprofiler.core.ui.views.provider.ResourceViewContentProvider) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Aggregations

ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)101 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)97 GridData (org.eclipse.swt.layout.GridData)62 Composite (org.eclipse.swt.widgets.Composite)48 GridLayout (org.eclipse.swt.layout.GridLayout)44 SelectionEvent (org.eclipse.swt.events.SelectionEvent)40 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)34 Label (org.eclipse.swt.widgets.Label)32 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)31 Button (org.eclipse.swt.widgets.Button)30 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)22 Viewer (org.eclipse.jface.viewers.Viewer)21 Table (org.eclipse.swt.widgets.Table)21 ArrayList (java.util.ArrayList)19 TableColumn (org.eclipse.swt.widgets.TableColumn)17 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)16 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)16 Event (org.eclipse.swt.widgets.Event)16 Listener (org.eclipse.swt.widgets.Listener)15 List (java.util.List)13