java - Programmaitcally adding nature to existing project -



java - Programmaitcally adding nature to existing project -

when adjust project nature of running project

workspacejob job = new workspacejob("addingnature") { @override public istatus runinworkspace(iprogressmonitor monitor) throws coreexception { seek { iprojectdescription description = activeproject .getdescription(); string[] prevnatures = description.getnatureids(); string[] newnatures = new string[prevnatures.length + 1]; system.arraycopy(prevnatures, 0, newnatures, 0, prevnatures.length); newnatures[prevnatures.length] = id; description.setnatureids(newnatures); activeproject.setdescription(description, new nullprogressmonitor()); homecoming status.ok_status; } grab (coreexception e) { logger.log(level.severe, warning_nature_fail, e.getmessage()); homecoming status.cancel_status; } } job.schedule()

i error " resource tree locked modifications." exception stack trace not available.

i thought schuduling should avoid resource tree beingness locked. can prevent this?, there other way add together natures / convert projects

this code called menuitem using class extends abstracthandler.

problem size of array string[] newnatures.

try this:

public static void addprojectnature(iproject project, string natureid, boolean addfirst) { seek { iprojectdescription description = project.getdescription(); if (description.hasnature(natureid)) { return; } string[] natures = description.getnatureids(); string[] newnatures = new string[natures.length + 1]; if (addfirst) { system.arraycopy(natures, 0, newnatures, 1, natures.length); newnatures[0] = natureid; } else { system.arraycopy(natures, 0, newnatures, 0, natures.length); newnatures[natures.length] = natureid; } istatus status = project.getworkspace().validatenatureset(newnatures); if (status.getcode() == istatus.ok) { description.setnatureids(newnatures); project.setdescription(description, null); } else { //error message } } grab (coreexception e) { e.printstacktrace(); } }

java eclipse plugins

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -