RCP II:扩展通用工作台(2-2)

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方法返回nullgetColumnText根据不同的列索引返回不同的文本内容

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.youkuaiyun.com/chenyun2000");
    
    
        
    
    
    }
    
    
 
    
    
    public void setFocus() {
    
    
 
    
    
        browser.setFocus();
    
    
    }
    
    
 
    
    
}
    
    

l         BrowserView视图的创建方法和SearchView视图是一样的:扩展ViewPart基类,实现createPartControlsetFocus方法

l         createPartControl方法中创建一个SWT浏览器控件,用来显示用户在搜索结果表中选中的Web页面

6)将SearchViewBrowserView集成到透视图中

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         在透视图类GooglePerspectivecreateInitialLayout方法中调用addView方法添加视图到透视图中

l         addView方法需要四个参数,分别是:

Ø         视图的唯一标识,与plugin.xml中定义的一致

Ø         参考部分中的相对位置,可以是IPageLayout.TOPIPageLayout.BOTTOMIPageLayout.LEFTIPageLayout.RIGHT

Ø         参考部分中当前占有的空间比率,值范围在0.05f0.95f之间

Ø         参考部分唯一标识;例中使用的是编辑区域(IPageLayout.ID_EDITOR_AREA

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值