javafxeclipse-rcprcpe4efxclipse

Checking if a Part inside of a PartStack was closed by pressing the close icon on the corresponding tab


Platform: Windows 8.1 Pro, E4 with e(fx)clipse

I'm currently working on caching opened Parts to reopen then when reloading the PartStack. This reloading method uses EPartService.hidePart() to close all Parts in the PartStack. Since I also need to remove Parts from the cache, I need to differentiate between reloading and actually closing a tab/Part.

I already tried to add the part to the cache a second time before removing it again by sending an event from the preDestroy() method of the Part. But this is less than ideal.

Is there a special event I can catch when clicking on the close icon or another way I could check for this?

Thanks for your help.


Solution

  • Turns out, the easiest way to do what I wanted to do was to use tags. Since I could only access the code for when the Part was closed by the program, I needed to set a tag on the part.

    if (part.isDirty()) {
        if(!partService.savePart(part, true)) {
            return;
        }
        part.getTags().add(Tag.PART_CLOSED_BY_PROGRAM);
        partService.hidePart(part);
        } else if (part.isCloseable()) {
            part.getTags().add(Tag.PART_CLOSED_BY_PROGRAM);
            partService.hidePart(part);
        }
    }
    

    Now I can just check in the preDestroy() method if the Part is being closed by the program or by the user.

    @PreDestroy
    protected void preDestroy() {
        if (part.getTags().contains(Tag.PART_CLOSED_BY_PROGRAM)) {
            part.getTags().remove(Tag.PART_CLOSED_BY_PROGRAM);
        } else {
            try {
                //remove "Part" from cache
            } catch (IllegalAccessException e) {
            } catch (InvocationTargetException e) {
            } catch (NoSuchMethodException e) {
            }
        }
    }