Author: tchemit Date: 2008-01-22 07:34:12 +0000 (Tue, 22 Jan 2008) New Revision: 395 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangePageAction.java Log: action change page ok Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangePageAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangePageAction.java 2008-01-22 07:33:24 UTC (rev 394) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangePageAction.java 2008-01-22 07:34:12 UTC (rev 395) @@ -18,9 +18,13 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.action.pagination; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerUI; +import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; import fr.cemagref.simexplorer.is.ui.swing.action.SimExplorerAbstractTabAction; -import jaxx.runtime.JAXXObject; +import fr.cemagref.simexplorer.is.ui.swing.model.JApplicationTableModel; +import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.PaginationModel; +import fr.cemagref.simexplorer.is.ui.swing.panel.JApplicationTable; +import fr.cemagref.simexplorer.is.ui.swing.tab.JApplicationListTab; import javax.swing.Action; import javax.swing.JComboBox; @@ -33,7 +37,6 @@ */ @jaxx.runtime.builder.SelectActionConfig( actionCommand = "goPage", - container = SimExplorerUI.class, name = "simexplorer.action.pagination.goPage", shortDescription = "simexplorer.action.pagination.goPage.tooltip", longDescription = "simexplorer.action.pagination.goPage.help", @@ -43,39 +46,67 @@ private static final long serialVersionUID = 448524625085364914L; - protected int selectedIndex; - protected int newIndex; + protected Integer newPage; public ChangePageAction(String name) { super(name, null); } @Override - public String toString() { - return super.toString() + " oldIndex:" + selectedIndex + ", newIndex:" + newIndex; - } + protected boolean beforeAction(ActionEvent e) throws Exception { + JComboBox jComboBox = getComboBox(); + if (!jComboBox.isEnabled()) { + return false; + } + ListTabModel model = (ListTabModel) getModel(); + Integer oldPage = model.getPagination().getCurrentPage(); + Object o = jComboBox.getSelectedItem(); + if (o != null) { + newPage = Integer.valueOf(o + ""); + } - @Override - protected boolean beforeAction(ActionEvent e) throws Exception { - super.beforeAction(e); - newIndex = getComboBox().getSelectedIndex(); - return newIndex != selectedIndex; + return !oldPage.equals(newPage); } @Override protected void doAction(ActionEvent e) throws Exception { + // user ask to change page + final ListTabModel model = (ListTabModel) getModel(); + final PaginationModel pagination = model.getPagination(); - super.doAction(e); - // deal with PaginationBean and ListApplicationBean + MetaDataEntity[] data; + int width = pagination.getWidth(); + long newFirstIndex = newPage * width; + + //long newLastIndex = newFirstIndex + width; + //long oldFirstindex = pagination.getFirstIndex(); + //long oldLastIndex = oldFirstindex + model.size(); + + //TODO optimiser l'algo + data = getData(false,width, newFirstIndex,-1); + + // save in model + model.setList(data); + + JApplicationListTab container = (JApplicationListTab) getUI(); + JApplicationTable jApplicationTable = container.getTable(); + JApplicationTableModel modelTab = (JApplicationTableModel) jApplicationTable.getModel(); + modelTab.setData(data); + + // save new firstIndex in model + pagination.setFirstIndex(newFirstIndex); + + // refresh ui + getMainUI().refreshListTabUI(model, container); } @Override - protected void afterAction(ActionEvent e) throws Exception { - super.afterAction(e); - selectedIndex = newIndex; + protected void clear() { + setTab(null); + newPage = null; } protected JComboBox getComboBox() { - return (JComboBox) ((JAXXObject) getTab()).getObjectById((String) getValue(Action.ACTION_COMMAND_KEY)); + return (JComboBox) getUIObject((String) getValue(Action.ACTION_COMMAND_KEY)); } } \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org