Author: tchemit Date: 2008-04-03 17:01:51 +0000 (Thu, 03 Apr 2008) New Revision: 306 Added: 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/VCSPopupAction.java Removed: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/action/VCSPopupAction.java 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/VCSUIFactory.java Log: implantations d'handler d'ui Added: 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 (rev 0) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/ConfirmUIHandler.java 2008-04-03 17:01:51 UTC (rev 306) @@ -0,0 +1,58 @@ +/** + * # #% 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.VCSAction; +import org.codelutin.vcs.ui.action.AbstractConfirmUIHandler; +import org.codelutin.vcs.ui.model.ConfirmUIModel; + +import javax.swing.JTable; +import javax.swing.ListSelectionModel; +import java.beans.PropertyChangeEvent; + +/** @author chemit */ +public class ConfirmUIHandler extends AbstractConfirmUIHandler { + + protected final JConfirmUI ui; + + public ConfirmUIHandler() { + super(); + this.ui = new JConfirmUI(this); + } + + public ConfirmUIModel getModel() { + return ui.getModel(); + } + + public JConfirmUI getUi() { + return ui; + } + + public ListSelectionModel getSelectionModel() { + JTable table = ui.getContentTable(); + return table.getSelectionModel(); + } + + protected void updateUI() { + VCSAction action = ui.getModel().getAction(); + ui.getAccept().setText(action.getLibelle()); + ui.getToolbar().setVisible(action.isCommit()); + } + + public void propertyChange(PropertyChangeEvent evt) { + super.propertyChange(evt); + + } +} Added: 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 (rev 0) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/DiffUIHandler.java 2008-04-03 17:01:51 UTC (rev 306) @@ -0,0 +1,63 @@ +/** + * # #% 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.VCSAction; +import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.ui.action.AbstractDiffUIHandler; +import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; +import org.codelutin.vcs.ui.model.DiffUIModel; +import org.codelutin.vcs.ui.model.SimpleVCSFileStatesModel; + +import javax.swing.ListSelectionModel; + +/** @author chemit */ +public class DiffUIHandler extends AbstractDiffUIHandler { + + protected final JDiffUI ui; + + public DiffUIHandler() { + super(); + this.ui = new JDiffUI(this); + } + + public JDiffUI getUi() { + return ui; + } + + public DiffUIModel getModel() { + return ui.getModel(); + } + + public ListSelectionModel getSelectionModel() { + AbstractVCSFileStatesModel tabModel = getModel().getTabModel(); + return tabModel == null ? null : ui.getTable(tabModel.getName()).getSelectionModel(); + } + + public void doSelectTab(SimpleVCSFileStatesModel action) { + } + + public void doSelectFile(VCSFileState model) { + } + + public void doAction(VCSAction action, VCSFileState model) { + } + + public void gotoNextDiff() { + } + + public void gotoPreviousDiff() { + } +} 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-03 17:01:40 UTC (rev 305) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/SynchUIHandler.java 2008-04-03 17:01:51 UTC (rev 306) @@ -3,10 +3,9 @@ import org.codelutin.vcs.VCSAction; import org.codelutin.vcs.VCSFileState; import org.codelutin.vcs.ui.action.AbstractSynchUIHandler; -import org.codelutin.vcs.ui.action.VCSPopupAction; import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; +import org.codelutin.vcs.ui.model.SimpleVCSFileStatesModel; import org.codelutin.vcs.ui.model.SynchUIModel; -import org.codelutin.vcs.ui.model.SynchVCSFileStatesModel; import javax.swing.JTable; import javax.swing.ListSelectionModel; @@ -15,6 +14,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @author chemit */ @@ -22,35 +22,33 @@ protected final JSynchUI ui; - public SynchUIHandler(JSynchUI ui) { + public SynchUIHandler() { super(); - this.ui = ui; + this.ui = new JSynchUI(this); } + public JSynchUI getUi() { + return ui; + } + @Override public void init() { super.init(); - initTab(VCSUIConstants.ALL_MODEL_PROPERTY); - initTab(VCSUIConstants.LOCAL_MODEL_PROPERTY); - initTab(VCSUIConstants.REMOTE_MODEL_PROPERTY); + initTab(VCSUIConstants.SYNCH_ALL_MODEL_PROPERTY); + initTab(VCSUIConstants.SYNCH_LOCAL_MODEL_PROPERTY); + initTab(VCSUIConstants.SYNCH_REMOTE_MODEL_PROPERTY); } - private void initTab(String modelName) { - JTable table = ui.getTable(modelName); - SynchVCSFileStatesModel fileStatesModel = getModel().getModel(modelName); - table.setModel(fileStatesModel); - table.getSelectionModel().addListSelectionListener(this); - table.addMouseListener(new ListMouseListener(ui, fileStatesModel)); - JVCSPopup jvcsPopup = ui.getPopup(modelName); - jvcsPopup.setInvoker(table); - jvcsPopup.setDispatchAction(new VCSPopupAction(ui, modelName)); - } - public SynchUIModel getModel() { return ui.getModel(); } - public void doAllAction(VCSAction action, SynchVCSFileStatesModel model) { + public ListSelectionModel getSelectionModel() { + AbstractVCSFileStatesModel tabModel = getModel().getTabModel(); + return tabModel == null ? null : ui.getTable(tabModel.getName()).getSelectionModel(); + } + + public void doAllAction(VCSAction action, SimpleVCSFileStatesModel model) { log.info(action + " : " + model); JTable table = ui.getTable(model.getName()); ListSelectionModel selectionModel = table.getSelectionModel(); @@ -66,7 +64,7 @@ } } - public void doSelectAction(VCSAction action, SynchVCSFileStatesModel model) { + public void doSelectAction(VCSAction action, SimpleVCSFileStatesModel model) { log.info(action + " : " + model); JTable table = ui.getTable(model.getName()); ListSelectionModel selectionModel = table.getSelectionModel(); @@ -74,12 +72,19 @@ // nothing to do return; } + if (action == VCSAction.DIFF) { + // show diff ui + return; + } VCSFileState[] states = model.getData(selectionModel); log.info("files to treate :" + states.length); - + JConfirmUI confirmUI = VCSUIFactory.newConfirmUI(Arrays.asList(states)); + confirmUI.getModel().setAction(action); + confirmUI.getHandler().getSelectionModel().setSelectionInterval(0, states.length - 1); + confirmUI.setVisible(true); } - public void doSelectTabAction(SynchVCSFileStatesModel model) { + public void doSelectTabAction(SimpleVCSFileStatesModel model) { log.info(model); String tabModelName = model.getName(); @@ -105,10 +110,22 @@ } } + private void initTab(String modelName) { + JTable table = ui.getTable(modelName); + SimpleVCSFileStatesModel fileStatesModel = getModel().getModel(modelName); + table.setModel(fileStatesModel); + table.getSelectionModel().addListSelectionListener(this); + table.addMouseListener(new ListMouseListener(ui, fileStatesModel)); + JVCSPopup jvcsPopup = ui.getPopup(modelName); + jvcsPopup.setDispatchAction(new VCSPopupAction(ui, modelName)); + } + private class ListMouseListener extends MouseAdapter { private final AbstractVCSFileStatesModel model; + private final ListSelectionModel selectionModel; + private final JTable jTable; private final JVCSPopup jPopupMenu; @@ -127,13 +144,17 @@ @Override public void mousePressed(MouseEvent e) { super.mousePressed(e); - initPopup(e); + if (e.isPopupTrigger()) { + initPopup(e.getX(), e.getY()); + } } @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); - initPopup(e); + if (e.isPopupTrigger()) { + initPopup(e.getX(), e.getY()); + } } @Override @@ -141,8 +162,8 @@ // nothing to do } - protected void initPopup(MouseEvent e) { - if (e.isPopupTrigger() && !selectionModel.isSelectionEmpty()) { + 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()); @@ -154,8 +175,9 @@ 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, e.getX(), e.getY()); + jPopupMenu.show(jTable, x, y); } } } Copied: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSPopupAction.java (from rev 299, trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/action/VCSPopupAction.java) =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSPopupAction.java (rev 0) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSPopupAction.java 2008-04-03 17:01:51 UTC (rev 306) @@ -0,0 +1,61 @@ +/** + * # #% 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.VCSAction; +import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.ui.action.VCSAbsractAction; +import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; + +import javax.swing.ListSelectionModel; +import java.awt.event.ActionEvent; +import java.util.Arrays; + +/** + * Action of a clik inside the popup menu + * + * @author chemit + */ +public class VCSPopupAction extends VCSAbsractAction { + private static final long serialVersionUID = -1983061535956510913L; + + protected AbstractVCSFileStatesModel model; + protected transient ListSelectionModel selectionModel; + + public VCSPopupAction(JSynchUI ui, String modelName) { + super(ui.getModel().getHandler()); + this.model = ui.getModel().getModel(modelName); + this.selectionModel = ui.getTable(modelName).getSelectionModel(); + } + + 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); + if (action == VCSAction.DIFF) { + // show diff ui + } else if (action == VCSAction.REFRESH) { + // refresh ui, and update list if needed + } else { + // show confirm action ui + JConfirmUI confirmUI = VCSUIFactory.newConfirmUI(Arrays.asList(states)); + confirmUI.getModel().setAction(action); + confirmUI.getHandler().getSelectionModel().setSelectionInterval(0, states.length - 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-03 17:01:40 UTC (rev 305) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-03 17:01:51 UTC (rev 306) @@ -15,20 +15,69 @@ package org.codelutin.vcs.ui; import org.codelutin.vcs.VCSFileState; +import org.codelutin.vcs.ui.action.AbstractUIHandler; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** @author chemit */ public class VCSUIFactory { - static JSynchUI synchUI; + 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(List<VCSFileState> states) { - if (synchUI == null) { - synchUI = new JSynchUI(); - synchUI.setHandler(new SynchUIHandler(synchUI)); + SynchUIHandler result = newHandler(SynchUIHandler.class, states); + return result.getUi(); + } + + public static JDiffUI newDiffUI(List<VCSFileState> states) { + DiffUIHandler result = newHandler(DiffUIHandler.class, states); + return result.getUi(); + } + + public static JConfirmUI newConfirmUI(List<VCSFileState> states) { + ConfirmUIHandler result = newHandler(ConfirmUIHandler.class, states); + return result.getUi(); + } + + public static void close() { + if (cache != null) { + cache.clear(); } - synchUI.getModel().setData(states); - return synchUI; + cache = null; } + + @SuppressWarnings({"unchecked"}) + protected static <H extends AbstractUIHandler> H newHandler(Class<H> klass, List<VCSFileState> states) { + H result; + result = (H) getCache().get(klass); + if (result == null) { + try { + 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()); + } + } + result.getModel().setData(states); + return result; + } + + protected VCSUIFactory() { + } } Deleted: trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/action/VCSPopupAction.java =================================================================== --- trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/action/VCSPopupAction.java 2008-04-03 17:01:40 UTC (rev 305) +++ trunk/lutinvcs/lutinvcs-ui/src/main/java/org/codelutin/vcs/ui/action/VCSPopupAction.java 2008-04-03 17:01:51 UTC (rev 306) @@ -1,49 +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.action; - -import org.codelutin.vcs.VCSFileState; -import org.codelutin.vcs.ui.JSynchUI; -import org.codelutin.vcs.ui.JVCSPopup; -import org.codelutin.vcs.ui.model.AbstractVCSFileStatesModel; - -import javax.swing.ListSelectionModel; -import java.awt.event.ActionEvent; - -/** @author chemit */ -public class VCSPopupAction extends VCSAbsractAction { - private static final long serialVersionUID = -1983061535956510913L; - - protected JVCSPopup popup; - protected AbstractVCSFileStatesModel model; - protected transient ListSelectionModel selectionModel; - - public VCSPopupAction(JSynchUI ui, String modelName) { - super(ui.getModel().getHandler()); - this.model = ui.getModel().getModel(modelName); - this.popup = ui.getPopup(modelName); - this.selectionModel = ui.getTable(modelName).getSelectionModel(); - } - - 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); - // do real vcs action on thoses lines - //TODO delegate to VCSActionThread ? - log.info("files to treate :" + states.length); - } -}