Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe2010-07-07 22:26:20 +0000
committerBogdan Gheorghe2010-07-07 22:26:20 +0000
commit5ff7eb5cebf3443880496aa4329547f5a02730a2 (patch)
tree74b9bd41dfbe889e23a096e5a6b44447e1767b44 /bundles/org.eclipse.e4.ui.css.swt/src/org
parent3c60682018d9b0d6c511be6ec245ec8f1f75be4d (diff)
downloadeclipse.platform.ui-5ff7eb5cebf3443880496aa4329547f5a02730a2.tar.gz
eclipse.platform.ui-5ff7eb5cebf3443880496aa4329547f5a02730a2.tar.xz
eclipse.platform.ui-5ff7eb5cebf3443880496aa4329547f5a02730a2.zip
313950 - CSS Engine creates unnecessary contexts and injections
Diffstat (limited to 'bundles/org.eclipse.e4.ui.css.swt/src/org')
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java13
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java17
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java28
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java14
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java43
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java20
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/internal/css/swt/CSSActivator.java81
7 files changed, 135 insertions, 81 deletions
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java
index 0bf6ec4cbb8..a2284200b0e 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyCornerRadiusSWTHandler.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.custom;
+import java.lang.reflect.Method;
+import org.eclipse.swt.graphics.Color;
+
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
@@ -31,15 +34,9 @@ public class CSSPropertyCornerRadiusSWTHandler extends AbstractCSSPropertySWTHan
if (!(control instanceof CTabFolder)) return;
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
int radiusValue = (int) ((CSSPrimitiveValue) value).getFloatValue(CSSPrimitiveValue.CSS_NUMBER);
-
CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
-
- Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
- if (cssContext != null && cssContext instanceof IEclipseContext) {
- IEclipseContext context = (IEclipseContext) cssContext;
- context.set("radius", new Integer(radiusValue));
- ContextInjectionFactory.inject(renderer, context);
- }
+ Method m = renderer.getClass().getMethod("setCornerRadius", new Class[]{int.class});
+ m.invoke(renderer, radiusValue);
}
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java
index f218295cc95..23db61e74e0 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyInnerKeylineSWTHandler.java
@@ -33,22 +33,9 @@ public class CSSPropertyInnerKeylineSWTHandler extends AbstractCSSPropertySWTHan
if (!(control instanceof CTabFolder)) return;
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay());
-
CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
- if (cssContext != null && cssContext instanceof IEclipseContext) {
- IEclipseContext context = (IEclipseContext) cssContext;
- context.set("innerKeyline", newColor);
- ContextInjectionFactory.inject(renderer, context);
- } else {
- Method[] methods = renderer.getClass().getMethods();
- for (int i = 0; i < methods.length; i++) {
- Method m = methods[i];
- if (m.getName().toLowerCase().contains("setinnerkeyline")) {
- m.invoke(renderer, newColor);
- }
- }
- }
+ Method m = renderer.getClass().getMethod("setInnerKeyline", new Class[]{Color.class});
+ m.invoke(renderer, newColor);
}
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java
index 6fc83808105..165742aa3aa 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyOuterKeylineSWTHandler.java
@@ -10,11 +10,7 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.custom;
-import java.util.HashMap;
-
import java.lang.reflect.Method;
-import org.eclipse.e4.core.contexts.ContextInjectionFactory;
-import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
@@ -26,8 +22,6 @@ import org.w3c.dom.css.CSSValue;
public class CSSPropertyOuterKeylineSWTHandler extends AbstractCSSPropertySWTHandler {
- HashMap contexts = new HashMap();
-
public static final ICSSPropertyHandler INSTANCE = new CSSPropertyOuterKeylineSWTHandler();
@Override
@@ -36,27 +30,9 @@ public class CSSPropertyOuterKeylineSWTHandler extends AbstractCSSPropertySWTHan
if (!(control instanceof CTabFolder)) return;
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
Color newColor = (Color) engine.convert(value, Color.class, control.getDisplay());
-
CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
- if (cssContext != null && cssContext instanceof IEclipseContext) {
- IEclipseContext context = (IEclipseContext) cssContext;
- IEclipseContext childContext = (IEclipseContext) contexts.get(control);
- if (childContext == null) {
- childContext = context.createChild();
- contexts.put(control, childContext);
- }
- childContext.set("outerKeyline", newColor);
- ContextInjectionFactory.inject(renderer, childContext);
- } else {
- Method[] methods = renderer.getClass().getMethods();
- for (int i = 0; i < methods.length; i++) {
- Method m = methods[i];
- if (m.getName().toLowerCase().contains("setouterkeyline")) {
- m.invoke(renderer, newColor);
- }
- }
- }
+ Method m = renderer.getClass().getMethod("setOuterKeyline", new Class[]{Color.class});
+ m.invoke(renderer, newColor);
}
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java
index cd430608827..26eac406650 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyShadowVisibleSWTHandler.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.custom;
+import java.lang.reflect.Method;
+import org.eclipse.swt.graphics.Color;
+
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
@@ -29,16 +32,9 @@ public class CSSPropertyShadowVisibleSWTHandler extends AbstractCSSPropertySWTHa
CSSValue value, String pseudo, CSSEngine engine) throws Exception {
if (!(control instanceof CTabFolder)) return;
boolean shadowVisible = (Boolean) engine.convert(value, Boolean.class, null);
-
CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
-
- Object appContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
- if (appContext != null && appContext instanceof IEclipseContext) {
- IEclipseContext context = (IEclipseContext) appContext;
- IEclipseContext childContext = context.createChild();
- childContext.set("shadowVisible", new Boolean(shadowVisible));
- ContextInjectionFactory.inject(renderer, childContext);
- }
+ Method m = renderer.getClass().getMethod("setShadowVisible", new Class[]{boolean.class});
+ m.invoke(renderer, shadowVisible);
}
protected String retrieveCSSProperty(Control control, String property,
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java
index 1fa541cea83..c8abafb1293 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyTabRendererSWTHandler.java
@@ -10,14 +10,18 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.custom;
-import org.eclipse.e4.core.contexts.IEclipseContext;
-import org.eclipse.e4.core.services.contributions.IContributionFactory;
+import org.eclipse.swt.custom.CTabFolderRenderer;
+
+import java.lang.reflect.Constructor;
+
import org.eclipse.e4.ui.css.core.dom.properties.ICSSPropertyHandler;
import org.eclipse.e4.ui.css.core.engine.CSSEngine;
import org.eclipse.e4.ui.css.swt.properties.AbstractCSSPropertySWTHandler;
+import org.eclipse.e4.ui.internal.css.swt.CSSActivator;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.swt.custom.CTabFolder;
-import org.eclipse.swt.custom.CTabFolderRenderer;
import org.eclipse.swt.widgets.Control;
+import org.osgi.framework.Bundle;
import org.w3c.dom.css.CSSPrimitiveValue;
import org.w3c.dom.css.CSSValue;
@@ -32,15 +36,30 @@ public class CSSPropertyTabRendererSWTHandler extends AbstractCSSPropertySWTHand
if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
String rendURL = ((CSSPrimitiveValue) value).getStringValue();
-
- Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
- if (cssContext != null && cssContext instanceof IEclipseContext) {
- IEclipseContext context = (IEclipseContext) cssContext;
- context.set(CTabFolder.class.getName(), control);
- IContributionFactory factory = (IContributionFactory) context.get(IContributionFactory.class.getName());
- Object rend = factory.create(rendURL, context);
- if (rend != null && rend instanceof CTabFolderRenderer){
- ((CTabFolder) control).setRenderer((CTabFolderRenderer)rend);
+ URI uri = URI.createURI(rendURL);
+ Bundle bundle = CSSActivator.getDefault().getBundleForName(uri.segment(1));
+ if (bundle != null) {
+ if (uri.segmentCount() > 3) {
+ //TODO: handle this case?
+ } else {
+ String clazz = uri.segment(2);
+ try {
+ Class<?> targetClass = bundle.loadClass(clazz);
+ Constructor constructor = targetClass.getConstructor(CTabFolder.class);
+ if (constructor != null) {
+ Object rend = constructor.newInstance(control);
+ if (rend != null && rend instanceof CTabFolderRenderer) {
+ ((CTabFolder) control).setRenderer((CTabFolderRenderer)rend);
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$
+ + bundle.getBundleId() + "'"; //$NON-NLS-1$
+ System.err.println(message);
+ if (e != null) {
+ e.printStackTrace(System.err);
+ }
+ }
}
}
} else {
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java
index e3d47f417f3..4aa915fe6e1 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/properties/custom/CSSPropertyUnselectedTabsSWTHandler.java
@@ -8,6 +8,8 @@
*******************************************************************************/
package org.eclipse.e4.ui.css.swt.properties.custom;
+import java.lang.reflect.Method;
+
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.css.core.dom.properties.Gradient;
@@ -38,17 +40,13 @@ public class CSSPropertyUnselectedTabsSWTHandler extends AbstractCSSPropertySWTH
folder.setBackground(colors, percents, true);
CTabFolderRenderer renderer = ((CTabFolder) control).getRenderer();
- Object cssContext = control.getDisplay().getData("org.eclipse.e4.ui.css.context");
- if (cssContext != null && cssContext instanceof IEclipseContext) {
- IEclipseContext context = (IEclipseContext) cssContext;
- if (pseudo != null && pseudo.equals("selected")) {
- context.set("activeToolbarColors", colors);
- context.set("activeToolbarPercents", percents);
- } else {
- context.set("inactiveToolbarColors", colors);
- context.set("inactiveToolbarPercents", percents);
- }
- ContextInjectionFactory.inject(renderer, context);
+
+ if (pseudo != null && pseudo.equals("selected")) {
+ Method m = renderer.getClass().getMethod("setActiveToolbarGradient", new Class[]{Color[].class, int[].class});
+ m.invoke(renderer, colors, percents);
+ } else {
+ Method m = renderer.getClass().getMethod("setInactiveToolbarGradient", new Class[]{Color[].class, int[].class});
+ m.invoke(renderer, colors, percents);
}
}
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/internal/css/swt/CSSActivator.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/internal/css/swt/CSSActivator.java
new file mode 100644
index 00000000000..882dfd60efe
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/internal/css/swt/CSSActivator.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.e4.ui.internal.css.swt;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class CSSActivator implements BundleActivator {
+
+ private static CSSActivator activator;
+
+ private BundleContext context;
+ private ServiceTracker pkgAdminTracker;
+
+ public static CSSActivator getDefault() {
+ return activator;
+ }
+
+ public Bundle getBundle() {
+ return context.getBundle();
+ }
+
+ public PackageAdmin getBundleAdmin() {
+ if (pkgAdminTracker == null) {
+ if (context == null)
+ return null;
+ pkgAdminTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null);
+ pkgAdminTracker.open();
+ }
+ return (PackageAdmin) pkgAdminTracker.getService();
+ }
+
+ /**
+ * @param bundleName
+ * the bundle id
+ * @return A bundle if found, or <code>null</code>
+ */
+ public Bundle getBundleForName(String bundleName) {
+ Bundle[] bundles = getBundleAdmin().getBundles(bundleName, null);
+ if (bundles == null)
+ return null;
+ // Return the first bundle that is not installed or uninstalled
+ for (int i = 0; i < bundles.length; i++) {
+ if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
+ return bundles[i];
+ }
+ }
+ return null;
+ }
+
+ public BundleContext getContext() {
+ return context;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ activator = this;
+ this.context = context;
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ if (pkgAdminTracker != null) {
+ pkgAdminTracker.close();
+ pkgAdminTracker = null;
+ }
+ context = null;
+ }
+
+
+
+}

Back to the top