You need to implement two methods to control the CARMA
view, createFramelist
and createViewer
.
About this task
To implement this code, you use the FrameList
and Viewer
class.
The FrameList
is a list of frames that allow navigation
through the view. The Viewer
contains the structure
that you see in the view. For the frame list, you create a frame list
for a tree viewer, which looks similar to the default CARMA
Repositories view. For the viewer, you set the content
provider to the default CARMA Content Provider.To implement the Java™ methods:
Procedure
- Open the
CARMADeveloperView
class by expanding,
in the Package Explorer view, com.ibm.carma.plugin.view
> view
,
and double-clicking CARMADeveloperView
.
- In the editor, you want to add the
createFrameList
method.
This method first creates the
TreeViewerFrameSource
,
then create a new
FrameList
, and then set the source
to the
TreeViewerFrameSource
. Use the following sample
code to implement this functionality:
protected FrameList createFrameList()
{
/*
* This code manages the front-back buttons in the view
* Will take the default tree frame listener from eclipse.
*/
TreeViewerFrameSource source = new TreeViewerFrameSource((TreeViewer)getViewer());
/* This is a TreeViewer.
* Create the frame list.
*/
FrameList frameList = new FrameList(source);
source.connectTo(frameList);
return frameList;
}
- Next, you want to overwrite the
createViewer
so
that it creates the CARMATreeViewer
with the default CARMAContentProvider
.
Use the following sample code to implement this functionality:
protected StructuredViewer createViewer(Composite parent)
{
/*
* Create the structure that you want to be present in the view here.
* The example uses the CARMA tree model like the CARMA Repositories view.
*/
CARMATreeViewer viewer = new CARMATreeViewer(parent);
return viewer;
}
- Ensure that all classes and packages that are mentioned
in the source are included in the import commands at the beginning
of the class. The easiest way to do this is to right click in the
editor and select Source > Organize
Imports.
Be sure to verify that the following
classes were all imported:
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.framelist.FrameList;
import org.eclipse.ui.views.framelist.TreeViewerFrameSource;
import com.ibm.carma.ui.view.BaseCarmaBrowser;
import com.ibm.carma.ui.widget.CARMATreeViewer;
- Save your changes and debug any errors.
- Finally, you must add the appropriate extension and configure
it. In the Plug-in Editor, select the Extensions tab
at the bottom of the editor. Click Add. Filter
for the extension:
org.eclipse.ui.views
. When it
appears, select it, and click OK. You should
see the extension that is listed in the left panel.
- Open the
plugin.xml
tab
from the bottom menu of tabs. Configure the plugin.xml
file
as follows: <plugin>
<extension
point="org.eclipse.ui.views">
<category
name="BootCamp"
id="carma.bootcamp.ui">
</category>
<view
name="CARMA Developer View"
icon="icons/sample.gif"
category="carma.bootcamp.ui"
class="view.CARMADeveloperView"
id="view.CARMADeveloperView">
</view>
</extension>
</plugin>
Note: The attributes that are
used in the
plugin.xml
file are described in more
detail below:
- Category: the attributes that are used with this markup
correspond to the labeling and view of the Show View dialog
box
- Name: the name that appears as the enclosing category in
the Show View dialog box
- Id: the id of the category that the view should display
under when searching for it in the Show View dialog box
- View: the attributes that are used with this markup correspond
to the labeling, appearance, and location of the source for the actual
view you created
- Name: the label that is given to the view, this name appears
in the tab that is associated with the view, and also in the Show
View dialog box
- Icon: the image to associate with the view, this is shown
in the tab associated with the view, and also next to its label in
the Show View dialog box
- Category: the id of the category that the view should display
under when searching for it in the Show View dialog box
- Class: the Java class
you wrote that controls the view, you should provide the enclosing
package as well
- Id: the unique identifier for the view