Search in sources :

Example 1 with CommitEditor

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

the class StashDropHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final RevCommit commit = getSelectedItem(RevCommit.class, event);
    if (commit == null)
        return null;
    Repository repo = getSelectedItem(Repository.class, event);
    if (repo == null)
        return null;
    final Shell parent = getPart(event).getSite().getShell();
    final int stashIndex = getStashIndex(repo, commit.getId());
    if (!confirmStashDrop(parent, stashIndex))
        return null;
    final StashDropOperation op = new StashDropOperation(repo, stashIndex);
    Job job = new WorkspaceJob(MessageFormat.format(UIText.StashDropCommand_jobTitle, commit.name())) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
            } catch (CoreException e) {
                Activator.logError(MessageFormat.format(UIText.StashDropCommand_dropFailed, // $NON-NLS-1$
                "stash@{" + stashIndex + "}"), // $NON-NLS-1$
                e);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.STASH.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    final IWorkbenchPart part = getPart(event);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            if (event.getResult().isOK()) {
                if (part instanceof CommitEditor) {
                    ((CommitEditor) part).close(false);
                }
            }
        }
    });
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.schedule();
    return null;
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) CommitEditor(org.eclipse.egit.ui.internal.commit.CommitEditor) Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) StashDropOperation(org.eclipse.egit.core.op.StashDropOperation) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with CommitEditor

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

the class CommitEditorTest method openAllEditorPagesOnValidCommit.

@Test
public void openAllEditorPagesOnValidCommit() throws Exception {
    final AtomicReference<IEditorPart> editorRef = new AtomicReference<>();
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            RepositoryCommit repoCommit = new RepositoryCommit(repository, commit);
            editorRef.set(CommitEditor.openQuiet(repoCommit));
        }
    });
    assertNotNull(editorRef.get());
    IEditorPart editor = editorRef.get();
    assertTrue(editor instanceof CommitEditor);
    RepositoryCommit adaptedCommit = Utils.getAdapter(editor, RepositoryCommit.class);
    assertNotNull(adaptedCommit);
    assertEquals(commit, adaptedCommit.getRevCommit());
    assertEquals(repository.getDirectory(), adaptedCommit.getRepository().getDirectory());
    IEditorInput input = editor.getEditorInput();
    assertNotNull(input);
    SWTBotMultiPageEditor botEditor = bot.multipageEditorByTitle(input.getName());
    assertNotNull(botEditor);
    assertTrue(botEditor.getPageCount() > 1);
    for (String name : botEditor.getPagesTitles()) botEditor.activatePage(name);
    botEditor.close();
}
Also used : SWTBotMultiPageEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotMultiPageEditor) AtomicReference(java.util.concurrent.atomic.AtomicReference) IEditorPart(org.eclipse.ui.IEditorPart) CommitEditor(org.eclipse.egit.ui.internal.commit.CommitEditor) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) IEditorInput(org.eclipse.ui.IEditorInput) Test(org.junit.Test)

Aggregations

CommitEditor (org.eclipse.egit.ui.internal.commit.CommitEditor)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 Job (org.eclipse.core.runtime.jobs.Job)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1 StashDropOperation (org.eclipse.egit.core.op.StashDropOperation)1 RepositoryCommit (org.eclipse.egit.ui.internal.commit.RepositoryCommit)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 Shell (org.eclipse.swt.widgets.Shell)1 SWTBotMultiPageEditor (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotMultiPageEditor)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 Test (org.junit.Test)1