Search in sources :

Example 1 with ICompletionProposal

use of com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal in project cubrid-manager by CUBRID.

the class SQLContentAssistProcessor method computeCompletionProposals.

public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    IDocument document = viewer.getDocument();
    int currOffset = offset - 1;
    try {
        String currWord = "";
        char currChar;
        while (currOffset >= 0 && !isKeywordSeparator(currChar = document.getChar(currOffset))) {
            currWord = currChar + currWord;
            currOffset--;
        }
        currWord = trimQualifier(currWord);
        if (currWord.trim().length() == 0 && isSQLEndPos(document, currOffset)) {
            return null;
        }
        // if currWord is "" or AssistProcessor is displaying return null;
        if (currWord.trim().equals("") && isRunning()) {
            return null;
        }
        setRunning(true);
        List<ICompletionProposal> finalProposals = new ArrayList<ICompletionProposal>();
        if (GeneralPreference.isAutoCompleteTablesOrColumns()) {
            // columns
            List<ColumnProposalDetailInfo> tableColumns = getColumnNames(currWord.toUpperCase(Locale.getDefault()), document, offset - 1);
            List<ICompletionProposal> columnProposals = buildColumnProposals(tableColumns, currWord, offset - currWord.length(), CommonUIPlugin.getImage("icons/navigator/table_column_item.png"), false);
            finalProposals.addAll(columnProposals);
            // tables
            List<String> tableNames = getTableNames(currWord.toUpperCase(Locale.getDefault()), document, offset - 1);
            List<ICompletionProposal> tableProposals = buildProposals(tableNames, currWord, offset - currWord.length(), CommonUIPlugin.getImage("icons/navigator/schema_table_item.png"), false);
            finalProposals.addAll(tableProposals);
        }
        // keywords
        if (GeneralPreference.isAutoCompleteKeyword()) {
            List<String> suggestions = wordTracker.suggest(currWord.toUpperCase(Locale.getDefault()), databaseProvider.getDatabaseInfo());
            List<ICompletionProposal> keywordProposals = buildProposals(suggestions, currWord, offset - currWord.length(), CommonUIPlugin.getImage("icons/navigator/sql.png"), true);
            finalProposals.addAll(keywordProposals);
        }
        return finalProposals.toArray(new ICompletionProposal[finalProposals.size()]);
    } catch (BadLocationException e) {
        LOGGER.error("", e);
        lastError = e.getMessage();
        return null;
    } finally {
        setRunning(false);
    }
}
Also used : ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with ICompletionProposal

use of com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal in project cubrid-manager by CUBRID.

the class RecentSQLContentAssistProcessor method computeCompletionProposals.

public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    IDocument document = viewer.getDocument();
    int currOffset = offset - 1;
    try {
        String currWord = "";
        char currChar;
        while (currOffset >= 0 && !isStatementSeparator(currChar = document.getChar(currOffset))) {
            currWord = Character.toUpperCase(currChar) + currWord;
            currOffset--;
        }
        //if currWord is "" display all;
        boolean allFlag = false;
        if (StringUtil.isEmpty(currWord)) {
            allFlag = true;
        }
        List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
        ICompletionProposal proposal = null;
        for (String sql : RecentlyUsedSQLContentPersistUtils.getRecentlyUsedSQLContentsById(databaseProvider.getDatabase())) {
            if (allFlag) {
                proposal = buildOneProposal(sql, currWord, offset - currWord.length(), null);
                proposals.add(proposal);
            } else if (StringUtil.startsWithIgnoreCase(currWord, sql)) {
                proposal = buildOneProposal(sql, currWord, offset - currWord.length(), null);
                proposals.add(proposal);
            }
        }
        return proposals.toArray(new ICompletionProposal[proposals.size()]);
    } catch (Exception e) {
        LOGGER.error("", e);
        return null;
    } finally {
        setRunning(false);
    }
}
Also used : ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with ICompletionProposal

use of com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal in project cubrid-manager by CUBRID.

the class SQLContentAssistProcessor method buildProposals.

/**
	 * Build the proposals with image
	 *
	 * @param names List
	 * @param replacedWord String
	 * @param offset int
	 * @param Image image
	 * @return proposals
	 */
private List<ICompletionProposal> buildProposals(List<String> names, String replacedWord, int offset, Image image, boolean showSecondProposals) {
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    for (String name : names) {
        String currSuggestion = name;
        String displayString = name;
        if (checkShowSecondProposals(showSecondProposals, name)) {
            // content += SECONDPROPOSALSUFFIX;
            proposals.add(new CompletionProposal(currSuggestion, offset, replacedWord.length(), currSuggestion.length(), CommonUIPlugin.getImage("icons/queryeditor/arrow_right.png"), displayString, null, null));
        } else {
            if (QuerySyntax.getKeywordContent(name) == null) {
                proposals.add(new CompletionProposal(currSuggestion, offset, replacedWord.length(), currSuggestion.length(), image, displayString, null, null));
            } else {
                // show help
                proposals.add(new CompletionProposal(currSuggestion, offset, replacedWord.length(), currSuggestion.length(), image, null, null, "<pre>" + QuerySyntax.getKeywordContent(name) + "</pre>"));
            }
        }
    }
    return proposals;
}
Also used : CompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.CompletionProposal) ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList)

Example 4 with ICompletionProposal

use of com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal in project cubrid-manager by CUBRID.

the class SQLContentAssistProcessor method buildColumnProposals.

/**
	 * build the column proposals with image
	 *
	 * @param tableColumns List<TableColumn>
	 * @param replacedWord String
	 * @param offset int
	 * @param Image image
	 * @return proposals
	 */
private List<ICompletionProposal> buildColumnProposals(List<ColumnProposalDetailInfo> tableColumns, String replacedWord, int offset, Image image, boolean showSecondProposals) {
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
    for (ColumnProposalDetailInfo column : tableColumns) {
        String columnName = column.getColumnName();
        String currSuggestion = columnName;
        String displayString = columnName;
        if (replacedWord.indexOf(".") > 0) {
            String[] words = replacedWord.split("\\.");
            currSuggestion = words[0] + "." + column.getColumnName();
        }
        if (checkShowSecondProposals(showSecondProposals, column.getColumnName())) {
            proposals.add(new CompletionProposal(currSuggestion, offset, replacedWord.length(), currSuggestion.length(), CommonUIPlugin.getImage("icons/queryeditor/arrow_right.png"), displayString, null, column.getColumnAdditionalInfo()));
        } else {
            proposals.add(new CompletionProposal(currSuggestion, offset, replacedWord.length(), currSuggestion.length(), image, displayString, null, "<pre>" + column.getColumnAdditionalInfo() + "</pre>"));
        }
    }
    return proposals;
}
Also used : CompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.CompletionProposal) ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList)

Example 5 with ICompletionProposal

use of com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal in project cubrid-manager by CUBRID.

the class SQLContentAssistProcessor method computeSecondProposals.

/**
	 * compute Second Proposals
	 *
	 * @param viewer
	 * @param offset
	 * @param firstProposalsSelectedProposal
	 * @return ICompletionProposal[]
	 */
public ICompletionProposal[] computeSecondProposals(ITextViewer viewer, int offset, ICompletionProposal firstProposalsSelectedProposal) {
    IDocument document = viewer.getDocument();
    int currOffset = offset - 1;
    try {
        String currWord = "";
        char currChar;
        while (currOffset >= 0 && !isKeywordSeparator(currChar = document.getChar(currOffset))) {
            currWord = Character.toUpperCase(currChar) + currWord;
            currOffset--;
        }
        List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
        String firstProposalsDisplayString = firstProposalsSelectedProposal.getDisplayString();
        for (String sql : RecentlyUsedSQLContentPersistUtils.getRecentlyUsedSQLContentsById(databaseProvider.getDatabase())) {
            if (StringUtil.startsWithIgnoreCase(firstProposalsDisplayString, sql)) {
                String content = "";
                if (sql.length() > 60) {
                    content = sql.substring(0, 57);
                    content += "...";
                } else {
                    content = sql;
                }
                proposals.add(new CompletionProposal(sql, offset - currWord.length(), currWord.length(), sql.length(), CommonUIPlugin.getImage("icons/queryeditor/arrow_left.png"), content, null, sql));
            }
        }
        return proposals.toArray(new ICompletionProposal[proposals.size()]);
    } catch (Exception e) {
        LOGGER.error("", e);
        return null;
    }
}
Also used : CompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.CompletionProposal) ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ICompletionProposal(com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) IDocument(org.eclipse.jface.text.IDocument) SQLException(java.sql.SQLException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ICompletionProposal (com.cubrid.common.ui.query.control.jface.text.contentassist.ICompletionProposal)5 ArrayList (java.util.ArrayList)5 CompletionProposal (com.cubrid.common.ui.query.control.jface.text.contentassist.CompletionProposal)3 IDocument (org.eclipse.jface.text.IDocument)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 SQLException (java.sql.SQLException)1