Java Reference
In-Depth Information
layout we need is similar, if you consider that mainly the orientation of the lay-
out needs to be changed from vertical to horizontal. This is exactly what the
GMF runtime's
LeftRightProvider
class provides, so we use it as a starting
point.
We could add the following modifications to our generated diagram plug-in,
but as mentioned earlier, this would make regeneration and maintenance more
difficult. Instead, here we create a new
org.eclipse.mindmap.diagram.
custom
plug-in project using PDE and put our modifications in this separate
plug-in.
Let's back up a minute and discuss the big picture of diagram layout and our
needs for the mindmap. You've seen that the main toolbar for all GMF diagrams
has a layout button, with a corresponding context menu on the diagram canvas.
The runtime provides these by default for all diagrams, so it's a matter of adding
our own provider for the layout service to invoke. We begin with the
layoutProviders
extension-point and contribute the following to our
plugin.xml
manifest. Section 10.4.10, “Layout Service,” discusses the layout
service.
<extension point="org.eclipse.gmf.runtime.diagram.ui.layoutProviders">
<layoutProvider class="org.eclipse.mindmap.diagram.layout.
MindmapDefaultLayoutProvider">
<Priority name="Low"/>
</layoutProvider>
</extension>
We've set the priority of our provider to
Low
, which is one level above
Lowest
. Now we need to implement the
MindmapDefaultLayoutProvider
,
as shown here:
public class
MindmapDefaultLayoutProvider
extends
LeftRightProvider {
public static
String DEFAULT_LAYOUT = "Default";
public boolean
provides(IOperation operation) {
// enable this provider only on mindmap diagrams
if
(operation
instanceof
ILayoutNodeOperation) {
Iterator<?> nodes = ((ILayoutNodeOperation)
operation).getLayoutNodes().listIterator();
if
(nodes.hasNext()) {
View node = ((ILayoutNode) nodes.next()).getNode();
Diagram container = node.getDiagram();
if
(container ==
null
||
!(container.getType().equalsIgnoreCase("mindmap")))
return
false;
}
Search WWH ::
Custom Search