Author: tchemit
Date: 2008-03-31 20:44:09 +0000 (Mon, 31 Mar 2008)
New Revision: 253
Added:
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSRepositoryState.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/AbstractTableModel.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccess.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccessManager.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldModelUtil.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FileStateTableModel.java
trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/package.html
Log:
pur generation module
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSRepositoryState.java (from rev 240, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/VCSRepositoryState.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSRepositoryState.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSRepositoryState.java 2008-03-31 20:44:09 UTC (rev 253)
@@ -0,0 +1,200 @@
+/* ##%
+* 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.vcs.ui.FileStateTableModel;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+
+/**
+ * Permet de rechercher et conserve les differences entre le repository local et
+ * distant.
+ *
+ * @author poussin
+ * @author chemit
+ */
+public class VCSRepositoryState {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static protected final Log log = LogFactory.getLog(VCSRepositoryState.class);
+
+ /** liste des �tats des fichiers scann�s */
+ protected List<VCSFileState> states = new ArrayList<VCSFileState>();
+
+ /** tableau des model de table (un par �tat VCSState) */
+ protected FileStateTableModel[] models;
+
+ /** le r�pertoire racine du working copy local */
+ protected File root;
+
+ /** 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;
+
+ public static final VCSState[] UPDATE_STATES = {
+ org.codelutin.vcs.VCSState.OUT_OF_DATE,
+ org.codelutin.vcs.VCSState.MODIFIED,
+ org.codelutin.vcs.VCSState.OUT_OF_DATE_AND_MODIFIED,
+ org.codelutin.vcs.VCSState.UNVERSIONNED,
+ org.codelutin.vcs.VCSState.MISSING
+ };
+
+ /**
+ * @param handler handlet to use
+ * @param root directory of root local working copy
+ * @param actions accepted actions
+ * @param modules la liste des modules a traiter
+ * @throws VCSException if any problem while building
+ */
+ protected VCSRepositoryState(VCSHandler handler, File root, EnumSet<VCSAction> actions, File... modules) throws VCSException {
+ this.acceptedActions = actions;
+ this.root = root;
+ this.acceptedStates = UPDATE_STATES;
+ this.handler = handler;
+ // scan all modules
+ for (File mod : modules) {
+ states.addAll(doScan(mod, acceptedStates));
+ }
+ }
+
+ public VCSHandler getHandler() {
+ return handler;
+ }
+
+ /**
+ * @param handler vcs handler to use for synch operation
+ * @throws VCSException if any problem while synchro
+ */
+ public void doSynch(VCSHandler handler) throws VCSException {
+ long timestamp = System.nanoTime();
+ for (VCSFileState fileState : states) {
+ fileState.doSynch(handler, timestamp);
+ }
+ }
+
+ public File getRoot() {
+ return root;
+ }
+
+ public List<VCSFileState> getStates() {
+ return states;
+ }
+
+ public VCSState[] getAcceptedStates() {
+ return acceptedStates;
+ }
+
+ public FileStateTableModel getModel(VCSState state) {
+ return getModels()[state.ordinal()];
+ }
+
+
+ protected FileStateTableModel[] getModels() {
+ if (models == null) {
+ models = new FileStateTableModel[VCSState.values().length];
+ }
+ return models;
+ }
+
+ public void createUIModels() {
+ for (VCSState state : acceptedStates) {
+ getModels()[state.ordinal()] = new FileStateTableModel(VCSFileStateManager.filter(states, state), acceptedActions);
+ }
+ }
+
+ public List<VCSFileState> selected(VCSState... wanted) {
+ if (wanted.length == 0) {
+ wanted = acceptedStates;
+ }
+ List<VCSFileState> result = new ArrayList<VCSFileState>();
+ for (VCSState state : wanted) {
+ FileStateTableModel tableModel = getModel(state);
+ if (tableModel != null) {
+ result.addAll(tableModel.getSelected());
+ }
+ }
+ return result;
+ }
+
+ public void checkAll(boolean toUse, VCSState... wanted) {
+ if (wanted.length == 0) wanted = acceptedStates;
+ for (VCSState state : wanted) {
+ FileStateTableModel tableModel = getModel(state);
+ if (tableModel != null) {
+ tableModel.checkAll(0, toUse);
+ }
+ }
+ }
+
+ public boolean isModelEmpty() {
+ for (VCSState state : acceptedStates) {
+ FileStateTableModel tableModel = getModel(state);
+ if (tableModel != null && tableModel.getRowCount() > 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public int getModelSelectedSize() {
+ int result = 0;
+ for (VCSState state : acceptedStates) {
+ result += getModelSelectedSize(state);
+ }
+ return result;
+ }
+
+ public boolean isModelEmpty(VCSState state) {
+ FileStateTableModel tableModel = getModel(state);
+ return !(tableModel != null && tableModel.getRowCount() > 0);
+ }
+
+ public int getModelSize(VCSState state) {
+ FileStateTableModel tableModel = getModel(state);
+ return tableModel == null ? 0 : tableModel.getRowCount();
+ }
+
+ public int getModelSelectedSize(VCSState state) {
+ FileStateTableModel tableModel = getModel(state);
+ return tableModel == null ? 0 : tableModel.getSelectedSize();
+ }
+
+ private List<VCSFileState> doScan(File module, VCSState... acceptedStates)
+ throws VCSException {
+ // obtain list of all VCSFileState found in module directory
+ List<VCSFileState> states;
+ states = VCSFileStateManager.doScan(getHandler(), module, true, acceptedStates);
+ return states;
+ }
+
+ public EnumSet<VCSAction> getAcceptedActions() {
+ return acceptedActions;
+ }
+}
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/AbstractTableModel.java (from rev 240, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/AbstractTableModel.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/AbstractTableModel.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/AbstractTableModel.java 2008-03-31 20:44:09 UTC (rev 253)
@@ -0,0 +1,190 @@
+/*
+* ##% 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 static java.lang.Boolean.TRUE;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/** TODO-TC */
+(a)org.codelutin.i18n.I18nable
+public abstract class AbstractTableModel<D> extends javax.swing.table.AbstractTableModel {
+
+
+ protected final FieldAccess<D>[] modelAccess;
+ protected List<D> data;
+
+ protected final int nbOptions;
+ protected Map<D, Boolean>[] options;
+ protected final String[] optionNames;
+ protected final Class[] optionClass;
+ protected boolean[] optionChecks;
+
+ private static final long serialVersionUID = 4697917831388337369L;
+
+ @SuppressWarnings({"unchecked"})
+ protected AbstractTableModel(
+ List<D> data, FieldAccess<D>[] modelAccess,
+ Class[] optionsClass, String[] optionsNames) throws RuntimeException {
+ if (optionsClass.length != optionsNames.length)
+ throw new RuntimeException(_("lutinvcs.error.fieldmodel.unmatchin.options"));
+
+ this.data = data;
+ this.optionClass = optionsClass;
+ this.optionNames = optionsNames;
+ this.modelAccess = modelAccess;
+ this.nbOptions = optionsClass.length;
+ this.options = new Map[this.nbOptions];
+ this.optionChecks = new boolean[this.nbOptions];
+ }
+
+ protected AbstractTableModel(List<D> data, FieldAccess<D>[] modelAccess,
+ Class optionsClass, String optionsNames) {
+ this(data, modelAccess, new Class[]{optionsClass},
+ new String[]{optionsNames});
+ }
+
+ protected AbstractTableModel(List<D> data, FieldAccess<D>[] modelAccess) {
+ this(data, modelAccess, new Class[0], new String[0]);
+ }
+
+ protected Map<D, Boolean> getOptionMap(int rowindex) {
+ if (rowindex >= nbOptions) return null;
+ Map<D, Boolean> map = options[rowindex];
+ if (map == null)
+ map = options[rowindex] = new LinkedHashMap<D, Boolean>();
+ return map;
+ }
+
+ /**
+ * @param index option index
+ * @return Returns the selected for an option.
+ */
+ public List<D> getSelected(int index) {
+ List<D> result = new ArrayList<D>();
+ Map<D, Boolean> option = nbOptions == 0 ? null : options[index];
+ if (index >= nbOptions || option == null) return result;
+ for (Map.Entry<D, Boolean> item : option.entrySet())
+ if (java.lang.Boolean.TRUE.equals(item.getValue()))
+ result.add(item.getKey());
+ return result;
+ }
+
+ public int getSelectedSize(int index) {
+ int result = 0;
+ Map<D, Boolean> option = nbOptions == 0 ? null : options[index];
+ if (index >= nbOptions || option == null) return result;
+ for (Map.Entry<D, Boolean> item : option.entrySet())
+ if (java.lang.Boolean.TRUE.equals(item.getValue()))
+ result++;
+ return result;
+ }
+
+ public List<D> getData() {
+ return data;
+ }
+
+ public int getColumnCount() {
+ return modelAccess.length + nbOptions;
+ }
+
+ public int getRowCount() {
+ return data.size();
+ }
+
+ public void checkAll() {
+ if (nbOptions != 1) return;
+ for (int i = 0; i < nbOptions; i++) checkAll(i);
+ }
+
+ @Override
+ public Class<?> getColumnClass(int columnIndex) {
+ Class result;
+ if (columnIndex < nbOptions) {
+
+ result = this.optionClass[columnIndex];
+ } else {
+ result = FieldAccessManager.getFieldClass(modelAccess[columnIndex - nbOptions]);
+ }
+ return result;
+ }
+
+ @Override
+ public String getColumnName(int columnIndex) {
+ String result;
+ if (columnIndex < nbOptions)
+ result = this.optionNames[columnIndex];
+ else
+ result = FieldAccessManager.getFieldName(modelAccess[columnIndex - nbOptions]);
+ return result;
+ }
+
+ @Override
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return columnIndex < nbOptions;
+ }
+
+ @Override
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ D item = data.get(rowIndex);
+ if (columnIndex < nbOptions)
+ setOptionValueAt(item, aValue, columnIndex);
+ // read only data
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ D item = data.get(rowIndex);
+ if (columnIndex < nbOptions)
+ return getOptionValueAt(item, columnIndex);
+ return modelAccess[columnIndex - nbOptions].getValue(item);
+ }
+
+ protected void setOptionValueAt(D item, Object aValue, int index) {
+ getOptionMap(index).put(item, TRUE.equals(aValue));
+ }
+
+ protected void checkAll(int index, boolean value) {
+ if (index >= nbOptions || nbOptions > 1) return;
+ for (int i = 0; i < getRowCount(); i++)
+ setValueAt(value, i, index);
+ }
+
+ protected void checkAll(int index) {
+ if (index >= nbOptions || nbOptions > 1) return;
+ checkAll(index, optionChecks[index] = !optionChecks[index]);
+ }
+
+ protected Boolean getOptionValueAt(D item, int index) {
+ return getOptionMap(index).get(item);
+ }
+
+ protected FieldAccess[] getFiedAccess() {
+ return modelAccess;
+ }
+
+ public void reset(List<D> states) {
+ data.clear();
+ data.addAll(states);
+ }
+}
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccess.java (from rev 240, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/FieldAccess.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccess.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccess.java 2008-03-31 20:44:09 UTC (rev 253)
@@ -0,0 +1,31 @@
+/*
+* ##% 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;
+
+/**
+ * A simple contract for a field access in vcs ui, says a cell
+ *
+ * @author chemit
+ */
+public interface FieldAccess<D> {
+
+ Object getValue(D item);
+
+}
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccessManager.java (from rev 240, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/FieldAccessManager.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccessManager.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldAccessManager.java 2008-03-31 20:44:09 UTC (rev 253)
@@ -0,0 +1,154 @@
+/*
+* ##% 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 org.apache.commons.logging.Log;
+import static org.apache.commons.logging.LogFactory.getLog;
+import static org.codelutin.i18n.I18n._;
+
+/**
+ * Class pour gérer un cache de {@link FieldAccessEntry} indexés à partir de
+ * {@link FieldAccess}.
+ *
+ * @author chemit
+ */
+(a)org.codelutin.i18n.I18nable
+public class FieldAccessManager {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = getLog(FieldAccessManager.class);
+
+ /** cache of registred FiledModelEntry associated to a FieldAccess */
+ static protected java.util.Map<FieldAccess, FieldAccessEntry> cache;
+
+ /**
+ * Register a FieldAccess in the cache
+ *
+ * @param constant the constant to be used
+ * @param libelle name of the field (libelle to display in row header)
+ * @param clazz class of the object used for this field
+ */
+ public static <D> void registerFieldAccess(FieldAccess<D> constant, String libelle, Class clazz) {
+ checkAlreadyRegistredEntry(constant);
+ FieldAccessEntry<D> entry = new FieldAccessEntry<D>(constant, libelle, clazz);
+ log.debug(entry);
+ getCache().put(constant, entry);
+ }
+
+ /**
+ * Obtain the class of a field via his constant type safe value
+ *
+ * @param constant the constant to be used
+ * @return the class defined for the field
+ */
+ public static <D> Class getFieldClass(FieldAccess<D> constant) {
+ FieldAccessEntry entry = getEntry(constant, true);
+ return entry == null ? null : entry.getClazz();
+ }
+
+ /**
+ * Obtain the libelle of a field via his constant type safe value
+ *
+ * @param constant the constant to be used
+ * @return the libelle defined for the field
+ */
+ public static <D> String getFieldName(FieldAccess<D> constant) {
+ FieldAccessEntry entry = getEntry(constant, true);
+ return entry == null ? null : entry.getLibelle();
+ }
+
+ /**
+ * Obtain for a item the value of his field via his constant type safe value
+ *
+ * @param constant the constant to be used
+ * @param item the item to be inspect
+ * @return the class defined for the field
+ */
+ public static <D> Object getFieldValue(FieldAccess<D> constant, D item) {
+ FieldAccessEntry<D> entry = getEntry(constant, true);
+ return entry == null ? null : entry.getValue(item);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected static <D> FieldAccessEntry<D> getEntry(FieldAccess<D> constant, boolean safe) {
+ FieldAccessEntry<D> entry = getCache().get(constant);
+ checkExistingEntry(constant, safe, entry);
+ return entry;
+ }
+
+ private static <D> void checkExistingEntry(FieldAccess<D> constant, boolean safe, FieldAccessEntry<D> entry) {
+ if (safe && entry == null) {
+ throw new RuntimeException(_("lutinvcs.error.fieldmodel.not.registred", constant));
+ }
+ }
+
+ private static <D> void checkAlreadyRegistredEntry(FieldAccess<D> constant) throws RuntimeException {
+ FieldAccessEntry<D> entry = getEntry(constant, false);
+ if (entry != null) {
+ throw new RuntimeException(_("lutinvcs.error.fieldmodel.already.registred", constant));
+ }
+ }
+
+
+ private static java.util.Map<FieldAccess, FieldAccessEntry> getCache() {
+ if (cache == null)
+ cache = new java.util.HashMap<FieldAccess, FieldAccessEntry>();
+ return cache;
+ }
+
+ protected static class FieldAccessEntry<D> implements FieldAccess<D> {
+
+ private final String libelle;
+ private final Class clazz;
+ private final FieldAccess<D> constant;
+
+ FieldAccessEntry(FieldAccess<D> constant, String libelle, Class clazz) {
+ this.constant = constant;
+ // keep only translated libelle
+ this.libelle = _(libelle);
+ this.clazz = clazz;
+ }
+
+ public String getLibelle() {
+ return libelle;
+ }
+
+ public Class getClazz() {
+ return clazz;
+ }
+
+ public Object getValue(D item) {
+ return constant.getValue(item);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(this.getClass().getSimpleName());
+ sb.append('@').append(Math.abs(hashCode()));
+ sb.append(" [").append(constant).append("] [").append(libelle).append("] [");
+ sb.append(clazz).append(']');
+ return sb.toString();
+ }
+ }
+
+ protected FieldAccessManager() {
+ }
+
+}
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldModelUtil.java (from rev 240, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/FieldModelUtil.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldModelUtil.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FieldModelUtil.java 2008-03-31 20:44:09 UTC (rev 253)
@@ -0,0 +1,121 @@
+/*
+* ##% 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.VCSFileState;
+
+import java.io.File;
+
+(a)org.codelutin.i18n.I18nable
+public class FieldModelUtil {
+
+
+ static public ModuleFile<String> createModuleFileTableModel(java.util.List<String> data) {
+ return new ModuleFile<String>(SimpleModuleFileAccess.getAcces(), data);
+ }
+
+ static public ModuleFile<String> createModuleFileTableModelWithSelect(java.util.List<String> data) {
+ return new ModuleFile<String>(SimpleModuleFileAccess.getAcces(), data, Boolean.class, _("lutinvcs.select"));
+ }
+
+ static public <D> ModuleFile<D> createModuleFileTableModelWithSelect(FieldAccess<D>[] model, java.util.List<D> data) {
+ return new ModuleFile<D>(model, data, Boolean.class, _("lutinvcs.select"));
+ }
+
+ static public <D> ModuleFile<D> createModuleFileTableModel(FieldAccess<D>[] model, java.util.List<D> data) {
+ return new ModuleFile<D>(model, data);
+ }
+
+ public static class ModuleFile<D> extends AbstractTableModel<D> {
+ private static final long serialVersionUID = 4067521432762944991L;
+
+ protected ModuleFile(FieldAccess<D>[] model, java.util.List<D> data, Class klazz, String select) {
+ super(data, model, klazz, select);
+ }
+
+ protected ModuleFile(FieldAccess<D>[] model, java.util.List<D> data) {
+ super(data, model);
+ }
+ }
+
+
+ public static enum SimpleModuleFileWithActionAccess implements FieldAccess<VCSFileState> {
+ ACTION(_("lutinvcs.action"), String.class) {
+ public Object getValue(VCSFileState item) {
+ return item.getAction().getLibelle();
+ }
+ },
+ MODULE(_("lutinvcs.module"), String.class) {
+ public Object getValue(VCSFileState item) {
+ return item.getModuleName();
+ }
+ },
+ NAME(_("lutinvcs.file"), String.class) {
+ public Object getValue(VCSFileState item) {
+ return item.getModuleRelativeFileName();
+ }
+ };
+
+ SimpleModuleFileWithActionAccess(String libelle, Class clazz) {
+ FieldAccessManager.registerFieldAccess(this, libelle, clazz);
+ }
+ }
+
+ public static enum SimpleModuleFileAccess implements FieldAccess<String> {
+
+ MODULE(_("lutinvcs.module"), String.class) {
+ public Object getValue(String item) {
+ return item.contains(java.io.File.separator) ? item.substring(
+ 0, item.lastIndexOf(java.io.File.separator)) : item;
+ }
+ },
+ NAME(_("lutinvcs.file"), String.class) {
+ public Object getValue(String item) {
+ return item.contains(java.io.File.separator) ? item
+ .substring(item.lastIndexOf(java.io.File.separator) + 1)
+ : "";
+ }
+ };
+
+ SimpleModuleFileAccess(String libelle, Class clazz) {
+ FieldAccessManager.registerFieldAccess(this, libelle, clazz);
+ }
+
+ public static FieldAccess<String>[] getAcces() {
+ return values();
+ }
+
+ }
+
+ public static enum SimpleFileAccess implements FieldAccess<File> {
+
+ NAME(_("lutinvcs.file"), File.class) {
+ public Object getValue(File item) {
+ return item.getAbsolutePath();
+ }
+ };
+
+ SimpleFileAccess(String libelle, Class clazz) {
+ FieldAccessManager.registerFieldAccess(this, libelle, clazz);
+ }
+ }
+
+}
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FileStateTableModel.java (from rev 240, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/FileStateTableModel.java)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FileStateTableModel.java (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/FileStateTableModel.java 2008-03-31 20:44:09 UTC (rev 253)
@@ -0,0 +1,234 @@
+/*
+* ##% 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 javax.swing.table.AbstractTableModel;
+import static java.lang.Boolean.FALSE;
+import static java.lang.Boolean.TRUE;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * TODO Use FieldAccessManager
+ *
+ * @author tchemit
+ * @see org.codelutin.vcs.ui.FieldAccessManager
+ * @see org.codelutin.vcs.ui.FieldModelUtil
+ * @see org.codelutin.vcs.ui.FieldAccess
+ */
+
+(a)org.codelutin.i18n.I18nable
+public class FileStateTableModel extends AbstractTableModel {
+
+ private static final long serialVersionUID = 5764217576707763232L;
+
+ public static enum FIELD_ACCESS {
+ MODULE(_("lutinvcs.module"), String.class) {
+ public Object getValue(VCSFileState item) {
+ return item.getModuleName();
+ }
+ },
+ NAME(_("lutinvcs.file"), String.class) {
+ public Object getValue(VCSFileState item) {
+ return item.getModuleRelativeFileName();
+ }
+ },
+ LOGDIFF(_("lutinvcs.logDiff"), String.class) {
+ public Object getValue(VCSFileState item) {
+ final String changeLog = item.getChangeLog();
+ return changeLog == null ? "" : changeLog;
+ }
+ },
+ REV(_("lutinvcs.rev"), Long.class) {
+ public Object getValue(VCSFileState item) {
+ return item.getRev();
+ }
+ };
+
+ protected String columnName;
+ protected Class columnClass;
+
+ FIELD_ACCESS(String columnName, Class columnClass) {
+ this.columnName = columnName;
+ this.columnClass = columnClass;
+ }
+
+ public String getColumnName() {
+ return columnName;
+ }
+
+ public Class getColumnClass() {
+ return columnClass;
+ }
+
+ public abstract Object getValue(VCSFileState item);
+ }
+
+ protected Map<VCSFileState, VCSAction> selected;
+ protected List<VCSFileState> data;
+ protected VCSState state;
+ protected List<VCSAction> actions;
+
+ public FileStateTableModel(List<VCSFileState> data, EnumSet<VCSAction> actions) {
+ this.data = data;
+ this.selected = new HashMap<VCSFileState, VCSAction>();
+ List<VCSAction> tmp = new ArrayList<VCSAction>();
+
+ if (!data.isEmpty()) {
+ // determine vcsstates used here for the moment a unique type
+ state = data.get(0).getState();
+
+ for (VCSAction action : state.getActions()) {
+ if (action.isVisible() && actions.contains(action)) {
+ tmp.add(action);
+ }
+ }
+ }
+ this.actions = tmp;
+ }
+
+ /** @return Returns the selected. */
+ public List<VCSFileState> getSelected() {
+ List<VCSFileState> result = new ArrayList<VCSFileState>();
+ for (Map.Entry<VCSFileState, VCSAction> item : selected.entrySet())
+ if (item.getValue() != null) {
+ item.getKey().setAction(item.getValue());
+ result.add(item.getKey());
+ }
+ return result;
+ }
+
+ public int getSelectedSize() {
+ int result = 0;
+ for (Map.Entry<VCSFileState, VCSAction> item : selected.entrySet()) {
+ if (item.getValue() != null) {
+ result++;
+ }
+ }
+ return result;
+ }
+
+ public List<VCSAction> getActions() {
+ return actions;
+ }
+
+ public VCSAction getAction(int row) {
+ return selected.get(data.get(row));
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getColumnCount()
+ */
+ public int getColumnCount() {
+ return _FIELD_ACCESS.length + actions.size() - 2;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getRowCount()
+ */
+ public int getRowCount() {
+ return data.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
+ */
+ @Override
+ public Class<?> getColumnClass(int columnIndex) {
+ Class result;
+ if (columnIndex < actions.size()) {
+ result = Boolean.class;
+ } else {
+ result = _FIELD_ACCESS[columnIndex - actions.size()].getColumnClass();
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#getColumnName(int)
+ */
+ @Override
+ public String getColumnName(int columnIndex) {
+ String result;
+ if (columnIndex < actions.size()) {
+ result = actions.get(columnIndex).getLibelle().substring(0, 1);
+ } else {
+ result = _FIELD_ACCESS[columnIndex - actions.size()].getColumnName();
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int)
+ */
+ @Override
+ public boolean isCellEditable(int rowIndex, int columnIndex) {
+ return columnIndex < actions.size();
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.AbstractTableModel#setValueAt(Object, int, int)
+ */
+ @Override
+ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
+ if (columnIndex < actions.size()) {
+ VCSFileState item = data.get(rowIndex);
+ VCSAction action = actions.get(columnIndex);
+ final boolean b = TRUE.equals(aValue);
+ selected.put(item, b ? action : null);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.table.TableModel#getValueAt(int, int)
+ */
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ VCSFileState item = data.get(rowIndex);
+ Object result;
+ if (getRowCount() == 0) return null;
+ if (columnIndex < actions.size()) {
+ result = selected.get(item);
+ VCSAction action = actions.get(columnIndex);
+ result = result == null || action != result ? FALSE : TRUE;
+ } else {
+ result = _FIELD_ACCESS[columnIndex - actions.size()].getValue(item);
+ }
+
+ return result;
+ }
+
+
+ public void checkAll(int index, boolean value) {
+ if (actions.size() != 1 || index >= actions.size()) return;
+ //if (getActions().size() == 1) return;
+ // the only case we can automaticly check-uncheck items
+ for (int i = 0; i < getRowCount(); i++) setValueAt(value, i, index);
+ }
+
+ private static final FIELD_ACCESS[] _FIELD_ACCESS = FIELD_ACCESS.values();
+}
\ No newline at end of file
Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/package.html (from rev 240, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/package.html)
===================================================================
--- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/package.html (rev 0)
+++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/package.html 2008-03-31 20:44:09 UTC (rev 253)
@@ -0,0 +1,6 @@
+<html>
+<body>
+<h1>Lutin vcs ui package</h1>
+TODO
+</body>
+</html>
\ No newline at end of file