Search in sources :

Example 21 with PropertyChangeCommand

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

the class GenericHiddenTextController method createButtonCommand.

protected Command createButtonCommand(final Button button) {
    if (button.getData(NAME).equals(HIDDEN_TEXT)) {
        InputDialog dlg = new InputDialog(button.getShell(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Messages.getString("GenericHiddenTextController.NewPassword"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Messages.getString("GenericHiddenTextController.NoteConvention"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "\"\"", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        null) {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
                 */
            @Override
            protected Control createDialogArea(Composite parent) {
                Control control = super.createDialogArea(parent);
                String paramName = (String) button.getData(PARAMETER_NAME);
                getText().setData(PARAMETER_NAME, paramName);
                // editionControlHelper.register(paramName, getText());
                return control;
            }
        };
        if (dlg.open() == Window.OK) {
            String paramName = (String) button.getData(PARAMETER_NAME);
            elem.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), new Boolean(true));
            return new PropertyChangeCommand(elem, paramName, dlg.getValue());
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) InputDialog(org.eclipse.jface.dialogs.InputDialog) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Composite(org.eclipse.swt.widgets.Composite)

Example 22 with PropertyChangeCommand

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

the class PropertyTypeController method createButtonCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createControl(org.eclipse
     * .swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
protected Command createButtonCommand(Button button) {
    // hwang add for feature 6484
    FileItem repositoryFileItem = null;
    LinkRulesItem linkItem = null;
    Map<String, FileItem> repositoryFileItemMap = null;
    Map<String, LinkRulesItem> repositoryLinkRulesItemMap = null;
    String paramName = (String) button.getData(PARAMETER_NAME);
    IElementParameter param = elem.getElementParameter(paramName);
    Object data = button.getData(NAME);
    if (data != null && data.equals(REPOSITORY_CHOICE)) {
        IElementParameter dbTypeParam = null;
        if (elem instanceof org.talend.designer.core.ui.editor.process.Process || elem instanceof StatsAndLogsElement || elem instanceof ImplicitContextLoadElement) {
            if (EParameterName.PROPERTY_TYPE.getName().equals(paramName)) {
                dbTypeParam = elem.getElementParameter(EParameterName.DB_TYPE.getName());
            } else if (JobSettingsConstants.getExtraParameterName(EParameterName.PROPERTY_TYPE.getName()).equals(paramName)) {
                dbTypeParam = elem.getElementParameter(JobSettingsConstants.getExtraParameterName(EParameterName.DB_TYPE.getName()));
            }
        }
        Item item = null;
        String id = null;
        RepositoryNode selectNode = null;
        if (id == null) {
            RepositoryReviewDialog dialog = null;
            if (dbTypeParam != null) {
                String[] listRepositoryItems = dbTypeParam.getListRepositoryItems();
                dialog = new RepositoryReviewDialog(Display.getCurrent().getActiveShell(), ERepositoryObjectType.METADATA, param.getRepositoryValue(), listRepositoryItems);
            } else {
                // Added TDQ-11688
                ITDQPatternService service = null;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQPatternService.class)) {
                    service = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
                }
                if (service != null && service.isSinglePatternNode(elem)) {
                    return processPattern(elem);
                }
                // ~
                dialog = new RepositoryReviewDialog(Display.getCurrent().getActiveShell(), ERepositoryObjectType.METADATA, elem, param);
            }
            if (dialog.open() == RepositoryReviewDialog.OK) {
                selectNode = dialog.getResult();
                id = selectNode.getObject().getId();
            }
        }
        if (id != null && !"".equals(id)) {
            //$NON-NLS-1$
            IElementParameter repositoryParam = param.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            //$NON-NLS-1$
            String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
            Connection repositoryConnection = null;
            // Map<String, ConnectionItem> repositoryConnectionItemMap =
            // dynamicProperty.getRepositoryConnectionItemMap();
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(id);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            if (item != null) {
                if (item instanceof ConnectionItem) {
                    repositoryConnection = ((ConnectionItem) item).getConnection();
                }
            } else {
                repositoryConnection = null;
                if (repositoryParam != null) {
                    item = selectNode.getObject().getProperty().getItem();
                    if (item instanceof ConnectionItem) {
                        repositoryConnection = ((ConnectionItem) item).getConnection();
                    }
                }
            }
            if (repositoryConnection != null) {
                CompoundCommand compoundCommand = new CompoundCommand();
                ChangeValuesFromRepository changeValuesFromRepository = null;
                if (selectNode.getObjectType() == ERepositoryObjectType.SERVICESOPERATION && GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
                    IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
                    IProcess2 process = (IProcess2) RepositoryPlugin.getDefault().getDesignerCoreService().getCurrentProcess();
                    String currentJobId = process.getProperty().getId();
                    String serviceId = item.getProperty().getId();
                    String portId = selectNode.getParent().getObject().getId();
                    String operationId = selectNode.getObject().getId();
                    changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, param.getName() + ":" + //$NON-NLS-1$
                    EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$ //$NON-NLS-2$
                    serviceId + " - " + portId + " - " + operationId);
                    service.deleteOldRelation(currentJobId);
                    //$NON-NLS-1$ //$NON-NLS-2$
                    service.updateOperation((INode) elem, serviceId + " - " + portId + " - " + operationId, selectNode);
                } else {
                    changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, fullParamName, id);
                }
                if (changeValuesFromRepository != null) {
                    compoundCommand.add(changeValuesFromRepository);
                }
                updateDBType(compoundCommand, repositoryConnection);
                return compoundCommand;
            }
            // for ruleItem,hywang add
            if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
                repositoryFileItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryFileItemMap();
                repositoryLinkRulesItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryLinkRulesItemMap();
            }
            if (repositoryFileItemMap.containsKey(id)) {
                repositoryFileItem = repositoryFileItemMap.get(id);
            } else if (repositoryLinkRulesItemMap.containsKey(id)) {
                linkItem = repositoryLinkRulesItemMap.get(id);
            } else {
                if (!repositoryFileItemMap.isEmpty()) {
                    repositoryFileItem = repositoryFileItemMap.values().iterator().next();
                } else {
                    repositoryFileItem = null;
                }
            }
            if (repositoryFileItem == null && item instanceof FileItem) {
                repositoryFileItem = (FileItem) item;
            }
            if (repositoryFileItem != null) {
                CompoundCommand compoundCommand = new CompoundCommand();
                final String showId = repositoryFileItem.getProperty().getId();
                Command command = new PropertyChangeCommand(elem, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
                compoundCommand.add(command);
                return compoundCommand;
            }
            if (linkItem != null) {
                CompoundCommand compoundCommand = new CompoundCommand();
                final String showId = linkItem.getProperty().getId();
                Command command = new PropertyChangeCommand(elem, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
                compoundCommand.add(command);
                return compoundCommand;
            }
        }
    } else {
        // 1. open wizard
        if (elem instanceof INode) {
            INode node = (INode) elem;
            final IRepositoryService repositoryService = CorePlugin.getDefault().getRepositoryService();
            if (param != null) {
                RepositoryNode realNode = null;
                String repositoryValue = param.getRepositoryValue();
                if (repositoryValue != null && repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_CONNECTIONS);
                } else // file delimited
                if (ERepositoryCategoryType.DELIMITED.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_DELIMITED);
                }
                // file positional
                if (ERepositoryCategoryType.POSITIONAL.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_POSITIONAL);
                }
                // file regexp
                if (ERepositoryCategoryType.REGEX.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_REGEXP);
                }
                // file xml
                if (ERepositoryCategoryType.XML.getName().equals(repositoryValue) || // bug 18012
                repositoryValue.startsWith(ERepositoryCategoryType.XML.getName())) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_XML);
                }
                // file ldif
                if (ERepositoryCategoryType.LDIF.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_LDIF);
                }
                // excel
                if (ERepositoryCategoryType.EXCEL.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EXCEL);
                }
                // generic schema
                if (ERepositoryCategoryType.GENERIC.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_GENERIC_SCHEMA);
                }
                // ldap
                if (ERepositoryCategoryType.LDAP.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_LDAP_SCHEMA);
                }
                // wsdl
                if (ERepositoryCategoryType.WSDL.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
                }
                if (ERepositoryCategoryType.WEBSERVICE.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_WSDL_SCHEMA);
                }
                // salesforce
                if (ERepositoryCategoryType.SALESFORCE.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
                }
                // ebcdic
                if (ERepositoryCategoryType.EBCDIC.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_EBCDIC);
                }
                // mdm
                if (ERepositoryCategoryType.MDM.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_MDMCONNECTION);
                }
                // sap
                if (ERepositoryCategoryType.SAP.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAPCONNECTIONS);
                }
                // sapIDoc
                if (ERepositoryCategoryType.SAPIDOC.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_SAP_IDOC);
                }
                if (ERepositoryCategoryType.HEADERFOOTER.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_HEADER_FOOTER);
                }
                // brms
                if (ERepositoryCategoryType.BRMS.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_BRMS);
                }
                // hl7
                if (ERepositoryCategoryType.HL7.getName().equals(repositoryValue)) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.METADATA_FILE_HL7);
                }
                // last resort we assume that the repository value was named after the root component type key
                if (realNode == null) {
                    realNode = (RepositoryNode) repositoryService.getRootRepositoryNode(ERepositoryObjectType.getTypeFromKey(repositoryValue));
                }
                if (realNode != null) {
                    final IMetadataService metadataService = CorePlugin.getDefault().getMetadataService();
                    if (metadataService != null) {
                        ConnectionItem connItem = metadataService.openMetadataConnection(true, realNode, node);
                        if (connItem != null) {
                            IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
                            propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                            // 2. commnd
                            Command cmd = new ChangeValuesFromRepository(node, connItem.getConnection(), //$NON-NLS-1$
                            propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), connItem.getProperty().getId());
                            executeCommand(cmd);
                            // see bug in feature 5998.refresh repositoryList.
                            if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
                                ((MultipleThreadDynamicComposite) dynamicProperty).updateRepositoryList();
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) MultipleThreadDynamicComposite(org.talend.designer.core.ui.views.properties.MultipleThreadDynamicComposite) IRepositoryService(org.talend.repository.model.IRepositoryService) 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) IElementParameter(org.talend.core.model.process.IElementParameter) ITDQPatternService(org.talend.core.ITDQPatternService) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) 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) RepositoryNode(org.talend.repository.model.RepositoryNode) RepositoryReviewDialog(org.talend.repository.ui.dialog.RepositoryReviewDialog) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IESBService(org.talend.core.IESBService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ImplicitContextLoadElement(org.talend.designer.core.ui.projectsetting.ImplicitContextLoadElement) StatsAndLogsElement(org.talend.designer.core.ui.projectsetting.StatsAndLogsElement) IMetadataService(org.talend.repository.model.IMetadataService)

Example 23 with PropertyChangeCommand

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

the class ModuleListController method createCommand.

public Command createCommand(Button button) {
    Node node = (Node) elem;
    IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
    if (externalNode != null && externalNode.getUniqueName().contains("tBRMS_")) {
        IConfigurationElement[] elems = Platform.getExtensionRegistry().getConfigurationElementsFor("org.talend.designer.core.brms_provider");
        String propertyName = (String) button.getData(PARAMETER_NAME);
        for (IConfigurationElement conElem : elems) {
            IBrmsExtension createExecutableExtension;
            try {
                createExecutableExtension = (IBrmsExtension) conElem.createExecutableExtension("class");
                createExecutableExtension.initialize(node, propertyName, hashCurControls);
                BrmsDialog brmsDialog = createExecutableExtension.createBrmsDialog(composite.getShell());
                String file = brmsDialog.getFile();
                if (file != null && !file.equals("")) {
                    String lastSegment = TalendTextUtils.addQuotes(Path.fromOSString(file).lastSegment());
                    try {
                        CorePlugin.getDefault().getLibrariesService().deployLibrary(Path.fromOSString(file).toFile().toURL());
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                    }
                    // update the combo current value
                    CCombo combo = (CCombo) hashCurControls.get(propertyName);
                    if (combo != null && !combo.isDisposed()) {
                        combo.setText(Path.fromOSString(file).lastSegment());
                    }
                    return new PropertyChangeCommand(elem, propertyName, lastSegment);
                }
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    } else {
        FileDialog dial = new FileDialog(composite.getShell(), SWT.NONE);
        dial.setFilterExtensions(FilesUtils.getAcceptJARFilesSuffix());
        String file = dial.open();
        if (file != null && !file.equals("")) {
            //$NON-NLS-1$
            String propertyName = (String) button.getData(PARAMETER_NAME);
            String lastSegment = TalendTextUtils.addQuotes(Path.fromOSString(file).lastSegment());
            try {
                CorePlugin.getDefault().getLibrariesService().deployLibrary(Path.fromOSString(file).toFile().toURL());
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
            if (!elem.getPropertyValue(propertyName).equals(lastSegment)) {
                // update the combo current value
                CCombo combo = (CCombo) hashCurControls.get(propertyName);
                if (combo != null && !combo.isDisposed()) {
                    combo.setText(Path.fromOSString(file).lastSegment());
                }
                return new PropertyChangeCommand(elem, propertyName, lastSegment);
            }
        }
    }
    return null;
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CoreException(org.eclipse.core.runtime.CoreException) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) BrmsDialog(org.talend.designer.core.ui.dialog.BrmsDialog) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) FileDialog(org.eclipse.swt.widgets.FileDialog) IBrmsExtension(org.talend.designer.core.ui.dialog.IBrmsExtension) CoreException(org.eclipse.core.runtime.CoreException) IExternalNode(org.talend.core.model.process.IExternalNode)

Example 24 with PropertyChangeCommand

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

the class PasswordController method createButtonCommand.

protected Command createButtonCommand(final Button button) {
    if (button.getData(NAME).equals(PASSWORD)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter param = elem.getElementParameter(paramName);
        //$NON-NLS-1$
        String initValue = "\"\"";
        if (param.getValue() != null && ContextParameterUtils.containContextVariables(param.getValue().toString())) {
            initValue = param.getValue().toString();
        }
        InputDialog dlg = new InputDialog(button.getShell(), //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("PasswordController.NewPassword"), //$NON-NLS-1$ //$NON-NLS-2$
        Messages.getString("PasswordController.NoteConvention"), initValue, null) {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
                 */
            @Override
            protected Control createDialogArea(Composite parent) {
                Control control = super.createDialogArea(parent);
                String paramName = (String) button.getData(PARAMETER_NAME);
                getText().setData(PARAMETER_NAME, paramName);
                editionControlHelper.register(paramName, getText());
                return control;
            }
        };
        if (dlg.open() == Window.OK) {
            elem.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), new Boolean(true));
            return new PropertyChangeCommand(elem, paramName, dlg.getValue());
        }
    }
    return null;
}
Also used : Control(org.eclipse.swt.widgets.Control) InputDialog(org.eclipse.jface.dialogs.InputDialog) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Composite(org.eclipse.swt.widgets.Composite) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 25 with PropertyChangeCommand

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

the class SapSchemaTypeController 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) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    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) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        /* see bug 16969 */
        // if (repositoryTableMap.containsKey(schemaSelected)) {
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // newRepositoryIdValue = schemaSelected;// + " - " + repositoryMetadata.getLabel();
        // } else {
        // if (repositoryTableMap.keySet().size() == 0) {
        // repositoryMetadata = new MetadataTable();
        // } else {
        // newRepositoryIdValue = repositoryTableMap.keySet().iterator().next();
        // // Gets the schema of the first item in repository schema type combo.
        // repositoryMetadata = repositoryTableMap.get(newRepositoryIdValue);
        // // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
        // // newRepositoryIdValue = newRepositoryIdValue + " - " + repositoryMetadata.getLabel();
        // }
        // }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)69 IElementParameter (org.talend.core.model.process.IElementParameter)34 Command (org.eclipse.gef.commands.Command)24 Point (org.eclipse.swt.graphics.Point)18 INode (org.talend.core.model.process.INode)18 Node (org.talend.designer.core.ui.editor.nodes.Node)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Control (org.eclipse.swt.widgets.Control)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)13 RepositoryNode (org.talend.repository.model.RepositoryNode)12 CCombo (org.eclipse.swt.custom.CCombo)11 IConnection (org.talend.core.model.process.IConnection)11 ConnectionItem (org.talend.core.model.properties.ConnectionItem)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)10 Item (org.talend.core.model.properties.Item)10 Button (org.eclipse.swt.widgets.Button)9 Text (org.eclipse.swt.widgets.Text)8 MetadataTable (org.talend.core.model.metadata.MetadataTable)8