Search in sources :

Example 21 with RepositoryEditorInput

use of org.talend.core.repository.ui.editor.RepositoryEditorInput in project tdi-studio-se by Talend.

the class AbstractSqlpatternAction method openSQLPatternEditor.

/**
     * DOC smallet Comment method "openRoutineEditor".
     * 
     * @param item
     * @throws SystemException
     * @throws PartInitException
     */
public IEditorPart openSQLPatternEditor(SQLPatternItem item, boolean readOnly) throws SystemException, PartInitException {
    if (item == null) {
        return null;
    }
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ISQLPatternSynchronizer routineSynchronizer = service.getSQLPatternSynchronizer();
    // check if the related editor is open.
    IWorkbenchPage page = getActivePage();
    IEditorReference[] editorParts = page.getEditorReferences();
    //$NON-NLS-1$ //$NON-NLS-2$
    String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
    boolean found = false;
    IEditorPart talendEditor = null;
    for (IEditorReference reference : editorParts) {
        IEditorPart editor = reference.getEditor(false);
        if (talendEditorID.equals(editor.getSite().getId())) {
            // TextEditor talendEditor = (TextEditor) editor;
            RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
            Item item2 = editorInput.getItem();
            if (item2 != null && item2 instanceof SQLPatternItem && item2.getProperty().getId().equals(item.getProperty().getId())) {
                if (item2.getProperty().getVersion().equals(item.getProperty().getVersion())) {
                    page.bringToTop(editor);
                    found = true;
                    talendEditor = editor;
                    break;
                } else {
                    page.closeEditor(editor, false);
                }
            }
        }
    }
    if (!found) {
        routineSynchronizer.syncSQLPattern(item, true);
        IFile file = routineSynchronizer.getSQLPatternFile(item);
        if (file == null) {
            return null;
        }
        RepositoryEditorInput input = new RepositoryEditorInput(file, item);
        input.setReadOnly(readOnly);
        //$NON-NLS-1$            
        talendEditor = page.openEditor(input, talendEditorID);
    }
    return talendEditor;
}
Also used : RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) IFile(org.eclipse.core.resources.IFile) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IEditorPart(org.eclipse.ui.IEditorPart) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) Item(org.talend.core.model.properties.Item) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)21 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)9 IFile (org.eclipse.core.resources.IFile)7 IEditorPart (org.eclipse.ui.IEditorPart)7 Item (org.talend.core.model.properties.Item)7 SQLPatternItem (org.talend.core.model.properties.SQLPatternItem)7 IEditorInput (org.eclipse.ui.IEditorInput)6 IEditorReference (org.eclipse.ui.IEditorReference)6 PartInitException (org.eclipse.ui.PartInitException)5 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)5 ECodeLanguage (org.talend.core.language.ECodeLanguage)4 CoreException (org.eclipse.core.runtime.CoreException)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 BusinessProcessItem (org.talend.core.model.properties.BusinessProcessItem)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 ISQLPatternSynchronizer (org.talend.designer.codegen.ISQLPatternSynchronizer)3 ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)3 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 IProject (org.eclipse.core.resources.IProject)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2