See Thread at:
http://www.techienuggets.com/Detail?tx=16855 Posted on behalf of a User
You can:
1. execute registered action:
ApplicationAction a = (ApplicationAction) getContext().getActionMap().get("copy");
a.actionPerformed(new ActionEvent(this,0,""));
2. or directly execute task:
getContext().getTaskService().execute(new PozdrowieniaZLublinaTask(getApplication()));
In Response To:
I know this isn't the correct place to ask this, but I've gotten introduced
to the topic via NB6 and the template for a Java Desktop Application and
using the 'Set Action' technique to create a background task. I've searched
online but documentation and examples for the framework are very scarce.
I've successfully (and easily) created background tasks with this method in
Netbeans,but I have a situation where I want to execute a background task
,using this method,from a list value changed event. The code I have will
start the task (ie do the create method), but the 'doInBackground' never
executes;
private void
fileListValueChanged(javax.swing.event.ListSelectionEventevt) {
loadFile();
}
@Action
public Task loadFile() {
return new LoadFileTask(
org.jdesktop.application.Application.getInstance(
summaryreader.SummaryReaderApp.class));
}
private class LoadFileTask extends org.jdesktop.application.Task<Object,
Void> {
private String fileToLoad;
LoadFileTask(org.jdesktop.application.Application app) {
// Runs on the EDT. Copy GUI state that
// doInBackground() depends on from parameters
// to SendEmailTaskTask fields, here.
super(app);
System.out.println("Starting thread to load file..." +
fileToLoad);
}
@Override protected Object doInBackground() {
System.out.println("Got to background method");
}
@Override protected void succeeded(Object result) {
System.out.println("Succeeded");
}
@Override protected void failed(Throwable e) {
System.out.println("Failed to open " + fileToLoad);
}
}
However,if i attach the action to, eg a button, everything works fine. I'm
obviously missing some part of the framework to register and fire the action
in code. Would be grateful if anyone could advise.
Chris.