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();
}
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();
}
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;
}
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);
}
}
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;
}
}
Aggregations