Search in sources :

Example 1 with INode

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

the class DBTreeActionGroup method fillContextMenu.

/**
     * Fill the node context menu with all the correct actions.
     * 
     * @param menu MenuManager.
     * @see org.eclipse.ui.actions.ActionGroup#fillContextMenu(org.eclipse.jface.action.IMenuManager)
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public void fillContextMenu(IMenuManager menu) {
    // find our target node..
    IStructuredSelection selection = (IStructuredSelection) pTreeViewer.getSelection();
    // check if we have a valid selection
    if (selection == null) {
        return;
    }
    ArrayList selectedNodes = new ArrayList();
    Iterator it = selection.iterator();
    while (it.hasNext()) {
        Object object = it.next();
        if (object instanceof INode) {
            selectedNodes.add(object);
        }
    }
    if (selectedNodes.size() == 0) {
        return;
    }
    INode[] nodes = (INode[]) selectedNodes.toArray(new INode[] {});
    IAction[] actions = getContextActions(nodes);
    for (int i = 0; i < actions.length; i++) {
        menu.add(actions[i]);
    }
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) IAction(org.eclipse.jface.action.IAction) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 2 with INode

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

the class DBTreeLabelProvider method getText.

/**
     * Return the text to display the INode.
     * 
     * @param element Node.
     * @return Text.
     * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
     */
public String getText(Object element) {
    INode node = (INode) element;
    String text = node.getLabelText();
    // return default if no label is provided
    if (text == null) {
        text = node.toString();
    }
    return text;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode)

Example 3 with INode

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

the class SessionTreeNodeManager method convert2INode.

/**
     * DOC qianbing Comment method "convert2INode". Converts the RepositoryNode input to INode. INode is used for the
     * sql editor,result viewer and the detail viewer.
     * 
     * @param repositoryNode RepositoryNode
     * @param selectedContext
     * @return INode
     */
public INode convert2INode(RepositoryNode repositoryNode, String selectedContext, SessionTreeNode sessionTreeNode) throws Exception {
    // Creates the SessionTreeNode.
    RepositoryNodeType nodeType = getRepositoryType(repositoryNode);
    if (nodeType.equals(RepositoryNodeType.DATABASE)) {
        // processes the database
        DatabaseModel model = sessionTreeNode.getDbModel();
        INode[] nodes = model.getChildNodes();
        DatabaseNode dn = (DatabaseNode) nodes[0];
        return dn;
    } else if (nodeType.equals(RepositoryNodeType.TABLE)) {
        // processes the table
        MetadataTableRepositoryObject tableObject = (MetadataTableRepositoryObject) repositoryNode.getObject();
        MetadataTable table = tableObject.getTable();
        String realName = table.getSourceName();
        DatabaseModel model = sessionTreeNode.getDbModel();
        INode[] nodes = model.getChildNodes();
        DatabaseNode dn = (DatabaseNode) nodes[0];
        nodes = dn.getChildNodes();
        CatalogNode cn = (CatalogNode) nodes[0];
        nodes = cn.getChildNodes();
        if (nodes != null && nodes.length > 0) {
            for (INode node : nodes) {
                TableNode tableNode = (TableNode) node;
                if (tableNode.getName().equals(realName)) {
                    return node;
                }
            }
        }
    } else if (nodeType.equals(RepositoryNodeType.COLUMN)) {
        // Processes the column.
        // Gets the repositoryNode's parent,should be the repositoryNode of table infomation.
        repositoryNode = repositoryNode.getParent();
        return convert2INode(repositoryNode, selectedContext, sessionTreeNode);
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) DatabaseNode(org.talend.sqlbuilder.dbstructure.nodes.DatabaseNode) CatalogNode(org.talend.sqlbuilder.dbstructure.nodes.CatalogNode) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)

Example 4 with INode

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

the class ImportedKeysTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table.
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getImportedKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getImportedKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 3, 4, 8, 9, 10, 11, 12, 13, 14 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Example 5 with INode

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

the class PrimaryKeysTab method getDataSet.

public DataSet getDataSet() throws Exception {
    INode node = getNode();
    if (node == null) {
        return null;
    }
    if (node.getSession() == null) {
        return null;
    }
    if (node instanceof TableNode) {
        TableNode tableNode = (TableNode) node;
        ITableInfo ti = tableNode.getTableInfo();
        if (tableNode.getTableInfo() == null) {
            return null;
        }
        ResultSet resultSet = null;
        SessionTreeNode treeNode = node.getSession();
        // For synonym table, should get the corresponding table name .
        if (ti.getType().equals("SYNONYM")) {
            //$NON-NLS-1$
            String realTableName = ExtractMetaDataFromDataBase.getTableNameBySynonym(treeNode.getInteractiveConnection().getConnection(), ti.getSimpleName());
            resultSet = treeNode.getMetaData().getJDBCMetaData().getPrimaryKeys(ti.getCatalogName(), ti.getSchemaName(), realTableName);
        } else {
            resultSet = node.getSession().getMetaData().getPrimaryKeys((tableNode.getTableInfo()));
        }
        DataSet dataSet = new DataSet(null, resultSet, new int[] { 4, 5, 6 });
        resultSet.close();
        return dataSet;
    }
    return null;
}
Also used : INode(org.talend.sqlbuilder.dbstructure.nodes.INode) ITableInfo(net.sourceforge.squirrel_sql.fw.sql.ITableInfo) DataSet(org.talend.sqlbuilder.dataset.dataset.DataSet) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) TableNode(org.talend.sqlbuilder.dbstructure.nodes.TableNode) ResultSet(java.sql.ResultSet)

Aggregations

INode (org.talend.sqlbuilder.dbstructure.nodes.INode)16 TableNode (org.talend.sqlbuilder.dbstructure.nodes.TableNode)11 DataSet (org.talend.sqlbuilder.dataset.dataset.DataSet)8 ResultSet (java.sql.ResultSet)6 ArrayList (java.util.ArrayList)5 ITableInfo (net.sourceforge.squirrel_sql.fw.sql.ITableInfo)5 SessionTreeNode (org.talend.sqlbuilder.sessiontree.model.SessionTreeNode)5 Iterator (java.util.Iterator)4 List (java.util.List)2 TreeSet (java.util.TreeSet)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 Point (org.eclipse.swt.graphics.Point)2 CatalogNode (org.talend.sqlbuilder.dbstructure.nodes.CatalogNode)2 DatabaseNode (org.talend.sqlbuilder.dbstructure.nodes.DatabaseNode)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 Statement (java.sql.Statement)1 SQLDatabaseMetaData (net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 ListenerList (org.eclipse.core.runtime.ListenerList)1 IAction (org.eclipse.jface.action.IAction)1