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

Bug 307748

Summary: [design] dynamically open a view in a placeholder tab doesn't work
Product: [RT] RAP Reporter: Holger Staudacher <holger.staudacher>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: martijn.cremer
Version: 1.3   
Target Milestone: 1.3 M7   
Hardware: All   
OS: All   
Whiteboard:

Description Holger Staudacher CLA 2010-03-31 11:19:44 EDT
The code bellow works fine in RCP and in RAP however. When I use a design based on the org.eclipse.rap.design.example the tab bar whit the different views only updates when I set focus to it and not on its own.

Here is the code to reproduce:

public class OpenDetailViewHandler extends AbstractHandler implements IHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {

		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IWorkbenchPage page = window.getActivePage();
		UniversalTreeTableView universalTreeTableView = (UniversalTreeTableView) page.findView(UniversalTreeTableView.ID);

		ISelection selection = universalTreeTableView.getSite().getSelectionProvider()
				.getSelection();
		if (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()) {
			Object obj = ((IStructuredSelection) selection).getFirstElement();

			if (obj != null) {
				try {
					page.showView("com.remainsoftware.incedents.ui.view.UniversalDetailView",  UniversalTreeTableView.ID + ";" + obj.toString(), IWorkbenchPage.VIEW_CREATE);
				} catch (PartInitException e) {
					System.out.println(e.getStackTrace());
				}
			}
		}
		
		return null;
	}
}
Comment 1 Martijn Cremer CLA 2010-04-06 04:44:06 EDT
There is a simple way to work around it (but its not user friendly seeing you force the focus of the newly opend item). Here is the code of the handler:

public class OpenDetailViewHandler extends AbstractHandler implements IHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		//Get the view	
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IWorkbenchPage page = window.getActivePage();
		UniversalTreeTableView universalTreeTableView = (UniversalTreeTableView) page.findView(UniversalTreeTableView.ID);
		
		//Get the selection
		ISelection selection = universalTreeTableView.getSite().getSelectionProvider()
				.getSelection();
		if (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()) {
			Object obj = ((IStructuredSelection) selection).getFirstElement();
			
			//If we had a selection lets open the Detail view.
			if (obj != null) {
				try {
					page.showView("com.remainsoftware.incedents.ui.view.UniversalDetailView2",  UniversalTreeTableView.ID + ";" + obj.toString(), IWorkbenchPage.VIEW_CREATE);
					
					// Workaround for not getting the new View straigt in the tab we set focus 2 it.
					page.showView("com.remainsoftware.incedents.ui.view.UniversalDetailView2",  UniversalTreeTableView.ID + ";" + obj.toString(), IWorkbenchPage.VIEW_ACTIVATE);
				} catch (PartInitException e) {
					System.out.println(e.getStackTrace());
				}
			}
		}
		
		return null;
	}
}
Comment 2 Holger Staudacher CLA 2010-04-06 04:54:02 EDT
The created parts are added to the StackPresentation correctly. A Tab (button) was created, too. So, the thing is that a relayout is needed to display the new part's tab (button). 

@martijn please feel free to reopen the bug if the error still exist for your usecase. 

Fixed and committed to CVS HEAD.