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

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

Introduction

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

Prototype

String OK_LABEL

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

Click Source Link

Document

The label for OK buttons.

Usage

From source file:net.sf.jmoney.jdbcdatastore.JDBCDatastorePlugin.java

License:Open Source License

/**
 * @param window/*from   w  ww.  j  ava2  s  . c  om*/
 * @return
 */
public SessionManager readSession(IWorkbenchWindow window) {
    SessionManager result = null;

    // The following lines cannot return a null value because if
    // no value is set then the default value set in
    // the above initializeDefaultPreferences method will be returned.
    String driver = getPreferenceStore().getString("driver");
    String subprotocol = getPreferenceStore().getString("subProtocol");
    String subprotocolData = getPreferenceStore().getString("subProtocolData");

    String url = "jdbc:" + subprotocol + ":" + subprotocolData;

    String user = getPreferenceStore().getString("user");
    String password = getPreferenceStore().getString("password");

    if (getPreferenceStore().getBoolean("promptEachTime")) {
        // TODO: Put up a dialog box so the user can change
        // the connection options for this connection only.
    }

    try {
        Class.forName(driver).newInstance();
    } catch (InstantiationException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    } catch (IllegalAccessException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    } catch (ClassNotFoundException e2) {
        String title = JDBCDatastorePlugin.getResourceString("errorTitle");
        String message = JDBCDatastorePlugin.getResourceString("driverNotFound");
        MessageDialog waitDialog = new MessageDialog(window.getShell(), title, null, // accept the default window icon
                message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();
        return null;
    }

    try {
        result = new SessionManager(url, user, password);
    } catch (SQLException e3) {
        if (e3.getSQLState().equals("08000")) {
            // A connection error which means the database server is probably not running.
            String title = JDBCDatastorePlugin.getResourceString("errorTitle");
            String message = JDBCDatastorePlugin.getResourceString("connectionFailed") + e3.getMessage()
                    + "  Check that the database server is running.";
            MessageDialog waitDialog = new MessageDialog(window.getShell(), title, null, // accept the default window icon
                    message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
            waitDialog.open();
        } else if (e3.getSQLState().equals("S1000")) {
            // The most likely cause of this error state is that the database is not attached.
            String title = JDBCDatastorePlugin.getResourceString("errorTitle");
            String message = e3.getMessage() + " " + JDBCDatastorePlugin.getResourceString("databaseNotFound");
            MessageDialog waitDialog = new MessageDialog(window.getShell(), title, null, // accept the default window icon
                    message, MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
            waitDialog.open();
        } else {
            throw new RuntimeException(e3);
        }
    }

    return result;
}

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();//from  w  ww  . j  a  v  a  2 s. c om
        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.paypal.CsvImportWizard.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 w w .  j a v  a  2  s  .  c  o m*/
 */
public void init(IWorkbench workbench, IStructuredSelection selection) {

    this.window = workbench.getActiveWorkbenchWindow();

    DatastoreManager sessionManager = (DatastoreManager) window.getActivePage().getInput();

    // Original JMoney disabled the import menu items when no
    // session was open. I don't know how to do that in Eclipse,
    // so we display a message instead.
    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.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();
        return;
    }

    /*
     * 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 = new TransactionManager(sessionManager);
    session = transactionManager.getSession();

    /*
     * Find the Paypal account. Currently this assumes that there is
     * only one Paypal account. If you have more than one then you will
     * need to implement some changes, perhaps require the account be
     * selected before the wizard is run, or add a wizard page that asks
     * which of the Paypal accounts is to be used.
     */
    PaypalAccount accountOutside = null;
    for (Iterator<CapitalAccount> iter = sessionManager.getSession().getCapitalAccountIterator(); iter
            .hasNext();) {
        CapitalAccount eachAccount = iter.next();
        if (eachAccount instanceof PaypalAccount) {
            if (accountOutside != null) {
                MessageDialog.openError(window.getShell(), "Problem",
                        "Multiple Paypal accounts.  Don't know which to use.  If you have multiple Paypal accounts, please submit a patch.");
                return;
            }
            accountOutside = (PaypalAccount) eachAccount;
        }
    }

    if (accountOutside == null) {
        MessageDialog.openError(window.getShell(), "Problem", "No Paypal account has been created");
        return;
    }

    paypalAccount = transactionManager.getCopyInTransaction(accountOutside);

    filePage = new CsvImportWizardPage(window);
    addPage(filePage);
}

From source file:net.sf.jmoney.qif.AccountChooser.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    // create OK and Cancel buttons by default
    okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);

    //do this here because setting the text will set enablement on the ok button
    text.setFocus();/*from w  w w . j  ava 2s  .  c om*/
    if (value != null) {
        text.setText(value);
        text.selectAll();
    }
}

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  w w .j av a  2  s . com
 */
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.reconciliation.reconcilePage.NewStatementDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    // create OK and Cancel buttons by default
    okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}

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./*w ww.ja va  2  s.  c  o m*/
 * @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.sf.jmoney.transactionDialog.TransactionDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(Composite parent) {
    createButton(parent, NEW_SPLIT_ID, Messages.TransactionDialog_ButtonTextNewSplit, false);
    createButton(parent, DELETE_SPLIT_ID, Messages.TransactionDialog_ButtonTextDeleteSplit, false);
    createButton(parent, ADJUST_AMOUNT_ID, Messages.TransactionDialog_ButtonTextAdjustAmont, false);
    // create OK and Cancel buttons by default
    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, 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 ww  w. j av  a2s. 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.sqlexplorer.dialogs.FilterStructureDialog.java

License:Open Source License

protected void createButtonsForButtonBar(Composite parent) {

    createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}