Search in sources :

Example 1 with ExternalFileEditorInput

use of com.collabnet.subversion.merge.editors.ExternalFileEditorInput in project subclipse by subclipse.

the class SVNConflictResolver method getConflictResolution.

private ConflictResolution getConflictResolution(final SVNConflictDescriptor descrip) {
    wait = false;
    dialogWizard = null;
    ConflictResolution conflictResolution = null;
    if (descrip.isTreeConflict() && applyToAllTreeConflictResolution != null) {
        conflictResolution = new ConflictResolution(descrip, applyToAllTreeConflictResolution.getResolution());
    } else if (descrip.getConflictKind() == SVNConflictDescriptor.Kind.property && applyToAllPropertyResolution != null)
        conflictResolution = new ConflictResolution(descrip, applyToAllPropertyResolution.getResolution());
    else if (descrip.isBinary() && applyToAllBinaryResolution != null)
        conflictResolution = new ConflictResolution(descrip, applyToAllBinaryResolution.getResolution());
    else if (descrip.getConflictKind() != SVNConflictDescriptor.Kind.property && !descrip.isBinary() && applyToAllTextResolution != null)
        conflictResolution = new ConflictResolution(descrip, applyToAllTextResolution.getResolution());
    if (conflictResolution == null) {
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                dialogWizard = new DialogWizard(DialogWizard.CONFLICT_HANDLING);
                dialogWizard.setConflictDescriptor(descrip);
                dialogWizard.setResources(new IResource[] { resource });
                MergeWizardDialog dialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogWizard);
                dialog.open();
            }
        });
        while (dialogWizard == null || dialogWizard.getConflictResolution() == null) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
            // we're still waiting...
            }
        }
        conflictResolution = dialogWizard.getConflictResolution();
        if (conflictResolution.isApplyToAll()) {
            if (descrip.isTreeConflict()) {
                applyToAllTreeConflictResolution = conflictResolution;
            } else if (descrip.getConflictKind() == SVNConflictDescriptor.Kind.property)
                applyToAllPropertyResolution = conflictResolution;
            else if (descrip.isBinary())
                applyToAllBinaryResolution = conflictResolution;
            else
                applyToAllTextResolution = conflictResolution;
        }
    }
    try {
        if (conflictResolution.getResolution() == ConflictResolution.FILE_EDITOR) {
            finished = false;
            // resolved = false;
            workingTempFile = null;
            File pathFile = new File(descrip.getPath());
            mergedFile = new File(descrip.getMergedPath());
            try {
                workingTempFile = createTempFile(pathFile);
                copyFile(mergedFile, workingTempFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
            IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(workingTempFile.getAbsolutePath()));
            final IWorkbenchPage page = part.getSite().getPage();
            final IEditorInput editorInput = new ExternalFileEditorInput(fileStore);
            final String editorId = getEditorId(fileStore);
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    try {
                        // final IEditorPart editorPart = IDE.openEditorOnFileStore(page,
                        // fileStore);
                        final IEditorPart editorPart = page.openEditor(editorInput, editorId);
                        if (editorPart == null) {
                            resolution = ISVNConflictResolver.Choice.postpone;
                            // resolved = false;
                            finished = true;
                        // finishEditing();
                        } else {
                            IPartListener2 closeListener = new IPartListener2() {

                                public void partClosed(IWorkbenchPartReference partRef) {
                                    if (partRef.getPart(false) == editorPart) {
                                        finishEditing(descrip);
                                    }
                                }

                                public void partActivated(IWorkbenchPartReference partRef) {
                                }

                                public void partBroughtToTop(IWorkbenchPartReference partRef) {
                                }

                                public void partDeactivated(IWorkbenchPartReference partRef) {
                                }

                                public void partHidden(IWorkbenchPartReference partRef) {
                                }

                                public void partInputChanged(IWorkbenchPartReference partRef) {
                                }

                                public void partOpened(IWorkbenchPartReference partRef) {
                                }

                                public void partVisible(IWorkbenchPartReference partRef) {
                                }
                            };
                            page.addPartListener(closeListener);
                        }
                    } catch (PartInitException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });
            while (!finished) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
            conflictResolution = new ConflictResolution(descrip, resolution);
            if (!conflictResolution.isResolved()) {
                if (descrip.getConflictKind() == SVNConflictDescriptor.Kind.property)
                    applyToAllPropertyResolution = null;
                else if (descrip.isBinary())
                    applyToAllBinaryResolution = null;
                else
                    applyToAllTextResolution = null;
            }
        }
        if (conflictResolution.getResolution() == ConflictResolution.CONFLICT_EDITOR) {
            File pathFile = new File(descrip.getPath());
            File conflictNewFile = new File(descrip.getTheirPath());
            File conflictWorkingFile = new File(descrip.getMyPath());
            if (descrip.getConflictKind() == SVNConflictDescriptor.Kind.property && descrip.getMergedPath() == null) {
                try {
                    final String theirValue = getPropertyValue(conflictNewFile);
                    final String myValue = getPropertyValue(conflictWorkingFile);
                    dialogWizard = null;
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            dialogWizard = new DialogWizard(DialogWizard.PROPERTY_VALUE_SELECTION);
                            dialogWizard.setConflictDescriptor(descrip);
                            dialogWizard.setMyValue(myValue);
                            dialogWizard.setIncomingValue(theirValue);
                            dialogWizard.setResources(new IResource[] { resource });
                            MergeWizardDialog dialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogWizard);
                            dialog.open();
                        }
                    });
                    while (dialogWizard == null || dialogWizard.getValueToUse() == null) {
                    }
                    String valueToUse = dialogWizard.getValueToUse();
                    if (!dialogWizard.isConflictResolved()) {
                        conflictResolution = new ConflictResolution(descrip, ISVNConflictResolver.Choice.postpone);
                        return conflictResolution;
                    } else {
                        mergeTempFile = createTempFile(pathFile);
                        setPropertyValue(mergeTempFile, valueToUse);
                        conflictResolution = new ConflictResolution(descrip, ISVNConflictResolver.Choice.chooseMerged);
                        conflictResolution.setMergedPath(mergeTempFile.getAbsolutePath());
                        return conflictResolution;
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            workingTempFile = null;
            mergeTempFile = null;
            File mergedFile;
            if (descrip.getMergedPath() == null) {
                mergedFile = new File(descrip.getPath());
            } else {
                mergedFile = new File(descrip.getMergedPath());
            }
            try {
                workingTempFile = createTempFile(pathFile);
                copyFile(conflictWorkingFile, workingTempFile);
                mergeTempFile = createTempFile(pathFile);
                copyFile(mergedFile, mergeTempFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
            File conflictOldFile = new File(descrip.getBasePath());
            final MergeEditConflictsAction editConflictsAction = new MergeEditConflictsAction(conflictNewFile, conflictOldFile, workingTempFile, mergedFile, pathFile.getName(), descrip);
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    editConflictsAction.run(null);
                }
            });
            while (editConflictsAction.getMergeConflictsCompareInput() == null || !editConflictsAction.getMergeConflictsCompareInput().isFinished()) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
            if (editConflictsAction.getMergeConflictsCompareInput().isResolved()) {
                // conflictResolution = new ConflictResolution(descrip,
                // ISVNConflictResolver.Result.resolved);
                conflictResolution = new ConflictResolution(descrip, editConflictsAction.getMergeConflictsCompareInput().getResolution());
            } else {
                // conflictResolution = new ConflictResolution(descrip,
                // ISVNConflictResolver.Result.conflicted);
                conflictResolution = new ConflictResolution(descrip, editConflictsAction.getMergeConflictsCompareInput().getResolution());
                if (descrip.getConflictKind() == SVNConflictDescriptor.Kind.property)
                    applyToAllPropertyResolution = null;
                else if (descrip.isBinary())
                    applyToAllBinaryResolution = null;
                else
                    applyToAllTextResolution = null;
                try {
                    copyFile(mergeTempFile, mergedFile);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    } catch (final RuntimeException re) {
        conflictResolution = new ConflictResolution(descrip, ISVNConflictResolver.Choice.postpone);
        wait = true;
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                Activator.handleError(Messages.SVNConflictResolver_handleConflictError, re);
                MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.SVNConflictResolver_handleConflict, Messages.SVNConflictResolver_conflictNotHandled + re.getLocalizedMessage() + Messages.SVNConflictResolver_resolveLater);
                re.printStackTrace();
                wait = false;
            }
        });
    }
    while (wait) {
    }
    return conflictResolution;
}
Also used : Path(org.eclipse.core.runtime.Path) IOException(java.io.IOException) IEditorPart(org.eclipse.ui.IEditorPart) IPartListener2(org.eclipse.ui.IPartListener2) ExternalFileEditorInput(com.collabnet.subversion.merge.editors.ExternalFileEditorInput) DialogWizard(com.collabnet.subversion.merge.wizards.DialogWizard) IFileStore(org.eclipse.core.filesystem.IFileStore) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MergeEditConflictsAction(com.collabnet.subversion.merge.actions.MergeEditConflictsAction) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) File(java.io.File) IResource(org.eclipse.core.resources.IResource) MergeWizardDialog(com.collabnet.subversion.merge.wizards.MergeWizardDialog) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

MergeEditConflictsAction (com.collabnet.subversion.merge.actions.MergeEditConflictsAction)1 ExternalFileEditorInput (com.collabnet.subversion.merge.editors.ExternalFileEditorInput)1 DialogWizard (com.collabnet.subversion.merge.wizards.DialogWizard)1 MergeWizardDialog (com.collabnet.subversion.merge.wizards.MergeWizardDialog)1 File (java.io.File)1 IOException (java.io.IOException)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 IResource (org.eclipse.core.resources.IResource)1 Path (org.eclipse.core.runtime.Path)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IPartListener2 (org.eclipse.ui.IPartListener2)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)1 PartInitException (org.eclipse.ui.PartInitException)1