Revision 1819

tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/swt/SwingChartComposite.java (revision 1819)
101 101
		// 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.
102 102
		// see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=377104
103 103
		// see: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8203855
104
//		this.frame.addWindowListener(new java.awt.event.WindowAdapter() {
105
//			@Override
106
//			public void windowActivated(java.awt.event.WindowEvent e) {
107
//				SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
108
//					@Override
109
//					public void run() {
110
//						if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
111
//							Stack<Control> stack = new Stack<Control>();
112
//							Control starter = SwingChartComposite.this;
113
//							Shell shell = SwingChartComposite.this.getShell();
114
//							while (starter != null && !(starter instanceof Shell)) {
115
//								stack.push(starter.getParent());
116
//								starter = starter.getParent();
117
//							}
118
//
119
//							Method m = null;
120
//							try {
121
//								// instead of calling the originally proposed
122
//								// workaround solution (below),
123
//								//
124
//								// Event event = new Event();
125
//								// event.display = Display.getCurrent();
126
//								// event.type = SWT.Activate;
127
//								// event.widget = stack.pop();
128
//								// event.widget.notifyListeners(SWT.Activate, event);
129
//								//
130
//								// which should but does NOT set the active
131
//								// widget/control on the shell, we had
132
//								// to call the setActiveControl method directly.
133
//								// Updating the active control on the shell is
134
//								// important so that the last active
135
//								// control, when selected again, get the proper
136
//								// activation events fired.
137
//
138
//								m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$
139
//								m.setAccessible(true);
140
//								while (!stack.isEmpty()) {
141
//									m.invoke(shell, stack.pop());
142
//								}
143
//								
144
//								// force the Swing component focus
145
//								//setFocus();
146
//								
147
//							}
148
//							catch (Exception e) {
149
//								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$
150
//								Log.printStackTrace(e);
151
//							}
152
//							finally {
153
//								if (m != null) {
154
//									m.setAccessible(false);
155
//								}
156
//							}
157
//						}
158
//					}
159
//				});
160
//			}
161
//		});
104
		this.frame.addWindowListener(new java.awt.event.WindowAdapter() {
105
			@Override
106
			public void windowActivated(java.awt.event.WindowEvent e) {
107
				SwingChartComposite.this.getDisplay().asyncExec(new Runnable() {
108
					@Override
109
					public void run() {
110
						if (Display.getCurrent().getFocusControl() == SwingChartComposite.this) {
111
							Stack<Control> stack = new Stack<Control>();
112
							Control starter = SwingChartComposite.this;
113
							Shell shell = SwingChartComposite.this.getShell();
114
							while (starter != null && !(starter instanceof Shell)) {
115
								stack.push(starter.getParent());
116
								starter = starter.getParent();
117
							}
118

  
119
							Method m = null;
120
							try {
121
								// instead of calling the originally proposed
122
								// workaround solution (below),
123
								//
124
								// Event event = new Event();
125
								// event.display = Display.getCurrent();
126
								// event.type = SWT.Activate;
127
								// event.widget = stack.pop();
128
								// event.widget.notifyListeners(SWT.Activate, event);
129
								//
130
								// which should but does NOT set the active
131
								// widget/control on the shell, we had
132
								// to call the setActiveControl method directly.
133
								// Updating the active control on the shell is
134
								// important so that the last active
135
								// control, when selected again, get the proper
136
								// activation events fired.
137

  
138
								m = shell.getClass().getDeclaredMethod("setActiveControl", Control.class);// $NON-NLS-1$
139
								m.setAccessible(true);
140
								while (!stack.isEmpty()) {
141
									m.invoke(shell, stack.pop());
142
								}
143
								
144
								// force the Swing component focus
145
								//setFocus();
146
								
147
							}
148
							catch (Exception e) {
149
								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$
150
								Log.printStackTrace(e);
151
							}
152
							finally {
153
								if (m != null) {
154
									m.setAccessible(false);
155
								}
156
							}
157
						}
158
					}
159
				});
160
			}
161
		});
162 162
		
163 163
		this.frame.addWindowListener(new WindowListener() {
164 164
			
tmp/org.txm.chartsengine.rcp/src/org/txm/chartsengine/rcp/SWTChartsComponentsProvider.java (revision 1819)
733 733

  
734 734
			@Override
735 735
			public void mouseReleased(final MouseEvent e) {
736
				if(!chartEditor.getComposite().isDisposed())	{
736 737
				chartEditor.getComposite().getDisplay().asyncExec(new Runnable () {
737 738
					public void run() {
738 739
						
......
768 769
						//chartEditor.activate();
769 770
					}
770 771
				});
772
				}
771 773
			}
772 774

  
773 775
			@Override

Also available in: Unified diff