Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How Can i Reach Dynamicly Created Text ?
How Can i Reach Dynamicly Created Text ? [message #1011402] Tue, 19 February 2013 14:15 Go to next message
serhat gezgin is currently offline serhat gezgin
Messages: 239
Registered: January 2013
Location: Izmir
Senior Member
Hi,

I'm new on Eclipse rcp and i little confused.

I have two part (part1, part2). And i want to;

on button click action from part1, i need to reach part2's Text field and change its text

but i can't do. What i must use anyone can help me ?
Re: How Can i Reach Dynamicly Created Text ? [message #1011417 is a reply to message #1011402] Tue, 19 February 2013 14:44 Go to previous messageGo to next message
Simon Scholz is currently offline Simon Scholz
Messages: 73
Registered: April 2012
Location: Germany
Member
Hello serhat,

by part you mean org.eclipse.ui.IViewPart?
Could you please explain your use case?
A button in a view, which modifies text in a second view sound a bit weird.
I guess I could offer a better solution for you, if you would tell us more about for intent.

Best regards,

Simon
Re: How Can i Reach Dynamicly Created Text ? [message #1011438 is a reply to message #1011417] Tue, 19 February 2013 15:03 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezgin
Messages: 239
Registered: January 2013
Location: Izmir
Senior Member
Hi,

Part mean, Part in PartSashContainer.

and i have two part in that PartSashContainer.

When part1's button clicked , part2's Text must contain Part1's Text value.

But i cant reach Part2's Text component in Part1's Button Action.

Part1;

generateButton = new Button(top, SWT.PUSH);
		generateButton.setText("Generate Ecore");
		generateButton.setLayoutData(gridData);

		Listener listener = new Listener() {
			public void handleEvent(Event event) {
				if (event.widget == generateButton) {
					// here u must reach Part2's Text component                                                 //and change its value.
				}
			}
		};



Re: How Can i Reach Dynamicly Created Text ? [message #1011561 is a reply to message #1011438] Tue, 19 February 2013 19:54 Go to previous messageGo to next message
Omer Gillani is currently offline Omer Gillani
Messages: 22
Registered: May 2012
Junior Member

Serhat,

Get your desire ViewPart by Id by using following code. Cast it and call your method to update text.

public static IViewPart getView(IWorkbenchWindow window, String viewId) {
    IViewReference[] refs = window.getActivePage().getViewReferences();
    for (IViewReference viewReference : refs) {
        if (viewReference.getId().equals(viewId)) {
            return viewReference.getView(true);
        }
    }
    return null;
}


-Omer Gillani
Re: How Can i Reach Dynamicly Created Text ? [message #1011594 is a reply to message #1011561] Tue, 19 February 2013 21:39 Go to previous messageGo to next message
serhat gezgin is currently offline serhat gezgin
Messages: 239
Registered: January 2013
Location: Izmir
Senior Member
after i reach my part how can i reach Text (SWT components) ?
Re: How Can i Reach Dynamicly Created Text ? [message #1011748 is a reply to message #1011594] Wed, 20 February 2013 07:34 Go to previous messageGo to next message
Omer Gillani is currently offline Omer Gillani
Messages: 22
Registered: May 2012
Junior Member


After getting your ViewPart. Type cast it to your ViewPart class

like...
....
if (event.widget == generateButton) {
IViewPart viewPart = getView(window, viewId);
MyViewPart myViewPart = (MyViewPart)viewPart;
myViewPart.updateText(...);					
}
...


Make the method in your MyViewPart class that will update the text.

-Omer Gillani
Re: How Can i Reach Dynamicly Created Text ? [message #1011775 is a reply to message #1011748] Wed, 20 February 2013 08:32 Go to previous message
Simon Scholz is currently offline Simon Scholz
Messages: 73
Registered: April 2012
Location: Germany
Member
Hello serhat,

I am still not sure what you want to archieve with this "button and text thing", so I´ll just give you the easiest solution I can imagine:

        Button button = new Button(parent, SWT.PUSH);
        button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Button button = (Button) e.widget;
                IViewPart findView = PlatformUI.getWorkbench()
                        .getActiveWorkbenchWindow().getActivePage()
                        .findView("Part 2 viewId, which is defined in the plugin.xml");
                if (findView instanceof Part2View) {
                    Part2View part2View = (Part2View) findView;
                    part2View.setText(button.getText());
                }
            }

        });


An even better approach would be to make Part1 offer an org.eclipse.jface.viewers.ISelectionProvider and register Part2 as org.eclipse.ui.ISelectionListener.
Will there be several buttons in Part1, which set the text in Part2?
Why don´t you use a TreeViewer or something simimar?
A TreeViewer for instance is a ISelectionProvider itself, so that it can easily pass it´s selection to other Parts, which are registered as ISelectionListener.

Let me know, if you want to know more about Eclipse´s SelectionServices or if the solution above satisfies you.

Best regards,

Simon
Previous Topic:Add MPart in all MPerspective in eclipse Juno
Next Topic:Hide perspective using xml ?
Goto Forum:
  


Current Time: Sun Sep 21 12:12:00 GMT 2014

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

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