It seems like a general Java question on how to make some object accessible by other objects. Obviously, you need to store it in a place, where it can be accessed by others (provide a getter, put to the registry, store to the DB, serialize to the hard drive, etc). There are many design patterns to solve your problem, so no ideal answer can be provided.
You can't, probably use getters, because as you mentioned Handler is created at the time menu is executed. I think that handler is not recreated each time, but only on first access, so you could make an instance variable in the handler, but this doesn't seem right.
Storing to a DB and serialization is probably way too overkill at this stage for you, so I would suggest you to put object to the registry, using Registry pattern (think of it as a global cache). So, here is what you could do:
public class DocumentsRegistry {
private Map<String, RecordingDocument> registry = new HashMap<String, RecordingDocument>();
private static DocumentRegistry instace = new DocumentRegistry();
public static DocumentRegistry getInstance() {
return instance;
}
public void registerDocument(String key, RecordingDocument document) {
registry.put(key, document);
}
public RecordingDocument getDocument(String key) {
return registry.get(key);
}
}
// your handler
public static final String DOCUMENT_KEY = "DOCUMENT";
public Object execute(ExecutionEvent event) throws ExecutionException {
IHandlerService service;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
try {
RecordingDocument d = new RecordingDocument("TestProject", "Tester", true);
d.record();
MessageDialog.openInformation(
window.getShell(),
"JavaTV",
"You are now recording.");
DocumentsRegistry.getInstance().registerDocument(DOCUMENT_KEY, d);
} catch (CoreException e) {
e.printStackTrace();
}
return null;
}
// another handler
public Object execute(ExecutionEvent event) throws ExecutionException {
RecordingDocument d = DocumentsRegistry.getInstance().getDocument(DOCUMENT_KEY);
// do something with it
return null;
}
If you want to support concurrent recordings, so that many documents can be opened at the same time, you would need a solution for generating keys per document.