Example usage for org.eclipse.jface.dialogs IDialogConstants YES_LABEL

List of usage examples for org.eclipse.jface.dialogs IDialogConstants YES_LABEL

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs IDialogConstants YES_LABEL.

Prototype

String YES_LABEL

To view the source code for org.eclipse.jface.dialogs IDialogConstants YES_LABEL.

Click Source Link

Document

The label for yes buttons.

Usage

From source file:org.jboss.tools.windup.ui.internal.wizards.WindupReportExportWizardPage1.java

License:Open Source License

/**
 * Displays a Yes/No question to the user with the specified message and returns the user's response.
 * // w  ww  .  j  a  v  a 2 s  . c  om
 * @param message the question to ask
 * @return <code>true</code> for Yes, and <code>false</code> for No
 */
private boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getContainer().getShell(), Messages.Question, (Image) null,
            message, MessageDialog.NONE, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL },
            0) {

        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    // ensure yes is the default

    return dialog.open() == 0;
}

From source file:org.jkiss.dbeaver.ext.exasol.manager.ExasolConnectionManager.java

License:Apache License

@Override
protected void addObjectModifyActions(List<DBEPersistAction> actionList, ObjectChangeCommand command,
        Map<String, Object> options) {
    ExasolConnection con = command.getObject();

    Map<Object, Object> com = command.getProperties();

    if (com.containsKey("description")) {
        actionList.add(Comment(con));
    }/*from   w ww  . j  a va2 s.  c  o m*/

    // url, username or password have changed
    if (com.containsKey("url") | com.containsKey("userName") | com.containsKey("password")) {
        // possible loss of information - warn
        if ((com.containsKey("url") | com.containsKey("userName")) & !con.getUserName().isEmpty()
                & con.getPassword().isEmpty()) {
            int result = new UITask<Integer>() {
                protected Integer runTask() {
                    ConfirmationDialog dialog = new ConfirmationDialog(UIUtils.getActiveWorkbenchShell(),
                            ExasolMessages.dialog_connection_alter_title, null,
                            ExasolMessages.dialog_connection_alter_message, MessageDialog.CONFIRM,
                            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0,
                            ExasolMessages.dialog_general_continue, false);
                    return dialog.open();
                }
            }.execute();
            if (result != IDialogConstants.YES_ID) {
                throw new IllegalStateException("User abort");
            }
        }
        StringBuilder script = new StringBuilder(
                String.format("ALTER CONNECTION %s ", DBUtils.getQuotedIdentifier(con)));
        script.append(" '" + ExasolUtils.quoteString(con.getConnectionString()) + "' ");
        if (!(con.getUserName().isEmpty() | con.getPassword().isEmpty())) {
            script.append(String.format(" USER '%s' IDENTIFIED BY '%s'",
                    ExasolUtils.quoteString(con.getUserName()), ExasolUtils.quoteString(con.getPassword())));
        }

        actionList.add(new SQLDatabasePersistAction("alter Connection", script.toString()));
    }
}

From source file:org.jkiss.dbeaver.ext.exasol.manager.ExasolSchemaManager.java

License:Apache License

@Override
protected void addObjectDeleteActions(List<DBEPersistAction> actions, ObjectDeleteCommand command,
        Map<String, Object> options) {
    int result = new UITask<Integer>() {
        protected Integer runTask() {
            ConfirmationDialog dialog = new ConfirmationDialog(UIUtils.getActiveWorkbenchShell(),
                    ExasolMessages.dialog_schema_drop_title, null, ExasolMessages.dialog_schema_drop_message,
                    MessageDialog.CONFIRM,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0,
                    ExasolMessages.dialog_general_continue, false);
            return dialog.open();
        }/*ww w.  ja va2  s .co m*/
    }.execute();
    if (result != IDialogConstants.YES_ID) {
        throw new IllegalStateException("User abort");
    }

    actions.add(new SQLDatabasePersistAction("Drop schema",
            "DROP SCHEMA " + DBUtils.getQuotedIdentifier(command.getObject()) + " CASCADE") //$NON-NLS-1$
    );
}

From source file:org.jkiss.dbeaver.ui.actions.navigator.NavigatorHandlerObjectDelete.java

License:Open Source License

private ConfirmResult confirmObjectDelete(final IWorkbenchWindow workbenchWindow, final DBNNode node,
        final boolean viewScript) {
    if (deleteAll != null) {
        return deleteAll ? ConfirmResult.YES : ConfirmResult.NO;
    }//from  ww w .j  a va 2  s. c  o  m
    ResourceBundle bundle = DBeaverActivator.getCoreResourceBundle();
    String objectType = node instanceof DBNLocalFolder ? DBeaverPreferences.CONFIRM_LOCAL_FOLDER_DELETE
            : DBeaverPreferences.CONFIRM_ENTITY_DELETE;
    String titleKey = ConfirmationDialog.RES_CONFIRM_PREFIX + objectType + "_" //$NON-NLS-1$
            + ConfirmationDialog.RES_KEY_TITLE;
    String messageKey = ConfirmationDialog.RES_CONFIRM_PREFIX + objectType + "_" //$NON-NLS-1$
            + ConfirmationDialog.RES_KEY_MESSAGE;

    String nodeTypeName = node.getNodeType();

    MessageDialog dialog = new MessageDialog(workbenchWindow.getShell(),
            UIUtils.formatMessage(bundle.getString(titleKey), nodeTypeName, node.getNodeName()),
            DBeaverIcons.getImage(UIIcon.REJECT),
            UIUtils.formatMessage(bundle.getString(messageKey), nodeTypeName.toLowerCase(), node.getNodeName()),
            MessageDialog.CONFIRM, null, 0) {
        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
            createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
            if (structSelection.size() > 1) {
                createButton(parent, IDialogConstants.YES_TO_ALL_ID, IDialogConstants.YES_TO_ALL_LABEL, false);
                createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
            }
            if (viewScript) {
                createButton(parent, IDialogConstants.DETAILS_ID,
                        CoreMessages.actions_navigator_view_script_button, false);
            }
        }
    };
    int result = dialog.open();
    switch (result) {
    case IDialogConstants.YES_ID:
        return ConfirmResult.YES;
    case IDialogConstants.YES_TO_ALL_ID:
        deleteAll = true;
        return ConfirmResult.YES;
    case IDialogConstants.NO_ID:
        return ConfirmResult.NO;
    case IDialogConstants.CANCEL_ID:
    case -1:
        deleteAll = false;
        return ConfirmResult.NO;
    case IDialogConstants.DETAILS_ID:
        return ConfirmResult.DETAILS;
    default:
        log.warn("Unsupported confirmation dialog result: " + result); //$NON-NLS-1$
        return ConfirmResult.NO;
    }
}

From source file:org.jkiss.dbeaver.ui.dialogs.ConfirmationDialog.java

License:Open Source License

static String[] getButtonLabels(int kind) {
    switch (kind) {
    case ERROR:/* w  w  w.  j a va2  s.  c o  m*/
    case INFORMATION:
    case WARNING:
        return new String[] { IDialogConstants.OK_LABEL };
    case CONFIRM:
        return new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL };
    case QUESTION:
        return new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL };
    case QUESTION_WITH_CANCEL: {
        return new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                IDialogConstants.CANCEL_LABEL };
    }
    default:
        throw new IllegalArgumentException("Illegal value for kind in MessageDialog.open()"); //$NON-NLS-1$
    }
}

From source file:org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.java

License:Open Source License

@Override
public boolean performFinish() {
    // FIXME: move into separate class

    final TuhhCalculation calculation = m_importPage.getCalculation();
    final TuhhReach reach = calculation.getReach();
    final TuhhReachProfileSegment[] segments = m_importPage.getReachProfileSegments();

    final IRiverProfileNetworkCollection profNetworkColl = m_networkModel;
    final IFEDiscretisationModel1d2d discModel = m_discretisationModel;
    final IFlowRelationshipModel flowRelModel = m_flowRelationCollection;

    final List<Feature> discModelAdds = m_discModelAdds;

    // TODO: do not every time create a new network: if an re-import happens
    // - find out if same network already exists... (how?)
    // - ask user to overwrite or not

    /* Set user friendly name and description */
    final IRiverProfileNetwork foundNetwork = findExistingNetwork(profNetworkColl, reach);
    final IRiverProfileNetwork existingNetwork;
    if (foundNetwork == null)
        existingNetwork = null;//from   www . j av a  2 s .c o m
    else {
        final String msg = Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.11", //$NON-NLS-1$
                foundNetwork.getName());
        final MessageDialog messageDialog = new MessageDialog(
                getShell(), getWindowTitle(), null, msg, MessageDialog.QUESTION, new String[] {
                        IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL },
                1);
        final int open = messageDialog.open();
        System.out.println(
                Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.12") + open); //$NON-NLS-1$
        if (open == 2 || open == -1)
            return false;

        if (open == 0)
            existingNetwork = foundNetwork;
        else
            existingNetwork = null; // do create a new network
    }

    /* Do import */
    final ICoreRunnableWithProgress op = new ICoreRunnableWithProgress() {
        @Override
        public IStatus execute(final IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask(Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.4"), //$NON-NLS-1$
                    3);

            try {
                /* Check if its the right calculation and if results are present */
                if (calculation.getCalcMode() != TuhhCalculation.MODE.REIB_KONST)
                    return new Status(IStatus.WARNING, KalypsoModel1D2DPlugin.PLUGIN_ID,
                            Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.5")); //$NON-NLS-1$

                try {
                    /* Import reach into profile collection */
                    monitor.subTask(
                            Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.6")); //$NON-NLS-1$

                    final SortedMap<BigDecimal, IProfileFeature> profilesByStation = doImportNetwork(reach,
                            segments, profNetworkColl, existingNetwork);
                    monitor.worked(1);

                    /* Create 1D-Network */
                    monitor.subTask(
                            Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.7")); //$NON-NLS-1$
                    final SortedMap<BigDecimal, IFE1D2DNode> elementsByStation = doCreate1DNet(reach, segments,
                            discModel, discModelAdds);
                    monitor.worked(1);

                    /* Create 1D-Network parameters (flow relations) */
                    monitor.subTask(
                            Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.8")); //$NON-NLS-1$
                    final IStatus status = doReadResults(calculation, segments, elementsByStation, flowRelModel,
                            profilesByStation);
                    monitor.worked(1);

                    return status;
                } catch (final Exception e) {
                    e.printStackTrace();
                    return StatusUtilities.statusFromThrowable(e,
                            Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.9")); //$NON-NLS-1$
                }
            } catch (final Throwable t) {
                // TODO: remove all added features from terrainModel

                // TODO: remove all added features from discModel

                throw new InvocationTargetException(t);
            } finally {
                monitor.done();
            }
        }
    };

    final IStatus status = RunnableContextHelper.execute(getContainer(), true, false, op);
    if (!status.isOK())
        KalypsoModel1D2DPlugin.getDefault().getLog().log(status);
    ErrorDialog.openError(getShell(), getWindowTitle(),
            Messages.getString("org.kalypso.kalypsomodel1d2d.ui.wizard.ImportWspmWizard.10"), status); //$NON-NLS-1$

    return !status.matches(IStatus.ERROR);
}

From source file:org.kalypso.model.wspm.pdb.ui.internal.wspm.PdbWspmProject.java

License:Open Source License

/**
 * Checks if the data should be save, and asks the user what to do.<br/>
 * Show a 'Yes', 'No', 'Cancel' dialog.// w w  w.  ja v a2  s. c o m
 * 
 * @param If
 *          set to <code>true</code>, the data will be reloaded if the user chooses 'NO'.
 * @return <code>false</code>, if the user cancels the operation.
 */
public boolean askForProjectSave() {
    if (m_provider == null)
        return true;

    final boolean dirty = m_provider.isDirty();
    if (!dirty)
        return true;

    final Shell shell = m_window.getShell();
    final String message = Messages.getString("PdbWspmProject.2"); //$NON-NLS-1$
    final String[] buttonLabels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
            IDialogConstants.CANCEL_LABEL };
    final MessageDialog dialog = new MessageDialog(shell, STR_SAVE_LOCAL_DATA_TITLE, null, message,
            MessageDialog.QUESTION_WITH_CANCEL, buttonLabels, 0);
    final int result = dialog.open();

    if (result == 0) {
        final ICoreRunnableWithProgress operation = new ICoreRunnableWithProgress() {
            @Override
            public IStatus execute(final IProgressMonitor monitor) throws CoreException {
                doSave(monitor);
                return Status.OK_STATUS;
            }
        };

        return busyCursorWhile(operation, STR_SAVE_LOCAL_DATA_TITLE, Messages.getString("PdbWspmProject.3")); //$NON-NLS-1$
    } else if (result == 1)
        return true;
    else if (result == 2 || result == -1)
        return false;

    throw new IllegalStateException();
}

From source file:org.kalypso.model.wspm.tuhh.core.wspwin.WspWinOutputDirGenerator.java

License:Open Source License

private File askForExistence(final File dir) {
    final String message = String.format(Messages.getString("WspWinOutputDirGenerator_1"), dir.getName()); //$NON-NLS-1$
    final String[] labels = new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
            Messages.getString("WspWinOutputDirGenerator_2"), Messages.getString("WspWinOutputDirGenerator_3"), //$NON-NLS-1$//$NON-NLS-2$
            IDialogConstants.CANCEL_LABEL };

    final Shell shell = SWT_AWT_Utilities.findActiveShell();
    final MessageDialog dialog = new MessageDialog(shell, Messages.getString("WspWinOutputDirGenerator_4"), //$NON-NLS-1$
            null, message, MessageDialog.QUESTION, labels, 0);
    switch (SWT_AWT_Utilities.openSwtWindow(dialog)) {
    case 0:/*from www  .  j a  v a2s. c  o m*/
        return dir;

    case 1:
        return null;

    case 2:
        m_askMode = AskMode.ALWAYS;
        return dir;

    case 3:
        m_askMode = AskMode.NEVER;
        return null;

    case 4:
        throw new OperationCanceledException();
    default:
        throw new IllegalStateException();
    }
}

From source file:org.kelvinst.psfimport.ui.importWizards.PsfImportWizardFilesSelectionPage.java

License:Open Source License

/**
 * Displays a Yes/No question to the user with the specified message and
 * returns the user's response./*  w w w  .  j  a va  2 s  . c  o  m*/
 * 
 * @param message
 *            the question to ask
 * @return <code>true</code> for Yes, and <code>false</code> for No
 */
protected boolean queryYesNoQuestion(String message) {
    MessageDialog dialog = new MessageDialog(getContainer().getShell(), "Question", (Image) null, message,
            MessageDialog.NONE, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0) {
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    // ensure yes is the default

    return dialog.open() == 0;
}

From source file:org.larz.dom4.dm.ui.editor.DmXtextEditor.java

License:Open Source License

@Override
protected void performSaveAs(IProgressMonitor progressMonitor) {

    Shell shell = getSite().getShell();/*from   w  w  w. j  a va2 s . c o m*/
    final IEditorInput input = getEditorInput();

    // Customize save as if the file is linked, and it is in the special external link project
    //
    if (input instanceof IFileEditorInput && ((IFileEditorInput) input).getFile().isLinked()
            && ((IFileEditorInput) input).getFile().getProject().getName().equals(AUTOLINK_PROJECT_NAME)) {
        final IEditorInput newInput;
        IDocumentProvider provider = getDocumentProvider();

        FileDialog dialog = new FileDialog(shell, SWT.SAVE);
        IPath oldPath = URIUtil.toPath(((IURIEditorInput) input).getURI());
        if (oldPath != null) {
            dialog.setFileName(oldPath.lastSegment());
            dialog.setFilterPath(oldPath.toOSString());
        }

        dialog.setFilterExtensions(new String[] { "*.dm", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
        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, "File Exists", null,
                    path + " already exists. Do you wish to overwrite? ", MessageDialog.WARNING,
                    new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 1); // 'No' is the default
            if (overwriteDialog.open() != Window.OK) {
                if (progressMonitor != null) {
                    progressMonitor.setCanceled(true);
                    return;
                }
            }
        }

        IFileStore fileStore;
        try {
            fileStore = EFS.getStore(localFile.toURI());
        } catch (CoreException ex) {
            MessageDialog.openError(shell, "Error", "Couldn't write file. " + ex.getMessage());
            return;
        }

        IFile file = getWorkspaceFile(fileStore);
        if (file != null)
            newInput = new FileEditorInput(file);
        else {
            IURIEditorInput uriInput = new FileStoreEditorInput(fileStore);
            java.net.URI uri = uriInput.getURI();
            IFile linkedFile = obtainLink(uri);

            newInput = new FileEditorInput(linkedFile);
        }

        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) {
                MessageDialog.openError(shell, "Error", "Couldn't write file. " + x.getMessage());
            }
        } finally {
            provider.changed(newInput);
            if (success)
                setInput(newInput);
        }

        if (progressMonitor != null)
            progressMonitor.setCanceled(!success);

        return;
    }

    super.performSaveAs(progressMonitor);
}