use of org.eclipse.jface.viewers.ViewerComparator in project webtools.sourceediting by eclipse.
the class JSPSyntaxColoringPage method createStylesViewer.
/**
* Creates the List viewer where we see the various syntax element display
* names--would it ever be a Tree like JDT's?
*
* @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() {
public String getText(Object element) {
Object description = fStyleToDescriptionMap.get(element);
if (description != null)
return description.toString();
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;
}
use of org.eclipse.jface.viewers.ViewerComparator in project webtools.sourceediting by eclipse.
the class XSLSyntaxColoringPage method createStylesViewer.
/**
* Creates the List viewer where we see the various syntax element display
* names--would it ever be a Tree like JDT's?
*
* @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 = styleToDescriptionMap.get(element);
if (description != null)
return description.toString();
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;
}
use of org.eclipse.jface.viewers.ViewerComparator in project bndtools by bndtools.
the class ImportBndWorkspaceWizardPageOne method createControl.
@Override
public void createControl(final Composite parent) {
final Composite container = new Composite(parent, SWT.NONE);
Label lblFolder = new Label(container, SWT.NONE);
lblFolder.setText("Root Directory:");
txtFolder = new Text(container, SWT.BORDER | SWT.SINGLE);
txtFolder.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent event) {
getWizard().getContainer().updateButtons();
}
});
// Adding the decorator
txtFolderErrorDecorator = new ControlDecoration(txtFolder, SWT.TOP | SWT.RIGHT);
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
Image img = fieldDecoration.getImage();
txtFolderErrorDecorator.setImage(img);
txtFolderErrorDecorator.setDescriptionText("Selected folder must contain valid Bnd Workspace configuration project.");
// hiding it initially
txtFolderErrorDecorator.hide();
Button btnOpenDialog = new Button(container, SWT.PUSH);
btnOpenDialog.setText("Browse...");
btnOpenDialog.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
DirectoryDialog dirDialog = new DirectoryDialog(container.getShell());
dirDialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
dirDialog.setText("Select the folder containing the project.");
txtFolder.setText(dirDialog.open());
getWizard().getContainer().updateButtons();
}
});
Label lblProjects = new Label(container, SWT.NONE);
lblProjects.setText("Projects:");
tableViewer = new TableViewer(container, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
// configuration project always first
if (e1 instanceof File && e2 instanceof Project) {
return -1;
} else if (e1 instanceof Project && e2 instanceof File) {
return 1;
}
Project p1 = (Project) e1;
Project p2 = (Project) e2;
return super.compare(viewer, p1.getName(), p2.getName());
}
});
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
// Disable selection since the tableviewer should be readonly, but not disabled
if (!event.getSelection().isEmpty()) {
tableViewer.setSelection(StructuredSelection.EMPTY);
}
}
});
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.setLabelProvider(new ProjectsColumnLabelProvider());
Button refreshButton = new Button(container, SWT.PUSH);
refreshButton.setText("Refresh");
refreshButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
getWizard().getContainer().updateButtons();
}
});
deleteButton = new Button(container, SWT.CHECK);
deleteButton.setText("Delete existing settings");
inferExecutionEnvironmentButton = new Button(container, SWT.CHECK);
inferExecutionEnvironmentButton.setSelection(true);
inferExecutionEnvironmentButton.setText("Infer execution-environment (J2SE and JavaSE).");
inferExecutionEnvironmentButton.setToolTipText("Uses the 'javac.target' from the Bnd Workspace to infer a Execution Environment to the JRE container. If nothing matches, the default JRE will be used.\nExisting containers will be removed.");
FormLayout layout = new FormLayout();
container.setLayout(layout);
FormData fd_lblFolder = new FormData();
fd_lblFolder.top = new FormAttachment(0, 10);
fd_lblFolder.left = new FormAttachment(0, 10);
lblFolder.setLayoutData(fd_lblFolder);
FormData fd_txtFolder = new FormData();
fd_txtFolder.top = new FormAttachment(lblFolder, 0, SWT.CENTER);
fd_txtFolder.left = new FormAttachment(lblFolder, 10);
fd_txtFolder.right = new FormAttachment(100, -100);
txtFolder.setLayoutData(fd_txtFolder);
FormData fd_btnDialog = new FormData();
fd_btnDialog.top = new FormAttachment(lblFolder, 0, SWT.CENTER);
fd_btnDialog.left = new FormAttachment(txtFolder, 10);
fd_btnDialog.right = new FormAttachment(100, -10);
btnOpenDialog.setLayoutData(fd_btnDialog);
FormData fd_lblProjects = new FormData();
fd_lblProjects.top = new FormAttachment(lblFolder, 20);
fd_lblProjects.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
lblProjects.setLayoutData(fd_lblProjects);
FormData fd_table = new FormData();
fd_table.top = new FormAttachment(lblProjects, 5);
fd_table.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
fd_table.right = new FormAttachment(100, -100);
fd_table.bottom = new FormAttachment(100, -55);
tableViewer.getTable().setLayoutData(fd_table);
FormData fd_btnRefresh = new FormData();
fd_btnRefresh.top = new FormAttachment(tableViewer.getTable(), 0, SWT.TOP);
fd_btnRefresh.left = new FormAttachment(btnOpenDialog, 0, SWT.LEFT);
fd_btnRefresh.right = new FormAttachment(100, -10);
refreshButton.setLayoutData(fd_btnRefresh);
FormData fd_btnDelete = new FormData();
fd_btnDelete.top = new FormAttachment(tableViewer.getTable(), 10);
fd_btnDelete.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
deleteButton.setLayoutData(fd_btnDelete);
FormData fd_btnInfer = new FormData();
fd_btnInfer.top = new FormAttachment(deleteButton, 10);
fd_btnInfer.left = new FormAttachment(lblFolder, 0, SWT.LEFT);
inferExecutionEnvironmentButton.setLayoutData(fd_btnInfer);
getShell().setMinimumSize(470, 450);
// required to avoid an error in the system
setControl(parent);
setPageComplete(false);
txtFolder.setText(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
}
use of org.eclipse.jface.viewers.ViewerComparator in project AutoRefactor by JnRouvignac.
the class ChooseRefactoringWizardPage method createRefactoringsTable.
private void createRefactoringsTable(Composite parent) {
tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.H_SCROLL | SWT.CHECK | SWT.NO_FOCUS | SWT.HIDE_SELECTION);
createColumns(tableViewer);
tableViewer.setContentProvider(new ArrayContentProvider());
final List<RefactoringRule> refactorings = AllCleanUpRules.getAllCleanUpRules();
tableViewer.setInput(refactorings);
tableViewer.setCheckStateProvider(new CheckStateProvider(refactorings));
tableViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
return ((RefactoringRule) o1).getName().compareTo(((RefactoringRule) o2).getName());
}
});
tableViewer.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object refactoring) {
final String filter = filterText.getText().toLowerCase();
final RefactoringRule rule = (RefactoringRule) refactoring;
final String description = rule.getDescription().toLowerCase();
final String name = rule.getName().toLowerCase();
return description.contains(filter) || name.contains(filter);
}
});
ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
tableViewer.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
final String filter = filterText.getText().toLowerCase();
final String name = ((RefactoringRule) cell.getElement()).getName();
cell.setText(name);
cell.setStyleRanges(getStyleRanges(name, filter));
}
private StyleRange[] getStyleRanges(String text, String filter) {
final int matchIndex = text.toLowerCase().indexOf(filter);
final int matchLength = filter.length();
if (matchIndex != -1 && matchLength != 0) {
final StyledString styledString = new StyledString(text, defaultStyler);
styledString.setStyle(matchIndex, matchLength, underlineStyler);
return styledString.getStyleRanges();
}
return null;
}
@Override
public String getToolTipText(Object refactoring) {
RefactoringRule refactoringRule = (RefactoringRule) refactoring;
// $NON-NLS-1$
return refactoringRule.getDescription() + "\n\nWhy to do so:\n" + refactoringRule.getReason();
}
@Override
public Point getToolTipShift(Object object) {
return new Point(10, 20);
}
});
final Table table = tableViewer.getTable();
table.setLinesVisible(false);
table.addListener(SWT.EraseItem, event -> {
if ((event.detail & SWT.SELECTED) != 0) {
event.detail &= ~SWT.SELECTED;
}
});
table.addListener(SWT.MouseDown, event -> {
Point pt = new Point(event.x, event.y);
TableItem item = table.getItem(pt);
if (item == null) {
return;
}
int index = table.indexOf(item);
Object element = tableViewer.getElementAt(index);
tableViewer.setChecked(element, !tableViewer.getChecked(element));
});
table.addListener(SWT.MouseDoubleClick, event -> {
Point pt = new Point(event.x, event.y);
TableItem item = table.getItem(pt);
if (item == null) {
return;
}
int index = table.indexOf(item);
Object element = tableViewer.getElementAt(index);
tableViewer.setCheckedElements(new Object[] { element });
ChooseRefactoringWizardPage.this.getWizard().performFinish();
((WizardDialog) ChooseRefactoringWizardPage.this.getWizard().getContainer()).close();
});
tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
packColumns(table);
table.setFocus();
}
use of org.eclipse.jface.viewers.ViewerComparator in project yamcs-studio by yamcs.
the class AddParameterPage method createControl.
@Override
public void createControl(Composite parent) {
var composite = new Composite(parent, SWT.NONE);
setControl(composite);
var gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.numColumns = 2;
gl.makeColumnsEqualWidth = false;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
var tableWrapper1 = new Composite(composite, SWT.NONE);
contentProvider = new ParameterContentProvider();
trcl = new TreeColumnLayout();
tableWrapper1.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper1.setLayout(trcl);
treeViewer = new TreeViewer(tableWrapper1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
treeViewer.getTree().setHeaderVisible(true);
treeViewer.getTree().setLinesVisible(true);
// column container
var pathColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
pathColumn.getColumn().setText(COL_NAMESPACE);
pathColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var namespace = (String) element;
return namespace.substring(namespace.lastIndexOf("/") + 1);
}
});
trcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
treeViewer.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
contentProvider.setNamespace(null);
return;
}
contentProvider.setNamespace((String) sel.getFirstElement());
});
treeViewer.setContentProvider(new NamespaceContentProvider());
treeViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
var n1 = (String) o1;
var n2 = (String) o2;
return n1.compareTo(n2);
}
});
var tableWrapper2 = new Composite(composite, SWT.NONE);
tcl = new TableColumnLayout();
tableWrapper2.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper2.setLayout(tcl);
tableViewer = new TableViewer(tableWrapper2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLinesVisible(true);
var nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
nameColumn.getColumn().setText(COL_NAME);
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var obj = (ParameterInfo) element;
return obj.getQualifiedName();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
tableViewer.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
setParameter(new ArrayList<>());
return;
}
var parameters = new ArrayList<ParameterInfo>();
for (var obj : sel.toArray()) {
parameters.add((ParameterInfo) obj);
}
setParameter(parameters);
setPageComplete(true);
});
tableViewer.setContentProvider(contentProvider);
tableViewer.setInput(contentProvider);
YamcsPlugin.getMissionDatabase().getParameters().forEach(pmtr -> {
for (var alias : pmtr.getAliasList()) {
var namespace = alias.getNamespace();
if (!namespace.startsWith("/")) {
return;
}
if (!parameterInfos.containsKey(namespace)) {
parameterInfos.put(namespace, new ArrayList<>());
}
parameterInfos.get(namespace).add(pmtr);
var parentns = namespace.substring(0, namespace.lastIndexOf("/"));
while (!parentns.isEmpty()) {
if (!parameterInfos.containsKey(parentns)) {
parameterInfos.put(parentns, new ArrayList<>());
}
parentns = parentns.substring(0, parentns.lastIndexOf("/"));
}
}
});
treeViewer.setInput(parameterInfos.keySet());
tableViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
var n1 = (ParameterInfo) o1;
var n2 = (ParameterInfo) o2;
return n1.getQualifiedName().compareTo(n2.getQualifiedName());
}
});
}
Aggregations