Search in sources :

Example 1 with IExternalFinderItemMenuGenerator

use of org.omegat.externalfinder.item.IExternalFinderItemMenuGenerator in project omegat by omegat-org.

the class ExternalFinder method generateIProjectEventListener.

private static IProjectEventListener generateIProjectEventListener() {
    return new IProjectEventListener() {

        private final List<Component> menuItems = new ArrayList<Component>();

        @Override
        public void onProjectChanged(final IProjectEventListener.PROJECT_CHANGE_TYPE eventType) {
            switch(eventType) {
                case LOAD:
                    onLoad();
                    break;
                case CLOSE:
                    onClose();
                    break;
                default:
            }
        }

        private void onLoad() {
            // clear old items
            menuItems.clear();
            // add finder items to menuItems
            IExternalFinderItemMenuGenerator generator = new ExternalFinderItemMenuGenerator(ExternalFinderItem.TARGET.BOTH, false);
            List<JMenuItem> newMenuItems = generator.generate();
            JMenu toolsMenu = Core.getMainWindow().getMainMenu().getToolsMenu();
            // Separator
            Component separator = new JPopupMenu.Separator();
            toolsMenu.add(separator);
            menuItems.add(separator);
            // add menuItems to menu
            MenuItemPager pager = new MenuItemPager(toolsMenu);
            for (JMenuItem component : newMenuItems) {
                pager.add(component);
            }
            menuItems.addAll(pager.getFirstPage());
        }

        private void onClose() {
            // remove menu items
            final JMenu menu = Core.getMainWindow().getMainMenu().getToolsMenu();
            menuItems.forEach(menu::remove);
            menuItems.clear();
            projectConfig = null;
        }
    };
}
Also used : IExternalFinderItemMenuGenerator(org.omegat.externalfinder.item.IExternalFinderItemMenuGenerator) ExternalFinderItemMenuGenerator(org.omegat.externalfinder.item.ExternalFinderItemMenuGenerator) IExternalFinderItemMenuGenerator(org.omegat.externalfinder.item.IExternalFinderItemMenuGenerator) ArrayList(java.util.ArrayList) List(java.util.List) MenuItemPager(org.omegat.util.gui.MenuItemPager) Component(java.awt.Component) JMenuItem(javax.swing.JMenuItem) IProjectEventListener(org.omegat.core.events.IProjectEventListener) JMenu(javax.swing.JMenu)

Aggregations

Component (java.awt.Component)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 IProjectEventListener (org.omegat.core.events.IProjectEventListener)1 ExternalFinderItemMenuGenerator (org.omegat.externalfinder.item.ExternalFinderItemMenuGenerator)1 IExternalFinderItemMenuGenerator (org.omegat.externalfinder.item.IExternalFinderItemMenuGenerator)1 MenuItemPager (org.omegat.util.gui.MenuItemPager)1