fcf61881e5a50faca2aa8b62f99e666b7db6a525
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / util / versioning / VersioningHelper.java
1 package com.quantum.util.versioning;
2
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
5
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.graphics.FontData;
8 import org.eclipse.swt.widgets.FontDialog;
9 import org.eclipse.ui.part.ViewPart;
10 import org.eclipse.ui.part.WorkbenchPart;
11
12 /**
13  * This class provides backward compatibility between versions of Eclipse for
14  * known differences.
15  * 
16  * @author BC
17  */
18 public class VersioningHelper {
19     
20     public static final int ECLIPSE_VERSION_2_1_1 = 2135;
21     public static final int ECLIPSE_VERSION_3_0_RC1 = 3054;
22     public static final int ECLIPSE_VERSION_3_0_RC3 = 3061;
23
24     /**
25      * Set the font in a FontDialog.  In Eclipse 2.1.1, the 
26      * <code>setFontData()</code> method was deprecated and an alternative
27      * method, <code>setFontList()</code> was suggested in its place.  
28      * 
29      * @param fontDialog
30      * @param fontData
31      */    
32     public static void setFont(FontDialog fontDialog, FontData[] fontData) {
33         try {
34             if (SWT.getVersion() >= ECLIPSE_VERSION_2_1_1) {
35                 Method method = fontDialog.getClass().getMethod(
36                     "setFontList", new Class[] { fontData.getClass()});
37                 method.invoke(fontDialog, new Object[] {fontData});
38             } else if (fontData.length > 0) {
39                 Method method = fontDialog.getClass().getMethod(
40                     "setFontData", new Class[] { FontData.class });
41                 method.invoke(fontDialog, new Object[] { fontData[0] });
42             }
43         } catch (NoSuchMethodException e) {
44             // should not happen
45         } catch (IllegalArgumentException e) {
46             // should not happen
47         } catch (IllegalAccessException e) {
48             // should not happen
49         } catch (InvocationTargetException e) {
50             // should not happen
51         }
52     }
53     
54     public static void setPartName(ViewPart viewPart, String partName) {
55         try {
56             if (SWT.getVersion() >= ECLIPSE_VERSION_3_0_RC1) {
57                 Method method = WorkbenchPart.class.getDeclaredMethod(
58                     "setPartName", new Class[] { String.class });
59                 method.invoke(viewPart, new Object[] {partName});
60             } else {
61                 Method method = WorkbenchPart.class.getDeclaredMethod(
62                     "setTitle", new Class[] { FontData.class });
63                 method.invoke(method, new Object[] { partName });
64             }
65         } catch (NoSuchMethodException e) {
66             // should not happen
67         } catch (IllegalArgumentException e) {
68             // should not happen
69         } catch (IllegalAccessException e) {
70             // should not happen
71         } catch (InvocationTargetException e) {
72             // should not happen
73         }
74     }
75     
76     public static void main(String[] args) {
77         System.out.println(SWT.getVersion());
78     }
79 }