Search in sources :

Example 1 with ParsedAnyData

use of alma.acs.eventbrowser.parts.ParsedAnyData in project ACS by ACS-Community.

the class CopyDetailsToClipboardHandler method execute.

/**
	 * Receives the selection from the event detail part.
	 * <p>
	 * It may be my lack of understanding of good Eclipse 4 RCP practices that I wish
	 * I could handle the mouse menu action locally in the event detail part,
	 * instead of sending the data via selection service to separate handler.
	 * Perhaps to be refactored once this becomes clearer. 
	 */
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) ParsedAnyData[] parsedAnyData) throws ExecutionException {
    if (parsedAnyData == null || parsedAnyData.length == 0) {
        return;
    }
    System.out.println("Will copy event details to the clipboard...");
    // Convert selected table rows into a multi-line String
    StringBuilder sb = new StringBuilder();
    for (ParsedAnyData parsedAny : parsedAnyData) {
        sb.append(parsedAnyDataToString(parsedAny));
    }
    // Write that data to the system clipboard
    Clipboard cb = new Clipboard(Display.getCurrent());
    TextTransfer textTransfer = TextTransfer.getInstance();
    cb.setContents(new Object[] { sb.toString() }, new Transfer[] { textTransfer });
    cb.dispose();
}
Also used : ParsedAnyData(alma.acs.eventbrowser.parts.ParsedAnyData) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Aggregations

ParsedAnyData (alma.acs.eventbrowser.parts.ParsedAnyData)1 CanExecute (org.eclipse.e4.core.di.annotations.CanExecute)1 Execute (org.eclipse.e4.core.di.annotations.Execute)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1