Author: tchemit Date: 2008-03-31 18:27:47 +0000 (Mon, 31 Mar 2008) New Revision: 245 Added: 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/VCSRepositoryModel.java Removed: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSFileStateTableModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSRepositoryModel.java Log: ui models Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSFileStateTableModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSFileStateTableModel.java 2008-03-31 18:27:28 UTC (rev 244) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSFileStateTableModel.java 2008-03-31 18:27:47 UTC (rev 245) @@ -1,204 +0,0 @@ -/* -* ##% 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; - -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 class VCSFileStateTableModel extends javax.swing.table.AbstractTableModel { - - protected List<VCSFileState> data; - - private static final long serialVersionUID = 4697917831388337369L; - - protected String[] columnNames; - - public VCSFileStateTableModel() { - super(); - columnNames = VCSUIConstants.SIMPLE_COLUMNS_NAMES; - } - - public VCSFileStateTableModel(String[] columnNames) { - super(); - this.columnNames = columnNames; - } - - public VCSFileStateTableModel(List<VCSFileState> data) throws RuntimeException { - super(); - setData(data); - } - - 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) { - return false; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - // read only data - } - - 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.getModuleName(); - } else if (columnIndex == 1) { - // get file - result = item.getFile().getName(); - } else if (columnIndex == 2) { - // get status - result = item.getState(); - } - return result; - } - - 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(); - } - - private 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 Deleted: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSRepositoryModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSRepositoryModel.java 2008-03-31 18:27:28 UTC (rev 244) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSRepositoryModel.java 2008-03-31 18:27:47 UTC (rev 245) @@ -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; - -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); - } - } - } -} Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java (from rev 244, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSFileStateTableModel.java) =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSFileStateTableModel.java 2008-03-31 18:27:47 UTC (rev 245) @@ -0,0 +1,205 @@ +/* +* ##% 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 org.codelutin.vcs.ui.VCSUIConstants; + +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 class VCSFileStateTableModel extends javax.swing.table.AbstractTableModel { + + protected List<VCSFileState> data; + + private static final long serialVersionUID = 4697917831388337369L; + + protected String[] columnNames; + + public VCSFileStateTableModel() { + super(); + columnNames = VCSUIConstants.SIMPLE_COLUMNS_NAMES; + } + + public VCSFileStateTableModel(String[] columnNames) { + super(); + this.columnNames = columnNames; + } + + public VCSFileStateTableModel(List<VCSFileState> data) throws RuntimeException { + super(); + setData(data); + } + + 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) { + return false; + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + // read only data + } + + 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.getModuleName(); + } else if (columnIndex == 1) { + // get file + result = item.getFile().getName(); + } else if (columnIndex == 2) { + // get status + result = item.getState(); + } + return result; + } + + 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(); + } + + private 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/VCSRepositoryModel.java (from rev 244, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSRepositoryModel.java) =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSRepositoryModel.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/VCSRepositoryModel.java 2008-03-31 18:27:47 UTC (rev 245) @@ -0,0 +1,124 @@ +/** + * # #% 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); + } + } + } +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org