Skip to content

Commit 95b8e9c

Browse files
committed
added 'paste' and 'select' panes
1 parent ce86936 commit 95b8e9c

2 files changed

Lines changed: 91 additions & 12 deletions

File tree

Tutorial-o-Matic/src/main/groovy/ToM.groovy

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class ToM{
2626
goto : 'ToM_goto' ,
2727
action : 'ToM_menuAction',
2828
groovy : 'ToM_groovy' ,
29+
copyPaste : 'ToM_copy' ,
30+
select : 'ToM_select' ,
2931
]
3032

3133
static final exeHowIcons = ['emoji-1F507', 'emoji-2328', 'emoji-1F5B1']
@@ -91,6 +93,12 @@ class ToM{
9193
case styles.groovy:
9294
addGroovyPane(myPanel, tutNode)
9395
break
96+
case styles.copyPaste:
97+
addPastePane(myPanel, tutNode)
98+
break
99+
case styles.select:
100+
addSelectPane(myPanel, tutNode)
101+
break
94102
default:
95103
ui.informationMessage('node style not defined')
96104
break
@@ -102,9 +110,14 @@ class ToM{
102110
tomui.adjustHeight(myPanel, doClear)
103111
}
104112

113+
def static fillPage(myP, nodo, included, doClear){
114+
def nextNodes = getNextTutNodes(nodo, included)
115+
fillContentPane(myP, nextNodes, doClear)
116+
}
117+
105118
// end:
106119

107-
// region: component node to tutorial
120+
// region: components nodes to tutorial
108121

109122
def static addNotes(myP, nodos){
110123
nodos.each{n ->
@@ -137,12 +150,6 @@ class ToM{
137150
myP.add(nextButtonPanel, tomui.GBC)
138151
}
139152

140-
def static fillPage(myP, nodo, included, doClear){
141-
def nextNodes = getNextTutNodes(nodo, included)
142-
fillContentPane(myP, nextNodes, doClear)
143-
}
144-
145-
146153
def static addShowMenuItemPane(myP, nodos){
147154
nodos.findAll{n -> toma.hasAction(n)}.each{nodo ->
148155
def infoAccion = toma.getActionInfoMap(nodo)
@@ -249,8 +256,7 @@ class ToM{
249256
}
250257

251258
def static addGroovyPane(myP, nodoT){
252-
//TODO: addGroovyPane
253-
def enabled = enableBttn(nodoT)
259+
def enabled = !disableBttn(nodoT)
254260
nodoT.children.findAll{n -> WSE.isGroovyNode(n)}.each{nodo ->
255261
def script = WSE.scriptFromNode(nodo)
256262
if (script){
@@ -283,7 +289,7 @@ class ToM{
283289
def msgHtml = nodo.note?tomui.getHtmlFromNote(nodo):null
284290
def bttnText = 'Execute'
285291
def bttnToolTip = "Click to execute the command on the selected nodes"
286-
def enabled = enableBttn(nodo)
292+
def enabled = !disableBttn(nodo)
287293
def exeHow = exeActionsHow(nodo)
288294
def bttnAction = { e ->
289295
def bttn = e.source
@@ -306,11 +312,74 @@ class ToM{
306312
}
307313
}
308314

309-
def static enableBttn(nodo){
315+
def static disableBttn(nodo){
310316
def iconos = nodo.icons.icons
311-
return !iconos.contains('emoji-1F56F')
317+
return iconos.contains('emoji-1F56F')
312318
}
313319

320+
def static addPastePane(myP, nodoSource){
321+
def enabled = !disableBttn(nodoSource)
322+
def msgHtml = "Click to paste the example nodes to the selected node"
323+
def bttnText = "Insert nodes"
324+
def bttnToolTip = "Click to paste the example nodes to the selected node"
325+
def bttnAction = { e ->
326+
def bttn = e.source
327+
bttn.setEnabled(enabled)
328+
def nodoTarget = c.selected
329+
nodoSource.children.each{n ->
330+
nodoTarget.appendBranch(n)
331+
}
332+
def idSource = ( nodoSource.findAll() - nodoSource )*.id
333+
def idTarget = ( nodoTarget.findAll() - nodoTarget )*.id
334+
for (def i = 0; i < idSource.size() ; i++){
335+
myP.idDictionary[ idSource[i] ] = idTarget[i]
336+
}
337+
}
338+
def buttonPanel = tomui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, false)
339+
myP.add(buttonPanel, tomui.GBC)
340+
}
341+
342+
def static addSelectPane(myP, nodo){
343+
def enabled = !disableBttn(nodo)
344+
def msgHtml = "Click to select the node(s)"
345+
def bttnText = "Select node(s)"
346+
def bttnToolTip = "Click to select the nodes"
347+
def bttnAction = { e ->
348+
def bttn = e.source
349+
bttn.setEnabled(enabled)
350+
def nodos = []
351+
(nodo.findAll()- nodo).each{ n ->
352+
//get list of clones ids
353+
uiMsg("n.Id ${n.id}")
354+
def clonesIds = n.getNodesSharingContent()*.id
355+
uiMsg("clonesIds $clonesIds")
356+
//intersect with list of dist.keySet
357+
def keySet = myP.idDictionary.keySet()
358+
uiMsg("keySet $keySet")
359+
def sourceId = keySet.intersect(clonesIds)
360+
uiMsg("sourceId $sourceId")
361+
//get Target id
362+
def targetId = sourceId?myP.idDictionary[ sourceId[0] ]:null
363+
uiMsg("targetId $targetId")
364+
//get node
365+
def targetNode = targetId?c.selected.map.node(targetId):null
366+
uiMsg("targetNode $targetNode")
367+
//add node to nodes list
368+
if(targetNode) nodos += targetNode
369+
uiMsg("nodos $nodos")
370+
}
371+
//select nodes list
372+
uiMsg("nodos $nodos")
373+
c.select(nodos)
374+
}
375+
def buttonPanel = tomui.getButtonPanel(msgHtml,bttnText,bttnToolTip, bttnAction, false)
376+
myP.add(buttonPanel, tomui.GBC)
377+
}
378+
379+
// end:
380+
381+
// region: Getting map
382+
314383
def static getMapFromPath(filePath, withView){
315384
if(exists(filePath)){
316385
def m = c.mapLoader(filePath)
@@ -323,4 +392,13 @@ class ToM{
323392

324393
// end:
325394

395+
// region: help / debug
396+
397+
def static uiMsg(texto){
398+
// ui.informationMessage(texto.toString())
399+
}
400+
401+
// end:
402+
403+
326404
}

Tutorial-o-Matic/src/main/groovy/ToM_ui.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class ToM_ui{
182182
// background: Color.gray
183183
){}
184184
contentPane.addComponentListener(new CustomComponentListener())
185+
contentPane.metaClass.idDictionary = [:]
185186
def panel = swing.panel(
186187
layout: new GridBagLayout(),
187188
preferredSize: new Dimension(minContentPaneWidth, maxContentPaneHeigth),

0 commit comments

Comments
 (0)