Author: tchemit Date: 2008-01-22 06:07:33 +0000 (Tue, 22 Jan 2008) New Revision: 384 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangeSizorAction.java Log: action de chnagement de nombre de r?\195?\169sultats ok Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangeSizorAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangeSizorAction.java 2008-01-22 06:04:17 UTC (rev 383) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/pagination/ChangeSizorAction.java 2008-01-22 06:07:33 UTC (rev 384) @@ -18,9 +18,17 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.action.pagination; +import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; +import fr.cemagref.simexplorer.is.service.StorageService; +import fr.cemagref.simexplorer.is.ui.SimExplorer; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTab; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerUI; 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; @@ -42,8 +50,7 @@ public class ChangeSizorAction extends SimExplorerAbstractTabAction { private static final long serialVersionUID = 5137512273375524199L; - protected int selectedIndex; - protected int newIndex; + protected Integer newWidth; public ChangeSizorAction(String name) { super(name, null); @@ -51,31 +58,69 @@ @Override protected boolean beforeAction(ActionEvent e) throws Exception { - super.beforeAction(e); - newIndex = getComboBox().getSelectedIndex(); - return getComboBox().isEnabled() && newIndex != selectedIndex; + + ListTabModel model = (ListTabModel) getModel(); + JComboBox jComboBox = getComboBox(); + + if (!jComboBox.isEnabled()) { + return false; + } + + Integer oldIndex = model.getPagination().getWidth(); + newWidth = Integer.valueOf(jComboBox.getSelectedItem() + ""); + return !oldIndex.equals(newWidth); } @Override protected void doAction(ActionEvent e) throws Exception { - super.doAction(e); - // deal with PaginationBean and ListApplicationBean + final ListTabModel model = (ListTabModel) getModel(); + final PaginationModel pagination = model.getPagination(); + int oldWidth = pagination.getWidth(); + MetaDataEntity[] data; + + if (oldWidth > newWidth || model.size() > newWidth) { + // just cut the data in the table model, don't touch the list + data = new MetaDataEntity[newWidth]; + System.arraycopy(model.getList(), 0, data, 0, newWidth); + + } else { + // need ask service more data + long firstIndex = pagination.getFirstIndex() + oldWidth; + int size = newWidth - oldWidth; + StorageService service; + service = getTab() == SimExplorerTab.local ? SimExplorer.getStorageService() : SimExplorer.getRemoteStorageService(); + MetaDataEntity[] newData; + newData = service.findApplications(false, (int) firstIndex, size, -1); + data = new MetaDataEntity[oldWidth + newData.length]; + System.arraycopy(model.getList(), 0, data, 0, oldWidth); + System.arraycopy(newData, 0, data, oldWidth, newData.length); + + // save in model + model.setList(data); + } + + // save in TableModel + JApplicationListTab container = (JApplicationListTab) getUI(); + JApplicationTable jApplicationTable = container.getTable(); + JApplicationTableModel modelTab = (JApplicationTableModel) jApplicationTable.getModel(); + modelTab.setData(data); + + // save new width in model + pagination.setWidth(newWidth); + + // refresh ui + getMainUI().refreshListTabUI(model, container); } @Override - protected void afterAction(ActionEvent e) throws Exception { - super.afterAction(e); - selectedIndex = newIndex; + protected void clear() { + setTab(null); + newWidth = null; } protected JComboBox getComboBox() { - return (JComboBox) ((JAXXObject) getTab()).getObjectById((String) getValue(Action.ACTION_COMMAND_KEY)); + return (JComboBox) getUIObject((String) getValue(Action.ACTION_COMMAND_KEY)); } - - @Override - public String toString() { - return super.toString() + " oldIndex:" + selectedIndex + ", newIndex:" + newIndex; - } } \ No newline at end of file