org.eclipse.graphiti.pattern.id

## Class IdPattern

- java.lang.Object
- - org.eclipse.graphiti.pattern.AbstractBasePattern
  - - org.eclipse.graphiti.pattern.AbstractPattern
    - - org.eclipse.graphiti.pattern.TypedPattern
      - - org.eclipse.graphiti.pattern.id.IdPattern

All Implemented Interfaces:
  IFeatureProviderHolder, IAdd, ICreate, ICreateInfo, IDelete, IDirectEditing, ILayout, IMoveShape, IRemove, IResizeShape, IUpdate, IPattern

    public abstract class IdPattern
    extends TypedPattern
    implements IPattern

Base class for ID patterns. The basic idea behind is to tag single parts of a pattern shape with IDs (using `Property` objects). These IDs are used to identify the parts of that shape and to call the update and layout methods for the shapes with IDs. Clients do not need to search through the shape hierarchy to find the shapes to update and layout.

Besides IDs this pattern base implementation also supports tagging `PictogramElement`s with an index property that allows to number a sequence of children using the same ID, e.g. a list of attributes inside a class.

Since:
  0.10

### Field Summary

### Fields inherited from interface org.eclipse.graphiti.func.ICreate

`EMPTY`

### Fields inherited from interface org.eclipse.graphiti.func.IDirectEditing

`TYPE_CUSTOM, TYPE_DROPDOWN, TYPE_DROPDOWN_READ_ONLY, TYPE_MULTILINETEXT, TYPE_NONE, TYPE_TEXT`

### Constructor Summary

Constructors
Constructor and Description
`IdPattern()` Default constructor for a new IdPattern.
`IdPattern(IPatternConfiguration patternConfiguration)` Constructor taking some pattern configuration data for the created IdPattern.

### Method Summary

All Methods Instance Methods Concrete Methods
`PictogramElement` `add(IAddContext context)` Adds a `PictogramElement` representation for the given context to the diagram.
`boolean` `canAdd(IAddContext context)` Checks if adding is possible using this pattern in the given context.
`boolean` `canDirectEdit(IDirectEditingContext context)` Clients can override this method to indicate that the pattern allows direct editing for the shape described in the passed `IDirectEditingContext`, but the recommended method to override for `IdPattern` is `canDirectEdit(IDirectEditingContext, String)`.
`boolean` `canLayout(ILayoutContext context)` Checks if layouting a shape is possible using this pattern in the given context.
`boolean` `canUpdate(IUpdateContext context)` Checks if updating a shape is possible using this pattern in the given context.
`String` `checkValueValid(String value, IDirectEditingContext context)` This method will be called by the framework to check if the passed String is valid as new value for the shape.
`int` `getEditingType()` The Graphiti framework calls this method to decide which UI to show up for direct editing.
`String` `getInitialValue(IDirectEditingContext context)` Provides the initial value for display in the newly opened text editing UI component.
`boolean` `layout(ILayoutContext context)` Layouts a `PictogramElement` representation given in the context.
`void` `setValue(String value, IDirectEditingContext context)` Set the new value after direct editing is finished.
`boolean` `update(IUpdateContext context)` Updates a `PictogramElement` representation given in the context.
`IReason` `updateNeeded(IUpdateContext context)` Checks if an updates is needed for a `PictogramElement` representation given in the context.

### Methods inherited from class org.eclipse.graphiti.pattern.AbstractPattern

`canCreate, canDelete, canMoveShape, canRemove, canResizeShape, completeInfo, completeInfo, completeValue, create, delete, getCreateDescription, getCreateImageId, getCreateLargeImageId, getCreateName, getPossibleValues, getProposalSupport, getResizeConfiguration, getValueProposals, hasDoneChanges, isAutoCompletionEnabled, isCompletionAvailable, isDeleteAbort, isMainBusinessObjectApplicable, isPaletteApplicable, isRemoveAbort, moveShape, postDelete, postRemove, preDelete, preRemove, remove, resizeShape, stretchFieldToFitText`

### Methods inherited from class org.eclipse.graphiti.pattern.AbstractBasePattern

`getFeatureProvider, setFeatureProvider`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.eclipse.graphiti.pattern.IPattern

`completeInfo, completeInfo, getCreateDescription, getCreateName, getResizeConfiguration, hasDoneChanges, isMainBusinessObjectApplicable, isPaletteApplicable, setFeatureProvider`

### Methods inherited from interface org.eclipse.graphiti.func.ICreate

`canCreate, create`

### Methods inherited from interface org.eclipse.graphiti.func.ICreateInfo

`getCreateImageId, getCreateLargeImageId`

### Methods inherited from interface org.eclipse.graphiti.func.IDelete

`canDelete, delete, isDeleteAbort, postDelete, preDelete`

### Methods inherited from interface org.eclipse.graphiti.func.IRemove

`canRemove, isRemoveAbort, postRemove, preRemove, remove`

### Methods inherited from interface org.eclipse.graphiti.func.IResizeShape

`canResizeShape, resizeShape`

### Methods inherited from interface org.eclipse.graphiti.func.IMoveShape

`canMoveShape, moveShape`

### Methods inherited from interface org.eclipse.graphiti.func.IDirectEditing

`completeValue, getPossibleValues, getProposalSupport, getValueProposals, isAutoCompletionEnabled, isCompletionAvailable, stretchFieldToFitText`

### Constructor Detail

#### IdPattern

    public IdPattern()

Default constructor for a new IdPattern. Clients should call either call this or the constructor using a `IPatternConfiguration` instance from their subclass constructor.

#### IdPattern

    public IdPattern(IPatternConfiguration patternConfiguration)

Constructor taking some pattern configuration data for the created IdPattern. Clients should call either call this or the null parameter constructor from their subclass constructor.

Parameters:
  `patternConfiguration` - The configuration data to use

### Method Detail

#### canAdd

    public boolean canAdd(IAddContext context)

Checks if adding is possible using this pattern in the given context. The default implementation simply checks if the new object passed in the context is the main domain object for the pattern, see `AbstractPattern.isMainBusinessObjectApplicable(Object)`.

Specified by:
  `canAdd` in interface `IAdd`
Specified by:
  `canAdd` in interface `IPattern`
Overrides:
  `canAdd` in class `AbstractBasePattern`
Parameters:
  `context` - An `IAddContext` describing the add operation.
Returns:
  `true` in case adding is possible, `false` otherwise.

#### add

    public PictogramElement add(IAddContext context)

Adds a `PictogramElement` representation for the given context to the diagram. The default implementation delegates to `doAdd(IAddContext)` (which clients should primarily override) and updates and layouts the returned `PictogramElement` afterwards.

Specified by:
  `add` in interface `IAdd`
Specified by:
  `add` in interface `IPattern`
Overrides:
  `add` in class `AbstractBasePattern`
Parameters:
  `context` - An `IAddContext` describing the add operation.
Returns:
  The root object of the created `PictogramElement` tree.

#### canLayout

    public boolean canLayout(ILayoutContext context)

Checks if layouting a shape is possible using this pattern in the given context. The default implementation simply checks if the object passed in the context is the main domain object for the pattern, see `AbstractPattern.isMainBusinessObjectApplicable(Object)` and if the `PictogramElement` given in the context is controlled by an ID pattern.

Specified by:
  `canLayout` in interface `ILayout`
Overrides:
  `canLayout` in class `AbstractPattern`
Parameters:
  `context` - An `ILayoutContext` describing the layout operation.
Returns:
  `true` in case layouting is possible, `false` otherwise.

#### layout

    public boolean layout(ILayoutContext context)

Layouts a `PictogramElement` representation given in the context. The default implementation delegates to `layout(IdLayoutContext, String)` (which clients should primarily override) to actually update individual `PictogramElement`s. This delegation is done for any `PictogramElement` tagged with an ID in the following order:

- The `PictogramElement` given in the context itself
- The `GraphicsAlgorithm` of the `PictogramElement` in the context
- The `PictogramElement` children of the `PictogramElement` in the context
- The `GraphicsAlgorithm` children of the `GraphicsAlgorithm` of the `PictogramElement` in the context. For this the method `layoutGraphicsAlgorithmChildren(GraphicsAlgorithm, IdLayoutContext)` is called which in term calles itself and this method recursively.

Specified by:
  `layout` in interface `ILayout`
Overrides:
  `layout` in class `AbstractPattern`
Parameters:
  `context` - An `ILayoutContext` describing the layout operation.
Returns:
  `true` in case the layout operation did changes to the diagram, `false` otherwise.

#### canUpdate

    public boolean canUpdate(IUpdateContext context)

Checks if updating a shape is possible using this pattern in the given context. The default implementation simply checks if the object passed in the context is the main domain object for the pattern, see `AbstractPattern.isMainBusinessObjectApplicable(Object)` and if the `PictogramElement` given in the context is controlled by an ID pattern.

Specified by:
  `canUpdate` in interface `IUpdate`
Overrides:
  `canUpdate` in class `AbstractPattern`
Parameters:
  `context` - An `IUpdateContext` describing the update operation.
Returns:
  `true` in case updating is possible, `false` otherwise.

#### updateNeeded

    public IReason updateNeeded(IUpdateContext context)

Checks if an updates is needed for a `PictogramElement` representation given in the context. The default implementation delegates to `updateNeeded(IdUpdateContext, String)` (which clients should primarily override) to actually update individual `PictogramElement`s. This delegation is done for any `PictogramElement` tagged with an ID in the following order:

- The `PictogramElement` given in the context itself
- The `GraphicsAlgorithm` of the `PictogramElement` in the context
- The `PictogramElement` children of the `PictogramElement` in the context
- The `GraphicsAlgorithm` children of the `GraphicsAlgorithm` of the `PictogramElement` in the context. For this the method `updateNeededGraphicsAlgorithmChildren(GraphicsAlgorithm, IdUpdateContext)` is called which in term calls itself and this method recursively.

Specified by:
  `updateNeeded` in interface `IUpdate`
Overrides:
  `updateNeeded` in class `AbstractPattern`
Parameters:
  `context` - An `IUpdateContext` describing the update operation.
Returns:
  An `IReason` indicating `true` and a `String` reason in case the update operation is needed, an `IReason` indicating `false` otherwise.

#### update

    public boolean update(IUpdateContext context)

Updates a `PictogramElement` representation given in the context. The default implementation only delegates to `update(IUpdateContext, boolean)` setting the parameter innerCall to `false`.

Specified by:
  `update` in interface `IUpdate`
Overrides:
  `update` in class `AbstractPattern`
Parameters:
  `context` - An `IUpdateContext` describing the update operation.
Returns:
  `true` in case the update operation did changes to the diagram, `false` otherwise.

#### getEditingType

    public int getEditingType()

The Graphiti framework calls this method to decide which UI to show up for direct editing. Corresponds to the method `IDirectEditing.getEditingType()`. The default implementation return `IDirectEditing.TYPE_NONE`, other valid type are defined by the TYPE_* constants in `IDirectEditing`.

Specified by:
  `getEditingType` in interface `IDirectEditing`
Overrides:
  `getEditingType` in class `AbstractPattern`
Returns:
  The desired editing type

#### canDirectEdit

    public boolean canDirectEdit(IDirectEditingContext context)

Clients can override this method to indicate that the pattern allows direct editing for the shape described in the passed `IDirectEditingContext`, but the recommended method to override for `IdPattern` is `canDirectEdit(IDirectEditingContext, String)`. Corresponds to the method `AbstractDirectEditingFeature.canDirectEdit(IDirectEditingContext)` . The default implementation checks if the pattern is responsible for the shape and an ID is set; in that case it delegates to `canDirectEdit(IDirectEditingContext, String)`.

Specified by:
  `canDirectEdit` in interface `IDirectEditing`
Overrides:
  `canDirectEdit` in class `AbstractPattern`
Parameters:
  `context` - A context object describing the direct edit request.
Returns:
  `true` in case direct editing shall be allowed, `false` otherwise.
See Also:
  `IFeature.canExecute(org.eclipse.graphiti.features.context.IContext)`

#### getInitialValue

    public String getInitialValue(IDirectEditingContext context)

Provides the initial value for display in the newly opened text editing UI component. Corresponds to the method `IDirectEditing.getInitialValue(IDirectEditingContext)` . The default implementation checks if the pattern is responsible for the shape and an ID is set; in that case it delegates to `getInitialValue(IDirectEditingContext, String)`.

Specified by:
  `getInitialValue` in interface `IDirectEditing`
Overrides:
  `getInitialValue` in class `AbstractPattern`
Parameters:
  `context` - A context object describing the direct edit request.
Returns:
  The initial string value to be displayed for editing by the user.

#### checkValueValid

    public String checkValueValid(String value,
                                  IDirectEditingContext context)

This method will be called by the framework to check if the passed String is valid as new value for the shape. This method's response time should be small since the method is queried after each change of the value in the direct edit UI. In case of a not valid value, the returned string shall indicate the reason why the value is not valid. Corresponds to the method `AbstractDirectEditingFeature.checkValueValid(String, IDirectEditingContext)` . The default implementation checks if the pattern is responsible for the shape and an ID is set; in that case it delegates to `checkValueValid(String, IDirectEditingContext, String)`.

Specified by:
  `checkValueValid` in interface `IDirectEditing`
Overrides:
  `checkValueValid` in class `AbstractPattern`
Parameters:
  `value` - The new value to check
  `context` - A context object describing the direct edit request.
Returns:
  `null` in case of a valid value, a string describing the reason for being not valid otherwise.

#### setValue

    public void setValue(String value,
                         IDirectEditingContext context)

Set the new value after direct editing is finished. The value comes from the text editing UI component. Corresponds to the method `AbstractDirectEditingFeature.setValue(String, IDirectEditingContext)` . The default implementation checks if the pattern is responsible for the shape and an ID is set; in that case it delegates to `setValue(String, IDirectEditingContext, String)`.

Specified by:
  `setValue` in interface `IDirectEditing`
Overrides:
  `setValue` in class `AbstractPattern`
Parameters:
  `value` - The new value to be set
  `context` - A context object describing the direct edit request.