ShowTable of Contents
The Clipboard API offers a simple way to write various data formats to the system clipboard.
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 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 complicated, but also much more 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]);
}
We are using these snippets in the "select file" and "select image" buttons to display file dialogs from server side JavaScript code.