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()]);
}
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();
}
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();
}
Aggregations