use of org.eclipse.wst.xsd.ui.internal.adt.editor.ADTFileStoreEditorInput 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;
}
}
Aggregations