Author: tchemit Date: 2008-04-05 20:40:12 +0000 (Sat, 05 Apr 2008) New Revision: 365 Modified: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSPopupAction.java trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java Log: refactor PRovider, Handler and Connexion Modified: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java 2008-04-05 20:37:48 UTC (rev 364) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java 2008-04-05 20:40:12 UTC (rev 365) @@ -15,7 +15,6 @@ package org.codelutin.vcs.ui; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSHandler; import org.codelutin.vcs.ui.handler.AbstractConfirmUIHandler; import org.codelutin.vcs.ui.model.ConfirmUIModel; @@ -26,8 +25,7 @@ protected final JConfirmUI ui; - public ConfirmUIHandler(VCSHandler handler) { - super(handler); + public ConfirmUIHandler() { this.ui = new JConfirmUI(this); } @@ -47,7 +45,7 @@ VCSAction action = ui.getModel().getAction(); ui.getAccept().setText(action.getLibelle()); ui.getToolbar().setVisible(action.isCommit()); - ui.getHandler().getSelectionModel().setSelectionInterval(0, getModel().getModel().size() - 1); + ui.getHandler().getSelectionModel().setSelectionInterval(0, getModel().getModel().getRowCount() - 1); } protected void updateMessageUI() { Modified: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java 2008-04-05 20:37:48 UTC (rev 364) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java 2008-04-05 20:40:12 UTC (rev 365) @@ -15,12 +15,10 @@ package org.codelutin.vcs.ui; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSHandler; +import org.codelutin.vcs.VCSEntry; import org.codelutin.vcs.ui.handler.AbstractDiffUIHandler; -import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; +import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; import org.codelutin.vcs.ui.model.DiffUIModel; -import org.codelutin.vcs.ui.model.SimpleVCSFileStatesModel; import javax.swing.ListSelectionModel; @@ -29,8 +27,7 @@ protected final JDiffUI ui; - public DiffUIHandler(VCSHandler handler) { - super(handler); + public DiffUIHandler() { this.ui = new JDiffUI(this); } @@ -43,17 +40,17 @@ } public ListSelectionModel getSelectionModel() { - AbstractVCSFileStatesModel tabModel = getModel().getTabModel(); - return tabModel == null ? null : ui.getTable(tabModel.getName()).getSelectionModel(); + AbstractVCSEntriesTableModel tabModel = getModel().getModel(); + return tabModel == null ? null : ui.getTable(tabModel.getLocation().name().toLowerCase()).getSelectionModel(); } - public void doSelectTab(SimpleVCSFileStatesModel action) { + public void doSelectTab(AbstractVCSEntriesTableModel action) { } - public void doSelectFile(VCSFileState model) { + public void doSelectFile(VCSEntry model) { } - public void doAction(VCSAction action, VCSFileState model) { + public void doAction(VCSAction action, VCSEntry model) { } public void gotoNextDiff() { Modified: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java 2008-04-05 20:37:48 UTC (rev 364) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java 2008-04-05 20:40:12 UTC (rev 365) @@ -1,30 +1,25 @@ package org.codelutin.vcs.ui; import org.codelutin.vcs.VCSAction; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSHandler; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; import org.codelutin.vcs.ui.handler.AbstractSynchUIHandler; -import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; -import org.codelutin.vcs.ui.model.SimpleVCSFileStatesModel; +import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; import org.codelutin.vcs.ui.model.SynchUIModel; import javax.swing.JTable; import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @author chemit */ -public class SynchUIHandler extends AbstractSynchUIHandler implements ListSelectionListener { +public class SynchUIHandler extends AbstractSynchUIHandler { protected final JSynchUI ui; - public SynchUIHandler(VCSHandler handler) { - super(handler); + public SynchUIHandler() { this.ui = new JSynchUI(this); } @@ -35,9 +30,9 @@ @Override public void init() { super.init(); - initTab(VCSUIConstants.SYNCH_ALL_MODEL_PROPERTY); - initTab(VCSUIConstants.SYNCH_LOCAL_MODEL_PROPERTY); - initTab(VCSUIConstants.SYNCH_REMOTE_MODEL_PROPERTY); + initTab(VCSEntryLocation.ALL); + initTab(VCSEntryLocation.LOCAL); + initTab(VCSEntryLocation.REMOTE); } public SynchUIModel getModel() { @@ -45,53 +40,45 @@ } public ListSelectionModel getSelectionModel() { - AbstractVCSFileStatesModel tabModel = getModel().getTabModel(); - return tabModel == null ? null : ui.getTable(tabModel.getName()).getSelectionModel(); + return ui.getTable(getModel().getModel().getLocation().name().toLowerCase()).getSelectionModel(); } - public void doAllAction(VCSAction action, SimpleVCSFileStatesModel model) { + public void doAllAction(VCSAction action) { + AbstractVCSEntriesTableModel model = getModel().getModel(); log.info(action + " : " + model); - JTable table = ui.getTable(model.getName()); - ListSelectionModel selectionModel = table.getSelectionModel(); + ListSelectionModel selectionModel = getSelectionModel(); if (action == VCSAction.REFRESH) { selectionModel.clearSelection(); // do refresh of all states - log.info("refresh :" + model.size()); - model.refresh(model.getStates()); + log.info("refresh :" + model.getRowCount()); + model.refresh(model.getEntries(), System.nanoTime()); } else { - model.select(action, selectionModel, true); - // do action on selected items - doSelectAction(action, model); - } - } + List<VCSEntry> entries = model.filter(action, model.getDisplayedEntries(null)); + if (entries.isEmpty()) { + // nothing to do + return; + } + if (action == VCSAction.DIFF) { + // show diff ui + return; + } + log.info("files to treate :" + entries.size()); + JConfirmUI confirmUI = VCSUIFactory.newConfirmUI(); - public void doSelectAction(VCSAction action, SimpleVCSFileStatesModel model) { - log.info(action + " : " + model); - JTable table = ui.getTable(model.getName()); - ListSelectionModel selectionModel = table.getSelectionModel(); - if (selectionModel.isSelectionEmpty()) { - // nothing to do - return; + confirmUI.getModel().init(action, model.getLocation(), entries.toArray(new VCSEntry[entries.size()])); + + confirmUI.setVisible(true); + //TODO SynchModel should listener for modification on ActionManagerQueue thread + log.info("TODO refresh states for files..."); } - if (action == VCSAction.DIFF) { - // show diff ui - return; - } - VCSFileState[] states = model.getData(selectionModel); - log.info("files to treate :" + states.length); - JConfirmUI confirmUI = VCSUIFactory.newConfirmUI(getHandler(), Arrays.asList(states)); - confirmUI.getModel().setAction(action); - confirmUI.setVisible(true); - //TODO SynchModel should listener for modification on ActionManagerQueue thread - log.info("TODO refresh states for files..."); } - public void doSelectTabAction(SimpleVCSFileStatesModel model) { - log.info(model); - String tabModelName = model.getName(); - ui.cardLayout.show(ui.preview, tabModelName); - VCSAction[] actions = model.getActions(); + public void doSelectLocation(VCSEntryLocation location) { + log.info(location); + + ui.cardLayout.show(ui.preview, location.name().toLowerCase() + "Content"); + VCSAction[] actions = getModel().getModel().getActions((ListSelectionModel) null); List<String> acts = new ArrayList<String>(); for (VCSAction action : actions) { acts.add(action.name().toLowerCase()); @@ -105,42 +92,31 @@ ui.getRefreshAll().setEnabled(hasActions); } - public void valueChanged(ListSelectionEvent e) { - ListSelectionModel list = (ListSelectionModel) e.getSource(); - if (!list.getValueIsAdjusting() && log.isDebugEnabled()) { - log.debug(list); - } - } - - private void initTab(String modelName) { - JTable table = ui.getTable(modelName); - SimpleVCSFileStatesModel fileStatesModel = getModel().getModel(modelName); + private void initTab(VCSEntryLocation location) { + String s = location.name().toLowerCase(); + JTable table = ui.getTable(s); + AbstractVCSEntriesTableModel fileStatesModel = getModel().getModel(); table.setModel(fileStatesModel); - table.getSelectionModel().addListSelectionListener(this); - table.addMouseListener(new ListMouseListener(ui, fileStatesModel)); - JVCSPopup jvcsPopup = ui.getPopup(modelName); - jvcsPopup.setDispatchAction(new VCSPopupAction(ui, modelName)); + table.addMouseListener(new ListMouseListener(ui, fileStatesModel, s)); + JVCSPopup jvcsPopup = ui.getPopup(s); + jvcsPopup.setDispatchAction(new VCSPopupAction(ui, location)); } private class ListMouseListener extends MouseAdapter { - private final AbstractVCSFileStatesModel model; + private final AbstractVCSEntriesTableModel model; private final ListSelectionModel selectionModel; private final JTable jTable; private final JVCSPopup jPopupMenu; - public ListMouseListener(JSynchUI ui, AbstractVCSFileStatesModel model) { + public ListMouseListener(JSynchUI ui, AbstractVCSEntriesTableModel model, String modelName) { this.model = model; - String modelName = model.getName(); - jPopupMenu = ui.getPopup(modelName); jTable = ui.getTable(modelName); selectionModel = jTable.getSelectionModel(); - // init actions - } @Override Modified: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSPopupAction.java =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSPopupAction.java 2008-04-05 20:37:48 UTC (rev 364) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSPopupAction.java 2008-04-05 20:40:12 UTC (rev 365) @@ -15,13 +15,14 @@ package org.codelutin.vcs.ui; 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.handler.VCSAbsractAction; -import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; +import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; import javax.swing.ListSelectionModel; import java.awt.event.ActionEvent; -import java.util.Arrays; +import java.util.List; /** * Action of a clik inside the popup menu @@ -31,30 +32,38 @@ public class VCSPopupAction extends VCSAbsractAction { private static final long serialVersionUID = -1983061535956510913L; - protected AbstractVCSFileStatesModel model; + protected VCSEntryLocation location; protected transient ListSelectionModel selectionModel; - public VCSPopupAction(JSynchUI ui, String modelName) { - super(ui.getHandler().getHandler()); - this.model = ui.getModel().getModel(modelName); - this.selectionModel = ui.getTable(modelName).getSelectionModel(); + protected transient JSynchUI ui; + + protected AbstractVCSEntriesTableModel tableModel; + + public VCSPopupAction(JSynchUI ui, VCSEntryLocation location) { + super(); + this.ui = ui; + this.location = location; + //this.selectionModel = ui.getHandler().getSelectionModel(); + this.selectionModel = ui.getTable(location.name().toLowerCase()).getSelectionModel(); + tableModel = ui.getModel().getModel(); } public void actionPerformed(ActionEvent e) { // select only lines for this action inside already selected lines - model.select(action, selectionModel, false); - // obtain thoses lines - VCSFileState[] states = model.getData(selectionModel); - log.info("action: " + action + ", files to treate :" + states.length); + List<VCSEntry> entries = tableModel.filter(action, tableModel.getDisplayedEntries(selectionModel)); + log.info("action: " + action + ", files to treate :" + entries.size() + " " + selectionModel); if (action == VCSAction.DIFF) { // show diff ui + ui.getModel().refresh(entries); + } else if (action == VCSAction.REFRESH) { // refresh ui, and update list if needed + } else { // show confirm action ui - JConfirmUI confirmUI = VCSUIFactory.newConfirmUI(getHandler(), Arrays.asList(states)); - confirmUI.getModel().setAction(action); - confirmUI.getHandler().getSelectionModel().setSelectionInterval(0, states.length - 1); + JConfirmUI confirmUI = VCSUIFactory.newConfirmUI(); + confirmUI.getModel().init(action, tableModel.getLocation(), entries.toArray(new VCSEntry[entries.size()])); + confirmUI.getHandler().getSelectionModel().setSelectionInterval(0, entries.size() - 1); confirmUI.setVisible(true); } } Modified: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-05 20:37:48 UTC (rev 364) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-05 20:40:12 UTC (rev 365) @@ -14,43 +14,36 @@ */ package org.codelutin.vcs.ui; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSHandler; import org.codelutin.vcs.ui.handler.AbstractUIHandler; -import java.lang.reflect.InvocationTargetException; import java.util.HashMap; -import java.util.List; import java.util.Map; -/** @author chemit */ +/** + * Factory if VCS UI, using a cache. + * + * @author chemit + */ public class VCSUIFactory { protected static Map<Class<? extends AbstractUIHandler>, AbstractUIHandler> cache; - public static Map<Class<? extends AbstractUIHandler>, AbstractUIHandler> getCache() { - if (cache == null) { - cache = new HashMap<Class<? extends AbstractUIHandler>, AbstractUIHandler>(); - } - return cache; - } - protected static JSynchUI synchUI; protected static JDiffUI diffUI; protected static JConfirmUI confirmUI; - public static JSynchUI newSynchUI(VCSHandler handler, List<VCSFileState> states) { - SynchUIHandler result = newHandler(handler, SynchUIHandler.class, states); + public static JSynchUI newSynchUI() { + SynchUIHandler result = newHandler(SynchUIHandler.class); return result.getUi(); } - public static JDiffUI newDiffUI(VCSHandler handler, List<VCSFileState> states) { - DiffUIHandler result = newHandler(handler, DiffUIHandler.class, states); + public static JDiffUI newDiffUI() { + DiffUIHandler result = newHandler(DiffUIHandler.class); return result.getUi(); } - public static JConfirmUI newConfirmUI(VCSHandler handler, List<VCSFileState> states) { - ConfirmUIHandler result = newHandler(handler, ConfirmUIHandler.class, states); + public static JConfirmUI newConfirmUI() { + ConfirmUIHandler result = newHandler(ConfirmUIHandler.class); return result.getUi(); } @@ -61,26 +54,28 @@ cache = null; } + protected static Map<Class<? extends AbstractUIHandler>, AbstractUIHandler> getCache() { + if (cache == null) { + cache = new HashMap<Class<? extends AbstractUIHandler>, AbstractUIHandler>(); + } + return cache; + } + @SuppressWarnings({"unchecked"}) - protected static <H extends AbstractUIHandler> H newHandler(VCSHandler handler, Class<H> klass, List<VCSFileState> states) { + protected static <H extends AbstractUIHandler> H newHandler(Class<H> klass) { H result; result = (H) getCache().get(klass); if (result == null) { try { - result = klass.getConstructor(VCSHandler.class).newInstance(handler); + result = klass.newInstance(); result.init(); getCache().put(klass, result); } catch (InstantiationException e) { throw new IllegalStateException("could not instanciate ui handler " + klass + " for reason : " + e.getMessage()); } catch (IllegalAccessException e) { throw new IllegalStateException("could not instanciate ui handler " + klass + " for reason : " + e.getMessage()); - } catch (InvocationTargetException e) { - throw new IllegalStateException("could not instanciate ui handler " + klass + " for reason : " + e.getMessage()); - } catch (NoSuchMethodException e) { - throw new IllegalStateException("could not instanciate ui handler " + klass + " for reason : " + e.getMessage()); } } - result.getModel().setData(states); return result; } Modified: trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java 2008-04-05 20:37:48 UTC (rev 364) +++ trunk/lutinvcs/lutinvcs-ui/src/test/java/org/codelutin/vcs/ui/UITest.java 2008-04-05 20:40:12 UTC (rev 365) @@ -14,13 +14,17 @@ */ package org.codelutin.vcs.ui; -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.VCSFileStateImpl; -import org.codelutin.vcs.VCSHandler; -import org.codelutin.vcs.VCSHandlerFactory; +import org.codelutin.i18n.I18n; +import org.codelutin.vcs.VCSConnexion; +import org.codelutin.vcs.VCSConnexionMode; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.VCSEntryLocation; +import org.codelutin.vcs.VCSFactory; import org.codelutin.vcs.VCSState; -import org.codelutin.vcs.impl.mock.MockVCSConfig; +import org.codelutin.vcs.VCSType; import org.codelutin.vcs.ui.model.SynchUIModel; +import org.codelutin.vcs.util.VCSConnexionConfigImpl; +import org.codelutin.vcs.util.VCSEntryImpl; import java.io.File; import java.util.ArrayList; @@ -33,52 +37,57 @@ static java.util.Random r = new java.util.Random(); public static void main(String[] args) { - org.codelutin.i18n.I18n.init(); - File root = new File(new File("").getAbsolutePath()); + I18n.init(); - VCSHandler handler = initVCS(root); + VCSConnexion connexion = initVCS(new File(new File("").getAbsolutePath())); - List<VCSFileState> datas = generateListFileStates(handler, 50, "trunk", "local/", "remote/"); + try { + connexion.open(); - JSynchUI synchUI = VCSUIFactory.newSynchUI(handler, datas); + JSynchUI ui = VCSUIFactory.newSynchUI(); - synchUI.setVisible(true); + fillSynchModel(connexion, ui.getModel(), 20, "trunk", "local/", "remote/"); - handler.close(); + ui.setVisible(true); + + } finally { + connexion.close(); + } } - public static VCSHandler initVCS(File root) { - MockVCSConfig config = new MockVCSConfig(); - config.setLocalRoot(root); - config.setInit(true); - VCSHandlerFactory.setConfig(config); - return VCSHandlerFactory.getHandler(); + public static VCSConnexion initVCS(File root) { + VCSConnexionConfigImpl config = new VCSConnexionConfigImpl(); + config.setType(VCSType.MOCK); + config.setLocalDatabasePath(root); + VCSConnexion connexion = VCSFactory.newConnexion(VCSConnexionMode.ANONYMOUS, config); + connexion.init(config); + return connexion; } - protected static void fillSynchModel(VCSHandler handler, SynchUIModel model, int max, String prefix, String localPRefix, String remotePrefix) { - List<VCSFileState> datas = generateListFileStates(handler, max, prefix, localPRefix, remotePrefix); - model.setData(datas); + protected static void fillSynchModel(VCSConnexion handler, SynchUIModel model, int max, String prefix, String localPRefix, String remotePrefix) { + List<VCSEntry> datas = generateListFileStates(handler, max, prefix, localPRefix, remotePrefix); + model.populate(VCSEntryLocation.UNKNOW, datas.toArray(new VCSEntry[datas.size()])); } - private static List<VCSFileState> generateListFileStates(VCSHandler handler, int max, String prefix, String localPRefix, String remotePrefix) { - List<VCSFileState> datas = generateLocalFileStates(handler, max, new File(handler.getConfig().getLocalDatabasePath(), prefix), localPRefix); + protected static List<VCSEntry> generateListFileStates(VCSConnexion handler, int max, String prefix, String localPRefix, String remotePrefix) { + List<VCSEntry> datas = generateLocalFileStates(handler, max, new File(handler.getConfig().getLocalDatabasePath(), prefix), localPRefix); datas.addAll(generateRemoteFileStates(handler, max, new File(handler.getConfig().getLocalDatabasePath(), prefix), remotePrefix)); return datas; } - protected static List<VCSFileState> generateLocalFileStates(VCSHandler handler, int max, File root, String localPRefix) { + protected static List<VCSEntry> generateLocalFileStates(VCSConnexion handler, int max, File root, String localPRefix) { return generateFileStates(handler, root, max, localPRefix, VCSState.MODIFIED, VCSState.UNVERSIONNED, VCSState.OUT_OF_DATE_AND_MODIFIED, VCSState.REMOVED); } - protected static List<VCSFileState> generateRemoteFileStates(VCSHandler handler, int max, File root, String remotePRefix) { + protected static List<VCSEntry> generateRemoteFileStates(VCSConnexion handler, int max, File root, String remotePRefix) { return generateFileStates(handler, root, max, remotePRefix, VCSState.MISSING, VCSState.OUT_OF_DATE, VCSState.OUT_OF_DATE_AND_MODIFIED); } - protected static List<VCSFileState> generateFileStates(VCSHandler handler, File root, int max, String prefix, VCSState... states) { - List<VCSFileState> datas = new ArrayList<VCSFileState>(); + protected static List<VCSEntry> generateFileStates(VCSConnexion handler, File root, int max, String prefix, VCSState... states) { + List<VCSEntry> datas = new ArrayList<VCSEntry>(); for (int i = 0, nbFiles = 1 + r.nextInt(max), size = states.length; i < nbFiles; i++) { - VCSFileStateImpl state = new VCSFileStateImpl(handler, new File(root, prefix + "file" + i)); + VCSEntry state = new VCSEntryImpl(handler, root.getName() + File.separator + prefix + "file" + i); state.setState(states[r.nextInt(size)]); datas.add(state); }