Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 向RCP中的作业添加进度条_Java_Eclipse Plugin_Eclipse Rcp_Rcp_Jobs - Fatal编程技术网

Java 向RCP中的作业添加进度条

Java 向RCP中的作业添加进度条,java,eclipse-plugin,eclipse-rcp,rcp,jobs,Java,Eclipse Plugin,Eclipse Rcp,Rcp,Jobs,在我的RCp应用程序中,我有一项非常耗时的工作,在这项工作中,我读取一个大数据库并将其保存在一个文件中。我正在一个单独的线程中运行此作业,以便我的应用程序的UI不会被阻止,但我不知道如何将进度条添加到此任务 我的代码: public class MirrorFeatureModel extends Job { protected class MutexRule implements ISchedulingRule { public boolean isConflicting(ISche

在我的RCp应用程序中,我有一项非常耗时的工作,在这项工作中,我读取一个大数据库并将其保存在一个文件中。我正在一个单独的线程中运行此作业,以便我的应用程序的UI不会被阻止,但我不知道如何将进度条添加到此任务

我的代码:

public class MirrorFeatureModel extends Job {

protected class MutexRule implements ISchedulingRule {
    public boolean isConflicting(ISchedulingRule rule) {
         return rule == this;
      }
    public boolean contains(ISchedulingRule rule) {
         return rule == this;
      }
}

private String source;
private String template;
private String target;

public MirrorFeatureModel(String name) {
    super(name);
}

public MirrorFeatureModel(String source, String template, String target){
    super("Mirroring SWA Model");
    this.source = source;
    this.template = template;
    this.target = target;
}

public void run() {
    this.schedule();
}


@Override
protected IStatus run(IProgressMonitor monitor)  {

    ILog logView = Activator.getDefault().getLog();
    String connectionString = this.source;
    String emptyEAP = this.template;
    String target = this.target;

    try{

        monitor.beginTask("Copying swa model to local", 1);
        new Mirror(connectionString, emptyEAP,target).run();
        monitor.worked(1);

    }catch(final Exception e) {

        logView.log(new Status(Status.ERROR, null , "Failed to create local SAM instance", e));         


        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Failed to create local SAM instance", e.getMessage());
            }

        });
        return Status.CANCEL_STATUS;
    }       

    return Status.OK_STATUS;
  }


}
run()方法

公共作废运行(IProgressMonitor){
试一试{
如果(监视器!=null)
子任务(“为eap文件创建目录”);
File testarget=File.createTempFile(“eap镜像”、“eap”);
如果(监视器!=null)
监测工作(1);
试一试{
如果(监视器!=null)
监控子任务(“建立连接”);
this.source=DriverManager.getConnection(com.intel.imc.swa.easql.EaDbStringParser.eaDbStringToJdbc(sourceString));
this.source.setReadOnly(true);
如果(监视器!=null)
监测工作(1);
copyFile(新文件(templateFileString),testarget);
如果(监视器!=null)
子任务(“打开数据库”);
this.target=Database.open(testarget,false,false);
如果(监视器!=null)
监测工作(1);
如果(监视器!=null)
子任务(“镜像表”);
收集表=selectTables(源);
长时间=System.currentTimeMillis();
for(字符串tableName:tables){
long tTime=System.currentTimeMillis();
Table=target.getTable(tableName);
系统输出打印(“镜像表”+表名+”);
表.setOverrideAutonNumber(真);
copyTable(表、源、目标);
System.out.println(“take”+(System.currentTimeMillis()-tTime));
}
System.out.println(“完成.总时间:”+(System.currentTimeMillis()-time));
如果(监视器!=null)
监测工作(1);
}捕获(SQLE异常){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
}
如何在此类中添加进度条以显示此作业的进度


谢谢

通常,作业会在进度视图和主窗口底部的状态行中显示进度指示器

如果在
schedule()
之前调用
setUser(true)
,则如果作业运行超过几秒钟,作业将显示弹出的进度对话框

要显示作业进度,必须在
beginTask
调用中指定总工作量

monitor.beginTask("...", total work);

然后,每次完成部分工作时,必须调用monitor.worked(xxx)。

底部显示进度,但即使作业正在运行,也始终为0%SetUser()现在显示进度对话框,但没有显示已完成工作的百分比。我怎么做?您必须使用monitor.beginTask说明将完成多少工作,然后致电monitor.worked更新进度-添加到回答如果您没有任何关于进度的信息,则无法神奇地报告进度
beginTask
call仍在为总工时指定1-它必须是您将要进行的所有
worked(n)
调用的总和。
monitor.beginTask("...", total work);