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

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

Introduction

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

Prototype

int YES_ID

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

Click Source Link

Document

Button id for a "Yes" button (value 2).

Usage

From source file:org.jboss.tools.project.examples.cheatsheet.internal.util.CheatSheetUtil.java

License:Open Source License

private static IFile promptToShowCheatsheets(List<IFile> cheatsheets) {
    IPreferenceStore store = ProjectExamplesActivator.getDefault().getPreferenceStore();
    String key = ProjectExamplesActivator.SHOW_CHEATSHEETS;
    String value = store.getString(key);
    if (MessageDialogWithToggle.ALWAYS.equals(value) && cheatsheets.size() == 1) {
        return cheatsheets.get(0);
    }/*www.  j a  v  a2 s  . c  o m*/
    if (MessageDialogWithToggle.NEVER.equals(value)) {
        return null;
    }
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    if (cheatsheets.size() == 1) {
        String projectName = cheatsheets.get(0).getProject().getName();
        String title = "Found cheatsheet";
        String message = "Do you wish to open the cheatsheet for the '" + projectName + "' project?";
        MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoQuestion(shell, title, message, null,
                false, store, key);
        int result = dialog.getReturnCode();
        if (result == Window.CANCEL || result == SWT.DEFAULT) {
            throw new OperationCanceledException();
        }
        if (dialog.getReturnCode() == IDialogConstants.YES_ID) {
            return cheatsheets.get(0);
        }
    } else {
        int kind = MessageDialog.QUESTION;
        String[] buttonLabels = new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL };
        String title = "Found cheatsheets";
        String message = "Please select the cheatsheet you want to show:";
        MyMessageDialogWithToggle dialog = new MyMessageDialogWithToggle(shell, title, null, message, kind,
                buttonLabels, 0, null, false, cheatsheets);
        dialog.setPrefStore(store);
        dialog.setPrefKey(key);
        dialog.open();
        int result = dialog.getReturnCode();
        if (result == Window.CANCEL || result == SWT.DEFAULT) {
            throw new OperationCanceledException();
        }
        if (dialog.getReturnCode() == IDialogConstants.OK_ID) {
            return dialog.getCheatsheet();
        }
    }
    return null;
}

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));
    }// w  w  w.j  av a 2  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();
        }//from w  ww  .  jav  a2  s .c o 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.datasource.DataSourceHandler.java

License:Open Source License

public static boolean checkAndCloseActiveTransaction(DBPDataSourceContainer container,
        Collection<? extends DBCExecutionContext> contexts) {
    if (container.getDataSource() == null) {
        return true;
    }//from  w  ww  . j a  va2 s  .c  o  m

    Boolean commitTxn = null;
    for (final DBCExecutionContext context : contexts) {
        // First rollback active transaction
        try {
            if (isContextTransactionAffected(context)) {
                if (commitTxn == null) {
                    // Ask for confirmation
                    TransactionCloseConfirmer closeConfirmer = new TransactionCloseConfirmer(
                            container.getName());
                    UIUtils.runInUI(null, closeConfirmer);
                    switch (closeConfirmer.result) {
                    case IDialogConstants.YES_ID:
                        commitTxn = true;
                        break;
                    case IDialogConstants.NO_ID:
                        commitTxn = false;
                        break;
                    default:
                        return false;
                    }
                }
                final boolean commit = commitTxn;
                DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
                    @Override
                    public void run(DBRProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        closeActiveTransaction(monitor, context, commit);
                    }
                });
            }
        } catch (Throwable e) {
            log.warn("Can't rollback active transaction before disconnect", e);
        }
    }
    return true;
}

From source file:org.jkiss.dbeaver.ui.actions.datasource.DataSourceHandler.java

License:Open Source License

public static int checkActiveTransaction(DBCExecutionContext context) {
    // First rollback active transaction
    if (isContextTransactionAffected(context)) {
        // Ask for confirmation
        TransactionCloseConfirmer closeConfirmer = new TransactionCloseConfirmer(
                context.getDataSource().getContainer().getName());
        UIUtils.runInUI(null, closeConfirmer);
        switch (closeConfirmer.result) {
        case IDialogConstants.YES_ID:
            return ISaveablePart2.YES;
        case IDialogConstants.NO_ID:
            return ISaveablePart2.NO;
        default://www.j a  v  a 2s.co m
            return ISaveablePart2.CANCEL;
        }
    }
    return ISaveablePart2.YES;
}

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  www  .j  a  v a 2  s.com
    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.controls.resultset.ResultSetViewer.java

License:Open Source License

@Override
public int promptToSaveOnClose() {
    if (!isDirty()) {
        return ISaveablePart2.YES;
    }//w ww. ja  v  a2 s .co m
    int result = ConfirmationDialog.showConfirmDialog(viewerPanel.getShell(),
            DBeaverPreferences.CONFIRM_RS_EDIT_CLOSE, ConfirmationDialog.QUESTION_WITH_CANCEL);
    if (result == IDialogConstants.YES_ID) {
        return ISaveablePart2.YES;
    } else if (result == IDialogConstants.NO_ID) {
        rejectChanges();
        return ISaveablePart2.NO;
    } else {
        return ISaveablePart2.CANCEL;
    }
}

From source file:org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer.java

License:Open Source License

@Override
public void readAllData() {
    if (!dataReceiver.isHasMoreData()) {
        return;//from  ww  w .  jav  a 2s .  com
    }
    if (ConfirmationDialog.showConfirmDialogEx(viewerPanel.getShell(), DBeaverPreferences.CONFIRM_RS_FETCH_ALL,
            ConfirmationDialog.QUESTION, ConfirmationDialog.WARNING) != IDialogConstants.YES_ID) {
        return;
    }

    DBSDataContainer dataContainer = getDataContainer();
    if (dataContainer != null && !model.isUpdateInProgress() && dataPumpJob == null) {
        dataReceiver.setHasMoreData(false);
        dataReceiver.setNextSegmentRead(true);

        runDataPump(dataContainer, null, model.getRowCount(), -1, curRow == null ? -1 : curRow.getRowNumber(),
                null);
    }
}

From source file:org.jkiss.dbeaver.ui.controls.resultset.spreadsheet.SpreadsheetPresentation.java

License:Open Source License

public void changeSorting(Object columnElement, final int state) {
    if (columnElement == null) {
        columnOrder = columnOrder == SWT.DEFAULT ? SWT.DOWN : (columnOrder == SWT.DOWN ? SWT.UP : SWT.DEFAULT);
        spreadsheet.refreshData(false);//from w ww.  j a  v  a2 s  .c  o m
        spreadsheet.redrawGrid();
        return;
    }
    DBDDataFilter dataFilter = controller.getModel().getDataFilter();
    boolean ctrlPressed = (state & SWT.CTRL) == SWT.CTRL;
    boolean altPressed = (state & SWT.ALT) == SWT.ALT;
    if (ctrlPressed) {
        dataFilter.resetOrderBy();
    }
    DBDAttributeBinding metaColumn = (DBDAttributeBinding) columnElement;
    DBDAttributeConstraint constraint = dataFilter.getConstraint(metaColumn);
    assert constraint != null;
    //int newSort;
    if (constraint.getOrderPosition() == 0) {
        if (ResultSetUtils.isServerSideFiltering(controller) && supportsDataFilter()) {
            if (ConfirmationDialog.showConfirmDialogEx(spreadsheet.getShell(),
                    DBeaverPreferences.CONFIRM_ORDER_RESULTSET, ConfirmationDialog.QUESTION,
                    ConfirmationDialog.WARNING, metaColumn.getName()) != IDialogConstants.YES_ID) {
                return;
            }
        }
        constraint.setOrderPosition(dataFilter.getMaxOrderingPosition() + 1);
        constraint.setOrderDescending(altPressed);
    } else if (!constraint.isOrderDescending()) {
        constraint.setOrderDescending(true);
    } else {
        for (DBDAttributeConstraint con2 : dataFilter.getConstraints()) {
            if (con2.getOrderPosition() > constraint.getOrderPosition()) {
                con2.setOrderPosition(con2.getOrderPosition() - 1);
            }
        }
        constraint.setOrderPosition(0);
        constraint.setOrderDescending(false);
    }

    if (!ResultSetUtils.isServerSideFiltering(controller) || !controller.isHasMoreData()) {
        reorderLocally();
    } else {
        controller.refreshData(null);
    }
}

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

License:Open Source License

public static int open(int kind, int imageKind, Shell parent, String title, String message,
        String toggleMessage, boolean toggleState, String key) {
    DBPPreferenceStore prefStore = DBeaverCore.getGlobalPreferenceStore();
    if (ConfirmationDialog.ALWAYS.equals(prefStore.getString(key))) {
        if (kind == QUESTION || kind == QUESTION_WITH_CANCEL) {
            return IDialogConstants.YES_ID;
        } else {//from   w  w w. ja  v a 2s  .com
            return IDialogConstants.OK_ID;
        }
    } else if (ConfirmationDialog.NEVER.equals(prefStore.getString(key))) {
        if (kind == QUESTION || kind == QUESTION_WITH_CANCEL) {
            return IDialogConstants.NO_ID;
        } else {
            return IDialogConstants.CANCEL_ID;
        }
    }
    ConfirmationDialog dialog = new ConfirmationDialog(
            parent == null ? DBeaverUI.getActiveWorkbenchShell() : parent, title, null, // accept the default window icon
            message, imageKind, getButtonLabels(kind), 0, toggleMessage, toggleState);
    dialog.setPrefStore(new PreferenceStoreDelegate(prefStore));
    dialog.setPrefKey(key);
    return dialog.open();
}