use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class TableController method updateContextList.
private void updateContextList(IElementParameter param) {
List<String> contextParameterNamesList = new ArrayList<String>();
IElementParameter processTypeParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
if (processTypeParam == null) {
processTypeParam = elem.getElementParameterFromField(EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE);
if (processTypeParam == null) {
return;
}
}
boolean haveContextParamList = false;
for (Object valueParam : param.getListItemsValue()) {
if (valueParam instanceof IElementParameter) {
IElementParameter vParam = (IElementParameter) valueParam;
if (vParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
haveContextParamList = true;
break;
}
}
}
if (!haveContextParamList) {
return;
}
IElementParameter jobElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
IElementParameter jobVersionParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_VERSION.getName());
IElementParameter contextElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_CONTEXT.getName());
// get context list
String processId = (String) jobElemParam.getValue();
String contextName = (String) contextElemParam.getValue();
if (contextName == null) {
contextName = new String();
}
if (processId == null || contextName == null) {
revertToolBarButtonState(false);
return;
}
IElementParameter useDynamic = elem.getElementParameter("USE_DYNAMIC_JOB");
if (useDynamic != null && Boolean.valueOf(String.valueOf(useDynamic.getValue()))) {
String[] split = processId.split(";");
processId = split[0];
}
ProcessItem processItem = ItemCacheManager.getProcessItem(processId, (String) jobVersionParam.getValue());
String[] contextParameterNames = null;
if (processItem != null) {
// achen modify to fix bug 0006107
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
// process = new Process(processItem.getProperty());
// process.loadXmlFile();
IContextManager contextManager = service.getProcessContextFromItem(processItem);
if (contextManager != null) {
IContext context = contextManager.getContext(contextName);
for (IContextParameter contextParam : context.getContextParameterList()) {
contextParameterNamesList.add(contextParam.getName());
}
}
contextParameterNames = contextParameterNamesList.toArray(new String[0]);
}
if (contextParameterNames == null || contextParameterNames.length == 0) {
contextParameterNamesList.clear();
// we rerebuild the list here from what was saved in the job before
for (HashMap<String, Object> values : (List<HashMap<String, Object>>) param.getValue()) {
//$NON-NLS-1$
String name = (String) values.get("PARAM_NAME_COLUMN");
contextParameterNamesList.add(name);
}
contextParameterNames = contextParameterNamesList.toArray(new String[0]);
}
// update table values
TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
Object[] itemsValue = param.getListItemsValue();
if (tableViewerCreator != null) {
List colList = tableViewerCreator.getColumns();
for (int j = 0; j < itemsValue.length; j++) {
if ((j + 1) >= colList.size()) {
break;
}
if (itemsValue[j] instanceof IElementParameter) {
IElementParameter tmpParam = (IElementParameter) itemsValue[j];
if (tmpParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
tmpParam.setListItemsDisplayCodeName(contextParameterNames);
tmpParam.setListItemsDisplayName(contextParameterNames);
tmpParam.setListItemsValue(contextParameterNames);
// TDI-35251 won't set default, if not fount, keep error
// if (contextParameterNames.length > 0) {
// tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
// } else {
//$NON-NLS-1$
tmpParam.setDefaultClosedListValue("");
// }
// j + 1 because first column is masked
TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
CCombo combo = (CCombo) column.getCellEditor().getControl();
String[] oldItems = combo.getItems();
combo.setItems(contextParameterNames);
List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
String[] items = param.getListItemsDisplayCodeName();
for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
Map<String, Object> currentLine = paramValues.get(currentIndex);
Object o = currentLine.get(items[j]);
if (o instanceof Integer) {
Integer nb = (Integer) o;
if ((nb >= oldItems.length) || (nb == -1)) {
currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
} else {
currentLine.put(items[j], oldItems[nb]);
}
} else {
if (o instanceof String) {
Integer nb = new Integer(tmpParam.getIndexOfItemFromList((String) o));
if (nb == -1 && !"".equals(tmpParam.getDefaultClosedListValue())) {
currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
}
}
}
}
}
}
}
}
// (bug 3740)
boolean checked = contextParameterNames != null && contextParameterNames.length > 0;
revertToolBarButtonState(checked);
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class SapSchemaTypeController method copySchemaFromChildJob.
/**
* DOC hcw Comment method "copySchemaFromChildJob".
*
* @param runJobNode
* @param item
*/
private void copySchemaFromChildJob(Node runJobNode, final Item item) {
// 0004322: tRunJob can import the tBufferOutput schema from the son job
if (runJobNode != null && item instanceof ProcessItem) {
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
IProcess process = service.getProcessFromProcessItem((ProcessItem) item);
List<? extends INode> graphicalNodes = process.getGraphicalNodes();
for (INode node : graphicalNodes) {
if ((node != null) && node.getComponent().getName().equals("tBufferOutput")) {
//$NON-NLS-1$
List<IMetadataTable> list = node.getMetadataList();
if (list.size() > 0) {
List<IMetadataTable> metadata = runJobNode.getMetadataList();
if (metadata.size() == 0) {
metadata.add(list.get(0).clone());
} else {
IMetadataTable table = metadata.get(0);
// clear schema of tRunJob, so we will replace with schema of tBufferOutput
table.getListColumns().clear();
List<IMetadataColumn> columns = list.get(0).getListColumns();
for (IMetadataColumn col : columns) {
table.getListColumns().add(col.clone());
}
}
// skip other tBufferOutput component
break;
}
}
}
}
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class Problems method addRoutineFile.
public static List<Information> addRoutineFile(IFile file, final Property property, boolean... fromJob) {
if (file == null) {
return Collections.emptyList();
}
String routineFileName = null;
String version = null;
if (property == null) {
routineFileName = getFileName(file);
} else {
routineFileName = property.getLabel();
version = property.getVersion();
}
ProblemType type = ProblemType.NONE;
if (property.getItem() instanceof RoutineItem) {
type = ProblemType.ROUTINE;
} else if (property.getItem() instanceof ProcessItem) {
type = ProblemType.JOB;
}
List<Information> listInfos = addRoutineFile(file, type, routineFileName, version, fromJob);
if (property == null || listInfos == null) {
return Collections.emptyList();
}
return listInfos;
}
use of org.talend.core.model.properties.ProcessItem 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;
}
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method refreshProcess.
/**
* Refresh the editor/process to the given refreshedItem version
*
* @param refreshedItem
* @param force
*/
private void refreshProcess(final Item refreshedItem, boolean force) {
Item currentItem = processEditorInput.getItem();
if (isStorageVersionChanged(refreshedItem, currentItem) || force) {
processEditorInput.setItem(refreshedItem);
final IProcess2 process = processEditorInput.getLoadedProcess();
getSite().getShell().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
process.setProperty(refreshedItem.getProperty());
process.updateProperties();
ProcessType processType = null;
if (refreshedItem instanceof ProcessItem) {
processType = ((ProcessItem) refreshedItem).getProcess();
} else if (refreshedItem instanceof JobletProcessItem) {
processType = ((JobletProcessItem) refreshedItem).getJobletProcess();
} else {
//$NON-NLS-1$
ExceptionHandler.process(new Exception("Mismatched case"));
}
if (processType != null) {
((Process) process).updateProcess(processType);
}
process.refreshProcess();
revisionChanged = true;
setName();
}
});
}
}
Aggregations