* Returns label for drbd volume edge. If it is longer than 10
* characters, it is shortened.
*/
@Override
protected String getLabelForEdgeStringer(final Edge edge) {
final VolumeInfo dvi = edgeToDrbdVolumeMap.get(edge);
if (dvi != null
&& dvi.getName() != null
&& dvi.getDrbdResourceInfo() != null) {
final Vertex source = edge.getSource();
final Vertex dest = edge.getDest();
final BlockDevInfo sourceBDI = (BlockDevInfo) getInfo(source);
if (sourceBDI == null) {
return "";
}
final BlockDevInfo destBDI = (BlockDevInfo) getInfo(dest);
if (destBDI == null) {
return "";
}
final BlockDevice sourceBD = sourceBDI.getBlockDevice();
final BlockDevice destBD = destBDI.getBlockDevice();
final Application.RunMode runMode = getRunMode();
if (!destBDI.isConnected(runMode)) {
if (sourceBDI.isWFConnection(runMode)
&& !destBDI.isWFConnection(runMode)) {
edge.setDirection(dest, source);
application.invokeLater(new Runnable() {
@Override
public void run() {
repaint();
}
});
}
} else if (!sourceBD.isPrimary() && destBD.isPrimary()) {
edge.setDirection(dest, source);
application.invokeLater(new Runnable() {
@Override
public void run() {
repaint();
}
});
}
final StringBuilder l = new StringBuilder(dvi.getNameForGraph());
final Map<Vertex, Point2D> vl = getVertexLocations();
final Point2D sp = vl.get(source);
final Point2D dp = vl.get(dest);
putVertexLocations();
final int len = (int) Math.sqrt(Math.pow(sp.getX() - dp.getX(), 2) + Math.pow(sp.getY() - dp.getY(), 2));
final int maxLen = (len - 200) / 7;
if (l.length() > maxLen) {
l.delete(0, l.length() - maxLen + 3);
l.insert(0, "...");
}
if (dvi.isSyncing()) {
String syncedProgress = dvi.getSyncedProgress();
if (syncedProgress == null) {
syncedProgress = "?.?";
}
final double sourceX = getLayout().transform(source).getX();
final double destX = getLayout().transform(dest).getX();
if (sourceBD.isPausedSync() || destBD.isPausedSync()) {
l.append(" (").append(syncedProgress).append("% paused)");
} else if (sourceBD.isSyncSource() && sourceX < destX
|| destBD.isSyncSource() && sourceX > destX) {
l.append(" (").append(syncedProgress).append("% \u2192)"); /* -> */
} else {
l.append(" (\u2190 ").append(syncedProgress).append("%)"); /* <- */
}
} else if (dvi.isSplitBrain()) {
l.append(" (split-brain)");
} else if (!dvi.isConnected(runMode)) {
l.append(" (disconnected)");
} else if (dvi.isVerifying()) {
l.append(" (verify)");
}
return l.toString();
}
return null;