Author: tchemit Date: 2008-02-25 21:43:05 +0000 (Mon, 25 Feb 2008) New Revision: 1238 Added: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerAbstractTabModel.java Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/PaginationModel.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/QueryModel.java Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/SearchAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/ShowTabAbstractAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/SimExplorerAbstractTabAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DetailTabModel.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTabModel.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerAbstractTabUpdater.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java Log: refactor model de tab Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportElementAction.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -27,7 +27,7 @@ import fr.cemagref.simexplorer.is.ui.swing.model.DataEntityModel; import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerAbstractTabModel; import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel; import fr.cemagref.simexplorer.is.ui.swing.ui.SimExplorerTab; import jaxx.runtime.UIHelper; @@ -108,7 +108,7 @@ } else if (tabModel instanceof ListTabModel) { ListTabModel model = (ListTabModel) getModel(); selected = model.getSelectedItem(); - } else if (tabModel instanceof SimExplorerTabModel) { + } else if (tabModel instanceof SimExplorerAbstractTabModel) { SynchronizeTabModel model = (SynchronizeTabModel) getModel(); // on doit traiter ça dans les classes étendues // car cela ne depend pas uniquement du model mais aussi de l'action Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/SearchAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/SearchAction.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/SearchAction.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -53,14 +53,14 @@ JTextField uiObject = (JTextField) getUIObject("searchText"); query = uiObject.getText(); ListTabModel model = (ListTabModel) getModel(); - return !query.isEmpty() && !query.equals(model.getQuery()); + return !query.isEmpty() && !query.equals(model.getQuery().getQuery()); } @Override protected void doAction(ActionEvent e) throws Exception { ListTabModel model = (ListTabModel) getModel(); - model.setQuery(query); + model.setSearchText(query); } @Override Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/ShowTabAbstractAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/ShowTabAbstractAction.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/ShowTabAbstractAction.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -18,7 +18,7 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.actions.util; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerAbstractTabModel; import jaxx.runtime.swing.JAXXTab; import java.awt.event.ActionEvent; @@ -28,7 +28,7 @@ * * @author chemit */ -public abstract class ShowTabAbstractAction<U extends JAXXTab, M extends SimExplorerTabModel> extends SimExplorerAbstractTabAction { +public abstract class ShowTabAbstractAction<U extends JAXXTab, M extends SimExplorerAbstractTabModel> extends SimExplorerAbstractTabAction { /** * Methode utilisée lors du premier * Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/SimExplorerAbstractTabAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/SimExplorerAbstractTabAction.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/util/SimExplorerAbstractTabAction.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -20,7 +20,7 @@ import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; import fr.cemagref.simexplorer.is.ui.swing.model.DataEntityModel; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerAbstractTabModel; import fr.cemagref.simexplorer.is.ui.swing.ui.JDetailTab; import fr.cemagref.simexplorer.is.ui.swing.ui.JSynchronizeTab; import fr.cemagref.simexplorer.is.ui.swing.ui.SimExplorerTab; @@ -118,7 +118,7 @@ return getTab().getUI(); } - public SimExplorerTabModel getModel() { + public SimExplorerAbstractTabModel getModel() { return getTab().getModel(getContext()); } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DetailTabModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DetailTabModel.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/DetailTabModel.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -32,7 +32,7 @@ * * @author chemit */ -public class DetailTabModel extends SimExplorerTabModel { +public class DetailTabModel extends SimExplorerAbstractTabModel { /** la propriété pour indiquer un changement de racine d'arbre */ public static final String ROOT_NODE_PROPERTY_CHANGED = "rootNodePropertyChanged"; Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTabModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTabModel.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/ListTabModel.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -24,12 +24,14 @@ import fr.cemagref.simexplorer.is.ui.swing.StorageServiceHelper; import jaxx.util.SimplePaginationEnum; +import java.io.Serializable; + /** - * Le model pour un Tab contenant une liste d'application + * Le model pour un Tab contenant une liste de metas * * @author chemit */ -public class ListTabModel extends SimExplorerTabModel { +public class ListTabModel extends SimExplorerAbstractTabModel { /** la propriété pour indiquer un changement de sélection de ligne dans la table */ public static final String SELECTED_ROW_PROPERTY_CHANGED = "selectedRowPropertyChanged"; @@ -40,34 +42,38 @@ /** la propriété pour indiquer un changement dans le modele de pagination */ public static final String PAGINATION_PROPERTY_CHANGED = "paginationPropertyChanged"; - protected final QueryModel queryModel; - protected final QueryModel oldQueryModel; + private static final long serialVersionUID = -3623331875470531459L; + /** le modele de requete */ + protected final QueryModel query; + + /** le modele de requete avant modification */ + protected final QueryModel oldQuery; + + /** le modele de pagination */ protected final PaginationModel pagination; + + /** le modele de pagination avant modification */ protected final PaginationModel oldPagination; + /** la liste des données */ protected MetaData[] list; + /** l'index de la donnée sélectionné dans l'ui */ protected int selectedIndex; - private static final long serialVersionUID = -3623331875470531459L; - public ListTabModel(SimExplorerContext context) { super(context); - queryModel = new QueryModel(); - oldQueryModel = new QueryModel(); + query = new QueryModel(); + oldQuery = new QueryModel(); pagination = new PaginationModel(SimplePaginationEnum._10); - oldPagination= new PaginationModel(SimplePaginationEnum._10); + oldPagination = new PaginationModel(SimplePaginationEnum._10); } public void initTabModel(boolean remote) { - reset(); - // no selection at first load synch(remote, null, null); - - // setdefault sizor from config setWidth(remote ? context.getConfig().getRemoteSizor() : context.getConfig().getLocalSizor()); } @@ -75,75 +81,99 @@ public void setSelectedIndex(int selectedIndex) { Integer oldSelectedIndex = this.selectedIndex; this.selectedIndex = selectedIndex; - if (selectedIndex!=-1) { - synch(isRemote(),get(selectedIndex)); + if (selectedIndex != -1) { + synch(isRemote(), get(selectedIndex)); } firePropertyChange(SELECTED_ROW_PROPERTY_CHANGED, oldSelectedIndex, selectedIndex); } public void setPageNumber(int pageNumber) { - getPagination().bind(oldPagination); - getPagination().setPageNumber(pageNumber); + PaginationModel newPagination = savePagination(); + newPagination.pageNumber = pageNumber; // rebuild list - rebuildList(context, false); - firePropertyChange(PAGINATION_PROPERTY_CHANGED, oldPagination, getPagination()); + rebuildList(false); + firePropertyChange(PAGINATION_PROPERTY_CHANGED, oldPagination, newPagination); } public void setWidth(SimplePaginationEnum width) { - getPagination().bind(oldPagination); - getPagination().setWidth(width); - // rebuild list - rebuildList(context, true); - firePropertyChange(PAGINATION_PROPERTY_CHANGED, oldPagination, getPagination()); - } + if (width == null) { + throw new NullPointerException("can not set a null width"); + } + PaginationModel newPagination = savePagination(); + newPagination.width = width; + //TODO should be -1 ? + newPagination.pageNumber = 0; - public void setQuery(String query) { - getQueryModel().bind(oldQueryModel); - getQueryModel().setQuery(query); // rebuild list - rebuildList(context, true); - firePropertyChange(QUERY_PROPERTY_CHANGED, oldQueryModel, getQueryModel()); + rebuildList(true); + firePropertyChange(PAGINATION_PROPERTY_CHANGED, oldPagination, newPagination); } public void reload() { - getPagination().setPageNumber(-1); - getPagination().bind(oldPagination); + PaginationModel newPagination = savePagination(); + // trick to force reload of page + // we must change the model to trigger ui, so doing this is ok + // if pageNumber was already at -1 : means no data + newPagination.pageNumber = -1; // rebuild list - rebuildList(context, true); - firePropertyChange(PAGINATION_PROPERTY_CHANGED, oldPagination, getPagination()); + rebuildList(true); + firePropertyChange(PAGINATION_PROPERTY_CHANGED, oldPagination, newPagination); } + public void setSearchText(String searchText) { + QueryModel newQuery = saveQuery(); + newQuery.searchText = searchText; + // rebuild list + rebuildList(true); + firePropertyChange(QUERY_PROPERTY_CHANGED, oldQuery, newQuery); + } + public void resetQuery() { - getQueryModel().bind(oldQueryModel); - getQueryModel().reset(); + QueryModel newQuery = saveQuery(); + newQuery.reset(); // rebuild list - rebuildList(context, true); - firePropertyChange(QUERY_PROPERTY_CHANGED, oldQueryModel, getQueryModel()); + rebuildList(true); + firePropertyChange(QUERY_PROPERTY_CHANGED, oldQuery, newQuery); } public void setOnlyLatest(boolean onlyLatest) { - getQueryModel().bind(oldQueryModel); - getQueryModel().setOnlyLatest(onlyLatest); + QueryModel newQuery = saveQuery(); + newQuery.onlyLatest = onlyLatest; // rebuild list - rebuildList(context, true); - firePropertyChange(QUERY_PROPERTY_CHANGED, oldQueryModel, getQueryModel()); + rebuildList(true); + firePropertyChange(QUERY_PROPERTY_CHANGED, oldQuery, newQuery); } public void setQuerySort(SortColumn sortColumn, boolean ascending) { - getQueryModel().bind(oldQueryModel); - getQueryModel().setOrder(sortColumn, ascending); + QueryModel newQuery = saveQuery(); + newQuery.sortColumn = sortColumn; + newQuery.sortAscending = ascending; // rebuild list - rebuildList(context, true); - firePropertyChange(QUERY_PROPERTY_CHANGED, oldQueryModel, getQueryModel()); + rebuildList(true); + firePropertyChange(QUERY_PROPERTY_CHANGED, oldQuery, newQuery); } public void setSimpleQuery(boolean simpleQuery) { - getQueryModel().bind(oldQueryModel); - getQueryModel().setSimpleQuery(simpleQuery); - firePropertyChange(QUERY_PROPERTY_CHANGED, oldQueryModel, getQueryModel()); + QueryModel newQuery = saveQuery(); + newQuery.simpleQuery = simpleQuery; + // rebuild list + rebuildList(true); + firePropertyChange(QUERY_PROPERTY_CHANGED, oldQuery, newQuery); } + protected PaginationModel savePagination() { + PaginationModel newPagination = getPagination(); + newPagination.bind(oldPagination); + return newPagination; + } + + protected QueryModel saveQuery() { + QueryModel newQuery = getQuery(); + newQuery.bind(oldQuery); + return newQuery; + } + public MetaData[] getList() { return list; } @@ -152,16 +182,16 @@ return pagination; } - public boolean hasQuery() { - return getQueryModel().hasQuery(); + public QueryModel getQuery() { + return query; } - public String getQuery() { - return getQueryModel().getQuery(); + public boolean hasQuery() { + return getQuery().hasQuery(); } - private QueryModel getQueryModel() { - return queryModel; + public boolean isEmpty() { + return list == null || list.length == 0; } @Override @@ -169,7 +199,7 @@ super.reset(); list = null; selectedIndex = -1; - queryModel.reset(); + query.reset(); pagination.reset(); } @@ -181,10 +211,6 @@ return getList()[index]; } - public boolean isEmpty() { - return list == null || list.length == 0; - } - public int size() { return isEmpty() ? 0 : list.length; } @@ -199,26 +225,25 @@ return s.substring(s.lastIndexOf(".") + 1) + "<size: " + size() + ",selectedItem:" + selectedItem + ">"; } - public void setList(MetaData[] list) { + protected void setList(MetaData[] list) { this.list = list; } - protected void rebuildList(SimExplorerContext context, boolean generatePagination) { + protected void rebuildList(boolean generatePagination) { - selectedIndex=-1; + selectedIndex = -1; PaginationModel page = getPagination(); - QueryModel query = getQueryModel(); + QueryModel query = getQuery(); // init pagination if (generatePagination) { // get size list - long size = StorageServiceHelper.getCount(context, isRemote(), query.getQuery(), query.isOnlyLatest()); + page.size = StorageServiceHelper.getCount(context, isRemote(), query.getQuery(), query.isOnlyLatest()); + //TODO should be at -1 + page.pageNumber = 0; - // init pagination - page.setSize(size); - } // init query model @@ -239,6 +264,206 @@ setList(data); } + /** + * Le modèle de pagination d'une liste + * + * @author tony + */ + public static class PaginationModel { + + /** default size of a page */ + protected SimplePaginationEnum defaultWidth; + + /** the current page number */ + protected int pageNumber; + + /** size of the total flow */ + protected long size; + + /** size of a page */ + protected SimplePaginationEnum width; + + public PaginationModel(SimplePaginationEnum defaultWidth) { + this.defaultWidth = defaultWidth; + reset(); + } + + public void reset() { + pageNumber = -1; + size = 0; + width = defaultWidth; + } + + public void bind(PaginationModel destination) { + destination.pageNumber = pageNumber; + destination.width = width; + destination.size = size; + } + + public long getFirstIndex() { + return pageNumber * getWidthInt(); + } + + public long getSize() { + return size; + } + + public SimplePaginationEnum getWidth() { + return width; + } + + public boolean hasNext() { + return size - pageNumber > getWidthInt(); + } + + public boolean hasPrevious() { + return pageNumber >= getWidthInt(); + } + + public int getCurrentPage() { + + return pageNumber; + } + + public int getNbPages() { + int anInt = getWidthInt(); + int nbPages = (int) (size / anInt); + if ((size % anInt != 0) || (nbPages == 0 && size > 0)) { + nbPages++; + } + return nbPages; + } + + public int getWidthInt() { + return width == null ? SimplePaginationEnum._10.intValue() : getWidth().intValue(); + } + + @Override + public String toString() { + String s = super.toString(); + return s.substring(s.indexOf('@')) + "<size:" + size + ", pageNumber:" + pageNumber + ", width:" + width + ", nbPages:" + getNbPages() + ">"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof PaginationModel)) return false; + PaginationModel that = (PaginationModel) o; + return pageNumber == that.pageNumber && + size == that.size && + width == that.width; + } + + @Override + public int hashCode() { + int result; + result = pageNumber; + result = 31 * result + (int) (size ^ (size >>> 32)); + result = 31 * result + width.hashCode(); + return result; + } + + } + + /** + * Le modele d'une recherche sur des loggable element. + * + * @author chemit + */ + public static class QueryModel implements Serializable { + + /** flag to detect simple text query */ + protected boolean simpleQuery; + + /** flag to get only latest version */ + protected boolean onlyLatest; + + /** flag to indicate sorting way (null for none) */ + protected boolean sortAscending; + + /** simple full text query */ + protected String searchText; + + /** query column ordering (use SortColumn.Noe if no sort) */ + protected SortColumn sortColumn; + + private static final long serialVersionUID = -5018101346037499469L; + + public QueryModel() { + // obtain default empty query + reset(); + } + + public void bind(QueryModel destination) { + destination.simpleQuery = simpleQuery; + destination.onlyLatest = onlyLatest; + destination.sortAscending = sortAscending; + destination.searchText = searchText; + destination.sortColumn = sortColumn; + } + + public void reset() { + simpleQuery = true; + onlyLatest = true; + sortAscending = true; + searchText = null; + sortColumn = SortColumn.None; + } + + public boolean hasQuery() { + return searchText != null && !searchText.isEmpty(); + } + + public boolean isSimpleQuery() { + return simpleQuery; + } + + public boolean isOnlyLatest() { + return onlyLatest; + } + + public boolean isSortAscending() { + return sortAscending; + } + + public String getQuery() { + return searchText; + } + + public SortColumn getSortColumn() { + return sortColumn; + } + + @Override + public String toString() { + String s = super.toString(); + return s.substring(s.lastIndexOf('.') + 1) + "<sortColumn:" + sortColumn + ",sortAscending:" + sortAscending + ", searchText:" + searchText + ">"; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof QueryModel)) return false; + QueryModel that = (QueryModel) o; + return onlyLatest == that.onlyLatest && + simpleQuery == that.simpleQuery && + sortAscending == that.sortAscending && + !(searchText != null ? !searchText.equals(that.searchText) : that.searchText != null) + && sortColumn == that.sortColumn; + } + + @Override + public int hashCode() { + int result; + result = (simpleQuery ? 1 : 0); + result = 31 * result + (onlyLatest ? 1 : 0); + result = 31 * result + (sortAscending ? 1 : 0); + result = 31 * result + (searchText != null ? searchText.hashCode() : 0); + result = 31 * result + sortColumn.hashCode(); + return result; + } + } + private void checkSize(int index) { if (index > -1 && (isEmpty() || size() < index)) { throw new IllegalStateException(getClass() + " has size " + size() + " and was required index " + index); Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/PaginationModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/PaginationModel.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/PaginationModel.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -1,138 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui.swing.model; - -import jaxx.util.SimplePaginationEnum; - -/** - * Le modèle de pagination d'une liste - * - * @author tony - */ -public class PaginationModel { - - /** default size of a page */ - protected SimplePaginationEnum defaultWidth; - - /** the current page number */ - protected int pageNumber; - - /** size of the total flow */ - protected long size; - - /** size of a page */ - protected SimplePaginationEnum width; - - public PaginationModel(SimplePaginationEnum defaultWidth) { - this.defaultWidth = defaultWidth; - reset(); - } - - public void reset() { - pageNumber = -1; - size = 0; - width = defaultWidth; - } - - public void bind(PaginationModel destination) { - destination.pageNumber = pageNumber; - destination.width = width; - destination.size = size; - } - - public long getFirstIndex() { - return pageNumber * getWidthInt(); - } - - public long getSize() { - return size; - } - - public SimplePaginationEnum getWidth() { - return width; - } - - public boolean hasNext() { - return size - pageNumber > getWidthInt(); - } - - public boolean hasPrevious() { - return pageNumber >= getWidthInt(); - } - - public int getCurrentPage() { - - return pageNumber; - } - - public int getNbPages() { - int anInt = getWidthInt(); - int nbPages = (int) (size / anInt); - if ((size % anInt != 0) || (nbPages == 0 && size > 0)) { - nbPages++; - } - return nbPages; - } - - public int getWidthInt() { - return width == null ? SimplePaginationEnum._10.intValue() : getWidth().intValue(); - } - - @Override - public String toString() { - String s = super.toString(); - return s.substring(s.indexOf('@')) + "<size:" + size + ", pageNumber:" + pageNumber + ", width:" + width + ", nbPages:" + getNbPages() + ">"; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof PaginationModel)) return false; - PaginationModel that = (PaginationModel) o; - return pageNumber == that.pageNumber && - size == that.size && - width == that.width; - } - - @Override - public int hashCode() { - int result; - result = pageNumber; - result = 31 * result + (int) (size ^ (size >>> 32)); - result = 31 * result + width.hashCode(); - return result; - } - - void setPageNumber(int pageNumber) { - this.pageNumber = pageNumber; - } - - void setSize(long size) { - this.size = size; - this.pageNumber = 0; - } - - void setWidth(SimplePaginationEnum width) { - if (width==null) { - throw new NullPointerException("can not set a null width"); - } - this.width = width; - this.pageNumber = 0; - } -} Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/QueryModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/QueryModel.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/QueryModel.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -1,138 +0,0 @@ -/* -* ##% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.ui.swing.model; - -import fr.cemagref.simexplorer.is.storage.SortColumn; - -import java.io.Serializable; - -/** - * Le modele d'une recherche sur des loggable element. - * - * @author chemit - */ -public class QueryModel implements Serializable { - - /** flag to detect simple text query */ - protected boolean simpleQuery; - - /** flag to get only latest version */ - protected boolean onlyLatest; - - /** flag to indicate sorting way (null for none) */ - protected boolean sortAscending; - - /** simple full text query */ - protected String query; - - /** query column ordering (use SortColumn.Noe if no sort) */ - protected SortColumn sortColumn; - - private static final long serialVersionUID = -5018101346037499469L; - - public QueryModel() { - // obtain default empty query - reset(); - } - - public void bind(QueryModel destination) { - destination.simpleQuery = simpleQuery; - destination.onlyLatest = onlyLatest; - destination.sortAscending = sortAscending; - destination.query = query; - destination.sortColumn = sortColumn; - } - - public void reset() { - simpleQuery = true; - onlyLatest = true; - sortAscending = true; - query = null; - sortColumn = SortColumn.None; - } - - public boolean hasQuery() { - return query != null && !query.isEmpty(); - } - - public boolean isSimpleQuery() { - return simpleQuery; - } - - public boolean isOnlyLatest() { - return onlyLatest; - } - - public boolean isSortAscending() { - return sortAscending; - } - - public String getQuery() { - return query; - } - - public SortColumn getSortColumn() { - return sortColumn; - } - - @Override - public String toString() { - String s = super.toString(); - return s.substring(s.lastIndexOf('.') + 1) + "<sortColumn:" + sortColumn + ",sortAscending:" + sortAscending + ", query:" + query + ">"; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof QueryModel)) return false; - QueryModel that = (QueryModel) o; - return onlyLatest == that.onlyLatest && - simpleQuery == that.simpleQuery && - sortAscending == that.sortAscending && - !(query != null ? !query.equals(that.query) : that.query != null) - && sortColumn == that.sortColumn; - } - - @Override - public int hashCode() { - int result; - result = (simpleQuery ? 1 : 0); - result = 31 * result + (onlyLatest ? 1 : 0); - result = 31 * result + (sortAscending ? 1 : 0); - result = 31 * result + (query != null ? query.hashCode() : 0); - result = 31 * result + sortColumn.hashCode(); - return result; - } - - void setOrder(SortColumn sortColumn, boolean sortAscending) { - this.sortColumn = sortColumn; - this.sortAscending = sortAscending; - } - - void setOnlyLatest(boolean onlyLatest) { - this.onlyLatest = onlyLatest; - } - - void setQuery(String query) { - this.query = query; - } - - void setSimpleQuery(boolean simpleQuery) { - this.simpleQuery = simpleQuery; - } -} Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerAbstractTabModel.java (from rev 1236, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerTabModel.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerAbstractTabModel.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerAbstractTabModel.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -0,0 +1,161 @@ +/* +* ##% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* ##% */ +package fr.cemagref.simexplorer.is.ui.swing.model; + +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; +import fr.cemagref.simexplorer.is.ui.swing.ui.SimExplorerTab; +import jaxx.runtime.builder.TabModel; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +/** + * Le model d'onglet de l'application + * + * @author chemit + * @see TabModel + * @see SimExplorerTab + */ +public abstract class SimExplorerAbstractTabModel implements TabModel { + + /** l'onglet associé au model */ + protected SimExplorerTab tab; + + /** le dernier élément sélectionné dans l'onglet */ + protected DataEntityModel selectedItem; + + /** flag pour savoir si la source est remote ou non */ + protected Boolean remote; + + protected final SimExplorerContext context; + + /** support pourles changements des propriétés */ + protected PropertyChangeSupport changeSupport; + + private static final long serialVersionUID = 4136959472154027361L; + + public SimExplorerAbstractTabModel(SimExplorerContext context) { + this.context = context; + } + + public String getName() { + return tab.name(); + } + + public boolean isRemote() { + return remote != null && remote; + } + + public void synch(EntityTreeNode node) { + this.remote = node == null ? null : node.isRemote(); + getSelectedItem().synch(node); + } + + public void synch(Boolean remote, LoggableElement selectedElement) { + this.remote = remote; + getSelectedItem().synch(remote, selectedElement); + } + + public void synch(Boolean remote, MetaData selectedMeta) { + this.remote = remote; + getSelectedItem().synch(remote, selectedMeta); + } + + public void synch(Boolean remote, String uuid, Version version) { + this.remote = remote; + getSelectedItem().synch(remote, uuid, version); + } + + public DataEntityModel getSelectedItem() { + if (selectedItem == null) { + selectedItem = new DataEntityModel(); + //selectedItem.setRemote(remote); + } + return selectedItem; + } + + public void setName(String name) { + this.tab = SimExplorerTab.valueOf(name); + } + + public void setSelectedItem(DataEntityModel selectedItem) { + this.selectedItem = selectedItem; + if (selectedItem != null) { + remote = selectedItem.isRemote(); + } + } + + public void reset() { + remote = null; + selectedItem = null; + } + + public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + if (listener == null) { + return; + } + if (changeSupport == null) { + changeSupport = new PropertyChangeSupport(this); + } + changeSupport.addPropertyChangeListener(propertyName, listener); + } + + public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { + if (listener == null) { + return; + } + if (changeSupport == null) { + changeSupport = new PropertyChangeSupport(this); + } + changeSupport.addPropertyChangeListener(listener); + } + + public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { + if (listener == null || changeSupport == null) { + return; + } + changeSupport.removePropertyChangeListener(listener); + } + + public synchronized void removePropertyChangeListeners() { + if (changeSupport == null) { + return; + } + for (PropertyChangeListener listener : getPropertyChangeListeners()) { + changeSupport.removePropertyChangeListener(listener); + } + } + + public synchronized PropertyChangeListener[] getPropertyChangeListeners() { + if (changeSupport == null) { + return new PropertyChangeListener[0]; + } + return changeSupport.getPropertyChangeListeners(); + } + + public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + if (changeSupport == null || (oldValue == null && newValue == null) || + (oldValue != null && oldValue.equals(newValue))) { + return; + } + changeSupport.firePropertyChange(propertyName, oldValue, newValue); + } +} Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -28,7 +28,7 @@ * * @author chemit */ -public class SynchronizeTabModel extends SimExplorerTabModel { +public class SynchronizeTabModel extends SimExplorerAbstractTabModel { /** la clef de l'évènement après des sources */ public static final String SOURCES_PROPERTY_CHANGED = "sourcesPropertyChanged"; Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabUpdater.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -23,8 +23,6 @@ import fr.cemagref.simexplorer.is.ui.swing.model.DataEntityModel; import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; import fr.cemagref.simexplorer.is.ui.swing.model.ListTableModel; -import fr.cemagref.simexplorer.is.ui.swing.model.PaginationModel; -import fr.cemagref.simexplorer.is.ui.swing.model.QueryModel; import javax.swing.JComboBox; import java.beans.PropertyChangeEvent; @@ -86,7 +84,7 @@ if (log.isDebugEnabled()) { log.debug(evt.getPropertyName() + "\n\told:" + evt.getOldValue() + ",\n\tnew:" + evt.getNewValue()); } - QueryModel query = (QueryModel) evt.getNewValue(); + ListTabModel.QueryModel query = (ListTabModel.QueryModel) evt.getNewValue(); if (query == null) { resetSearch(); return; @@ -111,7 +109,7 @@ log.debug(evt.getPropertyName() + "\n\told:" + evt.getOldValue() + ",\n\tnew:" + evt.getNewValue()); } - ui.getSearchText().setText(model.getQuery()); + ui.getSearchText().setText(model.getQuery().getQuery()); refreshSearchActions(); @@ -124,7 +122,7 @@ } } - protected void refreshPaginationActions(PaginationModel pagination) { + protected void refreshPaginationActions(ListTabModel.PaginationModel pagination) { JListTab ui = getUi(); JComboBox combo = ui.getGoPage(); long size = pagination.getNbPages(); Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerAbstractTabUpdater.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerAbstractTabUpdater.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerAbstractTabUpdater.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -18,7 +18,7 @@ package fr.cemagref.simexplorer.is.ui.swing.ui; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerAbstractTabModel; import jaxx.runtime.swing.JAXXTab; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,7 +30,7 @@ * * @author chemit */ -public abstract class SimExplorerAbstractTabUpdater<U extends JAXXTab, M extends SimExplorerTabModel> implements PropertyChangeListener { +public abstract class SimExplorerAbstractTabUpdater<U extends JAXXTab, M extends SimExplorerAbstractTabModel> implements PropertyChangeListener { protected static Log log = LogFactory.getLog(DetailTabUpdater.class); final protected SimExplorerContext context; protected SimExplorerTab tab; Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -20,7 +20,7 @@ import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerAbstractTabModel; import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; import jaxx.runtime.builder.TabContentConfig; @@ -127,11 +127,11 @@ return getFactory().getUI(name()); } - private SimExplorerTabModel getModel() { + private SimExplorerAbstractTabModel getModel() { return getFactory().getModel(name()); } - public SimExplorerTabModel getModel(SimExplorerContext context) { + public SimExplorerAbstractTabModel getModel(SimExplorerContext context) { return getFactory().getModel(name(),context); } Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java 2008-02-25 19:30:46 UTC (rev 1237) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java 2008-02-25 21:43:05 UTC (rev 1238) @@ -21,7 +21,7 @@ import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerAbstractTabModel; import fr.cemagref.simexplorer.is.ui.swing.ui.util.MyTabHeader; import jaxx.runtime.JAXXObject; import jaxx.runtime.builder.TabContentConfig; @@ -86,8 +86,8 @@ @Override - public SimExplorerTabModel getModel(String tabName,Object... params) { - return (SimExplorerTabModel) super.getModel(tabName,params); + public SimExplorerAbstractTabModel getModel(String tabName,Object... params) { + return (SimExplorerAbstractTabModel) super.getModel(tabName,params); } @Override
participants (1)
-
tchemit@users.labs.libre-entreprise.org