Showing posts with label Intralink Scripting. Show all posts
Showing posts with label Intralink Scripting. Show all posts

Monday, June 1, 2009

Intralink Scripting: Commonspace Folder Info - Part 3

In Part 1, I discussed how to use the ILFolderTreeModel class to recursively descend through your Commonspace folders to generate a folder list. In Part 2, I discussed how to use CSFolderObjectInfo to perform actions and obtain information on your folders. Now I'm going to discuss yet another data model class to get even more extensive information from your folders.

Intralink classes that extend ILTableModel are the core data presentation classes of the Intralink client. While the ObjectInfo classes represent a chunk of metadata for a specific object, the ILTabelModel presents the data model that is actually displayed in the GUI. Interrogating these classes lets you get data exactly as you would expect to see it in Intralink.

Two folder related data presentation classes that I'll now discuss are ILFolderAuthTableModel and ILPromoteDemoteTableModel. As you might expect from the name, ILFolderAuthTableModel represents the data presentation model of folder authorizations, while ILPromoteDemoteTableModel represents folder release procedures.

To utilize these classes, we need an ILAppObject representation of the folder. The static method getObjectByKey() of the ObjectInfo class allows us to create this object. Here is an example of instantiating an ILFolderAuthTableModel object:

    String folderName = "Root Folder/ProjectX";
ILAppObject fol_ao = ObjectInfo.getObjectByKey(ObjectInfo.tFolder, folderName);
ILFolderAuthTableModel fa_tm = new ILFolderAuthTableModel(false, fol_ao);
 

The table of data contained in the ILTableModel based object can be accessed with generic methods and other methods specific to the data type. Examples of generic methods include getRowCount(), getColumnCount(), getColumnName(), and getValueAt().

Example: Reporting Authorizations and Release Procedures

This example further expands upon the code in Part 2, by adding the output of folder authorizations, release level authorizations, and release procedures associated with each folder.

Just as in the GUI, the example shows output only if something was explicitly set for that folder. If a folder authorizations was set only in a parent folder, that authorization will not appear in the output for subfolders. The same applies to release procedures.

    CSFolderObjectInfo fol_oi = null;
ILAppObject fol_ao = null;
ILFolderAuthTableModel fa_tm = null;
ILPromoteDemoteTableModel pd_tm = null;

for (int i=0; i<folders.size(); i++) {

String folderName = folders.get(i).toString();
System.out.println( " " + (i+1) + ": " + folderName );

fol_oi = (CSFolderObjectInfo)ObjectInfo.createByKey( ObjectInfo.tFolder, folderName );
fol_ao = ObjectInfo.getObjectByKey( ObjectInfo.tFolder, folderName);

System.out.println( " " + "Release Scheme: " + fol_oi.getReleaseScheme() );
System.out.println( " " + "File Space: " + fol_oi.getFilespace() );

fa_tm = new ILFolderAuthTableModel(false, fol_ao);
System.out.println( " " + "Authorizations: ");

if (fa_tm.getRowCount() > 0) {

// output column info
for (int col=0; col<fa_tm.getColumnCount(); col++) {
String colName = fa_tm.getColumnName(col);
if (col == 0) {
System.out.print( " " + " " + colName );
}
else {
System.out.print( " / " + colName );
}
}
System.out.println();

// output row info
for (int row=0; row<fa_tm.getRowCount(); row++) {
for (int col=0; col<fa_tm.getColumnCount(); col++) {
String val = fa_tm.getValueAt(row,col).toString();
if (col == 0) {
System.out.print( " " + " " + val );
}
else {
System.out.print( " / " + val );
}
}
System.out.println();
}
}
else {
System.out.println( " " + " None" );
}

pd_tm = new ILPromoteDemoteTableModel(fol_ao);
System.out.println( " " + "Release Procedures: ");

if (pd_tm.getRowCount() > 0) {

// output column info
for (int col=0; col<pd_tm.getColumnCount(); col++) {
String colName = pd_tm.getColumnName(col);
if (col == 0) {
System.out.print( " " + " " + colName );
}
else {
System.out.print( " / " + colName );
}
}
System.out.println();

// output row info
for (int row=0; row<pd_tm.getRowCount(); row++) {
String rellevel = pd_tm.getValueAt(row,pd_tm.RELLEVEL_COLUMN).toString();
String promote_rp = pd_tm.getValueAt(row,pd_tm.PROMOTE_COLUMN).toString();
String demote_rp = pd_tm.getValueAt(row,pd_tm.DEMOTE_COLUMN).toString();
System.out.println( " " + " " + rellevel + " / " + promote_rp + " / " + demote_rp );
}
}
else {
System.out.println( " " + " None" );
}


pd_tm = null;
fa_tm = null;

fol_oi = null;
fol_ao = null;

System.out.println();
System.out.flush();
}
 

The output should look something like this:

  1: Root Folder/Project X
Release Scheme: ReleaseScheme-ProjectX
File Space: Filespace_ProjectX
Authorizations:
Name / Folder Role / WIP / Detail / Prototype / Manufacturing / Obsolete
*Admin / FolAdmin / Admin / Admin / Admin / Admin / Admin
*Engr / FolEngr / Engr / Engr / Engr / Engr / Engr
*Mgr / FolMgr / Mgr / Mgr / Mgr / Mgr / Mgr
*View / FolView / View / View / View / View / View
Release Procedures:
Name / Release Procedure Promote To / Release Procedure Demote From
WIP / /
Detail / /
Prototype / ProjectX_Mgr / ProjectX_Mgr
Manufacturing / ProjectX_Mgr / ProjectX_Mgr
Obsolete / /
 

As you can see, you can extract very specific information from Intralink quite easily with Java. This information would be very difficult, if not impossible, to extract using the GUI itself. A little bit of Intralink Scripting can often save you lots of time.


Need a program for data mining your Intralink metadata? Migrating from Intralink 3.x to PDM.Link or TeamCenter and need to extract metadata quickly? Contact me at MarcMettes@InversionConsulting.com to get an inexpensive application right now.

Tuesday, May 19, 2009

Intralink Scripting: Commonspace Folder Info - Part 2

In Part 1, I discussed how to use ILFolderTreeModel to recursively descend through your Commonspace folders to generate a folder list. Coupled with other classes, you can generate even more data about your folders.

In a previous article, I discussed the ObjectInfo subclasses and how to use them to get object metadata. In this article, I'll discuss how to use the ObjectInfo subclass pertaining to Commonspace folders called CSFolderObjectInfo.

The CSFolderObjectInfo class contains many methods to interact with Commonspace folders. The ObjectInfo class are extremely powerful as they let you bypass the user interface and talk directly with the data model of the Intralink client. Despite its name, the CSFolderObjectInfo class contains many methods to perform actions upon Commonspace folders, not just to get information about them.

Examples of methods specific to the CSFolderObjectInfo are: getParent(), getFullPath(), setDescription(), createFolder(), deleteFolder(), moveFolder(), getFilespace(), getReleaseLevel(), getReleaseScheme(), setRelScheme(), etc. Not all of these are guaranteed to work as you may hope. Caution must be exercised before experimenting on your production system. Do so at your own risk.

Before you can apply these methods, you need a CSFolderObjectInfo object. One way to instantiate a CSFolderObjectInfo object is with the static method createByKey() in the ObjectInfo class, although sometimes there are other ways. Here is an example, using the static field tFolder to specify the ObjectInfo object type and a String value for the folder name:

    CSFolderObjectInfo fol_oi = null;
fol_oi = (CSFolderObjectInfo)ObjectInfo.createByKey( ObjectInfo.tFolder, "Root Folder/ProjectX" );
 

This is a very generic technique that can be applied to most other ObjectInfo data types, even though there are specific createByKey() methods for specific object types.


Example: Release Scheme, File Space, and Release Levels

This example expands upon the code in Part 1, by adding the output of the Release Scheme name, the File Space used, and the Release Levels associated with each folder. Both getReleaseScheme() and getFilespace() return String values of their respective outputs. getReleaseLevel() returns a String array of Release Levels.

    CSFolderObjectInfo fol_oi = null;
List folders = getFolderList(tm, tree);

for (int i=0; i<folders.size(); i++) {

String folderName = folders.get(i).toString();
System.out.println( " " + (i+1) + ": " + folderName );

fol_oi = (CSFolderObjectInfo)ObjectInfo.createByKey( ObjectInfo.tFolder, folderName );

System.out.println( " " + "Release Scheme: " + fol_oi.getReleaseScheme() );
System.out.println( " " + "File Space: " + fol_oi.getFilespace() );

System.out.println( " " + "Release Levels: ");
String[] fol_rellevels = fol_oi.getReleaseLevel();

// release level array values start at 1, but still has element zero
for (int j=1; j<fol_rellevels.length; j++) {
System.out.println( " " + " " + j + ": " + fol_rellevels[j] );
}

fol_oi = null;

System.out.println(); // blank line for readability
System.out.flush(); // flush to see data in output file immediately
}
 


In the next installment, I'll show yet more information about folders that can be gathered, including folder and role based authorizations.

Monday, April 27, 2009

Intralink Scripting: Commonspace Folder Info, Part 1

A lot of administrative tasks in Intralink 3.x are much more difficult than necessary, and in some cases nearly impossible. Folder information is one of those tasks. Without running the DSMU, getting information on folders can be extremely tedious.

Fortunately with the right Java code, we can put some of the internal features of the Intralink client to use. These are the same data model classes that the client Java code uses, but now we can use them to get the information that you want, how you want it, and whenever you want it. Remember, it's your data.


To traverse the Commonspace folder structure, my utility method getFolderList() will be used. It uses an ILFolderTreeModel object, which is a folder tree data model class, and a TreeNode, which is a node within a tree structure. The method calls itself recursively to traverse a folder tree, which need not start at the Commonspace root folder.

Initially, the method builds a new ArrayList. Then, the root node is added to the ArrayList. The method then iterates over the children, if any, of the current node. If there are child nodes, the method calls itself using the same ILFolderTreeModel object, but this time with the child node. The resulting ArrayList of the child node recursion is added to the higher level ArrayList. The child ArrayList is then cleared and nulled. The first ArrayList is returned when recursion has completed.

  public List getFolderList ( ILFolderTreeModel treemodel, TreeNode tree ) throws Exception {

List list = new ArrayList();
list.add(tree.getKeyName());

for (int i=0; i<treemodel.getChildCount(tree); i++) {

TreeNode child = (TreeNode)treemodel.getChild(tree,i);

List sublist = getFolderList(treemodel, child);
list.addAll(sublist);
sublist.clear();
sublist = null;

}

return list;

}
 

In order to call this function, an ILFolderTreeModel and a TreeNode object are required.

For the ILFolderTreeModel object, we can simply call the constructor:
    ILFolderTreeModel tm = new ILFolderTreeModel();
 

If the root node is the Commonspace Root Folder, then the TreeNode object is obtained as follows from the ILFolderTreeModel object:
    TreeNode tree = (TreeRootNode)tm.getRoot();
 

If another folder is the root for the TreeNode, things get a bit more complicated. First, an ILAppObject is created representing the folder of interest, then TreeObject.createCSTree() is executed using the ILAppObject. Running the getRoot() method of the resulting TreeObject gives us a TreeNode that we can use.
    String startFolderName = "Root Folder/ProjectX";
ILAppObject start_fol_ao = ObjectInfo.getObjectByKey( ObjectInfo.tFolder, startFolderName );
TreeNode tree = TreeObject.createCSTree(start_fol_ao).getRoot();
 

To get the ArrayList, getFolderList() is executed:
    List folders = getFolderList(tm, tree);
 

To iterate over the resulting ArrayList, use code like this:
    for (int i=0; i<folders.size(); i++) {
String folderName = folders.get(i).toString();
System.out.println( " " + (i+1) + ": " + folderName );
}
 

The output will appear in the .proi.log file on Unix or the most recent .pro.log.N file on Windows.


Here is the complete program. Please note the addition of three import statements beyong the typical two that Intralink provides in each Intralink Scripting application.

import com.ptc.intralink.client.script.*;
import com.ptc.intralink.script.*;

import com.ptc.intralink.client.admin.folder.*;
import com.ptc.intralink.ila.*;
import java.util.*;


public class Folder_List extends ILIntralinkScript {

ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface)getScriptInterface();


public void run () throws Exception {

TreeNode tree = null;
ILFolderTreeModel tm = new ILFolderTreeModel();

String startFolderName = null;
startFolderName = "";
startFolderName = "/";
startFolderName = "Root Folder";
startFolderName = "Root Folder/ProjectX";

if ( startFolderName == null || startFolderName.matches("^/?$") ) {
tree = (TreeNode)tm.getRoot(); // Casting to TreeNode required
}
else {
ILAppObject start_fol_ao = ObjectInfo.getObjectByKey( ObjectInfo.tFolder, startFolderName );
tree = TreeObject.createCSTree(start_fol_ao).getRoot();
}

System.out.println( " tree: " + tree );
List folders = getFolderList(tm, tree);

for (int i=0; i<folders.size(); i++) {
String folderName = folders.get(i).toString();
System.out.println( " " + (i+1) + ": " + folderName );
System.out.flush();
}

folders.clear();
folders = null;
tm = null;

}


public List getFolderList ( ILFolderTreeModel treemodel, TreeNode tree ) throws Exception {

List list = new ArrayList();
list.add(tree.getKeyName());

for (int i=0; i<treemodel.getChildCount(tree); i++) {

TreeNode child = (TreeNode)treemodel.getChild(tree,i);

List sublist = getFolderList(treemodel, child);
list.addAll(sublist);
sublist.clear();
sublist = null;

}

return list;

}

}
 


In the next installment, I'll show how more information about folders can be gathered, along with a more sophisticated presentation of the data.

Monday, April 28, 2008

J-Link: Compile Your Pro/ENGINEER Java Application with Intralink!

If you've wanted to try some Pro/ENGINEER programming using J-Link (the free Java API), but didn't know how to compile your program, then this article is for you. Forget Netbeans, forget Eclipse, and forget downloading and installing the JDK. Just use Intralink's Java Runtime Environment to compile your apps.

Seriously though, those IDE's are really great programs, but sometimes you can't install them, or they're not available on your system, or you just need something minimal and fast. Fortunately, Intralink contains everything we need to compile J-Link applications: a JRE and tools.jar. tools.jar is the codebase from Javasoft that contains Java compilation code.

Here is a batch file that will compile J-Link Java code on Windows:

@echo off
rem jlink_javac.bat - Compile JLink Apps using Intralink JDK

set Proe_Install_Dir=c:\ptc\proeWildfire2.0_m200
set IL_Install_Dir=c:\ptc\proiclient3.3_m021
set CLASSPATH=%IL_Install_Dir%\i486_nt\lib\tools.jar
set path=%IL_Install_Dir%\i486_nt\jre\bin;%path%

java sun.tools.javac.Main -classpath %Proe_Install_Dir%\text\java\pfc.jar -d . %*
 
Run it like this:

jlink_javac.bat Abc.java Def.java Ghi.java
 

Here is a C shell script that will compile J-Link Java code on Unix:

#!/bin/csh
# jlink_javac.csh - Compile JLink Apps using Intralink JDK

setenv Proe_Install_Dir /opt/proeWildfire2.0_m200
setenv IL_Install_Dir /opt/proiclient3.3_m021
setenv CLASSPATH $IL_Install_Dir/sun4_solaris/lib/tools.jar
set path=( $IL_Install_Dir/sun4_solaris/jre/bin $path )

java sun.tools.javac.Main -classpath $Proe_Install_Dir/text/java/pfc.jar -d . $*
 
Run it like this:

jlink_javac.csh Abc.java Def.java Ghi.java
 

The resulting class files will be in the current directory. While I do use this for my own J-Link code which is typically targeted at Java 1.4.2, it may not work with newer Java versions, nor take advantage of their full capabilities. However, for you command line junkies out there, this is just the recipe.

Tuesday, April 15, 2008

Intralink Scripting: Creating Pro/ENGINEER Trail Files in Java

If you're trying to automate some Pro/ENGINEER activity, the use of trail files is a solid and reliable method. Whether you are trying to automate interference checks, convert files to ProductView or PDF, or just verify a large number of family tables, trail files work great. This is assuming that you don't need any interaction between Intralink and Pro/ENGINEER, during the trail file execution.

The first thing you need is a trail file template. This is simply a trail file that you have recorded. The content will be changed slightly to include variable names where real values will be substituted at runtime.

For example, this:
~ Activate `main_dlg_cur` `ProCmdModelOpen.file`
~ Select `file_open` `Ph_list.Filelist` \
1 `abc.prt`

Becomes this:
~ Activate `main_dlg_cur` `ProCmdModelOpen.file`
~ Select `file_open` `Ph_list.Filelist` \
1 `@NAME@`


One thing to note about trail files, they contain a lot of "fluff", which are lines that you don't need, but got recorded. You won't know what you need and don't need until you try to remove it. My advice is to comment lines you think you don't need, by placing an exclamation point as the first character of the line. Pro/ENGINEER will ignore these lines. If the trail file plays as expected, the line is probably not needed.

This means that any line starting with an exclamation point can be eliminated. The one exception is the first line of the file. You need this, don't remove it. Generally, I leave some of the commented lines that were originally recorded in order to remind myself when an action has started or finished.

There is a config.pro option that will help prevent trail file fluff. Set CMDMGR_TRAIL_OUTPUT to YES and Pro/ENGINEER will reduce the number of lines and increase readability substantially.

Here is an example of a trail file template that records a timestamp, opens a file, records another timestamp, and then exits. You'll notice the comments indicating "blocks" of actions.


!trail file version No. 1301
!!!
!!! Timestamp
!!!
~ Select `main_dlg_cur` `MenuBar1` \
1 `Info`
~ Select `main_dlg_cur` `Info.cb_info_session`
~ Close `main_dlg_cur` `MenuBar1`
~ Close `main_dlg_cur` `Info.cb_info_session`
~ Activate `main_dlg_cur` `psh_util_time`
!!!
!!! Open model
!!!
~ Activate `main_dlg_cur` `ProCmdModelOpen.file`
~ Select `file_open` `Ph_list.Filelist` \
1 `@NAME@`
~ Activate `file_open` `Open`
!Command ProCmdModelOpenExe was pushed from the software.
!!!
!!! Timestamp
!!!
~ Select `main_dlg_cur` `MenuBar1` \
1 `Info`
~ Select `main_dlg_cur` `Info.cb_info_session`
~ Close `main_dlg_cur` `MenuBar1`
~ Close `main_dlg_cur` `Info.cb_info_session`
~ Activate `main_dlg_cur` `psh_util_time`
!!!
!!! Exit
!!!
~ Select `main_dlg_cur` `MenuBar1` \
1 `File`
~ Close `main_dlg_cur` `MenuBar1`
~ Activate `main_dlg_cur` `File.psh_exit`
! Message Dialog: Warning
! : Do you really want to exit?
~ FocusIn `UI Message Dialog` `no`
~ FocusIn `UI Message Dialog` `yes`
~ Activate `UI Message Dialog` `yes`
!End of Trail File

Now that we have a template, we need some java code to create the trail file that Pro/ENGINEER will run. There are many Java templating libraries that do some very complex manipulations, but for this simple example, we need very simple substitutions. The code listed below is quite simple, but works great for basic trail file creation.

Once variables have been established, the first task is to generate file handle objects for reading (using the BufferedReader/FileReader classes) and for writing (using the FileWriter class). Each line of the template file is read from using readLine() in the while loop. Then the value of the objName variable is substituted where @NAME@ is found in the template. The resulting line is written to the output file. Closing both the input and output file is very important, especially on Windows, to make them fully accessible.

String text;
String inputFile = "trl-template.txt";
String outputFile = "trl-output.txt";
String newline = System.getProperty("line.separator");

// Set up input and output files
BufferedReader templateInput = new BufferedReader(new FileReader(inputFile));
FileWriter trailOutput = new FileWriter(outputFile);

// Read through all lines in file
while ((text = templateInput.readLine()) != null) {

// Replace @NAME@ with objName String
text = text.replaceAll( "@NAME@", objName );

// Output modified template line to given output file stream
trailOutput.write(text + newline);

}

trailOutput.close();
templateInput.close();

Following best practices, the code should be placed in its own function, or, even better, its own class. Also, using an array or HashMap, instead of a simple String object for input, would allow for more extensive substitutions to occur during trail file generation, but the above is the core of a simple approach that works very well.

Thursday, April 10, 2008

Intralink Scripting: Working with Dates in Locate

When recording dates during a Locate using the Scripting Options dialog, Intralink records it as a reference to the number of milliseconds since the beginning of 1970.

IL.addFilter( "Created On", ">=", new Object[]{new java.util.Date(1104555600000L)} ); 
It works fine, but with milliseconds it's a little hard to change to a specific date/time. It's still workable if your dates are relative to now, for example, models that have changed in the last 24 hours.

Date onedayago = new Date( (new Date()).getTime() - 24*3600*1000 );
IL.addFilter( "Created On", ">=", new Object[]{onedayago} );
Creating a new Date object sets it to the date/time right now and the getTime() method returns the number of milliseconds since 1970 for that object. For our "24 hours ago" Date object, we just need to subtract 24*3600*1000 milliseconds from that value and use it to create our object.

This is just quick and dirty calculations, if you need more precise calculations, you'll need to turn to Calendar based classes.


If we need to specify absolute date/time values, we'll have to incorporate the GregorianCalendar class into the mix. This class is the "official" way to specify absolute dates, provided you follow the Gregorian calendar.

The first step is to create the two objects and assign date/time values. Here were are setting year, month, day, hour, minute, and second values, but there are other options, such as add(), roll(), and setTime():
GregorianCalendar cal1 = new GregorianCalendar();
GregorianCalendar cal2 = new GregorianCalendar();
cal1.set(2008,0,1,0,0,0); // 2008-01-01 00:00:00
cal2.set(2008,2,15,23,59,0); // 2008-03-15 23:59:00

For the addFilter() method, we'll use the getTime() method on each GregorianCalendar object, which returns a Date object:
IL.addFilter( "Created On", ">=", new Object[]{ cal1.getTime() }
IL.addFilter( "Created On", "<=", new Object[]{ cal2.getTime() } ););

Sunday, April 6, 2008

Intralink Scripting: To Be or Not To Be, How to Best Answer the Question

Checking for Object Existence with CSPIObjectInfo and CSPIVObjectInfo

When processing Intralink objects in Java from a non-Intralink source, such as a text file or database, the typical process is to use Locate to search for the item to ensure that it exists. While this is usually sufficient, there are times when the overheard of using Locate is undesirable. The good news is that there is an alternative using the ObjectInfo derived classes.

Continuing on my discussion of ObjectInfo classes, I'll discuss how to apply these classes to determine whether a PI (i.e. abc.prt) or a PIV (i.e. abc.prt/main/A/0) exists.

If we're checking for "my_assembly.asm", we'd follow these steps. First declare an object of type CSPIObjectInfo. Then attempt to create the object using the createByKey() method of the ObjectInfo class, providing the type as ObjectInfo.tPI and name in the variable piName.

Although I have it captured in a try{} block, it won't throw an exception if the PI doesn't exist, instead as you may have guessed from the code, in merely returns null. If the object is null, it doesn't exist.

String piName = "my_assembly.asm";
CSObjectInfo pi_oi = null;

try {
pi_oi = (CSObjectInfo)ObjectInfo.createByKey( ObjectInfo.tPI, piName );
if (pi_oi == null) {
System.out.println( "pi_oi is null" );
}
else {
System.out.println( "pi_oi getName(): " + pi_oi.getName() );
}
}
catch (Exception e) {
System.out.println( "CSObjectInfo createByKey exception: " + e.getMessage() );
}

To determine is a PIV exists (i.e. "my_assembly.asm", main branch, revision 1, version 0), ObjectInfo.tPIV is the corresponding type to use also with the createByKey() method of the ObjectInfo class. It also has the same behavior, returning null is the PIV does not exist.
String pivName = "my_assembly.asm/main/1/0";
CSPIVObjectInfo piv_oi = null;

try {
piv_oi = (CSPIVObjectInfo)ObjectInfo.createByKey( ObjectInfo.tPIV, pivName );
if (piv_oi == null) {
System.out.println( "piv_oi is null" );
}
else {
System.out.println( "piv_oi getName(): " + piv_oi.getName() );
}
}
catch (Exception e) {
System.out.println( "CSPIVObjectInfo createByKey exception: " + e.getMessage() );
}

The major weakness with this approach for PIV's is that you have to know of it's name, revision, and version ahead of time. If you want to know what the latest revision/version is, the Locate approach will give you both confirmation of existence and knowledge of the revision/version at the same time.

You'll have to choose when it makes sense to use it, but it remains a very powerful technique nonetheless.

Friday, April 4, 2008

Intralink Scripting: Font Size Does Matter!

Using Java Swing Utilities to make the Intralink GUI text more readable

The font in the Intralink client is a little small for most people, and as a result changing the font size is a question that pops up from time to time. Unfortunately, Intralink doesn't provide a way to do this directly, which makes most people just give up.

Since we're dealing with Java, almost anything is possible, and changing the font is one of those things. There's basically three main steps: 1) Setup the font object to use, 2) Tell the UIManager is use the new font details, 3) Force a full GUI redraw. It's easiest to do this when Intralink is starting, then the user is good to go from that point on.

Steps 1 & 2 are encompassed into one function setMenuFontSizeDefault(). The first task is to obtain the font object used for menus ("Menu.font"). Then the details (Name, Style, Size) are extracted. The function is changing only the size, but a new font could be used as well (check the comments). With the changed font details, a new FontUIResource object is created.

The next task is to associate the new font object with many different font attributes, obviously in what looks to be a brute force attack.

private void setMenuFontSizeDefault(int size) {

// get font style and name from current menu font
//
String BaseFontSource = "Menu.font";
Font fontCurrent = UIManager.getFont(BaseFontSource);
String name = fontCurrent.getName();
int style = fontCurrent.getStyle();

String styleName = "(?)";
if (style == Font.PLAIN) { styleName = "(Plain)"; }
if (style == Font.ITALIC) { styleName = "(Italic)"; }
if (style == Font.BOLD) { styleName = "(Bold)"; }

System.out.println( "Current " + BaseFontSource + " name/style/size: "
+ name + "/" + style + styleName + "/" + fontCurrent.getSize() );

// Override font name and/or style by uncommenting one of these
// name = "Times New Roman";
// style = Font.BOLD; styleName = "(Bold)";

System.out.println( "Changing name/style/size to: " + name + "/" + style + styleName + "/" + size );

// create similar font with the specified size
//
FontUIResource fontResourceNew = new FontUIResource(name, style, size);


// change UI defaults for all types of menu components
//
UIManager.put("Button.font", fontResourceNew);
UIManager.put("CheckBox.font", fontResourceNew);
UIManager.put("CheckBoxMenuItem.acceleratorFont", fontResourceNew);
UIManager.put("CheckBoxMenuItem.font", fontResourceNew);
UIManager.put("ComboBox.font", fontResourceNew);
UIManager.put("DesktopIcon.font", fontResourceNew);
UIManager.put("EditorPane.font", fontResourceNew);
UIManager.put("FormattedTextField.font", fontResourceNew);
UIManager.put("InternalFrame.titleFont", fontResourceNew);
UIManager.put("Label.font", fontResourceNew);
UIManager.put("List.font", fontResourceNew);
UIManager.put("Menu.acceleratorFont", fontResourceNew);
UIManager.put("Menu.font", fontResourceNew);
UIManager.put("MenuBar.font", fontResourceNew);
UIManager.put("MenuItem.acceleratorFont", fontResourceNew);
UIManager.put("MenuItem.font", fontResourceNew);
UIManager.put("OptionPane.buttonFont", fontResourceNew);
UIManager.put("OptionPane.messageFont", fontResourceNew);
UIManager.put("PasswordField.font", fontResourceNew);
UIManager.put("PopupMenu.font", fontResourceNew);
UIManager.put("ProgressBar.font", fontResourceNew);
UIManager.put("RadioButton.font", fontResourceNew);
UIManager.put("RadioButtonMenuItem.acceleratorFont", fontResourceNew);
UIManager.put("RadioButtonMenuItem.font", fontResourceNew);
UIManager.put("Spinner.font", fontResourceNew);
UIManager.put("TabbedPane.font", fontResourceNew);
UIManager.put("Table.font", fontResourceNew);
UIManager.put("TableHeader.font", fontResourceNew);
UIManager.put("TextArea.font", fontResourceNew);
UIManager.put("TextField.font", fontResourceNew);
UIManager.put("TextPane.font", fontResourceNew);
UIManager.put("TitledBorder.font", fontResourceNew);
UIManager.put("ToggleButton.font", fontResourceNew);
UIManager.put("ToolBar.font", fontResourceNew);
UIManager.put("ToolTip.font", fontResourceNew);
UIManager.put("Tree.font", fontResourceNew);
UIManager.put("Viewport.font", fontResourceNew);
UIManager.put("JTitledPanel.title.font", fontResourceNew);

}

Probably a better way, but it works!


Step 3 is accomplished with the updateAllFrames() function. With the frames gathered from Frame.getFrames(), the font change is forced upon the frame (and the frames windows, if any) using SwingUtilities.updateComponentTreeUI().

private void updateAllFrames () {

Frame frames[] = Frame.getFrames();

for (int i = 0; i < frames.length; i++) {

if ( frames[i].getTitle().equals("") frames[i].getTitle().equals("Pending RTP Forms") ) {
continue;
}

// Update the frames
try {
SwingUtilities.updateComponentTreeUI(frames[i]);
}
catch (Exception e) {
// Exception thrown, skip it
}

// Update the frame's windows
Window windows[] = frames[i].getOwnedWindows();
for (int j = 0; j < windows.length; j++) {
try {
SwingUtilities.updateComponentTreeUI(windows[j]);
}
catch (Exception e) {
// Exception thrown, skip it
}
}

}

}

The two function are called in this order, as an example:

setMenuFontSizeDefault(15); // set font size to 15
updateAllFrames();



These import statement might be necessary as well:

import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;





Wednesday, April 2, 2008

Intralink Scripting: Processing Java Command Line Arguments

Using the Command Line in your Java Code

Accessing the command line arguments for a program is a very useful way to control its behavior during runtime. This is no different with Intralink, especially when running Intralink Scripting autonomously, where you can't prompt the user for information.

A little bit of digging will unveil the ILArgumentParser class. This allows access to the command line arguments used with Intralink. The following two functions are very helpful in working with this class.

Arguments are expected to be in this form:

ilink -- -loginfile login.txt

This function indicates whether a command line argument keyword exists:
public boolean isCmdLineArg ( String argName ) throws Exception {

String argSpec = "-" + argName.toLowerCase();

// Check command line args for argName
//
try {
ILArgumentParser ilargumentparser = Intralink.m_arguments;
if ( ilargumentparser.containsKey(argSpec) ) {
return true; // argName is a command line argument
}
}
catch (Exception e) {
// exception: command line arg does not exist, ignore
}

return false; // argName is not a command line argument
}

This function return a command line argument value:
public String getCmdLineArg ( String argName ) throws Exception {

String argValue = null;
String argSpec = "-" + argName.toLowerCase();

// Check command line args for argName
//
try {
ILArgumentParser ilargumentparser = Intralink.m_arguments;
if ( ilargumentparser.containsKey(argSpec) ) {
argValue = ilargumentparser.getValue(argSpec);
}
}
catch (Exception e) {
// exception: command line arg does not exist, ignore
}

return argValue;
}

Example usage:
String loginFile = "login.txt"; // default value
if (isCmdLineArg("loginFile")) { loginFile = getCmdLineArg("loginFile"); }

Sunday, March 30, 2008

Java: A JDialog and JProgressBar Example

If you have an application that runs for a long time, providing feedback that something is still happening is a really useful thing. Java provides a very wide range of GUI components.

One that fits the need is the JProgressBar. As you might expect, the JProgressBar allows you to draw a progress meter, either horizontally or vertically, and update it while your program is running.

Here is an example of using JProgressBar within a JDialog. JDialog allows you to set the dialog as modal, which will stop the application until the dialog is dismissed (as a JOptionPane does). There are many ways to create a dialog in java, this example includes both and is merely one (very minimalistic) way to do it.

First the JProgressBar object is created and attributes set, including min and max values of 0 and 100, respectively, and size of the progress bar:

JProgressBar pb = new JProgressBar(0,100);
pb.setPreferredSize(new Dimension(175,20));
pb.setString("Working");
pb.setStringPainted(true);
pb.setValue(0);


A JLabel object is created to display some text in the dialog:

JLabel label = new JLabel("Progress: ");


Then the label and progress bar are added to the panel:

JPanel center_panel = new JPanel();
center_panel.add(label);
center_panel.add(pb);



Once the panel is populated, the JDialog object is created, the panel is added,
and it is made visible:

dialog = new JDialog((JFrame)null, "Working ...");
dialog.getContentPane().add(center_panel, BorderLayout.CENTER);
dialog.pack();
dialog.setVisible(true);



Some useful actions to perform on the dialog, though not all at the same time:

dialog.setLocationRelativeTo(null); // center on screen
dialog.setLocation(550,25); // position by coordinates
dialog.toFront(); // raise above other java windows



While your program is running, you can update the progress bar by feeding it an integer value between the min and max values:

pb.setValue(25);


You have a couple of options when your program is done. The simplest thing to do is to close the dialog, and then display a JOptionPane, for example, informing the user:

dialog.dispose();


To get more creative, one can add a button to the dialog, which will can close the dialog when pressed. The action is defined by adding an action listener to the button. Here we dynamically add the button, but it could be done at the beginning.

JButton button = new JButton("Done");
button.setActionCommand("done");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt){
if ( evt.getActionCommand().equals("done") ) {
dialog.dispose();
}
}
});


The button is added to a new JPanel object:

JPanel page_end_panel = new JPanel();
page_end_panel.add(button);


Then the new panel is added to the dialog, which will make it appear immediately:

dialog.getContentPane().add(page_end_panel, BorderLayout.PAGE_END);


It's not required, but if you wish to force the user to hit the button, the dialog can be made "modal", which will cause it to act like a JOptionPane. It seems that the visibility of the dialog must be toggled for the change in modality to take effect:

dialog.setModal(true);
dialog.pack();
dialog.setVisible(false);
dialog.setVisible(true);



This will cause the program to wait until the button is pressed, which will dismiss the dialog.

Just in case the dialog is dismissed by closing the window, without hitting the button, you might want to add a call to dispose() anyway. Perhaps that is unnecessary.
dialog.dispose();

Intralink Scripting: Triggering on Java Events

It is possible to trigger on events occuring with the JVM using the AWTEventListener class. There won't be fine grain control nor information about what event occurred, but that can be derived from the expected events.

This is an example of how to use the AWTEventListener to monitor for window events such as opening windows and closing windows, as well as windows gaining and losing focus.

The first step is to define an AWT event listener. This listener makes the newly created frame invisible. It's almost immediate, but the frame will appear briefly before disappearing.

AWTEventListener listener = new AWTEventListener() {
public void eventDispatched(java.awt.AWTEvent event) {
if (event.getID() == WindowEvent.WINDOW_OPENED) {
Frame[] frames = Frame.getFrames();
int frm_idx = frames.length-1;
System.out.println( " making frame " + frm_idx
+ " (" + frames[frm_idx].getTitle()
+ ") invisible" );
frames[frm_idx].setVisible(false);
}
}
};

Once the listener object has been created, it needs to be registered to become active using addAWTEventListener():

Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.WINDOW_EVENT_MASK);


To disable the listener, use removeAWTEventListener():

Toolkit.getDefaultToolkit().removeAWTEventListener(listener);


Monday, March 24, 2008

Extracting Class Info with Java Reflection

Here is some code that I use to extract information about classes using Java Reflection. It takes the class name as a String argument (i.e. "java.util.Date"), then outputs the information to standard output.

It works best when incorporated into a loop reading class names from an input file or some other data source. For you Intralink Scripting users out there, the data will appear in your .proi.log file.


public void getClassData ( String className ) throws Exception {

System.out.println( "Class: " + className );
System.out.println();

try {

Class c = Class.forName(className);

System.out.println( " package: " + c.getPackage().getName() );
System.out.println( " isinterface: " + c.isInterface() );

System.out.print( " superclass: " );
if (c.getSuperclass() == null) { System.out.println(); }
Class sc = c;
int indent = 0;
while (sc.getSuperclass() != null) {
if (indent > 0) {
for (int i=0; i<indent; i++) { System.out.print( " " ); }
System.out.print( " -> " );
}
System.out.println( sc.getSuperclass().getName() );
sc = sc.getSuperclass();
indent += 3;
}

System.out.println();


System.out.println("Constructors: ");
try {
// Constructor[] cons = c.getDeclaredConstructors();
Constructor[] cons = c.getConstructors();
for (int i = 0; i < cons.length; i++) {
// System.out.println( " constr: " + cons[i].toString() );
System.out.println( " " + cons[i].toString() );
}
}
catch (Exception e1) {
// cannot get constructor info
}
System.out.println();


System.out.println("Interfaces: ");
try {
Class intfs[] = c.getInterfaces();
for (int i = 0; i < intfs.length; i++) {
// System.out.println( " intf: " + intfs[i].toString() );
System.out.println( " " + intfs[i].toString() );
}
}
catch (Exception e1) {
// cannot get interface info
}
System.out.println();


System.out.println("Methods: ");
try {
// Method meths[] = c.getDeclaredMethods();
Method meths[] = c.getMethods();
for (int i = 0; i < meths.length; i++) {
// System.out.println( " method " + meths[i].getName() + "(): " + meths[i].toString() );
System.out.println( " " + meths[i].getName() + "(): " + meths[i].toString() );
}
}
catch (Exception e1) {
// cannot get method info
}
System.out.println();


System.out.println("Fields: ");
try {
// Field flds[] = c.getDeclaredFields();
Field flds[] = c.getFields();
for (int i = 0; i < flds.length; i++) {
// System.out.println( " field " + flds[i].getName() + ": " + flds[i].toString() );
System.out.println( " " + flds[i].getName() + ": " + flds[i].toString() );
}
}
catch (Exception e1) {
// cannot get method info
}
System.out.println();


}
catch (Exception e) {
System.out.println( " Problem getting class information!" );
System.out.println( e.getMessage() );
System.out.println();
}


System.out.println();
System.out.flush();

}

This is easily modified to output data to a named file. Let me know if you need to see that.

Wednesday, March 19, 2008

Printing from Intralink: Where'd it go?!

One difficulty new Intralink users have is finding data that is printed from the Intralink client. The 'html' folder hidden deeply in the .proi is not the first place users expect the output to go.

To counteract this annoyance, several of my users use this one-liner Intralink Scripting application to direct output to their working directory.

IL.setReportAdapterDefaultPath( System.getProperty("user.dir") );

The users run this once per session.

Tuesday, March 18, 2008

Using ObjectInfo and its Subclasses in Intralink Scripting

Data can be extracted from Intralink with Intralink Scripting in a number of ways. The getTableCellValue() method can be used to pull data from a displayed table or form, but sometimes this is just not enough.

For example, let's say you want to know, for certain Commonspace objects, the file name in the file vault. This can be accomplished in several ways. You can use Oracle SQL queries, but this requires administrative access to Oracle on the server, and we need something simpler.

Another option is to check out the files to a Workspace, then examine the contents of the 'File Path' column. This is easier than SQL, but can be a time consuming task, especially if data is needed on many objects.

It turns out that there's a simple and direct way to access the information without SQL and without checkouts. The Java code that provides the core of the Intralink client provides powerful classes and methods that can be used to tap directly into Intralink. A little bit of Java Reflection tells us all about it, including constructors, methods, and available fields.

One hierachy of classes to do this is the ObjectInfo class and subclasses. These provide very extensive information about objects, in Commonspace and Workspaces, without needing to access displayed fields in the Intralink GUI.

Here is a list of most 'ObjectInfo' derived classes:

com.ptc.intralink.ila.AdmRelLevelObjectInfo
com.ptc.intralink.ila.AdmRelSchemeObjectInfo
com.ptc.intralink.ila.AdmRoleObjectInfo
com.ptc.intralink.ila.AdmUserGroupObjectInfo
com.ptc.intralink.ila.AdmUserObjectInfo
com.ptc.intralink.ila.ApprovalSchemeObjectInfo
com.ptc.intralink.ila.AttrClassObjectInfo
com.ptc.intralink.ila.AttrDefObjectInfo
com.ptc.intralink.ila.CSBaselineObjectInfo
com.ptc.intralink.ila.CSFolderObjectInfo
com.ptc.intralink.ila.CSObjectInfo
com.ptc.intralink.ila.CSPIObjectInfo
com.ptc.intralink.ila.CSPIVObjectInfo
com.ptc.intralink.ila.CSSubmFormObjectInfo
com.ptc.intralink.ila.LILObjectInfo
com.ptc.intralink.ila.LOObjectInfo
com.ptc.intralink.ila.LOVObjectInfo
com.ptc.intralink.ila.ObjectInfo
com.ptc.intralink.ila.PIVDependencyObjectInfo
com.ptc.intralink.ila.RTPObjectInfo
com.ptc.intralink.ila.WSDependencyObjectInfo
com.ptc.intralink.ila.WSObjectInfo
com.ptc.intralink.ila.WSPIObjectInfo

Here is some code that utilizes parts of ObjectInfo and CSPIVObjectInfo to get the file path for selected Commonspace objects:

IL.selectAll( "PIV" );
String[] o = IL.getSelectedObjects( "PIV" );
IL.deselectAll( "PIV" );

for (int i=0; i<o.length; i++) {
CSPIVObjectInfo oi = (CSPIVObjectInfo)ObjectInfo.createByKey( ObjectInfo.tPIV, o[i] );
String filePath = oi.getFilePath();
System.out.println( o[i] + "\t" + filePath );
}

The tricky part was figuring out how to instantiate the ObjectInfo objects, but with a little trial and error, and the help of Java Reflection output, it doesn't take to long to figure it out.