`

多页编辑器

 
阅读更多

      资源里存储了用户需要的信息,而编辑器是用户创建和修改资源最主要的方式,它是eclipse插件开发中最复

杂也是最主要的部分。

 

 

      编辑器必须实现org.eclipse.ui.IEditorPart接口,但通常继承子类org.eclipse.ui.part.EditorPart.

IEditorInput描述了编辑器的数据源。IPathEditorInput描述了数据源的格式,IFileEditorInput描述了基于

本地数据源。

 

      当编辑器被创建后,输入源是通过编辑器的init方法来设定的。可以通过getEditorInput方法来重新获取。

 

      MultiPageEditorPart,多页编辑器,每个页面都包含它自己的编辑器。FormEditor,它继承了MultiPageEditorPart类,用来实现表格编辑器。

 

创建编辑器,首先要在清单文件中声明扩展点,如下所示:

 <extension

         point="org.eclipse.ui.editors">

      <editor

            //与视图一样,一个编辑器对应一个class类,该类必须实现IEditorPart接口

            class="com.plugindev.addressbook.editors.AddressFormEditor"

            //实现了org.eclipse.ui.part.EditorActionBarContributor接口的全权限定名称

            contributorClass="com.plugindev.addressbook.editors.AddressFormEditorContributor"

            default="true"

            //编辑器左上角显示的图像

            icon="icons/editors/editor.gif"

            id="com.plugindev.addressbook.tableEditor"

            name="地址本编辑器"/>

   </extension>

 

 

FormEditor抽象类,提供了抽象方法addPages(),子类必须实现,用与为编辑器添加页面,

 

 

 

 

在打开编辑器时,必须同时制定输入的数据源

 

doubleClickAction = new Action() {

public void run() {

ISelection selection = viewer.getSelection();

AddressItem obj = (AddressItem)((IStructuredSelection)

selection).getFirstElement();

IWorkbenchPage page = PlatformUI.getWorkbench().

getActiveWorkbenchWindow().getActivePage();

try {

SimpleFormEditorInput input = new SimpleFormEditorInput(obj.getName());

page.openEditor(input, "com.plugindev.addressbook.tableEditor");

} catch (PartInitException e) {

System.out.println(e);

}

//为Editor增加的操作

}

};

 

 

org.eclipse.ui.forms.editor.FormEditor

 

在创建表格编辑器时,必须继承FormEditor类,而加入到FormEditor编辑器中的每个页面都必须继承FormPage

类,例如:

 

 

public class PageWithSubPages extends FormPage {

private FormEditor editor;

private CTabFolder tabFolder;

public PageWithSubPages(FormEditor editor) {

super(editor, "pageWithSub", Messages.PAGE_NAME_PAGEWITHSUB); 

this.editor = editor;

}

protected void createFormContent(IManagedForm managedForm) {

ScrolledForm form = managedForm.getForm();

FormToolkit toolkit = managedForm.getToolkit();

form.setText(Messages.PAGE_TITLE_PAGEWITHSUB); 

form.setBackgroundImage(ImageCache.getInstance().getImage

 

(ImageKeys.getImageDescriptor(ImageKeys.IMG_FORM_BG)));

GridLayout layout = new GridLayout();

layout.marginWidth = 10;

form.getBody().setLayout(layout);

tabFolder = new CTabFolder(form.getBody(), SWT.FLAT|SWT.TOP);

toolkit.adapt(tabFolder, true, true);

GridData gd = new GridData(GridData.FILL_HORIZONTAL);

gd.heightHint = 0;

tabFolder.setLayoutData(gd);

Color selectedColor = toolkit.getColors().getColor(FormColors.SEPARATOR);

tabFolder.setSelectionBackground(new Color[] {selectedColor, toolkit.getColors

 

().getBackground()}, new int[] {50});

 

}

}

 

 

 

主/从风格的页面

 

 

       MasterDetailsBlock类采用注册页面的方式来构建主从块,registerPages()方法用来为具体的从属页面注册

所允许的数据模型,从而建立起从属页面和数据模型的一一对应关系。

 

public class MasterDetailsPage extends FormPage {

 

        //该对象代表页面的MasterDetail部分

private ScrolledPropertiesBlock block;

 

public MasterDetailsPage(FormEditor editor) {

super(editor, "masterDetail", Messages.PAGE_NAME_MASTERDETAIL);

block = new ScrolledPropertiesBlock(this);

}

 

protected void createFormContent(final IManagedForm managedForm) {

final ScrolledForm form = managedForm.getForm();

form.setText(Messages.PAGE_TITLE_MASTERDETAIL); 

form.setBackgroundImage(null);

                //该方法非常重要,负责创建Master和Detail区域,尽量在最后调用

block.createContent(managedForm);

}

 

 

public IAction getTableAction(String workbenchActionId) {

return block.getTableAction(workbenchActionId);

}

}

 

具有MasterDetail模式的页面类都要继承自MasterDetailBlock类,并实现该类的3个方法:

1.createMasterPart

在该方法中创建master部分的控件

2.createToolBarActions

创建该页面的工具栏,本例有垂直和水平2个按钮

3.registerPages

注册master对应的detail部分,可以注册多个

 

 

 

public class ScrolledPropertiesBlock extends MasterDetailsBlock {

private FormPage page;

private TableViewer viewer;

private RemoveAddressListAction removeAction;

private Action vaction;

private Action haction;

public ScrolledPropertiesBlock(FormPage page) {

this.page = page;

}

 

protected void createMasterPart(final IManagedForm managedForm,

Composite parent) {

//final ScrolledForm form = managedForm.getForm();

FormToolkit toolkit = managedForm.getToolkit();

Section section = toolkit.createSection(parent, 

 

Section.DESCRIPTION|Section.TITLE_BAR);

section.setText(Messages.SCROL_BLOC_NAME); 

section.setDescription(Messages.SCROL_BLOC_DESCRIP); 

section.marginWidth = 10;

section.marginHeight = 5;

Composite client = toolkit.createComposite(section, SWT.WRAP);

GridLayout layout = new GridLayout();

layout.numColumns = 2;

layout.marginWidth = 2;

layout.marginHeight = 2;

client.setLayout(layout);

Table t = toolkit.createTable(client, SWT.NULL);

GridData gd = new GridData(GridData.FILL_BOTH);

gd.heightHint = 20;

gd.widthHint = 100;

gd.verticalSpan = 2;

t.setLayoutData(gd);

toolkit.paintBordersFor(client);

 

section.setClient(client);

 

                //代表master部分,且把该对象注册到managedForm中

final SectionPart spart = new SectionPart(section);

managedForm.addPart(spart);

viewer = new TableViewer(t);

viewer.addSelectionChangedListener(new ISelectionChangedListener() {

public void selectionChanged(SelectionChangedEvent event) {

                //当选择变化的时候,必须通过managedForm的该方法来发布事件,该事件接受的地方必须

                //在Detail页面进行

managedForm.fireSelectionChanged(spart, event.getSelection());

}

});

viewer.setContentProvider(new MasterContentProvider());

viewer.setLabelProvider(new MasterLabelProvider());

viewer.setInput(page.getEditor().getEditorInput());

      }

 

      protected void registerPages(DetailsPart detailsPart) {

detailsPart.registerPage(BasicAddressList.class, new BasicAddressListProperties());

detailsPart.registerPage(PhoneAddressList.class, new PhoneAddressListItemProperties());

detailsPart.registerPage(AreaAddressList.class, new AreaAddressListProperties());

}

}

 

Detail部分必须实现IDetailPage接口,主要是在createContents方法中创建Detail所需要使用的控件,并且

在selectChanged方法中处理当master对象选中事件发生的代码。

 

 

public class AddressListProperties implements IDetailsPage {

 

public AddressListProperties() {

}

 

public void initialize(IManagedForm mform) {

}

 

public void createContents(Composite parent) {

 

}

protected void createSection(Composite parent,

ArrayList<String> stringKeys, Map<String, Object[]>choiceKeysMap)

{

}

 

       //在此方法中处理mater选择事件

public void selectionChanged(IFormPart part, ISelection selection) {

IStructuredSelection ssel = (IStructuredSelection)selection;

if (ssel.size()==1) {

input = (AddressList)ssel.getFirstElement();

s1.setText(input.getName());

s1.setDescription(input.getDescription());

}

else

input = null;

update();

}

public void commit(boolean onSave) {

}

public void setFocus() {

choices[0][0].setFocus();

}

public void dispose() {

}

public boolean isDirty() {

return false;

}

public boolean isStale() {

return false;

}

public void refresh() {

update();

}

public boolean setFormInput(Object input) {

return false;

}

 

}

分享到:
评论

相关推荐

    tif图片多页面编辑器

    tif图片多页面编辑器

    swing类型多页面文本编辑器java源代码

    swing 类型的文本编辑器,附带实现背景音乐。可以实现多页面文本编辑器。

    Tif文件编辑器v0.6绿色中文免费版多页面TIF文件快速处理工具

    tif文件编辑器是一款多页面TIF文件快速处理工具,对扫描的多页TIF格式文件可进行编辑及格式转换,可以同时处理所有页面、可一次把所有页面导出为单个个图像文件。 基本简介 传真但面对多页格式的TIF文件束手无策吗...

    百度编辑器uedtior在一个页面实例化多个以及怎么简化编辑器

    百度编辑器uedtior在一个页面实例化多个以及怎么简化编辑器 公司让我替换前程序员做的网站 后台的编辑器 我用的是百度的 挺好用的 研究了几天 把自己的成果 分享一下

    oss-license-model-editor-eclipse-plugin:Eclipse多页编辑器插件,用于对开放源代码许可证进行建模和可视化

    ossLicenseModelEditor-eclipsePlugin Eclipse多页编辑器插件,用于对开放源代码许可证进行建模和可视化。

    Markdown编辑器原始编辑页面

    Markdown 是一种简单的、轻量级的标记...支持Markdown的编辑器太多,功能也不完全一致,有的是用来进行基本的写作,有的是用来写代码的,有的甚至只是博客平台配套的编辑器。本文按照编辑器的平台进行简单的介绍。 

    DXTB 多功能编辑器 v1.0

    使用说明: 1.将 DXControls.dll 文件放于空间根目录的bin文件夹里. 2.在需要用编辑器的ASPX页面代码...4.其中 id 为编辑器的ID,Path为编辑器所需资源(如JS)所在的文件夹,Height为编辑器高度,Width为编辑器宽度.

    多页文本编辑器 界面美观 功能强大

    多页文本编辑器,实现记事本功能,界面美观,非常好用

    解决文本编辑器展示样式不一致

    用在线编辑器或许都会存在一个问题,即内容发表后呈现的样式会与编辑时的不一样,原因是编辑器其实是个内嵌的iframe,它里面用的大多是浏览器默认的样式(ckeditor 在其中另外定义了字体以及ul, ol 的缩进值),而...

    百度富文本编辑器

    在很多后台发布消息的时候,总会用到富文本编辑器,这一款就是一款很好用的富文本编辑器!

    论文研究-基于Eclipse插件的scatter文件编辑器的设计与开发 .pdf

    基于Eclipse插件的scatter文件编辑器的设计与开发,江坤,张伟洋,文章介绍了一种scatter插件编辑器,编辑器主要采用Eclipse插件多页编辑器技术实现。在详细分析scatter文件的结构和特点基础上,编辑器利

    Net专版百度在线编辑器v1.2.4源码201291

    4、添加更多项编辑器属性到编辑器控件属性中,更方便通过编辑器控件订制编辑器UI 控件2012-08-29更新内容 1、调整编辑器版本为Ueditor1.2.3.0 UTF-8 2、控件属性增加SourceEditorFirst 3、调整控件版本号为1.2.4 4...

    Net专版百度在线编辑器 V1.2.1

    Net专版百度在线编辑器 V1.2.1 Ueditor特点: 1、体积小巧,性能优良,使用简单 2、分层架构,方便定制...3、修正母版页的内容页无法初始化编辑器的BUG 4、修正一个页面多次引用编辑器控件时编辑器样式多次注册的BUG

    Atom多标签文本编辑器v1.38.0Beta0英文安装版

    Atom编辑器是一款免费的windows代码编辑器,这款软件最大特点是采用Web技术构建桌面程序。Atom基于Chromium核心和Node.js,整个编辑器就是一个Web页面,通过Node.js实现本地文件系统访问、执行第三方进程等功能。...

    C# HHFeditor在线编辑器

    hhfeditor1.ascx是简洁版编辑器(适合网页前台客户简单留言等)、 hhfeditor2.ascx是功能版编辑器(适合论坛发帖等)、 hhfeditor3.ascx是全能版编辑器(适合后台管理时新闻发布或者网页编辑) 然后在需要调用的地方...

    FCK在线编辑器2.2版和2.4版.rar

    对于其他在线编辑器来说,这几乎是个很难解决的难题,因为在开启编辑器时需要装载太多的文件.比如CUTEEDITOR,虽然功能比FCKEDITOR还要强大,可是,它本身也够庞大了,至于FREETEXTBOX等,其易用性与FCKEDITOR相比,尚有差距...

    eWebSoft在线文本编辑器

    现在很多的在线文本编辑器,在提交后,如果服务器端较验没成功,点击“退回”时,原来编辑器中编辑的内容就会丢失,而eWebEditor会保持编辑后的状态,并且能够与Reset按钮同步Reset。 智能粘贴 eWebEditor具有三种...

    PDF文件编辑器

    许多人都希望能找到一个象编辑其它类型的文档的编辑器,事实上在Foxit PDF Editor出现之前,根本没有这样的工具。每一个PDF文件都包含很多页面,每一页包含各种可视对象,如文本对象、图形对象和图像对象。而每一个...

Global site tag (gtag.js) - Google Analytics