Skip to content

Commit 2fbeba2

Browse files
authored
LinkBase refactoring (#327)
* LinkModel class created which is now used in LinkBase * Link creation/deletion moved to WorkbenchModel from WorkbenchView
1 parent a6f9444 commit 2fbeba2

File tree

7 files changed

+309
-187
lines changed

7 files changed

+309
-187
lines changed

services/web/client/source/class/qxapp/component/widget/TreeTool.js

+58-38
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,22 @@
1-
/* eslint no-warning-comments: "off" */
2-
31
qx.Class.define("qxapp.component.widget.TreeTool", {
42
extend: qx.ui.core.Widget,
53

64
construct: function(projectName, workbenchModel) {
75
this.base(arguments);
86

9-
let treeLayout = new qx.ui.layout.VBox(10);
10-
this._setLayout(treeLayout);
11-
127
this.set({
138
projectName: projectName,
149
workbenchModel: workbenchModel
1510
});
1611

17-
this.__buildLayout();
18-
this.buildTree();
12+
this._setLayout(new qx.ui.layout.VBox());
13+
14+
this.__tree = this._createChildControlImpl("tree");
15+
this.populateTree();
1916

2017
this.addListener("keypress", function(keyEvent) {
2118
if (keyEvent.getKeyIdentifier() === "F2") {
22-
let treeSelection = this.__tree.getSelection();
23-
if (treeSelection.length < 1) {
24-
return;
25-
}
26-
let selectedItem = treeSelection.toArray()[0];
27-
const selectedNodeId = selectedItem.getNodeId();
28-
if (selectedNodeId === "root") {
29-
return;
30-
}
31-
32-
let treeItemRenamer = new qxapp.component.widget.TreeItemRenamer(selectedItem);
33-
treeItemRenamer.addListener("LabelChanged", e => {
34-
const data = e.getData();
35-
const newLabel = data.newLabel;
36-
const nodeId = selectedItem.getNodeId();
37-
let nodeModel = this.getWorkbenchModel().getNodeModel(nodeId);
38-
nodeModel.setLabel(newLabel);
39-
}, this);
40-
const bounds = this.getLayoutParent().getBounds();
41-
treeItemRenamer.moveTo(bounds.left+100, bounds.top+150);
42-
treeItemRenamer.open();
19+
this.__renameItem();
4320
}
4421
}, this);
4522
},
@@ -62,27 +39,36 @@ qx.Class.define("qxapp.component.widget.TreeTool", {
6239
members: {
6340
__tree: null,
6441

65-
__buildLayout: function() {
66-
let tree = this.__tree = new qx.ui.tree.VirtualTree(null, "label", "children").set({
67-
openMode: "none"
68-
});
42+
_createChildControlImpl: function(id) {
43+
let control;
44+
switch (id) {
45+
case "tree":
46+
control = this.__buildTree();
47+
this._add(control, {
48+
flex: 1
49+
});
50+
break;
51+
}
6952

70-
this._removeAll();
71-
this._add(tree, {
72-
flex: 1
73-
});
53+
return control || this.base(arguments, id);
54+
},
7455

75-
this.__tree.addListener("dblclick", e => {
56+
__buildTree: function() {
57+
let tree = new qx.ui.tree.VirtualTree(null, "label", "children").set({
58+
openMode: "none"
59+
});
60+
tree.addListener("dblclick", e => {
7661
let selection = this.__tree.getSelection();
7762
let currentSelection = selection.toArray();
7863
if (currentSelection.length > 0) {
7964
let selectedRow = currentSelection[0];
8065
this.fireDataEvent("NodeDoubleClicked", selectedRow.getNodeId());
8166
}
8267
}, this);
68+
return tree;
8369
},
8470

85-
buildTree: function() {
71+
populateTree: function() {
8672
const topLevelNodes = this.getWorkbenchModel().getNodeModels();
8773
let data = {
8874
label: this.getProjectName(),
@@ -137,6 +123,40 @@ qx.Class.define("qxapp.component.widget.TreeTool", {
137123
return null;
138124
},
139125

126+
__getSelection: function() {
127+
let treeSelection = this.__tree.getSelection();
128+
if (treeSelection.length < 1) {
129+
return null;
130+
}
131+
132+
let selectedItem = treeSelection.toArray()[0];
133+
const selectedNodeId = selectedItem.getNodeId();
134+
if (selectedNodeId === "root") {
135+
return null;
136+
}
137+
138+
return selectedItem;
139+
},
140+
141+
__renameItem: function() {
142+
let selectedItem = this.__getSelection();
143+
if (selectedItem === null) {
144+
return;
145+
}
146+
147+
let treeItemRenamer = new qxapp.component.widget.TreeItemRenamer(selectedItem);
148+
treeItemRenamer.addListener("LabelChanged", e => {
149+
const data = e.getData();
150+
const newLabel = data.newLabel;
151+
const nodeId = selectedItem.getNodeId();
152+
let nodeModel = this.getWorkbenchModel().getNodeModel(nodeId);
153+
nodeModel.setLabel(newLabel);
154+
}, this);
155+
const bounds = this.getLayoutParent().getBounds();
156+
treeItemRenamer.moveTo(bounds.left+100, bounds.top+150);
157+
treeItemRenamer.open();
158+
},
159+
140160
nodeSelected: function(nodeId) {
141161
const dataModel = this.__tree.getModel();
142162
let nodeInTree = this.__getNodeInTree(dataModel, nodeId);
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
qx.Class.define("qxapp.component.workbench.LinkBase", {
22
extend: qx.core.Object,
33

4-
construct: function(representation) {
4+
construct: function(linkModel, representation) {
55
this.base();
66

7+
this.setLinkModel(linkModel);
78
this.setRepresentation(representation);
8-
9-
this.setLinkId(qxapp.utils.Utils.uuidv4());
109
},
1110

1211
events: {
1312
"linkSelected": "qx.event.type.Data"
1413
},
1514

1615
properties: {
17-
representation: {
18-
init: null
19-
},
20-
linkId: {
21-
check: "String",
16+
linkModel: {
17+
check: "qxapp.data.model.LinkModel",
2218
nullable: false
2319
},
24-
inputNodeId: {
25-
init: null,
26-
check: "String"
27-
},
28-
outputNodeId: {
29-
init: null,
30-
check: "String"
20+
21+
representation: {
22+
init: null
23+
}
24+
},
25+
26+
members: {
27+
getLinkId: function() {
28+
return this.getLinkModel().getLinkId();
3129
}
3230
}
3331
});

0 commit comments

Comments
 (0)