Package org.eclipse.gef.mvc.fx.operations

# Class ChangeContentsOperation

java.lang.Object
org.eclipse.core.commands.operations.AbstractOperation
org.eclipse.gef.mvc.fx.operations.ChangeContentsOperation

All Implemented Interfaces:
  `IUndoableOperation`, `ITransactionalOperation`

public class ChangeContentsOperation extends AbstractOperation implements ITransactionalOperation
The `ChangeContentsOperation` can be used to change the content objects stored in the `IViewer.contentsProperty()`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`DEFAULT_LABEL`
"Change Contents"

## Constructor Summary

Constructors
Constructor
Description
`ChangeContentsOperation(String label, IViewer viewer, List<? extends Object> contents)`
Creates a new `ChangeContentsOperation` for changing the contents of the given `IViewer` to the specified list of objects.
`ChangeContentsOperation(IViewer viewer)`
Constructs a new `ChangeContentsOperation` that can be used to change the contents of the given `IViewer`.
`ChangeContentsOperation(IViewer viewer, List<? extends Object> contents)`
Creates a new `ChangeContentsOperation` for changing the contents of the given `IViewer` to the specified list of objects.

## Method Summary

Modifier and Type
Method
Description
`IStatus`
`execute(IProgressMonitor monitor, IAdaptable info)`
`protected List<? extends Object>`
`getInitialContents()`
Returns the list containing the initial contents by reference.
`protected List<? extends Object>`
`getNewContents()`
Returns the list containing the new contents by reference.
`boolean`
`isContentRelevant()`
Returns `true` if this `ITransactionalOperation` is actually changing model data (instead of only affecting the visualization).
`boolean`
`isNoOp()`
Returns `true` if this `ITransactionalOperation` has no effect (in comparison to its initial state).
`IStatus`
`redo(IProgressMonitor monitor, IAdaptable info)`
`void`
`setNewContents(List<? extends Object> newContents)`
Sets the final contents to the given list.
`IStatus`
`undo(IProgressMonitor monitor, IAdaptable info)`

### Methods inherited from class org.eclipse.core.commands.operations.AbstractOperation

`addContext, canExecute, canRedo, canUndo, dispose, getContexts, getLabel, hasContext, removeContext, setLabel, toString`

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.eclipse.core.commands.operations.IUndoableOperation

`addContext, canExecute, canRedo, canUndo, dispose, getContexts, getLabel, hasContext, removeContext`

## Field Details

### DEFAULT_LABEL

public static final String DEFAULT_LABEL

     "Change Contents"

The default label for this operation (i.e. used if no label is specified).

See Also:
  - Constant Field Values

## Constructor Details

### ChangeContentsOperation

public ChangeContentsOperation(IViewer viewer)
Constructs a new `ChangeContentsOperation` that can be used to change the contents of the given `IViewer`.

The operation is initialized as a no-op, i.e. the initial viewer contents are also used as the final viewer contents.

The final contents can later be set using the `setNewContents(List)` method.

Parameters:
  `viewer` - The `IViewer` of which the `IViewer.contentsProperty()` is to be changed.

### ChangeContentsOperation

public ChangeContentsOperation(IViewer viewer, List<? extends Object> contents)
Creates a new `ChangeContentsOperation` for changing the contents of the given `IViewer` to the specified list of objects.

Parameters:
  `viewer` - The `IViewer` of which the `IViewer.contentsProperty()` is to be changed.
  `contents` - The new content objects to store in the `IViewer.contentsProperty()`.

### ChangeContentsOperation

public ChangeContentsOperation(String label, IViewer viewer, List<? extends Object> contents)
Creates a new `ChangeContentsOperation` for changing the contents of the given `IViewer` to the specified list of objects. The given label is used as the label of the operation.

Parameters:
  `label` - The label of the operation.
  `viewer` - The `IViewer` of which the `IViewer.contentsProperty()` is to be changed.
  `contents` - The new content objects to store in the `IViewer.contentsProperty()`.

## Method Details

### execute

public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException

Specified by:
  `execute` in interface `IUndoableOperation`
Specified by:
  `execute` in class `AbstractOperation`
Throws:
  `ExecutionException`

### getInitialContents

protected List<? extends Object> getInitialContents()
Returns the list containing the initial contents by reference.

Returns:
  the list containing the initial contents by reference.

### getNewContents

protected List<? extends Object> getNewContents()
Returns the list containing the new contents by reference.

Returns:
  the list containing the new contents by reference.

### isContentRelevant

public boolean isContentRelevant()
Description copied from interface: `ITransactionalOperation`
Returns `true` if this `ITransactionalOperation` is actually changing model data (instead of only affecting the visualization). Otherwise returns `false`. The content relevance of an `ITransactionalOperation` can be checked to determine if the execution of the operation will affect the model, for example, to set an editor's dirty flag.

Specified by:
  `isContentRelevant` in interface `ITransactionalOperation`
Returns:
  `true` if this `ITransactionalOperation` is actually changing model data, otherwise `false`.

### isNoOp

public boolean isNoOp()
Description copied from interface: `ITransactionalOperation`
Returns `true` if this `ITransactionalOperation` has no effect (in comparison to its initial state). Otherwise returns `false`.

Specified by:
  `isNoOp` in interface `ITransactionalOperation`
Returns:
  `true` if this `ITransactionalOperation` has no effect, otherwise `false`.

### redo

public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException

Specified by:
  `redo` in interface `IUndoableOperation`
Specified by:
  `redo` in class `AbstractOperation`
Throws:
  `ExecutionException`

### setNewContents

public void setNewContents(List<? extends Object> newContents)
Sets the final contents to the given list.

Parameters:
  `newContents` - The new final contents.

### undo

public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException

Specified by:
  `undo` in interface `IUndoableOperation`
Specified by:
  `undo` in class `AbstractOperation`
Throws:
  `ExecutionException`