Search in sources :

Example 1 with EJMenuActionProcessor

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);
}
Also used : EJApplicationException(org.entirej.framework.core.EJApplicationException) Menu(org.eclipse.swt.widgets.Menu) EJMenuActionProcessor(org.entirej.framework.core.actionprocessor.interfaces.EJMenuActionProcessor)

Example 2 with EJMenuActionProcessor

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

Aggregations

EJApplicationException (org.entirej.framework.core.EJApplicationException)2 EJMenuActionProcessor (org.entirej.framework.core.actionprocessor.interfaces.EJMenuActionProcessor)2 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Image (org.eclipse.swt.graphics.Image)1 Menu (org.eclipse.swt.widgets.Menu)1 EJActionProcessorException (org.entirej.framework.core.EJActionProcessorException)1