Search in sources :

Example 76 with IEditorReference

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);
        }
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) ExtensionClassLoader(net.sf.eclipsecs.core.util.ExtensionClassLoader) Collection(java.util.Collection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 77 with IEditorReference

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);
}
Also used : Ref(org.eclipse.jgit.lib.Ref) IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) Description(org.hamcrest.Description) IProjectDescription(org.eclipse.core.resources.IProjectDescription) BaseMatcher(org.hamcrest.BaseMatcher) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 78 with IEditorReference

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;
}
Also used : CommitEditorInput(org.eclipse.egit.ui.internal.commit.CommitEditorInput) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Repository(org.eclipse.jgit.lib.Repository) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IEditorReference(org.eclipse.ui.IEditorReference) CoreException(org.eclipse.core.runtime.CoreException) StashDropOperation(org.eclipse.egit.core.op.StashDropOperation) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) StashedCommitNode(org.eclipse.egit.ui.internal.repository.tree.StashedCommitNode) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) IEditorInput(org.eclipse.ui.IEditorInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 79 with IEditorReference

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());
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Resource(org.eclipse.emf.ecore.resource.Resource) IWorkbench(org.eclipse.ui.IWorkbench) Item(org.talend.core.model.properties.Item) IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) Property(org.talend.core.model.properties.Property) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 80 with IEditorReference

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);
                }
            }
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorReference(org.eclipse.ui.IEditorReference) ArrayList(java.util.ArrayList) Statechart(org.yakindu.sct.model.sgraph.Statechart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IDiagramEditorInput(org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditorInput)

Aggregations

IEditorReference (org.eclipse.ui.IEditorReference)174 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)83 IEditorPart (org.eclipse.ui.IEditorPart)78 PartInitException (org.eclipse.ui.PartInitException)59 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)55 IFile (org.eclipse.core.resources.IFile)50 IEditorInput (org.eclipse.ui.IEditorInput)49 ArrayList (java.util.ArrayList)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)28 Item (org.talend.core.model.properties.Item)17 IWorkbench (org.eclipse.ui.IWorkbench)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 IOException (java.io.IOException)12 CoreException (org.eclipse.core.runtime.CoreException)12 ProcessItem (org.talend.core.model.properties.ProcessItem)11 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)10 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)10 Path (org.eclipse.core.runtime.Path)10 IProcess2 (org.talend.core.model.process.IProcess2)10