From: <jbo...@li...> - 2006-04-21 12:19:52
|
Author: KrisVerlaenen Date: 2006-04-21 08:19:44 -0400 (Fri, 21 Apr 2006) New Revision: 3885 Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java Log: fixed an error when trying to run AWT in SWT in Mac Modified: labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java =================================================================== --- labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-04-21 12:04:04 UTC (rev 3884) +++ labs/jbossrules/trunk/drools-ide/src/main/java/org/drools/ide/editors/ReteViewer.java 2006-04-21 12:19:44 UTC (rev 3885) @@ -18,6 +18,7 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTError; import org.eclipse.swt.awt.SWT_AWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@ -65,10 +66,16 @@ } }); - Composite frameParent = new Composite(parent, SWT.EMBEDDED); - frameParent.setLayoutData(new GridData(GridData.FILL_BOTH)); - frame = SWT_AWT.new_Frame(frameParent); - frame.setLayout(new BorderLayout()); + try { + Composite frameParent = new Composite(parent, SWT.EMBEDDED); + frameParent.setLayoutData(new GridData(GridData.FILL_BOTH)); + frame = SWT_AWT.new_Frame(frameParent); + frame.setLayout(new BorderLayout()); + } catch (SWTError exc) { + // it is possible that this exception is thrown if + // SWT is not supported, e.g. in Mac + DroolsIDEPlugin.log(exc); + } } private RuleBase getRuleBase() { @@ -127,7 +134,9 @@ } public void clear() { - frame.removeAll(); + if (frame != null) { // possible if frame creation failed + frame.removeAll(); + } } public boolean isDirty() { @@ -145,21 +154,23 @@ } private void generateReteView() { - clear(); - try { - RuleBase ruleBase = getRuleBase(); - if (ruleBase == null) { - // TODO signal user that rule cannot be parsed - } else { - ReteooJungViewerPanel viewer = new ReteooJungViewerPanel( - ruleBase); - frame.add(viewer); - frame.validate(); - parent.layout(); + if (frame != null) { // possible if frame creation failed + clear(); + try { + RuleBase ruleBase = getRuleBase(); + if (ruleBase == null) { + // TODO signal user that rule cannot be parsed + } else { + ReteooJungViewerPanel viewer = new ReteooJungViewerPanel( + ruleBase); + frame.add(viewer); + frame.validate(); + parent.layout(); + } + } catch (Throwable t) { + t.printStackTrace(); + DroolsIDEPlugin.log(t); } - } catch (Throwable t) { - t.printStackTrace(); - DroolsIDEPlugin.log(t); } } } |