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

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

Introduction

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

Prototype

public MessageDialog(Shell parentShell, String dialogTitle, Image dialogTitleImage, String dialogMessage,
        int dialogImageType, int defaultIndex, String... dialogButtonLabels) 

Source Link

Document

Create a message dialog.

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();/*from   w w w  .  j ava 2s  .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  .ja  va2 s . com
 */
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.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./*  w ww  . j  a  va  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.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 w  ww .j  a  v a2s. 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;
    }
}