- 浏览: 241552 次
- 性别:
- 来自: 济南
文章分类
最新评论
-
heartneo:
破解原作真是太厉害了。
Spket 1.6.18的简单破解 -
mwp1115:
谢谢,现在官方的demo代码还是jdk1.2的
Swing JTreeTable范例 -
bulktree:
Spket 谢谢了,js格式化 行宽太小了,你这个帮了我很大的 ...
Spket 1.6.18的简单破解 -
REGAL2T:
谢谢, 可以使用了
Spket 1.6.18的简单破解 -
wuwei1616:
我想问下lz 我生成了 wsdl文件 我用客户端去调用 怎么总 ...
调用CXF工具 生成 WSDL
Eclipse Tip: Define Custom Content Types to Identify Your Data Files
- 博客分类:
- Eclipse Plugins Dev
【转自】http://www.developer.com/java/data/article.php/3648736/Eclipse-Tip-Define-Custom-Content-Types-to-Identify-Your-Data-Files.htm
In desktop environments, the typical approach for identifying a file's content is to check its extension. You're familiar with the myriad of three-letter extensions used by the ever-growing number of desktop applications you run across. You also know that at times, the extension "gets it wrong"—even though its name ends in a ".doc", it may not be the text document format you expect.
In the Eclipse Workbench, the traditional approach also has been to assign a unique extension to each unique file format. The editor used to view and edit these files is then bound to that extension. This approach becomes problematic when a generic extension is used to represent an entire family of file formats. For example, the preferred extension for XML files is ".xml" regardless of what kind of data they contain. This way, generic applications capable of viewing XML files can immediately recognize the file as XML. However, this does not work for specialized Eclipse editors built to handle a specific type of XML content.
Defining Content Types
Listing 1: Declaring a content type extension for XML files containing the "apples" element.
<extension point="org.eclipse.core.contenttype.contentTypes">
<content-type base-type="org.eclipse.core.runtime.xml"
file-extensions="xml"
id="ca.ecliptical.examples.contenttype.apples"
name="Apples File"
priority="normal">
<describer class="org.eclipse.core.runtime.content
.XMLRootElementContentDescriber">
<parameter name="element"
value="apples">
</parameter>
</describer>
</content-type>
</extension>
Starting with version 3.0, Eclipse provides a mechanism to programmatically identify file types based on their actual content. The org. eclipse. core. contenttype. contentTypes extension point can be used to define a content type described by a "describer," which is a class capable of recognizing specific types of content given an input stream. Editors designed to work with a specific content type can be bound to it instead of a file extension.
Although it is possible to create and contribute custom content describers, the default ones often will do the job. Eclipse provides a BinarySignatureDescriber, which uses the file's binary signature to identify its content, and a XMLRootElementContentDescriber, which checks an XML document's root element (or its DTD). Both can be parameterized with application-specific values.
Listing 1 illustrates how to define a custom content type to represent XML files whose root element is "apples". See the Resources section for the entire source code for this example.
Note: The content type is narrowed to files whose extension is ".xml". This makes the identification process more efficient—it allows the platform to exclude this content type from consideration for files whose extensions don't match.
Binding Editors to Content Types
Listing 2: Declaring the "ApplesEditor" bound to the "apples" content type.
<extension point="org.eclipse.ui.editors">
<editor name="Apples Editor"
icon="icons/sample.gif"
contributorClass="org.eclipse.ui.texteditor
.BasicTextEditorActionContributor"
class="ca.ecliptical.examples.contenttype.apples
.ApplesEditor"
id="ca.ecliptical.examples.contenttype.apples
.ApplesEditor">
<contentTypeBinding
contentTypeId="ca.ecliptical.examples.contenttype
.apples">
</contentTypeBinding>
</editor>
</extension>
Once you define a content type for your data format, you can bind the appropriate editor to it. In the attached example, you have two sample XML editors. The ApplesEditor is used for XML files whose root element is "apples"; the OrangesEditor handles XML files with "oranges" in their root. Listing 2 shows an extension declaring the ApplesEditor and binding it to the "apples" content type.
Note: As far as the editors are concerned, the file extension no longer matters. Any file extension binding is relegated to the content type rather than the editor.
When you run the example as an Eclipse application, use the New XML file wizard in the Sample Wizards category to create a new file with either "apples" or "oranges" as its root element. Based on this, the workbench then opens either the ApplesEditor or the OrangesEditor, respectively. Also, when you right-click an XML file in the Resource Navigator, you will see the appropriate default editor in the "Open With" sub-menu.
Resources
* Eclipse Platform Plug-in Developer Guide: Content types
* Documentation for the org.eclipse.core.runtime.contentTypes extension point
* Example plug-in source (Eclipse 3.2 project)
About the Author
Peter Nehrer is a software consultant specializing in Eclipse-based enterprise solutions and J2EE applications. He is the founder of Ecliptical Software Inc. and a contributor to several Eclipse-related Open Source projects. He holds an M.S. in Computer Science from the University of Massachusetts at Amherst, MA. Peter can be reached at pnehrer AT eclipticalsoftware DOT com.
由于时间问题,也没来得及整理,直接就copy过来了。我自己简单试了一下,挺简单。
plugin.xml
<?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.4"?> <plugin> <extension point="org.eclipse.ui.editors"> <editor name="Sample XML Editor" extensions="test" icon="icons/sample.gif" contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor" class="contest.editors.XMLEditor" id="contest.editors.XMLEditor"> <contentTypeBinding contentTypeId="ca.ecliptical.examples.contenttype.apples"> </contentTypeBinding> </editor> </extension> <extension point="org.eclipse.core.contenttype.contentTypes"> <content-type base-type="org.eclipse.core.runtime.xml" file-extensions="test" id="ca.ecliptical.examples.contenttype.apples" name="Apples File" priority="normal"> <describer class="org.eclipse.core.runtime.content.XMLRootElementContentDescriber"> <parameter name="element" value="apples"> </parameter> </describer> </content-type> </extension> </plugin>
界面效果:
contents type
file associations
发表评论
-
目录树的生成
2011-09-22 08:54 1391项目上线需要生成个目录树文件,本来可以用dos的tree就搞定 ... -
WTP Facet 之 AddFilter
2010-06-11 14:22 1259做插件开发的人员都知道,如果你不晓得该使用那个Eclipse提 ... -
Properties文件的读写 : Properties操作示例
2010-04-21 14:19 1526package properties; import j ... -
wizardPage参考
2010-04-15 13:23 2512插件向导开发最好的例子莫过于Eclipse中本身一些向导,但如 ... -
如何访问当前Project???
2010-04-14 08:27 1124【转】http://wiki.eclipse.org/FAQ_ ... -
How to create dynamic web project using facets
2010-03-22 08:51 1486To create a blank faceted proje ... -
Introduction to the XSD Editor(XML Schema Editor)
2010-03-13 16:46 1353By Trung Ha August 30, 2006 ... -
同类编辑器只能打开一个
2010-02-23 13:28 1292在(http://sxw7362693.iteye.com/b ... -
通过事件驱动,创建不同的部件
2010-02-20 15:43 1072非常easy的东西,就是先dispose再create。 ... -
Tree Check 带复选框的树
2009-08-25 13:23 7699在SWT/JFace中,带复选框树最好使用Contain ... -
Swing JTreeTable范例
2009-08-21 13:48 3037由于工作需要,看了一点Swing的JtreeTable的实现。 ... -
SWT/JFACE——toolbar/toolItem
2009-04-23 22:47 10811工具栏通常有两种: toolbar、coolBar。两者的区 ... -
SWT-Menu篇
2009-04-23 17:12 3304今天用到Menu,本以为小菜一碟,都是老掉牙的东东了还不简单。 ... -
Eclipse.ini参数意义
2009-04-16 17:34 825eclipse.ini内存设置各参数含义 ... -
Editor的脏处理
2009-03-11 21:05 1716做编辑器Editor插件,肯定离不开对“脏”的处理。以前虽然也 ... -
SWT-Table按“行“进行编辑
2009-03-11 10:24 4693package table; /* * 通常在一个表 ... -
读取properties文件
2008-11-27 10:26 1839在 武晨伟的博客 http://blog.csdn.n ... -
移除Builders
2008-08-15 09:36 903public static void removeBuild ... -
Java项目classPath的添加
2008-08-15 09:28 3640// import org.eclipse.jem.workb ... -
tree file options
2008-08-15 08:47 1159package jface.treeviewer; impo ...
相关推荐
Custom Palette Sort: Define a custom order of palette entries on your printouts. Palette Symbol Enhancments: Select custom symbol colors for printouts. Choose symbol by stitch type. Export to ...
Custom Palette Sort: Define a custom order of palette entries on your printouts. Palette Symbol Enhancments: Select custom symbol colors for printouts. Choose symbol by stitch type. Export to ...
1. 之前稳定版开发工具用的好好的,突然某天真机调试一直报错: ReferenceError: define is not defined 2. 找解决办法后发现,更新至开发版最新版可以解决,如附件,下载安装后,即可解决该问题。
Next you learn how to sort a data range on one column or on multiple columns and how to use a custom sort order, the Filter (AutoFilter) feature and the Advanced Filter feature to view data that meets...
They can be customized to meet specific business needs and can be linked to content types to enforce data consistency. **Site Columns** These define fields that can be reused across multiple lists ...
You will create custom styleable attributes that work with Android XML layouts, learn to process touch events, define custom attributes, and add properties and events to them. By the end of this book...
Item 22: Use interfaces only to define types Item 23: Prefer class hierarchies to tagged classes Item 24: Favor static member classes over nonstatic Item 25: Limit source files to a single top-level ...
- **Defining Your Own Types**: Explanation of how to create custom data types using `typedef`. #### Files The document explains file handling in C, which involves reading from and writing to files: ...
- **Overloading Operators**: Operator overloading enables you to define how built-in operators behave with custom types. - **Conversions and Conversion Operator Overloads**: Conversion operator ...
Learn Docker "infrastructure as code" technology to define a system for performing standard but non-trivial data tasks on medium- to large-scale data sets, using Jupyter as the master controller. ...
### Odoo Themes: A Comprehensive Guide to Creating Custom Themes for Odoo 9.0 #### Introduction to Odoo Themes In the vibrant world of content management systems (CMS), Odoo stands out as a powerful...
The book will also guide you through creating custom graphs and visualizations, and show you how to go from the raw data to beautiful visualizations. The extensive examples will include working with ...
Complete with real-world examples, this book shows you how to make data-driven design part of your product design workflow. Understand the relationship between data, business, and design Get a firm ...
Course OutlineModule 1: Introduction to Business Intelligence and Data ModelingThis module introduces key BI concepts and the Microsoft BI product suite.Lessons Introduction to Business Intelligence...
Custom controllers are used when you need complete control over the data retrieval and processing, while controller extensions provide a way to extend an existing controller without modifying its ...
标题中的“解决样式多问题,You can define up to 4000 styles 包括poi全部jar”意味着在处理大型或者复杂的Excel文档时,由于`.xls`格式的限制,我们只能定义最多4000种不同的单元格样式。这4000种样式包括字体、...
Modular: Reference other config files on the classpath to merge into your config. Tagged: Define config blocks with tags to merge config at runtime. Formats: JSON and YAML Usage: MyConfig config = ...