insert more than one element with the palette at once [message #177825] |
Fri, 15 April 2005 10:58 |
Andreas Herz 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);
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.04295 seconds