use of org.eclipse.ui.IEditorReference in project eclipse-cs by checkstyle.
the class CheckstyleUIPlugin method start.
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
mQuickfixExtensionClassLoader = new ExtensionClassLoader(context.getBundle(), QUICKFIX_PROVIDER_EXT_PT_ID);
// add listeners for the Check-On-Open support
final IWorkbench workbench = getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
for (IWorkbenchWindow window : windows) {
if (window != null) {
// collect open editors and have then run against Checkstyle if
// appropriate
Collection<IWorkbenchPartReference> parts = new HashSet<>();
// add already opened files to the filter
// bugfix for 2923044
IWorkbenchPage[] pages = window.getPages();
for (IWorkbenchPage page : pages) {
IEditorReference[] editorRefs = page.getEditorReferences();
for (IEditorReference ref : editorRefs) {
parts.add(ref);
}
}
mPartListener.partsOpened(parts);
// remove listener first for safety, we don't want
// register the same listener twice accidently
window.getPartService().removePartListener(mPartListener);
window.getPartService().addPartListener(mPartListener);
}
}
workbench.addWindowListener(mWindowListener);
}
});
}
use of org.eclipse.ui.IEditorReference in project egit by eclipse.
the class SubmoduleFolderTest method compareWithHeadInSubmoduleFolder.
/**
* Tests that a CompareWithHeadAction on a file from a submodule folder does
* open the right compare editor, comparing against the version from the
* submodule (as opposed to the version from the parent repo).
*
* @throws Exception
*/
@Test
public void compareWithHeadInSubmoduleFolder() throws Exception {
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=446344#c11
// If the compare editor's title does not contain the HEAD id of
// the subrepo, then either no compare editor got opened, or
// it was opened using the parent repo.
IFolder childProjectFolder = childFolder.getFolder(CHILDPROJECT);
IFolder folder = childProjectFolder.getFolder(FOLDER);
IFile file = folder.getFile(FILE1);
touch(PROJ1, file.getProjectRelativePath().toOSString(), "Modified");
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree, file.getFullPath().segments());
node.select();
Ref headRef = subRepository.findRef(Constants.HEAD);
final String headId = headRef.getObjectId().abbreviate(6).name();
ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Compare With", util.getPluginLocalizedValue("CompareWithHeadAction_label"));
bot.waitUntil(waitForEditor(new BaseMatcher<IEditorReference>() {
@Override
public boolean matches(Object item) {
return (item instanceof IEditorReference) && ((IEditorReference) item).getTitle().contains(headId);
}
@Override
public void describeTo(Description description) {
description.appendText("Wait for editor containing " + headId);
}
}), 5000);
}
use of org.eclipse.ui.IEditorReference in project egit by eclipse.
the class StashDropCommand method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final List<StashedCommitNode> nodes = getSelectedNodes(event);
if (nodes.isEmpty())
return null;
final Repository repo = nodes.get(0).getRepository();
if (repo == null)
return null;
// Confirm deletion of selected nodes
final AtomicBoolean confirmed = new AtomicBoolean();
final Shell shell = getActiveShell(event);
shell.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
String message;
if (nodes.size() > 1)
message = MessageFormat.format(UIText.StashDropCommand_confirmMultiple, Integer.toString(nodes.size()));
else
message = MessageFormat.format(UIText.StashDropCommand_confirmSingle, Integer.toString(nodes.get(0).getIndex()));
confirmed.set(MessageDialog.openConfirm(shell, UIText.StashDropCommand_confirmTitle, message));
}
});
if (!confirmed.get())
return null;
Job job = new Job(UIText.StashDropCommand_jobTitle) {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(UIText.StashDropCommand_jobTitle, nodes.size());
// Sort by highest to lowest stash commit index.
// This avoids shifting problems that cause the indices of the
// selected nodes not match the indices in the repository
Collections.sort(nodes, new Comparator<StashedCommitNode>() {
@Override
public int compare(StashedCommitNode n1, StashedCommitNode n2) {
return n1.getIndex() < n2.getIndex() ? 1 : -1;
}
});
for (StashedCommitNode node : nodes) {
final int index = node.getIndex();
if (index < 0)
return null;
final RevCommit commit = node.getObject();
if (commit == null)
return null;
final String stashName = node.getObject().getName();
final StashDropOperation op = new StashDropOperation(repo, node.getIndex());
monitor.subTask(stashName);
try {
op.execute(monitor);
} catch (CoreException e) {
Activator.logError(MessageFormat.format(UIText.StashDropCommand_dropFailed, node.getObject().name()), e);
}
tryToCloseEditor(node);
monitor.worked(1);
}
monitor.done();
return Status.OK_STATUS;
}
private void tryToCloseEditor(final StashedCommitNode node) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editorReferences = activePage.getEditorReferences();
for (IEditorReference editorReference : editorReferences) {
IEditorInput editorInput = null;
try {
editorInput = editorReference.getEditorInput();
} catch (PartInitException e) {
Activator.handleError(e.getMessage(), e, true);
}
if (editorInput instanceof CommitEditorInput) {
CommitEditorInput comEditorInput = (CommitEditorInput) editorInput;
if (comEditorInput.getCommit().getRevCommit().equals(node.getObject())) {
activePage.closeEditor(editorReference.getEditor(false), false);
}
}
}
}
});
}
@Override
public boolean belongsTo(Object family) {
if (JobFamilies.STASH.equals(family))
return true;
return super.belongsTo(family);
}
};
job.setUser(true);
job.setRule((new StashDropOperation(repo, nodes.get(0).getIndex())).getSchedulingRule());
job.schedule();
return null;
}
use of org.eclipse.ui.IEditorReference in project tdq-studio-se by Talend.
the class CorePluginTest method testItemIsOpeningItemBoolean.
/**
* Test method for
* {@link org.talend.dataprofiler.core.CorePlugin#itemIsOpening(org.talend.core.model.properties.Item, boolean)}.
*/
@Test
public void testItemIsOpeningItemBoolean() {
try {
CorePlugin cpMock = mock(CorePlugin.class);
PowerMockito.mockStatic(CorePlugin.class);
when(CorePlugin.getDefault()).thenReturn(cpMock);
IWorkbench workbenchMock = mock(IWorkbench.class);
when(cpMock.getWorkbench()).thenReturn(workbenchMock);
IWorkbenchWindow workbenchWindowMock = mock(IWorkbenchWindow.class);
when(workbenchMock.getActiveWorkbenchWindow()).thenReturn(workbenchWindowMock);
IWorkbenchPage workbenchPageMock = mock(IWorkbenchPage.class);
when(workbenchWindowMock.getActivePage()).thenReturn(workbenchPageMock);
IEditorReference editorRefMock = mock(IEditorReference.class);
IEditorReference[] editorRefMocks = new IEditorReference[] { editorRefMock };
when(workbenchPageMock.getEditorReferences()).thenReturn(editorRefMocks);
FileEditorInput fileEditorInputMock = mock(FileEditorInput.class);
when(editorRefMock.getEditorInput()).thenReturn(fileEditorInputMock);
// $NON-NLS-1$
String path1 = "/abc1";
// $NON-NLS-1$
String path2 = "/abc2";
IFile inputFileMock = mock(IFile.class);
when(fileEditorInputMock.getFile()).thenReturn(inputFileMock);
IPath inputFilePathMock = mock(IPath.class);
when(inputFileMock.getFullPath()).thenReturn(inputFilePathMock);
when(inputFilePathMock.toString()).thenReturn(path1);
Item itemMock = mock(Item.class);
Property propertyMock = mock(Property.class);
when(itemMock.getProperty()).thenReturn(propertyMock);
Resource resourceMock = mock(Resource.class);
when(propertyMock.eResource()).thenReturn(resourceMock);
IPath ipathMock = mock(IPath.class);
PowerMockito.mockStatic(PropertyHelper.class);
when(PropertyHelper.getItemPath(propertyMock)).thenReturn(ipathMock);
when(ipathMock.toString()).thenReturn(path2);
CorePlugin cp = new CorePlugin();
assertFalse(cp.itemIsOpening(itemMock, false));
} catch (PartInitException e) {
fail(e.getMessage());
}
}
use of org.eclipse.ui.IEditorReference in project statecharts by Yakindu.
the class DiagramPartitioningEditor method closeSubdiagramEditors.
protected void closeSubdiagramEditors() {
if (getDiagram() != null && getDiagram().getElement() instanceof Statechart) {
List<IEditorReference> refsToClose = new ArrayList<IEditorReference>();
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (workbenchWindow == null)
return;
IWorkbenchPage activePage = workbenchWindow.getActivePage();
if (activePage == null)
return;
IEditorReference[] refs = activePage.getEditorReferences();
for (IEditorReference ref : refs) {
try {
if (ref.getEditorInput() instanceof IDiagramEditorInput) {
IDiagramEditorInput diagramInput = (IDiagramEditorInput) ref.getEditorInput();
if (diagramInput.getDiagram().eResource() == getDiagram().eResource()) {
refsToClose.add(ref);
}
}
} catch (PartInitException e) {
e.printStackTrace();
}
}
if (refsToClose.size() > 0) {
boolean close = MessageDialog.openQuestion(activePage.getActivePart().getSite().getShell(), "Close subdiagram editors?", "There are still subdiagram editors open. Do you want to close them?");
if (close) {
for (IEditorReference ref : refsToClose) {
activePage.closeEditor(ref.getEditor(false), false);
}
}
}
}
}
Aggregations