Search in sources :

Example 81 with ViewerComparator

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]);
}
Also used : ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 82 with ViewerComparator

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;
}
Also used : IColumnLabelProvider(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder.IColumnLabelProvider) Table(org.eclipse.swt.widgets.Table) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IKeyValueItem(org.jboss.tools.openshift.internal.common.ui.wizard.IKeyValueItem) TableViewerBuilder(org.jboss.tools.openshift.internal.common.ui.utils.TableViewerBuilder)

Example 83 with ViewerComparator

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) ConstantRasterColorMap(org.polymap.core.style.model.raster.ConstantRasterColorMap)

Example 84 with ViewerComparator

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);
}
Also used : RepositoryNodeComparator(org.talend.dq.helper.RepositoryNodeComparator) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ArrayList(java.util.ArrayList) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) DQRepositoryNode(org.talend.dq.nodes.DQRepositoryNode) GridData(org.eclipse.swt.layout.GridData) ItemRecord(org.talend.dataprofiler.core.ui.imex.model.ItemRecord) ContainerCheckedTreeViewer(org.eclipse.ui.dialogs.ContainerCheckedTreeViewer)

Example 85 with ViewerComparator

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("");
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) MergeResult(org.eclipse.jgit.api.MergeResult) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IOException(java.io.IOException) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

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