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

Bug 72383

Summary: [Perspectives] Placeholder folder error with multiple instance views
Product: [Eclipse Project] Platform Reporter: Marco Maccaferri <m_maccaf>
Component: UIAssignee: Nick Edgar <n.a.edgar>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: douglas.pollock, michaelvanmeekeren
Version: 3.0   
Target Milestone: 3.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Marco Maccaferri CLA 2004-08-21 07:08:09 EDT
MyViewId is a view with the allowMultiple flag set to true.
The following code in my IPerspectiveFactory implementation:
 
  public void createInitialLayout(IPageLayout layout)
  {
    layout.setEditorAreaVisible(false);
    IPlaceholderFolderLayout folder = layout.createPlaceholderFolder("book",
IPageLayout.LEFT, 0.27f, IPageLayout.ID_EDITOR_AREA);
    folder.addPlaceholder("MyViewId:*");
  }
 
Causes the following message:
 
!MESSAGE Unable to find view label: MyViewId:*

and the view's placement doesn't work.
 
I digged a bit on the source code and found that the addPlaceholder method for
the FolderPlaceholderLayout class doesn't verify if the view id is in the form
viewId:secondaryId, thus failing.
Comment 1 Randy Mays CLA 2004-08-23 15:19:25 EDT
I have this exact problem. I need to create a placeholder folder where the 
folder will contain multiple instances of two different views. Is there any 
plan to fix this in the near future or is there a known workaround?

I tried placing the id in the plugin.xml file twice, with and without the 
multiple instance wildcard ("primaryId" and "primaryId:*") so that the 
folder.addPlaceholder() would find what it needs, but I obviously then get the 
view showing up twice in the "Show Views" menu item. I've read all the history 
of bug ids 31612 and 56431.

Any suggestions would be helpful.

Thanks.
Comment 2 Nick Edgar CLA 2004-08-23 15:34:42 EDT
Added fixes to the addPlaceholder methods in PageLayout, PlaceholderFolderLayout
and FolderLayout.
They now all call PageLayout.checkValidPlaceholderId(String id) which is as follows.

    /**
     * Checks whether the given id is a valid placeholder id.
     * A placeholder id may be simple or compound, and can optionally contain a
wildcard.
     * 
     * @param id the placeholder id
     * @return <code>true</code> if the given id is a valid placeholder id,
<code>false</code> otherwise
     */
    boolean checkValidPlaceholderId(String id) {
        // Check that view is not already in layout.
        // This check is done even if the id has a wildcard, since it's
incorrect to create
        // multiple placeholders with the same id, wildcard or not.
        if (checkPartInLayout(id)) {
            return false;
        }

        // check that primary view id is valid, but only if it has no wildcard
        String primaryId = ViewFactory.extractPrimaryId(id);
        if (!ViewFactory.hasWildcard(primaryId)) {
	        IViewRegistry reg = WorkbenchPlugin.getDefault().getViewRegistry();
	        IViewDescriptor desc = reg.find(primaryId);
	        if (desc == null) {
	            // cannot safely open the dialog so log the problem
	            WorkbenchPlugin.log("Unable to find view with id: " + primaryId);
//$NON-NLS-1$
	            return false;
	        }
        }

        return true;
    }

Also added regression tests in IWorkbenchPageTest:
- testOpenPerspectiveWithMultiViewPlaceholdersAtTopLevel()
- testOpenPerspectiveWithMultiViewPlaceholdersInPlaceholderFolder()
- testOpenPerspectiveWithMultiViewPlaceholdersInFolder()
Comment 3 Nick Edgar CLA 2004-08-23 15:36:22 EDT
Re comment #1, I don't see any workaround.
Comment 4 Nick Edgar CLA 2004-09-02 12:23:21 EDT
This should go into 3.0.1 as well.
Comment 5 Michael Reitz CLA 2004-09-03 05:17:34 EDT
It works fine in Integration Build: I20040901 but not in Eclipse 3.0

Here is my piece of code:
IPlaceholderFolderLayout docs = layout.createPlaceholderFolder("docs",
IPageLayout.RIGHT, 0.5f, "results");
docs.addPlaceholder(DocumentView.ID_VIEW + ":*");
docs.addPlaceholder(BrowserView.ID_VIEW + ":*");
Comment 6 Nick Edgar CLA 2004-09-07 14:50:48 EDT
Patch released to 3.0.1.
Comment 7 Nick Edgar CLA 2004-09-09 16:55:00 EDT
Verified in M20040908 using modified browser example.
Plus the tests pass.