JPopupMenu popup = new JPopupMenu();
if (doc.isDirectory()) {
BeanDirectory dir = (BeanDirectory) doc;
popup.add(new JMenuItem(new PropertyDocumentAction(dir)));
popup.add(new JMenuItem(new RemoveDirectoryAction(dir)));
popup.addSeparator();
popup.add(new JMenuItem(new NewDirectoryAction(dir)));
popup.add(new JMenuItem(new NewDocumentAction(dir)));
} else {
BeanDocument file = (BeanDocument) doc;
popup.add(new JMenuItem(new PropertyDocumentAction(file)));
popup.add(new JMenuItem(new ViewDocumentAction(file)));
popup.addSeparator();
popup.add(new JMenuItem(new DeleteDocumentAction(file)));
}