Documentation

Advanced Folder Custom Filter Definition


What is a custom folder filter?
The Custom Filter field allows you to define custom JavaScript methods that can be called by IntelliCabinet for you to determine whether to filter a row. You can also perform on the fly edits to cell formats, such as background colors. Review the Java scripting programmers guide online if you are not familiar with the Java scripting api.
How to define a custom folder filter that interacts with the built in filter panel


The following functions must be defined, as shown in the JavaScript example below. The hasCustomPanel() function is called by IntelliCabinet when the folder filter toggle is turned on. This tells IntelliCabinet whether you have defined a custom JPanel for the user to enter filter criteria within or not. If not, the built in filter panel is displayed. When interacting with the built in filter panel you must include a function called isColumnMatch(ColumnName, ColumnType, FilterCriteria, RenderedText), as shown below showing 4 received arguments, ColumName which represents the name of the column, the ColumnType which represents the cell column's data type, the FilterCriteria which represents what the user entered in the built in filter criteria field, and the RenderedText which represents the cell's rendered text. The isColumnMatch function must return true or false for whether to display the row (true) or not (false). IntelliCabinet will already determine whether the built in folder filter Columns are a match or not.

Example JavaScript:

//
function hasCustomPanel()  {

	return false;
}
//
function isColumnMatch(ColumnName, ColumnType, FilterCriteria, RenderedText) {
	
	return (RenderedText.search(FilterCriteria)  != -1);
}


How to define a custom folder filter panel for displaying your own custom filter criteria


The following functions must be defined, as shown below. The hasCustomPanel() function is called by IntelliCabinet when the folder filter toggle is turned on. This tells IntelliCabinet whether you have defined a custom JPanel for the user to enter filter criteria within or not. When true, you must include a function called getCustomPanel() that returns a JPanel as shown in the JavaScript code below. To trigger the filtering of the folder's rows you would call the function FILTER.update() as shown below. When the update function is called you must have a function in the JavaScript code for IntelliCabinet to call defined as isRowMatch(TypeHash, RenderedHash, ValuesHash, FormatHash, TalkbackHash), as shown below showing 5 received arguments TypeHash which represents a <String, String> Hashtable containing the folders column names as keys and their column type as values, the RenderedHash which represents a <String, String> Hashtable containing the column names as keys and their rendered text displayed as values, the ValuesHash which represents a <String, String> Hashtable containing the column names as keys and their cell stored values as values, the FormatHash which represents a <String, Hashtable<String, String>> Hashtable containing the column names as keys and a Hashtable of the cells defined formatting keys and current settings as its values, the TalkbackHash which represents a <String, String> Hashtable that you must define when modifying a cells formatting. This Hashtable tells IntelliCabinet that you have modified a cells format and which Column and Formatting you have modified - see the example code below for how this must be defined. Available formatting includes - background [html hex color code], foreground [html hex color code], left_indent [integer, values of 10 for best results], right_indent [integer, values of 10 for best results], and style [bold, italic, plain].

Example JavaScript:
This example defines a Custom Java JPanel that has 1 field that when typed in checks the folder's name column for matching text. If a match is found it changes the background color, if no match is found it changes the background color to blank for the default color. The isRowMatch function returns true to tell IntelliCabinet to keep the row visible.

// Available variables
// CAB_PROP_HASH
// Hashtable<String, String> containing the active cabinet's properties, read only via get method

// FILTER
// Triggers filtering on the active folder via the FILTER.update() method

// ROW_COUNT
// The total number of rows

// Java Packages
importPackage(java.awt);
importPackage(javax.swing);

// Create custom form
var FilterPanel = new JPanel();
FilterPanel.getLayout().setAlignment(FlowLayout.LEFT);
var UserNameLabel = new JLabel("Name");
UserNameLabel.setForeground(Color.blue);
FilterPanel.add(UserNameLabel);

// Add Text Field
var UserNameField = new JTextField();
UserNameField.addKeyListener(new java.awt.event.KeyListener()  {
	keyPressed:  function(e) {

	},
	keyReleased:  function(e)  {
		
		// Update filter
		FILTER.update();
	},
	keyTyped:  function(e)  {

	}	
});
UserNameField.setPreferredSize(new Dimension(100,25));
FilterPanel.add(UserNameField);

// It is best practice to have a button trigger the filter updating method to avoid overlapping updates
var FolderItemSearchButton = new JButton("Apply");
FolderItemSearchButton.addActionListener(new java.awt.event.ActionListener() {
	actionPerformed: function(e) {
		
		FILTER.update();
	}		
});
FilterPanel.add(FolderItemSearchButton);



// Required functions

// 
function hasCustomPanel()  {

	return true;
}

//
function getCustomPanel()  {

	return FilterPanel;
}

//
function isRowMatch(TypeHash, RenderedHash, ValuesHash, FormatHash, TalkbackHash)  {
	
	// 'Column Name;format', 'background'
	TalkbackHash.put('Name;format', 'background');
	
	//
	if (RenderedHash.get('Name').search(UserNameField.getText())  != -1) {
		FormatHash.get('Name').put('background', '#F5F5F5');
	} else {
		FormatHash.get('Name').put('background', '');
	}

	return true;
}