use of org.talend.core.ui.services.IDesignerCoreUIService in project tdi-studio-se by Talend.
the class ContextParameterExtractor method saveContext.
/**
* qzhang Comment method "saveContext".
*
* @param parameterName
* @param elem
* @param replaceCode
*/
public static void saveContext(final String parameterName, final IElement elem, String replaceCode, IProcess2 process) {
PropertyChangeCommand cmd = new PropertyChangeCommand(elem, parameterName, replaceCode);
boolean executed = false;
if (process != null && process instanceof IGEFProcess) {
IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
if (designerCoreUIService != null) {
executed = designerCoreUIService.executeCommand((IGEFProcess) process, cmd);
}
}
if (!executed) {
cmd.execute();
}
// note that no undo will be available
}
use of org.talend.core.ui.services.IDesignerCoreUIService in project tdi-studio-se by Talend.
the class WebServiceManager method executeCommand.
public void executeCommand(Command cmd) {
IProcess process = this.getWebServiceComponent().getProcess();
boolean executed = false;
if (process != null && process instanceof IGEFProcess) {
IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
if (designerCoreUIService != null) {
executed = designerCoreUIService.executeCommand((IGEFProcess) process, cmd);
}
}
if (!executed) {
cmd.execute();
}
}
use of org.talend.core.ui.services.IDesignerCoreUIService in project tdi-studio-se by Talend.
the class JSONFileStep3Form method refreshMetaDataTable.
/**
* DOC ocarbone Comment method "refreshMetaData".
*
* @param csvArray
*/
public void refreshMetaDataTable(final CsvArray csvArray, List<SchemaTarget> schemaTarget, Boolean flag) {
informationLabel.setText(" " + "Guess successful");
List mcolumns = new ArrayList();
mcolumns.addAll(tableEditorView.getMetadataEditor().getMetadataColumnList());
// clear all items
tableEditorView.getMetadataEditor().removeAll();
List<MetadataColumn> columns = new ArrayList<MetadataColumn>();
String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
}
if (csvArray == null || csvArray.getRows().isEmpty()) {
return;
} else {
List<String[]> csvRows = csvArray.getRows();
String[] fields = csvRows.get(0);
int numberOfCol = fields.length;
// define the label to the metadata width the content of the first row
int firstRowToExtractMetadata = 0;
// the first rows is used to define the label of any metadata
String[] label = new String[numberOfCol];
for (int i = 0; i < numberOfCol; i++) {
label[i] = DEFAULT_LABEL + i;
if (firstRowToExtractMetadata == 0) {
if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
label[i] = MetadataToolHelper.validateColumnName(label[i], i);
}
}
// if (firstRowToExtractMetadata == 1) {
// String value = fields.get(i).getValue();
// if (!value.equals("")) {
// label[i] = value;
// }
// }
}
for (int i = 0; i < numberOfCol; i++) {
// define the first currentType and assimile it to globalType
String globalType = null;
int lengthValue = 0;
int precisionValue = 0;
int current = firstRowToExtractMetadata;
while (globalType == null) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "id_String";
} else {
globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "id_String"; //$NON-NLS-1$
// }
}
} else {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "String";
} else {
globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "String"; //$NON-NLS-1$
// }
}
}
}
// for another lines
for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
fields = csvRows.get(f);
if (fields.length > i) {
String value = fields[i];
if (!value.equals("")) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
}
} else {
if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
}
}
if (lengthValue < value.length()) {
lengthValue = value.length();
}
int positionDecimal = 0;
if (value.indexOf(',') > -1) {
positionDecimal = value.lastIndexOf(',');
precisionValue = lengthValue - positionDecimal;
} else if (value.indexOf('.') > -1) {
positionDecimal = value.lastIndexOf('.');
precisionValue = lengthValue - positionDecimal;
}
} else {
IPreferenceStore preferenceStore = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
preferenceStore = designerCoreUiService.getPreferenceStore();
}
if (preferenceStore != null && preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
//$NON-NLS-1$
globalType = preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
if (preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
//$NON-NLS-1$
lengthValue = Integer.parseInt(preferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
}
}
}
}
}
// define the metadataColumn to field i
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
// hshen bug7249
//$NON-NLS-1$
metadataColumn.setPattern("\"dd-MM-yyyy\"");
// Convert javaType to TalendType
String talendType = null;
talendType = globalType;
if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
metadataColumn.setPrecision(precisionValue);
} else {
metadataColumn.setPrecision(0);
}
metadataColumn.setTalendType(talendType);
metadataColumn.setLength(lengthValue);
// Check the label and add it to the table
metadataColumn.setLabel(tableEditorView.getMetadataEditor().getNextGeneratedColumnName(label[i]));
columns.add(i, metadataColumn);
}
}
if (!flag) {
for (int i = 0; i < columns.size(); i++) {
for (int j = 0; j < mcolumns.size(); j++) {
if (columns.get(i).getLabel().equals(((MetadataColumn) mcolumns.get(j)).getLabel())) {
columns.remove(i);
columns.add(i, (MetadataColumn) mcolumns.get(j));
}
}
}
}
tableEditorView.getMetadataEditor().addAll(columns);
checkFieldsValue();
tableEditorView.getTableViewerCreator().layout();
tableEditorView.getTableViewerCreator().getTable().deselectAll();
informationLabel.setText("Click to update schema preview");
}
use of org.talend.core.ui.services.IDesignerCoreUIService in project tdi-studio-se by Talend.
the class JSONWizard method resetMetadata.
private void resetMetadata(List<SchemaTarget> schemaTarget, boolean flag) {
// TODO
JSONFileConnection connection2 = JSONConnectionContextUtils.getJSONOriginalValueConnection(connection, this.connectionItem, connection.isContextMode(), true);
ProcessDescription processDescription = JSONShadowProcessHelper.getProcessDescription(connection2, getTempJsonPath());
CsvArray csvArray = null;
try {
if (EJsonReadbyMode.JSONPATH.getValue().equals(getReadbyMode())) {
//$NON-NLS-1$
csvArray = JSONShadowProcessHelper.getCsvArray(processDescription, "FILE_JSON");
} else {
//$NON-NLS-1$
csvArray = JSONShadowProcessHelper.getCsvArray(processDescription, "FILE_XML");
}
} catch (CoreException e) {
ExceptionHandler.process(e);
}
List<MetadataColumn> newColumns = new ArrayList<MetadataColumn>();
String file = ((JSONFileConnection) this.connectionItem.getConnection()).getJSONFilePath();
if (connection.isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
file = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, file));
}
if (file != null) {
// prepareColumnsFromXSD(file, newColumns, schemaTarget);
return;
}
if (csvArray == null || csvArray.getRows().isEmpty()) {
return;
} else {
List<String[]> csvRows = csvArray.getRows();
String[] fields = csvRows.get(0);
int numberOfCol = fields.length;
// define the label to the metadata width the content of the first row
int firstRowToExtractMetadata = 0;
// the first rows is used to define the label of any metadata
String[] label = new String[numberOfCol];
for (int i = 0; i < numberOfCol; i++) {
label[i] = DEFAULT_LABEL + i;
if (firstRowToExtractMetadata == 0) {
if (schemaTarget.get(i).getTagName() != null && !schemaTarget.get(i).getTagName().equals("")) {
//$NON-NLS-1$
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
label[i] = "" + schemaTarget.get(i).getTagName().trim().replaceAll(" ", "_");
label[i] = MetadataToolHelper.validateColumnName(label[i], i);
}
}
}
for (int i = 0; i < numberOfCol; i++) {
// define the first currentType and assimile it to globalType
String globalType = null;
int lengthValue = 0;
int precisionValue = 0;
int current = firstRowToExtractMetadata;
while (globalType == null) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "id_String";
} else {
globalType = JavaDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "id_String"; //$NON-NLS-1$
// }
}
} else {
if (i >= csvRows.get(current).length) {
//$NON-NLS-1$
globalType = "String";
} else {
globalType = PerlDataTypeHelper.getTalendTypeOfValue(csvRows.get(current)[i]);
current++;
// if (current == csvRows.size()) {
// globalType = "String"; //$NON-NLS-1$
// }
}
}
}
// for another lines
for (int f = firstRowToExtractMetadata; f < csvRows.size(); f++) {
fields = csvRows.get(f);
if (fields.length > i) {
String value = fields[i];
if (!value.equals("")) {
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (!JavaDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = JavaDataTypeHelper.getCommonType(globalType, JavaDataTypeHelper.getTalendTypeOfValue(value));
}
} else {
if (!PerlDataTypeHelper.getTalendTypeOfValue(value).equals(globalType)) {
globalType = PerlDataTypeHelper.getCommonType(globalType, PerlDataTypeHelper.getTalendTypeOfValue(value));
}
}
if (lengthValue < value.length()) {
lengthValue = value.length();
}
int positionDecimal = 0;
if (value.indexOf(',') > -1) {
positionDecimal = value.lastIndexOf(',');
precisionValue = lengthValue - positionDecimal;
} else if (value.indexOf('.') > -1) {
positionDecimal = value.lastIndexOf('.');
precisionValue = lengthValue - positionDecimal;
}
} else {
IPreferenceStore corePreferenceStore = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
IDesignerCoreUIService designerCoreUiService = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
corePreferenceStore = designerCoreUiService.getPreferenceStore();
}
if (corePreferenceStore != null && corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE) != null && !corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE).equals("")) {
//$NON-NLS-1$
globalType = corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_TYPE);
if (corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH) != null && !corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH).equals("")) {
//$NON-NLS-1$
lengthValue = Integer.parseInt(corePreferenceStore.getString(MetadataTypeLengthConstants.VALUE_DEFAULT_LENGTH));
}
}
}
}
}
// define the metadataColumn to field i
MetadataColumn metadataColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
// hshen bug7249
//$NON-NLS-1$
metadataColumn.setPattern("\"dd-MM-yyyy\"");
// Convert javaType to TalendType
String talendType = null;
talendType = globalType;
if (globalType.equals(JavaTypesManager.FLOAT.getId()) || globalType.equals(JavaTypesManager.DOUBLE.getId())) {
metadataColumn.setPrecision(precisionValue);
} else {
metadataColumn.setPrecision(0);
}
metadataColumn.setTalendType(talendType);
metadataColumn.setLength(lengthValue);
metadataColumn.setLabel(label[i]);
newColumns.add(i, metadataColumn);
}
}
EList columns = ConnectionHelper.getTables(connection).toArray(new MetadataTable[0])[0].getColumns();
if (!flag) {
for (int i = 0; i < newColumns.size(); i++) {
for (int j = 0; j < columns.size(); j++) {
if (newColumns.get(i).getLabel().equals(((MetadataColumn) columns.get(j)).getLabel())) {
newColumns.remove(i);
newColumns.add(i, (MetadataColumn) columns.get(j));
}
}
}
}
columns.clear();
columns.addAll(newColumns);
}
use of org.talend.core.ui.services.IDesignerCoreUIService in project tdi-studio-se by Talend.
the class JobExportAction method exportJobScript.
private boolean exportJobScript(List<? extends IRepositoryNode> nodes, String version, String bundleVersion, IProgressMonitor monitor) {
manager.setJobVersion(version);
manager.setBundleVersion(bundleVersion);
List<ExportFileResource> processes = getProcesses(nodes, "");
boolean isNotFirstTime = directoryName != null;
if (isNotFirstTime && processes != null) {
for (ExportFileResource process : processes) {
process.setDirectoryName(directoryName);
}
}
try {
ProxyRepositoryFactory.getInstance().initialize();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
ItemCacheManager.clearCache();
if (!isMultiNodes()) {
// TODO : bug with export?
for (ExportFileResource process : processes) {
process.removeAllMap();
ProcessItem processItem = (ProcessItem) process.getItem();
if (!processItem.getProperty().getVersion().equals(version)) {
// update with the correct version.
process.setProcess(ItemCacheManager.getProcessItem(processItem.getProperty().getId(), version));
}
}
}
manager.setProgressMonitor(monitor);
List<ExportFileResource> resourcesToExport = null;
try {
resourcesToExport = manager.getExportResources(processes.toArray(new ExportFileResource[] {}));
IStructuredSelection selection = new StructuredSelection(nodes);
// if job has compile error, will not export to avoid problem if run jobscript
boolean hasErrors = CorePlugin.getDefault().getRunProcessService().checkExportProcess(selection, true);
if (hasErrors) {
manager.deleteTempFiles();
return false;
}
} catch (ProcessorException e) {
MessageBoxExceptionHandler.process(e);
return false;
}
boolean addClasspathJar = true;
IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
if (designerCoreUIService != null) {
addClasspathJar = designerCoreUIService.getPreferenceStore().getBoolean(IRepositoryPrefConstants.ADD_CLASSPATH_JAR);
}
if (isMultiNodes() || addClasspathJar) {
manager.setTopFolder(resourcesToExport);
}
doArchiveExport(monitor, resourcesToExport);
clean();
ProcessorUtilities.resetExportConfig();
// no need to regenerate if run in export model
// boolean generated = generatedCodes(version, monitor, processes);
// if (!generated) {
// return false;
// }
//$NON-NLS-1$
monitor.subTask(Messages.getString("JobScriptsExportWizardPage.newExportSuccess", type));
if (addClasspathJar) {
reBuildJobZipFile(processes);
} else {
String zipFile = getTempDestinationValue();
String destinationZipFile = manager.getDestinationPath();
FileCopyUtils.copy(zipFile, destinationZipFile);
}
return true;
}
Aggregations