Author: tchemit Date: 2008-03-31 20:40:35 +0000 (Mon, 31 Mar 2008) New Revision: 248 Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchUIModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchVCSFileStatesModel.java Removed: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSRepositoryModel.java Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java Log: ui models Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java (from rev 245, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java) =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSFileStatesModel.java 2008-03-31 20:40:35 UTC (rev 248) @@ -0,0 +1,179 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Code Lutin, +* Benjamin Poussin, 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 org.codelutin.vcs.ui.model; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.vcs.VCSAction; +import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.VCSState; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * Simple Table model to display list of VCSFileState + * + * @author chemit + */ +public abstract class AbstractVCSFileStatesModel extends javax.swing.table.AbstractTableModel { + + protected List<VCSFileState> data; + + protected final String[] columnNames; + + private static final long serialVersionUID = 4697917831388337369L; + + protected AbstractVCSFileStatesModel(String[] columnNames) { + super(); + this.columnNames = columnNames; + } + + public List<VCSFileState> getData() { + return data; + } + + public int getColumnCount() { + return columnNames.length; + } + + public int getRowCount() { + return data == null ? 0 : data.size(); + } + + /*@Override + public Class<?> getColumnClass(int columnIndex) { + return String.class; + }*/ + + @Override + public String getColumnName(int columnIndex) { + return _(columnNames[columnIndex]); + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + // read only data + return false; + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + // read only data + } + + + public void setData(List<VCSFileState> states) { + if (data != null) { + data.clear(); + data.addAll(states); + } else { + data = new ArrayList<VCSFileState>(states); + } + fireTableDataChanged(); + } + + public void addData(VCSFileState... states) { + if (data != null) { + data.addAll(Arrays.asList(states)); + } else { + data = new ArrayList<VCSFileState>(Arrays.asList(states)); + } + fireTableDataChanged(); + } + + public void removeData(VCSFileState... states) { + if (isEmpty()) { + return; + } + data.removeAll(Arrays.asList(states)); + fireTableDataChanged(); + } + + protected boolean isEmpty() { + return data == null || data.isEmpty(); + } + + public void clear() { + if (isEmpty()) { + return; + } + data.clear(); + fireTableDataChanged(); + } + + public VCSFileState[] getData(VCSAction action) { + if (isEmpty()) { + return new VCSFileState[0]; + } + List<VCSFileState> list = new ArrayList<VCSFileState>(data); + for (Iterator<VCSFileState> it = list.iterator(); it.hasNext();) { + VCSFileState fileState = it.next(); + List<VCSAction> actions = fileState.getState().getActions(); + if (!actions.contains(action)) { + it.remove(); + } + } + return list.toArray(new VCSFileState[list.size()]); + } + + public VCSFileState[] getData(VCSState action) { + if (isEmpty()) { + return new VCSFileState[0]; + } + List<VCSFileState> list = new ArrayList<VCSFileState>(data); + for (Iterator<VCSFileState> it = list.iterator(); it.hasNext();) { + VCSFileState fileState = it.next(); + if (!action.equals(fileState.getState())) { + it.remove(); + } + } + return list.toArray(new VCSFileState[list.size()]); + } + + public VCSState[] getStates() { + if (isEmpty()) { + return new VCSState[0]; + } + List<VCSState> result = new ArrayList<VCSState>(); + for (VCSFileState vcsFileState : data) { + VCSState state = vcsFileState.getState(); + if (state != null && !result.contains(state)) { + result.add(state); + } + } + return result.toArray(new VCSState[result.size()]); + } + + public VCSAction[] getActions() { + if (isEmpty()) { + return new VCSAction[0]; + } + List<VCSAction> result = new ArrayList<VCSAction>(); + for (VCSFileState vcsFileState : data) { + VCSAction action = vcsFileState.getAction(); + if (action != null && !result.contains(action)) { + result.add(action); + } + } + return result.toArray(new VCSAction[result.size()]); + } +} \ No newline at end of file Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchUIModel.java (from rev 245, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSRepositoryModel.java) =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchUIModel.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchUIModel.java 2008-03-31 20:40:35 UTC (rev 248) @@ -0,0 +1,123 @@ +/** + * # #% Copyright (C) 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 org.codelutin.vcs.ui.model; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.VCSHandler; +import static org.codelutin.vcs.ui.VCSUIConstants.ALL_MODEL_PROPERTY; +import static org.codelutin.vcs.ui.VCSUIConstants.LOCAL_MODEL_PROPERTY; +import static org.codelutin.vcs.ui.VCSUIConstants.REMOTE_MODEL_PROPERTY; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * Model of a repository + * + * @author chemit + */ +public class SynchUIModel { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + static protected final Log log = LogFactory.getLog(SynchUIModel.class); + + /** local root : wroking copy */ + protected File localRoot; + + /** remote root : remote url */ + protected URL remoteRoot; + + /** vcs handler to use (lazy instanciation) */ + protected VCSHandler handler; + + /** map of models */ + protected Map<String, SynchVCSFileStatesModel> models; + + public SynchUIModel() { + } + + public SynchUIModel(VCSHandler handler, File localRoot, URL remoteRoot) { + this.handler = handler; + this.localRoot = localRoot; + this.remoteRoot = remoteRoot; + } + + public void setLocalRoot(File localRoot) { + this.localRoot = localRoot; + } + + public void setRemoteRoot(URL remoteRoot) { + this.remoteRoot = remoteRoot; + } + + public SynchVCSFileStatesModel getModel(String modelName) { + SynchVCSFileStatesModel tableModel = getModels().get(modelName); + if (tableModel == null) { + getModels().put(modelName, tableModel = new SynchVCSFileStatesModel()); + } + return tableModel; + } + + public void setData(List<VCSFileState> states) { + getModel(ALL_MODEL_PROPERTY).setData(states); + List<VCSFileState> local = new ArrayList<VCSFileState>(states); + List<VCSFileState> remote = new ArrayList<VCSFileState>(); + splitStates(states, local, remote); + getModel(LOCAL_MODEL_PROPERTY).setData(local); + getModel(REMOTE_MODEL_PROPERTY).setData(remote); + } + + public void addData(List<VCSFileState> states) { + getModel(ALL_MODEL_PROPERTY).setData(states); + List<VCSFileState> local = new ArrayList<VCSFileState>(); + List<VCSFileState> remote = new ArrayList<VCSFileState>(); + splitStates(states, local, remote); + getModel(LOCAL_MODEL_PROPERTY).addData(local.toArray(new VCSFileState[local.size()])); + getModel(REMOTE_MODEL_PROPERTY).addData(remote.toArray(new VCSFileState[remote.size()])); + } + + public void removeData(List<VCSFileState> states) { + getModel(ALL_MODEL_PROPERTY).removeData(states.toArray(new VCSFileState[states.size()])); + List<VCSFileState> local = new ArrayList<VCSFileState>(); + List<VCSFileState> remote = new ArrayList<VCSFileState>(); + splitStates(states, local, remote); + getModel(LOCAL_MODEL_PROPERTY).removeData(local.toArray(new VCSFileState[local.size()])); + getModel(REMOTE_MODEL_PROPERTY).removeData(remote.toArray(new VCSFileState[remote.size()])); + } + + protected Map<String, SynchVCSFileStatesModel> getModels() { + if (models == null) { + models = new TreeMap<String, SynchVCSFileStatesModel>(); + } + return models; + } + + protected void splitStates(List<VCSFileState> states, List<VCSFileState> local, List<VCSFileState> remote) { + for (VCSFileState state : states) { + if (state.getState()!=null && state.getState().isLocal()) { + local.add(state); + } + if (state.getState()!=null && state.getState().isRemote()) { + remote.add(state); + } + } + } +} Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchVCSFileStatesModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchVCSFileStatesModel.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchVCSFileStatesModel.java 2008-03-31 20:40:35 UTC (rev 248) @@ -0,0 +1,46 @@ +/** + * # #% Copyright (C) 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 org.codelutin.vcs.ui.model; + +import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.VCSState; +import org.codelutin.vcs.ui.VCSUIConstants; + +/** @author chemit */ +public class SynchVCSFileStatesModel extends AbstractVCSFileStatesModel { + private static final long serialVersionUID = -7592705623128585146L; + + public SynchVCSFileStatesModel() { + super(VCSUIConstants.SIMPLE_COLUMNS_NAMES); + } + + public Object getValueAt(int rowIndex, int columnIndex) { + if (isEmpty()) return null; + VCSFileState item = data.get(rowIndex); + Object result = null; + if (columnIndex == 0) { + // get module + result = item.getLocalPath(); + } else if (columnIndex == 1) { + // get file + result = item.getFile().getName(); + } else if (columnIndex == 2) { + // get status + VCSState state = item.getState(); + result = state==null?null:state.libelle(); + } + return result; + } +} Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java 2008-03-31 20:40:16 UTC (rev 247) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java 2008-03-31 20:40:35 UTC (rev 248) @@ -39,10 +39,10 @@ protected List<VCSFileState> data; + protected String[] columnNames; + private static final long serialVersionUID = 4697917831388337369L; - protected String[] columnNames; - public VCSFileStateTableModel() { super(); columnNames = VCSUIConstants.SIMPLE_COLUMNS_NAMES; Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSRepositoryModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSRepositoryModel.java 2008-03-31 20:40:16 UTC (rev 247) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSRepositoryModel.java 2008-03-31 20:40:35 UTC (rev 248) @@ -1,124 +0,0 @@ -/** - * # #% Copyright (C) 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 org.codelutin.vcs.ui.model; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSHandler; -import org.codelutin.vcs.VCSState; -import static org.codelutin.vcs.ui.VCSUIConstants.ALL_MODEL_PROPERTY; -import static org.codelutin.vcs.ui.VCSUIConstants.LOCAL_MODEL_PROPERTY; -import static org.codelutin.vcs.ui.VCSUIConstants.REMOTE_MODEL_PROPERTY; - -import java.io.File; -import java.net.URL; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * Model of a repository - * - * @author chemit - */ -public class VCSRepositoryModel { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - static protected final Log log = LogFactory.getLog(VCSRepositoryModel.class); - - /** list of states of scanned files */ - protected List<VCSFileState> states = new ArrayList<VCSFileState>(); - - /** local root : wroking copy */ - protected File localRoot; - - /** remote root : remote url */ - protected URL remoteRoot; - - /** vcs states to be authorized in this model */ - protected VCSState[] acceptedStates; - - /** vcs actions to be authorized in this model */ - protected EnumSet<VCSAction> acceptedActions; - - /** vcs handler to use (lazy instanciation) */ - protected VCSHandler handler; - - /** map of models */ - protected Map<String, VCSFileStateTableModel> models; - - public VCSRepositoryModel(VCSHandler handler, File localRoot, URL remoteRoot) { - this.handler = handler; - this.localRoot = localRoot; - this.remoteRoot = remoteRoot; - } - - public VCSFileStateTableModel getModel(String modelName) { - VCSFileStateTableModel tableModel = getModels().get(modelName); - if (tableModel == null) { - getModels().put(modelName, tableModel = new VCSFileStateTableModel()); - } - return tableModel; - } - - public void setData(List<VCSFileState> states) { - getModel(ALL_MODEL_PROPERTY).setData(states); - List<VCSFileState> local = new ArrayList<VCSFileState>(states); - List<VCSFileState> remote = new ArrayList<VCSFileState>(); - splitStates(states, local, remote); - getModel(LOCAL_MODEL_PROPERTY).setData(local); - getModel(REMOTE_MODEL_PROPERTY).setData(remote); - } - - public void addData(List<VCSFileState> states) { - getModel(ALL_MODEL_PROPERTY).setData(states); - List<VCSFileState> local = new ArrayList<VCSFileState>(); - List<VCSFileState> remote = new ArrayList<VCSFileState>(); - splitStates(states, local, remote); - getModel(LOCAL_MODEL_PROPERTY).addData(local.toArray(new VCSFileState[local.size()])); - getModel(REMOTE_MODEL_PROPERTY).addData(remote.toArray(new VCSFileState[remote.size()])); - } - - public void removeData(List<VCSFileState> states) { - getModel(ALL_MODEL_PROPERTY).removeData(states.toArray(new VCSFileState[states.size()])); - List<VCSFileState> local = new ArrayList<VCSFileState>(); - List<VCSFileState> remote = new ArrayList<VCSFileState>(); - splitStates(states, local, remote); - getModel(LOCAL_MODEL_PROPERTY).removeData(local.toArray(new VCSFileState[local.size()])); - getModel(REMOTE_MODEL_PROPERTY).removeData(remote.toArray(new VCSFileState[remote.size()])); - } - - protected Map<String, VCSFileStateTableModel> getModels() { - if (models == null) { - models = new TreeMap<String, VCSFileStateTableModel>(); - } - return models; - } - - protected void splitStates(List<VCSFileState> states, List<VCSFileState> local, List<VCSFileState> remote) { - for (VCSFileState state : states) { - if (state.getState().isLocal()) { - local.add(state); - } - if (state.getState().isRemote()) { - remote.add(state); - } - } - } -}