1

Tab Header switches but not "Whole Tab".

asked 2016-02-24 19:23:06 +0800

Princenuk gravatar image Princenuk
29 5

updated 2016-03-02 16:02:59 +0800

I have Java Code for The Tabs to switch, however when they switch in the Application, only the headers switch and not the content. The code:

public Tab createTab( String id,  String title){
    final Tab tab = new Tab();

    tab.setId( "tab_" + id);
    tab.setLabel(title);
        tab.setDraggable("true");
    tab.setDroppable("true");
    tab.setClosable(true);
    tab.setParent( getTabs());

    tab.addEventListener(Events.ON_DROP, new EventListener(){
        public void onEvent(Event event) {
            DropEvent dropEvent = (DropEvent)event;
            Tab tab =(Tab)dropEvent.getDragged();
            Component tabs = tab.getParent();
            tabs.removeChild(tab);
            tabs.appendChild(tab);
            tab.setSelected(true);
        }
        });

    return tab;     
}

When closed, the whole Tab closes both the Header and the content, however when Dragged and Dropped only the header moves and takes the place of the other Tab so now the Tab has a different header/Name but the same content.

Hi Chill,

I added the tabpanels like so (Is this how I switch the tabpanels?):

public void onEvent(Event event) {
            DropEvent dropEvent = (DropEvent)event;
            Tab tab =(Tab)dropEvent.getDragged();
            Tabpanel tabpanel = (Tabpanel)dropEvent.getDragged();
            Component tabs = tab.getParent();
            Component tabpanels = tabpanel.getParent();
            tabs.removeChild(tab);
            tabs.appendChild(tab);
            tabpanels.removeChild(tabpanel);
            tabpanels.appendChild(tabpanel);
            tab.setSelected(true);
        }
        });

However I get "org.zkoss.zul.Tab cannot be cast to org.zkoss.zul.Tabpanel" , which makes sense but I need it to treat the Tab & Tabpanel as one entity like it does with tab.setClosable(true) but its treating it as 2 different entities and I cant drag and drop tabpanels in this application.

The create tab class above is how each tab is generated and all the definitions inside are assigned to each tab, there is no zul file for the tab per sey if that makes sense.

delete flag offensive retag edit

Comments

I am not sure I added the tabpanels correctly.

Princenuk ( 2016-02-25 18:23:22 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-02-24 21:46:00 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2016-03-02 16:19:58 +0800

You need to switch the tabpanels to. Just fetch them on their index. They have same index as the tab.

Update:

Oke, I maybe didn't explain it correct.
I don't have an IDE at the moment to make 100% working code but this is what you should do :

int index = tab.getIndex();
Component tabs = tab.getParent();
tabs.removeChild(tab);
tabs.appendChild(tab);
Tabpanels panels = tabs.getParent().getTabPanels(); // maybe extra casting here
Tabpanel panel = panels.getChildren().get(index);
panels.removeChild(panel);
panels.appendChild(panel);

Update 2:

Created a fiddle for it.

Update 3:

public void onEvent(Event event) {
      DropEvent dropEvent = (DropEvent)event;
      Tab dragged = (Tab)dropEvent.getDragged();
      Tab target = (Tab)dropEvent.getTarget();
      if (dragged.getIndex() > target.getIndex()) {
        Tabpanel drag = dragged.getLinkedPanel();
        Tabpanel drop = target.getLinkedPanel();
        Tabpanels panels = (Tabpanels)drag.getParent();
        panels.getChildren().remove(drag);
        panels.getChildren().add(panels.getChildren().indexOf(drop),drag);
        dragged.getParent().insertBefore(dragged, target);
        panels.invalidate();// strange behavior when I don't do this
      } else {
        Tabpanel drag = dragged.getLinkedPanel();
        Tabpanel drop = target.getLinkedPanel();
        Tabpanels panels = (Tabpanels)drag.getParent();
        panels.getChildren().remove(drag);
        panels.getChildren().add(panels.getChildren().indexOf(drop)+1,drag);
        Tabs tabs = (Tabs)dragged.getParent();
        tabs.getChildren().remove(dragged);
        tabs.getChildren().add(tabs.getChildren().indexOf(target)+1,dragged);
        panels.invalidate(); // strange behavior when I don't do this
      }
      dragged.setSelected(true);
    }
});

Greetz chill

link publish delete flag offensive edit

Comments

What are your thoughts on the error message?

Princenuk ( 2016-02-26 15:30:32 +0800 )edit

The Tabs move when I removed "DropEvent dropEvent = (DropEvent)event; Tab tab =(Tab)dropEvent.getDragged();" I had to add extra casting to compile. The only two issues left, Is I can only move right to left and If there are 4 tabs I have to move one tab 3 times to get it to the other end.

Princenuk ( 2016-02-29 16:27:59 +0800 )edit

Jip that's because you don't look at the dropplace or beter said drop tab. If you look at that you can use insertbefore or insertafter, depending if you go left or right. I think somewhere on the forum there is such code from me.

chillworld ( 2016-02-29 17:33:48 +0800 )edit

Ok I will look for it , thanks.

Princenuk ( 2016-02-29 18:03:47 +0800 )edit

I can't find it but if you can't figure it out I'll rewrite it again. I know I look at index the 2 indexes to see if it was left to right or right to left dragged. If you know that you can use insertbefore(right to left) or insertafter(left to right).

chillworld ( 2016-03-01 10:04:26 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-02-24 19:23:06 +0800

Seen: 27 times

Last updated: Mar 02 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More