Improve Foudations Improve Technologies Improve Community Improve Institute

Eclipse RCP and OneNote

Eclipse is able to talk with OneNote...


Demonstration

Snippet

Here is a snippet to connect SWT and OneNote :

import java.io.IOException;
 
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.HTMLTransfer;
import org.eclipse.swt.dnd.RTFTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
 
 
public class OneNoteCopyPaste {
	private static final String PASTE_CMD = " /paste";
	private static final String ONENOTE_PATH = "C:/Program Files/Microsoft Office/OFFICE11/onenote.exe";
 
	public static void main (String [] args) {
		final Display display = new Display ();
		Shell shell = new Shell (display);
		Label label = new Label (shell, SWT.NONE);
		label.setText ("Enter your name:");
		final Text text = new Text (shell, SWT.BORDER);
		text.setLayoutData (new RowData (100, SWT.DEFAULT));
		Button ok = new Button (shell, SWT.PUSH);
		ok.setText ("OK");
		ok.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				Clipboard cb = new Clipboard(display);
 
				String textData = text.getText();
			 	String rtfData = "{\\rtf1\\b\\i " + textData + "}";
			 	String htmlData = "<html><body>" + textData+  "</body></html>";
 
			 	TextTransfer textTransfer = TextTransfer.getInstance();
			 	RTFTransfer rtfTransfer = RTFTransfer.getInstance();
			 	HTMLTransfer htmlTransfer = HTMLTransfer.getInstance();
			 	Transfer[] transfers = new Transfer[]{textTransfer, rtfTransfer, htmlTransfer};
			 	Object[] data = new Object[]{textData, rtfData, htmlData};
			 	cb.setContents(data, transfers);
			try {
				Runtime.getRuntime().exec(ONENOTE_PATH + PASTE_CMD);
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
			finally {
				cb.dispose();
			}
 
			}
		});
		Button cancel = new Button (shell, SWT.PUSH);
		cancel.setText ("Cancel");
		cancel.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				System.out.println("Cancel");
			}
		});
		shell.setDefaultButton (cancel);
		shell.setLayout (new RowLayout ());
		shell.pack ();
		shell.open ();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}
 
 
moni/trucs/eclipse_rcp_and_onenote.txt · Last modified: 2006/05/03 18:14 by dgirard