(4)创建SearchViewLabelProvider类 
package com.xqtu.google.views;   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 getColumnImage(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:               return "";         }              }   }  
l         TableViewer对象调用SearchViewLabelProvider来设置表格每行的列文本内容,第一列是搜索标题,第二列是URL 
l         SearchViewLabelProvider扩展LabelProvider,实现ItableLabelProvider接口,根据提供的元素对象为每列提供文本和/或图像 
l         由于表格不提供图像,getColumnImage方法返回null;getColumnText根据不同的列索引返回不同的文本内容 
(5)创建BrowserView视图 
package com.xqtu.google.views;   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.google.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_VERTICAL | GridData.FILL_HORIZONTAL                 | GridData.FILL_VERTICAL));         browser.setUrl("http://blog.csdn.net/chenyun2000");             }       public void setFocus() {          browser.setFocus();     }   }  
l         BrowserView视图的创建方法和SearchView视图是一样的:扩展ViewPart基类,实现createPartControl和setFocus方法 
l         在createPartControl方法中创建一个SWT浏览器控件,用来显示用户在搜索结果表中选中的Web页面 
(6)将SearchView和BrowserView集成到透视图中 
package com.xqtu.google;   import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory;   import com.xqtu.google.views.BrowserView; import com.xqtu.google.views.SearchView;   public class GooglePerspective implements IPerspectiveFactory {      public static final String ID = "com.xqtu.google.GooglePerspective";       public void createInitialLayout(IPageLayout layout) {                 layout.setEditorAreaVisible(false);         layout.addView(SearchView.ID, IPageLayout.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         在透视图类GooglePerspective的createInitialLayout方法中调用addView方法添加视图到透视图中 
l         addView方法需要四个参数,分别是: 
Ø         视图的唯一标识,与plugin.xml中定义的一致 
Ø         参考部分中的相对位置,可以是IPageLayout.TOP、IPageLayout.BOTTOM、IPageLayout.LEFT或IPageLayout.RIGHT 
Ø         参考部分中当前占有的空间比率,值范围在0.05f和0.95f之间 
Ø         参考部分唯一标识;例中使用的是编辑区域(IPageLayout.ID_EDITOR_AREA)  
 
  |