Search in sources :

Example 81 with MessageDialog

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);
}
Also used : IURIEditorInput(org.eclipse.ui.IURIEditorInput) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SaveAsDialog(org.eclipse.ui.dialogs.SaveAsDialog) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) IFileEditorInput(org.eclipse.ui.IFileEditorInput) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkspace(org.eclipse.core.resources.IWorkspace) IFileStore(org.eclipse.core.filesystem.IFileStore) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 82 with MessageDialog

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;
}
Also used : RowDataSet(org.eclipse.linuxtools.systemtap.graphing.core.datasets.row.RowDataSet) Image(org.eclipse.swt.graphics.Image) CoreException(org.eclipse.core.runtime.CoreException) Table(org.eclipse.swt.widgets.Table) Stack(java.util.Stack) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ExceptionErrorDialog(org.eclipse.linuxtools.systemtap.graphing.ui.widgets.ExceptionErrorDialog) Matcher(java.util.regex.Matcher) ILaunchConfigurationTab(org.eclipse.debug.ui.ILaunchConfigurationTab) GraphFactory(org.eclipse.linuxtools.systemtap.graphing.ui.wizards.graph.GraphFactory) IDEPlugin(org.eclipse.linuxtools.internal.systemtap.ui.ide.IDEPlugin) DataSetFactory(org.eclipse.linuxtools.systemtap.graphing.ui.wizards.dataset.DataSetFactory) IPath(org.eclipse.core.runtime.IPath) AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) Composite(org.eclipse.swt.widgets.Composite) GraphData(org.eclipse.linuxtools.systemtap.graphing.core.structures.GraphData) AbstractUIPlugin(org.eclipse.ui.plugin.AbstractUIPlugin) GridData(org.eclipse.swt.layout.GridData) LinkedList(java.util.LinkedList) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) TableItem(org.eclipse.swt.widgets.TableItem) Text(org.eclipse.swt.widgets.Text) PatternSyntaxException(java.util.regex.PatternSyntaxException) IDataSetParser(org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSetParser) Combo(org.eclipse.swt.widgets.Combo) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) IDataSet(org.eclipse.linuxtools.systemtap.graphing.core.datasets.IDataSet) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Group(org.eclipse.swt.widgets.Group) SelectGraphAndSeriesWizard(org.eclipse.linuxtools.systemtap.graphing.ui.wizards.graph.SelectGraphAndSeriesWizard) IFilteredDataSet(org.eclipse.linuxtools.systemtap.graphing.core.datasets.IFilteredDataSet) List(java.util.List) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ModifyListener(org.eclipse.swt.events.ModifyListener) SWT(org.eclipse.swt.SWT) Entry(java.util.Map.Entry) IWorkbench(org.eclipse.ui.IWorkbench) Pattern(java.util.regex.Pattern) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) LineParser(org.eclipse.linuxtools.systemtap.graphing.core.datasets.row.LineParser) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) LinkedList(java.util.LinkedList) Stack(java.util.Stack) IWorkbench(org.eclipse.ui.IWorkbench) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 83 with MessageDialog

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());
        }
    };
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 84 with MessageDialog

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();
}
Also used : MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 85 with MessageDialog

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;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Aggregations

MessageDialog (org.eclipse.jface.dialogs.MessageDialog)129 Shell (org.eclipse.swt.widgets.Shell)27 CoreException (org.eclipse.core.runtime.CoreException)16 IPath (org.eclipse.core.runtime.IPath)14 File (java.io.File)10 ArrayList (java.util.ArrayList)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 Composite (org.eclipse.swt.widgets.Composite)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 Point (org.eclipse.swt.graphics.Point)7 IOException (java.io.IOException)6 IFile (org.eclipse.core.resources.IFile)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 List (java.util.List)5 IStatus (org.eclipse.core.runtime.IStatus)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)5 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)5 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 Path (org.eclipse.core.runtime.Path)4