use of org.talend.sqlbuilder.ui.SQLBuilderDialog 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);
}
use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.
the class UIUtils method updateSqlBuilderDialogTitle.
public static void updateSqlBuilderDialogTitle(String newLabel, String jobName, String uniqueName) {
List<SQLBuilderDialog> list = sqlBuilders.get(jobName);
if (list != null) {
for (SQLBuilderDialog dialog : list) {
if (dialog != null && dialog.getShell() != null && !dialog.getShell().isDisposed()) {
if (dialog.getShell().getText().contains(uniqueName)) {
String title = TextUtil.SQL_BUILDER_TITLE_COMP_MODPREFIX + jobName;
//$NON-NLS-1$ //$NON-NLS-2$
title += TextUtil.SQL_BUILDER_TITLE_COMP_NAME + newLabel + "(" + uniqueName + ")";
dialog.getShell().setText(title);
}
}
}
}
}
use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.
the class ReadQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
DatabaseConnectionItem dbConnectionItem = null;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
}
Display display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(true);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(true);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
refresh(repositoryNode);
}
use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.
the class EditQueriesAction method doRun.
@Override
protected void doRun() {
IStructuredSelection selection = (IStructuredSelection) getSelection();
if (repositoryNode == null && selection != null) {
repositoryNode = (RepositoryNode) selection.getFirstElement();
}
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
IRepositoryViewObject nodeObject = repositoryNode.getObject();
boolean locked = false;
if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
locked = true;
}
}
// Avoid to delete node which is locked.
if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
final String title = "Impossible to edit queries";
String nodeName = nodeObject.getRepositoryObjectType().getLabel();
final String message = "item is already locked by another user.";
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog dialog = new MessageDialog(new Shell(), title, null, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
dialog.open();
}
});
return;
}
DatabaseConnectionItem dbConnectionItem = null;
boolean readOnly = false;
ConnectionParameters connParameters = new ConnectionParameters();
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
connParameters.setRepositoryId(repositoryNode.getObject().getId());
//$NON-NLS-1$
connParameters.setQuery("");
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
QueryRepositoryObject queryRepositoryObject = (QueryRepositoryObject) repositoryNode.getObject();
readOnly = SubItemHelper.isDeleted(queryRepositoryObject.getAbstractMetadataObject());
dbConnectionItem = (DatabaseConnectionItem) queryRepositoryObject.getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setQueryObject(queryRepositoryObject.getQuery());
connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
// first open Sql Builder,set true
connParameters.setFirstOpenSqlBuilder(true);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
dbConnectionItem = (DatabaseConnectionItem) repositoryNode.getObject().getProperty().getItem();
connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
connParameters.setMetadataTable((MetadataTableRepositoryObject) repositoryNode.getObject());
//$NON-NLS-1$
connParameters.setQuery("");
}
IRepositoryView viewPart = getViewPart();
Display display = null;
if (viewPart != null) {
display = viewPart.getViewer().getControl().getDisplay();
} else {
display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
}
Shell parentShell = new Shell(display);
TextUtil.setDialogTitle(TextUtil.SQL_BUILDER_TITLE_REP);
Connection connection = dbConnectionItem.getConnection();
String selectedContext = null;
if (connection.isContextMode()) {
ContextItem contextItem = ContextUtils.getContextItemById2(connection.getContextId());
if (contextItem != null && connection.isContextMode()) {
ContextSetsSelectionDialog setsDialog = new ContextSetsSelectionDialog(null, contextItem, false);
setsDialog.open();
selectedContext = setsDialog.getSelectedContext();
}
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell, repositoryNode, selectedContext);
dial.setReadOnly(readOnly);
if (connection instanceof DatabaseConnection) {
IMetadataConnection imetadataConnection = ConvertionHelper.convert(connection, true);
connParameters.setSchema(imetadataConnection.getSchema() == null ? "" : imetadataConnection.getSchema());
UIUtils.checkConnection(parentShell, imetadataConnection);
}
connParameters.setNodeReadOnly(readOnly);
connParameters.setFromRepository(true);
dial.setConnParameters(connParameters);
dial.open();
IRepositoryView view = getViewPart();
if (view != null) {
view.refreshView();
}
}
use of org.talend.sqlbuilder.ui.SQLBuilderDialog in project tdi-studio-se by Talend.
the class SQLBuilderService method openSQLBuilderDialog.
public Dialog openSQLBuilderDialog(Shell parentShell, String processName, ConnectionParameters connParameters) {
SQLBuilderDialog sqlBuilder = new SQLBuilderDialog(parentShell);
UIUtils.addSqlBuilderDialog(processName, sqlBuilder);
sqlBuilder.setConnParameters(connParameters);
// display a error message if the db connection is failed.
if (connParameters != null) {
DatabaseConnection connection = createConnection(connParameters);
if (connection != null) {
IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
UIUtils.checkConnection(parentShell, metadataConnection);
}
}
return sqlBuilder;
}
Aggregations