T
- The type of domain object of your formatpublic abstract class ALcyDefaultLayerSelectionTransferHandler<T> extends ALcyLayerSelectionTransferHandler
An abstract extension of ALcyLayerSelectionTransferHandler
which adds support to copy domain objects between models of
the same format and optionally to import shapes from another format.
This class does not support a partial copy. When multiple objects are copied or moved in one go, the operation will only take place when all objects can be copied or moved.
COPY, COPY_OR_MOVE, MOVE, NONE
Modifier | Constructor and Description |
---|---|
protected |
ALcyDefaultLayerSelectionTransferHandler(ILcdFilter<ILcdLayer> aLayerFilter)
Creates a new layer selection transfer handler which allows to import shapes from other formats.
|
protected |
ALcyDefaultLayerSelectionTransferHandler(ILcdFilter<ILcdLayer> aLayerFilter,
boolean aAllowImportShapesFromOtherFormats)
Creates a new layer selection transfer handler.
|
Modifier and Type | Method and Description |
---|---|
void |
addUndoableListener(ILcdUndoableListener aListener)
Adds a listener to this source, so this listener is notified when something undoable has
happened.
|
boolean |
canImport(DataFlavor[] aFlavors,
ILcdLayer aDestinationLayer,
ILcdView aDestinationView)
This method determines whether this
ALcyLayerSelectionTransferHandler can import
the given Transferable . |
protected abstract T |
createDomainObjectCopy(T aDomainObject,
ILcdModel aSourceModel,
ILcdModel aTargetModel)
Create a copy of
aDomainObject from aSourceModel which can be inserted into aTargetModel . |
protected abstract T |
createDomainObjectForShape(ILcdShape aShape,
ILcdModel aSourceModel,
ILcdModel aTargetModel)
Creates a new domain object which can be inserted into
aTargetModel where the shape of the
returned domain object is a copy of aShape . |
protected abstract ILcdShape |
createShapeCopy(ILcdShape aShape,
ILcdModel aSourceModel)
Creates a copy of
aShape retrieved from a domain object of aSourceModel , where the copy is
defined in the reference of aSourceModel . |
Transferable |
createTransferable(ILcdSelection aSelection,
ILcdLayer aSourceLayer,
ILcdView aSourceView)
Creates the transferable to export
aSelection . |
void |
exportDone(Transferable aTransferable,
ILcdLayer aSourceLayer,
ILcdView aSourceView,
int aAction)
This method is called when the export is done.
|
protected void |
fireUndoableHappened(ILcdUndoable aUndoable)
Notify all attached listeners of
aUndoable . |
ILcdLogListener |
getLogListener()
Gives you the ILcdLogListener that redirects all messages to the
ILcdLogListener s
attached to this ALcyLayerSelectionTransferHandler . |
int |
getSourceActions(ILcdSelection aSelection,
ILcdLayer aSourceLayer,
ILcdView aSourceView)
This method determines what this
ALcyLayerSelectionTransferHandler can do with the
given selection. |
boolean |
importData(Transferable aTransferable,
ILcdLayer aDestinationLayer,
ILcdView aDestinationView)
Actually imports the data into the destination layers.
|
void |
removeUndoableListener(ILcdUndoableListener aListener)
Removes the specified listener so it is no longer notified.
|
addLogListener, removeLogListener
protected ALcyDefaultLayerSelectionTransferHandler(ILcdFilter<ILcdLayer> aLayerFilter)
aLayerFilter
- Filter which only accepts layers of the format for which this transfer handler is created.
Might be null
, but in that case you have to ensure that the format (ALcyFormat
or ALcyLspFormat
) that plugs in this transfer handler
is decorated with a safe guard format wrapper (TLcySafeGuardFormatWrapper
or
TLcyLspSafeGuardFormatWrapper
).protected ALcyDefaultLayerSelectionTransferHandler(ILcdFilter<ILcdLayer> aLayerFilter, boolean aAllowImportShapesFromOtherFormats)
aLayerFilter
- Filter which only accepts layers of the format for which this transfer handler is created.
Might be null
, but in that case you have to ensure that the format (ALcyFormat
or ALcyLspFormat
) that plugs in this transfer handler
is decorated with a safe guard format wrapper (TLcySafeGuardFormatWrapper
or
TLcyLspSafeGuardFormatWrapper
).aAllowImportShapesFromOtherFormats
- When false
, this transfer handler will only allow to copy or move
domain objects between models of the same format.
It will no longer try to import shapes from another format.public int getSourceActions(ILcdSelection aSelection, ILcdLayer aSourceLayer, ILcdView aSourceView)
ALcyLayerSelectionTransferHandler
ALcyLayerSelectionTransferHandler
can do with the
given selection. The return value should be one of:
ALcyLayerSelectionTransferHandler.NONE
: indicates this transfer handler cannot export the selection.ALcyLayerSelectionTransferHandler.COPY
: indicates this ALcyLayerSelectionTransferHandler
can only copy
the selection.ALcyLayerSelectionTransferHandler.MOVE
: indicates this ALcyLayerSelectionTransferHandler
can only move the selection.ALcyLayerSelectionTransferHandler.COPY_OR_MOVE
: indicates this
ALcyLayerSelectionTransferHandler
can either move or copy the selection.getSourceActions
in class ALcyLayerSelectionTransferHandler
aSelection
- The selection that is to exported.aSourceLayer
- The ILcdLayer
that contains aSelection.aSourceView
- The ILcdView
that contains aSelection.ALcyLayerSelectionTransferHandler
can perform on
aSelection.public final Transferable createTransferable(ILcdSelection aSelection, ILcdLayer aSourceLayer, ILcdView aSourceView)
ALcyLayerSelectionTransferHandler
aSelection
.createTransferable
in class ALcyLayerSelectionTransferHandler
aSelection
- The selection that is to exported.aSourceLayer
- The ILcdLayer
that contains aSelection.aSourceView
- The ILcdView
that contains aSelection.Transferable
that contains the exported data in various flavors.public final boolean canImport(DataFlavor[] aFlavors, ILcdLayer aDestinationLayer, ILcdView aDestinationView)
ALcyLayerSelectionTransferHandler
ALcyLayerSelectionTransferHandler
can import
the given Transferable
. Typically this method will check if this
ALcyLayerSelectionTransferHandler
can do something with one of the
DataFlavor
s contained in aData
.canImport
in class ALcyLayerSelectionTransferHandler
aFlavors
- The available flavors in which the data to import can be represented.aDestinationLayer
- The ILcdLayer
in which the data should be imported.aDestinationView
- The ILcdView
which contains
aDestinationLayer
.true
if this ALcyLayerSelectionTransferHandler
can import
aData
.public final boolean importData(Transferable aTransferable, ILcdLayer aDestinationLayer, ILcdView aDestinationView)
ALcyLayerSelectionTransferHandler
importData
in class ALcyLayerSelectionTransferHandler
aTransferable
- The data to be imported.aDestinationLayer
- The ILcdLayer
in which the data should be imported.aDestinationView
- The ILcdView
which contains
aDestinationLayer
.public final void exportDone(Transferable aTransferable, ILcdLayer aSourceLayer, ILcdView aSourceView, int aAction)
ALcyLayerSelectionTransferHandler
aAction
was MOVE
.exportDone
in class ALcyLayerSelectionTransferHandler
aTransferable
- The Transferable
that was exported.aSourceLayer
- The ILcdLayer
containing the original objects. Possibly
null
if aAction
is NONE
.aSourceView
- The ILcdView
containing the original objects. Possibly
null
if aAction
is NONE
.aAction
- The action that was performed with the transferable.protected abstract T createDomainObjectCopy(T aDomainObject, ILcdModel aSourceModel, ILcdModel aTargetModel)
Create a copy of aDomainObject
from aSourceModel
which can be inserted into aTargetModel
.
If aSourceModel
and aTargetModel
are using different references, it is up to this method
to perform the necessary conversions.
aDomainObject
- The domain object that must be copied.aSourceModel
- The model containing aDomainObject
.
This is a model of the format for which this transfer handler is created.aTargetModel
- The model in which the returned copy might be inserted.
This is a model of the format for which this transfer handler is created,
possibly even the same instance as aSourceModel
when copy-pasting elements in the same model.aDomainObject
, suitable to be inserted in to aTargetModel
.
Should never return null
when aSourceModel
and aTargetModel
use the same reference.
Might return null
when the domain object is not supported in the target reference.
In that case, the implementation of this method can decide to log a fail message before returning (see getLogListener()
).protected abstract T createDomainObjectForShape(ILcdShape aShape, ILcdModel aSourceModel, ILcdModel aTargetModel)
Creates a new domain object which can be inserted into aTargetModel
where the shape of the
returned domain object is a copy of aShape
.
This method will be called when importing shapes from a different format into aTargetModel
.
It is the responsibility of this method to create a domain object for that shape,
and ensure that the shape of the returned domain object is a copy of aShape
.
The returned domain object should not use aShape directly
,
as that shape is part of (a domain object of) aSourceModel
.
If aSourceModel
and aTargetModel
are using different references, it is up to this method
to perform the necessary conversions.
This method will only be called when the transfer handler allows to import shapes from other formats
(see ALcyDefaultLayerSelectionTransferHandler(ILcdFilter, boolean)
).
aShape
- The shape.aSourceModel
- The model from which aShape
is obtained.
This might be a model from another format.aTargetModel
- The model in which the returned domain object might be inserted.
This is a model of the format for which this transfer handler is created.aTargetModel
using a shape based on aShape
,
or null
when aShape
cannot be converted to a valid domain object for aTargetModel
.
In that case, the implementation of this method can decide to log a fail message before returning (see getLogListener()
).protected abstract ILcdShape createShapeCopy(ILcdShape aShape, ILcdModel aSourceModel)
Creates a copy of aShape
retrieved from a domain object of aSourceModel
, where the copy is
defined in the reference of aSourceModel
.
aShape
- The shape.aSourceModel
- The model containing the domain object of which aShape
was derived.
This is a model of the format for which this transfer handler is created.aShape
defined in the reference of aSourceModel
.
Should never return null
.public final ILcdLogListener getLogListener()
ALcyLayerSelectionTransferHandler
ILcdLogListener
s
attached to this ALcyLayerSelectionTransferHandler
. You should use this log
listener to provide feedback to Lucy, for instance, when something failed during the
importing.getLogListener
in class ALcyLayerSelectionTransferHandler
ILcdLogListener
that redirects all messages to the attached
ILcdLogListener
s.public final void addUndoableListener(ILcdUndoableListener aListener)
ILcdUndoableSource
addUndoableListener
in interface ILcdUndoableSource
addUndoableListener
in class ALcyLayerSelectionTransferHandler
aListener
- The listener to be notified when something undoable has happened.public final void removeUndoableListener(ILcdUndoableListener aListener)
ILcdUndoableSource
removeUndoableListener
in interface ILcdUndoableSource
removeUndoableListener
in class ALcyLayerSelectionTransferHandler
aListener
- The listener to remove.protected final void fireUndoableHappened(ILcdUndoable aUndoable)
ALcyLayerSelectionTransferHandler
aUndoable
.fireUndoableHappened
in class ALcyLayerSelectionTransferHandler
aUndoable
- The undoables of which the listeners should be notified.