Activate part warning - eclipse-rcp

My application is a perspective with two views.
When starting it, the application shows viewA with a table, the viewB is hidden.
When I select an item from the table, opens the viewB, send the item you selected to viewB, and hides the viewA.
I can perform these actions but on the console I have the following warning:
"Prevented recursive attempt to activate part "viewB" while still in the middle of activating part "viewA".
Some help to solve this warning?.

Are you doing the work to display "viewB" inside the button click event method? If so, you probably need to queue that work up for the UI thread to do later on by wrapping it in:
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
// Your UI update code.
}
};

Related

Eclipse RCP Updating Toolbar and Menu Entries

I am using menu entries and toolbar buttons to link them to actions (AbstractHandler).
For example, I can connect to or disconnect from hardware. If I connect, there are menu and toolbar entries dependent on the connection state. They update after I click in the view or do another action within the view. For UX improvements it would be nice if they update after the action was executed.
Is there a way to update the view programmatically or do I have to implement this differently?
The connect handler is implemented very simple:
public class ConnectHandler extends AbstractHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Connect to hardware.
return null;
}
}
The menu and toolbar entries are defined in the plugin.xml.
I tried some stuff with the ICommandService and refreshElements, but was unsuccessful.

How to pass Activity type to a method in Xamarin.Android?

All my activities inherit from BaseActivity. In BaseActivity I have the following method:
protected void GoToPreviousActivity(Activity)
{
StartActivity(typeof(Activity));
Finish();
}
When I click the toolbar's back button of every activity I want to go back to the previous activity, like that:
toolbar.NavigationOnClick += delegate
{
this.GoToPreviousActivity(PreviousActivity);
};
How can I do that?
As #Mathias Kirkegaard commented, Android provides its own navigation back and it is very reliable (you can even manipulate the back stack (see the link at the bottom about what is it))
Having said that, if you want to use your method every time the user clicks on the back button you can override the OnBackPressed method, and provide your own implementation there.
In your case:
public override void OnBackPressed()
{
//base.OnBackPressed(); <-- this will use the default behaviour to navigate back, and if I understood correctly, you don't want to use it
GoToPreviousActivity(PreviousActivity);
}
Even though you can do that and it is valid, it is discouraged, you can read more about how Android manages the back navigation here:
https://developer.android.com/guide/components/activities/tasks-and-back-stack
and here is a good article on how to implement a custom back navigation: https://developer.android.com/guide/navigation/navigation-custom-back
should use OnBackPressed methode on click
base.OnBackPressed();

IInputSelectionProvider not considered by listeners of RCP SelectionService

I have a RCP application with different views. The views should interact with each other through the Eclipse SelectionService.
In view 1 I have added a SelectionListener with
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this.listener);
In view 2 I have added a SelectionProvider with
getSite().setSelectionProvider(this);
To get this working, I implemented the methods from the IInputSelectionProvider in view 2. When I run my program, view 1s selection listener is not invoked. After debugging,
I found out that view 1 is not added in the list of listeners of view 2. In view 2 I have a method
private ListenerList listenersList = new ListenerList();
#Override
public void addSelectionChangedListener(ISelectionChangedListener iselectionchangedlistener) {
// TODO Auto-generated method stub
listenersList.add(iselectionchangedlistener);
}
which adds listeners to the IInputSelectionProvider. My question is: Who should call this method. My understanding is that Eclipse SelectionService should does this with
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this.listener);
But it doesn't work. Do I have to fill the listenerList by myself? If yes, why do I have to use the SelectionService at all?
Or do I have to iterate through the list of listeners by calling any other method and not using the list at all? Because if I inspect the ISelectionService object
ISelectionService service = getSite().getWorkbenchWindow().getSelectionService();
I see all the listeners.
But they are not part of the listenerList above.
The addSelectionChangedListener is called every time a view gets activated and removed when a view is not longer active. This means: If View A is active and 'setSeletion' is called, all views which are listening are notified. If these views by themselves call 'setSelection' nothing happens. No notification is started.

MVP, best practice for passing row events back to the presenter

I have a CellTable within a GWT MVP view and want to inform the presenter when certain actions are taken on a row. For example a popup menu is presented for a row, and an action (Delete/Edit/etc.) selected. There's obviously a SelectionModel that is available via HasData, but how would I use this to pass back the action 'action'.
Is there a standard interface (like HasData) that I could use to pass back to the Presenter?
Usually in GWT MVP View exposes an object that can register event handlers: usually thay come in form of HasXyxHandlers, like HasClickHandlers or HasChangeHandlers.
In case of CellTable it's named differently: SelectionModel. Just implement in View a method that returns it:
SelectionModel<YourClass> getSelectionModel();
then Presenter calls this method and registers itself:
final SelectionModel<YourClass> selectionModel = view.getSelectionModel();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
#Override
public void onSelectionChange(SelectionChangeEvent event) {
YourClass selectedObject = selectionModel.getSelectedObject();
// do something with selectedObject
}
});
Thinking about this more, I could be over engineering it. If I have one popup menu that I reuse in the view, and have the presenter listen to click events on the menu (rather than the CellList), then I can query the CellList selection model through within the handler for the button(s).

Android's viewDidLoad and viewDidAppear equivalent

Does Android have an equivalent to Cocoa's viewDidLoad and viewDidAppear functions?
If not, then how would I go about performing an action when a View appears? My app is a tabbed application, in which one of the tabs is a list of forum topics. I would like the topic list to be refreshed every time the view appears. Is such a thing possible in Android?
The Activity class has onCreate and onResume methods that are pretty analagous to viewDidLoad and viewDidAppear.
Activity.onResume
EDIT
To add to this, since some have mentioned in the comments that the view tree is not yet fully available during these callbacks, there is the ViewTreeObserver that you can listen to if you need first access to the view hierarchy. Here is a sample of how you can use the ViewTreeObserver to achieve this.
View someView = findViewById(R.id.someView);
final ViewTreeObserver obs = someView.getViewTreeObserver();
obs.addOnPreDrawListener(new OnPreDrawListener() {
public boolean onPreDraw() {
obs.removeOnPreDrawListener(this);
doMyCustomLogic();
return true;
}
});
onResume() is more like viewCouldAppear. :) public void onWindowFocusChanged(boolean) is the closest to viewDidAppear. At this point within the activity lifecycle you may ask the view about its size.
From my limited, nascent understanding of Android, you implement viewDidLoad type functionality in the onCreate method of your Activity:
onCreate(Bundle) is where you
initialize your activity. Most
importantly, here you will usually
call setContentView(int) with a layout
resource defining your UI, and using
findViewById(int) to retrieve the
widgets in that UI that you need to
interact with programmatically.
The equivalent for viewDidAppear is closer to the onResume method:
Called after
onRestoreInstanceState(Bundle),
onRestart(), or onPause(), for your
activity to start interacting with the
user. This is a good place to begin
animations, open exclusive-access
devices (such as the camera), etc.