Search in sources :

Example 1 with WorkbenchStyledLabelProvider

use of org.eclipse.egit.ui.internal.WorkbenchStyledLabelProvider in project egit by eclipse.

the class RevertFailureDialog method createCustomArea.

@Override
protected Control createCustomArea(Composite parent) {
    if (reasons == null || reasons.isEmpty())
        return null;
    Composite fileArea = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).applyTo(fileArea);
    GridLayoutFactory.fillDefaults().applyTo(fileArea);
    TreeViewer viewer = new TreeViewer(fileArea);
    viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl());
    viewer.setContentProvider(new WorkbenchContentProvider() {

        @Override
        public Object[] getElements(Object element) {
            return ((Collection) element).toArray();
        }
    });
    final IStyledLabelProvider styleProvider = new WorkbenchStyledLabelProvider() {

        @Override
        public StyledString getStyledText(Object element) {
            // supported
            if (element instanceof RevertFailure)
                return ((RevertFailure) element).getStyledText(element);
            if (element instanceof Path)
                return ((Path) element).getStyledText(element);
            return super.getStyledText(element);
        }
    };
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
    viewer.setComparator(new ViewerComparator());
    Map<MergeFailureReason, RevertFailure> failures = new HashMap<>();
    for (Entry<String, MergeFailureReason> reason : reasons.entrySet()) {
        RevertFailure failure = failures.get(reason.getValue());
        if (failure == null) {
            failure = new RevertFailure(reason.getValue());
            failures.put(reason.getValue(), failure);
        }
        failure.add(reason.getKey());
    }
    viewer.setInput(failures.values());
    return fileArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) HashMap(java.util.HashMap) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) StyledString(org.eclipse.jface.viewers.StyledString) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason) WorkbenchStyledLabelProvider(org.eclipse.egit.ui.internal.WorkbenchStyledLabelProvider) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)

Aggregations

HashMap (java.util.HashMap)1 WorkbenchStyledLabelProvider (org.eclipse.egit.ui.internal.WorkbenchStyledLabelProvider)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 DelegatingStyledCellLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)1 IStyledLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider)1 StyledString (org.eclipse.jface.viewers.StyledString)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 MergeFailureReason (org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason)1 Composite (org.eclipse.swt.widgets.Composite)1 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)1