Announcement

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

    TabSet (close other tabs feature)

    Hello, guys!

    I need to implement a part of web app. functionality:
    When i'm clicking the right mouse button I need to close all tabs that is not under mouse pointer now ("close other tabs").

    BUT! Not -- "selected" tab (result of tabset.getSelectedTab()) must stay alive,
    but "tab that mouse pointer aimed on".

    Environment: SmartGWT 2.2.

    Anyone have an idea how can I reach that?

    #2
    Here's some code for you to base on.
    It creates a MenuItem which you can put in a Menu and add it as control on your TabSet.

    - It checks if the menu item is enabled (at least one tab must be closeable).
    - The onClick removes all other tabs but the selected one.


    Code:
    staticTabMenu[1] = new MenuItem("Close Others");
    staticTabMenu[1].setEnableIfCondition(new MenuItemIfFunction() {
    
    	public boolean execute(Canvas target, Menu menu, MenuItem item) {
    		String selectedTab = getSelectedTab().getID();
    
    		for (Tab t : getTabs()) {
    			if (t.getID().equals(selectedTab))
    				continue;
    			if (t.getCanClose())
    				return true;
    		}
    		return false;
    	}
    });
    staticTabMenu[1].addClickHandler(new ClickHandler() {
    
    	public void onClick(MenuItemClickEvent event) {
    		String selectedTab = getSelectedTab().getID();
    
    		for (Tab t : getTabs()) {
    			if (t.getCanClose() && !t.getID().equals(selectedTab)) {
    				removeTab(t);
    			}
    		}
    	}
    });

    Comment


      #3
      A new API TabSet.addTabContextMenuHandler(..) has been added in the latest nightly that will allow you to register a context menu listener with access to the tab where the mouse has been right-clicked. See TabContextMenuEvent.getTab

      Comment

      Working...
      X