@Override
public boolean canHandle(final ActionContext context) {
ImageIcon icon = context.getWindowManifestation().getManifestedComponent().getAsset(ImageIcon.class);
setIcon(MCTIcons.processIcon(icon, ICON_COLOR, false));
setTransferHandler(new TransferHandler() {
@Override
public int getSourceActions(JComponent c) {
return canComponentBeContained()?COPY:NONE;
}
private boolean canComponentBeContained() {
PolicyContext policyContext = new PolicyContext();
policyContext.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(),Collections.singleton(context.getWindowManifestation().getManifestedComponent()));
String policyCategoryKey = PolicyInfo.CategoryType.CAN_OBJECT_BE_CONTAINED_CATEGORY.getKey();
ExecutionResult result = PolicyManagerImpl.getInstance().execute(policyCategoryKey, policyContext);
return result.getStatus();
}
@Override
protected Transferable createTransferable(JComponent c) {
View v = context.getWindowManifestation();
Container container = v.getTopLevelAncestor();
if (container instanceof MCTStandardHousing) {
MCTStandardHousing housing = (MCTStandardHousing) container;
MCTContentArea contentArea = housing.getContentArea();
if (contentArea != null) {
v = contentArea.getHousedViewManifestation();
}
}
return new ViewRoleSelection(new View[] { v });
}
});
// Dragging of IconMenu is not permitted for the user environment.
// Achieve this by not adding the mouse drag listener.
if (context.getWindowManifestation().getManifestedComponent() != PlatformAccess.getPlatform().getRootComponent()) {
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
JComponent c = (JComponent) e.getSource();
TransferHandler th = c.getTransferHandler();
th.exportAsDrag(c, e, TransferHandler.COPY);
}
});
}