From: <mg...@us...> - 2007-07-24 21:53:08
|
Revision: 769 http://svn.sourceforge.net/obo/?rev=769&view=rev Author: mgibson Date: 2007-07-24 14:53:06 -0700 (Tue, 24 Jul 2007) Log Message: ----------- group adapter is now configurable with group_adapter="phenote.dataadapter.AllFieldsGroupAdapter" or some other group adapter in the group config Modified Paths: -------------- phenote/trunk/src/java/phenote/config/Config.java phenote/trunk/src/java/phenote/dataadapter/AllFieldsGroupAdapter.java phenote/trunk/src/java/phenote/gui/field/FieldPanel.java phenote/trunk/src/java/phenote/main/Phenote.java Added Paths: ----------- phenote/trunk/src/java/phenote/dataadapter/GroupAdapterI.java Modified: phenote/trunk/src/java/phenote/config/Config.java =================================================================== --- phenote/trunk/src/java/phenote/config/Config.java 2007-07-23 19:56:24 UTC (rev 768) +++ phenote/trunk/src/java/phenote/config/Config.java 2007-07-24 21:53:06 UTC (rev 769) @@ -8,11 +8,13 @@ import java.io.InputStream; import java.io.LineNumberReader; import java.io.PrintStream; +import java.lang.reflect.Constructor; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.log4j.Logger; import org.apache.xmlbeans.XmlException; import phenote.config.xml.PhenoteConfigurationDocument; @@ -29,8 +31,10 @@ import phenote.config.xml.UpdateTimerDocument.UpdateTimer; import phenote.config.xml.UvicGraphDocument.UvicGraph; import phenote.dataadapter.DataAdapterI; +import phenote.dataadapter.GroupAdapterI; import phenote.dataadapter.QueryableDataAdapterI; import phenote.datamodel.CharField; +import phenote.datamodel.OntologyManager; import phenote.gui.SearchFilterType; import phenote.gui.SearchParams; import phenote.main.PhenoteVersion; @@ -49,7 +53,7 @@ private List<FieldConfig> enabledFields = new ArrayList<FieldConfig>(); /** enabled & disabled */ private List<FieldConfig> allFields = new ArrayList<FieldConfig>(); - private static final String defaultLogConfigFile = "conf/log4j-standalone.xml"; + public static final String defaultLogConfigFile = "conf/log4j-standalone.xml"; // maybe should be using xmlbean where possible? //private boolean uvicGraphEnabled = false; // default false for now //private boolean termHistoryEnabled = false; //default to false for now @@ -1108,30 +1112,71 @@ return fCfgs; } + /** Returns null if group w groupName doesnt exist */ public String getTitleForGroup(String groupName) { + Group g = getGroup(groupName); + if (g == null) return null; + return g.getTitle(); + } + + /** Returns xmlbean Group for groupName, returns null if no such group + should it create group for "default" if it doesnt exist - i think so - just + have to make sure not creating 2 defaults */ + private Group getGroup(String groupName) { + if (groupName == null) return getDefaultGroup(); for (Group aGroup : this.phenoConfigBean.getGroupArray()) { if (aGroup.getName().equals(groupName)) { - return aGroup.getTitle(); + return aGroup; } } - return null; + if (groupName.equals(OntologyManager.DEFAULT_GROUP)) // OntMan? + return createDefaultGroup(); // ?? + //return null; // ex? return default? + return getDefaultGroup(); // if all fails just return default?? or null?? } -} -// if (overwrite || mode.equals("WIPEOUT_ALWAYS")) -// wipeoutAlways = true; -// else -// updateWithNewVersion = true; // for now -// private File getMyPhenoteCfgFile() { -// return new File(FileUtil.getDotPhenoteDir(),"my-phenote.cfg"); -// } + public Group getDefaultGroup() { + return getGroup(OntologyManager.DEFAULT_GROUP); + } - //File dotPhenote = FileUtil.getDotPhenoteDir(); - // this wont work with merging/updating - //File myPhenote = new File(dotPhenote,"my-phenote.cfg"); - //} catch (FileNotFoundException e) {throw new ConfigException(e);} - //return dotConfFile.toString(); // ? - //parseXmlFile("./conf/initial-flybase.cfg"); // hardwired for now... - //private FieldConfig lumpConfig = new FieldConfig(CharFieldEnum.LUMP,"Genotype"); - //private String lumpOntologyFile = null; private OntologyConfig lumpConfig = new OntologyConfig("Genotype"); + private Group createDefaultGroup() { + Group g = phenoConfigBean.addNewGroup(); + g.setName(OntologyManager.DEFAULT_GROUP); + return g; + } + public boolean hasGroupAdapter(String group) { + return getGroupAdapter(group) != null; + //getGroup(group).getGroupAdapter() != null; + } + + /** returns null if group adapter for group not found - ex? */ + public GroupAdapterI getGroupAdapter(String group) { + String classString = getGroup(group).getGroupAdapter(); + if (classString == null) return null; + try { + // should we cache in hash and insure 1 instance??? + Class c = Class.forName(classString); + Constructor cr = c.getConstructor(String.class); + Object o = cr.newInstance(group); + if (!(o instanceof GroupAdapterI)) { + log().error("group_adapter cfg is not a GroupAdapterI "+classString); + return null; + } + return (GroupAdapterI)o; + } + catch (Exception e) { + log().error("Unable to find group adapter for "+classString+"\n"+e); + e.printStackTrace(); + return null; + } + } + + private Logger log; + private Logger log() { + if (log == null) log = Logger.getLogger(getClass()); + return log; + } + +} + Modified: phenote/trunk/src/java/phenote/dataadapter/AllFieldsGroupAdapter.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/AllFieldsGroupAdapter.java 2007-07-23 19:56:24 UTC (rev 768) +++ phenote/trunk/src/java/phenote/dataadapter/AllFieldsGroupAdapter.java 2007-07-24 21:53:06 UTC (rev 769) @@ -17,7 +17,7 @@ import phenote.edit.CharChangeEvent; import phenote.edit.CharChangeListener; -public class AllFieldsGroupAdapter { // implements GroupAdapterI? +public class AllFieldsGroupAdapter implements GroupAdapterI { private CharChangeListener charListener = new AllCharChangeListener(); private String group = "genotypeMaker"; // hardwire for now for testing @@ -28,6 +28,8 @@ namespace = new Namespace(group); } + public boolean hasCharChangeListener() { return true; } + public CharChangeListener getCharChangeListener() { return charListener; } Added: phenote/trunk/src/java/phenote/dataadapter/GroupAdapterI.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/GroupAdapterI.java (rev 0) +++ phenote/trunk/src/java/phenote/dataadapter/GroupAdapterI.java 2007-07-24 21:53:06 UTC (rev 769) @@ -0,0 +1,10 @@ +package phenote.dataadapter; + +import phenote.edit.CharChangeListener; + +public interface GroupAdapterI { + + boolean hasCharChangeListener(); + CharChangeListener getCharChangeListener(); + +} Modified: phenote/trunk/src/java/phenote/gui/field/FieldPanel.java =================================================================== --- phenote/trunk/src/java/phenote/gui/field/FieldPanel.java 2007-07-23 19:56:24 UTC (rev 768) +++ phenote/trunk/src/java/phenote/gui/field/FieldPanel.java 2007-07-24 21:53:06 UTC (rev 769) @@ -14,9 +14,12 @@ import javax.swing.JPanel; import javax.swing.JTabbedPane; +import phenote.config.Config; +import phenote.config.xml.GroupDocument.Group; import phenote.datamodel.CharField; import phenote.datamodel.OntologyManager; import phenote.edit.EditManager; +import phenote.dataadapter.GroupAdapterI; import phenote.gui.selection.SelectionManager; /** @@ -47,6 +50,7 @@ // this(doAllFields, addSearchPanel, null, SelectionManager.inst(), EditManager.inst()); // } + // Group or String for group? public FieldPanel(boolean doAllFields, boolean addSearchPanel, String grp) { setGroup(grp); init(doAllFields,addSearchPanel,group,SelectionManager.getSelMan(group), @@ -75,10 +79,15 @@ if (addSearchPanel) initSearchPanel(); - // if haveGroupAdapter() && groupAdapter.hasCharChangeListener? - // editManager.addCharChangeListener(groupAdapter.getCharChangeListener()) - // testing out... - //editManager.addCharChangeListener(new phenote.dataadapter.AllFieldsGroupAdapter("genotypeMaker").getCharChangeListener()); + // should there be a GroupConfig object? + if (Config.inst().hasGroupAdapter(group)) { + GroupAdapterI groupAdap = Config.inst().getGroupAdapter(group); + if (groupAdap.hasCharChangeListener()) { + editManager.addCharChangeListener(groupAdap.getCharChangeListener()); + // testing out... + //editManager.addCharChangeListener(new phenote.dataadapter.AllFieldsGroupAdapter("genotypeMaker").getCharChangeListener()); + } + } } private void setGroup(String g) { Modified: phenote/trunk/src/java/phenote/main/Phenote.java =================================================================== --- phenote/trunk/src/java/phenote/main/Phenote.java 2007-07-23 19:56:24 UTC (rev 768) +++ phenote/trunk/src/java/phenote/main/Phenote.java 2007-07-24 21:53:06 UTC (rev 769) @@ -10,6 +10,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.FileNotFoundException; +import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -65,6 +66,16 @@ public static void main(String[] args) { standalone = true; // i think this is ok + // set up logging with default logger until we read in log file from + // config file + try { + URL u = FileUtil.findUrl(Config.defaultLogConfigFile); + DOMConfigurator.configure(u); + } + catch (FileNotFoundException e) { + System.out.println("Default log cfg file not found "+e); + } + System.out.println("This is Phenote version "+PhenoteVersion.versionString()); // default mac look & feel is "Mac OS X", but the JComboBox is buggy try { @@ -242,12 +253,13 @@ // this may be changed to applet... frame = new JFrame("Phenote "+PhenoteVersion.versionString()); if (getNumGroupTabs() < 2) { - frame.getContentPane().add(makeGroupPanel(OntologyManager.DEFAULT_GROUP)); + Group g = Config.inst().getDefaultGroup(); + frame.getContentPane().add(makeGroupPanel(g)); } else { JTabbedPane tabbedGroups = new JTabbedPane(); for (Group g : getGroupTabs()) { - JPanel p = makeGroupPanel(g.getName()); + JPanel p = makeGroupPanel(g); //.getName()); tabbedGroups.add(g.getTitle(),p); } frame.getContentPane().add(tabbedGroups); @@ -297,17 +309,18 @@ /** main panel contains FieldPanel CharTablePanel & TermInfo move this to gui? */ - private JPanel makeGroupPanel(String group) { + private JPanel makeGroupPanel(Group group) { JPanel mainPanel = new JPanel(new GridLayout()); JPanel infoHistoryPanel = new JPanel(new GridBagLayout()); infoHistoryPanel.setBorder(new EmptyBorder(10,10,10,10)); // need to do different selection & edit mgrs - FieldPanel groupFieldPanel = new FieldPanel(true,false,group); + FieldPanel groupFieldPanel = new FieldPanel(true,false,group.getName()); groupFieldPanel.setBorder(new EmptyBorder(10,10,10,10)); // for testing - thats it - if (group == null || group.equals("default")) mainFieldPanel = groupFieldPanel; + if (group == null || group.getName().equals("default")) + mainFieldPanel = groupFieldPanel; termInfo = new TermInfo(); GridBagConstraints ugbc = GridBagUtil.makeFillingConstraint(0,0); @@ -321,7 +334,7 @@ JSplitPane innerSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, groupFieldPanel, infoHistoryPanel); - characterTablePanel = new CharacterTablePanel(group); + characterTablePanel = new CharacterTablePanel(group.getName()); JSplitPane outerSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, innerSplitPane, characterTablePanel); mainPanel.add(outerSplitPane); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |