Author: tchemit Date: 2008-04-13 17:12:21 +0000 (Sun, 13 Apr 2008) New Revision: 513 Added: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ChangelogUI.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ChangelogUIHandler.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/model/ChangelogUIModel.java Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/DiffUI.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/SynchUI.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUI.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TabUIAction.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/SynchUIHandler.java Log: add changelog ui Copied: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ChangelogUI.java (from rev 511, trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/DiffUI.java) =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ChangelogUI.java (rev 0) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ChangelogUI.java 2008-04-13 17:12:21 UTC (rev 513) @@ -0,0 +1,36 @@ +/** + * ##% 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 javax.swing.AbstractButton; + +/** @author chemit */ +public abstract class ChangelogUI extends org.codelutin.vcs.ui.util.AbstractTabUI<org.codelutin.vcs.ui.handler.ChangelogUIHandler> { + + @Override + public void setVisible(boolean b) { + if (b) { + AbstractButton button = getButton(getHandler().getLocation()); + if (button == null) { + button = getAllTab(); + } + button.doClick(); + if (getContentTable().getRowCount() > 0) + getHandler().getSelectionModel().setSelectionInterval(0, 0); + } + super.setVisible(b); + } + +} \ No newline at end of file Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/DiffUI.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/DiffUI.java 2008-04-13 17:01:36 UTC (rev 512) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/DiffUI.java 2008-04-13 17:12:21 UTC (rev 513) @@ -14,8 +14,6 @@ */ package org.codelutin.vcs.ui; -import org.codelutin.vcs.ui.action.DiffAction; - import javax.swing.AbstractAction; import javax.swing.AbstractButton; @@ -26,6 +24,8 @@ public abstract AbstractButton getPreviousDiff(); + public abstract AbstractButton getCommit(); + @Override public void setVisible(boolean b) { if (b) { @@ -41,6 +41,6 @@ } protected AbstractAction createDiffAction(boolean goUp) { - return DiffAction.createAction(goUp, this); + return org.codelutin.vcs.ui.action.DiffAction.createAction(goUp, this); } } Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/SynchUI.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/SynchUI.java 2008-04-13 17:01:36 UTC (rev 512) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/SynchUI.java 2008-04-13 17:12:21 UTC (rev 513) @@ -24,6 +24,8 @@ public abstract AbstractButton getDiffAll(); + public abstract AbstractButton getChangelogAll(); + public abstract AbstractButton getUpdateAll(); public abstract AbstractButton getCommitAll(); @@ -36,10 +38,14 @@ public abstract AbstractButton getDiff(); + public abstract AbstractButton getChangelog(); + public abstract AbstractButton getAdd(); public abstract AbstractButton getDelete(); + public abstract AbstractButton getCommit(); + public abstract JPopupMenu getPopup(); @Override Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUI.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUI.java 2008-04-13 17:01:36 UTC (rev 512) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUI.java 2008-04-13 17:12:21 UTC (rev 513) @@ -22,12 +22,13 @@ * @author chemit * @see AbstractUI * @see AbstractUIModel - * @see org.codelutin.vcs.ui.util.AbstractUIHandler + * @see AbstractUIHandler */ public enum VCSUI { synch(SynchUI.class, org.codelutin.vcs.ui.handler.SynchUIHandler.class), diff(DiffUI.class, org.codelutin.vcs.ui.handler.DiffUIHandler.class), + changelog(ChangelogUI.class, org.codelutin.vcs.ui.handler.ChangelogUIHandler.class), confirm(ConfirmUI.class, org.codelutin.vcs.ui.handler.ConfirmUIHandler.class); private final Class<? extends AbstractUI> uiClass; Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-13 17:01:36 UTC (rev 512) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-13 17:12:21 UTC (rev 513) @@ -18,9 +18,6 @@ import org.apache.commons.logging.LogFactory; import org.codelutin.util.StringUtil; import org.codelutin.vcs.VCSFactory; -import org.codelutin.vcs.ui.ConfirmUI; -import org.codelutin.vcs.ui.DiffUI; -import org.codelutin.vcs.ui.SynchUI; import org.codelutin.vcs.ui.util.AbstractUI; import java.lang.reflect.InvocationTargetException; @@ -47,14 +44,18 @@ return (SynchUI) getInstance().newUI(VCSUI.synch); } + public static DiffUI newDiffUI() { + return (DiffUI) getInstance().newUI(VCSUI.diff); + } + + public static ChangelogUI newChangelogUI() { + return (ChangelogUI) getInstance().newUI(VCSUI.changelog); + } + public static ConfirmUI newConfirmUI() { return (ConfirmUI) getInstance().newUI(VCSUI.confirm); } - public static DiffUI newDiffUI() { - return (DiffUI) getInstance().newUI(VCSUI.diff); - } - public void close() { if (cache != null) { cache.clear(); @@ -86,6 +87,7 @@ return cache; } + protected synchronized ServiceLoader<VCSUIProvider> getProviders() { if (loader == null) { long t0 = System.nanoTime(); @@ -101,7 +103,6 @@ return loader; } - protected AbstractUI newUI(VCSUI uiType) { AbstractUI result = getInstance().getCache().get(uiType); @@ -134,5 +135,4 @@ protected VCSUIFactory() { } - } \ No newline at end of file Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TabUIAction.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TabUIAction.java 2008-04-13 17:01:36 UTC (rev 512) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TabUIAction.java 2008-04-13 17:12:21 UTC (rev 513) @@ -49,7 +49,7 @@ List<VCSEntry> entries = model.filter(action, model.getDisplayedEntries(useSelection ? handler.getSelectionModel() : null)); switch (action) { case CHANGELOG: - //TODO + handler.showChangelogUI(useSelection, model, entries); return; case DIFF: handler.showDiffUI(useSelection, model, entries); Copied: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ChangelogUIHandler.java (from rev 511, trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/DiffUIHandler.java) =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ChangelogUIHandler.java (rev 0) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ChangelogUIHandler.java 2008-04-13 17:12:21 UTC (rev 513) @@ -0,0 +1,95 @@ +/** + * ##% 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.handler; + +import static org.codelutin.i18n.I18n._; +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.type.VCSAction; +import org.codelutin.vcs.ui.ChangelogUI; +import org.codelutin.vcs.ui.model.ChangelogUIModel; +import org.codelutin.vcs.ui.model.DiffUIModel; +import org.codelutin.vcs.ui.util.AbstractTabUIHandler; + +import javax.swing.AbstractButton; +import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import java.beans.PropertyChangeEvent; +import java.util.Collections; +import java.util.EnumMap; + +/** @author chemit */ +public class ChangelogUIHandler extends AbstractTabUIHandler<ChangelogUIModel, ChangelogUI> { + + public ChangelogUIHandler(ChangelogUI ui) { + super(ui, new ChangelogUIModel()); + ui.setHandler(this); + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (log.isDebugEnabled()) { + log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); + } + if (DiffUIModel.FILE_PROPERTY_CHANGED.equals(evt.getPropertyName())) { + afterSelectionChanged(); + return; + } + super.propertyChange(evt); + } + + @Override + public void valueChanged(ListSelectionEvent e) { + if (!e.getValueIsAdjusting()) { + // update model selected file ? TODO Is this really necessary, + ListSelectionModel selectionModel = (ListSelectionModel) e.getSource(); + VCSEntry vcsEntry = null; + if (!selectionModel.isSelectionEmpty()) { + vcsEntry = getModel().getEntriesModel().getDisplayedEntry(selectionModel.getMinSelectionIndex()); + } + getModel().setFileModel(vcsEntry); + } + } + + public void afterLocationChanged() { + if (getModel().getEntriesModel().getRowCount() > 0) { + // select first row + getSelectionModel().addSelectionInterval(0, 0); + } + } + + protected void afterSelectionChanged() { + + VCSEntry vcsEntry = getModel().getFileModel(); + EnumMap<VCSAction, Integer> actions = vcsEntry == null ? null : getModel().getEntriesModel().countActions(Collections.singletonList(vcsEntry)); + boolean hasActions = actions != null && !actions.isEmpty(); + ChangelogUI ui = getUi(); + updateAction(actions, hasActions, ui.getUpdate(), VCSAction.UPDATE, vcsEntry); + updateAction(actions, hasActions, ui.getRevert(), VCSAction.REVERT, vcsEntry); + updateAction(actions, hasActions, ui.getRefresh(), VCSAction.REFRESH, vcsEntry); + //TODO init changelog handler + log.info("//TODO: show changleog for "+vcsEntry); + + } + + protected void updateAction(EnumMap<VCSAction, Integer> actions, boolean hasActions, AbstractButton ui, VCSAction action, VCSEntry vcsEntry) { + super.updateAction(actions, hasActions, ui, action); + boolean useAction = hasActions && actions.containsKey(action) && actions.get(action) > 0; + String tip = null; + if (useAction) { + tip = _("lutinvcs.action.single.tip", action.getLibelle(), vcsEntry.getFile().getName()); + } + ui.setToolTipText(tip); + } +} \ No newline at end of file Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/SynchUIHandler.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/SynchUIHandler.java 2008-04-13 17:01:36 UTC (rev 512) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/SynchUIHandler.java 2008-04-13 17:12:21 UTC (rev 513) @@ -65,6 +65,7 @@ SynchUI ui = getUi(); int nbFiles = actions.get(VCSAction.REFRESH); updateAction(actions, hasActions, ui.getDiff(), VCSAction.DIFF, false, nbFiles); + updateAction(actions, hasActions, ui.getChangelog(), VCSAction.CHANGELOG, false, nbFiles); updateAction(actions, hasActions, ui.getUpdate(), VCSAction.UPDATE, false, nbFiles); updateAction(actions, hasActions, ui.getRevert(), VCSAction.REVERT, false, nbFiles); updateAction(actions, hasActions, ui.getCommit(), VCSAction.COMMIT, false, nbFiles); @@ -81,6 +82,7 @@ // refresh actions is enabled on all files int nbFiles = actions.get(VCSAction.REFRESH); updateAction(actions, hasActions, ui.getDiffAll(), VCSAction.DIFF, true, nbFiles); + updateAction(actions, hasActions, ui.getChangelogAll(), VCSAction.CHANGELOG, true, nbFiles); updateAction(actions, hasActions, ui.getUpdateAll(), VCSAction.UPDATE, true, nbFiles); updateAction(actions, hasActions, ui.getRevertAll(), VCSAction.REVERT, true, nbFiles); updateAction(actions, hasActions, ui.getCommitAll(), VCSAction.COMMIT, true, nbFiles); Copied: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/model/ChangelogUIModel.java (from rev 511, trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/model/DiffUIModel.java) =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/model/ChangelogUIModel.java (rev 0) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/model/ChangelogUIModel.java 2008-04-13 17:12:21 UTC (rev 513) @@ -0,0 +1,49 @@ +/** + * ##% 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.type.VCSEntryLocation; +import org.codelutin.vcs.ui.util.AbstractTabUIModel; + +/** + * Model of a repository + * + * @author chemit + */ +public class ChangelogUIModel extends AbstractTabUIModel { + + public static final String FILE_PROPERTY_CHANGED = "file"; + + /** current file displayed */ + protected VCSEntry fileModel; + + public VCSEntry getFileModel() { + return fileModel; + } + + public void setFileModel(VCSEntry fileModel) { + VCSEntry oldFileModel = this.fileModel; + this.fileModel = fileModel; + firePropertyChange(FILE_PROPERTY_CHANGED, oldFileModel, fileModel); + } + + public void init(VCSEntryLocation location, VCSEntry[] states) { + getEntriesModel().clear(); + getEntriesModel().populate(VCSEntryLocation.ALL, states); + setFileModel(null); + setLocation(location); + } +} \ No newline at end of file