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 19:12  |
Eclipse User |
|
|
|
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 00:19] by Moderator
|
|
| | | | | | | | | |
Re: Can you programmatically add Tasks to the TaskView? [message #287184 is a reply to message #287181] |
Sun, 26 June 2005 12:00   |
Eclipse User |
|
|
|
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 12:16   |
Eclipse User |
|
|
|
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? - Solved!!! [message #287435 is a reply to message #287400] |
Wed, 29 June 2005 19:20  |
Eclipse User |
|
|
|
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 00:24] by Moderator
|
|
|
Goto Forum:
Current Time: Thu Sep 25 18:42:12 EDT 2025
Powered by FUDForum. Page generated in 1.07380 seconds
|