Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Can you programmatically add Tasks to the TaskList?
Can you programmatically add Tasks to the TaskList? [message #287100] Thu, 23 June 2005 23:12 Go to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
I was confused at first by the two classes TaskList and TaskView due to
naming and after inspection see that the TaskList is the object being used
ie IPageLayout.ID_TASK_LIST.

I've added the TaskList view to my perspective.

Unfortunately this also meant I had to add the IDE plugin to my RCP app.

Now I'm trying to figure out how I can add my own tasks programmatically.

How do you go about doing this? Any hints or suggested reading or
tutorials would be great. I bought the Quality plugin book today and I'm
waiting on the FAQ book to be mailed to me.

[Updated on: Sat, 30 March 2013 04:19]

Report message to a moderator

Re: Can you programmatically add Tasks to the TaskList? [message #287104 is a reply to message #287100] Fri, 24 June 2005 00:39 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
My apologies! I had searched the newsgroup earlier using TaskView instead
of TaskList.

After searching using TaskList, I found several helpful posts.

However for some reason I'm getting a class cast exception from this line
of code.
TaskList taskList = (TaskList)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().findView(IPageLayout.ID_TASK_LIST);

findView() returns an IViewPart and TaskList extends ViewPart which
implements IViewPart.

So I don't see why this yields a class cast exception. The other posts
showed this same cast.

I even changed the code around to cast it to a ViewPart and that worked
and checked for null which it wasn't.


ViewPart viewPart = (ViewPart)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().findView(IPageLayout.ID_TASK_LIST);

if (viewPart == null) {
System.out.println("View part is null!");
}
System.out.println(viewPart.getTitle());

TaskList taskList = (TaskList) viewPart; <-- This caused a cast
class exception.

Any ideas?
Re: Can you programmatically add Tasks to the TaskList? [message #287106 is a reply to message #287104] Fri, 24 June 2005 00:54 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Ok. Now I'm terribly confused.


The class cast exception was because the ViewPart wasn't TaskList but
TaskView.

<view
name="%Views.Task"
icon="icons/full/eview16/tasks_tsk.gif"
category="org.eclipse.ui"
class="org.eclipse.ui.views.markers.internal.TaskView"
id="org.eclipse.ui.views.TaskList">
</view>

So the ID is TaskList and the class is TaskView.

However looking at the code in TaskList it looks like what the view shows
and not what's in TaskView.

Can anyone explain the tie between TaskList and TaskView?? I really don't
see it. Does it have to do with adapters??

[Updated on: Sat, 30 March 2013 04:19]

Report message to a moderator

Re: Can you programmatically add Tasks to the TaskView? [message #287107 is a reply to message #287106] Fri, 24 June 2005 01:19 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Ok. I found this link which explains what the deal is with TaskList and
TaskView.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=37974

TaskList was split into TaskView and ProblemView.

Apparently a lot of people don't like the idea of splitting the TaskList
into two views. And there was going to be a change for this in 3.1 but it
didn't make it.

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/plat form-ui-home/generic-marker-view/markers.html


So now I'm back to square one trying to figure out how to add tasks to the
TaskView.

Ideas? Suggestions?
Re: Can you programmatically add Tasks to the TaskView? [message #287155 is a reply to message #287107] Fri, 24 June 2005 20:32 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mvsteenbergen.eljakim.scratch-this.nl

You could try adding a task marker to a resource in the workspace. You
add markers by calling createMarker() on a specific resource. If I
recall correctly, you'll have to do this from a special thread, but I
don't remember in detail how. It shouldn't be hard to find some
examples, though.

Good luck,

Martijn van Steenbergen.

Daniel W King wrote:
> So now I'm back to square one trying to figure out how to add tasks to
> the TaskView.
>
> Ideas? Suggestions?
Re: Can you programmatically add Tasks to the TaskView? [message #287161 is a reply to message #287155] Fri, 24 June 2005 21:41 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Thanks for the reply.

I have code to do the following:

IResource resource = ....

try {
IMarker marker = resource.createMarker(IMarker.TASK);
marker.setAttribute(IMarker.MESSAGE, "Test");
}
catch (CoreException e) {
e.printStackTrace();
}

And I remember reading somewhere what you said about a special thread. I
think its a WorkspaceRunnable or something like that.

However my editor's input is URIEditorInput from emf so now I'm trying to
figure out how to get a IResource from it. So I'm searching the
newsgroups and looking at IFile, IContainer, IResource and URIEditorInput
trying to figure it out.

[Updated on: Sat, 30 March 2013 04:21]

Report message to a moderator

Re: Can you programmatically add Tasks to the TaskView? [message #287162 is a reply to message #287161] Fri, 24 June 2005 22:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Daniel,

Typically URIEditorInput is only used in RCP. You can call getURI and
if it's of the form platform:/resource/<path> you can look up that with
IWorkspaceRoot.getFile("<path>"); you could interpret a URI of the form
/<project>/<path> similarly. Looking in
org.eclipse.emf.edit.ui.action.ValidationAction, which creates markers,
should help.


Daniel W King wrote:

> Thanks for the reply.
>
> I have code to do the following:
>
> IResource resource = ....
>
> try {
> IMarker marker = resource.createMarker(IMarker.TASK);
> marker.setAttribute(IMarker.MESSAGE, "Test");
> }
> catch (CoreException e) {
> e.printStackTrace();
> }
>
> And I remember reading somewhere what you said about a special
> thread. I think its a WorkspaceRunnable or something like that.
>
> However my editor's input is URIEditorInput from emf so now I'm trying
> to figure out how to get a IResource from it. So I'm searching the
> newsgroups and looking at IFile, IContainer, IResource and
> URIEditorInput trying to figure it out.
>
> Thanks,
> Daniel
>
Re: Can you programmatically add Tasks to the TaskView? [message #287176 is a reply to message #287161] Sat, 25 June 2005 07:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Platform.asLocalURL().

Bob

Daniel W King wrote:
> Thanks for the reply.
>
> I have code to do the following:
>
> IResource resource = ....
>
> try {
> IMarker marker = resource.createMarker(IMarker.TASK);
> marker.setAttribute(IMarker.MESSAGE, "Test");
> }
> catch (CoreException e) {
> e.printStackTrace();
> }
>
> And I remember reading somewhere what you said about a special thread.
> I think its a WorkspaceRunnable or something like that.
>
> However my editor's input is URIEditorInput from emf so now I'm trying
> to figure out how to get a IResource from it. So I'm searching the
> newsgroups and looking at IFile, IContainer, IResource and
> URIEditorInput trying to figure it out.
>
> Thanks,
> Daniel
>
Re: Can you programmatically add Tasks to the TaskView? [message #287178 is a reply to message #287176] Sat, 25 June 2005 13:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Bob,

I'm not sure how this helps determine the IFile? It just gives you yet
another URL...


Bob Foster wrote:

> Platform.asLocalURL().
>
> Bob
>
> Daniel W King wrote:
>
>> Thanks for the reply.
>>
>> I have code to do the following:
>>
>> IResource resource = ....
>>
>> try {
>> IMarker marker = resource.createMarker(IMarker.TASK);
>> marker.setAttribute(IMarker.MESSAGE, "Test");
>> }
>> catch (CoreException e) {
>> e.printStackTrace();
>> }
>>
>> And I remember reading somewhere what you said about a special
>> thread. I think its a WorkspaceRunnable or something like that.
>>
>> However my editor's input is URIEditorInput from emf so now I'm
>> trying to figure out how to get a IResource from it. So I'm
>> searching the newsgroups and looking at IFile, IContainer, IResource
>> and URIEditorInput trying to figure it out.
>>
>> Thanks,
>> Daniel
>>
Re: Can you programmatically add Tasks to the TaskView? [message #287181 is a reply to message #287178] Sat, 25 June 2005 17:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

Little too cryptic, eh? Yes, but you can use this URL to make a
java.io.File and from the file you can get an absolute path from which
you can make an IPath.

Bob

Ed Merks wrote:
> Bob,
>
> I'm not sure how this helps determine the IFile? It just gives you yet
> another URL...
>
>
> Bob Foster wrote:
>
>> Platform.asLocalURL().
>>
>> Bob
>>
>> Daniel W King wrote:
>>
>>> Thanks for the reply.
>>>
>>> I have code to do the following:
>>>
>>> IResource resource = ....
>>>
>>> try {
>>> IMarker marker = resource.createMarker(IMarker.TASK);
>>> marker.setAttribute(IMarker.MESSAGE, "Test");
>>> }
>>> catch (CoreException e) {
>>> e.printStackTrace();
>>> }
>>>
>>> And I remember reading somewhere what you said about a special
>>> thread. I think its a WorkspaceRunnable or something like that.
>>>
>>> However my editor's input is URIEditorInput from emf so now I'm
>>> trying to figure out how to get a IResource from it. So I'm
>>> searching the newsgroups and looking at IFile, IContainer, IResource
>>> and URIEditorInput trying to figure it out.
>>>
>>> Thanks,
>>> Daniel
>>>
Re: Can you programmatically add Tasks to the TaskView? [message #287184 is a reply to message #287181] Sun, 26 June 2005 16:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------080404050608070100030305
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Bob,

It's not just cryptic, it doesn't seem like such a great approach
either. The Platform.aslLocalURL method is documented like this:

/**
* Returns a URL that is the local equivalent of the
* supplied URL. This method is expected to be used with the
* plug-in-relative URLs returned by IPluginDescriptor,
Bundle.getEntry()
* and Platform.find().
* If the specified URL is not a plug-in-relative URL, it
* is returned as is. If the specified URL is a plug-in-relative
* URL of a file (including .jar archive), it is returned as
* a locally accessible URL using "file:" protocol
* (extracting/caching the file locally, if required). If the
specified URL
* is a plug-in-relative URL of a directory, the directory and
any files and directories
* under it are made locally accessible likewise. If
*
* @param url original plug-in-relative URL.
* @return the resolved URL
* @exception IOException if unable to resolve URL
* @see #resolve(URL)
* @see #find(Bundle, IPath)
* @see Bundle#getEntry(String)
*/

Which is very similar to platform.resolve is documented like this:

/**
* Returns a URL which is the resolved equivalent of the
* supplied URL. This method is expected to be used with the
* plug-in-relative URLs returned by IPluginDescriptor,
Bundle.getEntry()
* and Platform.find().
* <p>
* If the specified URL is not a plug-in-relative URL, it is
returned
* as is. If the specified URL is a plug-in-relative URL, this
method
* attempts to reduce the given URL to one which is native to
the Java
* class library (eg. file, http, etc).
* </p><p>
* Note however that users of this API should not assume too
much about the
* results of this method. While it may consistently return a
file: URL in certain
* installation configurations, others may result in jar: or
http: URLs.
* </p>
* @param url original plug-in-relative URL.
* @return the resolved URL
* @exception IOException if unable to resolve URL
* @see #asLocalURL(URL)
* @see #find(Bundle, IPath)
* @see Bundle#getEntry(String)
*/

I know Platform.resolve is supposed to do something with
platform:/plugin and platform:/resource URL, but that's not clear from
the Javadoc. In any case, neither seem quite appropriate, with the
asLocalURL method possibly doing lots of work that just isn't necessary,
i.e., localizing a URI shouldn't be necessary for something you expect
is in the workspace.. In the best case, these methods might produce a
file: URL which you can convert to an IPath and then lookup in the
workspace root, but it may map to multiple IFiles or none at all. If
the original URI is of the form platform:/resource/<project>, all this
is an awful lot of indirection and cost, when the one and only correct
answer is already available via syntactic manipulation of the URI.


Bob Foster wrote:

> Little too cryptic, eh? Yes, but you can use this URL to make a
> java.io.File and from the file you can get an absolute path from which
> you can make an IPath.
>
> Bob
>
> Ed Merks wrote:
>
>> Bob,
>>
>> I'm not sure how this helps determine the IFile? It just gives you
>> yet another URL...
>>
>>
>> Bob Foster wrote:
>>
>>> Platform.asLocalURL().
>>>
>>> Bob
>>>
>>> Daniel W King wrote:
>>>
>>>> Thanks for the reply.
>>>>
>>>> I have code to do the following:
>>>>
>>>> IResource resource = ....
>>>>
>>>> try {
>>>> IMarker marker = resource.createMarker(IMarker.TASK);
>>>> marker.setAttribute(IMarker.MESSAGE, "Test");
>>>> }
>>>> catch (CoreException e) {
>>>> e.printStackTrace();
>>>> }
>>>>
>>>> And I remember reading somewhere what you said about a special
>>>> thread. I think its a WorkspaceRunnable or something like that.
>>>>
>>>> However my editor's input is URIEditorInput from emf so now I'm
>>>> trying to figure out how to get a IResource from it. So I'm
>>>> searching the newsgroups and looking at IFile, IContainer,
>>>> IResource and URIEditorInput trying to figure it out.
>>>>
>>>> Thanks,
>>>> Daniel
>>>>


--------------080404050608070100030305
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Bob,<br>
<br>
It's not just cryptic, it doesn't seem like such a great approach
either. The Platform.aslLocalURL method is documented like this:<br>
<blockquote>
Re: Can you programmatically add Tasks to the TaskView? [message #287185 is a reply to message #287184] Sun, 26 June 2005 16:16 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: bob.objfac.com

There's no more overhead than syntactic manipulation except where
necessary, and you do _not_ want to try syntactically manipulating URLs
with strange, undocumented schemes. If you have a bundle: URL, for
example, the authority will be an integer; try to figure that out by
yourself.

Use resolve() if you want; these methods are intended to turn _any_ sort
of odd URL that Eclipse throws at you to one with a well-known scheme.
If you get back a file: URL it's a file or a folder; don't get wrapped
around the axle about it, just make a java.io.File and test it. It is
not wise to count on programs always putting a / at the end of a folder
URL, but File will sort it out.

Bob

Ed Merks wrote:
> Bob,
>
> It's not just cryptic, it doesn't seem like such a great approach
> either. The Platform.aslLocalURL method is documented like this:
>
> /**
> * Returns a URL that is the local equivalent of the
> * supplied URL. This method is expected to be used with the
> * plug-in-relative URLs returned by IPluginDescriptor,
> Bundle.getEntry()
> * and Platform.find().
> * If the specified URL is not a plug-in-relative URL, it
> * is returned as is. If the specified URL is a plug-in-relative
> * URL of a file (including .jar archive), it is returned as
> * a locally accessible URL using "file:" protocol
> * (extracting/caching the file locally, if required). If the
> specified URL
> * is a plug-in-relative URL of a directory, the directory and
> any files and directories
> * under it are made locally accessible likewise. If
> *
> * @param url original plug-in-relative URL.
> * @return the resolved URL
> * @exception IOException if unable to resolve URL
> * @see #resolve(URL)
> * @see #find(Bundle, IPath)
> * @see Bundle#getEntry(String)
> */
>
> Which is very similar to platform.resolve is documented like this:
>
> /**
> * Returns a URL which is the resolved equivalent of the
> * supplied URL. This method is expected to be used with the
> * plug-in-relative URLs returned by IPluginDescriptor,
> Bundle.getEntry()
> * and Platform.find().
> * <p>
> * If the specified URL is not a plug-in-relative URL, it is
> returned
> * as is. If the specified URL is a plug-in-relative URL, this
> method
> * attempts to reduce the given URL to one which is native to
> the Java
> * class library (eg. file, http, etc).
> * </p><p>
> * Note however that users of this API should not assume too
> much about the
> * results of this method. While it may consistently return a
> file: URL in certain
> * installation configurations, others may result in jar: or
> http: URLs.
> * </p>
> * @param url original plug-in-relative URL.
> * @return the resolved URL
> * @exception IOException if unable to resolve URL
> * @see #asLocalURL(URL)
> * @see #find(Bundle, IPath)
> * @see Bundle#getEntry(String)
> */
>
> I know Platform.resolve is supposed to do something with
> platform:/plugin and platform:/resource URL, but that's not clear from
> the Javadoc. In any case, neither seem quite appropriate, with the
> asLocalURL method possibly doing lots of work that just isn't necessary,
> i.e., localizing a URI shouldn't be necessary for something you expect
> is in the workspace.. In the best case, these methods might produce a
> file: URL which you can convert to an IPath and then lookup in the
> workspace root, but it may map to multiple IFiles or none at all. If
> the original URI is of the form platform:/resource/<project>, all this
> is an awful lot of indirection and cost, when the one and only correct
> answer is already available via syntactic manipulation of the URI.
>
>
> Bob Foster wrote:
>
>> Little too cryptic, eh? Yes, but you can use this URL to make a
>> java.io.File and from the file you can get an absolute path from which
>> you can make an IPath.
>>
>> Bob
>>
>> Ed Merks wrote:
>>
>>> Bob,
>>>
>>> I'm not sure how this helps determine the IFile? It just gives you
>>> yet another URL...
>>>
>>>
>>> Bob Foster wrote:
>>>
>>>> Platform.asLocalURL().
>>>>
>>>> Bob
>>>>
>>>> Daniel W King wrote:
>>>>
>>>>> Thanks for the reply.
>>>>>
>>>>> I have code to do the following:
>>>>>
>>>>> IResource resource = ....
>>>>>
>>>>> try {
>>>>> IMarker marker = resource.createMarker(IMarker.TASK);
>>>>> marker.setAttribute(IMarker.MESSAGE, "Test");
>>>>> }
>>>>> catch (CoreException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>>
>>>>> And I remember reading somewhere what you said about a special
>>>>> thread. I think its a WorkspaceRunnable or something like that.
>>>>>
>>>>> However my editor's input is URIEditorInput from emf so now I'm
>>>>> trying to figure out how to get a IResource from it. So I'm
>>>>> searching the newsgroups and looking at IFile, IContainer,
>>>>> IResource and URIEditorInput trying to figure it out.
>>>>>
>>>>> Thanks,
>>>>> Daniel
>>>>>
>
Re: Can you programmatically add Tasks to the TaskView? [message #287227 is a reply to message #287162] Mon, 27 June 2005 20:21 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Ed and Bob,

Thanks for the replies. I can get an IFile now but can't seem to get one
that exists. I have a file named sample.richtext.

C:\workspace-x\richTextEditor.editor\sample.richtext

My code looks like this:
============================================================ ======
public static String openFilePathDialog(Shell shell, String
fileExtensionFilter, int style) {

FileDialog fileDialog = new FileDialog(shell, style);
if (fileExtensionFilter == null) {
fileExtensionFilter = "*." +
getString("_UI_RichtextEditorFilenameExtension");
}
fileDialog.setFilterExtensions(new String[] { fileExtensionFilter
});

fileDialog.open();
if (fileDialog.getFileName() != null &&
fileDialog.getFileName().length() > 0) {
return fileDialog.getFilterPath() + File.separator +
fileDialog.getFileName();
}
else {
return null;
}
}
============================================================ ======

String path =
openFilePathDialog(PlatformUI.getWorkbench().getActiveWorkbe nchWindow().getShell(),
null, SWT.OPEN);
URI uri = URI.createPlatformResourceURI(path);
URIEditorInput editorInput = new URIEditorInput(uri);
URI uri = ((URIEditorInput)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor().getEditorInput()).getURI();

IFile file = null;

if ("platform".equals(scheme) && uri.segmentCount() > 1 &&
"resource".equals(uri.segment(0))) {
StringBuffer platformResourcePath = new StringBuffer();
for (int j = 1, size = uri.segmentCount(); j < size; ++j) {
platformResourcePath.append('/');
platformResourcePath.append(uri.segment(j));
}

IWorkspace workspace = ResourcesPlugin.getWorkspace();

IWorkspaceRoot workspaceRoot = workspace.getRoot();

Path path = new Path(platformResourcePath.toString());

file = workspaceRoot.getFile(path);

Now if I do a file.exists() it returns false.

I've tried:
java.io.File javaFile = path.toFile();
file = fileToIFile(javaFile);

public IFile fileToIFile(File file) {

String p = file.getPath();
IPath path = new Path(p);
return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}

And ...

workspaceRoot.getFileForLocation(new
Path("C:\workspace-x\richTextEditor.editor\sample.richtext"));

And tried using the path
"//workspace-x/richTextEditor.editor/sample.richtext"


And a few other variations messing with the path to no avail.

I did notice if I do workspaceRoot.getFullPath() it returns "/".

That looks odd to me. I expected it to be something like "workspace-x"
since that's the name of my workspace or maybe "C:/workspace-x".

What am I missing here? Before I was using URI.createFileURI and saw that
I had file: on the front and changed that to
URI.createPlatformResourceURI(path);

I read through a lot of posts on IFile and it seems like I'm screwing up
my path but have tried a lot of combinations.

[Updated on: Sat, 30 March 2013 04:21]

Report message to a moderator

Re: Can you programmatically add Tasks to the TaskView? [message #287400 is a reply to message #287227] Wed, 29 June 2005 15:27 Go to previous messageGo to next message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
I finally figured out why the method exists() on my IFile kept returning
false. My app is an RCP application. My file was in workspace-x and my
RCP app's workspace is runtime-workspace. I read some posts where people
are using Platform.getInstanceLocation() or Platform.getLocation() to get
the location and then setting the URL on location. However my file might
be anywhere on the file system which may or may not be in a workspace so
back to reading posts. I remember reading somewhere that you can link to
external resources now better than you could in previous versions of
Eclipse. I'm using 3.1RC1.

And thanks again Ed and Bob.

[Updated on: Sat, 30 March 2013 04:22]

Report message to a moderator

Re: Can you programmatically add Tasks to the TaskView? - Solved!!! [message #287435 is a reply to message #287400] Wed, 29 June 2005 23:20 Go to previous message
W W is currently offline W WFriend
Messages: 45
Registered: July 2009
Member
Since this was an RCP app my main problem was getting the IFile. The
projectName passed in here can be total crap :P I just got this working
and probably need to do a better job with the code overall hence my TODOs.
However I put the addTask in a for loop and created a 100 tasks. I think
I'll change this so I get the IFile once and pass it in to create tasks
and not call all that crap a 100 times since it was just a test :) So yes
its sloppy but it works for now.

------------
public static IFile getFileFromURI(URI uri, String projectName) {

IFile file = null;

if (uri != null && projectName != null) {

String scheme = uri.scheme();

if ("platform".equals(scheme) && uri.segmentCount() > 1 &&
"resource".equals(uri.segment(0))) {

StringBuffer platformResourcePath = new StringBuffer();

for (int j = 1, size = uri.segmentCount(); j < size; ++j) {

platformResourcePath.append('/');
platformResourcePath.append(uri.segment(j));
}

file = getExternalFile(platformResourcePath.toString(),
projectName);
}
}

return file;
}

---------
public static IFile getExternalFile(IPath location, String projectName)
{

IFile file = null;
IProject project = getProject(projectName);

if (location != null) {

file = project.getFile(location.lastSegment());

if (file != null && !file.exists()) {

try {

file.createLink(location, IResource.NONE, null);
}
catch (CoreException e) {

e.printStackTrace();
}
}
}

return file;
}

-----
private static IProject getProject(String projectName) {

IProject project = null;
IWorkspace workspace = ResourcesPlugin.getWorkspace();

if (workspace != null && workspace.getRoot() != null) {

project = workspace.getRoot().getProject(projectName);

try {

if (!project.exists()) {

project.create(null);
}

if (!project.isOpen()) {

project.open(null);
}
}
catch (Throwable t) {

t.printStackTrace();
}
}

return project;
}

-----

public void addTask(String message) {
// TODO probably need to change this to pass in the URI.
// What if the user of this API wants to add the task to an editor that
isnt active
URI uri = ((URIEditorInput)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor().getEditorInput()).getURI();
// TODO Need to pass in the project name
IFile file = getFileFromURI(uri, "My project that may or may not
exist");

if (file != null && file.exists()) {

try {

// TODO Need to see if the marker already exists
// FIXME Probably need to use MarkerUtilities ...
IMarker marker = file.createMarker(IMarker.TASK);
marker.setAttribute(IMarker.MESSAGE, message);
}
catch (CoreException e) {

e.printStackTrace();
}
}
}

[Updated on: Sat, 30 March 2013 04:24]

Report message to a moderator

Previous Topic:3.2 doesn't start for regular user
Next Topic:Pathological Performance Problem with MarkerUtilities
Goto Forum:
  


Current Time: Thu Apr 18 23:10:13 GMT 2024

Powered by FUDForum. Page generated in 0.02515 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top