Removing SingleCDockable

Hi,

i want to remove some SingleCDockable. I implement CControlListener to listen to closing Dockables.
My code looks like this:


@Override
    public void closed(CControl controlEvent, CDockable dockableEvent) {
        // TODO Auto-generated method stub
        for(int i=0; i<docks.size(); i++){
            DefaultSingleCDockable d = docks.get(i);
            if(d.intern().getTitleText().equals(dockableEvent.intern().getTitleText())){
                
                for(int j = 0; j < vectorServiceTabs.size(); j ++){
                    IFView v = vectorServiceTabs.get(j);
                    
                    String serviceName = ((DiagnosticServiceView)v).getServiceName();
                    String dockName = d.intern().getTitleText();
                    if(serviceName.equals(dockName)){
                        ((DiagnosticServiceView)v).deleteObserver(dockName);
                        vectorServiceTabs.remove(j);
                        d.setVisible(false);
                        control.remove(d);
                        removeFromControl = true;
                        break;
                    }
                }
            }
        }
    }

Now my problem is, if i have 3 Tabs open, for example: Tab 1, Tab 2, Tab 3. First i close Tab 2 than 3 and 1. Now if i want to open Tab 1, 2 and 3, it cannot be open, because that tabs are still in the Controllers list. So if i say controll.remove(dockable) it don’t gets removed from the controller list. I hope somebody can help me.

thx brainjay

My Code looks like so now


@Override
    public void closed(CControl controlEvent, CDockable dockableEvent) {
        // TODO Auto-generated method stub
//        if(dockableEvent.isDockableVisible()){
            for(int j = 0; j < vectorServiceTabs.size(); j ++){
                IFView v = vectorServiceTabs.get(j);

                String serviceName = ((DiagnosticServiceView)v).getServiceName();
                String dockName = dockableEvent.intern().getTitleText();
                if(serviceName.equals(dockName)){
                    ((DiagnosticServiceView)v).deleteObserver(dockName);
                    vectorServiceTabs.remove(j);
                    dockableEvent.setVisible(false);
                    control.remove((SingleCDockable)dockableEvent);
                    removeFromControl = true;
                    break;
                }
            }
//        }
    }

The next Problem is, sometimes the closed method is called twice. So if i want to add a tab another tab is deleted.

I do not understand what exactly your application is doing, but „ccontrol.remove“ works usually. You are certain you have not mixed up different instances of Dockables? Code like …
dockableEvent.setVisible(false);
… should not be necessary as the Dockable was just closed (the ccontorl.remove is necessary).

I think to answer your question I need you to write a small sample application that reproduces the behavior. Because your code snippets alone do not tell me where the issue lies.

The next Problem is, sometimes the closed method is called twice. So if i want to add a tab another tab is deleted.

With the same Dockable (the same instance)? That would be really be a bug.

My Code is too big to post it… Thx for your answer, i think there is a bug.
If i start my tool and i add a ControlListener the close method is getting called. Like the example above:

I open:
Tab 1
Tab 2
Tab 3

Now i switch to Tab 2:

Tab 1
Tab 2 → is active
Tab 3

If i now close tab 2 the close method is getting called twice. It looks like that:

Tab 1
Tab 2 → was removed
Tab 3 → was removed

Only Tab 1 is in the List, but Tab 1 and Tab 3 is visible. I hope you have understood me :slight_smile:

Greetz Brainjay

Ok, that explanation did help.

In your listener, add a line like this:
new IllegalStateException("bla").printStackTrace();

What is the stacktrace of the first and the second time the listener is invoked? That should help finding out which code is responsible for “closing” Tab 3.



Observers: 8
Observers: 9
Observers: 10

Closing Tab 2

java.lang.IllegalStateException: bla
    at mvc.view.DiagnosticClient.closed(DiagnosticClient.java:655)
    at bibliothek.gui.dock.common.CControl$2.dockableUnregistered(CControl.java:498)
    at bibliothek.gui.dock.control.DockRegister.fireDockableUnregistered(DockRegister.java:441)
    at bibliothek.gui.dock.control.DockRegister.unregister(DockRegister.java:363)
    at bibliothek.gui.dock.control.DockRegister$StationListener.removeDockable(DockRegister.java:668)
    at bibliothek.gui.dock.control.DockRegister$StationListener.fire(DockRegister.java:545)
    at bibliothek.gui.dock.control.DockRegister.setStalled(DockRegister.java:504)
    at bibliothek.gui.dock.common.CControl$Access.hide(CControl.java:2755)
    at bibliothek.gui.dock.common.intern.AbstractCDockable.setVisible(AbstractCDockable.java:292)
    at bibliothek.gui.dock.common.action.predefined.CCloseAction.close(CCloseAction.java:85)
    at bibliothek.gui.dock.common.action.predefined.CCloseAction$Action.close(CCloseAction.java:109)
    at bibliothek.gui.dock.facile.action.CloseAction.action(CloseAction.java:86)
    at bibliothek.gui.dock.themes.basic.action.BasicButtonHandler.triggered(BasicButtonHandler.java:48)
    at bibliothek.gui.dock.themes.basic.action.BasicButtonModel.trigger(BasicButtonModel.java:631)
    at bibliothek.gui.dock.themes.basic.action.BasicButtonModel$Listener.mouseReleased(BasicButtonModel.java:669)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
CLOSING!!!!!!!!!!!!!

----------- Here the closing Method is called the second time

java.lang.IllegalStateException: bla
    at mvc.view.DiagnosticClient.closed(DiagnosticClient.java:655)
    at bibliothek.gui.dock.common.CControl$2.dockableUnregistered(CControl.java:498)
    at bibliothek.gui.dock.control.DockRegister.fireDockableUnregistered(DockRegister.java:441)
    at bibliothek.gui.dock.control.DockRegister.unregister(DockRegister.java:363)
    at bibliothek.gui.dock.control.DockRegister$StationListener.removeDockable(DockRegister.java:668)
    at bibliothek.gui.dock.control.DockRegister$StationListener.fire(DockRegister.java:545)
    at bibliothek.gui.dock.control.DockRegister.setStalled(DockRegister.java:504)
    at bibliothek.gui.dock.common.CControl$Access.hide(CControl.java:2755)
    at bibliothek.gui.dock.common.intern.AbstractCDockable.setVisible(AbstractCDockable.java:292)
    at mvc.view.DiagnosticClient.addServiceToTab(DiagnosticClient.java:259)
    at mvc.controller.DiagnosticController.addServiceToTab(DiagnosticController.java:86)
    at mvc.view.DiagnosticTreeView.addServiceTabAndGetSubFunctions(DiagnosticTreeView.java:866)
    at mvc.view.DiagnosticTreeView.valueChanged(DiagnosticTreeView.java:922)
    at javax.swing.JList.fireSelectionValueChanged(Unknown Source)
    at javax.swing.JList$ListSelectionHandler.valueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
    at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
    at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
    at javax.swing.DefaultListSelectionModel.setSelectionInterval(Unknown Source)
    at javax.swing.JList.setSelectionInterval(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI$Handler.adjustSelection(Unknown Source)
    at javax.swing.plaf.basic.BasicListUI$Handler.mousePressed(Unknown Source)
    at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
CLOSING!!!!!!!!!!!!!



Oh sorry, it was my fault… I deleted it two times… I forgotten to set a boolean to false. That’s why it was deleting an other dockingframe. P.S. your framework rocks :slight_smile:

Good to hear, that you found the bug. There are bugs in the framework, if you ever have another suspicious behavior, please ask again :slight_smile:

P.S. your framework rocks

Thanks