Search in sources :

Example 16 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class DynamicTabbedPropertySection method updateContextList.

/**
     * ftang Comment method "updateContextList".
     */
private void updateContextList() {
    List<String> contextNameList = new ArrayList<String>();
    List<String> contextValueList = new ArrayList<String>();
    IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    String selectedProcess = null;
    for (int i = 0; (i < elem.getElementParameters().size()) && (selectedProcess == null); i++) {
        IElementParameter param = elem.getElementParameters().get(i);
        if (param.getName().equals(EParameterName.PROCESS_TYPE_PROCESS.getName())) {
            selectedProcess = (String) param.getValue();
        }
    }
    if (selectedProcess == null) {
        return;
    }
    try {
        List<IRepositoryViewObject> list = factory.getAll(ERepositoryObjectType.PROCESS);
        for (IRepositoryViewObject process : list) {
            String id = process.getLabel();
            if (selectedProcess.equals(id)) {
                if (process.getProperty().getItem() instanceof ProcessItem) {
                    ProcessItem processItem = (ProcessItem) process.getProperty().getItem();
                    for (Object o : processItem.getProcess().getContext()) {
                        if (o instanceof ContextType) {
                            ContextType context = (ContextType) o;
                            contextNameList.add(context.getName());
                            contextValueList.add(context.getName());
                        }
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    String[] contextTableNameList = contextNameList.toArray(new String[0]);
    String[] contextTableValueList = contextValueList.toArray(new String[0]);
    for (int i = 0; i < elem.getElementParameters().size(); i++) {
        IElementParameter param = elem.getElementParameters().get(i);
        if (param.getName().equals(EParameterName.PROCESS_TYPE_CONTEXT.getName())) {
            param.setListItemsDisplayName(contextTableNameList);
            param.setListItemsValue(contextTableValueList);
            if (!contextValueList.contains(param.getValue())) {
                if (contextTableNameList.length > 0) {
                    elem.setPropertyValue(EParameterName.PROCESS_TYPE_CONTEXT.getName(), contextTableValueList[0]);
                }
            } else {
                // force to store the value again to activate the code
                // generation in Node.setPropertyValue
                elem.setPropertyValue(EParameterName.PROCESS_TYPE_CONTEXT.getName(), param.getValue());
            }
        }
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 17 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class JSONFileStep1Form method initialize.

/**
     * 
     * Initialize value, forceFocus first field.
     */
@Override
protected void initialize() {
    getConnection().setInputModel(true);
    availableJSONTreeViewer = new TreeViewer(availableJSONTree);
    this.xmlTreePopulator = new TreePopulator(availableJSONTreeViewer);
    // this.xmlTreePopulator.configureDefaultTreeViewer();
    this.jsonTreePopulator = new JsonTreePopulator(availableJSONTreeViewer);
    // this.jsonTreePopulator.configureDefaultTreeViewer();
    this.availableJSONTreeViewer.setUseHashlookup(true);
    // add init of CheckBoxIsGuess and Determine the Initialize checkFileXsdorJSON
    // if (getConnection().getXsdFilePath() != null) {
    // fileFieldXsd.setText(getConnection().getXsdFilePath().replace("\\\\", "\\"));
    // // init the fileViewer
    // this.treePopulator.populateTree(fileFieldXsd.getText(), treeNode);
    // checkFieldsValue();
    // }
    EJsonReadbyMode eJsonReadbyMode = null;
    if (getConnection().getReadbyMode() != null) {
        eJsonReadbyMode = EJsonReadbyMode.getEJsonReadbyModeByValue(getConnection().getReadbyMode());
    }
    if (eJsonReadbyMode == null) {
        eJsonReadbyMode = getDefaultJsonReadbyMode();
    }
    // JSONFileStep1Form.this.wizard.setReadbyMode(readbyCombo.getText());
    readbyCombo.setText(eJsonReadbyMode.getDisplayName());
    getConnection().setReadbyMode(eJsonReadbyMode.getValue());
    JSONFileStep1Form.this.wizard.setReadbyMode(eJsonReadbyMode.getValue());
    if (getConnection().getJSONFilePath() != null) {
        //$NON-NLS-1$ //$NON-NLS-2$
        fileFieldJSON.setText(getConnection().getJSONFilePath().replace("\\\\", "\\"));
        // init the fileViewer
        checkFieldsValue();
        String jsonFilePath = fileFieldJSON.getText();
        if (isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection());
            jsonFilePath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, fileFieldJSON.getText()));
        }
        File file = new File(jsonFilePath);
        if (!file.exists() && getConnection().getFileContent() != null && getConnection().getFileContent().length > 0) {
            initFileContent();
            jsonFilePath = tempJSONXsdPath;
        }
        String tempxml = null;
        tempxml = getFilePath4Populate(jsonFilePath);
        switchPopulator(JSONFileStep1Form.this.wizard.getReadbyMode(), tempxml);
    }
    // Fields to the Group Delimited File Settings
    if (getConnection().getEncoding() != null && !getConnection().getEncoding().equals("")) {
        //$NON-NLS-1$
        encodingCombo.setText(getConnection().getEncoding());
    } else {
        encodingCombo.select(0);
    }
    encodingCombo.clearSelection();
    // if (getConnection().getMaskXPattern() != null) {
    // fieldMaskXPattern.setText(getConnection().getMaskXPattern().replace("\\\\", "\\"));
    // }
    adaptFormToEditable();
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) JsonTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator) AbstractTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.AbstractTreePopulator) TreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.xml.TreePopulator) TreeViewer(org.eclipse.jface.viewers.TreeViewer) EJsonReadbyMode(org.talend.repository.ui.wizards.metadata.connection.files.json.EJsonReadbyMode) JsonTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator) File(java.io.File)

Example 18 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class JSONFileStep1Form method addFieldsListeners.

/**
     * Main Fields addControls.
     */
@Override
protected void addFieldsListeners() {
    // fileFieldXsd : Event modifyText
    // fileFieldXsd.addModifyListener(new ModifyListener() {
    //
    // public void modifyText(final ModifyEvent e) {
    // getConnection().setXsdFilePath(fileFieldXsd.getText());
    // treePopulator.populateTree(fileFieldXsd.getText(), treeNode);
    // checkFieldsValue();
    // }
    // });
    // fileFieldJSON.addSelectionListener(new SelectionListener() {
    //
    // public void widgetSelected(SelectionEvent event) {
    // if (fileFieldJSON.getResult() == null) {
    // return;
    // }
    // String text = fileFieldJSON.getText();
    // if (isContextMode()) {
    // ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(
    // connectionItem.getConnection(), true);
    // text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
    // }
    // // getConnection().setJSONFilePath(PathUtils.getPortablePath(JSONXsdFilePath.getText()));
    // File file = new File(text);
    // if (file.exists()) {
    // if (file.exists()) {
    // String tempxml = JSONUtil.changeJsonToXml(text);
    // JSONFileStep1Form.this.wizard.setTempJsonPath(tempxml);
    // valid = treePopulator.populateTree(tempxml, treeNode);
    // }
    // // add for bug TDI-20432
    // checkFieldsValue();
    // }
    //
    // }
    //
    // public void widgetDefaultSelected(SelectionEvent e) {
    //
    // }
    // });
    readbyCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            EJsonReadbyMode eJsonReadbyMode = EJsonReadbyMode.getEJsonReadbyModeByDisplayName(readbyCombo.getText());
            if (eJsonReadbyMode == null) {
                eJsonReadbyMode = getDefaultJsonReadbyMode();
            }
            String readbyMode = eJsonReadbyMode.getValue();
            JSONFileStep1Form.this.wizard.setReadbyMode(readbyMode);
            String jsonPath = fileFieldJSON.getText();
            String text = validateJsonFilePath(jsonPath);
            if (text == null || text.isEmpty()) {
                return;
            }
            String tempxml = null;
            if (EJsonReadbyMode.JSONPATH.getValue().equals(readbyMode)) {
                tempxml = text;
            } else {
                tempxml = JSONUtil.changeJsonToXml(text);
            }
            JSONFileStep1Form.this.wizard.setTempJsonPath(tempxml);
            switchPopulator(readbyMode, tempxml);
        }
    });
    // fileFieldJSON : Event modifyText
    fileFieldJSON.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            String jsonPath = fileFieldJSON.getText();
            String _jsonPath = jsonPath;
            if (isContextMode()) {
                ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
                jsonPath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, jsonPath));
            }
            String text = validateJsonFilePath(jsonPath);
            if (text == null || text.isEmpty()) {
                return;
            }
            String tempxml = null;
            String readbyMode = JSONFileStep1Form.this.wizard.getReadbyMode();
            if (EJsonReadbyMode.JSONPATH.getValue().equals(readbyMode)) {
                tempxml = text;
            } else {
                tempxml = JSONUtil.changeJsonToXml(text);
            }
            File file = new File(text);
            if (!file.exists()) {
                file = new File(JSONUtil.tempJSONXsdPath);
            }
            JSONFileStep1Form.this.wizard.setTempJsonPath(tempxml);
            String limitString = commonNodesLimitation.getText();
            try {
                limit = Integer.valueOf(limitString);
                labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, limit));
            } catch (Exception excpt) {
            // nothing need to do
            }
            switchPopulator(readbyMode, tempxml);
            // }
            // add for bug TDI-20432
            checkFieldsValue();
            if (getConnection().getJSONFilePath() != null && !getConnection().getJSONFilePath().equals(text)) {
                getConnection().getLoop().clear();
                xsdPathChanged = true;
            } else {
                xsdPathChanged = false;
            }
            if (isContextMode()) {
                jsonPath = _jsonPath;
            }
            if (Path.fromOSString(jsonPath).toFile().isFile()) {
                getConnection().setJSONFilePath(PathUtils.getPortablePath(jsonPath));
            } else {
                getConnection().setJSONFilePath(jsonPath);
            }
            JSONWizard wizard = ((JSONWizard) getPage().getWizard());
            wizard.setTreeRootNode(treeNode);
            BufferedReader in = null;
            try {
                Charset guessedCharset = CharsetToolkit.guessEncoding(file, 4096);
                String str;
                in = new BufferedReader(new InputStreamReader(new FileInputStream(file), guessedCharset.displayName()));
                while ((str = in.readLine()) != null) {
                    if (str.contains("encoding")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        String regex = "^<\\?JSON\\s*version=\\\"[^\\\"]*\\\"\\s*encoding=\\\"([^\\\"]*)\\\"\\?>$";
                        Perl5Compiler compiler = new Perl5Compiler();
                        Perl5Matcher matcher = new Perl5Matcher();
                        Pattern pattern = null;
                        try {
                            pattern = compiler.compile(regex);
                            if (matcher.contains(str, pattern)) {
                                MatchResult matchResult = matcher.getMatch();
                                if (matchResult != null) {
                                    encoding = matchResult.group(1);
                                }
                            }
                        } catch (MalformedPatternException malE) {
                            ExceptionHandler.process(malE);
                        }
                    }
                }
            } catch (Exception ex) {
                String fileStr = text;
                String msgError = //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                "JSON" + " \"" + fileStr.replace("\\\\", "\\") + //$NON-NLS-1$
                "\"\n";
                if (ex instanceof FileNotFoundException) {
                    msgError = msgError + "is not found";
                } else if (ex instanceof EOFException) {
                    msgError = msgError + "have an incorrect character EOF";
                } else if (ex instanceof IOException) {
                    msgError = msgError + "is locked by another soft";
                } else {
                    msgError = msgError + "doesn't exist";
                }
                if (!isReadOnly()) {
                    updateStatus(IStatus.ERROR, msgError);
                }
            // ExceptionHandler.process(ex);
            } finally {
                try {
                    if (in != null) {
                        in.close();
                    }
                } catch (Exception ex2) {
                    ExceptionHandler.process(ex2);
                }
            }
            if (getConnection().getEncoding() == null || "".equals(getConnection().getEncoding())) {
                //$NON-NLS-1$
                getConnection().setEncoding(encoding);
                if (encoding != null && !("").equals(encoding)) {
                    //$NON-NLS-1$
                    encodingCombo.setText(encoding);
                } else {
                    //$NON-NLS-1$
                    encodingCombo.setText("UTF-8");
                }
            }
            // if (tempJSONXsdPath != null && getConnection().getFileContent() != null
            // && getConnection().getFileContent().length > 0 && !isModifing) {
            // valid = treePopulator.populateTree(tempJSONXsdPath, treeNode);
            // } else {
            // valid = treePopulator.populateTree(text, treeNode);
            // }
            checkFieldsValue();
            isModifing = true;
        }
    });
    // Event encodingCombo
    encodingCombo.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            getConnection().setEncoding(encodingCombo.getText());
            checkFieldsValue();
        }
    });
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) Perl5Compiler(org.apache.oro.text.regex.Perl5Compiler) Pattern(org.apache.oro.text.regex.Pattern) ModifyListener(org.eclipse.swt.events.ModifyListener) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) Charset(java.nio.charset.Charset) EJsonReadbyMode(org.talend.repository.ui.wizards.metadata.connection.files.json.EJsonReadbyMode) Perl5Matcher(org.apache.oro.text.regex.Perl5Matcher) IOException(java.io.IOException) MatchResult(org.apache.oro.text.regex.MatchResult) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) BusinessException(org.talend.commons.exception.BusinessException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) FileInputStream(java.io.FileInputStream) ModifyEvent(org.eclipse.swt.events.ModifyEvent) BufferedReader(java.io.BufferedReader) EOFException(java.io.EOFException) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) File(java.io.File)

Example 19 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class JSONFileStep1Form method setVisible.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.widgets.Control#setVisible(boolean)
     */
@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (isReadOnly() != readOnly) {
        adaptFormToReadOnly();
    }
    if (super.isVisible()) {
        String JSONFilePath = getConnection().getJSONFilePath();
        // Fields to the Group Delimited File Settings
        if (getConnection().getEncoding() != null && !getConnection().getEncoding().equals("")) {
            //$NON-NLS-1$
            encodingCombo.setText(getConnection().getEncoding());
            isModifing = false;
            fileFieldJSON.setText(JSONFilePath);
        } else {
            encodingCombo.select(0);
        }
        if (isContextMode()) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
            JSONFilePath = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, JSONFilePath));
        }
        if (!creation) {
            updateTreeNodes(JSONFilePath);
            JSONWizard wizard = ((JSONWizard) getPage().getWizard());
            if (wizard.getTreeRootNode() == null) {
                wizard.setTreeRootNode(treeNode);
            }
        }
        if (LanguageManager.getCurrentLanguage() == ECodeLanguage.PERL && GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
            ILibrariesService moduleService = (ILibrariesService) GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
            try {
                ELibraryInstallStatus status = moduleService.getLibraryStatus("JSON::LibJSON");
                if (status != ELibraryInstallStatus.INSTALLED) {
                    new ErrorDialogWidthDetailArea(getShell(), PID, "The Perl Module" + " JSON::LibJSON " + "is not installed", "For more information, check out Talend's Wiki website at http\\://talendforge.org/wiki/doku.php.");
                    log.error("The Perl Module" + " JSON::LibJSONL " + "is not installed");
                }
            } catch (BusinessException e) {
                new ErrorDialogWidthDetailArea(getShell(), PID, "The Perl Module" + " JSON::LibJSON " + "is not installed", "For more information, check out Talend's Wiki website at http\\://talendforge.org/wiki/doku.php.");
                log.error("The Perl Module" + " JSON::LibJSONL " + "is not installed");
            }
        }
        adaptFormToEditable();
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) BusinessException(org.talend.commons.exception.BusinessException) ILibrariesService(org.talend.core.model.general.ILibrariesService) ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea) ELibraryInstallStatus(org.talend.core.model.general.ModuleNeeded.ELibraryInstallStatus)

Example 20 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class JSONFileStep2Form method setVisible.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.swt.widgets.Control#setVisible(boolean)
     */
@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (super.isVisible()) {
        if (this.linker != null) {
            this.linker.removeAllLinks();
        }
        String pathStr = getConnection().getJSONFilePath();
        boolean isContextMode = isContextMode();
        if (isContextMode) {
            ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), connectionItem.getConnection().getContextName());
            pathStr = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, pathStr));
        }
        exportContextBtn.setEnabled(!isContextMode);
        revertContextBtn.setEnabled(isContextMode);
        // diffrent from xml , we do not save the content in item , find it in wizard temp
        if (EJsonReadbyMode.XPATH.getValue().equals(this.wizard.getReadbyMode()) && (pathStr == null || !new File(pathStr).exists())) {
            // initFileContent();
            tempJSONXsdPath = JSONUtil.tempJSONXsdPath;
            pathStr = tempJSONXsdPath;
        }
        // fix bug: when the JSON file is changed, the linker doesn't work.
        resetStatusIfNecessary();
        String tempJson = this.wizard.getTempJsonPath();
        this.treePopulator.populateTree(tempJson, treeNode);
        ScrollBar verticalBar = availableJSONTree.getVerticalBar();
        if (verticalBar != null) {
            verticalBar.setSelection(0);
        }
        if (this.linker == null) {
            this.linker = prepareJsonLinker();
        } else {
            this.linker.init(treePopulator);
            this.linker.createLinks();
        }
        checkFilePathAndManageIt();
        if (isContextMode()) {
            adaptFormToEditable();
        }
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) File(java.io.File) ScrollBar(org.eclipse.swt.widgets.ScrollBar)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)58 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)19 PersistenceException (org.talend.commons.exception.PersistenceException)16 ArrayList (java.util.ArrayList)15 File (java.io.File)13 ContextItem (org.talend.core.model.properties.ContextItem)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 List (java.util.List)6 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 IProject (org.eclipse.core.resources.IProject)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 BufferedReader (java.io.BufferedReader)3 EOFException (java.io.EOFException)3 FileInputStream (java.io.FileInputStream)3