use of org.eclipse.jface.viewers.ViewerComparator in project jbosstools-openshift by jbosstools.
the class ProjectTreeSorterTest method testProjectsWithLabelProvider.
@Test
public void testProjectsWithLabelProvider() {
final ViewerComparator comparator = new ProjectViewerComparator(new OpenShiftExplorerLabelProvider());
IProject p1 = mockProject("default", "z");
IProject p2 = mockProject("openshift", "y");
IProject p3 = mockProject("a", "c");
IProject p4 = mockProject("b2", null);
IProject p5 = mockProject("d", "b");
IProject[] projects = new IProject[] { p3, p5, p2, p1, p4 };
Arrays.sort(projects, new Comparator<IProject>() {
@Override
public int compare(IProject o1, IProject o2) {
return comparator.compare(null, o1, o2);
}
});
assertEquals(p1, projects[0]);
assertEquals(p2, projects[1]);
assertEquals(p5, projects[2]);
assertEquals(p4, projects[3]);
assertEquals(p3, projects[4]);
}
use of org.eclipse.jface.viewers.ViewerComparator in project jbosstools-openshift by jbosstools.
the class EnvironmentVariablePage method createEnvVarTable.
protected TableViewer createEnvVarTable(Composite tableContainer) {
Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLinesVisible(true);
table.setHeaderVisible(true);
this.envViewer = new TableViewerBuilder(table, tableContainer).column(new IColumnLabelProvider<IKeyValueItem>() {
@Override
public String getValue(IKeyValueItem label) {
boolean isDeleted = model.isEnvironmentVariableDeleted(label);
return !isDeleted ? label.getKey() : "[deleted] " + label.getKey();
}
@Override
public boolean isModified(IKeyValueItem e) {
return ((EnvironmentVariable) e).isNew() || model.isEnvironmentVariableDeleted(e);
}
}).name("Name").align(SWT.LEFT).weight(2).minWidth(75).buildColumn().column(new IColumnLabelProvider<IKeyValueItem>() {
@Override
public String getValue(IKeyValueItem label) {
if (model.isEnvironmentVariableDeleted(label)) {
return "";
}
return label.getValue();
}
@Override
public boolean isModified(IKeyValueItem e) {
return model.isEnvironmentVariableModified((EnvironmentVariable) e);
}
}).name("Value").align(SWT.LEFT).weight(2).minWidth(100).buildColumn().buildViewer();
envViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
IKeyValueItem first = (IKeyValueItem) e1;
IKeyValueItem other = (IKeyValueItem) e2;
return first.getKey().compareTo(other.getKey());
}
});
envViewer.addDoubleClickListener(new EditHandler());
return envViewer;
}
use of org.eclipse.jface.viewers.ViewerComparator in project polymap4-core by Polymap4.
the class PredefinedColorMapEditor method createContents.
@Override
public Composite createContents(Composite parent) {
Composite contents = super.createContents(parent);
ComboViewer combo = new ComboViewer(contents, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
combo.getCombo().setVisibleItemCount(13);
combo.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object elm) {
return ((PredefinedColorMap) elm).name;
}
});
combo.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object elm1, Object elm2) {
PredefinedColorMap cm1 = (PredefinedColorMap) elm1;
PredefinedColorMap cm2 = (PredefinedColorMap) elm2;
return cm1.name.compareToIgnoreCase(cm2.name);
}
});
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setInput(input = PredefinedColorMap.all.get());
findSelected().ifPresent(selected -> combo.setSelection(new StructuredSelection(selected)));
combo.addSelectionChangedListener(ev -> {
ConstantRasterColorMap newColorMap = prop.createValue(ConstantRasterColorMap.defaults());
newColorMap.entries.clear();
PredefinedColorMap colorMap = SelectionAdapter.on(ev.getSelection()).first(PredefinedColorMap.class).get();
UIJob.schedule("Color map", monitor -> {
// Thread.sleep( 3000 );
colorMap.fillModel(newColorMap, site().gridCoverage.get(), monitor);
});
});
return contents;
}
use of org.eclipse.jface.viewers.ViewerComparator in project tdq-studio-se by Talend.
the class ExportWizardPage method createRepositoryTree.
/**
* DOC bZhou Comment method "createRepositoryTree".
*
* @param top
*/
protected void createRepositoryTree(Composite top) {
Composite treeComposite = new Composite(top, SWT.NONE);
treeComposite.setLayout(new GridLayout(2, false));
treeComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
repositoryTree = new ContainerCheckedTreeViewer(treeComposite);
repositoryTree.setContentProvider(new FileTreeContentProvider());
repositoryTree.setLabelProvider(new FileTreeLabelProvider());
repositoryTree.setInput(writer.computeInput(specifiedPath));
repositoryTree.expandAll();
repositoryTree.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
// ADD msjian TDQ-14573: automatically checked the initial selected items.
if (intCheckedElements != null) {
List<ItemRecord> selectedItemRecords = new ArrayList<ItemRecord>();
for (Object intCheckedElement : intCheckedElements) {
getFileFromNode(selectedItemRecords, (IRepositoryNode) intCheckedElement);
}
repositoryTree.setCheckedElements(selectedItemRecords.toArray());
}
// show the same order with repository tree
repositoryTree.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer iviewer, Object o1, Object o2) {
DQRepositoryNode recursiveFind = RepositoryNodeHelper.recursiveFind(((ItemRecord) o1).getElement());
DQRepositoryNode recursiveFind2 = RepositoryNodeHelper.recursiveFind(((ItemRecord) o2).getElement());
return new RepositoryNodeComparator().compare(recursiveFind, recursiveFind2);
}
});
// TDQ-14573~
createUtilityButtons(treeComposite);
}
use of org.eclipse.jface.viewers.ViewerComparator in project archi-modelrepository-plugin by archi-contribs.
the class ConflictsDialog 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));
Table table = new Table(tableComp, SWT.MULTI | SWT.FULL_SELECTION | SWT.CHECK);
table.setHeaderVisible(true);
fTableViewer = new CheckboxTableViewer(table);
fTableViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
fTableViewer.getTable().setLinesVisible(true);
fTableViewer.setComparator(new ViewerComparator());
// Columns
TableViewerColumn column1 = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
column1.getColumn().setText(Messages.ConflictsDialog_5);
tableLayout.setColumnData(column1.getColumn(), new ColumnWeightData(100, true));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
MergeResult result = fHandler.getMergeResult();
return result.getConflicts().keySet().toArray();
}
});
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
String path = (String) ((StructuredSelection) event.getSelection()).getFirstElement();
try {
fFileViewerOurs.setText(fHandler.getArchiRepository().getFileContents(path, IGraficoConstants.HEAD));
fFileViewerTheirs.setText(fHandler.getArchiRepository().getFileContents(path, IGraficoConstants.ORIGIN_MASTER));
fFileViewerDiff.setText(fHandler.getArchiRepository().getWorkingTreeFileContents(path));
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelProvider());
// Start the table
// anything will do //$NON-NLS-1$
fTableViewer.setInput("");
}
Aggregations