Search in sources :

Example 41 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 42 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 43 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 44 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)44 Shell (org.eclipse.swt.widgets.Shell)13 CoreException (org.eclipse.core.runtime.CoreException)7 File (java.io.File)5 IPath (org.eclipse.core.runtime.IPath)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IFile (org.eclipse.core.resources.IFile)4 Point (org.eclipse.swt.graphics.Point)4 Composite (org.eclipse.swt.widgets.Composite)4 IOException (java.io.IOException)3 HashSet (java.util.HashSet)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 Path (org.eclipse.core.runtime.Path)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 CombinedQueryEditorComposite (com.cubrid.common.ui.query.control.CombinedQueryEditorComposite)2 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 IProject (org.eclipse.core.resources.IProject)2