use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.
the class InstanceValidationReportDetailsPage method createControls.
/**
* @see CustomReportDetailsPage#createControls(Composite)
*/
@Override
public Control createControls(Composite parent) {
// filtered tree sets itself GridData, so set layout to gridlayout
parent.setLayout(GridLayoutFactory.fillDefaults().create());
// create pattern filter for FilteredTree
PatternFilter filter = new TreePathPatternFilter();
filter.setIncludeLeadingWildcard(true);
// create FilteredTree
FilteredTree filteredTree = new TreePathFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
treeViewer = filteredTree.getViewer();
// set content provider
contentProvider = new InstanceValidationReportDetailsContentProvider();
treeViewer.setContentProvider(contentProvider);
// set label provider
treeViewer.setLabelProvider(new InstanceValidationReportDetailsLabelProvider(contentProvider));
// set comparator
treeViewer.setComparator(new ViewerComparator() {
/**
* @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
*/
@Override
public int category(Object element) {
if (element instanceof QName || element instanceof Definition<?>)
// Path
return 0;
else if (element instanceof String)
// Category
return 1;
else
// InstanceValidationMessage
return 2;
}
});
// add menu on right-click
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
if (getValidSelection() == null)
return;
// selection is valid, offer link to transformed data view
manager.add(new ShowExampleAction());
}
});
// remove previous menus
menuMgr.setRemoveAllWhenShown(true);
// add menu to tree
treeViewer.getTree().setMenu(menu);
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
showSelectionInDataView();
}
});
Image noReportBaseImage = InstanceValidationUIPlugin.getDefault().getImageRegistry().get(InstanceValidationUIPlugin.IMG_INSTANCE_VALIDATION);
reportImage = new DecorationOverlayIcon(noReportBaseImage, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), IDecoration.BOTTOM_LEFT).createImage();
return filteredTree;
}
use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.
the class ReportList method createViewControl.
/**
* Create contents of the view part.
*
* @param parent parent element
*/
@Override
public void createViewControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
TreeColumnLayout layout = new TreeColumnLayout();
composite.setLayout(layout);
{
_treeViewer = new TreeViewer(composite, SWT.BORDER);
final Tree tree = _treeViewer.getTree();
tree.setHeaderVisible(false);
tree.setLinesVisible(false);
// create column for reports
TreeViewerColumn col1 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col1.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelProvider()));
// and layout
layout.setColumnData(col1.getColumn(), new ColumnWeightData(3));
// create column for reports
TreeViewerColumn col2 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col2.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelDateProvider()));
// create column for reports
layout.setColumnData(col2.getColumn(), new ColumnWeightData(1));
new ReportListMenu(getSite(), _treeViewer);
}
createActions();
initializeToolBar();
initializeMenu();
// set label provider
// _treeViewer.setLabelProvider(new ReportListLabelProvider());
// set content provider
_treeViewer.setContentProvider(new ReportListContentProvider());
// disable this if it uses too much memory
// but should maintain the list much faster
_treeViewer.setUseHashlookup(true);
// order the sessions from latest to oldest
_treeViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof ReportSession && e2 instanceof ReportSession) {
long first = ((ReportSession) e1).getId();
long second = ((ReportSession) e2).getId();
if (first > second) {
return -1;
} else if (first < second) {
return 1;
} else {
return 0;
}
} else if (e1 instanceof Report<?> && e2 instanceof Report<?>) {
Report<?> first = (Report<?>) e1;
Report<?> second = (Report<?>) e2;
if (first.getStartTime() == null && second.getStartTime() == null) {
return 0;
} else if (first.getStartTime() == null) {
return 1;
} else if (second.getStartTime() == null) {
return -1;
} else if (first.getStartTime().getTime() > second.getStartTime().getTime()) {
return -1;
} else if (first.getStartTime().getTime() < second.getStartTime().getTime()) {
return 1;
} else {
return 0;
}
}
return 0;
}
});
// set selection provider
getSite().setSelectionProvider(_treeViewer);
_treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
OpenPropertiesHandler.unpinAndOpenPropertiesView(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
}
});
// load all added reports
this.loadReports();
}
use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.
the class GeneralPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, HELP_ID);
Composite client = new Composite(parent, SWT.NULL);
client.setLayout(new GridLayout());
GridData gd;
Group fileGroup = new Group(client, SWT.NULL);
fileGroup.setText(Messages.GeneralPreferencePage_0);
fileGroup.setLayout(new GridLayout(2, false));
fileGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Automatically open views when opening a model file
fOpenDiagramsOnLoadButton = new Button(fileGroup, SWT.CHECK);
fOpenDiagramsOnLoadButton.setText(Messages.GeneralPreferencePage_1);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fOpenDiagramsOnLoadButton.setLayoutData(gd);
// Backup file on save
fBackupOnSaveButton = new Button(fileGroup, SWT.CHECK);
fBackupOnSaveButton.setText(Messages.GeneralPreferencePage_5);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fBackupOnSaveButton.setLayoutData(gd);
// Size of recently opened file list
Label label = new Label(fileGroup, SWT.NULL);
label.setText(Messages.GeneralPreferencePage_2);
fMRUSizeSpinner = new Spinner(fileGroup, SWT.BORDER);
fMRUSizeSpinner.setMinimum(3);
fMRUSizeSpinner.setMaximum(15);
// Appearance
Group appearanceGroup = new Group(client, SWT.NULL);
appearanceGroup.setText(Messages.GeneralPreferencePage_3);
appearanceGroup.setLayout(new GridLayout(2, false));
appearanceGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Themes
label = new Label(appearanceGroup, SWT.NULL);
label.setText(Messages.GeneralPreferencePage_4);
fThemeComboViewer = new ComboViewer(appearanceGroup, SWT.READ_ONLY);
gd = new GridData(GridData.FILL_HORIZONTAL);
fThemeComboViewer.getCombo().setLayoutData(gd);
fThemeComboViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
return (Object[]) inputElement;
}
});
fThemeComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((ITheme) element).getLabel();
}
});
fThemeComboViewer.setComparator(new ViewerComparator());
// Show Status Line
fShowStatusLineButton = new Button(appearanceGroup, SWT.CHECK);
fShowStatusLineButton.setText(Messages.GeneralPreferencePage_9);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fShowStatusLineButton.setLayoutData(gd);
label = new Label(appearanceGroup, SWT.NULL);
label.setText(Messages.GeneralPreferencePage_8);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
label.setLayoutData(gd);
// Model Tree
Group modelTreeGroup = new Group(client, SWT.NULL);
modelTreeGroup.setText(Messages.GeneralPreferencePage_10);
modelTreeGroup.setLayout(new GridLayout(2, false));
modelTreeGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fShowUnusedElementsInModelTreeButton = new Button(modelTreeGroup, SWT.CHECK);
fShowUnusedElementsInModelTreeButton.setText(Messages.GeneralPreferencePage_11);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fShowUnusedElementsInModelTreeButton.setLayoutData(gd);
// Visualiser
Group visualiserGroup = new Group(client, SWT.NULL);
visualiserGroup.setText(Messages.GeneralPreferencePage_6);
visualiserGroup.setLayout(new GridLayout(2, false));
visualiserGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fAnimateVisualiserNodesButton = new Button(visualiserGroup, SWT.CHECK);
fAnimateVisualiserNodesButton.setText(Messages.GeneralPreferencePage_7);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
fAnimateVisualiserNodesButton.setLayoutData(gd);
fAnimateVisualiserNodesButton.setEnabled(AnimationUtil.supportsAnimation());
setValues();
fThemeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ITheme theme = (ITheme) ((IStructuredSelection) fThemeComboViewer.getSelection()).getFirstElement();
if (theme != null && theme != fThemeEngine.getActiveTheme()) {
setTheme(theme, false);
}
}
});
return client;
}
use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.
the class UserPropertiesManagerDialog method createTableControl.
private void createTableControl(Composite parent) {
Composite tableComp = new Composite(parent, SWT.BORDER);
TableColumnLayout tableLayout = new TableColumnLayout();
tableComp.setLayout(tableLayout);
tableComp.setLayoutData(new GridData(GridData.FILL_BOTH));
fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.FULL_SELECTION);
fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
fTableViewer.getTable().setHeaderVisible(true);
fTableViewer.getTable().setLinesVisible(true);
fTableViewer.setComparator(new ViewerComparator());
// Columns
TableViewerColumn columnOldKey = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
columnOldKey.getColumn().setText(Messages.UserPropertiesManagerDialog_6);
tableLayout.setColumnData(columnOldKey.getColumn(), new ColumnWeightData(40, true));
TableViewerColumn columnNewKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
columnNewKey.getColumn().setText(Messages.UserPropertiesManagerDialog_7);
tableLayout.setColumnData(columnNewKey.getColumn(), new ColumnWeightData(40, true));
columnNewKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
TableViewerColumn columnUsedNumber = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
// $NON-NLS-1$
columnUsedNumber.getColumn().setText("# " + Messages.UserPropertiesManagerDialog_8);
tableLayout.setColumnData(columnUsedNumber.getColumn(), new ColumnWeightData(20, true));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
return fKeysTable.entrySet().toArray();
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelCellProvider());
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
fActionDelete.setEnabled(!event.getSelection().isEmpty());
fButtonDelete.setEnabled(!event.getSelection().isEmpty());
fActionRename.setEnabled(!event.getSelection().isEmpty());
fButtonRename.setEnabled(!event.getSelection().isEmpty());
}
});
// anything will do //$NON-NLS-1$
fTableViewer.setInput("");
}
use of org.eclipse.jface.viewers.ViewerComparator in project eclipse.platform.text by eclipse.
the class AnnotationsConfigurationBlock method createControl.
@Override
public Control createControl(Composite parent) {
PixelConverter pixelConverter = new PixelConverter(parent);
Composite composite = new Composite(parent, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
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() {
@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))
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() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
fStore.setValue(item.overviewRulerKey, fShowInOverviewRulerCheckBox.getSelection());
fAnnotationTypeViewer.refresh(item);
}
});
fShowInVerticalRulerCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
fStore.setValue(item.verticalRulerKey, fShowInVerticalRulerCheckBox.getSelection());
fAnnotationTypeViewer.refresh(item);
}
});
fIsNextPreviousTargetCheckBox.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
fStore.setValue(item.isNextPreviousNavigationKey, fIsNextPreviousTargetCheckBox.getSelection());
fAnnotationTypeViewer.refresh(item);
}
});
foregroundColorButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// do nothing
}
@Override
public void widgetSelected(SelectionEvent e) {
ListItem item = getSelectedItem();
PreferenceConverter.setValue(fStore, item.colorKey, fAnnotationForegroundColorEditor.getColorValue());
fAnnotationTypeViewer.refresh(item);
}
});
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)) {
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;
}
Aggregations