use of org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton in project tdi-studio-se by Talend.
the class DbTableController method createOpenSQLCommand.
/**
* qzhang Comment method "createOpenSQLCommand".
*
* @param button
*/
protected void createOpenSQLCommand(Button button, IContextManager contextManager) {
final Button btn = button;
initConnectionParameters();
if (this.connParameters != null) {
if (isUseExistingConnection()) {
initConnectionParametersWithContext(connectionNode, contextManager.getDefaultContext());
} else {
initConnectionParametersWithContext(elem, contextManager.getDefaultContext());
}
DatabaseConnection connection = getExistConnection();
if (connection == null) {
ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
connection = service.createConnection(connParameters);
}
boolean isStatus = false;
if (connection != null) {
String contextId = connection.getContextId();
if (contextId == null || "".equals(contextId)) {
IMetadataConnection metadataConnection = null;
metadataConnection = ConvertionHelper.convert(connection);
isStatus = checkConnection(metadataConnection);
} else {
isStatus = true;
}
}
if (isStatus) {
openSQLBuilderWithParamer(button);
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = "Database connection is failed. ";
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(btn, part.getProcess().getContextManager());
}
}
});
}
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = "Database connection is failed. ";
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(btn, part.getProcess().getContextManager());
}
}
});
}
}
use of org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton in project tdi-studio-se by Talend.
the class GuessSchemaController method useMockJob.
private void useMockJob() {
/*
* get the select node,it's the input node of the process. then transfer selected context varriable to
* openContextChooseDialog, added by hyWang
*/
final IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
final Shell parentShell = this.composite.getShell();
final Node inputNode = (Node) this.curParameter.getElement();
if (connParameters == null) {
initConnectionParameters();
}
final String tmpMemoSql = this.memoSQL;
final DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
IMetadataConnection iMetadataConnection = null;
boolean isStatus = false;
try {
if (connt != null) {
iMetadataConnection = ConvertionHelper.convert(connt);
isStatus = checkConnection(iMetadataConnection);
}
if (isStatus) {
if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(iMetadataConnection.getDbType())) {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getAdditionalParams());
} else if (EDatabaseTypeName.HIVE.getDisplayName().equals(iMetadataConnection.getDbType())) {
String jobTracker = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL)));
String nameNode = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL)));
String thrifturi = null;
if (HiveModeInfo.get(iMetadataConnection.getDbVersionString()) == HiveModeInfo.EMBEDDED) {
thrifturi = "thrift://" + iMetadataConnection.getServerName() + ":" + iMetadataConnection.getPort();
}
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), jobTracker, nameNode, thrifturi, iMetadataConnection.getDriverJarPath());
String hiveServerVersion = String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.HIVE_SERVER_VERSION));
//$NON-NLS-1$
String driverClass = "";
if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
driverClass = EDatabase4DriverClassName.HIVE2.getDriverClass();
} else {
driverClass = EDatabase4DriverClassName.HIVE.getDriverClass();
}
info.setDriverClassName(driverClass);
} else {
info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverJarPath());
}
final Property property = GuessSchemaProcess.getNewmockProperty();
List<IContext> allcontexts = inputNode.getProcess().getContextManager().getListContext();
OpenContextChooseComboDialog dialog = new OpenContextChooseComboDialog(parentShell, allcontexts);
dialog.create();
dialog.getShell().setText(CONTEXT_CHOOSE_DIALOG_TITLE);
IContext selectContext = null;
// job only have defoult context,or the query isn't context mode
if (allcontexts.size() == 1 || TalendTextUtils.isCommonString(tmpMemoSql)) {
selectContext = inputNode.getProcess().getContextManager().getDefaultContext();
} else if (Window.OK == dialog.open()) {
selectContext = dialog.getSelectedContext();
}
final IContext context = selectContext;
if (context != null) {
//
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
runShadowProcess(property, inputNode, context, switchParam);
}
});
}
});
}
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = Messages.getString("GuessSchemaController.connectionFailed");
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
}
}
});
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
// else {
// try {
// pmd2.run(true, true, new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Display.getDefault().asyncExec(new Runnable() {
//
// public void run() {
// String pid = SqlBuilderPlugin.PLUGIN_ID;
// String mainMsg = Messages.getString("GuessSchemaController.connectionFailed"); //$NON-NLS-1$
// ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite
// .getShell(), pid, mainMsg, connParameters.getConnectionComment());
// if (dialog.getCodeOfButton() == Window.OK) {
// openParamemerDialog(composite.getShell(), part.getTalendEditor().getProcess().getContextManager());
// }
// }
// });
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
use of org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton in project tdi-studio-se by Talend.
the class GuessSchemaController method runShadowProcessForPerl.
private void runShadowProcessForPerl() {
final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
try {
pmd.run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (columns != null) {
columns.clear();
}
//$NON-NLS-1$
monitor.beginTask(Messages.getString("GuessSchemaController.waitOpenDatabase"), IProgressMonitor.UNKNOWN);
if (connParameters == null) {
initConnectionParameters();
}
ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
DatabaseConnection connt = service.createConnection(connParameters);
IMetadataConnection iMetadataConnection = null;
boolean isStatus = false;
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
if (connt != null) {
iMetadataConnection = ConvertionHelper.convert(connt);
isStatus = checkConnection(iMetadataConnection);
}
if (!monitor.isCanceled()) {
try {
if (isStatus) {
extractMeta.getConnection(iMetadataConnection.getDbType(), iMetadataConnection.getUrl(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDatabase(), iMetadataConnection.getSchema(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getAdditionalParams());
if (extractMeta.getConn() != null) {
Statement smst = extractMeta.getConn().createStatement();
extractMeta.setQueryStatementTimeout(smst);
ResultSet rs = smst.executeQuery(memoSQL);
ResultSetMetaData rsmd = rs.getMetaData();
int numbOfColumn = rsmd.getColumnCount();
int count = 0;
List<String[]> cvsArrays = new ArrayList<String[]>();
while (rs.next() && count < 50) {
String[] dataOneRow = new String[numbOfColumn];
for (int i = 1; i <= numbOfColumn; i++) {
String tempStr = rs.getString(i);
dataOneRow[i - 1] = tempStr;
}
cvsArrays.add(dataOneRow);
count++;
}
refreshMetaDataTable(rsmd, cvsArrays);
extractMeta.closeConnection();
}
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = "Database connection is failed. ";
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
}
}
});
}
} catch (Exception e) {
extractMeta.closeConnection();
ExceptionHandler.process(e);
final String strExcepton = "Connect to DB error ,or some errors in SQL query string, or 'Guess Schema' not compatible with current SQL query string." + System.getProperty("line.separator");
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connError"), //$NON-NLS-1$
strExcepton);
}
});
}
}
}
});
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
use of org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton in project tdi-studio-se by Talend.
the class DbTableController method openDbTableSelectorJob.
/**
* qzhang Comment method "openDbTableSelectorJob".
*
* @param openListTable
*/
private void openDbTableSelectorJob(final Button openListTable) {
Job job = new //$NON-NLS-1$
Job(//$NON-NLS-1$
Messages.getString("DbTableController.openSelectionDialog")) {
@Override
protected IStatus run(final IProgressMonitor monitor) {
//$NON-NLS-1$
monitor.beginTask(Messages.getString("DbTableController.waitingForOpen"), IProgressMonitor.UNKNOWN);
DatabaseConnection existConnection = getExistConnection();
if (existConnection == null) {
if (connParameters == null) {
initConnectionParameters();
}
existConnection = TracesConnectionUtils.createConnection(connParameters);
}
final DatabaseConnection con = existConnection;
IMetadataConnection iMetadataConnection = null;
final IMetadataConnection[] iMetadata = new IMetadataConnection[1];
boolean isStatus = false;
if (existConnection != null) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IMetadataConnection convert = ConvertionHelper.convert(con);
iMetadata[0] = convert;
}
});
iMetadataConnection = iMetadata[0];
// Added by Marvin Wang for bug TDI-24288.
if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
try {
HiveConnectionManager.getInstance().checkConnection(iMetadataConnection);
isStatus = true;
} catch (ClassNotFoundException e) {
isStatus = false;
ExceptionHandler.process(e);
} catch (InstantiationException e) {
isStatus = false;
ExceptionHandler.process(e);
} catch (IllegalAccessException e) {
isStatus = false;
ExceptionHandler.process(e);
} catch (SQLException e) {
isStatus = false;
ExceptionHandler.process(e);
}
}
} else {
isStatus = checkConnection(iMetadataConnection);
}
}
String type = null;
if (iMetadataConnection != null) {
type = iMetadataConnection.getDbType();
}
final String dbType = type;
if (!monitor.isCanceled()) {
try {
if (isStatus) {
// Added by Marvin Wang for bug TDI-24288.
if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
JavaSqlFactory.doHivePreSetup((DatabaseConnection) iMetadataConnection.getCurrentConnection());
returnTablesFormConnection = ExtractMetaDataFromDataBase.fetchAllTablesForHiveEmbeddedModel(iMetadataConnection);
JavaSqlFactory.doHiveConfigurationClear();
}
} else {
returnTablesFormConnection = ExtractMetaDataFromDataBase.returnTablesFormConnection(iMetadataConnection);
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
final DbTableSelectorObject object = new DbTableSelectorObject();
DbTableSelectorObject connO = new DbTableSelectorObject();
if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
connO.setLabel(connParameters.getLocalServiceName());
} else if ("".equals(connParameters.getDbName())) {
//$NON-NLS-1$
connO.setLabel(connParameters.getDatasource());
} else {
connO.setLabel(connParameters.getDbName());
}
// ...
if (connO.getLabel() == null || connO.getLabel().equals("")) {
//$NON-NLS-1$
if (elem instanceof INode) {
connO.setLabel(elem.getElementName());
} else {
connO.setLabel("tJDBCConnection");
}
}
connO.setType(ObjectType.DB);
if (monitor.isCanceled()) {
monitor.done();
return;
}
for (String string : returnTablesFormConnection) {
DbTableSelectorObject tableO = new DbTableSelectorObject();
tableO.setLabel(string);
tableO.setType(ObjectType.TABLE);
connO.addChildren(tableO);
}
object.addChildren(connO);
String propertyName = (String) openListTable.getData(PARAMETER_NAME);
DbTableSelectorDialog selectorDialog = new DbTableSelectorDialog(composite.getShell(), object);
if (selectorDialog.open() == DbTableSelectorDialog.OK) {
String name = selectorDialog.getSelectName();
if (name != null) {
Command dbSelectorCommand = new PropertyChangeCommand(elem, propertyName, TalendTextUtils.addQuotes(name));
executeCommand(dbSelectorCommand);
Text labelText = (Text) hashCurControls.get(propertyName);
labelText.setText(TalendTextUtils.addQuotes(name));
}
}
}
});
} else {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
//$NON-NLS-1$
String pid = "org.talend.sqlbuilder";
//$NON-NLS-1$
String mainMsg = "Database connection is failed. ";
ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
if (dialog.getCodeOfButton() == Window.OK) {
openParamemerDialog(openListTable, part.getProcess().getContextManager());
}
}
});
}
} catch (SQLException e) {
// Added by Marvin Wang for bug TDI-24288.
JavaSqlFactory.doHiveConfigurationClear();
ExceptionHandler.process(e);
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(openListTable.getShell(), //$NON-NLS-1$
Messages.getString("DbTableController.dialog.title"), //$NON-NLS-1$
Messages.getString("DbTableController.dialog.contents.fetchTableFailed"));
}
});
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
monitor.done();
return Status.OK_STATUS;
}
};
if (part != null) {
IWorkbenchSiteProgressService siteps = (IWorkbenchSiteProgressService) part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
siteps.showInDialog(composite.getShell(), job);
} else {
PlatformUI.getWorkbench().getProgressService().showInDialog(composite.getShell(), job);
}
job.setUser(true);
job.schedule();
}
use of org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton in project tdi-studio-se by Talend.
the class OpenSQLBuilderDialogJob method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected IStatus run(IProgressMonitor monitor) {
loginProgress = new OpenSQLBuilderDialogProgress(connectionParameters, manager, composite);
Object obj = controller.getDynamicProperty().getPart();
Process p = null;
if (obj instanceof IMultiPageTalendEditor) {
p = (Process) ((IMultiPageTalendEditor) obj).getProcess();
} else {
//$NON-NLS-1$
throw new RuntimeException(Messages.getString("OpenSQLBuilderDialogJob.typeRequried"));
}
final Process process = p;
try {
loginProgress.run(monitor);
if (EDatabaseTypeName.ACCESS.getDisplayName().equals(connectionParameters.getDbType()) || connectionParameters.isStatus()) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
Shell parentShell = new Shell(composite.getShell().getDisplay());
if (elem instanceof Node) {
TextUtil.setDialogTitle(process.getName(), (String) //$NON-NLS-1$
((Node) elem).getElementParameter("LABEL").getValue(), elem.getElementName());
} else {
TextUtil.setDialogTitle(process.getName(), null, null);
}
SQLBuilderDialog dial = new SQLBuilderDialog(parentShell);
UIUtils.addSqlBuilderDialog(process.getName(), dial);
dial.setConnParameters(connectionParameters);
if (Window.OK == dial.open()) {
if (!composite.isDisposed() && !connectionParameters.isNodeReadOnly()) {
if (EParameterFieldType.DBTABLE.equals(connectionParameters.getFieldType())) {
// final String selectDBTable = connectionParameters.getSelectDBTable();
// if (selectDBTable != null) {
// Command cmd = new PropertyChangeCommand(elem, propertyName, TalendTextUtils
// .addSQLQuotes(selectDBTable));
// commandStack.execute(cmd);
// }
} else {
String sql = connectionParameters.getQuery();
sql = QueryUtil.checkAndAddQuotes(sql);
PropertyChangeCommand cmd = new PropertyChangeCommand(elem, propertyName, sql);
cmd.setUpdate(true);
commandStack.execute(cmd);
}
}
}
}
});
} else {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
String pid = SqlBuilderPlugin.PLUGIN_ID;
//$NON-NLS-1$
String mainMsg = Messages.getString("ConnectionError.Message");
if (new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connectionParameters.getConnectionComment()).getCodeOfButton() == Dialog.OK) {
ConfigureConnParamDialog paramDialog = new ConfigureConnParamDialog(composite.getShell(), connectionParameters, process.getContextManager(), elem);
if (paramDialog.open() == Window.OK) {
controller.openSqlBuilderBuildIn(connectionParameters, propertyName);
}
}
}
});
}
} catch (InterruptedException ie) {
loginProgress.cleanUp();
//$NON-NLS-1$
return new Status(IStatus.CANCEL, id, IStatus.CANCEL, "Progress.OpenSqlBuilderDialog.Cancelled", null);
} catch (Exception e) {
loginProgress.cleanUp();
//$NON-NLS-1$
return new Status(IStatus.ERROR, id, IStatus.CANCEL, "Progress.OpenSqlBuilderDialog.Error", e);
}
//$NON-NLS-1$
return new Status(IStatus.OK, id, IStatus.OK, "tested ok ", null);
}
Aggregations