Author: tchemit Date: 2008-04-06 17:19:12 +0000 (Sun, 06 Apr 2008) New Revision: 412 Added: trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java Removed: 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/VCSUIFactory.java Log: move ui-pre-jaxx module TODO rename module ui-pre-jaxx to ui-common TODO rename module ui-jaxx to ui Deleted: 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-06 17:18:56 UTC (rev 411) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java 2008-04-06 17:19:12 UTC (rev 412) @@ -1,112 +0,0 @@ -/** - * # #% 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.codelutin.vcs.VCSEntry; -import org.codelutin.vcs.type.VCSAction; -import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; -import org.codelutin.vcs.ui.model.ConfirmUIModel; - -import javax.swing.ListSelectionModel; -import java.beans.PropertyChangeEvent; -import java.util.List; - -/** @author chemit */ -public class ConfirmUIHandler extends org.codelutin.vcs.ui.handler.AbstractUIHandler<ConfirmUIModel, AbstractConfirmUI> { - - - public ConfirmUIHandler() { - super(); - //this.ui = new JConfirmUI(this); - } - - /*public void setUi(AbstractConfirmUI ui) { - this.ui = ui; - }*/ - - /*public ConfirmUIModel getModel() { - return getUi().getModel(); - }*/ - - - public Class<AbstractConfirmUI> getUiClass() { - return AbstractConfirmUI.class; - } - - public Class<? super ConfirmUIModel> getModelClass() { - return ConfirmUIModel.class; - } - - public ListSelectionModel getSelectionModel() { - return getUi().getContentTable().getSelectionModel(); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (log.isDebugEnabled()) { - log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); - } - String action = evt.getPropertyName(); - - if (ConfirmUIModel.ACCEPT_PROPERTY_CHANGED.equals(action)) { - updateUI(); - return; - } - - if (ConfirmUIModel.MESSAGE_HISTORY_PROPERTY_CHANGED.equals(action)) { - updateMessageUI(); - return; - } - - throw new IllegalStateException("unimplemented property changed : " + evt); - } - - protected void updateUI() { - VCSAction action = getModel().getAction(); - getUi().getAccept().setText(action.getLibelle()); - getUi().getToolbar().setVisible(action.isCommit()); - getUi().getHandler().getSelectionModel().setSelectionInterval(0, getModel().getEntriesModel().getRowCount() - 1); - } - - protected void updateMessageUI() { - // update message history combo box ? - getUi().getLastMessages().setEnabled(!getModel().getCommitMessages().isEmpty()); - } - - public void doAction(String commitMessage, AbstractVCSEntriesTableModel model) { - - VCSAction action = getModel().getAction(); - - List<VCSEntry> entries = model.filter(action, model.getDisplayedEntries(getSelectionModel())); - - if (action.isCommit()) { - getModel().addCommitMessage(commitMessage); - - } else { - commitMessage = null; - } - - if (log.isDebugEnabled()) { - log.debug("action:" + action + ", message:" + commitMessage + ", nb files:" + entries.size()); - } - - getActionManager().add(action, entries.toArray(new VCSEntry[entries.size()]), commitMessage); - - // dispose ui - getUi().dispose(); - - } - - -} Deleted: 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-06 17:18:56 UTC (rev 411) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java 2008-04-06 17:19:12 UTC (rev 412) @@ -1,92 +0,0 @@ -/** - * # #% 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.codelutin.vcs.VCSEntry; -import org.codelutin.vcs.type.VCSAction; -import org.codelutin.vcs.type.VCSEntryLocation; -import org.codelutin.vcs.ui.model.DiffUIModel; - -import java.beans.PropertyChangeEvent; - -/** @author chemit */ -public class DiffUIHandler extends org.codelutin.vcs.ui.handler.AbstractTabUIHandler<DiffUIModel, AbstractDiffUI> { - - //protected AbstractDiffUI ui; - - public DiffUIHandler() { - //this.ui = new JDiffUI(this); - } - - /*public AbstractDiffUI getUi() { - return ui; - }*/ - - /*public void setUi(AbstractDiffUI ui) { - this.ui = ui; - } - - public DiffUIModel getModel() { - return ui.getModel(); - }*/ - - public Class<AbstractDiffUI> getUiClass() { - return AbstractDiffUI.class; - } - - public Class<? super DiffUIModel> getModelClass() { - return DiffUIModel.class; - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - //if (log.isDebugEnabled()) { - log.info(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); - //} - - String action = evt.getPropertyName(); - if (DiffUIModel.FILE_PROPERTY_CHANGED.equals(action)) { - doSelectFile((VCSEntry) evt.getNewValue()); - } else { - super.propertyChange(evt); - } - } - - @Override - public void doSelectLocation(VCSEntryLocation location) { - super.doSelectLocation(location); - - } - - protected void initTab(VCSEntryLocation location) { - //TODO - } - - public void doSelectFile(VCSEntry model) { - //TODO - } - - public void doAction(VCSAction action, VCSEntry model) { - //TODO - } - - public void gotoNextDiff() { - //TODO - } - - public void gotoPreviousDiff() { - //TODO - } -} Deleted: 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-06 17:18:56 UTC (rev 411) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java 2008-04-06 17:19:12 UTC (rev 412) @@ -1,177 +0,0 @@ -package org.codelutin.vcs.ui; - -import org.codelutin.vcs.VCSEntry; -import org.codelutin.vcs.type.VCSAction; -import org.codelutin.vcs.type.VCSEntryLocation; -import org.codelutin.vcs.ui.handler.VCSAbsractAction; -import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; -import org.codelutin.vcs.ui.model.SynchUIModel; - -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.List; - -/** @author chemit */ -public class SynchUIHandler extends org.codelutin.vcs.ui.handler.AbstractTabUIHandler<SynchUIModel, AbstractSynchUI> { - - //protected AbstractSynchUI ui; - - public SynchUIHandler() { - //this.ui = new JSynchUI(this); - } - - public Class<AbstractSynchUI> getUiClass() { - return AbstractSynchUI.class; - } - - public Class<? super SynchUIModel> getModelClass() { - return SynchUIModel.class; - } - - /*public void setUi(AbstractSynchUI ui) { - this.ui = ui; - } - - public AbstractSynchUI getUi() { - return ui; - }*/ - - /*public SynchUIModel getModel() { - return ui.getModel(); - }*/ - - /*public void doAllAction(VCSAction action) { - doAction(action, false); - } - - public void doSelectAction(VCSAction action) { - doAction(action, true); - }*/ - - @Override - public void doSelectLocation(VCSEntryLocation location) { - - super.doSelectLocation(location); - - VCSAction[] actions = getModel().getEntriesModel().getActions((ListSelectionModel) null); - List<String> acts = new ArrayList<String>(); - for (VCSAction action : actions) { - acts.add(action.name().toLowerCase()); - } - boolean hasActions = actions.length > 0; - getUi().getDiffAll().setEnabled(hasActions && acts.contains("diff")); - getUi().getUpdateAll().setEnabled(hasActions && acts.contains("update")); - getUi().getCommitAll().setEnabled(hasActions && acts.contains("commit")); - getUi().getRevertAll().setEnabled(hasActions && acts.contains("revert")); - getUi().getDeleteAll().setEnabled(hasActions && acts.contains("delete")); - getUi().getRefreshAll().setEnabled(hasActions); - } - - public void doAction(VCSAction action, boolean useSelection) { - AbstractVCSEntriesTableModel model = getModel().getEntriesModel(); - log.info(action + " : " + model); - ListSelectionModel selectionModel = getSelectionModel(); - if (action == VCSAction.REFRESH) { - selectionModel.clearSelection(); - // do refresh of all states - log.info("refresh :" + model.getRowCount()); - model.refresh(model.getEntries(), System.nanoTime()); - } else { - List<VCSEntry> entries = model.filter(action, model.getDisplayedEntries(useSelection ? selectionModel : null)); - if (entries.isEmpty()) { - // nothing to do - return; - } - if (action == VCSAction.DIFF) { - // show diff ui - return; - } - log.info("files to treate :" + entries.size()); - - AbstractConfirmUI confirmUI = VCSUIFactory.newConfirmUI(); - - 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..."); - } - } - - protected void initTab(VCSEntryLocation location) { - JTable table = getUi().getTable(location); - AbstractVCSEntriesTableModel fileStatesModel = getModel().getEntriesModel(); - table.setModel(fileStatesModel); - table.addMouseListener(new ListMouseListener(getUi(), fileStatesModel, location)); - AbstractVCSPopup popup = getUi().getPopup(location); - - popup.setDispatchAction(new VCSAbsractAction() { - private static final long serialVersionUID = 8622118724992019898L; - - public void actionPerformed(ActionEvent e) { - doAction(action, false); - } - }); - } - - protected static class ListMouseListener extends MouseAdapter { - - private final AbstractVCSEntriesTableModel model; - - private final ListSelectionModel selectionModel; - - private final JTable jTable; - private final AbstractVCSPopup jPopupMenu; - - public ListMouseListener(AbstractSynchUI ui, AbstractVCSEntriesTableModel model, VCSEntryLocation modelName) { - this.model = model; - jPopupMenu = ui.getPopup(modelName); - jTable = ui.getTable(modelName); - selectionModel = jTable.getSelectionModel(); - } - - @Override - public void mousePressed(MouseEvent e) { - super.mousePressed(e); - if (e.isPopupTrigger()) { - initPopup(e.getX(), e.getY()); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - super.mouseReleased(e); - if (e.isPopupTrigger()) { - initPopup(e.getX(), e.getY()); - } - } - - @Override - public void mouseClicked(MouseEvent e) { - // nothing to do - } - - protected void initPopup(int x, int y) { - if (!selectionModel.isSelectionEmpty()) { - List<String> acts = new ArrayList<String>(); - for (VCSAction action : model.getActions(selectionModel)) { - acts.add(action.name().toLowerCase()); - } - boolean hasActions = !acts.isEmpty(); - jPopupMenu.getDiff().setEnabled(hasActions && acts.contains("diff")); - jPopupMenu.getUpdate().setEnabled(hasActions && acts.contains("update")); - jPopupMenu.getCommit().setEnabled(hasActions && acts.contains("commit")); - jPopupMenu.getRevert().setEnabled(hasActions && acts.contains("revert")); - jPopupMenu.getDelete().setEnabled(hasActions && acts.contains("delete")); - jPopupMenu.getRefresh().setEnabled(hasActions); - jPopupMenu.pack(); - // display popup - jPopupMenu.show(jTable, x, y); - } - } - } -} Deleted: 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-06 17:18:56 UTC (rev 411) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-06 17:19:12 UTC (rev 412) @@ -1,156 +0,0 @@ -/** - * # #% 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.util.StringUtil; -import org.codelutin.vcs.VCSFactory; -import org.codelutin.vcs.ui.handler.AbstractUIHandler; -import org.codelutin.vcs.ui.model.AbstractUIModel; - -import java.util.HashMap; -import java.util.Map; -import java.util.ServiceLoader; - -/** - * Factory if VCS UI, using a cache. - * - * @author chemit - */ -public class VCSUIFactory { - - static protected final Log log = LogFactory.getLog(VCSFactory.class); - - protected static VCSUIFactory instance; - - protected Map<Class<? extends AbstractUIHandler>, AbstractUIHandler> cache; - protected ServiceLoader<AbstractUI> loader; - - - public static AbstractSynchUI newSynchUI() { - SynchUIHandler result = getInstance().newHandler(SynchUIHandler.class); - return result.getUi(); - } - - public static AbstractConfirmUI newConfirmUI() { - ConfirmUIHandler result = getInstance().newHandler(ConfirmUIHandler.class); - return result.getUi(); - } - - public static AbstractDiffUI newDiffUI() { - DiffUIHandler result = getInstance().newHandler(DiffUIHandler.class); - return result.getUi(); - } - - public void close() { - if (cache != null) { - cache.clear(); - cache = null; - } - if (loader != null) { - loader.reload(); - loader = null; - } - } - - protected static VCSUIFactory getInstance() { - if (instance == null) { - instance = new VCSUIFactory(); - } - return instance; - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - close(); - } - - protected synchronized Map<Class<? extends AbstractUIHandler>, AbstractUIHandler> getCache() { - if (cache == null) { - cache = new HashMap<Class<? extends AbstractUIHandler>, AbstractUIHandler>(); - } - return cache; - } - - protected synchronized ServiceLoader<AbstractUI> getLoader() { - if (loader == null) { - long t0 = System.nanoTime(); - - loader = ServiceLoader.load(AbstractUI.class); - int nb = 0; - for (AbstractUI provider : loader) { - log.info(provider.getName() + " [" + provider + ']'); - nb++; - } - log.info("found " + nb + " ui(s) in " + StringUtil.convertTime(t0, System.nanoTime())); - } - return loader; - } - - @SuppressWarnings({"unchecked"}) - protected <H extends AbstractUIHandler> H newHandler(Class<H> klass) { - H result; - - result = (H) getInstance().getCache().get(klass); - - if (result == null) { - - try { - // instance of handler - result = klass.getConstructor().newInstance(); - - // instance of model - AbstractUIModel model = (AbstractUIModel) result.getModelClass().newInstance(); - - // obtain intance of ui - AbstractUI ui = getUI(result.getUiClass()); - - // attach model to ui - ui.setModel(model); - - // attach handler to ui - ui.setHandler(result); - - // attach ui to handler - result.setUi(ui); - - // init handler - result.init(); - - getCache().put(klass, result); - } catch (Exception e) { - throw new IllegalStateException("could not instanciate ui handler " + klass + " for reason : " + e.getMessage()); - } - } - return result; - } - - @SuppressWarnings({"unchecked"}) - protected <U extends AbstractUI> U getUI(Class<U> klass) { - - for (AbstractUI ui : getLoader()) { - if (klass.isAssignableFrom(ui.getClass())) { - return (U) ui; - } - } - throw new IllegalStateException("could not find ui " + klass); - } - - protected VCSUIFactory() { - } - -} Copied: trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java (from rev 410, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java) =================================================================== --- trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java (rev 0) +++ trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java 2008-04-06 17:19:12 UTC (rev 412) @@ -0,0 +1,112 @@ +/** + * # #% 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.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.type.VCSAction; +import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; +import org.codelutin.vcs.ui.model.ConfirmUIModel; + +import javax.swing.ListSelectionModel; +import java.beans.PropertyChangeEvent; +import java.util.List; + +/** @author chemit */ +public class ConfirmUIHandler extends org.codelutin.vcs.ui.handler.AbstractUIHandler<ConfirmUIModel, AbstractConfirmUI> { + + + public ConfirmUIHandler() { + super(); + //this.ui = new JConfirmUI(this); + } + + /*public void setUi(AbstractConfirmUI ui) { + this.ui = ui; + }*/ + + /*public ConfirmUIModel getModel() { + return getUi().getModel(); + }*/ + + + public Class<AbstractConfirmUI> getUiClass() { + return AbstractConfirmUI.class; + } + + public Class<? super ConfirmUIModel> getModelClass() { + return ConfirmUIModel.class; + } + + public ListSelectionModel getSelectionModel() { + return getUi().getContentTable().getSelectionModel(); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (log.isDebugEnabled()) { + log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); + } + String action = evt.getPropertyName(); + + if (ConfirmUIModel.ACCEPT_PROPERTY_CHANGED.equals(action)) { + updateUI(); + return; + } + + if (ConfirmUIModel.MESSAGE_HISTORY_PROPERTY_CHANGED.equals(action)) { + updateMessageUI(); + return; + } + + throw new IllegalStateException("unimplemented property changed : " + evt); + } + + protected void updateUI() { + VCSAction action = getModel().getAction(); + getUi().getAccept().setText(action.getLibelle()); + getUi().getToolbar().setVisible(action.isCommit()); + getUi().getHandler().getSelectionModel().setSelectionInterval(0, getModel().getEntriesModel().getRowCount() - 1); + } + + protected void updateMessageUI() { + // update message history combo box ? + getUi().getLastMessages().setEnabled(!getModel().getCommitMessages().isEmpty()); + } + + public void doAction(String commitMessage, AbstractVCSEntriesTableModel model) { + + VCSAction action = getModel().getAction(); + + List<VCSEntry> entries = model.filter(action, model.getDisplayedEntries(getSelectionModel())); + + if (action.isCommit()) { + getModel().addCommitMessage(commitMessage); + + } else { + commitMessage = null; + } + + if (log.isDebugEnabled()) { + log.debug("action:" + action + ", message:" + commitMessage + ", nb files:" + entries.size()); + } + + getActionManager().add(action, entries.toArray(new VCSEntry[entries.size()]), commitMessage); + + // dispose ui + getUi().dispose(); + + } + + +} Copied: trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java (from rev 410, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java) =================================================================== --- trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java (rev 0) +++ trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java 2008-04-06 17:19:12 UTC (rev 412) @@ -0,0 +1,92 @@ +/** + * # #% 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.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.type.VCSAction; +import org.codelutin.vcs.type.VCSEntryLocation; +import org.codelutin.vcs.ui.model.DiffUIModel; + +import java.beans.PropertyChangeEvent; + +/** @author chemit */ +public class DiffUIHandler extends org.codelutin.vcs.ui.handler.AbstractTabUIHandler<DiffUIModel, AbstractDiffUI> { + + //protected AbstractDiffUI ui; + + public DiffUIHandler() { + //this.ui = new JDiffUI(this); + } + + /*public AbstractDiffUI getUi() { + return ui; + }*/ + + /*public void setUi(AbstractDiffUI ui) { + this.ui = ui; + } + + public DiffUIModel getModel() { + return ui.getModel(); + }*/ + + public Class<AbstractDiffUI> getUiClass() { + return AbstractDiffUI.class; + } + + public Class<? super DiffUIModel> getModelClass() { + return DiffUIModel.class; + } + + @Override + public void propertyChange(PropertyChangeEvent evt) { + //if (log.isDebugEnabled()) { + log.info(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); + //} + + String action = evt.getPropertyName(); + if (DiffUIModel.FILE_PROPERTY_CHANGED.equals(action)) { + doSelectFile((VCSEntry) evt.getNewValue()); + } else { + super.propertyChange(evt); + } + } + + @Override + public void doSelectLocation(VCSEntryLocation location) { + super.doSelectLocation(location); + + } + + protected void initTab(VCSEntryLocation location) { + //TODO + } + + public void doSelectFile(VCSEntry model) { + //TODO + } + + public void doAction(VCSAction action, VCSEntry model) { + //TODO + } + + public void gotoNextDiff() { + //TODO + } + + public void gotoPreviousDiff() { + //TODO + } +} Copied: trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java (from rev 410, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java) =================================================================== --- trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java (rev 0) +++ trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java 2008-04-06 17:19:12 UTC (rev 412) @@ -0,0 +1,177 @@ +package org.codelutin.vcs.ui; + +import org.codelutin.vcs.VCSEntry; +import org.codelutin.vcs.type.VCSAction; +import org.codelutin.vcs.type.VCSEntryLocation; +import org.codelutin.vcs.ui.handler.VCSAbsractAction; +import org.codelutin.vcs.ui.model.AbstractVCSEntriesTableModel; +import org.codelutin.vcs.ui.model.SynchUIModel; + +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import java.awt.event.ActionEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.List; + +/** @author chemit */ +public class SynchUIHandler extends org.codelutin.vcs.ui.handler.AbstractTabUIHandler<SynchUIModel, AbstractSynchUI> { + + //protected AbstractSynchUI ui; + + public SynchUIHandler() { + //this.ui = new JSynchUI(this); + } + + public Class<AbstractSynchUI> getUiClass() { + return AbstractSynchUI.class; + } + + public Class<? super SynchUIModel> getModelClass() { + return SynchUIModel.class; + } + + /*public void setUi(AbstractSynchUI ui) { + this.ui = ui; + } + + public AbstractSynchUI getUi() { + return ui; + }*/ + + /*public SynchUIModel getModel() { + return ui.getModel(); + }*/ + + /*public void doAllAction(VCSAction action) { + doAction(action, false); + } + + public void doSelectAction(VCSAction action) { + doAction(action, true); + }*/ + + @Override + public void doSelectLocation(VCSEntryLocation location) { + + super.doSelectLocation(location); + + VCSAction[] actions = getModel().getEntriesModel().getActions((ListSelectionModel) null); + List<String> acts = new ArrayList<String>(); + for (VCSAction action : actions) { + acts.add(action.name().toLowerCase()); + } + boolean hasActions = actions.length > 0; + getUi().getDiffAll().setEnabled(hasActions && acts.contains("diff")); + getUi().getUpdateAll().setEnabled(hasActions && acts.contains("update")); + getUi().getCommitAll().setEnabled(hasActions && acts.contains("commit")); + getUi().getRevertAll().setEnabled(hasActions && acts.contains("revert")); + getUi().getDeleteAll().setEnabled(hasActions && acts.contains("delete")); + getUi().getRefreshAll().setEnabled(hasActions); + } + + public void doAction(VCSAction action, boolean useSelection) { + AbstractVCSEntriesTableModel model = getModel().getEntriesModel(); + log.info(action + " : " + model); + ListSelectionModel selectionModel = getSelectionModel(); + if (action == VCSAction.REFRESH) { + selectionModel.clearSelection(); + // do refresh of all states + log.info("refresh :" + model.getRowCount()); + model.refresh(model.getEntries(), System.nanoTime()); + } else { + List<VCSEntry> entries = model.filter(action, model.getDisplayedEntries(useSelection ? selectionModel : null)); + if (entries.isEmpty()) { + // nothing to do + return; + } + if (action == VCSAction.DIFF) { + // show diff ui + return; + } + log.info("files to treate :" + entries.size()); + + AbstractConfirmUI confirmUI = VCSUIFactory.newConfirmUI(); + + 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..."); + } + } + + protected void initTab(VCSEntryLocation location) { + JTable table = getUi().getTable(location); + AbstractVCSEntriesTableModel fileStatesModel = getModel().getEntriesModel(); + table.setModel(fileStatesModel); + table.addMouseListener(new ListMouseListener(getUi(), fileStatesModel, location)); + AbstractVCSPopup popup = getUi().getPopup(location); + + popup.setDispatchAction(new VCSAbsractAction() { + private static final long serialVersionUID = 8622118724992019898L; + + public void actionPerformed(ActionEvent e) { + doAction(action, false); + } + }); + } + + protected static class ListMouseListener extends MouseAdapter { + + private final AbstractVCSEntriesTableModel model; + + private final ListSelectionModel selectionModel; + + private final JTable jTable; + private final AbstractVCSPopup jPopupMenu; + + public ListMouseListener(AbstractSynchUI ui, AbstractVCSEntriesTableModel model, VCSEntryLocation modelName) { + this.model = model; + jPopupMenu = ui.getPopup(modelName); + jTable = ui.getTable(modelName); + selectionModel = jTable.getSelectionModel(); + } + + @Override + public void mousePressed(MouseEvent e) { + super.mousePressed(e); + if (e.isPopupTrigger()) { + initPopup(e.getX(), e.getY()); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + super.mouseReleased(e); + if (e.isPopupTrigger()) { + initPopup(e.getX(), e.getY()); + } + } + + @Override + public void mouseClicked(MouseEvent e) { + // nothing to do + } + + protected void initPopup(int x, int y) { + if (!selectionModel.isSelectionEmpty()) { + List<String> acts = new ArrayList<String>(); + for (VCSAction action : model.getActions(selectionModel)) { + acts.add(action.name().toLowerCase()); + } + boolean hasActions = !acts.isEmpty(); + jPopupMenu.getDiff().setEnabled(hasActions && acts.contains("diff")); + jPopupMenu.getUpdate().setEnabled(hasActions && acts.contains("update")); + jPopupMenu.getCommit().setEnabled(hasActions && acts.contains("commit")); + jPopupMenu.getRevert().setEnabled(hasActions && acts.contains("revert")); + jPopupMenu.getDelete().setEnabled(hasActions && acts.contains("delete")); + jPopupMenu.getRefresh().setEnabled(hasActions); + jPopupMenu.pack(); + // display popup + jPopupMenu.show(jTable, x, y); + } + } + } +} Copied: trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java (from rev 410, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java) =================================================================== --- trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java (rev 0) +++ trunk/lutinvcs/lutinvcs-ui-pre-jaxx/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-06 17:19:12 UTC (rev 412) @@ -0,0 +1,156 @@ +/** + * # #% 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.util.StringUtil; +import org.codelutin.vcs.VCSFactory; +import org.codelutin.vcs.ui.handler.AbstractUIHandler; +import org.codelutin.vcs.ui.model.AbstractUIModel; + +import java.util.HashMap; +import java.util.Map; +import java.util.ServiceLoader; + +/** + * Factory if VCS UI, using a cache. + * + * @author chemit + */ +public class VCSUIFactory { + + static protected final Log log = LogFactory.getLog(VCSFactory.class); + + protected static VCSUIFactory instance; + + protected Map<Class<? extends AbstractUIHandler>, AbstractUIHandler> cache; + protected ServiceLoader<AbstractUI> loader; + + + public static AbstractSynchUI newSynchUI() { + SynchUIHandler result = getInstance().newHandler(SynchUIHandler.class); + return result.getUi(); + } + + public static AbstractConfirmUI newConfirmUI() { + ConfirmUIHandler result = getInstance().newHandler(ConfirmUIHandler.class); + return result.getUi(); + } + + public static AbstractDiffUI newDiffUI() { + DiffUIHandler result = getInstance().newHandler(DiffUIHandler.class); + return result.getUi(); + } + + public void close() { + if (cache != null) { + cache.clear(); + cache = null; + } + if (loader != null) { + loader.reload(); + loader = null; + } + } + + protected static VCSUIFactory getInstance() { + if (instance == null) { + instance = new VCSUIFactory(); + } + return instance; + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + close(); + } + + protected synchronized Map<Class<? extends AbstractUIHandler>, AbstractUIHandler> getCache() { + if (cache == null) { + cache = new HashMap<Class<? extends AbstractUIHandler>, AbstractUIHandler>(); + } + return cache; + } + + protected synchronized ServiceLoader<AbstractUI> getLoader() { + if (loader == null) { + long t0 = System.nanoTime(); + + loader = ServiceLoader.load(AbstractUI.class); + int nb = 0; + for (AbstractUI provider : loader) { + log.info(provider.getName() + " [" + provider + ']'); + nb++; + } + log.info("found " + nb + " ui(s) in " + StringUtil.convertTime(t0, System.nanoTime())); + } + return loader; + } + + @SuppressWarnings({"unchecked"}) + protected <H extends AbstractUIHandler> H newHandler(Class<H> klass) { + H result; + + result = (H) getInstance().getCache().get(klass); + + if (result == null) { + + try { + // instance of handler + result = klass.getConstructor().newInstance(); + + // instance of model + AbstractUIModel model = (AbstractUIModel) result.getModelClass().newInstance(); + + // obtain intance of ui + AbstractUI ui = getUI(result.getUiClass()); + + // attach model to ui + ui.setModel(model); + + // attach handler to ui + ui.setHandler(result); + + // attach ui to handler + result.setUi(ui); + + // init handler + result.init(); + + getCache().put(klass, result); + } catch (Exception e) { + throw new IllegalStateException("could not instanciate ui handler " + klass + " for reason : " + e.getMessage()); + } + } + return result; + } + + @SuppressWarnings({"unchecked"}) + protected <U extends AbstractUI> U getUI(Class<U> klass) { + + for (AbstractUI ui : getLoader()) { + if (klass.isAssignableFrom(ui.getClass())) { + return (U) ui; + } + } + throw new IllegalStateException("could not find ui " + klass); + } + + protected VCSUIFactory() { + } + +}