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);
}
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;
}
}
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;
}
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);
}
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;
}
Aggregations