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