001 package nl.cwi.sen1.visplugin.csvexport; 002 003 import nl.cwi.sen1.relationstores.types.RType; 004 import nl.cwi.sen1.relationstores.types.RTypeColumnTypes; 005 import nl.cwi.sen1.relationstores.types.rtype.Bag; 006 import nl.cwi.sen1.relationstores.types.rtype.Relation; 007 import nl.cwi.sen1.relationstores.types.rtype.Set; 008 import nl.cwi.sen1.visplugin.VisualizationPluginController; 009 import nl.cwi.sen1.visplugin.VisualizationPluginWindow; 010 import aterm.ATerm; 011 012 /** 013 * The CsvExportController class 014 * @author Chris Woolderink 015 * @author Antoine Savelkoul 016 * @date 13-03-2007 017 */ 018 public class CsvExportController extends VisualizationPluginController { 019 020 021 /**************** 022 CONSTRUCTORS 023 ****************/ 024 025 public CsvExportController() { 026 super(); 027 } 028 029 030 /**************** 031 VISUALIZATION PLUGIN CONTROLLER IMPLEMENTATION 032 ****************/ 033 034 /** 035 * Return Table visualization window 036 * @author Chris Woolderink 037 * @author Antoine Savelkoul 038 * @date 13-03-2007 039 */ 040 public VisualizationPluginWindow createWindow() { 041 CsvExportVisualizationWindow window = new CsvExportVisualizationWindow(); 042 043 return window; 044 } 045 046 047 048 /** 049 * Gets the plugin name [Table Visualization Plugin] 050 * @author Chris Woolderink 051 * @author Antoine Savelkoul 052 * @date 13-03-2007 053 */ 054 public String getPluginName(){ 055 return "CSV export"; 056 } 057 058 059 /**************** 060 TOOLBUS EVENT HANDLERS 061 ****************/ 062 063 /** 064 * Define the supported types. Not implemented 065 * because we override the isTypeSupported() 066 * function. 067 * @author Anton Lycklama 068 * @author Bas Basten 069 * @date 13-03-2007 070 */ 071 public ATerm[] getSupportedTypes() { 072 ATerm[] atermList = new ATerm[0]; 073 return atermList; 074 } 075 076 /** 077 * Check if a type is supported 078 * @param type The type to check 079 * @author Anton Lycklama 080 * @author Bas Basten 081 * @date 13-03-2007 082 */ 083 protected boolean isTypeSupported(ATerm type) { 084 RType rtype = m_factory.RTypeFromTerm(type); 085 086 boolean isBag = rtype.isBag(); 087 boolean isRelation = rtype.isRelation(); 088 boolean isSet = rtype.isSet(); 089 090 if (isRelation) { 091 Relation relation = (Relation) rtype; 092 RTypeColumnTypes columnTypes = relation.getColumnTypes(); 093 094 int numColumns = columnTypes.getLength(); 095 if (numColumns > 0) { 096 for (int i = 0; i < numColumns; i++) { 097 RType childType = columnTypes.getRTypeAt(i); 098 // We don't support complex types. 099 if (isComplexType(childType)) { 100 return false; 101 } 102 } 103 return true; 104 } 105 } 106 // Maybe we can refactor this when we have more time. 107 // The set and the bag use the same code to determine 108 // if the type is supported or not. 109 else if (isSet) { 110 Set set = (Set) rtype; 111 RType elementType = set.getElementType(); 112 // If the type is complex we don't support it, 113 // otherwise we do support it. 114 return !isComplexType(elementType); 115 } 116 else if (isBag) { 117 Bag bag = (Bag) rtype; 118 RType elementType = bag.getElementType(); 119 // If the type is complex we don't support it, 120 // otherwise we do support it. 121 return !isComplexType(elementType); 122 } 123 124 return false; 125 } 126 127 /** 128 * 129 * @param rtype The RType to be evaluated 130 * @return true if the given RType represents a complex type (not int/string) 131 * @author Anton Lycklama 132 * @author Bas Basten 133 * @date 13-03-2007 134 */ 135 private boolean isComplexType(RType rtype) { 136 boolean isBag = rtype.isBag(); 137 boolean isRelation = rtype.isRelation(); 138 boolean isSet = rtype.isSet(); 139 boolean isTuple = rtype.isTuple(); 140 141 if (isBag || isRelation || isSet || isTuple) { 142 return true; 143 } 144 145 return false; 146 } 147 }