Example usage for org.eclipse.jface.dialogs MessageDialog ERROR

List of usage examples for org.eclipse.jface.dialogs MessageDialog ERROR

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs MessageDialog ERROR.

Prototype

int ERROR

To view the source code for org.eclipse.jface.dialogs MessageDialog ERROR.

Click Source Link

Document

Constant for the error image, or a simple dialog with the error image and a single OK button (value 1).

Usage

From source file:net.sf.jmoney.ofx.OfxImporter.java

License:Open Source License

public void importFile(File file) {
    DatastoreManager sessionManager = (DatastoreManager) window.getActivePage().getInput();
    if (sessionManager == null) {
        MessageDialog waitDialog = new MessageDialog(window.getShell(), "Disabled Action Selected", null, // accept the default window icon
                "You cannot import data into an accounting session unless you have a session open.  You must first open a session or create a new session.",
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();//  w  w  w. j av  a2  s  . c o m
        return;
    }

    try {
        /*
         * Create a transaction to be used to import the entries.  This allows the entries to
         * be more efficiently written to the back-end datastore and it also groups
         * the entire import as a single change for undo/redo purposes.
         */
        TransactionManager transactionManager = new TransactionManager(sessionManager);

        BufferedReader buffer = null;
        buffer = new BufferedReader(new FileReader(file));

        SimpleDOMParser parser = new SimpleDOMParser();
        SimpleElement rootElement = null;
        rootElement = parser.parse(buffer);

        //         FileWriter fw = new FileWriter(new File("c:\\xml.xml"));
        //         String xml = rootElement.toXMLString(0);
        //         fw.append(xml);
        //         fw.close();

        Session session = transactionManager.getSession();

        Session sessionOutsideTransaction = sessionManager.getSession();

        SimpleElement statementResultElement = rootElement.getDescendant("BANKMSGSRSV1", "STMTTRNRS", "STMTRS");
        if (statementResultElement != null) {
            importBankStatement(transactionManager, rootElement, session, sessionOutsideTransaction,
                    statementResultElement, false);
        } else {
            statementResultElement = rootElement.getDescendant("CREDITCARDMSGSRSV1", "CCSTMTTRNRS", "CCSTMTRS");
            if (statementResultElement != null) {
                importBankStatement(transactionManager, rootElement, session, sessionOutsideTransaction,
                        statementResultElement, true);
            } else {
                statementResultElement = rootElement.getDescendant("INVSTMTMSGSRSV1", "INVSTMTTRNRS",
                        "INVSTMTRS");
                if (statementResultElement != null) {
                    importStockStatement(transactionManager, rootElement, session, sessionOutsideTransaction,
                            statementResultElement);
                } else {
                    MessageDialog.openWarning(window.getShell(), "OFX file not imported",
                            MessageFormat.format(
                                    "{0} did not contain expected nodes for either a bank or a stock account.",
                                    file.getName()));
                    return;
                }
            }
        }

        /*
         * All entries have been imported and all the properties
         * have been set and should be in a valid state, so we
         * can now commit the imported entries to the datastore.
         */
        if (transactionManager.hasChanges()) {
            String transactionDescription = MessageFormat.format("Import {0}", file.getName());
            transactionManager.commit(transactionDescription);

            StringBuffer combined = new StringBuffer();
            combined.append(file.getName());
            combined.append(" was successfully imported. ");
            MessageDialog.openInformation(window.getShell(), "OFX file imported", combined.toString());
        } else {
            MessageDialog.openWarning(window.getShell(), "OFX file not imported",
                    MessageFormat.format(
                            "{0} was not imported because all the data in it had already been imported.",
                            file.getName()));
        }
    } catch (IOException e) {
        MessageDialog.openError(window.getShell(), "Unable to read OFX file", e.getLocalizedMessage());
    } catch (TagNotFoundException e) {
        MessageDialog.openError(window.getShell(), "Unable to read OFX file", e.getLocalizedMessage());
    }
}

From source file:net.sf.jmoney.qif.wizards.QifExportWizard.java

License:Open Source License

/**
 * We will cache window object in order to be able to provide parent shell
 * for the message dialog./*from  w ww  .  j av a 2  s.  c o m*/
 */
public void init(IWorkbench workbench, IStructuredSelection selection) {
    this.window = workbench.getActiveWorkbenchWindow();

    // Original JMoney disabled the export menu items when no
    // session was open.  I don't know how to do that in Eclipse,
    // so we display a message instead.
    DatastoreManager sessionManager = (DatastoreManager) window.getActivePage().getInput();
    if (sessionManager == null) {
        MessageDialog waitDialog = new MessageDialog(window.getShell(), "Disabled Action Selected", null, // accept the default window icon
                "You cannot export data unless you have a session open.  You must first open a session.",
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();
        return;
    }

    mainPage = new QifExportWizardPage(window);
    addPage(mainPage);
}

From source file:net.sf.jmoney.serializeddatastore.SerializedDatastorePlugin.java

License:Open Source License

/**
 * Check that we have a current session and that the session
 * was created by this plug-in.  If not, display an appropriate
 * message to the user indicating that the user operation
 * is not available and giving the reasons why the user
 * operation is not available./*from   ww w .ja v  a 2 s.  c om*/
 * @param window
 *  
 * @return true if the current session was created by this
 *          plug-in, false if no session is open
 *          or if the current session was created by
 *          another plug-in that also implements a datastore.
 */
public static boolean checkSessionImplementation(DatastoreManager datastoreManager, IWorkbenchWindow window) {
    if (datastoreManager == null) {
        MessageDialog dialog = new MessageDialog(window.getShell(),
                Messages.SerializedDatastorePlugin_MessageMenu, null, // accept the default window icon
                Messages.SerializedDatastorePlugin_MessageNoSession, MessageDialog.ERROR,
                new String[] { IDialogConstants.OK_LABEL }, 0);
        dialog.open();
        return false;
    } else if (datastoreManager instanceof SessionManager) {
        return true;
    } else {
        MessageDialog dialog = new MessageDialog(window.getShell(),
                Messages.SerializedDatastorePlugin_MessageMenu, null, // accept the default window icon
                Messages.SerializedDatastorePlugin_SaveProblem, MessageDialog.ERROR,
                new String[] { IDialogConstants.OK_LABEL }, 0);
        dialog.open();
        return false;
    }
}

From source file:net.sourceforge.sqlexplorer.dbproduct.ConnectionJob.java

License:Open Source License

/**
 * Prompts the user for a new username/password to attempt login with; if the dialog is
 * cancelled then this.user is set to null.
 * @param message//from   w w  w. j  av a 2s.  c  o m
 */
private void promptForPassword(final String message) {
    final Shell shell = SQLExplorerPlugin.getDefault().getSite().getShell();

    // Switch to the UI thread to run the password dialog, but run it synchronously so we
    //   wait for it to complete
    shell.getDisplay().syncExec(new Runnable() {
        public void run() {
            if (message != null) {
                String title = Messages.getString("Progress.Connection.Title") + ' ' + alias.getName();
                if (user != null && !alias.hasNoUserName())
                    title += '/' + user.getUserName();
                if (alias.hasNoUserName()) {
                    MessageDialog dlg = new MessageDialog(shell, title, null,
                            Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message,
                            MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
                    dlg.open();
                    cancelled = true;
                    return;
                } else {
                    MessageDialog dlg = new MessageDialog(shell, title, null,
                            Messages.getString("Progress.Connection.ErrorMessage_Part1") + "\n\n" + message
                                    + "\n\n" + Messages.getString("Progress.Connection.ErrorMessage_Part2"),
                            MessageDialog.ERROR,
                            new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
                    boolean retry = dlg.open() == 0;
                    if (!retry) {
                        cancelled = true;
                        return;
                    }
                }
            }

            Shell shell = Display.getCurrent().getActiveShell();
            PasswordConnDlg dlg = new PasswordConnDlg(shell, user.getAlias(), user);
            if (dlg.open() != Window.OK) {
                cancelled = true;
                return;
            }

            // Create a new user and add it to the alias
            User userTmp = new User(dlg.getUserName(), dlg.getPassword());
            userTmp.setAutoCommit(dlg.getAutoCommit());
            userTmp.setCommitOnClose(dlg.getCommitOnClose());
            user = alias.addUser(userTmp);
        }
    });
}

From source file:net.sourceforge.texlipse.properties.TexlipseProperties.java

License:Open Source License

/**
 * Saves the project properties to a file.
 * /*  w w w  .  j a v a  2  s . co  m*/
 * @param project current project
 */
public static void saveProjectProperties(IProject project) {

    IFile settingsFile = project.getFile(LATEX_PROJECT_SETTINGS_FILE);

    // check if we can write to the properties file
    if (settingsFile.isReadOnly()) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        workbench.getDisplay().asyncExec(new Runnable() {
            public void run() {
                IWorkbench workbench = PlatformUI.getWorkbench();
                // show an error message is the file is not writable
                MessageDialog dialog = new MessageDialog(workbench.getActiveWorkbenchWindow().getShell(),
                        TexlipsePlugin.getResourceString("projectSettingsReadOnlyTitle"), null,
                        TexlipsePlugin.getResourceString("projectSettingsReadOnly"), MessageDialog.ERROR,
                        new String[] { IDialogConstants.OK_LABEL }, 0);
                dialog.open();
            }
        });
        return;
    }

    Properties prop = new Properties();

    prop.setProperty(MAINFILE_PROPERTY, getProjectProperty(project, MAINFILE_PROPERTY));
    prop.setProperty(OUTPUTFILE_PROPERTY, getProjectProperty(project, OUTPUTFILE_PROPERTY));
    prop.setProperty(SOURCE_DIR_PROPERTY, getProjectProperty(project, SOURCE_DIR_PROPERTY));
    prop.setProperty(OUTPUT_DIR_PROPERTY, getProjectProperty(project, OUTPUT_DIR_PROPERTY));
    prop.setProperty(TEMP_DIR_PROPERTY, getProjectProperty(project, TEMP_DIR_PROPERTY));
    prop.setProperty(BIBREF_DIR_PROPERTY, getProjectProperty(project, BIBREF_DIR_PROPERTY));
    prop.setProperty(BUILDER_NUMBER, getProjectProperty(project, BUILDER_NUMBER));
    prop.setProperty(OUTPUT_FORMAT, getProjectProperty(project, OUTPUT_FORMAT));
    prop.setProperty(MARK_TEMP_DERIVED_PROPERTY, getProjectProperty(project, MARK_TEMP_DERIVED_PROPERTY));
    prop.setProperty(MARK_OUTPUT_DERIVED_PROPERTY, getProjectProperty(project, MARK_OUTPUT_DERIVED_PROPERTY));
    prop.setProperty(LANGUAGE_PROPERTY, getProjectProperty(project, LANGUAGE_PROPERTY));
    prop.setProperty(MAKEINDEX_STYLEFILE_PROPERTY, getProjectProperty(project, MAKEINDEX_STYLEFILE_PROPERTY));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        prop.store(baos, "TeXlipse project settings");
    } catch (IOException e) {
    }

    NullProgressMonitor mon = new NullProgressMonitor();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    try {

        if (settingsFile.exists()) {
            settingsFile.setContents(bais, true, false, mon);
        } else {
            settingsFile.create(bais, true, mon);
        }

    } catch (CoreException e) {
        TexlipsePlugin.log("Saving project property file", e);
    }
}

From source file:org.apache.directory.studio.common.ui.CommonUIUtils.java

License:Apache License

/**
 * Opens an Error {@link MessageDialog} with the given title and message.
 *
 * @param title the title/*w w w. j  a  v a  2  s .com*/
 * @param message the message
 */
public static void openErrorDialog(String title, String message) {
    MessageDialog dialog = new MessageDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            title, null, message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL },
            MessageDialog.OK);
    dialog.open();
}

From source file:org.apache.directory.studio.connection.ui.PasswordsKeyStoreManagerUtils.java

License:Apache License

/**
 * Asks the user to load the keystore./*from w ww .  j  av a 2s. c  o  m*/
 *
 * @return <code>true</code> if the keystore was loaded,
 *         <code>false</code> if not.
 */
public static boolean askUserToLoadKeystore() {
    final boolean[] keystoreLoaded = new boolean[1];
    keystoreLoaded[0] = false;

    PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
        while (true) {
            // Getting the shell
            Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();

            // We ask the user for the keystore password
            PasswordDialog passwordDialog = new PasswordDialog(shell,
                    Messages.getString("PasswordsKeyStoreManagerUtils.VerifyMasterPassword"), //$NON-NLS-1$
                    Messages.getString("PasswordsKeyStoreManagerUtils.PleaseEnterMasterPassword"), null); //$NON-NLS-1$

            if (passwordDialog.open() == PasswordDialog.CANCEL) {
                // The user cancelled the action
                keystoreLoaded[0] = false;
                return;
            }

            // Getting the password
            String masterPassword = passwordDialog.getPassword();

            // Checking the password
            Exception checkPasswordException = null;
            try {
                if (ConnectionCorePlugin.getDefault().getPasswordsKeyStoreManager()
                        .checkMasterPassword(masterPassword)) {
                    keystoreLoaded[0] = true;
                    break;
                }
            } catch (KeyStoreException e) {
                checkPasswordException = e;
            }

            // Creating the message
            String message = null;

            if (checkPasswordException == null) {
                message = Messages.getString("PasswordsKeyStoreManagerUtils.MasterPasswordVerificationFailed"); //$NON-NLS-1$
            } else {
                message = Messages.getString(
                        "PasswordsKeyStoreManagerUtils.MasterPasswordVerificationFailedWithException") //$NON-NLS-1$
                        + checkPasswordException.getMessage();
            }

            // We ask the user if he wants to retry to unlock the passwords keystore
            MessageDialog errorDialog = new MessageDialog(shell,
                    Messages.getString("PasswordsKeyStoreManagerUtils.VerifyMasterPasswordFailed"), null, //$NON-NLS-1$
                    message, MessageDialog.ERROR,
                    new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.CANCEL_LABEL }, 0);

            if (errorDialog.open() == MessageDialog.CANCEL) {
                // The user cancelled the action
                keystoreLoaded[0] = false;
                return;
            }
        }
    });

    return keystoreLoaded[0];
}

From source file:org.apache.directory.studio.connection.ui.preferences.PasswordsKeystorePreferencePage.java

License:Apache License

/**
 * Disables the passwords keystore.//from w  ww .j av  a2  s.c o m
 *
 * @return <code>true</code> if the passwords keystore was successfully disabled,
 *         <code>false</code> if not.
 */
private boolean disablePasswordsKeystore() {
    // Asking the user if he wants to keep its connections passwords
    MessageDialog keepConnectionsPasswordsDialog = new MessageDialog(enableKeystoreCheckbox.getShell(),
            Messages.getString("PasswordsKeystorePreferencePage.KeepConnectionsPasswords"), //$NON-NLS-1$
            null, Messages.getString("PasswordsKeystorePreferencePage.DoYouWantToKeepYourConnectionsPasswords"), //$NON-NLS-1$
            MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL,
                    IDialogConstants.CANCEL_LABEL },
            0);
    int keepConnectionsPasswordsValue = keepConnectionsPasswordsDialog.open();

    if (keepConnectionsPasswordsValue == 1) {
        // The user chose NOT to keep the connections passwords
        connectionsPasswordsBackup.clear();
        passwordsKeyStoreManager.deleteKeystoreFile();
        return true;
    } else if (keepConnectionsPasswordsValue == 0) {
        // The user chose to keep the connections passwords
        connectionsPasswordsBackup.clear();

        while (true) {
            // We ask the user for the keystore password
            PasswordDialog passwordDialog = new PasswordDialog(enableKeystoreCheckbox.getShell(),
                    Messages.getString("PasswordsKeystorePreferencePage.VerifyMasterPassword"), //$NON-NLS-1$
                    Messages.getString("PasswordsKeystorePreferencePage.PleaseEnterYourMasterPassword"), //$NON-NLS-1$
                    null);

            if (passwordDialog.open() == PasswordDialog.CANCEL) {
                // The user cancelled the action
                return false;
            }

            // Getting the password
            String password = passwordDialog.getPassword();

            // Checking the password
            Exception checkPasswordException = null;
            try {
                if (passwordsKeyStoreManager.checkMasterPassword(password)) {
                    break;
                }
            } catch (KeyStoreException e) {
                checkPasswordException = e;
            }

            // Creating the message
            String message = null;

            if (checkPasswordException == null) {
                message = Messages
                        .getString("PasswordsKeystorePreferencePage.MasterPasswordVerificationFailed"); //$NON-NLS-1$
            } else {
                message = Messages.getString(
                        "PasswordsKeystorePreferencePage.MasterPasswordVerificationFailedWithException") //$NON-NLS-1$
                        + checkPasswordException.getMessage();
            }

            // We ask the user if he wants to retry to unlock the passwords keystore
            MessageDialog errorDialog = new MessageDialog(enableKeystoreCheckbox.getShell(),
                    Messages.getString("PasswordsKeystorePreferencePage.VerifyMasterPasswordFailed"), null, //$NON-NLS-1$
                    message, MessageDialog.ERROR, new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.CANCEL_LABEL }, 0);

            if (errorDialog.open() == MessageDialog.CANCEL) {
                // The user cancelled the action
                return false;
            }
        }

        // Getting the connection IDs having their passwords saved in the keystore
        String[] connectionIds = passwordsKeyStoreManager.getConnectionIds();

        if (connectionIds != null) {
            // Adding the passwords to the backup map
            for (String connectionId : connectionIds) {
                String password = passwordsKeyStoreManager.getConnectionPassword(connectionId);

                if (password != null) {
                    connectionsPasswordsBackup.put(connectionId, password);
                }
            }
        }

        passwordsKeyStoreManager.deleteKeystoreFile();

        return true;
    } else {
        // The user cancelled the action
        return false;
    }
}

From source file:org.apache.directory.studio.connection.ui.preferences.PasswordsKeystorePreferencePage.java

License:Apache License

/**
 * Changes the master password./*w w w  . j a  va2  s . c o  m*/
 *
 * @return <code>true</code> if the master password was successfully changed,
 *         <code>false</code> if not.
 */
private void changeMasterPassword() {
    String newMasterPassword = null;

    while (true) {
        // We ask the user to reset his master password
        ResetPasswordDialog resetPasswordDialog = new ResetPasswordDialog(changeMasterPasswordButton.getShell(),
                StringUtils.EMPTY, null, null); //$NON-NLS-1$

        if (resetPasswordDialog.open() != ResetPasswordDialog.OK) {
            // The user cancelled the action
            return;
        }

        // Checking the password
        Exception checkPasswordException = null;
        try {
            if (passwordsKeyStoreManager.checkMasterPassword(resetPasswordDialog.getCurrentPassword())) {
                newMasterPassword = resetPasswordDialog.getNewPassword();
                break;
            }
        } catch (KeyStoreException e) {
            checkPasswordException = e;
        }

        // Creating the message
        String message = null;

        if (checkPasswordException == null) {
            message = Messages.getString("PasswordsKeystorePreferencePage.MasterPasswordVerificationFailed"); //$NON-NLS-1$
        } else {
            message = Messages
                    .getString("PasswordsKeystorePreferencePage.MasterPasswordVerificationFailedWithException") //$NON-NLS-1$
                    + checkPasswordException.getMessage();
        }

        // We ask the user if he wants to retry to unlock the passwords keystore
        MessageDialog errorDialog = new MessageDialog(enableKeystoreCheckbox.getShell(),
                Messages.getString("PasswordsKeystorePreferencePage.VerifyMasterPasswordFailed"), null, message, //$NON-NLS-1$
                MessageDialog.ERROR, new String[] { IDialogConstants.RETRY_LABEL, IDialogConstants.CANCEL_LABEL }, 0);

        if (errorDialog.open() == MessageDialog.CANCEL) {
            // The user cancelled the action
            return;
        }
    }

    if (newMasterPassword != null) {
        try {
            passwordsKeyStoreManager.setMasterPassword(newMasterPassword);
            passwordsKeyStoreManager.save();
        } catch (KeyStoreException e) {
            ConnectionUIPlugin.getDefault().getLog().log(new Status(Status.ERROR,
                    ConnectionUIConstants.PLUGIN_ID, Status.ERROR, "Couldn't save the keystore file.", e)); //$NON-NLS-1$
        }
    }
}

From source file:org.apache.directory.studio.ldapservers.apacheds.CreateConnectionAction.java

License:Apache License

/**
 * {@inheritDoc}//from  w  ww  .  j  av a 2  s  .c om
 */
public void run(IAction action) {
    if (view != null) {
        // Getting the selection
        StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection();
        if ((!selection.isEmpty()) && (selection.size() == 1)) {
            // Getting the server
            LdapServer server = (LdapServer) selection.getFirstElement();

            // Checking that the server is really an ApacheDS 2.0.0 server
            if (!ExtensionUtils.verifyApacheDs200OrPrintError(server, view)) {
                return;
            }

            // Parsing the 'config.ldif' file
            ConfigBean configuration = null;
            try {
                configuration = ApacheDS200LdapServerAdapter.getServerConfiguration(server).getConfigBean();
            } catch (Exception e) {
                String message = Messages.getString("CreateConnectionAction.UnableReadServerConfiguration") //$NON-NLS-1$
                        + "\n\n" //$NON-NLS-1$
                        + Messages.getString("CreateConnectionAction.FollowingErrorOccurred") + e.getMessage(); //$NON-NLS-1$

                reportErrorReadingServerConfiguration(view, message);
                return;
            }

            // Checking if we could read the 'server.xml' file
            if (configuration == null) {
                reportErrorReadingServerConfiguration(view,
                        Messages.getString("CreateConnectionAction.UnableReadServerConfiguration")); //$NON-NLS-1$
                return;
            }

            // Checking is LDAP and/or LDAPS is/are enabled
            if ((ApacheDS200LdapServerAdapter.isEnableLdap(configuration))
                    || (ApacheDS200LdapServerAdapter.isEnableLdaps(configuration))) {
                // Creating the connection using the helper class
                createConnection(server, configuration);
            } else {
                // LDAP and LDAPS protocols are disabled, we report this error to the user
                MessageDialog dialog = new MessageDialog(view.getSite().getShell(),
                        Messages.getString("CreateConnectionAction.UnableCreateConnection"), null, //$NON-NLS-1$
                        Messages.getString("CreateConnectionAction.LDAPAndLDAPSDisabled"), MessageDialog.ERROR, //$NON-NLS-1$
                        new String[] { IDialogConstants.OK_LABEL }, MessageDialog.OK);
                dialog.open();
            }
        }
    }
}