use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel in project tdi-studio-se by Talend.
the class AbstractJSONStepForm method exportAsContext.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.swt.utils.AbstractForm#exportAsContext()
*/
@Override
protected void exportAsContext() {
if (hasContextBtn() && connectionItem != null) {
if (isContextMode()) {
JSONConnectionContextHelper.openInConetxtModeDialog();
} else {
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = JSONConnectionContextHelper.exportAsContext(connectionItem, getConetxtParams());
contextManager = JSONConnectionContextHelper.contextManager;
if (variableModels != null) {
Iterator<ContextItem> contextItor = variableModels.keySet().iterator();
while (contextItor.hasNext()) {
ContextItem contextItem = contextItor.next();
List<ConectionAdaptContextVariableModel> apaptModels = variableModels.get(contextItem);
if (contextItem != null && apaptModels.size() == 0) {
// create
if (contextManager instanceof JobContextManager) {
Map<String, String> map = ((JobContextManager) contextManager).getNameMap();
// set properties for context mode
JSONConnectionContextHelper.setPropertiesForContextMode(connectionItem, contextItem, getConetxtParams(), map);
}
} else {
// set properties for exist context
JSONConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, getConetxtParams(), variableModels);
}
// refresh current UI.
initialize();
adaptFormToEditable();
}
}
}
}
}
use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method setJSONFilePropertiesForExistContextMode.
static void setJSONFilePropertiesForExistContextMode(JSONFileConnection jsonConn, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> map) {
if (jsonConn == null) {
return;
}
String jsonVariableName = null;
for (IConnParamName param : paramSet) {
if (param instanceof EParamName) {
EParamName jsonParam = (EParamName) param;
if (map != null && map.size() > 0) {
for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : map.entrySet()) {
List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
for (ConectionAdaptContextVariableModel model : modelList) {
if (model.getValue().equals(jsonParam.name())) {
jsonVariableName = model.getName();
break;
}
}
}
}
if (jsonConn.isInputModel()) {
switch(jsonParam) {
case FilePath:
jsonConn.setJSONFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
break;
case Encoding:
jsonConn.setEncoding(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
break;
case XPathQuery:
EList schema = jsonConn.getSchema();
if (schema != null) {
if (schema.get(0) instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor descriptor = (JSONXPathLoopDescriptor) schema.get(0);
descriptor.setAbsoluteXPathQuery(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
}
}
default:
}
} else {
if (jsonParam.equals(EParamName.OutputFilePath)) {
jsonConn.setOutputFilePath(ContextParameterUtils.getNewScriptCode(jsonVariableName, LANGUAGE));
}
}
}
}
}
use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method exportAsContext.
/**
*
* ggu Comment method "exportAsContext".
*
*/
public static Map<ContextItem, List<ConectionAdaptContextVariableModel>> exportAsContext(ConnectionItem connItem, Set<IConnParamName> paramSet) {
if (connItem == null) {
return null;
}
List<IContextParameter> varList = createContextParameters(connItem, paramSet);
if (varList == null || varList.isEmpty()) {
return null;
}
String contextName = convertContextLabel(connItem.getProperty().getLabel());
ISelection selection = getRepositoryContext(contextName, false);
if (selection == null) {
return null;
}
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableContextMap = new HashMap();
List<ConectionAdaptContextVariableModel> models = new ArrayList<ConectionAdaptContextVariableModel>();
Set<String> connectionVaribles = getConnVariables(connItem, paramSet);
ContextModeWizard contextWizard = new ContextModeWizard(contextName, selection.isEmpty(), selection, varList, connectionVaribles);
WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), contextWizard);
if (dlg.open() == Window.OK) {
ContextItem contextItem = contextWizard.getContextItem();
models = contextWizard.getAdaptModels();
if (contextItem != null) {
variableContextMap.put(contextItem, models);
}
contextManager = contextWizard.getContextManager();
if (contextItem != null) {
contextItem.getProperty().setLabel(contextName);
}
return variableContextMap;
}
return null;
}
use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel in project tdi-studio-se by Talend.
the class GenericContextHandler method exportContext.
@Override
public boolean exportContext(ConnectionItem connectionItem) {
boolean isContextMode = connectionItem.getConnection().isContextMode();
if (isContextMode) {
ConnectionContextHelper.openInConetxtModeDialog();
} else {
String defaultContextName = ConnectionContextHelper.convertContextLabel(connectionItem.getProperty().getLabel());
if (StringUtils.isEmpty(defaultContextName)) {
//$NON-NLS-1$ //$NON-NLS-2$
MessageDialog.openError(DisplayUtils.getDefaultShell(), Messages.getString("GenericContextHandler.wizardTitle"), Messages.getString("GenericContextHandler.defineConnectionName"));
}
Set<IConnParamName> contextParams = getContextParams();
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = ConnectionContextHelper.exportAsContext(defaultContextName, connectionItem, contextParams);
if (variableModels != null) {
Iterator<ContextItem> contextItor = variableModels.keySet().iterator();
while (contextItor.hasNext()) {
ContextItem contextItem = contextItor.next();
List<ConectionAdaptContextVariableModel> apaptModels = variableModels.get(contextItem);
if (contextItem != null && apaptModels.size() == 0) {
// create
if (ConnectionContextHelper.contextManager instanceof JobContextManager) {
Map<String, String> map = ((JobContextManager) ConnectionContextHelper.contextManager).getNameMap();
// set properties for context mode
ConnectionContextHelper.setPropertiesForContextMode(defaultContextName, connectionItem, contextItem, contextParams, map);
}
} else {
// set properties for exist context
ConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, contextParams, variableModels);
}
}
}
return true;
}
return false;
}
use of org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel in project tdi-studio-se by Talend.
the class GenericContextUtil method setPropertiesForExistContextMode.
public static void setPropertiesForExistContextMode(Connection connection, Set<IConnParamName> paramSet, Map<ContextItem, List<ConectionAdaptContextVariableModel>> adaptMap) {
if (connection == null) {
return;
}
if (connection instanceof GenericConnection) {
GenericConnection genericConn = (GenericConnection) connection;
ComponentProperties componentProperties = getComponentProperties(genericConn);
ContextItem currentContext = null;
for (IConnParamName param : paramSet) {
if (param instanceof GenericConnParamName) {
String genericVariableName = null;
GenericConnParamName genericParam = (GenericConnParamName) param;
if (adaptMap != null && adaptMap.size() > 0) {
for (Map.Entry<ContextItem, List<ConectionAdaptContextVariableModel>> entry : adaptMap.entrySet()) {
currentContext = entry.getKey();
List<ConectionAdaptContextVariableModel> modelList = entry.getValue();
for (ConectionAdaptContextVariableModel model : modelList) {
if (model.getValue().equals(genericParam.getName())) {
genericVariableName = model.getName();
break;
}
}
}
}
if (genericVariableName != null) {
genericVariableName = getCorrectVariableName(currentContext, genericVariableName, genericParam);
matchContextForAttribues(componentProperties, genericParam, genericVariableName);
}
}
}
updateComponentProperties(genericConn, componentProperties);
}
}
Aggregations