Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 137527

Summary: [PresentationAPI] (regression) Implementors of StackPresentation now must implement save/restore state methods
Product: [Eclipse Project] Platform Reporter: Matthew Hatem <Matthew_Hatem>
Component: UIAssignee: Paul Webster <pwebster>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: michaelvanmeekeren, Mike_Wilson, n.a.edgar, shaun, sxenos
Version: 3.2   
Target Milestone: 3.2 RC1   
Hardware: PC   
OS: All   
Whiteboard:
Attachments:
Description Flags
Changes to PresentablePartFolder#insert(IPresentablePart, int)
none
partstack patch + example patch none

Description Matthew Hatem CLA 2006-04-19 12:13:44 EDT
In previous releases it was okay not to implement the save/restore state methods for subclasses of StackPresentation.  In recent builds, unexpected errors occur when restoring a perpsective from a previous run.  Without code that looks like the following, no views are ever added to the StackPresentation on a restore event.

    public void restoreState(IPresentationSerializer serializer,
            IMemento savedState) {
        IMemento[] parts = savedState.getChildren(IWorkbenchConstants.TAG_PART);

        for (int idx = 0; idx < parts.length; idx++) {
            String id = parts[idx].getString(IWorkbenchConstants.TAG_ID);

            if (id != null) {
                IPresentablePart part = serializer.getPart(id);

                if (part != null) {
                    addPart(part, null);
                }
            }
        }
    }

    public void saveState(IPresentationSerializer context, IMemento {

    	TabItem[] items = tabFolder.getItems();
    	ArrayList parts = new ArrayList(3);
    	for (int i=0; i<items.length; i++) {
    		parts.add(getPartForTab(items[i]));
    	}
    	
        Iterator iter = parts.iterator();
        while (iter.hasNext()) {
            IPresentablePart next = (IPresentablePart) iter.next();

            IMemento childMem = memento
                    .createChild(IWorkbenchConstants.TAG_PART);
            childMem.putString(IWorkbenchConstants.TAG_ID, context.getId(next));
        }
    }

We are fine with this change in behavior, we will update our presentation, however we should probably update the Javadoc.
Comment 1 Nick Edgar CLA 2006-04-19 16:36:10 EDT
Stefan, do you know whether this was an intentional change?
Comment 2 Matthew Hatem CLA 2006-04-19 16:44:33 EDT
I'm not sure if this problem was introduced in recent builds or if it's been there since the beginning of 3.2.

We've just recently moved to 3.2 and more recently began running tests without cleaning the runtime workspace.
Comment 3 Stefan Xenos CLA 2006-04-19 18:42:58 EDT
Looks like an unintentional regression to me.
Comment 4 Nick Edgar CLA 2006-04-20 10:00:52 EDT
So this means that existing presentation implementations out there coded against 3.0 or 3.1 will fail against 3.2 unless this is addressed.
Comment 5 Paul Webster CLA 2006-04-21 11:02:27 EDT
Matt, do you still have an error log around that you could attach to the bug?  Was it NPEs in PresentablePart?

Thanx in advance,
PW
Comment 6 Shaun Skelton CLA 2006-04-21 11:48:20 EDT
Created attachment 39175 [details]
Changes to PresentablePartFolder#insert(IPresentablePart, int)

Normally if a part already exists in the folder, insert is short circuited with a call to return. This change will add a check to see if the part should be moved before returning.
Comment 7 Matthew Hatem CLA 2006-04-21 11:57:11 EDT
There were no runtime errors to log.  The problem is that perspectives are restored but no views are added.
Comment 8 Paul Webster CLA 2006-04-23 17:09:53 EDT
Created attachment 39262 [details]
partstack patch + example patch

The PartStack should always add parts to the presentation so that they can be restored by the presentation serializer.

PW
Comment 9 Paul Webster CLA 2006-04-24 11:17:25 EDT
The PartStack was getting the parts, but not adding them to the presentation.  In the case where the presentation implemented restoreState(*), the presentation was adding the parts to itself.

Any presentation that didn't implement restoreState(*) got the default one that did nothing (so now parts got added to the presentation).

Now the part stack adds the parts to the presentation, and restoreState(*) re-orders them based on it's algorithm.

Fixed in HEAD >20060424

PW
Comment 10 Paul Webster CLA 2007-02-06 11:16:18 EST
bookkeeping