Search in sources :

Example 1 with CommitEditorInput

use of org.eclipse.egit.ui.internal.commit.CommitEditorInput in project egit by eclipse.

the class CommitEditorInputFactoryTest method shouldPersistAndRestoreCommit.

@Test
public void shouldPersistAndRestoreCommit() {
    RepositoryCommit repositoryCommit = new RepositoryCommit(repository, commit);
    new CommitEditorInput(repositoryCommit).saveState(memento);
    IAdaptable restored = new CommitEditorInputFactory().createElement(memento);
    assertNotNull(restored);
    assertThat(restored, instanceOf(CommitEditorInput.class));
    assertThat(repositoryCommit, isSameCommit(((CommitEditorInput) restored).getCommit()));
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) CommitEditorInputFactory(org.eclipse.egit.ui.internal.commit.CommitEditorInputFactory) CommitEditorInput(org.eclipse.egit.ui.internal.commit.CommitEditorInput) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) Test(org.junit.Test)

Example 2 with CommitEditorInput

use of org.eclipse.egit.ui.internal.commit.CommitEditorInput in project egit by eclipse.

the class CommitEditorInputFactoryTest method shouldPersistAndRestoreStashCommit.

@Test
public void shouldPersistAndRestoreStashCommit() {
    RepositoryCommit stashCommit = new RepositoryCommit(repository, commit);
    stashCommit.setStash(true);
    new CommitEditorInput(stashCommit).saveState(memento);
    IAdaptable restored = new CommitEditorInputFactory().createElement(memento);
    assertNotNull(restored);
    assertThat(restored, instanceOf(CommitEditorInput.class));
    assertThat(stashCommit, isSameCommit(((CommitEditorInput) restored).getCommit()));
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) CommitEditorInputFactory(org.eclipse.egit.ui.internal.commit.CommitEditorInputFactory) CommitEditorInput(org.eclipse.egit.ui.internal.commit.CommitEditorInput) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) Test(org.junit.Test)

Example 3 with CommitEditorInput

use of org.eclipse.egit.ui.internal.commit.CommitEditorInput in project egit by eclipse.

the class CommitEditorInputTest method testInput.

@Test
public void testInput() {
    RepositoryCommit repoCommit = new RepositoryCommit(repository, commit);
    CommitEditorInput input = new CommitEditorInput(repoCommit);
    assertNotNull(input.getImageDescriptor());
    assertNotNull(input.getToolTipText());
    assertNotNull(input.getName());
    assertEquals(repoCommit, input.getCommit());
    assertNotNull(input.getPersistable());
}
Also used : CommitEditorInput(org.eclipse.egit.ui.internal.commit.CommitEditorInput) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) Test(org.junit.Test)

Example 4 with CommitEditorInput

use of org.eclipse.egit.ui.internal.commit.CommitEditorInput in project egit by eclipse.

the class StashDropCommand method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final List<StashedCommitNode> nodes = getSelectedNodes(event);
    if (nodes.isEmpty())
        return null;
    final Repository repo = nodes.get(0).getRepository();
    if (repo == null)
        return null;
    // Confirm deletion of selected nodes
    final AtomicBoolean confirmed = new AtomicBoolean();
    final Shell shell = getActiveShell(event);
    shell.getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            String message;
            if (nodes.size() > 1)
                message = MessageFormat.format(UIText.StashDropCommand_confirmMultiple, Integer.toString(nodes.size()));
            else
                message = MessageFormat.format(UIText.StashDropCommand_confirmSingle, Integer.toString(nodes.get(0).getIndex()));
            confirmed.set(MessageDialog.openConfirm(shell, UIText.StashDropCommand_confirmTitle, message));
        }
    });
    if (!confirmed.get())
        return null;
    Job job = new Job(UIText.StashDropCommand_jobTitle) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(UIText.StashDropCommand_jobTitle, nodes.size());
            // Sort by highest to lowest stash commit index.
            // This avoids shifting problems that cause the indices of the
            // selected nodes not match the indices in the repository
            Collections.sort(nodes, new Comparator<StashedCommitNode>() {

                @Override
                public int compare(StashedCommitNode n1, StashedCommitNode n2) {
                    return n1.getIndex() < n2.getIndex() ? 1 : -1;
                }
            });
            for (StashedCommitNode node : nodes) {
                final int index = node.getIndex();
                if (index < 0)
                    return null;
                final RevCommit commit = node.getObject();
                if (commit == null)
                    return null;
                final String stashName = node.getObject().getName();
                final StashDropOperation op = new StashDropOperation(repo, node.getIndex());
                monitor.subTask(stashName);
                try {
                    op.execute(monitor);
                } catch (CoreException e) {
                    Activator.logError(MessageFormat.format(UIText.StashDropCommand_dropFailed, node.getObject().name()), e);
                }
                tryToCloseEditor(node);
                monitor.worked(1);
            }
            monitor.done();
            return Status.OK_STATUS;
        }

        private void tryToCloseEditor(final StashedCommitNode node) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    IEditorReference[] editorReferences = activePage.getEditorReferences();
                    for (IEditorReference editorReference : editorReferences) {
                        IEditorInput editorInput = null;
                        try {
                            editorInput = editorReference.getEditorInput();
                        } catch (PartInitException e) {
                            Activator.handleError(e.getMessage(), e, true);
                        }
                        if (editorInput instanceof CommitEditorInput) {
                            CommitEditorInput comEditorInput = (CommitEditorInput) editorInput;
                            if (comEditorInput.getCommit().getRevCommit().equals(node.getObject())) {
                                activePage.closeEditor(editorReference.getEditor(false), false);
                            }
                        }
                    }
                }
            });
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.STASH.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.setRule((new StashDropOperation(repo, nodes.get(0).getIndex())).getSchedulingRule());
    job.schedule();
    return null;
}
Also used : CommitEditorInput(org.eclipse.egit.ui.internal.commit.CommitEditorInput) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEditorReference(org.eclipse.ui.IEditorReference) CoreException(org.eclipse.core.runtime.CoreException) StashDropOperation(org.eclipse.egit.core.op.StashDropOperation) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StashedCommitNode(org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) IEditorInput(org.eclipse.ui.IEditorInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with CommitEditorInput

use of org.eclipse.egit.ui.internal.commit.CommitEditorInput in project egit by eclipse.

the class CommitEditorInputTest method testAdapters.

@Test
public void testAdapters() {
    RepositoryCommit repoCommit = new RepositoryCommit(repository, commit);
    CommitEditorInput input = new CommitEditorInput(repoCommit);
    assertEquals(repoCommit, input.getAdapter(RepositoryCommit.class));
    assertEquals(repository, input.getAdapter(Repository.class));
    assertEquals(commit, input.getAdapter(RevCommit.class));
}
Also used : Repository(org.eclipse.jgit.lib.Repository) CommitEditorInput(org.eclipse.egit.ui.internal.commit.CommitEditorInput) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

CommitEditorInput (org.eclipse.egit.ui.internal.commit.CommitEditorInput)5 RepositoryCommit (org.eclipse.egit.ui.internal.commit.RepositoryCommit)4 Test (org.junit.Test)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 CommitEditorInputFactory (org.eclipse.egit.ui.internal.commit.CommitEditorInputFactory)2 Repository (org.eclipse.jgit.lib.Repository)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1 StashDropOperation (org.eclipse.egit.core.op.StashDropOperation)1 StashedCommitNode (org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorReference (org.eclipse.ui.IEditorReference)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 PartInitException (org.eclipse.ui.PartInitException)1