blob: 7f26802f36bc7699ca0009aa20e22c01c4c1c62c [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2020 CEA LIST 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
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* CEA LIST - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.cdo.internal.core.resource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.util.CDOURIUtil;
import org.eclipse.emf.common.util.URI;
import org.eclipse.papyrus.cdo.internal.core.Activator;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.internationalization.modelresource.AbstractInternationalizationPreferenceModelProvider;
import org.eclipse.papyrus.infra.internationalization.modelresource.InternationalizationPreferenceModel;
public class CDOInternationalizationPreferenceModelProvider extends AbstractInternationalizationPreferenceModelProvider {
public CDOInternationalizationPreferenceModelProvider() {
super();
}
/**
* @see org.eclipse.papyrus.infra.internationalization.modelresource.IInternationalizationPreferenceModelProvider#getInternationalizationPreferenceModelURI(org.eclipse.emf.common.util.URI)
*
* @param userModelURI
* @return
*/
@Override
public URI getInternationalizationPreferenceModelURI(URI userModelURI) {
URI uriWithoutExtension = userModelURI.trimFileExtension();
IPath stateLocation = indexFolder.append(CDOURIUtil.extractResourcePath(uriWithoutExtension));
return URI.createFileURI(stateLocation.toString()).appendFileExtension(InternationalizationPreferenceModel.INTERNATIONALIZATION_PREFERENCE_FILE_EXTENSION);
}
private static final IPath INTERNATIONALIZATION_PREFERENCE_MODEL_STORAGE_ROOT = Activator.getDefault().getStateLocation().append("internationalizationidx"); //$NON-NLS-1$
private IPath indexFolder;
@Override
public void initialize(ModelSet modelSet) {
super.initialize(modelSet);
CDOCheckout checkout = CDOExplorerUtil.getCheckout(modelSet);
if (checkout != null) {
initialize(checkout);
} else {
// Model probably is in the workspace if null
indexFolder = INTERNATIONALIZATION_PREFERENCE_MODEL_STORAGE_ROOT;
}
}
public CDOInternationalizationPreferenceModelProvider initialize(CDOCheckout checkout) {
indexFolder = INTERNATIONALIZATION_PREFERENCE_MODEL_STORAGE_ROOT.append(checkout.getView().getSession().getRepositoryInfo().getUUID());
return this;
}
}