use of org.csstudio.logbook.Attachment in project org.csstudio.display.builder by kasemir.
the class SendToElogAction method createImageAttachment.
/**
* @return Logbook attachment for the plot's image
* @throws Exception
* on error
*/
private Attachment createImageAttachment() throws Exception {
// Dump image into buffer
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { ImageConverter.convertToSWT(graph.getImage()) };
ByteArrayOutputStream buf = new ByteArrayOutputStream();
loader.save(buf, SWT.IMAGE_PNG);
buf.close();
final byte[] image_bits = buf.toByteArray();
buf = null;
loader = null;
// Attachment provides input stream
return new Attachment() {
@Override
public Boolean getThumbnail() {
return true;
}
@Override
public InputStream getInputStream() {
try {
return new ByteArrayInputStream(image_bits);
} catch (Exception ex) {
return null;
}
}
@Override
public Long getFileSize() {
return (long) image_bits.length;
}
@Override
public String getFileName() {
return "plot.png";
}
@Override
public String getContentType() {
return "image/png";
}
};
}
use of org.csstudio.logbook.Attachment in project org.csstudio.display.builder by kasemir.
the class SendToElogAction method makeLogEntry.
/**
* Make a logbook entry.
*/
public void makeLogEntry() {
try {
final Attachment image_attachment = createImageAttachment();
final String text = Messages.LogentryDefaultTitle + "\n" + Messages.LogentryDefaultBody;
final LogEntryBuilder entry = LogEntryBuilder.withText(text).attach(AttachmentBuilder.attachment(image_attachment));
// get the command from plugin.xml
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
List<LogEntryBuilder> logList = new ArrayList<LogEntryBuilder>();
logList.add(entry);
Event event = new Event();
event.data = logList;
// execute the command
IHandlerService handlerService = window.getService(IHandlerService.class);
handlerService.executeCommand(OPEN_LOGENTRY_BUILDER_DIALOG_ID, event);
} catch (Exception e) {
MessageDialog.openError(null, "Logbook Error", "Failed to make logbook entry: \n" + e.getMessage());
}
}
Aggregations