public List<UpdatableItem> getPulldownMenu(final BlockDevInfo blockDevInfo) {
this.blockDevInfo = blockDevInfo;
final List<UpdatableItem> items = new ArrayList<UpdatableItem>();
final Application.RunMode runMode = Application.RunMode.LIVE;
final MyMenu repMenuItem = menuFactory.createMenu(
Tools.getString("HostBrowser.Drbd.AddDrbdResource"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
final DrbdXml dxml = getClusterBrowser().getDrbdXml();
if (getDrbdVolumeInfo() != null) {
return "it is already a drbd resouce";
} else if (!getHost().isConnected()) {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
} else if (!getHost().isDrbdLoaded()) {
return "drbd is not loaded";
} else if (getBlockDevice().isMounted()) {
return "is mounted";
} else if (getBlockDevice().isVolumeGroupOnPhysicalVolume()) {
return "is volume group";
} else if (!getBlockDevice().isAvailable()) {
return "not available";
} else if (dxml.isDrbdDisabled()) {
return "disabled because of config";
} else {
final String noavail = getClusterBrowser().isDrbdAvailable(getHost());
if (noavail != null) {
return "DRBD installation problem: " + noavail;
}
}
return null;
}
});
repMenuItem.onUpdate(new Runnable() {
@Override
public void run() {
repMenuItem.updateMenuComponents();
final Cluster cluster = getHost().getCluster();
final Host[] otherHosts = cluster.getHostsArray();
final Collection<MyMenu> hostMenus = new ArrayList<MyMenu>();
for (final Host oHost : otherHosts) {
if (oHost == getHost()) {
continue;
}
final MyMenu hostMenu = menuFactory.createMenu(oHost.getName(),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
final DrbdXml dxml = getClusterBrowser().getDrbdXml();
if (!oHost.isConnected()) {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
} else if (!oHost.isDrbdLoaded()) {
return "drbd is not loaded";
} else {
final String noavail = getClusterBrowser().isDrbdAvailable(getHost());
if (noavail != null) {
return "DRBD installation problem: " + noavail;
}
return null;
}
}
});
hostMenu.onUpdate(new Runnable() {
@Override
public void run() {
hostMenu.updateMenuComponents();
hostMenu.removeAll();
final Set<BlockDevInfo> blockDevInfos = oHost.getBrowser().getSortedBlockDevInfos();
final List<BlockDevInfo> blockDevInfosS = new ArrayList<BlockDevInfo>();
for (final BlockDevInfo oBdi : blockDevInfos) {
if (oBdi.getName().equals(getBlockDevice().getName())) {
blockDevInfosS.add(0, oBdi);
} else {
blockDevInfosS.add(oBdi);
}
}
for (final BlockDevInfo oBdi : blockDevInfosS) {
if (oBdi.getDrbdVolumeInfo() == null && oBdi.getBlockDevice().isAvailable()) {
hostMenu.add(addDrbdResourceMenuItem(oBdi, runMode));
}
if (oBdi.getName().equals(getBlockDevice().getName())) {
hostMenu.addSeparator();
}
}
hostMenu.processAccessMode();
}
});
hostMenu.updateAndWait();
hostMenus.add(hostMenu);
}
repMenuItem.removeAll();
for (final MyMenu hostMenu : hostMenus) {
repMenuItem.add(hostMenu);