CustomInfosetExtensionHandler.jsx
Summary
Demonstrates a basic implementation of a node-handling extension with a custom Infoset.
See:
function CustomInfosetExtensionHandler() {
$.level = 1;
this.requiredContext = "\tNeed to be running in context of Bridge\n";
this.buttonIcon = new File($.fileName).parent.fsName + "/resources/editIcon.png";
}
CustomInfosetExtensionHandler.prototype.run = function()
{
if(!this.canRun())
{
return false;
}
$.writeln("CustomInfosetExtensionHandler: About to run");
var root = new SDKNode("CIRoot", true);
var sub = new SDKNode("CIFolder1", true)
root.addNode(sub);
var lf = new SDKNode("RootLeaf", false);
root.addNode(lf);
var n = new SDKNode("leaf1", false);
var d = root.findChildNode("CIFolder1");
d.addNode(n);
root.addNode(new SDKNode("CIFolder2", true));
n = new SDKNode("leaf2", false);
d = root.findChildNode("CIFolder2");
d.addNode(n);
n = new SDKNode("leaf3", false);
d = root.findChildNode("CIFolder2");
d.addNode(n);
root.getChildNode("CIFolder2").addNode(new SDKNode("CISubFolder1", true));
n = new SDKNode("leaf4", false);
d = root.findChildNode("CISubFolder1");
d.addNode(n);
var sys = new SDKSystem("bridge:ciNode:");
sys.addRoot(root);
var ciHandler = new ExtensionHandler("ciHandler");
app.registerExtension(ciHandler);
app.registerPrefix( "bridge:ciNode:", ciHandler);
ciHandler.getBridgeUriForPath = function(path)
{
return path;
}
var wrapperObject = this;
ciHandler.makeModel = function(path)
{
ciModel = new ExtensionModel(path);
ciModel.path = path;
this.path = path;
wrapperObject.initModel(ciModel, sys);
return ciModel;
}
var customInfoDescriptions = new Array();
customInfoDescriptions[0] = new InfosetMemberDescription( "CustomString", "String" );
customInfoDescriptions[1] = new InfosetMemberDescription( "CustomNumber", "Integer" );
customInfoDescriptions[2] = new InfosetMemberDescription( "CustomDate", "String" );
customInfoDescriptions[3] = new InfosetMemberDescription( "CustomArray", "Array of String" );
customInfoDescriptions[4] = new InfosetMemberDescription( "CustomBool", "Boolean" );
var customInfoset = new Infoset("customInfoset", customInfoDescriptions);
app.registerInfoset(ciHandler, customInfoset);
onEvent = function(event)
{
if(event.object instanceof Document)
{
if(event.type == "selectionsChanged")
{
if(event.object.selections.length > 0)
{
var thumb = event.object.selections[0];
if(thumb.ciHandler)
{
stringText.text = thumb.ciHandler.customInfoset.CustomString;
numbersText.text = thumb.ciHandler.customInfoset.CustomNumber;
dateText.text = thumb.ciHandler.customInfoset.CustomDate;
arrStringText.text = thumb.ciHandler.customInfoset.CustomArray.toString();
boolList.selection = (thumb.ciHandler.customInfoset.CustomBool) ? 0 : 1;
customDataPalette.content.enabled = true;
customDataPalette.content.visible = true;
}
else
{
customDataPalette.content.visible= false;
}
}
else
{
customDataPalette.content.visible= false;
}
}
}
}
app.eventHandlers.push({handler: onEvent});
var customDataPalette = new TabbedPalette(app.document, "SDK: Custom Infoset Data", "SDKCustomInfoPalette", "script");
var win = customDataPalette.content;
var stringLabel = win.add("statictext", [5, 9, 115, 25], "Custom String");
var stringText = win.add("edittext", [120, 5, 320, 25], "");
stringText.onChange = function()
{
var selected = app.document.selections[0];
if(selected != undefined)
{
if(confirm("Are you sure you want to change this data?"))
{
selected.ciHandler.customInfoset.CustomString = stringText.text ;
selected.ciHandler.customInfoset.cacheData.status = "bad";
selected.model.privateData.node.setCustomString(stringText.text);
}
else
{
stringText.text = selected.ciHandler.customInfoset.CustomString;
}
app.document.selections[0] = selected;
}
}
var numbersLabel = win.add("statictext", [5, 39, 115, 55], "Custom Number");
var numbersText = win.add("edittext", [120, 35, 320, 55], "");
numbersText.onChange = function()
{
var selected = app.document.selections[0];
if(selected != undefined)
{
if(confirm("Are you sure you want to change this data?"))
{
selected.ciHandler.customInfoset.CustomNumber = numbersText.text ;
selected.ciHandler.customInfoset.cacheData.status = "bad";
selected.model.privateData.node.setCustomNumber(parseInt(numbersText.text));
}
else
{
numbersText.text = selected.ciHandler.customInfoset.CustomNumber;
}
app.document.selections[0] = selected;
}
}
var dateLabel = win.add("statictext", [5, 69, 115, 85], "Custom Date");
var dateText = win.add("edittext", [120, 65, 320, 85], "");
dateText.enabled = false;
var arrLabel = win.add("statictext", [5, 99, 115, 115], "Custom Array");
var arrStringText = win.add("edittext", [120, 95, 320, 115], "");
arrStringText.enabled = false;
var boolLabel = win.add("statictext", [5, 129, 115, 145], "Custom Boolean");
var boolList = win.add("dropdownlist", [120, 125, 320, 145]);
var tItem = boolList.add("item", "True");
tItem.val = true;
var fItem = boolList.add("item", "False");
fItem.val = false;
boolList.onChange = function()
{
var selected = app.document.selections[0];
var currentVal = selected.ciHandler.customInfoset.CustomBool;
if(boolList.selection)
{
if(currentVal == boolList.selection)
{
if(confirm("Are you sure you want to change this data?"))
{
selected.ciHandler.customInfoset.CustomBool = boolList.selection.val;
selected.ciHandler.customInfoset.cacheData.status = "bad";
selected.model.privateData.node.setCustomBool(boolList.selection.val);
}
}
app.document.selections[0] = selected;
}
}
customDataPalette.content.visible = false;
var t = new Thumbnail("bridge:ciNode:/CIRoot");
app.favorites.insert(t);
t.refresh();
$.writeln("CustomInfosetExtensionHandler ran successfully");
return true;
}
CustomInfosetExtensionHandler.prototype.canRun = function() {
if(BridgeTalk.appName == "bridge") {
for(index in app.extensions)
{
if(app.extensions[index].name == "ciHandler")
{
$.writeln("CustomInfosetExtensionHandler: ERROR - Cannot run twice! You must restart Bridge");
return false;
}
}
return true;
}
$.writeln("CustomInfosetExtensionHandler: ERROR - Cannot run CustomInfosetExtensionHandler");
$.writeln("CustomInfosetExtensionHandler: " + this.requiredContext);
return false;
}
CustomInfosetExtensionHandler.prototype.initModel = function(ciModel, sys)
{
ciModel.needAuthentication = function()
{
return false;
}
ciModel.authenticate = function()
{
return;
}
ciModel.exists = function()
{
return true;
}
ciModel.initialize = function()
{
this.privateData.node = sys.getNodeFromPath(this.path);
}
ciModel.registerInterest = function(cacheElement)
{
this.privateData.cacheElement = cacheElement;
}
ciModel.unregisterInterest = function()
{
this.privateData.cacheElement = undefined;
}
ciModel.getParent = function()
{
var parent = this.privateData.node.getParent();
if(parent != undefined)
{
return (sys.getPrefix() + parent.getPath());
}
}
ciModel.refreshInfoset = function(infosetName)
{
var infoset = this.privateData.cacheElement[infosetName];
var currentNode = this.privateData.node;
try
{
if(infosetName == "immediate" || infosetName == "all")
{
infoset.name =currentNode.getName();
infoset.isContainer = currentNode.isContainer();
infoset.cacheData.status = "good";
}
if(infosetName == "item" || infosetName == "all")
{
infoset.cacheData.status = "good";
}
if(infosetName == "children" || infosetName == "all")
{
var arr = currentNode.getChildren();
for(var j = 0;j < arr.length;j++)
{
infoset.addChild( sys.getPrefix() + arr[j].getPath() );
}
infoset.cacheData.status = "good";
}
if(infosetName == "icon" || infosetName == "all")
{
infoset.bitmap = currentNode.getIcon();
infoset.cacheData.status = "good";
}
if(infosetName == "thumbnail" || infosetName == "all")
{
infoset.thumbnail = currentNode.getThumb();
infoset.cacheData.status = "good";
}
if(infosetName == "quickMetadata" || infosetName == "all")
{
infoset.colorMode = -1;
infoset.hasRawSetting = false;
infoset.hasCrop = false;
infoset.height = 300;
infoset.rating = 0;
infoset.rotation = 0;
infoset.stockPhotoStatus = 0;
infoset.xResolution = 0;
infoset.yResolution = 0;
infoset.width = 300;
infoset.cacheData.status = "good";
}
if(infosetName == "itemContent" || infosetName == "all")
{
infoset.canGetPreview = false;
infoset.cacheData.status = "good";
}
if(infosetName == "preview" || infosetName == "all")
{
infoset.preview = currentNode.getPreview();
infoset.cacheData.status = "good";
}
if(infosetName == "customInfoset" || "all")
{
if(this.privateData.cacheElement.customInfoset.cacheData.status != "good")
{
this.privateData.cacheElement.customInfoset.CustomString = currentNode.getCustomString();
this.privateData.cacheElement.customInfoset.CustomNumber = currentNode.getCustomNumber();
this.privateData.cacheElement.customInfoset.CustomDate = currentNode.getCustomDate();
this.privateData.cacheElement.customInfoset.CustomArray = currentNode.getCustomArray();
this.privateData.cacheElement.customInfoset.CustomBool = currentNode.getCustomBool();
}
else
{
currentNode.setCustomString(this.privateData.cacheElement.customInfoset.CustomString);
currentNode.setCustomNumber(this.privateData.cacheElement.customInfoset.CustomNumber);
currentNode.setCustomBool(this.privateData.cacheElement.customInfoset.CustomBool);
}
this.privateData.cacheElement.customInfoset.cacheData.status = "good";
}
} catch(error) { alert(error); }
}
ciModel.getCacheStatus = function( infosetName, cookie )
{
if(typeof this.privateData.cacheElement == "undefined")
{
return "bad";
}
if(typeof this.privateData.cacheElement.infosetName== "undefined")
{
var ce = this.privateData.cacheElement;
var info = ce[infosetName];
var cd = info.cacheData;
var stat = cd.status;
return stat;
}
return this.privateData.cacheElement[infosetName].cacheData.status;
}
ciModel.terminate = function()
{
return;
}
}
#include SDKSystem.jsx
#include SDKNode.jsx
if(typeof(CustomInfosetExtensionHandler_unitTest) == "undefined") {
new CustomInfosetExtensionHandler().run();
}
http://www.adobe.com/devnet/bridge
Documentation generated by
JSDoc on Tue Apr 27 10:21:34 2010