Search in sources :

Example 76 with IWorkbenchPart

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

the class DynamicHistoryMenu method getRepository.

private GitFlowRepository getRepository() {
    IWorkbenchPart activePart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
    Repository repository = Utils.getAdapter(activePart, Repository.class);
    if (repository == null) {
        return null;
    }
    return new GitFlowRepository(repository);
}
Also used : GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) Repository(org.eclipse.jgit.lib.Repository) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository)

Example 77 with IWorkbenchPart

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

the class DiscardChangesActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // capture selection from active part as long as we have context
    mySelection = getSelection(event);
    try {
        IWorkbenchPart part = getPart(event);
        String question = UIText.DiscardChangesAction_confirmActionMessage;
        ILaunchConfiguration launch = LaunchFinder.getRunningLaunchConfiguration(Arrays.asList(getRepositories()), null);
        if (launch != null) {
            question = MessageFormat.format(question, "\n\n" + // $NON-NLS-1$
            MessageFormat.format(UIText.LaunchFinder_RunningLaunchMessage, launch.getName()));
        } else {
            // $NON-NLS-1$
            question = MessageFormat.format(question, "");
        }
        boolean performAction = openConfirmationDialog(event, question);
        if (!performAction) {
            return null;
        }
        final DiscardChangesOperation operation = createOperation(part, event);
        if (operation == null) {
            return null;
        }
        String jobname = UIText.DiscardChangesAction_discardChanges;
        Job job = new WorkspaceJob(jobname) {

            @Override
            public IStatus runInWorkspace(IProgressMonitor monitor) {
                try {
                    operation.execute(monitor);
                } catch (CoreException e) {
                    return Activator.createErrorStatus(e.getStatus().getMessage(), e);
                }
                return Status.OK_STATUS;
            }

            @Override
            public boolean belongsTo(Object family) {
                if (JobFamilies.DISCARD_CHANGES.equals(family)) {
                    return true;
                }
                return super.belongsTo(family);
            }
        };
        job.setUser(true);
        job.setRule(operation.getSchedulingRule());
        job.schedule();
        return null;
    } finally {
        // cleanup mySelection to avoid side effects later after execution
        mySelection = null;
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) DiscardChangesOperation(org.eclipse.egit.core.op.DiscardChangesOperation) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob)

Example 78 with IWorkbenchPart

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

the class AddToIndexActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final IResource[] sel = getSelectedResources(event);
    if (sel.length == 0)
        return null;
    IResource[] resourcesInScope;
    try {
        IWorkbenchPart part = getPart(event);
        resourcesInScope = GitScopeUtil.getRelatedChanges(part, sel);
    } catch (InterruptedException e) {
        // cancels the scope operation
        return null;
    }
    final AddToIndexOperation operation = new AddToIndexOperation(resourcesInScope);
    String jobname = UIText.AddToIndexAction_addingFiles;
    Job job = new Job(jobname) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                operation.execute(monitor);
            } catch (CoreException e) {
                return Activator.createErrorStatus(e.getStatus().getMessage(), e);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.ADD_TO_INDEX.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.setRule(operation.getSchedulingRule());
    job.schedule();
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Job(org.eclipse.core.runtime.jobs.Job) IResource(org.eclipse.core.resources.IResource) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation)

Example 79 with IWorkbenchPart

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

the class RebaseInteractiveView method setupRepositoryViewSelectionChangeListener.

private void setupRepositoryViewSelectionChangeListener() {
    selectionChangedListener = new ISelectionListener() {

        @Override
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (!listenOnRepositoryViewSelection || part == getSite().getPart()) {
                return;
            }
            // this may happen if we switch between editors
            if (part instanceof IEditorPart) {
                IEditorInput input = ((IEditorPart) part).getEditorInput();
                if (input instanceof IFileEditorInput) {
                    newInput(new StructuredSelection(((IFileEditorInput) input).getFile()), false);
                }
            } else {
                newInput(selection, false);
            }
        }
    };
    ISelectionService srv = CommonUtils.getService(getSite(), ISelectionService.class);
    srv.addPostSelectionListener(selectionChangedListener);
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IFileEditorInput(org.eclipse.ui.IFileEditorInput) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISelectionService(org.eclipse.ui.ISelectionService) IEditorPart(org.eclipse.ui.IEditorPart) ISelectionListener(org.eclipse.ui.ISelectionListener) IEditorInput(org.eclipse.ui.IEditorInput)

Example 80 with IWorkbenchPart

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

the class AbstractReflogCommandHandler method getView.

protected ReflogView getView() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null)
        return null;
    if (window.getActivePage() == null)
        return null;
    IWorkbenchPart part = window.getActivePage().getActivePart();
    if (!(part instanceof ReflogView))
        return null;
    return (ReflogView) part;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ReflogView(org.eclipse.egit.ui.internal.reflog.ReflogView)

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