Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.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:显示进度监视器和子进度监视器的进度_Java_Eclipse_Monitor_Progress - Fatal编程技术网

Java:显示进度监视器和子进度监视器的进度

Java:显示进度监视器和子进度监视器的进度,java,eclipse,monitor,progress,Java,Eclipse,Monitor,Progress,嗨,我实现了“org.eclipse.core.runtime”的IProgressMonitor和SubgressMonitor。进度监视器正在工作,但我的问题是它没有像我希望的那样显示进度。在完成之前,它不会显示任何进展。我会给你的代码样本 try { PlatformUI.getWorkbench().getProgressService(). busyCursorWhile(new IRunnableWithProgress() {

嗨,我实现了“org.eclipse.core.runtime”的IProgressMonitor和SubgressMonitor。进度监视器正在工作,但我的问题是它没有像我希望的那样显示进度。在完成之前,它不会显示任何进展。我会给你的代码样本

    try {
            PlatformUI.getWorkbench().getProgressService().
            busyCursorWhile(new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException,
                        InterruptedException {
                    // TODO Auto-generated method stub
                    try{

                        monitor.beginTask("Operation in Progress...", ticks);

                        for(int i = 0;  i < getCompilationUnit().size(); i++){

                            try {
                                IType type = getCompilationUnit().get(i).findPrimaryType();

                                IType[] types = getCompilationUnit().get(i).getTypes();

                                if(monitor.isCanceled())
                                    throw new OperationCanceledException();

                                updateListPrimaryType(type, totalNumberOfCode, types);
                                monitor.worked(1/ticks);

                                IMethod[] method = type.getMethods();
                                int work = method.length;
                                updateListIMethod(method);
                                monitor.worked(1/ticks);

                                updateListMethodAttributeMember(type,new SubProgressMonitor(monitor, (1/ticks)));           
                                updateListMember(type,types);
                                monitor.worked(1/ticks);

                            } catch (JavaModelException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }

                    }finally{
                        monitor.done();
                    }
                }
            });
试试看{
PlatformUI.getWorkbench().getProgressService()。
busyCursorWhile(新iRunTableWithProgress(){
@凌驾
公共无效运行(IProgressMonitor监视器)引发InvocationTargetException,
中断异常{
//TODO自动生成的方法存根
试一试{
monitor.beginTask(“正在进行的操作…”,滴答声);
对于(int i=0;i
这是updateListMethodAttributeMember方法的代码:

  private void updateListMethodAttributeMember(IType type,SubProgressMonitor subProgressMonitor) {
    // TODO Auto-generated method stub      
    ClassList tmp;
    try{

        IMethod[] method = type.getMethods();
        IField[] field = type.getFields();

        subProgressMonitor.beginTask("Operation in Progress...", method.length);
        for(int m = 0; m < method.length; m++){
            String methodName = getSubstringName(method[m].toString());

            IMethod met = method[m];
            tmp = new ClassList(className, methodName, path);

            if(!met.isConstructor() || !met.isMainMethod()){
                try {
                    int number = performIMethodSearch(met);
                    tmp.setNumberOfCalls(number);
                } catch (CoreException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            subProgressMonitor.worked(1/method.length);
            getMethodClassList().add(tmp);
        }

        for(int f = 0; f < field.length; f++){
            String attributeName = getSubstringName(field[f].toString());
            tmp = new ClassList(className, attributeName, path);
            String parent = field[f].getParent().getElementName().toString();
            String description = "Parent Class: " + parent;
            tmp.setDataDescription(description);
            getAttributeClassList().add(tmp);
        }

    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }finally{
        subProgressMonitor.done();
    }
}
private void updateListMethodAttributeMember(IType类型,subgressMonitor subgressMonitor){
//TODO自动生成的方法存根
类列表tmp;
试一试{
IMethod[]method=type.getMethods();
IField[]field=type.getFields();
SubgressMonitor.beginTask(“正在进行的操作…”,方法.长度);
for(int m=0;m
worked()方法将整数作为工作单位数。看起来您正在传入一个四舍五入为0的浮点值,因此不会更改进度条。将worked()调用更改为pass in 1,您应该会看到正确的进度。

worked()方法方法将整数作为工作单位数。看起来您正在传入一个四舍五入为0的浮点值,因此不会对进度条进行任何更改。将worked()调用更改为pass in 1,您应该会看到正确的进度。

事实上,进度监视器会为您计算。您会告诉它有多少个“滴答声”有,然后通过调用worked()来“勾选它们”。千万不要在编写代码时期望使用SubgressMonitor,它只是在父进度监视器中抽象出对多个勾号的处理,同时使自己看起来有不同的勾号(例如,parent有5个刻度,SubgressMonitor被传递给您的方法来处理其中的1个,但它本身的行为就像它在传递给的方法中处理10个刻度)。只需开始/结束传入的IProgressMonitor或进一步传递它。事实上,进度监视器为您计算。您告诉它有多少个“刻度”,然后通过调用worked()来“勾选它们”。千万不要在编写代码时期望使用SubgressMonitor,它只是在父进程监视器中抽象出对多个勾选的处理,同时使自己看起来有不同的勾选数(例如,父级有5个记号,SubgressMonitor被传递给您的方法以处理其中1个记号,但其本身的行为就像它在传递给的方法中处理10个记号一样)。只需开始/结束传入的IProgressMonitor或进一步传递它即可。