From b33768692788964bbdc4839678e079d0517d07dc Mon Sep 17 00:00:00 2001
From: Chan Le Duc <chan.leduc@univ-paris13.fr>
Date: Wed, 26 Aug 2009 16:53:51 +0000
Subject: [PATCH] --Updated for OWLAPI

---
 .../exmo/align/plugin/neontk/AlignView.java   |  78 ++++--
 .../align/plugin/neontk/NavigationView.java   | 250 ------------------
 .../align/plugin/neontk/OfflineAlign.java     |   4 +-
 3 files changed, 55 insertions(+), 277 deletions(-)
 delete mode 100755 plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/NavigationView.java

diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java
index 4c9ccbc3..1a694060 100755
--- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java
+++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/AlignView.java
@@ -58,23 +58,32 @@ import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.dialogs.MessageDialog;
 
 //import org.eclipse.jface.dialogs.MessageDialog;
-import org.semanticweb.kaon2.api.OntologyManager;
+//import org.semanticweb.kaon2.api.OntologyManager;
 import org.semanticweb.owl.align.Alignment;
 import org.semanticweb.owl.align.AlignmentVisitor;
 
-import com.ontoprise.config.IConfig;
-import com.ontoprise.ontostudio.datamodel.DatamodelPlugin;
-import com.ontoprise.ontostudio.datamodel.DatamodelTypes;
-import com.ontoprise.ontostudio.datamodel.exception.ControlException;
-import com.ontoprise.ontostudio.gui.commands.project.CreateProject;
-import com.ontoprise.ontostudio.io.ImportExportControl;
+//import com.ontoprise.config.IConfig;
+import org.neontoolkit.core.NeOnCorePlugin;
+
+//import org.neontoolkit.datamodel.DatamodelPlugin;
+//import org.neontoolkit.core.DatamodelTypes;
+//import com.ontoprise.ontostudio.datamodel.exception.ControlException;
+
+import org.neontoolkit.core.command.project.CreateProject;
+import org.neontoolkit.core.project.IOntologyProject;
+import org.neontoolkit.core.project.OntologyProjectManager;
+//import org.neontoolkit.io.ImportExportControl;
+import org.neontoolkit.io.util.ImportExportUtils;
+import org.semanticweb.owlapi.model.OWLOntologyManager;
+import org.semanticweb.owlapi.model.OWLOntology;
+import com.ontoprise.ontostudio.owl.model.OWLManchesterProjectFactory;
 
 import fr.inrialpes.exmo.align.impl.ObjectAlignment;
 import fr.inrialpes.exmo.align.impl.URIAlignment;
 import fr.inrialpes.exmo.align.impl.renderer.HTMLRendererVisitor;
 import fr.inrialpes.exmo.align.impl.renderer.OWLAxiomsRendererVisitor;
 import fr.inrialpes.exmo.align.onto.OntologyFactory;
-//import fr.inrialpes.exmo.align.onto.owlapi10.OWLAPIOntologyFactory;
+
 import fr.inrialpes.exmo.align.parser.AlignmentParser;
 import fr.inrialpes.exmo.align.plugin.neontk.AlignFormLayoutFactory;
 import fr.inrialpes.exmo.align.plugin.neontk.AlignFormSectionFactory;
@@ -739,7 +748,9 @@ public class AlignView extends ViewPart
 							return;
 						}
                                
-						String[] projects = DatamodelPlugin.getDefault().getOntologyProjects();
+						String[] projects = OntologyProjectManager.getDefault().getOntologyProjects();
+						 
+						//String[] projects = DatamodelPlugin.getDefault().getOntologyProjects();
 	    				if(projects!=null) {
 	    				boolean found = false;	
 	    				
@@ -752,9 +763,12 @@ public class AlignView extends ViewPart
 	    				
 	    				if(!found) {
 	    					 
-	    					Properties proper = new Properties();
-   						proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString());
-   						new CreateProject(	inputName, DatamodelTypes.RAM, proper ).run();
+	    					//Properties proper = new Properties();
+   						//proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString());
+	    					
+   						new CreateProject( inputName, OWLManchesterProjectFactory.FACTORY_ID, new Properties()).run();
+   						
+   						//new CreateProject( inputName, DatamodelTypes.RAM, proper ).run();
 	    				}
 	    			    }
 	    				
@@ -766,7 +780,13 @@ public class AlignView extends ViewPart
 						out.write( owlalignStr );
 					    out.flush();
 						out.close();
-						 
+						
+						ImportExportUtils ieControl = new ImportExportUtils();
+   	    				
+   	    				URI uris[] = new URI[1];
+   	    				uris[0] = new File(owlPath).toURI();
+   	    				ieControl.copyOntologyFileToProject(uris[0].toString(), inputName);
+   	    				/*
 						try {
 							ImportExportControl ieControl = new ImportExportControl();
 							URI uris[] = new URI[1];
@@ -775,7 +795,7 @@ public class AlignView extends ViewPart
 					
 							//ieControl.addOntologies2Project(importedModules, inputName);
 						} catch (  ControlException ex ) { }
-							 
+						*/ 
 					} 
 					catch ( Exception ex ) { ex.printStackTrace();}
 				   
@@ -807,7 +827,7 @@ public class AlignView extends ViewPart
 						   return;
 					   }
    						
-					   String[] projects = DatamodelPlugin.getDefault().getOntologyProjects();
+					   String[] projects = OntologyProjectManager.getDefault().getOntologyProjects();
 					   
 					   if(projects!=null) {
 	 					boolean found = false;	
@@ -819,16 +839,20 @@ public class AlignView extends ViewPart
    	    				}
    	    				
    	    				if(!found) {
-   	    						Properties proper = new Properties();
-   	    						proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString());
-   	    						new CreateProject(	inputName, DatamodelTypes.RAM, proper ).run();
+   	    						//Properties proper = new Properties();
+   	    						//proper.put(IConfig.ONTOLOGY_LANGUAGE.toString(), IConfig.OntologyLanguage.OWL.toString());
+   	    						new CreateProject( inputName, OWLManchesterProjectFactory.FACTORY_ID, new Properties()).run();
+   	    						//new CreateProject(	inputName, DatamodelTypes.RAM, proper ).run();
            				
    	    				}
    					 
-   	    				ImportExportControl ieControl = new ImportExportControl();	
+   	    				//ImportExportControl ieControl = new ImportExportControl();
+   	    				ImportExportUtils ieControl = new ImportExportUtils();
+   	    				
    	    				URI uris[] = new URI[1];
    	    				uris[0] = new File(fn.getAbsolutePath()).toURI();
-   	    				ieControl.importFileSystem(inputName, uris, null);
+   	    				ieControl.copyOntologyFileToProject(uris[0].toString(), inputName);
+   	    				//ieControl.importFileSystem(inputName, uris, null);
    	    				 
    	    				}
        				}
@@ -1058,14 +1082,17 @@ public class AlignView extends ViewPart
 			HashMap<String,String>  vec = new HashMap<String,String>();
 			//OWLAPIOntologyFactory fact = new OWLAPIOntologyFactory();
 			OntologyFactory fact =  OntologyFactory.getFactory();
+			 
 			try {
-				String[] projects = DatamodelPlugin.getDefault().getOntologyProjects();
+				String[] projects = OntologyProjectManager.getDefault().getOntologyProjects();
 				if(projects != null) {
 				for(int i=0; i < projects.length; i++) {	 
 					if(projects[i]!=null) {  
-							 
-							OntologyManager connection = DatamodelPlugin.getDefault().getKaon2Connection(projects[i]);
-							Set<String> strSet = connection.getAvailableOntologyURIs();
+							  
+							//OntologyManager connection = DatamodelPlugin.getDefault().getKaon2Connection(projects[i]);
+							//Set<String> strSet = connection.getAvailableOntologyURIs();
+							IOntologyProject ontoProject = OntologyProjectManager.getDefault().getOntologyProject( projects[i] );
+							Set<String> strSet = ontoProject.getAvailableOntologyURIs();
 							String[] uris = (String[])strSet.toArray(new String[0]);
 							if(online) {
 								for(int k=0; k < uris.length; k++) {
@@ -1079,7 +1106,8 @@ public class AlignView extends ViewPart
 								}
 							} else {
 								for(int k=0; k < uris.length; k++) {
-									vec.put(DatamodelPlugin.getDefault().getPhysicalOntologyUri(projects[i], uris[k]).toString(),projects[i]);
+									vec.put(  (uris[k]).toString(), projects[i]);
+									//vec.put(DatamodelPlugin.getDefault().getPhysicalOntologyUri(projects[i], uris[k]).toString(),projects[i]);
 								}
 							}
 					}
diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/NavigationView.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/NavigationView.java
deleted file mode 100755
index 60e17914..00000000
--- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/NavigationView.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) INRIA, 2007-2008
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
- */
-
-
-package fr.inrialpes.exmo.align.plugin.neontk;
-
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerDropAdapter;
-import org.eclipse.ui.ISharedImages;
-//import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.PlatformUI;
-//import org.eclipse.ui.part.PluginDropAdapter;
-//import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.dnd.TransferData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.part.ViewPart;
-import java.util.ArrayList;
-
-import com.ontoprise.ontostudio.gui.navigator.SelectionTransfer;
-//import com.ontoprise.ontostudio.gui.instanceview.InstanceViewContentProvider;
-//import com.ontoprise.ontostudio.ontovisualize2.ModuleContentProvider;
-import com.ontoprise.ontostudio.gui.navigator.module.ModuleTreeElement;
-//import com.ontoprise.ontostudio.gui.navigator.MainTreeDataProvider;
-//import com.ontoprise.ontostudio.gui.TreeExtensionHandler;
-//import com.ontoprise.ontostudio.datamodel.natures.OntologyProjectNature;
-
-
-public class NavigationView extends ViewPart {
-	public static final String ID = "fr.inrialpes.exmo.align.plugin.neontk.navigationView";
-	private TreeViewer viewer;
-	//private ITreeDataProvider viewer;
-	 
-	/**
-     * This is a callback that will allow us to create the viewer and initialize
-     * it.
-     */
-	public void createPartControl(Composite parent) {
-		viewer = new TreeViewer(parent);
-		viewer.setContentProvider( new ViewContentProvider() );
-		//viewer.setContentProvider( new MainTreeDataProvider() );
-		//viewer.setLabelProvider( new ViewLabelProvider() );
-		//viewer.setInput( createDummyModel() );
-        createDropSupport();     
-	}
-	
-	class ViewLabelProvider extends LabelProvider {
-
-		public String getText(Object obj) {
-			return obj.toString();
-		}
-		public Image getImage(Object obj) {
-			String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
-			if (obj instanceof TreeParent)
-			   imageKey = ISharedImages.IMG_OBJ_FOLDER;
-			return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
-		}
-	}
-	
-	class TreeObject {
-		private String name;
-		private TreeParent parent;
-		
-		public TreeObject(String name) {
-			this.name = name;
-		}
-		public String getName() {
-			return name;
-		}
-		public void setParent(TreeParent parent) {
-			this.parent = parent;
-		}
-		public TreeParent getParent() {
-			return parent;
-		}
-		public String toString() {
-			return getName();
-		}
-	}
-	
-	class TreeParent extends TreeObject {
-		private ArrayList<TreeObject> children;
-		public TreeParent(String name) {
-			super(name);
-			children = new ArrayList<TreeObject>();
-		}
-		public void addChild(TreeObject child) {
-			children.add(child);
-			child.setParent(this);
-		}
-		public void removeChild(TreeObject child) {
-			children.remove(child);
-			child.setParent(null);
-		}
-		public TreeObject[] getChildren() {
-			return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
-		}
-		public boolean hasChildren() {
-			return children.size()>0;
-		}
-	}
-
-	class ViewContentProvider implements IStructuredContentProvider, 
-	   ITreeContentProvider {
-		
-				public void inputChanged(Viewer v, Object oldInput, Object newInput) {
-		}	
-
-		public void dispose() {
-		}
-
-		public Object[] getElements(Object parent) {
-			return getChildren(parent);
-		}
-
-		public Object getParent(Object child) {
-			if (child instanceof TreeObject) {
-				return ((TreeObject)child).getParent();
-			}
-			return null;
-		}
-
-		public Object[] getChildren(Object parent) {
-			if (parent instanceof TreeParent) {
-				return ((TreeParent)parent).getChildren();
-			}
-			return new Object[0];
-		}
-
-		public boolean hasChildren(Object parent) {
-		if (parent instanceof TreeParent)
-			return ((TreeParent)parent).hasChildren();
-		return false;
-	}
-	}
-
-	
-	private TreeObject createDummyModel() {
-        TreeObject to1 = new TreeObject("Inbox");
-        TreeObject to2 = new TreeObject("Drafts");
-        TreeObject to3 = new TreeObject("Sent");
-        TreeParent p1 = new TreeParent("me@this.com");
-        p1.addChild(to1);
-        p1.addChild(to2);
-        p1.addChild(to3);
-
-        TreeObject to4 = new TreeObject("Inbox");
-        TreeParent p2 = new TreeParent("other@aol.com");
-        p2.addChild(to4);
-
-        TreeParent root = new TreeParent("");
-        root.addChild(p1);
-        root.addChild(p2);
-        return root;
-    }
-	
-	private void createDropSupport() {
-        int operations = DND.DROP_MOVE;
-        Transfer[] transferTypes = new Transfer[] {
-                SelectionTransfer.getInstance()};
-        
-        //System.out.println("drop support ... ");
-        
-        //drop support for adding ontology from Ontology Navigator
-        viewer.addDropSupport(operations, transferTypes,
-                new ViewerDropAdapter(viewer){
-        		//new PluginDropAdapter(viewer){
-                     //@Override
-                     public boolean performDrop(Object data) {
-                    	 System.out.println("check 1 ...");
-                         if (data instanceof IStructuredSelection) {
-                        	 System.out.println("check 2 ...");
-                             Object[] elems = ((IStructuredSelection) data).toArray();
-                             for (int i = 0; i < elems.length; i++) {
-                                 if (elems[i] instanceof TreeItem) {
-                                     TreeItem ti = (TreeItem) elems[i];
-                                     System.out.println("reading tree ...");
-                                     if (ti.getData() instanceof ModuleTreeElement) {
-                                    	 
-                                         ModuleTreeElement modElement = (ModuleTreeElement) ti.getData();
-                                         //NavigationView target = (NavigationView)getCurrentTarget();
-                                         //if (target == null){
-                                        	 //target = (NavigationView) viewer;
-                                        	 //target = (NavigationView)getViewer().getInput();
-                                        	 //System.out.println("current viewer null ");
-                                         //}
-                                         //else System.out.println("current viewer non null ");
-                                         System.out.println("Set Element");
-                                         viewer.setInput(modElement);
-                                         //System.out.println("Id=" + modElement.getModuleId());
-                                         //TreeObject root = new TreeObject(modElement);
-                                         //viewer.setInput(createDummyModel());
-                                         //viewer.add(target, modElement);
-                                         //viewer.reveal(modElement);
-                                         //return true;
-                                     }
-                                 }
-                             }
-                         }
-                        return false;
-                     }
-                     
-                     //@Override
-                     public boolean validateDrop(Object target, int operation, TransferData transferType) {
-                        // check for Drop from Ontology Navigator
-                        if (SelectionTransfer.getInstance().isSupportedType(transferType)) {
-                            this.setFeedbackEnabled(false);
-                            System.out.println(" dropped ok ");
-                            return true;
-                        }
-                        
-                        System.out.println("no drop ");
-                        
-                        return false;
-                     }
-                });
-
-    }
-	/**
-	 * Passing the focus request to the viewer's control.
-	 */
-	public void setFocus() {
-		viewer.getControl().setFocus();
-	}
-}
diff --git a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java
index edf7480b..d4d82198 100755
--- a/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java
+++ b/plugins/neon/src/fr/inrialpes/exmo/align/plugin/neontk/OfflineAlign.java
@@ -42,7 +42,7 @@ import org.semanticweb.owl.align.Parameters;
 //import com.ontoprise.api.formatting.OntoBrokerOntologyFileFormat;
 //import com.ontoprise.config.IConfig;
 //import com.ontoprise.config.IConfig.OntologyLanguage;
-import com.ontoprise.ontostudio.io.ImportExportControl;
+//import com.ontoprise.ontostudio.io.ImportExportControl;
 
 import fr.inrialpes.exmo.align.impl.BasicParameters;
 import fr.inrialpes.exmo.align.onto.OntologyCache;
@@ -65,7 +65,7 @@ public class OfflineAlign {
    String matchAndExportAlign (String method, String proj1, String selectedNeOnOnto1, String proj2, String selectedNeOnOnto2) {	 
 	  
 	  //export ontologies
-      ImportExportControl ieControl = new ImportExportControl();
+      //ImportExportControl ieControl = new ImportExportControl();
       //Integer name1 = new Integer(AlignView.alignId++);  
 	  //Integer name2 = new Integer(AlignView.alignId++);
 	  //File f1 = new File( selectedNeOnOnto1.replace("file:","") );
-- 
GitLab