Script Example - Pop-Up Menu to Set Attributes

Script Example - Pop-Up Menu to Set Attributes

Postby krumriver » Mon Nov 11, 2013 3:48 pm

Does someone have a Groovy code example that will display a pop-up window with a pull down menu that allows me to set attributes for a node and a text entry box? I'm trying to recreate something similar to the Quinbus note taking structure. Thanks very much....
krumriver
 
Posts: 7
Joined: Fri Nov 01, 2013 5:32 am

Re: Script Example - Pop-Up Menu to Set Attributes

Postby moebiuus » Wed Nov 13, 2013 10:40 am

Hi,
you can find a script for a change attributes dialog in my note taking post:
http://sourceforge.net/apps/phpbb/freeplane/viewtopic.php?f=3&t=491&p=3661#p3661

The dialog is created dynamically, based on the attributes a node has. Also the comboboxes with the available values are dynamically populated, based on all different values of the same attribute appearing in the map.

To add multiple attributes to a node, you can also use the select_template script. If a template node has the attribute: "OnlyAttributes=yes", the template script will just add the attributes to the target node.

BR
moebiuus
 
Posts: 6
Joined: Mon Jul 29, 2013 6:39 pm

Re: Script Example - Pop-Up Menu to Set Attributes

Postby quinbus » Fri Mar 14, 2014 4:57 pm

Sorry so much that I've been absent without leave. I'm recovering from a devastating illness in the family that has prevented all but critical communications. I'm coming out of those dark woods now and can rejoin the human race.

Well, at least the human walk. :roll:

Here's what I have--as I've said before, it's not pretty and I'm sure there are programmers that will have ideas about how to fix it up. I use conditional styles triggered off the values in the "Type" attribute to provide the necessary formatting. You can change the values in the "assignees" column to reflect your own regular team, as well as the values you want to use for node types.

Hoping you enjoy long strings of spaghetti, because that's the only coding technique I know :?

Q!
Code: Select all
// @CacheScriptContent(true)
import groovy.swing.SwingBuilder
import java.awt.FlowLayout as FL
import javax.swing.BoxLayout as BXL
import javax.swing.JFrame

def s = new SwingBuilder()
s.setVariable('myDialog-properties',[:])
def vars = s.variables
def assignments = ['Bill', 'Brian', 'Ed', 'Jaap', 'John', 'Tammy']
def dial = s.dialog(title:'Type and Assignments', id:'myDialog', minimumSize: [300,50], modal:true, locationRelativeTo:ui.frame, owner:ui.frame, defaultCloseOperation:JFrame.DISPOSE_ON_CLOSE, pack:true, show:true) {

    panel() {
   
   boxLayout(axis:BXL.Y_AXIS)
   
   panel(alignmentX:0f) {
    flowLayout(alignment:FL.LEFT)
    label('Type')
    comboBox(id:'type', items:['WebVideo', 'WebPage', 'Todo', 'PrivateNode', 'Book', 'Quote', 'LocalURL'])
     }

   panel(alignmentX: 0f) {
      assignments.eachWithIndex { assignee, i ->
      checkBox(id: assignee, text: assignee)
      }
   }

   panel(alignmentX:0f) {
        flowLayout(alignment:FL.LEFT)
        label('Other assignees')
        textArea(id:'textArea', lineWrap: "true", wrapStyleWord: "true", columns:25, rows:2)
        }   


   panel(alignmentX:0f) {
        flowLayout(alignment:FL.LEFT)
        label('Date ')
        textArea(id:'date', lineWrap: "true", wrapStyleWord: "true", columns:6, rows:1)   
        }
      
   panel(alignmentX:0f) {
            flowLayout(alignment:FL.RIGHT)
            button(action: action(name: 'OK', defaultButton: true, mnemonic: 'O',
                                  closure: {vars.ok = true; dispose()}))
            button(action: action(name: 'Cancel', mnemonic: 'C', closure: {dispose()}))
        }

    }
}
if (vars.ok){

   node["Type"] = vars.type.selectedItem
   node["Date"] = vars.date.text
   node["Complete"] = 0
   node["Completed"] = " "
   
   attributes.set("Assigned", ( assignments.findAll { vars[it].selected } ).join(" ") + " " + vars.textArea.text )

   if ( vars.type.selectedItem == "Todo" ) {
   attributes.set("Assigned", ( assignments.findAll { vars[it].selected } ).join(" ") + " " + vars.textArea.text )
   }

   }
quinbus
 
Posts: 228
Joined: Wed Jul 27, 2011 4:04 am


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 1 guest