KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > jres > JREsEnvironmentLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.debug.ui.jres;
12
13 import com.ibm.icu.text.MessageFormat;
14
15 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
16 import org.eclipse.jdt.launching.IVMInstall;
17 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
18 import org.eclipse.jface.resource.JFaceResources;
19 import org.eclipse.jface.viewers.IFontProvider;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Font;
22 import org.eclipse.swt.graphics.FontData;
23 import org.eclipse.swt.widgets.Display;
24
25 /**
26  * Decorates JREs to emphasize those that are strictly compatible with an environment.
27  *
28  * @since 3.2
29  *
30  */

31 public class JREsEnvironmentLabelProvider extends JREsLabelProvider implements IFontProvider {
32     
33     private IExecutionEnvironmentProvider fProvider;
34     private Font fFont = null;
35     
36     /**
37      * Returns the current environment or <code>null</code> id none
38      *
39      * @since 3.2
40      */

41     public interface IExecutionEnvironmentProvider {
42         public IExecutionEnvironment getEnvironment();
43     }
44
45     public JREsEnvironmentLabelProvider(IExecutionEnvironmentProvider provider) {
46         fProvider = provider;
47     }
48     
49     
50     
51     /* (non-Javadoc)
52      * @see org.eclipse.jface.viewers.LabelProvider#dispose()
53      */

54     public void dispose() {
55         if (fFont != null) {
56             fFont.dispose();
57         }
58         super.dispose();
59     }
60
61
62
63     /* (non-Javadoc)
64      * @see org.eclipse.jdt.internal.debug.ui.jres.JREsLabelProvider#getText(java.lang.Object)
65      */

66     public String JavaDoc getText(Object JavaDoc element) {
67         String JavaDoc label = super.getText(element);
68         if (isStrictlyCompatible(element)) {
69             label = MessageFormat.format(JREMessages.JREsEnvironmentLabelProvider_0, new String JavaDoc[]{label, JREMessages.JREsEnvironmentLabelProvider_1});
70         }
71         return label;
72     }
73     
74     private boolean isStrictlyCompatible(Object JavaDoc element) {
75         IExecutionEnvironment environment = fProvider.getEnvironment();
76         if (environment != null && element instanceof IVMInstall) {
77             return environment.isStrictlyCompatible((IVMInstall)element);
78         }
79         return false;
80     }
81
82
83     /* (non-Javadoc)
84      * @see org.eclipse.jface.viewers.IFontProvider#getFont(java.lang.Object)
85      */

86     public Font getFont(Object JavaDoc element) {
87         if (isStrictlyCompatible(element)) {
88             if (fFont == null) {
89                 Font dialogFont = JFaceResources.getDialogFont();
90                 FontData[] fontData = dialogFont.getFontData();
91                 for (int i = 0; i < fontData.length; i++) {
92                     FontData data = fontData[i];
93                     data.setStyle(SWT.BOLD);
94                 }
95                 Display display = JDIDebugUIPlugin.getActiveWorkbenchShell().getDisplay();
96                 fFont = new Font(display, fontData);
97             }
98             return fFont;
99         } else {
100             return null;
101         }
102     }
103
104 }
105
Popular Tags