[Buix-commits] r362 - in trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs: . ui ui/handler ui/model
Author: tchemit Date: 2008-04-05 20:37:17 +0000 (Sat, 05 Apr 2008) New Revision: 362 Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFactory.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSEntriesTableModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSEntriesTableModelImpl.java Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSUIConstants.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractDiffUIHandler.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractSynchUIHandler.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractUIHandler.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/VCSAbsractAction.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractUIModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/ConfirmUIModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffPanelUIModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffUIModel.java trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchUIModel.java Log: refactor PRovider, Handler and Connexion Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFactory.java (from rev 353, trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSHandlerFactory.java) =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFactory.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/VCSFactory.java 2008-04-05 20:37:17 UTC (rev 362) @@ -0,0 +1,145 @@ +/* *##% +* 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.util.StringUtil; +import org.codelutin.vcs.runner.VCSActionManager; + +import java.util.ArrayList; +import java.util.List; +import java.util.ServiceLoader; + +/** + * This classes acts as a factory of {@link VCSProvider}, and {@link VCSConnexion}. + * + * @author chemit + * @see VCSConnexionConfig + * @see VCSConnexion + * @see VCSProvider + * @see VCSHandler + */ +@org.codelutin.i18n.I18nable +public class VCSFactory implements VCSConnexionEventListener { + + static protected final Log log = LogFactory.getLog(VCSFactory.class); + + /** shared instance */ + static protected VCSFactory instance; + + /** providers availables */ + protected List<VCSProvider> providers; + + /** connexions opened */ + protected List<VCSConnexion> connexions; + + /** action manager */ + protected VCSActionManager actionManager; + + protected static VCSFactory getInstance() { + if (instance == null) { + instance = new VCSFactory(); + } + return instance; + } + + public static VCSActionManager getActionManager() { + return getInstance().actionManager; + } + + /** + * instanciate a new connexion. + * <p/> + * the method will produce a runtime exception if config is null and not init. + * + * @param mode mode of connexion required + * @param config config to use @return the new connexion instance + * @return instanicate and init connexion (but not opened). + */ + public static VCSConnexion newConnexion(VCSConnexionMode mode, VCSConnexionConfig config) { + + VCSFactory factory = getInstance(); + VCSProvider<?, ?> provider; + + // obtain matching provider + provider = factory.getProvider(config.getType().name().toUpperCase()); + + // make sure provider is init + provider.init(); + + // delegate instanciation of connexion to provider + VCSConnexion connexion = provider.newConnection(mode, config); + + // init connexion + connexion.init(config); + + // register connexion + connexion.addVCSConnexionEventListener(factory); + return connexion; + } + + public VCSProvider getProvider(String type) { + VCSFactory factory = getInstance(); + for (VCSProvider provider : factory.providers) { + if (type.equals(provider.getName().toUpperCase())) { + return provider; + } + } + throw new IllegalArgumentException("could not find a provider for type " + type); + } + + public VCSConnexion[] getConnexions() { + return connexions.toArray(new VCSConnexion[connexions.size()]); + } + + public void open(VCSConnexionEvent event) { + // register connexion as active + connexions.add(event.getSource()); + if (connexions.size() == 1) { + // first connexion to be opened, open actionManager + getActionManager().open(); + } + } + + public void close(VCSConnexionEvent event) { + // remove connexion from active + connexions.remove(event.getSource()); + if (connexions.isEmpty()) { + // close actionManager ? + getActionManager().close(); + } + } + + protected VCSFactory() { + long t0 = System.nanoTime(); + providers = new ArrayList<VCSProvider>(); + for (VCSProvider provider : ServiceLoader.load(VCSProvider.class)) { + providers.add(provider); + } + log.info("found " + providers.size() + " provider(s) " + providers.toString() + " in " + StringUtil.convertTime(t0, System.nanoTime())); + for (VCSProvider provider : providers) { + log.info(provider.getName() + " [" + provider + ']'); + } + actionManager = new VCSActionManager(); + connexions = new ArrayList<VCSConnexion>(); + } + +} \ No newline at end of file Modified: 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 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/VCSUIConstants.java 2008-04-05 20:37:17 UTC (rev 362) @@ -27,6 +27,8 @@ }; /** model name for synchronize all tab ui */ + public static final String SYNCH_MODEL_PROPERTY = "modelSynch"; + public static final String SYNCH_ALL_MODEL_PROPERTY = "modelSynchAll"; /** model name for synchronize local tab ui */ Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractConfirmUIHandler.java 2008-04-05 20:37:17 UTC (rev 362) @@ -15,14 +15,13 @@ package org.codelutin.vcs.ui.handler; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.runner.VCSActionManager; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSHandler; +import org.codelutin.vcs.VCSEntry; import org.codelutin.vcs.ui.VCSUIConstants; -import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; +import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; import org.codelutin.vcs.ui.model.ConfirmUIModel; import java.beans.PropertyChangeEvent; +import java.util.List; /** * Abstract ConfirmUI handler @@ -31,14 +30,6 @@ */ public abstract class AbstractConfirmUIHandler extends AbstractUIHandler<ConfirmUIModel> { - protected final VCSActionManager actionManager; - - - protected AbstractConfirmUIHandler(VCSHandler handler) { - super(handler); - this.actionManager = new VCSActionManager(handler); - } - protected abstract void updateUI(); protected abstract void updateMessageUI(); @@ -62,11 +53,11 @@ throw new IllegalStateException("unimplemented property changed : " + evt); } - public void doAction(String commitMessage, AbstractVCSFileStatesModel model) { + public void doAction(String commitMessage, AbstractVCSEntriesTableModel model) { VCSAction action = getModel().getAction(); - VCSFileState[] data = selectData(model, action, false); + List<VCSEntry> entries = model.filter(action, model.getDisplayedEntries(getSelectionModel())); if (action.isCommit()) { getModel().addCommitMessage(commitMessage); @@ -76,10 +67,10 @@ } if (log.isDebugEnabled()) { - log.debug("action:" + action + ", message:" + commitMessage + ", nb files:" + data.length); + log.debug("action:" + action + ", message:" + commitMessage + ", nb files:" + entries.size()); } - actionManager.add(action, data); + getActionManager().add(action, entries.toArray(new VCSEntry[entries.size()]), commitMessage); // dispose ui getUi().dispose(); Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractDiffUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractDiffUIHandler.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractDiffUIHandler.java 2008-04-05 20:37:17 UTC (rev 362) @@ -15,21 +15,16 @@ package org.codelutin.vcs.ui.handler; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSHandler; -import org.codelutin.vcs.ui.model.DiffUIModel; -import org.codelutin.vcs.ui.model.SimpleVCSFileStatesModel; +import org.codelutin.vcs.VCSEntry; import org.codelutin.vcs.ui.VCSUIConstants; +import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; +import org.codelutin.vcs.ui.model.DiffUIModel; import java.beans.PropertyChangeEvent; /** @author chemit */ public abstract class AbstractDiffUIHandler extends AbstractUIHandler<DiffUIModel> { - protected AbstractDiffUIHandler(VCSHandler handler) { - super(handler); - } - public void propertyChange(PropertyChangeEvent evt) { //if (log.isDebugEnabled()) { log.info(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); @@ -37,14 +32,14 @@ String action = evt.getPropertyName(); if (VCSUIConstants.TAB_PROPERTY_CHANGED.equals(action)) { - doSelectTab((SimpleVCSFileStatesModel) evt.getNewValue()); + doSelectTab((AbstractVCSEntriesTableModel) evt.getNewValue()); } else { if (VCSUIConstants.FILE_PROPERTY_CHANGED.equals(action)) { - doSelectFile((VCSFileState) evt.getNewValue()); + doSelectFile((VCSEntry) evt.getNewValue()); } else { try { VCSAction vcsAction = VCSAction.valueOf(action.toUpperCase()); - doAction(vcsAction, (VCSFileState) evt.getNewValue()); + doAction(vcsAction, (VCSEntry) evt.getNewValue()); } catch (IllegalArgumentException e) { // ignore ite } @@ -52,11 +47,11 @@ } } - public abstract void doSelectTab(SimpleVCSFileStatesModel action); + public abstract void doSelectTab(AbstractVCSEntriesTableModel action); - public abstract void doSelectFile(VCSFileState model); + public abstract void doSelectFile(VCSEntry model); - public abstract void doAction(VCSAction action, VCSFileState model); + public abstract void doAction(VCSAction action, VCSEntry model); public abstract void gotoNextDiff(); Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractSynchUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractSynchUIHandler.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractSynchUIHandler.java 2008-04-05 20:37:17 UTC (rev 362) @@ -15,51 +15,38 @@ package org.codelutin.vcs.ui.handler; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSHandler; -import org.codelutin.vcs.ui.model.SimpleVCSFileStatesModel; -import org.codelutin.vcs.ui.model.SynchUIModel; +import org.codelutin.vcs.VCSEntryLocation; import org.codelutin.vcs.ui.VCSUIConstants; +import org.codelutin.vcs.ui.model.SynchUIModel; import java.beans.PropertyChangeEvent; /** @author chemit */ public abstract class AbstractSynchUIHandler extends AbstractUIHandler<SynchUIModel> { - protected AbstractSynchUIHandler(VCSHandler handler) { - super(handler); - } - public void propertyChange(PropertyChangeEvent evt) { //if (log.isDebugEnabled()) { log.info(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); //} String action = evt.getPropertyName(); - SimpleVCSFileStatesModel model = (SimpleVCSFileStatesModel) evt.getNewValue(); + if (VCSUIConstants.TAB_PROPERTY_CHANGED.equals(action)) { - doSelectTabAction(model); + doSelectLocation((VCSEntryLocation) evt.getNewValue()); } else if (action.endsWith("All")) { try { String actionName = action.substring(0, action.length() - 3); VCSAction vcsAction = VCSAction.valueOf(actionName.toUpperCase()); - doAllAction(vcsAction, model); + doAllAction(vcsAction); } catch (IllegalArgumentException e) { // ignore it ? } - } else { - try { - VCSAction vcsAction = VCSAction.valueOf(action.toUpperCase()); - doSelectAction(vcsAction, model); - } catch (IllegalArgumentException e) { - // ignore it ? - } - } } - public abstract void doSelectAction(VCSAction action, SimpleVCSFileStatesModel model); + //public abstract void doSelectAction(VCSAction action); - public abstract void doAllAction(VCSAction action, SimpleVCSFileStatesModel model); + public abstract void doAllAction(VCSAction action); - public abstract void doSelectTabAction(SimpleVCSFileStatesModel action); + public abstract void doSelectLocation(VCSEntryLocation action); } Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractUIHandler.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/AbstractUIHandler.java 2008-04-05 20:37:17 UTC (rev 362) @@ -16,20 +16,18 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.codelutin.vcs.VCSFactory; +import org.codelutin.vcs.runner.VCSActionManager; import org.codelutin.vcs.ui.model.AbstractUIModel; -import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSHandler; -import javax.swing.ListSelectionModel; import javax.swing.JDialog; +import javax.swing.ListSelectionModel; import java.beans.PropertyChangeListener; /** @author chemit */ public abstract class AbstractUIHandler<M extends AbstractUIModel> implements PropertyChangeListener { - protected static Log log = LogFactory.getLog(AbstractConfirmUIHandler.class); + protected static Log log = LogFactory.getLog(AbstractUIHandler.class); public abstract M getModel(); @@ -37,17 +35,6 @@ public abstract ListSelectionModel getSelectionModel(); - /** vcs handler to use (lazy instanciation) */ - protected VCSHandler handler; - - public VCSHandler getHandler() { - return handler; - } - - protected AbstractUIHandler(VCSHandler handler) { - this.handler = handler; - } - public void init() { if (getModel() == null) { throw new IllegalStateException("no model was defined for " + this); @@ -55,9 +42,7 @@ getModel().addPropertyChangeListener(this); } - protected VCSFileState[] selectData(AbstractVCSFileStatesModel model, VCSAction action, boolean b) { - ListSelectionModel selectionModel = getSelectionModel(); - model.select(action, selectionModel, b); - return model.getData(selectionModel); + protected VCSActionManager getActionManager() { + return VCSFactory.getActionManager(); } } Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/VCSAbsractAction.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/VCSAbsractAction.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/handler/VCSAbsractAction.java 2008-04-05 20:37:17 UTC (rev 362) @@ -17,7 +17,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSHandler; import javax.swing.AbstractAction; @@ -28,19 +27,13 @@ protected VCSAction action; - protected transient VCSHandler handler; - private static final long serialVersionUID = 1074145285171920255L; - public VCSAbsractAction(VCSHandler handler) { - this.handler = handler; + public VCSAbsractAction() { } public void setAction(VCSAction action) { this.action = action; } - public VCSHandler getHandler() { - return handler; - } } Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractUIModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractUIModel.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractUIModel.java 2008-04-05 20:37:17 UTC (rev 362) @@ -16,8 +16,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSHandler; +import org.codelutin.vcs.VCSConnexion; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; +import org.codelutin.vcs.VCSException; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -29,28 +31,35 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static protected final Log log = LogFactory.getLog(AbstractUIModel.class); - /** support for change properties support */ protected PropertyChangeSupport changeSupport; + protected final AbstractVCSEntriesTableModel model; - public abstract void setData(List<VCSFileState> states); + protected AbstractUIModel() { + model = new SimpleVCSEntriesTableModelImpl(getClass().getSimpleName()); + } - public abstract void addData(List<VCSFileState> states); + public AbstractVCSEntriesTableModel getModel() { + return model; + } - public abstract void removeData(List<VCSFileState> states); + public void populate(VCSConnexion connexion) throws VCSException { + getModel().populate(connexion, System.nanoTime()); + } - 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); - } - } + public void populate(VCSConnexion connexion, List<String> relativeLocalPaths, VCSEntryLocation location) throws VCSException { + getModel().populate(connexion, relativeLocalPaths, location, System.nanoTime()); } + public void populate(VCSEntryLocation location, VCSEntry[] datas) { + getModel().populate(location, datas); + } + + public void refresh(List<VCSEntry> entries) { + getModel().refresh(entries, System.nanoTime()); + } + public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { if (listener == null) { return; Copied: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSEntriesTableModel.java (from rev 345, 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/AbstractVCSEntriesTableModel.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/AbstractVCSEntriesTableModel.java 2008-04-05 20:37:17 UTC (rev 362) @@ -0,0 +1,187 @@ +/* +* ##% 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.VCSConnexion; +import org.codelutin.vcs.VCSEntries; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; +import org.codelutin.vcs.VCSException; +import org.codelutin.vcs.VCSState; +import org.codelutin.vcs.util.VCSEntriesImpl; + +import javax.swing.ListSelectionModel; +import java.util.ArrayList; +import java.util.List; + +/** + * Simple Table model to display list of VCSFileState + * + * @author chemit + */ +public abstract class AbstractVCSEntriesTableModel extends javax.swing.table.AbstractTableModel implements VCSEntries { + + protected final String name; + + /** column names */ + protected final String[] columnNames; + + protected VCSEntryLocation location; + + /** delegate model */ + protected final transient VCSEntries delegate; + + /** displayed entries */ + protected final transient List<VCSEntry> displayedEntries; + + private static final long serialVersionUID = 4697917831388337369L; + + protected AbstractVCSEntriesTableModel(String name, String[] columnNames) { + super(); + this.name = name; + this.columnNames = columnNames; + this.displayedEntries = new ArrayList<VCSEntry>(); + this.delegate = new VCSEntriesImpl(); + } + + public String getName() { + return name; + } + + public VCSEntryLocation getLocation() { + return location; + } + + public List<VCSEntry> getDisplayedEntries(ListSelectionModel selectionModel) { + return selectionModel == null ? new ArrayList<VCSEntry>(displayedEntries) : filter(selectionModel, displayedEntries); + } + + public int getColumnCount() { + return columnNames.length; + } + + public int getRowCount() { + return displayedEntries.size(); + } + + @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 setLocation(VCSEntryLocation location) { + this.location = location; + displayedEntries.clear(); + displayedEntries.addAll(filter(location, getEntries())); + fireTableDataChanged(); + } + + public VCSAction[] getActions(ListSelectionModel selectionModel) { + return getActions(getDisplayedEntries(selectionModel)); + } + + @Override + public String toString() { + return super.toString() + "<name:" + name + ", size:" + (getRowCount()) + '>'; + } + + //===================================================================================================// + // === delegate methods =============================================================================// + //===================================================================================================// + + public List<VCSEntry> getEntries() { + return delegate.getEntries(); + } + + public List<VCSEntry> filter(VCSAction action, List<VCSEntry> entries) { + return delegate.filter(action, entries); + } + + public List<VCSEntry> filter(VCSConnexion connexion, List<VCSEntry> entries) { + return delegate.filter(connexion, entries); + } + + public List<VCSEntry> filter(VCSEntryLocation location, List<VCSEntry> entries) { + return delegate.filter(location, entries); + } + + public List<VCSEntry> filter(VCSState state, List<VCSEntry> entries) { + return delegate.filter(state, entries); + } + + public List<VCSEntry> filter(ListSelectionModel selectionModel, List<VCSEntry> entries) { + return delegate.filter(selectionModel, entries); + } + + public void populate(VCSConnexion connexion, long timestamp) throws VCSException { + delegate.populate(connexion, timestamp); + updateEntries(); + } + + public void populate(VCSConnexion connexion, List<String> relativeLocalPaths, VCSEntryLocation location, long timestamp) throws VCSException { + delegate.populate(connexion, relativeLocalPaths, location, timestamp); + updateEntries(); + } + + public void populate(VCSEntryLocation location, VCSEntry[] states) { + clear(); + this.location = location; + delegate.populate(location, states); + updateEntries(); + } + + public void refresh(List<VCSEntry> entries, long timestamp) throws IllegalStateException { + delegate.refresh(entries, timestamp); + updateEntries(); + } + + public VCSAction[] getActions(List<VCSEntry> entries) { + return delegate.getActions(entries); + } + + public VCSState[] getStates(List<VCSEntry> entries) { + return delegate.getStates(entries); + } + + public void clear() { + delegate.clear(); + displayedEntries.clear(); + fireTableDataChanged(); + } + + protected void updateEntries() { + displayedEntries.clear(); + displayedEntries.addAll(filter(location, delegate.getEntries())); + fireTableDataChanged(); + } +} \ No newline at end of file Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/ConfirmUIModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/ConfirmUIModel.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/ConfirmUIModel.java 2008-04-05 20:37:17 UTC (rev 362) @@ -15,9 +15,9 @@ package org.codelutin.vcs.ui.model; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; import static org.codelutin.vcs.ui.VCSUIConstants.ACTION_PROPERTY_CHANGED; -import static org.codelutin.vcs.ui.VCSUIConstants.CONFIRM_MODEL_PROPERTY; import static org.codelutin.vcs.ui.VCSUIConstants.MESSAGE_HISTORY_PROPERTY_CHANGED; import java.util.ArrayList; @@ -30,22 +30,12 @@ */ public class ConfirmUIModel extends AbstractUIModel { - /** list of states */ - protected SimpleVCSFileStatesModel model; - /** history of commit messages */ protected List<String> commitMessages; /** current action to fired */ protected VCSAction action; - public AbstractVCSFileStatesModel getModel() { - if (model == null) { - model = new SimpleVCSFileStatesModel(CONFIRM_MODEL_PROPERTY); - } - return model; - } - public VCSAction getAction() { return action; } @@ -57,12 +47,6 @@ return commitMessages; } - public void setAction(VCSAction action) { - this.action = action; - // never propagate old action, since need always the property changed - firePropertyChange(ACTION_PROPERTY_CHANGED, null, action); - } - public void addCommitMessage(String commitMessage) { if (commitMessage != null && !commitMessage.isEmpty() && !getCommitMessages().contains(commitMessage)) { // add message in history @@ -71,16 +55,11 @@ } } - public void setData(List<VCSFileState> states) { - getModel().setData(states); + public void init(VCSAction action, VCSEntryLocation location, VCSEntry[] states) { + this.action = action; + model.clear(); + model.populate(location, states); + // never propagate old action, since need always the property changed + firePropertyChange(ACTION_PROPERTY_CHANGED, null, action); } - - public void addData(List<VCSFileState> states) { - getModel().addData(states.toArray(new VCSFileState[states.size()])); - } - - public void removeData(List<VCSFileState> states) { - getModel().removeData(states.toArray(new VCSFileState[states.size()])); - } - } \ No newline at end of file Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffPanelUIModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffPanelUIModel.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffPanelUIModel.java 2008-04-05 20:37:17 UTC (rev 362) @@ -17,7 +17,7 @@ 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.VCSEntry; import org.codelutin.vcs.VCSHandler; import java.beans.PropertyChangeListener; @@ -44,7 +44,7 @@ protected VCSHandler handler; /** map of models */ - protected VCSFileState model; + protected VCSEntry model; /** support for change properties support */ protected PropertyChangeSupport changeSupport; Modified: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffUIModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffUIModel.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/DiffUIModel.java 2008-04-05 20:37:17 UTC (rev 362) @@ -15,16 +15,10 @@ package org.codelutin.vcs.ui.model; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; import org.codelutin.vcs.ui.VCSUIConstants; -import static org.codelutin.vcs.ui.VCSUIConstants.SYNCH_ALL_MODEL_PROPERTY; -import static org.codelutin.vcs.ui.VCSUIConstants.SYNCH_LOCAL_MODEL_PROPERTY; -import static org.codelutin.vcs.ui.VCSUIConstants.SYNCH_REMOTE_MODEL_PROPERTY; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - /** * Model of a repository * @@ -32,122 +26,40 @@ */ public class DiffUIModel extends AbstractUIModel { - /** local root : wroking copy */ - protected URL leftRoot; - /** remote root : remote url */ - protected URL rightRoot; - - /** map of models */ - protected List<SimpleVCSFileStatesModel> models; - - /** current tab displayed */ - protected AbstractVCSFileStatesModel tabModel; - /** current file displayed */ - protected VCSFileState fileModel; + protected VCSEntry fileModel; /** current action to fired */ protected VCSAction action; - public DiffUIModel() { - } + private VCSEntryLocation location; - public DiffUIModel(URL leftRoot, URL rightRoot) { - this.leftRoot = leftRoot; - this.rightRoot = rightRoot; + public void setLocation(VCSEntryLocation location) { + VCSEntryLocation oldLocation = this.location; + getModel().setLocation(location); + this.location = location; + firePropertyChange(VCSUIConstants.TAB_PROPERTY_CHANGED, oldLocation, location); } - public AbstractVCSFileStatesModel getTabModel() { - return tabModel; - } - public void setTabModel(AbstractVCSFileStatesModel tabModel) { - AbstractVCSFileStatesModel oldTabModel = this.tabModel; - this.tabModel = tabModel; - firePropertyChange(VCSUIConstants.TAB_PROPERTY_CHANGED, oldTabModel, tabModel); - } - - public void setFileModel(VCSFileState fileModel) { - VCSFileState oldFileModel = this.fileModel; + public void setFileModel(VCSEntry fileModel) { + VCSEntry oldFileModel = this.fileModel; this.fileModel = fileModel; - firePropertyChange(VCSUIConstants.TAB_PROPERTY_CHANGED, oldFileModel, tabModel); + firePropertyChange(VCSUIConstants.TAB_PROPERTY_CHANGED, oldFileModel, fileModel); } - public AbstractVCSFileStatesModel getTabModel(String tabModel) { - return getModel(tabModel); - } - - public void setLeftRoot(URL leftRoot) { - this.leftRoot = leftRoot; - } - - public void setRightRoot(URL rightRoot) { - this.rightRoot = rightRoot; - } - - public SimpleVCSFileStatesModel getModel(String modelName) { - SimpleVCSFileStatesModel tableModel = null; - for (SimpleVCSFileStatesModel model : getModels()) { - if (modelName.equals(model.getName())) { - tableModel = model; - break; - } - } - if (tableModel == null) { - getModels().add(tableModel = new SimpleVCSFileStatesModel(modelName)); - } - return tableModel; - } - public void doAllAction(VCSAction action) { - if (tabModel == null) { - return; - } this.action = action; - firePropertyChange(action.name().toLowerCase() + "All", null, tabModel); + firePropertyChange(action.name().toLowerCase() + "All", null, model); } - public void setData(List<VCSFileState> states) { - getModel(SYNCH_ALL_MODEL_PROPERTY).setData(states); - List<VCSFileState> local = new ArrayList<VCSFileState>(); - List<VCSFileState> remote = new ArrayList<VCSFileState>(); - splitStates(states, local, remote); - getModel(SYNCH_LOCAL_MODEL_PROPERTY).setData(local); - getModel(SYNCH_REMOTE_MODEL_PROPERTY).setData(remote); - } - - public void addData(List<VCSFileState> states) { - getModel(SYNCH_ALL_MODEL_PROPERTY).setData(states); - List<VCSFileState> local = new ArrayList<VCSFileState>(); - List<VCSFileState> remote = new ArrayList<VCSFileState>(); - splitStates(states, local, remote); - getModel(SYNCH_LOCAL_MODEL_PROPERTY).addData(local.toArray(new VCSFileState[local.size()])); - getModel(SYNCH_REMOTE_MODEL_PROPERTY).addData(remote.toArray(new VCSFileState[remote.size()])); - } - - public void removeData(List<VCSFileState> states) { - getModel(SYNCH_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(SYNCH_LOCAL_MODEL_PROPERTY).removeData(local.toArray(new VCSFileState[local.size()])); - getModel(SYNCH_REMOTE_MODEL_PROPERTY).removeData(remote.toArray(new VCSFileState[remote.size()])); - } - public void doAction(VCSAction action) { - if (tabModel == null) { - return; - } this.action = action; - firePropertyChange(action.name().toLowerCase(), null, tabModel); + firePropertyChange(action.name().toLowerCase(), null, model); } - protected List<SimpleVCSFileStatesModel> getModels() { - if (models == null) { - models = new ArrayList<SimpleVCSFileStatesModel>(); - } - return models; + public VCSEntryLocation getLocation() { + return location; } - } \ No newline at end of file Added: trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSEntriesTableModelImpl.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSEntriesTableModelImpl.java (rev 0) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SimpleVCSEntriesTableModelImpl.java 2008-04-05 20:37:17 UTC (rev 362) @@ -0,0 +1,52 @@ +/** + * # #% 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.VCSEntry; +import org.codelutin.vcs.VCSState; +import org.codelutin.vcs.ui.VCSUIConstants; + +/** @author chemit */ +public class SimpleVCSEntriesTableModelImpl extends AbstractVCSEntriesTableModel { + + private static final long serialVersionUID = -6397327068709720165L; + + protected SimpleVCSEntriesTableModelImpl(String name) { + + super(name, VCSUIConstants.SIMPLE_COLUMNS_NAMES); + } + + public Object getValueAt(int rowIndex, int columnIndex) { + if (getRowCount() == 0) { + return null; + } + VCSEntry item = displayedEntries.get(rowIndex); + Object result = null; + if (columnIndex == 0) { + // get module + result = item.getRelativeLocalPath(); + } 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/SynchUIModel.java =================================================================== --- trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchUIModel.java 2008-04-05 20:37:02 UTC (rev 361) +++ trunk/lutinvcs/lutinvcs-core/src/main/java/org/codelutin/vcs/ui/model/SynchUIModel.java 2008-04-05 20:37:17 UTC (rev 362) @@ -15,17 +15,9 @@ package org.codelutin.vcs.ui.model; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.VCSEntryLocation; import org.codelutin.vcs.ui.VCSUIConstants; -import static org.codelutin.vcs.ui.VCSUIConstants.SYNCH_ALL_MODEL_PROPERTY; -import static org.codelutin.vcs.ui.VCSUIConstants.SYNCH_LOCAL_MODEL_PROPERTY; -import static org.codelutin.vcs.ui.VCSUIConstants.SYNCH_REMOTE_MODEL_PROPERTY; -import java.io.File; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - /** * Model of a repository * @@ -33,106 +25,18 @@ */ public class SynchUIModel extends AbstractUIModel { - /** local root : wroking copy */ - protected File localRoot; - - /** remote root : remote url */ - protected URL remoteRoot; - - /** map of models */ - protected List<SimpleVCSFileStatesModel> models; - - /** current tab displayed */ - protected AbstractVCSFileStatesModel tabModel; - - /** current action to fired */ + /** current action to be fired */ protected VCSAction action; - public SynchUIModel() { + public void setLocation(VCSEntryLocation location) { + VCSEntryLocation oldLocation = getModel().getLocation(); + getModel().setLocation(location); + firePropertyChange(VCSUIConstants.TAB_PROPERTY_CHANGED, oldLocation, location); } - public SynchUIModel(File localRoot, URL remoteRoot) { - this.localRoot = localRoot; - this.remoteRoot = remoteRoot; - } - - public AbstractVCSFileStatesModel getTabModel() { - return tabModel; - } - - public void setTabModel(AbstractVCSFileStatesModel tabModel) { - AbstractVCSFileStatesModel oldTabModel = this.tabModel; - this.tabModel = tabModel; - firePropertyChange(VCSUIConstants.TAB_PROPERTY_CHANGED, oldTabModel, tabModel); - } - - public AbstractVCSFileStatesModel getTabModel(String tabModel) { - return getModel(tabModel); - } - - public void setLocalRoot(File localRoot) { - this.localRoot = localRoot; - } - - public void setRemoteRoot(URL remoteRoot) { - this.remoteRoot = remoteRoot; - } - - public SimpleVCSFileStatesModel getModel(String modelName) { - SimpleVCSFileStatesModel tableModel = null; - for (SimpleVCSFileStatesModel model : getModels()) { - if (modelName.equals(model.getName())) { - tableModel = model; - break; - } - } - if (tableModel == null) { - getModels().add(tableModel = new SimpleVCSFileStatesModel(modelName)); - } - return tableModel; - } - - public void setData(List<VCSFileState> states) { - getModel(SYNCH_ALL_MODEL_PROPERTY).setData(states); - List<VCSFileState> local = new ArrayList<VCSFileState>(); - List<VCSFileState> remote = new ArrayList<VCSFileState>(); - splitStates(states, local, remote); - getModel(SYNCH_LOCAL_MODEL_PROPERTY).setData(local); - getModel(SYNCH_REMOTE_MODEL_PROPERTY).setData(remote); - } - - public void addData(List<VCSFileState> states) { - getModel(SYNCH_ALL_MODEL_PROPERTY).setData(states); - List<VCSFileState> local = new ArrayList<VCSFileState>(); - List<VCSFileState> remote = new ArrayList<VCSFileState>(); - splitStates(states, local, remote); - getModel(SYNCH_LOCAL_MODEL_PROPERTY).addData(local.toArray(new VCSFileState[local.size()])); - getModel(SYNCH_REMOTE_MODEL_PROPERTY).addData(remote.toArray(new VCSFileState[remote.size()])); - } - - public void removeData(List<VCSFileState> states) { - getModel(SYNCH_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(SYNCH_LOCAL_MODEL_PROPERTY).removeData(local.toArray(new VCSFileState[local.size()])); - getModel(SYNCH_REMOTE_MODEL_PROPERTY).removeData(remote.toArray(new VCSFileState[remote.size()])); - } - public void doAllAction(VCSAction action) { - if (tabModel == null) { - return; - } this.action = action; - firePropertyChange(action.name().toLowerCase() + "All", null, tabModel); + firePropertyChange(action.name().toLowerCase() + "All", null, model); } - protected List<SimpleVCSFileStatesModel> getModels() { - if (models == null) { - models = new ArrayList<SimpleVCSFileStatesModel>(); - } - return models; - } - - }
participants (1)
-
tchemit@users.labs.libre-entreprise.org