Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Interaction of Views and Actions - triggering actions from views & accessing views from actions
Interaction of Views and Actions - triggering actions from views & accessing views from actions [message #460042] Tue, 12 December 2006 04:46 Go to next message
Eclipse UserFriend
Hi all!

I am a RCP-newbie and I am developing my first RCP-application which is
based on the "RCP Mail Template".

The application is working as it should but I am not sure if I have
developed the interaction between views and actions in a right
appropriate, rcp-like way.

This posting might be a little bit long but I want to give you a
detailed description of my problem and my questions related to the problem.

First let me describe the application:
The application can search persons, identified by there lastname, in
one not closeable view.
The search field plus search-button and the search result is located in
one view.
By distinct interactions at the search result (doubleclick or selecting
person plus pressing enter or by selecting the person or clicking a
button in the toolbar)
every person will be opened their own view.

The "search-view" is displayed on the left side and the person-detail
views are displayed on the right side.
Every person gets its own "detail-view". If one person has already been
openend its view will get the focus and will be displayed.
If there are more than one detail-views they will be displayed with tabs.

Let me explain you how I have solved the interaction between the
search-view and the detail-views:
1. creating the initial gui - the Perspective class:
The SearchPersonView is added to the layout and closeable will be set to
false.
An IFolderLayout is added to the layout and one Placeholder for the the
PersonDetailView is added to it.

2. OpenPersonViewAction:
The OpenPersonViewAction that is based on the RCP-Mail Templates
OpenViewAction is registered at the ApplicationActionBarAdvisor and is
added to the fileMenu and to the toolbar.

3. Implementation of the interaction:
3.1 The process of opening or setting the focus to an already opened
view is triggered by:
- Selecting one person and clicking the button in the toolbar or the
item in the filemenu
- doubleclicking at one person
- or selecting on person an pressing enter

The process of opening or setting the focus on a view is done by the
OpenPersonViewAction.
If one Person has been doubleclicked or has been selected and enter has
been pressed a new instance of the OpenPersonViewAction will be created
in the SearchPersonView and the OpenPersonViewAction's run method will
be called.

<code snipplet>
private void showPersonView() {
OpenPersonViewAction openViewAction = new
OpenPersonViewAction(getSite().getWorkbenchWindow(), "Open Another
Message PersonView", PersonView.ID);
openViewAction.run();
}
</code snipplet>

--> my question:
Is that the right way to trigger an action from a view
or is there a way to register an action to the "triggering" components
(doubleclick, selecting and pressing enter)?

3.2 Opening and handling the persondetail views:
The process of opening and handling the persondetail views is
implemented in the OpenPersonViewAction's run method:

First an instance of the SearchPersonView is fetched and the selected
person is retrieved:
<code snipplet>
SearchPersonView searchPersonView = (SearchPersonView)
iWorkbenchWindow.getActivePage().showView(SearchPersonView.I D);
Person selectedPerson = searchPersonView.getSelectedPerson();
</code snipplet>

To handle multiple PersonDetailViews a static Integer secondaryId and a
static registering and deregistering of Persons to secondaryIds is
implemented at the PersonDetailView. Registering and deregistering is
done by a static final map in the PersonDetailView.
<code snipplet>
private static final Map<Person, String> openViews = new HashMap<Person,
String>();
</code snipplet>

By getting the secondaryId for a certain Person its PersonDetailView is
fetched and the selected person is given to the PersonDetailView and a
"updatePersonWidgets()" method is called.
<code snipplet>
String secondaryId = PersonView.getViewSecondaryId(selectedPerson);
if (secondaryId == null) {
secondaryId = PersonView.registerViewWithSecondaryId(selectedPerson);
}

PersonView personView = (PersonView)
WorkbenchWindow.getActivePage().showView(viewId,
secondaryId, IWorkbenchPage.VIEW_ACTIVATE);

personView.setPerson(selectedPerson);
personView.refreshPersonFromBackend();
personView.updatePersonWidgets();
</code snipplet>

The person's PersonView is opened or given focus with following
statement, by opening the view with a viewId and a
secondary id.
<code snipplet>
PersonView personView = (PersonView)
iWorkbenchWindow.getActivePage().showView(viewId,
secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
</code snipplet>

My question:
This solutions is working but I am note sure if this is the appropriate,
nice rcp-like solution.
It seems to be too much hardcoded/hardwired - isn't there another
solution to access Views from an Action and to access/trigger
Actions from Views?

Another thing, is there a possibility to connect Actions to certain
UI-commands, e.g. triggering an action when one person of the
searchresult has been doubleclicked or one person has been selected and
enter has been pressed? Also the possibility of enabling/disabling
actions based on conditions of a view (e.g. "no person selected" means
showPersonView-Action disabled)

I did not find any other recommended way or pattern to solve that problem.
In all sample programms I have looked at had been single views that
"listen" to another editor or view but there was no example that shows
how to control several instances of the same view with different
model-data e.g. persons and how to connect that to certain actions.

I hope I am not the only one with such a problem and maybe someone can
give me a hint.

Many thanks in advance and kind regards,
Robert Reinhardt
Re: Interaction of Views and Actions - triggering actions from views & accessing views from acti [message #460049 is a reply to message #460042] Tue, 12 December 2006 09:33 Go to previous messageGo to next message
Eclipse UserFriend
Just as to opening Views: I have used a system similar to yours, but disliked it, and I think it is
not "Eclipsically-correct" (and may even be an "anti-pattern"). What I prefer to do now is to have
some sort of data-model (often a singleton "manager" class) that provides a listener interface. Then
the action (wherever located) would update the data-model, which would in turn signal its listeners,
one of which is the View, which then responds. That way, the View can be coded indep. of the action
(and vice versa).

(If you can make you actions work via selections, you could save yourself a small bit of work by
using the Eclipse ISelectionProvider / ISelectionChangedListener system as your listener-system.)

HTH,
Paul
Re: Interaction of Views and Actions - triggering actions from views & accessing views from acti [message #460054 is a reply to message #460042] Tue, 12 December 2006 13:08 Go to previous message
Eclipse UserFriend
So there are 2 patterns that might be able to help you. The first one
is the selection service:

See http://www.eclipse.org/articles/Article-WorkbenchSelections/ article.html

Your SearchPerson view (which is probably using a JFace viewer (list,
tree, table, etc)) would register a selection provider. That means
while your SearchPerson view is active, its selection is posted to the
workbench window selection service.

Then your action would look at the selection service to find the current
selection (which would be the selected person) to open the view on.

A common approach is to just have your person view monitor the selection
service. If the incoming current selection is your Person object, then
your view would view that person. If the incoming selection is not
understood, just show the last useful selection. This way you actually
don't need a special action.

The other pattern, if you want an action based on the current selection
is to use a context menu/org.eclipse.ui.popupMenus ... register a
context menu in your SearchPerson view and tie it to an objectClass.

See
http://www.eclipse.org/articles/Article-action-contribution/ index.html
for an explanation of different kinds of actions.


Later,
PW
Previous Topic:Plugin-driven status line
Next Topic:Global Event Service
Goto Forum:
  


Current Time: Mon Apr 14 16:32:48 EDT 2025

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

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

Back to the top