The following two requirements are central to extending
the existing handler to support the newly added action: Logic for enabling/disabling the newly added action based
on the currently-selected items. This logic is enabled by overriding
the function set selectedAssets(selectedAssets:Array):void.
Actual handling of AssetActionEvent when
the user clicks the action. This is done by overriding the function handleAction(event:AssetActionEvent):void.
An implementation for com.adobe.icc.customizations.handler.CustomLayoutHandler that
extends LayoutHandler is as follows:
CustomLayoutHandler.as
package com.adobe.icc.customizations.handler
{
import com.adobe.consulting.pst.vo.Form;
import com.adobe.icc.editors.handlers.LayoutHandler;
import com.adobe.icc.editors.managers.ErrorManager;
import com.adobe.icc.services.ServiceProvider;
import com.adobe.icc.vo.DataDownload;
import com.adobe.livecycle.assetmanager.client.event.AssetActionEvent;
import com.adobe.livecycle.assetmanager.client.model.AssetAction;
import flash.net.FileReference;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
public class CustomLayoutHandler extends LayoutHandler
{
/**
* Constant for the name of the action related to creation of an asset.
*/
static public const ACTION_DOWNLOAD:String = "Download";
override public function set selectedAssets(selectedAssets:Array):void
{
super.selectedAssets = selectedAssets;
for each(var assetAction:AssetAction in assetActions)
{
if(assetAction.name == ACTION_DOWNLOAD)
{
assetAction.enabled = (selectedAssets!=null) && (selectedAssets.length==1);
break;
}
}
}
override public function handleAction(event:AssetActionEvent):void
{
if(event.actionName == ACTION_DOWNLOAD)
{
downloadLayout();
}
else
{
super.handleAction(event);
}
}
protected function downloadLayout():void
{
var selectedLayout:Form = selectedAssets[0];
ServiceProvider.getDownloadService().getFormData(selectedLayout.id)
.addHandlers( layoutDownloadResultHandler,
function(faultEvent:FaultEvent){
ErrorManager.handleFault(faultEvent.fault, selectedLayout);
}
);
}
private function layoutDownloadResultHandler(event:ResultEvent):void
{
var data : DataDownload = event.result as DataDownload;
Alert.show("Pick a location to download Layout XDP", "Download Layout", Alert.OK | Alert.CANCEL, null,
function (event:*):void
{
if ( event.detail == Alert.OK ) {
var fileReference:FileReference = new FileReference();
fileReference.save(data.objByteArray ,data.objFileName);
}
}
);
}
}
}
|
|
|