List of usage examples for org.eclipse.jface.viewers ViewerComparator ViewerComparator
public ViewerComparator(Comparator<? super String> comparator)
From source file:org.eclipse.incquery.tooling.ui.queryexplorer.content.detail.TableViewerUtil.java
License:Open Source License
public void prepareTableViewerForMatcherConfiguration(ObservablePatternMatcher observableMatcher, TableViewer viewer) {/*from ww w . j ava 2 s . co m*/ clearTableViewerColumns(viewer); String[] titles = { "Parameter", "Filter", "Class" }; createColumns(viewer, titles); viewer.setUseHashlookup(true); viewer.setColumnProperties(titles); viewer.setContentProvider(new MatcherConfigurationContentProvider()); viewer.setLabelProvider(new MatcherConfigurationLabelProvider()); viewer.setCellModifier(new MatcherConfigurationCellModifier(viewer)); viewer.setComparator( new ViewerComparator(new DetailComparator(observableMatcher.getMatcher().getParameterNames()))); Table table = viewer.getTable(); CellEditor[] editors = new CellEditor[titles.length]; editors[0] = new TextCellEditor(table); ModelElementCellEditor cellEditor = new ModelElementCellEditor(table, observableMatcher); injector.injectMembers(cellEditor); editors[1] = cellEditor; editors[2] = new TextCellEditor(table); viewer.setCellEditors(editors); Pattern pattern = PatternRegistry.getInstance().getPatternByFqn(observableMatcher.getPatternName()); Object[] filter = observableMatcher.getFilter(); MatcherConfiguration[] input = new MatcherConfiguration[pattern.getParameters().size()]; if (filter != null) { for (int i = 0; i < pattern.getParameters().size(); i++) { Variable var = pattern.getParameters().get(i); String name = var.getName(); JvmTypeReference ref = typeProvider.getTypeForIdentifiable(var); String clazz = (ref == null) ? "" : ref.getType().getQualifiedName(); input[i] = new MatcherConfiguration(name, clazz, filter[i]); } viewer.setInput(input); } }
From source file:org.eclipse.php.internal.ui.preferences.PHPSyntaxColoringPage.java
License:Open Source License
/** * Creates the List viewer where we see the various syntax element display * names--would it ever be a Tree like JDT's? * //from www .j ava2s. c om * @param parent * @return */ private StructuredViewer createStylesViewer(Composite parent) { StructuredViewer stylesViewer = new ListViewer(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); stylesViewer.setComparator(new ViewerComparator(Collator.getInstance())); stylesViewer.setLabelProvider(new LabelProvider() { @Override public String getText(Object element) { Object description = fStyleToDescriptionMap.get(element); if (description != null) return description.toString(); else if (SemanticHighlightingManager.getInstance().getSemanticHighlightings() .containsKey(element)) { AbstractSemanticHighlighting semanticHighlighting = SemanticHighlightingManager.getInstance() .getSemanticHighlightings().get(element); return semanticHighlighting.getDisplayName(); } return super.getText(element); } }); stylesViewer.setContentProvider(new ITreeContentProvider() { public void dispose() { } public Object[] getChildren(Object parentElement) { return getStylePreferenceKeys().toArray(); } public Object[] getElements(Object inputElement) { return getChildren(inputElement); } public Object getParent(Object element) { return getStylePreferenceKeys(); } public boolean hasChildren(Object element) { return false; } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); return stylesViewer; }
From source file:org.eclipse.riena.ui.ridgets.swt.AbstractListRidget.java
License:Open Source License
public void setComparator(final int columnIndex, final Comparator<?> comparator) { Assert.isLegal(columnIndex == 0, "columnIndex out of bounds (must be 0)"); //$NON-NLS-1$ if (comparator != null) { final SortableComparator sortableComparator = new SortableComparator(this, comparator); this.comparator = new ViewerComparator(sortableComparator); } else {//www .ja v a 2 s .c om this.comparator = null; } updateComparator(); }
From source file:org.eclipse.ui.internal.editors.text.AnnotationsConfigurationBlock.java
License:Open Source License
public Control createControl(Composite parent) { PixelConverter pixelConverter = new PixelConverter(parent); Composite composite = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); layout.numColumns = 2;/*from w w w .ja v a2s . com*/ layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); Label label = new Label(composite, SWT.LEFT); label.setText(TextEditorMessages.AnnotationsConfigurationBlock_annotationPresentationOptions); GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); gd.horizontalSpan = 2; 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(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL); gd.horizontalSpan = 2; editorComposite.setLayoutData(gd); fAnnotationTypeViewer = new TableViewer(editorComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); fAnnotationTypeViewer.setLabelProvider(new ItemLabelProvider()); fAnnotationTypeViewer.setContentProvider(new ItemContentProvider()); gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false); gd.heightHint = pixelConverter.convertHeightInCharsToPixels(20); 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(GridData.FILL_BOTH)); label = new Label(optionsComposite, SWT.LEFT); label.setText(TextEditorMessages.AnnotationsConfigurationBlock_labels_showIn); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalSpan = 2; label.setLayoutData(gd); fShowInVerticalRulerCheckBox = new Button(optionsComposite, SWT.CHECK); fShowInVerticalRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInVerticalRuler); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalSpan = 2; gd.horizontalIndent = 20; fShowInVerticalRulerCheckBox.setLayoutData(gd); fShowInOverviewRulerCheckBox = new Button(optionsComposite, SWT.CHECK); fShowInOverviewRulerCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInOverviewRuler); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalSpan = 2; gd.horizontalIndent = 20; fShowInOverviewRulerCheckBox.setLayoutData(gd); fShowInTextCheckBox = new Button(optionsComposite, SWT.CHECK); fShowInTextCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_showInText); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalIndent = 20; 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, PROBLEM_UNDERLINE, IBEAM }); fDecorationViewer.getCombo().setVisibleItemCount(fDecorationViewer.getCombo().getItemCount()); label = new Label(optionsComposite, SWT.LEFT); label.setText(TextEditorMessages.AnnotationsConfigurationBlock_color); gd = new GridData(); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalIndent = 20; label.setLayoutData(gd); fAnnotationForegroundColorEditor = new ColorSelector(optionsComposite); Button foregroundColorButton = fAnnotationForegroundColorEditor.getButton(); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; foregroundColorButton.setLayoutData(gd); addFiller(optionsComposite); fIsNextPreviousTargetCheckBox = new Button(optionsComposite, SWT.CHECK); fIsNextPreviousTargetCheckBox.setText(TextEditorMessages.AnnotationsConfigurationBlock_isNavigationTarget); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalAlignment = GridData.BEGINNING; gd.horizontalSpan = 2; gd.horizontalIndent = 0; fIsNextPreviousTargetCheckBox.setLayoutData(gd); fAnnotationTypeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { handleAnnotationListSelection(); } }); fShowInTextCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } 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)) fStore.setValue(item.highlightKey, true); else fStore.setValue(item.textKey, true); } else { // disable both if (item.textKey != null) fStore.setValue(item.textKey, false); if (item.highlightKey != null) fStore.setValue(item.highlightKey, false); } fStore.setValue(item.textKey, value); updateDecorationViewer(item, false); fAnnotationTypeViewer.refresh(item); } }); fShowInOverviewRulerCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { ListItem item = getSelectedItem(); fStore.setValue(item.overviewRulerKey, fShowInOverviewRulerCheckBox.getSelection()); fAnnotationTypeViewer.refresh(item); } }); fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { ListItem item = getSelectedItem(); fStore.setValue(item.verticalRulerKey, fShowInVerticalRulerCheckBox.getSelection()); fAnnotationTypeViewer.refresh(item); } }); fIsNextPreviousTargetCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { ListItem item = getSelectedItem(); fStore.setValue(item.isNextPreviousNavigationKey, fIsNextPreviousTargetCheckBox.getSelection()); fAnnotationTypeViewer.refresh(item); } }); foregroundColorButton.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { ListItem item = getSelectedItem(); PreferenceConverter.setValue(fStore, item.colorKey, fAnnotationForegroundColorEditor.getColorValue()); fAnnotationTypeViewer.refresh(item); } }); fDecorationViewer.addSelectionChangedListener(new ISelectionChangedListener() { /* * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */ public void selectionChanged(SelectionChangedEvent event) { String[] decoration = (String[]) ((IStructuredSelection) fDecorationViewer.getSelection()) .getFirstElement(); ListItem item = getSelectedItem(); if (fShowInTextCheckBox.getSelection()) { if (HIGHLIGHT.equals(decoration)) { fStore.setValue(item.highlightKey, true); if (item.textKey != null) { fStore.setValue(item.textKey, false); if (item.textStyleKey != null) fStore.setValue(item.textStyleKey, AnnotationPreference.STYLE_NONE); } } else { if (item.highlightKey != null) fStore.setValue(item.highlightKey, false); if (item.textKey != null) { fStore.setValue(item.textKey, true); if (item.textStyleKey != null) fStore.setValue(item.textStyleKey, decoration[1]); } } } fAnnotationTypeViewer.refresh(item); } }); composite.layout(); return composite; }
From source file:org.eclipse.ui.internal.editors.text.LinkedModeConfigurationBlock.java
License:Open Source License
/** * Creates page for hover preferences.// w w w . jav a2s . co m * * @param parent the parent composite * @return the control for the preference page */ 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() { public void selectionChanged(SelectionChangedEvent event) { handleAnnotationListSelection(); } }); fShowInTextCheckBox.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } 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() { public void widgetDefaultSelected(SelectionEvent e) { // do nothing } public void widgetSelected(SelectionEvent e) { ListItem item = getSelectedItem(); PreferenceConverter.setValue(getPreferenceStore(), item.colorKey, fAnnotationForegroundColorEditor.getColorValue()); } }); fDecorationViewer.addSelectionChangedListener(new ISelectionChangedListener() { /* * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */ 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; }