| /******************************************************************************* |
| * Copyright (c) 2011-2015 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 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Eugen Neufeld - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.emf.ecp.ui.view.swt.di.renderer; |
| |
| import org.eclipse.emf.ecp.view.spi.context.ViewModelContext; |
| import org.eclipse.emf.ecp.view.spi.model.VElement; |
| import org.eclipse.emf.ecp.view.spi.model.VView; |
| import org.eclipse.emfforms.spi.common.locale.EMFFormsLocaleProvider; |
| import org.eclipse.emfforms.spi.common.report.ReportService; |
| import org.eclipse.emfforms.spi.swt.core.AbstractSWTRenderer; |
| import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererFactory; |
| import org.eclipse.emfforms.spi.swt.core.EMFFormsRendererService; |
| import org.osgi.framework.BundleContext; |
| import org.osgi.framework.ServiceReference; |
| |
| /** |
| * NumberControlSWTRendererService which provides the NumberControlSWTRenderer. |
| * |
| * @author Eugen Neufeld |
| * |
| */ |
| public class DIViewSWTRendererService implements EMFFormsRendererService<VView> { |
| |
| private EMFFormsRendererFactory rendererFactory; |
| private ReportService reportService; |
| private ServiceReference<EMFFormsRendererFactory> serviceReference; |
| private EMFFormsLocaleProvider localeProvider; |
| |
| /** |
| * Activate ViewSWTRendererService. |
| * |
| * @param bundleContext The {@link BundleContext} |
| */ |
| protected void activate(BundleContext bundleContext) { |
| serviceReference = bundleContext.getServiceReference(EMFFormsRendererFactory.class); |
| rendererFactory = bundleContext.getService(serviceReference); |
| } |
| |
| /** |
| * Deactivate ViewSWTRendererService. |
| * |
| * @param bundleContext The {@link BundleContext} |
| */ |
| protected void deactivate(BundleContext bundleContext) { |
| bundleContext.ungetService(serviceReference); |
| } |
| |
| /** |
| * Called by the initializer to set the ReportService. |
| * |
| * @param reportService The ReportService |
| */ |
| protected void setReportService(ReportService reportService) { |
| this.reportService = reportService; |
| } |
| |
| /** |
| * Called by the initializer to unset the ReportService. |
| * |
| * @param reportService The ReportService |
| */ |
| protected void unsetReportService(ReportService reportService) { |
| this.reportService = null; |
| } |
| |
| /** |
| * Called by the initializer to set the EMFFormsLocaleProvider. |
| * |
| * @param localeProvider The EMFFormsLocaleProvider |
| */ |
| protected void setEMFFormsLocaleProvider(EMFFormsLocaleProvider localeProvider) { |
| this.localeProvider = localeProvider; |
| } |
| |
| /** |
| * Called by the initializer to unset the EMFFormsLocaleProvider. |
| * |
| * @param localeProvider The EMFFormsLocaleProvider |
| */ |
| protected void unsetEMFFormsLocaleProvider(EMFFormsLocaleProvider localeProvider) { |
| this.localeProvider = null; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emfforms.spi.swt.core.EMFFormsRendererService#isApplicable(VElement,ViewModelContext) |
| */ |
| @Override |
| public double isApplicable(VElement vElement, ViewModelContext viewModelContext) { |
| if (!VView.class.isInstance(vElement)) { |
| return NOT_APPLICABLE; |
| } |
| return 3d; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.emfforms.spi.swt.core.EMFFormsRendererService#getRendererInstance(org.eclipse.emf.ecp.view.spi.model.VElement, |
| * org.eclipse.emf.ecp.view.spi.context.ViewModelContext) |
| */ |
| @Override |
| public AbstractSWTRenderer<VView> getRendererInstance(VView vElement, ViewModelContext viewModelContext) { |
| return new DIViewSWTRenderer(vElement, viewModelContext, reportService, rendererFactory, localeProvider); |
| } |
| |
| } |