use of org.eclipse.jface.dialogs.MessageDialog in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method performSaveAs.
/**
* This implementation asks the user for the workspace path of a file resource and saves the document there.
*
* @param progressMonitor the progress monitor to be used
* @since 3.2
*/
@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {
Shell shell = PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
final IEditorInput input = getEditorInput();
IDocumentProvider provider = getDocumentProvider();
final IEditorInput newInput;
if (input instanceof IURIEditorInput && !(input instanceof IFileEditorInput)) {
FileDialog dialog = new FileDialog(shell, SWT.SAVE);
IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
if (oldPath != null && !oldPath.isEmpty()) {
dialog.setFileName(oldPath.lastSegment());
dialog.setFilterPath(oldPath.removeLastSegments(1).toOSString());
}
String path = dialog.open();
if (path == null) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
// Check whether file exists and if so, confirm overwrite
final File localFile = new File(path);
if (localFile.exists()) {
MessageDialog overwriteDialog = new MessageDialog(shell, TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_title, null, NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_saveAs_overwrite_message, path), MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, // 'No' is the default
1);
if (overwriteDialog.open() != Window.OK) {
if (progressMonitor != null) {
progressMonitor.setCanceled(true);
return;
}
}
}
IFileStore fileStore;
try {
fileStore = EFS.getStore(localFile.toURI());
} catch (CoreException ex) {
EditorsPlugin.log(ex.getStatus());
String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, ex.getMessage());
MessageDialog.openError(shell, title, msg);
return;
}
IFile file = getWorkspaceFile(fileStore);
if (file != null)
newInput = new FileEditorInput(file);
else
newInput = new FileStoreEditorInput(fileStore);
} else {
SaveAsDialog dialog = new SaveAsDialog(shell);
IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
if (original != null)
dialog.setOriginalFile(original);
else
dialog.setOriginalName(input.getName());
dialog.create();
if (provider.isDeleted(input) && original != null) {
String message = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_warning_saveAs_deleted, original.getName());
dialog.setErrorMessage(null);
dialog.setMessage(message, IMessageProvider.WARNING);
}
if (dialog.open() == Window.CANCEL) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
IPath filePath = dialog.getResult();
if (filePath == null) {
if (progressMonitor != null)
progressMonitor.setCanceled(true);
return;
}
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFile file = workspace.getRoot().getFile(filePath);
newInput = new FileEditorInput(file);
}
if (provider == null) {
// editor has programmatically been closed while the dialog was open
return;
}
boolean success = false;
try {
provider.aboutToChange(newInput);
provider.saveDocument(progressMonitor, newInput, provider.getDocument(input), true);
success = true;
} catch (CoreException x) {
final IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
String title = TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_title;
String msg = NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_error_saveAs_message, x.getMessage());
MessageDialog.openError(shell, title, msg);
}
} finally {
provider.changed(newInput);
if (success)
setInput(newInput);
}
if (progressMonitor != null)
progressMonitor.setCanceled(!success);
}
use of org.eclipse.jface.dialogs.MessageDialog in project linuxtools by eclipse.
the class SystemTapScriptGraphOptionsTab method createColumnSelector.
private void createColumnSelector(Composite parent) {
GridLayout layout = new GridLayout();
parent.setLayout(layout);
Composite topLayout = new Composite(parent, SWT.NONE);
topLayout.setLayout(new GridLayout(1, false));
topLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Button generateExpsButton = new Button(topLayout, SWT.PUSH);
generateExpsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
generateExpsButton.setText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsButton);
generateExpsButton.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_generateFromPrintsTooltip);
generateExpsButton.addSelectionListener(regexGenerator);
Composite regexButtonLayout = new Composite(parent, SWT.NONE);
regexButtonLayout.setLayout(new GridLayout(3, false));
regexButtonLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
Label selectedRegexLabel = new Label(regexButtonLayout, SWT.NONE);
selectedRegexLabel.setText(Messages.SystemTapScriptGraphOptionsTab_regexLabel);
selectedRegexLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_regexTooltip);
regularExpressionCombo = new Combo(regexButtonLayout, SWT.DROP_DOWN);
regularExpressionCombo.setTextLimit(MAX_REGEX_LENGTH);
regularExpressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
regularExpressionCombo.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
int selected = regularExpressionCombo.getSelectionIndex();
if (selected == selectedRegex) {
return;
}
// If deselecting an empty regular expression, delete it automatically.
if (regularExpressionCombo.getItem(selectedRegex).isEmpty() && graphsDataList.get(selectedRegex).size() == 0 && outputList.get(selectedRegex).isEmpty()) {
// Otherwise, the deleted blank entry would be replaced by another blank entry.
if (selected == regularExpressionCombo.getItemCount() - 1) {
// To keep the text blank.
regularExpressionCombo.select(selectedRegex);
return;
}
removeRegex(false);
if (selected > selectedRegex) {
selected--;
}
}
// update all appropriate values to make room for a new regular expression.
if (selected == regularExpressionCombo.getItemCount() - 1 && getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
// $NON-NLS-1$
outputList.add("");
regexErrorMessages.add(null);
columnNamesList.add(new ArrayList<String>());
cachedNamesList.add(new Stack<String>());
graphsDataList.add(new LinkedList<GraphData>());
// Remove "Add New Regex" from the selected combo item; make it blank.
// $NON-NLS-1$
regularExpressionCombo.setItem(selected, "");
regularExpressionCombo.select(selected);
updateRegexSelection(selected, false);
updateLaunchConfigurationDialog();
// (Don't do this _every_ time something is added.)
if (getNumberOfRegexs() == 2) {
removeRegexButton.setEnabled(true);
}
if (getNumberOfRegexs() < MAX_NUMBER_OF_REGEXS) {
regularExpressionCombo.add(Messages.SystemTapScriptGraphOptionsTab_regexAddNew);
}
} else {
updateRegexSelection(selected, false);
}
}));
regularExpressionCombo.addModifyListener(regexListener);
removeRegexButton = new Button(regexButtonLayout, SWT.PUSH);
removeRegexButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
removeRegexButton.setText(Messages.SystemTapScriptGraphOptionsTab_regexRemove);
removeRegexButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
IWorkbench workbench = PlatformUI.getWorkbench();
MessageDialog dialog = new MessageDialog(workbench.getActiveWorkbenchWindow().getShell(), Messages.SystemTapScriptGraphOptionsTab_removeRegexTitle, null, MessageFormat.format(Messages.SystemTapScriptGraphOptionsTab_removeRegexAsk, regularExpressionCombo.getItem(selectedRegex)), MessageDialog.QUESTION, new String[] { "Yes", "No" }, // $NON-NLS-1$ //$NON-NLS-2$
0);
int result = dialog.open();
if (result == 0) {
// Yes
removeRegex(true);
}
}));
GridLayout twoColumns = new GridLayout(2, false);
Composite regexSummaryComposite = new Composite(parent, SWT.NONE);
regexSummaryComposite.setLayout(twoColumns);
regexSummaryComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Label sampleOutputLabel = new Label(regexSummaryComposite, SWT.NONE);
sampleOutputLabel.setText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputLabel);
sampleOutputLabel.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);
this.sampleOutputText = new Text(regexSummaryComposite, SWT.BORDER);
this.sampleOutputText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
this.sampleOutputText.addModifyListener(sampleOutputListener);
sampleOutputText.setToolTipText(Messages.SystemTapScriptGraphOptionsTab_sampleOutputTooltip);
Composite expressionTableLabels = new Composite(parent, SWT.NONE);
expressionTableLabels.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
expressionTableLabels.setLayout(twoColumns);
Label label = new Label(expressionTableLabels, SWT.NONE);
label.setText(Messages.SystemTapScriptGraphOptionsTab_columnTitle);
label.setAlignment(SWT.LEFT);
Label label2 = new Label(expressionTableLabels, SWT.NONE);
label2.setAlignment(SWT.LEFT);
label2.setText(Messages.SystemTapScriptGraphOptionsTab_extractedValueLabel);
ScrolledComposite regexTextScrolledComposite = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.BORDER);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
data.heightHint = 200;
regexTextScrolledComposite.setLayoutData(data);
textFieldsComposite = new Composite(regexTextScrolledComposite, SWT.NONE);
textFieldsComposite.setLayout(new GridLayout(4, false));
regexTextScrolledComposite.setContent(textFieldsComposite);
regexTextScrolledComposite.setExpandHorizontal(true);
// To position the column labels properly, add a dummy column and use its children's sizes for reference.
// This is necessary since expressionTableLabels can't share a layout with textFieldsComposite.
textListenersEnabled = false;
addColumn(null);
data = new GridData(SWT.FILL, SWT.FILL, false, false);
data.horizontalIndent = textFieldsComposite.getChildren()[2].getLocation().x;
data.widthHint = textFieldsComposite.getChildren()[2].getSize().x;
label.setLayoutData(data);
label2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
removeColumn(false);
textListenersEnabled = true;
}
use of org.eclipse.jface.dialogs.MessageDialog in project linuxtools by eclipse.
the class NewDockerConnectionPage method onTestConnectionButtonSelection.
/**
* Verifies that the given connection settings work by trying to connect to
* the target Docker daemon
*
* @return
*/
private SelectionListener onTestConnectionButtonSelection() {
return new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent event) {
try {
getWizard().getContainer().run(true, false, monitor -> {
monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.pingTask"), IProgressMonitor.UNKNOWN);
try {
final DockerConnection dockerConnection = getDockerConnection();
dockerConnection.open(false);
dockerConnection.ping();
dockerConnection.close();
// ping succeeded
displaySuccessDialog();
} catch (DockerException e) {
// in Eclipse.org AERI
if (e.getCause() != null) {
displayErrorDialog(e.getCause());
} else {
displayErrorDialog(e);
}
}
});
} catch (InvocationTargetException | InterruptedException o_O) {
Activator.log(o_O);
}
}
private void displaySuccessDialog() {
displayDialog(WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.success"), WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.pingSuccess"), SWT.ICON_INFORMATION, new String[] { WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.ok") });
}
private void displayErrorDialog(final Throwable cause) {
displayDialog(WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.failure"), WizardMessages.getFormattedString(// $NON-NLS-1$
"DockerConnectionPage.pingFailure", cause.getMessage()), SWT.ICON_ERROR, new String[] { WizardMessages.getString(// $NON-NLS-1$
"DockerConnectionPage.ok") });
}
private void displayDialog(final String dialogTitle, final String dialogMessage, final int icon, final String[] buttonLabels) {
Display.getDefault().syncExec(() -> new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), dialogTitle, null, dialogMessage, icon, buttonLabels, 0).open());
}
};
}
use of org.eclipse.jface.dialogs.MessageDialog in project linuxtools by eclipse.
the class STDataViewersExportToCSVDialog method okPressed.
@Override
protected void okPressed() {
File f = new File(outputFile.getText());
if (f.exists()) {
MessageDialog dialog = new MessageDialog(this.getShell(), "Warning: file already exists", null, "File \"" + f.getAbsolutePath() + "\" already exists.\n" + "Overwrite it anyway?", MessageDialog.WARNING, new String[] { "OK", "Cancel" }, 1);
if (dialog.open() > 0) {
return;
}
}
if (isDirty()) {
saveExporterSettings();
}
super.okPressed();
}
use of org.eclipse.jface.dialogs.MessageDialog in project knime-core by knime.
the class WorkflowEditor method promptToSaveOnClose.
/**
* Brings up the Save-Dialog and sets the m_isClosing flag.
* {@inheritDoc}
*/
@Override
public int promptToSaveOnClose() {
/*
* Ideally we would just set the m_isClosing flag and return
* ISaveablePart2.DEFAULT which will bring up a separate dialog. This
* does not work as we have to set the m_isClosing only if the user
* presses YES (no means to figure out what button was pressed when
* eclipse opens the dialog).
*/
if (m_parentEditor != null) {
// ignore closing metanode editors.
return ISaveablePart2.NO;
}
String message = NLS.bind(WorkbenchMessages.EditorManager_saveChangesQuestion, getTitle());
// Show a dialog.
Shell sh = Display.getDefault().getActiveShell();
String[] buttons = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL };
MessageDialog d = new MessageDialog(sh, WorkbenchMessages.Save_Resource, null, message, MessageDialog.QUESTION, buttons, 0);
switch(// returns index in buttons[] array
d.open()) {
case // YES
0:
m_isClosing = true;
return ISaveablePart2.YES;
case // NO
1:
return ISaveablePart2.NO;
default:
// CANCEL button or window 'x'
return ISaveablePart2.CANCEL;
}
}
Aggregations