org.openide.util.TaskListener Java Examples

The following examples show how to use org.openide.util.TaskListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomizerFrameworks.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates new form CustomizerFrameworks */
public CustomizerFrameworks(ProjectCustomizer.Category category, WebProjectProperties uiProperties) {
    this.category = category;
    this.uiProperties = uiProperties;
    initComponents();
    
    project = uiProperties.getProject();
    jListFrameworks.setModel(new DefaultListModel());
    ((DefaultListModel) jListFrameworks.getModel()).addElement(NbBundle.getMessage(CustomizerFrameworks.class, "LBL_CustomizerFrameworks_Loading"));
    // do not load frameworks again but use list from uiProperties; list is being loaded in background thread:
    uiProperties.getLoadingFrameworksTask().addTaskListener(new TaskListener() {
        public void taskFinished(Task task) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    initFrameworksList(project.getAPIWebModule());
                }
            });
        }
    });
    if (uiProperties.getLoadingFrameworksTask().isFinished()) {
        initFrameworksList(project.getAPIWebModule());
    }
}
 
Example #2
Source File: SaveEGTask.java    From BART with MIT License 6 votes vote down vote up
@Override
    public void save() throws IOException {
        dto = CentralLookup.getDefLookup().lookup(EGTaskDataObjectDataObject.class);
        final InputOutput io = IOProvider.getDefault().getIO(dto.getPrimaryFile().getName(), false);
        io.select();
        OutputWindow.openOutputWindowStream(io.getOut(), io.getErr());
        final Dialog d = BusyDialog.getBusyDialog();
        RequestProcessor.Task T = RequestProcessor.getDefault().post(new SaveEgtaskRunnable());
        T.addTaskListener(new TaskListener() {

            @Override
            public void taskFinished(Task task) {
//                d.setVisible(false);
                if(esito)   {
                    System.out.println(Bundle.MSG_SaveEGTask_OK(dto.getPrimaryFile().getName()));
                }else{
                    System.err.println(Bundle.MSG_SaveEGTask_Failed(dto.getPrimaryFile().getName()));                  
                }
                OutputWindow.closeOutputWindowStream(io.getOut(), io.getErr());
//                d.setVisible(false);
            }
            
        });
//        d.setVisible(true);
    }
 
Example #3
Source File: CheckCleanInstance.java    From BART with MIT License 6 votes vote down vote up
@Override
    public void actionPerformed(ActionEvent ev) {
        final Dialog d = BusyDialog.getBusyDialog();
        
        RequestProcessor.Task T = RequestProcessor.getDefault().post(new checkCleanRunnable());
        T.addTaskListener(new TaskListener() {

            @Override
            public void taskFinished(Task task) {
//                d.setVisible(false);
                if(esito)   {                
                    StatusBar.setStatus(Bundle.MSG_STATUS_Clean(), 10,5000);
                    DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                        Bundle.MSG_CheckCleanInstanceClean(), 
                        NotifyDescriptor.INFORMATION_MESSAGE));
                }else{
                    StatusBar.setStatus(Bundle.MSG_STATUS_Violated(), 10, 5000);
                    DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                            message.toString(), 
                            NotifyDescriptor.WARNING_MESSAGE));
                }
            }
        });
//        d.setVisible(true);
    }
 
Example #4
Source File: ImageCompress.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent ev) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            compress();
        }
    };
    
    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Compressing Image " + context.getPrimaryFile().getName(), theTask);
    
    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            NotificationDisplayer.getDefault().notify("Image compressed successfully", NotificationDisplayer.Priority.NORMAL.getIcon(), "The compression of the image was successful.", null);
            
            ph.finish();
        }
    });
    
    ph.start();
    theTask.schedule(0);

}
 
Example #5
Source File: Base64Decode.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent ev) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            decode();
        }
    };

    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Base64 Decoding Image " + context.getPrimaryFile().getName(), theTask);

    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
        }
    });

    ph.start();
    theTask.schedule(0);
}
 
Example #6
Source File: Base64Encode.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent ev) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            encode();
        }
    };
    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Base64 Encoding Image " + context.getPrimaryFile().getName(), theTask);
    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            NotificationDisplayer.getDefault().notify("Image encoded successfully", NotificationDisplayer.Priority.NORMAL.getIcon(), "The encoding of the image was successful.", null);
            
            ph.finish();
        }
    });

    ph.start();
    theTask.schedule(0);
}
 
Example #7
Source File: Minify.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent ev) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            minify();
        }
    };
    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Minifying JS , CSS and other WEB Content ", theTask);
    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
        }
    });
    ph.start();
    theTask.schedule(0);
}
 
Example #8
Source File: JSMinify.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
public static void execute(final DataObject context, final String content, final boolean notify) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            jsMinify(context, content, notify);
        }
    };

    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandle.createHandle("Minifying JS " + context.getPrimaryFile().getName(), theTask);

    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
        }
    });

    ph.start();
    theTask.schedule(0);
}
 
Example #9
Source File: XMLMinify.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
public static void execute(final DataObject context, final String content, final boolean notify) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            xmlMinify(context, content, notify);
        }
    };
    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Minifying XML " + context.getPrimaryFile().getName(), theTask);
    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
        }
    });
    ph.start();
    theTask.schedule(0);
}
 
Example #10
Source File: JSONMinify.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
public static void execute(final DataObject context, final String content, final boolean notify) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            jsonMinify(context, content, notify);
        }
    };
    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Minifying JSON " + context.getPrimaryFile().getName(), theTask);
    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
        }
    });
    ph.start();
    theTask.schedule(0);
}
 
Example #11
Source File: HTMLMinify.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
public static void execute(final DataObject context, final String content, final boolean notify) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            htmlMinify(context, content, notify);
        }
    };
    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Minifying HTML " + context.getPrimaryFile().getName(), theTask);
    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
        }
    });
    ph.start();
    theTask.schedule(0);
}
 
Example #12
Source File: CSSMinify.java    From minifierbeans with Apache License 2.0 6 votes vote down vote up
public static void execute(final DataObject context, final String content, final boolean notify) {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            cssMinify(context, content, notify);
        }
    };

    final RequestProcessor.Task theTask = RP.create(runnable);
    final ProgressHandle ph = ProgressHandleFactory.createHandle("Minifying CSS " + context.getPrimaryFile().getName(), theTask);

    theTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
        }
    });

    ph.start();
    theTask.schedule(0);
}
 
Example #13
Source File: JAXBDeleteSchemaAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void performAction(Node[] nodes) {
    JAXBWizardSchemaNode schemaNode = 
            nodes[0].getLookup().lookup(JAXBWizardSchemaNode.class);
    if (schemaNode != null){
        Schema schema = schemaNode.getSchema();
        final Project prj = schemaNode.getProject();
        ProjectHelper.deleteSchemaFromModel(prj, schema);
        ProjectHelper.cleanupLocalSchemaDir(prj, schema);
        ProjectHelper.cleanCompileXSDs(prj, false, new TaskListener() {
            
            @Override
            public void taskFinished( Task arg0 ) {
                ProjectHelper.checkAndDeregisterScript(prj);
            }
        });
    }        
}
 
Example #14
Source File: OptionsDisplayerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void setUpApplyChecker(final OptionsPanel optsPanel) {
final RequestProcessor.Task applyChecker = RP.post(new Runnable() {
    @Override
    public void run() {
               SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                       if (!savingInProgress) {
                           bAPPLY.setEnabled(optsPanel.isChanged() && optsPanel.dataValid());
                       }
                   }
               });
    }
});
applyChecker.addTaskListener(new TaskListener() {
    @Override
    public void taskFinished(Task task) {
	if (dialog != null) {
	    applyChecker.schedule(DELAY);
	}
    }
});
   }
 
Example #15
Source File: UnitTab.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void setEnabled (boolean enabled) {
    if (isEnabled () != enabled) {
        if (enabled) {
            RequestProcessor.Task t = PluginManagerUI.getRunningTask (new Runnable () {

                @Override
                public void run() {
                    setEnabled (true);
                }
            });
            if (t != null && ! t.isFinished ()) {
                t.addTaskListener (new TaskListener () {
                    @Override
                    public void taskFinished (org.openide.util.Task task) {
                        setEnabled (true);
                    }
                });
            } else {
                super.setEnabled (true);
            }
        } else {
            super.setEnabled (false);
        }
    }
}
 
Example #16
Source File: ProjectRunnerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private synchronized void setResult(final Union2<ExecutorTask,Throwable> result) {
    this.result = result;
    if (result.hasFirst()) {
        result.first().addTaskListener(new TaskListener() {
            @Override
            public void taskFinished(Task task) {
                callBack.get().run();
            }
        });
        if (stopped) {
            result.first().stop();
        }
    } else {
        callBack.get().run();
    }
    this.notifyAll();
}
 
Example #17
Source File: AutoupdateCheckScheduler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void scheduleRefreshProviders () {
    refreshUpdateCenters (null);
    final int delay = 500;
    final long startTime = System.currentTimeMillis ();
    RequestProcessor.Task t = Installer.RP.post (doCheckAvailableUpdates, delay);
    t.addTaskListener (new TaskListener () {
        @Override
        public void taskFinished (Task task) {
            task.removeTaskListener (this);
            long time = (System.currentTimeMillis () - startTime - delay) / 1000;
            if (time > 0) {
                Utilities.putTimeOfInitialization (time);
            }
        }
    });
}
 
Example #18
Source File: ReloadDependencies.java    From BART with MIT License 5 votes vote down vote up
@Override// closeDependencyViewTopComponent
    public void actionPerformed(ActionEvent ev) {
        if(dto == null || dto.getEgtask() == null)return;       
        if(textPanel.getText().isEmpty())return;
        if((egtask.getTarget() == null) || (egtask.getTarget() instanceof EmptyDB))   {
                DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                        Bundle.MSG_ReloadDependenciesNoDBTarget(), 
                        NotifyDescriptor.INFORMATION_MESSAGE));
            return;
        }   
        final InputOutput io = IOProvider.getDefault().getIO(dto.getPrimaryFile().getName(), false);
        io.select();
        OutputWindow.openOutputWindowStream(io.getOut(), io.getErr());
        final Dialog d = BusyDialog.getBusyDialog();
        RequestProcessor.Task T = RequestProcessor.getDefault().post(new reloadDependeciesRunnable());
        T.addTaskListener(new TaskListener() {
            @Override
            public void taskFinished(Task task) {
//                d.setVisible(false);
                if(esito)   {     
                    dto.setEgtModified(true);
                    StatusBar.setStatus(Bundle.MSG_ReloadDependenciesExecuted(), 10,5000);
                    System.out.println(Bundle.MSG_ReloadDependenciesExecuted());
                    DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                            Bundle.MSG_ReloadDependenciesExecuted(), 
                            NotifyDescriptor.INFORMATION_MESSAGE));
                }else{
                    System.err.println(Bundle.MSG_ReloadDependenciesException());
                    StatusBar.setStatus(Bundle.MSG_ReloadDependenciesExecuted(), 10,5000);
                }
                OutputWindow.closeOutputWindowStream(io.getOut(), io.getErr());
            }
        });
//        d.setVisible(true);
    }
 
Example #19
Source File: AntDebugger.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void setExecutor(ExecutorTask execTask) {
    this.execTask = execTask;
    if (execTask != null) {
        execTask.addTaskListener(new TaskListener() {
            @Override
            public void taskFinished(org.openide.util.Task task) {
                // The ANT task was finished
                finish();
            }
        });
    }
}
 
Example #20
Source File: Actions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void runTarget(FileObject scriptFile, String[] targetNameArray, Properties props, final ActionProgress listener) {
    try {
        ActionUtils.runTarget(scriptFile, targetNameArray, props).addTaskListener(new TaskListener() {
            @Override public void taskFinished(Task task) {
                listener.finished(((ExecutorTask) task).result() == 0);
            }
        });
    } catch (IOException e) {
        ErrorManager.getDefault().notify(e);
        listener.finished(false);
    }
}
 
Example #21
Source File: BIEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initialize() {
    if (!isInitialized) {
        setLayout(new BorderLayout());
        biPanel = new BiPanel();
        add(biPanel, BorderLayout.CENTER);
        isInitialized = true;
    } else {
        biPanel.setContext(new BiNode.Wait());
    }
    
    FileObject biFile = dataObject.getPrimaryFile();
    String name = biFile.getName();
    name = name.substring(0, name.length() - "BeanInfo".length()); // NOI18N
    FileObject javaFile = biFile.getParent().getFileObject(name, biFile.getExt());
    BIEditorSupport editor = findEditor(dataObject);
    if (javaFile != null) {
        final BeanInfoWorker beanInfoWorker = new GenerateBeanInfoAction.BeanInfoWorker(javaFile, biPanel);
        editor.worker = beanInfoWorker;
        beanInfoWorker.analyzePatterns().addTaskListener(new TaskListener() {

            public void taskFinished(Task task) {
                beanInfoWorker.updateUI();
            }
        });
    } else {
        // notify missing source file
        biPanel.setContext(BiNode.createNoSourceNode(biFile));
    }
}
 
Example #22
Source File: Manager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 */
private TaskListener getTaskListener() {
    if (taskListener == null) {
        taskListener = new MyTaskListener();
    }
    return taskListener;
}
 
Example #23
Source File: GenerateBeanInfoAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** This method is called by one of the "invokers" as a result of
* some user's action that should lead to actual "performing" of the action.
* This default implementation calls the assigned actionPerformer if it
* is not null otherwise the action is ignored.
*/
public void performAction ( final Node[] nodes ) {

    if (nodes.length != 1)
        return;

    // Open the diaog for bean info generation

    final BiPanel biPanel = new BiPanel();

    // Get pattern analyser & bean info and create BiAnalyser & BiNode

    FileObject javaFile = findFileObject(nodes[0]);
    final BeanInfoWorker performer = new BeanInfoWorker(javaFile, biPanel);
    
    class Task implements TaskListener, Runnable {

        public void taskFinished(org.openide.util.Task task) {
            EventQueue.invokeLater(this);
        }

        public void run() {
            if (performer.error != null) {
                DialogDisplayer.getDefault().notify(performer.error);
            }
            if (performer.bia != null) {
                performer.bia.openSource();
            }
        }
        
    }

    performer.analyzePatterns().addTaskListener(new Task());

}
 
Example #24
Source File: PropertiesEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected Task reloadDocument(){
    Task tsk = super.reloadDocument();
    tsk.addTaskListener(new TaskListener(){
        public void taskFinished(Task task){
            myEntry.getHandler().autoParse();
        }
    });
    return tsk;
}
 
Example #25
Source File: TestMethodDebuggerAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(final Node[] activatedNodes) {
    final Collection<? extends TestMethodDebuggerProvider> providers = Lookup.getDefault().lookupAll(TestMethodDebuggerProvider.class);
    RequestProcessor RP = new RequestProcessor("TestMethodDebuggerAction", 1, true);   // NOI18N
    debugMethodTask = RP.create(new Runnable() {
        @Override
        public void run() {
            for (TestMethodDebuggerProvider provider : providers) {
                if (provider.canHandle(activatedNodes[0])) {
                    debugMethodProvider = provider;
                    break;
                }
            }
        }
    });
    final ProgressHandle ph = ProgressHandleFactory.createHandle(Bundle.Search_For_Provider(), debugMethodTask);
    debugMethodTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(org.openide.util.Task task) {
            ph.finish();
            if (debugMethodProvider == null) {
                StatusDisplayer.getDefault().setStatusText(Bundle.No_Provider_Found());
            } else {
                debugMethodProvider.debugTestMethod(activatedNodes[0]);
            }
        }
    });
    ph.start();
    debugMethodTask.schedule(0);
}
 
Example #26
Source File: MavenCommandLineExecutor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ExecutorTask execute(RunConfig config, InputOutput io, TabContext tc) {
    LifecycleManager.getDefault().saveAll();
    MavenExecutor exec = new MavenCommandLineExecutor(config, io, tc);
    ExecutorTask task = ExecutionEngine.getDefault().execute(config.getTaskDisplayName(), exec, new ProxyNonSelectableInputOutput(exec.getInputOutput()));
    exec.setTask(task);
    task.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(Task t) {
            MavenProject mp = config.getMavenProject();
            if (mp == null) {
                return;
            }
            final List<Artifact> arts = new ArrayList<Artifact>();
            Artifact main = mp.getArtifact();
            if (main != null) {
                arts.add(main);
            }
            arts.addAll(mp.getArtifacts());
            UPDATE_INDEX_RP.post(new Runnable() {
                @Override
                public void run() {
                    RepositoryIndexer.updateIndexWithArtifacts(RepositoryPreferences.getInstance().getLocalRepository(), arts);
                }
            });
        }
    });
    return task;
}
 
Example #27
Source File: FolderInstance.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public HoldInstance (DataObject source, InstanceCookie cookie) {
    this.cookie = cookie;
    this.source = source;

    if (cookie instanceof Task) {
        // for example FolderInstance ;-) attach itself for changes
        // in the cookie
        Task t = (Task)cookie;
        t.addTaskListener(WeakListeners.create(TaskListener.class, this, t));
    }
}
 
Example #28
Source File: FindComponentModules.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Associates a listener with currently running computation.
 * One the results for {@link #getModulesForEnable()} and
 * {@link #getModulesForInstall()} is available, the listener 
 * will be called back.
 * 
 * @param l the listener which receives <code>this</code> as a task
 *   once the result is available
 */
public void onFinished(final TaskListener l) {
    findingTask.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(Task task) {
            l.taskFinished(FindComponentModules.this);
        }
    });
}
 
Example #29
Source File: ConfigurationPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private TaskListener onActivationFinished() {
    return (task) -> {
        if (!progressMonitor.error) {
            SwingUtilities.invokeLater(new Runnable() {
                private String msg;

                public void run() {
                    ConfigurationPanel.this.removeAll();
                    ConfigurationPanel.this.setLayout(new BorderLayout());
                    try {
                        ConfigurationPanel.this.add(callable.call(), BorderLayout.CENTER);
                    } catch (Exception ex) {
                        Exceptions.attachSeverity(ex, Level.INFO);
                        Exceptions.printStackTrace(ex);
                    }
                    ConfigurationPanel.this.invalidate();
                    ConfigurationPanel.this.revalidate();
                    ConfigurationPanel.this.repaint();
                    if (featureInfo != null && !featureInfo.isEnabled()) {
                        if (featureInfo.isPresent()) {
                            msg = NbBundle.getMessage(ConfigurationPanel.class, "MSG_EnableFailed");
                        } else {
                            msg = NbBundle.getMessage(ConfigurationPanel.class, "MSG_DownloadFailed");
                        }
                        progressMonitor.onError(msg);
                        return;
                    }
                    activateButton.setEnabled(true);
                    progressPanel.removeAll();
                    progressPanel.revalidate();
                    progressPanel.repaint();
                }
            });
        }
    };
}
 
Example #30
Source File: RequestProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Make sure that successfully canceled task is not performed.
 */
public void testCancel() throws Exception {
    class X implements Runnable {
        public boolean performed = false;
        public void run() {
            performed = true;
        }
    }
    
    X x = new X();
    final boolean[] finished = new boolean[1];
    finished[0] = false;
    
    // post task with some delay
    RequestProcessor.Task task = RequestProcessor.postRequest(x, 1000);
    task.addTaskListener(new TaskListener() {
        @Override
        public void taskFinished(Task t) {
            finished[0] = true;
        }
    });

    boolean canceled = task.cancel();
    assertTrue("Task is canceled now", canceled);
    assertTrue("Cancelling actually means finished", finished[0]);
    Thread.sleep(1500); // wait longer than task delay
    assertFalse("Task should not be performed", x.performed);
}