use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method doSave.
@Override
public void doSave(final IProgressMonitor monitor) {
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
repFactory.lock(item);
} catch (Exception e) {
ExceptionHandler.process(e);
}
ERepositoryStatus status = repFactory.getStatus(item);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage.routine"));
return;
}
EList adapters = item.getProperty().eAdapters();
adapters.remove(dirtyListener);
super.doSave(monitor);
try {
resetItem();
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(((FileEditorInput) getEditorInput()).getFile());
final IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
runProcessService.buildJavaProject();
// check syntax error
addProblems();
//$NON-NLS-1$
String name = "Save Routine";
RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>(name, this) {
@Override
protected void run() throws LoginException, PersistenceException {
refreshJobAndSave(repFactory);
}
};
repositoryWorkUnit.setAvoidSvnUpdate(true);
repositoryWorkUnit.setAvoidUnloadResources(true);
repFactory.executeRepositoryWorkUnit(repositoryWorkUnit);
repositoryWorkUnit.throwPersistenceExceptionIfAny();
// for bug 11930: Unable to save Routines.* in db project
// repFactory.save(item);
// startRefreshJob(repFactory);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class JavaCommandController method createControl.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#createControl
* (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
* org.eclipse.swt.widgets.Control)
*/
@Override
public Control createControl(Composite subComposite, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
Button btnEdit;
//$NON-NLS-1$
btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
FormData data;
btnEdit.setData(NAME, JAVA_COMMAND);
btnEdit.setData(PARAMETER_NAME, param.getName());
btnEdit.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void widgetSelected(SelectionEvent e) {
// execute Java Command
ElementParameter fullParam = (ElementParameter) param;
File jar;
URL url;
try {
List<URL> listURL = new ArrayList<URL>();
ILibraryManagerService libManager = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
IFolder javaLibFolder = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
if (talendProcessJavaProject != null) {
javaLibFolder = talendProcessJavaProject.getLibFolder();
}
}
if (javaLibFolder == null) {
return;
}
for (String jarString : fullParam.getJar().split(";")) {
IPath libPath = javaLibFolder.getLocation();
libManager.retrieve(jarString, libPath.toPortableString(), new NullProgressMonitor());
jar = libPath.append(jarString).toFile();
url = jar.toURL();
listURL.add(url);
}
URLClassLoader urlClassLoader = new URLClassLoader(listURL.toArray(new URL[0]));
Class<?> classLoaded = Class.forName(fullParam.getJavaClass(), true, urlClassLoader);
Object object = classLoaded.newInstance();
List<String> args = new ArrayList<String>();
for (String arg : fullParam.getArgs()) {
args.add(ElementParameterParser.parse(elem, arg));
}
for (Method method : classLoaded.getDeclaredMethods()) {
if (method.getName().equals(fullParam.getJavaFunction())) {
Object[] arglist = new Object[1];
arglist[0] = args.toArray(new String[0]);
method.invoke(object, arglist);
}
}
} catch (Exception e1) {
MessageBoxExceptionHandler.process(e1);
}
}
});
if (elem instanceof Node) {
btnEdit.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
}
CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
data = new FormData();
if (lastControl != null) {
data.left = new FormAttachment(lastControl, 0);
} else {
data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
}
data.top = new FormAttachment(0, top);
labelLabel.setLayoutData(data);
if (numInRow != 1) {
labelLabel.setAlignment(SWT.RIGHT);
}
// **************************
data = new FormData();
int currentLabelWidth = STANDARD_LABEL_WIDTH;
GC gc = new GC(labelLabel);
Point labelSize = gc.stringExtent(param.getDisplayName());
gc.dispose();
if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
}
if (numInRow == 1) {
if (lastControl != null) {
data.left = new FormAttachment(lastControl, currentLabelWidth);
data.right = new FormAttachment(lastControl, currentLabelWidth + STANDARD_BUTTON_WIDTH);
} else {
data.left = new FormAttachment(0, currentLabelWidth);
data.right = new FormAttachment(0, currentLabelWidth + STANDARD_BUTTON_WIDTH);
}
} else {
data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
data.right = new FormAttachment(labelLabel, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
}
data.top = new FormAttachment(0, top);
btnEdit.setLayoutData(data);
// **************************
hashCurControls.put(param.getName(), btnEdit);
Point initialSize = btnEdit.computeSize(SWT.DEFAULT, SWT.DEFAULT);
dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
return btnEdit;
}
use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class MultipleThreadDynamicComposite method operationInThread.
// refactore to be synchonized with the dispose() method because of TDI-24184
// the synchronized methodis a quick fix but not the ideal one because this method is accessing many attributes
// of the current class that may be modified by other thread (just like "elem" modified by the dispose() method.
protected synchronized void operationInThread() {
if (elem == null) {
return;
}
// hywang modified for
List<? extends IElementParameter> listParam = elem.getElementParametersWithChildrens();
Boolean updateNeeded = (Boolean) elem.getPropertyValue(updataComponentParamName);
if (updateNeeded != null) {
if (updateNeeded) {
if (elem != null) {
addComponents(forceRedraw);
elem.setPropertyValue(updataComponentParamName, new Boolean(false));
forceRedraw = false;
}
}
}
final ECodeLanguage language = ((RepositoryContext) org.talend.core.CorePlugin.getContext().getProperty(org.talend.core.context.Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
final ICodeProblemsChecker syntaxChecker = service.getSyntaxChecker(language);
List<Problem> javaProblem = null;
for (int i = 0; i < listParam.size(); i++) {
if (listParam.get(i).getCategory() == section) {
if (listParam.get(i).isShow(listParam)) {
final IElementParameter e = listParam.get(i);
e.isReadOnly();
e.isNoCheck();
if (language == ECodeLanguage.JAVA && javaProblem == null) {
if (!e.isReadOnly() && !e.isNoCheck()) {
javaProblem = syntaxChecker.checkProblems(null);
}
}
final List<Problem> nodePros = javaProblem;
if (generator != null) {
AbstractElementPropertySectionController controller = generator.getController(e.getFieldType(), MultipleThreadDynamicComposite.this);
if (controller != null) {
controller.updateCodeProblems(nodePros);
controller.refresh(e, checkErrorsWhenViewRefreshed);
}
}
}
}
}
if (propertyResized) {
try {
removeListener(SWT.Resize, resizeListener);
getParent().layout();
composite.pack();
propertyResized = false;
addListener(SWT.Resize, resizeListener);
} catch (Exception e) {
}
}
checkErrorsWhenViewRefreshed = false;
// long time = TimeMeasure.timeSinceBegin("DC:refresh:" + getCurrentComponent()); //$NON-NLS-1$
// TimeMeasure.end("DC:refresh:" + getCurrentComponent()); //$NON-NLS-1$
// if (DynamicTabbedPropertySection.DEBUG_TIME) {
// System.out.println("DC;total;" + getCurrentComponent() + ";" + time); //$NON-NLS-1$ //$NON-NLS-2$
// }
}
use of org.talend.designer.runprocess.IRunProcessService in project tesb-studio-se by Talend.
the class JavaCamelJobScriptsExportWSAction method collectBuildArtifacts.
protected void collectBuildArtifacts() throws IOException {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
for (Map.Entry<IRepositoryViewObject, Map<String, File>> e : buildArtifactsMap.entrySet()) {
IRepositoryViewObject repoObject = e.getKey();
Map<String, File> m = e.getValue();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendJobJavaProject(repoObject.getProperty());
String bundleVersion = null;
if (repoObject != null && JobUtils.isJob(repoObject.getProperty())) {
IProcess process = CoreRuntimePlugin.getInstance().getDesignerCoreService().getProcessFromItem(repoObject.getProperty().getItem());
if (process != null && ProcessUtils.isChildRouteProcess(process)) {
bundleVersion = PomIdsHelper.getJobVersion(routeObject.getProperty());
}
} else if (repoObject != null && JobUtils.isRoute(repoObject.getProperty()) && routeObject != null) {
bundleVersion = PomIdsHelper.getJobVersion(routeObject.getProperty());
}
for (Map.Entry<String, File> e1 : m.entrySet()) {
String extension = e1.getKey();
if (extension != null && extension.equalsIgnoreCase("jar") && bundleVersion != null) {
extension = "-" + bundleVersion + "." + extension;
}
File destination = e1.getValue();
List<File> fileList = new ArrayList<File>();
FilesUtils.getAllFilesFromFolder(talendProcessJavaProject.getTargetFolder().getLocation().toFile(), fileList, null);
if (!fileList.isEmpty()) {
for (File f : fileList) {
if (f.isFile() && f.getName().endsWith(extension) && destination != null && StringUtils.isNotBlank(destination.getPath())) {
if (!"classpath.jar".equalsIgnoreCase(f.getName())) {
FilesUtils.copyFile(f, destination);
break;
}
}
}
}
}
}
}
use of org.talend.designer.runprocess.IRunProcessService in project tesb-studio-se by Talend.
the class RouteResourceUtil method synchronizeRouteResource.
public static Collection<IPath> synchronizeRouteResource(final ProcessItem item) {
final boolean routelet;
if (item.eClass() == CamelPropertiesPackage.Literals.CAMEL_PROCESS_ITEM) {
routelet = false;
} else if (item.eClass() == CamelPropertiesPackage.Literals.ROUTELET_PROCESS_ITEM) {
routelet = true;
} else {
return null;
}
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
return null;
}
final IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
final ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendJobJavaProject(item.getProperty());
if (talendProcessJavaProject == null) {
return null;
}
final IFolder routeExternalResourceFolder = talendProcessJavaProject.getExternalResourcesFolder();
final IFolder routeResourceFolder = talendProcessJavaProject.getResourcesFolder();
final Collection<IPath> result = new ArrayList<IPath>();
// add spring file
if (!routelet) {
final IFolder metaExtInf = routeExternalResourceFolder.getFolder("META-INF/spring/");
final IFolder metaInf = routeResourceFolder.getFolder("META-INF/spring/");
try {
prepareFolder(metaExtInf);
prepareFolder(metaInf);
final IFile springExt = metaExtInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
final IFile spring = metaInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
final InputStream inputStream = new ByteArrayInputStream(((CamelProcessItem) item).getSpringContent().getBytes());
routeExternalResourceFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
routeResourceFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
if (springExt.exists()) {
springExt.setContents(inputStream, 0, null);
} else {
springExt.create(inputStream, true, null);
}
result.add(springExt.getLocation());
if (spring.exists()) {
spring.setContents(springExt.getContents(), 0, null);
} else {
spring.create(springExt.getContents(), true, null);
}
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
for (ResourceDependencyModel model : getResourceDependencies(item)) {
IFile file = copyResources(routeExternalResourceFolder, model);
String itemName = getItemName(model.getItem()) + file.getName();
if (file != null) {
try {
FilesUtils.copyFile(file.getLocation().toFile(), new File(talendProcessJavaProject.getBundleResourcesFolder().getLocation().toOSString() + File.separator + RESOURCES + File.separator + itemName));
FilesUtils.copyFile(file.getLocation().toFile(), new File(talendProcessJavaProject.getResourcesFolder().getLocation().toOSString() + File.separator + itemName));
} catch (IOException e) {
e.printStackTrace();
}
result.add(file.getLocation());
}
}
return result;
}
Aggregations