use of org.talend.designer.codegen.ICodeGeneratorService in project tdi-studio-se by Talend.
the class LogRowNode method getGeneratedCode.
/*
* (non-Java)
*
* @see org.talend.core.model.process.INode#getGeneratedCode()
*/
public String getGeneratedCode() {
String generatedCode;
try {
ICodeGeneratorService service = PluginUtils.getCodeGeneratorService();
generatedCode = service.createCodeGenerator().generateComponentCode(this, ECodePart.MAIN);
} catch (SystemException e) {
generatedCode = null;
}
return generatedCode;
}
use of org.talend.designer.codegen.ICodeGeneratorService in project tdi-studio-se by Talend.
the class ImportItemUtil method getRoutineSynchronizer.
// private void applyMigrationTasks(ItemRecord itemRecord, IProgressMonitor monitor) {
// Context ctx = CorePlugin.getContext();
// RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
// ITalendSynchronizer routineSynchronizer = getRoutineSynchronizer();
//
// ERepositoryObjectType repositoryType = itemRecord.getRepositoryType();
//
// Item item = null;
// try {
// List<IRepositoryViewObject> allVersion = ProxyRepositoryFactory.getInstance().getAllVersion(
// ProjectManager.getInstance().getCurrentProject(), itemRecord.getItemId(), itemRecord.getImportPath(),
// repositoryType);
// for (IRepositoryViewObject repositoryObject : allVersion) {
// if (repositoryObject.getProperty().getVersion().equals(itemRecord.getItemVersion())) {
// item = repositoryObject.getProperty().getItem();
// }
// }
// } catch (Exception e) {
// logError(e);
// }
//
// if (item == null) {
// return;
// }
//
// List<IProjectMigrationTask> toExecute = new ArrayList<IProjectMigrationTask>();
// for (String taskId : itemRecord.getMigrationTasksToApply()) {
// IProjectMigrationTask task = GetTasksHelper.getInstance().getProjectTask(taskId);
// if (task == null) {
// log.warn(Messages.getString("ImportItemUtil.taskLogWarn", taskId)); //$NON-NLS-1$
// } else if (!task.isDeprecated()) {
// toExecute.add(task);
// }
//
// }
// Collections.sort(toExecute, new Comparator<IProjectMigrationTask>() {
//
// public int compare(IProjectMigrationTask o1, IProjectMigrationTask o2) {
// return o1.getOrder().compareTo(o2.getOrder());
// }
// });
//
// IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
//
// for (IProjectMigrationTask task : toExecute) {
// monitor.subTask(Messages.getString("ImportItemUtil.taskMonitor", task.getName(), itemRecord.getItemName())); //$NON-NLS-1$
// try {
// // in case the resource has been modified (see MergeTosMetadataMigrationTask for example)
// if ((item.getProperty().eResource() == null || item.eResource() == null)) {
// Property updatedProperty = factory.reload(item.getProperty());
// item = updatedProperty.getItem();
// }
//
// if (item != null) {
// ExecutionResult executionResult = task.execute(repositoryContext.getProject(), item);
// if (executionResult == ExecutionResult.FAILURE) {
// log.warn(Messages.getString("ImportItemUtil.itemLogWarn", itemRecord.getItemName(), task.getName())); //$NON-NLS-1$
// // TODO smallet add a warning/error to the job using
// // model
// }
// }
// } catch (Exception e) {
// log.warn(Messages.getString("ImportItemUtil.itemLogException", itemRecord.getItemName(), task.getName()), e); //$NON-NLS-1$
// try {
// factory.deleteObjectPhysical(new RepositoryObject(item.getProperty()));
// break;// stop migrating the object it has be deleted
// } catch (PersistenceException e1) {
// log.error("Could not delete physical item(" + item.getProperty().getLabel() + "), Project may be corrupted.",
// e);
// }
// }
// }
//
// try {
// if (item != null && item instanceof RoutineItem) {
// RoutineUtils.changeRoutinesPackage(item);
// RoutineItem routineItem = (RoutineItem) item;
// routineSynchronizer.forceSyncRoutine(routineItem);
// routineSynchronizer.syncRoutine(routineItem, true);
// routineSynchronizer.getFile(routineItem);
// }
// // if (item.getProperty().eResource().isModified()) {
// // ProxyRepositoryFactory.getInstance().save(item, true);
// // item.getProperty().eResource().setModified(false);
// // }
// if (item.getProperty().eResource() != null) {
// ProxyRepositoryFactory.getInstance().unloadResources(item.getProperty());
// if (item.getParent() != null && item.getParent() instanceof FolderItem) {
// ((FolderItem) item.getParent()).getChildren().remove(item);
// item.setParent(null);
// }
// }
//
// itemRecord.setExistingItemWithSameId(null);
// itemRecord.clear();
//
// } catch (Exception e) {
// logError(e);
// }
// }
private ITalendSynchronizer getRoutineSynchronizer() {
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
ITalendSynchronizer routineSynchronizer = null;
switch(lang) {
case JAVA:
routineSynchronizer = service.createJavaRoutineSynchronizer();
break;
case PERL:
routineSynchronizer = service.createPerlRoutineSynchronizer();
break;
default:
//$NON-NLS-1$
throw new UnsupportedOperationException(Messages.getString("ImportItemUtil.unknowException", lang));
}
return routineSynchronizer;
}
use of org.talend.designer.codegen.ICodeGeneratorService in project tdi-studio-se by Talend.
the class SaveAsSQLPatternAction method run.
@Override
public void run() {
SaveAsSQLPatternWizard processWizard = new SaveAsSQLPatternWizard(editorPart);
WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
if (dlg.open() == Window.OK) {
try {
SQLPatternItem sqlpatternItem = processWizard.getSQLPatternItem();
// get the IFile
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
// only for talend java version
ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
IFile file = sqlPatternSynchronizer.getSQLPatternFile(sqlpatternItem);
if (file == null) {
return;
}
// Set readonly to false since created job will always be editable.
RepositoryEditorInput repositoryEditorInput = new RepositoryEditorInput(file, sqlpatternItem);
IWorkbenchPage page = getActivePage();
IRepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(repositoryEditorInput.getItem().getProperty().getId(), false);
repositoryEditorInput.setRepositoryNode(repositoryNode);
// here really do the normal save as function
IDocumentProvider provider = ((StandAloneTalendJavaEditor) this.editorPart).getDocumentProvider();
provider.aboutToChange(repositoryEditorInput);
provider.saveDocument(null, repositoryEditorInput, provider.getDocument(this.editorPart.getEditorInput()), true);
provider.changed(repositoryEditorInput);
// copy back from the *.java file to *.item file.
// @see:StandAloneTalendJavaEditor.doSave(IProgressMonitor monitor)
ByteArray byteArray = sqlpatternItem.getContent();
byteArray.setInnerContentFromFile(repositoryEditorInput.getFile());
IProxyRepositoryFactory repFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
repFactory.save(sqlpatternItem);
// close the old editor
page.closeEditor(this.editorPart, false);
// open the new editor, because at the same time, there will update the jobSetting/componentSetting view
page.openEditor(repositoryEditorInput, StandAloneTalendJavaEditor.ID, true);
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "SQLTemplate could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
}
}
use of org.talend.designer.codegen.ICodeGeneratorService in project tdi-studio-se by Talend.
the class SaveAsRoutineAction method run.
@Override
public void run() {
SaveAsRoutineWizard processWizard = new SaveAsRoutineWizard(editorPart);
WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
if (dlg.open() == Window.OK) {
try {
RoutineItem routineItem = processWizard.getRoutineItem();
// get the IFile
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
ITalendSynchronizer routineSynchronizer = null;
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
routineSynchronizer = service.createJavaRoutineSynchronizer();
break;
case PERL:
routineSynchronizer = service.createPerlRoutineSynchronizer();
break;
default:
}
IFile file = routineSynchronizer.getFile(routineItem);
if (file == null) {
return;
}
// Set readonly to false since created job will always be editable.
RoutineEditorInput routineEditorInput = new RoutineEditorInput(file, routineItem);
IWorkbenchPage page = getActivePage();
IRepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(routineEditorInput.getItem().getProperty().getId(), false);
routineEditorInput.setRepositoryNode(repositoryNode);
// here really do the normal save as function
IDocumentProvider provider = ((AbstractTextEditor) this.editorPart).getDocumentProvider();
provider.aboutToChange(routineEditorInput);
provider.saveDocument(null, routineEditorInput, provider.getDocument(this.editorPart.getEditorInput()), true);
provider.changed(routineEditorInput);
// copy back from the *.java file to *.item file.
// @see:StandAloneTalendJavaEditor.doSave(IProgressMonitor monitor)
ByteArray byteArray = routineItem.getContent();
byteArray.setInnerContentFromFile(routineEditorInput.getFile());
IProxyRepositoryFactory repFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
repFactory.save(routineItem);
// close the old editor
page.closeEditor(this.editorPart, false);
// open the new editor, because at the same time, there will update the jobSetting/componentSetting view
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
page.openEditor(routineEditorInput, StandAloneTalendJavaEditor.ID, true);
break;
default:
}
} catch (Exception e) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "Routine could not be saved" + " : " + e.getMessage());
ExceptionHandler.process(e);
}
}
}
use of org.talend.designer.codegen.ICodeGeneratorService in project tdi-studio-se by Talend.
the class ShadowNode method getGeneratedCode.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.process.INode#getGeneratedCode()
*/
public String getGeneratedCode() {
String generatedCode;
try {
ICodeGeneratorService service = RunProcessPlugin.getDefault().getCodeGeneratorService();
generatedCode = service.createCodeGenerator().generateComponentCode(this, ECodePart.MAIN);
} catch (SystemException e) {
generatedCode = null;
}
return generatedCode;
}
Aggregations