From: <ba...@us...> - 2008-11-04 15:13:24
|
Revision: 2200 http://obo.svn.sourceforge.net/obo/?rev=2200&view=rev Author: balhoff Date: 2008-11-04 15:13:14 +0000 (Tue, 04 Nov 2008) Log Message: ----------- Other phenotypes of the same state are now checked for a previously entered entity, before copying one from another state for that character. Modified Paths: -------------- phenex/trunk/src/org/phenoscape/view/PhenotypeTableComponent.java Modified: phenex/trunk/src/org/phenoscape/view/PhenotypeTableComponent.java =================================================================== --- phenex/trunk/src/org/phenoscape/view/PhenotypeTableComponent.java 2008-11-04 02:39:46 UTC (rev 2199) +++ phenex/trunk/src/org/phenoscape/view/PhenotypeTableComponent.java 2008-11-04 15:13:14 UTC (rev 2200) @@ -42,286 +42,295 @@ public class PhenotypeTableComponent extends PhenoscapeGUIComponent { - private JButton addPhenotypeButton; - private JButton deletePhenotypeButton; - private PopupListener tablePopup; - private PhenotypesTableFormat tableFormat; - private JTable phenotypesTable; - - public PhenotypeTableComponent(String id, PhenoscapeController controller) { - super(id, controller); - } - - @Override - public void init() { - super.init(); - this.initializeInterface(); - } + private JButton addPhenotypeButton; + private JButton deletePhenotypeButton; + private PopupListener tablePopup; + private PhenotypesTableFormat tableFormat; + private JTable phenotypesTable; - private void initializeInterface() { - this.setLayout(new BorderLayout()); - this.tableFormat = new PhenotypesTableFormat(); - final EventTableModel<Phenotype> phenotypesTableModel = new EventTableModel<Phenotype>(this.getController().getPhenotypesForCurrentStateSelection(), this.tableFormat); - this.phenotypesTable = new BugWorkaroundTable(phenotypesTableModel); - this.phenotypesTable.setSelectionModel(this.getController().getCurrentPhenotypesSelectionModel()); - this.phenotypesTable.setDefaultRenderer(Object.class, new PlaceholderRenderer("None")); - this.phenotypesTable.setDefaultRenderer(OBOObject.class, new TermRenderer("None")); - for (int i = 0; i < this.phenotypesTable.getColumnCount(); i++) { - final TableCellEditor editor = this.tableFormat.getColumnEditor(i); - if (editor != null) { this.phenotypesTable.getColumnModel().getColumn(i).setCellEditor(editor); } + public PhenotypeTableComponent(String id, PhenoscapeController controller) { + super(id, controller); } - this.phenotypesTable.putClientProperty("Quaqua.Table.style", "striped"); - new TableColumnPrefsSaver(this.phenotypesTable, this.getClass().getName()); - this.tablePopup = new PopupListener(this.createTablePopupMenu()); - this.phenotypesTable.addMouseListener(this.tablePopup); - final TableComparatorChooser<Phenotype> sortChooser = new TableComparatorChooser<Phenotype>(this.phenotypesTable, this.getController().getPhenotypesForCurrentStateSelection(), false); - sortChooser.addSortActionListener(new SortDisabler()); - this.add(new JScrollPane(this.phenotypesTable), BorderLayout.CENTER); - this.add(this.createToolBar(), BorderLayout.NORTH); - this.getController().getCurrentStatesSelectionModel().addListSelectionListener(new StateSelectionListener()); - this.getController().getCurrentPhenotypesSelectionModel().addListSelectionListener(new PhenotypeSelectionListener()); - } - - private void addPhenotype() { - final State state = this.getSelectedState(); - if (state != null) { - final Phenotype phenotype = state.newPhenotype(); - phenotype.setEntity(this.getAutofillEntity()); + + @Override + public void init() { + super.init(); + this.initializeInterface(); } - } - - private OBOClass getAutofillEntity() { - for (State state : this.getController().getStatesForCurrentCharacterSelection()) { - for (Phenotype phenotype : state.getPhenotypes()) { - if (phenotype.getEntity() != null) { - return phenotype.getEntity(); + + private void initializeInterface() { + this.setLayout(new BorderLayout()); + this.tableFormat = new PhenotypesTableFormat(); + final EventTableModel<Phenotype> phenotypesTableModel = new EventTableModel<Phenotype>(this.getController().getPhenotypesForCurrentStateSelection(), this.tableFormat); + this.phenotypesTable = new BugWorkaroundTable(phenotypesTableModel); + this.phenotypesTable.setSelectionModel(this.getController().getCurrentPhenotypesSelectionModel()); + this.phenotypesTable.setDefaultRenderer(Object.class, new PlaceholderRenderer("None")); + this.phenotypesTable.setDefaultRenderer(OBOObject.class, new TermRenderer("None")); + for (int i = 0; i < this.phenotypesTable.getColumnCount(); i++) { + final TableCellEditor editor = this.tableFormat.getColumnEditor(i); + if (editor != null) { this.phenotypesTable.getColumnModel().getColumn(i).setCellEditor(editor); } } - } + this.phenotypesTable.putClientProperty("Quaqua.Table.style", "striped"); + new TableColumnPrefsSaver(this.phenotypesTable, this.getClass().getName()); + this.tablePopup = new PopupListener(this.createTablePopupMenu()); + this.phenotypesTable.addMouseListener(this.tablePopup); + final TableComparatorChooser<Phenotype> sortChooser = new TableComparatorChooser<Phenotype>(this.phenotypesTable, this.getController().getPhenotypesForCurrentStateSelection(), false); + sortChooser.addSortActionListener(new SortDisabler()); + this.add(new JScrollPane(this.phenotypesTable), BorderLayout.CENTER); + this.add(this.createToolBar(), BorderLayout.NORTH); + this.getController().getCurrentStatesSelectionModel().addListSelectionListener(new StateSelectionListener()); + this.getController().getCurrentPhenotypesSelectionModel().addListSelectionListener(new PhenotypeSelectionListener()); } - return null; - } - - private void deleteSelectedPhenotype() { - final State state = this.getSelectedState(); - if (state != null) { - final Phenotype phenotype = this.getSelectedPhenotype(); - if (phenotype != null) { state.removePhenotype(phenotype); } + + private void addPhenotype() { + final State state = this.getSelectedState(); + if (state != null) { + final Phenotype phenotype = state.newPhenotype(); + phenotype.setEntity(this.getAutofillEntity()); + } } - } - - private State getSelectedState() { - final EventList<State> selected = this.getController().getCurrentStatesSelectionModel().getSelected(); - if (selected.size() == 1) { - return selected.get(0); - } else { - return null; + + private OBOClass getAutofillEntity() { + //check current state + for (State state : this.getController().getCurrentStatesSelectionModel().getSelected()) { + for (Phenotype phenotype : state.getPhenotypes()) { + if (phenotype.getEntity() != null) { + return phenotype.getEntity(); + } + } + } + //then check all states + for (State state : this.getController().getStatesForCurrentCharacterSelection()) { + for (Phenotype phenotype : state.getPhenotypes()) { + if (phenotype.getEntity() != null) { + return phenotype.getEntity(); + } + } + } + return null; } - } - - private Phenotype getSelectedPhenotype() { - final EventList<Phenotype> selected = this.getController().getCurrentPhenotypesSelectionModel().getSelected(); - if (selected.size() == 1) { - return selected.get(0); - } else { - return null; + + private void deleteSelectedPhenotype() { + final State state = this.getSelectedState(); + if (state != null) { + final Phenotype phenotype = this.getSelectedPhenotype(); + if (phenotype != null) { state.removePhenotype(phenotype); } + } } - } - - private void stateSelectionDidChange() { - final String unselectedTitle = "Phenotypes"; - final String selectedPrefix = "Phenotypes for State: "; - final List<State> states = this.getController().getCurrentStatesSelectionModel().getSelected(); - if (states.isEmpty()) { - this.updatePanelTitle(unselectedTitle); - } else { - this.updatePanelTitle(selectedPrefix + states.get(0)); + + private State getSelectedState() { + final EventList<State> selected = this.getController().getCurrentStatesSelectionModel().getSelected(); + if (selected.size() == 1) { + return selected.get(0); + } else { + return null; + } } - this.updateButtonStates(); - } - - private void phenotypeSelectionDidChange() { - this.updateButtonStates(); - } - - private void updateButtonStates() { - this.addPhenotypeButton.setEnabled(this.getSelectedState() != null); - this.deletePhenotypeButton.setEnabled(this.getSelectedPhenotype() != null); - } - - private void runPostCompositionForTermAtPoint(Point p) { - final int column = this.phenotypesTable.getTableHeader().columnAtPoint(p); - final int row = this.phenotypesTable.rowAtPoint(p); - if (!this.tableFormat.getColumnClass(column).equals(OBOObject.class)) return; - final Phenotype phenotype = this.getController().getPhenotypesForCurrentStateSelection().get(row); - final OBOClass term = (OBOClass)(this.tableFormat.getColumnValue(phenotype, column)); - final PostCompositionEditor pce = new PostCompositionEditor(this.getController(), this.tableFormat.getColumnTermSet(column)); - pce.setTerm(term); - final int result = pce.runPostCompositionDialog(); - if (result == JOptionPane.OK_OPTION) { - this.tableFormat.setColumnValue(phenotype, pce.getTerm(), column); + + private Phenotype getSelectedPhenotype() { + final EventList<Phenotype> selected = this.getController().getCurrentPhenotypesSelectionModel().getSelected(); + if (selected.size() == 1) { + return selected.get(0); + } else { + return null; + } } - } - private JToolBar createToolBar() { - final JToolBar toolBar = new JToolBar(); - this.addPhenotypeButton = new JButton(new AbstractAction(null, new ImageIcon(this.getClass().getResource("/org/phenoscape/view/images/list-add.png"))) { - public void actionPerformed(ActionEvent e) { - addPhenotype(); - } - }); - this.addPhenotypeButton.setToolTipText("Add Phenotype"); - toolBar.add(this.addPhenotypeButton); - this.deletePhenotypeButton = new JButton(new AbstractAction(null, new ImageIcon(this.getClass().getResource("/org/phenoscape/view/images/list-remove.png"))) { - public void actionPerformed(ActionEvent e) { - deleteSelectedPhenotype(); - } - }); - this.deletePhenotypeButton.setToolTipText("Delete Phenotype"); - toolBar.add(this.deletePhenotypeButton); - toolBar.setFloatable(false); - return toolBar; - } - - private JPopupMenu createTablePopupMenu() { - final JPopupMenu menu = new JPopupMenu(); - menu.add(new AbstractAction("Edit Post-composed Term") { - public void actionPerformed(ActionEvent e) { - runPostCompositionForTermAtPoint(tablePopup.getLocation()); - } - }); - return menu; - } - - private class PhenotypesTableFormat implements WritableTableFormat<Phenotype>, AdvancedTableFormat<Phenotype> { - - public boolean isEditable(Phenotype phenotype, int column) { - return true; + private void stateSelectionDidChange() { + final String unselectedTitle = "Phenotypes"; + final String selectedPrefix = "Phenotypes for State: "; + final List<State> states = this.getController().getCurrentStatesSelectionModel().getSelected(); + if (states.isEmpty()) { + this.updatePanelTitle(unselectedTitle); + } else { + this.updatePanelTitle(selectedPrefix + states.get(0)); + } + this.updateButtonStates(); } - public Phenotype setColumnValue(Phenotype phenotype, Object editedValue, int column) { - switch (column) { - case 0: phenotype.setEntity((OBOClass)editedValue); break; - case 1: phenotype.setQuality((OBOClass)editedValue); break; - case 2: phenotype.setRelatedEntity((OBOClass)editedValue); break; - case 3: phenotype.setCount((Integer)editedValue); break; - case 4: phenotype.setMeasurement((Float)editedValue); break; - case 5: phenotype.setUnit((OBOClass)editedValue); break; - case 6: phenotype.setComment(editedValue.toString()); break; - } - return phenotype; + private void phenotypeSelectionDidChange() { + this.updateButtonStates(); } - public int getColumnCount() { - return 7; + private void updateButtonStates() { + this.addPhenotypeButton.setEnabled(this.getSelectedState() != null); + this.deletePhenotypeButton.setEnabled(this.getSelectedPhenotype() != null); } - public String getColumnName(int column) { - switch (column) { - case 0: return "Entity"; - case 1: return "Quality"; - case 2: return "Related Entity"; - case 3: return "Count"; - case 4: return "Measurement"; - case 5: return "Unit"; - case 6: return "Comment"; - default: return null; - } + private void runPostCompositionForTermAtPoint(Point p) { + final int column = this.phenotypesTable.getTableHeader().columnAtPoint(p); + final int row = this.phenotypesTable.rowAtPoint(p); + if (!this.tableFormat.getColumnClass(column).equals(OBOObject.class)) return; + final Phenotype phenotype = this.getController().getPhenotypesForCurrentStateSelection().get(row); + final OBOClass term = (OBOClass)(this.tableFormat.getColumnValue(phenotype, column)); + final PostCompositionEditor pce = new PostCompositionEditor(this.getController(), this.tableFormat.getColumnTermSet(column)); + pce.setTerm(term); + final int result = pce.runPostCompositionDialog(); + if (result == JOptionPane.OK_OPTION) { + this.tableFormat.setColumnValue(phenotype, pce.getTerm(), column); + } } - - public TermSet getColumnTermSet(int column) { - switch (column) { - case 0: return getController().getOntologyController().getEntityTermSet(); - case 1: return getController().getOntologyController().getQualityTermSet(); - case 2: return getController().getOntologyController().getRelatedEntityTermSet(); - case 3: return null; - case 4: return null; - case 5: return getController().getOntologyController().getUnitTermSet(); - case 6: return null; - default: return null; - } + + private JToolBar createToolBar() { + final JToolBar toolBar = new JToolBar(); + this.addPhenotypeButton = new JButton(new AbstractAction(null, new ImageIcon(this.getClass().getResource("/org/phenoscape/view/images/list-add.png"))) { + public void actionPerformed(ActionEvent e) { + addPhenotype(); + } + }); + this.addPhenotypeButton.setToolTipText("Add Phenotype"); + toolBar.add(this.addPhenotypeButton); + this.deletePhenotypeButton = new JButton(new AbstractAction(null, new ImageIcon(this.getClass().getResource("/org/phenoscape/view/images/list-remove.png"))) { + public void actionPerformed(ActionEvent e) { + deleteSelectedPhenotype(); + } + }); + this.deletePhenotypeButton.setToolTipText("Delete Phenotype"); + toolBar.add(this.deletePhenotypeButton); + toolBar.setFloatable(false); + return toolBar; } - - public TableCellEditor getColumnEditor(int column) { - switch (column) { - case 0: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); - case 1: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); - case 2: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); - case 3: return null; - case 4: return null; - case 5: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); - case 6: return null; - default: return null; - } + + private JPopupMenu createTablePopupMenu() { + final JPopupMenu menu = new JPopupMenu(); + menu.add(new AbstractAction("Edit Post-composed Term") { + public void actionPerformed(ActionEvent e) { + runPostCompositionForTermAtPoint(tablePopup.getLocation()); + } + }); + return menu; } - public Object getColumnValue(Phenotype phenotype, int column) { - switch (column) { - case 0: return phenotype.getEntity(); - case 1: return phenotype.getQuality(); - case 2: return phenotype.getRelatedEntity(); - case 3: return phenotype.getCount(); - case 4: return phenotype.getMeasurement(); - case 5: return phenotype.getUnit(); - case 6: return phenotype.getComment(); - default: return null; - } + private class PhenotypesTableFormat implements WritableTableFormat<Phenotype>, AdvancedTableFormat<Phenotype> { + + public boolean isEditable(Phenotype phenotype, int column) { + return true; + } + + public Phenotype setColumnValue(Phenotype phenotype, Object editedValue, int column) { + switch (column) { + case 0: phenotype.setEntity((OBOClass)editedValue); break; + case 1: phenotype.setQuality((OBOClass)editedValue); break; + case 2: phenotype.setRelatedEntity((OBOClass)editedValue); break; + case 3: phenotype.setCount((Integer)editedValue); break; + case 4: phenotype.setMeasurement((Float)editedValue); break; + case 5: phenotype.setUnit((OBOClass)editedValue); break; + case 6: phenotype.setComment(editedValue.toString()); break; + } + return phenotype; + } + + public int getColumnCount() { + return 7; + } + + public String getColumnName(int column) { + switch (column) { + case 0: return "Entity"; + case 1: return "Quality"; + case 2: return "Related Entity"; + case 3: return "Count"; + case 4: return "Measurement"; + case 5: return "Unit"; + case 6: return "Comment"; + default: return null; + } + } + + public TermSet getColumnTermSet(int column) { + switch (column) { + case 0: return getController().getOntologyController().getEntityTermSet(); + case 1: return getController().getOntologyController().getQualityTermSet(); + case 2: return getController().getOntologyController().getRelatedEntityTermSet(); + case 3: return null; + case 4: return null; + case 5: return getController().getOntologyController().getUnitTermSet(); + case 6: return null; + default: return null; + } + } + + public TableCellEditor getColumnEditor(int column) { + switch (column) { + case 0: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); + case 1: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); + case 2: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); + case 3: return null; + case 4: return null; + case 5: return createAutocompleteEditor(this.getColumnTermSet(column).getTerms()); + case 6: return null; + default: return null; + } + } + + public Object getColumnValue(Phenotype phenotype, int column) { + switch (column) { + case 0: return phenotype.getEntity(); + case 1: return phenotype.getQuality(); + case 2: return phenotype.getRelatedEntity(); + case 3: return phenotype.getCount(); + case 4: return phenotype.getMeasurement(); + case 5: return phenotype.getUnit(); + case 6: return phenotype.getComment(); + default: return null; + } + } + + public Class<?> getColumnClass(int column) { + switch (column) { + case 0: return OBOObject.class; + case 1: return OBOObject.class; + case 2: return OBOObject.class; + case 3: return Integer.class; + case 4: return Float.class; + case 5: return OBOObject.class; + case 6: return String.class; + default: return null; + } + } + + public Comparator<?> getColumnComparator(int column) { + switch (column) { + case 0: return GlazedLists.comparableComparator(); + case 1: return GlazedLists.comparableComparator(); + case 2: return GlazedLists.comparableComparator(); + case 3: return GlazedLists.comparableComparator(); + case 4: return GlazedLists.comparableComparator(); + case 5: return GlazedLists.comparableComparator(); + case 6: return Strings.getNaturalComparator(); + default: return null; + } + } + } - public Class<?> getColumnClass(int column) { - switch (column) { - case 0: return OBOObject.class; - case 1: return OBOObject.class; - case 2: return OBOObject.class; - case 3: return Integer.class; - case 4: return Float.class; - case 5: return OBOObject.class; - case 6: return String.class; - default: return null; - } + private class StateSelectionListener implements ListSelectionListener { + + public StateSelectionListener() { + stateSelectionDidChange(); + } + + public void valueChanged(ListSelectionEvent e) { + stateSelectionDidChange(); + } + } - public Comparator<?> getColumnComparator(int column) { - switch (column) { - case 0: return GlazedLists.comparableComparator(); - case 1: return GlazedLists.comparableComparator(); - case 2: return GlazedLists.comparableComparator(); - case 3: return GlazedLists.comparableComparator(); - case 4: return GlazedLists.comparableComparator(); - case 5: return GlazedLists.comparableComparator(); - case 6: return Strings.getNaturalComparator(); - default: return null; - } + private class PhenotypeSelectionListener implements ListSelectionListener { + + public PhenotypeSelectionListener() { + phenotypeSelectionDidChange(); + } + + public void valueChanged(ListSelectionEvent e) { + phenotypeSelectionDidChange(); + } + } - - } - - private class StateSelectionListener implements ListSelectionListener { - - public StateSelectionListener() { - stateSelectionDidChange(); - } - public void valueChanged(ListSelectionEvent e) { - stateSelectionDidChange(); + @SuppressWarnings("unused") + private Logger log() { + return Logger.getLogger(this.getClass()); } - - } - - private class PhenotypeSelectionListener implements ListSelectionListener { - - public PhenotypeSelectionListener() { - phenotypeSelectionDidChange(); - } - public void valueChanged(ListSelectionEvent e) { - phenotypeSelectionDidChange(); - } - - } - - @SuppressWarnings("unused") -private Logger log() { - return Logger.getLogger(this.getClass()); - } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |