Commit 628186ce authored by Stephan Eberle's avatar Stephan Eberle
Browse files

Reworked guards enabling Sphinx to be used in Java standalone

applications to enable it also to be used when an OSGi runtime is
available but not Eclipse workspace is used
parent 0799ebb4
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
/**
 * <copyright>
 * 
 * Copyright (c) 2008-2012 See4sys, BMW Car IT and others.
 * Copyright (c) 2008-2019 See4sys, BMW Car IT 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
@@ -15,7 +15,6 @@
 */
package org.eclipse.sphinx.emf.internal.ecore.proxymanagement;

import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notifier;
@@ -26,6 +25,7 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.sphinx.emf.domain.factory.EditingDomainFactoryListenerRegistry;
import org.eclipse.sphinx.emf.domain.factory.ITransactionalEditingDomainFactoryListener;
import org.eclipse.sphinx.emf.metamodel.MetaModelDescriptorRegistry;
import org.eclipse.sphinx.platform.util.ExtendedPlatform;

/**
 * An {@link AdapterFactory adapter factory} for creating {@link ProxyHelper} adapters on {@link ResourceSet}s.
@@ -46,13 +46,13 @@ public class ProxyHelperAdapterFactory extends AdapterFactoryImpl implements ITr
	}

	public void start() {
		if (Platform.isRunning()) {
		if (ExtendedPlatform.IS_PLATFORM_RUNNING) {
			EditingDomainFactoryListenerRegistry.INSTANCE.addListener(MetaModelDescriptorRegistry.ANY_MM, null, this, null);
		}
	}

	public void stop() {
		if (Platform.isRunning()) {
		if (ExtendedPlatform.IS_PLATFORM_RUNNING) {
			EditingDomainFactoryListenerRegistry.INSTANCE.removeListener(this);
		}
	}
+8 −6
Original line number Diff line number Diff line
/**
 * <copyright>
 *
 * Copyright (c) 2008-2014 See4sys, itemis and others.
 * Copyright (c) 2008-2019 See4sys, itemis 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
@@ -28,7 +28,6 @@ import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
@@ -38,6 +37,7 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.sphinx.emf.Activator;
import org.eclipse.sphinx.emf.resource.ExtendedResourceSet;
import org.eclipse.sphinx.platform.util.ExtendedPlatform;
import org.eclipse.sphinx.platform.util.PlatformLogUtil;

/**
@@ -59,13 +59,13 @@ public class MapModelIndex implements IResourceChangeListener {
	}

	public void startListening() {
		if (Platform.isRunning()) {
		if (ExtendedPlatform.IS_PLATFORM_RUNNING && ExtendedPlatform.IS_WORKSPACE_AVAILABLE) {
			ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
		}
	}

	public void stopListening() {
		if (Platform.isRunning()) {
		if (ExtendedPlatform.IS_PLATFORM_RUNNING && ExtendedPlatform.IS_WORKSPACE_AVAILABLE) {
			ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
		}
	}
@@ -97,7 +97,8 @@ public class MapModelIndex implements IResourceChangeListener {
			// System.out.println("Added Proxy: " + proxyURIs.size() + " " + proxyURI); //$NON-NLS-1$ //$NON-NLS-2$
			return true;
		} else {
			// System.out.println("Trying to add existing proxy: " + proxyURIs.size() + " " + proxyURI); //$NON-NLS-1$//$NON-NLS-2$
			// System.out.println("Trying to add existing proxy: " + proxyURIs.size() + " " + proxyURI);
			// //$NON-NLS-1$//$NON-NLS-2$
			return false;
		}
	}
@@ -110,7 +111,8 @@ public class MapModelIndex implements IResourceChangeListener {
			// System.out.println("Removed Proxy: " + proxyURIs.size() + " " + proxyURI); //$NON-NLS-1$ //$NON-NLS-2$
			return true;
		} else {
			// System.out.println("Trying to remove proxy: " + proxyURIs.size() + " " + proxyURI); //$NON-NLS-1$ //$NON-NLS-2$
			// System.out.println("Trying to remove proxy: " + proxyURIs.size() + " " + proxyURI); //$NON-NLS-1$
			// //$NON-NLS-2$
			return false;
		}
	}
+8 −7
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
@@ -219,12 +218,13 @@ public class ResourceProblemMarkerService {
			}
		}

		if (!resourcesWithProblems.isEmpty() && Platform.isRunning()) {
		if (!resourcesWithProblems.isEmpty()) {
			// Collect resources to update problem markers for in sets of resources per editing domain; tolerate
			// resources that aren't in any editing domain
			final Map<TransactionalEditingDomain, Collection<Resource>> resourcesToUpdate = new HashMap<TransactionalEditingDomain, Collection<Resource>>();
			for (Resource resource : resourcesWithProblems) {
				TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
				if (editingDomain != null) {
					Collection<Resource> resourcesToUpdateInEditingDomain = resourcesToUpdate.get(editingDomain);
					if (resourcesToUpdateInEditingDomain == null) {
						resourcesToUpdateInEditingDomain = new HashSet<Resource>();
@@ -232,6 +232,7 @@ public class ResourceProblemMarkerService {
					}
					resourcesToUpdateInEditingDomain.add(resource);
				}
			}

			// Update problem markers of resources in each editing domain
			SubMonitor progress = SubMonitor.convert(monitor, resourcesToUpdate.keySet().size());
+4 −4
Original line number Diff line number Diff line
/**
 * <copyright>
 *
 * Copyright (c) 2008-2014 BMW Car IT, See4sys, itemis and others.
 * Copyright (c) 2008-2019 BMW Car IT, See4sys, itemis 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
@@ -197,7 +197,7 @@ public class MetaModelDescriptorRegistry implements IAdaptable {
	 */
	private void readContributedDescriptors() {
		IExtensionRegistry extensionRegistry = getExtensionRegistry();
		if (extensionRegistry != null) {
		if (extensionRegistry != null && extensionRegistry.getExtensionPoint(EXTP_META_MODEL_DESCRIPTORS) != null) {
			IExtension[] extensions = extensionRegistry.getExtensionPoint(EXTP_META_MODEL_DESCRIPTORS).getExtensions();
			for (IExtension extension : extensions) {
				IConfigurationElement[] configElements = extension.getConfigurationElements();
@@ -236,7 +236,7 @@ public class MetaModelDescriptorRegistry implements IAdaptable {
	 */
	private void readAssociatedContentTypeIds() {
		IExtensionRegistry extensionRegistry = getExtensionRegistry();
		if (extensionRegistry != null) {
		if (extensionRegistry != null && extensionRegistry.getExtensionPoint(EXTP_META_MODEL_DESCRIPTORS) != null) {
			IExtension[] extensions = extensionRegistry.getExtensionPoint(EXTP_META_MODEL_DESCRIPTORS).getExtensions();
			for (IExtension extension : extensions) {
				IConfigurationElement[] configElements = extension.getConfigurationElements();
@@ -294,7 +294,7 @@ public class MetaModelDescriptorRegistry implements IAdaptable {
	 */
	private void readContributedTargetMetaModelDescriptorProviders() {
		IExtensionRegistry extensionRegistry = getExtensionRegistry();
		if (extensionRegistry != null) {
		if (extensionRegistry != null && extensionRegistry.getExtensionPoint(EXTP_META_MODEL_DESCRIPTORS) != null) {
			Set<String> overriddenIds = new HashSet<String>();
			IExtension[] extensions = extensionRegistry.getExtensionPoint(EXTP_META_MODEL_DESCRIPTORS).getExtensions();
			for (IExtension extension : extensions) {
+16 −13
Original line number Diff line number Diff line
/**
 * <copyright>
 * 
 * Copyright (c) 2008-2010 See4sys, BMW Car IT and others.
 * Copyright (c) 2008-2019 See4sys, BMW Car IT 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
@@ -29,6 +29,7 @@ import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.sphinx.emf.Activator;
import org.eclipse.sphinx.emf.internal.resource.ModelConverterDescription;
import org.eclipse.sphinx.emf.metamodel.IMetaModelDescriptor;
import org.eclipse.sphinx.platform.util.ExtendedPlatform;
import org.eclipse.sphinx.platform.util.PlatformLogUtil;

/**
@@ -59,6 +60,7 @@ public class ModelConverterRegistry {
	protected void init() {
		fModelConverters = new ArrayList<IModelConverter>();
		try {
			if (ExtendedPlatform.IS_PLATFORM_RUNNING) {
				IExtensionRegistry registry = Platform.getExtensionRegistry();
				if (registry != null) {
					String symbolicName = Activator.getPlugin().getSymbolicName();
@@ -74,6 +76,7 @@ public class ModelConverterRegistry {
						}
					}
				}
			}
		} catch (Exception ex) {
			PlatformLogUtil.logAsError(Activator.getDefault(), ex);
		}
Loading