package org.eclipse.bpmn2.modeler.ui.property.tabs;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.platform.GFPropertySection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

public class GeneralTabSection extends GFPropertySection implements
		ITabbedPropertyConstants {
	
	private Composite parentComposite;
	private TabbedPropertySheetPage page;

	@Override
	public void createControls(Composite parent,
			TabbedPropertySheetPage aTabbedPropertySheetPage) {
		super.createControls(parent, aTabbedPropertySheetPage);
		this.parentComposite = parent;
		this.page = aTabbedPropertySheetPage;
	}
	
	public Composite createPropertiesComposite (Composite parent,
			TabbedPropertySheetPage tabbedPropertySheetPage) {
		super.createControls(parent, tabbedPropertySheetPage);
		
		PictogramElement pe = getSelectedPictogramElement();
		final EObject bo = Graphiti.getLinkService()
				.getBusinessObjectForLinkedPictogramElement(pe);
		
		return new BpmnPropertyCompositeFactory(this, parent).createCompositeForBpmnElement(bo);
	}
	
	private void rebuildParentComposite() {
		Composite oldComposite = parentComposite;
		parentComposite = getWidgetFactory().createFlatFormComposite(parentComposite.getParent());
		oldComposite.dispose();
		
		parentComposite.setLayout(new GridLayout(1, false));
		parentComposite.setLayoutData(new GridData(SWT.FILL, GridData.CENTER, true, false));
		
		internalRefresh();
	}
	
	@Override
	public void refresh() {
		rebuildParentComposite();
		createPropertiesComposite(parentComposite, page);

		internalRefresh(); // otherwise the composite will not properly redrawn after saving some changes, SWT sucks
	}
	
	private void internalRefresh() {
		parentComposite.getParent().layout();
		parentComposite.getParent().setFocus(); // otherwise the composite will not properly redrawn, SWT sucks		
	}
}

@@ -2101,24 +2101,43 @@
 resh() %7B%0D%0A%09%09
+Composite parent = 
 parentCompos
@@ -2151,16 +2151,27 @@
 Parent()
+;%0D%0A%09%09parent
 .layout(
@@ -2170,32 +2170,36 @@
 .layout();%0D%0A
+%09%09%0D%0A
 %09%09parent
 Composite.ge
@@ -2190,38 +2190,15 @@
 rent
-Composite.getParent().setFocus
+.redraw
 (); 

Fix focus bug