Search in sources :

Example 11 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTMessenger method askQuestion.

/**
 * Asks the given question and after the user has made an answer, the answer
 * will be sent to the corresponding <code>IActionProcessor</code>
 *
 * @param question
 *            The question to be asked
 */
@Override
public void askQuestion(final EJQuestion question) {
    final EJQuestionButton[] optionsButtons = getOptions(question);
    String[] options = new String[optionsButtons.length];
    for (int i = 0; i < optionsButtons.length; i++) {
        options[i] = question.getButtonText(optionsButtons[i]);
    }
    MessageDialog dialog = new MessageDialog(manager.getShell(), question.getTitle(), null, question.getMessageText(), MessageDialog.QUESTION, options, 2) {

        @Override
        public boolean close() {
            boolean close = super.close();
            int answer = getReturnCode();
            try {
                if (answer > -1) {
                    question.setAnswer(optionsButtons[answer]);
                    question.getActionProcessor().questionAnswered(question);
                }
            } catch (EJApplicationException e) {
                handleException(e);
            }
            return close;
        }
    };
    dialog.setBlockOnOpen(false);
    dialog.open();
}
Also used : EJQuestionButton(org.entirej.framework.core.enumerations.EJQuestionButton) EJApplicationException(org.entirej.framework.core.EJApplicationException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 12 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTMessenger method askInternalQuestion.

/**
 * Asks the given question and after the user has made an answer, the answer
 * will be sent to the corresponding <code>IActionProcessor</code>
 *
 * @param question
 *            The question to be asked
 */
@Override
public void askInternalQuestion(final EJInternalQuestion question) {
    final EJQuestionButton[] optionsButtons = getOptions(question);
    String[] options = new String[optionsButtons.length];
    for (int i = 0; i < optionsButtons.length; i++) {
        options[i] = question.getButtonText(optionsButtons[i]);
    }
    MessageDialog dialog = new MessageDialog(manager.getShell(), question.getTitle(), null, question.getMessageText(), MessageDialog.QUESTION, options, 2) {

        @Override
        public boolean close() {
            boolean close = super.close();
            int answer = getReturnCode();
            try {
                if (answer > -1) {
                    question.setAnswer(optionsButtons[answer]);
                    question.getActionProcessor().questionAnswered(question);
                }
                question.getForm().internalQuestionAnswered(question);
            } catch (EJApplicationException e) {
                handleException(e);
            }
            return close;
        }
    };
    dialog.setBlockOnOpen(false);
    dialog.open();
}
Also used : EJQuestionButton(org.entirej.framework.core.enumerations.EJQuestionButton) EJApplicationException(org.entirej.framework.core.EJApplicationException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 13 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTDefaultMenuBuilder method createMenuTree.

private TreeViewer createMenuTree(EJRWTMenuTreeRoot root, boolean tselectionMode) {
    _menuTree = new TreeViewer(_parent);
    _menuTree.setContentProvider(new EJRWTMenuTreeContentProvider());
    _menuTree.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof EJRWTMenuTreeElement) {
                return ((EJRWTMenuTreeElement) element).getText();
            }
            return "<EMPTY>";
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof EJRWTMenuTreeElement) {
                return ((EJRWTMenuTreeElement) element).getImage();
            }
            return super.getImage(element);
        }
    });
    _menuTree.setAutoExpandLevel(2);
    _menuTree.setInput(root);
    EJMenuActionProcessor actionProcessor = null;
    if (root.getActionProcessorClassName() != null && root.getActionProcessorClassName().length() > 0) {
        try {
            Class<?> processorClass = Class.forName(root.getActionProcessorClassName());
            try {
                Object processorObject = processorClass.newInstance();
                if (processorObject instanceof EJMenuActionProcessor) {
                    actionProcessor = (EJMenuActionProcessor) processorObject;
                } else {
                    throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_ACTION_PROCESSOR_NAME, processorClass.getName(), "EJMenuActionProcessor"));
                }
            } catch (InstantiationException e) {
                throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.UNABLE_TO_CREATE_ACTION_PROCESSOR, processorClass.getName()), e);
            } catch (IllegalAccessException e) {
                throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.UNABLE_TO_CREATE_ACTION_PROCESSOR, processorClass.getName()), e);
            }
        } catch (ClassNotFoundException e) {
            throw new EJApplicationException(EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_ACTION_PROCESSOR_FOR_MENU, root.getActionProcessorClassName()));
        }
    }
    final EJMenuActionProcessor menuActionProcessor = actionProcessor;
    if (tselectionMode) {
        _menuTree.getTree().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseUp(MouseEvent event) {
                ISelection selection = _menuTree.getSelection();
                if (selection instanceof IStructuredSelection) {
                    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                    if (structuredSelection.getFirstElement() instanceof EJRWTMenuTreeElement) {
                        EJRWTMenuTreeElement element = (EJRWTMenuTreeElement) structuredSelection.getFirstElement();
                        if (element.getType() == Type.FORM) {
                            _applicationManager.getFrameworkManager().openForm(element.getActionCommand(), null, false);
                        } else if (element.getType() == Type.ACTION && menuActionProcessor != null) {
                            try {
                                menuActionProcessor.executeActionCommand(element.getActionCommand());
                            } catch (EJActionProcessorException e) {
                                _applicationManager.getApplicationMessenger().handleException(e, true);
                            }
                        }
                    }
                }
            }
        });
    }
    _menuTree.getTree().addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
            ISelection selection = _menuTree.getSelection();
            if (selection instanceof IStructuredSelection) {
                final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                if (structuredSelection.getFirstElement() instanceof EJRWTMenuTreeElement) {
                    Display.getCurrent().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                EJRWTMenuTreeElement element = (EJRWTMenuTreeElement) structuredSelection.getFirstElement();
                                if (element.getType() == Type.FORM) {
                                    _applicationManager.getFrameworkManager().openForm(element.getActionCommand(), null, false);
                                } else if (element.getType() == Type.ACTION && menuActionProcessor != null) {
                                    try {
                                        menuActionProcessor.executeActionCommand(element.getActionCommand());
                                    } catch (EJActionProcessorException e) {
                                        _applicationManager.getApplicationMessenger().handleException(e, true);
                                    }
                                }
                            } catch (EJApplicationException e) {
                                _applicationManager.handleException(e);
                            }
                        }
                    });
                }
            }
        }
    });
    return _menuTree;
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) MouseAdapter(org.eclipse.swt.events.MouseAdapter) EJApplicationException(org.entirej.framework.core.EJApplicationException) EJActionProcessorException(org.entirej.framework.core.EJActionProcessorException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) EJMenuActionProcessor(org.entirej.framework.core.actionprocessor.interfaces.EJMenuActionProcessor) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 14 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTRadioGroupItemRenderer method getValueAsObject.

private Object getValueAsObject(Class<?> dataType, String value) {
    try {
        Constructor<?> constructor = dataType.getConstructor(String.class);
        Object val = constructor.newInstance(value);
        return val;
    } catch (SecurityException e) {
        throw new EJApplicationException("Unable to find a constructor with a String parameter for the data type: " + dataType.getName(), e);
    } catch (NoSuchMethodException e) {
        throw new EJApplicationException("Unable to find a constructor with a String parameter for the data type: " + dataType.getName(), e);
    } catch (IllegalArgumentException e) {
        throw new EJApplicationException("Unable create a new data type: " + dataType.getName() + ". With a single string parameter of: " + value);
    } catch (InstantiationException e) {
        throw new EJApplicationException("Unable create a new data type: " + dataType.getName() + ". With a single string parameter of: " + value);
    } catch (IllegalAccessException e) {
        throw new EJApplicationException("Unable create a new data type: " + dataType.getName() + ". With a single string parameter of: " + value);
    } catch (InvocationTargetException e) {
        throw new EJApplicationException("Unable create a new data type: " + dataType.getName() + ". With a single string parameter of: " + value);
    }
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 15 with EJApplicationException

use of org.entirej.framework.core.EJApplicationException in project rap by entirej.

the class EJRWTNumberItemRenderer method setValue.

@Override
public void setValue(Object value) {
    try {
        _modifyListener.enable = false;
        if (value != null && !Number.class.isAssignableFrom(value.getClass())) {
            EJMessage message = EJMessageFactory.getInstance().createMessage(EJFrameworkMessage.INVALID_DATA_TYPE_FOR_ITEM, _item.getName(), Number.class.getName(), value.getClass().getName());
            throw new IllegalArgumentException(message.getMessage());
        }
        _baseValue = value;
        if (_displayValueAsLabel) {
            if (controlState(_valueLabel)) {
                _valueLabel.setText(value != null ? _decimalFormatter.format(value) : "");
            }
        } else {
            if (controlState(_textField)) {
                if (value != null) {
                    if (_maxLength > 0 && value.toString().length() > _maxLength) {
                        EJMessage message = new EJMessage("The value for item, " + _item.getReferencedItemProperties().getBlockName() + "." + _item.getReferencedItemProperties().getName() + " is too long for its field definition.");
                        throw new EJApplicationException(message);
                    }
                }
                _textField.setText(value != null ? _decimalFormatter.format(value) : "");
                setMandatoryBorder(_mandatory);
            }
        }
    } finally {
        _modifyListener.enable = true;
    }
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException) EJMessage(org.entirej.framework.core.EJMessage)

Aggregations

EJApplicationException (org.entirej.framework.core.EJApplicationException)18 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)6 Composite (org.eclipse.swt.widgets.Composite)6 EJRWTScrolledComposite (org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite)6 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)5 EJMessage (org.entirej.framework.core.EJMessage)5 Collection (java.util.Collection)4 FillLayout (org.eclipse.swt.layout.FillLayout)4 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)4 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)4 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)4 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)4 Button (org.eclipse.swt.widgets.Button)3 EJRWTAbstractDialog (org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog)3 EJRWTItemTextChangeNotifier (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier)3 ChangeListener (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener)3 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 Control (org.eclipse.swt.widgets.Control)2