Search in sources :

Example 6 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class Dictionary method loadSchemaCatalog.

/**
     * Load dictionary data for catalog.
     * 
     * @param iNode catalognode to load
     * @param monitor ProgressMonitor displayed whilst loading
     * @throws InterruptedException If user cancelled loading
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private void loadSchemaCatalog(INode iNode, IProgressMonitor monitor) throws InterruptedException {
    // check for cancellation by user
    if (monitor.isCanceled()) {
        //$NON-NLS-1$
        throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
    }
    putCatalogSchemaName(iNode.toString(), iNode);
    monitor.subTask(iNode.getName());
    INode[] children = iNode.getChildNodes();
    if (children != null) {
        // check for cancellation by user
        if (monitor.isCanceled()) {
            //$NON-NLS-1$
            throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
        }
        // divide work equally between type nodes
        int typeNodeWorkUnit = ROOT_WORK_UNIT / SUPPORTED_CONTENT_ASSIST_TYPES.length;
        int typeNodeWorkCompleted = 0;
        for (int i = 0; i < children.length; i++) {
            INode typeNode = children[i];
            //                if (logger.isDebugEnabled()) {
            //                    logger.debug("Loading dictionary: " + typeNode.getName());
            //                }
            // only load a few types like tables and view nodes into the
            // dictionary
            boolean isIncludedInContentAssist = false;
            for (int j = 0; j < SUPPORTED_CONTENT_ASSIST_TYPES.length; j++) {
                if (typeNode.getType().equalsIgnoreCase(SUPPORTED_CONTENT_ASSIST_TYPES[j])) {
                    isIncludedInContentAssist = true;
                }
            }
            if (!isIncludedInContentAssist) {
                continue;
            }
            monitor.subTask(typeNode.getName());
            // check for cancellation by user
            if (monitor.isCanceled()) {
                //$NON-NLS-1$
                throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
            }
            INode[] tableNodes = typeNode.getChildNodes();
            if (tableNodes != null) {
                // check for cancellation by user
                if (monitor.isCanceled()) {
                    //$NON-NLS-1$
                    throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
                }
                int tableNodeWorkUnit = typeNodeWorkUnit / tableNodes.length;
                for (int j = 0; j < tableNodes.length; j++) {
                    INode tableNode = tableNodes[j];
                    if (monitor != null) {
                        monitor.worked(tableNodeWorkUnit);
                        typeNodeWorkCompleted = typeNodeWorkCompleted + tableNodeWorkUnit;
                        //                            if (logger.isDebugEnabled()) {
                        //                                logger.debug("worked table: " + tableNodeWorkUnit + ", total type work: "
                        //                                        + typeNodeWorkCompleted);
                        //                            }
                        monitor.subTask(tableNode.getQualifiedName());
                        // check for cancellation by user
                        if (monitor.isCanceled()) {
                            //$NON-NLS-1$
                            throw new InterruptedException(Messages.getString("Progress.Dictionary.Cancelled"));
                        }
                    }
                    // add table name
                    ArrayList tableDetails = (ArrayList) getByTableName(tableNode.getName());
                    if (tableDetails == null) {
                        tableDetails = new ArrayList();
                        putTableName(tableNode.getName(), tableDetails);
                    }
                    tableDetails.add(tableNode);
                    // add column names
                    if (tableNode instanceof TableNode) {
                        TreeSet columnNames = new TreeSet();
                        List columns = ((TableNode) tableNode).getColumnNames();
                        if (columns != null) {
                            Iterator it = columns.iterator();
                            while (it.hasNext()) {
                                columnNames.add(it.next());
                            }
                        }
                        putColumnsByTableName(tableNode.getName(), columnNames);
                    }
                }
            }
            if (typeNodeWorkCompleted < typeNodeWorkUnit) {
                // consume remainder of work for this type node
                //                    if (logger.isDebugEnabled()) {
                //                        logger.debug("consuming remainder: " + (typeNodeWorkUnit - typeNodeWorkCompleted));
                //                    }
                monitor.worked(typeNodeWorkUnit - typeNodeWorkCompleted);
            }
            typeNodeWorkCompleted = 0;
        }
    }
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method getProposalsByNode.

/**
     * DOC dev Comment method "getProposalsByNode".
     * 
     * @param documentOffset
     * @param node
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] getProposalsByNode(int documentOffset, INode node) {
    Object[] children = (Object[]) node.getChildNodes();
    ArrayList propList = new ArrayList();
    if (children != null) {
        for (int i = 0; i < children.length; i++) {
            String childName = children[i].toString().toLowerCase();
            if (//$NON-NLS-1$
            childName.equals("table") || childName.equals("view")) {
                //$NON-NLS-1$
                Object[] tables = (Object[]) ((INode) children[i]).getChildNodes();
                if (tables != null) {
                    for (int j = 0; j < tables.length; j++) {
                        Image tmpImage = null;
                        String tableName = tables[j].toString();
                        if (tables[j] instanceof TableNode) {
                            if (((TableNode) tables[j]).isTable()) {
                                tmpImage = tableImage;
                            } else if (((TableNode) tables[j]).isView()) {
                                tmpImage = viewImage;
                            }
                            propList.add(new ExtendedCompletionProposal(tableName, documentOffset, 0, tableName.length(), tmpImage, tableName, (TableNode) tables[j]));
                        }
                    }
                }
            }
        }
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size()];
    System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
    Arrays.sort(res, new ICompletionProposalComparator());
    return res;
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 8 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method inputNotContainDot.

/**
     * DOC dev Comment method "inputNotContainDot".
     * 
     * @param documentOffset
     * @param string
     * @param length
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] inputNotContainDot(int documentOffset, String string, int length) {
    // The string does not contain "."
    String[] keywordProposal = Dictionary.matchKeywordsPrefix(string);
    ICompletionProposal[] resKey = new ICompletionProposal[keywordProposal.length];
    for (int i = 0; i < keywordProposal.length; i++) {
        resKey[i] = new CompletionProposal(keywordProposal[i], documentOffset - length, length, keywordProposal[i].length(), keywordImage, keywordProposal[i], null, null);
    }
    String[] proposalsString = dictionary.matchTablePrefix(string.toLowerCase());
    ArrayList propList = new ArrayList();
    for (int i = 0; i < proposalsString.length; i++) {
        ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
        for (int j = 0; j < ls.size(); j++) {
            TableNode tbNode = (TableNode) ls.get(j);
            Image tmpImage = null;
            if (tbNode.isView()) {
                tmpImage = viewImage;
            } else if (tbNode.isTable()) {
                tmpImage = tableImage;
            }
            ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - length, length, proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
            propList.add(cmp);
        }
    }
    String[] proposalsString2 = dictionary.matchCatalogSchemaPrefix(string.toLowerCase());
    ICompletionProposal[] resKey2 = new ICompletionProposal[proposalsString2.length];
    for (int i = 0; i < proposalsString2.length; i++) {
        resKey2[i] = new CompletionProposal(proposalsString2[i], documentOffset - length, length, proposalsString2[i].length(), catalogImage, proposalsString2[i], null, null);
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size() + keywordProposal.length + resKey2.length];
    System.arraycopy(resKey, 0, res, 0, resKey.length);
    System.arraycopy(propList.toArray(), 0, res, resKey.length, propList.size());
    System.arraycopy(resKey2, 0, res, resKey.length + propList.size(), resKey2.length);
    Arrays.sort(res, new ICompletionProposalComparator());
    return res;
}
Also used : CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 9 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method getProposalsByNode2.

/**
     * DOC dev Comment method "getProposalsByNode2".
     * 
     * @param documentOffset
     * @param lastPart
     * @param node
     * @return
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] getProposalsByNode2(int documentOffset, String lastPart, INode node) {
    String[] proposalsString = dictionary.matchTablePrefix(lastPart.toLowerCase());
    ArrayList propList = new ArrayList();
    for (int i = 0; i < proposalsString.length; i++) {
        ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
        for (int j = 0; j < ls.size(); j++) {
            TableNode tbNode = (TableNode) ls.get(j);
            Image tmpImage = null;
            TableFolderNode totn = (TableFolderNode) tbNode.getParent();
            INode catSchema = (INode) totn.getParent();
            if (catSchema == node) {
                if (tbNode.isView()) {
                    tmpImage = viewImage;
                } else if (tbNode.isTable()) {
                    tmpImage = tableImage;
                }
                ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - lastPart.length(), lastPart.length(), proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
                propList.add(cmp);
            }
        }
    }
    ICompletionProposal[] res = new ICompletionProposal[propList.size()];
    System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
    return res;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) TableFolderNode(org.talend.sqlbuilder.dbstructure.nodes.TableFolderNode)

Example 10 with TableNode

use of org.talend.sqlbuilder.dbstructure.nodes.TableNode in project tdi-studio-se by Talend.

the class SQLCompletionProcessor method computeCompletionProposals.

/**
     * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
     * int)
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    if (dictionary == null) {
        return null;
    }
    String text = viewer.getDocument().get();
    String string = text.substring(0, documentOffset);
    if (string.equals("")) {
        //$NON-NLS-1$
        return null;
    }
    int position = string.length() - 1;
    char character;
    while (position > 0) {
        character = string.charAt(position);
        if (!Character.isJavaIdentifierPart(character) && (character != '.')) {
            break;
        }
        --position;
    }
    if (position == 0) {
        position = -1;
    }
    string = string.substring(position + 1);
    // JFaceDbcPlugin.error("String: "+string,new Exception());
    if (string == null || string.equals("")) {
        //$NON-NLS-1$
        return null;
    }
    string = string.toLowerCase();
    int length = string.length();
    if (length < 1) {
        return null;
    }
    //$NON-NLS-1$
    int dotIndex = string.lastIndexOf(".");
    if (string.charAt(length - 1) == ' ') {
        return null;
    } else if (string.charAt(length - 1) == '.') {
        // Last typed character
        // is '.'
        String name = string.substring(0, length - 1);
        if (name == null) {
            return null;
        }
        //$NON-NLS-1$
        int otherDot = name.lastIndexOf(".");
        if (otherDot != -1) {
            name = name.substring(otherDot + 1);
        }
        if (name == null || name.equals("")) {
            //$NON-NLS-1$
            return null;
        }
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(name);
        if (st != null) {
            ArrayList list = (ArrayList) dictionary.getByTableName(name);
            if (list == null) {
                return null;
            }
            TableNode nd = null;
            if (list.size() == 1) {
                nd = (TableNode) list.get(0);
            } else {
                return null;
            }
            Object[] obj = st.toArray();
            String[] arr = new String[obj.length];
            System.arraycopy(obj, 0, arr, 0, obj.length);
            ICompletionProposal[] result = new ICompletionProposal[arr.length];
            String tableDesc = null;
            if (nd != null) {
                tableDesc = nd.getTableDesc();
            }
            for (int i = 0; i < arr.length; i++) {
                result[i] = new CompletionProposal(arr[i], documentOffset, 0, arr[i].length(), colImage, arr[i], null, tableDesc);
            }
            return result;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(name);
        if (node != null) {
            return getProposalsByNode(documentOffset, node);
        }
    } else if (dotIndex == -1) {
        return inputNotContainDot(documentOffset, string, length);
    } else if (dotIndex != -1) {
        String firstPart = string.substring(0, dotIndex);
        //$NON-NLS-1$
        int otherDot = firstPart.indexOf(".");
        if (otherDot != -1) {
            firstPart = firstPart.substring(otherDot + 1);
        }
        String lastPart = string.substring(dotIndex + 1);
        if (//$NON-NLS-1$
        lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals("")) {
            //$NON-NLS-1$
            return null;
        }
        TreeSet st = (TreeSet) dictionary.getColumnListByTableName(firstPart);
        if (st != null) {
            Iterator iter = st.iterator();
            ArrayList propList = new ArrayList();
            while (iter.hasNext()) {
                String colName = (String) iter.next();
                int length2 = lastPart.length();
                if (colName.length() >= length2) {
                    if ((colName.substring(0, lastPart.length())).equalsIgnoreCase(lastPart)) {
                        CompletionProposal cmp = new CompletionProposal(colName, documentOffset - length2, length2, colName.length(), colImage, colName, null, null);
                        propList.add(cmp);
                    }
                }
            }
            ICompletionProposal[] res = new ICompletionProposal[propList.size()];
            System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
            return res;
        }
        INode node = (INode) dictionary.getByCatalogSchemaName(firstPart);
        if (node != null) {
            return getProposalsByNode2(documentOffset, lastPart, node);
        }
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) Iterator(java.util.Iterator) Point(org.eclipse.swt.graphics.Point)

Aggregations

TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)15 INode (org.talend.sqlbuilder.dbstructure.nodes.INode)11 ArrayList (java.util.ArrayList)7 DataSet (org.talend.sqlbuilder.dataset.dataset.DataSet)7 ResultSet (java.sql.ResultSet)6 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)5 SessionTreeNode (org.talend.sqlbuilder.sessiontree.model.SessionTreeNode)5 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 Point (org.eclipse.swt.graphics.Point)4 TreeSet (java.util.TreeSet)3 Image (org.eclipse.swt.graphics.Image)3 Iterator (java.util.Iterator)2 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)2 DatabaseNode (org.talend.sqlbuilder.dbstructure.nodes.DatabaseNode)2 Statement (java.sql.Statement)1 List (java.util.List)1 IToken (org.eclipse.jface.text.rules.IToken)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 ColumnInfoTab (org.talend.sqlbuilder.dbdetail.tab.ColumnInfoTab)1 ConnectionInfoTab (org.talend.sqlbuilder.dbdetail.tab.ConnectionInfoTab)1