use of org.entirej.framework.core.actionprocessor.interfaces.EJMenuActionProcessor in project rap by entirej.
the class EJRWTDefaultMenuBuilder method createApplicationMenu.
public static void createApplicationMenu(EJApplicationManager applicationManager, Shell shell, EJRWTMenuTreeRoot 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()));
}
}
Menu appMenuBar = shell.getDisplay().getMenuBar();
if (appMenuBar == null) {
appMenuBar = new Menu(shell, SWT.BAR);
shell.setMenuBar(appMenuBar);
}
createMenu(applicationManager, appMenuBar, root, actionProcessor);
}
use of org.entirej.framework.core.actionprocessor.interfaces.EJMenuActionProcessor 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;
}
Aggregations