| <html> |
| |
| <head> |
| <meta http-equiv=Content-Type content="text/html; charset=windows-1252"> |
| <meta name=Generator content="Microsoft Word 11 (filtered)"> |
| <title>Providing custom functionality</title> |
| <link rel=Stylesheet type="text/css" media=all href="../book.css"> |
| <style> |
| <!-- |
| /* Font Definitions */ |
| @font-face |
| {font-family:Tahoma; |
| panose-1:2 11 6 4 3 5 4 4 2 4;} |
| /* Style Definitions */ |
| p.MsoNormal, li.MsoNormal, div.MsoNormal |
| {margin:0cm; |
| margin-bottom:.0001pt; |
| font-size:12.0pt; |
| font-family:"Times New Roman"; |
| color:windowtext;} |
| h1 |
| {margin-top:12.0pt; |
| margin-right:0cm; |
| margin-bottom:3.0pt; |
| margin-left:0cm; |
| page-break-after:avoid; |
| font-size:16.0pt; |
| font-weight:bold;} |
| h2 |
| {margin-top:12.0pt; |
| margin-right:0cm; |
| margin-bottom:3.0pt; |
| margin-left:0cm; |
| page-break-after:avoid; |
| font-size:14.0pt; |
| font-weight:bold; |
| font-style:italic;} |
| h3 |
| {margin-top:12.0pt; |
| margin-right:0cm; |
| margin-bottom:3.0pt; |
| margin-left:0cm; |
| page-break-after:avoid; |
| font-size:13.0pt; |
| font-weight:bold;} |
| h4 |
| {margin-top:11.25pt; |
| margin-right:0cm; |
| margin-bottom:1.7pt; |
| margin-left:0cm; |
| font-size:12.0pt; |
| font-weight:bold; |
| font-style:italic;} |
| h5 |
| {margin-right:0cm; |
| margin-left:0cm; |
| font-size:10.0pt; |
| font-weight:bold;} |
| h6 |
| {margin-right:0cm; |
| margin-left:0cm; |
| font-size:7.5pt; |
| font-weight:bold;} |
| p.MsoCaption, li.MsoCaption, div.MsoCaption |
| {margin-top:6.0pt; |
| margin-right:0cm; |
| margin-bottom:24.0pt; |
| margin-left:0cm; |
| text-align:justify; |
| font-size:10.0pt; |
| font-weight:bold;} |
| a:link, span.MsoHyperlink |
| {color:blue; |
| text-decoration:underline;} |
| a:visited, span.MsoHyperlinkFollowed |
| {color:purple; |
| text-decoration:underline;} |
| p |
| {margin-top:5.65pt; |
| margin-right:0cm; |
| margin-bottom:5.65pt; |
| margin-left:0cm; |
| font-size:12.0pt;} |
| pre |
| {margin-top:0cm; |
| margin-right:0cm; |
| margin-bottom:0cm; |
| margin-left:3.4pt; |
| margin-bottom:.0001pt; |
| font-size:11.0pt;} |
| p.MsoAcetate, li.MsoAcetate, div.MsoAcetate |
| {margin:0cm; |
| margin-bottom:.0001pt; |
| font-size:8.0pt; |
| font-family:Tahoma;} |
| p.code, li.code, div.code |
| {margin-top:0cm; |
| margin-right:0cm; |
| margin-bottom:0cm; |
| margin-left:15.0pt; |
| margin-bottom:.0001pt; |
| font-size:12.0pt;} |
| p.note, li.note, div.note |
| {margin-top:19.5pt; |
| margin-right:0cm; |
| margin-bottom:19.5pt; |
| margin-left:30.0pt; |
| font-size:13.0pt; |
| font-style:italic;} |
| span.code1 |
| {font-style:italic;} |
| @page Section1 |
| {size:595.45pt 841.7pt; |
| margin:72.0pt 89.85pt 72.0pt 89.85pt;} |
| div.Section1 |
| {page:Section1;} |
| /* List Definitions */ |
| ol |
| {margin-bottom:0cm;} |
| ul |
| {margin-bottom:0cm;} |
| --> |
| </style> |
| |
| </head> |
| |
| <body bgcolor=white lang=DE link=blue vlink=purple style='margin-bottom:12.0pt'> |
| |
| <div class=Section1> |
| |
| <h1><span lang=EN-GB>Providing Custom Functionality</span></h1> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>If the editor developer |
| wants to add some editor specific functionality (e.g. context menu actions |
| which can change the business and/or the pictogram model) the predefined |
| features are not enough. In this case we need a more general feature. For |
| that purpose the framework provides a custom feature. Examples for a custom |
| feature are rename, change color, check out,
</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <h2><span lang=EN-GB>Create a Custom Feature</span></h2> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>A custom feature has to |
| implement the interface </span><span class=code1><span lang=EN-US |
| style='color:black'><a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/custom/ICustomFeature.html"><span |
| style='font-style:normal'>ICustomFeature</span></a>.</span></span><span |
| lang=EN-US style='color:black'> </span><span lang=EN-GB style='color:black'>Instead |
| of implementing it directly it should extend one of the available base classes. |
| In this example we extend the base class<span class=code1> </span></span><span |
| class=code1><span lang=EN-US style='color:black'><a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/custom/AbstractCustomFeature.html"><span |
| style='font-style:normal'>AbstractCustomFeature</span></a></span></span><span |
| lang=EN-GB style='color:black'>.</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>In this case we have to |
| implement/overwrite 4 methods:</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>The method <a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/custom/ICustomFeature.html#canExecute(com.sap.tc.emf.gfw.features.context.ICustomContext)">c<span |
| lang=EN-US>anExecute</span></a> has to check whether the custom feature can be |
| executed on the current pictogram element of the given context.</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>The method </span><span |
| class=code1><span lang=EN-US style='color:black'><a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/custom/ICustomFeature.html#execute(com.sap.tc.emf.gfw.features.context.ICustomContext)"><span |
| style='font-style:normal'>execute</span></a></span></span><span lang=EN-US |
| style='color:black'> </span><span lang=EN-GB style='color:black'>has to perform |
| the custom specific stuff.</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>These two methods |
| receive a custom context as parameter. Interface </span><span class=code1><span |
| lang=EN-US style='color:black'><a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/context/ICustomContext.html"><span |
| style='font-style:normal'>ICustomContext</span></a></span></span><span |
| lang=EN-GB style='color:black'> provides the inner pictogram element and the |
| inner graphics algorithm additionally to the (selected) pictogram element. |
| These are the inner elements the mouse pointer is placed / clicked on.</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>Currently only custom |
| features receive the information on the inner elements additionally to the |
| selected/selectable ones. </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>The methods </span><span |
| class=code1><span lang=EN-US style='color:black'><a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/custom/ICustomFeature.html#getName()"><span |
| style='font-style:normal'>getName</span></a> / <a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/custom/ICustomFeature.html#getDescription()"><span |
| style='font-style:normal'>getDescription</span></a></span></span><span |
| lang=EN-GB style='color:black'> have to return the information for the UI |
| representation. </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>In this example we want |
| to implement a custom feature which opens a popup-dialog to change the EClass name. This custom feature should be available and enabled in the context |
| menu if exactly one EClass is selected.</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>You can see the |
| complete implementation of the custom feature here:</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=907 |
| style='width:18.0cm;border-collapse:collapse'> |
| <tr> |
| <td width=907 valign=top style='width:18.0cm;border:solid windowtext 1.0pt; |
| padding:0cm 5.4pt 0cm 5.4pt'> |
| <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-GB |
| style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'> </span></b></p> |
| <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>package</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| org.eclipse.graphiti.examples.tutorial.features;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>class</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| TutorialRenameEClassFeature </span><b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:#7F0055'>extends</span></b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| AbstractCustomFeature {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| TutorialRenameEClassFeature(IFeatureProvider fp) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>super</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>(fp);</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| String getName() {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"Rename |
| EClass"</span><span lang=EN-US style='font-size:10.0pt;font-family: |
| "Courier New";color:black'>;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| String getDescription() {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"Change |
| the name of the EClass"</span><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'>;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>boolean</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| canExecute(ICustomContext context) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// |
| allow rename if exactly one pictogram element</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// |
| representing a EClass is selected</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>boolean</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| ret = </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#7F0055'>false</span></b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'>;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| PictogramElement[] pes = context.getPictogramElements();</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| (pes != </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#7F0055'>null</span></b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> && pes.</span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>length</span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> == |
| 1) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> Object |
| bo = getBusinessObjectForPictogramElement(pes[0]);</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| (bo </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#7F0055'>instanceof</span></b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> EClass) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| ret = </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#7F0055'>true</span></b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'>;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| ret;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>void</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| execute(ICustomContext context) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> PictogramElement[] |
| pes = context.getPictogramElements();</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| (pes != </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#7F0055'>null</span></b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> && pes.</span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>length</span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> == |
| 1) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> Object |
| bo = getBusinessObjectForPictogramElement(pes[0]);</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>if</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| (bo </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#7F0055'>instanceof</span></b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> EClass) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| EClass eClass = (EClass) bo;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| String currentName = eClass.getName();</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| </span><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#3F7F5F'>// ask user for a new class name</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| String newName =SampleUtil.askString(getName(), getDescription(),</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| currentName);</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| </span><b><span lang=EN-US style='font-size:10.0pt;font-family:"Courier New"; |
| color:#7F0055'>if</span></b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> (newName != </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>null</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| eClass.setName(newName);</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| </span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>}</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt; |
| font-family:"Courier New";color:black'>}</span></p> |
| <p class=MsoNormal><span style='color:black'> </span></p> |
| </td> |
| </tr> |
| </table> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>Additionally the |
| feature provider has to deliver our newly created custom feature (overwrite the |
| method </span><span class=code1><span lang=EN-US style='color:black'><a |
| href="../../../javadoc/com/sap/tc/emf/gfw/features/IFeatureProvider.html#getCustomFeatures(com.sap.tc.emf.gfw.features.context.ICustomContext)"><span |
| style='font-style:normal'>getCustomFeatures</span></a></span></span><span |
| class=code1><span lang=EN-US style='color:black;font-style:normal'>)</span></span><i><span |
| lang=EN-GB style='color:black'>. </span></i></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>This implementation can |
| be seen here:</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=907 |
| style='width:18.0cm;border-collapse:collapse'> |
| <tr> |
| <td width=907 valign=top style='width:18.0cm;border:solid windowtext 1.0pt; |
| padding:0cm 5.4pt 0cm 5.4pt'> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-GB |
| style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| ICustomFeature[] getCustomFeatures(ICustomContext context) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>new</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| ICustomFeature[] { </span><b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:#7F0055'>new</span></b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| TutorialRenameEClassFeature(</span><b><span lang=EN-US style='font-size:10.0pt; |
| font-family:"Courier New";color:#7F0055'>this</span></b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'>) };</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| style='font-size:10.0pt;font-family:"Courier New";color:black'>}</span></p> |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| </td> |
| </tr> |
| </table> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <h2><span lang=EN-GB>Create a Tool Behavior Provider</span></h2> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>Additionally we have to |
| define that this custom feature can appear in the context menu. For that |
| purpose we have to define it in the <a href="tool-behavior-provider.htm">tool |
| behavior provider</a>. The concept of the tool behaviour provider will be discussed |
| later in this tutorial in more detail. </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>For this example of a |
| custom feature it is enough to <b>create a tool behavior provider and add it to |
| the diagram type provider as described <a href="tool-behavior-provider.htm">here</a>. |
| </b>Afterwards you can add the custom feature to the context menu.</span></p> |
| |
| <p class=MsoNormal><b><span lang=EN-GB style='color:black'> </span></b></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>You can see the |
| complete implementation of the tool behavior provider here:</span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=907 |
| style='width:18.0cm;border-collapse:collapse'> |
| <tr> |
| <td width=907 valign=top style='width:18.0cm;border:solid windowtext 1.0pt; |
| padding:0cm 5.4pt 0cm 5.4pt'> |
| <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-GB |
| style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'> </span></b></p> |
| <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>package</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| org.eclipse.graphiti.examples.tutorial.diagram;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>class</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| TutorialToolBehaviorProvider </span><b><span lang=EN-US style='font-size: |
| 10.0pt;font-family:"Courier New";color:#7F0055'>extends</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| DefaultToolBehaviorProvider {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New"'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| TutorialToolBehaviorProvider(IDiagramTypeProvider dtp) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>super</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'>(dtp);</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#646464'>@Override</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>protected</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>boolean</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| isContextMenuApplicable(IFeature feature) {</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// |
| use all custom features as candidates for the context menu</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>boolean</span></b><span |
| lang=EN-US style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| ret = (feature </span><b><span lang=EN-US style='font-size:10.0pt;font-family: |
| "Courier New";color:#7F0055'>instanceof</span></b><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> |
| ICustomFeature);</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span lang=EN-US |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span |
| style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>return</span></b><span |
| style='font-size:10.0pt;font-family:"Courier New";color:black'> ret;</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt; |
| font-family:"Courier New";color:black'> }</span></p> |
| <p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt; |
| font-family:"Courier New";color:black'>}</span></p> |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| </td> |
| </tr> |
| </table> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <h2><span lang=EN-GB>Test: Rename a EClass with a Custom Popup-Dialog</span></h2> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'>Now start the editor |
| and test this new custom feature:</span></p> |
| |
| <ol style='margin-top:0cm' start=1 type=1> |
| <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>create |
| or open a diagram </span></li> |
| <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>create |
| a new EClass A</span></li> |
| <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>open |
| the context menu on this newly created EClass; choose Rename EClass</span></li> |
| <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>rename |
| this EClass to B</span></li> |
| <li class=MsoNormal style='color:black;text-align:justify'><span lang=EN-GB>the |
| diagram will be updated automatically with new class name</span></li> |
| </ol> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| <p class=MsoNormal><span lang=EN-GB style='color:black'> </span></p> |
| |
| </div> |
| <hr> |
| <a href="http://www.eclipse.org/legal/epl-v10.html" shape="rect">Copyright (c) SAP AG 2005, 2010.</a> |
| |
| </body> |
| |
| </html> |