## Layout Service Example

### Introduction

This guide describes the Layout Service example in the SDK. This example demonstrates a how to create a custom provider for the Layout Service which can be invoked from with-in a diagram editor.

### Description

This plug-in is named org.eclipse.gmf.examples.runtime.diagram.layout. The purpose of the plug-in is provide an action that invokes a custom layout. In this case the custom layout is called a 'Square' layout which will calculate a square area based on the number of shapes and arrange the shapes in a grid with-in the calculated square.
The algorithm for this custom layout is defined inside a provider called 'SquareLayoutProvider'. To register this provider, an extension for the org.eclipse.gmf.runtime.diagram.ui.layoutProviders extension point must be added to the plugin.xml file.

i.e.

<extension
point="org.eclipse.gmf.runtime.diagram.ui.layoutProviders">
<layoutProvider class="org.eclipse.gmf.examples.runtime.diagram.layout.provider.SquareLayoutProvider">
<Priority
name="Medium">
</Priority>
</layoutProvider>
</extension>
If we examine the 'SquareLayoutProvider' java class, in the provides() routine, it is merely checking to see if the nodes on the diagram can be laid-out according to the algorithm and also verifying that the layout type being passed through the ILayoutNodesOperation is of type 'SQUARE_LAYOUT'. This check is necessary because we only want to invoke this layout when our specific action is called, not when a default arrange action is invoked.
The layoutNodes(?) routine is where the actual computation takes place. It returns a 'Runnable' that performs the execution of the layout.

### Usage

Refer to this example if you need:

1. How to create a manipulate shapes positions programmatically
2. How to create a custom layout provider that can be invoked through a specific action

Copyright (c) 2000,2005 IBM Corporation and others. All Rights Reserved.