use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.
the class DeleteAction method confirmDeletion.
private boolean confirmDeletion(final List<IContainer> toDel, final List<IContainer> toDelWFs) {
String msg = "";
if (toDel.size() == 1) {
boolean isGroup = toDelWFs.size() != 1;
msg = "Do you want to delete the workflow ";
if (isGroup) {
msg += "group ";
}
msg += "\"" + toDel.get(0).getName() + "\"?\n";
} else {
int groups = toDel.size() - toDelWFs.size();
if (groups == 0) {
msg = "Do you want to delete all " + toDel.size() + " selected workflows?\n";
} else {
if (groups == 1) {
msg = "Do you want to delete the workflow group \"" + toDel.get(0).getName() + "\"?\n";
} else {
msg = "Do you want to delete all " + toDel.size() + " workflow groups?\n";
}
if (toDelWFs.size() > 0) {
if (groups == 1) {
msg += "It contains ";
} else {
msg += "They contain ";
}
msg += toDelWFs.size() + " workflow";
if (toDelWFs.size() > 1) {
msg += "s";
}
msg += ".\n";
}
}
}
msg += "\nThis operation cannot be undone.";
MessageBox mb = new MessageBox(m_shell, SWT.ICON_QUESTION | SWT.OK | SWT.CANCEL);
mb.setMessage(msg);
mb.setText("Confirm Deletion");
if (mb.open() != SWT.OK) {
LOGGER.debug("Deletion of " + toDel.size() + " items canceled by user.");
return false;
} else {
LOGGER.debug("Deletion of " + toDel.size() + " items confirmed by user.");
return true;
}
}
use of org.eclipse.swt.widgets.MessageBox in project knime-core by knime.
the class HeadlessPreferencePage method checkChanges.
private void checkChanges() {
boolean apply = m_apply;
m_apply = false;
if (apply) {
return;
}
// get the preference store for the UI plugin
IPreferenceStore store = KNIMECorePlugin.getDefault().getPreferenceStore();
String currentTmpDir = store.getString(HeadlessPreferencesConstants.P_TEMP_DIR);
boolean tempDirChanged = !m_tempPath.equals(currentTmpDir);
if (tempDirChanged) {
// reset the directory
m_tempPath = currentTmpDir;
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
mb.setText("Restart workbench...");
mb.setMessage("Changes of the temporary directory become " + "first available after restarting the workbench.\n" + "Do you want to restart the workbench now?");
if (mb.open() != SWT.YES) {
return;
}
PlatformUI.getWorkbench().restart();
}
}
use of org.eclipse.swt.widgets.MessageBox in project yamcs-studio by yamcs.
the class AddCommentHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection sel = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
Shell shell = HandlerUtil.getActiveShell(event);
if (sel != null && sel instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) sel;
if (selection.isEmpty()) {
return null;
}
// Populate with text of first record. But only if single selection
String initialValue = "";
if (selection.size() == 1) {
CommandHistoryRecord rec = (CommandHistoryRecord) selection.getFirstElement();
String existingComment = rec.getTextForColumn("Comment", false);
if (existingComment != null) {
initialValue = existingComment;
}
}
String dialogMessage;
if (selection.size() == 1) {
dialogMessage = "Add a comment for this command";
} else {
dialogMessage = "Add a comment for the " + selection.size() + " selected commands";
}
IInputValidator validator = newText -> null;
InputDialog commentDialog = new InputDialog(shell, "Add Comment", dialogMessage, initialValue, validator) {
@Override
protected int getInputTextStyle() {
return SWT.MULTI | SWT.BORDER | SWT.V_SCROLL;
}
@Override
protected Control createDialogArea(Composite parent) {
Control res = super.createDialogArea(parent);
((GridData) this.getText().getLayoutData()).heightHint = 4 * this.getText().getLineHeight();
return res;
}
};
int commentResult = commentDialog.open();
if (commentResult == Window.OK) {
String newComment = commentDialog.getValue();
CommandingCatalogue catalogue = CommandingCatalogue.getInstance();
// TODO improve me. Bundle into only one error message
// Or even better: one api call.
Iterator<?> it = selection.iterator();
while (it.hasNext()) {
CommandHistoryRecord rec = (CommandHistoryRecord) it.next();
catalogue.updateCommandComment("realtime", rec.getCommandId(), newComment).exceptionally(t -> {
Display.getDefault().asyncExec(() -> {
MessageBox dialog = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
dialog.setText("Comment Update");
dialog.setMessage("Comment has not been updated. Details: " + t.getMessage());
// open dialog and await user selection
dialog.open();
});
return null;
});
}
}
}
return null;
}
use of org.eclipse.swt.widgets.MessageBox in project yamcs-studio by yamcs.
the class GUIUtil method openConfirmDialog.
/**
*Open a dialog to ask for confirmation.
* @param dialogMessage the message on the dialog.
* @return true if user has clicked the YES button. False otherwise.
*/
public static boolean openConfirmDialog(final String dialogMessage) {
MessageBox mb = new MessageBox(DisplayUtils.getDefaultShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
mb.setMessage(dialogMessage);
mb.setText("Confirm Dialog");
int val = mb.open();
if (val == SWT.YES)
return true;
return false;
}
Aggregations