Author: mallon Date: 2012-07-10 17:03:48 +0200 (Tue, 10 Jul 2012) New Revision: 3510 Url: http://chorem.org/repositories/revision/lima/3510 Log: refs #688 R?\195?\169solution du probl?\195?\168me de choix des mod?\195?\168les ?\195?\160 la s?\195?\169lection d'une entr?\195?\169e lettr?\195?\169e ou non-lettr?\195?\169e. Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java trunk/lima-swing/src/main/resources/log4j.properties Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java 2012-07-10 11:52:09 UTC (rev 3509) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java 2012-07-10 15:03:48 UTC (rev 3510) @@ -1,15 +1,19 @@ package org.chorem.lima.ui.lettering; -import jaxx.runtime.swing.model.AbstractGenericListSelectionModel; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Entry; +import javax.swing.*; import java.util.List; /** * @author sletellier <letellier@codelutin.com> */ -public class LetteringSelectionModel extends AbstractGenericListSelectionModel<Entry> { +public class LetteringSelectionModel extends DefaultListSelectionModel { + private static final Log log = LogFactory.getLog(LetteringViewHandler.class); protected LetteringTableModel letteringTableModel; protected int lineSelected; @@ -22,42 +26,38 @@ @Override public void setSelectionInterval(int row, int column){ lineSelected = row; - super.setSelectionInterval(lineSelected, column); - //select entries with the same letter of the selected entry - for(Entry entry : getEntries()){ - if (entry.getLettering() != null && !entry.getLettering().isEmpty()){ - if (entry.getLettering().equals(getCurrentLettring())){ - int entryToSelect = letteringTableModel.getIndexOfEntry(entry); - super.addSelectionInterval(entryToSelect, entryToSelect); + String currentLettring = getCurrentLettring(); + if (log.isInfoEnabled()) { + log.info("Select line"); + } + + //FIXME allon 10-07-12 : problème de rafraichissement très long + setValueIsAdjusting(true); + super.clearSelection(); + try { + //select entries with the same letter of the selected entry + for(Entry entry : getEntries()){ + if (StringUtils.isNotBlank(entry.getLettering())){ + if (entry.getLettering().equals(currentLettring)){ + int entryToSelect = letteringTableModel.getIndexOfEntry(entry); + super.addSelectionInterval(entryToSelect, entryToSelect); + } } } + } finally { + setValueIsAdjusting(false); } } - @Override - public int getSize() { - return letteringTableModel.getRowCount(); - } - - @Override - public Entry getValueAt(int i) { - return letteringTableModel.getEntryAt(i); - } - public List<Entry> getEntries(){ return letteringTableModel.getEntries(); } - public Entry getCurrentEntrySelected(){ - return letteringTableModel.getEntryAt(lineSelected); - } - public String getCurrentLettring(){ return getCurrentEntrySelected().getLettering(); } - @Override - public int getSelectionMode() { - return SINGLE_SELECTION; + public Entry getCurrentEntrySelected(){ + return letteringTableModel.getEntryAt(lineSelected); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-07-10 11:52:09 UTC (rev 3509) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-07-10 15:03:48 UTC (rev 3510) @@ -95,14 +95,14 @@ } public Integer getIndexOfEntry(Entry entrySearch){ - Integer index = -1; - for (Entry entry : entries){ - index++; - if (entrySearch == entry){ - return index; - } - } - return null; +// Integer index = -1; +// for (Entry entry : entries){ +// index++; +// if (entrySearch == entry){ +// return index; +// } +// } + return entries.indexOf(entrySearch); } public int getNumberOfEntries(){ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2012-07-10 11:52:09 UTC (rev 3509) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2012-07-10 15:03:48 UTC (rev 3510) @@ -191,9 +191,9 @@ id="table" sortable="false" rowHeight="22" editable='true' constructorParams="getTableModel()" selectionMode="{ListSelectionModel.MULTIPLE_INTERVAL_SELECTION}" - selectionModel="{lettringAndUnlettringSelectionModel.getSelectedModel()}" + selectionModel="{lettringAndUnlettringSelectionModel}" /> </JScrollPane> </cell> - </row> + </row> </Table> \ No newline at end of file Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java 2012-07-10 11:52:09 UTC (rev 3509) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java 2012-07-10 15:03:48 UTC (rev 3510) @@ -1,84 +1,143 @@ package org.chorem.lima.ui.lettering; -import jaxx.runtime.swing.model.AbstractGenericListSelectionModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.entity.Entry; +import javax.swing.*; +import javax.swing.event.ListSelectionListener; + /** * @author sletellier <letellier@codelutin.com> */ -public class LettringAndUnlettringSelectionModel extends AbstractGenericListSelectionModel<Entry> { +public class LettringAndUnlettringSelectionModel implements ListSelectionModel { private static final Log log = LogFactory.getLog(LetteringViewHandler.class); protected LetteringSelectionModel letteringSelectionModel; protected UnlettringSelectionModel unlettringSelectionModel; protected LetteringTableModel letteringTableModel; - protected boolean modelSelected; + protected ListSelectionModel delegate; public LettringAndUnlettringSelectionModel(LetteringSelectionModel letteringSelectionModel, UnlettringSelectionModel unlettringSelectionModel, LetteringTableModel letteringTableModel) { this.letteringSelectionModel = letteringSelectionModel; this.unlettringSelectionModel = unlettringSelectionModel; this.letteringTableModel = letteringTableModel; - modelSelected = false; //By default, unLettred entries + delegate = unlettringSelectionModel; } /**choice of model : two differents ui reactions, if lettering is present or not*/ @Override public void setSelectionInterval(int row, int column) { - if (log.isInfoEnabled()) { - log.info("Selection de ligne : choix du modele"); - } - if (!letteringNotExist(row)) { - modelSelected = true; - letteringSelectionModel.setSelectionInterval(row, column); - } else { - if (log.isInfoEnabled()) { - log.info("Modele de selection utilise : 'unlettringSelectionModel'"); - } - modelSelected = false; - unlettringSelectionModel.setSelectionInterval(row, column); - } + delegate=(!letteringNotExist(row)?letteringSelectionModel:unlettringSelectionModel); + delegate.setSelectionInterval(row, column); + } /**return true if lettering is null, or not null but empty*/ public boolean letteringNotExist(int row){ boolean emptyOrNull; + String lettering = letteringTableModel.getEntryAt(row).getLettering(); + emptyOrNull = (lettering!=null?lettering.isEmpty():true); - if (lettering != null){ - emptyOrNull = lettering.isEmpty(); - }else - emptyOrNull = true; + return emptyOrNull; + } - if (log.isInfoEnabled()) { - log.info("Retour : " + emptyOrNull); - } + @Override + public void addSelectionInterval(int index0, int index1) { + delegate.addSelectionInterval(index0, index1); + } - return emptyOrNull; + @Override + public void removeSelectionInterval(int index0, int index1) { + delegate.removeSelectionInterval(index0, index1); } - /**return number of row in the model*/ @Override - public int getSize() { - return letteringTableModel.getRowCount(); + public int getMinSelectionIndex() { + return delegate.getMinSelectionIndex(); } - /**return the entry at the index indicate*/ @Override - public Entry getValueAt(int i) { - return letteringTableModel.getEntryAt(i); + public int getMaxSelectionIndex() { + return delegate.getMaxSelectionIndex(); } - public AbstractGenericListSelectionModel<Entry> getSelectedModel(){ - if (modelSelected) { - return letteringSelectionModel; - }else{ - return unlettringSelectionModel; - } + @Override + public boolean isSelectedIndex(int index) { + return delegate.isSelectedIndex(index); } + @Override + public int getAnchorSelectionIndex() { + return delegate.getAnchorSelectionIndex(); + } + + @Override + public void setAnchorSelectionIndex(int index) { + delegate.setAnchorSelectionIndex(index); + } + + @Override + public int getLeadSelectionIndex() { + return delegate.getLeadSelectionIndex(); + } + + @Override + public void setLeadSelectionIndex(int index) { + delegate.setLeadSelectionIndex(index); + } + + @Override + public void clearSelection() { + delegate.clearSelection(); + } + + @Override + public boolean isSelectionEmpty() { + return delegate.isSelectionEmpty(); + } + + @Override + public void insertIndexInterval(int index, int length, boolean before) { + delegate.insertIndexInterval(index, length, before); + } + + @Override + public void removeIndexInterval(int index0, int index1) { + delegate.removeIndexInterval(index0, index1); + } + + @Override + public void setValueIsAdjusting(boolean valueIsAdjusting) { + delegate.setValueIsAdjusting(valueIsAdjusting); + } + + @Override + public boolean getValueIsAdjusting() { + return delegate.getValueIsAdjusting(); + } + + @Override + public void setSelectionMode(int selectionMode) { + delegate.setSelectionMode(selectionMode); + } + + @Override + public int getSelectionMode() { + return delegate.getSelectionMode(); + } + + @Override + public void addListSelectionListener(ListSelectionListener x) { + delegate.addListSelectionListener(x); + } + + @Override + public void removeListSelectionListener(ListSelectionListener x) { + delegate.removeListSelectionListener(x); + } + /**clear the selection of the current using model*/ /*@Override public void clearSelection(){ Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java 2012-07-10 11:52:09 UTC (rev 3509) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java 2012-07-10 15:03:48 UTC (rev 3510) @@ -1,14 +1,13 @@ package org.chorem.lima.ui.lettering; -import jaxx.runtime.swing.model.AbstractGenericListSelectionModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.entity.Entry; +import javax.swing.*; import java.util.ArrayList; import java.util.List; -public class UnlettringSelectionModel extends AbstractGenericListSelectionModel<Entry> { +public class UnlettringSelectionModel extends DefaultListSelectionModel { private static final Log log = LogFactory.getLog(LetteringViewHandler.class); protected LetteringTableModel letteringTableModel; @@ -62,21 +61,6 @@ } @Override - public int getSize() { - return letteringTableModel.getRowCount(); - } - - @Override - public Entry getValueAt(int i) { - return letteringTableModel.getEntryAt(i); - } - - @Override - public void addSelectionInterval(int index0, int index1) { - setSelectionInterval(index0, index1); - } - - @Override public int getSelectionMode() { return MULTIPLE_INTERVAL_SELECTION; } Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-07-10 11:52:09 UTC (rev 3509) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-07-10 15:03:48 UTC (rev 3510) @@ -45,4 +45,5 @@ log4j.logger.org.chorem.lima.ui.lettering.LetteringViewHandler=DEBUG log4j.logger.org.chorem.lima.ui.lettering.LetteringTableModel=DEBUG log4j.logger.org.chorem.lima.ui.lettering.LetteringModelUi=DEBUG -log4j.logger.org.chorem.lima.ui.lettering.LettringAndUnlettringSelectionModel=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.ui.lettering.LettringAndUnlettringSelectionModel=DEBUG +log4j.logger.org.chorem.lima.ui.lettering.LetteringSelectionModel=DEBUG \ No newline at end of file
participants (1)
-
mallon@users.chorem.org