0

Assume I have

combo(["A","B","C","D"])

How can I select item B. Is there a property like selectIndex(2) or selectItem("B") ?

I could not find such property.

robert
  • 1,921
  • 2
  • 17
  • 27
  • I've answered assuming combo is declared as I've given, but if you are looking for something else (maybe something with figures) please let me know, it isn't clear from the question. – Mark Hills Dec 09 '14 at 14:56
  • Thanks for the answer but this was not the question. If I load A, B, C in a combo then by default A is selected (visible beside the arrow) once visible. I want that B is selected once it become visible while maintaining the A..C ordering – robert Dec 09 '14 at 15:01

2 Answers2

1

I will assume you have a datatype declared like this:

data C = combo(list[str] items);

and a value like this (to line up with your question):

rascal>c = combo(["A","B","C","D"]);
C: combo(["A","B","C","D"])

Given that, there are several ways you can get at the second item in the list. If you have given a field name to the data held in combo (above, this is items), you can just say this (remembering that lists in Rascal are 0-indexed):

rascal>c.items[1];
str: "B"

If you haven't given it a name, and don't want to, you can also do this, using a match:

rascal>if (combo(l) := c) println(l[1]);
B

The variable l will be bound to the list held inside combo; this new variable is then available inside the if. Of course, in both of these cases you would want to make sure the list is long enough, so you don't get an error trying to read the second element. You could also do the following, which uses a nested list match:

rascal>if (combo([s1,s2,s*]) := c) println(s2);
B

In this case, s1 will be found to the first element of the list, s2 to the second, and s to anything (0 or more, which is what the * means) that follows. Since this will only match if the list held in combo is at least length 2, you wouldn't need to separately check for this.

Mark Hills
  • 1,028
  • 5
  • 4
0

Looks like the first entry is hard-wired to be selected by default: https://github.com/cwi-swat/rascal/blob/master/src/org/rascalmpl/library/vis/figure/interaction/swtwidgets/Combo.java#L40

So the only way to select the item you want is to create the combo with the first item the one you want selected.

Jurgen Vinju
  • 6,393
  • 1
  • 15
  • 26