Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Question about customizing PickTreeItem

    SmartClient Version: v10.0p_2015-05-19/LGPL Development Only (built 2015-05-19)

    I am using a PickTreeItem and the drop down menu that displays seems to have space for some type of image on the left (see attached screen shot).

    I'd like to hide this image column, but I can't seem to find a way to do it using any of the setShowXxx() methods on PickTreeItem. Is there a way to hide this so I don't have all that empty space on the left?
    Attached Files

    #2
    That space is the iconField of the Menu created by the TreeMenuButton that IPickTreeItem uses.

    Currently, a chain of calls like pickTreeItem.getCanvas().getMenu().hideField("icon") would allow you to get to this menu after it's first been shown and get rid of the icon field.

    To make this simpler, we'll look at documenting the auto-generated Menu as an AutoChild of TreeMenuButton.

    Comment


      #3
      This is not working for me. I'm not certain when I can make these calls.

      I tried doing this when I construct my PickTreeItem, but at that time getCanvas() returns null.

      I am stylizing my button so me code looks like this in my class derived from PickTreeItem:

      Code:
      TreeMenuButton button = new TreeMenuButton();
      button.setBaseStyle("pm-darkPickTreeMenuButton");
      button.setMenuButtonImage("[SKINIMG]Product/SelectItem/dark/button.png");
      button.setIconWidth(18);
      button.setIconHeight(6);
      button.setWidth(20);
      button.setHeight(20);
      changeAutoChildDefaults("button", button);
      So I tried adding button.getMenu().hideField("icon") to this, but that blows up because getMenu() returns null.

      I've even tried adding a DrawHandler to button and doing in the draw handler. However in this case, getCanvas() is no longer null, but getMenu() still is.

      At what point will these calls work? What can I trigger off of to make these calls?

      Comment


        #4
        I was able to deal with this by adding the following line to my code:

        Code:
        button.setMenuConstructor(PMDarkPickTreeMenu.class.getName());
        Registering my class, and implementing it as in the attached file. The key being to reconfigure the menu in its onDraw method.

        Although this works, it seems cumbersome. Is there a better way?
        Attached Files

        Comment


          #5
          I spoke too soon. This is not working for me either. If I override the menu class, then for some strange reason I get the following error when it tries to display the nested menu items and then selecting items in the pick tree does nothing. Possible something else I'm doing wrong, but the end result is I still don't have a working solution.

          Comment


            #6
            As we mentioned previously, you would have to wait for the menu to be shown. So your first attempts would not be expected to work.

            As far as your most recent attempt, it looks like you intended to post an error message but forgot to.

            Comment


              #7
              So is the way I did it the correct way to be able to tell when the menu is first shown or is there a more direct approach?

              Comment


                #8
                When I define the derived menu class that I attached earlier and set the menu constructor to this class on the TreeMenuButton (see attached file), I get the following exception:

                Code:
                08:32:21.371 [ERROR] [com.hp.cp.pm.gwt.linker.PMLinker] 08:32:21.369:TMR9:WARN:Log:Object {} cannot be registered with a null ID
                
                com.smartgwt.client.core.JsObject$SGWT_WARN: 08:32:21.369:TMR9:WARN:Log:Object {} cannot be registered with a null ID
                    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
                    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
                    at java.lang.reflect.Constructor.newInstance(Unknown Source)
                    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
                    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
                    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
                    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:341)
                    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:222)
                    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:137)
                    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:589)
                    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:315)
                    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
                    at com.smartgwt.client.util.SC.logWarn(SC.java)
                    at com.smartgwt.client.util.IDManager.registerID(IDManager.java:121)
                    at com.smartgwt.client.widgets.BaseWidget.internalSetID(BaseWidget.java:453)
                    at com.smartgwt.client.widgets.BaseWidget.setJavaScriptObject(BaseWidget.java:156)
                    at com.smartgwt.client.widgets.Img.<init>(Img.java:140)
                    at com.smartgwt.client.widgets.ImgValueType.newInstance(ImgValueType.java:30)
                    at com.smartgwt.client.widgets.ImgValueType.newInstance(ImgValueType.java:1)
                    at com.smartgwt.client.bean.types.JsoWrapperValueType.convertFrom(JsoWrapperValueType.java:108)
                    at com.smartgwt.client.bean.types.CanvasBaseValueType.convertFrom(CanvasBaseValueType.java:91)
                    at com.smartgwt.client.bean.types.CanvasBaseValueType.convertFrom(CanvasBaseValueType.java:89)
                    at com.smartgwt.client.bean.types.CanvasBaseValueType.convertFrom(CanvasBaseValueType.java:1)
                    at com.smartgwt.client.bean.BeanMethod.setProperty(BeanMethod.java:83)
                    at com.smartgwt.client.bean.BeanProperty.setProperty(BeanProperty.java:73)
                    at com.smartgwt.client.bean.BeanFactory.doSetProperty(BeanFactory.java:1402)
                    at com.smartgwt.client.bean.BeanFactory.doSetProperty(BeanFactory.java:1396)
                    at com.smartgwt.client.bean.BeanFactory.doSetProperties(BeanFactory.java:1420)
                    at com.smartgwt.client.bean.BeanFactory.setProperties(BeanFactory.java:1004)
                    at com.smartgwt.client.widgets.BaseWidget.applyFactoryProperties(BaseWidget.java:573)
                    at com.smartgwt.client.bean.BeanFactoryForBaseWidget.applyFactoryProperties(BeanFactoryForBaseWidget.java:105)
                    at com.smartgwt.client.bean.BeanFactoryForBaseWidget.applyFactoryProperties(BeanFactoryForBaseWidget.java:1)
                    at com.smartgwt.client.bean.BeanFactory.newInstance(BeanFactory.java:1320)
                    at com.smartgwt.client.bean.BeanFactory.newInstance(BeanFactory.java:1286)
                    at com.smartgwt.client.bean.BeanFactory.newInstance(BeanFactory.java:877)
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
                    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
                    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
                    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:341)
                    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:222)
                    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:137)
                    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:589)
                    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:293)
                    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
                    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
                    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:299)
                    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
                    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                    at java.lang.reflect.Method.invoke(Unknown Source)
                    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
                    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:72)
                    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
                    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:296)
                    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:551)
                    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:368)
                    at java.lang.Thread.run(Unknown Source)
                The only difference between not getting this error and getting it, is whether or not the button.setMenuConstructor(PMDarkPickTreeMenu.class.getName()) line is commented out or not.
                Attached Files

                Comment


                  #9
                  I should have been more clear...

                  I have create a Tree that had one root item and two root parent items. Each of the parent items has one child.

                  When I click on the PickTreeItem the root elements show. As I move mouse down, it moves over the first root item and then over the first root parent item. At the point where it moves over the first root parent item, the parent's child item shows and it is during this activity that the exception occurs.

                  Normally when I select the child of the first root parent item the value in the PickTreeItem control changes to this value. However if I get this exception, selecting the child puts the menus away, but does not change the value displayed in the PickTreeItem.

                  Note this all works fine until I call setMenuConstructor.

                  Comment


                    #10
                    Using setMenuConstructor() would require you to register your class for Reflection, which it doesn't seem like you've done (at least, not in these test files).

                    But again, this wasn't what we suggested - if you don't want to wait for the AutoChild APIs here, you should be able to just add a click handler for the TreeMenuButton and be able to access the auto-created menu there, instead of trying to replace it's class.

                    Comment


                      #11
                      Although I didn't include the module, I am registering my class for Reflection.

                      I tried your suggestion of the click handler. When I get into the onClick handler, getCanvas() returns a reference to the PickTreeItem, but a call to getMenu() at this time returns null.

                      Comment


                        #12
                        We were able to reproduce the problem and see the warning. We're looking into the best way to resolve it and will update this thread when there's new information.

                        Comment


                          #13
                          In the meantime, about the approach that should work with existing APIs - you probably meant that getCanvas() returned a TreeMenuButton. It's not clear where you installed the ClickHandler, but the TreeMenuButton is the right place.

                          With the ClickHandler in the right place, you should not, at that point, receive null from getMenu(), since the menu is displayed synchronously on mouseDown. However, if you somehow do, using a 0ms timeout with Scheduler should allow you to call getMenu() without getting a null.

                          Comment


                            #14
                            The null ID warning (related to BeanFactory) should now be resolved. The misbehavior you reported was actually unrelated - to solve it you'll need to extend SelectionTreeMenu (which we've just exposed) rather than Menu when defining PMDarkPickTreeMenu, since that's the button class used internally by TreeMenuButton. These changes will be in the nightly builds for SGWT 5.0p and newer dated 5-27-2015.

                            Comment


                              #15
                              Well, you're correct that this fixed my issue of hiding the icon column. However, just rolling to the new version (with no code changes at all) broke most of my other menus. They are too narrow now. See attached screen shot.
                              Attached Files

                              Comment

                              Working...
                              X