Chapter 11. Eclipse Designer(Eclipse 設計器)
Table of Contents
- Installation
- Activiti Designer editor features(特性)
- Activiti Designer BPMN features(Activiti設計器BPMN特性)
- Extending Activiti Designer(擴展Activiti設計器)
-
- Customizing the palette(定制面板)
- Exporting to custom output formats(輸出定制的格式)
Activiti comes with an Eclipse plugin, the Activiti Eclipse Designer, that can be used to graphically model, test and deploy BPMN 2.0 processes Eclipse. The Activiti Eclipse Designer is started and maintained by Tijs Rademakers, Tiese Barrell, Ron van Liempd and Yvo Swillens.
Activiti攜帶了能夠在Eclipse里面用來對BPMN 2.0流程進行圖形化建模的Eclipse插件。Activiti Eclipse Designer由Tijs Rademakers, Tiese Barrell, Ron van Liempd 和 Yvo Swillens發起并維護。
Installation
The following installation instructions are verified on Eclipse Classic Helios.
下列安裝指令在 classic Eclipse Helios 環境里面得到驗證。
Go to Help -> Install New Software. In the following panel, click on Add button and fill in the following fields:
到 Help -> Install New Software.在下面面板里面,點擊 Add 按鈕并填充下面的字段:
Make sure the "Contact all updates sites.." checkbox is not checked, because all the necessary plugins can be downloaded from the Activiti update site.
確保選擇 "Contact all updates sites.."復選框,這是因為所有必要的插件從Activiti的更新站點下載。
Activiti Designer editor features(特性)
-
Create Activiti projects and diagrams.
建立Activiti項目和流程圖。

-
The Activiti project is generated as a Maven project. To configure the dependencies you need to run mvn eclipse:eclipse and the project dependencies will be configured as expected.
Activiti項目作為一個Maven項目而產生。為了配置所需的依賴,請運行 mvn eclipse:eclipse,那么項目依賴的配置將如你所愿。

-
A BPMN 2.0 XML file and an image of the process are automatically generated after each save of the Activiti diagram (the automatic generation can be switched of in the Eclipse preferences in the Activiti tab).
在Activiti流程圖每次保存時將自動產生BPMN 2.0 XML文件和流程的圖像(在Eclipse的preferences的Activiti標簽頁里可以關閉自動產生的選項)。

-
Generate a unit test (right click on a BPMN 2.0 XML file in the package explorer and select generate unit test) A unit test is generated with an Activiti configuration that runs on an embedded H2 database. You can now run the unit test to test your process definition.
產生單元測試(右擊包導航器的BPMN 2.0 XML文件并選擇產生單元測試(generate unit test))。Activiti配置產生的單元測試運行在嵌入式H2的數據庫之上。現在能夠運行單元測試來測試流程定義。

-
The BPMN 2.0 XML is opened in a Activiti XML editor which provides content assist. Note that there are 2 main XSDs configured, the BPMN 2.0 spec XSD and the Activiti extensions XSD. These two XSDs are not yet alligned in a good manneer.
Activiti XML編輯器提供內容輔助功能。可以在Activiti XML編輯器里面打開BPMN 2.0 XML文件。注意存在兩種可配置的XSD:符合BPMN 2.0規范的XSD和Activiti擴展的XSD。這兩個還沒有以良好的方式齊頭并進。

-
A basic validation is performed after each save of the Activiti diagram and the errors are mentioned in the Eclipse problem view.
當Activiti流程圖每次保存時,完成基本的校驗。校驗錯誤顯示在Eclipse 問題視圖里。

-
A basic deployment editor is available when right-clicking on an Activiti diagram in the package explorer. You see a Deployment property at the end of the pop-up items. The deployment editor currently supports saving a BAR file, and will be extended in the next release to also deploy the BAR file to the Activiti engine.
當右擊包導航器的Activiti的流程圖時,將顯示一個基本的部署編輯器。在彈出項的的最下端將顯示一個"Deployment"屬性。部署編輯器當前支持保存為一個BAR文件。在下一個版本將擴展為將BAR文件部署到Activiti引擎。

Activiti Designer BPMN features(Activiti設計器BPMN特性)
-
Support for start event, end event, sequence flow, parallel gateway, exclusive gateway, embedded subprocess, script task, user task, service task, mail task and manual tasks.
支持啟動事件,結束事件,順序流,并行網關,唯一網關,嵌入式子流程,腳本任務,用戶任務,服務任務,郵件任務和手動任務。

-
Java class or expression configuration is supported for the Java service task. In addition field extensions can be configured.
支持對Java服務任務進行Java類或者表達式配置。能夠配置另外的字段擴展。

-
Support for additional Activiti extensions like the Mail task, the candidate configuration of User tasks and Script task configuration.
支持像Mail任務的Activiti擴展任務,用戶任務的候選人配置和腳本任務配置。
-

-
Support for conditions on sequence flows.
支持順序流之上的條件表達式。

Extending Activiti Designer(擴展Activiti設計器)
You can extend the default functionality offered by Activiti Designer. This section documents which extensions are available, how they can be used and provides some usage examples. Extending Activiti Designer is useful in cases where the default functionality doesn't suit your needs, you require additional capabilities or have domain specific requirements when modelling business processes. Extension of Activiti Designer falls into two distinct categories, extending the palette and extending output formats. Each of these extension ways requires a specific approach and different technical expertise.
你能夠擴展由Activiti Designer提供的缺省功能。本章為哪些擴展可用,如何使用這些擴展問題提供一些有用的示例。在缺省功能不適合你的需求,你需要額外的能力,或者當對業務流程建模時具有領域特定的需求的地方,正是擴展Activiti Designer擴展有用武之地。Activiti Designer擴展有兩個明顯的分類:擴展面板和擴展輸入格式。每個擴展方式需要特定的方法和不同的技術技巧。
Note
Extending Activiti Designer requires technical knowledge and more specifically, knowledge of programming in Java. Depending on the type of extension you want to create, you might also need to be familiar with Maven, Eclipse, OSGi, Eclipse extensions and SWT.
注意
擴展需要技術基礎和更特別的Java編程基礎。依賴ni ddddd所想建立的擴展類型,你也許需要熟悉Maven,Eclipse,OSGi,Eclipse擴展和SWT。
Customizing the palette(定制面板)
You can customize the palette that is offered to users when modelling processes. The palette is the collection of shapes that can be dragged onto the canvas in a process diagram and is displayed to the right hand side of the canvas. As you can see in the default palette, the default shapes are grouped into compartments (these are called "drawers") for Events, Gateways and so on. There are two options built-in to Activiti Designer to customize the drawers and shapes in the palette:
當建模時,你可以給用戶提供一個定制的面板。面板是能夠拉至
-
Adding your own shapes / nodes to existing or new drawers
增加你自己的圖形或者節點到已存在或新的抽屜上。
-
Disabling any or all of the default BPMN 2.0 shapes offered by Activiti Designer, with the exception of the connection and selection tools
j禁止任何Activiti Designer提供的缺省BPMN 2.0圖形,連接和選擇
In order to customize the palette, you create a JAR file that is added to a specific installation of Activiti Designer (more on how to do that later). Such a JAR file is called anextension. By writing classes that are included in your extension, Activiti Designer understands which customizations you wish to make. In order for this to work, your classes should implement certain interfaces. There is an integration library available with those interfaces and base classes to extend which you should add to your project's classpath.
未來定制調色板,你建立一個可以添加到Activiti Designer(后面將更多介紹how to do that )里的JAR的文件。這樣的JAR文件叫一個擴展(extension) 。
Note
You can setup your project in whichever tool you prefer and build the JAR with your build tool of choice. For the instructions below, a setup is assumed with Eclipse Helios, using Maven (3.x) as build tool, but any setup should enable you to create the same results.
注意
ni你能夠設置你喜歡的工具來設置你的項目。用這個工具來構建這個JAR包。對于下列指令,假定用Eclipse Helios設置,采用Maven(3.x)作為構建工具,但是任何設置建立相同的結果。
Extension setup (Eclipse/Maven)(擴展設置(Eclipse/Maven))
Download and extract Eclipse (Galileo or Helios should both work) and a recent version (3.x) of Apache Maven. If you use a 2.x vesion of Maven, you will run into problems when building your project, so make sure your version is up to date. We assume you are familiar with using basic features and the Java editor in Eclipse. It's up to you whether your prefer to use Eclipse's features for Maven or run Maven commands from a command prompt.
下載并抽取 和最新版本。如果你使用Maven 2.x版本,在構建項目時將帶來問題,所以確保它的版本及時更新。我們假定你熟悉Eclipse里面的基本特性和Java編輯器。是否你鐘情在Eclipse里面使用Maven或者在命令行提示下使用Maven,完全取決于你。
Create a new project in Eclipse. This can be a general project type. Create a pom.xml
file at the root of the project to contain the Maven project setup. Also create folders for the src/main/java
and src/main/resources
folders, which are Maven conventions for your Java source files and resources respectively. Open the pom.xml
file and add the following lines:
在Eclipse里面建立一個新項目。這個項目可以是一個一般類型的項目。為了包含Maven項目設置,在項目的根目錄下建立一個pom.xml文件夾。也要建立 src/main/java
和 src/main/resources
文件夾,這是Maven對Java源代碼文件和相關資源文件的約定。打開pom.xml文件并增加下列行:
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>money-tasks</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Acme Corporation Money Tasks</name>
...
</pom>
As you can see, this is just a basic pom.xml file that defines a groupId
, artifactId
and version
for the project. We will create a customization that includes a single custom node for our money business.
正如你所見,這只是定義了項目的 一個基本的pom.xml文件。我們
Add the integration library to your project's dependencies by including this dependency in your pom.xml
file:
通過在pom.xml文件里包含項目的依賴庫,將集成的庫加到項目里面。
<dependencies>
<dependency>
<groupId>org.activiti.designer</groupId>
<artifactId>org.activiti.designer.integration</artifactId>
<version><!-- Current Activiti Designer Version --></version>
<scope>compile</scope>
</dependency>
</dependencies>
Warning
At the moment, the dependency is not available from the Activiti Maven repository. To use it, you should download it from here and place it in your local Maven repository.
此時,還未從Activiti的Maven倉庫獲得依賴。為了使用它,從這里下載 from here,并把它放到你本地的Maven倉庫里。
Finally, in the pom.xml
file, add the configuration for the maven-compiler-plugin
so the Java source level is at least 1.5 (see snippet below). You will need this in order to use annotations. You can also include instructions for Maven to generate the JAR's MANIFEST.MF
file. This is not required, but you can use a specific property in the manifest to provide a name for your extension (this name may be shown at certain places in the designer and is primarily intended for future use if you have several extensions in the designer). If you wish to do so, include the following snippet in pom.xml
:
最后,因為
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<optimize>true</optimize>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>false</addClasspath>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<ActivitiDesigner-Extension-Name>Acme Money</ActivitiDesigner-Extension-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
The name for the extension is described by the ActivitiDesigner-Extension-Name
property. The only thing left to do now is tell Eclipse to setup the project according to the instructions in pom.xml
. So open up a command shell and go to the root folder of your project in the Eclipse workspace. Then execute the following Maven command:
擴展名由ActivitiDesigner-Extension-Name
屬性描述。唯一剩下的d事實告訴Eclipse根據文件里指令建立這個項目。所以打開一個命令shell并到Eclipse工作區的項目根文件夾。執行下面的Maven命令:
mvn eclipse:eclipse
Wait until the build is successful. Refresh the project (use the project's context menu (right-click) and select Refresh
). You should now have the src/main/java
and src/main/resources
folders as source folders in the Eclipse project.
等到構建成功完成。刷新項目(使用項目的上下文菜單(右擊)并選擇“刷新”(Refresh
))。現在你應當在Eclipse項目里看見文件夾src/main/java
和 src/main/resources
作為源代碼文件夾。
Note
You can of course also use the m2eclipse plugin and simply enable Maven dependency management from the context menu (right-click) of the project. Then choose Maven
> Update project configuration
from the project's context menu. That should setup the source folders as well.
你當然也可使用 m2eclipse 插件。簡單地從上項目下文菜單(右擊)啟動Maven依賴管理。然后從項目的上下文菜單選擇“ Maven
> Update project configuration
”。也要設置設置源代碼。
That's it for the setup. Now you're ready to start creating customizations to Activiti Designer!
設置就這樣弄好了。建立Activiti Designer的定制的準備工作就緒。
Applying your extension to Activiti Designer(應用對Activiti Designer的擴展)
You might be wondering how you can add your extension to Activiti Designer so your customizations are applied. These are the steps to do just that:
你可能疑惑如何才能把自己的定制加入到Activiti Designer以便讓自己的定制起作用呢。那么采取這些步驟可以解決:
-
Once you've created your extension JAR (for instance, by performing a mvn install in your project to build it with Maven), you need to transfer the extension to the computer where Activiti Designer is installed;
一旦你建立自己的擴展JAR(例如,通過Maven在你的項目里執行一個mvn install 來構建)。你需要將這個擴展放到Activiti Designer安裝的地方。
-
Store the extension somewhere on the hard drive where it will be able to remain and remember the location;
ddd將擴展存儲在硬盤的某個地方,在那可以保存擴展。
-
Start Activiti Designer and from the menu, select Window
> Preferences
首先啟動Activiti Designer,然后在菜單里選擇 Window
> Preferences
.
-
In the preferences screen, type user
as keyword. You should see an option to access the User Libraries
in Eclipse in the Java
section.
在preferences 屏幕,鍵入 user
作為關鍵字。你應當在Eclipse的Java部分看見訪問 User Libraries
的選項。

-
Select the User Libraries item and a tree view shows up to the right where you can add libraries. You should see the default group where you can add extensions to Activiti Designer (depending on your Eclipse installation, you might see several others as well).
選擇 User Libraries 項,在右端將顯示一個樹形視圖,在此可以添加你自己的Java庫。你應當能看見擴展加入到Activiti Designer 的缺省組(依賴于你的Eclipse的安裝,你可能看到其它的情況)。

-
Select the Activiti Designer Extensions
group and click the Add JARs...
button. Navigate to to folder where your extension is stored and select the extension file you want to add. After completing this, your preferences screen should show the extension as part of the Activiti Designer Extensions
group, as shown below.
選擇組Activiti Designer Extensions
組并點擊 Add JARs...
按鈕。導航至你自己擴展所保存的文件夾并選擇所要添加的擴展。完成之后,你的 preference屏幕應當顯示作為 Activiti Designer Extensions
組的一部分的擴展,如下所示。

-
Click the OK
button to save and close the preferences dialog. The Activiti Designer Extensions
group is automatically added to new Activiti projects you create. You can see the user library as entry in the project's tree in the Navigator or Package Explorer. If you already had Activiti projects in the workspace, you should also see the new extensions show up in the group. An example is shown below.
點擊OK按鈕,保存并關閉preference對話框。組自動添加到你所建的Activiti項目里面。在Navigator或者Package Explorer視圖上的項目樹書上,用戶庫作為一個條目顯示。如果你在工作區上存在一個Activiti項目,那么你應當看見在組里顯示的新的擴展。示例如下所示。

Diagrams you open will now have the shapes from the new extension in their palette (or shapes disabled, depending on the customizations in your extension). If you already had a diagram opened, close and reopen it to see the changes in the palette.
打開的流程圖的有一個新的擴展,并能看見圖形(依賴于你的定制,這些圖形可能被禁止)。如果流程圖已經打開,關閉并重新打開,觀察面板發生的變化。
Adding shapes to the palette(把圖形加到面板)
With your project set up, you can now easily add shapes to the palette. Each shape you wish to add is represented by a class in your JAR. Take note that these classes are not the classes that will be used by the Activiti engine during runtime. In your extension you describe the properties that can be set in Activiti Designer for each shape. From these shapes, your refer to the runtime class that should be used by the engine. This class should implement JavaDelegate as for any ServiceTask in Activiti.
一旦項目設置好,你能輕易把圖形添加到面板。你想加入的圖形在Jar包里用一個類來表示。注意這些類不是Activiti引擎在運行期間所使用的類。在擴展里,描述了在Activiti Designer里可以設置的屬性。通過這些圖形,引用應當有引擎所使用的運行期類。這些類應當為Activiti里的ServiceTask實現JavaDelegte接口。
A shape's class is a simple Java class, to which a number of annotations are added. The class should implement the CustomServiceTask
interface, but you shouldn't implement this interface yourself. Extend the AbstractCustomServiceTask
base class instead (at the moment you MUST extend this class directly, so no abstract classes in between). In the Javadoc for that class you can find instructions on the defaults it provides and when you should override any of the methods it already implements.
圖形類是一個簡單的Java類,加入了注釋。盡管這個類應當實現接口,但是不應當你自己實現這個接口。而應當擴展這個基類作為代替(目前你必須直接擴展這個類,所以沒有抽象類)。在那個類的Javadoc里面,可以找它提供的缺省功能的指令。你應當復寫它已經實現的任何方法。
/**
* @author John Doe
* @version 1
* @since 1.0.0
*/
public class AcmeMoneyTask extends AbstractCustomServiceTask {
...
}
You will need to implement the getName()
method to determine the name the node will have in the palette. You can also put the nodes in their own drawer and provide an icon. Override the appropriate methods from AbstractCustomServiceTask
. If you want to provide an icon, make sure it's in the src/main/resources
package in your JAR. The path you supply is relative to that folder.
需要實現 getName()
方法來決定將在面板中節點的名稱。你也能將節點放置到它們的抽屜里并提供一個圖標。復寫AbstractCustomServiceTask類里合適的方法。如果你想提供一個圖標,確定它在JAR包里的src/main/resources
包。提供的路徑是相對路徑。
You can add properties to the shape by adding members to the class and annotating them with the @Property
annotation like this:
通過向類加入成員并以如下方式用 @Property
標注標注它們可以給圖形增加屬性。
@Property(type = PropertyType.TEXT, displayName = "Account Number")
@Help(displayHelpShort = "Provide an account number", displayHelpLong = HELP_ACCOUNT_NUMBER_LONG)
private String accountNumber;
At the moment, there are just two PropertyType
values you can use, TEXT
and MULTILINE_TEXT
. Future releases will allow you to use other types. You can make a field required by setting the required attribute to true. A message and red background will appear if the user doesn't fill out the field.
當前,只存在兩種可以使用的PropertyType
值: TEXT
和MULTILINE_TEXT
。未來版本將允許你使用其它的類型。通過設置必選的屬性為true讓字段必選。如果用戶沒有填充字段,將出現一個消息,背景為紅色。
As you can see, there's also an @Help
annotation that's used to provide the user some guidance when filling out the field. You can also use the @Help
annotation on the class itself - this information is shown at the top of the property sheet presented to the user.
如你所見,當填充字段時,也有一個標注用來提供給用戶一些指南的的 @Help
標注。也可在類自身使用 @Help
標注--這個信息在屬性表上提供給用戶信息。
Below is the listing for a further elaboration of the MoneyTask
. A comment field has been added and you can see an icon is included for the node.
為了獲得MoneyTask的詳情,以下是列表。已經加入注釋字段,并且在節點能看見圖標。
/**
* @author John Doe
* @version 1
* @since 1.0.0
*/
@Runtime(delegationClass = "org.acme.runtime.AcmeMoneyJavaDelegation")
@Help(displayHelpShort = "Creates a new account", displayHelpLong = "Creates a new account using the account number specified")
public class AcmeMoneyTask extends AbstractCustomServiceTask {
private static final String HELP_ACCOUNT_NUMBER_LONG = "Provide a number that is suitable as an account number.";
@Property(type = PropertyType.TEXT, displayName = "Account Number", required = true)
@Help(displayHelpShort = "Provide an account number", displayHelpLong = HELP_ACCOUNT_NUMBER_LONG)
private String accountNumber;
@Property(type = PropertyType.MULTILINE_TEXT, displayName = "Comments")
@Help(displayHelpShort = "Provide comments", displayHelpLong = "You can add comments to the node to provide a brief description.")
private String comments;
/*
* (non-Javadoc)
*
* @see org.activiti.designer.integration.servicetask.AbstractCustomServiceTask #contributeToPaletteDrawer()
*/
@Override
public String contributeToPaletteDrawer() {
return "Acme Corporation";
}
@Override
public String getName() {
return "Money node";
}
/*
* (non-Javadoc)
*
* @see org.activiti.designer.integration.servicetask.AbstractCustomServiceTask #getSmallIconPath()
*/
@Override
public String getSmallIconPath() {
return "icons/coins.png";
}
}
If you extend Activiti Designer with this shape, The palette and corresponding node will look like this:
如果用這個圖形擴展Activiti Designer,面板及其相關節點如下所示:
The properties screen for the money task is shown below. Note the required message for the accountNumber
field.
money任務的屬性屏幕如下所示。注意 accountNumber
字段的必填的消息。
The help for fields is offered by the buttons to the right of each property. Clicking on the button shows a popup as displayed below.
在每個屬性的右側的按鈕提供字段的幫助信息。點擊按鈕將顯示如下彈出的信息。
The final step for your shape is to indicate the class that is instantiated by the Activiti engine when it reaches your node when executing a process instance. To do this, you use the @Runtime
annotation. The delegationClass
attribute you return should contain the canonical name of the runtime class. Note that the runtime class shouldn't be in your extension JAR, as it's dependent on the Activiti libraries.
當執行一個流程實例時,Activiti引擎到達你的節點。圖形的最終步驟指明被Activiti引擎實例化的那個類。可以 @Runtime
標注來完成這個功能。返回屬性應當包含運行時期的正規名稱。注意運行時期類不應當在擴展JAR包里,因為它依賴于Activiti類庫。
@Runtime(delegationClass = "org.acme.runtime.AcmeMoneyJavaDelegation")
Disabling default shapes in the palette(禁止面板里的缺省圖形)
This customization requires you to include a class in your extension that implements the DefaultPaletteCustomizer
interface. You should not implement this interface directly, but subclass the AbstractDefaultPaletteCustomizer
base class. Currently, this class provides no functionality, but future versions of the DefaultPaletteCustomizer
interface will offer more capabilities for which this base class will provide some sensible defaults so it's best to subclass so your extension will be compatible with future releases.
這個定制需要你在擴展里包含實現接口的類。你不應當直接實現這個接口,而是子類化AbstractDefaultPaletteCustomizer
基類。當前,接口的未來版本將提供為那些基類通過更多功能,所以最好子類化,這樣,你的擴展將會和未來的版本。
Extending the AbstractDefaultPaletteCustomizer
class requires you to implement one method, disablePaletteEntries()
, from which you must return a list of PaletteEntry
values. For each of the default shapes, you can disable it by adding its corresponding PaletteEntry
value to your list. Note that if you remove shapes from the default set and there are no remaining shapes in a particular drawer, that drawer will be removed from the palette in its entirety. If you wish to disable all of the default shapes, you only need to addPaletteEntry.ALL
to your result. As an example, the code below disables the Manual task and Script task shapes in the palette.
擴展 AbstractDefaultPaletteCustomizer
類需要你實現一個disablePaletteEntries()
方法,你必須返回一個 PaletteEntry
值列表。對于每個缺省圖形,通過增加相關的 PaletteEntry
值到你的列表,你能禁止它。注意如果從缺省集合里刪除圖形,特別的抽屜里沒有任何圖形,那么這個抽屜也將從面板中刪除。如果你想禁止所有缺省的圖形,你只需要把加入PaletteEntry.ALL
到結果。作為一個示例,下列代碼禁止了面板中的手動任務和腳本任務。
public class MyPaletteCustomizer extends AbstractDefaultPaletteCustomizer {
/*
* (non-Javadoc)
*
* @see org.activiti.designer.integration.palette.DefaultPaletteCustomizer#disablePaletteEntries()
*/
@Override
public List<PaletteEntry> disablePaletteEntries() {
List<PaletteEntry> result = new ArrayList<PaletteEntry>();
result.add(PaletteEntry.MANUAL_TASK);
result.add(PaletteEntry.SCRIPT_TASK);
return result;
}
}
The result of applying this extension is shown in the picture below. As you can see, the manual task and script task shapes are no longer available in the Tasks
drawer.
這個擴展的應用效果如下圖所示。如你所見,手動任務和腳本任務的圖形不在Task抽屜上獲取。
To disable all of the default shapes, you could use something similar to the code below.
為了禁止所有的缺省圖形,你可以應當使用和下列相似的代碼。
public class MyPaletteCustomizer extends AbstractDefaultPaletteCustomizer {
/*
* (non-Javadoc)
*
* @see org.activiti.designer.integration.palette.DefaultPaletteCustomizer#disablePaletteEntries()
*/
@Override
public List<PaletteEntry> disablePaletteEntries() {
List<PaletteEntry> result = new ArrayList<PaletteEntry>();
result.add(PaletteEntry.ALL);
return result;
}
}
The result will look like this (notice that the drawers the default shapes were in are no longer in the palette):
結果將如下相似(注意缺省圖形原來所在的抽屜也不在面板里面了)。
Exporting to custom output formats(輸出定制的格式)
You can extend Activiti Designer to publish to additional formats when saving diagrams. These extensions are called Export Marshallers
and are invoked automatically by Activiti Designer on each save action by the user. This behavior can be enabled or disabled by setting a preference in Eclipse's preferences dialog for each format to be saved.
當你保存流程圖時,你能夠擴展Activiti Designer 發表另外的格式。這些擴展被稱為。當用戶每次采取保存的行為時,由Activiti Designer自動調用。
You can compare these extensions to the BPMN 2.0 export and process image saving that's performed during save actions by default in Activiti Designer. In fact, these functions use exactly the same extension features you can use to save to your own formats.
你能將這些功能和BPMN 2.0輸出和流程圖像進行比較。缺省地,后者在Activiti Designer里在保存動作期間完成。
事實上,這些功能完全使用你能使用的相同的擴展特性。它通常保存為你自己的格式。
To create an Export Marshaller
, you need to create a different kind of extension than for extending the palette. The reason for this is simple: from your code you will need access to more APIs than are offered by the integration library. In particular, you will need classes that are available in Eclipse itself. The way to implement an Export Marshaller
is therefore to create an Eclipse plugin (which you can do by using Eclipse's PDE support) and package it in a custom Eclipse product. It's beyond the scope of this user guide to explain all the details involved in developing Eclipse plugins, so the instructions below are limited to the functionality for extending Activiti Designer.
為了建立一個輸出解組( Export Marshaller
),你需要建立不同種類的擴展,而不是擴展面板。這個原因是簡單的:從代碼觀點來看,你將需要比訪問比集成庫需要更多的API。特別地,你將需要Eclipse里能夠獲取的類。實現一個Export Marshaller
方法是建立一個Eclipse的插件(通過Eclipse的PDE支持),并且在一個定制的Eclipse產品里將它打包。解釋所有關于開發Eclipse 插件的細節超過了本用戶指南的范圍,所以下列指令被限制為擴展Activiti Designer的功能。
Your bundle should be dependent on the following libraries:
你的bundle應當依賴下列庫:
Create an extension to the org.activiti.designer.eclipse.extension.export.ExportMarshaller
extension point. For this extension point, you are required to subclass the AbstractExportMarshaller
class. This abstract base class provides you with a number of useful methods when marshalling to your own format, such as adding markers to Eclipse's problems view and saving resources to the workspace.
建立一個org.activiti.designer.eclipse.extension.export.ExportMarshaller
擴展點的擴展。對于這個擴展點,需要子類化 AbstractExportMarshaller
這個類。當自己的格式時這個抽象基類提供了大量的有用的方法,諸如在Eclipse Problem視圖添加標記,并把資源保存到工作區里面。
You are required to implement some methods, such as getMarshallerName()
and getFormatName()
. These methods are used to display options to the user and to show information in progress dialogs, so make sure the descriptions you return reflect the functionality you are implementing.
需要實現諸如這樣getMarshallerName()
和 getFormatName()
的方法。這些方法用來顯示用戶的選項和顯示進度對話框的信息,這樣確保返回的描述反應了所實現的功能。
The bulk of your work is performed in the marshallDiagram(Diagram diagram, IProgressMonitor monitor)
method. You are provided with the diagram object, which contains all of the information about the objects in the diagram (BPMN constructs) and the graphical representation. If you want to access the diagram through its resource in Eclipse or you want to transform the diagram using XSLT, there are methods to get to Resources
and InputStreams
for the diagram in the AbstractExportMarshaller
class.
工作的大部分在 marshallDiagram(Diagram diagram, IProgressMonitor monitor)
方法里面執行。提供了流程圖對象,它包含關于流程圖(BPMN構件)對象和圖形表示的所有信息。如果你想通過Eclipse里的一樣訪問流程圖,或者你想采用XSLT來轉換流程圖,在AbstractExportMarshaller
類里有為流程圖獲取Resources
和的 InputStreams
方法。
It's probably a good idea to invoke clearProblems()
as one of the first things you do; this will clear any previous markers for your marshaller. You should also use the progress monitor provided to report your progress back to the user. If you need examples on how to do this, take a look at the code of Activiti Designer itself.
首先調用 clearProblems()
方法可能是個好主意;這將清除 marshaller先前的標記。你也應當所提供的進度監視器,向用戶報告進展情況。如果需要如何完成這樣功能的示例,請參考Activiti Designer 自身的代碼。