Search in sources :

Example 6 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