public List<UpdatableItem> getPulldownMenu(final Host host, final HostDrbdInfo hostDrbdInfo) {
final List<UpdatableItem> items = new ArrayList<UpdatableItem>();
/* host wizard */
final MyMenuItem hostWizardItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.HostWizard"),
HostBrowser.HOST_ICON_LARGE,
Tools.getString("HostBrowser.HostWizard"),
new AccessMode(AccessMode.RO, AccessMode.NORMAL),
new AccessMode(AccessMode.RO, AccessMode.NORMAL))
.addAction(new MenuAction() {
@Override
public void run(final String text) {
editHostDialog.showDialogs(host);
}
});
items.add(hostWizardItem);
guiData.registerAddHostButton(hostWizardItem);
/* proxy host wizard */
final MyMenuItem proxyHostWizardItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.ProxyHostWizard"),
HostBrowser.HOST_ICON_LARGE,
Tools.getString("HostBrowser.ProxyHostWizard"),
new AccessMode(AccessMode.RO, AccessMode.NORMAL),
new AccessMode(AccessMode.RO, AccessMode.NORMAL))
.addAction(new MenuAction() {
@Override
public void run(final String text) {
proxyHostWizard.init(host, null);
proxyHostWizard.showDialogs();
}
});
items.add(proxyHostWizardItem);
guiData.registerAddHostButton(proxyHostWizardItem);
final Application.RunMode runMode = Application.RunMode.LIVE;
/* load drbd */
final UpdatableItem loadItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.LoadDrbd"),
null,
Tools.getString("HostBrowser.Drbd.LoadDrbd"),
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (host.isConnected()) {
if (host.isDrbdLoaded()) {
return "already loaded";
} else {
return null;
}
} else {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.load(host, runMode);
hostDrbdInfo.getBrowser().getClusterBrowser().updateHWInfo(host, !Host.UPDATE_LVM);
}
});
items.add(loadItem);
/* proxy start/stop */
final UpdatableItem proxyItem =
menuFactory.createMenuItem(Tools.getString("HostDrbdInfo.Drbd.StopProxy"),
null,
hostDrbdInfo.getMenuToolTip("DRBD.stopProxy", ""),
Tools.getString("HostDrbdInfo.Drbd.StartProxy"),
null,
hostDrbdInfo.getMenuToolTip("DRBD.startProxy", ""),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.predicate(new Predicate() {
@Override
public boolean check() {
return host.isDrbdProxyRunning();
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
if (host.isDrbdProxyRunning()) {
DRBD.stopProxy(host, runMode);
} else {
DRBD.startProxy(host, runMode);
}
hostDrbdInfo.getBrowser().getClusterBrowser().updateHWInfo(host, !Host.UPDATE_LVM);
}
});
items.add(proxyItem);
/* all proxy connections up */
final UpdatableItem allProxyUpItem =
menuFactory.createMenuItem(Tools.getString("HostDrbdInfo.Drbd.AllProxyUp"),
null,
hostDrbdInfo.getMenuToolTip("DRBD.proxyUp", DRBD.ALL_DRBD_RESOURCES),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return host.isConnected() && host.isDrbdProxyRunning();
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.proxyUp(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
hostDrbdInfo.getBrowser().getClusterBrowser().updateHWInfo(host, !Host.UPDATE_LVM);
}
});
items.add(allProxyUpItem);
/* all proxy connections down */
final UpdatableItem allProxyDownItem =
menuFactory.createMenuItem(Tools.getString("HostDrbdInfo.Drbd.AllProxyDown"),
null,
hostDrbdInfo.getMenuToolTip("DRBD.proxyDown", DRBD.ALL_DRBD_RESOURCES),
new AccessMode(AccessMode.ADMIN, AccessMode.ADVANCED),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.visiblePredicate(new VisiblePredicate() {
@Override
public boolean check() {
return host.isConnected() && host.isDrbdProxyRunning();
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.proxyDown(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
hostDrbdInfo.getBrowser().getClusterBrowser().updateHWInfo(host, !Host.UPDATE_LVM);
}
});
items.add(allProxyDownItem);
/* load DRBD config / adjust all */
final MyMenuItem adjustAllItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.AdjustAllDrbd"),
null,
Tools.getString("HostBrowser.Drbd.AdjustAllDrbd.ToolTip"),
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (host.isConnected()) {
return null;
} else {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.adjust(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
hostDrbdInfo.getBrowser().getClusterBrowser().updateHWInfo(host, !Host.UPDATE_LVM);
}
});
items.add(adjustAllItem);
final ClusterBrowser cb = hostDrbdInfo.getBrowser().getClusterBrowser();
if (cb != null) {
final ButtonCallback adjustAllItemCallback = cb.new DRBDMenuItemCallback(host)
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
DRBD.adjust(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
hostDrbdInfo.addMouseOverListener(adjustAllItem, adjustAllItemCallback);
}
/* start drbd */
final MyMenuItem upAllItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.UpAll"),
null,
Tools.getString("HostBrowser.Drbd.UpAll"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!host.isDrbdStatusOk()) {
return HostDrbdInfo.NO_DRBD_STATUS_TOOLTIP;
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.up(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
}
});
items.add(upAllItem);
if (cb != null) {
final ButtonCallback upAllItemCallback = cb.new DRBDMenuItemCallback(host)
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
DRBD.up(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
hostDrbdInfo.addMouseOverListener(upAllItem, upAllItemCallback);
}
/* change host color */
final UpdatableItem changeHostColorItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.ChangeHostColor"),
null,
Tools.getString("HostBrowser.Drbd.ChangeHostColor"),
new AccessMode(AccessMode.RO, AccessMode.NORMAL),
new AccessMode(AccessMode.RO, AccessMode.NORMAL))
.addAction(new MenuAction() {
@Override
public void run(final String text) {
final Color newColor = JColorChooser.showDialog(guiData.getMainFrame(),
"Choose " + host.getName() + " color",
host.getPmColors()[0]);
if (newColor != null) {
host.setSavedHostColorInGraphs(newColor);
}
}
});
items.add(changeHostColorItem);
/* view logs */
final UpdatableItem viewLogsItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.ViewLogs"),
Info.LOGFILE_ICON,
Tools.getString("HostBrowser.Drbd.ViewLogs"),
new AccessMode(AccessMode.RO, AccessMode.NORMAL),
new AccessMode(AccessMode.RO, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (!host.isConnected()) {
return Host.NOT_CONNECTED_MENU_TOOLTIP_TEXT;
}
return null;
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
final DrbdsLog drbdsLog = drbdsLogProvider.get();
drbdsLog.init(host);
drbdsLog.showDialog();
}
});
items.add(viewLogsItem);
/* connect all */
final MyMenuItem connectAllItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.ConnectAll"),
null,
Tools.getString("HostBrowser.Drbd.ConnectAll"),
new AccessMode(AccessMode.OP, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (host.isDrbdStatusOk()) {
return null;
} else {
return HostDrbdInfo.NO_DRBD_STATUS_TOOLTIP;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.connect(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
items.add(connectAllItem);
if (cb != null) {
final ButtonCallback connectAllItemCallback = cb.new DRBDMenuItemCallback(host)
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
DRBD.connect(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
hostDrbdInfo.addMouseOverListener(connectAllItem, connectAllItemCallback);
}
/* disconnect all */
final MyMenuItem disconnectAllItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.DisconnectAll"),
null,
Tools.getString("HostBrowser.Drbd.DisconnectAll"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (host.isDrbdStatusOk()) {
return null;
} else {
return HostDrbdInfo.NO_DRBD_STATUS_TOOLTIP;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.disconnect(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
}
});
items.add(disconnectAllItem);
if (cb != null) {
final ButtonCallback disconnectAllItemCallback = cb.new DRBDMenuItemCallback(host)
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
DRBD.disconnect(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
hostDrbdInfo.addMouseOverListener(disconnectAllItem, disconnectAllItemCallback);
}
/* attach dettached */
final MyMenuItem attachAllItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.AttachAll"),
null,
Tools.getString("HostBrowser.Drbd.AttachAll"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (host.isDrbdStatusOk()) {
return null;
} else {
return HostDrbdInfo.NO_DRBD_STATUS_TOOLTIP;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.attach(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
}
});
items.add(attachAllItem);
if (cb != null) {
final ButtonCallback attachAllItemCallback = cb.new DRBDMenuItemCallback(host)
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
DRBD.attach(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
hostDrbdInfo.addMouseOverListener(attachAllItem, attachAllItemCallback);
}
/* detach */
final MyMenuItem detachAllItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.DetachAll"),
null,
Tools.getString("HostBrowser.Drbd.DetachAll"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (host.isDrbdStatusOk()) {
return null;
} else {
return HostDrbdInfo.NO_DRBD_STATUS_TOOLTIP;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.detach(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
}
});
items.add(detachAllItem);
if (cb != null) {
final ButtonCallback detachAllItemCallback = cb.new DRBDMenuItemCallback(host)
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
DRBD.detach(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
hostDrbdInfo.addMouseOverListener(detachAllItem, detachAllItemCallback);
}
/* set all primary */
final MyMenuItem setAllPrimaryItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.SetAllPrimary"),
null,
Tools.getString("HostBrowser.Drbd.SetAllPrimary"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.OP, AccessMode.NORMAL))
.enablePredicate(new EnablePredicate() {
@Override
public String check() {
if (host.isDrbdStatusOk()) {
return null;
} else {
return HostDrbdInfo.NO_DRBD_STATUS_TOOLTIP;
}
}
})
.addAction(new MenuAction() {
@Override
public void run(final String text) {
DRBD.setPrimary(host, DRBD.ALL_DRBD_RESOURCES, null, runMode);
}
});
items.add(setAllPrimaryItem);
if (cb != null) {
final ButtonCallback setAllPrimaryItemCallback = cb.new DRBDMenuItemCallback(host)
.addAction(new CallbackAction() {
@Override
public void run(final Host host) {
DRBD.setPrimary(host, DRBD.ALL_DRBD_RESOURCES, null, Application.RunMode.TEST);
}
});
hostDrbdInfo.addMouseOverListener(setAllPrimaryItem, setAllPrimaryItemCallback);
}
/* set all secondary */
final MyMenuItem setAllSecondaryItem =
menuFactory.createMenuItem(Tools.getString("HostBrowser.Drbd.SetAllSecondary"),
null,
Tools.getString("HostBrowser.Drbd.SetAllSecondary"),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL),
new AccessMode(AccessMode.ADMIN, AccessMode.NORMAL))