Subject: hw6 - how it all works and what is those Input,ContentProvider and LabelProvider
From: Kojarski Sergei (kojarski@ccs.neu.edu)
Date: Mon Dec 02 2002 - 17:57:10 EST
Hi everybody,
That's my view as it should work:
Inside your view createPartControl(..) method you do the following:
(see jfview.java)
1. Create viewer
2. Find what project is selected at this time in the Resource Navigator
(IProject).
3. Create Input object. As parameter to constructor you'd better send to
your Input class currently selected project (IProject object) from step 2
4. Create your DebugEventSetListener and give it as parameter to
constructor your Input object (from step 2). Make sure, that your
DebugEventSetListener, when creating StreamListeners will give them this
Input object, so each StreamListener know about Input object.
Make also sure, that each created StreamListener knows the project it
listens to (When you create StreamListener inside
DebugEventSetListener.handleDebugEvent(DebugEvent[] events), you can get
from each DebugEvent the project that causes this event:
Object x = DebugEvent.getSource();
String projectName;
if (x instanceof IProcess) {
projectName=((IProcess)x).getLaunch().getLaunchConfiguration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,"");
if (!projectName.equals("")) {
IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
... some stuff
//Having project here and having Input object passed as parameter to
constructor you can do:
StreamListener sl = new StreamListener(input,project);
..... make sl listener for stream events inside IProcess....
}
}
So, inside StreamListener, each time it receives an event you can say:
StreamListener (Input input,IProject project) {
this.input=input;
this.project=project;
}
//Yes, we changing Input!!!!
public void streamAppended(String text) {
Input.streamAppended(text,project)
}
5. Create and set into viewer ContentProvider & LabelProvider objects.
6. call viewer.setInput(<Input object from step 2>);
This will call ContentProvider.inputChanged() method with new Input.
YOUR CONTENTPROVIDER MUST LISTEN INPUT OBJECT. SEE EXAMPLE.
So, inside ContentProvider.inputChanged() you need to subscribe it for
events from Input object. FOR DETAILS SEE jfContentProvider.java
7. call DebugPlugin.addEventSetListener(<Your event set listener>);
Furthermore, your view can listen for selection changes in
Resource Navigator view, and each time it happens -> it should set new
IProject into Input element!!!
Your ContentProvider should be listener for Input events (see example).
So, each time Input.streamAppended(String text,IProject project) is called
(from StreamListener) -> we do smth like this:
Input.streamAppended(text,project) {
if (this.project==project) {
....Change the model....
....Notify content provider about changes in the model....
}
}
Let's assume that Inside your ContentProvider method update(Object obj) is
called that actually a notification about changes sent from
Input.streamAppended(..)
Inside ContentProvider.update(..) you actually update information in the
view...
(like saying viewer.add(Object[] new_elements));
Observe, that only ContentProvider and LabelProvider should know nature of
new_element object.
Actually, as response to call of viewer.setInput method viewer will call
1. first your ContentProvider.getElements -> to get an array of elements
that LabelProvider knows
2. your LabelProvider.getText(element) (or whatever) where element is one
of the guys from the array returned from
ContentProvider.getElements(input)
3. Viewer will show on the view information obtained from
LabelProvider (for each element!!!)
Your Input is the guy who is
1. Got initial violation information from log file
2. called from streamListeners when they get new text from stream
3. event source for ContentProvider
Your ContentProvider:
1. Listens for the Input object
2. Know how to transform Input object into array of elements readable by
LabelProvider
3. Can switch Input to some other project when user change selection in
Resource Navigator
Your LabelProvider
is the guy that simply knows how to convert each object
from array provided by ContentProvider to smth that can be shown in the
view.
Your viewer is just some standard viewer.
Your view is the top - most guy that arranges all of those guys in a right
order...
Maybe I missed smth. Let me know if smth is strange or wrong.
Sergei
This archive was generated by hypermail 2b28 : Mon Dec 02 2002 - 17:57:13 EST