Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Access to SWT Widgets in Parts at runtime
Access to SWT Widgets in Parts at runtime [message #1016830] Thu, 07 March 2013 20:26 Go to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
Hi at all,

is it possible to get access to the SWT Widgets of a Part at runtime in a Handler class?

I have a Customer View that shall act as both, view and editor. I have text fields in there and I want the text fields to be disabled / not editable by default (act as View = read-only to prevent unintentional editing) and if I invoke the "Edit Customer" command (from the main menu or context menu from view) I want the text fields in that view to be editable and in addition show a 'Save' and 'Cancel' button in that part.

I use the following code to make sure the command can be executed and the right part is active:

@CanExecute
	public boolean canEditCustomer(@Optional @Named(IServiceConstants.ACTIVE_PART) MApplicationElement part) {
		// true if Active part is of type "customerDetails"
		if (part.getElementId().equals("com.im.ticd.app.part.customerDetails"))
			return true;
		else
			return false;
	}


But how - if at all - can I get access to my text fields in that part. I cannot cast to that implementation class as it doesn't inherit from MPart, so I think accessor methods like getNameTextField() won't work.

Any ideas on how to accomplish this?

Thx, Marina
Re: Access to SWT Widgets in Parts at runtime [message #1016911 is a reply to message #1016830] Fri, 08 March 2013 08:09 Go to previous messageGo to next message
Bastian Wagenfeld is currently offline Bastian WagenfeldFriend
Messages: 183
Registered: January 2013
Senior Member
Hi Marina,

can you send an event from your Handler, so your View/Part gets notified. I suppose the Part includes the SWT widgets and can control them. So it should just set them to be editable. Or did i misunderstand something?

Best regards
Bastian
Re: Access to SWT Widgets in Parts at runtime [message #1016913 is a reply to message #1016911] Fri, 08 March 2013 08:12 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Using MPart.getObject() will return the part implementation. You need to cast this to your concrete implementation and it should work out for you.

Of course you should do an instanceof check prior casting to ensure the command handler is not executed from another part.
Re: Access to SWT Widgets in Parts at runtime [message #1016961 is a reply to message #1016913] Fri, 08 March 2013 11:11 Go to previous message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
This sounds exactly like what I was looking for. I've been looking through all those MPart methods, but the JavaDoc isn't really helpful for them, because it's only the default EMF docs.

I will try that and post later whether it worked for me.
Thx for now.

[UPDATE]
Works perfectly, thanks.

[Updated on: Fri, 08 March 2013 12:29]

Report message to a moderator

Previous Topic:Launching from PDE with -console
Next Topic:Keybindings in Kepler's compat layer
Goto Forum:
  


Current Time: Fri Apr 26 21:54:21 GMT 2024

Powered by FUDForum. Page generated in 0.03128 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top