Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 91
Registered: ‎02-04-2009
My Device: Not Specified

TreeField of ObjectChoiceFields

In the Permissions editor (Options -> Advanced Options -> Applications -> Edit Permissions), the widgets for Connections, Interactions, and User Data look like combinations of TreeFields and ObjectChoiceFields.  I'd like to have that same functionality in my application, but I'm not sure how to deal with a tree of fields.  Does anyone have an sample code for something like that?

 

I know how to create a TreeField, populate it with objects, and add it to my screen.  I have the TreeFieldCallback set up too, so the only part I'm missing is how to draw the ObjectChoiceField from the drawTreeItem callback.  How can I tell the ObjectChoiceField to paint itself?

 

public void drawTreeItem(TreeField tree, Graphics graphics, int node, int y, int width, int indent) {

Object cookie = tree.getCookie(node);

if (cookie instanceof ObjectChoiceField) {

ObjectChoiceField choice = (ObjectChoiceField) cookie;

// Paiting the field should happen here

}

}

 

This has been discussed here before, but the only examples that people have shown involve trees of strings:

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=5227

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800441/How_To_...

 

Thanks for the help. 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: TreeField of ObjectChoiceFields

It looks like no one else replied and I was kind of curious so let me take a shot at this.

I took a look at my treefield code and  offhand i don't see why you can't just

call paint on your field passing the gr context you already have?

You may want to subclass the field or play some games with the gr contexts

but it shouldn't be all that different from the gr.drawText() or similar

last-line you would have for a string. 

Developer
Posts: 91
Registered: ‎02-04-2009
My Device: Not Specified

Re: TreeField of ObjectChoiceFields

[ Edited ]

Thanks for the quick reply.  I'm getting closer, but it's still not working.  I subclassed ObjectChoiceField (because paint was protected), had my paint call super.paint, but it still doesn't work quite right.  The tree is on the screen, but there are blank lines instead of choice fields.

 

class MyObjectChoiceField extends ObjectChoiceField

{

public void paint(Graphics graphics) {

super.paint(graphics);

}

}

 

class MyScreen extends Screen implements TreeFieldCallback

{

MyScreen() {

MyObjectChoiceField choice1 = new MyObjectChoiceField();

choice1.setLabel("Choice 1");

choice1.setChoices(new Object[] {"One", "Two"});

 

MyObjectChoiceField choice2 = new MyObjectChoiceField();

choice2.setLabel("Choice 2");

choice2.setChoices(new Object[] {"Three", "Four"});

 

TreeField tree = new TreeField(this, TreeField.FOCUSABLE);

int node = tree.addChildNode(0, choice1);

tree.addChildNode(node, choice2);

add(tree);

}

 

public void drawTreeItem(TreeField tree, Graphics graphics, int node, int y, int width, int indent) {

Object cookie = tree.getCookie(node);

if (cookie instanceof MyObjectChoiceField) {

MyObjectChoiceField choice = (MyObjectChoiceField) cookie;

choice.paint(graphics);

}

}

}

 

 

 

Message Edited by almeida on 03-25-2009 05:18 PM
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: TreeField of ObjectChoiceFields

Well, you need to convince it to lay itself out and make sure the graphics origins

are right etc. You could perhaps start with some simple things where you insert your own code into

the paint method and draw on the gr context. Step through it in debugger and you can

see the parameters being used even if you can't see source code in the api code.

 

 

Sorry, I don't have a known good example but the simple approach should work if you

can take care of all the details. Not sure if there is a good or best way depending on

what you want to do. I'm actually making some of my own lower level "components"

that just draw on one big bitmap, input is still a bit of an unknown but I have decent

focus selection, so I'm kind of curious to know how this works out.

 

 

 

Developer
Posts: 91
Registered: ‎02-04-2009
My Device: Not Specified

Re: TreeField of ObjectChoiceFields

This level of GUI work is a bit beyond my abilities and probably way beyond the project's scope right now, so I think I'll just hold off on TreeFields and just do something basic.  Thank you for your help so far.  I'll resurrect this thread when I pick up this stuff again.  If you, or anyone else, figure anything out, please let me know.