Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Master block in forms
Master block in forms [message #697889] Mon, 18 July 2011 09:40
mousa.alsulaimi is currently offline mousa.alsulaimiFriend
Messages: 18
Registered: June 2011
Junior Member
hello , I'm facing a problem when using master details pattern in a from , spseficly when i put the master block in a form section and then i compact it .. when i do that the application throws a nullPointer exception . can some help tell me what im doing wrong ........ here is my code .

this is the main form :

package com.capmtech.financial.forms;

import org.eclipse.swt.widgets.Composite;

public class GardianDetailsForm extends FormPage {

	/**
	 * Create the form page.
	 * @param id
	 * @param title
	 */
	public GardianDetailsForm(String id, String title) {
		super(id, title);
	}

	/**
	 * Create the form page.
	 * @param editor
	 * @param id
	 * @param title
	 * @wbp.parser.constructor
	 * @wbp.eval.method.parameter id "Some id"
	 * @wbp.eval.method.parameter title "Some title"
	 */
	public GardianDetailsForm(FormEditor editor, String id, String title) {
		super(editor, id, title);
	}

	/**
	 * Create contents of the form.
	 * @param managedForm
	 */
	@Override
	protected void createFormContent(IManagedForm managedForm) {
		FormToolkit toolkit = managedForm.getToolkit();
		ScrolledForm form = managedForm.getForm();
		form.setText("Empty FormPage");
		Composite body = form.getBody();
		toolkit.decorateFormHeading(form.getForm());
		toolkit.paintBordersFor(body);
		GuardianMasterDetails mster = new GuardianMasterDetails(); 
		mster.createContent(managedForm, form.getBody()) ; 
		
	}

}


this is the Master block that im calling from the main form :

package com.capmtech.financial.forms;

import java.util.ArrayList;

public class GuardianMasterDetails extends MasterDetailsBlock  implements IDetailsPageProvider{
private HashMap<String, IDetailsPage> detailsMap = new HashMap<String, IDetailsPage>() ; 
	private FormToolkit toolkit;

	/**
	 * Create the master details block.
	 */
	public GuardianMasterDetails() {
		// Create the master details block
		System.out.println("constructor");
	}

	/**
	 * Create contents of the master details block.
	 * @param managedForm
	 * @param parent
	 */
	private ArrayList<Object> myList= new ArrayList<Object>() ;
	private SectionPart spart = null ;  
	private IManagedForm managed =null ;
	private TableViewer viewer ; 
	
	@Override
	protected void createMasterPart(IManagedForm managedForm, Composite parent) {
		managed=managedForm ; 
		 
		
		toolkit = managedForm.getToolkit();
			
		Section section = toolkit.createSection(parent,
				Section.TWISTIE| ExpandableComposite.TITLE_BAR);
		section.setText("Gardian Type :");
		//
		Composite composite = toolkit.createComposite(section, SWT.NONE);
		toolkit.paintBordersFor(composite);
		section.setClient(composite);
		composite.setLayout(new GridLayout(5, false)) ; 
		Table table = managedForm.getToolkit().createTable(composite, SWT.BORDER) ;
		table.setHeaderVisible(false) ; 
		table.setLinesVisible(false) ; 
		 viewer = new TableViewer(table) ; 
		TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE, 0) ; 
		viewerColumn.setLabelProvider(new ColumnLabelProvider() {
			@Override
			public String getText(Object element) {
			if(element instanceof String)
				return (String) element ;
			else if(element instanceof Integer)
				return "Institutional Gardian" ;
			return "";
			}

			
			
		});
		
		
		
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
			
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				// TODO Auto-generated method stub
				managed.fireSelectionChanged(spart, event.getSelection()) ; 
			}
		}); 
		 spart = new SectionPart(section) ; 
		 
		table.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,true , 4, 10)) ; 
		viewerColumn.getColumn().setResizable(false) ; 
		viewerColumn.getColumn().setWidth(200) ; 
		viewer.setContentProvider(new ArrayContentProvider()) ; 
		viewer.setInput(myList.toArray()) ;
		Button addNewContactPerson = managedForm.getToolkit().createButton(composite, "add new ConactPerson ", SWT.None) ; 
		addNewContactPerson.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,false , 1 ,1)) ; 
		addNewContactPerson.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub
				myList.add("Contact person "+(int)(myList.size()+1)) ; 
				System.out.println("click click ");
				viewer.setInput(myList.toArray()) ;
				viewer.refresh(); 
				
			}
			
			@Override
			public void mouseDown(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseDoubleClick(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
		})  ; 
		
		
	
		Button removeContactPerson = managedForm.getToolkit().createButton(composite, "remove Conact Person ", SWT.None) ; 
		removeContactPerson.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,false , 1 ,1)) ; 
		removeContactPerson.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub
			
				System.out.println("click click ");
				String selected = (String)(((IStructuredSelection)viewer.getSelection()).getFirstElement()) ;
				System.out.println("selected : "+ selected);
				myList.remove(selected) ; 
				viewer.setInput(myList.toArray()) ;
				viewer.refresh(); 
				detailsMap.remove(selected) ; 
				
				
			}
			
			@Override
			public void mouseDown(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseDoubleClick(MouseEvent e) {
				// TODO Auto-generated method stub
				
			}
		})  ; 
		
		
		
	
		
		
	}
	
	
	
	
	

	/**
	 * Register the pages.
	 * @param part
	 */
	@Override
	protected void registerPages(DetailsPart part) {
		// Register the pages
		//System.out.println("register") ; 
part.setPageProvider(this) ; 
	}

	/**
	 * Create the toolbar actions.
	 * @param managedForm
	 */
	@Override
	protected void createToolBarActions(IManagedForm managedForm) {
		// Create the toolbar actions
	}




	@Override
	public Object getPageKey(Object object) {
		// TODO Auto-generated method stub
		
		
		// Im using the object as the map key 
		return object;
	}




	@Override
	public IDetailsPage getPage(Object key) {
IDetailsPage temp = null ; 
		// TODO Auto-generated method stub
		if(detailsMap.containsKey((String) key)) temp= detailsMap.get((String) key);
		else 
			detailsMap.put((String) key,temp=new IndivisualGuardianDetails());
		return temp ; 
	}

}



and here is the details form section :

package com.capmtech.financial.forms;

import java.util.ArrayList;

public class IndivisualGuardianDetails implements IDetailsPage {

	private IManagedForm managedForm;

	/**
	 * Create the details page.
	 */
	
	public IndivisualGuardianDetails() {
		
		// Create the details page
	}

	/**
	 * Initialize the details page.
	 * @param form
	 */
	public void initialize(IManagedForm form) {
		managedForm = form;
	}

	/**
	 * Create contents of the details page.
	 * @param parent
	 */
	public void createContents(Composite parent) {
		 
		FormToolkit toolkit = managedForm.getToolkit();
		parent.setLayout(new FillLayout());
		//		
		Section section = toolkit.createSection(parent,
				ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
		section.setText("Gardian properties");
		//
		section.setLayout(new GridLayout(1, true)) ; 
       Composite composite = managedForm.getToolkit().createComposite(section) ; 
       section.setClient(composite) ; 
       
       managedForm.getToolkit().paintBordersFor(composite) ; 
       composite.setLayout(new GridLayout(3, false)) ; 
		Label nameLabel_lo = managedForm.getToolkit().createLabel(composite, "Arabic name :", SWT.NONE);
		nameLabel_lo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		
		Text nameText_lo = managedForm.getToolkit().createText(composite, "New Text", SWT.NONE);
		
		nameText_lo.setText("");
		
		
		
		nameText_lo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
		
		Label nameLabel_en = managedForm.getToolkit().createLabel(composite, "English name : ", SWT.NONE);
		nameLabel_en.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		
		Text  nameText_en = managedForm.getToolkit().createText(composite, "New Text", SWT.NONE);
		nameText_en.setText("");
		GridData gd_nameText_en = new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1);
		gd_nameText_en.widthHint = 345;
		nameText_en.setLayoutData(gd_nameText_en);
		
		Label lblDateOfBirth = managedForm.getToolkit().createLabel(composite, "Date Of Birth :", SWT.NONE);
		lblDateOfBirth.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		DateTime dobDateTime = new DateTime(composite, SWT.BORDER);
		dobDateTime.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
		Label sexLabel = managedForm.getToolkit().createLabel(composite, "Sex" , SWT.None) ;  
		sexLabel.setLayoutData(new GridData(SWT.FILL , SWT.CENTER , false , false , 1 , 1)) ; 
		Button genderMaleCheckbox = managedForm.getToolkit().createButton(composite, "male", SWT.CHECK) ; 
		genderMaleCheckbox.setLayoutData(new GridData(SWT.FILL , SWT.CENTER , false , false , 1 , 1)) ;
		Button genderFemaleCheckbox = managedForm.getToolkit().createButton(composite, "female", SWT.CHECK) ; 
		genderFemaleCheckbox.setLayoutData(new GridData(SWT.FILL , SWT.CENTER , false , false , 1 , 1)) ;
	    
		Label minorLabel = managedForm.getToolkit().createLabel(composite, "minor" , SWT.None) ;  
		minorLabel.setLayoutData(new GridData(SWT.FILL , SWT.CENTER , false , false , 1 , 1)) ; 
		Button minorCheckbox = managedForm.getToolkit().createButton(composite, "Yes", SWT.CHECK) ; 
		minorCheckbox.setLayoutData(new GridData(SWT.FILL , SWT.CENTER , false , false , 1 , 1)) ;
		Button notMinorCheckbox = managedForm.getToolkit().createButton(composite, "No", SWT.CHECK) ; 
		notMinorCheckbox.setLayoutData(new GridData(SWT.FILL , SWT.CENTER , false , false , 1 , 1)) ;
	
		Label nationaltyLabel = managedForm.getToolkit().createLabel(composite, "Nationalty : ", SWT.NONE);
		nationaltyLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		
	 Text	nationalityText = managedForm.getToolkit().createText(composite, "", SWT.NONE);
//		gd_nationalityText.widthHint = 355;
		nationalityText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
		
		Label idDocTypeLabel = managedForm.getToolkit().createLabel(composite, "Identification Document Type : ", SWT.NONE);
		idDocTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
		
		Button civilIdCheckButton = managedForm.getToolkit().createButton(composite, "Civil ID", SWT.CHECK);
		civilIdCheckButton.setLayoutData( new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1) ); 
		
		Label lblNewLabel = managedForm.getToolkit().createLabel(composite, "", SWT.NONE);
		lblNewLabel.setLayoutData( new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1) ); 
		
		Button passportButtonChech = managedForm.getToolkit().createButton(composite, "Passport", SWT.CHECK);
		passportButtonChech.setLayoutData( new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1) ); 
		
		Label documentNumberLabel = managedForm.getToolkit().createLabel(composite, "Identification Document Number : ", SWT.NONE);
	documentNumberLabel.setLayoutData( new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1) );
	
	Text docmentNumberText = managedForm.getToolkit().createText(composite, "", SWT.NONE);
	docmentNumberText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
	
	Label documentIssueDateLabel = managedForm.getToolkit().createLabel(composite, "Issue Date:", SWT.NONE);
	documentIssueDateLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
	
	DateTime documentIssueDateDateTime = new DateTime(composite, SWT.BORDER);
	managedForm.getToolkit().adapt(documentIssueDateDateTime);
	managedForm.getToolkit().paintBordersFor(documentIssueDateDateTime);
	documentIssueDateDateTime.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)) ; 
	
	Label documentExpiryDateLabel = managedForm.getToolkit().createLabel(composite, "Issue Date:", SWT.NONE);
	documentExpiryDateLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
	
	DateTime documentExpiryDateDateTime = new DateTime(composite, SWT.BORDER);
	managedForm.getToolkit().adapt(documentExpiryDateDateTime);
	managedForm.getToolkit().paintBordersFor(documentExpiryDateDateTime);
	documentExpiryDateDateTime.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)) ; 
	
	Label placeOfIssueLabel = managedForm.getToolkit().createLabel(composite, "Place of Issue :", SWT.NONE);
	placeOfIssueLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
	
Text	placeOfIssueText = managedForm.getToolkit().createText(composite, "New Text", SWT.NONE);
	placeOfIssueText.setText("");
	placeOfIssueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
	
	Label phoneNumbersLabel = managedForm.getToolkit().createLabel(composite, "Phone numbers : ", SWT.NONE);
	GridData gd_phoneNumbersLabel = new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1);
	gd_phoneNumbersLabel.widthHint = 264;
	phoneNumbersLabel.setLayoutData(gd_phoneNumbersLabel) ; 
	Label mobilePhoneNumberLabel= managedForm.getToolkit().createLabel(composite, "mobile : " , SWT.None) ; 
	mobilePhoneNumberLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)) ;
	Text mobilePhoneNumberText= managedForm.getToolkit().createText(composite, "" , SWT.None) ; 
	mobilePhoneNumberText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)) ;
	Label workPhoneNumberLabel= managedForm.getToolkit().createLabel(composite, " work : " , SWT.None) ; 
	workPhoneNumberLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)) ;
	Text workPhoneNumberText= managedForm.getToolkit().createText(composite, "" , SWT.None) ; 
	workPhoneNumberText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)) ;
	Label homePhoneNumberLabel= managedForm.getToolkit().createLabel(composite, "home :" , SWT.None) ; 
	homePhoneNumberLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)) ;
	Text homePhoneNumberText= managedForm.getToolkit().createText(composite, "" , SWT.None) ; 
	homePhoneNumberText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)) ;


	Label emailAddressLabel = managedForm.getToolkit().createLabel(composite, "Email address : ", SWT.NONE);
	emailAddressLabel.setLayoutData( new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
	Label personalEmailAddressLabel = managedForm.getToolkit().createLabel(composite, " personal Email : ", SWT.NONE);
	personalEmailAddressLabel.setLayoutData( new GridData(SWT.FILL, SWT.CENTER, false, false,1, 1));
	
	Text personalEmailAddressText= managedForm.getToolkit().createText(composite, "" , SWT.None) ; 
	personalEmailAddressText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1)) ;
	Label workEmailAddressLabel= managedForm.getToolkit().createLabel(composite, "work email  :" , SWT.None) ; 
	workEmailAddressLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)) ;
	Text workEmailAddressText= managedForm.getToolkit().createText(composite, "" , SWT.None) ; 
	workEmailAddressText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false,2, 1)) ;
	}

	public void dispose() {
		// Dispose
	}

	public void setFocus() {
		// Set focus
	}

	private void update() {
		// Update
	}

	public boolean setFormInput(Object input) {
		return false;
	}

	public void selectionChanged(IFormPart part, ISelection selection) {
		IStructuredSelection structuredSelection = (IStructuredSelection) selection;
		update();
	}

	public void commit(boolean onSave) {
		// Commit
	}

	public boolean isDirty() {
		return false;
	}

	public boolean isStale() {
		return false;
	}

	public void refresh() {
		update();
	}
}



im prety much sure that it is not the details block that is causing the problem since it is being called by the workbench it self .

and at last here is my exception stack trace :
 !SESSION 2011-07-18 12:36:07.503 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.6.0_21
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en
Framework arguments:  -application formsProject.application
Command-line arguments:  -application formsProject.application -data C:\Users\hp\MousaWorkSpace/../runtime-formsProject.application -dev file:C:/Users/hp/MousaWorkSpace/.metadata/.plugins/org.eclipse.pde.core/formsProject.application/dev.properties -os win32 -ws win32 -arch x86_64 -consoleLog

!ENTRY org.eclipse.ui 4 0 2011-07-18 12:36:16.767
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
	at org.eclipse.ui.forms.SectionPart.expansionStateChanged(SectionPart.java:106)
	at org.eclipse.ui.forms.SectionPart$1.expansionStateChanged(SectionPart.java:73)
	at org.eclipse.ui.forms.widgets.ExpandableComposite.fireExpanding(ExpandableComposite.java:1081)
	at org.eclipse.ui.forms.widgets.ExpandableComposite.toggleState(ExpandableComposite.java:1065)
	at org.eclipse.ui.forms.widgets.ExpandableComposite.access$5(ExpandableComposite.java:1061)
	at org.eclipse.ui.forms.widgets.ExpandableComposite$2.linkActivated(ExpandableComposite.java:576)
	at org.eclipse.ui.forms.widgets.AbstractHyperlink.handleActivate(AbstractHyperlink.java:233)
	at org.eclipse.ui.forms.widgets.AbstractHyperlink.handleMouseUp(AbstractHyperlink.java:327)
	at org.eclipse.ui.forms.widgets.AbstractHyperlink.access$2(AbstractHyperlink.java:311)
	at org.eclipse.ui.forms.widgets.AbstractHyperlink$4.handleEvent(AbstractHyperlink.java:125)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at formsproject.Application.start(Application.java:20)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)


please note that if the section containing the master block is styled as Section.EXPANDED no exception is thrown , but if it is styled as Section.TWISTIE the i well get the mentioned exception
Previous Topic:One handler sees source provider, another doesn't
Next Topic:Key binding with command framework in a dialog
Goto Forum:
  


Current Time: Thu Apr 25 06:00:37 GMT 2024

Powered by FUDForum. Page generated in 0.02598 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top