blob: 1f4624abb6faa108c60371ac9e359d2fc27278cf [file] [log] [blame]
<?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>trigger-refresh-graphical-changes</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="TriggeraSiriusrefreshonspecificgraphicalchanges">Trigger a Sirius refresh on specific graphical changes</h1>
<h2 id="Description">Description</h2>
<p>In automatic refresh mode, representations are refreshed as soon as at least one semantic change is done. Graphical changes are not considered as they are not impacting the mapping precondition. In some cases, the mapping can depend on the graphical state. A typical example is the &#8220;collapse&#8221; state of a
<a href="../specifier/diagrams/Diamgram.html#graphical_elements">region</a> to change the mapping according to it. Since Sirius 6.1.3, it is possible to register a new graphical change to trigger a Sirius refresh.
</p>
<h2 id="RegisteranewgraphicalchangetotriggeraSiriusrefresh">Register a new graphical change to trigger a Sirius refresh</h2>
<p>The
<code>org.eclipse.sirius.tools.api.ui.RefreshHelper.registerImpactingNotification(Predicate&lt;Notification&gt;)</code> allows to consider some graphical modifications as requiring a refresh. This method is called through the pre-commit listener
<code>org.eclipse.sirius.tools.api.ui.RefreshEditorsPrecommitListener</code>. So it is called only if you are in automatic refresh mode or if the &#8220;forceRefresh&#8221; mode has been activated (
<code>org.eclipse.sirius.tools.api.ui.RefreshEditorsPrecommitListener.setForceRefresh(boolean)</code>) with the corresponding representation to refresh (
<code>org.eclipse.sirius.tools.api.ui.RefreshEditorsPrecommitListener.addRepresentationToForceRefresh(DRepresentation)</code>).
<br/>For the specific case of collapse/expand, current representation is automatically added as a force refresh representation. So the collapse/expand of a region automatically launch a refresh, even in manual refresh mode.
</p>
<h3 id="Example">Example</h3>
<pre>// Register a predicate to consider Collapse/Expand changes as impacting in diagram of kind "MyDiagramDescriptionName".
RefreshHelper.registerImpactingNotification(new Predicate&lt;Notification&gt;() {
@Override
public boolean test(Notification notification) {
if (notification != null) {
if (NotationPackage.eINSTANCE.getDrawerStyle_Collapsed().equals(notification.getFeature())) {
if (notification.getNotifier() instanceof EObject) {
Option&lt;DDiagram&gt; optionalDDiagram = new EObjectQuery((EObject) notification.getNotifier()).getParentDiagram();
if (optionalDDiagram.some()) {
return "MyDiagramDescriptionName".equals(optionalDDiagram.get().getDescription().getName);
}
}
}
}
return false;
}
});
</pre>
<h2 id="Unregisterapreviouslyregistergraphicalchanges">Unregister a previously register graphical changes</h2>
<p>You can use
<code>org.eclipse.sirius.tools.api.ui.RefreshHelper.unregisterImpactingNotification(Predicate&lt;Notification&gt;)</code> to unregister a previously registered predicate.
</p>
<h2 id="Recommendation">Recommendation</h2>
<p>The
<code>RefreshEditorsPrecommitListener</code> is called after each changes. So each predicate added through
<code>registerImpactingNotification()</code> will be called on each notification (until one is considered as impacting). These predicates must be efficient.
</p>
</body>
</html>