use of org.talend.repository.services.action.ServiceEditorInput in project tesb-studio-se by Talend.
the class OpenOnSelectionHelper method openEditor.
@Override
protected void openEditor(String resource, String spec) {
//$NON-NLS-1$
String pattern = "platform:/resource";
IWorkbenchPage workbenchPage = WSDLEditorPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart editorPart = workbenchPage.getActiveEditor();
String currentEditorId = editorPart.getEditorSite().getId();
if (resource != null && resource.startsWith(pattern)) {
Path path = new Path(resource.substring(pattern.length()));
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (editorPart.getEditorInput() instanceof IFileEditorInput && ((IFileEditorInput) editorPart.getEditorInput()).getFile().equals(file)) {
workbenchPage.getNavigationHistory().markLocation(editorPart);
} else {
try {
Item item = ((ServiceEditorInput) editorPart.getEditorInput()).getItem();
// TODO: Use content type as below
if (resource.endsWith("xsd")) {
//$NON-NLS-1$
editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), WSDLEditorPlugin.XSD_EDITOR_ID);
} else {
// Since we are already in the wsdleditor
editorPart = workbenchPage.openEditor(new ServiceEditorInput(file, item), editorPart.getEditorSite().getId());
}
} catch (PartInitException initEx) {
ExceptionHandler.process(initEx);
}
}
try {
Class<? extends IEditorPart> theClass = editorPart.getClass();
Class<?>[] methodArgs = { String.class };
//$NON-NLS-1$
Method method = theClass.getMethod("openOnSelection", methodArgs);
Object[] args = { spec };
method.invoke(editorPart, args);
workbenchPage.getNavigationHistory().markLocation(editorPart);
} catch (Exception e) {
ExceptionHandler.process(e);
}
} else if (resource != null && resource.startsWith("http")) {
IEditorPart newEditorPart = null;
boolean doOpenWsdlEditor = true;
if (//$NON-NLS-1$
resource.endsWith("xsd")) {
doOpenWsdlEditor = false;
}
try {
IEditorReference[] refs = workbenchPage.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(resource) && (!doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.XSD_EDITOR_ID) || doOpenWsdlEditor && readOnlyEditorInput.getEditorID().equals(WSDLEditorPlugin.WSDL_EDITOR_ID))) {
newEditorPart = refs[i].getEditor(true);
workbenchPage.activate(refs[i].getPart(true));
break;
}
}
}
if (newEditorPart == null) {
ADTReadOnlyFileEditorInput readOnlyStorageEditorInput = new ADTReadOnlyFileEditorInput(resource);
IContentType contentType = null;
try (InputStream iStream = readOnlyStorageEditorInput.getStorage().getContents()) {
contentType = Platform.getContentTypeManager().findContentTypeFor(iStream, resource);
}
// content type more reliable check
if (//$NON-NLS-1$
contentType != null && contentType.equals(XSDEditorPlugin.XSD_CONTENT_TYPE_ID) || resource.endsWith("xsd")) {
readOnlyStorageEditorInput.setEditorID(WSDLEditorPlugin.XSD_EDITOR_ID);
//$NON-NLS-1$
workbenchPage.openEditor(readOnlyStorageEditorInput, WSDLEditorPlugin.XSD_EDITOR_ID, true, 0);
} else {
readOnlyStorageEditorInput.setEditorID(currentEditorId);
//$NON-NLS-1$
workbenchPage.openEditor(readOnlyStorageEditorInput, currentEditorId, true, 0);
}
}
} catch (IOException | CoreException e) {
ExceptionHandler.process(e);
}
}
}
Aggregations