use of org.openide.util.RequestProcessor.Task in project netbeans-rcp-lite by outersky.
the class RunOffEDTImpl method runOffEventThreadCustomDialogImpl.
private void runOffEventThreadCustomDialogImpl(final Runnable operation, final String operationDescr, final JPanel contentPanel, int waitCursorAfter, int dialogAfter) {
if (waitCursorAfter < 0)
waitCursorAfter = 1000;
if (dialogAfter < 0)
dialogAfter = 2000;
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Dialog> d = new AtomicReference<Dialog>();
final AtomicReference<RequestProcessor.Task> t = new AtomicReference<RequestProcessor.Task>();
JDialog dialog = createModalDialog(operation, operationDescr, contentPanel, d, t, operation instanceof Cancellable);
final Task rt = TI_WORKER.post(new Runnable() {
@Override
public void run() {
try {
operation.run();
} finally {
latch.countDown();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Dialog dd = d.get();
if (dd != null) {
dd.setVisible(false);
dd.dispose();
}
}
});
}
}
});
t.set(rt);
Window window = null;
Component glassPane = null;
Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusOwner != null) {
window = SwingUtilities.getWindowAncestor(focusOwner);
if (window != null) {
RootPaneContainer root = (RootPaneContainer) SwingUtilities.getAncestorOfClass(RootPaneContainer.class, focusOwner);
glassPane = root.getGlassPane();
}
}
if (window == null || glassPane == null) {
window = WindowManager.getDefault().getMainWindow();
glassPane = ((JFrame) window).getGlassPane();
}
if (waitMomentarily(glassPane, null, waitCursorAfter, latch, window)) {
return;
}
Cursor wait = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
if (waitMomentarily(glassPane, wait, dialogAfter, latch, window)) {
return;
}
d.set(dialog);
if (EventQueue.isDispatchThread()) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
d.get().setVisible(true);
}
});
} else {
d.get().setVisible(true);
}
}
use of org.openide.util.RequestProcessor.Task in project netbeans-rcp-lite by outersky.
the class CommandEvaluator method evaluate.
/**
* Runs evaluation.
*
* @param command text to evauate, to search for
*
* @return task of this evaluation, which waits for all providers to complete
* execution. Use returned instance to recognize if this evaluation still
* runs and when it actually will finish.
*/
public static org.openide.util.Task evaluate(String command, ResultsModel model) {
List<CategoryResult> l = new ArrayList<CategoryResult>();
String[] commands = parseCommand(command);
SearchRequest sRequest = Accessor.DEFAULT.createRequest(commands[1], null);
List<Task> tasks = new ArrayList<Task>();
List<Category> provCats = new ArrayList<Category>();
boolean allResults = getProviderCategories(commands, provCats);
for (ProviderModel.Category curCat : provCats) {
CategoryResult catResult = new CategoryResult(curCat, allResults);
SearchResponse sResponse = Accessor.DEFAULT.createResponse(catResult, sRequest);
for (SearchProvider provider : curCat.getProviders()) {
Task t = runEvaluation(provider, sRequest, sResponse, curCat);
if (t != null) {
tasks.add(t);
}
}
l.add(catResult);
}
model.setContent(l);
return new Wait4AllTask(tasks);
}
use of org.openide.util.RequestProcessor.Task in project netbeans-rcp-lite by outersky.
the class JarFileSystem method freeReference.
private void freeReference() {
aliveCount--;
// Nobody uses this JarFileSystem => stop watcher, close JarFile and throw away cache.
if (aliveCount == 0) {
Task w = watcherTask;
if (w != null) {
w.cancel();
watcherTask = null;
}
// no more active FO, keep only soft ref
strongCache = null;
closeCurrentRoot(false);
}
}
use of org.openide.util.RequestProcessor.Task in project netbeans-rcp-lite by outersky.
the class UnitTab method addNotify.
@Override
public void addNotify() {
super.addNotify();
if (dlForSearch == null) {
tfSearch.getDocument().addDocumentListener(getDocumentListener());
}
if (flForSearch == null) {
flForSearch = new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
tfSearch.selectAll();
}
@Override
public void focusLost(FocusEvent e) {
tfSearch.select(0, 0);
}
};
tfSearch.addFocusListener(flForSearch);
}
RequestProcessor.Task runningTask = PluginManagerUI.getRunningTask(new Runnable() {
@Override
public void run() {
if (isWaitingForExternal) {
reloadTask(false).schedule(10);
isWaitingForExternal = false;
}
}
});
synchronized (this) {
if (runningTask != null && !runningTask.isFinished() && !isWaitingForExternal) {
isWaitingForExternal = true;
runningTask.addTaskListener(new TaskListener() {
@Override
public void taskFinished(org.openide.util.Task task) {
if (isWaitingForExternal) {
reloadTask(false).schedule(10);
}
isWaitingForExternal = false;
}
});
}
}
}
Aggregations