Announcement

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

    Tab Title Formatter

    Hi Isomorphic,

    We have a requirement that requires allowing a particular tab title to be edited by a user (via double-clicking the tab), which could feasibly include any kind of characters, including HTML special characters, of which, should be escaped when displayed outside of tab title edit mode.

    The user must be able to re-edit the title, and when re-editing the title (via double click on tab), the user must be presented with the raw, original value, not an escaped value. Therefore, the tab title cannot be escaped prior to setting it on the tab.
    We need some kind of title formatter capability that would allow us to escape the title for read only display, however, when in tab title edit mode, display the original, raw, unescaped value for continued editing.

    So far, we have been unable to find a solution, can you please provide some guidance?

    Thank you kindly.

    SmartClient Version: v10.1p_2017-03-11/Pro Deployment (built 2017-03-11)

    #2
    Why wouldn't you simply keep an unescaped copy of the title around and use that when editing starts? Are we missing something?

    Comment


      #3
      Hi Isomorphic,
      That was my original attempt at a workaround, however, I could not find a way to populate the editor with the original value when the editing starts/editor appears. A bit of guidance here would be much appreciated.
      Thanks

      Comment


        #4
        You could install a ValueFormatter and ValueParser on the titleEditor AutoChild to inject the original (unformatted) value and re-add escaping on parse.

        Comment


          #5
          Thank you for the suggestion, I will give it a try.

          Comment


            #6
            Hi Isomorphic,

            Some follow up questions.

            1) I couldn't see where you would specify a ValueParser on the TextItem autoChild. I have considered using an EditorExitHandler instead.

            2) The ValueFormatter didn't appear to fire for me, so I used the EditorEnterHandler.

            3) Since the titleEditor is on the TabSet, I don't seem to have any information as to which tab is being edited, for example in the onEditorEnter, to populate the original (unformatted) value, I would need to know which tab, so I can obtain the original value attribute from that tab.


            Thanks

            Comment


              #7
              Hi Isomorphic,

              All I need to do is check which Tab is currently selected by the TabSet. Not sure why that didn't come to mind earlier. :)

              Regards

              Comment


                #8
                Hi Isomorphic,

                I have implemented it using the EditorEnterHandler and EditorExitHandler on the titleEditor autoChild TextItem.

                It appears to be working as desired.

                Code:
                        TextItem titleEditor = new TextItem();
                        titleEditor.addEditorEnterHandler(new EditorEnterHandler() {
                
                            @Override
                            public void onEditorEnter(EditorEnterEvent event) {
                                Tab currentTab = tabSet.getSelectedTab();
                                String originalTitle = currentTab.getAttribute("originalTitle");
                                event.getItem().setValue(originalTitle);
                            }
                        });
                        titleEditor.addEditorExitHandler(new EditorExitHandler() {
                
                            @Override
                            public void onEditorExit(EditorExitEvent event) {
                                Tab currentTab = tabSet.getSelectedTab();
                                String originalTitle = SharedUtils.toString(event.getValue());
                                currentTab.setTitle(StringUtil.asHTML(originalTitle));
                                currentTab.setAttribute("originalTitle", originalTitle);
                            }
                        });
                        tabSet.setAutoChildProperties("titleEditor", titleEditor);
                Regards
                Last edited by stonebranch2; 3 Aug 2017, 13:46.

                Comment


                  #9
                  This approach looks fine. The formatter/parser approach we recommended early would use setEditorValueFormatter() and setEditorValueParser(), which are APIs on FormItem, inherited by TextItem.

                  Comment


                    #10
                    Thank you for the feedback and clarification.

                    Comment

                    Working...
                    X