thegreatjedi
thegreatjedi

Reputation: 3038

How do I close a tab in Eclipse using Javascript?

I am currently modernising some plugin modules from version 2.x to the OSGi-based 4.x. This project uses the Eclipse application and takes advantage of its view & perspective architecture to serve as a tabbed browser.

Studying the old code and running the Eclipse application, this is what I understand to be the expected behaviour of one particular functionality:

Most of the above works as intended, however instead of closing just that one tab, clicking either button causes the entire Eclipse application to attempt to terminate (I received a confirmation prompt asking if I want to exit Eclipse). The submit button did successfully update submitted info into the database before attempting to terminate the Eclipse application.

This is what the offending part of the code looks like:

function onSubmit() {
    //processForm();
    if (opener) {
        opener.newAddressValue(newToAddress);
        window.close();
    } else if (parent.parent) {
        parent.parent.newAddressValue(newToAddress);
        parent.parent.closeUsrFrame();
    } else {
        parent.newAddressValue(newToAddress);
        parent.closeUsrFrame();
    }
}            
function onCancel() {
    if (opener) {
        window.close();
    } else {
        parent.closeUsrFrame();
    }
}

I suspect the expected behaviour is for program flow to reach window.close() at which point the tab containing the opened panel should close, but instead it is causing the entire Eclipse application to terminate. What is the correct way to exit the current tab in Eclipse 4.x using JavaScript?

Upvotes: 2

Views: 91

Answers (1)

Beck Yang
Beck Yang

Reputation: 3024

If the program display a HTML file using SWT Browser widget, you can use Browser.addCloseWindowListener(CloseWindowListener listener) to hook the event that triggered by javascript window.close.

If your program do prompt about exiting Eclipse, you shall search class that implement CloseWindowListener interface. Modify its behavior as you wished.

Upvotes: 0

Related Questions