| <?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| <title>extensions-provide_toolfilter</title> |
| <link type="text/css" rel="stylesheet" href="../resources/bootstrap.css"/> |
| <link type="text/css" rel="stylesheet" href="../resources/custom.css"/> |
| </head> |
| <body> |
| <h1 id="SiriusProvideatoolfilter">Sirius – Provide a tool filter</h1> |
| <h2 id="Goals">Goals</h2> |
| <p>The extension point |
| <code>org.eclipse.sirius.diagram.toolManagement</code> allows to contribute filters which can hide tools from the diagram palette depending on some custom condition. Contributed filters must implement |
| <code>org.eclipse.sirius.diagram.tools.api.management.ToolFilter</code>. Many extensions can be provided. If many extensions are provided, the tool in the palette will be hidden as soon as at least one ToolFilter’s |
| <code>filter(DDiagram diagram, AbstractToolDescription tool)</code> implementation returns true. It is important to leverage the given arguments diagram and tool to make sure that the tool is filtered for the specific use case only. |
| </p> |
| <h2 id="Example">Example</h2> |
| <p>Here is an example that filters tools based on an imaginary concept of advanced and basic user profiles.</p> |
| <p>You have to add your tool filter contribution in the plugin.xml file.</p> |
| <pre><extension point="org.eclipse.sirius.diagram.toolManagement"> |
| <toolFilter |
| class="com.acme.UserProfileToolFilter"> |
| </resourceStrategy> |
| </extension> |
| |
| </pre> |
| <p>The class references a class implementing |
| <code>ToolFilter</code>. The corresponding code is: |
| </p> |
| <pre>/** |
| * Filter diagram tools according to a given user profile |
| */ |
| public class UserProfileToolFilter implements ToolFilter { |
| |
| @Override |
| public boolean filter(DDiagram diagram, AbstractToolDescription tool); |
| return isAdvancedProfileTool(tool) && !isAdvancedUser(diagram); |
| } |
| |
| @Override |
| private boolean isAdvancedProfileTool(AbstractToolDescription tool){ |
| //... |
| } |
| |
| private bookean isAdvancedUser(DDiagram diagram){ |
| //... |
| } |
| |
| } |
| |
| </pre> |
| <p></p> |
| </body> |
| </html> |