Search in sources :

Example 6 with ComponentSetting

use of org.talend.core.model.properties.ComponentSetting in project tdi-studio-se by Talend.

the class ChangeComponentSettingNameMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.migration.IProjectMigrationTask#execute(org.talend.core.model.general.Project)
     */
@Override
public ExecutionResult execute(Project project) {
    List<ComponentSetting> components = project.getEmfProject().getComponentsSettings();
    List<ComponentSetting> newAdded = new ArrayList<ComponentSetting>();
    Set<IComponent> componentList = ComponentsFactoryProvider.getInstance().getComponents();
    for (ComponentSetting componentSetting : components) {
        for (IComponent comp : componentList) {
            if (comp != null && comp.getName().equals(componentSetting.getName())) {
                componentSetting.setName(comp.getPaletteType() + "|" + comp.getName());
                String family = componentSetting.getFamily();
                if (family.contains("|")) {
                    String[] fams = family.split("\\|");
                    for (int i = 0; i < fams.length; i++) {
                        if (i == 0) {
                            componentSetting.setFamily(fams[0]);
                        } else {
                            ComponentSetting cs = PropertiesFactory.eINSTANCE.createComponentSetting();
                            cs.setName(comp.getPaletteType() + "|" + comp.getName());
                            cs.setHidden(componentSetting.isHidden());
                            cs.setFamily(fams[i]);
                            newAdded.add(cs);
                        }
                    }
                }
                break;
            }
        }
    }
    components.addAll(newAdded);
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) ComponentSetting(org.talend.core.model.properties.ComponentSetting)

Example 7 with ComponentSetting

use of org.talend.core.model.properties.ComponentSetting in project tdi-studio-se by Talend.

the class VisibleComponentSettingsMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    Project currentProject = ProjectManager.getInstance().getCurrentProject();
    List<ComponentSetting> componentsSettings = (List<ComponentSetting>) currentProject.getEmfProject().getComponentsSettings();
    boolean modified = false;
    if (processType != null) {
        EList nodes = processType.getNode();
        for (Object node : nodes) {
            NodeType nodeType = (NodeType) node;
            for (ComponentSetting setting : componentsSettings) {
                if (setting.getName().equals(nodeType.getComponentName())) {
                    if (setting.isHidden()) {
                        setting.setHidden(false);
                        modified = true;
                    }
                }
            }
        }
    }
    if (modified) {
        IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
        try {
            prf.saveProject(currentProject);
        } catch (Exception ex) {
            ExceptionHandler.process(ex);
            return ExecutionResult.FAILURE;
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : Project(org.talend.core.model.general.Project) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EList(org.eclipse.emf.common.util.EList) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) ComponentSetting(org.talend.core.model.properties.ComponentSetting) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 8 with ComponentSetting

use of org.talend.core.model.properties.ComponentSetting in project tdi-studio-se by Talend.

the class ImportProjectSettings method updateProjectSettings.

public void updateProjectSettings() throws ParserConfigurationException, SAXException, IOException {
    if (this.path == null) {
        return;
    }
    File file = new File(path);
    org.talend.core.model.properties.Project project = pro.getEmfProject();
    final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
    DocumentBuilder analyseur = fabrique.newDocumentBuilder();
    analyseur.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(final SAXParseException exception) throws SAXException {
            throw exception;
        }

        @Override
        public void fatalError(final SAXParseException exception) throws SAXException {
            throw exception;
        }

        @Override
        public void warning(final SAXParseException exception) throws SAXException {
            throw exception;
        }
    });
    final Document document = analyseur.parse(file);
    // PTODO, if need, get the version from the imported file.
    // NodeList exportParametersNodes = document.getElementsByTagName("exportParameters");
    // String importStudioVersion=null;
    //$NON-NLS-1$
    final NodeList nodes = document.getElementsByTagName("exportParameter");
    List addedComponentSetting = new ArrayList();
    List technical = project.getTechnicalStatus();
    List documentation = project.getDocumentationStatus();
    technical.clear();
    documentation.clear();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        final NamedNodeMap attrMap = node.getAttributes();
        //$NON-NLS-1$
        final Node typeAttr = attrMap.getNamedItem("type");
        if ("technicalStatus".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            updateStatus(node, attrMap, technical, "technicalStatus");
        } else if ("documentationStatus".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            updateStatus(node, attrMap, documentation, "documentationStatus");
        } else if ("security".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            project.isHidePassword();
            project.setHidePassword(Boolean.valueOf(node.getTextContent()));
        } else if ("statAndLogs".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            if (project.getStatAndLogsSettings() == null) {
                TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
                StatAndLogsSettings stats = PropertiesFactory.eINSTANCE.createStatAndLogsSettings();
                project.setStatAndLogsSettings(stats);
                stats.setParameters(talendF.createParametersType());
            }
            List statAndLogs = project.getStatAndLogsSettings().getParameters().getElementParameter();
            updateParameters(node, attrMap, statAndLogs);
        } else if ("implicitContext".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            if (project.getImplicitContextSettings() == null) {
                TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
                ImplicitContextSettings implicit = PropertiesFactory.eINSTANCE.createImplicitContextSettings();
                project.setImplicitContextSettings(implicit);
                implicit.setParameters(talendF.createParametersType());
            }
            List implicitContexts = project.getImplicitContextSettings().getParameters().getElementParameter();
            updateParameters(node, attrMap, implicitContexts);
        } else if ("palette".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            List componentSettings = project.getComponentsSettings();
            boolean existed = false;
            //$NON-NLS-1$
            String name = attrMap.getNamedItem("name").getTextContent();
            //$NON-NLS-1$
            final Node familyAttr = attrMap.getNamedItem("family");
            Boolean hide = Boolean.valueOf(node.getTextContent());
            for (Object obj : componentSettings) {
                ComponentSetting setting = (ComponentSetting) obj;
                if (setting.getName().equals(name)) {
                    if (familyAttr != null && familyAttr.getTextContent().equals(setting.getFamily())) {
                        existed = true;
                        setting.setHidden(hide);
                    }
                }
            }
            if (!existed && familyAttr != null) {
                ComponentSetting setting = PropertiesFactory.eINSTANCE.createComponentSetting();
                setting.setFamily(familyAttr.getTextContent());
                setting.setName(name);
                setting.setHidden(hide);
                addedComponentSetting.add(setting);
            }
        }
    }
    project.getComponentsSettings().addAll(addedComponentSetting);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) TalendFileFactory(org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory) SAXParseException(org.xml.sax.SAXParseException) StatAndLogsSettings(org.talend.core.model.properties.StatAndLogsSettings) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ErrorHandler(org.xml.sax.ErrorHandler) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) ComponentSetting(org.talend.core.model.properties.ComponentSetting) ImplicitContextSettings(org.talend.core.model.properties.ImplicitContextSettings) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File)

Example 9 with ComponentSetting

use of org.talend.core.model.properties.ComponentSetting in project tdi-studio-se by Talend.

the class ExportProjectSettings method savePalette.

/**
     * wchen Comment method "saveParameters".
     * 
     * @param document
     * @param root
     * @param list
     */
private void savePalette(Document document, Element root, List list) {
    for (Object obj : list) {
        //$NON-NLS-1$
        Element exportParameter = document.createElement("exportParameter");
        root.appendChild(exportParameter);
        //$NON-NLS-1$
        Attr typeAttr = document.createAttribute("type");
        //$NON-NLS-1$
        typeAttr.setNodeValue("palette");
        exportParameter.setAttributeNode(typeAttr);
        //$NON-NLS-1$
        Attr name = document.createAttribute("name");
        name.setNodeValue(((ComponentSetting) obj).getName());
        exportParameter.setAttributeNode(name);
        //$NON-NLS-1$
        Attr family = document.createAttribute("family");
        family.setNodeValue(((ComponentSetting) obj).getFamily());
        exportParameter.setAttributeNode(family);
        exportParameter.setTextContent(String.valueOf(((ComponentSetting) obj).isHidden()));
    }
}
Also used : Element(org.w3c.dom.Element) ComponentSetting(org.talend.core.model.properties.ComponentSetting) Attr(org.w3c.dom.Attr)

Aggregations

ComponentSetting (org.talend.core.model.properties.ComponentSetting)9 ArrayList (java.util.ArrayList)3 List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 IComponent (org.talend.core.model.components.IComponent)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 RepositoryContext (org.talend.core.context.RepositoryContext)1 IComponentsFactory (org.talend.core.model.components.IComponentsFactory)1 Project (org.talend.core.model.general.Project)1 ImplicitContextSettings (org.talend.core.model.properties.ImplicitContextSettings)1 StatAndLogsSettings (org.talend.core.model.properties.StatAndLogsSettings)1 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)1 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)1 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)1 TalendFileFactory (org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory)1