Search in sources :

Example 1 with QueryRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject in project tdi-studio-se by Talend.

the class DeleteQueryAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    RepositoryNode node = (RepositoryNode) getStructuredSelection().getFirstElement();
    QueryRepositoryObject object = (QueryRepositoryObject) node.getObject();
    Query query = object.getQuery();
    // Finds the root
    node = SQLBuilderRepositoryNodeManager.getRoot(node);
    List<Query> queries = new ArrayList<Query>();
    queries.add(query);
    repositoryNodeManager.deleteQueries(node, queries);
    dialog.refreshNode(node);
    dialog.notifySQLBuilder(node.getObject());
}
Also used : QueryRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject) Query(org.talend.core.model.metadata.builder.connection.Query) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 2 with QueryRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject in project tdi-studio-se by Talend.

the class ShowQueryPropertyAction method run.

@Override
public void run() {
    RepositoryNode node = (RepositoryNode) getStructuredSelection().getFirstElement();
    QueryRepositoryObject object = (QueryRepositoryObject) node.getObject();
    Query query = object.getQuery();
    String oldQuery = query.getLabel();
    // Finds the root
    node = SQLBuilderRepositoryNodeManager.getRoot(node);
    List<String> existingName = repositoryNodeManager.getALLQueryLabels(node);
    SQLPropertyDialog saveSQLDialog = new SQLPropertyDialog(dialog.getShell(), true);
    saveSQLDialog.setQuery(query);
    if (Window.OK == saveSQLDialog.open()) {
        query = saveSQLDialog.getQuery();
        repositoryNodeManager.saveQuery(node, query, oldQuery);
        dialog.refreshNode(node);
        dialog.notifySQLBuilder(node.getObject());
    }
}
Also used : QueryRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject) Query(org.talend.core.model.metadata.builder.connection.Query) RepositoryNode(org.talend.repository.model.RepositoryNode) SQLPropertyDialog(org.talend.sqlbuilder.ui.SQLPropertyDialog)

Example 3 with QueryRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject in project tdi-studio-se by Talend.

the class SQLBuilderTabComposite method createTabItem.

/**
     * Creates tab item. Changed by Marvin Wang on Feb. 24, 2012 for bug TDI-7643, for all SQLBuilderEditorComposite
     * when using <code>editorComposite.getConnParam().getQueryObject()</code> to get the query object, the query every
     * time get is the same object. Caz all <code>SQLBuilderEditorComposite</code>s use the same connection parameter.
     * 
     * @param node
     * @param connParam
     * @param isDefaultEditor
     */
private void createTabItem(RepositoryNode node, ConnectionParameters connParam, boolean isDefaultEditor) {
    //$NON-NLS-1$
    String queryStr = "";
    if (node != null) {
        CTabItem[] tabItems = tabFolder.getItems();
        for (int i = 0; i < tabItems.length; i++) {
            SQLBuilderEditorComposite editorComposite = (SQLBuilderEditorComposite) (((CTabFolder) tabItems[i].getControl()).getItems()[0]).getControl();
            // To get the different query object for each SQLBuilderEditorComposite, use the following method. The
            // queryObject is stored in <code>SQLBuilderEditorComposite.doSaveSQL()</code>
            Query query2 = editorComposite.getQueryObject();
            if ((RepositoryNodeType) node.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.QUERY) {
                Query query = ((QueryRepositoryObject) node.getObject()).getQuery();
                if (query2 == null && tabItems[i].getData() instanceof Query) {
                    query2 = (Query) tabItems[i].getData();
                }
                if (query2 != null && query.getLabel().equals(query2.getLabel())) {
                    if ("".equals(editorComposite.getEditorContent())) {
                        //$NON-NLS-1$
                        editorComposite.setEditorContent(query.getValue());
                    }
                    tabFolder.setSelection(i);
                    return;
                }
                connParam.setQueryObject(query);
                queryStr = query.getValue();
            }
        }
    }
    CTabItem tabItem = null;
    if (connParam.isFromDBNode()) {
        tabItem = new CTabItem(tabFolder, SWT.NULL);
    } else {
        tabItem = new CTabItem(tabFolder, SWT.CLOSE);
    }
    node = SQLBuilderRepositoryNodeManager.getRoot(node);
    if (!"".equals(queryStr)) {
        //$NON-NLS-1$
        try {
            nodesSel = EMFRepositoryNodeManager.getInstance().parseSqlStatement(queryStr, node);
        } catch (Exception e) {
            MessageDialog.openError(new Shell(), Messages.getString("SQLBuilderTabComposite.Notice.title"), //$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "SQLBuilderTabComposite.Notice.Info"));
        }
    }
    MultiPageSqlBuilderEditor builderEditor = new MultiPageSqlBuilderEditor(nodesSel, tabItem, isDefaultEditor, connParam, node, dialog);
    builderEditor.setReadOnly(readOnly);
    try {
        builderEditor.init(new SQLBuilderEditorSite(), new SQLBuilderEditorInput());
    } catch (PartInitException e) {
        ExceptionHandler.process(e);
    }
    builderEditor.createPartControl2(tabFolder);
    tabItem.setControl(builderEditor.getContainer());
    tabItem.setData(TextUtil.KEY, builderEditor);
    if (connParam.isFromRepository() && connParam.getQueryObject() != null) {
        queryStr = connParam.getQueryObject().getValue();
    }
    builderEditor.setSqlText(queryStr);
    if (connParam.isShowDesignerPage()) {
        builderEditor.showDesignerPage();
    }
    // set new tab as the active one.
    tabFolder.setSelection(tabFolder.getItemCount() - 1);
    // refresh view
    tabFolder.layout();
    tabFolder.redraw();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) Query(org.talend.core.model.metadata.builder.connection.Query) SQLBuilderEditorInput(org.talend.sqlbuilder.editors.SQLBuilderEditorInput) CTabItem(org.eclipse.swt.custom.CTabItem) PartInitException(org.eclipse.ui.PartInitException) QueryRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject) Shell(org.eclipse.swt.widgets.Shell) MultiPageSqlBuilderEditor(org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor) PartInitException(org.eclipse.ui.PartInitException) SQLBuilderEditorSite(org.talend.sqlbuilder.editors.SQLBuilderEditorSite)

Example 4 with QueryRepositoryObject

use of org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject in project tdi-studio-se by Talend.

the class OpenQueryAction method run.

@Override
public void run() {
    RepositoryNode node = (RepositoryNode) getStructuredSelection().getFirstElement();
    if (node == null) {
        return;
    }
    if (node.getProperties(EProperties.CONTENT_TYPE) == RepositoryNodeType.QUERY) {
        List<String> repositoryName = repositoryNodeManager.getALLReposotoryNodeNames();
        ConnectionParameters connectionParameters = new ConnectionParameters();
        IRepositoryViewObject repViewObject = node.getObject();
        if (repViewObject instanceof QueryRepositoryObject) {
            QueryRepositoryObject queryRepObj = (QueryRepositoryObject) repViewObject;
            Query query = queryRepObj.getQuery();
            connectionParameters.setQueryObject(query);
            dialog.setConnParameters(connectionParameters);
        }
        connectionParameters.setQuery(dialog.getConnParameters().getQuery());
        connectionParameters.setShowDesignerPage(false);
        dialog.openEditor(node, repositoryName, connectionParameters, false);
    }
}
Also used : QueryRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject) Query(org.talend.core.model.metadata.builder.connection.Query) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryNode(org.talend.repository.model.RepositoryNode)

Aggregations

Query (org.talend.core.model.metadata.builder.connection.Query)4 QueryRepositoryObject (org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject)4 RepositoryNode (org.talend.repository.model.RepositoryNode)3 ArrayList (java.util.ArrayList)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Shell (org.eclipse.swt.widgets.Shell)1 PartInitException (org.eclipse.ui.PartInitException)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 ConnectionParameters (org.talend.core.sqlbuilder.util.ConnectionParameters)1 MultiPageSqlBuilderEditor (org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor)1 SQLBuilderEditorInput (org.talend.sqlbuilder.editors.SQLBuilderEditorInput)1 SQLBuilderEditorSite (org.talend.sqlbuilder.editors.SQLBuilderEditorSite)1 SQLPropertyDialog (org.talend.sqlbuilder.ui.SQLPropertyDialog)1