use of org.talend.core.services.ICreateXtextProcessService in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method turnToJobScriptPage.
protected void turnToJobScriptPage(int newPageIndex) {
if (jobletEditor != getEditor(newPageIndex)) {
return;
}
ICreateXtextProcessService convertJobtoScriptService = CorePlugin.getDefault().getCreateXtextProcessService();
try {
final String scriptValue = convertJobtoScriptService.convertJobtoScript(getProcess().saveXmlFile());
IFile file = (IFile) jobletEditor.getEditorInput().getAdapter(IResource.class);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(scriptValue.getBytes());
if (file.exists()) {
jobletEditor.getDocumentProvider().getDocument(jobletEditor.getEditorInput()).set(scriptValue);
boolean isProcessReadOnly = ((JobEditorInput) getEditor(0).getEditorInput()).isReadOnly();
IProxyRepositoryFactory rFactory = ProxyRepositoryFactory.getInstance();
if (isProcessReadOnly || rFactory.isUserReadOnlyOnCurrentProject()) {
IDocumentProvider provider = jobletEditor.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);
}
//$NON-NLS-1$
IAction action = jobletEditor.getAction("FoldingRestore");
action.run();
jobletEditor.doSave(null);
} else {
file.create(byteArrayInputStream, true, null);
}
if (propertyListener == null) {
propertyListener = new IPropertyListener() {
@Override
public void propertyChanged(Object source, int propId) {
if (source instanceof IEditorPart && ((IEditorPart) source).isDirty()) {
getProcess().setProcessModified(true);
getProcess().setNeedRegenerateCode(true);
}
}
};
jobletEditor.addPropertyListener(propertyListener);
}
} catch (PartInitException e) {
ExceptionHandler.process(e);
} catch (CoreException e) {
ExceptionHandler.process(e);
} catch (IOException 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);
}
changeContextsViewStatus(false);
}
use of org.talend.core.services.ICreateXtextProcessService in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method covertJobscriptOnPageChange.
private void covertJobscriptOnPageChange() {
try {
boolean isDirty = jobletEditor.isDirty();
jobletEditor.doSave(null);
IProcess2 oldProcess = getProcess();
ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
Item item = oldProcess.getProperty().getItem();
ProcessType processType = null;
if (item instanceof ProcessItem) {
processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
} else if (item instanceof JobletProcessItem) {
processType = n.convertJobletDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
}
if (item instanceof ProcessItem) {
((Process) oldProcess).updateProcess(processType);
} else if (item instanceof JobletProcessItem) {
((Process) oldProcess).updateProcess(processType);
}
oldProcess.getUpdateManager().updateAll();
designerEditor.setDirty(isDirty);
List<Node> nodes = (List<Node>) oldProcess.getGraphicalNodes();
List<Node> newNodes = new ArrayList<Node>();
newNodes.addAll(nodes);
for (Node node : newNodes) {
node.getProcess().checkStartNodes();
node.checkAndRefreshNode();
IElementParameter ep = node.getElementParameter("ACTIVATE");
if (ep != null && ep.getValue().equals(Boolean.FALSE)) {
node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
} else if (ep != null && ep.getValue().equals(Boolean.TRUE)) {
node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
}
for (IElementParameter param : node.getElementParameters()) {
if (!param.getChildParameters().isEmpty()) {
if (param.getValue() != null && param.getValue() instanceof String && ((String) param.getValue()).contains(":")) {
String[] splited = ((String) param.getValue()).split(":");
String childNameNeeded = splited[0].trim();
String valueChild = TalendQuoteUtils.removeQuotes(splited[1].trim());
if (param.getChildParameters().containsKey(childNameNeeded)) {
param.getChildParameters().get(childNameNeeded).setValue(valueChild);
}
}
}
}
if (node.getNodeContainer() instanceof JobletContainer) {
JobletContainer jc = (JobletContainer) node.getNodeContainer();
if (node.isMapReduceStart()) {
//$NON-NLS-1$
jc.updateState("UPDATE_STATUS", "", jc.getPercentMap(), jc.getPercentReduce());
}
}
}
} catch (PersistenceException e) {
}
}
use of org.talend.core.services.ICreateXtextProcessService in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method doSave.
/**
* Saves the multi-page editor's document.
*/
@Override
public void doSave(final IProgressMonitor monitor) {
Item curItem = getProcess().getProperty().getItem();
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
try {
// For TDI-23825, if not lock by user try to lock again.
if (!getProcess().isReadOnly()) {
repFactory.lock(curItem);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
if (getProcess().isReadOnly() || repFactory.isUserReadOnlyOnCurrentProject()) {
MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.readonly"), Messages.getString("AbstractMultiPageTalendEditor.readonlyMessage"));
return;
}
ERepositoryStatus status = repFactory.getStatus(curItem);
if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
MessageDialog.openWarning(getEditor(0).getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage"));
return;
}
if (!isDirty()) {
return;
}
Map<String, Boolean> jobletMap = new HashMap<String, Boolean>();
changeCollapsedState(true, jobletMap);
updateRunJobContext();
designerEditor.getProcess().getProperty().eAdapters().remove(dirtyListener);
repFactory.addRepositoryWorkUnitListener(repositoryWorkListener);
if (jobletEditor == getActiveEditor()) {
boolean isDirty = jobletEditor.isDirty();
refreshPropertyDirtyStatus();
jobletEditor.doSave(monitor);
try {
IProcess2 oldProcess = getProcess();
ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
ProcessType processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
IProcess2 newProcess = null;
Item item = getProcess().getProperty().getItem();
if (item instanceof ProcessItem) {
((Process) designerEditor.getProcess()).updateProcess(processType);
if (isDirty) {
getProcess().setProcessModified(true);
getProcess().setNeedRegenerateCode(true);
}
} else if (item instanceof JobletProcessItem) {
AbstractProcessProvider processProvider = AbstractProcessProvider.findProcessProviderFromPID(IComponent.JOBLET_PID);
if (processProvider != null) {
newProcess = processProvider.buildNewGraphicProcess(item);
}
designerEditor.setProcess(newProcess);
Boolean lastVersion = null;
if (oldProcess instanceof ILastVersionChecker) {
lastVersion = ((ILastVersionChecker) oldProcess).isLastVersion(item);
}
if (designerEditor.getEditorInput() instanceof JobEditorInput) {
((JobEditorInput) designerEditor.getEditorInput()).checkInit(lastVersion, null, true);
}
}
getEditor(0).doSave(monitor);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
} else {
refreshPropertyDirtyStatus();
getEditor(0).doSave(monitor);
}
/*
* refresh should be executed before add the listener,or it will has eProxy on the property,it will cause a
* editor dirty problem. hywang commet bug 17357
*/
if (processEditorInput != null) {
propertyInformation = new ArrayList(processEditorInput.getItem().getProperty().getInformations());
propertyIsDirty = false;
}
if (designerEditor != null && dirtyListener != null) {
designerEditor.getProcess().getProperty().eAdapters().add(dirtyListener);
}
refreshJobSettingsView();
changeCollapsedState(false, jobletMap);
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
testContainerService.updateDetect(getProcess(), false);
}
}
if (isCheckout) {
CommandStack stack = (CommandStack) getAdapter(CommandStack.class);
stack.flush();
isCheckout = false;
}
}
Aggregations