use of org.talend.core.model.process.IContextManager in project tdi-studio-se by Talend.
the class UpdateContextParameterCommand method doExecute.
private void doExecute() {
if (result == null) {
return;
}
Object job = result.getJob();
if (job == null) {
return;
}
if (job instanceof IProcess2) {
IProcess2 process = (IProcess2) job;
ContextParameterMap deleteParameters = new ContextParameterMap();
Object updateObject = result.getUpdateObject();
List<IContext> listContext = process.getContextManager().getListContext();
if (updateObject instanceof Set) {
Set<String> names = (Set<String>) updateObject;
if (result.getResultType() == EUpdateResult.ADD && result.isChecked()) {
// check parameters that have been added to repository context group
checkNewRepositoryParameters(process, names);
return;
}
for (IContext context : listContext) {
for (IContextParameter param : context.getContextParameterList()) {
ContextItem item = null;
if (names != null && names.contains(param.getName())) {
switch(result.getResultType()) {
case DELETE:
item = (ContextItem) result.getParameter();
if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
// delete it later
deleteParameters.addParameter(context, param);
} else {
param.setSource(IContextParameter.BUILT_IN);
}
break;
case UPDATE:
item = (ContextItem) result.getParameter();
if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
ContextUtils.updateParameterFromRepository(item, param, context.getName());
} else {
param.setSource(IContextParameter.BUILT_IN);
}
break;
case RENAME:
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
item = (ContextItem) parameter.get(0);
String sourceId = item.getProperty().getId();
String oldName = (String) parameter.get(1);
String newName = (String) parameter.get(2);
if (oldName.equals(param.getName()) && sourceId.equals(param.getSource())) {
if (newName != null) {
param.setName(newName);
ContextUtils.updateParameterFromRepository(item, param, context.getName());
}
}
}
break;
// built-in
case BUIL_IN:
default:
param.setSource(IContextParameter.BUILT_IN);
break;
}
}
}
}
}
if (updateObject instanceof JobContext) {
if (result.getResultType() == EUpdateResult.ADD && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
String name = context.getName();
if (!listContext.contains(context) && result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
JobContext newContext = new JobContext(name);
List<IContextParameter> newParamList = new ArrayList<IContextParameter>();
newContext.setContextParameterList(newParamList);
JobContextParameter param = null;
// add other context params to the new group
for (IContextParameter contextParam : process.getContextManager().getDefaultContext().getContextParameterList()) {
boolean exist = false;
for (IContextParameter existParam : context.getContextParameterList()) {
if (contextParam.getName().equals(existParam.getName())) {
exist = true;
}
}
if (exist) {
continue;
}
param = (JobContextParameter) contextParam.clone();
param.setContext(newContext);
newParamList.add(param);
}
// current context params for the new group
for (int i = 0; i < context.getContextParameterList().size(); i++) {
IContextParameter oldParam = context.getContextParameterList().get(i);
param = (JobContextParameter) oldParam.clone();
param.setSource(item.getProperty().getId());
param.setContext(newContext);
newParamList.add(param);
}
listContext.add(newContext);
}
} else if (result.getResultType() == EUpdateResult.DELETE && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
if (result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
List<IContext> listC = new ArrayList<IContext>(listContext);
for (IContext con : listC) {
if (con.getName().equals(context.getName())) {
for (IContextParameter oldParam : con.getContextParameterList()) {
if (item.getProperty().getId().equals(oldParam.getSource())) {
listContext.remove(con);
}
}
}
}
}
return;
} else if (result.getResultType() == EUpdateResult.RENAME && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
IContextManager contextManager = process.getContextManager();
Map<IContext, String> renameGroupContext = ((JobContextManager) contextManager).getRenameGroupContext();
String oldName = renameGroupContext.get(context);
if (result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
for (IContext con : listContext) {
if (con.getName().equals(oldName)) {
for (IContextParameter oldParam : con.getContextParameterList()) {
if (item.getProperty().getId().equals(oldParam.getSource())) {
con.setName(context.getName());
}
}
}
}
}
}
return;
}
// delete parameters
deleteParameters.removeFromContext();
// update parameters
if (result.getResultType() == EUpdateResult.RENAME) {
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
String oldName = (String) parameter.get(1);
String newName = (String) parameter.get(2);
UpdateContextVariablesHelper.updateProcessForRenamed(process, oldName, newName);
// tRunJob parameters rename
IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
Map<String, String> renamedMap = new HashMap<String, String>();
renamedMap.put(newName, oldName);
UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, renamedMap, process.getId(), null);
try {
// perhaps, need optimize.
UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(DesignerPlugin.getDefault().getProxyRepositoryFactory(), renamedMap, process.getId(), null);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
}
use of org.talend.core.model.process.IContextManager in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createContext.
private void createContext(List<Object> sourceList) {
if (sourceList.size() == 0) {
return;
}
boolean created = false;
for (Object source : sourceList) {
if (source instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) source;
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
EList context = contextItem.getContext();
Set<String> contextSet = new HashSet<String>();
Iterator iterator = context.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextTypeImpl) {
EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
Iterator contextParas = contextParameters.iterator();
while (contextParas.hasNext()) {
ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
String name = contextParameterType.getName();
contextSet.add(name);
}
}
}
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof JobEditorInput) {
JobEditorInput jobInput = (JobEditorInput) editorInput;
IProcess2 process = jobInput.getLoadedProcess();
IContextManager contextManager = process.getContextManager();
List<IContext> listContext = contextManager.getListContext();
// context group will reflect absolutely if no context variable in contextViewer
// if (!ConnectionContextHelper.containsVariable(contextManager)) {
// for bug 15608
// ConnectionContextHelper.addContextVarForJob(process, contextItem, contextManager);
// ConnectionContextHelper.checkAndAddContextsVarDND(contextItem, contextManager);
Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
// show
Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
addedVarsMap.put(item.getProperty().getLabel(), contextSet);
if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
created = true;
}
}
// } else {
// Set<String> addedContext = ConnectionContextHelper.checkAndAddContextVariables(contextItem,
// contextSet, contextManager, false);
// if (addedContext != null && addedContext.size() > 0) {
// ConnectionContextHelper.addContextVarForJob(process, contextItem, contextSet);
// created = true;
// }
// }
}
}
}
}
if (created) {
RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
}
}
use of org.talend.core.model.process.IContextManager in project tdi-studio-se by Talend.
the class RepositoryWebService method parseContextParameter.
private String parseContextParameter(String contextValue) {
String url = "";
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
IContextManager contextManager = connector.getProcess().getContextManager();
String currentDefaultName = contextManager.getDefaultContext().getName();
List contextList = contextManager.getListContext();
if (!contextList.isEmpty() && contextList.size() > 1) {
currentDefaultName = ConnectionContextHelper.getContextTypeForJob(shell, contextManager, false);
}
// ContextSetsSelectionDialog cssd=new ContextSetsSelectionDialog(shell,,false);
// ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(connector);
IContext context = contextManager.getContext(currentDefaultName);
url = ContextParameterUtils.parseScriptContextCode(contextValue, context);
return url;
}
use of org.talend.core.model.process.IContextManager in project tesb-studio-se by Talend.
the class CamelEditorDropTargetListener method createContext.
private void createContext() {
if (selectSourceList.size() == 0) {
return;
}
boolean created = false;
for (Object source : selectSourceList) {
if (source instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) source;
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
EList context = contextItem.getContext();
Set<String> contextSet = new HashSet<String>();
Iterator iterator = context.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextTypeImpl) {
EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
Iterator contextParas = contextParameters.iterator();
while (contextParas.hasNext()) {
ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
String name = contextParameterType.getName();
contextSet.add(name);
}
}
}
IEditorInput editorInput = editor.getEditorInput();
if (editorInput instanceof JobEditorInput) {
JobEditorInput jobInput = (JobEditorInput) editorInput;
IProcess2 process = jobInput.getLoadedProcess();
IContextManager contextManager = process.getContextManager();
List<IContext> listContext = contextManager.getListContext();
Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
// show
Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
addedVarsMap.put(item.getProperty().getLabel(), contextSet);
if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
created = true;
}
} else {
//$NON-NLS-1$
MessageDialog.openInformation(//$NON-NLS-1$
editor.getEditorSite().getShell(), //$NON-NLS-1$
"Adding Context", //$NON-NLS-1$
"Context \"" + contextItem.getProperty().getDisplayName() + "\" already exist.");
}
}
}
}
}
if (created) {
RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
}
}
Aggregations