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

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

Introduction

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

Prototype

int ERROR

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

Click Source Link

Document

Constant for an error message (value 3).

Usage

From source file:net.sf.jmoney.importer.matcher.PatternMatchingDialog.java

License:Open Source License

/**
 * Sets or clears the error message.//from w w w.  java 2s  .  c o m
 * If not <code>null</code>, the OK button is disabled.
 * 
 * @param errorMessage
 *            the error message, or <code>null</code> to clear
 */
public void updateErrorMessage() {
    String errorMessage = null;

    if (account.isReconcilable()) {
        if (account.getDefaultCategory() == null) {
            errorMessage = "All reconcilable accounts must have a default category set.";
        } else {
            // Check the patterns
            for (MemoPattern pattern : account.getPatternCollection()) {
                if (isMemoPatternValid(pattern) != null) {
                    errorMessage = "There are errors in the patterns table.  Hover over the error image to the left of the row to see details.";
                    break;
                }
            }
        }
    }

    if (errorMessage == null) {
        //         messageArea.clearErrorMessage();    ?????
        messageArea.restoreTitle();
    } else {
        messageArea.updateText(errorMessage, IMessageProvider.ERROR);
    }

    // If called during createDialogArea, the okButton
    // will not have been created yet.
    Button okButton = getButton(IDialogConstants.OK_ID);
    if (okButton != null) {
        okButton.setEnabled(errorMessage == null);
    }
}

From source file:net.sf.jmoney.transactionDialog.TransactionDialog.java

License:Open Source License

/**
 * Sets or clears the error message.//from w  w  w  . j  a va  2  s. c  o m
 * If not <code>null</code>, the OK button is disabled.
 * 
 * @param errorMessage
 *            the error message, or <code>null</code> to clear
 */
public void updateErrorMessage() {
    String errorMessage = null;

    try {
        BaseEntryRowControl.baseValidation(topEntry.getTransaction());

        // No exception was thrown, so transaction is valid.

        // If there are two currencies/commodities involved in
        // the transaction then the exchange rate or conversion cost
        // or net price or whatever is displayed.

        Map<Commodity, Long> amounts = new HashMap<Commodity, Long>();

        for (Entry entry : transaction.getEntryCollection()) {
            Commodity commodity = entry.getCommodityInternal();
            Long previousAmount = amounts.get(commodity);
            if (previousAmount == null) {
                amounts.put(commodity, entry.getAmount());
            } else {
                amounts.put(commodity, entry.getAmount() + previousAmount);
            }
        }

        if (amounts.size() == 2) {
            List<Map.Entry<Commodity, Long>> a = new ArrayList<Map.Entry<Commodity, Long>>(amounts.entrySet());

            Commodity commodity1 = a.get(0).getKey();
            Commodity commodity2 = a.get(1).getKey();
            long amount1 = a.get(0).getValue();
            long amount2 = a.get(1).getValue();

            if (amount1 >= 0 && amount2 >= 0) {
                messageArea.updateText("A net gain has occurred!", IMessageProvider.ERROR);
            } else if (amount1 <= 0 && amount2 <= 0) {
                messageArea.updateText("A net loss has occurred!", IMessageProvider.ERROR);
            } else {
                amount1 = Math.abs(amount1);
                amount2 = Math.abs(amount2);

                long worthOfCommodity1 = amount2 * commodity1.getScaleFactor() / amount1;
                long worthOfCommodity2 = amount1 * commodity2.getScaleFactor() / amount2;

                String message = MessageFormat.format(Messages.TransactionDialog_Message, commodity1.getName(),
                        commodity2.getName(), commodity2.format(worthOfCommodity1),
                        commodity1.format(worthOfCommodity2));
                messageArea.updateText(message, IMessageProvider.INFORMATION);
            }
        } else {
            //            messageArea.clearErrorMessage();    ?????
            messageArea.restoreTitle();
        }
    } catch (InvalidUserEntryException e) {
        errorMessage = e.getLocalizedMessage();
        messageArea.updateText(errorMessage, IMessageProvider.ERROR);
    }

    // If called during createDialogArea, the okButton
    // will not have been created yet.
    Button okButton = this.getButton(IDialogConstants.OK_ID);
    if (okButton != null) {
        okButton.setEnabled(errorMessage == null);
    }
}

From source file:net.tourbook.ui.MessageDialogPage.java

License:Open Source License

@Override
public void setErrorMessage(final String newMessage) {
    super.setErrorMessage(newMessage);
    fMessageRegion.updateText(newMessage, IMessageProvider.ERROR);
}

From source file:net.tourbook.ui.MessageManager.java

License:Open Source License

/**
 * @return Returns the number of error messages
 */// ww w .j  a v a2s .  com
@SuppressWarnings("unchecked")
public int getErrorMessageCount() {

    int errors = 0;

    for (final Enumeration<ControlDecorator> enm = decorators.elements(); enm.hasMoreElements();) {
        final ControlDecorator dec = enm.nextElement();
        final ArrayList<?> allMessages = dec.controlMessages;

        for (final Object object : allMessages) {
            if (object instanceof Message) {
                final Message message = (Message) object;
                if (message.getMessageType() == IMessageProvider.ERROR) {
                    errors++;
                }
            }
        }
    }

    return errors;
}

From source file:net.tourbook.ui.MessageRegion.java

License:Open Source License

/**
 * Show the new message in the message text and update the image. Base the background color on
 * whether or not there are errors.//from w ww  . j  a va 2  s .c  om
 * 
 * @param newMessage
 *            The new value for the message
 * @param newType
 *            One of the IMessageProvider constants. If newType is IMessageProvider.NONE show
 *            the title.
 * @see IMessageProvider
 */
public void updateText(final String newMessage, final int newType) {
    Image newImage = null;
    boolean showingError = false;
    switch (newType) {
    case IMessageProvider.NONE:
        hideRegion();
        return;
    case IMessageProvider.INFORMATION:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_INFO);
        break;
    case IMessageProvider.WARNING:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
        break;
    case IMessageProvider.ERROR:
        newImage = JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
        showingError = true;
        break;
    }

    if (newMessage == null) {//No message so clear the area
        hideRegion();
        return;
    }
    showRegion();
    // Any more updates required
    if (newMessage.equals(messageText.getText()) && newImage == messageImageLabel.getImage()) {
        return;
    }
    messageImageLabel.setImage(newImage);
    messageText.setText(newMessage);
    if (showingError) {
        setMessageColors(JFaceColors.getErrorBackground(messageComposite.getDisplay()));
    } else {
        lastMessageText = newMessage;
        setMessageColors(JFaceColors.getBannerBackground(messageComposite.getDisplay()));
    }

}

From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java

License:Open Source License

private void createFieldListener() {

    _modifyListener = new ModifyListener() {
        @Override/* w w w . j a v  a  2s .  c  om*/
        public void modifyText(final ModifyEvent e) {

            if (_isSetField || _isSavingInProgress) {
                return;
            }

            updateModelFromUI();
            setTourDirty();
        }
    };

    _mouseWheelListener = new MouseWheelListener() {
        @Override
        public void mouseScrolled(final MouseEvent event) {

            if (_isSetField || _isSavingInProgress) {
                return;
            }

            Util.adjustSpinnerValueOnMouseScroll(event);

            updateModelFromUI();
            setTourDirty();

            updateUI_Time(event.widget);
        }
    };

    _selectionListener = new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {

            if (_isSetField || _isSavingInProgress) {
                return;
            }

            updateModelFromUI();
            setTourDirty();
        }
    };

    _keyListener = new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            onModifyContent();
        }
    };

    /*
     * listener for tour date/time
     */
    _dateTimeListener = new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {

            if (_isSetField || _isSavingInProgress) {
                return;
            }

            setTourDirty();

            updateUI_Title();

            onModifyContent();
        }
    };

    /*
     * listener for recording/driving/paused time
     */
    _tourTimeListener = new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {

            if (_isSetField || _isSavingInProgress) {
                return;
            }

            updateModelFromUI();
            setTourDirty();

            updateUI_Time(event.widget);
        }
    };

    _verifyFloatValue = new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent event) {

            if (_isSetField || _isSavingInProgress) {
                return;
            }

            final Text widget = (Text) event.widget;
            final String valueText = widget.getText().trim();

            if (valueText.length() > 0) {
                try {

                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    //
                    // Float.parseFloat() ignores localized strings therefore the databinding converter is used
                    // which provides also a good error message
                    //
                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                    StringToNumberConverter.toFloat(true).convert(valueText);

                    _messageManager.removeMessage(widget.getData(WIDGET_KEY), widget);

                } catch (final IllegalArgumentException e) {

                    // wrong characters are entered, display an error message

                    _messageManager.addMessage(widget.getData(WIDGET_KEY), e.getLocalizedMessage(), null,
                            IMessageProvider.ERROR, widget);
                }
            }

            /*
             * tour dirty must be set after validation because an error can occure which enables
             * actions
             */
            if (_isTourDirty) {
                /*
                 * when an error occured previously and is now solved, the save action must be
                 * enabled
                 */
                enableActions();
            } else {
                setTourDirty();
            }
        }
    };

    _verifyIntValue = new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent event) {

            if (_isSetField || _isSavingInProgress) {
                return;
            }

            final Text widget = (Text) event.widget;
            final String valueText = widget.getText().trim();

            if (valueText.length() > 0) {
                try {

                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    //
                    // Float.parseFloat() ignores localized strings therefore the databinding converter is used
                    // which provides also a good error message
                    //
                    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                    StringToNumberConverter.toInteger(true).convert(valueText);

                    _messageManager.removeMessage(widget.getData(WIDGET_KEY), widget);

                } catch (final IllegalArgumentException e) {

                    // wrong characters are entered, display an error message

                    _messageManager.addMessage(widget.getData(WIDGET_KEY), e.getLocalizedMessage(), null,
                            IMessageProvider.ERROR, widget);
                }
            }

            /*
             * tour dirty must be set after validation because an error can occure which enables
             * actions
             */
            if (_isTourDirty) {
                /*
                 * when an error occured previously and is now solved, the save action must be
                 * enabled
                 */
                enableActions();
            } else {
                setTourDirty();
            }
        }
    };
}

From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java

License:Open Source License

/**
 * Checks if tour has no errors//from ww w .j  ava2  s. c  o m
 * 
 * @return Returns <code>true</code> when all data for the tour are valid, <code>false</code>
 *         otherwise
 */
private boolean isTourValid() {

    if (_tourData == null) {
        return false;
    }

    if (_isTourDirty) {

        if (_tourData.isValidForSave() == false) {
            return false;
        }

        if (_tourData.getTourPerson() == null) {

            // tour is modified but not yet saved in the database

            _messageManager.addMessage(WIDGET_KEY_PERSON, Messages.tour_editor_message_person_is_required, null,
                    IMessageProvider.ERROR, _txtPerson);

        } else {
            _messageManager.removeMessage(WIDGET_KEY_PERSON, _txtPerson);
        }

        // tour is valid when there are no error messages

        return _messageManager.getErrorMessageCount() == 0;

    } else {

        // tour is not dirty

        return true;
    }
}

From source file:net.tourbook.ui.views.tourDataEditor.TourDataEditorView.java

License:Open Source License

private void onSelectionChanged(final ISelection selection) {

    if (_isSavingInProgress) {
        return;//from  w  w  w  .j av  a2  s . c  om
    }

    if (selection instanceof SelectionDeletedTours) {

        clearEditorContent();

        return;
    }

    // ensure that the tour manager contains the same tour data
    if ((_tourData != null) && _isTourDirty) {
        try {
            TourManager.checkTourData(_tourData, getTourData(_tourData.getTourId()));
        } catch (final MyTourbookException e) {
            e.printStackTrace();
        }
    }

    if (onSelectionChanged_isTourInSelection(selection)) {

        /*
         * tour in the selection is already displayed or a tour is not in the selection
         */

        if (_isInfoInTitle) {
            showDefaultTitle();
        }

        return;

    } else {

        // another tour is selected, show info

        if (_isTourDirty) {

            if (_isInfoInTitle == false) {

                /*
                 * show info only when it is not yet displayed, this is an optimization because
                 * setting the message causes an layout and this is EXTREMLY SLOW because of the
                 * bad date time controls
                 */

                // hide title
                _pageEditorForm.setText(UI.EMPTY_STRING);

                // show info
                _messageManager.addMessage(MESSAGE_KEY_ANOTHER_SELECTION,
                        NLS.bind(Messages.tour_editor_message_show_another_tour, getTourTitle()), null,
                        IMessageProvider.ERROR);

                _isInfoInTitle = true;
            }

            return;
        }
    }

    if (_isInfoInTitle) {
        showDefaultTitle();
    }

    if (selection instanceof SelectionTourData) {

        final SelectionTourData selectionTourData = (SelectionTourData) selection;
        final TourData tourData = selectionTourData.getTourData();
        if (tourData == null) {
            _tourChart = null;
        } else {

            final TourChart tourChart = selectionTourData.getTourChart();

            _tourChart = tourChart;
            updateUI_FromModel(tourData, false, true);
        }

    } else if (selection instanceof SelectionTourId) {

        displayTour(((SelectionTourId) selection).getTourId());

    } else if (selection instanceof SelectionTourIds) {

        final ArrayList<Long> tourIds = ((SelectionTourIds) selection).getTourIds();
        if ((tourIds != null) && (tourIds.size() > 0)) {
            displayTour(tourIds.get(0));
        }

    } else if (selection instanceof SelectionTourMarker) {

        displayTour(((SelectionTourMarker) selection).getTourData());

    } else if (selection instanceof SelectionTourCatalogView) {

        final SelectionTourCatalogView tourCatalogSelection = (SelectionTourCatalogView) selection;

        final TVICatalogRefTourItem refItem = tourCatalogSelection.getRefItem();
        if (refItem != null) {
            displayTour(refItem.getTourId());
        }

    } else if (selection instanceof SelectionChartInfo) {

        final ChartDataModel chartDataModel = ((SelectionChartInfo) selection).chartDataModel;
        if (chartDataModel != null) {

            final Object tourId = chartDataModel.getCustomData(Chart.CUSTOM_DATA_TOUR_ID);
            if (tourId instanceof Long) {

                final TourData tourData = getTourData((Long) tourId);
                if (tourData != null) {

                    if (_tourData == null) {

                        _tourData = tourData;
                        _tourChart = null;
                        updateUI_FromModel(tourData, false, true);

                    } else {

                        if (_tourData.getTourId().equals(tourData.getTourId())) {

                            // a new tour id is in the selection
                            _tourData = tourData;
                            _tourChart = null;
                            updateUI_FromModel(tourData, false, true);
                        }
                    }
                }
            }
        }

    } else if (selection instanceof StructuredSelection) {

        final Object firstElement = ((StructuredSelection) selection).getFirstElement();
        if (firstElement instanceof TVICatalogComparedTour) {

            displayTour(((TVICatalogComparedTour) firstElement).getTourId());

        } else if (firstElement instanceof TVICompareResultComparedTour) {

            displayTour(((TVICompareResultComparedTour) firstElement).getComparedTourData().getTourId());
        }
    }
}

From source file:nz.ac.massey.cs.jquest.views.VisualizationForm.java

License:Open Source License

protected void configureFormText(final Form form, FormText text) {
    text.addHyperlinkListener(new HyperlinkAdapter() {
        public void linkActivated(HyperlinkEvent e) {
            String is = (String) e.getHref();
            try {
                ((FormText) e.widget).getShell().dispose();
                int index = Integer.parseInt(is);
                IMessage[] messages = form.getChildrenMessages();
                IMessage message = messages[index];
                //               ErrorReporting error = (ErrorReporting) message.getData();
                //               if (error != null) {
                //                  error.handleError();
                //               }
            } catch (NumberFormatException ex) {
            }//from   w w  w  . j  a va2 s  . com
        }
    });
    text.setImage("error", getImage(IMessageProvider.ERROR));
    text.setImage("warning", getImage(IMessageProvider.WARNING));
    text.setImage("info", getImage(IMessageProvider.INFORMATION));
}

From source file:nz.ac.massey.cs.jquest.views.VisualizationForm.java

License:Open Source License

String createFormTextContent(IMessage[] messages) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    pw.println("<form>");
    for (int i = 0; i < messages.length; i++) {
        IMessage message = messages[i];//from   w w w . jav a  2 s . c  o  m
        pw.print("<li vspace=\"false\" style=\"image\" indent=\"16\" value=\"");
        switch (message.getMessageType()) {
        case IMessageProvider.ERROR:
            pw.print("error");
            break;
        case IMessageProvider.WARNING:
            pw.print("warning");
            break;
        case IMessageProvider.INFORMATION:
            pw.print("info");
            break;
        }
        pw.print("\"> <a href=\"");
        pw.print(i + "");
        pw.print("\">");
        if (message.getPrefix() != null) {
            pw.print(message.getPrefix());
        }
        pw.print(message.getMessage());
        pw.println("</a></li>");
    }
    pw.println("</form>");
    pw.flush();
    return sw.toString();
}