Author: tchemit
Date: 2008-02-12 01:39:20 +0000 (Tue, 12 Feb 2008)
New Revision: 853
Modified:
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerUIRefreshHelper.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowDetailTabAction.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowSynchronizeTabAction.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java
Log:
mise en place de l'onglet de syncho reste, ?\195?\160 appeler le service et faire le rafraichissement post service
+ correction actions sur arbre qui sont bien ind?\195?\169pendantes du model, seul le noeud s?\195?\169lectionn?\195?\169 compte.
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerUIRefreshHelper.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerUIRefreshHelper.java 2008-02-12 01:36:33 UTC (rev 852)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerUIRefreshHelper.java 2008-02-12 01:39:20 UTC (rev 853)
@@ -31,6 +31,7 @@
import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper;
import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode;
import fr.cemagref.simexplorer.is.ui.swing.model.PaginationModel;
+import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel;
import org.codelutin.i18n.CountryEnum;
import static org.codelutin.i18n.I18n._;
import org.codelutin.i18n.LanguageEnum;
@@ -42,6 +43,7 @@
import javax.swing.JList;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
+import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
@@ -104,9 +106,9 @@
});
}
- public static void refreshListTablePopupMenu(final JListTab ui,final ListTabModel model) {
+ public static void refreshListTablePopupMenu(final JListTab ui, final ListTabModel model) {
int index = model.getSelectedIndex();
- if (index ==-1) {
+ if (index == -1) {
// disable popupmenu
ui.getTablePopupMenu().setEnabled(false);
return;
@@ -115,19 +117,20 @@
MetaData data = model.get(index);
String text = data.getName() + " [" + data.getVersion() + "]";
-
+
String tooltip = _("simexplorer.action.downloadLoggableElement.tooltip", text);
updateButton(ui.getDownloadElement(), true, tooltip);
- tooltip = _("simexplorer.action.deleteLoggableElement.tooltip", text);
+ tooltip = _("simexplorer.action.deleteLoggableElement.tooltip", text);
updateButton(ui.getDeleteElement(), true, tooltip);
tooltip = _("simexplorer.action.export.tooltip", text);
updateButton(ui.getExportElement(), true, tooltip);
tooltip = _("simexplorer.action.synchronize.tooltip", text);
- updateButton(ui.getSynchronizeElement(), true, tooltip);
+ updateButton(ui.getShowTab_synchronize(), true, tooltip);
}
+
/**
* Rafraichit les actions i18n dans le menu en fonction de la locale
* actuellement utilisée.
@@ -178,7 +181,7 @@
// public void run() {
ui.getConnect().setEnabled(!isConnected);
ui.getUnconnect().setEnabled(isConnected);
- ui.getShowTab_remote().setEnabled(isConnected);
+ ui.getShowTab_remote().setEnabled(isConnected);
ui.getToggleTab_remote().setEnabled(isConnected);
if (!isConnected) {
@@ -222,32 +225,29 @@
// refresh export button
refreshExportAction(ui, model);
// refresh download Attachment button
- refreshDownloadAttachmentAction(ui, model);
- // refresh tree buttons
- refreshTreeActions(ui, node);
+ refreshDownloadAttachmentAction(ui, model);
}
- protected static void refreshTreeActions(JDetailTab ui, LoggableElementTreeNode node) {
-
+ public static void refreshTreeDetailActions(JDetailTab ui, LoggableElementTreeNode node) {
String tooltip;
boolean enabled = node != null && !node.isLeaf() && node.getChildCount() > 0;
tooltip = !enabled ? null : _("simexplorer.action.collapseAll.tooltip", node.getUserObject());
- updateButton(ui.getCollapseAll(), enabled, tooltip);
+ updateButton(ui.getCollapseAllDetail(), enabled, tooltip);
tooltip = !enabled ? null : _("simexplorer.action.expandAll.tooltip", node.getUserObject());
- updateButton(ui.getExpandAll(), enabled, tooltip);
+ updateButton(ui.getExpandAllDetail(), enabled, tooltip);
}
- protected static void refreshDownloadElementAction(JDetailTab ui, DetailTabModel model, LoggableElementTreeNode node) {
+ public static void refreshDownloadElementAction(JDetailTab ui, DetailTabModel model, LoggableElementTreeNode node) {
MetaData detail = model.getDetail();
boolean enabled = detail != null || LoggableElementTreeHelper.canDownload(node);
- String tooltip = !enabled ? null : _("simexplorer.action.downloadLoggableElement.tooltip", detail == null ? node.getUserObject() : detail.getName() + " [" + model.getSelectedVersion()+"]");
+ String tooltip = !enabled ? null : _("simexplorer.action.downloadLoggableElement.tooltip", detail == null ? node.getUserObject() : detail.getName() + " [" + model.getSelectedVersion() + "]");
updateButton(ui.getDownloadElement(), enabled, tooltip);
}
protected static void refreshDeleteElementAction(JDetailTab ui, DetailTabModel model) {
MetaData detail = model.getDetail();
boolean enabled = detail != null;
- String tooltip = !enabled ? null : _("simexplorer.action.deleteLoggableElement.tooltip", detail.getName() + " [" + model.getSelectedVersion()+"]");
+ String tooltip = !enabled ? null : _("simexplorer.action.deleteLoggableElement.tooltip", detail.getName() + " [" + model.getSelectedVersion() + "]");
updateButton(ui.getDeleteElement(), enabled, tooltip);
}
@@ -262,18 +262,82 @@
public static void refreshSynchroniseElementAction(JDetailTab ui, DetailTabModel model) {
MetaData detail = model.getDetail();
boolean enabled = detail != null;
- String tooltip = !enabled ? null : _("simexplorer.action.synchronize.tooltip", detail.getName() + " [" + model.getSelectedVersion()+"]");
- updateButton(ui.getSynchronizeElement(), enabled, tooltip);
+ String tooltip = !enabled ? null : _("simexplorer.action.synchronize.tooltip", detail.getName() + " [" + model.getSelectedVersion() + "]");
+ updateButton(ui.getShowTab_synchronize(), enabled, tooltip);
}
protected static void refreshExportAction(JDetailTab ui, DetailTabModel model) {
MetaData detail = model.getDetail();
LoggableElement sNode = model.getSelectedNode();
boolean enabled = sNode != null && sNode instanceof ExplorationApplication;
- String tooltip = !enabled ? null : _("simexplorer.action.export.tooltip", detail.getName() + " [" + model.getSelectedVersion()+"]");
+ String tooltip = !enabled ? null : _("simexplorer.action.export.tooltip", detail.getName() + " [" + model.getSelectedVersion() + "]");
updateButton(ui.getExportElement(), enabled, tooltip);
}
+ public static void refreshExportElementToRemoteAction(JSynchronizeTab ui, SynchronizeTabModel model) {
+ LoggableElement sNode = model.getLocalSelectedNode();
+ boolean enabled = sNode != null;
+ String tooltip = !enabled ? null : _("simexplorer.action.exportToRemote.tooltip", sNode.getMetaData().getName() + " [" + sNode.getMetaData().getVersion() + "]");
+ updateButton(ui.getExportElementToRemote(), enabled, tooltip);
+ }
+
+ public static void refreshExportElementToLocalAction(JSynchronizeTab ui, SynchronizeTabModel model) {
+ LoggableElement sNode = model.getRemoteSelectedNode();
+ boolean enabled = sNode != null;
+ String tooltip = !enabled ? null : _("simexplorer.action.exportToLocal.tooltip", sNode.getMetaData().getName() + " [" + sNode.getMetaData().getVersion() + "]");
+ updateButton(ui.getExportElementToLocal(), enabled, tooltip);
+ }
+
+ public static void refreshTreeLocalActions(JSynchronizeTab ui, LoggableElementTreeNode node) {
+ String tooltip;
+ boolean enabled = node != null && !node.isLeaf() && node.getChildCount() > 0;
+ tooltip = !enabled ? null : _("simexplorer.action.collapseAll.tooltip", node.getUserObject());
+ updateButton(ui.getCollapseAllLocal(), enabled, tooltip);
+ tooltip = !enabled ? null : _("simexplorer.action.expandAll.tooltip", node.getUserObject());
+ updateButton(ui.getExpandAllLocal(), enabled, tooltip);
+ }
+
+ public static void refreshTreeRemoteActions(JSynchronizeTab ui, LoggableElementTreeNode node) {
+ String tooltip;
+ boolean enabled = node != null && !node.isLeaf() && node.getChildCount() > 0;
+ tooltip = !enabled ? null : _("simexplorer.action.collapseAll.tooltip", node.getUserObject());
+ updateButton(ui.getCollapseAllRemote(), enabled, tooltip);
+ tooltip = !enabled ? null : _("simexplorer.action.expandAll.tooltip", node.getUserObject());
+ updateButton(ui.getExpandAllRemote(), enabled, tooltip);
+ }
+
+ public static void updateSynchronizeNavigationTrees(JSynchronizeTab ui, SynchronizeTabModel model) {
+
+ TreeNode sourceRoot = LoggableElementTreeHelper.buildLoggableElementNode(model.getSource());
+ TreeNode destinationRoot = model.getDestination() == null ? null : LoggableElementTreeHelper.buildLoggableElementNode(model.getDestination());
+
+ JTree sourceTree, destinationTree;
+ if (model.isRemote()) {
+ // source is remote
+ sourceTree = ui.getContentTreeRemote();
+ destinationTree = ui.getContentTreeLocal();
+ } else {
+ // source is local
+ sourceTree = ui.getContentTreeLocal();
+ destinationTree = ui.getContentTreeRemote();
+ }
+
+ ((DefaultTreeModel) sourceTree.getModel()).setRoot(sourceRoot);
+ ((DefaultTreeModel) destinationTree.getModel()).setRoot(destinationRoot);
+
+ // by default select the root node
+ sourceTree.setSelectionRow(0);
+ if (destinationRoot == null) {
+ destinationTree.getSelectionModel().clearSelection();
+
+ } else {
+ destinationTree.setSelectionRow(0);
+ }
+ //sourceTree.invalidate();
+ //destinationTree.invalidate();
+ //ui.repaint();
+ }
+
protected static void refreshPagination(JListTab ui, PaginationModel pagination) {
int page = pagination.getCurrentPage();
boolean notLast = page + 1 < pagination.getNbPages();
@@ -313,11 +377,6 @@
ui.getCurrentPage().setEnabled(b);
}
- protected static void updateButton(AbstractButton button, boolean enabled, String tooltip) {
- button.setEnabled(enabled);
- button.setToolTipText(tooltip);
- }
-
public static void resetHistory(JDetailTab ui, DetailTabModel model, DefaultComboBoxModel historyModel) {
historyModel.removeAllElements();
LoggableElement selectedNode = model.getSelectedNode();
@@ -342,6 +401,15 @@
}
}
+ public static void updateDetailNavigationTree(JDetailTab ui, DetailTabModel model) {
+ // create navigation tree
+ TreeNode root = LoggableElementTreeHelper.buildLoggableElementNode(model.getRootNode());
+ // push it in tree model
+ ((DefaultTreeModel) ui.getNavigationTree().getModel()).setRoot(root);
+ // by default select the root node
+ ui.getNavigationTree().setSelectionRow(0);
+ }
+
public static void resetDetailPanel(final JDetailTab ui) {
ui.getDetailHeader().setText(_("simexplorer.node.nodetail"));
ui.getDetailAttachmentsHeader().setText(_("simexplorer.node.noattachments"));
@@ -413,7 +481,12 @@
ui.repaint();
}
- public static int[] computeRows(int nbDescriptorRows, int nbAttachmentRows) {
+ protected static void updateButton(AbstractButton button, boolean enabled, String tooltip) {
+ button.setEnabled(enabled);
+ button.setToolTipText(tooltip);
+ }
+
+ protected static int[] computeRows(int nbDescriptorRows, int nbAttachmentRows) {
int[] result = new int[2];
if (nbDescriptorRows == 0) {
result[0] = 0;
@@ -446,18 +519,9 @@
result[1] = nbAttachmentRows;
return result;
}
- throw new IllegalStateException("can not come her :)");
+ throw new IllegalStateException("can not come her :)");
}
- public static void updateDetailNavigationTree(JDetailTab ui, DetailTabModel model) {
- // create navigation tree
- TreeNode root = LoggableElementTreeHelper.buildLoggableElementNode(model.getRootNode());
- // push it in tree model
- ((DefaultTreeModel) ui.getNavigationTree().getModel()).setRoot(root);
- // by default select the root node
- ui.getNavigationTree().setSelectionRow(0);
- }
-
protected SimExplorerUIRefreshHelper() {
// do not instanciate me please
}
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowDetailTabAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowDetailTabAction.java 2008-02-12 01:36:33 UTC (rev 852)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowDetailTabAction.java 2008-02-12 01:39:20 UTC (rev 853)
@@ -22,13 +22,15 @@
import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
import fr.cemagref.simexplorer.is.entities.metadata.Version;
import fr.cemagref.simexplorer.is.ui.StorageServiceHelper;
+import fr.cemagref.simexplorer.is.ui.swing.JDetailTab;
+import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager;
import fr.cemagref.simexplorer.is.ui.swing.SimExplorerUIRefreshHelper;
-import fr.cemagref.simexplorer.is.ui.swing.JDetailTab;
import fr.cemagref.simexplorer.is.ui.swing.actions.util.ShowTabAbstractAction;
import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel;
import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper;
import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode;
+import javax.swing.AbstractButton;
import javax.swing.DefaultComboBoxModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@@ -85,6 +87,7 @@
}
protected void initUI(JDetailTab ui, DetailTabModel model) {
+ SimExplorerUIRefreshHelper.refreshTreeDetailActions(ui, null);
SimExplorerUIRefreshHelper.updateDetailNavigationTree(ui, model);
}
@@ -95,7 +98,7 @@
*/
protected class NavigationSelectionListener implements TreeSelectionListener, PropertyChangeListener {
- public NavigationSelectionListener() {
+ public NavigationSelectionListener() {
getTabModel().addPropertyChangeListener(DetailTabModel.Properties.SELECTED_NODE_PROPERTY_CHANGED, this);
}
@@ -107,6 +110,10 @@
if (path != null) {
node = (LoggableElementTreeNode) path.getLastPathComponent();
}
+ // on rafraichit toujours ici les actions de l'arbre qui sont
+ // indépendantes du model et dépendent juste dunoeud sélectionné
+ SimExplorerUIRefreshHelper.refreshTreeDetailActions(getTabUI(), node);
+
Object o = node == null ? null : node.getUserObject();
// always reset version index, in that way, if there is no more
// version list, nothing will be trigger by setting selectedVersion
@@ -124,11 +131,11 @@
if (!history) {
versions = null;
selectedVersion = null;
- selectedAttachment=null;
+ selectedAttachment = null;
} else {
versions = StorageServiceHelper.getVersions(getContext(), model.isRemote(), element.getMetaData().getUuid());
selectedVersion = element.getMetaData().getVersion();
- selectedAttachment=element.getMetaData().getAttachments().isEmpty()?null:0;
+ selectedAttachment = element.getMetaData().getAttachments().isEmpty() ? null : 0;
}
model.setVersions(versions);
@@ -143,6 +150,17 @@
// on positionne l'attachment selectionne
model.setSelectedAttachmentIndex(selectedAttachment);
+ // preparation de l'action de synchronisation
+
+ ShowSynchronizeTabAction synchronizeAction;
+ synchronizeAction = (ShowSynchronizeTabAction) SimExplorerActionManager.newAction("showTab_synchronize", (AbstractButton) null);
+ if (element == null) {
+ synchronizeAction.clear();
+ } else {
+ synchronizeAction.setRemote(model.isRemote());
+ synchronizeAction.setUuid(model.getDetail().getUuid());
+ synchronizeAction.setVersion(model.getDetail().getVersion());
+ }
}
/**
@@ -207,7 +225,7 @@
selectedVersion.toString()
);
- selectedAttachment=metas.getAttachments().isEmpty()?null:0;
+ selectedAttachment = metas.getAttachments().isEmpty() ? null : 0;
model.setDetail(metas);
@@ -216,6 +234,13 @@
// on positionne l'attachment selectionne
model.setSelectedAttachmentIndex(selectedAttachment);
+
+ // preparation de l'action de synchronisation
+ ShowSynchronizeTabAction synchronizeAction;
+ synchronizeAction = (ShowSynchronizeTabAction) SimExplorerActionManager.newAction("synchronizeElement", (AbstractButton) null);
+ synchronizeAction.setRemote(isRemote());
+ synchronizeAction.setUuid(metas.getUuid());
+ synchronizeAction.setVersion(metas.getVersion());
}
/**
@@ -304,7 +329,7 @@
// change the selection, and we don't want the model to be updated
// again
setEnabled(false);
- SimExplorerUIRefreshHelper.refreshDownloadAttachmentAction(ui, model);
+ SimExplorerUIRefreshHelper.refreshDownloadAttachmentAction(ui, model);
setEnabled(wasEnable);
}
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowSynchronizeTabAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowSynchronizeTabAction.java 2008-02-12 01:36:33 UTC (rev 852)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ShowSynchronizeTabAction.java 2008-02-12 01:39:20 UTC (rev 853)
@@ -1,5 +1,5 @@
/*
-* \#\#% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin,
+* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin,
* Tony Chemit, Gabriel Landais
*
* This program is free software; you can redistribute it and/or
@@ -15,14 +15,25 @@
* 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 fr.cemagref.simexplorer.is.ui.swing.actions;
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.ui.StorageServiceHelper;
+import fr.cemagref.simexplorer.is.ui.swing.JSynchronizeTab;
+import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTab;
+import fr.cemagref.simexplorer.is.ui.swing.SimExplorerUIRefreshHelper;
import fr.cemagref.simexplorer.is.ui.swing.actions.util.ShowTabAbstractAction;
+import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode;
import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel;
-import fr.cemagref.simexplorer.is.ui.swing.JSynchronizeTab;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.TreePath;
import java.awt.event.ActionEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
/**
* Action pour afficher le tab de synchronisation
@@ -30,33 +41,184 @@
* @author chemit
*/
@jaxx.runtime.builder.ActionConfig(
- actionCommand = "showtag_synchronize",
+ actionCommand = "showTab_synchronize",
name = "simexplorer.action.show.synchronize",
shortDescription = "simexplorer.action.show.synchronize.tooltip",
longDescription = "simexplorer.action.show.synchronize.help",
smallIcon = "action/reload.png",
mnemonic = 'S',
- hideActionText = false
+ hideActionText = true
)
public class ShowSynchronizeTabAction extends ShowTabAbstractAction<JSynchronizeTab, SynchronizeTabModel> {
+
+ /** flag pour indiquer si la source vient de la base locale ou distante */
+ protected Boolean remote;
+ /** l'uuid de l'éléement que l'on veut synchroniser */
+ protected String uuid;
+ /** la version de l'élément que l'on veut synchroniser */
+ protected Version version;
private static final long serialVersionUID = -3901398502496915785L;
+ protected TreeSelectionListener navigationLocalListener;
+
+ protected TreeSelectionListener navigationRemoteListener;
+
public ShowSynchronizeTabAction(String name) {
super(name);
+ navigationLocalListener = new NavigationLocalSelectionListener();
+ navigationRemoteListener = new NavigationRemoteSelectionListener();
}
+ public void setRemote(Boolean remote) {
+ this.remote = remote;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public void setVersion(Version version) {
+ this.version = version;
+ }
+
@Override
protected boolean beforeAction(ActionEvent e) throws Exception {
- //TODO
- return super.beforeAction(e);
+ if (!super.beforeAction(e) || remote == null || uuid == null || version == null) {
+ return false;
+ }
+ LoggableElement source = StorageServiceHelper.getElement(getContext(), remote, uuid, version.toString());
+
+ LoggableElement destination;
+ // recuperation des versions de l'element destination
+ Version[] versions = StorageServiceHelper.getVersions(getContext(), !remote, uuid);
+ if (versions.length == 0) {
+ destination = null;
+ } else {
+ // on prend la dernière version disponible dans la base
+ destination = StorageServiceHelper.getElement(getContext(), !remote, uuid, versions[versions.length - 1].toString());
+ }
+
+ // preparation du model de l'onglet
+ SynchronizeTabModel model = (SynchronizeTabModel) SimExplorerTab.synchronize.getModel();
+ model.setRemote(remote);
+ model.setSource(source);
+ model.setDestination(destination);
+
+ model.resetSelectedNodes();
+ return true;
}
protected void initFirstUsage(JSynchronizeTab ui, SynchronizeTabModel model) {
- //TODO
+ // add a listener on navigation tree
+ ui.getContentTreeLocal().addTreeSelectionListener(navigationLocalListener);
+ ui.getContentTreeRemote().addTreeSelectionListener(navigationRemoteListener);
}
protected void initUI(JSynchronizeTab ui, SynchronizeTabModel model) {
- //TODO
+ SimExplorerUIRefreshHelper.refreshTreeLocalActions(ui, null);
+ SimExplorerUIRefreshHelper.refreshTreeRemoteActions(ui, null);
+ SimExplorerUIRefreshHelper.refreshExportElementToLocalAction(ui, model);
+ SimExplorerUIRefreshHelper.refreshExportElementToRemoteAction(ui, model);
+
+ SimExplorerUIRefreshHelper.updateSynchronizeNavigationTrees(ui, model);
}
+ @Override
+ protected void clear() {
+ super.clear();
+ remote = null;
+ uuid = null;
+ version = null;
+ }
+
+ /**
+ * The listener of the selection in local navigation tree.
+ *
+ * @author chemit
+ */
+ protected class NavigationLocalSelectionListener implements TreeSelectionListener, PropertyChangeListener {
+
+ public NavigationLocalSelectionListener() {
+ getTabModel().addPropertyChangeListener(SynchronizeTabModel.Properties.SELECTED_LOCAL_NODE_PROPERTY_CHANGED, this);
+ }
+
+ public void valueChanged(TreeSelectionEvent e) {
+ SynchronizeTabModel model = getTabModel();
+
+ TreePath path = e.getNewLeadSelectionPath();
+ LoggableElementTreeNode node = null;
+ if (path != null) {
+ node = (LoggableElementTreeNode) path.getLastPathComponent();
+ }
+ // on rafraichit toujours ici les actions de l'arbre qui sont
+ // indépendantes du model et dépendent juste dunoeud sélectionné
+ SimExplorerUIRefreshHelper.refreshTreeLocalActions(getTabUI(), node);
+
+ Object o = node == null ? null : node.getUserObject();
+
+ // update history list
+ LoggableElement element = (LoggableElement) (o == null || !(o instanceof LoggableElement) ? null : o);
+
+ // le node est acceptable uniquement si c'est un loggableElement
+ model.setLocalSelectedNode(element);
+ }
+
+ /**
+ * Notify a modification in the model.
+ * <p/>
+ * This method will update ui.
+ *
+ * @param evt event coming from DetailTabModel
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+ log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue());
+ SimExplorerUIRefreshHelper.refreshExportElementToRemoteAction(getTabUI(), getTabModel());
+ }
+ }
+
+ /**
+ * The listener of the selection in local navigation tree.
+ *
+ * @author chemit
+ */
+ protected class NavigationRemoteSelectionListener implements TreeSelectionListener, PropertyChangeListener {
+
+ public NavigationRemoteSelectionListener() {
+ getTabModel().addPropertyChangeListener(SynchronizeTabModel.Properties.SELECTED_REMOTE_NODE_PROPERTY_CHANGED, this);
+ }
+
+ public void valueChanged(TreeSelectionEvent e) {
+ SynchronizeTabModel model = getTabModel();
+
+ TreePath path = e.getNewLeadSelectionPath();
+ LoggableElementTreeNode node = null;
+ if (path != null) {
+ node = (LoggableElementTreeNode) path.getLastPathComponent();
+ }
+ // on rafraichit toujours ici les actions de l'arbre qui sont
+ // indépendantes du model et dépendent juste dunoeud sélectionné
+ SimExplorerUIRefreshHelper.refreshTreeRemoteActions(getTabUI(), node);
+
+ Object o = node == null ? null : node.getUserObject();
+
+ // update history list
+ LoggableElement element = (LoggableElement) (o == null || !(o instanceof LoggableElement) ? null : o);
+
+ // le node est acceptable uniquement si c'est un loggableElement
+ model.setRemoteSelectedNode(element);
+ }
+
+ /**
+ * Notify a modification in the model.
+ * <p/>
+ * This method will update ui.
+ *
+ * @param evt event coming from DetailTabModel
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+ log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue());
+ SimExplorerUIRefreshHelper.refreshExportElementToLocalAction(getTabUI(), getTabModel());
+ }
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java 2008-02-12 01:36:33 UTC (rev 852)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SynchronizeTabModel.java 2008-02-12 01:39:20 UTC (rev 853)
@@ -18,10 +18,12 @@
* ##% */
package fr.cemagref.simexplorer.is.ui.swing.model;
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
import fr.cemagref.simexplorer.is.ui.swing.SimExplorerTab;
import jaxx.runtime.builder.TabModel;
import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
/**
* Le model pour un Tab contenant 2 listes d'applications
@@ -30,19 +32,28 @@
*/
public class SynchronizeTabModel implements TabModel {
+ public enum Properties {
+ SELECTED_LOCAL_NODE_PROPERTY_CHANGED,
+ SELECTED_REMOTE_NODE_PROPERTY_CHANGED
+ }
+
protected SimExplorerTab tab;
/** flag pour savoir si la source est remote ou non */
protected boolean remote;
- /** le model de l'arbre local */
- protected DetailTabModel localModel;
+ private static final long serialVersionUID = -3623331875470531459L;
- /** le model de l'arbre distant */
- protected DetailTabModel remoteModel;
+ /** l'élément source de la demande de synchronisation */
+ protected LoggableElement destination;
- private static final long serialVersionUID = -3623331875470531459L;
+ /** l'élément destination de la demande de synchronisation */
+ protected LoggableElement source;
+ protected LoggableElement remoteSelectedNode;
+
+ protected LoggableElement localSelectedNode;
+
public String getName() {
return tab.name();
}
@@ -51,14 +62,22 @@
return remote;
}
- public DetailTabModel getLocalModel() {
- return localModel;
+ public LoggableElement getSource() {
+ return source;
}
- public DetailTabModel getRemoteModel() {
- return remoteModel;
+ public LoggableElement getDestination() {
+ return destination;
}
+ public LoggableElement getLocalSelectedNode() {
+ return localSelectedNode;
+ }
+
+ public LoggableElement getRemoteSelectedNode() {
+ return remoteSelectedNode;
+ }
+
public void setName(String name) {
this.tab = SimExplorerTab.valueOf(name);
}
@@ -67,23 +86,81 @@
this.remote = remote;
}
- public synchronized void removePropertyChangeListeners() {
- if (localModel!=null) {
- localModel.removePropertyChangeListeners();
+ public void setSource(LoggableElement source) {
+ this.source = source;
+ }
+
+ public void setDestination(LoggableElement destination) {
+ this.destination = destination;
+ }
+
+ public void setLocalSelectedNode(LoggableElement localSelectedNode) {
+ LoggableElement oldSelectedNode = this.localSelectedNode;
+ this.localSelectedNode = localSelectedNode;
+ firePropertyChange(Properties.SELECTED_LOCAL_NODE_PROPERTY_CHANGED, oldSelectedNode, localSelectedNode);
+ }
+
+ public void setRemoteSelectedNode(LoggableElement remoteSelectedNode) {
+ LoggableElement oldSelectedNode = this.remoteSelectedNode;
+ this.remoteSelectedNode = remoteSelectedNode;
+ firePropertyChange(Properties.SELECTED_REMOTE_NODE_PROPERTY_CHANGED, oldSelectedNode, remoteSelectedNode);
+ }
+
+ public void resetSelectedNodes() {
+ localSelectedNode = remoteSelectedNode = null;
+ }
+
+ protected PropertyChangeSupport changeSupport;
+
+ public synchronized void addPropertyChangeListener(Properties propertyName, PropertyChangeListener listener) {
+ if (listener == null) {
+ return;
}
- if (remoteModel!=null) {
- remoteModel.removePropertyChangeListeners();
- }
+ if (changeSupport == null) {
+ changeSupport = new PropertyChangeSupport(this);
+ }
+ changeSupport.addPropertyChangeListener(propertyName.name(), listener);
}
- public synchronized void addPropertyChangeListener(DetailTabModel.Properties propertyName, PropertyChangeListener listener) {
+
+ public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
if (listener == null) {
return;
}
- if (localModel!=null) {
- localModel.addPropertyChangeListener(propertyName,listener);
+ if (changeSupport == null) {
+ changeSupport = new PropertyChangeSupport(this);
}
- if (remoteModel!=null) {
- remoteModel.addPropertyChangeListener(propertyName,listener);
+ changeSupport.addPropertyChangeListener(listener);
+ }
+
+ public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
+ if (listener == null || changeSupport == null) {
+ return;
}
+ changeSupport.removePropertyChangeListener(listener);
}
+
+ public synchronized void removePropertyChangeListeners() {
+ if (changeSupport == null) {
+ return;
+ }
+ for (PropertyChangeListener listener : getPropertyChangeListeners()) {
+ changeSupport.removePropertyChangeListener(listener);
+ }
+ }
+
+ public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
+ if (changeSupport == null) {
+ return new PropertyChangeListener[0];
+ }
+ return changeSupport.getPropertyChangeListeners();
+ }
+
+ public void firePropertyChange(Properties propertyName, Object oldValue, Object newValue) {
+ if (changeSupport == null || (oldValue == null && newValue == null) ||
+ (oldValue != null && oldValue.equals(newValue))) {
+ return;
+ }
+ changeSupport.firePropertyChange(propertyName.name(), oldValue, newValue);
+ }
+
}
\ No newline at end of file