[Buix-commits] r244 - trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui
Author: tchemit Date: 2008-03-31 18:27:28 +0000 (Mon, 31 Mar 2008) New Revision: 244 Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSRepositoryModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSUIConstants.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/ Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSFileStateTableModel.java Log: ui models Modified: 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:10:36 UTC (rev 243) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSFileStateTableModel.java 2008-03-31 18:27:28 UTC (rev 244) @@ -20,7 +20,6 @@ package org.codelutin.vcs.ui; import static org.codelutin.i18n.I18n._; -import static org.codelutin.i18n.I18n.n_; import org.codelutin.vcs.VCSAction; import org.codelutin.vcs.VCSFileState; import org.codelutin.vcs.VCSState; @@ -30,24 +29,29 @@ import java.util.Iterator; import java.util.List; -/** Simple Table model to display list of VCSFileState */ -@org.codelutin.i18n.I18nable +/** + * Simple Table model to display list of VCSFileState + * + * @author chemit + */ public class VCSFileStateTableModel extends javax.swing.table.AbstractTableModel { - private final String[] colomnNames = new String[]{ - n_("lutinvcs.module"), - n_("lutinvcs.file"), - n_("lutinvcs.status") - }; - protected List<VCSFileState> data; private static final long serialVersionUID = 4697917831388337369L; - protected VCSFileStateTableModel() { + 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); @@ -58,7 +62,7 @@ } public int getColumnCount() { - return colomnNames.length; + return columnNames.length; } public int getRowCount() { @@ -72,7 +76,7 @@ @Override public String getColumnName(int columnIndex) { - return _(colomnNames[columnIndex]); + return _(columnNames[columnIndex]); } @Override Added: 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 (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSRepositoryModel.java 2008-03-31 18:27:28 UTC (rev 244) @@ -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; + +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); + } + } + } +} Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSUIConstants.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSUIConstants.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSUIConstants.java 2008-03-31 18:27:28 UTC (rev 244) @@ -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; + +import static org.codelutin.i18n.I18n.n_; + +/** @author chemit */ +public class VCSUIConstants { + + /** columns names for a simple table model with module, file and status */ + public static final String[] SIMPLE_COLUMNS_NAMES = new String[]{ + n_("lutinvcs.module"), + n_("lutinvcs.file"), + n_("lutinvcs.status") + }; + + /** model name for synchronize all tab ui */ + public static final String ALL_MODEL_PROPERTY = "model.synch.all"; + + /** model name for synchronize local tab ui */ + public static final String LOCAL_MODEL_PROPERTY = "model.synch.local"; + + /** model name for synchronize remote tab ui */ + public static final String REMOTE_MODEL_PROPERTY = "model.synch.remote"; + + /** model name for diff ui */ + public static final String DIFF_MODEL_PROPERTY = "model.diff"; + + /** model name for commit ui */ + public static final String COMMIT_MODEL_PROPERTY = "model.commit"; + + /** model name for confirm ui (all actions exception commit) */ + public static final String CONFIRM_MODEL_PROPERTY = "model.confirm"; +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org