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