组合备忘单

组合备忘单通过将问题分解成一组小型任务来提供对复杂问题的指导。组合备忘单是使用 org.eclipse.ui.cheatsheets.cheatSheetContent 扩展点来注册的。

内容文件格式

组合备忘单内容本身是在符合组合备忘单内容文件规范的独立文件中定义的。内容文件是一个 XML 文件,它包含一组组织成树结构的任务。  

<compositeCheatsheet> 是组合备忘单的根元素。它将带有单个根任务,此任务可以是 <task> 或 <taskGroup>。<taskGroup> 元素可以有一个或多个子代,每个子代都可以是 <task> 或 <taskGroup>。<task> 没有子任务。

任务和任务组可以包含 <intro> 元素(此元素包含任务启动前显示的文本)和 <onCompletion> 元素(此元素包含任务完成后显示的文本)。<intro> 和 <onCompletion> 元素都可以包含表单文本标记。在以下示例中,使用了 <b> 和 </b> 标记来设置粗体文本。

任务还可以包含 <param> 元素。备忘单任务可以包含下列任何参数:“id”是已注册备忘单的标识,“path”是备忘单内容文件的相对路径或 URL,“skipIntro”是一个布尔参数,如果将其设置为 true,将导致备忘单从第一个步骤启动,而不是从简介启动。必须指定“id”或“path”,但不 能同时指定这两者。

从任务“B”到任务“A”的 <dependency> 节点表示在开始任务 B 之前必须先完成任务 A。

备忘单任务参数

如果某个任务的 kind 参数值为“cheatsheet”,则该任务启动时将打开备忘单。备忘单任务有三个可能的参数。

参数名 描述 
id 使用扩展点 org.eclipse.ui.cheatsheets.cheatSheetContent 注册的备忘单的标识。此参数标识将与此任务相关联的备忘单。应该指定 id 或 path 参数(但不能同时指定它们)。
path 备忘单内容文件的 URL。这可以是绝对 URL,也可以相对于组合备忘单的内容文件。如果同时指定 id 和 path,则将使用 path 来查找内容文件,并且将忽略 id 参数。
showIntro 缺省值为 true 的布尔参数。如果设置为“false”,则该备忘单启动时将首先显示第一个步骤,而不是显示简介。

组合备忘单示例

以下文件示例说明如何根据现有备忘单来创建组合备忘单。此示例还说明了如何创建任务组并使那些任务可被跳过。

<?xml version="1.0" encoding="UTF-8"?>
<compositeCheatsheet name="Composite cheat sheet example">
    <taskGroup name= "Composite cheat sheet example">
         <intro> This is an example of a <b>composite cheat sheet</b> built from existing cheat sheets.
                 <br/><br/>You can select a task to work on either by following the hyperlinks or by
                 selecting a task in the tree. 
         </intro>
         <onCompletion>Congratulations you have completed all the tasks.</onCompletion>             
         <task kind="cheatsheet" name= "Branching and merging using CVS" skip="true">
              <param name = "id" value = "org.eclipse.platform.cvs_1" />
              <intro>This cheat sheet is intended for CVS users. If you are not using CVS or do
              not intend to branch and merge you may skip this task.
              </intro>
               <onCompletion>Congratulations you now know how to branch and merge.</onCompletion>
         </task>
         <taskGroup name= "Create Java Projects" kind = "sequence">
             <intro> First you will learn how to create a simple java project, then you will create
             an java project which uses SWT.
             <br/><br/>This task group is a sequence which means that
             if you click on the subtask "Standalone SWT Application" it will not let that task be started
             until "Create a java project" has been completed.
             </intro>
              <onCompletion>Congratulations you have built both Java applications.</onCompletion>
             <task kind="cheatsheet" name= "Create a java project" id = "createJavaProject">
                 <param name="id" value = "org.eclipse.jdt.helloworld"/>
                 <param name="showIntro" value = "false"/>
                 <intro>This cheat sheet walks through the process of creating a simple hello world application.
                        The cheat sheet can launch wizards to create a new project and a new class.
                 </intro>
                 <onCompletion>Congratulations you have succeeded in creating a hello world application</onCompletion>
             </task>
             <task kind="cheatsheet" name= "Standalone SWT Application">
                 <intro>Eclipse plugins which contribute to the user interface use The Standard Widget Toolkit (SWT).
                    This task guide can be used to learn more about SWT.
                 </intro>
                 <param name = "id" value = "org.eclipse.jdt.helloworld.swt" />
                  <onCompletion>Congratulations you have succeeded in creating an SWT application.</onCompletion>
             </task>
         </taskGroup>
    </taskGroup>
</compositeCheatsheet>

组合备忘单可扩展性 - 在 Eclipse 3.2 中是临时的

组合备忘单是可扩展的,但在 Eclipse 3.2 中,此可扩展性是临时的,并且类可能会在成为 API 之前发生更改。可以使用扩展点 org.eclipse.ui.cheatsheets.cheatSheetContent 来扩展组合备忘单支持。此扩展点包含两个新元素 taskEditor 和 taskExplorer,它们允许添加任务编辑器和任务资源管理器。

添加任务编辑器时,将定义一种新任务,该任务将显示在任务详细信息部分中。要添加任务编辑器,请实现 TaskEditor 的具体子类,然后在 plugin.xml 中添加 taskEditor 元素。  

任务资源管理器的表示也可以通过扩展点来进行配置,Eclipse 平台提供了树资源管理器。缺省情况下,组合备忘单的资源管理器在第一次打开时是一个树,<compositeCheatSheet> 元素的一个属性允许覆盖缺省值。如果注册了多个资源管理器,则视图菜单将包含用于在各个资源管理器之间进行切换的菜单项。要添加任务资源管理器,请首先实现 TaskExplorer 的具体子类,然后在 plugin.xml 中添加 taskExplorer 元素。  

相关链接

使用备忘单
使用组合备忘单
创建备忘单
编辑准则
组合备忘单内容文件规范
org.eclipse.ui.cheatsheets.cheatSheetContent 扩展点