Index: trunk/org.modelica.mdt/BUGS
===================================================================
--- trunk/org.modelica.mdt/BUGS	(revision 172)
+++ trunk/org.modelica.mdt/BUGS	(revision 174)
@@ -32,4 +32,15 @@
 [..snip..]
 This should probably be reported upstream.
+------------------------------------------
+Mail sent to modelica-pelab list, waiting for reply.
+
+BUGID: 5
+STATUS: open
+TESTCASE: absent
+'Open project' and 'Close project' menu items are not updated after invocation.
+
+Try this. Select an open project and click on 'close project' menu (for example
+in contex menu). Look at the menu again, 'Open project' is still disabled 
+and 'Close project' enabled. Same problem if you open a closed project.
 
 
Index: trunk/org.modelica.mdt/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.modelica.mdt/META-INF/MANIFEST.MF	(revision 172)
+++ trunk/org.modelica.mdt/META-INF/MANIFEST.MF	(revision 174)
@@ -13,5 +13,6 @@
  org.eclipse.ui.workbench.texteditor,
  org.eclipse.jface.text,
- org.eclipse.ui.console
+ org.eclipse.ui.console,
+ org.eclipse.debug.core
 Bundle-ClassPath: mdt.jar,
  bin/,
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/MdtPlugin.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/MdtPlugin.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/MdtPlugin.java	(revision 174)
@@ -49,4 +49,6 @@
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.modelica.mdt.core.ModelicaCore;
@@ -178,4 +180,21 @@
 	}
 
+	private IWorkbenchPage internalGetActivePage() 
+	{
+		IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
+		if (window == null)
+		{
+			return null;
+		}
+		return getWorkbench().getActiveWorkbenchWindow().getActivePage();
+	}
+
+	
+	public static IWorkbenchPage getActivePage() 
+	{
+		return getDefault().internalGetActivePage();
+	}
+
+	
 	/**
 	 * Note: This method is for internal use only. Clients should not
@@ -207,3 +226,5 @@
 		return res;
 	}
+	
+	
 }
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/builder/SyntaxChecker.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/builder/SyntaxChecker.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/builder/SyntaxChecker.java	(revision 174)
@@ -43,4 +43,7 @@
 
 import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -61,4 +64,6 @@
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
 import org.modelica.mdt.MdtPlugin;
 import org.modelica.mdt.internal.omcproxy.CompileError;
@@ -240,4 +245,79 @@
 	}
 
+	/**
+	 * Calculate where the particular line begins and how long it stretches.
+	 *  
+	 * @param filePath the full path to the file where to look for lines
+	 * @param lineno line number to find
+	 * @return region which line occupies or null if the does not 
+	 * have such a line number
+	 * @throws CoreException if there were errors reading file contents 
+	 * @throws FileNotFoundException if the filePath does not exists 
+	 */
+	
+	public static IRegion getLineRegion(String filePath, int lineno)
+		throws CoreException, FileNotFoundException
+	{
+		// TODO this probably should be moved into ModelicaFile class,
+		// however that would require that IFile -> IModelicaFile mapping
+		// is implemented. such a mupping is probably needed anyway to
+		// know which other files that should be loaded into OMC and checked
+		// for errors. that is all dependant files, e.g. if file A defines foo
+		// and file B imports foo both A and B should be reshecked for errors
+		// when A is modified (saved), right now only A is checked. end of rant.
+
+		/*
+		 * To find out where the line is in the file, we have to read it
+		 * in to a Document and then use getLineOffset to convert from a
+		 * line number to a character positions.
+		 */
+
+		return getLineRegion(new FileInputStream(new File(filePath)), lineno);
+
+	}
+	
+	public static IRegion getLineRegion(IFile file, int lineno) 
+		throws CoreException
+	{
+		return getLineRegion(file.getContents(), lineno);
+	}
+
+	
+	private static IRegion getLineRegion(InputStream fileContents, int lineno)
+	{
+		BufferedInputStream bis = new BufferedInputStream(fileContents);
+		String contents = "";
+		while(true)
+		{
+			try
+			{
+				int avail = bis.available();
+				if(avail == 0)
+					break;
+				byte[] buf = new byte[avail];
+				bis.read(buf, 0, avail);
+
+				contents += new String(buf);
+			}
+			catch(IOException e)
+			{
+				e.printStackTrace();
+			}
+		}
+
+		Document d = new Document(contents);
+		try
+		{
+			return new Region(d.getLineOffset(lineno - 1), 
+					d.getLineLength(lineno - 1));
+		}
+		catch(BadLocationException e)
+		{
+			MdtPlugin.log(e);
+		}
+		
+		return null;
+	}
+
 	public static IMarker createMarkerAtLine(IFile file, int lineno,
 			String message, String type)
@@ -246,47 +326,16 @@
 		try
 		{
+			IRegion lineReg = getLineRegion(file, lineno);
+			int start = lineReg.getOffset();
+			int end = start + lineReg.getLength();
+			
 			marker = file.createMarker(type);
+
+			marker.setAttribute(IMarker.CHAR_START, start);
+			marker.setAttribute(IMarker.CHAR_END, end);
 			marker.setAttribute(IMarker.MESSAGE, message);
 			marker.setAttribute(IMarker.LINE_NUMBER, lineno);
 			marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
 			marker.setAttribute(IMarker.LOCATION, Integer.toString(lineno));
-
-			/*
-			 * To find out where the error is in the file, we have to read it
-			 * in to a Document and then use getLineOffset to convert from a
-			 * line number to a character position.
-			 */
-			int start = 0, end = 0;
-			InputStream is = file.getContents();
-			BufferedInputStream bis = new BufferedInputStream(is);
-			String contents = "";
-			while(true)
-			{
-				try
-				{
-					int avail = bis.available();
-					if(avail == 0)
-						break;
-					byte[] buf = new byte[avail];
-					bis.read(buf, 0, avail);
-	
-					contents += new String(buf);
-				}
-				catch(IOException e)
-				{
-					e.printStackTrace();
-				}
-			}
-	
-			Document d = new Document(contents);
-			try
-			{
-				start = d.getLineOffset(lineno - 1);
-				end = start + d.getLineLength(lineno - 1);
-			}
-			catch(BadLocationException e)
-			{
-				MdtPlugin.log(e);
-			}
 			
 			marker.setAttribute(IMarker.CHAR_START, start);
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaClass.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaClass.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaClass.java	(revision 174)
@@ -42,10 +42,5 @@
 package org.modelica.mdt.core;
 
-import java.io.File;
-
 import org.modelica.mdt.internal.omcproxy.ConnectionException;
-import org.modelica.mdt.internal.omcproxy.UnexpectedReplyException;
-
-
 
 /**
@@ -69,13 +64,4 @@
 	
 	/**
-	 * @return the file where this class is defined
-	 * @throws ConnectionException 
-	 * @throws UnexpectedReplyException 
-	 */
-	public File getFile() throws ConnectionException, UnexpectedReplyException;
-
-	public int getLine() throws ConnectionException, UnexpectedReplyException;
-
-	/**
 	 * @return all imports this class is making
 	 */
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaElement.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaElement.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaElement.java	(revision 174)
@@ -39,9 +39,13 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
 package org.modelica.mdt.core;
 
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.text.IRegion;
 import org.modelica.mdt.internal.omcproxy.ConnectionException;
+import org.modelica.mdt.internal.omcproxy.InvocationError;
 import org.modelica.mdt.internal.omcproxy.UnexpectedReplyException;
 
@@ -77,3 +81,34 @@
 	IResource getResource()
 		throws ConnectionException, UnexpectedReplyException;
+	
+	/**
+	 * For elements that are defined inside a file this method returns
+	 * the region of the file where the file is defined.
+	 * 
+	 * If the element is not defined in a file, null is returned.
+	 * 
+	 * Remark: due to limitations in the OMC, the actual region returned is
+	 * the first line of the elements definition.
+	 * @throws UnexpectedReplyException 
+	 * @throws ConnectionException 
+	 * @throws CoreException 
+	 * 
+	 */
+	IRegion getLocation() 
+		throws ConnectionException, UnexpectedReplyException, 
+			InvocationError, CoreException;
+
+	/**
+	 * If this element is external then this method returns full path
+	 * to the file where this element is defined. If this element is not
+	 * external (e.g. defined inside the workspace) or is not defined in a
+	 * file null is returned.
+	 *  
+	 * @return
+	 * @throws InvocationError 
+	 * @throws UnexpectedReplyException 
+	 * @throws ConnectionException 
+	 */
+	public String getFilePath() 
+		throws ConnectionException, UnexpectedReplyException, InvocationError;
 }
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/editor/EditorUtility.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/editor/EditorUtility.java	(revision 174)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/editor/EditorUtility.java	(revision 174)
@@ -0,0 +1,157 @@
+/*
+ * This file is part of Modelica Development Tooling.
+ *
+ * Copyright (c) 2005, Linköpings universitet, Department of
+ * Computer and Information Science, PELAB
+ *
+ * All rights reserved.
+ *
+ * (The new BSD license, see also
+ * http://www.opensource.org/licenses/bsd-license.php)
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of Linköpings universitet nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.modelica.mdt.editor;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.modelica.mdt.MdtPlugin;
+import org.modelica.mdt.core.IModelicaElement;
+import org.modelica.mdt.core.IModelicaFile;
+import org.modelica.mdt.internal.omcproxy.ConnectionException;
+import org.modelica.mdt.internal.omcproxy.InvocationError;
+import org.modelica.mdt.internal.omcproxy.UnexpectedReplyException;
+
+/**
+ * A number of routines for working with modelica elements in editors.
+ * 
+ */
+public class EditorUtility
+{
+
+	/**
+	 * handles the tricky buisness of opening the element in editor depending
+	 * on it's type
+	 * @param element the element to open in the editor
+	 * @throws ConnectionException
+	 * @throws UnexpectedReplyException
+	 * @throws InvocationError
+	 * @throws CoreException
+	 */
+	public static void openInEditor(Object element)
+		throws ConnectionException, UnexpectedReplyException, 
+			InvocationError, CoreException
+	{
+		if (element instanceof IModelicaElement)
+		{
+			IModelicaElement modelicaElement = (IModelicaElement)element;
+			IResource res = modelicaElement.getResource();
+			ITextEditor editor = null;
+			
+			if (res == null)
+			{
+				/* 
+				 * if the resource is null then we have an external 
+				 * defined element
+				 * Fetch the path to the source file and wrap it into
+				 * a system file editor input converter 
+				 */
+				editor = (ITextEditor)openInEditor(
+							 new SystemFileEditorInput(
+									 modelicaElement.getFilePath()));
+			} 
+			else if (res instanceof IFile)
+			{
+				/* a element defined inside a file in the workspace */
+				editor = (ITextEditor) openInEditor((IFile)res);
+			}
+			
+			if (!(element instanceof IModelicaFile))
+			{
+				/*
+				 * for all elements except modelica files goto the line
+				 * where the definition of the element begins
+				 */
+				IRegion reg = ((IModelicaElement)element).getLocation();
+				
+				if (reg != null)
+				{
+					editor.selectAndReveal(reg.getOffset(), reg.getLength());
+				}
+			}
+		}
+		else if (element instanceof IFile)
+		{
+			openInEditor((IFile)element);
+		}
+		
+	}
+	
+	private static IEditorPart openInEditor(IFile file) 
+		throws PartInitException 
+	{
+		if (file != null) 
+		{
+			IWorkbenchPage p = MdtPlugin.getActivePage();
+			if (p != null) 
+			{
+				IEditorPart editorPart= IDE.openEditor(p, file, true);
+				return editorPart;
+			}
+		}
+		return null;
+	}
+	
+	private static IEditorPart openInEditor(IEditorInput input)
+		throws PartInitException 
+	{
+		if (input != null) 
+		{
+			IWorkbenchPage p = MdtPlugin.getActivePage();
+			if (p != null) 
+			{
+				IEditorPart editorPart = 
+						p.openEditor(input, "org.modelica.mdt.editor", true);
+
+				return editorPart;
+			}
+		}
+		return null;
+	}
+}
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/editor/SystemFileEditorInput.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/editor/SystemFileEditorInput.java	(revision 174)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/editor/SystemFileEditorInput.java	(revision 174)
@@ -0,0 +1,147 @@
+/*
+ * This file is part of Modelica Development Tooling.
+ *
+ * Copyright (c) 2005, Linköpings universitet, Department of
+ * Computer and Information Science, PELAB
+ *
+ * All rights reserved.
+ *
+ * (The new BSD license, see also
+ * http://www.opensource.org/licenses/bsd-license.php)
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of Linköpings universitet nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.modelica.mdt.editor;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IStorageEditorInput;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author Homer Simpson
+ */
+public class SystemFileEditorInput implements IStorageEditorInput
+{
+
+	private IStorage fileStorage;
+
+	public SystemFileEditorInput(String path)
+	{
+		fileStorage = new LocalFileStorage(new File(path));
+	}
+	
+	public boolean equals(Object obj) 
+	{
+		if (this == obj)
+		{
+			return true;
+		}
+		if (!(obj instanceof SystemFileEditorInput))
+		{
+			return false;
+		}
+		
+		SystemFileEditorInput other = (SystemFileEditorInput) obj;
+		return fileStorage.equals(other.fileStorage);
+	}
+
+	/*
+	 * @see IEditorInput#getPersistable()
+	 */
+	public IPersistableElement getPersistable() {
+		return null;
+	}
+
+	/*
+	 * @see IEditorInput#getName()
+	 */
+	public String getName() {
+		return fileStorage.getName();
+	}
+
+	/*
+	 * @see IEditorInput#getFullPath()
+	 */
+	public String getFullPath() {
+		return fileStorage.getFullPath().toString();
+	}
+
+	/*
+	 * @see IEditorInput#getContentType()
+	 */
+	public String getContentType() {
+		return fileStorage.getFullPath().getFileExtension();
+	}
+
+	/*
+	 * @see IEditorInput#getToolTipText()
+	 */
+	public String getToolTipText() {
+		return fileStorage.getFullPath().toString();
+	}
+
+	/*
+	 * @see IEditorInput#getImageDescriptor()
+	 */
+	public ImageDescriptor getImageDescriptor() {
+		IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry();
+		return registry.getImageDescriptor(fileStorage.getFullPath().getFileExtension());
+	}
+
+	/*
+	 * @see IEditorInput#exists()
+	 */
+	public boolean exists() {
+		// JAR entries can't be deleted
+		return true;
+	}
+
+	/*
+	 * @see IAdaptable#getAdapter(Class)
+	 */
+	public Object getAdapter(Class adapter) {
+		return null;
+	}
+
+	/*
+	 * see IStorageEditorInput#getStorage()
+	 */
+	 public IStorage getStorage() {
+	 	return fileStorage;
+	 }
+
+}
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/InnerPackage.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/InnerPackage.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/InnerPackage.java	(revision 174)
@@ -42,12 +42,21 @@
 package org.modelica.mdt.internal.core;
 
+import java.io.FileNotFoundException;
 import java.util.Collection;
 import java.util.Hashtable;
 import java.util.LinkedList;
 
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.IRegion;
+import org.modelica.mdt.MdtPlugin;
+import org.modelica.mdt.builder.SyntaxChecker;
 import org.modelica.mdt.core.IModelicaElementChange;
 import org.modelica.mdt.core.IModelicaElementChange.ChangeType;
 import org.modelica.mdt.internal.omcproxy.ConnectionException;
+import org.modelica.mdt.internal.omcproxy.ElementLocation;
 import org.modelica.mdt.internal.omcproxy.InvocationError;
 import org.modelica.mdt.internal.omcproxy.OMCProxy;
@@ -61,9 +70,21 @@
 public class InnerPackage extends ModelicaPackage
 {
+	
+	/*
+	 * the file where this package is defined, 
+	 * can be null if it is unknown
+	 * when the container is unknow the class is assumed to 
+	 * be external e.g. defined in system library
+	 */
+	private IFile container;
+	
+	private ElementLocation location = null;
+
 	/* subpackages and subclasses hashed by the thier's shortname */
 	private Hashtable<String, Object> children = null;
 	
-	public InnerPackage(String prefix, String name)
-	{
+	public InnerPackage(IFile container, String prefix, String name)
+	{
+		this.container = container;
 		this.prefix = prefix;
 		this.name = name;
@@ -71,4 +92,18 @@
 		
 	}
+	
+	/**
+	 * Create a modelica package that is defined in unknow location, for example
+	 * a system library class. This method assumes that a class named
+	 * 'prefix'.'name' is loaded into OMC.
+	 * 
+	 * @param prefix
+	 * @param name
+	 */
+	protected InnerPackage(String prefix, String name)
+	{
+		this(null, prefix, name);
+	}
+
 
 	/* (non-Javadoc)
@@ -93,10 +128,10 @@
 		for (String name : OMCProxy.getPackages(fullName))
 		{
-			elements.put(name, new InnerPackage(fullName, name));
+			elements.put(name, new InnerPackage(container, fullName, name));
 		}
 		
 		for (String name : OMCProxy.getClassNames(fullName))
 		{
-			elements.put(name, new ModelicaClass(fullName, name));
+			elements.put(name, new ModelicaClass(container, fullName, name));
 		}
 	
@@ -167,4 +202,68 @@
 		return changes;
 	}
+	
+	public IResource getResource()
+	{
+		return container;
+	}
+	
+	/**
+	 * @throws InvocationError 
+	 * @throws CoreException 
+	 * @see org.modelica.mdt.core.IModelicaElement#getLocation()
+	 */
+	public IRegion getLocation() 
+		throws ConnectionException, UnexpectedReplyException, 
+			InvocationError, CoreException
+	{
+		if (location == null)
+		{
+			loadElementLocation();
+		}
+		
+		if (container != null)
+		{
+			SyntaxChecker.getLineRegion(container, location.getLine());
+		}
+
+		IRegion reg = null;
+		
+		try
+		{
+			reg = 
+				SyntaxChecker.getLineRegion(location.getPath(), 
+						location.getLine());
+		}
+		catch (FileNotFoundException e)
+		{
+			throw new CoreException(
+					new Status(IStatus.ERROR,
+								MdtPlugin.getSymbolicName(),
+								IStatus.OK, 
+								"could not find modelica source file " + 
+									location.getPath(),
+								e));
+		}
+		return reg;
+	}
+
+	@Override
+	public String getFilePath() 
+		throws ConnectionException, UnexpectedReplyException, InvocationError
+	{
+		if (location == null)
+		{
+			loadElementLocation();
+		}
+		return location.getPath();
+	}
+
+	private void loadElementLocation()
+		throws ConnectionException, UnexpectedReplyException, InvocationError
+	{
+		location = OMCProxy.getElementLocation(fullName);
+	}
+
+
 
 }
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaClass.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaClass.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaClass.java	(revision 174)
@@ -1,5 +1,5 @@
 package org.modelica.mdt.internal.core;
 
-import java.io.File;
+import java.io.FileNotFoundException;
 import java.util.Collection;
 import java.util.Hashtable;
@@ -8,8 +8,10 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.text.IRegion;
+import org.modelica.mdt.MdtPlugin;
+import org.modelica.mdt.builder.SyntaxChecker;
 import org.modelica.mdt.core.IClassComponent;
 import org.modelica.mdt.core.IClassExtend;
@@ -19,4 +21,5 @@
 import org.modelica.mdt.core.IModelicaElementChange.ChangeType;
 import org.modelica.mdt.internal.omcproxy.ConnectionException;
+import org.modelica.mdt.internal.omcproxy.ElementLocation;
 import org.modelica.mdt.internal.omcproxy.InvocationError;
 import org.modelica.mdt.internal.omcproxy.OMCProxy;
@@ -24,7 +27,5 @@
 
 /**
- * 
  * @author Andreas Remar
- *
  */
 public class ModelicaClass extends ModelicaElement implements IModelicaClass
@@ -38,12 +39,26 @@
 	private Type type;
 	
+	private ElementLocation location = null;
+	
+	/*
+	 * the file where this class is defined, 
+	 * can be null if it is unknown
+	 * when the container is unknow the class is assumed to 
+	 * be external e.g. defined in system library
+	 */
+	private IFile container;
+	
 	private boolean typeKnown = false;
 
 	/**
+	 * Create a modelica class that is defined inside a modelica file.
+	 * @param container the file where this file is defined
 	 * @param prefix
 	 * @param name
 	 */
-	protected ModelicaClass(String prefix, String name)
-	{
+	protected ModelicaClass(IFile container, String prefix, String name)	
+	{
+
+		this.container = container;
 		this.name = name;
 		this.prefix = prefix;
@@ -59,4 +74,17 @@
 
 		type = Type.CLASS;
+	}
+	
+	/**
+	 * Create a modelica class that is defined in unknow location, for example
+	 * a system library class. This method assumes that a class named
+	 * 'prefix'.'name' is loaded into OMC.
+	 * 
+	 * @param prefix
+	 * @param name
+	 */
+	protected ModelicaClass(String prefix, String name)
+	{
+		this(null, prefix, name);
 	}
 	
@@ -90,47 +118,66 @@
 	
 	public IResource getResource()
-		throws ConnectionException, UnexpectedReplyException
-	{
-		// TODO The path to the file should actually be stored somewhere in
-		//      ModelicaClass (at least that's what I've heard)
-		String[] tokens = OMCProxy.getCrefInfo(fullName);
-
-		IPath filePath = new Path(tokens[0]);
-
-		/*
-		 * filePath is an absolute path starting at the root of the file system,
-		 * what we want is a path starting from the workspace root.
-		 * To accomplish this, we cut off the first segments. 
-		 */
-		IPath workspacePath = ResourcesPlugin.getWorkspace()
-			.getRoot().getRawLocation();
-		
-		/* Make sure that this file really is inside the workspace root */
-		if(workspacePath.isPrefixOf(filePath) == false)
-			return null;
-		
-		filePath = filePath.removeFirstSegments(workspacePath.segmentCount());
-		
-		IFile f = 
-			ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
-		
-		return f;
-	}
-	
-	public File getFile() throws ConnectionException, UnexpectedReplyException
-	{
-		String[] tokens = OMCProxy.getCrefInfo(fullName);
-		
-		File file = new File(tokens[0]);
-		
-		return file;
-	}
-	
-	public int getLine() throws ConnectionException, UnexpectedReplyException
-	{
-		String[] tokens = OMCProxy.getCrefInfo(fullName);
-		return Integer.parseInt(tokens[1]);
-	}
-
+	{
+		return container;
+	}
+
+	
+	
+	/**
+	 * @throws InvocationError 
+	 * @throws CoreException 
+	 * @see org.modelica.mdt.core.IModelicaElement#getLocation()
+	 */
+	public IRegion getLocation() 
+		throws ConnectionException, UnexpectedReplyException, 
+			InvocationError, CoreException
+	{
+		if (location == null)
+		{
+			loadElementLocation();
+		}
+		
+		if (container != null)
+		{
+			SyntaxChecker.getLineRegion(container, location.getLine());
+		}
+
+		IRegion reg = null;
+		
+		try
+		{
+			reg = 
+				SyntaxChecker.getLineRegion(location.getPath(), 
+						location.getLine());
+		}
+		catch (FileNotFoundException e)
+		{
+			throw new CoreException(
+					new Status(IStatus.ERROR,
+								MdtPlugin.getSymbolicName(),
+								IStatus.OK, 
+								"could not find modelica source file " + 
+									location.getPath(),
+								e));
+		}
+		return reg;
+	}
+
+	@Override
+	public String getFilePath() 
+		throws ConnectionException, UnexpectedReplyException, InvocationError
+	{
+		if (location == null)
+		{
+			loadElementLocation();
+		}
+		return location.getPath();
+	}
+
+	private void loadElementLocation()
+		throws ConnectionException, UnexpectedReplyException, InvocationError
+	{
+		location = OMCProxy.getElementLocation(fullName);
+	}
 
 	public Collection<Object> getChildren() 
@@ -153,10 +200,10 @@
 		for (String name : OMCProxy.getPackages(fullName))
 		{
-			elements.put(name, new InnerPackage(fullName, name));
+			elements.put(name, new InnerPackage(container, fullName, name));
 		}
 		
 		for (String name : OMCProxy.getClassNames(fullName))
 		{
-			elements.put(name, new ModelicaClass(fullName, name));
+			elements.put(name, new ModelicaClass(container, fullName, name));
 		}
 		
@@ -183,4 +230,7 @@
 			return changes;
 		}
+		
+		/* invalidate location */
+		location = null;
 		
 		Hashtable<String, Object> newChildren = loadElements();
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaElement.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaElement.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaElement.java	(revision 174)
@@ -47,5 +47,7 @@
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.jface.text.IRegion;
 import org.eclipse.ui.model.IWorkbenchAdapter;
 import org.modelica.mdt.core.IModelicaElement;
@@ -170,3 +172,18 @@
 		return new LinkedList<IModelicaElementChange>();		
 	}
+
+	public IRegion getLocation() 
+		throws ConnectionException, UnexpectedReplyException, 
+			InvocationError, CoreException
+	{
+		/* we don't have a definition region by default */
+		return null;
+	}
+
+	public String getFilePath() 
+		throws ConnectionException, UnexpectedReplyException, InvocationError
+	{
+		/* we are not defined in an external file by default */
+		return null;
+	}
 }
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaFile.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaFile.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaFile.java	(revision 174)
@@ -126,9 +126,10 @@
 				{
 					/* we are not inside a package */
-					elements.put(name, new InnerPackage("", name));
+					elements.put(name, new InnerPackage(file, "", name));
 				}
 				else
 				{
 					elements.put(name, new InnerPackage(
+							file,
 							parentPackage.getFullName(),
 							name));					
@@ -137,5 +138,5 @@
 			else
 			{
-				elements.put(name, new ModelicaClass("", name));
+				elements.put(name, new ModelicaClass(file, "", name));
 			}
 		}
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/ElementLocation.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/ElementLocation.java	(revision 174)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/ElementLocation.java	(revision 174)
@@ -0,0 +1,88 @@
+/*
+ * This file is part of Modelica Development Tooling.
+ *
+ * Copyright (c) 2005, Linköpings universitet, Department of
+ * Computer and Information Science, PELAB
+ *
+ * All rights reserved.
+ *
+ * (The new BSD license, see also
+ * http://www.opensource.org/licenses/bsd-license.php)
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of Linköpings universitet nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.modelica.mdt.internal.omcproxy;
+
+/**
+ * Presents information on some elements location in a file.
+ * More specific this class stores the location of the begging of the
+ * definition of the element.
+ * 
+ * @author Homer Simpson
+ */
+public class ElementLocation
+{
+	private String path;
+	private int line;
+	private int column;
+	
+	protected ElementLocation(String path, int line, int column)
+	{
+		this.path = path;
+		this.line = line;
+		this.column = column;
+	}
+
+	/**
+	 * @return the column where this element is defined
+	 */
+	public int getColumn()
+	{
+		return column;
+	}
+
+	/**
+	 * @return line number where this element is defined
+	 */
+	public int getLine()
+	{
+		return line;
+	}
+
+	/**
+	 * @return full path to the file where the element is defined
+	 */
+	public String getPath()
+	{
+		return path;
+	}
+	
+}
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/ElementsInfo.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/ElementsInfo.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/ElementsInfo.java	(revision 174)
@@ -1,4 +1,48 @@
+/*
+ * This file is part of Modelica Development Tooling.
+ *
+ * Copyright (c) 2005, Link�pings universitet, Department of
+ * Computer and Information Science, PELAB
+ *
+ * All rights reserved.
+ *
+ * (The new BSD license, see also
+ * http://www.opensource.org/licenses/bsd-license.php)
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of Link�pings universitet nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 package org.modelica.mdt.internal.omcproxy;
 
+/**
+ * what the fudge does this class do, and why is it empty ?
+ */
 public class ElementsInfo
 {
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/OMCProxy.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/OMCProxy.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/omcproxy/OMCProxy.java	(revision 174)
@@ -521,6 +521,7 @@
 	}
 
-	public static String[] getCrefInfo(String className)
-		throws ConnectionException, UnexpectedReplyException 
+	
+	public static ElementLocation getElementLocation(String className)
+		throws ConnectionException, UnexpectedReplyException, InvocationError 
 	{
 		String retval = sendExpression("getCrefInfo(" + className + ")");
@@ -528,13 +529,34 @@
 		if(retval.contains("Error") || retval.contains("error"))
 		{
-			return null;
-		}
+			throw new InvocationError("getCrefInfo(" + className + 
+					") replys error");
+		}
+		
+		
+		/*
+		 * getCrefInfo reply have following format:
+		 * 
+		 * <file path>,<line number>,<column number>
+		 * 
+		 */
 		
 		/* For some reason, the list returned doesn't contain curly braces. */
 		retval = "{" + retval + "}"; 
-		
+
 		String[] tokens = ProxyParser.parseSimpleList(retval);
-		
-		return tokens; 
+		int line, column;
+
+		try
+		{
+			line = Integer.parseInt(tokens[1]);
+			column = Integer.parseInt(tokens[2]);
+		}
+		catch (NumberFormatException e)
+		{
+			throw new InvocationError("can't parse getCrefInfo() reply, "+
+					"unexpected format");
+		}
+		
+		return new ElementLocation(tokens[0], line, column);
 	}
 	
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/ui/PerspectiveFactory.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/ui/PerspectiveFactory.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/ui/PerspectiveFactory.java	(revision 174)
@@ -2,5 +2,5 @@
  * This file is part of Modelica Development Tooling.
  *
- * Copyright (c) 2005, Link�pings universitet, Department of
+ * Copyright (c) 2005, Linköpings universitet, Department of
  * Computer and Information Science, PELAB
  *
@@ -23,5 +23,5 @@
  *   distribution.
  *
- * * Neither the name of Link�pings universitet nor the names of its
+ * * Neither the name of Linköpings universitet nor the names of its
  *   contributors may be used to endorse or promote products derived from
  *   this software without specific prior written permission.
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/ui/ProjectsView.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/ui/ProjectsView.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/ui/ProjectsView.java	(revision 174)
@@ -1,6 +1,46 @@
+/*
+ * This file is part of Modelica Development Tooling.
+ *
+ * Copyright (c) 2005, Linköpings universitet, Department of
+ * Computer and Information Science, PELAB
+ *
+ * All rights reserved.
+ *
+ * (The new BSD license, see also
+ * http://www.opensource.org/licenses/bsd-license.php)
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of Linköpings universitet nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 package org.modelica.mdt.ui;
 
-import org.eclipse.core.resources.IResourceChangeListener;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
 
 import org.eclipse.jface.action.IMenuListener;
@@ -10,6 +50,8 @@
 import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IOpenListener;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.TreeViewer;
@@ -25,4 +67,5 @@
 import org.eclipse.ui.IWorkbenchActionConstants;
 import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.actions.CloseResourceAction;
@@ -36,4 +79,8 @@
 import org.modelica.mdt.MdtPlugin;
 import org.modelica.mdt.core.ModelicaCore;
+import org.modelica.mdt.editor.EditorUtility;
+import org.modelica.mdt.internal.omcproxy.ConnectionException;
+import org.modelica.mdt.internal.omcproxy.InvocationError;
+import org.modelica.mdt.internal.omcproxy.UnexpectedReplyException;
 
 public class ProjectsView extends ViewPart
@@ -44,5 +91,4 @@
 	private TreeViewer viewer;
 	private DrillDownAdapter drillDownAdapter;
-	private IResourceChangeListener resourceListener;
 	private ProjectsViewDoubleClickAction doubleClickAction;
 	
@@ -81,4 +127,11 @@
 		site.registerContextMenu(contextMenu, viewer);
 		site.setSelectionProvider(viewer);
+		
+		viewer.addOpenListener(new IOpenListener() {
+			public void open(OpenEvent event) 
+			{
+				handleOpen(event);
+			}
+		});
 		
 		makeActions(); // call before registering for selection changes
@@ -97,4 +150,5 @@
 		
 		hookDoubleClickAction();
+		
 		viewer.getTree().addKeyListener(new KeyAdapter()
 		{
@@ -106,4 +160,34 @@
 			
 		});
+	}
+
+	protected void handleOpen(OpenEvent event)
+	{
+		IStructuredSelection selecton = 
+			(IStructuredSelection) event.getSelection();
+		try
+		{
+			EditorUtility.openInEditor(selecton.getFirstElement());
+		} catch (PartInitException e)
+		{
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (ConnectionException e)
+		{
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (UnexpectedReplyException e)
+		{
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (InvocationError e)
+		{
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (CoreException e)
+		{
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 	}
 
@@ -212,9 +296,8 @@
 		manager.add(closeProjectAction);
 
-		
-//		openProjectAction.selectionChanged((IStructuredSelection) viewer.getSelection());
 		deleteAction.selectionChanged((IStructuredSelection) viewer.getSelection());
 		manager.add(new Separator());
 		drillDownAdapter.addNavigationActions(manager);
+		
 		// Other plug-ins can contribute there actions here
 		manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
@@ -225,7 +308,4 @@
 	{
 		super.dispose();
-
-		ResourcesPlugin.getWorkspace().
-			removeResourceChangeListener(resourceListener);
 	}
 
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/ui/ProjectsViewDoubleClickAction.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/ui/ProjectsViewDoubleClickAction.java	(revision 172)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/ui/ProjectsViewDoubleClickAction.java	(revision 174)
@@ -1,39 +1,60 @@
+/*
+ * This file is part of Modelica Development Tooling.
+ *
+ * Copyright (c) 2005, Linköpings universitet, Department of
+ * Computer and Information Science, PELAB
+ *
+ * All rights reserved.
+ *
+ * (The new BSD license, see also
+ * http://www.opensource.org/licenses/bsd-license.php)
+ *
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in
+ *   the documentation and/or other materials provided with the
+ *   distribution.
+ *
+ * * Neither the name of Linköpings universitet nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
 package org.modelica.mdt.ui;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.content.IContentType;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.ui.IEditorDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorRegistry;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.ide.IDE;
-import org.modelica.mdt.MdtPlugin;
-import org.modelica.mdt.builder.SyntaxChecker;
-import org.modelica.mdt.core.IModelicaClass;
-import org.modelica.mdt.core.IModelicaFile;
 import org.modelica.mdt.core.IModelicaFolder;
 import org.modelica.mdt.core.IModelicaPackage;
 import org.modelica.mdt.core.IModelicaProject;
 import org.modelica.mdt.core.ISystemLibrary;
-import org.modelica.mdt.editor.ModelicaFileEditorInput;
-import org.modelica.mdt.internal.omcproxy.CompilerException;
+
+/**
+ * Defines what happens when user double clicks on items in the
+ * projects view tree. 
+ */
 
 public class ProjectsViewDoubleClickAction extends Action 
@@ -53,52 +74,5 @@
 		Object obj = ((IStructuredSelection)selection).getFirstElement();
 		
-		/* open modelica files in an editor on double click */
-		if (obj instanceof IModelicaFile)
-		{
-			try
-			{
-				openInternalFile((IFile)((IModelicaFile)obj).getResource());
-			} 
-			catch (CompilerException e)
-			{
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-		/* open files in an editor on double click */
-		else if (obj instanceof IFile)
-		{
-			openInternalFile((IFile)obj);
-		}
-		/* open file that this class is contained in */
-		else if(obj instanceof IModelicaClass)
-		{
-			try
-			{
-				IFile file = (IFile)((IModelicaClass)obj).getResource();
-				
-				/* If file is null, the ModelicaClass is contained in an 
-				 * external file. */
-				if(file == null)
-				{
-					openExternalFile(((IModelicaClass)obj).getFile());
-				}
-				else
-				{
-					int line = ((IModelicaClass)obj).getLine();
-					IMarker marker;
-					marker = SyntaxChecker.createMarkerAtLine(file, line,
-							"TEMP", IMarker.TEXT);
-					openInternalFile(file, marker);
-				}
-			}
-			catch (CompilerException e)
-			{
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-		/* expands a bunch of objects on double click */
-		else if (obj instanceof IModelicaProject ||
+		if (obj instanceof IModelicaProject ||
 				 obj instanceof IModelicaFolder  ||
 				 obj instanceof IModelicaPackage ||
@@ -121,96 +95,3 @@
 		viewer.expandToLevel(element, 1);
 	}
-
-	private void openInternalFile(IFile file)
-	{
-		openInternalFile(file, null);
-	}
-	/**
-	 * Opens file in the default editor
-	 * param file file to open
-	 */
-	private void openInternalFile(IFile file, IMarker marker)
-	{
-			
-		IWorkbenchPage page = PlatformUI.getWorkbench().
-			getActiveWorkbenchWindow().getActivePage();
-
-		if (page != null)
-		{
-			try
-			{
-				IDE.openEditor(page, file);
-				if(marker != null)
-				{
-					IDE.openEditor(page, marker);
-					try
-					{
-						file.deleteMarkers(IMarker.TEXT, true,
-								IFile.DEPTH_INFINITE);
-					}
-					catch(CoreException e)
-					{
-						e.printStackTrace();
-						MdtPlugin.log(e);
-					}
-				}
-			} 
-			catch (PartInitException e)  
-			{
-				// TODO proper error handling
-				e.printStackTrace();
-			}
-		}
-	}
-
-	private void openExternalFile(File file)
-	{
-		IEditorInput input = new ModelicaFileEditorInput(file);
-		
-		String editorId = getEditorId(file);
-		
-		IWorkbenchPage page = PlatformUI.getWorkbench()
-			.getActiveWorkbenchWindow().getActivePage();
-		
-		try
-		{
-			page.openEditor(input, editorId);
-		}
-		catch (PartInitException e)
-		{
-			MdtPlugin.log(e.getStatus());
-		}
-	}
-	
-	private String getEditorId(File file)
-	{
-		IWorkbench workbench= PlatformUI.getWorkbench(); 
-		IEditorRegistry editorRegistry= workbench.getEditorRegistry();
-		IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName(), getContentType(file));
-		if (descriptor != null)
-			return descriptor.getId();
-		return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
-	}
-	
-	private IContentType getContentType (File file)
-	{
-		if (file == null)
-			return null;
-
-		InputStream stream= null;
-		try {
-			stream= new FileInputStream(file);
-			return Platform.getContentTypeManager().findContentTypeFor(stream, file.getName());
-		} catch (IOException x) {
-			MdtPlugin.log(x);
-			return null;
-		} finally {
-			try {
-				if (stream != null)
-					stream.close();
-			} catch (IOException x) {
-				MdtPlugin.log(x);
-			}
-		}
-	}
 }
