Search in sources :

Example 1 with MergeFailureReason

use of org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason in project egit by eclipse.

the class RevertFailureDialog method show.

/**
 * Show dialog for failure result
 *
 * @param shell
 * @param commit
 * @param result
 */
public static void show(Shell shell, RevCommit commit, MergeResult result) {
    String message;
    Map<String, MergeFailureReason> reasons = result != null ? result.getFailingPaths() : null;
    if (reasons != null && !reasons.isEmpty())
        message = MessageFormat.format(UIText.RevertFailureDialog_Message, commit.abbreviate(7).name());
    else
        message = MessageFormat.format(UIText.RevertFailureDialog_MessageNoFiles, commit.abbreviate(7).name());
    RevertFailureDialog dialog = new RevertFailureDialog(shell, message, reasons);
    dialog.setShellStyle(dialog.getShellStyle() | SWT.SHEET | SWT.RESIZE);
    dialog.open();
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason)

Example 2 with MergeFailureReason

use of org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason 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)

Example 3 with MergeFailureReason

use of org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason in project egit by eclipse.

the class CherryPickHandler method getErrorList.

private IStatus getErrorList(Map<String, MergeFailureReason> failingPaths) {
    MultiStatus result = new MultiStatus(Activator.getPluginId(), IStatus.ERROR, UIText.CherryPickHandler_CherryPickFailedMessage, null);
    for (Entry<String, MergeFailureReason> entry : failingPaths.entrySet()) {
        String path = entry.getKey();
        String reason = getReason(entry.getValue());
        String errorMessage = NLS.bind(UIText.CherryPickHandler_ErrorMsgTemplate, path, reason);
        result.add(Activator.createErrorStatus(errorMessage));
    }
    return result;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason)

Example 4 with MergeFailureReason

use of org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason in project egit by eclipse.

the class MergeResultDialog method createDialogArea.

@Override
public Control createDialogArea(final Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    composite.setLayout(gridLayout);
    // result
    Label resultLabel = new Label(composite, SWT.NONE);
    resultLabel.setText(UIText.MergeResultDialog_result);
    resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    Text resultText = new Text(composite, SWT.READ_ONLY);
    MergeStatus status = mergeResult.getMergeStatus();
    resultText.setText(status.toString());
    resultText.setSelection(resultText.getCaretPosition());
    resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    if (status == MergeStatus.FAILED) {
        resultText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
        StringBuilder paths = new StringBuilder();
        Label pathsLabel = new Label(composite, SWT.NONE);
        pathsLabel.setText(UIText.MergeResultDialog_failed);
        pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        Text pathsText = new Text(composite, SWT.READ_ONLY);
        pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
        Set<Entry<String, MergeFailureReason>> failedPaths = mergeResult.getFailingPaths().entrySet();
        int n = 0;
        for (Map.Entry<String, MergeFailureReason> e : failedPaths) {
            if (n > 0)
                paths.append(Text.DELIMITER);
            paths.append(e.getValue());
            // $NON-NLS-1$
            paths.append("\t");
            paths.append(e.getKey());
            n++;
            if (n > 10 && failedPaths.size() > 15)
                break;
        }
        if (n < failedPaths.size()) {
            paths.append(Text.DELIMITER);
            paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - failedPaths.size())));
        }
        pathsText.setText(paths.toString());
    }
    if (status == MergeStatus.FAST_FORWARD || status == MergeStatus.FAST_FORWARD_SQUASHED || status == MergeStatus.MERGED) {
        // new head
        Label newHeadLabel = new Label(composite, SWT.NONE);
        newHeadLabel.setText(UIText.MergeResultDialog_newHead);
        newHeadLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        Text newHeadText = new Text(composite, SWT.READ_ONLY);
        ObjectId newHead = mergeResult.getNewHead();
        if (newHead != null)
            newHeadText.setText(getCommitMessage(newHead) + SPACE + abbreviate(mergeResult.getNewHead(), true));
        newHeadText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    }
    // Merge Input
    Label mergeInputLabel = new Label(composite, SWT.NONE);
    mergeInputLabel.setText(UIText.MergeResultDialog_mergeInput);
    GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).span(2, 1).applyTo(mergeInputLabel);
    TableViewer viewer = new TableViewer(composite);
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        // empty
        }

        @Override
        public void inputChanged(Viewer theViewer, Object oldInput, Object newInput) {
        // empty
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return getCommits(mergeResult.getMergedCommits());
        }
    });
    final IStyledLabelProvider styleProvider = new IStyledLabelProvider() {

        private final WorkbenchLabelProvider wrapped = new WorkbenchLabelProvider();

        @Override
        public void removeListener(ILabelProviderListener listener) {
        // Empty
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            return false;
        }

        @Override
        public void dispose() {
            wrapped.dispose();
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
        // Empty
        }

        @Override
        public StyledString getStyledText(Object element) {
            // supported
            if (element instanceof RepositoryCommit)
                return ((RepositoryCommit) element).getStyledText(element);
            return new StyledString(wrapped.getText(element));
        }

        @Override
        public Image getImage(Object element) {
            return wrapped.getImage(element);
        }
    };
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
    applyDialogFont(composite);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(viewer.getControl());
    viewer.setInput(mergeResult);
    new OpenAndLinkWithEditorHelper(viewer) {

        @Override
        protected void linkToEditor(ISelection selection) {
        // Not supported
        }

        @Override
        protected void open(ISelection selection, boolean activate) {
            handleOpen(selection, OpenStrategy.activateOnOpen());
        }

        @Override
        protected void activate(ISelection selection) {
            handleOpen(selection, true);
        }

        private void handleOpen(ISelection selection, boolean activateOnOpen) {
            if (selection instanceof IStructuredSelection)
                for (Object element : ((IStructuredSelection) selection).toArray()) if (element instanceof RepositoryCommit)
                    CommitEditor.openQuiet((RepositoryCommit) element, activateOnOpen);
        }
    };
    return composite;
}
Also used : OpenAndLinkWithEditorHelper(org.eclipse.ui.OpenAndLinkWithEditorHelper) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) ISelection(org.eclipse.jface.viewers.ISelection) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ObjectId(org.eclipse.jgit.lib.ObjectId) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) StyledString(org.eclipse.jface.viewers.StyledString) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) MergeStatus(org.eclipse.jgit.api.MergeResult.MergeStatus) IStyledLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Map(java.util.Map) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 5 with MergeFailureReason

use of org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason in project egit by eclipse.

the class RebaseResultDialog method createFailedOrConflictsParts.

/**
 * Create the items in composite necessary for a rebase result
 *
 * @param composite
 * @param result
 */
public static void createFailedOrConflictsParts(Composite composite, RebaseResult result) {
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    composite.setLayout(gridLayout);
    // result
    Label resultLabel = new Label(composite, SWT.NONE);
    resultLabel.setText(UIText.MergeResultDialog_result);
    resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    Text resultText = new Text(composite, SWT.READ_ONLY);
    resultText.setText(getStatusText(result.getStatus()));
    if (!result.getStatus().isSuccessful())
        resultText.setForeground(composite.getParent().getDisplay().getSystemColor(SWT.COLOR_RED));
    resultText.setSelection(resultText.getCaretPosition());
    resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    if (result.getStatus() == Status.FAILED) {
        StringBuilder paths = new StringBuilder();
        Label pathsLabel = new Label(composite, SWT.NONE);
        pathsLabel.setText(UIText.MergeResultDialog_failed);
        pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        Text pathsText = new Text(composite, SWT.READ_ONLY);
        pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
        Set<Entry<String, MergeFailureReason>> failedPaths = result.getFailingPaths().entrySet();
        int n = 0;
        for (Map.Entry<String, MergeFailureReason> e : failedPaths) {
            if (n > 0)
                paths.append(Text.DELIMITER);
            paths.append(e.getValue());
            // $NON-NLS-1$
            paths.append("\t");
            paths.append(e.getKey());
            n++;
            if (n > 10 && failedPaths.size() > 15)
                break;
        }
        if (n < failedPaths.size()) {
            paths.append(Text.DELIMITER);
            paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - failedPaths.size())));
        }
        pathsText.setText(paths.toString());
    } else if (result.getStatus() == Status.CONFLICTS) {
        StringBuilder paths = new StringBuilder();
        Label pathsLabel = new Label(composite, SWT.NONE);
        pathsLabel.setText(UIText.MergeResultDialog_conflicts);
        pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        Text pathsText = new Text(composite, SWT.READ_ONLY);
        pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
        List<String> conflList = result.getConflicts();
        int n = 0;
        for (String e : conflList) {
            if (n > 0)
                paths.append(Text.DELIMITER);
            paths.append(e);
            n++;
            if (n > 10 && conflList.size() > 15)
                break;
        }
        if (n < conflList.size()) {
            paths.append(Text.DELIMITER);
            paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - conflList.size())));
        }
        pathsText.setText(paths.toString());
    }
}
Also used : Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText) MergeFailureReason(org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) CheckResultEntry(org.eclipse.egit.core.internal.FileChecker.CheckResultEntry) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

MergeFailureReason (org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason)5 StyledString (org.eclipse.jface.viewers.StyledString)3 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 UIText (org.eclipse.egit.ui.internal.UIText)2 DelegatingStyledCellLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)2 IStyledLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 CheckResultEntry (org.eclipse.egit.core.internal.FileChecker.CheckResultEntry)1 WorkbenchStyledLabelProvider (org.eclipse.egit.ui.internal.WorkbenchStyledLabelProvider)1 RepositoryCommit (org.eclipse.egit.ui.internal.commit.RepositoryCommit)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1