Search in sources :

Example 1 with ErDiagramDialog

use of org.talend.sqlbuilder.erdiagram.ui.ErDiagramDialog 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)

Aggregations

CTabItem (org.eclipse.swt.custom.CTabItem)1 Shell (org.eclipse.swt.widgets.Shell)1 IRepositoryNode (org.talend.repository.model.IRepositoryNode)1 MultiPageSqlBuilderEditor (org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor)1 ErDiagramDialog (org.talend.sqlbuilder.erdiagram.ui.ErDiagramDialog)1 ISQLBuilderDialog (org.talend.sqlbuilder.ui.ISQLBuilderDialog)1 SQLBuilderDialog (org.talend.sqlbuilder.ui.SQLBuilderDialog)1 SqlEditDialog (org.talend.sqlbuilder.ui.SqlEditDialog)1 QueryTokenizer (org.talend.sqlbuilder.util.QueryTokenizer)1