Search in sources :

Example 71 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project egit by eclipse.

the class UIUtils method notifySelectionChangedWithCurrentSelection.

/**
 * Locates the current part and selection and fires
 * {@link ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)}
 * on the passed listener.
 *
 * @param serviceLocator
 * @param selectionListener
 */
public static void notifySelectionChangedWithCurrentSelection(ISelectionListener selectionListener, IServiceLocator serviceLocator) {
    IHandlerService handlerService = CommonUtils.getService(serviceLocator, IHandlerService.class);
    IEvaluationContext state = handlerService.getCurrentState();
    // This seems to be the most reliable way to get the active part, it
    // also returns a part when it is called while creating a view that is
    // being shown.Getting the active part through the active workbench
    // window returned null in that case.
    Object partObject = state.getVariable(ISources.ACTIVE_PART_NAME);
    Object selectionObject = state.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
    if (partObject instanceof IWorkbenchPart && selectionObject instanceof ISelection) {
        IWorkbenchPart part = (IWorkbenchPart) partObject;
        ISelection selection = (ISelection) selectionObject;
        if (!selection.isEmpty())
            selectionListener.selectionChanged(part, selection);
    }
}
Also used : IHandlerService(org.eclipse.ui.handlers.IHandlerService) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) ISelection(org.eclipse.jface.viewers.ISelection)

Example 72 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project egit by eclipse.

the class GitHistoryPage method getPartSite.

private IWorkbenchPartSite getPartSite() {
    final IWorkbenchPart part = getHistoryPageSite().getPart();
    IWorkbenchPartSite site = null;
    if (part != null)
        site = part.getSite();
    return site;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart)

Example 73 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project egit by eclipse.

the class GitModelSynchronize method fireSynchronizeAction.

private static void fireSynchronizeAction(final IWorkbenchWindow window, final GitSynchronizeDataSet gsdSet, final ResourceMapping[] mappings) {
    final GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber(gsdSet);
    Job syncJob = new WorkspaceJob(UIText.GitModelSynchronize_fetchGitDataJobName) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            subscriber.init(monitor);
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.SYNCHRONIZE_READ_DATA.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    syncJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            RemoteResourceMappingContext remoteContext = new GitSubscriberResourceMappingContext(subscriber, gsdSet);
            SubscriberScopeManager manager = new SubscriberScopeManager(subscriber.getName(), mappings, subscriber, remoteContext, true);
            GitSubscriberMergeContext context = new GitSubscriberMergeContext(subscriber, manager, gsdSet);
            final GitModelSynchronizeParticipant participant = new GitModelSynchronizeParticipant(context);
            TeamUI.getSynchronizeManager().addSynchronizeParticipants(new ISynchronizeParticipant[] { participant });
            IWorkbenchPart activePart = null;
            if (window != null)
                activePart = window.getActivePage().getActivePart();
            participant.run(activePart);
        }
    });
    syncJob.setUser(true);
    syncJob.schedule();
}
Also used : GitSubscriberResourceMappingContext(org.eclipse.egit.core.synchronize.GitSubscriberResourceMappingContext) SubscriberScopeManager(org.eclipse.team.core.subscribers.SubscriberScopeManager) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) GitResourceVariantTreeSubscriber(org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriber) RemoteResourceMappingContext(org.eclipse.core.resources.mapping.RemoteResourceMappingContext) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ISynchronizeParticipant(org.eclipse.team.ui.synchronize.ISynchronizeParticipant) GitSubscriberMergeContext(org.eclipse.egit.core.synchronize.GitSubscriberMergeContext)

Example 74 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart in project egit by eclipse.

the class GitScopeUtilTest method setup.

@Before
public void setup() throws Exception {
    SWTBotView view = TestUtil.showExplorerView();
    part = view.getViewReference().getPart(false);
    repositoryFile = createProjectAndCommitToRepository();
    GitScopeOperationFactory.setFactory(new GitScopeOperationFactory() {

        @Override
        public GitScopeOperation createGitScopeOperation(IWorkbenchPart workbenchPart, SubscriberScopeManager manager) {
            return new GitScopeOperation(workbenchPart, manager) {

                @Override
                protected boolean promptForInputChange(String requestPreviewMessage, IProgressMonitor monitor) {
                    // we will avoid the confirmation prompt in the tests
                    return false;
                }
            };
        }
    });
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GitScopeOperationFactory(org.eclipse.egit.ui.internal.operations.GitScopeOperationFactory) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) SubscriberScopeManager(org.eclipse.team.core.subscribers.SubscriberScopeManager) SWTBotView(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView) GitScopeOperation(org.eclipse.egit.ui.internal.operations.GitScopeOperation) Before(org.junit.Before)

Example 75 with IWorkbenchPart

use of org.eclipse.ui.IWorkbenchPart 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)

Aggregations

IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)289 ISelection (org.eclipse.jface.viewers.ISelection)113 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)112 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)72 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)69 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)59 IEditorPart (org.eclipse.ui.IEditorPart)57 IFile (org.eclipse.core.resources.IFile)52 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)44 IResource (org.eclipse.core.resources.IResource)42 PartInitException (org.eclipse.ui.PartInitException)41 ArrayList (java.util.ArrayList)36 ISetSelectionTarget (org.eclipse.ui.part.ISetSelectionTarget)35 FileEditorInput (org.eclipse.ui.part.FileEditorInput)33 HashMap (java.util.HashMap)32 EObject (org.eclipse.emf.ecore.EObject)31 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)31 URI (org.eclipse.emf.common.util.URI)30 MissingResourceException (java.util.MissingResourceException)29 Resource (org.eclipse.emf.ecore.resource.Resource)29