Search in sources :

Example 1 with ColumnProposal

use of com.cubrid.common.ui.query.editor.ColumnProposal in project cubrid-manager by CUBRID.

the class QuickBuilderDialog method createContents.

protected void createContents() {
    sqlComp = CommonUITool.getActiveSQLEditorComposite();
    if (sqlComp == null) {
        closeThisDialog();
        return;
    }
    CubridDatabase cubridDatabase = sqlComp.getQueryEditorPart().getSelectedDatabase();
    if (CubridDatabase.hasValidDatabaseInfo(cubridDatabase)) {
        databaseInfo = cubridDatabase.getDatabaseInfo();
    }
    boolean loadedProposal = true;
    proposal = ColumnProposalAdvisor.getInstance().findProposal(databaseInfo);
    if (proposal == null) {
        proposal = new ColumnProposal();
        if (databaseInfo != null) {
            startTimerForUpdateProposal();
        }
        loadedProposal = false;
    }
    isSupportLimit = CompatibleUtil.isSupportLimit(cubridDatabase.getDatabaseInfo());
    shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    {
        GridLayout gl = new GridLayout();
        gl.numColumns = 1;
        shell.setLayout(gl);
    }
    shell.setSize(450, 300);
    shell.setText(Messages.quickQueryBuilderTitle);
    final Composite composite = new Composite(shell, SWT.NONE);
    {
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        composite.setLayoutData(gd);
        GridLayout gl = new GridLayout();
        composite.setLayout(gl);
    }
    final Label findWhatLabel = new Label(composite, SWT.NONE);
    findWhatLabel.setText(Messages.quickQueryBuilderLabel);
    inputText = new Text(composite, SWT.BORDER);
    {
        GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
        inputText.setLayoutData(gd);
    }
    inputText.setEditable(true);
    inputText.addKeyListener(inputTextKeyListener);
    searchView = new TableViewer(composite, SWT.BORDER);
    {
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        searchView.getTable().setLayoutData(gd);
    }
    searchView.setContentProvider(searchViewContentProvider);
    searchView.setLabelProvider(searchViewLabelProvider);
    searchView.setInput(proposal);
    searchView.getTable().addKeyListener(new KeyListener() {

        public void keyReleased(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.CR) {
                makeQueryAndClose(0);
            }
        }
    });
    TableColumn col1 = new TableColumn(searchView.getTable(), SWT.NONE);
    col1.setWidth(200);
    TableColumn col2 = new TableColumn(searchView.getTable(), SWT.NONE);
    col2.setWidth(200);
    if (!loadedProposal) {
        updateNoticeBanner = new Label(composite, SWT.BORDER);
        {
            GridData gd = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
            updateNoticeBanner.setLayoutData(gd);
        }
        updateNoticeBanner.setText(Messages.quickQueryBuilderLoading);
        updateNoticeBanner.setBackground(ResourceManager.getColor(255, 255, 255));
    }
    Composite bottomPanel = new Composite(composite, SWT.NONE);
    {
        GridLayout gl = new GridLayout();
        gl.numColumns = 4;
        bottomPanel.setLayout(gl);
        GridData gd = new GridData(SWT.FILL, SWT.BOTTOM, true, false);
        bottomPanel.setLayoutData(gd);
    }
    createButtons(bottomPanel);
}
Also used : ColumnProposal(com.cubrid.common.ui.query.editor.ColumnProposal) SQLEditorComposite(com.cubrid.common.ui.query.control.SQLEditorComposite) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) KeyEvent(org.eclipse.swt.events.KeyEvent) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) KeyListener(org.eclipse.swt.events.KeyListener) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 2 with ColumnProposal

use of com.cubrid.common.ui.query.editor.ColumnProposal in project cubrid-manager by CUBRID.

the class QuickBuilderDialog method startTimerForUpdateProposal.

private void startTimerForUpdateProposal() {
    TimerTask proposalUpdateNotifyTask = new TimerTask() {

        public void run() {
            ColumnProposal proposalTemp = ColumnProposalAdvisor.getInstance().findProposal(databaseInfo);
            if (proposalTemp == null) {
                return;
            }
            if (proposalUpdateTimer != null) {
                proposalUpdateTimer.cancel();
                proposalUpdateTimer = null;
            }
            proposal = proposalTemp;
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    if (updateNoticeBanner != null) {
                        updateNoticeBanner.dispose();
                        updateNoticeBanner = null;
                    }
                    if (searchView != null) {
                        searchView.setInput(proposal);
                    }
                    shell.layout(true, true);
                }
            });
        }
    };
    proposalUpdateTimer = new Timer(true);
    proposalUpdateTimer.schedule(proposalUpdateNotifyTask, 500);
}
Also used : TimerTask(java.util.TimerTask) ColumnProposal(com.cubrid.common.ui.query.editor.ColumnProposal) Timer(java.util.Timer)

Example 3 with ColumnProposal

use of com.cubrid.common.ui.query.editor.ColumnProposal in project cubrid-manager by CUBRID.

the class QuickBuilderDialog method makeQueryAndClose.

private void makeQueryAndClose(int type) {
    // FIXME move this logic to core module
    String tableName = getSelectedTable().trim();
    List<ColumnProposalDetailInfo> columns = null;
    String query = null;
    ColumnProposal proposal = ColumnProposalAdvisor.getInstance().findProposal(sqlComp.getQueryEditorPart().getSelectedDatabase().getDatabaseInfo());
    if (proposal != null) {
        columns = proposal.getColumns().get(tableName);
    }
    if (columns == null) {
        columns = new ArrayList<ColumnProposalDetailInfo>();
    }
    int cursorPosition = 0;
    if (type == 0) {
        query = "SELECT * FROM " + QuerySyntax.escapeKeyword(tableName) + " " + appendLimit() + ";" + StringUtil.NEWLINE;
        cursorPosition = query.length() - 1;
    } else if (type == 1) {
        StringBuilder col = new StringBuilder();
        if (columns != null) {
            for (ColumnProposalDetailInfo info : columns) {
                String column = info.getColumnName();
                if (col.length() > 0) {
                    col.append(", ");
                }
                col.append(QuerySyntax.escapeKeyword(column));
            }
        }
        query = "SELECT " + col.toString() + " FROM " + QuerySyntax.escapeKeyword(tableName) + " " + appendLimit() + ";" + StringUtil.NEWLINE;
        cursorPosition = query.length() - 1;
    } else if (type == 2) {
        StringBuilder col = new StringBuilder();
        StringBuilder col2 = new StringBuilder();
        if (columns != null) {
            for (ColumnProposalDetailInfo info : columns) {
                String column = info.getColumnName();
                if (col.length() > 0) {
                    col.append(", ");
                    col2.append(", ");
                }
                col.append(QuerySyntax.escapeKeyword(column));
                col2.append(column);
            }
        }
        query = "INSERT INTO " + QuerySyntax.escapeKeyword(tableName) + " (" + col.toString() + ") VALUES (" + col2.toString() + ");\n";
        cursorPosition = 14 + tableName.length() + col.length() + 10;
    } else if (type == 3) {
        StringBuilder col = new StringBuilder();
        if (columns != null) {
            for (ColumnProposalDetailInfo info : columns) {
                String column = info.getColumnName();
                if (col.length() > 0) {
                    col.append(", ");
                }
                col.append(QuerySyntax.escapeKeyword(column)).append("=");
            }
        }
        query = "UPDATE " + QuerySyntax.escapeKeyword(tableName) + " SET " + col.toString() + " WHERE ;" + StringUtil.NEWLINE;
        cursorPosition = 12 + tableName.length();
    }
    pasteIntoQueryEditor(query, cursorPosition);
    closeThisDialog();
}
Also used : ColumnProposal(com.cubrid.common.ui.query.editor.ColumnProposal) ColumnProposalDetailInfo(com.cubrid.common.ui.query.editor.ColumnProposalDetailInfo)

Aggregations

ColumnProposal (com.cubrid.common.ui.query.editor.ColumnProposal)3 SQLEditorComposite (com.cubrid.common.ui.query.control.SQLEditorComposite)1 ColumnProposalDetailInfo (com.cubrid.common.ui.query.editor.ColumnProposalDetailInfo)1 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 StyledText (org.eclipse.swt.custom.StyledText)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Shell (org.eclipse.swt.widgets.Shell)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 Text (org.eclipse.swt.widgets.Text)1