Search in sources :

Example 6 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter 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 7 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project tdq-studio-se by Talend.

the class NewWizardSelectionPage method createControl.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
     */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout gdLayout = new GridLayout(1, true);
    container.setLayout(gdLayout);
    PatternFilter filter = new PatternFilter();
    FilteredTree tree = new FilteredTree(container, SWT.BORDER, filter, true);
    typeTreeViewer = tree.getViewer();
    typeTreeViewer.setContentProvider(new AnalysisTypeContentProvider());
    typeTreeViewer.setLabelProvider(new AnalysisTypeLabelProvider());
    typeTreeViewer.setInput(ViewerDataFactory.createTreeData());
    addListeners();
    setControl(container);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) AnalysisTypeContentProvider(org.talend.dataprofiler.core.ui.wizard.analysis.provider.AnalysisTypeContentProvider) Composite(org.eclipse.swt.widgets.Composite) AnalysisTypeLabelProvider(org.talend.dataprofiler.core.ui.wizard.analysis.provider.AnalysisTypeLabelProvider) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Example 8 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project dbeaver by serge-rider.

the class ManageCRSDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite dialogArea = super.createDialogArea(parent);
    if (crsLoader == null) {
        crsLoader = new CRSLoader();
        try {
            UIUtils.runInProgressDialog(crsLoader);
        } catch (InvocationTargetException e) {
            log.error("Error loading CRS list", e.getTargetException());
        }
    }
    PatternFilter patternFilter = new PatternFilter() {

        @Override
        protected boolean isLeafMatch(Viewer viewer, Object element) {
            if (element instanceof CRSInfo) {
                return wordMatches(((CRSInfo) element).name) || wordMatches(String.valueOf(((CRSInfo) element).code)) || wordMatches(((CRSInfo) element).coordSystemName) || wordMatches(((CRSInfo) element).projectionName);
            }
            return super.isLeafMatch(viewer, element);
        }
    };
    TreeViewer treeViewer = DialogUtils.createFilteredTree(dialogArea, SWT.BORDER | SWT.FULL_SELECTION, patternFilter, null);
    Tree crsTree = treeViewer.getTree();
    crsTree.setLayoutData(new GridData(GridData.FILL_BOTH));
    crsTree.setHeaderVisible(true);
    UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_name);
    UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_srid);
    UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_coordinate_system);
    UIUtils.createTreeColumn(crsTree, SWT.LEFT, GISMessages.panel_manage_crs_dialog_tree_column_text_projection);
    treeViewer.setContentProvider(new ITreeContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement == crsLoader) {
                return crsLoader.crsMap.keySet().toArray(new Object[0]);
            } else if (parentElement instanceof String) {
                List<CRSInfo> crsInfos = crsLoader.crsMap.get(parentElement);
                return crsInfos == null ? null : crsInfos.toArray(new Object[0]);
            } else {
                return new Object[0];
            }
        }

        @Override
        public Object getParent(Object element) {
            if (element instanceof String) {
                return crsTree;
            } else {
                return null;
            }
        }

        @Override
        public boolean hasChildren(Object element) {
            if (element == crsLoader) {
                return !crsLoader.crsMap.isEmpty();
            } else if (element instanceof String) {
                List<CRSInfo> crsInfos = crsLoader.crsMap.get(element);
                return crsInfos != null && !crsInfos.isEmpty();
            } else {
                return false;
            }
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return getChildren(inputElement);
        }
    });
    treeViewer.setLabelProvider(new CRSLabelProvider());
    treeViewer.setInput(crsLoader);
    treeViewer.expandAll();
    treeViewer.addSelectionChangedListener(event -> {
        ISelection selection = event.getSelection();
        if (selection instanceof IStructuredSelection) {
            Object selElement = ((IStructuredSelection) selection).getFirstElement();
            if (selElement instanceof CRSInfo) {
                // List<CRSInfo> crsInfo = crsLoader.crsMap.get(selElement);
                selectedSRID = ((CRSInfo) selElement).code;
            }
        }
    });
    /*
        for (String regName : crsLoader.crsMap.keySet()) {
            regName = regName.toUpperCase(Locale.ENGLISH);
            TreeItem regItem = new TreeItem(crsTree, SWT.NONE);
            regItem.setText(0, regName);
            for (CRSInfo crsInfo : crsLoader.crsMap.get(regName)) {
                TreeItem crsItem = new TreeItem(regItem, SWT.NONE);
                crsItem.setText(0, crsInfo.name);
                crsItem.setText(1, String.valueOf(crsInfo.code));
                crsItem.setText(2, crsInfo.coordSystemName);
                crsItem.setText(3, crsInfo.projectionName);
                crsItem.setData(crsInfo);
            }
            regItem.setExpanded(true);
        }
*/
    UIUtils.packColumns(crsTree, true, null);
    return dialogArea;
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Composite(org.eclipse.swt.widgets.Composite) InvocationTargetException(java.lang.reflect.InvocationTargetException) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree)

Example 9 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.

the class SchemaPresetSelectionDialog method createViewer.

/**
 * @see AbstractViewerSelectionDialog#createViewer(Composite)
 */
@Override
protected TreeViewer createViewer(Composite parent) {
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    tree.getViewer().setComparator(new SchemaPresetComparator());
    // set filter to only accept schema selection (must be set after
    // pattern filter is created)
    setFilters(new ViewerFilter[] { new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return element instanceof SchemaPreset;
        }
    } });
    return tree.getViewer();
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SchemaPreset(eu.esdihumboldt.hale.common.schema.presets.extension.SchemaPreset) Viewer(org.eclipse.jface.viewers.Viewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Example 10 with PatternFilter

use of org.eclipse.ui.dialogs.PatternFilter in project hale by halestudio.

the class DataSetTypeSelectionDialog method createViewer.

@Override
protected TreeViewer createViewer(Composite parent) {
    // create viewer
    PatternFilter patternFilter = new PatternFilter();
    patternFilter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, patternFilter, true);
    tree.getViewer().setComparator(new DefinitionComparator());
    return tree.getViewer();
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) DefinitionComparator(eu.esdihumboldt.hale.ui.common.definition.viewer.DefinitionComparator) FilteredTree(org.eclipse.ui.dialogs.FilteredTree)

Aggregations

PatternFilter (org.eclipse.ui.dialogs.PatternFilter)31 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)23 Composite (org.eclipse.swt.widgets.Composite)20 GridLayout (org.eclipse.swt.layout.GridLayout)12 TreeViewer (org.eclipse.jface.viewers.TreeViewer)11 Viewer (org.eclipse.jface.viewers.Viewer)11 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)9 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)9 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)8 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)8 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)7 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 GridData (org.eclipse.swt.layout.GridData)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 Label (org.eclipse.swt.widgets.Label)6 Tree (org.eclipse.swt.widgets.Tree)6 CachedCheckboxTreeViewer (org.eclipse.egit.ui.internal.components.CachedCheckboxTreeViewer)5 FilteredCheckboxTree (org.eclipse.egit.ui.internal.components.FilteredCheckboxTree)5