use of org.talend.core.model.properties.JobScriptItem in project tdi-studio-se by Talend.
the class ChangeJobscriptContentValueMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (item instanceof JobScriptItem) {
byte[] bytes = ((JobScriptItem) item).getContent().getInnerContent();
String message = new String(bytes);
message = message.replaceAll("PATTREN", "PATTERN");
try {
ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
byteArray.setInnerContent(message.getBytes());
((JobScriptItem) item).setContent(byteArray);
factory.save(item, true);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.SUCCESS_NO_ALERT;
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.JobScriptItem in project tdi-studio-se by Talend.
the class OpenExistVersionProcessWizard method openAnotherVersion.
protected void openAnotherVersion(final RepositoryNode node, final boolean readonly) {
try {
if (node.getObject() != null) {
final Item item = node.getObject().getProperty().getItem();
final IWorkbenchPage page = getActivePage();
final RepositoryEditorInput fileEditorInput = getEditorInput(item, readonly, page);
if (fileEditorInput != null) {
IEditorPart editorPart = page.findEditor(fileEditorInput);
if (editorPart == null) {
fileEditorInput.setRepositoryNode(node);
if (item instanceof ProcessItem) {
page.openEditor(fileEditorInput, MultiPageTalendEditor.ID, readonly);
} else if (item instanceof BusinessProcessItem) {
CorePlugin.getDefault().getDiagramModelService().openBusinessDiagramEditor(page, fileEditorInput);
} else {
ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
//$NON-NLS-1$ //$NON-NLS-2$
String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor";
page.openEditor(fileEditorInput, talendEditorID);
}
} else {
page.activate(editorPart);
}
} else {
// TDI-19014:open another version of jobScript
if (item instanceof JobScriptItem) {
IProject fsProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
openXtextEditor(node, fsProject, readonly);
}
}
}
} catch (PartInitException e) {
MessageBoxExceptionHandler.process(e);
} catch (SystemException e) {
MessageBoxExceptionHandler.process(e);
}
}
use of org.talend.core.model.properties.JobScriptItem 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);
}
}
use of org.talend.core.model.properties.JobScriptItem in project tdi-studio-se by Talend.
the class EditPropertiesAction method init.
@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
boolean canWork = selection.size() == 1;
if (canWork) {
Object o = selection.getFirstElement();
if (o instanceof IRepositoryNode) {
IRepositoryNode node = (IRepositoryNode) o;
switch(node.getType()) {
case REPOSITORY_ELEMENT:
if (node.getObjectType() == ERepositoryObjectType.BUSINESS_PROCESS || node.getObjectType() == ERepositoryObjectType.PROCESS) {
canWork = true;
} else if (node.getObjectType() == ERepositoryObjectType.ROUTINES) {
Item item = node.getObject().getProperty().getItem();
if (item instanceof RoutineItem) {
canWork = !((RoutineItem) item).isBuiltIn();
} else {
canWork = false;
}
} else if (node.getObjectType() == ERepositoryObjectType.SQLPATTERNS) {
Item item = node.getObject().getProperty().getItem();
if (item instanceof SQLPatternItem) {
canWork = !((SQLPatternItem) item).isSystem();
} else {
canWork = false;
}
} else if (node.getObjectType() == ERepositoryObjectType.JOB_SCRIPT) {
Item item = node.getObject().getProperty().getItem();
if (item instanceof JobScriptItem) {
canWork = true;
} else {
canWork = false;
}
} else {
canWork = isInstanceofCamelRoutes(node.getObjectType()) || isInstanceofCamelBeans(node.getObjectType());
}
break;
default:
canWork = false;
break;
}
if (canWork) {
canWork = (node.getObject().getRepositoryStatus() != ERepositoryStatus.DELETED);
}
if (canWork) {
canWork = isLastVersion(node);
}
}
}
setEnabled(canWork);
}
Aggregations