Search in sources :

Example 11 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository 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;
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Point(org.eclipse.swt.graphics.Point) MultipleThreadDynamicComposite(org.talend.designer.core.ui.views.properties.MultipleThreadDynamicComposite) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FileItem(org.talend.core.model.properties.FileItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 12 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class AbstractPreferenceComposite method updateContextValue.

protected void updateContextValue(boolean update) {
    if (!update) {
        return;
    }
    IElementParameter proElement = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
    Object value = proElement.getValue();
    if (value instanceof String && ((String) value).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
        String id = (String) elem.getElementParameter(//$NON-NLS-1$
        EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
        String propertyType = EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
        ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(id);
        Connection connection = connectionItem.getConnection();
        ChangeValuesFromRepository command = new ChangeValuesFromRepository(elem, connection, propertyType, id);
        getCommandStack().execute(command);
    }
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 13 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class ImplicitContextLoadHelper method loadPropertyTypeFromPreference.

/**
     * DOC hcw Comment method "reloadPropertyType".
     * 
     * @param element
     * @param extraComposite
     * @param languagePrefix
     * @param elementParameter
     */
private static void loadPropertyTypeFromPreference(Element element, ExtraComposite extraComposite, String languagePrefix, IElementParameter elementParameter) {
    String propertyType = (String) getPreferenceValue(languagePrefix, EParameterName.PROPERTY_TYPE, String.class);
    String id = (String) getPreferenceValue(languagePrefix, EParameterName.REPOSITORY_PROPERTY_TYPE, String.class);
    Connection repositoryConnection = null;
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    Item item = null;
    try {
        IRepositoryViewObject repobj = factory.getLastVersion(id);
        if (repobj != null) {
            Property tmpproperty = repobj.getProperty();
            if (tmpproperty != null) {
                item = tmpproperty.getItem();
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (item != null && item instanceof ConnectionItem) {
        repositoryConnection = ((ConnectionItem) item).getConnection();
    } else {
        repositoryConnection = null;
    }
    ChangeValuesFromRepository cmd1 = new ChangeValuesFromRepository(element, repositoryConnection, getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.PROPERTY_TYPE.getName(), //$NON-NLS-1$
    propertyType);
    ChangeValuesFromRepository cmd2 = new ChangeValuesFromRepository(element, repositoryConnection, getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
    id);
    AbstractMultiPageTalendEditor part = (AbstractMultiPageTalendEditor) ((IProcess2) element).getEditor();
    if (part instanceof AbstractMultiPageTalendEditor) {
        Object adapter = (part).getTalendEditor().getAdapter(CommandStack.class);
        if (adapter != null) {
            CommandStack commandStack = ((CommandStack) adapter);
            commandStack.execute(cmd1);
            commandStack.execute(cmd2);
        }
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) CommandStack(org.eclipse.gef.commands.CommandStack) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) RepositoryToComponentProperty(org.talend.core.model.metadata.designerproperties.RepositoryToComponentProperty) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 14 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class AbstractElementPropertySectionController method changeToBuildInCommand.

private Command changeToBuildInCommand(Control control) {
    //$NON-NLS-1$
    final String typeName = ":" + EParameterName.PROPERTY_TYPE.getName();
    if (curParameter != null) {
        String parentName = null;
        if (curParameter.getCategory() == EComponentCategory.EXTRA) {
            parentName = JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName());
        } else if (curParameter.getCategory() == EComponentCategory.STATSANDLOGS) {
            parentName = EParameterName.PROPERTY_TYPE.getName();
        }
        if (parentName != null) {
            return new ChangeValuesFromRepository(elem, null, parentName + typeName, EmfComponent.BUILTIN);
        }
    }
    Object objProperty = control.getData(PARAMETER_NAME);
    String property = null;
    if (objProperty != null && elem != null) {
        String curSubParam = objProperty.toString().trim();
        if (!curSubParam.isEmpty()) {
            IElementParameter iElementParam = elem.getElementParameter(curSubParam);
            if (iElementParam != null) {
                property = iElementParam.getRepositoryProperty();
            }
        }
    }
    if (property == null || property.trim().isEmpty()) {
        property = UpgradeParameterHelper.PROPERTY;
    }
    return new ChangeValuesFromRepository(elem, null, property + typeName, EmfComponent.BUILTIN);
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 15 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class StatsAndLogsViewHelper method applySettings.

/**
     * yzhang Comment method "applySettings".
     * 
     * @param element
     * @param dynamicProperty
     */
public static void applySettings(IElement element, IElement applyTo, IDynamicProperty dynamicProperty) {
    List<? extends IElementParameter> elementParameters = applyTo.getElementParameters();
    for (IElementParameter elementParameterType : elementParameters) {
        String parameterName = elementParameterType.getName();
        if (parameterName.equals(EParameterName.ON_STATCATCHER_FLAG.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.ON_STATCATCHER_FLAG.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.ON_LOGCATCHER_FLAG.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.ON_LOGCATCHER_FLAG.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.ON_METERCATCHER_FLAG.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.ON_METERCATCHER_FLAG.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.ON_FILES_FLAG.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.ON_FILES_FLAG.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.FILE_PATH.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.FILE_PATH.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.FILENAME_STATS.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.FILENAME_STATS.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.FILENAME_LOGS.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.FILENAME_LOGS.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.FILENAME_METTER.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.FILENAME_METTER.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.ON_DATABASE_FLAG.getName())) {
            elementParameterType.setValue(element.getElementParameter(EParameterName.ON_DATABASE_FLAG.getName()).getValue());
            continue;
        }
        if (parameterName.equals(EParameterName.PROPERTY_TYPE.getName())) {
            String id = (String) element.getElementParameter(//$NON-NLS-1$
            EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
            String propertyType = (String) element.getElementParameter(EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.PROPERTY_TYPE.getName()).getValue();
            /* 16969 */
            Connection repositoryConnection = null;
            // Map<String, ConnectionItem> repositoryConnectionItemMap =
            // dynamicProperty.getRepositoryConnectionItemMap();
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            Item item = null;
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(id);
                if (repobj != null) {
                    Property tmpproperty = repobj.getProperty();
                    if (tmpproperty != null) {
                        item = tmpproperty.getItem();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            if (item != null && item instanceof ConnectionItem) {
                repositoryConnection = ((ConnectionItem) item).getConnection();
            } else {
                repositoryConnection = null;
            }
            // if (repositoryConnectionItemMap.containsKey(id)) {
            // repositoryConnection = repositoryConnectionItemMap.get(id).getConnection();
            // } else {
            // repositoryConnection = null;
            // }
            ChangeValuesFromRepository cmd1 = new ChangeValuesFromRepository(applyTo, repositoryConnection, EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.PROPERTY_TYPE.getName(), //$NON-NLS-1$
            propertyType);
            ChangeValuesFromRepository cmd2 = new ChangeValuesFromRepository(applyTo, repositoryConnection, EParameterName.PROPERTY_TYPE.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
            id);
            CompoundCommand cc = new CompoundCommand();
            cc.add(cmd1);
            cc.add(cmd2);
            boolean executed = false;
            if (applyTo instanceof IGEFProcess) {
                IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
                if (designerCoreUIService != null) {
                    executed = designerCoreUIService.executeCommand((IGEFProcess) applyTo, cc);
                }
            }
            if (!executed) {
                cc.execute();
            }
            continue;
        }
        if (PREFERENCE_STORE.getString(LANGUAGE_PREFIX + EParameterName.PROPERTY_TYPE.getName()).equals(EmfComponent.BUILTIN)) {
            if (parameterName.equals(EParameterName.DB_TYPE.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.DB_TYPE.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.HOST.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.HOST.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.PORT.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.PORT.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.DBNAME.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.DBNAME.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.PROPERTIES.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.PROPERTIES.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.DBFILE.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.DBFILE.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.SCHEMA_DB.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.SCHEMA_DB.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.USER.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.USER.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.PASS.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.PASS.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.TABLE_STATS.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.TABLE_STATS.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.TABLE_LOGS.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.TABLE_LOGS.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.TABLE_METER.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.TABLE_METER.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.CATCH_RUNTIME_ERRORS.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.CATCH_RUNTIME_ERRORS.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.CATCH_USER_ERRORS.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.CATCH_USER_ERRORS.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.CATCH_USER_WARNING.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.CATCH_USER_WARNING.getName()).getValue());
                continue;
            }
            if (parameterName.equals(EParameterName.CATCH_REALTIME_STATS.getName())) {
                elementParameterType.setValue(element.getElementParameter(EParameterName.CATCH_REALTIME_STATS.getName()).getValue());
                continue;
            }
        }
    }
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IGEFProcess(org.talend.core.ui.process.IGEFProcess) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)24 IElementParameter (org.talend.core.model.process.IElementParameter)19 ConnectionItem (org.talend.core.model.properties.ConnectionItem)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 Connection (org.talend.core.model.metadata.builder.connection.Connection)13 PersistenceException (org.talend.commons.exception.PersistenceException)11 Item (org.talend.core.model.properties.Item)10 Property (org.talend.core.model.properties.Property)9 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)7 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)5 CommandStack (org.eclipse.gef.commands.CommandStack)4 CDCConnection (org.talend.core.model.metadata.builder.connection.CDCConnection)4 Element (org.talend.core.model.process.Element)4 FileItem (org.talend.core.model.properties.FileItem)4 LinkRulesItem (org.talend.core.model.properties.LinkRulesItem)4 Command (org.eclipse.gef.commands.Command)3