Index: tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java
===================================================================
--- tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java	(revision 1829)
+++ tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java	(revision 1830)
@@ -11,37 +11,21 @@
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
+import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
-import java.awt.event.WindowFocusListener;
-import java.awt.event.WindowListener;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.Stack;
 
 import javax.swing.JApplet;
 import javax.swing.JComponent;
 import javax.swing.SwingUtilities;
-import javax.swing.border.LineBorder;
 
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.awt.SWT_AWT;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
 import org.txm.chartsengine.core.results.ChartResult;
 import org.txm.chartsengine.rcp.IChartComponent;
 import org.txm.chartsengine.rcp.editors.ChartEditor;
 import org.txm.chartsengine.rcp.events.EventCallBackHandler;
-import org.txm.core.messages.TXMCoreMessages;
-import org.txm.core.preferences.TBXPreferences;
-import org.txm.rcp.preferences.RCPPreferences;
-import org.txm.utils.logger.Log;
 
 /**
  * Base chart composite with Swing/AWT support.
@@ -55,13 +39,13 @@
 	
 	
 	// For reducing resize flickering on Windows
-//	static	{
-//		try {
-//			System.setProperty("sun.awt.noerasebackground", "true"); //$NON-NLS-1$ //$NON-NLS-2$
-//		}
-//		catch (NoSuchMethodError error) {
-//		}
-//	}
+	static	{
+		try {
+			System.setProperty("sun.awt.noerasebackground", "true"); //$NON-NLS-1$ //$NON-NLS-2$
+		}
+		catch (NoSuchMethodError error) {
+		}
+	}
 
 
 	
@@ -91,31 +75,215 @@
 		//this.rootPanel = new JPanel(new BorderLayout());
 
 		// FIXME: tests with Applet, see: https://www.eclipse.org/articles/article.php?file=Article-Swing-SWT-Integration/index.html
-		JApplet applet = new JApplet(); 
+		final JApplet applet = new JApplet(); 
 		this.rootPanel = (JComponent) applet.getRootPane().getContentPane();
 		
+		
 		this.frame.add(applet);
 		
 		//this.frame.pack();
 
-		this.frame.setVisible(true);
+		//this.frame.setVisible(true);
+		//this.frame.setVisible(false);
 
 
 		this.rootPanel.setBackground(Color.WHITE);
 		
 		
+//		final sun.awt.EmbeddedFrame ef = (sun.awt.EmbeddedFrame)this.frame;
+//		 		ef.addWindowListener(new WindowAdapter() {
+//		 			public void windowActivated(WindowEvent e) {
+//		 				ef.synthesizeWindowActivation(true);
+//		 			}		
+//		 		});
+//		  		
+//		  		SwingUtilities.invokeLater(new Runnable() {
+//		  			public void run() {
+//		  				applet.requestFocusInWindow();
+//		  			}
+//		  		});
 		
 		
-		// SJ: Workaround to fix a bug with some Java version and some OS where the focus of an embedded Swing component does not delegate to SWT, eg. the Part is not activated.
-		// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104
-		// see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855
-//		this.frame.addWindowListener(new java.awt.event.WindowAdapter() {
+		
+//		// SJ: Workaround to fix a bug with some Java version and some OS where the focus of an embedded Swing component does not delegate to SWT, eg. the Part is not activated.
+//		// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104
+//		// see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855
+////		this.frame.addWindowListener(new java.awt.event.WindowAdapter() {
+////			@Override
+////			public void windowActivated(java.awt.event.WindowEvent e) {
+////				SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
+////					@Override
+////					public void run() {
+////						if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
+////							Stack<Control> stack = new Stack<Control>();
+////							Control starter = SwingChartComposite.this;
+////							Shell shell = SwingChartComposite.this.getShell();
+////							while (starter != null && !(starter instanceof Shell)) {
+////								stack.push(starter.getParent());
+////								starter = starter.getParent();
+////							}
+////
+////							Method m = null;
+////							try {
+////								// instead of calling the originally proposed
+////								// workaround solution (below),
+////								//
+////								// Event event = new Event();
+////								// event.display = Display.getCurrent();
+////								// event.type = SWT.Activate;
+////								// event.widget = stack.pop();
+////								// event.widget.notifyListeners(SWT.Activate, event);
+////								//
+////								// which should but does NOT set the active
+////								// widget/control on the shell, we had
+////								// to call the setActiveControl method directly.
+////								// Updating the active control on the shell is
+////								// important so that the last active
+////								// control, when selected again, get the proper
+////								// activation events fired.
+////
+////								m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$
+////								m.setAccessible(true);
+////								while (!stack.isEmpty()) {
+////									m.invoke(shell, stack.pop());
+////								}
+////								
+////								// force the Swing component focus
+////								//setFocus();
+////								
+////							}
+////							catch (Exception e) {
+////								Log.severe("** Embedded part was not able to set active control on Shell. This will result in other workbench parts not getting activated."); //$NON-NLS-1$
+////								Log.printStackTrace(e);
+////							}
+////							finally {
+////								if (m != null) {
+////									m.setAccessible(false);
+////								}
+////							}
+////						}
+////					}
+////				});
+////			}
+////		});
+//		
+//		this.frame.addWindowListener(new WindowListener() {
+//			
 //			@Override
-//			public void windowActivated(java.awt.event.WindowEvent e) {
+//			public void windowOpened(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				
+//			}
+//			
+//			@Override
+//			public void windowIconified(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				
+//			}
+//			
+//			@Override
+//			public void windowDeiconified(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				
+//			}
+//			
+//			@Override
+//			public void windowDeactivated(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowListener() {...}.windowDeactivated()");
+//			}
+//			
+//			@Override
+//			public void windowClosing(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				
+//			}
+//			
+//			@Override
+//			public void windowClosed(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				
+//			}
+//			
+//			@Override
+//			public void windowActivated(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowListener() {...}.windowActivated()");
+//			}
+//		});
+//		
+//		
+//		this.frame.addFocusListener(new FocusListener() {
+//			
+//			@Override
+//			public void focusLost(FocusEvent e) {
+//				// TODO Auto-generated method stub
+//				Log.finest("SwingChartComposite.SwingChartComposite(...).new FocusListener() {...}.focusLost()");
+//			}
+//			
+//			@Override
+//			public void focusGained(FocusEvent e) {
+//				// TODO Auto-generated method stub
+//				Log.finest("SwingChartComposite.SwingChartComposite(...).new FocusListener() {...}.focusGained()");
+//			}
+//		});
+//
+//		
+//		this.frame.addWindowFocusListener(new WindowFocusListener() {
+//			
+//			@Override
+//			public void windowLostFocus(WindowEvent e) {
+//				// TODO Auto-generated method stub
+//				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowLostFocus()");
+//				
+//				// Force the keep the focus if the ChartEditor has the focus
+//				if(!SwingChartComposite.this.isDisposed())	{
+//					SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
+//						@Override
+//						public void run() {
+//							if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
+//								Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowLostFocus(): force focus in chart component.");
+//								requestFocusInChartComponent();
+//							}
+//						}
+//					});
+//				}
+//				
+//				
+//				
+//				// FIXME: For Swing focus debug tests
+//				if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER))	{
+//					((JComponent) rootPanel).setBorder(javax.swing.BorderFactory.createEmptyBorder());
+//				}
+//
+//				
+//			}
+//			
+//			@Override
+//			public void windowGainedFocus(WindowEvent e) {
+//				
+//				// FIXME: For Swing focus debug tests
+//				if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER))	{
+//					((JComponent) rootPanel).setBorder(new LineBorder(Color.red, 1));
+//				}
+//
+//				
+//				// TODO Auto-generated method stub
+//				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowGainedFocus()");
+//				
+//				
 //				SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
 //					@Override
 //					public void run() {
-//						if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
+//						if (
+//								Display.getCurrent().getFocusControl() == SwingChartComposite.this
+//								//&&
+//								//SwingChartComposite.this.chartEditor.getContextActivationToken() == null
+////								SwingChartComposite.this.chartEditor != PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
+//								) {
+//							
+//							Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowGainedFocus(): activate the EditorPart.");
+//							
 //							Stack<Control> stack = new Stack<Control>();
 //							Control starter = SwingChartComposite.this;
 //							Shell shell = SwingChartComposite.this.getShell();
@@ -129,11 +297,11 @@
 //								// instead of calling the originally proposed
 //								// workaround solution (below),
 //								//
-//								// Event event = new Event();
-//								// event.display = Display.getCurrent();
-//								// event.type = SWT.Activate;
-//								// event.widget = stack.pop();
-//								// event.widget.notifyListeners(SWT.Activate, event);
+////								 Event event = new Event();
+////								 event.display = Display.getCurrent();
+////								 event.type = SWT.Activate;
+////								 event.widget = stack.pop();
+////								 event.widget.notifyListeners(SWT.Activate, event);
 //								//
 //								// which should but does NOT set the active
 //								// widget/control on the shell, we had
@@ -143,6 +311,8 @@
 //								// control, when selected again, get the proper
 //								// activation events fired.
 //
+//								//PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(SwingChartComposite.this.chartEditor);
+//								
 //								m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$
 //								m.setAccessible(true);
 //								while (!stack.isEmpty()) {
@@ -165,255 +335,85 @@
 //						}
 //					}
 //				});
+//				
 //			}
 //		});
 		
-		this.frame.addWindowListener(new WindowListener() {
-			
-			@Override
-			public void windowOpened(WindowEvent e) {
-				// TODO Auto-generated method stub
-				
-			}
-			
-			@Override
-			public void windowIconified(WindowEvent e) {
-				// TODO Auto-generated method stub
-				
-			}
-			
-			@Override
-			public void windowDeiconified(WindowEvent e) {
-				// TODO Auto-generated method stub
-				
-			}
-			
-			@Override
-			public void windowDeactivated(WindowEvent e) {
-				// TODO Auto-generated method stub
-				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowListener() {...}.windowDeactivated()");
-			}
-			
-			@Override
-			public void windowClosing(WindowEvent e) {
-				// TODO Auto-generated method stub
-				
-			}
-			
-			@Override
-			public void windowClosed(WindowEvent e) {
-				// TODO Auto-generated method stub
-				
-			}
-			
-			@Override
-			public void windowActivated(WindowEvent e) {
-				// TODO Auto-generated method stub
-				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowListener() {...}.windowActivated()");
-			}
-		});
 		
 		
-		this.frame.addFocusListener(new FocusListener() {
-			
-			@Override
-			public void focusLost(FocusEvent e) {
-				// TODO Auto-generated method stub
-				Log.finest("SwingChartComposite.SwingChartComposite(...).new FocusListener() {...}.focusLost()");
-			}
-			
-			@Override
-			public void focusGained(FocusEvent e) {
-				// TODO Auto-generated method stub
-				Log.finest("SwingChartComposite.SwingChartComposite(...).new FocusListener() {...}.focusGained()");
-			}
-		});
-
-		
-		this.frame.addWindowFocusListener(new WindowFocusListener() {
-			
-			@Override
-			public void windowLostFocus(WindowEvent e) {
-				// TODO Auto-generated method stub
-				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowLostFocus()");
-				
-				// Force the keep the focus if the ChartEditor has the focus
-				if(!SwingChartComposite.this.isDisposed())	{
-					SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
-						@Override
-						public void run() {
-							if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
-								Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowLostFocus(): force focus in chart component.");
-								requestFocusInChartComponent();
-							}
-						}
-					});
-				}
-				
-				
-				
-				// FIXME: For Swing focus debug tests
-				if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER))	{
-					((JComponent) rootPanel).setBorder(javax.swing.BorderFactory.createEmptyBorder());
-				}
-
-				
-			}
-			
-			@Override
-			public void windowGainedFocus(WindowEvent e) {
-				
-				// FIXME: For Swing focus debug tests
-				if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER))	{
-					((JComponent) rootPanel).setBorder(new LineBorder(Color.red, 1));
-				}
-
-				
-				// TODO Auto-generated method stub
-				Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowGainedFocus()");
-				
-				
-				SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
-					@Override
-					public void run() {
-						if (
-								Display.getCurrent().getFocusControl() == SwingChartComposite.this
-//								&&
-//								SwingChartComposite.this.chartEditor != PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor()
-								) {
-							
-							Log.finest("SwingChartComposite.SwingChartComposite(...).new WindowFocusListener() {...}.windowGainedFocus(): activate the EditorPart.");
-							
-							Stack<Control> stack = new Stack<Control>();
-							Control starter = SwingChartComposite.this;
-							Shell shell = SwingChartComposite.this.getShell();
-							while (starter != null && !(starter instanceof Shell)) {
-								stack.push(starter.getParent());
-								starter = starter.getParent();
-							}
-
-							Method m = null;
-							try {
-								// instead of calling the originally proposed
-								// workaround solution (below),
-								//
-//								 Event event = new Event();
-//								 event.display = Display.getCurrent();
-//								 event.type = SWT.Activate;
-//								 event.widget = stack.pop();
-//								 event.widget.notifyListeners(SWT.Activate, event);
-								//
-								// which should but does NOT set the active
-								// widget/control on the shell, we had
-								// to call the setActiveControl method directly.
-								// Updating the active control on the shell is
-								// important so that the last active
-								// control, when selected again, get the proper
-								// activation events fired.
-
-								//PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().activate(SwingChartComposite.this.chartEditor);
-								
-								m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$
-								m.setAccessible(true);
-								while (!stack.isEmpty()) {
-									m.invoke(shell, stack.pop());
-								}
-								
-								// force the Swing component focus
-								//setFocus();
-								
-							}
-							catch (Exception e) {
-								Log.severe("** Embedded part was not able to set active control on Shell. This will result in other workbench parts not getting activated."); //$NON-NLS-1$
-								Log.printStackTrace(e);
-							}
-							finally {
-								if (m != null) {
-									m.setAccessible(false);
-								}
-							}
-						}
-					}
-				});
-				
-			}
-		});
-		
-		
-		
 	}
 
 	
-	
-	@Override
-	public boolean setFocus() {
-
-		if (this.isDisposed()) {
-			return false;
-		}
-		
-		// Debug
-		Log.finest("SwingChartComposite.setFocus(): trying to give focus to SWT composite and AWT component..."); //$NON-NLS-1$
-		
-		boolean focusState = super.setFocus();
-		
-		// Debug
-		Log.finest(TXMCoreMessages.bind("SwingChartComposite.setFocus(): SWT composite focus given state = {0}.", this.isFocusControl())); //$NON-NLS-1$
-		
-		this.requestFocusInChartComponent();
-		
-		return focusState;
-	}
-	
-	
-	
-	/**
-	 * Requests the focus in chart component.
-	 */
-	public void requestFocusInChartComponent()	{
-		
-		
-		if(chartComponent != null) {
-		
-//		try {
-			SwingUtilities.invokeLater(new Runnable () {
-				public void run () {
-//				if(!((Component) chartComponent).isFocusOwner())	{
-						
-						//((Component) chartComponent).requestFocus();
-						((JComponent) chartComponent).grabFocus();
-						boolean focusState = ((Component) chartComponent).requestFocusInWindow();
-						
-						// Debug
-						//Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", ((Component) chartComponent).isFocusOwner())); //$NON-NLS-1$
-						Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", focusState)); //$NON-NLS-1$
-						
-//					// FIXME: For Swing focus debug tests
-//					if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER))	{
-//						if(((Component) chartComponent).isFocusOwner())	{
-//							((JComponent) chartComponent).setBorder(new LineBorder(Color.red, 1));
-//						}
-//						else	{
-//							((JComponent) chartComponent).setBorder(javax.swing.BorderFactory.createEmptyBorder());
-//						}
-//					}
-						
-						
-//			}
-				}
-			});
-	//	}
-//		catch (InvocationTargetException e) {
-//			// TODO Auto-generated catch block
-//			e.printStackTrace();
+//	
+//	@Override
+//	public boolean setFocus() {
+//
+//		if (this.isDisposed()) {
+//			return false;
 //		}
-//		catch (InterruptedException e) {
-//			// TODO Auto-generated catch block
-//			e.printStackTrace();
+//		
+//		// Debug
+//		Log.finest("SwingChartComposite.setFocus(): trying to give focus to SWT composite and AWT component..."); //$NON-NLS-1$
+//		
+//		boolean focusState = super.setFocus();
+//		
+//		// Debug
+//		Log.finest(TXMCoreMessages.bind("SwingChartComposite.setFocus(): SWT composite focus given state = {0}.", this.isFocusControl())); //$NON-NLS-1$
+//		
+//		this.requestFocusInChartComponent();
+//		
+//		return focusState;
+//	}
+//	
+//	
+//	
+//	/**
+//	 * Requests the focus in chart component.
+//	 */
+//	public void requestFocusInChartComponent()	{
+//		
+//		
+//		if(chartComponent != null) {
+//		
+////		try {
+//			SwingUtilities.invokeLater(new Runnable () {
+//				public void run () {
+////				if(!((Component) chartComponent).isFocusOwner())	{
+//						
+//						//((Component) chartComponent).requestFocus();
+//						((JComponent) chartComponent).grabFocus();
+//						boolean focusState = ((Component) chartComponent).requestFocusInWindow();
+//						
+//						// Debug
+//						//Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", ((Component) chartComponent).isFocusOwner())); //$NON-NLS-1$
+//						Log.finest(TXMCoreMessages.bind("SwingChartComposite.requestFocusInChartComponent(): AWT component focus given state = {0}.", focusState)); //$NON-NLS-1$
+//						
+////					// FIXME: For Swing focus debug tests
+////					if(RCPPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER))	{
+////						if(((Component) chartComponent).isFocusOwner())	{
+////							((JComponent) chartComponent).setBorder(new LineBorder(Color.red, 1));
+////						}
+////						else	{
+////							((JComponent) chartComponent).setBorder(javax.swing.BorderFactory.createEmptyBorder());
+////						}
+////					}
+//						
+//						
+////			}
+//				}
+//			});
+//	//	}
+////		catch (InvocationTargetException e) {
+////			// TODO Auto-generated catch block
+////			e.printStackTrace();
+////		}
+////		catch (InterruptedException e) {
+////			// TODO Auto-generated catch block
+////			e.printStackTrace();
+////		}
+//		
 //		}
-		
-		}
-	}
+//	}
 
 	
 	
