Commit a5278e1b authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ integrated yang 2 tdl translator

* refined error messages
parent 9b8becb5
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -6,7 +6,9 @@ import java.util.LinkedHashMap;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
@@ -92,6 +94,7 @@ public class TranslationHandler extends AbstractHandler {
		ISelection selection = HandlerUtil.getCurrentSelection(event);
		IEditorInput input = HandlerUtil.getActiveEditorInput(event);
		IFile file = null;
		IContainer container = null; 
		if (input != null && input instanceof FileEditorInput) {
			file = ((FileEditorInput) input).getFile();
		} else if (selection !=null && selection instanceof IStructuredSelection) {
@@ -100,9 +103,13 @@ public class TranslationHandler extends AbstractHandler {
			if (firstElement instanceof IFile) {
				file = (IFile) firstElement;
			}
			if (firstElement instanceof IContainer) {
				container = (IContainer) firstElement;
			}
		}
		
		if (file !=null) {
		if (file !=null || container != null) {
			//TODO: handle directories as well..
			URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
			ResourceSet rs = new ResourceSetImpl();
			
@@ -140,6 +147,19 @@ public class TranslationHandler extends AbstractHandler {
				}
				if (type.contains("yang")) {
					translator = new Yang2TDLTranslator();
					//determine limit for looking for related module definitions 
					//also if linked folders are used
					if (container == null) {
						container = file.getParent();
					}
					while (container.getParent() != null 
							&& !container.isLinked()
							&& container.getType() == IResource.FOLDER
							) {
						container = container.getParent();
					}
					String limit = container.getLocation().toFile().getAbsolutePath();
					((Yang2TDLTranslator) translator).setLimit(limit);
				}
				if (translator != null) {
					translator.setTargetResource(tr);
@@ -182,6 +202,11 @@ public class TranslationHandler extends AbstractHandler {
	}

	private void showErrorDialog(Exception e) {
		String message = e.getMessage();
		Throwable cause = e;
		while ((cause = cause.getCause()) != null) {
			message+="\n"+"Caused by: \n\t"+cause.getMessage();
		}
		MessageDialog errorDialog = new MessageDialog(
				Display.getDefault().getActiveShell(), 
				"Translation error...", 
@@ -190,7 +215,7 @@ public class TranslationHandler extends AbstractHandler {
				+ "It may be due to problems occurring while processing the input, "
				+ "e.g if the input could not be processed. "
				+ "See details for a more technical description:\n\n"
				+ e.getMessage()
				+ message
				,		
				MessageDialog.ERROR, 
				0,