| /******************************************************************************* |
| * Copyright (c) 2015 Obeo. |
| * 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: |
| * Obeo - initial API and implementation and/or initial documentation |
| * ... |
| *******************************************************************************/ |
| package org.eclipse.intent.mapping.ide.connector; |
| |
| import java.io.IOException; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| import org.eclipse.core.runtime.content.IContentTypeManager; |
| import org.eclipse.intent.mapping.MappingUtils; |
| import org.eclipse.intent.mapping.base.ILocationContainer; |
| import org.eclipse.intent.mapping.content.IFileType; |
| import org.eclipse.intent.mapping.ide.Activator; |
| import org.eclipse.intent.mapping.ide.resource.IFileLocation; |
| import org.eclipse.intent.mapping.ide.resource.ITextFileLocation; |
| import org.eclipse.intent.mapping.text.TextConnector.TextContainerHelper; |
| |
| /** |
| * {@link ITextFileLocation} delegate. |
| * |
| * @author <a href="mailto:yvan.lussaud@obeo.fr">Yvan Lussaud</a> |
| */ |
| public class TextFileConnectorDelegate extends AbstractFileConnectorDelegate { |
| |
| /** |
| * The {@link IFileType}. |
| */ |
| private static final IFileType FILE_TYPE = MappingUtils.getFileTypeRegistry().getFileType( |
| IContentTypeManager.CT_TEXT); |
| |
| /** |
| * The {@link TextContainerHelper}. |
| */ |
| private final TextContainerHelper textContainerHelper = new TextContainerHelper(); |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.intent.mapping.ide.connector.IFileConnectorDelegate#getFileType() |
| */ |
| public IFileType getFileType() { |
| return FILE_TYPE; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.intent.mapping.ide.connector.IFileConnectorDelegate#getFileLocationType() |
| */ |
| public Class<? extends IFileLocation> getFileLocationType() { |
| return ITextFileLocation.class; |
| } |
| |
| /** |
| * {@inheritDoc} |
| * |
| * @see org.eclipse.intent.mapping.ide.connector.IFileConnectorDelegate#initLocation(org.eclipse.intent.mapping.base.ILocationContainer, |
| * org.eclipse.intent.mapping.ide.resource.IFileLocation, org.eclipse.core.resources.IFile) |
| */ |
| public void initLocation(ILocationContainer container, IFileLocation location, IFile element) { |
| try { |
| final String text = MappingUtils.getContent(element.getLocation().toFile(), element.getCharset()); |
| textContainerHelper.updateTextContainer(container, (ITextFileLocation)location, text); |
| } catch (CoreException e) { |
| Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), |
| e)); |
| } catch (IOException e) { |
| Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), |
| e)); |
| } catch (InstantiationException e) { |
| Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), |
| e)); |
| } catch (IllegalAccessException e) { |
| Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), |
| e)); |
| } catch (ClassNotFoundException e) { |
| Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), |
| e)); |
| } |
| } |
| |
| } |