public class GraphClipboard extends Object
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.
The clipboard can be configured to copy and paste items that depend on other items
without copying the items it depends on, e.g. labels, ports, edges, and bends.
Also depending on the selection in the target graph, items can be pasted at multiple locations at once, e.g. a single label can be copied to the clipboard independently and pasted onto several selected target items.
Modifier and Type | Class and Description |
---|---|
static class |
GraphClipboard.ParentNodeDetectionModes
Defines the rules for pasting nodes into group nodes.
|
Constructor and Description |
---|
GraphClipboard()
Creates a new initially empty clipboard.
|
Modifier and Type | Method and Description |
---|---|
void |
addElementsCopiedListener(IEventHandler<IEventArgs> elementsCopiedEvent)
Adds the given listener for the
ElementsCopied event that occurs when the copy(IGraph, Predicate)
operation finished successfully. |
void |
addElementsCutListener(IEventHandler<IEventArgs> elementsCutEvent)
Adds the given listener for the
ElementsCut event that occurs when the cut(IGraph, Predicate) operation
finished successfully. |
void |
addElementsPastedListener(IEventHandler<IEventArgs> elementsPastedEvent)
Adds the given listener for the
ElementsPasted event that occurs when the paste(IInputModeContext, IGraph, Predicate, IElementCopiedCallback, Predicate)
operation finished successfully. |
void |
clear()
Clears the clipboard's contents.
|
void |
copy(IGraph sourceGraph,
Predicate<IModelItem> filter)
Copies the elements indicated by the filter to the clipboard graph.
|
protected void |
copy(IGraph sourceGraph,
Predicate<IModelItem> filter,
IGraph targetGraph,
INode targetRootNode,
IElementCopiedCallback elementCopiedCallback)
Calls
GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback) on the current ToClipboardCopier
instance or FromClipboardCopier instance, depending on whether the targetGraph
is the ClipboardGraph instance. |
protected IGraph |
createClipboardGraph()
Creates the graph used for the clipboard.
|
Predicate<IModelItem> |
createClipBoardHelperCopyFilter()
Convenience method that creates a
Predicate that is based upon the outcome of the IClipboardHelper.shouldCopy(IGraphClipboardContext, IModelItem)
method that can be found in the ILookup.lookup(Class) of the provided
IModelItem . |
Predicate<IModelItem> |
createClipBoardHelperCutFilter()
Convenience method that creates a
Predicate that is based upon the outcome of the IClipboardHelper.shouldCut(IGraphClipboardContext, IModelItem)
method that can be found in the ILookup.lookup(Class) of the provided
IModelItem . |
Predicate<IModelItem> |
createClipBoardHelperPasteFilter()
Convenience method that creates a
Predicate that is based upon the outcome of the IClipboardHelper.shouldPaste(IGraphClipboardContext, IModelItem, Object)
method that can be found in the ILookup.lookup(Class) of the provided
IModelItem . |
protected IGraphClipboardContext |
createContext(IGraph sourceGraph,
IGraph targetGraph)
Factory method that creates the context for the upcoming calls to the
IClipboardHelper methods. |
protected IClipboardIdProvider |
createDefaultClipboardIdProvider()
Creates the default
IClipboardIdProvider used by this instance to provide IDs for copied items. |
Predicate<IModelItem> |
createDefaultCopyFilter(IGraphSelection selection,
IGraph graph)
Creates a
Predicate for use in the copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
method. |
Predicate<IModelItem> |
createDefaultCutFilter(IGraphSelection selection,
IGraph graph)
Creates a
Predicate for use in the cut(IGraph, Predicate) method. |
Predicate<IModelItem> |
createDefaultDuplicateFilter(IGraphSelection selection,
IGraph graph)
Creates a
Predicate for use in the duplicate(IInputModeContext, IGraph, Predicate, IElementCopiedCallback)
method. |
protected GraphCopier |
createDuplicateCopier()
Factory method that creates the
DuplicateCopier . |
protected GraphCopier |
createFromClipboardCopier()
Factory method that creates the
FromClipboardCopier . |
Predicate<IModelItem> |
createSelectionFilter(IGraphSelection selection,
IGraph graph)
Creates a
Predicate for use in the cut(IGraph, Predicate) and copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
methods. |
protected GraphCopier |
createToClipboardCopier()
Factory method that creates the
ToClipboardCopier . |
static Predicate<IModelItem> |
createWrappedFilter(Predicate<IModelItem> coreFilter,
IGraph graph,
boolean restrictive)
Creates an induced
Predicate from coreFilter for use in the cut(IGraph, Predicate) and copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
methods that takes dependent items into account. |
void |
cut(IGraph sourceGraph,
Predicate<IModelItem> filter)
Cuts the items indicated by
filter to the clipboard and removes them from the graph. |
void |
duplicate(IInputModeContext context,
IGraph sourceGraph,
Predicate<IModelItem> filter,
IElementCopiedCallback elementDuplicated)
Duplicates the elements indicated by the filter.
|
IGraph |
getClipboardGraph()
Gets the graph that contains the clipboard's contents.
|
protected IClipboardHelper |
getClipboardHelper(IModelItem item)
Retrieves the
IClipboardHelper instance associated with the given item. |
GraphItemTypes |
getCopyItems()
Gets the type of items that can be copied and pasted at all using the clipboard.
|
GraphItemTypes |
getDependentCopyItems()
Gets the type of items that depend on other elements but should automatically be copied implicitly to the clipboard if
all elements that it depends on are explicitly selected for copying.
|
GraphCopier |
getDuplicateCopier()
Gets the
GraphCopier instance that will be used to duplicate elements inside the graph. |
protected IEdge |
getFoldingEdgeState(IEdge edge,
FoldingEdgeStateId id)
Gets a folding state of an edge for a given
FoldingEdgeStateId . |
GraphCopier |
getFromClipboardCopier()
Gets the
GraphCopier instance that will be used to copy the graph from the clipboard to the target graph. |
IClipboardIdProvider |
getIdProvider()
Gets the
IClipboardIdProvider used by this instance to provide IDs for copied items. |
GraphItemTypes |
getIndependentCopyItems()
Gets the type of items that can be copied and pasted independently of their owning element.
|
protected ILabelModelParameter |
getLabelLayoutParameter(GraphCopier copier,
IGraph graph,
ILabel label,
ILabelOwner newOwner)
|
Object |
getMemento(IModelItem clipboardItem)
Retrieves the memento associated with an item in the clipboard graph that has been stored with the item during
onElementCopied(IModelItem, IModelItem)
and onElementCut(IModelItem, IModelItem) . |
GraphClipboard.ParentNodeDetectionModes |
getParentNodeDetection()
Gets whether or not nodes should be automatically put into a group node and if so how this group will be determined.
|
PointD |
getPasteDelta()
Gets a vector that will be used to move nodes and bends by after they have been pasted to the target graph.
|
protected IPortLocationModelParameter |
getPortLocationParameter(GraphCopier copier,
IGraph graph,
IPort originalPort,
IPortOwner newOwner)
|
protected IEdge |
getTarget(IBend originalBend)
Provides an
IEdge where the given originalBend can be added to. |
protected IPort |
getTarget(IEdge originalEdge,
boolean atSource)
Provides an
IPort where the given originalEdge can be added to. |
protected ILabelOwner |
getTarget(ILabel originalLabel)
Provides an
ILabelOwner where the given originalLabel can be added to. |
protected INode |
getTarget(INode originalNode)
Provides a parent group node for the given
originalNode . |
protected IPortOwner |
getTarget(IPort originalPort)
Provides an
IPortOwner where the given originalPort can be added to. |
GraphCopier |
getToClipboardCopier()
Gets the
GraphCopier instance that will be used to copy the graph to the clipboard. |
boolean |
isDummy(IModelItem item)
Whether the given
item is a "dummy" item which should not be pasted. |
boolean |
isEmpty()
Determines whether the clipboard graph is empty.
|
protected static boolean |
isFoldingStateElement(IModelItem owner,
IModelItem item)
Whether the given
item exists in a folding state of its owner . |
boolean |
isIgnoringEdgesWithOneNodeEnabled()
Whether to paste edges whose source or target node was selected when copying to the clipboard while the other node was
not.
|
protected void |
onElementCopied(IModelItem original,
IModelItem copy)
IElementCopiedCallback that will be invoked for each item that has been copied into the clipboard graph in
response to a copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback) operation. |
protected void |
onElementCut(IModelItem original,
IModelItem copy)
IElementCopiedCallback that will be invoked for each item that has been copied into the clipboard graph in
response to a cut(IGraph, Predicate) operation. |
protected void |
onElementPasted(IModelItem original,
IModelItem copy)
IElementCopiedCallback that will be invoked for each item that has been pasted into the target graph in response
to a paste(IGraph, Predicate, IGraph, INode, IElementCopiedCallback, Predicate) operation. |
void |
paste(IGraph targetGraph)
|
void |
paste(IGraph targetGraph,
IGraphSelection selection)
Pastes the
ClipboardGraph 's contents into the
targetGraph , selecting all pasted elements. |
void |
paste(IGraph targetGraph,
Predicate<IModelItem> filter)
|
void |
paste(IGraph targetGraph,
Predicate<IModelItem> filter,
IElementCopiedCallback elementPasted)
|
protected void |
paste(IGraph sourceGraph,
Predicate<IModelItem> filter,
IGraph targetGraph,
INode targetRootNode,
IElementCopiedCallback elementCopiedCallback,
Predicate<IModelItem> targetFilter)
Calls
GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback) on the current FromClipboardCopier
instance, depending on whether the targetGraph is the ClipboardGraph instance. |
void |
paste(IInputModeContext context,
IGraph targetGraph,
Predicate<IModelItem> filter,
IElementCopiedCallback elementPasted,
Predicate<IModelItem> targetFilter)
|
protected void |
removeElements(IGraph sourceGraph,
Predicate<IModelItem> predicate)
Removes elements from the graph based on a
Predicate . |
void |
removeElementsCopiedListener(IEventHandler<IEventArgs> elementsCopiedEvent)
Removes the given listener for the
ElementsCopied event that occurs when the copy(IGraph, Predicate)
operation finished successfully. |
void |
removeElementsCutListener(IEventHandler<IEventArgs> elementsCutEvent)
Removes the given listener for the
ElementsCut event that occurs when the cut(IGraph, Predicate)
operation finished successfully. |
void |
removeElementsPastedListener(IEventHandler<IEventArgs> elementsPastedEvent)
Removes the given listener for the
ElementsPasted event that occurs when the paste(IInputModeContext, IGraph, Predicate, IElementCopiedCallback, Predicate)
operation finished successfully. |
void |
setClipboardGraph(IGraph value)
Sets the graph that contains the clipboard's contents.
|
void |
setCopyItems(GraphItemTypes value)
Sets the type of items that can be copied and pasted at all using the clipboard.
|
void |
setDependentCopyItems(GraphItemTypes value)
Sets the type of items that depend on other elements but should automatically be copied implicitly to the clipboard if
all elements that it depends on are explicitly selected for copying.
|
void |
setDuplicateCopier(GraphCopier value)
Sets the
GraphCopier instance that will be used to duplicate elements inside the graph. |
void |
setFromClipboardCopier(GraphCopier value)
Sets the
GraphCopier instance that will be used to copy the graph from the clipboard to the target graph. |
void |
setIdProvider(IClipboardIdProvider value)
Sets the
IClipboardIdProvider used by this instance to provide IDs for copied items. |
void |
setIgnoringEdgesWithOneNodeEnabled(boolean value)
Whether to paste edges whose source or target node was selected when copying to the clipboard while the other node was
not.
|
void |
setIndependentCopyItems(GraphItemTypes value)
Sets the type of items that can be copied and pasted independently of their owning element.
|
void |
setParentNodeDetection(GraphClipboard.ParentNodeDetectionModes value)
Sets whether or not nodes should be automatically put into a group node and if so how this group will be determined.
|
void |
setPasteDelta(PointD value)
Sets a vector that will be used to move nodes and bends by after they have been pasted to the target graph.
|
void |
setToClipboardCopier(GraphCopier value)
Sets the
GraphCopier instance that will be used to copy the graph to the clipboard. |
public final void addElementsCopiedListener(IEventHandler<IEventArgs> elementsCopiedEvent)
ElementsCopied
event that occurs when the copy(IGraph, Predicate)
operation finished successfully.elementsCopiedEvent
- The listener to add.removeElementsCopiedListener(IEventHandler)
public final void addElementsCutListener(IEventHandler<IEventArgs> elementsCutEvent)
ElementsCut
event that occurs when the cut(IGraph, Predicate)
operation
finished successfully.elementsCutEvent
- The listener to add.removeElementsCutListener(IEventHandler)
public final void addElementsPastedListener(IEventHandler<IEventArgs> elementsPastedEvent)
ElementsPasted
event that occurs when the paste(IInputModeContext, IGraph, Predicate, IElementCopiedCallback, Predicate)
operation finished successfully.elementsPastedEvent
- The listener to add.removeElementsPastedListener(IEventHandler)
public void clear()
public void copy(IGraph sourceGraph, Predicate<IModelItem> filter)
For each element copied to the clipboard graph the onElementCopied(IModelItem, IModelItem)
delegate will be
called. The actual work of this method is delegated to the ToClipboardCopier
's GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
method.
sourceGraph
- The graph to copy the contents from.filter
- The filter to apply to the source graph's elements.protected void copy(IGraph sourceGraph, Predicate<IModelItem> filter, IGraph targetGraph, INode targetRootNode, IElementCopiedCallback elementCopiedCallback)
GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
on the current ToClipboardCopier
instance or FromClipboardCopier
instance, depending on whether the targetGraph
is the ClipboardGraph
instance.sourceGraph
- The source graph to pass to GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
filter
- The predicate to pass on.targetGraph
- The target graph to pass on.targetRootNode
- The node to use as the root node in the grouped targetGraph
.elementCopiedCallback
- The delegate to pass on. For each element that is copied during the operation to the clipboard, this callback will be
passed the original and the copy of the item. In case the sourceGraph
is a folding view graph
both elements are passed as master
elements or folding state elements
if a master element does not exist.protected IGraph createClipboardGraph()
DefaultGraph
instance.public Predicate<IModelItem> createClipBoardHelperCopyFilter()
Predicate
that is based upon the outcome of the IClipboardHelper.shouldCopy(IGraphClipboardContext, IModelItem)
method that can be found in the ILookup.lookup(Class)
of the provided
IModelItem
.IClipboardHelper.shouldCopy(IGraphClipboardContext, IModelItem)
.copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
public Predicate<IModelItem> createClipBoardHelperCutFilter()
Predicate
that is based upon the outcome of the IClipboardHelper.shouldCut(IGraphClipboardContext, IModelItem)
method that can be found in the ILookup.lookup(Class)
of the provided
IModelItem
.IClipboardHelper.shouldCut(IGraphClipboardContext, IModelItem)
.cut(IGraph, Predicate)
public Predicate<IModelItem> createClipBoardHelperPasteFilter()
Predicate
that is based upon the outcome of the IClipboardHelper.shouldPaste(IGraphClipboardContext, IModelItem, Object)
method that can be found in the ILookup.lookup(Class)
of the provided
IModelItem
.IClipboardHelper.shouldPaste(IGraphClipboardContext, IModelItem, Object)
.cut(IGraph, Predicate)
protected IGraphClipboardContext createContext(IGraph sourceGraph, IGraph targetGraph)
IClipboardHelper
methods.sourceGraph
- The source graph of the operation.targetGraph
- The target graph of the operation.protected IClipboardIdProvider createDefaultClipboardIdProvider()
IClipboardIdProvider
used by this instance to provide IDs for copied items.
The default implementation simply uses a reference to the original item as ID.
Custom ID can be used to map between elements in different graphs.
public Predicate<IModelItem> createDefaultCopyFilter(IGraphSelection selection, IGraph graph)
Predicate
for use in the copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
method.
This filter uses two predicates to decide whether a graph item can be copied. The base set of items specified by this
filter is induced by the createSelectionFilter(IGraphSelection, IGraph)
. Optionally, this set can be restricted
further by an IClipboardHelper.shouldCopy(IGraphClipboardContext, IModelItem)
predicate. If such a predicate
returns false
for the item itself or any item this item depends on, then the item will not be copied. Items
without such a predicate are handled solely according to their selection state.
selection
- The selection model to base the filter on.graph
- The graph to use for determining adjacency.IClipboardHelper.shouldCopy(IGraphClipboardContext, IModelItem)
predicate.public Predicate<IModelItem> createDefaultCutFilter(IGraphSelection selection, IGraph graph)
Predicate
for use in the cut(IGraph, Predicate)
method.
This filter uses two predicates to decide whether a graph item can be cut. The base set of items specified by this
filter is induced by the createSelectionFilter(IGraphSelection, IGraph)
. Optionally, this set can be restricted
further by an IClipboardHelper.shouldCut(IGraphClipboardContext, IModelItem)
predicate. If such a predicate
returns false
for the item itself or any item this item depends on, then the item will not be cut. Items without
such a predicate are handled solely according to their selection state.
selection
- The selection model to base the filter on.graph
- The graph to use for determining adjacency.IClipboardHelper.shouldCut(IGraphClipboardContext, IModelItem)
predicate.public Predicate<IModelItem> createDefaultDuplicateFilter(IGraphSelection selection, IGraph graph)
Predicate
for use in the duplicate(IInputModeContext, IGraph, Predicate, IElementCopiedCallback)
method.
By default this method uses the same filter implementation as createDefaultCopyFilter(IGraphSelection, IGraph)
:
This filter uses two predicates to decide whether a graph item will be duplicated. The base set of items specified by
this filter is induced by the createSelectionFilter(IGraphSelection, IGraph)
. Optionally, this set can be
restricted further by an IClipboardHelper.shouldCopy(IGraphClipboardContext, IModelItem)
predicate. If such a
predicate returns false
for the item itself or any item this item depends on, then the item will not be copied.
Items without such a predicate are handled solely according to their selection state.
selection
- The selection model to base the filter on.graph
- The graph to use for determining adjacency.IClipboardHelper.shouldCopy(IGraphClipboardContext, IModelItem)
predicate.protected GraphCopier createDuplicateCopier()
DuplicateCopier
.GraphCopier
instance.protected GraphCopier createFromClipboardCopier()
FromClipboardCopier
.GraphCopier
instance.public Predicate<IModelItem> createSelectionFilter(IGraphSelection selection, IGraph graph)
Predicate
for use in the cut(IGraph, Predicate)
and copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
methods.
This predicate is based on the element induced by the set of selected nodes, e.g. 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. Also ports where
no adjacent edge is included (but edges exist), will not be included, unless the AutoCleanupEnabled
is set to false
.
selection
- The selection model to base the filter on.graph
- The graph to use for determining adjacency.protected GraphCopier createToClipboardCopier()
ToClipboardCopier
.GraphCopier
instance.public static final Predicate<IModelItem> createWrappedFilter(Predicate<IModelItem> coreFilter, IGraph graph, boolean restrictive)
Predicate
from coreFilter
for use in the cut(IGraph, Predicate)
and copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
methods that takes dependent items into account.
This method can create a predicate for only a core set of items which is then extended or restricted depending on the predicate values of graph item dependencies.
The restrictive
parameter determines whether the result restricts or extends the set of elements handled by
coreFilter
:
restrictive
is false
, an item is allowed if either coreFilter
returns true
for itself
or if all items it depends on (e.g. label/port owner, source/target port etc.) are allowed by coreFilter
.
restrictive
is true
, an item is forbidden if either coreFilter
returns false
for
itself or if any item it depends on (e.g. label/port owner, source/target port etc.) is forbidden by
coreFilter
.
coreFilter
- The core predicate for the base set of elements.graph
- The graph to use for determining adjacency.restrictive
- Whether to create a restriction or extension for the coreFilter
predicatepublic void cut(IGraph sourceGraph, Predicate<IModelItem> filter)
filter
to the clipboard and removes them from the graph.
This method delegates the core work to copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
which
will use the ToClipboardCopier
to copy the cut elements to the clipboard.
sourceGraph
- The graph to cut the items from.filter
- The filter to use.createSelectionFilter(IGraphSelection, IGraph)
public void duplicate(IInputModeContext context, IGraph sourceGraph, Predicate<IModelItem> filter, IElementCopiedCallback elementDuplicated)
The ClipboardGraph
is not altered by this operation.
context
- The current IInputModeContext
.sourceGraph
- The graph whose elements should be duplicated.filter
- A Predicate
which returns true
for elements which should be duplicated.elementDuplicated
- An IElementCopiedCallback
which gets invoked for each element which has been duplicated. The two parameters
passed into the callback are guaranteed to be part of the sourceGraph
.public final IGraph getClipboardGraph()
NullPointerException
- If value
is null
.setClipboardGraph(IGraph)
protected IClipboardHelper getClipboardHelper(IModelItem item)
IClipboardHelper
instance associated with the given item.
This implementation uses the item's ILookup.lookup(Class)
method to retrieve the helper
instance.
item
- The item to find the clipboard helper for.null
.public final GraphItemTypes getCopyItems()
If the corresponding element type is set in this property, items can be effectively copied.
If the corresponding element type is not set in this property, items will not be pasted, even if they have been
explicitly selected. They may copied to the clipboard and become part of the
ClipboardGraph
, nevertheless though, if they are required as
dummy elements
. But these elements will not be pasted to the target during paste or
duplicate operations.
The default is GraphItemTypes.ALL
.
setCopyItems(GraphItemTypes)
public final GraphItemTypes getDependentCopyItems()
Labels
depend on their owner
, like ports
depend on their
owner
. Also bends
of course depend on their owning edge
.
If the corresponding element type is set in this property, items that depend on other items are implicitly included in the copy operation, if all of the items that they depend on are included recursively, even if they are not included explicitly themselves.
The default is GraphItemTypes.ALL
minus
GraphItemTypes.NODE
, which means that selecting a number of nodes will automatically select all elements
that directly and indirectly depend on the existence of this set of nodes will be copied to the clipboard, too.
Technically nodes do not depend on anything. Setting this property to a value that includes GraphItemTypes.NODE
will include all child nodes for every selected group node.
setDependentCopyItems(GraphItemTypes)
public final GraphCopier getDuplicateCopier()
GraphCopier
instance that will be used to duplicate elements inside the graph.
This instance is lazily created using createDuplicateCopier()
.
setDuplicateCopier(GraphCopier)
protected IEdge getFoldingEdgeState(IEdge edge, FoldingEdgeStateId id)
FoldingEdgeStateId
.
This method might be overridden to map folding states for edges whose source or target node's hierarchy might have changed during a paste operation.
edge
- The edge to get the folding state for.id
- The original FoldingEdgeStateId
to get the folding state for. Passing null
will return the folding state
which was visible when the edge was copied into the clipboard.id
. May be null
.public final GraphCopier getFromClipboardCopier()
GraphCopier
instance that will be used to copy the graph from the clipboard to the target graph.
This instance is lazily created using createFromClipboardCopier()
.
setFromClipboardCopier(GraphCopier)
public final IClipboardIdProvider getIdProvider()
IClipboardIdProvider
used by this instance to provide IDs for copied items.
The default implementation simply uses a reference to the original item as ID.
Custom ID can be used to map between elements in different graphs.
setIdProvider(IClipboardIdProvider)
public final GraphItemTypes getIndependentCopyItems()
Labels
depend on their owner
, like ports
depend on their
owner
. Also bends
of course depend on their owning edge
.
If the corresponding element type is set in this property, items can be copied alone to the clipboard and be pasted onto different owning elements.
This enables copying of a label to one or more owners, without having to copy the owner of the label. Also ports can be
copied to other IPortOwner
s and bends to other edges.
The default is GraphItemTypes.ALL
which means that all elements can be copied to the clipboard even if the items
that they depend on are not copied to the clipboard.
Technically owning elements are still part of the clipboard as
dummy elements
, but these elements will not be pasted to the target during paste or
duplicate operations.
setIndependentCopyItems(GraphItemTypes)
protected ILabelModelParameter getLabelLayoutParameter(GraphCopier copier, IGraph graph, ILabel label, ILabelOwner newOwner)
ILabelModelParameter
for the given label
to be placed at the given newOwner
.
Implementations might delegate to GraphCopier.copyLabelLayoutParameter(IGraph, ILabel)
to copy the existing
parameter or use the NodeDefaults
or EdgeDefaults
to
create a new one. Note that the type of the owner might have changed during the copy operation.
copier
- The GraphCopier
whose GraphCopier.copyLabelLayoutParameter(IGraph, ILabel)
method can be used to copy
the existing parameter.graph
- The IGraph
whose NodeDefaults
or EdgeDefaults
can be used to create a new parameter.label
- The label to be copied.newOwner
- The new owner for the label.ILabelModelParameter
for the copied label.public final Object getMemento(IModelItem clipboardItem)
onElementCopied(IModelItem, IModelItem)
and onElementCut(IModelItem, IModelItem)
.clipboardItem
- The item in the clipboard graph.IClipboardHelper
methods or null
.public final GraphClipboard.ParentNodeDetectionModes getParentNodeDetection()
This property is used by getTarget(INode)
to decide what node to yield as the target group node for the newly
pasted node.
The default is GraphClipboard.ParentNodeDetectionModes.SELECTION
|GraphClipboard.ParentNodeDetectionModes.PREVIOUS_PARENT
.
setParentNodeDetection(ParentNodeDetectionModes)
public final PointD getPasteDelta()
setPasteDelta(PointD)
protected IPortLocationModelParameter getPortLocationParameter(GraphCopier copier, IGraph graph, IPort originalPort, IPortOwner newOwner)
IPortLocationModelParameter
for the given originalPort
to be placed at the given
newOwner
.
Implementations might delegate to GraphCopier.copyPortLocationParameter(IGraph, IPort)
to copy the existing
parameter or use the NodeDefaults
or EdgeDefaults
to
create a new one. Note that the type of the owner might have changed during the copy operation.
copier
- The GraphCopier
whose GraphCopier.copyPortLocationParameter(IGraph, IPort)
method can be used to copy
the existing parameter.graph
- The IGraph
whose NodeDefaults
or EdgeDefaults
can be used to create a new parameter.originalPort
- The port to be copied.newOwner
- The new owner for the port.IPortLocationModelParameter
for the copied port.protected IEdge getTarget(IBend originalBend)
IEdge
where the given originalBend
can be added to.
Called for IBend
s whose edge is not copied to provide a new owner. Might return null
if no target for
the given originalBend
is found. In this case the bend will not be copied.
originalBend
- The bend to be copied.IEdge
for the bend to be added to or null
if the bend should not be copied.protected IPort getTarget(IEdge originalEdge, boolean atSource)
IPort
where the given originalEdge
can be added to.
Called for IEdge
s whose source or target ports are not copied to provide a new port. Might return null
if no target for the given originalEdge
is found. In this case the edge will not be copied.
originalEdge
- The edge to be copied.atSource
- Whether to look for a source port.IPort
for the edge to be added to or null
if the edge should not be copied.protected ILabelOwner getTarget(ILabel originalLabel)
ILabelOwner
where the given originalLabel
can be added to.
Called for ILabel
s whose owners are not copied to provide a new owner. Might return null
if no target
for the given originalLabel
is found. In this case the label will not be copied.
originalLabel
- The label to be copied.ILabelOwner
for the label to be added to or null
if the label should not be copied.protected INode getTarget(INode originalNode)
originalNode
.
Called for INode
s to place them inside a group node. Might return null
if the given node should be
placed at the root or if the graph is not grouped.
originalNode
- The node to be copied.null
if the node should be placed at the root of the hierarchy or if the
graph is not grouped.getParentNodeDetection()
protected IPortOwner getTarget(IPort originalPort)
IPortOwner
where the given originalPort
can be added to.
Called for IPort
s whose owners are not copied to provide a new owner. Might return null
if no target for
the given originalPort
is found. In this case the port will not be copied.
originalPort
- The port to be copied.IPortOwner
for the port to be added to or null
if the port should not be copied.public final GraphCopier getToClipboardCopier()
GraphCopier
instance that will be used to copy the graph to the clipboard.
This instance is lazily created using createToClipboardCopier()
.
setToClipboardCopier(GraphCopier)
public final boolean isDummy(IModelItem item)
item
is a "dummy" item which should not be pasted.
A dummy item is used to keep IModelItem
s which cannot exist without an owner in the ClipboardGraph
(e.g. ILabel
s).
item
- The item to test.true
if the item is a "dummy" item.public boolean isEmpty()
protected static final boolean isFoldingStateElement(IModelItem owner, IModelItem item)
item
exists in a folding state of its owner
.public final boolean isIgnoringEdgesWithOneNodeEnabled()
The default is false
.
setIgnoringEdgesWithOneNodeEnabled(boolean)
protected void onElementCopied(IModelItem original, IModelItem copy)
IElementCopiedCallback
that will be invoked for each item that has been copied into the clipboard graph in
response to a copy(IGraph, Predicate, IGraph, INode, IElementCopiedCallback)
operation.
This implementation will ILookup.lookup(Class)
a IClipboardHelper
for each item
in the original graph and remember the memento retrieved by the IClipboardHelper.copy(IGraphClipboardContext, IModelItem)
method for later use during the onElementPasted(IModelItem, IModelItem)
operation.
original
- The original element from the source graph instance. If the source graph is a managed folding view, this is always a
master item.copy
- The copy from the clipboard graph.protected void onElementCut(IModelItem original, IModelItem copy)
IElementCopiedCallback
that will be invoked for each item that has been copied into the clipboard graph in
response to a cut(IGraph, Predicate)
operation.
This implementation will ILookup.lookup(Class)
a IClipboardHelper
for each item
in the original graph and remember the memento retrieved by the IClipboardHelper.cut(IGraphClipboardContext, IModelItem)
method for later use during the onElementPasted(IModelItem, IModelItem)
operation.
original
- The original element from the source graph instance. If the source graph is a managed folding view, this is always a
master item.copy
- The copy from the clipboard graph.protected void onElementPasted(IModelItem original, IModelItem copy)
IElementCopiedCallback
that will be invoked for each item that has been pasted into the target graph in response
to a paste(IGraph, Predicate, IGraph, INode, IElementCopiedCallback, Predicate)
operation.
This method will use a previously stored IClipboardHelper
to let it finish
its work.
original
- The original element from the clipboard graph instance. If the target graph is a managed folding view, this is always a
master item.copy
- The copy from the target graph.public final void paste(IGraph targetGraph)
ClipboardGraph
to the targetGraph
after applying a
filter
.
For each element pasted into the graph the elementPasted
delegate will be invoked and the onElementPasted(IModelItem, IModelItem)
method will be called. The actual work of this method is delegated to the
FromClipboardCopier
's GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
method.
targetGraph
- The graph to paste the contents in.public void paste(IGraph targetGraph, IGraphSelection selection)
ClipboardGraph
's contents into the
targetGraph
, selecting all pasted elements.
The actual work of this method is delegated to the FromClipboardCopier
's GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
method.
targetGraph
- The graph to paste into.selection
- The selection model to set the selection on.public final void paste(IGraph targetGraph, Predicate<IModelItem> filter)
ClipboardGraph
to the targetGraph
after applying a
filter
.
For each element pasted into the graph the elementPasted
delegate will be invoked and the onElementPasted(IModelItem, IModelItem)
method will be called. The actual work of this method is delegated to the
FromClipboardCopier
's GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
method.
targetGraph
- The graph to paste the contents in.filter
- The filter to apply to the clipboard graph.public void paste(IGraph targetGraph, Predicate<IModelItem> filter, IElementCopiedCallback elementPasted)
ClipboardGraph
to the targetGraph
after applying a
filter
.
For each element pasted into the graph the elementPasted
delegate will be invoked and the onElementPasted(IModelItem, IModelItem)
method will be called. The actual work of this method is delegated to the
FromClipboardCopier
's GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
method.
targetGraph
- The graph to paste the contents in.filter
- The filter to apply to the clipboard graph.elementPasted
- The callback to use for each element that has been pasted. For each element that is copied during the operation to the
clipboard, this callback will be passed the original and the copy of the item. In case the targetGraph
is a folding view graph
the original element is passed as master
elements or folding state elements
if a master element does not exist. The copied element is always part of the targetGraph
.protected void paste(IGraph sourceGraph, Predicate<IModelItem> filter, IGraph targetGraph, INode targetRootNode, IElementCopiedCallback elementCopiedCallback, Predicate<IModelItem> targetFilter)
GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
on the current FromClipboardCopier
instance, depending on whether the targetGraph
is the ClipboardGraph
instance.sourceGraph
- The source graph to pass to GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
filter
- The predicate to pass on.targetGraph
- The target graph to pass on.targetRootNode
- The node to use as the root node in the grouped targetGraph
.elementCopiedCallback
- The delegate to pass on. For each element that is copied during the operation to the clipboard, this callback will be
passed the original and the copy of the item. In case the targetGraph
is a folding view graph
the original element is passed as master
elements or folding state elements
if a master element does not exist. The copied element is always part of the targetGraph
.targetFilter
- This predicate is used to determine which INode
s and IEdge
s can be used as targets for paste operations,
e.g. if a labels or ports are copied without their owners. If null
all model items can be used as targets.public void paste(IInputModeContext context, IGraph targetGraph, Predicate<IModelItem> filter, IElementCopiedCallback elementPasted, Predicate<IModelItem> targetFilter)
ClipboardGraph
to the targetGraph
after applying a
filter
.
For each element pasted into the graph the elementPasted
delegate will be invoked and the onElementPasted(IModelItem, IModelItem)
method will be called. The actual work of this method is delegated to the
FromClipboardCopier
's GraphCopier.copy(IGraph, Predicate, IGraph, INode, PointD, IElementCopiedCallback)
method.
Providing a valid targetFilter
allows for pasting ILabel
s, IPort
s, and
IEdge
s without valid owners.
context
- A valid input mode context. Passing a valid input mode context is required for keeping orthogonal edges at group nodes
whose size might be adjusted after the paste operation.targetGraph
- The graph to paste the contents in.filter
- The filter to apply to the clipboard graph.elementPasted
- The callback to use for each element that has been pasted. For each element that is copied during the operation to the
clipboard, this callback will be passed the original and the copy of the item. In case the targetGraph
is a folding view graph
the original element is passed as master
elements or folding state elements
if a master element does not exist. The copied element is always part of the targetGraph
.targetFilter
- A filter which returns true
for model items which can be used as target for clipboard items which need an owner
(e.g. ILabel
s which were copied without their owner). If null
all model items can be used as targets.protected void removeElements(IGraph sourceGraph, Predicate<IModelItem> predicate)
Predicate
.sourceGraph
- The graph to remove elements from.predicate
- The predicate that decides which elements to remove.cut(IGraph, Predicate)
public final void removeElementsCopiedListener(IEventHandler<IEventArgs> elementsCopiedEvent)
ElementsCopied
event that occurs when the copy(IGraph, Predicate)
operation finished successfully.elementsCopiedEvent
- The listener to remove.addElementsCopiedListener(IEventHandler)
public final void removeElementsCutListener(IEventHandler<IEventArgs> elementsCutEvent)
ElementsCut
event that occurs when the cut(IGraph, Predicate)
operation finished successfully.elementsCutEvent
- The listener to remove.addElementsCutListener(IEventHandler)
public final void removeElementsPastedListener(IEventHandler<IEventArgs> elementsPastedEvent)
ElementsPasted
event that occurs when the paste(IInputModeContext, IGraph, Predicate, IElementCopiedCallback, Predicate)
operation finished successfully.elementsPastedEvent
- The listener to remove.addElementsPastedListener(IEventHandler)
public final void setClipboardGraph(IGraph value)
NullPointerException
- If value
is null
.value
- The ClipboardGraph to set.getClipboardGraph()
public final void setCopyItems(GraphItemTypes value)
If the corresponding element type is set in this property, items can be effectively copied.
If the corresponding element type is not set in this property, items will not be pasted, even if they have been
explicitly selected. They may copied to the clipboard and become part of the
ClipboardGraph
, nevertheless though, if they are required as
dummy elements
. But these elements will not be pasted to the target during paste or
duplicate operations.
The default is GraphItemTypes.ALL
.
value
- The CopyItems to set.getCopyItems()
public final void setDependentCopyItems(GraphItemTypes value)
Labels
depend on their owner
, like ports
depend on their
owner
. Also bends
of course depend on their owning edge
.
If the corresponding element type is set in this property, items that depend on other items are implicitly included in the copy operation, if all of the items that they depend on are included recursively, even if they are not included explicitly themselves.
The default is GraphItemTypes.ALL
minus
GraphItemTypes.NODE
, which means that selecting a number of nodes will automatically select all elements
that directly and indirectly depend on the existence of this set of nodes will be copied to the clipboard, too.
Technically nodes do not depend on anything. Setting this property to a value that includes GraphItemTypes.NODE
will include all child nodes for every selected group node.
value
- The DependentCopyItems to set.getDependentCopyItems()
public final void setDuplicateCopier(GraphCopier value)
GraphCopier
instance that will be used to duplicate elements inside the graph.
This instance is lazily created using createDuplicateCopier()
.
value
- The DuplicateCopier to set.getDuplicateCopier()
public final void setFromClipboardCopier(GraphCopier value)
GraphCopier
instance that will be used to copy the graph from the clipboard to the target graph.
This instance is lazily created using createFromClipboardCopier()
.
value
- The FromClipboardCopier to set.getFromClipboardCopier()
public final void setIdProvider(IClipboardIdProvider value)
IClipboardIdProvider
used by this instance to provide IDs for copied items.
The default implementation simply uses a reference to the original item as ID.
Custom ID can be used to map between elements in different graphs.
value
- The IdProvider to set.getIdProvider()
public final void setIgnoringEdgesWithOneNodeEnabled(boolean value)
The default is false
.
value
- The IgnoringEdgesWithOneNodeEnabled to set.isIgnoringEdgesWithOneNodeEnabled()
public final void setIndependentCopyItems(GraphItemTypes value)
Labels
depend on their owner
, like ports
depend on their
owner
. Also bends
of course depend on their owning edge
.
If the corresponding element type is set in this property, items can be copied alone to the clipboard and be pasted onto different owning elements.
This enables copying of a label to one or more owners, without having to copy the owner of the label. Also ports can be
copied to other IPortOwner
s and bends to other edges.
The default is GraphItemTypes.ALL
which means that all elements can be copied to the clipboard even if the items
that they depend on are not copied to the clipboard.
Technically owning elements are still part of the clipboard as
dummy elements
, but these elements will not be pasted to the target during paste or
duplicate operations.
value
- The IndependentCopyItems to set.getIndependentCopyItems()
public final void setParentNodeDetection(GraphClipboard.ParentNodeDetectionModes value)
This property is used by getTarget(INode)
to decide what node to yield as the target group node for the newly
pasted node.
The default is GraphClipboard.ParentNodeDetectionModes.SELECTION
|GraphClipboard.ParentNodeDetectionModes.PREVIOUS_PARENT
.
value
- The ParentNodeDetection to set.getParentNodeDetection()
public final void setPasteDelta(PointD value)
value
- The PasteDelta to set.getPasteDelta()
public final void setToClipboardCopier(GraphCopier value)
GraphCopier
instance that will be used to copy the graph to the clipboard.
This instance is lazily created using createToClipboardCopier()
.
value
- The ToClipboardCopier to set.getToClipboardCopier()