Specifying the perspective layout

The layout of the perspective can be specified by configuring an XML file. The path of this file can be set in extension points. BTT also provides a pre-activity for you to launch an activity before the perspective is initialized. This activity is to specify which perspective definition file will be used. Different definition files lead to different perspective layouts.

For more information about the parameters of BTT Rich Client Perspective Definition extension point, refer to the documentation of extension point.

  1. Define the user01.xml file which describes the perspective layout.
    <perspectiveDef>
    	<view id="com.ibm.btt.rcp.views.NavigatorView" relationship="left" ratio="1.0" refId="editarea" />
    	<folder id="integration" relationship="right" ratio="0.28" refId="com.ibm.btt.rcp.views.NavigatorView">
    		<page id="com.ibm.btt.rcp.views.WorkingAreaView:com.ibm.btt.rcp.sample.ExcelActivity" holder="true"/>
    		<page id="com.ibm.btt.rcp.views.WorkingAreaView:com.ibm.btt.rcp.sample.website" holder="true"/>
    	</folder>
    	<folder id="workarea" relationship="bottom" ratio="0.4" refId="integration">
    		<page id="com.ibm.btt.rcp.views.WorkingAreaView:com.ibm.btt.rcp.sample.logo" holder="true" moveable="false" closeable="false"/>
    		<page id="com.ibm.btt.rcp.views.WorkingAreaView:*" holder="true"/>		
    	</folder>
    </perspectiveDef>

    Three tags are defined in this configuration file: view, folder and page. Page is a kind of special view to hold in the folder. All the attributes are designed to map the eclipse perspective layout definition.

    Following are the attributes in the layout configuration files:
    • id: required. The id of the view.
    • refId: required. The referred view id in order to identify the position. The value editarea is the whole area of this perspective.
    • relationship: required. The relationship between this component and the referred component. Valid values are left, right, top and bottom.
    • showTitile: optional. If this view shows its title. The default value is true.
    • standalone: optional. If this view is standalone. The default value is false.
    • holder: optional. If this view should be displayed at first. The default value is true. True means not to display at first but hold a space for it to display.
    • closeable: optional. If this view can be closed. The default value is true.
    • moveable: optional. If this view can be moveable. The default value is true.
  2. Define the project’s plugin.xml file.
    Make sure these 2 extensions exit without error.
       <extension
             point="org.eclipse.ui.perspectives">
          <perspective
                class="com.ibm.btt.rcp.perspective.ui.Perspective"
                id="com.ibm.btt.rcp.sample.perspective"
                name="BTT RCP Sample"/>
       </extension>
       <extension point="com.ibm.btt.rcp.perspective.perspectiveDef">
       	  <define
                perspective="com.ibm.btt.rcp.sample.perspective"
                preActivity="com.ibm.btt.rcp.sample.PerspectiveActivity"/>
       </extension>
  3. Dynamically assign different perspective to different user by implementing PerspectiveActivity.java. ServiceManager.getPerspectiveRegistry().setDefinitionPath() can be called in PerspectiveActivity to change the perspective dynamically according to user name, user role etc.
    public class PerspectiveActivity extends Activity {
    
    	public void dispose() {
    	}
    
    	public void run() {
    		SignInDialog dlg = new SignInDialog(Display.getCurrent()
    				.getActiveShell());
    		if (dlg.open() == Window.OK) {
    			String userName = Activator.getDefault().getCurrentUser();
    			try {
    				//different user name, using different perspective definition file
    				URL url = Activator.getDefault().getBundle().getResource(
    						"/" + userName + ".xml");
    				ServiceManager.getPerspectiveRegistry().setDefinitionPath(
    						FileLocator.toFileURL(url).getPath());
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		} 
    	}
    }