Skip to content

Commit 23f4014

Browse files
committed
Initial code for pathways
1 parent b354b17 commit 23f4014

File tree

2 files changed

+76
-136
lines changed

2 files changed

+76
-136
lines changed

stroom-app/src/main/resources/ui/css/pathways.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
color: red;
3333
}
3434

35-
.pathway-row {
36-
37-
}
38-
3935
.pathway-node {
4036
display: flex;
4137
gap: 4px;

stroom-core-client/src/main/java/stroom/pathways/client/presenter/PathwayTreePresenter.java

Lines changed: 76 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ public class PathwayTreePresenter
3434
extends MyPresenterWidget<PathwayTreeView> {
3535

3636
private static final int ROW_HEIGHT = 22;
37-
private static final int INDENT = 20;//56;
38-
private static final int START_X_OFFSET = 13;
39-
private static final int START_Y_OFFSET = 0;
40-
private static final int END_X_OFFSET = 23;
41-
private static final int END_Y_OFFSET = -9;
37+
private static final int INDENT = 20;
4238

4339
private final ButtonView newButton;
4440
private final ButtonView editButton;
@@ -76,8 +72,6 @@ protected void onBind() {
7672
NullSafe.isNonBlankString(element.getAttribute("uuid")), 3);
7773
if (node != null) {
7874
final String uuid = node.getAttribute("uuid");
79-
// AlertEvent.fireInfo(this, uuid, null);
80-
8175
if (!Objects.equals(selected, node)) {
8276
if (selected != null) {
8377
selected.removeClassName("pathway-nodeName--selected");
@@ -140,154 +134,86 @@ private void addNode(final PathNode node) {
140134
}
141135

142136
private void append(final HtmlBuilder hb,
143-
final PathNode node,
144-
final HtmlBuilder svg,
145-
final int nodeDepth,
146-
final AtomicInteger rowNum,
147-
final AtomicInteger width,
148-
final AtomicInteger height) {
149-
hb.div(d -> {
150-
final int sourceRowNum = rowNum.incrementAndGet();
151-
152-
// Render node icon and text.
153-
d.div(nodeDiv -> {
154-
nodeDiv.div(icon ->
155-
icon.appendTrustedString(SvgImage.PATHWAYS_NODE.getSvg()),
156-
Attribute.className("pathway-nodeIcon svgIcon " +
157-
SvgImage.PATHWAYS_NODE.getClassName()));
158-
nodeDiv.div(n -> n.append(node.getName()),
159-
Attribute.className("pathway-nodeName"), new Attribute("uuid", node.getUuid()));
160-
}, Attribute.className("pathway-node"));
161-
162-
// Add child node targets.
163-
// final int parentRowNum = count.incrementAndGet();
164-
final List<PathNodeList> targets = NullSafe.list(node.getTargets());
165-
if (targets.size() > 1) {
166-
// Add bezier curve to target set.
167-
appendBezier(svg, nodeDepth, sourceRowNum, rowNum.get(), width, height);
168-
169-
// Add target set.
170-
final String choiceCss = "pathway-nodeIcon svgIcon " +
171-
SvgImage.PATHWAYS_CHOICE.getClassName();
172-
173-
d.div(targetsOuterDiv -> {
174-
targetsOuterDiv.div(icon -> icon.appendTrustedString(SvgImage.PATHWAYS_CHOICE.getSvg()),
175-
Attribute.className(choiceCss));
137+
final PathNode node,
138+
final HtmlBuilder svg,
139+
final int nodeDepth,
140+
final AtomicInteger rowNum,
141+
final AtomicInteger width,
142+
final AtomicInteger height) {
143+
final int sourceRowNum = rowNum.incrementAndGet();
144+
145+
// Render node icon and text.
146+
hb.div(nodeDiv -> {
147+
nodeDiv.div(icon ->
148+
icon.appendTrustedString(SvgImage.PATHWAYS_NODE.getSvg()),
149+
Attribute.className("pathway-nodeIcon svgIcon " +
150+
SvgImage.PATHWAYS_NODE.getClassName()));
151+
nodeDiv.div(n -> n.append(node.getName()),
152+
Attribute.className("pathway-nodeName"), new Attribute("uuid", node.getUuid()));
153+
}, Attribute.className("pathway-node"));
154+
155+
// Add child node targets.
156+
final List<PathNodeList> targets = NullSafe.list(node.getTargets());
157+
if (targets.size() > 1) {
158+
// Add bezier curve to target set.
159+
appendBezier(svg, nodeDepth, sourceRowNum, rowNum.get(), width, height);
176160

177-
targetsOuterDiv.div(inner -> {
178-
targets.forEach(target -> {
161+
// Add target set.
162+
final String choiceCss = "pathway-nodeIcon svgIcon " +
163+
SvgImage.PATHWAYS_CHOICE.getClassName();
179164

180-
// final AtomicInteger rowNum = new AtomicInteger(parentRowNum);
181-
// Add bezier curve to target set.
182-
// final int targetRowNum =
183-
// rowNum.getAndIncrement();
165+
hb.div(targetsOuterDiv -> {
166+
targetsOuterDiv.div(icon -> icon.appendTrustedString(SvgImage.PATHWAYS_CHOICE.getSvg()),
167+
Attribute.className(choiceCss));
184168

169+
targetsOuterDiv.div(inner -> {
170+
targets.forEach(target -> {
185171

186-
final int startX = ((nodeDepth + 2) * INDENT) - 2;
187-
final int startY = (sourceRowNum * ROW_HEIGHT) + 8;
188-
final int endX = ((nodeDepth + 2) * INDENT) + 18;
189-
final int endY = (rowNum.get() * ROW_HEIGHT) + 8;
190-
Bezier.quadratic(svg, new Point(startX, startY), new Point(endX, endY));
191-
if (endX > width.get()) {
192-
width.set(endX);
193-
}
194-
if (endY > height.get()) {
195-
height.set(endY);
196-
}
172+
// Add quadratic curve to this node.
173+
appendQuadratic(svg, nodeDepth + 2, sourceRowNum, rowNum.get(), width, height);
197174

198-
addTargets(inner, target, svg, nodeDepth + 3, rowNum, width, height);
199-
});
200-
}, Attribute.className("pathway-targets-inner"));
175+
addTargets(inner, target, svg, nodeDepth + 3, rowNum, width, height);
176+
});
177+
}, Attribute.className("pathway-targets-inner"));
201178

202179

203-
}, Attribute.className("pathway-targets-outer"));
180+
}, Attribute.className("pathway-targets-outer"));
204181

205-
} else if (!targets.isEmpty()) {
206-
final PathNodeList target = targets.get(0);
207-
if (!target.getNodes().isEmpty()) {
208-
// Add bezier curve to target set.
209-
appendBezier(svg, nodeDepth, sourceRowNum, rowNum.get(), width, height);
182+
} else if (!targets.isEmpty()) {
183+
final PathNodeList target = targets.get(0);
184+
if (!target.getNodes().isEmpty()) {
185+
// Add bezier curve to target set.
186+
appendBezier(svg, nodeDepth, sourceRowNum, rowNum.get(), width, height);
210187

211-
addTargets(d, target, svg, nodeDepth + 1, rowNum, width, height);
212-
}
188+
addTargets(hb, target, svg, nodeDepth + 1, rowNum, width, height);
213189
}
214-
215-
}, Attribute.className("pathway-row"));
190+
}
216191
}
217192

218193
private void addTargets(final HtmlBuilder hb,
219-
final PathNodeList target,
220-
final HtmlBuilder svg,
221-
final int nodeDepth,
222-
final AtomicInteger rowNum,
223-
final AtomicInteger width,
224-
final AtomicInteger height) {
194+
final PathNodeList target,
195+
final HtmlBuilder svg,
196+
final int nodeDepth,
197+
final AtomicInteger rowNum,
198+
final AtomicInteger width,
199+
final AtomicInteger height) {
225200
if (!target.getNodes().isEmpty()) {
226-
// Add bezier curve to target set.
227-
// final int targetRowNum = rowNum.getAndIncrement();
228-
229-
230-
// final int startX = (nodeDepth * INDENT);
231-
// final int startY = (parentRowNum * ROW_HEIGHT) + 8;
232-
// final int endX = (nodeDepth * INDENT) + 18;
233-
// final int endY = (rowNum.get() * ROW_HEIGHT) + 8;
234-
// Bezier.quadratic(svg, new Point(startX, startY), new Point(endX, endY));
235-
//
236-
237-
// appendBezier(svg, nodeDepth, parentRowNum - 1, targetRowNum - 1, width, height);
238-
239201
final int sourceRowNum = rowNum.get();
240202

241203
// Add target set.
242204
final String choiceCss = "pathway-nodeIcon svgIcon " +
243205
SvgImage.PATHWAYS_SEQUENCE.getClassName();
244206

245-
// hb.div(outer -> {
246-
247207
hb.div(targetDiv -> {
248208
targetDiv.div(icon -> icon.appendTrustedString(SvgImage.PATHWAYS_SEQUENCE.getSvg()),
249209
Attribute.className(choiceCss));
250210

251-
// final int choiceRowNum = count.get();
252-
253211
targetDiv.div(o -> {
254212

255213
o.div(targetsDiv -> {
256214
target.getNodes().forEach(pathNode -> {
257-
// Add bezier curve to this node.
258-
259-
final int startX = ((nodeDepth + 1) * INDENT) - 2;
260-
final int startY = (sourceRowNum * ROW_HEIGHT) + 8;
261-
final int endX = ((nodeDepth + 1) * INDENT) + 18;
262-
final int endY = (rowNum.get() * ROW_HEIGHT) + 8;
263-
Bezier.quadratic(svg, new Point(startX, startY), new Point(endX, endY));
264-
if (endX > width.get()) {
265-
width.set(endX);
266-
}
267-
if (endY > height.get()) {
268-
height.set(endY);
269-
}
270-
271-
272-
// final int nodeDepth = depth + 1;
273-
// final int nodeRowNum = (count.get() + 1);
274-
// appendBezier(svg, nodeDepth, targetRowNum, nodeRowNum, width, height);
275-
276-
277-
// final int startX = (nodeDepth * INDENT) + 43;
278-
// final int startY = (parentRowNum * ROW_HEIGHT) + 13;
279-
// final int endX = (nodeDepth * INDENT) + 60;
280-
// final int endY = (parentRowNum * ROW_HEIGHT) + 13;
281-
// Bezier.quadratic(svg, new Point(startX, startY), new Point(endX, endY));
282-
283-
284-
// if (endX > width.get()) {
285-
// width.set(endX);
286-
// }
287-
// if (endY > height.get()) {
288-
// height.set(endY);
289-
// }
290-
215+
// Add quadratic curve to this node.
216+
appendQuadratic(svg, nodeDepth + 1, sourceRowNum, rowNum.get(), width, height);
291217

292218
// Add node div.
293219
append(targetsDiv,
@@ -303,7 +229,6 @@ private void addTargets(final HtmlBuilder hb,
303229

304230

305231
}, Attribute.className("pathway-target"));
306-
// }, Attribute.className("pathway-targets-outer"));
307232
}
308233
}
309234

@@ -313,10 +238,10 @@ private void appendBezier(final HtmlBuilder svg,
313238
final int endRow,
314239
final AtomicInteger width,
315240
final AtomicInteger height) {
316-
final int startX = (depth * INDENT) + 8;// + START_X_OFFSET;
317-
final int startY = (startRow * ROW_HEIGHT) - 4;// + START_Y_OFFSET;
318-
final int endX = (depth * INDENT) + 18;//END_X_OFFSET;
319-
final int endY = (endRow * ROW_HEIGHT) + 8;// + END_Y_OFFSET;
241+
final int startX = (depth * INDENT) + 8;
242+
final int startY = (startRow * ROW_HEIGHT) - 4;
243+
final int endX = (depth * INDENT) + 18;
244+
final int endY = (endRow * ROW_HEIGHT) + 8;
320245
Bezier.curve(svg, new Point(startX, startY), new Point(endX, endY));
321246

322247
if (endX > width.get()) {
@@ -327,6 +252,25 @@ private void appendBezier(final HtmlBuilder svg,
327252
}
328253
}
329254

255+
private void appendQuadratic(final HtmlBuilder svg,
256+
final int depth,
257+
final int startRow,
258+
final int endRow,
259+
final AtomicInteger width,
260+
final AtomicInteger height) {
261+
final int startX = (depth * INDENT) - 2;
262+
final int startY = (startRow * ROW_HEIGHT) + 8;
263+
final int endX = (depth * INDENT) + 18;
264+
final int endY = (endRow * ROW_HEIGHT) + 8;
265+
Bezier.quadratic(svg, new Point(startX, startY), new Point(endX, endY));
266+
if (endX > width.get()) {
267+
width.set(endX);
268+
}
269+
if (endY > height.get()) {
270+
height.set(endY);
271+
}
272+
}
273+
330274
private void enableButtons() {
331275
newButton.setEnabled(!readOnly);
332276
if (!readOnly) {

0 commit comments

Comments
 (0)