Search in sources :

Example 1 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class MultiSchemasUI method getFieldSeparatorStyleSupportByLanguage.

private String[] getFieldSeparatorStyleSupportByLanguage() {
    ECodeLanguage language = LanguageManager.getCurrentLanguage();
    String[] styles = { FieldSeparator.SEMICOLON_LITERAL.getName(), FieldSeparator.COMMA_LITERAL.getName(), FieldSeparator.TABULATION_LITERAL.getName(), FieldSeparator.SPACE_LITERAL.getName(), FieldSeparator.ALT_65_LITERAL.getName(), FieldSeparator.CUSTOM_ANSI_LITERAL.getName(), FieldSeparator.CUSTOM_UTF8_LITERAL.getName(), FieldSeparator.CUSTOM_REG_EXP_LITERAL.getName() };
    switch(language) {
        case JAVA:
            String[] javaStyles = new String[styles.length - 1];
            System.arraycopy(styles, 0, javaStyles, 0, javaStyles.length);
            return javaStyles;
        default:
            // PERL
            return styles;
    }
}
Also used : ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 2 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class AbstractHL7MetadataTableEditorView method configureTalendTypeColumn.

/**
     * DOC amaumont Comment method "initTalendTypeColumn".
     * 
     * @param tableViewerCreator
     * @param comboValueAdapter
     * @param arrayTalendTypes
     */
private TableViewerCreatorColumn configureTalendTypeColumn(final TableViewerCreator<B> tableViewerCreator) {
    CellEditorValueAdapter comboValueAdapter = null;
    ECodeLanguage codeLanguage = LanguageManager.getCurrentLanguage();
    if (codeLanguage == ECodeLanguage.JAVA) {
        comboValueAdapter = new JavaTypeComboValueAdapter<B>(JavaTypesManager.getDefaultJavaType(), getNullableAccessor());
    } else if (codeLanguage == ECodeLanguage.PERL) {
        comboValueAdapter = CellEditorValueAdapterFactory.getComboAdapterForComboCellEditor();
    }
    String[] arrayTalendTypes = new String[0];
    try {
        arrayTalendTypes = MetadataTalendType.getTalendTypesLabels();
    } catch (NoClassDefFoundError e) {
        // shouln't be happend
        // e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (ExceptionInInitializerError e) {
        // shouln't be happend
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    TableViewerCreatorColumn column = new TableViewerCreatorColumn(tableViewerCreator);
    //$NON-NLS-1$
    column.setTitle(Messages.getString("MetadataTableEditorView.TypleTitle"));
    //$NON-NLS-1$
    column.setToolTipHeader(Messages.getString("MetadataTableEditorView.TypleTitle"));
    column.setId(ID_COLUMN_TYPE);
    column.setBeanPropertyAccessors(getTalendTypeAccessor());
    column.setModifiable(!isReadOnly());
    column.setWeight(10);
    column.setMinimumWidth(30);
    ComboBoxCellEditor typeComboEditor = new ComboBoxCellEditor(tableViewerCreator.getTable(), arrayTalendTypes, SWT.READ_ONLY);
    CCombo typeCombo = (CCombo) typeComboEditor.getControl();
    typeCombo.setEditable(false);
    column.setCellEditor(typeComboEditor, comboValueAdapter);
    return column;
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) CellEditorValueAdapter(org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TableViewerCreatorColumn(org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 3 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class ScdManager method createOutputSchema.

/**
     * DOC chuang Comment method "createOutputSchema".
     * 
     * @param unusedFields
     */
public void createOutputSchema() {
    // adding the surrogate Keys column
    Map<String, IMetadataColumn> surrogateKeysColumnMap = new HashMap<String, IMetadataColumn>();
    List<IMetadataColumn> outputColumnsAll = getOutputColumns(component);
    for (IMetadataColumn column : outputColumnsAll) {
        if (column.isKey()) {
            surrogateKeysColumnMap.put(column.getLabel(), column);
            break;
        }
    }
    // the unused columns must not be present in the output schema and also
    // remove all generated column from
    // output schema
    Map<String, IMetadataColumn> outputColumns = removeUnusedAndGeneratedColumns(component.getMetadataList(), unusedFields);
    IMetadataTable schema = component.getMetadataList().get(0);
    // adding all used columns to output schema
    Map<String, IMetadataColumn> inputColumnsMap = new HashMap<String, IMetadataColumn>();
    List<IMetadataColumn> inputColumns = getInputColumns(component);
    for (IMetadataColumn column : inputColumns) {
        inputColumnsMap.put(column.getLabel(), column);
        if (!unusedFields.contains(column.getLabel()) && outputColumns.get(column.getLabel()) == null) {
            schema.getListColumns().add(cloneColumn(column, column.getLabel()));
        }
    }
    // "current value" column
    if (type3Table != null) {
        for (Type3Field type3 : type3Table) {
            if (outputColumns.get(type3.getPreviousValue()) != null || StringUtils.isEmpty(type3.getPreviousValue())) {
                continue;
            }
            IMetadataColumn column = inputColumnsMap.get(type3.getCurrentValue());
            IMetadataColumn previous = cloneColumn(column, type3.getPreviousValue());
            outputColumns.put(previous.getLabel(), previous);
            schema.getListColumns().add(previous);
        }
    }
    // removeVersionFieldsFromOutput(outputColumns, schema, new String[] {
    // versionData.getStartName(),
    // versionData.getEndName(),
    // versionData.getVersionName(), versionData.getActiveName() });
    // for versionning columns {start, end} are datetime data type, version
    // is an integer, active is a
    // boolean
    ECodeLanguage lang = LanguageManager.getCurrentLanguage();
    if (type2Table != null && !type2Table.isEmpty()) {
        // start date
        IMetadataColumn startColumn = createMetadataColumn(outputColumns, schema, versionData.getStartName(), Date.class, lang);
        if (startColumn != null) {
            startColumn.setCustomId(1);
            startColumn.setCustom(true);
        }
        // end date
        IMetadataColumn endColumn = createMetadataColumn(outputColumns, schema, versionData.getEndName(), Date.class, lang);
        if (endColumn != null) {
            endColumn.setNullable(true);
            endColumn.setCustomId(2);
            endColumn.setCustom(true);
        }
        if (versionData.isVersionChecked()) {
            IMetadataColumn versionColumn = createMetadataColumn(outputColumns, schema, versionData.getVersionName(), Integer.class, lang);
            if (versionColumn != null) {
                versionColumn.setCustomId(3);
                versionColumn.setCustom(true);
            }
        }
        if (versionData.isActiveChecked()) {
            IMetadataColumn activeColumn = createMetadataColumn(outputColumns, schema, versionData.getActiveName(), Boolean.class, lang);
            if (activeColumn != null) {
                activeColumn.setCustomId(4);
                activeColumn.setCustom(true);
            }
        }
    }
    fixKeyColumnsInOutputSchema(schema, inputColumnsMap, surrogateKeysColumnMap, lang);
// removed by TDI-30934
// sort column by name
// Collections.sort(schema.getListColumns(), new Comparator<IMetadataColumn>() {
//
// public int compare(IMetadataColumn o1, IMetadataColumn o2) {
//
// return o1.getLabel().compareTo(o2.getLabel());
// }
//
// });
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HashMap(java.util.HashMap) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Type3Field(org.talend.designer.scd.model.Type3Field) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 4 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class ImportItemUtil method getRoutineSynchronizer.

// private void applyMigrationTasks(ItemRecord itemRecord, IProgressMonitor monitor) {
// Context ctx = CorePlugin.getContext();
// RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
// ITalendSynchronizer routineSynchronizer = getRoutineSynchronizer();
//
// ERepositoryObjectType repositoryType = itemRecord.getRepositoryType();
//
// Item item = null;
// try {
// List<IRepositoryViewObject> allVersion = ProxyRepositoryFactory.getInstance().getAllVersion(
// ProjectManager.getInstance().getCurrentProject(), itemRecord.getItemId(), itemRecord.getImportPath(),
// repositoryType);
// for (IRepositoryViewObject repositoryObject : allVersion) {
// if (repositoryObject.getProperty().getVersion().equals(itemRecord.getItemVersion())) {
// item = repositoryObject.getProperty().getItem();
// }
// }
// } catch (Exception e) {
// logError(e);
// }
//
// if (item == null) {
// return;
// }
//
// List<IProjectMigrationTask> toExecute = new ArrayList<IProjectMigrationTask>();
// for (String taskId : itemRecord.getMigrationTasksToApply()) {
// IProjectMigrationTask task = GetTasksHelper.getInstance().getProjectTask(taskId);
// if (task == null) {
//                log.warn(Messages.getString("ImportItemUtil.taskLogWarn", taskId)); //$NON-NLS-1$
// } else if (!task.isDeprecated()) {
// toExecute.add(task);
// }
//
// }
// Collections.sort(toExecute, new Comparator<IProjectMigrationTask>() {
//
// public int compare(IProjectMigrationTask o1, IProjectMigrationTask o2) {
// return o1.getOrder().compareTo(o2.getOrder());
// }
// });
//
// IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
//
// for (IProjectMigrationTask task : toExecute) {
//            monitor.subTask(Messages.getString("ImportItemUtil.taskMonitor", task.getName(), itemRecord.getItemName())); //$NON-NLS-1$
// try {
// // in case the resource has been modified (see MergeTosMetadataMigrationTask for example)
// if ((item.getProperty().eResource() == null || item.eResource() == null)) {
// Property updatedProperty = factory.reload(item.getProperty());
// item = updatedProperty.getItem();
// }
//
// if (item != null) {
// ExecutionResult executionResult = task.execute(repositoryContext.getProject(), item);
// if (executionResult == ExecutionResult.FAILURE) {
//                        log.warn(Messages.getString("ImportItemUtil.itemLogWarn", itemRecord.getItemName(), task.getName())); //$NON-NLS-1$
// // TODO smallet add a warning/error to the job using
// // model
// }
// }
// } catch (Exception e) {
//                log.warn(Messages.getString("ImportItemUtil.itemLogException", itemRecord.getItemName(), task.getName()), e); //$NON-NLS-1$
// try {
// factory.deleteObjectPhysical(new RepositoryObject(item.getProperty()));
// break;// stop migrating the object it has be deleted
// } catch (PersistenceException e1) {
// log.error("Could not delete physical item(" + item.getProperty().getLabel() + "), Project may be corrupted.",
// e);
// }
// }
// }
//
// try {
// if (item != null && item instanceof RoutineItem) {
// RoutineUtils.changeRoutinesPackage(item);
// RoutineItem routineItem = (RoutineItem) item;
// routineSynchronizer.forceSyncRoutine(routineItem);
// routineSynchronizer.syncRoutine(routineItem, true);
// routineSynchronizer.getFile(routineItem);
// }
// // if (item.getProperty().eResource().isModified()) {
// // ProxyRepositoryFactory.getInstance().save(item, true);
// // item.getProperty().eResource().setModified(false);
// // }
// if (item.getProperty().eResource() != null) {
// ProxyRepositoryFactory.getInstance().unloadResources(item.getProperty());
// if (item.getParent() != null && item.getParent() instanceof FolderItem) {
// ((FolderItem) item.getParent()).getChildren().remove(item);
// item.setParent(null);
// }
// }
//
// itemRecord.setExistingItemWithSameId(null);
// itemRecord.clear();
//
// } catch (Exception e) {
// logError(e);
// }
// }
private ITalendSynchronizer getRoutineSynchronizer() {
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ITalendSynchronizer routineSynchronizer = null;
    switch(lang) {
        case JAVA:
            routineSynchronizer = service.createJavaRoutineSynchronizer();
            break;
        case PERL:
            routineSynchronizer = service.createPerlRoutineSynchronizer();
            break;
        default:
            //$NON-NLS-1$
            throw new UnsupportedOperationException(Messages.getString("ImportItemUtil.unknowException", lang));
    }
    return routineSynchronizer;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 5 with ECodeLanguage

use of org.talend.core.language.ECodeLanguage in project tdi-studio-se by Talend.

the class ImplicitContextLoadHelper method saveValuesToPreferencePage.

/**
     * DOC hcw Comment method "saveValuesToPreferencePage".
     * 
     * @param elem
     * @param extraComposite
     */
public static void saveValuesToPreferencePage(Element element, ExtraComposite extraComposite) {
    ECodeLanguage language = LanguageManager.getCurrentLanguage();
    //$NON-NLS-1$
    String languagePrefix = language.toString() + "_";
    EParameterName[] params = { EParameterName.IMPLICIT_TCONTEXTLOAD, EParameterName.FROM_FILE_FLAG, EParameterName.FROM_DATABASE_FLAG, EParameterName.IMPLICIT_TCONTEXTLOAD_FILE, EParameterName.FIELDSEPARATOR, EParameterName.DB_TYPE, EParameterName.HOST, EParameterName.PORT, EParameterName.DBNAME, EParameterName.SCHEMA_DB, EParameterName.USER, EParameterName.PASS, EParameterName.DBFILE, EParameterName.DBTABLE, EParameterName.QUERY_CONDITION, EParameterName.LOAD_NEW_VARIABLE, EParameterName.NOT_LOAD_OLD_VARIABLE, EParameterName.PRINT_OPERATIONS, EParameterName.DISABLE_WARNINGS, EParameterName.DISABLE_ERROR, EParameterName.DISABLE_INFO };
    Map<String, EParameterName> extraParams = new HashMap<String, EParameterName>();
    for (EParameterName param : params) {
        extraParams.put(getExtraParameterName(param), param);
    }
    List<? extends IElementParameter> elementParameters = element.getElementParameters();
    for (IElementParameter elementParameter : elementParameters) {
        String name = elementParameter.getName();
        Object value = elementParameter.getValue();
        if (name.equals(getExtraParameterName(EParameterName.PROPERTY_TYPE))) {
            savePropertyTypeToPreference(extraComposite, languagePrefix, elementParameter);
        } else if (extraParams.containsKey(name)) {
            if (value instanceof String) {
                PREFERENCE_STORE.setValue(languagePrefix + getExtraParameterName(extraParams.get(name)), removeQuote((String) value));
            } else if (value instanceof Boolean) {
                PREFERENCE_STORE.setValue(languagePrefix + getExtraParameterName(extraParams.get(name)), (Boolean) value);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) EParameterName(org.talend.designer.core.model.components.EParameterName) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

ECodeLanguage (org.talend.core.language.ECodeLanguage)29 RepositoryContext (org.talend.core.context.RepositoryContext)5 HashMap (java.util.HashMap)4 StyledText (org.eclipse.swt.custom.StyledText)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 RepositoryEditorInput (org.talend.core.repository.ui.editor.RepositoryEditorInput)4 IFile (org.eclipse.core.resources.IFile)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 IEditorReference (org.eclipse.ui.IEditorReference)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 ITableEntry (org.talend.designer.abstractmap.model.tableentry.ITableEntry)3 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 EList (org.eclipse.emf.common.util.EList)2 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)2 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)2 Item (org.talend.core.model.properties.Item)2