use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.
the class JSPRenameChange method findOpenEditor.
/**
* <p>Checks if a document is open in an editor and returns it if it is</p>
*
* @param jspDoc check to see if this {@link IDocument} is currently open in an editor
* @return the open {@link ITextEditor} associated with the given {@link IDocument} or
* <code>null</code> if none can be found.
*/
private static ITextEditor findOpenEditor(IDocument jspDoc) {
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
IWorkbenchWindow w = null;
for (int i = 0; i < windows.length; i++) {
w = windows[i];
IWorkbenchPage page = w.getActivePage();
if (page != null) {
IEditorReference[] references = page.getEditorReferences();
IEditorPart editor = null;
Object o = null;
IDocument doc = null;
for (int j = 0; j < references.length; j++) {
editor = references[j].getEditor(false);
if (editor != null) {
// editor might not be instantiated
// https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3764
// use adapter to get ITextEditor (for things like
// page designer)
o = editor.getAdapter(ITextEditor.class);
if (o != null && o instanceof ITextEditor) {
doc = ((ITextEditor) o).getDocumentProvider().getDocument(editor.getEditorInput());
if (doc != null && doc.equals(jspDoc)) {
return (ITextEditor) o;
}
}
}
}
}
}
return null;
}
use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.
the class OpenInNewEditor method openExternalFiles.
public static void openExternalFiles(IWorkbenchPage page, String schemaLocation, XSDConcreteComponent fComponent) {
// Assert not null
if (schemaLocation == null)
return;
IPath schemaPath = new Path(schemaLocation);
// So as a result of bug 221421, we will just use the schemaLocation.
if (!schemaLocation.startsWith("http")) {
schemaPath = new Path(URIHelper.removeProtocol(schemaLocation));
}
IFileStore fileStore = EFS.getLocalFileSystem().getStore(schemaPath);
URI schemaURI = URI.create(schemaLocation);
if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
try {
IEditorPart editorPart = null;
IEditorReference[] refs = page.getEditorReferences();
int length = refs.length;
// Need to find if an editor on that schema has already been opened
for (int i = 0; i < length; i++) {
IEditorInput input = refs[i].getEditorInput();
if (input instanceof FileStoreEditorInput) {
URI uri = ((FileStoreEditorInput) input).getURI();
if (uri.equals(schemaURI)) {
editorPart = refs[i].getEditor(true);
page.activate(refs[i].getPart(true));
break;
}
}
}
if (editorPart == null) {
editorPart = IDE.openEditorOnFileStore(page, fileStore);
}
if (editorPart instanceof InternalXSDMultiPageEditor) {
InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
xsdEditor.openOnGlobalReference(fComponent);
}
} catch (PartInitException pie) {
}
} else {
try {
if (schemaLocation.startsWith("http")) {
try {
IEditorPart editorPart = null;
IEditorReference[] refs = page.getEditorReferences();
int length = refs.length;
// Need to find if an editor on that schema has already been opened
for (int i = 0; i < length; i++) {
IEditorInput input = refs[i].getEditorInput();
if (input instanceof ADTReadOnlyFileEditorInput) {
ADTReadOnlyFileEditorInput readOnlyEditorInput = (ADTReadOnlyFileEditorInput) input;
if (readOnlyEditorInput.getUrlString().equals(schemaLocation) && XSDEditorPlugin.EDITOR_ID.equals(readOnlyEditorInput.getEditorID())) {
editorPart = refs[i].getEditor(true);
page.activate(refs[i].getPart(true));
break;
}
}
}
if (editorPart == null) {
ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(schemaLocation);
readOnlyStorageEditorInput.setEditorID(XSDEditorPlugin.EDITOR_ID);
// $NON-NLS-1$
editorPart = page.openEditor(readOnlyStorageEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
}
if (editorPart instanceof InternalXSDMultiPageEditor) {
InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
xsdEditor.openOnGlobalReference(fComponent);
}
} catch (PartInitException pie) {
}
} else {
FileStoreEditorInput xsdFileStoreEditorInput = new FileStoreEditorInput(fileStore);
// $NON-NLS-1$
page.openEditor(xsdFileStoreEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
}
} catch (PartInitException e) {
}
}
}
use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.
the class OpenInNewEditor method openInlineSchema.
public static void openInlineSchema(IEditorInput editorInput, XSDConcreteComponent xsdComponent, XSDSchema schema, String editorName) {
IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = null;
if (workbenchWindow != null) {
page = workbenchWindow.getActivePage();
}
boolean isWorkspaceFile = false;
String schemaLocation = schema.getSchemaLocation();
String workspaceFileLocation = URIHelper.removePlatformResourceProtocol(schemaLocation);
IPath workspaceFilePath = new Path(workspaceFileLocation);
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(workspaceFilePath);
if (page != null && file != null && file.exists()) {
isWorkspaceFile = true;
}
if (isWorkspaceFile) {
try {
IEditorPart editorPart = null;
XSDFileEditorInput xsdFileEditorInput = new XSDFileEditorInput(file, schema);
xsdFileEditorInput.setEditorName(editorName);
IEditorReference[] refs = page.getEditorReferences();
int length = refs.length;
for (int i = 0; i < length; i++) {
IEditorInput input = refs[i].getEditorInput();
if (input instanceof XSDFileEditorInput) {
IFile aFile = ((XSDFileEditorInput) input).getFile();
if (aFile.getFullPath().equals(file.getFullPath())) {
if (((XSDFileEditorInput) input).getSchema() == schema) {
editorPart = refs[i].getEditor(true);
page.activate(refs[i].getPart(true));
break;
}
}
}
}
if (editorPart == null) {
// $NON-NLS-1$
editorPart = page.openEditor(xsdFileEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
}
if (editorPart instanceof InternalXSDMultiPageEditor) {
InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
xsdEditor.openOnGlobalReference(xsdComponent);
}
} catch (PartInitException pie) {
}
} else {
if (schemaLocation != null && !schemaLocation.startsWith("http")) {
String fileLocation = null;
//
if (java.io.File.separatorChar == '/') {
fileLocation = "/" + URIHelper.removePlatformResourceProtocol(schemaLocation);
} else // Windows
{
fileLocation = URIHelper.removeProtocol(schemaLocation);
}
IPath schemaPath = new Path(fileLocation);
IFileStore fileStore = EFS.getLocalFileSystem().getStore(schemaPath);
if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) {
try {
ADTFileStoreEditorInput xsdFileStoreEditorInput = new ADTFileStoreEditorInput(fileStore, schema);
xsdFileStoreEditorInput.setEditorName(editorName);
IEditorPart editorPart = null;
IEditorReference[] refs = page.getEditorReferences();
int length = refs.length;
for (int i = 0; i < length; i++) {
IEditorInput input = refs[i].getEditorInput();
if (input instanceof ADTFileStoreEditorInput) {
URI uri = ((ADTFileStoreEditorInput) input).getURI();
if (uri.equals(xsdFileStoreEditorInput.getURI()) && ((ADTFileStoreEditorInput) input).getSchema() == xsdFileStoreEditorInput.getSchema()) {
editorPart = refs[i].getEditor(true);
page.activate(refs[i].getPart(true));
break;
}
}
}
if (page != null && editorPart == null) {
// $NON-NLS-1$
editorPart = page.openEditor(xsdFileStoreEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
}
if (editorPart instanceof InternalXSDMultiPageEditor) {
InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
xsdEditor.openOnGlobalReference(xsdComponent);
}
} catch (PartInitException pie) {
}
}
} else {
try {
IEditorPart editorPart = null;
IEditorReference[] refs = page.getEditorReferences();
int length = refs.length;
// Need to find if an editor on that schema has already been opened
for (int i = 0; i < length; i++) {
IEditorInput input = refs[i].getEditorInput();
if (input instanceof ADTReadOnlyFileEditorInput) {
ADTReadOnlyFileEditorInput xsdFileStorageEditorInput = (ADTReadOnlyFileEditorInput) input;
if (xsdFileStorageEditorInput.getUrlString().equals(schemaLocation) && xsdFileStorageEditorInput.getEditorID().equals(XSDEditorPlugin.EDITOR_ID)) {
editorPart = refs[i].getEditor(true);
page.activate(refs[i].getPart(true));
break;
}
}
}
if (editorPart == null) {
ADTReadOnlyFileEditorInput xsdFileStorageEditorInput = new ADTReadOnlyFileEditorInput(schemaLocation);
xsdFileStorageEditorInput.setSchema(schema);
xsdFileStorageEditorInput.setEditorName(editorName);
xsdFileStorageEditorInput.setEditorID(XSDEditorPlugin.EDITOR_ID);
editorPart = page.openEditor(xsdFileStorageEditorInput, XSDEditorPlugin.EDITOR_ID, true, 0);
}
if (editorPart instanceof InternalXSDMultiPageEditor) {
InternalXSDMultiPageEditor xsdEditor = (InternalXSDMultiPageEditor) editorPart;
xsdEditor.openOnGlobalReference(xsdComponent);
}
} catch (PartInitException pie) {
}
}
return;
}
}
use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.
the class ResourceSelectionBlock method filterOpenEditorsByFileExtension.
private String[] filterOpenEditorsByFileExtension(IEditorReference[] editors) {
String[] paths = new String[editors.length];
String[] fileExts = getFileExtensions();
for (int i = 0; i < editors.length; i++) {
IEditorReference currentEditor = editors[i];
IEditorPart editorPart = currentEditor.getEditor(true);
IFile file = (IFile) editorPart.getEditorInput().getAdapter(IFile.class);
if (file != null) {
IPath path = file.getFullPath();
paths[i] = getEditorPath(path, fileExts);
}
}
return paths;
}
use of org.eclipse.ui.IEditorReference in project webtools.sourceediting by eclipse.
the class DelegatingSourceValidatorForXSL method validate.
@Override
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException {
super.validate(helper, reporter);
// validating will refresh the model, so now calculate the overrides.
// (we only calculate overrides for source validation as we only want to do it for files open in an editor)
// There follows a very complicated way of creating the required annotations in an editor.
// TODO resolve this when bug 247222 is sorted
String[] delta = helper.getURIs();
if (delta.length > 0) {
IFile file = getFile(delta[0]);
// find any files with open editors...
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (IWorkbenchWindow workbenchWindow : windows) {
IWorkbenchPage page = workbenchWindow.getActivePage();
if (page != null) {
IEditorReference[] refs = page.findEditors(new FileEditorInput(file), XSL_UI_XSL_EDITOR_ID, IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);
// lets hope we only have one XSL editor open on the file, or else we don't know which one started this validation...
if (refs.length == 1) {
XSLEditor editor = (XSLEditor) refs[0].getEditor(false);
if (editor != null) {
// all this work just to get here...
editor.getOverrideIndicatorManager().updateAnnotations();
}
}
}
}
}
}
Aggregations