1 package com.quantum.util.versioning;
3 import java.lang.reflect.InvocationTargetException;
4 import java.lang.reflect.Method;
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;
13 * This class provides backward compatibility between versions of Eclipse for
18 public class VersioningHelper {
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;
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.
32 public static void setFont(FontDialog fontDialog, FontData[] fontData) {
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] });
43 } catch (NoSuchMethodException e) {
45 } catch (IllegalArgumentException e) {
47 } catch (IllegalAccessException e) {
49 } catch (InvocationTargetException e) {
54 public static void setPartName(ViewPart viewPart, String partName) {
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});
61 Method method = WorkbenchPart.class.getDeclaredMethod(
62 "setTitle", new Class[] { FontData.class });
63 method.invoke(method, new Object[] { partName });
65 } catch (NoSuchMethodException e) {
67 } catch (IllegalArgumentException e) {
69 } catch (IllegalAccessException e) {
71 } catch (InvocationTargetException e) {
76 public static void main(String[] args) {
77 System.out.println(SWT.getVersion());