Search in sources :

Example 16 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project linuxtools by eclipse.

the class RunScriptHandler method executeAction.

private void executeAction(ExecutionEvent event) throws ExecutionException {
    final boolean local = getRunLocal();
    findTargetEditor(event);
    findFilePath();
    tryEditorSave(event);
    if (!local) {
        prepareNonLocalScript();
    }
    final String[] script = buildStandardScript();
    final String[] envVars = EnvironmentVariablesPreferencePage.getEnvironmentVariables();
    Display.getDefault().asyncExec(() -> {
        String name = getConsoleName();
        if (ScriptConsole.instanceIsRunning(name)) {
            MessageDialog dialog = new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.RunScriptHandler_AlreadyRunningDialogTitle, null, MessageFormat.format(Messages.RunScriptHandler_AlreadyRunningDialogMessage, fileName), MessageDialog.QUESTION, new String[] { "Yes", "No" }, // $NON-NLS-1$ //$NON-NLS-2$
            0);
            if (dialog.open() != Window.OK) {
                if (launch != null) {
                    launch.forceRemove();
                }
                return;
            }
        }
        final ScriptConsole console = ScriptConsole.getInstance(name);
        if (!local) {
            console.run(script, envVars, remoteOptions, new StapErrorParser());
        } else {
            console.runLocally(script, envVars, new StapErrorParser(), getProject());
        }
        scriptConsoleInitialized(console);
    });
}
Also used : ScriptConsole(org.eclipse.linuxtools.systemtap.ui.consolelog.structures.ScriptConsole) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) StapErrorParser(org.eclipse.linuxtools.internal.systemtap.ui.ide.structures.StapErrorParser)

Example 17 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project linuxtools by eclipse.

the class EditDockerConnectionPage 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.close();
                        // ping succeeded
                        displaySuccessDialog();
                    } catch (DockerException e) {
                        // only log if there's an underlying cause.
                        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 : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) 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 18 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project knime-core by knime.

the class GUIWorkflowLoadHelper method shouldLoadFutureVersionWorkflow.

/**
 * Called from {@link #getUnknownKNIMEVersionLoadPolicy(LoadVersion, Version, boolean)} when loading a
 * workflow created by a future version of KNIME AP.
 */
private UnknownKNIMEVersionLoadPolicy shouldLoadFutureVersionWorkflow(final LoadVersion workflowKNIMEVersion, final Version createdByKNIMEVersion, final boolean isNightlyBuild) {
    StringBuilder e = new StringBuilder("Your version of KNIME Analytics Platform (");
    e.append(CURRENT_VERSION);
    e.append(") version does not support reading workflows created by a newer release");
    e.append(" of KNIME Analytics Platform (");
    e.append(createdByKNIMEVersion);
    if (isNightlyBuild) {
        e.append("-nightly");
    }
    e.append(").\n\n");
    e.append("You should upgrade to the latest version of KNIME Analytics Platform to open this workflow.\n\n");
    e.append(LOAD_FUTURE_FLOW_TEXT);
    String cancel = "&Cancel";
    String loadAnyway = "&Load Anyway";
    final String[] labels = new String[] { cancel, loadAnyway };
    final AtomicReference<UnknownKNIMEVersionLoadPolicy> result = new AtomicReference<>(UnknownKNIMEVersionLoadPolicy.Abort);
    m_display.syncExec(new Runnable() {

        @Override
        public void run() {
            MessageDialog dialog = new MessageDialog(m_display.getActiveShell(), "Workflow version not supported by KNIME Analytics Platform version", null, e.toString(), MessageDialog.WARNING, labels, 0);
            switch(dialog.open()) {
                // 0 button: Cancel
                case 0:
                case // cancel by 'esc'
                SWT.DEFAULT:
                    result.set(UnknownKNIMEVersionLoadPolicy.Abort);
                    break;
                default:
                    result.set(UnknownKNIMEVersionLoadPolicy.Try);
            }
        }
    });
    return result.get();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 19 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project knime-core by knime.

the class WorkflowEditor method openQuestionDialogWhenLoadingWorkflowWithAutoSaveCopy.

/**
 * Opens dialog to ask user for action when auto-save copy is found. Return values:
 * <ul>
 * <li>0: Open Copy</li>
 * <li>1: Open Original</li>
 * <li>any other value: Cancel</li>
 * </ul>
 * @param workflowName to print in message
 * @param restoredPath the path where the workflow will be restored to.
 * @return as above...
 */
private int openQuestionDialogWhenLoadingWorkflowWithAutoSaveCopy(final String workflowName, final String restoredPath) {
    String[] buttons = new String[] { "Open Auto-Save Co&py", "Open &Original", "&Cancel" };
    StringBuilder m = new StringBuilder("\"");
    m.append(workflowName).append("\" was not properly closed.\n\n");
    m.append("An auto-saved copy will be restored to \"").append(restoredPath).append("\".\n");
    Shell sh = Display.getDefault().getActiveShell();
    MessageDialog d = new MessageDialog(sh, "Detected auto-save copy", null, m.toString(), MessageDialog.QUESTION, buttons, 0);
    return d.open();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 20 with MessageDialog

use of org.eclipse.jface.dialogs.MessageDialog in project knime-core by knime.

the class WorkflowEditor method saveBackToServer.

private void saveBackToServer() {
    if (m_parentEditor != null) {
        // parent does it if this is a metanode editor
        m_parentEditor.saveBackToServer();
        return;
    }
    assert m_origRemoteLocation != null : "No remote workflow";
    AbstractExplorerFileStore remoteStore = ExplorerFileSystem.INSTANCE.getStore(m_origRemoteLocation);
    AbstractExplorerFileInfo fetchInfo = remoteStore.fetchInfo();
    if (fetchInfo.exists()) {
        if (!fetchInfo.isModifiable()) {
            MessageDialog.openError(getSite().getShell(), "Workflow not writable", "You don't have permissions to overwrite the workflow. Use \"Save As...\" in order to save it to " + "a different location.");
            return;
        }
        boolean snapshotSupported = remoteStore.getContentProvider().supportsSnapshots();
        final AtomicReference<SnapshotPanel> snapshotPanel = new AtomicReference<SnapshotPanel>(null);
        MessageDialog dlg = new MessageDialog(getSite().getShell(), "Overwrite on server?", null, "The workflow\n\n\t" + remoteStore.getMountIDWithFullPath() + "\n\nalready exists on the server. Do you want to overwrite it?\n", MessageDialog.QUESTION, new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL }, 1) {

            /**
             * {@inheritDoc}
             */
            @Override
            protected Control createCustomArea(final Composite parent) {
                if (snapshotSupported) {
                    snapshotPanel.set(new SnapshotPanel(parent, SWT.NONE));
                    snapshotPanel.get().setEnabled(true);
                    return snapshotPanel.get();
                } else {
                    return null;
                }
            }
        };
        int dlgResult = dlg.open();
        if (dlgResult != 1) {
            return;
        }
        if ((snapshotPanel.get() != null) && (snapshotPanel.get().createSnapshot())) {
            try {
                ((RemoteExplorerFileStore) remoteStore).createSnapshot(snapshotPanel.get().getComment());
            } catch (CoreException e) {
                String msg = "Unable to create snapshot before overwriting the workflow:\n" + e.getMessage() + "\n\nUpload was canceled.";
                LOGGER.error("Unable to create snapshot before overwriting the workflow: " + e.getMessage() + " Upload was canceled.", e);
                MessageDialog.openError(getSite().getShell(), "Server Error", msg);
                return;
            }
        }
    } else if (!remoteStore.getParent().fetchInfo().isModifiable()) {
        MessageDialog.openError(getSite().getShell(), "Workflow not writable", "You don't have permissions to write into the workflow's parent folder. Use \"Save As...\" in order to" + " save it to a different location.");
        return;
    }
    // selected a remote location: save + upload
    if (isDirty()) {
        saveTo(m_fileResource, new NullProgressMonitor(), true, null);
    }
    AbstractExplorerFileStore localFS = getFileStore(m_fileResource);
    if ((localFS == null) || !(localFS instanceof LocalExplorerFileStore)) {
        LOGGER.error("Unable to resolve current workflow location. Workflow not uploaded!");
        return;
    }
    try {
        m_workflowCanBeDeleted.acquire();
        remoteStore.getContentProvider().performUploadAsync((LocalExplorerFileStore) localFS, (RemoteExplorerFileStore) remoteStore, /*deleteSource=*/
        false, false, t -> m_workflowCanBeDeleted.release());
    } catch (CoreException | InterruptedException e) {
        String msg = "Failed to upload the workflow to its remote location\n(" + e.getMessage() + ")";
        LOGGER.error(msg, e);
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Upload failed.", msg);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Composite(org.eclipse.swt.widgets.Composite) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) SnapshotPanel(org.knime.workbench.explorer.view.dialogs.SnapshotPanel) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) CoreException(org.eclipse.core.runtime.CoreException) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) AbstractExplorerFileInfo(org.knime.workbench.explorer.filesystem.AbstractExplorerFileInfo) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) RemoteExplorerFileStore(org.knime.workbench.explorer.filesystem.RemoteExplorerFileStore)

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