Search in sources :

Example 1 with StagingView

use of org.eclipse.egit.ui.internal.staging.StagingView in project egit by eclipse.

the class CommitActionStagingViewTest method testOpenStagingViewNoLinkWithSelection.

@Test
public void testOpenStagingViewNoLinkWithSelection() throws Exception {
    setTestFileContent("I have changed this");
    SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
    util.getProjectItems(projectExplorerTree, PROJ1)[0].select();
    String menuString = util.getPluginLocalizedValue("CommitAction_label");
    ContextMenuHelper.clickContextMenu(projectExplorerTree, "Team", menuString);
    TestUtil.joinJobs(ADD_TO_INDEX);
    TestUtil.waitUntilViewWithGivenIdShows(StagingView.VIEW_ID);
    final Repository[] repo = { null };
    PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            StagingView view;
            try {
                view = (StagingView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(StagingView.VIEW_ID);
                repo[0] = view.getCurrentRepository();
            } catch (PartInitException e) {
            // Ignore, repo[0] remains null
            }
        }
    });
    Repository repository = lookupRepository(repositoryFile);
    assertNotNull("No repository found", repository);
    assertEquals("Repository mismatch", repository, repo[0]);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) StagingView(org.eclipse.egit.ui.internal.staging.StagingView) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 2 with StagingView

use of org.eclipse.egit.ui.internal.staging.StagingView in project egit by eclipse.

the class CommitViewerComparator method openStagingViewLinkClicked.

private void openStagingViewLinkClicked() {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
    try {
        StagingView view = (StagingView) workbenchPage.showView(StagingView.VIEW_ID);
        view.reload(repository);
        String message = commitMessageComponent.getCommitMessage();
        if (message != null && message.length() > 0)
            view.setCommitMessage(message);
        setReturnCode(CANCEL);
        close();
    } catch (PartInitException e) {
        Activator.handleError(UIText.CommitDialog_OpenStagingViewError, e, true);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StagingView(org.eclipse.egit.ui.internal.staging.StagingView) StyledString(org.eclipse.jface.viewers.StyledString) PartInitException(org.eclipse.ui.PartInitException)

Example 3 with StagingView

use of org.eclipse.egit.ui.internal.staging.StagingView in project egit by eclipse.

the class AbstractRebaseCommandHandler method startRebaseJob.

private void startRebaseJob(final RebaseOperation rebase, final Repository repository, final RebaseCommand.Operation operation) {
    JobUtil.scheduleUserWorkspaceJob(rebase, jobname, JobFamilies.REBASE, new JobChangeAdapter() {

        @Override
        public void aboutToRun(IJobChangeEvent event) {
            // that repository state is safe
            if (operation == Operation.BEGIN && !repository.getRepositoryState().equals(RepositoryState.SAFE)) {
                throw new IllegalStateException(// $NON-NLS-1$
                "Can't start rebase if repository state isn't SAFE");
            }
            super.aboutToRun(event);
        }

        @Override
        public void done(IJobChangeEvent cevent) {
            finishRebaseInteractive();
            IStatus result = cevent.getJob().getResult();
            if (result == null) {
                return;
            }
            // abort and show exception
            if (operation == Operation.BEGIN && result.getSeverity() == IStatus.ERROR) {
                handleBeginError(repository, result);
            } else if (result.getSeverity() == IStatus.CANCEL)
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        // don't use getShell(event) here since
                        // the active shell has changed since the
                        // execution has been triggered.
                        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
                        MessageDialog.openInformation(shell, UIText.AbstractRebaseCommand_DialogTitle, dialogMessage);
                    }
                });
            else if (result.isOK()) {
                if (rebase.getResult().getStatus() == Status.UNCOMMITTED_CHANGES) {
                    handleUncommittedChanges(repository, rebase.getResult().getUncommittedChanges());
                } else {
                    RebaseResultDialog.show(rebase.getResult(), repository);
                    if (operation == Operation.ABORT)
                        setAmending(false, false);
                    if (rebase.getResult().getStatus() == Status.EDIT)
                        setAmending(true, true);
                }
            }
        }

        private void setAmending(final boolean amending, final boolean openStagingView) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        IViewPart view;
                        if (openStagingView)
                            view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(StagingView.VIEW_ID);
                        else
                            view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(StagingView.VIEW_ID);
                        if (view instanceof StagingView) {
                            final StagingView sv = (StagingView) view;
                            sv.reload(repository);
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    sv.setAmending(amending);
                                }
                            });
                        }
                    } catch (PartInitException e) {
                        Activator.logError(e.getMessage(), e);
                    }
                }
            });
        }

        private void finishRebaseInteractive() {
            RebaseInteractivePlan plan = RebaseInteractivePlan.getPlan(repository);
            if (plan != null && !plan.isRebasingInteractive())
                plan.dispose();
        }
    });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Shell(org.eclipse.swt.widgets.Shell) IViewPart(org.eclipse.ui.IViewPart) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) RebaseInteractivePlan(org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) StagingView(org.eclipse.egit.ui.internal.staging.StagingView) PartInitException(org.eclipse.ui.PartInitException)

Example 4 with StagingView

use of org.eclipse.egit.ui.internal.staging.StagingView in project egit by eclipse.

the class EditHandler method openStagingAndRebaseInteractiveViews.

private void openStagingAndRebaseInteractiveViews(final Repository repository) {
    Job job = new UIJob(UIText.EditHandler_OpenStagingAndRebaseInteractiveViews) {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            try {
                IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                final StagingView stagingView = (StagingView) workbenchPage.showView(StagingView.VIEW_ID);
                stagingView.reload(repository);
                stagingView.setAmending(true);
                RebaseInteractiveView rebaseView = (RebaseInteractiveView) workbenchPage.showView(RebaseInteractiveView.VIEW_ID);
                rebaseView.setInput(repository);
            } catch (PartInitException e) {
                Activator.logError(e.getMessage(), e);
            }
            return Status.OK_STATUS;
        }
    };
    job.setRule(RuleUtil.getRule(repository));
    job.setUser(true);
    job.schedule();
}
Also used : RebaseInteractiveView(org.eclipse.egit.ui.internal.rebase.RebaseInteractiveView) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StagingView(org.eclipse.egit.ui.internal.staging.StagingView) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob)

Example 5 with StagingView

use of org.eclipse.egit.ui.internal.staging.StagingView in project egit by eclipse.

the class CommitActionHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(true, event);
    if (repository == null) {
        return null;
    }
    IPreferenceStore uiPreferences = Activator.getDefault().getPreferenceStore();
    boolean useStagingView = uiPreferences.getBoolean(UIPreferences.ALWAYS_USE_STAGING_VIEW);
    if (useStagingView) {
        if (uiPreferences.getBoolean(UIPreferences.AUTO_STAGE_ON_COMMIT)) {
            boolean includeUntracked = uiPreferences.getBoolean(UIPreferences.COMMIT_DIALOG_INCLUDE_UNTRACKED);
            autoStage(repository, includeUntracked, getResourcesInScope(event));
        }
        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                try {
                    StagingView view = (StagingView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(StagingView.VIEW_ID);
                    if (view.getCurrentRepository() != repository) {
                        view.reload(repository);
                    }
                    view.setFocus();
                } catch (PartInitException e) {
                    Activator.logError(e.getMessage(), e);
                }
            }
        });
    } else {
        final Shell shell = getShell(event);
        IResource[] resourcesInScope = getResourcesInScope(event);
        if (resourcesInScope != null) {
            CommitUI commitUi = new CommitUI(shell, repository, resourcesInScope, false);
            commitUi.commit();
        }
    }
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) StagingView(org.eclipse.egit.ui.internal.staging.StagingView) PartInitException(org.eclipse.ui.PartInitException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IResource(org.eclipse.core.resources.IResource) CommitUI(org.eclipse.egit.ui.internal.commit.CommitUI)

Aggregations

StagingView (org.eclipse.egit.ui.internal.staging.StagingView)5 PartInitException (org.eclipse.ui.PartInitException)5 Repository (org.eclipse.jgit.lib.Repository)2 Shell (org.eclipse.swt.widgets.Shell)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 IResource (org.eclipse.core.resources.IResource)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)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 RebaseInteractivePlan (org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan)1 CommitUI (org.eclipse.egit.ui.internal.commit.CommitUI)1 RebaseInteractiveView (org.eclipse.egit.ui.internal.rebase.RebaseInteractiveView)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 StyledString (org.eclipse.jface.viewers.StyledString)1 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)1 IViewPart (org.eclipse.ui.IViewPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 UIJob (org.eclipse.ui.progress.UIJob)1