/**
* @inheritDoc()
*/
public ContextMenuItem[] getContextMenuItems(ContextEvent event) {
final SimpleContextMenuItem deleteItem = new SimpleContextMenuItem(
BUNDLE.getString("Delete"), null, new DeleteListener());
final SimpleContextMenuItem duplicateItem = new SimpleContextMenuItem(
BUNDLE.getString("Duplicate"), null, new DuplicateListener());
// find the security component for both this cell and it's parent,
// if any
final Cell cell = event.getPrimaryCell();
final SecurityComponent sc = cell.getComponent(SecurityComponent.class);
final SecurityComponent psc;
if (cell.getParent() != null) {
psc = cell.getParent().getComponent(SecurityComponent.class);
} else {
psc = null;
}
// see if we can check security locally, or if we have to make a
// remote request
if ((sc == null || sc.hasPermissions()) &&
(psc == null || psc.hasPermissions())) {
duplicateItem.setEnabled(canDuplicate(psc));
deleteItem.setEnabled(canDelete(sc, psc));
} else {
Thread t = new Thread(new Runnable() {
public void run() {
duplicateItem.setEnabled(canDuplicate(psc));
duplicateItem.setLabel(BUNDLE.getString("Duplicate"));
duplicateItem.fireMenuItemRepaintListeners();
deleteItem.setEnabled(canDelete(sc, psc));
deleteItem.setLabel(BUNDLE.getString("Delete"));
deleteItem.fireMenuItemRepaintListeners();
}
}, "Cell palette security check");
t.start();
// wait for a little bit to see if the check comes back
// quickly
try {
t.join(250);
} catch (InterruptedException ie) {
}
if (!t.isAlive()) {
duplicateItem.setEnabled(false);
duplicateItem.setLabel(BUNDLE.getString("Duplicate_Checking"));
deleteItem.setEnabled(false);
deleteItem.setLabel(BUNDLE.getString("Delete_Checking"));
}
}