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.groovyMonkey.actions.PasteScriptFromClipboardAction.java

License:Open Source License

private IFile createScriptFile(final IFolder destination, final ScriptMetadata metadata, final String script)
        throws CoreException, IOException {
    final String defaultName = substringAfterLast(metadata.scriptPath(), "/");
    String basename = defaultName;
    final int ix = basename.lastIndexOf(".");
    if (ix > 0)
        basename = basename.substring(0, ix);
    createFolder(destination);/*from   w  w  w . jav a2 s  .  c o  m*/
    final IResource[] members = destination.members(0);
    final Pattern suffix = compile(basename + "(-(\\d+))?\\" + FILE_EXTENSION);
    int maxsuffix = -1;
    for (final IResource resource : members) {
        if (resource instanceof IFile) {
            final IFile file = (IFile) resource;
            final String filename = file.getName();
            final Matcher match = suffix.matcher(filename);
            if (match.matches()) {
                if (file.exists() && file.getName().equals(defaultName)) {
                    final MessageDialog dialog = new MessageDialog(shell(), "Overwrite?", null,
                            "Overwrite existing script: " + file.getName() + " ?", MessageDialog.WARNING,
                            new String[] { "Yes", "No" }, 0);
                    if (dialog.open() == 0) {
                        file.delete(true, null);
                        closeEditor(file);
                        maxsuffix = -1;
                        basename = substringBeforeLast(file.getName(), ".");
                        break;
                    }
                }
                if (match.group(2) == null)
                    maxsuffix = max(maxsuffix, 0);
                else {
                    final int n = Integer.parseInt(match.group(2));
                    maxsuffix = max(maxsuffix, n);
                }
            }
        }
    }
    final String filename = maxsuffix == -1 ? basename + FILE_EXTENSION
            : basename + "-" + (maxsuffix + 1) + FILE_EXTENSION;
    final IFile file = destination.getFile(filename);
    final ByteArrayInputStream stream = new ByteArrayInputStream(script.getBytes());
    file.create(stream, true, null);
    stream.close();
    return file;
}

From source file:net.sf.groovyMonkey.ScriptMetadata.java

License:Open Source License

private String notifyMissingDOMs(final String missingPlugins) {
    if (getCurrent() == null) {
        final String[] returnValue = new String[1];
        final Runnable runnable = new Runnable() {
            public void run() {
                returnValue[0] = notifyMissingDOMs(missingPlugins);
            }/*from  ww  w.  jav a 2s.com*/
        };
        getDefault().syncExec(runnable);
        return returnValue[0];
    }
    final String plural = missingPlugins.indexOf("\n") >= 0 ? "s" : "";
    final String these = isNotBlank(plural) ? "these" : "this";
    final String[] choices = new String[] { "Cancel Script", "Edit Script", "Install Plug-in" + plural };
    final MessageDialog dialog = new MessageDialog(null, "Missing DOM" + plural, null, "The script "
            + file.getName() + " requires " + these + " missing DOM plug-in" + plural + ":\n" + missingPlugins,
            QUESTION, choices, 2);
    final int result = dialog.open();
    final String choice = choices[result];
    return choice;
}

From source file:net.sf.jasperreports.eclipse.ui.util.UIUtils.java

License:Open Source License

/**
 * @return true if yes//from   ww  w. ja va 2  s. c  o m
 */
public static boolean showConfirmation(String title, String message) {
    MessageDialog dialog = new MessageDialog(getShell(), title, null, message, MessageDialog.QUESTION,
            new String[] { Messages.UIUtils_AnswerYes, Messages.UIUtils_AnswerNo }, 0) {

        @Override
        protected void setShellStyle(int newShellStyle) {
            super.setShellStyle(newShellStyle | SWT.SHEET);
        }
    };
    return dialog.open() == 0;
}

From source file:net.sf.jmoney.copier.actions.CutSessionAction.java

License:Open Source License

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI./*from  ww w. j av  a2 s. c om*/
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    DatastoreManager sessionManager = JMoneyPlugin.getDefault().getSessionManager();

    if (sessionManager == null) {
        MessageDialog waitDialog = new MessageDialog(window.getShell(), "Menu item unavailable", null, // accept the default window icon
                "No session is open.  "
                        + "This action is used to copy session data from one session to another.  "
                        + "You must first use this action to save the contents of the current session.  "
                        + "You must then open another session and then select the 'Paste Contents' action.  "
                        + "The contents of the session will then be copied into the new session.",
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();
        return;
    }

    // We call canClose now so that we are sure
    // that we can later close the session without
    // further user input.  If the user does not
    // provide at this time all the information required
    // to close the session then we terminate the operation
    // now.
    if (!sessionManager.canClose(window)) {
        return;
    }

    // Save the session in a static location.
    // The session is left open so that we can
    // later read the data from it.
    CopierPlugin.setSessionManager(sessionManager);

    /*
     * Close this window but leave the session open.
     * 
     * This ensures that the session cannot be closed before
     * it is pasted into the new location.
     */
    // TODO: There is a problem with this.  If the session is
    // never pasted then it is never closed.  Better may be to
    // leave the window open, requiring the user to create a
    // target session in another window, and giving an error if
    // a paste is done after the source session was closed.
    try {
        window.getActivePage().close();
        window.openPage(null);
    } catch (WorkbenchException e) {
        // TODO: Uncomment this when this becomes a handler
        //         throw new ExecutionException("Workbench exception occured while closing window.", e); //$NON-NLS-1$
    }
}

From source file:net.sf.jmoney.copier.actions.PasteContentsAction.java

License:Open Source License

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI./*from   ww  w.j a va 2 s.c om*/
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    DatastoreManager destinationSessionManager = JMoneyPlugin.getDefault().getSessionManager();

    if (destinationSessionManager == null) {
        MessageDialog waitDialog = new MessageDialog(window.getShell(), "Menu item unavailable", null, // accept the default window icon
                "No session is open.  "
                        + "This action is used to copy session data from one session to another.  "
                        + "You must open a new session into which the session contents can be copied.",
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();
        return;
    }

    DatastoreManager sourceSessionManager = CopierPlugin.getSessionManager();
    if (sourceSessionManager == null) {
        MessageDialog waitDialog = new MessageDialog(window.getShell(), "Menu item unavailable", null, // accept the default window icon
                "No session has been cut.  "
                        + "Before using this action, you must first use the 'Cut Session' action "
                        + "while the source session is open.",
                MessageDialog.ERROR, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();
        return;
    }

    // Copy the data across.
    CopierPlugin.getDefault().populateSession(destinationSessionManager.getSession(),
            sourceSessionManager.getSession());

    // Confirm copy.
}

From source file:net.sf.jmoney.entrytable.BaseEntryRowControl.java

License:Open Source License

/**
 * Validate the changes made by the user to this row and, if they are valid,
 * commit them./* w w  w.j a v  a2s.c  o m*/
 * <P>
 * The changes may not be committed for a number of reasons. Perhaps they
 * did not meet the restrictions imposed by a validating listener, or
 * perhaps the user responded to a dialog in a way that indicated that the
 * changes should not be committed.
 * <P>
 * If false is returned then the caller should not move the selection off
 * this row.
 * 
 * @return true if the changes are either valid and were committed or were
 *         discarded by the user, false if the changes were neither committed
 *         nor discarded (and thus remain outstanding)
 */
public boolean commitChanges(String transactionLabel) {
    // If changes have been made then check they are valid and ask
    // the user if the changes should be committed.
    if (transactionManager.hasChanges()) {
        // Validate the transaction.

        // TODO: itemWithError is not actually used. See if there is an
        // easy way of accessing the relevant controls. Otherwise we should
        // delete this.

        try {
            baseValidation(uncommittedEntryData.getEntry().getTransaction());

            // Do any specific processing in derived classes.
            specificValidation();

        } catch (InvalidUserEntryException e) {
            MessageDialog dialog = new MessageDialog(getShell(), Messages.BaseEntryRowControl_ErrorTitle, null, // accept the default window icon
                    e.getLocalizedMessage(), MessageDialog.ERROR,
                    new String[] { Messages.BaseEntryRowControl_Discard, IDialogConstants.CANCEL_LABEL }, 1);
            int result = dialog.open();
            if (result == 0) {
                // Discard

                // TODO: Some of this code is duplicated below.

                transactionManager = new TransactionManager(committedEntryData.getBaseSessionManager());
                Entry entryInTransaction;
                if (committedEntryData.getEntry() == null) {
                    Transaction newTransaction = transactionManager.getSession().createTransaction();
                    entryInTransaction = createNewEntry(newTransaction);
                } else {
                    entryInTransaction = transactionManager.getCopyInTransaction(committedEntryData.getEntry());
                }

                // Update the controls.

                /*
                 * We create a new EntryData object. This is important so
                 * that we start over with the 'fluid' fields and other
                 * stuff. These are reset when we set the input. We reset
                 * the input to the same value to get the 'fluid' fields
                 * reset. We are re-using the objects for the new entry, but
                 * if fields have been set to be not fluid then we must
                 * ensure they are fluid again. Without this calculated
                 * values are not being calculated.
                 */
                uncommittedEntryData = createUncommittedEntryData(entryInTransaction, transactionManager);
                uncommittedEntryData.setIndex(committedEntryData.getIndex());
                uncommittedEntryData.setBalance(committedEntryData.getBalance());

                for (final IPropertyControl<? super T> control : controls.values()) {
                    control.load(uncommittedEntryData);
                }

                this.setInput(uncommittedEntryData);

                return true;
            } else {
                // Cancel the selection change
                if (e.getItemWithError() != null) {
                    e.getItemWithError().setFocus();
                }
                return false;
            }
        }

        // Commit the changes to the transaction
        transactionManager.commit(transactionLabel);

        // Sound the tone
        //         clip.play();

        /*
         * It may be that this was a new entry not previously committed. If
         * so, the committed entry in the EntryData object will be null. In
         * this case we now clear out the controls so that it is ready for
         * the next new transaction. (A new row will have been created for
         * the new entry that we have just committed because the table is
         * listening for new entries).
         * 
         * This listener should also have caused the balance for the new
         * entry row to be updated.
         */
        if (committedEntryData.getEntry() == null) {
            Transaction newTransaction = transactionManager.getSession().createTransaction();
            Entry entryInTransaction = createNewEntry(newTransaction);

            // Update the controls.

            uncommittedEntryData = createUncommittedEntryData(entryInTransaction, transactionManager);
            uncommittedEntryData.setIndex(committedEntryData.getIndex());
            uncommittedEntryData.setBalance(committedEntryData.getBalance());

            // Load all top level controls with this data.
            for (final IPropertyControl<? super T> control : controls.values()) {
                control.load(uncommittedEntryData);
            }
        }
    }

    return true;
}

From source file:net.sf.jmoney.gnucashXML.actions.GnucashXMLExportAction.java

License:Open Source License

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI./*w w w.  jav a 2 s  .c  om*/
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    Session session = JMoneyPlugin.getDefault().getSession();

    // 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.
    if (session == 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 or create a new session.",
                MessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0);
        waitDialog.open();
        return;
    }

    // Display a warning
    // TODO Remove this warning when the problem is resolved 
    MessageBox diag = new MessageBox(window.getShell());
    diag.setText("Warning");
    diag.setMessage(
            "Warning:\nFor this time, the export as a GnuCash file produce a file which can't be imported under GnuCash. The file can only be imported in the current JMoney application.");
    diag.open();

    FileDialog xmlFileChooser = new FileDialog(window.getShell());
    xmlFileChooser.setText(GnucashXMLPlugin.getResourceString("MainFrame.export"));
    xmlFileChooser.setFilterExtensions(new String[] { "*.xml;*.xac" });
    xmlFileChooser.setFilterNames(new String[] { "XML Gnucash Files (*.xml; *.xac)" });
    // TODO: Faucheux - delete Directory 
    xmlFileChooser.setFilterPath("D:\\Documents and Settings\\Administrateur\\Mes documents\\Mes comptes");
    String fileName = xmlFileChooser.open();

    if (fileName != null) {
        GnucashXML export = GnucashXML.getSingleton(window);
        export.export(session, fileName);
    }

}

From source file:net.sf.jmoney.gnucashXML.actions.GnucashXMLImportAction.java

License:Open Source License

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI.//from   w w w .j a  v a  2 s.c om
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    Session session = JMoneyPlugin.getDefault().getSession();

    // 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 (session == 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;
    }

    FileDialog xmlFileChooser = new FileDialog(window.getShell());
    xmlFileChooser.setText(GnucashXMLPlugin.getResourceString("MainFrame.import"));
    xmlFileChooser.setFilterExtensions(new String[] { "*.xml;*.xac" });
    xmlFileChooser.setFilterNames(new String[] { "XML Gnucash Files (*.xml; *.xac)" });
    // TODO: Faucheux - delete Directory 
    xmlFileChooser.setFilterPath("D:\\Documents and Settings\\Administrateur\\Mes documents\\Mes comptes");
    String fileName = xmlFileChooser.open();

    if (fileName != null) {
        File qifFile = new File(fileName);
        GnucashXML gnucashXML = GnucashXML.getSingleton(window);
        gnucashXML.importFile(session, qifFile);
    }

}

From source file:net.sf.jmoney.gnucashXML.wizards.GnucashImportWizard.java

License:Open Source License

public void init(IWorkbench workbench, IStructuredSelection selection) {
    this.window = workbench.getActiveWorkbenchWindow();

    this.session = JMoneyPlugin.getDefault().getSession();

    // 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 (session == 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();//from  www.j a  v  a  2s. c o m
        return;
    }

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

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

License:Open Source License

/**
 * @param window/*from w  w w. j a  v a2 s .  c  o m*/
 * @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;
}