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