diff options
author | jonas | 2014-11-13 17:53:41 +0000 |
---|---|---|
committer | jonas | 2014-11-13 17:53:57 +0000 |
commit | 363bb37ee92ba94dea9c820a94708ed9b7584520 (patch) | |
tree | 8d55a82ba4f6977b7608af8d2c58c6634f54159c | |
parent | c6f504a963c8b91ffab685c50243f058985b7311 (diff) | |
download | org.eclipse.e4.tools-I20141113-2200.tar.gz org.eclipse.e4.tools-I20141113-2200.tar.xz org.eclipse.e4.tools-I20141113-2200.zip |
Bug 444340 - Externalize Strings - and Bug 444692I20141117-2200I20141117-0900I20141116-2200I20141115-2200I20141114-2200I20141113-2200
13 files changed, 228 insertions, 183 deletions
diff --git a/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF index ad7b0ab6..c1c3677d 100644 --- a/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.tools.compat/META-INF/MANIFEST.MF @@ -14,8 +14,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.6.0", org.eclipse.e4.ui.css.swt.theme;bundle-version="0.9.0", org.eclipse.e4.ui.di;bundle-version="0.9.0", org.eclipse.core.databinding;bundle-version="1.4.0" -Export-Package: org.eclipse.e4.tools.compat.internal;x-internal:=true, - org.eclipse.e4.tools.compat.parts;x-internal:=true +Export-Package: org.eclipse.e4.tools.compat.internal;version="0.12.0.qualifier";x-internal:=true, + org.eclipse.e4.tools.compat.parts;version="0.12.0.qualifier";x-internal:=true Bundle-ActivationPolicy: lazy Bundle-Vendor: %Bundle-Vendor Import-Package: javax.inject;version="1.0.0" diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ContextServiceFactory.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ContextServiceFactory.java index 11f44408..bb54e563 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ContextServiceFactory.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ContextServiceFactory.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation - * Lars Vogel <Lars.Vogel@gmail.com> - Bug 421453 + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 421453 ******************************************************************************/ package org.eclipse.e4.tools.compat.internal; @@ -46,25 +46,24 @@ public class ContextServiceFactory extends AbstractServiceFactory { @Override public Object create(@SuppressWarnings("rawtypes") Class serviceInterface, IServiceLocator parentLocator, - IServiceLocator locator) { - if( ! IEclipseContext.class.equals(serviceInterface) ) { + IServiceLocator locator) { + if (!IEclipseContext.class.equals(serviceInterface)) { return null; } - - IWorkbenchLocationService wls = (IWorkbenchLocationService) locator.getService(IWorkbenchLocationService.class); + final IWorkbenchLocationService wls = (IWorkbenchLocationService) locator + .getService(IWorkbenchLocationService.class); final IWorkbenchWindow window = wls.getWorkbenchWindow(); final IWorkbenchPartSite site = wls.getPartSite(); - Object o = parentLocator.getService(serviceInterface); + final Object o = parentLocator.getService(serviceInterface); // This happens when we run in plain 3.x // We need to create a parent service context - if( window == null && site == null ) { - Bundle bundle = FrameworkUtil.getBundle(ContextServiceFactory.class); - BundleContext bundleContext = bundle.getBundleContext(); - IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext); - + if (window == null && site == null) { + final Bundle bundle = FrameworkUtil.getBundle(ContextServiceFactory.class); + final BundleContext bundleContext = bundle.getBundleContext(); + final IEclipseContext serviceContext = EclipseContextFactory.getServiceContext(bundleContext); final IEclipseContext appContext = serviceContext.createChild("WorkbenchContext"); //$NON-NLS-1$ appContext.set(Display.class, Display.getCurrent()); @@ -86,10 +85,11 @@ public class ContextServiceFactory extends AbstractServiceFactory { } }); - IContributionFactory contributionFactory = ContextInjectionFactory.make(ReflectionContributionFactory.class, appContext); - appContext.set(IContributionFactory.class.getName(),contributionFactory); + final IContributionFactory contributionFactory = ContextInjectionFactory.make( + ReflectionContributionFactory.class, appContext); + appContext.set(IContributionFactory.class.getName(), contributionFactory); - IThemeManager manager = serviceContext.get(IThemeManager.class); + final IThemeManager manager = serviceContext.get(IThemeManager.class); final IThemeEngine engine = manager.getEngineForDisplay(Display.getCurrent()); appContext.set(IThemeEngine.class, engine); @@ -97,8 +97,7 @@ public class ContextServiceFactory extends AbstractServiceFactory { @Override public void setClassname(Object widget, String classname) { - ((Widget) widget).setData( - "org.eclipse.e4.ui.css.CssClassName", classname); //$NON-NLS-1$ + ((Widget) widget).setData("org.eclipse.e4.ui.css.CssClassName", classname); //$NON-NLS-1$ engine.applyStyles(widget, true); } @@ -120,21 +119,21 @@ public class ContextServiceFactory extends AbstractServiceFactory { @Override public void setClassnameAndId(Object widget, String classname, - String id) { - ((Widget) widget).setData( - "org.eclipse.e4.ui.css.CssClassName", classname); //$NON-NLS-1$ + String id) { + ((Widget) widget).setData("org.eclipse.e4.ui.css.CssClassName", classname); //$NON-NLS-1$ ((Widget) widget).setData("org.eclipse.e4.ui.css.id", id); //$NON-NLS-1$ engine.applyStyles(widget, true); } }); - if( appContext.get(ILoggerProvider.class) == null ) { - appContext.set(ILoggerProvider.class, ContextInjectionFactory.make(DefaultLoggerProvider.class, appContext)); + if (appContext.get(ILoggerProvider.class) == null) { + appContext.set(ILoggerProvider.class, + ContextInjectionFactory.make(DefaultLoggerProvider.class, appContext)); } return appContext; - } else if( o != null && site == null ) { - final IEclipseContext windowContext = ((IEclipseContext)o).createChild("WindowContext("+window+")"); + } else if (o != null && site == null) { + final IEclipseContext windowContext = ((IEclipseContext) o).createChild("WindowContext(" + window + ")"); //$NON-NLS-1$ //$NON-NLS-2$ windowContext.set(ISelectionService.class, window.getSelectionService()); windowContext.declareModifiable(IServiceConstants.ACTIVE_SELECTION); @@ -142,10 +141,10 @@ public class ContextServiceFactory extends AbstractServiceFactory { @Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { - if( ! selection.isEmpty() ) { - if( selection instanceof IStructuredSelection ) { - IStructuredSelection s = (IStructuredSelection) selection; - if( s.size() == 1 ) { + if (!selection.isEmpty()) { + if (selection instanceof IStructuredSelection) { + final IStructuredSelection s = (IStructuredSelection) selection; + if (s.size() == 1) { windowContext.set(IServiceConstants.ACTIVE_SELECTION, s.getFirstElement()); } else { windowContext.set(IServiceConstants.ACTIVE_SELECTION, s.toList()); diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CopyAction.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CopyAction.java index a6493fee..153fc5b4 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CopyAction.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CopyAction.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation ******************************************************************************/ package org.eclipse.e4.tools.compat.internal; @@ -14,13 +14,13 @@ import org.eclipse.e4.tools.services.IClipboardService; import org.eclipse.jface.action.Action; public class CopyAction extends Action { - private IClipboardService service; - + private final IClipboardService service; + public CopyAction(IClipboardService service) { - super("Copy"); + super(Messages.CopyAction); this.service = service; } - + @Override public void run() { service.copy(); diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CutAction.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CutAction.java index 02a0c9dd..88f8fbb7 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CutAction.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/CutAction.java @@ -17,7 +17,7 @@ public class CutAction extends Action { private IClipboardService service; public CutAction(IClipboardService service) { - super("Cut"); + super(Messages.CutAction); this.service = service; } diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DefaultLoggerProvider.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DefaultLoggerProvider.java index ea751895..cfa745ba 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DefaultLoggerProvider.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/DefaultLoggerProvider.java @@ -8,13 +8,14 @@ import org.eclipse.e4.core.services.log.ILoggerProvider; import org.eclipse.e4.core.services.log.Logger; import org.osgi.framework.FrameworkUtil; +@SuppressWarnings("restriction") public class DefaultLoggerProvider implements ILoggerProvider { @Inject private IEclipseContext context; @Override public Logger getClassLogger(Class<?> clazz) { - IEclipseContext childContext = context.createChild(); + final IEclipseContext childContext = context.createChild(); childContext.set("logger.bundlename", FrameworkUtil.getBundle(clazz).getSymbolicName()); //$NON-NLS-1$ return ContextInjectionFactory.make(WorkbenchLogger.class, childContext); } diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Messages.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Messages.java new file mode 100644 index 00000000..c1fe7f67 --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Messages.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 EclipseSource Muenchen GmbH 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: + * Jonas - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.tools.compat.internal; + +import org.eclipse.osgi.util.NLS; + +/** + * @author Jonas + * + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.e4.tools.compat.internal.messages"; //$NON-NLS-1$ + public static String CopyAction; + public static String CutAction; + public static String PasteAction; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PartHelper.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PartHelper.java index d752045c..996cbad8 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PartHelper.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PartHelper.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation + * Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation ******************************************************************************/ package org.eclipse.e4.tools.compat.internal; @@ -30,82 +30,84 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.part.WorkbenchPart; public class PartHelper { + private static final String ORG_ECLIPSE_E4_UI_WORKBENCH_I_PRESENTATION_ENGINE = "org.eclipse.e4.ui.workbench.IPresentationEngine"; //$NON-NLS-1$ + public static IEclipseContext createPartContext(WorkbenchPart part) throws PartInitException { - IWorkbenchPartSite site = part.getSite(); - IEclipseContext parentContext = (IEclipseContext) site.getService(IEclipseContext.class); - + final IWorkbenchPartSite site = part.getSite(); + final IEclipseContext parentContext = (IEclipseContext) site.getService(IEclipseContext.class); + // Check if running in 4.x - if( parentContext.get("org.eclipse.e4.ui.workbench.IPresentationEngine") != null ) { + if (parentContext.get(ORG_ECLIPSE_E4_UI_WORKBENCH_I_PRESENTATION_ENGINE) != null) { // Hack to get the MPart-Context try { - Class<?> clazz = Util.getBundle("org.eclipse.e4.ui.model.workbench").loadClass("org.eclipse.e4.ui.model.application.ui.basic.MPart"); - Object instance = site.getService(clazz); - Method m = clazz.getMethod("getContext", new Class[0]); + final Class<?> clazz = Util.getBundle("org.eclipse.e4.ui.model.workbench").loadClass( //$NON-NLS-1$ + "org.eclipse.e4.ui.model.application.ui.basic.MPart"); //$NON-NLS-1$ + final Object instance = site.getService(clazz); + final Method m = clazz.getMethod("getContext", new Class[0]); //$NON-NLS-1$ IEclipseContext ctx = (IEclipseContext) m.invoke(instance); - IEclipseContext rv = ctx; - while( ctx.getParent() != null ) { + final IEclipseContext rv = ctx; + while (ctx.getParent() != null) { ctx = ctx.getParent(); } ctx.set(IClipboardService.class, new ClipboardServiceImpl()); return rv; - } catch (Exception e) { - throw new PartInitException("Could not create context",e); + } catch (final Exception e) { + throw new PartInitException("Could not create context", e); //$NON-NLS-1$ } - } else { - return parentContext.createChild("EditPart('"+part.getPartName()+"')"); //$NON-NLS-1$ } + return parentContext.createChild("EditPart('" + part.getPartName() + "')"); //$NON-NLS-1$ //$NON-NLS-2$ } - + public static <C> C createComponent(Composite parent, IEclipseContext context, Class<C> clazz, WorkbenchPart part) { - ISelectionProvider s = new SelectionProviderImpl(); + final ISelectionProvider s = new SelectionProviderImpl(); context.set(ISelectionProvider.class, s); part.getSite().setSelectionProvider(s); - - IStylingEngine styleEngine = context.get(IStylingEngine.class); - Composite comp = new Composite(parent, SWT.NONE); + + final IStylingEngine styleEngine = context.get(IStylingEngine.class); + final Composite comp = new Composite(parent, SWT.NONE); comp.setBackgroundMode(SWT.INHERIT_DEFAULT); - - //FIXME This should be read from the CSS - FillLayout layout = new FillLayout(); + + // FIXME This should be read from the CSS + final FillLayout layout = new FillLayout(); layout.marginWidth = 10; layout.marginHeight = 10; comp.setLayout(layout); - + context.set(Composite.class.getName(), comp); - C component = ContextInjectionFactory.make(clazz, context); - + final C component = ContextInjectionFactory.make(clazz, context); + styleEngine.setClassname(comp, part.getClass().getSimpleName()); - + return component; } - + static class SelectionProviderImpl implements ISelectionProvider { private ISelection currentSelection = StructuredSelection.EMPTY; - - private ListenerList listeners = new ListenerList(); - + + private final ListenerList listeners = new ListenerList(); + @Override public void setSelection(ISelection selection) { currentSelection = selection; - SelectionChangedEvent evt = new SelectionChangedEvent(this, selection); - - for( Object l : listeners.getListeners() ) { - ((ISelectionChangedListener)l).selectionChanged(evt); + final SelectionChangedEvent evt = new SelectionChangedEvent(this, selection); + + for (final Object l : listeners.getListeners()) { + ((ISelectionChangedListener) l).selectionChanged(evt); } } - + @Override public void removeSelectionChangedListener( - ISelectionChangedListener listener) { + ISelectionChangedListener listener) { listeners.remove(listener); } - + @Override public ISelection getSelection() { return currentSelection; } - + @Override public void addSelectionChangedListener(ISelectionChangedListener listener) { listeners.add(listener); @@ -113,14 +115,14 @@ public class PartHelper { } public static void disposeContextIfE3(IEclipseContext parentContext, - IEclipseContext context) { - // Check if running in 3.x, otherwise there was no dedicated context - // created - if (parentContext - .get("org.eclipse.e4.ui.workbench.IPresentationEngine") == null) { - context.dispose(); - context = null; + IEclipseContext context) { + // Check if running in 3.x, otherwise there was no dedicated context + // created + if (parentContext + .get(ORG_ECLIPSE_E4_UI_WORKBENCH_I_PRESENTATION_ENGINE) == null) { + context.dispose(); + context = null; } - + } } diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PasteAction.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PasteAction.java index 9e3b40a2..cb2cbbc2 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PasteAction.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/PasteAction.java @@ -16,7 +16,7 @@ import org.eclipse.jface.action.Action; public class PasteAction extends Action { private IClipboardService service; public PasteAction(IClipboardService service) { - super("Paste"); + super(Messages.PasteAction); this.service = service; } diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java index fc626d06..c473d725 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/ReflectionContributionFactory.java @@ -24,21 +24,21 @@ import org.osgi.service.packageadmin.PackageAdmin; /** * Create the contribution factory. */ -@SuppressWarnings("restriction") +@SuppressWarnings({ "restriction", "deprecation" }) public class ReflectionContributionFactory implements IContributionFactory { - private IExtensionRegistry registry; + private final IExtensionRegistry registry; private Map<String, Object> languages; @Inject private PackageAdmin packageAdmin; - + @Inject private Logger logger; - + /** * Create a reflection factory. - * + * * @param registry * to read languages. */ @@ -67,64 +67,65 @@ public class ReflectionContributionFactory implements IContributionFactory { if (uriString.startsWith("platform:/plugin/")) { //$NON-NLS-1$ logger.error("platform-style URIs deprecated for referencing types: " + uriString); //$NON-NLS-1$ uriString = uriString - .replace("platform:/plugin/", "bundleclass://"); //$NON-NLS-1$ //$NON-NLS-2$ + .replace("platform:/plugin/", "bundleclass://"); //$NON-NLS-1$ //$NON-NLS-2$ logger.error("URI rewritten as: " + uriString); //$NON-NLS-1$ } - URI uri = URI.createURI(uriString); - Bundle bundle = getBundle(uri); + final URI uri = URI.createURI(uriString); + final Bundle bundle = getBundle(uri); Object contribution; if (bundle != null) { contribution = createFromBundle(bundle, context, staticContext, uri); } else { contribution = null; logger.error("Unable to retrive the bundle from the URI: " //$NON-NLS-1$ - + uriString); + + uriString); } return contribution; } protected Object createFromBundle(Bundle bundle, IEclipseContext context, - IEclipseContext staticContext, URI uri) { + IEclipseContext staticContext, URI uri) { Object contribution; if (uri.segmentCount() > 1) { - String prefix = uri.segment(0); - IContributionFactorySpi factory = (IContributionFactorySpi) languages.get(prefix); - if(factory == null) { - String message = "Unsupported contribution factory type '" + prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$ - logger.error(message); - return null; + final String prefix = uri.segment(0); + final IContributionFactorySpi factory = (IContributionFactorySpi) languages.get(prefix); + if (factory == null) { + final String message = "Unsupported contribution factory type '" + prefix + "'"; //$NON-NLS-1$ //$NON-NLS-2$ + logger.error(message); + return null; } - StringBuffer resource = new StringBuffer(uri.segment(1)); + final StringBuffer resource = new StringBuffer(uri.segment(1)); for (int i = 2; i < uri.segmentCount(); i++) { resource.append('/'); resource.append(uri.segment(i)); } contribution = factory.create(bundle, resource.toString(), context); } else { - String clazz = uri.segment(0); + final String clazz = uri.segment(0); try { - Class<?> targetClass = bundle.loadClass(clazz); - if (staticContext == null) + final Class<?> targetClass = bundle.loadClass(clazz); + if (staticContext == null) { contribution = ContextInjectionFactory.make(targetClass, context); - else + } else { contribution = ContextInjectionFactory - .make(targetClass, context, staticContext); + .make(targetClass, context, staticContext); + } if (contribution == null) { - String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ - + bundle.getBundleId() + "'"; //$NON-NLS-1$ + final String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ + + bundle.getBundleId() + "'"; //$NON-NLS-1$ logger.error(message); } - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { contribution = null; - String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ - + bundle.getBundleId() + "'"; //$NON-NLS-1$ - logger.error(e,message); - } catch (InjectionException e) { + final String message = "Unable to load class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ + + bundle.getBundleId() + "'"; //$NON-NLS-1$ + logger.error(e, message); + } catch (final InjectionException e) { contribution = null; - String message = "Unable to create class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ - + bundle.getBundleId() + "'"; //$NON-NLS-1$ + final String message = "Unable to create class '" + clazz + "' from bundle '" //$NON-NLS-1$ //$NON-NLS-2$ + + bundle.getBundleId() + "'"; //$NON-NLS-1$ logger.error(e, message); } } @@ -133,24 +134,23 @@ public class ReflectionContributionFactory implements IContributionFactory { protected void processLanguages() { languages = new HashMap<String, Object>(); - String extId = "org.eclipse.e4.languages"; //$NON-NLS-1$ - IConfigurationElement[] languageElements = registry.getConfigurationElementsFor(extId); + final String extId = "org.eclipse.e4.languages"; //$NON-NLS-1$ + final IConfigurationElement[] languageElements = registry.getConfigurationElementsFor(extId); for (int i = 0; i < languageElements.length; i++) { - IConfigurationElement languageElement = languageElements[i]; + final IConfigurationElement languageElement = languageElements[i]; try { languages.put(languageElement.getAttribute("name"), //$NON-NLS-1$ - languageElement.createExecutableExtension("contributionFactory")); //$NON-NLS-1$ - } catch (InvalidRegistryObjectException e) { + languageElement.createExecutableExtension("contributionFactory")); //$NON-NLS-1$ + } catch (final InvalidRegistryObjectException e) { // TODO Auto-generated catch block e.printStackTrace(); - } catch (CoreException e) { + } catch (final CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } - protected Bundle getBundle(URI platformURI) { return getBundleForName(platformURI.authority()); } @@ -159,18 +159,19 @@ public class ReflectionContributionFactory implements IContributionFactory { public Bundle getBundle(String uriString) { return getBundle(new URI(uriString)); } - + public Bundle getBundleForName(String bundlename) { - if( packageAdmin == null ) { - Bundle bundle = FrameworkUtil.getBundle(getClass()); - BundleContext context = bundle.getBundleContext(); - ServiceReference reference = context.getServiceReference(PackageAdmin.class.getName()); - packageAdmin = (PackageAdmin) context.getService(reference); + if (packageAdmin == null) { + final Bundle bundle = FrameworkUtil.getBundle(getClass()); + final BundleContext context = bundle.getBundleContext(); + final ServiceReference<?> reference = context.getServiceReference(PackageAdmin.class.getName()); + packageAdmin = (PackageAdmin) context.getService(reference); } - - Bundle[] bundles = packageAdmin.getBundles(bundlename, null); - if (bundles == null) + + final Bundle[] bundles = packageAdmin.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) { @@ -179,35 +180,37 @@ public class ReflectionContributionFactory implements IContributionFactory { } return null; } - + static class URI { - String scheme; + String scheme; String authority; String[] segments = new String[0]; - + URI(String uriString) { - int colon = uriString.indexOf(':'); - if(colon < 0) { throw new IllegalArgumentException("invalid URI"); } - scheme = uriString.substring(0, colon); - uriString = uriString.substring(colon + 1); - if(uriString.startsWith("//")) { - int authEnd = uriString.indexOf('/', 2); - if(authEnd < 0) { - authority = uriString.substring(2); - } else { - authority = uriString.substring(2, authEnd); - segments = uriString.substring(authEnd + 1).split("/"); - } - } else { - segments = uriString.substring(uriString.indexOf('/')+1).split("/"); - } + final int colon = uriString.indexOf(':'); + if (colon < 0) { + throw new IllegalArgumentException("invalid URI"); //$NON-NLS-1$ + } + scheme = uriString.substring(0, colon); + uriString = uriString.substring(colon + 1); + if (uriString.startsWith("//")) { //$NON-NLS-1$ + final int authEnd = uriString.indexOf('/', 2); + if (authEnd < 0) { + authority = uriString.substring(2); + } else { + authority = uriString.substring(2, authEnd); + segments = uriString.substring(authEnd + 1).split("/"); //$NON-NLS-1$ + } + } else { + segments = uriString.substring(uriString.indexOf('/') + 1).split("/"); //$NON-NLS-1$ + } } - + public String authority() { - return authority; - } + return authority; + } - public String segment(int i) { + public String segment(int i) { return segments[i]; } diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java index 567fcc2b..a72f261a 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/Util.java @@ -6,15 +6,18 @@ import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; import org.osgi.service.packageadmin.PackageAdmin; +@SuppressWarnings("deprecation") public class Util { public static Bundle getBundle(String bundleName) { - Bundle bundle = FrameworkUtil.getBundle(Util.class); - BundleContext ctx = bundle.getBundleContext(); - ServiceReference ref = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName()); - PackageAdmin bundleAdmin = (PackageAdmin) ctx.getService(ref); - Bundle[] bundles = bundleAdmin.getBundles(bundleName, null); - if (bundles == null) + final Bundle bundle = FrameworkUtil.getBundle(Util.class); + final BundleContext ctx = bundle.getBundleContext(); + final ServiceReference<PackageAdmin> ref = bundle.getBundleContext().getServiceReference( + PackageAdmin.class); + final PackageAdmin bundleAdmin = ctx.getService(ref); + final Bundle[] bundles = bundleAdmin.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) { diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/WorkbenchLogger.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/WorkbenchLogger.java index eb14dfa4..3806c8d0 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/WorkbenchLogger.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/WorkbenchLogger.java @@ -18,10 +18,11 @@ import org.osgi.framework.FrameworkUtil; /** * The workbench implementation of the logger service. */ +@SuppressWarnings("restriction") public final class WorkbenchLogger extends Logger { protected DebugTrace trace; protected FrameworkLog log; - private Bundle bundle = FrameworkUtil.getBundle(WorkbenchLogger.class); + private final Bundle bundle = FrameworkUtil.getBundle(WorkbenchLogger.class); /** * Creates a new workbench logger @@ -43,43 +44,43 @@ public final class WorkbenchLogger extends Logger { @Override public void error(Throwable t, String message) { log(new Status(IStatus.ERROR, bundle.getSymbolicName(), - message, t)); + message, t)); } /** * Copied from PlatformLogWriter in core runtime. */ private static FrameworkLogEntry getLog(IStatus status) { - Throwable t = status.getException(); - ArrayList childlist = new ArrayList(); + final Throwable t = status.getException(); + final ArrayList<FrameworkLogEntry> childlist = new ArrayList<FrameworkLogEntry>(); - int stackCode = t instanceof CoreException ? 1 : 0; + final int stackCode = t instanceof CoreException ? 1 : 0; // ensure a substatus inside a CoreException is properly logged if (stackCode == 1) { - IStatus coreStatus = ((CoreException) t).getStatus(); + final IStatus coreStatus = ((CoreException) t).getStatus(); if (coreStatus != null) { childlist.add(getLog(coreStatus)); } } if (status.isMultiStatus()) { - IStatus[] children = status.getChildren(); + final IStatus[] children = status.getChildren(); for (int i = 0; i < children.length; i++) { childlist.add(getLog(children[i])); } } - FrameworkLogEntry[] children = (FrameworkLogEntry[]) (childlist.size() == 0 ? null - : childlist.toArray(new FrameworkLogEntry[childlist.size()])); + final FrameworkLogEntry[] children = childlist.size() == 0 ? null + : childlist.toArray(new FrameworkLogEntry[childlist.size()]); return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), - status.getMessage(), stackCode, t, children); + status.getMessage(), stackCode, t, children); } @Override public void info(Throwable t, String message) { log(new Status(IStatus.INFO, bundle.getSymbolicName(), message, - t)); + t)); } @Override @@ -112,21 +113,22 @@ public final class WorkbenchLogger extends Logger { log.log(getLog(status)); } else { System.out.println(status.getMessage()); - if (status.getException() != null) + if (status.getException() != null) { status.getException().printStackTrace(); + } } } /** * Sets the debug options service for this logger. - * + * * @param options * The debug options to be used by this logger */ @Inject public void setDebugOptions(DebugOptions options) { if (options != null) { - this.trace = options.newDebugTrace(bundle.getSymbolicName(), WorkbenchLogger.class); + trace = options.newDebugTrace(bundle.getSymbolicName(), WorkbenchLogger.class); } } @@ -151,6 +153,6 @@ public final class WorkbenchLogger extends Logger { @Override public void warn(Throwable t, String message) { log(new Status(IStatus.WARNING, bundle.getSymbolicName(), - message, t)); + message, t)); } }
\ No newline at end of file diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/messages.properties b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/messages.properties new file mode 100644 index 00000000..d60d7bac --- /dev/null +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/internal/messages.properties @@ -0,0 +1,3 @@ +CopyAction=Copy +CutAction=Cut +PasteAction=Paste diff --git a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java index 97b46ad0..ede67b2d 100644 --- a/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java +++ b/bundles/org.eclipse.e4.tools.compat/src/org/eclipse/e4/tools/compat/parts/DIHandler.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Jonas Helming <jhelming@eclipsesource.com> - initial API and implementation - * Lars Vogel <Lars.Vogel@gmail.com> - Bug 421453 + * Jonas Helming <jhelming@eclipsesource.com> - initial API and implementation + * Lars Vogel <Lars.Vogel@gmail.com> - Bug 421453 ******************************************************************************/ package org.eclipse.e4.tools.compat.parts; @@ -18,37 +18,37 @@ import org.eclipse.e4.core.contexts.ContextInjectionFactory; import org.eclipse.e4.core.contexts.IEclipseContext; import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.ui.PlatformUI; + /** * This is a preliminary implementation of a Handler wrapper. It does not support @CanExecute yet + * * @author Jonas * * @param <C> */ public class DIHandler<C> extends AbstractHandler { - private Class<C> clazz; - private C component; + private final C component; public DIHandler(Class<C> clazz) { - this.clazz = clazz; - IEclipseContext context = getActiveContext(); + final IEclipseContext context = getActiveContext(); component = ContextInjectionFactory.make(clazz, context); } private static IEclipseContext getActiveContext() { - IEclipseContext parentContext = getParentContext(); + final IEclipseContext parentContext = getParentContext(); return parentContext.getActiveLeaf(); } private static IEclipseContext getParentContext() { return (IEclipseContext) PlatformUI.getWorkbench().getService( - IEclipseContext.class); + IEclipseContext.class); } @Override public Object execute(ExecutionEvent event) throws ExecutionException { return ContextInjectionFactory.invoke(component, Execute.class, - getActiveContext()); + getActiveContext()); } }
\ No newline at end of file |