Home » Eclipse Projects » GEF » How to get information from user in the getCreateCommand(CreateRequest request)
How to get information from user in the getCreateCommand(CreateRequest request) [message #158387] |
Wed, 17 November 2004 22:06 |
Eclipse User |
|
|
|
Originally posted by: bandrews.nospam_bphnx.com
In my getCreateCommand() method in XYLayoutEditPolicy, I want to get
information from the user, for example the name of the object to create.
I had this working before, by bringing up an InputDialog in my
CreateCommand, but I really wanted to get this information before then
and just pass it to the command. But when I call the InputDialog from
the getCreateCommand(), the dialog just pops up over and over. I realize
it keeps popping up because every time I move the mouse, this method
gets called. My question is what is the best way to get information from
the user before an object is created?
thanks so much!
Barry
|
|
| |
Re: How to get information from user in the getCreateCommand(CreateRequest request) [message #158500 is a reply to message #158418] |
Thu, 18 November 2004 16:38 |
Eclipse User |
|
|
|
Originally posted by: bandrews.nospam_bphnx.com
Thanks! I believe this will give me what I want. I do have one problem
that I can't figure out. After I hit OK or Cancel on the InputDialog, I
get a NullPointerException in SelectionEditPartTracker. I can't seem to
track this down as it is happening in another thread. Everything else
works fine.
I can't figure out why the SelectionTool's mouseUp() method gets called
when the mouse up is happening on a button on a dialog.
Is there something else I need to do in my extended CreationTool to keep
from getting this exception?
Here is my code:
public class DECreationTool extends CreationTool
{
private String objectName;
/**
*
*/
public DECreationTool()
{
super();
}
/**
* @param aFactory
*/
public DECreationTool(CreationFactory aFactory)
{
super(aFactory);
}
/* (non-Javadoc)
* @see org.eclipse.gef.Tool#activate()
*/
public void activate()
{
super.activate();
InputDialog input = new InputDialog(
DrawingEditor.getShell(),
"Name","Name: ","",null);
if(input.open() == InputDialog.CANCEL)
this.objectName = null;
else
this.objectName = input.getValue();
}
/* (non-Javadoc)
* @see org.eclipse.gef.tools.CreationTool#performCreation(int)
*/
protected void performCreation(int button)
{
if(this.objectName == null || this.objectName.length() == 0)
{
deactivate();
return;
}
CreateCommand command = (CreateCommand)this.getCommand();
command.setName(this.objectName);
this.setCurrentCommand(command);
super.performCreation(button);
}
}
Here is the exception:
java.lang.NullPointerException
at
org.eclipse.gef.tools.SelectEditPartTracker.handleButtonUp(S electEditPartTracker.java:114)
at
org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditP art$OtherToggleButtonTracker.handleButtonUp(ToolEntryEditPar t.java:176)
at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1054)
at org.eclipse.gef.tools.SelectionTool.mouseUp(SelectionTool.ja va:544)
at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:245)
at
org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouse Released(DomainEventDispatcher.java:359)
at
org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(Li ghtweightSystem.java:528)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:136)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :82)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:2783)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2442)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1443)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1414)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:271)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:144)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplicatio n.java:102)
at
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:335)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:273)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
at org.eclipse.core.launcher.Main.run(Main.java:704)
at org.eclipse.core.launcher.Main.main(Main.java:688)
Pratik Shah wrote:
> Perhaps popping up a dialog when the tool is activated.
>
> "Barry Andrews" <bandrews@nospam_bphnx.com> wrote in message
> news:cngi25$84p$1@www.eclipse.org...
>
>>In my getCreateCommand() method in XYLayoutEditPolicy, I want to get
>>information from the user, for example the name of the object to create.
>>I had this working before, by bringing up an InputDialog in my
>>CreateCommand, but I really wanted to get this information before then
>>and just pass it to the command. But when I call the InputDialog from
>>the getCreateCommand(), the dialog just pops up over and over. I realize
>>it keeps popping up because every time I move the mouse, this method
>>gets called. My question is what is the best way to get information from
>>the user before an object is created?
>>
>>thanks so much!
>>
>>Barry
>
>
>
|
|
|
Re: How to get information from user in the getCreateCommand(CreateRequest request) [message #158515 is a reply to message #158500] |
Thu, 18 November 2004 16:48 |
Eclipse User |
|
|
|
Originally posted by: bandrews.nospam_bphnx.com
Never mind... I am too quick to post.
If I put the dialog in the performCreation() method instead of
activate(), I do not get this exception. Why, I am still not quite sure.
I will try to figure that out, or if you already know please tell. ;)
This actually works out better, because I would rather the dialog pop up
after the user has selected the location to plop down the object rather
than when the CreationTool is selected.
Thanks for your help!
Barry
Barry Andrews wrote:
> Thanks! I believe this will give me what I want. I do have one problem
> that I can't figure out. After I hit OK or Cancel on the InputDialog, I
> get a NullPointerException in SelectionEditPartTracker. I can't seem to
> track this down as it is happening in another thread. Everything else
> works fine.
>
> I can't figure out why the SelectionTool's mouseUp() method gets called
> when the mouse up is happening on a button on a dialog.
>
> Is there something else I need to do in my extended CreationTool to keep
> from getting this exception?
>
> Here is my code:
>
> public class DECreationTool extends CreationTool
> {
> private String objectName;
>
> /**
> *
> */
> public DECreationTool()
> {
> super();
> }
>
> /**
> * @param aFactory
> */
> public DECreationTool(CreationFactory aFactory)
> {
> super(aFactory);
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.gef.Tool#activate()
> */
> public void activate()
> {
> super.activate();
> InputDialog input = new InputDialog(
> DrawingEditor.getShell(),
> "Name","Name: ","",null);
> if(input.open() == InputDialog.CANCEL)
> this.objectName = null;
> else
> this.objectName = input.getValue();
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.gef.tools.CreationTool#performCreation(int)
> */
> protected void performCreation(int button)
> {
> if(this.objectName == null || this.objectName.length() == 0)
> {
> deactivate();
> return;
> }
>
> CreateCommand command = (CreateCommand)this.getCommand();
> command.setName(this.objectName);
> this.setCurrentCommand(command);
> super.performCreation(button);
> }
> }
>
> Here is the exception:
>
>
> java.lang.NullPointerException
> at
> org.eclipse.gef.tools.SelectEditPartTracker.handleButtonUp(S electEditPartTracker.java:114)
>
> at
> org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditP art$OtherToggleButtonTracker.handleButtonUp(ToolEntryEditPar t.java:176)
>
> at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1054)
> at org.eclipse.gef.tools.SelectionTool.mouseUp(SelectionTool.ja va:544)
> at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:245)
> at
> org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouse Released(DomainEventDispatcher.java:359)
>
> at
> org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(Li ghtweightSystem.java:528)
>
> at
> org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:136)
> at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :82)
> at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
> at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:2783)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2442)
> at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1443)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1414)
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:271)
> at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:144)
> at
> org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplicatio n.java:102)
> at
> org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:335)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:273)
>
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:129)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
> at org.eclipse.core.launcher.Main.run(Main.java:704)
> at org.eclipse.core.launcher.Main.main(Main.java:688)
>
>
>
> Pratik Shah wrote:
>
>> Perhaps popping up a dialog when the tool is activated.
>>
>> "Barry Andrews" <bandrews@nospam_bphnx.com> wrote in message
>> news:cngi25$84p$1@www.eclipse.org...
>>
>>> In my getCreateCommand() method in XYLayoutEditPolicy, I want to get
>>> information from the user, for example the name of the object to create.
>>> I had this working before, by bringing up an InputDialog in my
>>> CreateCommand, but I really wanted to get this information before then
>>> and just pass it to the command. But when I call the InputDialog from
>>> the getCreateCommand(), the dialog just pops up over and over. I realize
>>> it keeps popping up because every time I move the mouse, this method
>>> gets called. My question is what is the best way to get information from
>>> the user before an object is created?
>>>
>>> thanks so much!
>>>
>>> Barry
>>
>>
>>
>>
|
|
|
Re: How to get information from user in the getCreateCommand(CreateRequest request) [message #158580 is a reply to message #158515] |
Thu, 18 November 2004 20:45 |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
You should definitely override performCreation, since the ENTER key can also
be used in accessibility mode. The other alternative is to have the
execute() prompt, but I don't think you could handle cancel at that point.
"Barry Andrews" <bandrews@nospam_bphnx.com> wrote in message
news:cnijq2$96k$1@www.eclipse.org...
> Never mind... I am too quick to post.
>
> If I put the dialog in the performCreation() method instead of
> activate(), I do not get this exception. Why, I am still not quite sure.
> I will try to figure that out, or if you already know please tell. ;)
>
> This actually works out better, because I would rather the dialog pop up
> after the user has selected the location to plop down the object rather
> than when the CreationTool is selected.
>
>
> Thanks for your help!
>
>
> Barry
>
>
> Barry Andrews wrote:
>
> > Thanks! I believe this will give me what I want. I do have one problem
> > that I can't figure out. After I hit OK or Cancel on the InputDialog, I
> > get a NullPointerException in SelectionEditPartTracker. I can't seem to
> > track this down as it is happening in another thread. Everything else
> > works fine.
> >
> > I can't figure out why the SelectionTool's mouseUp() method gets called
> > when the mouse up is happening on a button on a dialog.
> >
> > Is there something else I need to do in my extended CreationTool to keep
> > from getting this exception?
> >
> > Here is my code:
> >
> > public class DECreationTool extends CreationTool
> > {
> > private String objectName;
> >
> > /**
> > *
> > */
> > public DECreationTool()
> > {
> > super();
> > }
> >
> > /**
> > * @param aFactory
> > */
> > public DECreationTool(CreationFactory aFactory)
> > {
> > super(aFactory);
> > }
> >
> > /* (non-Javadoc)
> > * @see org.eclipse.gef.Tool#activate()
> > */
> > public void activate()
> > {
> > super.activate();
> > InputDialog input = new InputDialog(
> > DrawingEditor.getShell(),
> > "Name","Name: ","",null);
> > if(input.open() == InputDialog.CANCEL)
> > this.objectName = null;
> > else
> > this.objectName = input.getValue();
> > }
> >
> > /* (non-Javadoc)
> > * @see org.eclipse.gef.tools.CreationTool#performCreation(int)
> > */
> > protected void performCreation(int button)
> > {
> > if(this.objectName == null || this.objectName.length() == 0)
> > {
> > deactivate();
> > return;
> > }
> >
> > CreateCommand command = (CreateCommand)this.getCommand();
> > command.setName(this.objectName);
> > this.setCurrentCommand(command);
> > super.performCreation(button);
> > }
> > }
> >
> > Here is the exception:
> >
> >
> > java.lang.NullPointerException
> > at
> >
org.eclipse.gef.tools.SelectEditPartTracker.handleButtonUp(S electEditPartTra
cker.java:114)
> >
> > at
> >
org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditP art$OtherToggleB
uttonTracker.handleButtonUp(ToolEntryEditPart.java:176)
> >
> > at
org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java :1054)
> > at
org.eclipse.gef.tools.SelectionTool.mouseUp(SelectionTool.ja va:544)
> > at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:245)
> > at
> >
org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouse Released(DomainE
ventDispatcher.java:359)
> >
> > at
> >
org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(Li ghtweightSystem.
java:528)
> >
> > at
> >
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:136)
> > at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :82)
> > at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
> > at
org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:2783)
> > at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :2442)
> > at
org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:1443)
> > at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1414)
> > at
> >
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:271)
> > at
org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:144)
> > at
> > org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplicatio n.java:102)
> > at
> >
org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.
java:335)
> >
> > at
> >
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:273)
> >
> > at
> >
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:129)
> >
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at
> >
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39
)
> >
> > at
> >
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl
..java:25)
> >
> > at java.lang.reflect.Method.invoke(Method.java:585)
> > at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
> > at org.eclipse.core.launcher.Main.run(Main.java:704)
> > at org.eclipse.core.launcher.Main.main(Main.java:688)
> >
> >
> >
> > Pratik Shah wrote:
> >
> >> Perhaps popping up a dialog when the tool is activated.
> >>
> >> "Barry Andrews" <bandrews@nospam_bphnx.com> wrote in message
> >> news:cngi25$84p$1@www.eclipse.org...
> >>
> >>> In my getCreateCommand() method in XYLayoutEditPolicy, I want to get
> >>> information from the user, for example the name of the object to
create.
> >>> I had this working before, by bringing up an InputDialog in my
> >>> CreateCommand, but I really wanted to get this information before then
> >>> and just pass it to the command. But when I call the InputDialog from
> >>> the getCreateCommand(), the dialog just pops up over and over. I
realize
> >>> it keeps popping up because every time I move the mouse, this method
> >>> gets called. My question is what is the best way to get information
from
> >>> the user before an object is created?
> >>>
> >>> thanks so much!
> >>>
> >>> Barry
> >>
> >>
> >>
> >>
|
|
|
Goto Forum:
Current Time: Sun Jan 19 21:18:55 GMT 2025
Powered by FUDForum. Page generated in 0.03429 seconds
|