Use GMF to develop a visual Interface Editor (2) -- custom figure

Source: Internet
Author: User

In addition to configuring the figure component in XML format, GMF allows you to directly write the figure implementation class.

Like GEF, GMF still uses the Java draw2d technical framework in view display, while the figure component we create inherits org. Eclipse. draw2d. Figure

Class or its subclass. Here, we can refer to the source code of the jbpm built-in process editor and copy the predefined figure component for a little modification. For example, startfigure is used to define the view component of the Start Node.

Public class startfigure extends actelementfigure {<br/> Private Static final image icon = imgutil. getimgfromplugin ("org. chen. test. digoal. custom ", <br/>" icons/start_event_empty.png "); <br/> @ override <br/> protected void customizefigure () {<br/> seticon (icon ); <br/>}< br/>}

Public abstract class extends actelementfigure extends panel {<br/> private label Label = new label (); <br/> protected static imageutil imgutil = new imageutil (); <br/> public encryption actelementfigure () {<br/> Add (Label); <br/> customizefigure (); <br/> setsize (48, 48 ); <br/>}< br/> protected abstract void customizefigure (); </P> <p> Public void seticon (image icon) {<br/> label. seticon (icon); <br/>}</P> <p> Public void settext (string text) {<br/> label. settext (text); <br/>}</P> <p> Public label getlabel () {<br/> return label; <br/>}</P> <p> Public void setcolor (color) {<br/> setbackgroundcolor (color ); <br/>}</P> <p> Public void setbounds (rectangle bounds) {<br/> bounds. setsize (48, 48); <br/> super. setbounds (bounds); <br/> label. setbounds (bounds); <br/>}< br/> Public void paint (Graphics g) {<br/> int saved = G. getantialias (); <br/> G. setantialias (SWT. on); <br/> super. paint (g); <br/> G. setantialias (saved); <br/>}< br/>}

Public class imageutil {<br/> public image getimgfromplugin (string plugin, string path) {<br/> image result = abstractuiplugin. imagedescriptorfromplugin (plugin, PATH ). createimage (); <br/> return result; <br/>}< br/>}

In addition, we recommend that you put the custom figure or other components in an independent bundle for management and distinguish them from the code driven by GMF. For example, in the existing

Add m on the basis of the bundle to indicate that the bundle is not driven by GMF, but is defined by us.

After figure is defined, you can introduce it to our view model, create a new figure descriptor, set the name attribute to startfigure, and then add a custom figure node, set the qualified class name attribute to the full name of the startfigure class name. After the setting is complete, add the package of startfigure to manifest. mf file package dependency, because the figure we define is in another bundle, and the startfigure we declare is instantiated under the canvas node to add a new node, set the name attribute to start and the figure attribute to startfigure. At this point, the view model definition ends.

 

After defining the view model, modify the tool model.

Create a new creation tool, set the title attribute to "start", set the description attribute to "create Start Node", and then specify the default icon information for the tool.

 

Finally, modify the ing model to complete the ing between the start nodes.

Create a new top node reference, set the containment feature attribute to process. nodes, and add the node mapping node for it to complete the attribute settings.

After the model is modified, We need to regenerate the generator model, right-click the ing model configuration file, and select create generator model in the pop-up menu to follow the Wizard to generate the model.

Finally, regenerate the project code and start the project instance. You can see that the Start Node has also been added to the view.

You can follow this method to add an end node. skip this step.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.