| /******************************************************************************* |
| * Copyright (c) 2016 Chalmers | University of Gothenburg, rt-labs 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 |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation |
| *******************************************************************************/ |
| package org.eclipse.capra.handler.file; |
| |
| import org.eclipse.capra.core.adapters.ArtifactMetaModelAdapter; |
| import org.eclipse.capra.core.handlers.ArtifactHandler; |
| import org.eclipse.capra.core.helpers.ExtensionPointHelper; |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.emf.ecore.EObject; |
| |
| /** |
| * Handler to allow tracing to and from arbitrary files in the file system. |
| */ |
| public class IFileHandler implements ArtifactHandler { |
| |
| @Override |
| public boolean canHandleSelection(Object selection) { |
| return selection instanceof IFile; |
| } |
| |
| @Override |
| public EObject getEObjectForSelection(Object selection, EObject artifactModel) { |
| IFile selectionAsFile = (IFile) selection; |
| ArtifactMetaModelAdapter adapter = ExtensionPointHelper.getArtifactWrapperMetaModelAdapter().get(); |
| EObject wrapper = adapter.createArtifact(artifactModel, this.getClass().getName(), |
| selectionAsFile.getFullPath().toString(), selectionAsFile.getName()); |
| return wrapper; |
| } |
| |
| @Override |
| public Object resolveArtifact(EObject artifact) { |
| //TO DO |
| return null; |
| } |
| |
| @Override |
| public String getDisplayName(Object selection) { |
| IFile selectionAsFile = (IFile) selection; |
| return selectionAsFile.getName(); |
| } |
| } |