Search in sources :

Example 81 with IEditorReference

use of org.eclipse.ui.IEditorReference in project statecharts by Yakindu.

the class ResourceUnloadingTool method unloadEditorInput.

public static void unloadEditorInput(ResourceSet resourceSet, IEditorInput editorInput) {
    final EList<Resource> resources = resourceSet.getResources();
    final List<Resource> resourcesToUnload = new ArrayList<Resource>(resources);
    IEditorReference[] editorReferences;
    try {
        editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    } catch (final NullPointerException exc) {
        // see bug http://code.google.com/p/gmftools/issues/detail?id=9
        return;
    }
    for (final IEditorReference openEditorReference : editorReferences) {
        try {
            final IEditorInput openEditorInput = openEditorReference.getEditorInput();
            if (openEditorInput != editorInput) {
                final IEditorPart openEditor = openEditorReference.getEditor(false);
                if (openEditor instanceof IEditingDomainProvider) {
                    final IEditingDomainProvider openDiagramEditor = (IEditingDomainProvider) openEditor;
                    final ResourceSet diagramResourceSet = openDiagramEditor.getEditingDomain().getResourceSet();
                    if (diagramResourceSet == resourceSet) {
                        final Resource diagramResource = getDiagramResource(diagramResourceSet, openEditorInput);
                        resourcesToUnload.remove(diagramResource);
                        final Collection<?> imports = EMFCoreUtil.getImports(diagramResource);
                        resourcesToUnload.removeAll(imports);
                    }
                }
            }
        } catch (final Exception exc) {
            exc.printStackTrace();
        }
    }
    for (final Resource resourceToUnload : resourcesToUnload) {
        try {
            resourceToUnload.unload();
            resources.remove(resourceToUnload);
        } catch (final Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IEditorReference(org.eclipse.ui.IEditorReference) IEditorInput(org.eclipse.ui.IEditorInput) URIEditorInput(org.eclipse.emf.common.ui.URIEditorInput) IEditingDomainProvider(org.eclipse.emf.edit.domain.IEditingDomainProvider)

Example 82 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdq-studio-se by Talend.

the class ResourceDropAdapterAssistant method closeEditorIfOpened.

/**
 * DOC bZhou Comment method "closeEditorIfOpened".
 *
 * @param fileRes
 */
private void closeEditorIfOpened(IFile fileRes) {
    IWorkbenchPage activePage = CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorReference[] editorReferences = activePage.getEditorReferences();
    for (IEditorReference reference : editorReferences) {
        try {
            IEditorInput editorInput = reference.getEditorInput();
            if (editorInput instanceof FileEditorInput) {
                FileEditorInput fileInput = (FileEditorInput) editorInput;
                if (fileRes.getName().equals(fileInput.getFile().getName())) {
                    activePage.closeEditor(reference.getEditor(false), false);
                    break;
                }
            }
        } catch (PartInitException e) {
            e.printStackTrace();
        }
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 83 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdq-studio-se by Talend.

the class RepNodeUtils method closeFileEditor.

/**
 * close file node's editor.
 *
 * @param files
 * @param save
 */
public static void closeFileEditor(List<IFile> files, boolean save) {
    List<IEditorReference> need2CloseEditorRefs = new ArrayList<IEditorReference>();
    IEditorReference[] editorReferences = CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    try {
        for (IEditorReference editorRef : editorReferences) {
            if (editorRef != null) {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (editorInput != null) {
                    if (editorInput instanceof FileEditorInput) {
                        IFile file = ((FileEditorInput) editorInput).getFile();
                        if (file != null) {
                            for (IFile ifile : files) {
                                if (ifile != null) {
                                    String osString = ifile.getRawLocation().toOSString();
                                    String osString2 = file.getRawLocation().toOSString();
                                    if (osString.equals(osString2)) {
                                        need2CloseEditorRefs.add(editorRef);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (PartInitException e) {
        log.warn(e, e);
    }
    if (need2CloseEditorRefs.size() > 0) {
        CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditors(need2CloseEditorRefs.toArray(new IEditorReference[need2CloseEditorRefs.size()]), save);
    }
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ArrayList(java.util.ArrayList) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 84 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdq-studio-se by Talend.

the class WorkbenchUtils method closeAndOpenEditor.

/**
 * close and open the editors same method {@link CorePlugin}.getDefault().itemIsOpening() MOD TDQ-8360 20140410
 * yyin: will only operate the analysis who is related and has opened (by its observer --added when opening)
 *
 * @param iEditorReference
 */
private static void closeAndOpenEditor(List<IEditorReference> iEditorReference) {
    // Refresh current opened editors.
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPartReference activePartReference = activePage.getActivePartReference();
    // MOD qiongli 2011-9-8 TDQ-3317.when focucs on DI perspective,don't refresh the open editors
    DQRespositoryView findView = (DQRespositoryView) activePage.findView(DQRespositoryView.ID);
    if (findView == null) {
        return;
    }
    if (iEditorReference.size() > 0) {
        try {
            for (IEditorReference editorRef : iEditorReference) {
                IEditorInput editorInput = editorRef.getEditorInput();
                if (editorInput instanceof AbstractItemEditorInput) {
                    AbstractItemEditorInput anaItemEditorInput = (AbstractItemEditorInput) editorInput;
                    // close the editor
                    activePage.closeEditor(editorRef.getEditor(false), false);
                    // reopen the analysis
                    new OpenItemEditorAction(new IRepositoryNode[] { anaItemEditorInput.getRepNode() }).run();
                }
            }
        } catch (PartInitException e) {
            log.error(e);
        }
    }
    activePage.activate(activePartReference.getPart(false));
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) AbstractItemEditorInput(org.talend.dataprofiler.core.ui.editor.AbstractItemEditorInput) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) OpenItemEditorAction(org.talend.dataprofiler.core.ui.action.actions.OpenItemEditorAction) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView) IEditorInput(org.eclipse.ui.IEditorInput)

Example 85 with IEditorReference

use of org.eclipse.ui.IEditorReference in project tdq-studio-se by Talend.

the class ContextViewHelper method hideContextView.

public static void hideContextView(IWorkbenchPart part) {
    boolean currentEditorOpened = false;
    IWorkbenchPage page = part.getSite().getWorkbenchWindow().getActivePage();
    if (page == null) {
        return;
    }
    IEditorReference[] editorReferences = page.getEditorReferences();
    for (IEditorReference editorRef : editorReferences) {
        if (editorRef != null && editorRef.getEditor(false) != null) {
            if (editorRef.getEditor(false) instanceof SupportContextEditor) {
                currentEditorOpened = true;
                break;
            }
        }
    }
    if (!currentEditorOpened) {
        IViewPart ctxViewer = page.findView(AbstractContextView.CTX_ID_TDQ);
        if (ctxViewer != null) {
            page.hideView(ctxViewer);
        }
    }
}
Also used : SupportContextEditor(org.talend.dataprofiler.core.ui.editor.SupportContextEditor) IViewPart(org.eclipse.ui.IViewPart) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

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