Search in sources :

Example 1 with MultiPageSqlBuilderEditor

use of org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor 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 2 with MultiPageSqlBuilderEditor

use of org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor 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 3 with MultiPageSqlBuilderEditor

use of org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor in project tdi-studio-se by Talend.

the class ContextModeSessionSwitcher method createControl.

@Override
protected Control createControl(Composite parent) {
    button = new Button(parent, SWT.CHECK);
    //$NON-NLS-1$
    button.setText(Messages.getString("ContextModeSessionSwitcher.buttonText"));
    final Query query = (QueryImpl) contextmodeaction.getQuery();
    // judge from repository node
    if (query != null) {
        button.setSelection(query.isContextMode());
    // judge from designer built-in
    } else {
        button.setSelection(contextmodeaction.getParameters().getIfContextButtonCheckedFromBuiltIn());
    }
    button.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            contextmodeaction.setChecked(button.getSelection());
            contextmodeaction.getParameters().setIfContextButtonCheckedFromBuiltIn(button.getSelection());
            // judge dirty
            MultiPageSqlBuilderEditor m = editor.getMultiPageEditor();
            m.updateEditorTitle(null);
        }
    });
    return button;
}
Also used : QueryImpl(org.talend.core.model.metadata.builder.connection.impl.QueryImpl) Query(org.talend.core.model.metadata.builder.connection.Query) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MultiPageSqlBuilderEditor(org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor)

Example 4 with MultiPageSqlBuilderEditor

use of org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor in project tdi-studio-se by Talend.

the class SQLEditorSessionSwitcher method createControl.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
     */
protected Control createControl(Composite parent) {
    sessionCombo = new Combo(parent, SWT.READ_ONLY);
    //$NON-NLS-1$
    sessionCombo.setToolTipText(Messages.getString("SQLEditor.Actions.ChooseSession.ToolTip"));
    List<String> repositoryNameList = nodeManager.getALLReposotoryNodeNames();
    sessionCombo.setItems(repositoryNameList.toArray(new String[repositoryNameList.size()]));
    sessionCombo.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            String repoName = sessionCombo.getText();
            RepositoryNode node = nodeManager.getRepositoryNodebyName(repoName);
            if (!repoName.equals(DBTreeProvider.BUILT_IN)) {
                MultiPageSqlBuilderEditor multiPageEditor = editor.getMultiPageEditor();
                multiPageEditor.setRepositoryNode(node);
            }
        // editor.refresh(true);
        }
    });
    return sessionCombo;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Combo(org.eclipse.swt.widgets.Combo) MultiPageSqlBuilderEditor(org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 5 with MultiPageSqlBuilderEditor

use of org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor in project tdi-studio-se by Talend.

the class SQLBuilderDialog method okPressed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
     */
@Override
public void okPressed() {
    // gain the contextmode from sqlbuilder,and set it in connParameters,add by hyWang
    MultiPageSqlBuilderEditor editor = null;
    CTabFolder folder = getEditorComposite().getTabFolder();
    CTabItem[] a = folder.getItems();
    for (CTabItem itm : a) {
        //$NON-NLS-1$
        Object obj = itm.getData("KEY");
        if (obj instanceof MultiPageSqlBuilderEditor) {
            editor = (MultiPageSqlBuilderEditor) obj;
        }
        if (editor != null) {
            if (itm.getData() instanceof Query) {
                Query q = (Query) itm.getData();
                connParameters.setIfContextButtonCheckedFromBuiltIn(q.isContextMode());
            }
        }
    }
    if (EParameterFieldType.DBTABLE.equals(connParameters.getFieldType())) {
        final IStructuredSelection selection = (IStructuredSelection) structureComposite.getTreeViewer().getSelection();
        final Object firstElement = selection.getFirstElement();
        if (firstElement instanceof RepositoryNode) {
            RepositoryNode node = (RepositoryNode) firstElement;
            boolean is = node.getProperties(EProperties.CONTENT_TYPE).equals(RepositoryNodeType.TABLE);
            if (is) {
                MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) node.getObject();
                connParameters.setSelectDBTable(object.getSourceName());
            }
        }
    } else {
        //$NON-NLS-1$
        String sql = "";
        // sql = editorComposite.getDefaultTabSql();
        sql = editorComposite.getCurrentTabSql();
        // if (ConnectionParameters.isJavaProject()) {
        // sql = sql.replace("\"", "\\" + "\"");
        // } else {
        // sql = sql.replace("'", "\\'");
        // }
        // sql = QueryUtil.checkAndAddQuotes(sql);
        connParameters.setQuery(sql);
        if (connParameters.isFromRepository() && !connParameters.isNodeReadOnly()) {
            List<Query> qs = new ArrayList<Query>();
            boolean isInfo = false;
            final CTabFolder tabFolder = getEditorComposite().getTabFolder();
            final CTabItem[] items = tabFolder.getItems();
            for (CTabItem item : items) {
                final String text = item.getText();
                //$NON-NLS-1$
                boolean isInfo2 = text.length() > 1 && text.substring(0, 1).equals("*");
                if (isInfo2) {
                    isInfo = true;
                }
            }
            if (isInfo) {
                //$NON-NLS-1$
                String title = Messages.getString("SQLBuilderDialog.SaveAllQueries.Title");
                //$NON-NLS-1$
                String info = Messages.getString("SQLBuilderDialog.SaveAllQueries.Info");
                boolean openQuestion = MessageDialog.openQuestion(getShell(), title, info);
                if (openQuestion) {
                    for (CTabItem item : items) {
                        final String text = item.getText();
                        //$NON-NLS-1$
                        boolean isInfo2 = text.length() > 1 && text.substring(0, 1).equals("*");
                        if (isInfo2) {
                            MultiPageSqlBuilderEditor meditor = null;
                            //$NON-NLS-1$
                            Object control = item.getData("KEY");
                            if (control instanceof MultiPageSqlBuilderEditor) {
                                meditor = (MultiPageSqlBuilderEditor) control;
                            }
                            if (meditor != null) {
                                RepositoryNode node = null;
                                node = meditor.getActivePageRepositoryNode();
                                if (text.substring(1).startsWith(AbstractSQLEditorComposite.QUERY_PREFIX)) {
                                    if (item.getData() instanceof Query) {
                                        Query q = (Query) item.getData();
                                        q.setValue(meditor.getActivePageSqlString());
                                        // add by hyWang
                                        q.setContextMode(meditor.getActiveEditors().getContextmode().getContextmodeaction().isChecked());
                                        qs.add(q);
                                        if (node != null && q != null) {
                                            manager.saveQuery(node, q, null);
                                        }
                                    }
                                } else {
                                    meditor.getActivePageSaveAsSQLAction().run();
                                }
                            }
                        }
                    }
                }
            }
            if (connParameters.getQueryObject() != null) {
                RepositoryUpdateManager.updateQuery(connParameters.getQueryObject(), node);
            }
        }
    }
    deleteNoUseTable();
    super.okPressed();
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) Query(org.talend.core.model.metadata.builder.connection.Query) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CTabItem(org.eclipse.swt.custom.CTabItem) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) MultiPageSqlBuilderEditor(org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor) MetadataTableRepositoryObject(org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

MultiPageSqlBuilderEditor (org.talend.sqlbuilder.editors.MultiPageSqlBuilderEditor)6 CTabItem (org.eclipse.swt.custom.CTabItem)4 Query (org.talend.core.model.metadata.builder.connection.Query)4 CTabFolder (org.eclipse.swt.custom.CTabFolder)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Shell (org.eclipse.swt.widgets.Shell)2 IRepositoryNode (org.talend.repository.model.IRepositoryNode)2 RepositoryNode (org.talend.repository.model.RepositoryNode)2 ArrayList (java.util.ArrayList)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 PartInitException (org.eclipse.ui.PartInitException)1 QueryImpl (org.talend.core.model.metadata.builder.connection.impl.QueryImpl)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 MetadataTableRepositoryObject (org.talend.sqlbuilder.dbstructure.DBTreeProvider.MetadataTableRepositoryObject)1 QueryRepositoryObject (org.talend.sqlbuilder.dbstructure.DBTreeProvider.QueryRepositoryObject)1 SQLBuilderEditorInput (org.talend.sqlbuilder.editors.SQLBuilderEditorInput)1 SQLBuilderEditorSite (org.talend.sqlbuilder.editors.SQLBuilderEditorSite)1