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();
}
Aggregations