Adding targeting to an interactive task

You can use the following steps to add targeting to an interactive task:

  1. Change the task properties
  2. Change the task frame code to find the targets
  3. Add any new translated strings to the resource bundle
  4. Redeploy and test.

Change the task properties

The first thing to do is to tell IBM Director that the task requires a target. Edit the task properties file and modify the Subtask.0.Context line. Change it from this:

Subtask.0.Context = interactive:true | server:false | targeted:none

To this:

Subtask.0.Context = interactive:true | server:false  | client:ignore | targeted:one

The next thing we need to modify is the action. If the task is targeted, then having the user double-click to activate the task does not make sense, so we need to allow the user to drag-drop the task onto a managed object. Find the line for Subtask.0.Actions and change it from:

Subtask.0.Actions = double-click 
to:
Subtask.0.Actions = double-click | drag-drop 

Now we need to tell IBM Director something about the targets that are valid for this class. For now, we will make the task valid for all managed objects. The Client.0.Class property will describe the Java classname for valid targets. The base class for all Managed Objects is com.tivoli.twg.engine.TWGManagedObject so we will specify that. The Client.0.Bind can allow for even more granularity on the valid task targets, but for now, we will simply specify Class.soft, which is the least restrictive.
Add these two lines:

Client.0.Class = com.tivoli.twg.engine.TWGManagedObject
Client.0.Bind  = Class.soft

Next, we are going to add some menu information. Add these two lines:

Subtask.0.Menu = TargetedInteractive,150
Subtask.0.MenuLocation = TaskIcon

Note that TargetedInteractive is a key in the resource bundle. The 150 is a weight value. Use the range 100 to 199 for you extensions. A lower number places the menu higher up in the list of menu items.

Save the file.

Change the task frame code to find the targets

Inside the task frame, you can access information about how your task was invoked. This information is in a class called TWGTaskActivator and there is a method inside TWGTaskFrame called getTaskActivator(). getTaskActivator() returns the TWGTaskActivation object. The most important thing in the task activator is a collection of managed objects that are targets. There are a few important points to note: Since our task properties specified targeted:one, we know that there will be only one target in the collection.

In summary, we will modify the code in buildView() to handle targets. The original buildView(0 method built up a string "message" as follows:

String message resourceBundle.getString("HelloMsg");
We will change this code to:
 	// Get the targets
1	TWGTaskActivator taskActivator = this.getTaskActivator();
2	LongValueSet moids = taskActivator.getMoid();

3	String message;
4	if ((moids != null) && (moids.Length() > 0)) {
		// There are targets so retrieve the first and process it
5		String msg = resourceBundle.getString("HelloMsgTarget");
6		Long moid = new Long(moids.GetValue(0));  // get the first moid
	
 		// Build the substitution array to format the translated string 
7		Object substitutions[] =  new Object[]{moid};
8		message = MessageFormat.format(msg, substitutions);
9	} else {
		// Handle the case where there is NO target because the user 
		// double-clicked the task
10		message = resourceBundle.getString("HelloMsg");
11	}

Line 1 and 2

Add new strings to the resource bundle

Edit the resource bundle and add the menu string:

{ "HelloMsgTarget", "Hello From Bob Co target moid = {0}" },
{ "TargetedInteractive", "Bob Co Interactive Task" },

Redeploy and test

After you redeploy your extension, log in with the IBM Director Console and drag the Bob Co Interactive Task onto a managed object. You would see this ouput.

Processing the MOID

The MOID is not useful to an IBM Director user. In fact, is is almost never shown to the user, so you will want add code that uses the MOID to get a more useful string to display. Click here to modify your code to display the label for the managed object and then return to read about multitargeting.

Adding multitargeting

Multitargeting is a very powerful feature of IBM Director Tasks. It makes it possible for an IBM Director user to, with one action, activate a single task on a whole group of managed objects. To provide multitargeting in your task frame, you need to do two things:

  1. Modify your task properties to tell IBM Director that your task supports multitargeting.
  2. Modify your code to handle more than one MOID in the Task Activator.


Modifying the task properties

To change the properties for a targeted task, change the "targeted:one" to "targeted:multi". The full change looks like this:

Change the subtask context from:

Subtask.0.Context = interactive:true | server:false | client:ignore | targeted:one
to:
Subtask.0.Context = interactive:true | server:false | client:ignore | targeted:multi

Also, you need to change the action to drag-drop-multi like this:

Subtask.0.Actions = double-click | drag-drop-multi 


Modifying the task frame

In a single targeted task, the MOID of the target is retrieved with code like this:

String msg = resourceBundle.getString("HelloMsgTarget");
long moid = moids.GetValue(0);  // get the first moid
// Now get the label of the current managed object
TWGConManagedObject conObject = (TWGConManagedObject) TWGConObject.FindObject(moid);
String targetLabel = conObject.getName();
// Build the substitution array to format the translated string 
Object substitutions[] =  new Object[]{targetLabels};
message = MessageFormat.format(msg, substitutions);

In a multi-targeted task, use a loop to process all values in the LongValueSet of MOIDs. For example:

String msg = resourceBundle.getString("HelloMsgTarget");
String targetLabels = "";
for (int i=0; i < moids.Length(); i++) {
	long moid = moids.GetValue(i);  // get the first moid
	
	// Now get the label of the Current Managed Object
	TWGConManagedObject conObject = (TWGConManagedObject) TWGConObject.FindObject(moid);
	targetLabels += conObject.getName() + ", ";
}
			
// Build the substitution array to format the translated string 
Object substitutions[] =  new Object[]{targetLabels};
message = MessageFormat.format(msg, substitutions);

When you redeploy and test, you can drag the task onto either a group or a set of multi-selected managed objects and see all the system names in the message.