Search in sources :

Example 1 with SQLBuilderDialog

use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.

the class GUIModificationQueryAction method run.

/*
     * (non-Java)
     * 
     * @see org.talend.sqlbuilder.actions.AbstractEditorAction#run()
     */
@Override
public void run() {
    currentSql = getEditor().getSQLToBeExecuted();
    // }
    if (dialog instanceof SQLBuilderDialog) {
        SQLBuilderDialog d = (SQLBuilderDialog) dialog;
        final CTabItem selection = d.getEditorComposite().getTabFolder().getSelection();
        if (selection.getData("KEY") instanceof MultiPageSqlBuilderEditor) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            MultiPageSqlBuilderEditor editor = (MultiPageSqlBuilderEditor) selection.getData("KEY");
            switch(editor.getActivePage()) {
                case 1:
                    isDesigner = true;
                    break;
                default:
                    isDesigner = false;
                    break;
            }
        }
    }
    String query = null;
    if (isDesigner) {
        SqlEditDialog textDialog = new SqlEditDialog(dialog.getShell(), Messages.getString("GUIModificationQueryAction.TextDialog.TitleText"), currentSql, //$NON-NLS-1$
        currentNode);
        if (Window.OK == textDialog.open()) {
            query = textDialog.getSql();
        }
    } else {
        List<IRepositoryNode> selectedNodes = null;
        try {
            selectedNodes = EMFRepositoryNodeManager.getInstance().parseSqlStatement(currentSql, currentNode);
        } catch (Exception e) {
            MessageDialog.openError(new Shell(), Messages.getString("GUIModificationQueryAction.Error.Notice"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("GUIModificationQueryAction.SqlStatement.ErrorMsg"));
        }
        if (selectedNodes == null) {
            return;
        }
        // String info = Messages.getString("MultiPageSqlBuilderEditor.Notice.InformationNotFull");
        // MessageDialog.openInformation(new Shell(),
        // Messages.getString("GUIModificationQueryAction.Information.Msg"), info); //$NON-NLS-1$
        ErDiagramDialog erDiagramDialog = new ErDiagramDialog(dialog.getShell(), Messages.getString("GUIModificationQueryAction.Dialog.TitleText"), //$NON-NLS-1$
        currentNode);
        erDiagramDialog.setDialog(dialog);
        erDiagramDialog.setNodes(selectedNodes);
        erDiagramDialog.setSqlText(currentSql);
        EMFRepositoryNodeManager.getInstance().setRoot(currentNode);
        if (Window.OK == erDiagramDialog.open()) {
            query = erDiagramDialog.getSql();
        }
    }
    if (query == null) {
        return;
    }
    if (!query.endsWith(";\n") && !query.endsWith(";")) {
        //$NON-NLS-1$ //$NON-NLS-2$
        //$NON-NLS-1$
        query += ";\n";
    }
    //$NON-NLS-1$
    String targetSql = "";
    boolean isfirst = true;
    QueryTokenizer qt = new QueryTokenizer(currentSql, queryDelimiter, alternateDelimiter, commentDelimiter);
    while (qt.hasQuery()) {
        String querySql = qt.nextQuery();
        if (querySql.startsWith("--") || !isfirst) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            targetSql += querySql + ";\n";
        } else {
            targetSql += query;
            isfirst = false;
        }
    }
    if (!qt.hasQuery()) {
        targetSql = query;
    }
    // currentSql = currentSql.replaceFirst(queryStrings.get(0), query);
    getEditor().setEditorContent(targetSql);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) QueryTokenizer(org.talend.sqlbuilder.util.QueryTokenizer) SqlEditDialog(org.talend.sqlbuilder.ui.SqlEditDialog) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ErDiagramDialog(org.talend.sqlbuilder.erdiagram.ui.ErDiagramDialog) MultiPageSqlBuilderEditor(org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor) ISQLBuilderDialog(org.talend.sqlbuilder.ui.ISQLBuilderDialog) SQLBuilderDialog(org.talend.sqlbuilder.ui.SQLBuilderDialog) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 2 with SQLBuilderDialog

use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.

the class UIUtils method updateSqlBuilderDialogTitle.

public static void updateSqlBuilderDialogTitle(String newLabel, String jobName, String uniqueName) {
    List<SQLBuilderDialog> list = sqlBuilders.get(jobName);
    if (list != null) {
        for (SQLBuilderDialog dialog : list) {
            if (dialog != null && dialog.getShell() != null && !dialog.getShell().isDisposed()) {
                if (dialog.getShell().getText().contains(uniqueName)) {
                    String title = TextUtil.SQL_BUILDER_TITLE_COMP_MODPREFIX + jobName;
                    //$NON-NLS-1$ //$NON-NLS-2$
                    title += TextUtil.SQL_BUILDER_TITLE_COMP_NAME + newLabel + "(" + uniqueName + ")";
                    dialog.getShell().setText(title);
                }
            }
        }
    }
}
Also used : SQLBuilderDialog(org.talend.sqlbuilder.ui.SQLBuilderDialog)

Example 3 with SQLBuilderDialog

use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.

the class ReadQueriesAction method doRun.

@Override
protected void doRun() {
    IStructuredSelection selection = (IStructuredSelection) getSelection();
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (repositoryNode == null && selection != null) {
        repositoryNode = (RepositoryNode) selection.getFirstElement();
    }
    DatabaseConnectionItem dbConnectionItem = null;
    ConnectionParameters connParameters = new ConnectionParameters();
    if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
        dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
        connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
        connParameters.setRepositoryId(repositoryNode.getObject().getId());
        //$NON-NLS-1$
        connParameters.setQuery("");
    } else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
        QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
        dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
        connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
        connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
        connParameters.setQueryObject(queryRepositoryObject.getQuery());
        connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
        // first open Sql Builder,set true
        connParameters.setFirstOpenSqlBuilder(true);
    }
    Display display = Display.getCurrent();
    if (display == null) {
        display = Display.getDefault();
    }
    Shell parentShell = new Shell(display);
    TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
    Connection connection = dbConnectionItem.getConnection();
    String selectedContext = null;
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null && connection.isContextMode()) {
            ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
            setsDialog.open();
            selectedContext = setsDialog.getSelectedContext();
        }
    }
    SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
    dial.setReadOnly(true);
    if (connection instanceof DatabaseConnection) {
        IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
        connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
        UIUtils.checkConnection(parentShell, imetadataConnection);
    }
    connParameters.setNodeReadOnly(true);
    connParameters.setFromRepository(true);
    dial.setConnParameters(connParameters);
    dial.open();
    refresh(repositoryNode);
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) Shell(org.eclipse.swt.widgets.Shell) ContextSetsSelectionDialog(org.talend.metadata.managment.ui.wizard.metadata.ContextSetsSelectionDialog) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) SQLBuilderDialog(org.talend.sqlbuilder.ui.SQLBuilderDialog) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Display(org.eclipse.swt.widgets.Display)

Example 4 with SQLBuilderDialog

use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.

the class EditQueriesAction method doRun.

@Override
protected void doRun() {
    IStructuredSelection selection = (IStructuredSelection) getSelection();
    if (repositoryNode == null && selection != null) {
        repositoryNode = (RepositoryNode) selection.getFirstElement();
    }
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IRepositoryViewObject nodeObject = repositoryNode.getObject();
    boolean locked = false;
    if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
        if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
            locked = true;
        }
    }
    // Avoid to delete node which is locked.
    if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
        final String title = "Impossible to edit queries";
        String nodeName = nodeObject.getRepositoryObjectType().getLabel();
        final String message = "item is already locked by another user.";
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialog dialog = new MessageDialog(new Shell(), title, null, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
                dialog.open();
            }
        });
        return;
    }
    DatabaseConnectionItem dbConnectionItem = null;
    boolean readOnly = false;
    ConnectionParameters connParameters = new ConnectionParameters();
    if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
        dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
        connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
        connParameters.setRepositoryId(repositoryNode.getObject().getId());
        //$NON-NLS-1$
        connParameters.setQuery("");
    } else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
        QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
        readOnly = SubItemHelper.isDeleted(queryRepositoryObject.getAbstractMetadataObject());
        dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
        connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
        connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
        connParameters.setQueryObject(queryRepositoryObject.getQuery());
        connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
        // first open Sql Builder,set true
        connParameters.setFirstOpenSqlBuilder(true);
    } else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
        dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
        connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
        connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
        connParameters.setMetadataTable((MetadataTableRepositoryObject) repositoryNode.getObject());
        //$NON-NLS-1$
        connParameters.setQuery("");
    }
    IRepositoryView viewPart = getViewPart();
    Display display = null;
    if (viewPart != null) {
        display = viewPart.getViewer().getControl().getDisplay();
    } else {
        display = Display.getCurrent();
        if (display == null) {
            display = Display.getDefault();
        }
    }
    Shell parentShell = new Shell(display);
    TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
    Connection connection = dbConnectionItem.getConnection();
    String selectedContext = null;
    if (connection.isContextMode()) {
        ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
        if (contextItem != null && connection.isContextMode()) {
            ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
            setsDialog.open();
            selectedContext = setsDialog.getSelectedContext();
        }
    }
    SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
    dial.setReadOnly(readOnly);
    if (connection instanceof DatabaseConnection) {
        IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
        connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
        UIUtils.checkConnection(parentShell, imetadataConnection);
    }
    connParameters.setNodeReadOnly(readOnly);
    connParameters.setFromRepository(true);
    dial.setConnParameters(connParameters);
    dial.open();
    IRepositoryView view = getViewPart();
    if (view != null) {
        view.refreshView();
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionParameters(org.talend.core.sqlbuilder.util.ConnectionParameters) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Shell(org.eclipse.swt.widgets.Shell) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) ContextSetsSelectionDialog(org.talend.metadata.managment.ui.wizard.metadata.ContextSetsSelectionDialog) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) SQLBuilderDialog(org.talend.sqlbuilder.ui.SQLBuilderDialog) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) Display(org.eclipse.swt.widgets.Display)

Example 5 with SQLBuilderDialog

use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.

the class SQLBuilderService method openSQLBuilderDialog.

public Dialog openSQLBuilderDialog(Shell parentShell, String processName, ConnectionParameters connParameters) {
    SQLBuilderDialog sqlBuilder = new SQLBuilderDialog(parentShell);
    UIUtils.addSqlBuilderDialog(processName, sqlBuilder);
    sqlBuilder.setConnParameters(connParameters);
    // display a error message if the db connection is failed.
    if (connParameters != null) {
        DatabaseConnection connection = createConnection(connParameters);
        if (connection != null) {
            IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
            UIUtils.checkConnection(parentShell, metadataConnection);
        }
    }
    return sqlBuilder;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) SQLBuilderDialog(org.talend.sqlbuilder.ui.SQLBuilderDialog)

Aggregations

SQLBuilderDialog (org.talend.sqlbuilder.ui.SQLBuilderDialog)5 Shell (org.eclipse.swt.widgets.Shell)3 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Display (org.eclipse.swt.widgets.Display)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 ContextItem (org.talend.core.model.properties.ContextItem)2 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)2 QueryRepositoryObject (org.talend.core.repository.model.repositoryObject.QueryRepositoryObject)2 ConnectionParameters (org.talend.core.sqlbuilder.util.ConnectionParameters)2 ContextSetsSelectionDialog (org.talend.metadata.managment.ui.wizard.metadata.ContextSetsSelectionDialog)2 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)2 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1 IRepositoryView (org.talend.repository.ui.views.IRepositoryView)1 MultiPageSqlBuilderEditor (org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor)1 ErDiagramDialog (org.talend.sqlbuilder.erdiagram.ui.ErDiagramDialog)1