*/
@SuppressWarnings("serial")
public TransferableIcon(final AbstractComponent referencedComponent, final ViewTransferCallback viewTransferCallback) {
super(MCTIcons.processIcon(referencedComponent.getAsset(ImageIcon.class), ICON_COLOR, false));
final AtomicBoolean clicked = new AtomicBoolean(false);
setTransferHandler(new TransferHandler() {
@Override
public int getSourceActions(JComponent c) {
return canComponentBeContained()?COPY:NONE;
}
private boolean canComponentBeContained() {
PolicyContext context = new PolicyContext();
context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(),Collections.singleton(referencedComponent));
String policyCategoryKey = PolicyInfo.CategoryType.CAN_OBJECT_BE_CONTAINED_CATEGORY.getKey();
Platform platform = PlatformAccess.getPlatform();
PolicyManager policyManager = platform.getPolicyManager();
ExecutionResult result = policyManager.execute(policyCategoryKey, context);
return result.getStatus();
}
@Override
protected Transferable createTransferable(JComponent c) {
return new ViewRoleSelection(viewTransferCallback.getViewsToTransfer().toArray(new View[0]));
}
@Override
protected void exportDone(JComponent source, Transferable data, int action) {
super.exportDone(source, data, action);
clicked.set(false);
}
});
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
if (clicked.get()) {
JComponent c = (JComponent) e.getSource();
TransferHandler th = c.getTransferHandler();
th.exportAsDrag(c, e, TransferHandler.COPY);
}
}
});
addMouseListener(new MouseAdapter() {