use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class RepositoryHelper method createTalendItem.
public TalendItem createTalendItem(Repository repository, Object object) {
TalendItem result = null;
if (object instanceof RepositoryNode) {
RepositoryNode repositoryNode = (RepositoryNode) object;
if (repositoryNode.getType() == RepositoryNode.ENodeType.REPOSITORY_ELEMENT) {
IRepositoryViewObject repositoryObject = repositoryNode.getObject();
ERepositoryObjectType nodeType = (ERepositoryObjectType) repositoryNode.getProperties(EProperties.CONTENT_TYPE);
EClass class1 = getEClass(nodeType);
if (class1 != null) {
result = (TalendItem) BusinessFactory.eINSTANCE.create(class1);
result.setRepository(repository);
if (ERepositoryObjectType.METADATA_CON_TABLE.equals(repositoryObject.getRepositoryObjectType())) {
Property property = ((MetadataTableRepositoryObject) repositoryObject).getProperty();
Item item = property.getItem();
if (item instanceof SAPConnectionItem) {
if (repositoryNode.getParent() != null) {
result.setId(property.getId() + " - " + repositoryNode.getParent().getProperties(EProperties.LABEL) + " - " + repositoryObject.getLabel());
}
} else {
//$NON-NLS-1$
result.setId(property.getId() + " - " + repositoryObject.getLabel());
}
} else if (ERepositoryObjectType.METADATA_CON_QUERY.equals(repositoryObject.getRepositoryObjectType())) {
Property property = ((QueryRepositoryObject) repositoryObject).getProperty();
//$NON-NLS-1$
result.setId(property.getId() + " - " + repositoryObject.getLabel());
} else if (ERepositoryObjectType.METADATA_SAP_FUNCTION.equals(repositoryObject.getRepositoryObjectType())) {
Property property = ((SAPFunctionRepositoryObject) repositoryObject).getProperty();
//$NON-NLS-1$
result.setId(property.getId() + " - " + repositoryObject.getLabel());
} else {
result.setId(repositoryObject.getId());
}
result.setLabel(repositoryObject.getLabel());
}
}
}
return result;
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class PropertyTypeController method createComboCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
* .eclipse.swt.custom.CCombo)
*/
@Override
protected Command createComboCommand(CCombo combo) {
Connection repositoryConnection = null;
ConnectionItem repositoryConnectionItem = null;
// hwang add
FileItem repositoryFileItem = null;
String paramName = (String) combo.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
String value = combo.getText();
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
if (value.equals(param.getValue())) {
return null;
}
// Map<String, ConnectionItem> repositoryConnectionItemMap = null;
IElementParameter repositoryParam = null;
// hywang add for feature 6484
Map<String, FileItem> repositoryFileItemMap = null;
if (value.equals(EmfComponent.REPOSITORY)) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
repositoryFileItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryFileItemMap();
}
repositoryParam = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
String connectionSelected = (String) repositoryParam.getValue();
// if (repositoryConnectionItemMap.containsKey(connectionSelected)) {
try {
Item item = null;
if (!StringUtils.isEmpty(connectionSelected)) {
IRepositoryViewObject repobj = factory.getLastVersion(connectionSelected);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnectionItem = (ConnectionItem) factory.getLastVersion(connectionSelected).getProperty().getItem();
repositoryConnection = repositoryConnectionItem.getConnection();
} else {
repositoryConnection = null;
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
// for ruleItem,hywang add
if (repositoryFileItemMap.containsKey(connectionSelected)) {
repositoryFileItem = repositoryFileItemMap.get(connectionSelected);
} else {
if (!repositoryFileItemMap.isEmpty()) {
repositoryFileItem = repositoryFileItemMap.values().iterator().next();
} else {
repositoryFileItem = null;
}
}
}
CompoundCommand cc = new CompoundCommand();
if (repositoryConnectionItem != null) {
initCDC(cc, repositoryConnectionItem);
}
ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, repositoryConnection, paramName, value);
cc.add(changeValuesFromRepository1);
if (repositoryConnection != null) {
ChangeValuesFromRepository changeValuesFromRepository2 = new ChangeValuesFromRepository(elem, repositoryConnection, repositoryParam.getParentParameter().getName() + ":" + repositoryParam.getName(), //$NON-NLS-1$
repositoryConnectionItem.getProperty().getId());
cc.add(changeValuesFromRepository2);
}
// hywang add for feature 6484
if (repositoryFileItem != null) {
final String id = repositoryFileItem.getProperty().getId();
cc.add(new Command() {
@Override
public void execute() {
IElementParameter elementParameter = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName());
if (elementParameter != null) {
elementParameter = elementParameter.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (elementParameter != null) {
elementParameter.setValue(id);
}
}
}
});
}
if (value.equals(EmfComponent.REPOSITORY)) {
updateDBType(cc, repositoryConnection);
}
return cc;
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class QueryTypeController method getGuessQueryCommand.
/**
* DOC nrousseau Comment method "getGuessQueryCommand".
*
* @return
*/
private QueryGuessCommand getGuessQueryCommand() {
// Map<String, IMetadataTable> repositoryTableMap = null;
IMetadataTable newRepositoryMetadata = null;
String realTableName = null;
String realTableId = null;
String schemaName = "";
// Only for getting the real table name.
if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (repositorySchemaTypeParameter != null) {
final Object value = repositorySchemaTypeParameter.getValue();
if (elem instanceof Node) {
/* value can be devided means the value like "connectionid - label" */
String[] keySplitValues = value.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = value.toString().split(" - ")[0];
String tableLabel = value.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
// bug 20365
if (table.getLabel().equals(tableLabel)) {
IMetadataTable repositoryMetadata = ConvertionHelper.convert(table);
realTableName = repositoryMetadata.getTableName();
realTableId = repositoryMetadata.getId();
// }
break;
}
}
}
}
// if (repositoryTableMap.containsKey(value)) {
// IMetadataTable repositoryMetadata = repositoryTableMap.get(value);
// realTableName = repositoryMetadata.getTableName();
// realTableId = repositoryMetadata.getId();
// }
}
}
// }
// }
}
// Ends
Connection repositoryConnection = null;
boolean useExisting = false;
IElementParameter elementParameter = elem.getElementParameter(EParameterName.USE_EXISTING_CONNECTION.name());
if (elem instanceof Node) {
IProcess process = ((Node) elem).getProcess();
if (elementParameter != null && Boolean.valueOf(String.valueOf(elementParameter.getValue()))) {
String connName = (String) elem.getPropertyValue("CONNECTION");
for (INode node : process.getGraphicalNodes()) {
if (node.getElementName().equals(connName)) {
useExisting = true;
final Object propertyValue = node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (propertyValue != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
} else {
initConnectionParameters();
repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
}
}
break;
}
}
}
}
if (!useExisting && elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
final Object propertyValue = elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (propertyValue != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
}
}
} else {
initConnectionParameters();
repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
}
QueryGuessCommand cmd = null;
INode node = null;
if (elem instanceof INode) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
List<IMetadataTable> metadataList = node.getMetadataList();
newRepositoryMetadata = metadataList.get(0);
// for tInformixRow
if (newRepositoryMetadata.getListColumns().size() == 0 && metadataList.size() > 1) {
newRepositoryMetadata = metadataList.get(1);
}
if (newRepositoryMetadata == null) {
String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (schemaSelected != null) {
// repositoryMetadata = repositoryTableMap.get(schemaSelected);
} else if (newRepositoryMetadata == null) {
MessageDialog.openWarning(new Shell(), Messages.getString("QueryTypeController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("QueryTypeController.nothingToGuess"));
return cmd;
}
}
cmd = new QueryGuessCommand(node, newRepositoryMetadata, repositoryConnection);
cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
//$NON-NLS-1$
String type = getValueFromRepositoryName("TYPE");
if ("Oracle".equalsIgnoreCase(type)) {
type = EDatabaseTypeName.ORACLEFORSID.getDisplayName();
}
cmd.setParameters(realTableId, realTableName, type);
return cmd;
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class QueryTypeController method createComboCommand.
/*
* (non-Javadoc)
*
* @see
* org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
* .eclipse.swt.custom.CCombo)
*/
@Override
protected Command createComboCommand(CCombo combo) {
String paramName = (String) combo.getData(PARAMETER_NAME);
IElementParameter param = elem.getElementParameter(paramName);
IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
String name = param.getName();
String value = combo.getText();
for (int j = 0; j < param.getListItemsValue().length; j++) {
if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
value = (String) param.getListItemsValue()[j];
}
}
if (name.equals(EParameterName.QUERYSTORE_TYPE.getName())) {
if (elem instanceof Node) {
String querySelected;
Query repositoryQuery = null;
// Map<String, Query> repositoryQueryStoreMap = this.dynamicProperty.getRepositoryQueryStoreMap();
IElementParameter repositoryParam = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName());
querySelected = (String) repositoryParam.getValue();
/* value can be devided means the value like "connectionid - label" */
String[] keySplitValues = querySelected.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = querySelected.split(" - ")[0];
String queryLabel = querySelected.split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof DatabaseConnectionItem) {
Connection conn = ((DatabaseConnectionItem) item).getConnection();
if (conn instanceof DatabaseConnection) {
DatabaseConnection dbconn = (DatabaseConnection) conn;
QueriesConnection queryConnection = dbconn.getQueries();
for (Query query : queryConnection.getQuery()) {
if (query.getLabel().equals(queryLabel)) {
repositoryQuery = query;
break;
}
}
}
}
}
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
if (repositoryQuery != null) {
return new RepositoryChangeQueryCommand(elem, repositoryQuery, name, value);
} else {
return new PropertyChangeCommand(elem, name, value);
}
}
}
return null;
}
use of org.talend.core.model.properties.Property in project tdi-studio-se by Talend.
the class AbstractPreferenceComposite method addButtonListeners.
private void addButtonListeners() {
reloadBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
onReloadButtonClick();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
saveBtn.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
onSaveButtonClick();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
if (hasRunJobNode(false) && needApplyToChildren()) {
applyToChildrenJob.addSelectionListener(new SelectionListener() {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
// zli for bug 12335
final ProgressDialog progress = new ProgressDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()) {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorReference[] editorReferences = activePage.getEditorReferences();
CorePlugin defaultPlugin = CorePlugin.getDefault();
IDesignerCoreService designerCoreService = defaultPlugin.getDesignerCoreService();
List<IProcess2> openedProcessList = designerCoreService.getOpenedProcess(RepositoryUpdateManager.getEditors());
List<String> activeProcessId = new ArrayList<String>();
for (IProcess process : openedProcessList) {
activeProcessId.add(process.getId());
}
final int rate = 1 / openedProcessList.size() - activeProcessId.size();
for (INode runjobNode : tRunJobNodes) {
String id = (String) runjobNode.getElementParameter(EParameterName.PROCESS_TYPE_PROCESS.getName()).getValue();
String version = (String) runjobNode.getElementParameter(EParameterName.PROCESS_TYPE_VERSION.getName()).getValue();
if ("".equals(id) || id == null) {
//$NON-NLS-1$
MessageDialog.openWarning(getShell(), //$NON-NLS-1$
Messages.getString("AbstractPreferenceComposite.warning", runjobNode.getUniqueName()), Messages.getString("AbstractPreferenceComposite.jobAssigned", //$NON-NLS-1$
runjobNode.getUniqueName()));
return;
}
if (activeProcessId.contains(id)) {
IEditorPart activeEditorPart = activePage.getActiveEditor();
for (IEditorReference editorReference : editorReferences) {
IEditorPart editorPart = editorReference.getEditor(false);
if ((editorPart != activeEditorPart) && (editorPart instanceof MultiPageTalendEditor)) {
IElement element = ((MultiPageTalendEditor) editorPart).getProcess();
StatsAndLogsViewHelper.applySettings(elem, element, AbstractPreferenceComposite.this);
}
}
} else {
try {
SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1 * UpdatesConstants.SCALE, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask(UpdatesConstants.EMPTY, 1 * rate);
IRepositoryViewObject lastVersion = DesignerPlugin.getDefault().getProxyRepositoryFactory().getLastVersion(id);
if (lastVersion != null) {
Item item = lastVersion.getProperty().getItem();
IProcess processFromItem = designerCoreService.getProcessFromItem(item);
if (processFromItem instanceof Process) {
Process process = (Process) processFromItem;
StatsAndLogsViewHelper.applySettings(elem, process, AbstractPreferenceComposite.this);
IProxyRepositoryFactory factory = defaultPlugin.getProxyRepositoryFactory();
Property property = factory.getUptodateProperty(process.getProperty());
process.setProperty(property);
subMonitor.subTask(RepositoryUpdateManager.getUpdateJobInfor(process.getProperty()));
ProcessType processType = process.saveXmlFile();
Item item2 = process.getProperty().getItem();
if (item2 instanceof JobletProcessItem) {
((JobletProcessItem) item2).setJobletProcess((JobletProcess) processType);
} else {
((ProcessItem) item2).setProcess(processType);
}
factory.save(item2);
subMonitor.done();
}
}
} catch (PersistenceException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
}
applySettingsToSubJob(id, version);
}
}
};
try {
progress.executeProcess();
} catch (InvocationTargetException e1) {
e1.printStackTrace();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
/**
* yzhang Comment method "applySettingsToSubJob".
*
* @param id
* @param version
*/
private void applySettingsToSubJob(String id, String version) {
final ProcessItem processItem = ItemCacheManager.getProcessItem(id, version);
if (processItem == null) {
return;
}
ProcessType processType = processItem.getProcess();
EList<ElementParameterType> parameters = processType.getParameters().getElementParameter();
StatsAndLogsViewHelper.applySettings(parameters, elem);
List<NodeType> nodes = findRunJobNode(processType.getNode());
for (NodeType nodeType : nodes) {
EList<ElementParameterType> list = nodeType.getElementParameter();
ElementParameterType idParam = getElementParameterType(list, //$NON-NLS-1$
PROCESS + ":" + EParameterName.PROCESS_TYPE_PROCESS.getName());
ElementParameterType versionParam = getElementParameterType(list, //$NON-NLS-1$
PROCESS + ":" + EParameterName.PROCESS_TYPE_VERSION.getName());
String subId = idParam.getValue();
String subVersion = versionParam.getValue();
applySettingsToSubJob(subId, subVersion);
}
}
});
}
}
Aggregations