ShowTable of Contents
The Clipboard API offers a simple way to write various data formats to the system clipboard. This article demonstrates some of the available methods and their syntax.
For a complete reference, please refer to the
XPages2Eclipse Base API Javadocs.
Access to API
You can get access to this API by getting a new instance of
IRemoteClipboardAccess from the ClipboardAPI
factory class:
var conn=X2E.createConnection();
var clipboardAccess=x2e.ClipboardAPI.getClipboardAccess(conn);
This instance has methods to write plain text, a file and an image to the clipboard:
clipboardAccess.setTextContent("Hello world!");
clipboardAccess.setFileContent("c:\temp\archiv.zip");
clipboardAccess.setImageContent("c:\temp\image.png");
XPages2Eclipse uses the Eclipse class
org.eclipse.swt.graphics.Image
internally to load the image. This class supports the file formats BMP, ICO, JPEG, GIF, png and TIFF.
Sample application
Our sample application lets you enter text or select files and images which can then be copied to the clipboard with a button click.
The file and image selection actions are leveraging the IRemoteFileDialogTools
that are available from the IRemotePlatformUI
class.
To select a file, we are using a pretty simple syntax, because any file can be selected:
var conn=X2E.createConnection();
var platformUI=x2e.PlatformUIAPI.getUI(conn);
var fdTools=platformUI.getFileDialogTools();
var selPath=fdTools.showFileOpenDialog();
if (selPath) {
getComponent("filePath").setValue(selPath);
}
The image selection uses a more advanced and powerful call syntax:
var conn=X2E.createConnection();
var platformUI=x2e.PlatformUIAPI.getUI(conn);
var fdTools=platformUI.getFileDialogTools();
var filterNames=["All images", "All files"];
var filterExt=["*.jpg;*.jpeg;*.png;*.gif", "*.*"];
var filterIndex=0;
var filterPath=null;
var fileName=null;
var overwrite=false;
var dlgText=null;
//use bitmask OPEN+SINGLE (4096+4) for selection type
var selPath=fdTools.showFileDialog(4096+4, filterNames, filterExt, filterIndex, filterPath, fileName, overwrite, dlgText);
if (selPath && selPath.length>0) {
//method returns an array of paths even for single selection
getComponent("imagePath").setValue(selPath[0]);
}
These code snippets are executed in the onClick events of the "select file" and "select image" buttons to display file dialogs from server side JavaScript code, write the path of the selected files in a UI field and do a partial or full refresh of the XPage to display the path to the user.
Please note that the sample code increases the