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;
}
Aggregations