Index: trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaRoot.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaRoot.java	(revision 124)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/core/IModelicaRoot.java	(revision 127)
@@ -56,3 +56,10 @@
 	 */
 	public Object[] getProjects() throws CoreException;
+	
+//	/**
+//	 * @param path the path to directory or file where to look for package
+//	 * @return the package located at path or null if there is no package at
+//	 * that path
+//	 */
+//	public IModelicaPackage getPackage(IPath path);
 }
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 124)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaClass.java	(revision 127)
@@ -17,5 +17,5 @@
 	
 	private boolean typeKnown = false;
-	
+		
 	protected ModelicaClass(String name, String pkg)
 	{
@@ -52,3 +52,4 @@
 		return type;
 	}
+
 }
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 124)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaElement.java	(revision 127)
@@ -41,4 +41,6 @@
 package org.modelica.mdt.internal.core;
 
+import java.util.regex.Pattern;
+
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.PlatformObject;
@@ -51,6 +53,16 @@
  *
  */
-abstract public class ModelicaElement extends PlatformObject implements IModelicaElement 
+abstract public class ModelicaElement extends PlatformObject 
+	implements IModelicaElement 
 {
+	
+	/* regexp pattern of a valid modelica class name */
+	//TODO add complete regexp for modelcia class name 
+	// see modelica specification page 9 (and perhaps some other pages as
+	// well)
+	// http://www.modelica.org/documents/ModelicaSpec22.pdf
+    private static Pattern classNamePattern = Pattern.compile("[a-zA-Z]\\w*");
+
+
 
 	@Override
@@ -77,4 +89,12 @@
 		return null;
 	}
+
+	/**
+	 * @return true if name is a valid modelica identifier name
+	 */
+	public static boolean isLegalIdentifierName(String name)
+	{
+		return classNamePattern.matcher(name).matches();
+	}
 	
 	
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaPackage.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaPackage.java	(revision 124)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaPackage.java	(revision 127)
@@ -174,4 +174,14 @@
 	}
 
+	public String getFullName() 
+	{
+		if (baseName.equals(""))
+		{
+			return getElementName();
+		}
+
+		return baseName + "." + getElementName();
+	}
+
 	public List<?> getChildren() 
 	{
@@ -216,3 +226,5 @@
 		return folder.getFiles();
 	}
+
+
 }
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaRoot.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaRoot.java	(revision 124)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/internal/core/ModelicaRoot.java	(revision 127)
@@ -56,5 +56,5 @@
 	private IWorkspaceRoot workspaceRoot = null;
 
-	/* (non-Javadoc)
+	/**
 	 * @see org.modelica.mdt.core.IModelicaRoot#getProjects()
 	 */
@@ -88,5 +88,10 @@
 	}
 
-
+//	public IModelicaPackage getPackage(IPath path)
+//	{
+//		return null;
+//	}
+//
+//	
 
 }
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/ui/wizards/NewClassWizard.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/ui/wizards/NewClassWizard.java	(revision 124)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/ui/wizards/NewClassWizard.java	(revision 127)
@@ -47,5 +47,4 @@
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
-import java.util.regex.Pattern;
 
 import org.eclipse.core.resources.IContainer;
@@ -88,4 +87,5 @@
 import org.eclipse.ui.ide.IDE;
 import org.modelica.mdt.MdtPlugin;
+import org.modelica.mdt.internal.core.ModelicaElement;
 
 public class NewClassWizard extends Wizard implements INewWizard
@@ -111,13 +111,5 @@
 	
 		private IPath selection = null;
-		
-		
-		/* regexp pattern of a valid modelica class name */
-		//TODO add complete regexp for modelcia class name 
-		// see modelica specification page 9 (and perhaps some other pages as
-		// well)
-		// http://www.modelica.org/documents/ModelicaSpec22.pdf
-        Pattern classNamePattern = Pattern.compile("[a-zA-Z]\\w*");
-        
+		        
 		private boolean classNameValid = false;
 		private boolean sourceFolderValid = false;		
@@ -208,5 +200,5 @@
 	        	public void modifyText(ModifyEvent e)
 	        	{
-	        		if (!isLegalClassName(className.getText()))
+	        		if (!ModelicaElement.isLegalIdentifierName(className.getText()))
 	        		{
 	        			classNameValid  = false;
@@ -343,14 +335,6 @@
 			updateStatus(null, DialogPage.NONE);
 		}
-
-		/**
-		 * @return true if name is a valid modelica class name
-		 */
-		protected boolean isLegalClassName(String name)
-		{
-			return classNamePattern.matcher(name).matches();
-		}
-		
-		public void init(IStructuredSelection selection)
+		
+		public void setSelection(IStructuredSelection selection)
 		{
 			if (selection == null || selection.size() != 1)
@@ -608,5 +592,5 @@
 	public void init(IWorkbench workbench, IStructuredSelection selection)
 	{
-		classPage.init(selection);
+		classPage.setSelection(selection);
 		setWindowTitle("New Modelica Class");
 	}
Index: trunk/org.modelica.mdt/src/org/modelica/mdt/ui/wizards/NewPackageWizard.java
===================================================================
--- trunk/org.modelica.mdt/src/org/modelica/mdt/ui/wizards/NewPackageWizard.java	(revision 124)
+++ trunk/org.modelica.mdt/src/org/modelica/mdt/ui/wizards/NewPackageWizard.java	(revision 127)
@@ -41,5 +41,20 @@
 package org.modelica.mdt.ui.wizards;
 
+import java.io.ByteArrayInputStream;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.dialogs.DialogPage;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
@@ -58,8 +73,8 @@
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
-import org.modelica.mdt.core.IModelicaClass;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+import org.modelica.mdt.MdtPlugin;
 import org.modelica.mdt.core.IModelicaElement;
-import org.modelica.mdt.core.IModelicaFile;
-import org.modelica.mdt.core.IModelicaFolder;
+import org.modelica.mdt.internal.core.ModelicaElement;
 import org.modelica.mdt.internal.core.ModelicaPackage;
 import org.modelica.mdt.ui.ModelicaImages;
@@ -67,19 +82,106 @@
 public class NewPackageWizard extends Wizard implements INewWizard
 {
+
+	public static final String PACKAGE_NAME_TAG = "packageNameTag";
+	public static final String PACKAGE_DESC_TAG = "packageDescTag";
+	public static final String SOURCE_FOLDER_TAG = "pkgSourceFolderTag";
+	public static final String IS_ENCAPSULATED_TAG = "isEncapsulatedTag";
+
 	private Text sourceFolder;
+	@SuppressWarnings("unused")
 	private Text parentPackage;
 	private Text packageName;
 	private Text packageDesc;
 	public Button isEncapsulated;
-	
-	
-
 	private NewPackagePage packagePage = new NewPackagePage();
+
+	private class PackageCreator implements IRunnableWithProgress 
+	{
+		private IPath packagePath;
+		private String packageName;
+		private boolean isEncapsulated;
+		private String description;
+
+		/**
+		 * 
+		 * @param packagePath
+		 * @param packageName
+		 * @param description package documentation string, if is "" no
+		 *        documentation string generated 
+		 * @param isEncapsulated
+		 */
+		public PackageCreator(IPath packagePath, String packageName,
+							String description, boolean isEncapsulated)
+		{
+			this.packagePath = packagePath;
+			this.packageName = packageName;
+			this.isEncapsulated = isEncapsulated;
+			this.description = description;
+		}
+		public void run(IProgressMonitor monitor)
+				throws InvocationTargetException, InterruptedException 
+		{
+			monitor.beginTask("Creating package " + packageName, 3);
+			/*
+			 * generate contents of package.mo
+			 */
+			String contents = "";
+			
+			if (isEncapsulated)
+			{
+				contents += "encapsulated ";
+			}
+			contents += "package " + packageName;
+
+			if (!description.equals(""))
+			{
+				contents += " \"" + description + "\"";
+			}
+			contents += "\n\nend " + packageName + ";";
+			
+			monitor.worked(1);
+
+			try 
+			{
+				/*
+				 * create the new package's root folder  
+				 */
+
+				IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+				IContainer pkgParent = (IContainer) root.findMember(packagePath);
+
+				IFolder pkgFolder = 
+					pkgParent.getFolder(new Path(packageName));
+
+				pkgFolder.create(false, true, null);
+				monitor.worked(1);
+
+				/*
+				 * create the new package's package.mo file
+				 */
+				IFile packageMo = 
+					pkgFolder.getFile(new Path("package.mo"));
+
+				packageMo.create(new ByteArrayInputStream(contents.getBytes()),
+						true, null);
+				monitor.worked(1);
+
+			}
+			catch (CoreException e) 
+			{
+				throw new InvocationTargetException(e);
+			}
+			finally
+			{
+				monitor.done();
+			}
+		}
+	}
 
 	public class NewPackagePage extends WizardPage
 	{
-
-		@SuppressWarnings("unused")
 		private Object selection = null;
+		protected boolean packageNameValid = false;
+		public boolean sourceFolderValid = true;
 
 		public NewPackagePage()
@@ -103,5 +205,5 @@
 			 * setup widgets for this page
 			 */
-			Composite composite= new Composite(parent, SWT.NONE);
+			Composite composite = new Composite(parent, SWT.NONE);
 			setControl(composite);
 			composite.setFont(parent.getFont());
@@ -124,13 +226,13 @@
 	        					GridData.GRAB_HORIZONTAL);
 	        sourceFolder.setLayoutData(gd);
-
+	        MdtPlugin.tag(sourceFolder, SOURCE_FOLDER_TAG);
 	        
 	        sourceFolder.addModifyListener(new ModifyListener()
 	    	{
-	    	      	/* check if entered path exists */
-	    	       	public void modifyText(ModifyEvent e)
-	    	       	{
-	    	       		//sourceFolderChanged();
-	    	       	}
+	        	/* check if entered path exists */
+	        	public void modifyText(ModifyEvent e)
+	        	{
+	    	       		sourceFolderChanged();
+	        	}
 	    	});
 
@@ -145,43 +247,43 @@
 				public void widgetSelected(SelectionEvent e)
 				{
-					//handleBrowse();
+					handleBrowse();
 				}
 			});
 
-	        /* parent package field */
-	        l = new Label(composite, SWT.LEFT | SWT.WRAP);
-	        l.setText("Parent package:");
-	        gd = new GridData();
-	        gd.horizontalAlignment = GridData.BEGINNING;
-	        l.setLayoutData(gd);
-	        
-	        parentPackage = new Text(composite, SWT.SINGLE | SWT.BORDER);
-	        gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
-	        					GridData.GRAB_HORIZONTAL);
-	        parentPackage.setLayoutData(gd);
-
-	        
-	        parentPackage.addModifyListener(new ModifyListener()
-	    	{
-	    	      	/* check if entered path exists */
-	    	       	public void modifyText(ModifyEvent e)
-	    	       	{
-	    	       		//sourceFolderChanged();
-	    	       	}
-	    	});
-
-
-	        b = new Button(composite, SWT.PUSH);
-	        b.setText("Browse...");
-	        gd = new GridData();
-	        gd.horizontalAlignment = GridData.END;
-	        b.setLayoutData(gd);
-			b.addSelectionListener(new SelectionAdapter()
-			{
-				public void widgetSelected(SelectionEvent e)
-				{
-					//handleBrowse();
-				}
-			});
+//	        /* parent package field */
+//	        l = new Label(composite, SWT.LEFT | SWT.WRAP);
+//	        l.setText("Parent package:");
+//	        gd = new GridData();
+//	        gd.horizontalAlignment = GridData.BEGINNING;
+//	        l.setLayoutData(gd);
+//	        
+//	        parentPackage = new Text(composite, SWT.SINGLE | SWT.BORDER);
+//	        gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL |
+//	        					GridData.GRAB_HORIZONTAL);
+//	        parentPackage.setLayoutData(gd);
+//
+//	        
+//	        parentPackage.addModifyListener(new ModifyListener()
+//	    	{
+//	    	      	/* check if entered path exists */
+//	    	       	public void modifyText(ModifyEvent e)
+//	    	       	{
+//	    	       		//sourceFolderChanged();
+//	    	       	}
+//	    	});
+//
+//
+//	        b = new Button(composite, SWT.PUSH);
+//	        b.setText("Browse...");
+//	        gd = new GridData();
+//	        gd.horizontalAlignment = GridData.END;
+//	        b.setLayoutData(gd);
+//			b.addSelectionListener(new SelectionAdapter()
+//			{
+//				public void widgetSelected(SelectionEvent e)
+//				{
+//					//handleBrowse();
+//				}
+//			});
 			
 	        /* create separator */
@@ -205,4 +307,5 @@
 	        gd.horizontalSpan = 2;
 	        packageName.setLayoutData(gd);
+	        MdtPlugin.tag(packageName, PACKAGE_NAME_TAG);
 
 	        packageName.addModifyListener(new ModifyListener()
@@ -211,4 +314,17 @@
 	        	public void modifyText(ModifyEvent e)
 	        	{
+	        		if (!ModelicaElement.isLegalIdentifierName
+	        				(packageName.getText()))
+	        		{
+	        			packageNameValid  = false;
+	        			updateStatus("Package name is not valid. Illegal " +
+	        					"identifier.",
+	        					DialogPage.WARNING);
+	        		}
+	        		else
+	        		{
+	        			packageNameValid  = true;
+	        			updateStatus(null, DialogPage.NONE);
+	        		}
 	        	}
 	        });
@@ -227,4 +343,5 @@
 	        gd.horizontalSpan = 2;
 	        packageDesc.setLayoutData(gd);
+	        MdtPlugin.tag(packageDesc, PACKAGE_DESC_TAG);
 	        
 	        /* is encapsulated package field */
@@ -237,47 +354,127 @@
 	        gd.horizontalSpan = 2;
 	        isEncapsulated.setLayoutData(gd);
-	        
-	        setSelection();
-		}
-
-		private void setSelection() 
-		{
+	        MdtPlugin.tag(isEncapsulated, IS_ENCAPSULATED_TAG);
+	        
+	        setSelection(selection);
+		}
+		
+		private void sourceFolderChanged()
+		{
+			IResource container = ResourcesPlugin.getWorkspace().getRoot()
+					.findMember(new Path(sourceFolder.getText()));
+
+			sourceFolderValid = false;
+			if (sourceFolder.getText().length() == 0) {
+				updateStatus("File container must be specified", 
+						DialogPage.ERROR);
+				return;
+			}
+			if (container == null ||
+			    (container.getType() & 
+			      (IResource.PROJECT | IResource.FOLDER)) == 0) 
+			{
+				updateStatus("File container must exist", DialogPage.ERROR);
+				return;
+			}
+			if (!container.isAccessible()) {
+				updateStatus("Project must be writable", DialogPage.ERROR);
+				return;
+			}
+			sourceFolderValid = true;
+			updateStatus(null, DialogPage.NONE);
+		}
+
+		private void handleBrowse()
+		{
+			ContainerSelectionDialog dialog =
+				new ContainerSelectionDialog(
+					getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
+					"Choose a source folder:");
+			
+			if (dialog.open() == ContainerSelectionDialog.OK)
+			{
+				Object[] result = dialog.getResult();
+				if (result.length == 1)
+				{
+					setSourceFolder((IPath) result[0]);
+				}
+			}
+		}
+
+		private void setSelection(Object selection) 
+		{
+			IResource res;
+			
 			if (selection instanceof ModelicaPackage)
 			{
-				setParentPackage((ModelicaPackage)selection);
-				System.out.println("filesystem package");
-			}
-			else if (selection instanceof IModelicaFolder || 
-					 selection instanceof IModelicaClass  ||
-					 selection instanceof IModelicaFile)
-			{	
-				System.out.println("modelica element " +
-						(IModelicaElement)selection);
+				/*
+				 *  ModelicaPackage used instead of IModelicaPackage
+				 * to ignore modelica packages elements that are listed under
+				 * system library subtree
+				 */
+
+				//setParentPackage((ModelicaPackage)selection);
+				res = ((ModelicaPackage)selection).getResource();
+			}
+			else if (selection instanceof IModelicaElement)
+			{
+				res = 
+					((IModelicaElement)selection).getResource();
 			}
 			else if (selection instanceof IResource)
 			{
-				/* a file or a folder is selected */
-				System.out.println("resource ");
-			}
-			/* ignore all other types of selections */
-		}
-
+				res = ((IResource)selection);
+			}
+			else
+			{
+				/* ignore all other types of selections */
+				return;
+			}
+			
+			/*
+			 * calculate the source folder path 
+			 */
+			IPath path = res.getFullPath();
+			
+			if (res.getType() == IResource.FILE)
+			{
+				path = path.removeLastSegments(1);
+			}
+
+			setSourceFolder(path);
+
+		}
+		
 		/**
-		 * set parent package field in the dialog
+		 * set source folder field in the dialog
 		 * 
-		 * @param parentPkg the parent package to set or null to set
-		 * empty parent package 
+		 * @param path the path to set source folder field to
 		 */
-		private void setParentPackage(ModelicaPackage parentPkg) 
-		{
-			if (parentPkg == null)
-			{
-				parentPackage.setText("");
-			}
-			else
-			{
-			//	parentPgk;
-			}
-		}
+		public void setSourceFolder(IPath path)
+		{
+	        if (path != null)
+	        {	        	
+	        	sourceFolder.setText(path.makeRelative().toString());
+	        	sourceFolderChanged();
+	        }	        			
+		}
+		
+//		/**
+//		 * set parent package field in the dialog
+//		 * 
+//		 * @param parentPkg the parent package to set or null to set
+//		 * empty parent package 
+//		 */
+//		private void setParentPackage(ModelicaPackage parentPkg) 
+//		{
+//			if (parentPkg == null)
+//			{
+//				parentPackage.setText("");
+//			}
+//			else
+//			{
+//				parentPackage.setText(parentPkg.getFullName());
+//			}
+//		}
 
 		public void init(IStructuredSelection selection)
@@ -295,16 +492,16 @@
 		
 		
-		@SuppressWarnings("unused")
 		private void updateStatus(String message, int messageType)
 		{
 			setMessage(message, messageType);
+			setPageComplete((packageNameValid && sourceFolderValid));
 		}
 
 	}
-
 
 	public NewPackageWizard()
 	{
 		super();
+		setNeedsProgressMonitor(true);
 	}
 
@@ -313,4 +510,25 @@
 	public boolean performFinish()
 	{
+		IRunnableWithProgress runable = 
+			new PackageCreator(new Path(sourceFolder.getText()),
+							   packageName.getText(),
+							   packageDesc.getText(),
+							   isEncapsulated.getSelection());
+
+		try
+		{
+			getContainer().run(true, false, runable);
+		}
+		catch (InterruptedException e)
+		{
+			return false;
+		}
+		catch (InvocationTargetException e)
+		{
+			Throwable realException = e.getTargetException();
+			MessageDialog.openError(getShell(), "Error", 
+					realException.getMessage());
+			return false;
+		}
 		return true;
 	}
