Reputation: 864
I am new to Eclipse RCP and I am working on an application (Eclipse 4), I have multiple parts within I display data from different sources. I would like to add a menu that displays a Dialog that offers the possibility to select dynamically the data sources that the user wants. When the options are selected I would like to re-instantiate the Part's class using the options as parameters and refresh the view. Is that possible ?
My Part's createComposite method :
@PostConstruct
public void createComposite(Composite parent) {
Composite composite = new Composite(parent, SWT.EMBEDDED);
parent_C = parent;
Frame frame_1 = SWT_AWT.new_Frame(composite);
JPanel mainPanel = new JPanel();
BorderLayout layout = new BorderLayout();
mainPanel.setLayout(layout);
/* Layout Definition */
}
I would like to add another parameter to the createComposite Method that indicates the options :
@PostConstruct
public void createComposite(Composite parent, String[] options) {
/*Code Here*/
}
The Value of the String array changes when the user validate the options from the Menu. When the users validate his options the part's class should be called with the new options.
Is there any way to do this ? Thank You
Upvotes: 0
Views: 90
Reputation: 921
Instead of recreating the entire part again, it will be easier to refresh of re-create the content inside the part itself. That should be possible by either disposing the content of the part and recreate the content again under that container, or by refresh mechanism of any table/table viewer.
Upvotes: 0
Reputation: 111142
To do this you need to get the values in the IEclipseContext
of the part being created. One way to do this is to subscribe to the UIEvents.Context.TOPIC_CONTEXT
event and modify the new part's context in that event.
@Inject
IEventBroker eventBroker;
eventBroker.subscribe(UIEvents.Context.TOPIC_CONTEXT, this::handleContextEvent);
private void handleContextEvent(Event event)
{
Object origin = event.getProperty(UIEvents.EventTags.ELEMENT);
if (!(origin instanceof MPart))
return;
MPart part = (MPart)origin;
// TODO check this is the MPart you want
Object context = event.getProperty(UIEvents.EventTags.NEW_VALUE);
if (!(context instanceof IEclipseContext))
return;
IEclipseContext newContext = (IEclipseContext)context;
newContext.set("nameForOptions", .... options ....);
}
I have used a name for the options here so you would use @Named
:
@PostConstruct
public void createComposite(Composite parent, @Named("nameForOptions") String[] options)
Upvotes: 1