Content Typesって何すか?


Eclipse3.1の設定画面で、File Associations(ファイルの関連付け)に似たものにContent Typeというのがある。なんだこれは?ということで調べてみた。

設定画面でできること

File Associationsでは、ユーザーは「ファイル名とエディタ」を直接関連づけました。

ファイル名―エディタ

一方、Content Typeでは、ユーザーは、ユーザーは「Content Typeとファイル名」の関連付けを行います(他にデフォルトエンコーディングの設定もできる)。Content Typeとエディタの関連はプラグイン側の設定で、ユーザーは変更できないようです。

ファイル名―Content Type―エディタ

つまりContent Typeでユーザーが設定するのは間接的な関連づけとなります。
File Associationでは、「ケーキを食べていいのは太郎くん」と名指しで氏名しているのに対して、Content Typesでは、「ケーキを食べていいのは、デブ」「太郎はデブ」と直接名指しでなく、間接的なマッピングになっているようです。


Content Typeのメリット

Content Typeが導入されたのは、この辺の話からのようです。

Content-type-based editor lookup
https://bugs.eclipse.org/bugs/show_bug.cgi?id=37668


Content Typeは、File Associations同様、ファイルを開くときのエディタの選択に利用されますが、Content Typeにより、より柔軟に(なんか具体例。。。。えーとえーと)エディタの選択が行えます。そういうわけで導入されたっぽいですが、中の人(プラグイン開発者)のメリットはありそうですが、エンドユーザーにとっては、難しい(混乱する?)項目が一つ増えただけのようにも思えたり。上のスレッドを下まで読めばありがたみがわかるのかな。。。でも、これにあんまり時間とっても仕方がないので、スキップします。

参考、その他

ヘルプのContent Types

The Content Types preference page allows you to edit content types, their associated file names and character sets as well as associate arbitrary file names or file extensions with content types. A content type acts as a description of a certain class of files (for instance, XML files). Eclipse uses this description in various scenarios such as editor look up and file comparing.

ヘルプのEclipse Platform What's New in 3.1

・Editor lookup based on content type
When determining the appropriate editor to open for a given file, the file's content type is now taken into account. Editors may now advertise that they are capable of working on certain content types as well as their traditional file name and extensions.

・Content type preference page
A new preference page to edit content types and their associated file names and character sets has been added under the General/Editors preference page.


http://eclipse.pookzilla.net/2005/03/content-type-based-editor-lookup-take.php

あと、拡張ポイントorg.eclipse.core.runtime.contentTypesは3.0からある