[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.gef] Re: How to get information from user in the getCreateCommand(CreateRequest request)

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(SelectEditPartTracker.java:114)
at org.eclipse.gef.internal.ui.palette.editparts.ToolEntryEditPart$OtherToggleButtonTracker.handleButtonUp(ToolEntryEditPart.java:176)
at org.eclipse.gef.tools.AbstractTool.mouseUp(AbstractTool.java:1054)
at org.eclipse.gef.tools.SelectionTool.mouseUp(SelectionTool.java:544)
at org.eclipse.gef.EditDomain.mouseUp(EditDomain.java:245)
at org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouseReleased(DomainEventDispatcher.java:359)
at org.eclipse.draw2d.LightweightSystem$EventHandler.mouseUp(LightweightSystem.java:528)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.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.java:2783)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2442)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1443)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1414)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:271)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:144)
at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:102)
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:335)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:273)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.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@xxxxxxxxxxxxxxxx> wrote in message
news:cngi25$84p$1@xxxxxxxxxxxxxxxxxx

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