Sunday, 15 April 2012

java - Copy files from filesystem to a project and correctly manage the progress monitor -



java - Copy files from filesystem to a project and correctly manage the progress monitor -

i trying modify that reply needs , create progress monitor reflect progress correctly. approach till now:

import org.eclipse.core.runtime.subprogressmonitor; private void configureproject(iprogressmonitor monitor) throws coreexception, ioexception { seek { url templatesurl = activator.getdefault().getbundle().getentry(templates); file templatesfolder = new file(filelocator.tofileurl(templatesurl).getpath()); int filecount = getelementscount(templatesfolder); monitor.begintask("creating file construction new project...", filecount + 5); project.getfolder(p_src).delete(true, new subprogressmonitor(monitor, 1)); project.getfolder(p_bin).delete(true, new subprogressmonitor(monitor, 1)); copyfiles(templatesfolder, project, new subprogressmonitor(monitor, filecount)); project.getfile(p_touch).delete(true, new subprogressmonitor(monitor, 1)); iclasspathentry[] newentries = new iclasspathentry[3]; newentries[0] = javacore.newsourceentry(getcreatedelement().getpath().append(src_main)); newentries[1] = javacore.newsourceentry(getcreatedelement().getpath().append(src_res), exclude_all); newentries[2] = javacore.newsourceentry(getcreatedelement().getpath().append(src_test)); javaproject.setrawclasspath(newentries, new subprogressmonitor(monitor, 2)); } { if (!monitor.iscanceled()) monitor.done(); } } private int getelementscount(file file) { // homecoming number of files , folders in file }

as see have 3 ticks delete operations , 2 setting classpath. 5 plus count of files in source folder, if say: 1 tick per file or folder. have problem method copyfiles. modified related code work iprogressmonitor:

private void copyfiles(file srcfolder, icontainer destfolder, iprogressmonitor monitor) throws coreexception, ioexception { (file f : srcfolder.listfiles()) { if (f.isdirectory()) { ifolder newfolder = destfolder.getfolder(new path(f.getname())); newfolder.create(true, true, new subprogressmonitor(monitor, 1)); copyfiles(f, newfolder, monitor); } else { newfile.create(new fileinputstream(f), true, new subprogressmonitor(monitor, 1)); } } }

as 1 of methods create(...) called (either on ifile or on ifolder) progress bar should moved 1 tick. doesn't move @ all. reason , how solve problem?

upd: modified method configureproject follows:

subprogressmonitor copyfilesmonitor = new subprogressmonitor(monitor, filecount); copyfilesmonitor.begintask("copying files...", filecount); copyfiles(templatesfolder, project, copyfilesmonitor); copyfilesmonitor.done();

now problem after invocation of create() (either on ifolder or on ifile) progressbar set 2/3 - 2 ticks. 2/3 designated whole configureproject() method , lastly 2 ticks made setrawclasspath(...) yet.

before:

after:

you need phone call begintask (and done) on new subprogressmonitor(monitor, filecount) creating copyfiles method.

if don't phone call begintask worked calls ignored.

java eclipse eclipse-plugin progressmonitor

No comments:

Post a Comment