Search in sources :

Example 1 with JsonTreePopulator

use of org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator in project tdi-studio-se by Talend.

the class JSONXPathProposalProvider method getProposals4JsonPath.

private IContentProposal[] getProposals4JsonPath(String contents, int position) {
    AbstractTreePopulator treePopulator = linker.getTreePopulator();
    if (!(treePopulator instanceof JsonTreePopulator)) {
        return null;
    }
    XmlNodeRetriever nodeRetriever = linker.getNodeRetriever();
    if (!(nodeRetriever instanceof JsonNodeRetriever)) {
        return null;
    }
    JsonNodeRetriever jsonNodeRetriever = (JsonNodeRetriever) nodeRetriever;
    String beforeCursorExp = null;
    boolean isAbsoluteExpression = contents.trim().startsWith(linker.getRootSeperator());
    beforeCursorExp = contents.substring(0, position);
    int lastIndexFieldSeperator = beforeCursorExp.lastIndexOf(linker.getFieldSeperator());
    String currentExpr = null;
    if (0 <= lastIndexFieldSeperator) {
        currentExpr = beforeCursorExp.substring(0, lastIndexFieldSeperator);
    } else {
        currentExpr = beforeCursorExp;
    }
    currentExpr = currentExpr.trim();
    String currentWord = extractLastWord(beforeCursorExp);
    if (!isAbsoluteExpression && lastIndexFieldSeperator < 0) {
        currentWord = currentExpr;
        currentExpr = "";
    }
    if (currentWord != null) {
        currentWord = currentWord.trim();
    }
    List<JsonTreeNode> proposalNodes = jsonNodeRetriever.retrieveProposalJsonTreeNode((JsonTreePopulator) treePopulator, currentExpr, currentWord, isRelativeTable, isAbsoluteExpression);
    List<IContentProposal> proposals = new ArrayList<IContentProposal>();
    if (proposalNodes != null && !proposalNodes.isEmpty()) {
        Iterator<JsonTreeNode> iter = proposalNodes.iterator();
        while (iter.hasNext()) {
            JsonTreeNode jsonTreeNode = iter.next();
            JsonPathContentProposal proposal = new JsonPathContentProposal(jsonTreeNode.getLabel());
            proposals.add(proposal);
        }
    }
    return proposals.toArray(new IContentProposal[proposals.size()]);
}
Also used : JsonTreeNode(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreeNode) XmlNodeRetriever(org.talend.commons.runtime.xml.XmlNodeRetriever) ArrayList(java.util.ArrayList) IContentProposal(org.eclipse.jface.fieldassist.IContentProposal) AbstractTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.AbstractTreePopulator) JsonTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator)

Example 2 with JsonTreePopulator

use of org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator 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 3 with JsonTreePopulator

use of org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator in project tdi-studio-se by Talend.

the class JSONFileStep2Form method initTreePopulator.

private void initTreePopulator() {
    if (EJsonReadbyMode.JSONPATH.getValue().equals(this.wizard.getReadbyMode())) {
        this.treePopulator = new JsonTreePopulator(availableJSONTreeViewer);
    } else {
        this.treePopulator = new TreePopulator(availableJSONTreeViewer);
    }
    this.treePopulator.setFilePath(this.wizard.getTempJsonPath());
    this.treePopulator.configureDefaultTreeViewer();
}
Also used : 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) JsonTreePopulator(org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator)

Aggregations

AbstractTreePopulator (org.talend.repository.ui.wizards.metadata.connection.files.json.AbstractTreePopulator)3 JsonTreePopulator (org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreePopulator)3 TreePopulator (org.talend.repository.ui.wizards.metadata.connection.files.xml.TreePopulator)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 IContentProposal (org.eclipse.jface.fieldassist.IContentProposal)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 XmlNodeRetriever (org.talend.commons.runtime.xml.XmlNodeRetriever)1 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)1 EJsonReadbyMode (org.talend.repository.ui.wizards.metadata.connection.files.json.EJsonReadbyMode)1 JsonTreeNode (org.talend.repository.ui.wizards.metadata.connection.files.json.JsonTreeNode)1