| /******************************************************************************* |
| * Copyright (c) 2011, 2014 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * 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: |
| * Florian Pirchner - copied source from Xtend and adjusted to EntityDSL |
| * |
| * Original source from org.eclipse.xtend.ide.buildpath.XtendsContainerInitializer |
| * |
| *******************************************************************************/ |
| package org.eclipse.osbp.dsl.eclipse.ui.buildpath; |
| |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IPath; |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Path; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.core.runtime.jobs.Job; |
| import org.eclipse.jdt.core.ClasspathContainerInitializer; |
| import org.eclipse.jdt.core.IClasspathContainer; |
| import org.eclipse.jdt.core.IJavaProject; |
| import org.eclipse.jdt.core.JavaCore; |
| |
| public class EntityContainerInitializer extends ClasspathContainerInitializer { |
| |
| public static final Path ENTITY_LIBRARY_PATH = new Path("org.eclipse.osbp.dsl.entity.ENTITY_CONTAINER"); //$NON-NLS-1$ |
| |
| /** |
| * {@inheritDoc} |
| */ |
| @Override |
| public void initialize(final IPath containerPath, final IJavaProject project) throws CoreException { |
| if (isEntityPath(containerPath)) { |
| IClasspathContainer container = new EntityClasspathContainer(containerPath); |
| JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, |
| new IClasspathContainer[] { container }, null); |
| } |
| } |
| |
| /** |
| * Allows users to manually add source bundles |
| */ |
| @Override |
| public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) { |
| return true; |
| } |
| |
| @Override |
| public void requestClasspathContainerUpdate(final IPath containerPath, final IJavaProject project, |
| final IClasspathContainer containerSuggestion) throws CoreException { |
| super.requestClasspathContainerUpdate(containerPath, project, containerSuggestion); |
| new Job("Classpath container update") { //$NON-NLS-1$ |
| @Override |
| protected IStatus run(IProgressMonitor monitor) { |
| try { |
| JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, |
| new IClasspathContainer[] { containerSuggestion }, null); |
| } catch (CoreException ex) { |
| return new Status(IStatus.ERROR, "org.eclipse.osbp.dsl.entity.xtext", 0, |
| "Classpath container update failed", ex); //$NON-NLS-1$ |
| } |
| return Status.OK_STATUS; |
| } |
| }.schedule(); |
| } |
| |
| private boolean isEntityPath(final IPath containerPath) { |
| return ENTITY_LIBRARY_PATH.equals(containerPath); |
| } |
| |
| } |