noneItem.setEnabled(false);
add(noneItem);
}
void update() {
ComboFrame frame = getComboFrame();
Document newDoc = (frame != null) ? frame.getDocument() : null;
Document oldDoc = docRef.get();
if (newDoc != oldDoc) {
try {
removeAll();
if (newDoc != null) {
List<TemplateKey> keys = TemplateDatabase.getTemplateKeys();
if (! keys.isEmpty()) {
LinkedHashMap<String, LinkedList<TemplateKey>> nsMap =
new LinkedHashMap<String, LinkedList<TemplateKey>>();
for (TemplateKey key : keys) {
String namespace = key.getNamespace();
if (! nsMap.containsKey(namespace)) {
nsMap.put(
namespace, new LinkedList<TemplateKey>()
);
}
nsMap.get(namespace).add(key);
}
for (String namespace : nsMap.keySet()) {
JMenu nsItem = new JMenu(namespace);
List<TemplateKey> nsKeys = nsMap.get(namespace);
for (final TemplateKey key : nsKeys) {
JMenuItem templateItem =
new JMenuItem(key.getName());
templateItem.addActionListener(
new ActionListener() {
public void actionPerformed(
ActionEvent event
) {
ComboFrame frame = getComboFrame();
Application.applyTemplate(frame, key);
}
}
);
nsItem.add(templateItem);