Packagecom.yworks.graph.model
Classpublic class GraphClipboard
InheritanceGraphClipboard Inheritance flash.events.EventDispatcher

Clipboard implementation for IGraph instances.

This implementation copies a given graph to an internally held clipboard graph. The clipboard graph can then be pasted to a target graph instance.

See also

IClipboardHelper
cut
copy
paste
clipboardGraph


Public Properties
 PropertyDefined By
  clipboardGraph : IGraph
The graph which is used as clipboard.
GraphClipboard
  copier : GraphCopier
The GraphCopier instance that will be used to copy the graph to the clipboard and from the clipboard to the graph.
GraphClipboard
  empty : Boolean
[read-only] Determines whether the clipboard graph is empty.
GraphClipboard
  pasteDelta : IPoint
A vector that will be used to move nodes and bends by after they have been pasted to the target graph.
GraphClipboard
Public Methods
 MethodDefined By
  
Creates a new initially empty clipboard.
GraphClipboard
  
clear():void
Clears the clipboard's contents.
GraphClipboard
  
copy(sourceGraph:IGraph, filter:Function):void
Copies the elements indicated by the filter to the clipboard graph.
GraphClipboard
  
Convenience method that creates a Function that is based upon the outcome of the IClipboardHelper.shouldCopy method that can be found in the ILookup.lookup of the provided IModelItem.
GraphClipboard
  
Convenience method that creates a Function that is based upon the outcome of the IClipboardHelper.shouldCut method that can be found in the ILookup.Lookup of the provided IModelItem.
GraphClipboard
  
Convenience method that creates a filter Function that is based upon the outcome of the IClipboardHelper.ShouldPaste method that can be found in the ILookup.lookup of the provided IModelItem.
GraphClipboard
  
Creates a Function for use in the cut and copy methods.
GraphClipboard
  
cut(sourceGraph:IGraph, filter:Function):void
Cuts the items indicated by filter to the clipboard and removes them from the graph.
GraphClipboard
  
getMemento(clipboardModelItem:IModelItem):Object
Retrieves the memento associated with an item in the clipboard graph that has been stored with the item during onElementCopied and onElementCut.
GraphClipboard
  
paste(targetGraph:IGraph, graphSelection:IGraphSelection = null, filter:Function = null, elementPasted:Function = null):void
Pastes the contents from the clipboardGraph to the targetGraph after applying a filter.
GraphClipboard
Protected Methods
 MethodDefined By
  
Adjusts the state of the dummy edge after a paste operation according to pasteDelta.
GraphClipboard
  
Adjusts the state of the dummy node after a paste operation according to pasteDelta.
GraphClipboard
  
adjustPosition(copiedItem:IModelItem):void
Moves the item after a paste operation according to pasteDelta.
GraphClipboard
  
copyImpl(sourceGraph:IGraph, filter:Function, targetRoot:INode, targetGraph:IGraph, elementCopiedDelegate:Function):void
Calls GraphCopier.copy() on the current copier instance.
GraphClipboard
  
Creates the graph used for the clipboard.
GraphClipboard
  
Factory method that creates the copier.
GraphClipboard
  
Retrieves the IClipboardHelper instance associated with the given item.
GraphClipboard
  
Delegate that will be invoked for each item that has been copied into the clipboard graph in response to a copy operation.
GraphClipboard
  
onElementCut(original:IModelItem, copy:IModelItem):void
Delegate that will be invoked for each item that has been copied into the clipboard graph in response to a cut operation.
GraphClipboard
  
Delegate that will be invoked for each item that has been pasted into the target graph in response to a paste(IGraph) operation.
GraphClipboard
  
removeElements(sourceGraph:IGraph, filter:Function):void
Removes elements from the graph based on the predicate function.
GraphClipboard
Public Constants
 ConstantDefined By
  defaultExpansionStateMapperTag : String = defaultExpansionState
[static]
GraphClipboard
Property Detail
clipboardGraphproperty
clipboardGraph:IGraph

The graph which is used as clipboard.

This property can be used as the source for data binding.


Implementation
    public function get clipboardGraph():IGraph
    public function set clipboardGraph(value:IGraph):void

Throws
ArgumentError — if the clipboardGraph is set to null
copierproperty 
copier:GraphCopier

The GraphCopier instance that will be used to copy the graph to the clipboard and from the clipboard to the graph.

This instance is lazily created using createCopier.

This property can be used as the source for data binding.


Implementation
    public function get copier():GraphCopier
    public function set copier(value:GraphCopier):void
emptyproperty 
empty:Boolean  [read-only]

Determines whether the clipboard graph is empty.

This property can be used as the source for data binding.


Implementation
    public function get empty():Boolean
pasteDeltaproperty 
pasteDelta:IPoint

A vector that will be used to move nodes and bends by after they have been pasted to the target graph.

onElementPasted will use this in adjustPosition to adjust the position of the nodes and bends.

This property can be used as the source for data binding.


Implementation
    public function get pasteDelta():IPoint
    public function set pasteDelta(value:IPoint):void
Constructor Detail
GraphClipboard()Constructor
public function GraphClipboard()

Creates a new initially empty clipboard.

Method Detail
adjustDummyEdgePosition()method
protected function adjustDummyEdgePosition(callback:IChangeDummyEdgeAppearanceCallback, edgeViewState:IEdge):void

Adjusts the state of the dummy edge after a paste operation according to pasteDelta.

Parameters

callback:IChangeDummyEdgeAppearanceCallback — The callback to use to adjust the position.
 
edgeViewState:IEdge — The state of the edge to adjust the position of after it has been pasted into the target graph.

See also

adjustDummyNodePosition()method 
protected function adjustDummyNodePosition(callback:IChangeDummyNodeAppearanceCallback, nodeViewState:INode):void

Adjusts the state of the dummy node after a paste operation according to pasteDelta.

Parameters

callback:IChangeDummyNodeAppearanceCallback — The callback to use to adjust the position.
 
nodeViewState:INode — The state of the node to adjust after it has been pasted into the target graph.

See also

adjustPosition()method 
protected function adjustPosition(copiedItem:IModelItem):void

Moves the item after a paste operation according to pasteDelta.

For each INode and IBend this method will ILookup.lookup the IMovable implementation and if successfull will move that element by the amount specified by pasteDelta.

Parameters

copiedItem:IModelItem — The item to adjust the position of after it has been pasted into the target graph.

clear()method 
public function clear():void

Clears the clipboard's contents.

copy()method 
public function copy(sourceGraph:IGraph, filter:Function):void

Copies the elements indicated by the filter to the clipboard graph.

For each element copied to the clipboard graph the onElementCopied delegate will be called. The actual work of this method is delegated to the copier's GraphCopier.copy method.

Parameters

sourceGraph:IGraph — The graph to copy the contents from.
 
filter:Function — The filter to apply to the source graph's elements.

copyImpl()method 
protected function copyImpl(sourceGraph:IGraph, filter:Function, targetRoot:INode, targetGraph:IGraph, elementCopiedDelegate:Function):void

Calls GraphCopier.copy() on the current copier instance.

Parameters

sourceGraph:IGraph — The graph to copy the elements from.
 
filter:Function — The filter that decides which elements to copy: a function which takes a IModelItem as parameter and returns true if the item should be copied.
 
targetRoot:INode — The graph to copy the elements to.
 
targetGraph:IGraph — A delegate to invoke for each element being copied.
 
elementCopiedDelegate:Function

createClipboardGraph()method 
protected function createClipboardGraph():IGraph

Creates the graph used for the clipboard.

Returns
IGraph — A new preconfigured DefaultGraph instance.
createClipBoardHelperCopyFilter()method 
public function createClipBoardHelperCopyFilter():Function

Convenience method that creates a Function that is based upon the outcome of the IClipboardHelper.shouldCopy method that can be found in the ILookup.lookup of the provided IModelItem.

Returns
Function — A function that uses IClipboardHelper.shouldCopy

See also

createClipBoardHelperCutFilter()method 
public function createClipBoardHelperCutFilter():Function

Convenience method that creates a Function that is based upon the outcome of the IClipboardHelper.shouldCut method that can be found in the ILookup.Lookup of the provided IModelItem.

Returns
Function — A function that uses IClipboardHelper.shouldCut

See also

createClipBoardHelperPasteFilter()method 
public function createClipBoardHelperPasteFilter():Function

Convenience method that creates a filter Function that is based upon the outcome of the IClipboardHelper.ShouldPaste method that can be found in the ILookup.lookup of the provided IModelItem.

Returns
Function — A predicate that uses IClipboardHelper.shouldPaste.
createCopier()method 
protected function createCopier():GraphCopier

Factory method that creates the copier.

Returns
GraphCopier — A new GraphCopier instance.
createSelectionFilter()method 
public function createSelectionFilter(selection:IGraphSelection):Function

Creates a Function for use in the cut and copy methods.

This filter bases its predicate upon the fact whether the element is induced by a set of selected nodes, i.e. each edge that has both of its adjacent port owners selected will be included as well as each label and port whose owner is included.

Parameters

selection:IGraphSelection — The selection model to base the filter on.

Returns
Function — A predicate that filters subgraph induced by the selection of nodes.
cut()method 
public function cut(sourceGraph:IGraph, filter:Function):void

Cuts the items indicated by filter to the clipboard and removes them from the graph.

This method delegates the core work to copy()

Parameters

sourceGraph:IGraph — The graph to cut the items from.
 
filter:Function — The filter to use.

See also

getClipboardHelper()method 
protected function getClipboardHelper(item:IModelItem):IClipboardHelper

Retrieves the IClipboardHelper instance associated with the given item.

This implementation uses the item's ILookup.lookup method to retrieve the helper instance.

Parameters

item:IModelItem — The item to find the clipboard helper for.

Returns
IClipboardHelper — An instance or .
getMemento()method 
public function getMemento(clipboardModelItem:IModelItem):Object

Retrieves the memento associated with an item in the clipboard graph that has been stored with the item during onElementCopied and onElementCut.

Parameters

clipboardModelItem:IModelItem — The item in the clipboard graph.

Returns
Object — The object returned by the IClipboardHelper methods or null.
onElementCopied()method 
protected function onElementCopied(original:IModelItem, copy:IModelItem):void

Delegate that will be invoked for each item that has been copied into the clipboard graph in response to a copy operation.

This implementation will ILookup.lookup a IClipboardHelper for each item in the original graph and remember the memento retrieved by the IClipboardHelper.copy method for later use during the onElementPasted operation.

Parameters

original:IModelItem — The original element from the source graph instance.
 
copy:IModelItem — The copy from the clipboard graph.

onElementCut()method 
protected function onElementCut(original:IModelItem, copy:IModelItem):void

Delegate that will be invoked for each item that has been copied into the clipboard graph in response to a cut operation.

This implementation will ILookup.lookup a IClipboardHelper for each item in the original graph and remember the memento retrieved by the IClipboardHelper.cut method for later use during the onElementPasted operation.

Parameters

original:IModelItem — The original element from the source graph instance.
 
copy:IModelItem — The copy from the clipboard graph.

onElementPasted()method 
protected function onElementPasted(original:IModelItem, copy:IModelItem):void

Delegate that will be invoked for each item that has been pasted into the target graph in response to a paste(IGraph) operation.

This method will use a previously stored IClipboardHelper to let IClipboardHelper.pastefinish its work.

Parameters

original:IModelItem — The original element from the clipboard graph instance.
 
copy:IModelItem — The copy from the target graph.

paste()method 
public function paste(targetGraph:IGraph, graphSelection:IGraphSelection = null, filter:Function = null, elementPasted:Function = null):void

Pastes the contents from the clipboardGraph to the targetGraph after applying a filter. If the IGraphSelection instance of the target graph is passed, all pasted items will be selected.

For each element pasted into the graph the elementPasted delegate will be invoked and the onElementPasted method will be called. The actual work of this method is delegated to the copier's GraphCopier.copy() method. As a final step, this method will invoke the adjustPosition method for all items that have been pasted.

Parameters

targetGraph:IGraph — The graph to paste the contents in.
 
graphSelection:IGraphSelection (default = null) — The selection model to set the selection on. If none is provided, the pasted elements will not be selected.
 
filter:Function (default = null) — The filter to apply to the clipboard graph: a function which takes a IModelItem as parameter and returns true if that item should be pasted. If no filter is provided, all items of the clipboard graph will be pasted, except the ones which have a IClipboardHelper instance whose shouldPaste method returns false as memento.
 
elementPasted:Function (default = null) — The callback to use for each element that has been pasted.

removeElements()method 
protected function removeElements(sourceGraph:IGraph, filter:Function):void

Removes elements from the graph based on the predicate function.

Parameters

sourceGraph:IGraph — The graph to remove elements from.
 
filter:Function — The filter that decides which elements to remove: a function which takes a IModelItem as parameter and returns true if the item should be removed.

Constant Detail
defaultExpansionStateMapperTagConstant
public static const defaultExpansionStateMapperTag:String = defaultExpansionState