Search in sources :

Example 56 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project translationstudio8 by heartsome.

the class ImportProjectWizardPage 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(DataTransferMessages.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));
    projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.widthHint = new PixelConverter(projectsList.getControl()).convertWidthInCharsToPixels(25);
    gridData.heightHint = new PixelConverter(projectsList.getControl()).convertHeightInCharsToPixels(10);
    projectsList.getControl().setLayoutData(gridData);
    projectsList.setContentProvider(new ITreeContentProvider() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java
			 * .lang.Object)
			 */
        public Object[] getChildren(Object parentElement) {
            return null;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements
			 * (java.lang.Object)
			 */
        public Object[] getElements(Object inputElement) {
            return getProjectRecords();
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java
			 * .lang.Object)
			 */
        public boolean hasChildren(Object element) {
            return false;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java
			 * .lang.Object)
			 */
        public Object getParent(Object element) {
            return null;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
			 */
        public void dispose() {
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
			 * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
			 */
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    projectsList.setLabelProvider(new ProjectLabelProvider());
    projectsList.addCheckStateListener(new ICheckStateListener() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
			 * (org.eclipse.jface.viewers.CheckStateChangedEvent)
			 */
        public void checkStateChanged(CheckStateChangedEvent event) {
            ProjectRecord element = (ProjectRecord) event.getElement();
            if (element.hasConflicts) {
                projectsList.setChecked(element, false);
            }
            setPageComplete(projectsList.getCheckedElements().length > 0);
        }
    });
    projectsList.setInput(this);
    projectsList.setComparator(new ViewerComparator());
    createSelectionButtons(listComposite);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Composite(org.eclipse.swt.widgets.Composite) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 57 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project translationstudio8 by heartsome.

the class ConverterUtil method bindValue.

/**
	 * 对下拉列表和转换器列表进行绑定
	 * @param context
	 * @param comboViewer
	 * @param model
	 *            ;
	 */
public static void bindValue(DataBindingContext context, ComboViewer comboViewer, ConverterViewModel model) {
    // ViewerSupport.bind(comboViewer, BeansObservables.observeList(
    // model, "supportTypes", String.class),
    // Properties.selfValue(String.class));
    //		
    //
    // context.bindValue(ViewersObservables
    // .observeSingleSelection(comboViewer), BeansObservables
    // .observeValue(model,
    // "selectedType"));
    // ObservableListContentProvider viewerContentProvider=new ObservableListContentProvider();
    comboViewer.setContentProvider(new ArrayContentProvider());
    comboViewer.setComparator(new ViewerComparator());
    // IObservableMap[] attributeMaps = BeansObservables.observeMaps(
    // viewerContentProvider.getKnownElements(),
    // ConverterBean.class, new String[] { "description" });
    // comboViewer.setLabelProvider(new ObservableMapLabelProvider(
    // attributeMaps));
    // comboViewer.setInput(Observables.staticObservableList(model.getSupportTypes(),ConverterBean.class));
    comboViewer.setInput(model.getSupportTypes());
    IViewerObservableValue selection = ViewersObservables.observeSingleSelection(comboViewer);
    IObservableValue observableValue = BeansObservables.observeDetailValue(selection, PROPERTIES_NAME, null);
    context.bindValue(observableValue, BeansObservables.observeValue(model, PROPERTIES_SELECTED_TYPE));
}
Also used : ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) IViewerObservableValue(org.eclipse.jface.databinding.viewers.IViewerObservableValue)

Example 58 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project eclipse.platform.text by eclipse.

the class LinkedModeConfigurationBlock method createControl.

/**
 * Creates page for hover preferences.
 *
 * @param parent the parent composite
 * @return the control for the preference page
 */
@Override
public Control createControl(Composite parent) {
    OverlayPreferenceStore store = getPreferenceStore();
    store.load();
    store.start();
    initializeDialogUnits(parent);
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.LEFT);
    label.setText(TextEditorMessages.LinkedModeConfigurationBlock_annotationPresentationOptions);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    label.setLayoutData(gd);
    Composite editorComposite = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    editorComposite.setLayoutData(gd);
    fAnnotationTypeViewer = new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    fAnnotationTypeViewer.setLabelProvider(new ItemLabelProvider());
    fAnnotationTypeViewer.setContentProvider(new ItemContentProvider());
    gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
    gd.heightHint = convertHeightInCharsToPixels(5);
    fAnnotationTypeViewer.getControl().setLayoutData(gd);
    Composite optionsComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    optionsComposite.setLayout(layout);
    optionsComposite.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
    // we only allow to set either "show in text" or "highlight in text", but not both
    fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK);
    fShowInTextCheckBox.setText(TextEditorMessages.LinkedModeConfigurationBlock_labels_showIn);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    fShowInTextCheckBox.setLayoutData(gd);
    fDecorationViewer = new ComboViewer(optionsComposite, SWT.READ_ONLY);
    fDecorationViewer.setContentProvider(new ArrayContentProvider());
    fDecorationViewer.setLabelProvider(new ArrayLabelProvider());
    fDecorationViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    fDecorationViewer.getControl().setLayoutData(gd);
    fDecorationViewer.setInput(new Object[] { HIGHLIGHT, SQUIGGLES, BOX, DASHED_BOX, UNDERLINE, IBEAM });
    label = new Label(optionsComposite, SWT.LEFT);
    label.setText(TextEditorMessages.LinkedModeConfigurationBlock_color);
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    label.setLayoutData(gd);
    fAnnotationForegroundColorEditor = new ColorSelector(optionsComposite);
    Button foregroundColorButton = fAnnotationForegroundColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);
    createDependency(fShowInTextCheckBox, new Control[] { label, foregroundColorButton });
    fAnnotationTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            handleAnnotationListSelection();
        }
    });
    fShowInTextCheckBox.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            final boolean value = fShowInTextCheckBox.getSelection();
            if (value) {
                // enable whatever is in the combo
                String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
                if (HIGHLIGHT.equals(decoration))
                    getPreferenceStore().setValue(item.highlightKey, true);
                else
                    getPreferenceStore().setValue(item.textKey, true);
            } else {
                // disable both
                getPreferenceStore().setValue(item.textKey, false);
                getPreferenceStore().setValue(item.highlightKey, false);
            }
            getPreferenceStore().setValue(item.textKey, value);
            updateDecorationViewer(item, false);
        }
    });
    foregroundColorButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            ListItem item = getSelectedItem();
            PreferenceConverter.setValue(getPreferenceStore(), item.colorKey, fAnnotationForegroundColorEditor.getColorValue());
        }
    });
    fDecorationViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()).getFirstElement();
            ListItem item = getSelectedItem();
            if (fShowInTextCheckBox.getSelection()) {
                if (HIGHLIGHT.equals(decoration)) {
                    getPreferenceStore().setValue(item.highlightKey, true);
                    getPreferenceStore().setValue(item.textKey, false);
                    getPreferenceStore().setValue(item.textStyleKey, AnnotationPreference.STYLE_NONE);
                } else {
                    getPreferenceStore().setValue(item.highlightKey, false);
                    getPreferenceStore().setValue(item.textKey, true);
                    getPreferenceStore().setValue(item.textStyleKey, decoration[1]);
                }
            }
        }
    });
    return composite;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 59 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project knime-core by knime.

the class AbstractRepositoryView method onSearchQueryChanged.

/* called whenever the search query changes (no matter in what search mode, i.e. fuzzy or text) */
private void onSearchQueryChanged() {
    if (m_fuzzySearchButton.isChecked()) {
        // if the query string is empty, use the category tree, otherwise show the node list (in case fuzzy search is activated)
        if (m_fuzzyTextInfoFilter.getDelegateFilter().hasNonEmptyQuery()) {
            if (!(m_viewer.getContentProvider() instanceof ListRepositoryContentProvider)) {
                // only change the content provider if its not a list content provider already
                m_viewer.setContentProvider(new ListRepositoryContentProvider());
                // sync the additional info to be shown
                onShowAdditionalInfoClicked();
            }
            m_viewer.setComparator(new ViewerComparator(m_fuzzyTextInfoFilter.getDelegateFilter().createComparator()));
        } else {
            if (!(m_viewer.getContentProvider() instanceof RepositoryContentProvider)) {
                // only change the content provider if its not a tree content provider already
                m_viewer.setContentProvider(new RepositoryContentProvider());
                m_viewer.setComparator(null);
                // sync the additional info to be shown
                onShowAdditionalInfoClicked();
            }
        }
    }
}
Also used : ViewerComparator(org.eclipse.jface.viewers.ViewerComparator)

Example 60 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project knime-core by knime.

the class AbstractRepositoryView method onFuzzySearchButtonClicked.

/* action to be performed if the "Fuzzy Search" button is clicked */
private void onFuzzySearchButtonClicked(final AdditionalInfoViewFilter extFuzzyFilter, final AdditionalInfoViewFilter extTextFilter) {
    if (m_fuzzySearchButton.isChecked()) {
        m_viewer.setFilters(new ViewerFilter[] { extFuzzyFilter });
        m_toolbarSearchText.setFilter(extFuzzyFilter.getDelegateFilter());
        // sync streamable filter settings
        extTextFilter.setDoFilter(m_filterStreamNodesButton.isChecked());
        extFuzzyFilter.setDoFilter(m_filterStreamNodesButton.isChecked());
        // transfer the search query
        extFuzzyFilter.getDelegateFilter().setQueryString(extTextFilter.getDelegateFilter().getQueryString());
        // set the content provider. If search query is empty, show the tree, otherwise the list
        if (extTextFilter.getDelegateFilter().hasNonEmptyQuery()) {
            m_viewer.setContentProvider(new ListRepositoryContentProvider());
            m_viewer.setComparator(new ViewerComparator(extFuzzyFilter.getDelegateFilter().createComparator()));
        } else {
            m_viewer.setContentProvider(new RepositoryContentProvider());
            m_viewer.setComparator(null);
        }
    } else {
        m_viewer.setContentProvider(new RepositoryContentProvider());
        m_viewer.setFilters(new ViewerFilter[] { extTextFilter });
        m_toolbarSearchText.setFilter(extTextFilter.getDelegateFilter());
        // sync streamable filter settings
        extTextFilter.setDoFilter(m_filterStreamNodesButton.isChecked());
        extFuzzyFilter.setDoFilter(m_filterStreamNodesButton.isChecked());
        // transfer the search query
        extTextFilter.getDelegateFilter().setQueryString(extFuzzyFilter.getDelegateFilter().getQueryString());
        m_viewer.setComparator(null);
    }
    // sync the additional info info
    // mainly to set the right label provider
    onShowAdditionalInfoClicked();
    if (extTextFilter.getDelegateFilter().hasNonEmptyQuery()) {
        TreeViewerUpdater.update(m_viewer, true, true);
    }
}
Also used : ViewerComparator(org.eclipse.jface.viewers.ViewerComparator)

Aggregations

ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)110 Viewer (org.eclipse.jface.viewers.Viewer)64 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)50 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)34 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)23 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)18 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)17 Button (org.eclipse.swt.widgets.Button)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)15 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)15