Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » insert more than one element at once
insert more than one element at once [message #177833] Fri, 15 April 2005 11:04 Go to next message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Hi

I have implemented a command that insert more than one element at once (see below).
It work fine.....but!


java.lang.NullPointerException
at org.eclipse.gef.tools.CreationTool.selectAddedObject(Creatio nTool.java:247)
at org.eclipse.gef.tools.CreationTool.performCreation(CreationT ool.java:236)
at org.eclipse.gef.tools.CreationTool.handleButtonUp(CreationTo ol.java:159)
at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1054)
at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:245)

The GEF Framework can't select the EditPart. Why?
I have inserted the inital templateModel and added additional objects
to the model.

Why can't the GEF find the EditPart for the inserted templateModel?
I can see them in my GEF-Editor.

At least the EditPart of the templateModel should be selected...or?


Greetings

Andreas

Additional Question: It is possible(/allowed) to open a dialog in the execute method
of an command?

============================================================ ===========================
============================================================ ===========================

public class CreateMyElementCommand extends Command
{
private MyModel templateModel;
private MyGroupModel group;
private Point location;
private Dimension size;
private List newModels=new ArrayList();

public CreateGroupDBElementCommand(MyGroupModel group, MyModel templateModel, Point
location, Dimension size)
{
this.location = location;
this.size = size;
this.templateModel = templateModel;
this.group = group;
}


// 1. Open a dialog to select more than one element
// 2. insert the original model element
// 3. create n clones from the templateModel and add them too
//
public void execute()
{
ElementListSelectionDialog dialog = new ElementListSelectionDialog(null....)
dialog.setElements(anyArray....);
dialog.setTitle("Select the table columns for the GUI element");
dialog.setMessage("Select the table columns for the GUI element.");
dialog.setMultipleSelection(true);
dialog.create();
if(dialog.open()==Window.OK)
{
Object[] fields= dialog.getResult();
if(size != null)
{
if(size.height<=0)
size.height=20;
if(size.width<=0)
size.width=100;
}

// add the initial model from the toolbar
//
templateModel.setSize(size);
templateModel.setLocation(location);
templateModel.setData(field[0]);
group.addChild(model);

for (int i = 1; i < fields.length; i++)
{
String field = (String)fields[i];
MyModel model = (MyModel)templateModel.getClass().newInstance();
model.setSize(size);
model.setLocation(location.getTranslated(0,(model.getSize(). height+10)*i));
model.setData(field);
group.addChild(model);
}
}
}

public boolean canUndo()
{
return newModels.size()>0;
}

public void redo()
{
Iterator iter = newModels.iterator();
while (iter.hasNext())
{
MyModel obj = (MyModel) iter.next();
group.addElement(obj);
}
}

public void undo()
{
Iterator iter = newModels.iterator();
while (iter.hasNext())
{
MyModel obj = (MyModel) iter.next();
group.removeElement(obj);
}
}
}
Re: insert more than one element at once [message #177877 is a reply to message #177833] Fri, 15 April 2005 14:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Maybe the viewer is null because you have lost focus? Does the diagram lose
focus on creation?

"FreeGroup" <a.herz@FreeGroup.de> wrote in message
news:d3o7p7$gfd$1@news.eclipse.org...
> Hi
>
> I have implemented a command that insert more than one element at once
> (see below).
> It work fine.....but!
>
>
> java.lang.NullPointerException
> at
> org.eclipse.gef.tools.CreationTool.selectAddedObject(Creatio nTool.java:247)
> at
> org.eclipse.gef.tools.CreationTool.performCreation(CreationT ool.java:236)
> at
> org.eclipse.gef.tools.CreationTool.handleButtonUp(CreationTo ol.java:159)
> at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1054)
> at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:245)
>
> The GEF Framework can't select the EditPart. Why?
> I have inserted the inital templateModel and added additional objects
> to the model.
>
> Why can't the GEF find the EditPart for the inserted templateModel?
> I can see them in my GEF-Editor.
>
> At least the EditPart of the templateModel should be selected...or?
>
>
> Greetings
>
> Andreas
>
> Additional Question: It is possible(/allowed) to open a dialog in the
> execute method
> of an command?
Re: insert more than one element at once [message #177916 is a reply to message #177833] Fri, 15 April 2005 18:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: etiennet16.hotmail.com

The default behavior when you Create an object is that the creation tool
will try to select the edit part it created the object for... So in your
command are you using the object created by your palette factory? If you
don't use the object the creation tool createed, then the creation tool
won't be able to select it after and will throw a NullPointer exception.

--
Etienne

"FreeGroup" <a.herz@FreeGroup.de> wrote in message
news:d3o7p7$gfd$1@news.eclipse.org...
> Hi
>
> I have implemented a command that insert more than one element at once
(see below).
> It work fine.....but!
>
>
> java.lang.NullPointerException
> at
org.eclipse.gef.tools.CreationTool.selectAddedObject(Creatio nTool.java:247)
> at
org.eclipse.gef.tools.CreationTool.performCreation(CreationT ool.java:236)
> at
org.eclipse.gef.tools.CreationTool.handleButtonUp(CreationTo ol.java:159)
> at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1054)
> at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:245)
>
> The GEF Framework can't select the EditPart. Why?
> I have inserted the inital templateModel and added additional objects
> to the model.
>
> Why can't the GEF find the EditPart for the inserted templateModel?
> I can see them in my GEF-Editor.
>
> At least the EditPart of the templateModel should be selected...or?
>
>
> Greetings
>
> Andreas
>
> Additional Question: It is possible(/allowed) to open a dialog in the
execute method
> of an command?
>
>
============================================================ ================
===========
>
============================================================ ================
===========
>
> public class CreateMyElementCommand extends Command
> {
> private MyModel templateModel;
> private MyGroupModel group;
> private Point location;
> private Dimension size;
> private List newModels=new ArrayList();
>
> public CreateGroupDBElementCommand(MyGroupModel group, MyModel
templateModel, Point
> location, Dimension size)
> {
> this.location = location;
> this.size = size;
> this.templateModel = templateModel;
> this.group = group;
> }
>
>
> // 1. Open a dialog to select more than one element
> // 2. insert the original model element
> // 3. create n clones from the templateModel and add them too
> //
> public void execute()
> {
> ElementListSelectionDialog dialog = new
ElementListSelectionDialog(null....)
> dialog.setElements(anyArray....);
> dialog.setTitle("Select the table columns for the GUI element");
> dialog.setMessage("Select the table columns for the GUI element.");
> dialog.setMultipleSelection(true);
> dialog.create();
> if(dialog.open()==Window.OK)
> {
> Object[] fields= dialog.getResult();
> if(size != null)
> {
> if(size.height<=0)
> size.height=20;
> if(size.width<=0)
> size.width=100;
> }
>
> // add the initial model from the toolbar
> //
> templateModel.setSize(size);
> templateModel.setLocation(location);
> templateModel.setData(field[0]);
> group.addChild(model);
>
> for (int i = 1; i < fields.length; i++)
> {
> String field = (String)fields[i];
> MyModel model = (MyModel)templateModel.getClass().newInstance();
> model.setSize(size);
>
model.setLocation(location.getTranslated(0,(model.getSize(). height+10)*i));
> model.setData(field);
> group.addChild(model);
> }
> }
> }
>
> public boolean canUndo()
> {
> return newModels.size()>0;
> }
>
> public void redo()
> {
> Iterator iter = newModels.iterator();
> while (iter.hasNext())
> {
> MyModel obj = (MyModel) iter.next();
> group.addElement(obj);
> }
> }
>
> public void undo()
> {
> Iterator iter = newModels.iterator();
> while (iter.hasNext())
> {
> MyModel obj = (MyModel) iter.next();
> group.removeElement(obj);
> }
> }
> }
Re: insert more than one element at once [message #177949 is a reply to message #177877] Fri, 15 April 2005 19:23 Go to previous messageGo to next message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Randy Hudson wrote:
> Maybe the viewer is null because you have lost focus? Does the diagram lose
> focus on creation?
>
....yes(/I think). I open SelectionDialog.

greetings

Andreas
Re: insert more than one element at once [message #178004 is a reply to message #177877] Sat, 16 April 2005 07:50 Go to previous messageGo to next message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Hi

Yes - the editor lost the focus. Is the a workaround
available.....like "setFocus(getLastViewWithFocus())".

greetings

Andreas
Re: insert more than one element at once [message #178085 is a reply to message #178004] Mon, 18 April 2005 14:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Tools release any references to the viewer to avoid potential short-term
memory leaks. This problem seems to come up again and again, so maybe we
will provide some kind of workaround such as using a weak reference or
creating a runnable block of code which does not require calling back to the
tools viewer.

"FreeGroup" <a.herz@FreeGroup.de> wrote in message
news:d3qgqh$aat$1@news.eclipse.org...
> Hi
>
> Yes - the editor lost the focus. Is the a workaround
> available.....like "setFocus(getLastViewWithFocus())".
>
> greetings
>
> Andreas
>
Re: insert more than one element at once [message #178094 is a reply to message #178085] Mon, 18 April 2005 14:44 Go to previous messageGo to next message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Randy Hudson wrote:
> Tools release any references to the viewer to avoid potential short-term
> memory leaks. This problem seems to come up again and again, so maybe we
> will provide some kind of workaround such as using a weak reference or
> creating a runnable block of code which does not require calling back to the
> tools viewer.

Hi,

FINE! - any release date in mind ;-)




......a way to go is to provide a class "DialogEnabledCommand"
which handles the 'lost focus' with a weak reference.

or - can I ignore the error, and the next release of the GEF
handle this feature?

greetings

Andreas
Re: insert more than one element at once [message #178131 is a reply to message #178094] Mon, 18 April 2005 17:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

Open a bugzilla to track this.

"FreeGroup" <a.herz@FreeGroup.de> wrote in message
news:d40htf$n6l$1@news.eclipse.org...
> Randy Hudson wrote:
>> Tools release any references to the viewer to avoid potential short-term
>> memory leaks. This problem seems to come up again and again, so maybe we
>> will provide some kind of workaround such as using a weak reference or
>> creating a runnable block of code which does not require calling back to
>> the tools viewer.
>
> Hi,
>
> FINE! - any release date in mind ;-)
>
>
>
>
> .....a way to go is to provide a class "DialogEnabledCommand"
> which handles the 'lost focus' with a weak reference.
>
> or - can I ignore the error, and the next release of the GEF
> handle this feature?
>
> greetings
>
> Andreas
Re: insert more than one element at once [message #178165 is a reply to message #178131] Mon, 18 April 2005 19:34 Go to previous messageGo to next message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
For the others:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=91778
handling right-click in editor [message #178263 is a reply to message #178165] Tue, 19 April 2005 13:16 Go to previous messageGo to next message
benedict heal is currently offline benedict healFriend
Messages: 28
Registered: July 2009
Junior Member
I can pick up a right click, and execute an action, but cannot see how
the Action can retrieve the object under the right click.

Can anyone point me in the right direction?
many thanks,
Benedict
Re: handling right-click in editor [message #178396 is a reply to message #178263] Wed, 20 April 2005 06:28 Go to previous message
Andreas Herz is currently offline Andreas HerzFriend
Messages: 196
Registered: July 2009
Senior Member
Hi,

add the selectionChanged(IAction action, ISelection selection)
method to your action. Your EditPart will be part of the selection
(or more edit parts).

example:
-------
public void selectionChanged(IAction action, ISelection selection)
{
mySelectedModel=null;
if(((IStructuredSelection)selection).getFirstElement()!=null )
{
MyEditPart editPart = (MyEditPart)((IStructuredSelection)selection).getFirstElemen t();
if(editPart.getModel() instanceof MyModel)
mySelectedModel = (MyModel)editPart.getModel();
}
}



greetings

Andreas


....but this was not my initial question ;-)
Previous Topic:How to create a new file inside an editor
Next Topic:Where this exception comes from?
Goto Forum:
  


Current Time: Thu Mar 28 09:29:53 GMT 2024

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

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

Back to the top