Search in sources :

Example 1 with IOpenJobScriptActionService

use of org.talend.core.ui.services.IOpenJobScriptActionService in project tdi-studio-se by Talend.

the class OpenExistVersionProcessWizard method openXtextEditor.

private void openXtextEditor(RepositoryNode repositoryNode, IProject fsProject, boolean readonly) {
    try {
        if (ProjectManager.getInstance().isInCurrentMainProject(repositoryNode)) {
            IFile linkedFile = null;
            IOpenJobScriptActionService openJobScriptActionService = (IOpenJobScriptActionService) GlobalServiceRegister.getDefault().getService(IOpenJobScriptActionService.class);
            if (openJobScriptActionService != null) {
                linkedFile = openJobScriptActionService.createWorkspaceLink(fsProject, repositoryNode.getObject().getProperty().getItem());
            } else {
                linkedFile = createWorkspaceLink(fsProject, fsProject.getFolder(ERepositoryObjectType.getFolderName(ERepositoryObjectType.JOB_SCRIPT)).getFolder(repositoryNode.getParent().getRepositoryPath()).getFile(repositoryNode.getObject().getProperty().getLabel()).getLocation(), repositoryNode.getObject().getProperty().getVersion());
            }
            IWorkbenchPage page = getActivePage();
            IEditorPart editor = IDE.openEditor(page, linkedFile);
            if (readonly) {
                IDocumentProvider provider = ((AbstractDecoratedTextEditor) editor).getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
        } else {
            JobScriptItem jobScriptItem = (JobScriptItem) repositoryNode.getObject().getProperty().getItem();
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(jobScriptItem.eResource().getURI().path()).removeFirstSegments(1).removeFileExtension());
            IFile linkedFile = createWorkspaceLink(fsProject, file.getLocation(), "");
            IWorkbenchPage page = getActivePage();
            IEditorPart editor = IDE.openEditor(page, linkedFile);
            if (readonly) {
                IDocumentProvider provider = ((AbstractDecoratedTextEditor) editor).getDocumentProvider();
                Class p = provider.getClass();
                Class[] type = new Class[1];
                type[0] = Boolean.TYPE;
                Object[] para = new Object[1];
                para[0] = Boolean.TRUE;
                Method method = p.getMethod("setReadOnly", type);
                method.invoke(provider, para);
            }
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    } catch (SecurityException e) {
        ExceptionHandler.process(e);
    } catch (NoSuchMethodException e) {
        ExceptionHandler.process(e);
    } catch (IllegalArgumentException e) {
        ExceptionHandler.process(e);
    } catch (IllegalAccessException e) {
        ExceptionHandler.process(e);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IOpenJobScriptActionService(org.talend.core.ui.services.IOpenJobScriptActionService) JobScriptItem(org.talend.core.model.properties.JobScriptItem) IEditorPart(org.eclipse.ui.IEditorPart) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractDecoratedTextEditor(org.eclipse.ui.texteditor.AbstractDecoratedTextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 AbstractDecoratedTextEditor (org.eclipse.ui.texteditor.AbstractDecoratedTextEditor)1 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)1 JobScriptItem (org.talend.core.model.properties.JobScriptItem)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 IOpenJobScriptActionService (org.talend.core.ui.services.IOpenJobScriptActionService)1