Extending the classification browser

Ever wanted to display records via a classification browser? The ADAM ClassificationTree control makes this easy for you. All you need is a... ClassificationTree control and a couple lines of code.

This example shows you how to accomplish this.

Example

Create a web page containing an AdamPageManager and a ClassificationTree. The AdamPageManager (required on all ADAM pages) manages all kinds of page events, such as gathering and showing messages when needed.
Obviously, we also need a ClassificationTree control on this page.

XML
1
2
3
4
5
<awc:AdamPageManager id="ctrAdamPageManager" runat="server" />
<awc:ClassificationTree ID="ctrTree" 
   OnClassNodeChildAdding="ctrTree_ClassNodeChildAdding"
   OnSelectedNodeChanged="ctrTree_SelectedNodeChanged" 
   AutoPostBack="NodeSelect" runat="server" />

IIn the code-beside, the ClassNodeChildAdding event is used to create new textnodes where we:

  1. load the records, classified in the current classification and containing at least one file.
  2. determine the imageurl based on the resolution of the record's master file. This will give the user a quick view on the resolution of the record's file.
  3. create a new textnode where the label is the record's filename.
  4. add this textnode to the list of childnodes of the current ClassNode.
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
protected void ctrTree_ClassNodeChildAdding(object sender, ClassNodeCancelEventArgs e)
{
  ClassificationHelper classHelper = new ClassificationHelper(AdamHelper.DefaultApplication);
  if (!classHelper.HasChildren(e.Classification.Id))
  {
    // Search for records with the  following restrictions:
    // 1: The number of files should be at least 0
    // 2: The records should be classified in the current classNode
    string expression = "FileCount > 0 AND DirectClassification.Id = ?";
    RecordCollection records = new RecordCollection(AdamHelper.DefaultApplication);
    RecordLoadOptions options = new RecordLoadOptions();
    options.PreLoadClassifications = false;
    options.PreLoadFields = string.Empty;
    options.PreLoadFileFields = string.Empty;
    options.PreLoadFiles = PreLoadFile.FilesVersions;
    options.LockMode = LockMode.ReadUncommitted;

    records.Load(new SearchExpression(expression, new object[] { e.Classification.Id }), string.Empty, options);
    foreach (Record record in records)
    {
       ImageUri uri = new ImageUri(record, ImageType.Preview);
       TextNode node = new TextNode(record.Files.LatestMaster.FileName, record.Id.ToString(),
       this.GetImageUrl(record.Files.LatestMaster), uri.ToString(), "_blank");
       e.Node.ChildNodes.Add(node);
    }
  }
}

A remark on performance

It's important to know that we need to minimise the number of record loads as much as possible. Recordloadoptions are very useful to do that. In these options we specify:

  • that the record's fields and classifications should not be loaded because the're not used.
  • the lockmode is set to readuncommitted, which basically means that the data is gathered with an optimal performance. This makes the impact on the sql server lower than when using the default lockmode.

Running this web page will give you the result shown below. As you can see, this example makes it  easy to distinguish high-res from low-res images:


Sample Code

The article contains sample code project(s).
You must be logged in to view or download sample code.
Sign in now

Comments

Wednesday, 10 March 2010Peter Scoins says
Great Arcticle. Is there an easy way of using the classification browser to get some sort of facetted search? i.e the number of items inside a classification to display next to the classification itself.
Leave a comment
You must be logged in to post comments.
Sign in now
 
 
CATEGORIES
AnnouncementsDocMaker StudioEnginePageBuilderPIMSSales & MarketingSharePoint ConnectorWeb DevelopmentWebinarsWorkflow Studio
rss feed