Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 313950 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +4 lines)
Lines 20-25 Link Here
20
 org.eclipse.e4.core.contexts,
20
 org.eclipse.e4.core.contexts,
21
 org.eclipse.e4.core.di,
21
 org.eclipse.e4.core.di,
22
 org.eclipse.e4.core.services;bundle-version="0.9.1",
22
 org.eclipse.e4.core.services;bundle-version="0.9.1",
23
 org.eclipse.core.runtime;bundle-version="3.6.0"
23
 org.eclipse.core.runtime;bundle-version="3.6.0",
24
 org.eclipse.emf.common;bundle-version="2.6.0"
24
Bundle-RequiredExecutionEnvironment: J2SE-1.5
25
Bundle-RequiredExecutionEnvironment: J2SE-1.5
25
Bundle-Vendor: Eclipse.org
26
Bundle-Vendor: Eclipse.org
27
Bundle-Activator: org.eclipse.e4.ui.internal.css.swt.CSSActivator
28
Bundle-ActivationPolicy: lazy
(-)src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java (-8 / +5 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.css.swt.properties.custom;
11
package org.eclipse.e4.ui.css.swt.properties.custom;
12
12
13
import java.lang.reflect.Method;
14
import org.eclipse.swt.graphics.Color;
15
13
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
16
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
14
import org.eclipse.e4.core.contexts.IEclipseContext;
17
import org.eclipse.e4.core.contexts.IEclipseContext;
15
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
18
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
Lines 31-45 Link Here
31
		if (!(control instanceof CTabFolder)) return;
34
		if (!(control instanceof CTabFolder)) return;
32
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
35
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
33
			int radiusValue = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
36
			int radiusValue = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
34
			
35
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
37
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
36
					
38
			Method m = renderer.getClass().getMethod("setCornerRadius", new Class[]{Integer.class});
37
			Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
39
			m.invoke(renderer, Integer.valueOf(radiusValue));
38
			if (cssContext != null && cssContext instanceof IEclipseContext) {
39
				IEclipseContext context = (IEclipseContext) cssContext;
40
				context.set("radius", new Integer(radiusValue));
41
				ContextInjectionFactory.inject(renderer, context); 
42
			}
43
		}
40
		}
44
	}
41
	}
45
	
42
	
(-)src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java (-15 / +2 lines)
Lines 33-54 Link Here
33
		if (!(control instanceof CTabFolder)) return;
33
		if (!(control instanceof CTabFolder)) return;
34
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
34
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
35
			Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay());
35
			Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay());
36
			
37
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
36
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
38
			Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
37
			Method m = renderer.getClass().getMethod("setInnerKeyline", new Class[]{Color.class});
39
			if (cssContext != null && cssContext instanceof IEclipseContext) {
38
			m.invoke(renderer, newColor);
40
				IEclipseContext context = (IEclipseContext) cssContext;
41
				context.set("innerKeyline", newColor);
42
				ContextInjectionFactory.inject(renderer, context); 
43
			} else {
44
				Method[] methods = renderer.getClass().getMethods();
45
				for (int i = 0; i < methods.length; i++) {
46
					Method m = methods[i];
47
					if (m.getName().toLowerCase().contains("setinnerkeyline")) {
48
						m.invoke(renderer, newColor);
49
					}
50
				}
51
			}
52
		}
39
		}
53
	}
40
	}
54
	
41
	
(-)src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java (-26 / +2 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.css.swt.properties.custom;
11
package org.eclipse.e4.ui.css.swt.properties.custom;
12
12
13
import java.util.HashMap;
14
15
import java.lang.reflect.Method;
13
import java.lang.reflect.Method;
16
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
17
import org.eclipse.e4.core.contexts.IEclipseContext;
18
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
14
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
19
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
15
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
20
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
16
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
Lines 26-33 Link Here
26
22
27
public class CSSPropertyOuterKeylineSWTHandler extends AbstractCSSPropertySWTHandler {
23
public class CSSPropertyOuterKeylineSWTHandler extends AbstractCSSPropertySWTHandler {
28
24
29
	HashMap contexts = new HashMap();
30
	
31
	public static final ICSSPropertyHandler INSTANCE = new CSSPropertyOuterKeylineSWTHandler();
25
	public static final ICSSPropertyHandler INSTANCE = new CSSPropertyOuterKeylineSWTHandler();
32
	
26
	
33
	@Override
27
	@Override
Lines 36-62 Link Here
36
		if (!(control instanceof CTabFolder)) return;
30
		if (!(control instanceof CTabFolder)) return;
37
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
31
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
38
			Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay());
32
			Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay());
39
			
40
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
33
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
41
			Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
34
			Method m = renderer.getClass().getMethod("setOuterKeyline", new Class[]{Color.class});
42
			if (cssContext != null && cssContext instanceof IEclipseContext) {
35
			m.invoke(renderer, newColor);
43
				IEclipseContext context = (IEclipseContext) cssContext;
44
				IEclipseContext childContext = (IEclipseContext) contexts.get(control);
45
				if (childContext == null) {
46
						childContext = context.createChild();
47
						contexts.put(control, childContext);
48
				}
49
				childContext.set("outerKeyline", newColor);
50
				ContextInjectionFactory.inject(renderer, childContext); 
51
			} else {
52
				Method[] methods = renderer.getClass().getMethods();
53
				for (int i = 0; i < methods.length; i++) {
54
					Method m = methods[i];
55
					if (m.getName().toLowerCase().contains("setouterkeyline")) {
56
						m.invoke(renderer, newColor);
57
					}
58
				}
59
			}
60
		}
36
		}
61
	}
37
	}
62
	
38
	
(-)src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java (-9 / +5 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.css.swt.properties.custom;
11
package org.eclipse.e4.ui.css.swt.properties.custom;
12
12
13
import java.lang.reflect.Method;
14
import org.eclipse.swt.graphics.Color;
15
13
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
16
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
14
import org.eclipse.e4.core.contexts.IEclipseContext;
17
import org.eclipse.e4.core.contexts.IEclipseContext;
15
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
18
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
Lines 29-44 Link Here
29
			CSSValue value, String pseudo, CSSEngine engine) throws Exception {
32
			CSSValue value, String pseudo, CSSEngine engine) throws Exception {
30
		if (!(control instanceof CTabFolder)) return;
33
		if (!(control instanceof CTabFolder)) return;
31
		boolean shadowVisible = (Boolean) engine.convert(value, Boolean.class, null);
34
		boolean shadowVisible = (Boolean) engine.convert(value, Boolean.class, null);
32
		
33
		CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
35
		CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
34
		
36
		Method m = renderer.getClass().getMethod("setShadowVisible",  new Class[]{Boolean.class});
35
		Object appContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
37
		m.invoke(renderer, Boolean.valueOf(shadowVisible));
36
		if (appContext != null && appContext instanceof IEclipseContext) {
37
			IEclipseContext context = (IEclipseContext) appContext;
38
			IEclipseContext childContext = context.createChild();
39
			childContext.set("shadowVisible", new Boolean(shadowVisible));
40
			ContextInjectionFactory.inject(renderer, childContext); 
41
		}
42
	}
38
	}
43
	
39
	
44
	protected String retrieveCSSProperty(Control control, String property,
40
	protected String retrieveCSSProperty(Control control, String property,
(-)src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java (-12 / +31 lines)
Lines 10-23 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.css.swt.properties.custom;
11
package org.eclipse.e4.ui.css.swt.properties.custom;
12
12
13
import org.eclipse.e4.core.contexts.IEclipseContext;
13
import org.eclipse.swt.custom.CTabFolderRenderer;
14
import org.eclipse.e4.core.services.contributions.IContributionFactory;
14
15
import java.lang.reflect.Constructor;
16
15
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
17
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
16
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
18
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
17
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
19
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
20
import org.eclipse.e4.ui.internal.css.swt.CSSActivator;
21
import org.eclipse.emf.common.util.URI;
18
import org.eclipse.swt.custom.CTabFolder;
22
import org.eclipse.swt.custom.CTabFolder;
19
import org.eclipse.swt.custom.CTabFolderRenderer;
20
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Control;
24
import org.osgi.framework.Bundle;
21
import org.w3c.dom.css.CSSPrimitiveValue;
25
import org.w3c.dom.css.CSSPrimitiveValue;
22
import org.w3c.dom.css.CSSValue;
26
import org.w3c.dom.css.CSSValue;
23
27
Lines 32-46 Link Here
32
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
36
		if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
33
			if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
37
			if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
34
				String rendURL = ((CSSPrimitiveValue) value).getStringValue();
38
				String rendURL = ((CSSPrimitiveValue) value).getStringValue();
35
			
39
				URI uri = URI.createURI(rendURL);
36
				Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
40
				Bundle bundle = CSSActivator.getDefault().getBundleForName(uri.segment(1));
37
				if (cssContext != null && cssContext instanceof IEclipseContext) {
41
				if (bundle != null) {
38
					IEclipseContext context = (IEclipseContext) cssContext;
42
					if (uri.segmentCount() > 3) {
39
					context.set(CTabFolder.class.getName(), control);
43
						//TODO: handle this case?
40
					IContributionFactory factory = (IContributionFactory) context.get(IContributionFactory.class.getName());
44
					} else {
41
					Object rend = factory.create(rendURL, context);
45
						String clazz = uri.segment(2);
42
					if (rend != null && rend instanceof CTabFolderRenderer){
46
						try {
43
						((CTabFolder) control).setRenderer((CTabFolderRenderer)rend);
47
							Class<?> targetClass = bundle.loadClass(clazz);
48
							Constructor constructor = targetClass.getConstructor(CTabFolder.class);
49
							if (constructor != null) {
50
								Object rend = constructor.newInstance(control);
51
								if (rend != null && rend instanceof CTabFolderRenderer) {
52
									((CTabFolder) control).setRenderer((CTabFolderRenderer)rend);
53
								}
54
							}
55
						} catch (ClassNotFoundException e) {
56
							String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
57
									+ bundle.getBundleId() + "'"; //$NON-NLS-1$
58
							System.err.println(message);
59
							if (e != null) {
60
								e.printStackTrace(System.err);
61
							}
62
						} 
44
					}
63
					}
45
				}
64
				}
46
			} else {
65
			} else {
(-)src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java (-11 / +9 lines)
Lines 8-13 Link Here
8
 *******************************************************************************/
8
 *******************************************************************************/
9
package org.eclipse.e4.ui.css.swt.properties.custom;
9
package org.eclipse.e4.ui.css.swt.properties.custom;
10
10
11
import java.lang.reflect.Method;
12
11
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
13
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
12
import org.eclipse.e4.core.contexts.IEclipseContext;
14
import org.eclipse.e4.core.contexts.IEclipseContext;
13
import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
15
import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
Lines 38-54 Link Here
38
			folder.setBackground(colors, percents, true);
40
			folder.setBackground(colors, percents, true);
39
			
41
			
40
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
42
			CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
41
			Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
43
			
42
			if (cssContext != null && cssContext instanceof IEclipseContext) {
44
			if (pseudo != null && pseudo.equals("selected")) {
43
				IEclipseContext context = (IEclipseContext) cssContext;
45
				Method m = renderer.getClass().getMethod("setActiveToolbarGradient",  new Class[]{Color[].class, int[].class});
44
				if (pseudo != null && pseudo.equals("selected")) {
46
				m.invoke(renderer, colors, percents);
45
					context.set("activeToolbarColors", colors);
47
			} else {
46
					context.set("activeToolbarPercents", percents);
48
				Method m = renderer.getClass().getMethod("setInactiveToolbarGradient",  new Class[]{Color[].class, int[].class});
47
				} else {
49
				m.invoke(renderer, colors, percents);
48
					context.set("inactiveToolbarColors", colors);
49
					context.set("inactiveToolbarPercents", percents);
50
				}
51
				ContextInjectionFactory.inject(renderer, context); 
52
			}
50
			}
53
		}
51
		}
54
	}
52
	}
(-)src/org/eclipse/e4/ui/internal/css/swt/CSSActivator.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2010 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.e4.ui.internal.css.swt;
12
13
import org.osgi.framework.Bundle;
14
import org.osgi.framework.BundleActivator;
15
import org.osgi.framework.BundleContext;
16
import org.osgi.service.packageadmin.PackageAdmin;
17
import org.osgi.util.tracker.ServiceTracker;
18
19
public class CSSActivator implements BundleActivator {
20
21
	private static CSSActivator activator;
22
23
	private BundleContext context;
24
	private ServiceTracker pkgAdminTracker;
25
26
	public static CSSActivator getDefault() {
27
		return activator;
28
	}
29
30
	public Bundle getBundle() {
31
		return context.getBundle();
32
	}
33
34
	public PackageAdmin getBundleAdmin() {
35
		if (pkgAdminTracker == null) {
36
			if (context == null)
37
				return null;
38
			pkgAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null);
39
			pkgAdminTracker.open();
40
		}
41
		return (PackageAdmin) pkgAdminTracker.getService();
42
	}
43
44
	/**
45
	 * @param bundleName
46
	 *            the bundle id
47
	 * @return A bundle if found, or <code>null</code>
48
	 */
49
	public Bundle getBundleForName(String bundleName) {
50
		Bundle[] bundles = getBundleAdmin().getBundles(bundleName, null);
51
		if (bundles == null)
52
			return null;
53
		// Return the first bundle that is not installed or uninstalled
54
		for (int i = 0; i < bundles.length; i++) {
55
			if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
56
				return bundles[i];
57
			}
58
		}
59
		return null;
60
	}
61
62
	public BundleContext getContext() {
63
		return context;
64
	}
65
66
	public void start(BundleContext context) throws Exception {
67
		activator = this;
68
		this.context = context;
69
	}
70
71
	public void stop(BundleContext context) throws Exception {
72
		if (pkgAdminTracker != null) {
73
			pkgAdminTracker.close();
74
			pkgAdminTracker = null;
75
		}
76
		context = null;
77
	}
78
	
79
	
80
81
}

Return to bug 313950