cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject svn commit: r1188633 - in /cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views: CayenneContentProvider.java CayenneDatamapFile.java CayenneLabelProvider.java CayenneProjectFile.java CayenneView.java
Date Tue, 25 Oct 2011 12:40:18 GMT
Author: dkazimirchyk
Date: Tue Oct 25 12:40:18 2011
New Revision: 1188633

URL: http://svn.apache.org/viewvc?rev=1188633&view=rev
Log:
CayenneModeler Eclipse Plugin: added datamaps to Eclipse view

Added:
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneDatamapFile.java
Modified:
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneContentProvider.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneLabelProvider.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneProjectFile.java
    cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneView.java

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneContentProvider.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneContentProvider.java?rev=1188633&r1=1188632&r2=1188633&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneContentProvider.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneContentProvider.java
Tue Oct 25 12:40:18 2011
@@ -24,6 +24,10 @@ public class CayenneContentProvider impl
 			WorkspaceProject project = (WorkspaceProject)parentElement;
 			return project.getCayenneProjects().toArray();
 		}
+		else if (parentElement instanceof CayenneProjectFile) {
+			CayenneProjectFile project = (CayenneProjectFile)parentElement;
+			return project.getDatamaps().toArray();
+		}
 		return null;
 	}
 

Added: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneDatamapFile.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneDatamapFile.java?rev=1188633&view=auto
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneDatamapFile.java
(added)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneDatamapFile.java
Tue Oct 25 12:40:18 2011
@@ -0,0 +1,31 @@
+package org.apache.cayenne.extensions.views;
+
+import java.io.File;
+
+public class CayenneDatamapFile {
+	
+	private File path;
+	private String name;
+	
+	private CayenneProjectFile parentProject;
+	
+	public CayenneDatamapFile(
+			String name, File path, CayenneProjectFile parentProject) {
+		this.name = name;
+		this.path = path;
+		this.parentProject = parentProject;
+	}
+	
+	public String getName() {
+		return name;
+	}
+	
+	public File getPath() {
+		return path;
+	}
+	
+	public CayenneProjectFile getParentProject() {
+		return parentProject;
+	}
+
+}

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneLabelProvider.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneLabelProvider.java?rev=1188633&r1=1188632&r2=1188633&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneLabelProvider.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneLabelProvider.java
Tue Oct 25 12:40:18 2011
@@ -14,9 +14,12 @@ public class CayenneLabelProvider extend
 		if (element instanceof WorkspaceProject) {
 			return ((WorkspaceProject) element).getName();
 		}
-		else {
+		else if (element instanceof CayenneProjectFile) {
 			return ((CayenneProjectFile) element).getName();
 		}
+		else {
+			return ((CayenneDatamapFile) element).getName();
+		}
 	}
 	
 	@Override

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneProjectFile.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneProjectFile.java?rev=1188633&r1=1188632&r2=1188633&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneProjectFile.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneProjectFile.java
Tue Oct 25 12:40:18 2011
@@ -1,15 +1,32 @@
 package org.apache.cayenne.extensions.views;
 
 import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
 
 public class CayenneProjectFile {
 	
+	private static Log logger = LogFactory.getLog(CayenneProjectFile.class);
+	
 	private File path;
 	private String name;
 	
+	private List<CayenneDatamapFile> datamaps;
+	private List<String> datamapNames;
+	
 	public CayenneProjectFile(String name, File path) {
 		this.name = name;
 		this.path = path;
+		this.datamapNames = getDatamapNames();
 	}
 	
 	public String getName() {
@@ -19,5 +36,72 @@ public class CayenneProjectFile {
 	public File getPath() {
 		return path;
 	}
+	
+	public List<CayenneDatamapFile> getDatamaps() {
+		if (datamaps != null) {
+			return datamaps;
+		}
+		
+		datamaps = new ArrayList<CayenneDatamapFile>();
+		List<File> datamapFiles = new ArrayList<File>();
+		getDatamapFiles(path.getParentFile(), datamapFiles);
+		
+		for (File file : datamapFiles) {
+			datamaps.add(new CayenneDatamapFile(file.getName(), file, this));
+		}
+		
+		return datamaps;
+	}
+	
+	protected void getDatamapFiles(File rootDir, List<File> results) {
+		File dir = rootDir;
+		
+		if (dir != null) {
+			FilenameFilter datamapFilter = new FilenameFilter() {
+				
+				public boolean accept(File dir, String name) {
+					return name.endsWith(".map.xml") && datamapNames.contains(name.substring(0,
name.length() - 8));
+				}
+			};
+			
+			FileFilter folderFilter = new FileFilter() {
+				
+				public boolean accept(File pathname) {
+					return pathname.isDirectory();
+				}
+			};
+			
+			for (File file : dir.listFiles(datamapFilter)) {
+				results.add(file);
+			}
+			
+			// searching in one more directory level down
+			for (File subdir : dir.listFiles(folderFilter)) {
+				for (File file : subdir.listFiles(datamapFilter)) {
+					results.add(file);
+				}
+			}
+		}
+	}
+	
+	protected List<String> getDatamapNames() {
+		List<String> datamapNames = new ArrayList<String>();
+		
+		try {
+			Document doc = DocumentBuilderFactory.newInstance()
+					.newDocumentBuilder().parse(path);
+
+			NodeList maps = doc.getElementsByTagName("map");
+
+			for (int i = 0; i < maps.getLength(); i++) {
+				datamapNames.add(
+						maps.item(i).getAttributes().getNamedItem("name").getNodeValue());
+			}
+		} catch (Exception e) {
+			logger.error(name + ": error searching for datamaps.");
+		}
+		
+		return datamapNames;
+	}
 
 }

Modified: cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneView.java
URL: http://svn.apache.org/viewvc/cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneView.java?rev=1188633&r1=1188632&r2=1188633&view=diff
==============================================================================
--- cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneView.java
(original)
+++ cayenne/sandbox/cayenne-modeler-eclipse-plugin-gsoc/src/main/java/org/apache/cayenne/extensions/views/CayenneView.java
Tue Oct 25 12:40:18 2011
@@ -32,12 +32,12 @@ public class CayenneView extends ViewPar
 				IStructuredSelection selection = (IStructuredSelection)e.getSelection();
 				Object element = selection.getFirstElement();
 				if (element instanceof CayenneProjectFile) {
-					File projFile = ((CayenneProjectFile) element).getPath();
-					if (projFile != null) {
-						String[] args = new String[] { projFile.toString() };
-						PluginMain plugin = new PluginMain(args);
-						plugin.start();
-					}
+					runModeler((CayenneProjectFile) element);
+					
+					viewer.setExpandedState(element, !viewer.getExpandedState(element));
+				}
+				else if (element instanceof CayenneDatamapFile) {
+					runModeler(((CayenneDatamapFile) element).getParentProject());
 				}
 				else {
 					viewer.setExpandedState(element, !viewer.getExpandedState(element));
@@ -47,6 +47,15 @@ public class CayenneView extends ViewPar
 		
 	}
 	
+	protected void runModeler(CayenneProjectFile project) {
+		File projFile = project.getPath();
+		if (projFile != null) {
+			String[] args = new String[] { projFile.toString() };
+			PluginMain plugin = new PluginMain(args);
+			plugin.start();
+		}
+	}
+	
 	@Override
 	public void setFocus() {
 		viewer.getControl().setFocus();



Mime
View raw message