How to change the label of a ToolControlImpl [message #1033286] |
Thu, 04 April 2013 00:17  |
Eclipse User |
|
|
|
I have a ToolControlImpl added to the trim for various views, and I'm able to retrieve it with the model service. Now I want to do a couple things with it, and I haven't been able to find out how:
I need to get a reference to the Control that was created as a child of 'parent' in ToolControlImpl#createPartControl. It happens to be a Label in my case. I don't see any way to get access to it. I tried casting the retrieved model object to its actual class, which is a subclass of ToolControlImpl, but the cast fails. WHat I'm trying to do is dynamically change the label text and the listener on the Label inside the ToolControlImpl.
If I call getWidget() on the ToolControlImpl, I get a Composite, but its list of children is empty. Yet a Label was added to it when the part control was created. Here's the code for my ToolControlImpl:
public class CustomButton1 extends ToolControlImpl {
private Label label;
@PostConstruct
public void createPartControl(Composite parent) {
GridLayoutFactory.fillDefaults().applyTo(parent);
label = new Label(parent, SWT.NONE);
label.setText("Label");
GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER);
label.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
System.err.println("MOUSE MOVE Label 1");
}
});
}
public Control getControl() {
return this.label;
}
}
[Updated on: Thu, 04 April 2013 00:19] by Moderator
|
|
|
Re: How to change the label of a ToolControlImpl [message #1033748 is a reply to message #1033286] |
Thu, 04 April 2013 11:43   |
Eclipse User |
|
|
|
So I think the problem is that the model service is not returning the proper ToolControlImpl. In the model editor, I add a ToolControl to
Application -> Windows -> Trimmed Window -> TrimBars -> Window Trim -> Toolbar .
I also add a ToolControl to
Application -> Windows -> Trimmed Window -> Main Menu -> Controls -> Perspective Stack -> Perspective -> Controls -> PartSashContainer -> Part Stack -> Part -> Toolbar
for each of three Parts.
But when I search via the model service, I only find the ToolControl added to the toolbar of the TrimBars, and not the ones added to the toolbar of each Part, even though the Part's ToolControls are displayed and active.
I tried searching by element type
elements = modelService.findElements(application, null, ToolControlImpl.class, null)
This returns only the TrimBars ToolControl.
by ID:
elements = modelService.findElements(application, controlId ,null, null)
This returns the TrimBars ToolControl when I give it that ID, empty list when I give it the ID of either of the Part ToolControl items.
and by tag
elements = modelService.findElements(application, null, null, tags)
This returns an empty list when I specify a tag that was assigned to one of the Part's ToolControl items.
|
|
|
|
|
|
Re: How to access the wrapped Control of a ToolControlImpl [message #1038228 is a reply to message #1038196] |
Wed, 10 April 2013 11:25  |
Eclipse User |
|
|
|
Thanks for the reply, Sopot. The ToolControl in the TrimBars' ToolBar actually is returned by ModelService#findElements, even with the Application instance as the search root. It's the ToolControl in the Window's ToolBar that I was unable to find this way. I tried with the Application and the Window as the root.
Regarding what I subclassed, I think it's a bit different than what you commented on. I extended ToolControlImpl (let's call it MyToolControl), and I specified MyToolControl as the class for the ToolControl I added to the ToolBar via the model editor. Then I retrieve an MToolControl instance from the model (by walking the model starting with the Window), and call getObject() on this MToolControl instance. The object returned is an instance of MyToolControl, which is what I was after. What I was doing wrong before was retrieving ToolControlImpl from the model (via the Model Service) instead of retrieving MToolControl and calling getObject(). I assume this approach is not problematic?
|
|
|
Powered by
FUDForum. Page generated in 0.07464 seconds