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