use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project tdq-studio-se by Talend.
the class SQLExecution method doExecution.
protected void doExecution(IProgressMonitor monitor) throws Exception {
int numErrors = 0;
SQLException lastSQLException = null;
try {
long overallUpdateCount = 0;
long overallStartTime = System.currentTimeMillis();
for (Query query : getQueryParser()) {
if (monitor.isCanceled())
break;
if (getEditor().isClosed())
break;
// Get the next bit of SQL to run and store it as "current"
if (query == null)
break;
String querySQL = query.getQuerySql().toString();
if (querySQL == null)
continue;
// Initialise
setProgressMessage(Messages.getString("SQLResultsView.Executing"));
final long startTime = System.currentTimeMillis();
// Run it
DatabaseProduct.ExecutionResults results = null;
try {
DatabaseProduct product = getEditor().getSession().getDatabaseProduct();
try {
results = product.executeQuery(_connection, query, _maxRows);
} catch (RuntimeException e) {
throw new SQLException(e.getMessage());
}
final long endTime = System.currentTimeMillis();
DataSet dataSet;
boolean checkedForMessages = false;
while ((dataSet = results.nextDataSet()) != null) {
// update sql result
SQLResult sqlResult = new SQLResult();
sqlResult.setQuery(query);
sqlResult.setDataSet(dataSet);
sqlResult.setExecutionTimeMillis(endTime - startTime);
// Save successfull query
SQLExplorerPlugin.getDefault().getSQLHistory().addSQL(querySQL, _session);
if (monitor.isCanceled())
return;
checkForMessages(query);
checkedForMessages = true;
// show results..
displayResults(sqlResult);
}
overallUpdateCount += results.getUpdateCount();
if (!checkedForMessages)
checkForMessages(query);
debugLogQuery(query, null);
} catch (final SQLException e) {
debugLogQuery(query, e);
boolean stopOnError = SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.STOP_ON_ERROR);
logException(e, query, stopOnError);
closeStatement();
hasMessages = true;
if (stopOnError) {
errorDialog(Messages.getString("SQLResultsView.Error.Title"), e.getMessage());
return;
}
numErrors++;
lastSQLException = e;
} finally {
try {
if (results != null) {
results.close();
results = null;
}
} catch (SQLException e) {
// Nothing
}
}
}
if (!hasMessages || SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.LOG_SUCCESS_MESSAGES)) {
long overallTime = System.currentTimeMillis() - overallStartTime;
String message = Long.toString(overallUpdateCount) + " " + Messages.getString("SQLEditor.Update.Prefix") + " " + Long.toString(overallTime) + " " + Messages.getString("SQLEditor.Update.Postfix");
addMessage(new Message(Message.Status.STATUS, getQueryParser().adjustLineNo(1), 0, "", message));
}
} catch (Exception e) {
closeStatement();
throw e;
}
if (numErrors == 1)
throw lastSQLException;
else if (numErrors > 1 && SQLExplorerPlugin.getDefault().getPreferenceStore().getBoolean(IConstants.CONFIRM_BOOL_SHOW_DIALOG_ON_QUERY_ERROR))
getEditor().getSite().getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(getEditor().getSite().getShell(), Messages.getString("SQLExecution.Error.Title"), Messages.getString("SQLExecution.Error.Message"), Messages.getString("SQLExecution.Error.Toggle"), false, null, null);
if (dialog.getToggleState() && dialog.getReturnCode() == IDialogConstants.OK_ID)
SQLExplorerPlugin.getDefault().getPluginPreferences().setValue(IConstants.CONFIRM_BOOL_SHOW_DIALOG_ON_QUERY_ERROR, false);
}
});
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project tbd-studio-se by Talend.
the class HDFSFileSelectorForm method showTableIsExistConfirmDialog.
private synchronized void showTableIsExistConfirmDialog(final MetadataTable existTable) {
if (notShowAgain == false) {
// orgomg.cwm.objectmodel.core.Package pack = (orgomg.cwm.objectmodel.core.Package) existTable.eContainer();
MessageDialogWithToggle dialog = new MessageDialogWithToggle(Display.getDefault().getActiveShell(), Messages.getString("HDFSFileSelectorForm.title.confirm"), null, // $NON-NLS-1$
Messages.getString("HDFSFileSelectorForm.tableIsExist.new", // $NON-NLS-1$
existTable.getLabel()), MessageDialog.CONFIRM, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1, // $NON-NLS-1$
Messages.getString("HDFSFileSelectorForm.tableIsExist.notShowAgain"), false);
int result = dialog.open();
notShowAgain = dialog.getToggleState();
if (result == IDialogConstants.YES_ID) {
userConfirmed = true;
} else {
userConfirmed = false;
}
}
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project eclipse-cs by checkstyle.
the class CheckstylePropertyPage method performOk.
@Override
public boolean performOk() {
try {
IProject project = mProjectConfig.getProject();
// save the edited project configuration
if (mProjectConfig.isDirty()) {
mProjectConfig.store();
}
boolean checkstyleEnabled = mChkEnable.getSelection();
boolean needRebuild = mProjectConfig.isRebuildNeeded();
// check if checkstyle nature has to be configured/deconfigured
if (checkstyleEnabled != mCheckstyleInitiallyActivated) {
ConfigureDeconfigureNatureJob configOperation = new ConfigureDeconfigureNatureJob(project, CheckstyleNature.NATURE_ID);
configOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
configOperation.schedule();
needRebuild = needRebuild || !mCheckstyleInitiallyActivated;
}
if (checkstyleEnabled && mProjectConfig.isSyncFormatter()) {
TransformCheckstyleRulesJob transFormJob = new TransformCheckstyleRulesJob(project);
transFormJob.schedule();
}
// really be done.
if (checkstyleEnabled && needRebuild) {
String promptRebuildPref = CheckstyleUIPluginPrefs.getString(CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
boolean doRebuild = MessageDialogWithToggle.ALWAYS.equals(promptRebuildPref) && needRebuild;
//
if (MessageDialogWithToggle.PROMPT.equals(promptRebuildPref) && needRebuild) {
MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(getShell(), Messages.CheckstylePropertyPage_titleRebuild, Messages.CheckstylePropertyPage_msgRebuild, Messages.CheckstylePropertyPage_nagRebuild, false, CheckstyleUIPlugin.getDefault().getPreferenceStore(), CheckstyleUIPluginPrefs.PREF_ASK_BEFORE_REBUILD);
doRebuild = dialog.getReturnCode() == IDialogConstants.YES_ID;
}
// check if a rebuild is necessary
if (checkstyleEnabled && doRebuild) {
BuildProjectJob rebuildOperation = new BuildProjectJob(project, IncrementalProjectBuilder.FULL_BUILD);
rebuildOperation.setRule(ResourcesPlugin.getWorkspace().getRoot());
rebuildOperation.schedule();
}
}
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.errorDialog(getShell(), e, true);
}
return true;
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project titan.EclipsePlug-ins by eclipse.
the class MergeLog method askUserToCreateOrOverwrite.
private void askUserToCreateOrOverwrite(final IPreferenceStore prefStore, final IFile originalFile) {
final String[] buttonLabels = new String[] { "Create a new file", "Overwrite" };
final MessageDialogWithToggle msgDialog = new MessageDialogWithToggle(null, "File already exists", null, "An error occured during log file merging. The file '" + outputFile.getName() + "' already exists. " + "Do you want to keep the original file and choose another location/name for the new one?", MessageDialog.NONE, buttonLabels, SWT.DEFAULT, "Don't ask again", false);
msgDialog.setBlockOnOpen(true);
final int result = msgDialog.open() - 256;
if (result == SWT.DEFAULT) {
// The dialog was closed
setOutputFile(null);
return;
}
// lets save the chosen option to the preference store if the user checked the 'Dont ask' checkbox
final boolean dontAskChecked = msgDialog.getToggleState();
if (dontAskChecked) {
if (result == 0) {
// create a new file pressed
prefStore.setValue(PreferenceConstants.LOG_MERGE_OPTIONS, PreferenceConstants.LOG_MERGE_OPTIONS_CREATE);
} else if (result == 1) {
// overwrite
prefStore.setValue(PreferenceConstants.LOG_MERGE_OPTIONS, PreferenceConstants.LOG_MERGE_OPTIONS_OVERWRITE);
}
} else {
prefStore.setValue(PreferenceConstants.LOG_MERGE_OPTIONS, PreferenceConstants.LOG_MERGE_OPTIONS_ASK);
}
if (result == 0) {
// create a new file pressed
if (dontAskChecked) {
setOutputFile(createNewFileWithUniqueName(originalFile));
return;
}
displayOutputSelectionDialog();
} else {
// overwrite
FileUtils.deleteQuietly(outputFile);
}
}
use of org.eclipse.jface.dialogs.MessageDialogWithToggle in project pentaho-kettle by pentaho.
the class Spoon method quitFile.
public boolean quitFile(boolean canCancel) throws KettleException {
if (log.isDetailed()) {
// "Quit application."
log.logDetailed(BaseMessages.getString(PKG, "Spoon.Log.QuitApplication"));
}
boolean exit = true;
saveSettings();
if (props.showExitWarning() && canCancel) {
// Display message: are you sure you want to exit?
//
MessageDialogWithToggle md = new MessageDialogWithToggle(shell, // "Warning!"
BaseMessages.getString(PKG, "System.Warning"), null, BaseMessages.getString(PKG, "Spoon.Message.Warning.PromptExit"), MessageDialog.WARNING, new String[] { // "Yes",
BaseMessages.getString(PKG, "Spoon.Message.Warning.Yes"), // "No"
BaseMessages.getString(PKG, "Spoon.Message.Warning.No") }, 1, // "Please, don't show this warning anymore."
BaseMessages.getString(PKG, "Spoon.Message.Warning.NotShowWarning"), !props.showExitWarning());
MessageDialogWithToggle.setDefaultImage(GUIResource.getInstance().getImageSpoon());
int idx = md.open();
props.setExitWarningShown(!md.getToggleState());
props.saveProps();
if ((idx & 0xFF) == 1) {
// No selected: don't exit!
return false;
}
}
// Check all tabs to see if we can close them...
//
List<TabMapEntry> list = delegates.tabs.getTabs();
for (TabMapEntry mapEntry : list) {
TabItemInterface itemInterface = mapEntry.getObject();
if (!itemInterface.canBeClosed()) {
// Show the tab
tabfolder.setSelected(mapEntry.getTabItem());
// Unsaved work that needs to changes to be applied?
//
int reply = itemInterface.showChangedWarning();
if (reply == SWT.YES) {
// If there is a fatal error, give the user opportunity to rename file w/out overwriting existing file
if (hasFatalError) {
saveFileAs(itemInterface.getMeta());
} else {
exit = itemInterface.applyChanges();
}
} else {
if (reply == SWT.CANCEL) {
return false;
} else {
// SWT.NO
exit = true;
}
}
}
}
if (exit || !canCancel) {
// all the tabs, stop the running transformations
for (TabMapEntry mapEntry : list) {
if (!mapEntry.getObject().canBeClosed()) {
//
if (mapEntry.getObject() instanceof TransGraph) {
TransMeta transMeta = (TransMeta) mapEntry.getObject().getManagedObject();
if (transMeta.hasChanged()) {
delegates.tabs.removeTab(mapEntry);
}
}
//
if (mapEntry.getObject() instanceof TransGraph) {
TransGraph transGraph = (TransGraph) mapEntry.getObject();
if (transGraph.isRunning()) {
transGraph.stop();
delegates.tabs.removeTab(mapEntry);
}
}
}
}
}
try {
lifecycleSupport.onExit(this);
} catch (LifecycleException e) {
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
box.setMessage(e.getMessage());
box.open();
}
if (exit) {
// so we first move the focus to somewhere else
if (this.designTreeToolbar != null && !this.designTreeToolbar.isDisposed()) {
this.designTreeToolbar.forceFocus();
}
close();
}
return exit;
}
Aggregations