Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [JET2] Using MessageDialog in custom Tag
[JET2] Using MessageDialog in custom Tag [message #22536] Tue, 19 June 2007 09:46 Go to next message
Eclipse UserFriend
Originally posted by: vincent.lg.voila.fr

Hi everyone,

I wrote some custom tags for my application and I wanted to display a
MessageDialog to ask users for something, but
MessageDialog.openInformation() throws a nullPointerException.

Here is a sample code :

public class AutoDeployTag extends AbstractEmptyTag {

public AutoDeployTag() {
// TODO Auto-generated constructor stub
}

@Override
public void doAction(TagInfo td, JET2Context context, JET2Writer
out)
throws JET2TagException {

MessageDialog.openInformation(null, "Test", "Test");
}
}

The dialog fails because it can't find any active shell to be displayed
on. I tried to pass
Activator.getDefault().getWorkbench().getDisplay().getActive Shell()
instead of null, but it doesn't work.

Does anyone have an idea ?
Many Thanks.
Re: [JET2] Using MessageDialog in custom Tag [message #22580 is a reply to message #22536] Tue, 19 June 2007 12:35 Go to previous messageGo to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Vincent:

The JET transformation typically runs in a thread other than the UI thread.
The Eclipse FAQ (http://wiki.eclipse.org/index.php/Eclipse_FAQs) has the
answers:

FAQ: Why do I get an invalid thread access exception? -
http://wiki.eclipse.org/index.php/FAQ_Why_do_I_get_an_invali d_thread_access_exception%3F
FAQ: How do I get a Display instance? -
http://wiki.eclipse.org/index.php/FAQ_How_do_I_get_a_Display _instance%3F

Also, the JET context maintains a reference to the active shell, although it
may be null in some circumstances...

JET2Context context; ...

Object shell =
TransformContextExtender.getInstance(context).getShellContex t();
if(shell instanceof Shell) {
// found a shell, so we are operating with a GUI.
... get the Display, and do an asyncExec or a syncExec to display the
dialog ...
}

I recommend caution in creating user interface elements in a tag. One of the
design principles of JET is that transformations should be able to run
'headless', which means without any UI present at all. Your tag should be
able to execute even if no shell is present.

Paul
Re: [JET2] Using MessageDialog in custom Tag [message #22709 is a reply to message #22580] Tue, 19 June 2007 13:48 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: vincent.lg.voila.fr

Thanks a lot for the quick answer Paul,

Indeed, I've found that one couldn't create a MessageDialog outside the UI
thread, as you mentioned it in your answer. And I think I will give up
because you're right saying JET should be able to run without the UI.

I've one more question : I would like to be able to make a copy of some
files at the end of the transformation. In the workspace tags, it is only
proposed to create/copy files and folders in the current workspace, but
I'd like to copy them outside the workspace, say in my 'homedir' for
example. As it was impossible with standard tags, I've created a new tag
to copy the generated files (those in workspace) in my 'homedir', but it
is also impossible because JET uses a transaction system and actually
writes files on the disk when the transformation has ended, and the copy
doesn't work since files does not yet exist.

Can you give me some information about how I can do that ? Maybe there's a
way to chain 2 transformations, one that writes files in the workspace,
and the other that deploy those files elsewhere.

Many thanks,
Vincent.
Re: [JET2] Using MessageDialog in custom Tag [message #23015 is a reply to message #22709] Wed, 20 June 2007 12:36 Go to previous message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Vincent:

Your tag can participate in JET's transactin by adding an 'action' via the
WorkspaceContextExtender:

WorkspaceContextExtender.getInstance(context).addAction( ...an
implementation of IWorkspaceAction or a subclass of
AbstractWorkspaceAction...)

Although this is targetted at writting to the Eclipse workspace, I think you
could make them work for your purposes. If you subclass
AbstractWorkspaceAction, you must implement three methods:

* performAction, which would actually write your file (and which would have
access to all previously written files)
* requiresValidateEdit, which can return false, as files outside the
workspace are not affected by the team system.
* getResource(), which can return null (or throw an
UnsupportedOperationException) - it will not be called if
requiresValidateEdit returns false.

Actions added via addAction are executed in the order in which they are
added. WorkspaceContextExtender also has a method addFinalAction, which
causes the action to be executed after all actions added by addAction.

Paul

"vincent" <vincent.lg@voila.fr> wrote in message
news:b52f08b4fe4c4a642c7ffb134a729203$1@www.eclipse.org...
> Thanks a lot for the quick answer Paul,
> Indeed, I've found that one couldn't create a MessageDialog outside the UI
> thread, as you mentioned it in your answer. And I think I will give up
> because you're right saying JET should be able to run without the UI.
>
> I've one more question : I would like to be able to make a copy of some
> files at the end of the transformation. In the workspace tags, it is only
> proposed to create/copy files and folders in the current workspace, but
> I'd like to copy them outside the workspace, say in my 'homedir' for
> example. As it was impossible with standard tags, I've created a new tag
> to copy the generated files (those in workspace) in my 'homedir', but it
> is also impossible because JET uses a transaction system and actually
> writes files on the disk when the transformation has ended, and the copy
> doesn't work since files does not yet exist.
>
> Can you give me some information about how I can do that ? Maybe there's a
> way to chain 2 transformations, one that writes files in the workspace,
> and the other that deploy those files elsewhere.
>
> Many thanks, Vincent.
Previous Topic:Log with Jet ?
Next Topic:JET in GMF Project
Goto Forum:
  


Current Time: Sat Oct 19 18:17:59 GMT 2024

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

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

Back to the top