(4) Creating a SearchViewLabelProvider class
Package com.xqtu.igoogle.view;
Import org.eclipse.jface.viewers.itablelabelprovider;
Import org.eclipse.jface.viewers.labelprovider;
Import org.eclipse.swt.graphics.image;
Import com.google.soap.search.googlesearchResulTelement;
Public Class SearchViewLabelProvider Extends LabelProvider Implements
Itablelabelprovider {
Public Image getColumnImnImage (Object Element, Int ColumnIndex) {
Return NULL;
}
Public String getColumnText (Object Element, INT ColumnIndex) {
Switch (columnIndex) {
Case 0:
Return (GooglesearchResulTelement) Element. Gettitle ();
Case 1:
Return (GooglesearchResulTelement) Element .geturl ();
DEFAULT:
""; "
}
}
}
l TableViewer object calls SearchViewLabelProvider to set the column text content of the table, the first column is the search title, the second column is the URL
l SearchViewLabelProvider Extended LabelProvider, implements the ITABLABELPROVIDER interface, providing text and / or images for each column according to the elements provided
l Since the form does not provide an image, the getColumnImage method returns null; getColumnText returns different text content according to different column indexes.
(5) Creating a BrowserView view
Package com.xqtu.igoogle.view;
Import org.eclipse.swt.swt;
Import org.eclipse.swt.browser.browser;
Import Org.eclipse.swt.Layout.Griddata;
Import org.eclipse.swt.Layout.GridLayout;
Import org.eclipse.swt.widgets.composite;
Import org.eclipse.ui.part.viewpart;
Public class browserview extends viewpart {
Public static final string id = "com.xqtu.igoogle.views.browserview";
Public Static Browser Browser;
Public void createpartControl (Composite Parent) {
GridLayout GridLayout = New GridLayout ();
GridLayout.NumColumns = 1;
GridLayout.Marginheight = 5;
GridLayout.marginwidth = 5;
Parent.setLayout (GridLayout);
Browser = New Browser (PARENT, SWT.NONE);
Browser.setLayOutdata (New GridData (GridData.grab_horizontal | griddata.grab_vertage | griddata.fill_horizontal
GridData.fill_vertage);
Browser.SETURL ("http://blog.9cbs.net/chenyun2000");
}
Public void setfocus () {
Browser.Setfocus ();
}
}
l BrowserView view creation method and searchView view are the same: extending the ViewPart base class, implementing createPartControl and SetFocus method
l Create a SWT browser control in the createPartControl method to display the web page selected in the search results table.
(6) Integrate SearchView and BrowserView into the perspective
Package com.xqtu.google;
Import org.eclipse.ui.ipagelight;
Import Org.eclipse.ui.iPerspectiveFactory;
Import com.xqtu.google.views.browserview;
Import com.xqtu.igoogle.views.searchview;
Public Class GooglePective Implements IPerspectiveFactory {
Public static final string id = "com.xqtu.google.googlePerspective";
Public void createinitialLayout (iPageLayout Layout) {
Layout.seteditorAreavisible (FALSE);
Layout.addview (searchview.id, ipagelight.bottom, new float (0.60)
.floatvalue (), ipagelayout.id_editor_area;
Layout.addview (browserview.id, ipagelayout.top, new float (0.40)
.floatvalue (), ipagelayout.id_editor_area;
}
}
l In the createInitialLayout method of the Perspective Chart GooglePective, call the AddView method to add a view to the perspective
l The AddView method requires four parameters, namely:
Ø The unique identifier of the view, the consistency of the definition in plugin.xml
Ø Relative position in the reference section, can be ipagelight.top, ipagelight.bottom, ipagelight.right or ipagelightout.right
Ø The current occupied spatial ratio in the reference section, between 0.05F and 0.95F
Ø Reference section unique identifier; use in the example is the editing area (ipagellout.id_editor_area)