Search in sources :

Example 1 with Task

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);
    }
}
Also used : FutureTask(java.util.concurrent.FutureTask) Task(org.openide.util.RequestProcessor.Task) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ProgressRunnable(org.netbeans.api.progress.ProgressRunnable)

Example 2 with Task

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);
}
Also used : SearchRequest(org.netbeans.spi.quicksearch.SearchRequest) Task(org.openide.util.RequestProcessor.Task) Category(org.netbeans.modules.quicksearch.ProviderModel.Category) ArrayList(java.util.ArrayList) SearchProvider(org.netbeans.spi.quicksearch.SearchProvider) Category(org.netbeans.modules.quicksearch.ProviderModel.Category) SearchResponse(org.netbeans.spi.quicksearch.SearchResponse)

Example 3 with Task

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);
    }
}
Also used : Task(org.openide.util.RequestProcessor.Task)

Example 4 with Task

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;
                }
            });
        }
    }
}
Also used : TaskListener(org.openide.util.TaskListener) Task(org.openide.util.RequestProcessor.Task) FocusListener(java.awt.event.FocusListener) FocusEvent(java.awt.event.FocusEvent) RequestProcessor(org.openide.util.RequestProcessor)

Aggregations

Task (org.openide.util.RequestProcessor.Task)4 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 FutureTask (java.util.concurrent.FutureTask)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ProgressRunnable (org.netbeans.api.progress.ProgressRunnable)1 Category (org.netbeans.modules.quicksearch.ProviderModel.Category)1 SearchProvider (org.netbeans.spi.quicksearch.SearchProvider)1 SearchRequest (org.netbeans.spi.quicksearch.SearchRequest)1 SearchResponse (org.netbeans.spi.quicksearch.SearchResponse)1 RequestProcessor (org.openide.util.RequestProcessor)1 TaskListener (org.openide.util.TaskListener)1