r1143 - in trunk/simexplorer-is/simexplorer-is-swing/src: java/fr/cemagref/simexplorer/is/ui/swing java/fr/cemagref/simexplorer/is/ui/swing/ui test/fr/cemagref/simexplorer/is/ui/swing test/fr/cemagref/simexplorer/is/ui/swing/ui
Author: tchemit Date: 2008-02-20 18:45:16 +0000 (Wed, 20 Feb 2008) New Revision: 1143 Added: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/DetailTabRefreshHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabRefreshHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/MainUIRefreshHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SynchronizeTabRefreshHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/test/fr/cemagref/simexplorer/is/ui/swing/ui/ trunk/simexplorer-is/simexplorer-is-swing/src/test/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerUIRefreshHelperTest.java Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/DetailTabRefreshHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/EntityTreeNodeHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ListTabRefreshHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/MainUIRefreshHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTab.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SynchronizeTabRefreshHelper.java Log: move ui to ui package Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/DetailTabRefreshHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/DetailTabRefreshHelper.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/DetailTabRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,294 +0,0 @@ -/* -* ##% 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 -* 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 fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.entities.EntityHelper; -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.entities.metadata.Version; -import fr.cemagref.simexplorer.is.ui.SimExplorer; -import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.DetailTableModel; -import fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode; -import fr.cemagref.simexplorer.is.ui.swing.model.HistoryModel; -import static org.codelutin.i18n.I18n._; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.DefaultListModel; -import javax.swing.JList; -import javax.swing.JTable; -import javax.swing.tree.DefaultTreeModel; -import java.awt.Dimension; -import java.awt.Rectangle; -import java.text.SimpleDateFormat; -import java.util.List; - -/** - * Cette classe contient les méthodes utiles et réutilisables pour rafraichir - * l'onglet de detail. - * <p/> - * Les méthodes utilisent les données stockées dans les modèles pour rafraichir - * les uis concernées. - * <p/> - * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> - * <p/> - * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) - * mais uniquement à partir de nos modèles. - * - * @author chemit - */ -public class DetailTabRefreshHelper { - - public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS"); - - public static void refreshDetailTab(JDetailTab ui, DetailTabModel model) { - EntityTreeNode root = EntityTreeNodeHelper.build(model.getRootNode(), model.isRemote()); - EntityTreeNode current = model.getHistory().getCurrent(); - //FIXME : if object has different version, it says that this is same!!! - if (current == null || !root.getUserObject().equals(current.getUserObject())) { - model.getHistory().add(root); - } - DetailTabRefreshHelper.updateDetailNavigationTree(ui, model.getHistory()); - } - - /** - * Rafraichit les actions d'un node dans l'arbre de navigation - * - * @param ui l'onglet de détail - * @param model le model de d'onglet detail - * @param node le node sélectionné dans l'arbre de navigation - */ - public static void refreshDetailActions(JDetailTab ui, DetailTabModel model, EntityTreeNode node) { - // refresh synchronize action button - refreshSynchroniseAction(ui, model); - // refresh download LoggableElement button - refreshDownloadElementAction(ui, model, node); - // refresh delete button - refreshDeleteAction(ui, model); - // refresh export button - refreshExportAction(ui, model); - // refresh download Attachment button - refreshDownloadAttachmentAction(ui, model); - } - - public static void refreshTreeDetailActions(JDetailTab ui, EntityTreeNode node) { - EntityTreeNodeHelper.refreshTreeActions(ui.getCollapseAllDetail(), ui.getExpandAllDetail(), node); - } - - public static void refreshDownloadElementAction(JDetailTab ui, DetailTabModel model, EntityTreeNode node) { - MetaData detail = model.getDetail(); - boolean enabled = EntityHelper.Action.DOWNLOAD.accept(node); - MainUIRefreshHelper.UpdateButton(ui.getDownloadElement(), enabled, enabled ? detail == null ? node.getUserObject() : detail.getName() + " [" + model.getSelectedVersion() + "]" : null); - } - - protected static void refreshDeleteAction(JDetailTab ui, DetailTabModel model) { - MetaData detail = model.getDetail(); - boolean enabled = EntityHelper.Action.DELETE.accept(detail); - MainUIRefreshHelper.UpdateButton(ui.getDeleteElement(), enabled, enabled ? detail.getName() + " [" + model.getSelectedVersion() + "]" : null); - } - - public static void refreshDownloadAttachmentAction(JDetailTab ui, DetailTabModel model) { - Attachment attachment = model.getSelectedAttachment(); - boolean enabled = model.getDetail() != null && attachment != null; - MainUIRefreshHelper.UpdateButton(ui.getDownloadAttachment(), enabled, enabled ? attachment : null); - } - - public static void refreshDetailToTreeAction(JDetailTab ui, DetailTabModel model) { - MetaData detail = model.getDetail(); - EntityTreeNode rootNode = model.getHistory().getCurrent(); - LoggableElement rootElement = (LoggableElement) rootNode.getUserObject(); - MetaData data = rootElement.getMetaData(); - Version version = model.getSelectedVersion(); - if (version == null) { - // la version peut être null, ce qui veut dire que l'on vient d'un changement - // de node dans l'arbre de navigation et donc la version est celle du detai - version = detail.getVersion(); - } - boolean enabled = !(detail.getName().equals(data.getName()) && data.getVersion().equals(version)); - - MainUIRefreshHelper.UpdateButton(ui.getDetailToTree(), enabled, enabled ? detail.getName() + " [" + version + "]" : null); - } - - public static void refreshSynchroniseAction(JDetailTab ui, DetailTabModel model) { - MetaData detail = model.getDetail(); - boolean enabled = detail != null && SimExplorer.getContext().isConnected(); - MainUIRefreshHelper.UpdateButton(ui.getShowTab_synchronize(), enabled, enabled ? detail.getName() + " [" + model.getSelectedVersion() + "]" : null); - } - - public static void refreshExportAction(JDetailTab ui, DetailTabModel model) { - LoggableElement sNode = model.getSelectedNode(); - MainUIRefreshHelper.refreshExportElement(ui.getExportElement(), - model.isRemote(), - sNode); - } - - public static void resetHistory(JDetailTab ui, DetailTabModel model, DefaultComboBoxModel historyModel) { - historyModel.removeAllElements(); - LoggableElement selectedNode = model.getSelectedNode(); - Version[] versions = model.getVersions(); - boolean nodetail = versions == null || selectedNode == null; - if (nodetail) { - resetDetailPanel(ui); - } else { - ui.getDetailHeaderFromLocal().setVisible(!model.isRemote()); - ui.getDetailHeaderFromRemote().setVisible(model.isRemote()); - for (Version version : versions) { - historyModel.addElement(version); - } - boolean enabled = ui.getDetailVersions().getItemCount() > 1; - ui.getDetailVersions().setEnabled(enabled); - String text; - text = !enabled ? null : _("simexplorer.action.changeVersion.tooltip"); - ui.getDetailVersions().setToolTipText(text); - } - // can not synchronize to tree - MainUIRefreshHelper.UpdateButton(ui.getDetailToTree(), false); - } - - public static void resetDetailPanel(final JDetailTab ui) { - ui.getDetailVersions().setVisible(false); - ui.getDetailHeader().setText(_("simexplorer.node.nodetail")); - ui.getDetailAttachmentsHeader().setText(_("simexplorer.node.noattachments")); - JList listAttchments = ui.getDetailAttachments(); - listAttchments.clearSelection(); - DefaultListModel listModel = (DefaultListModel) listAttchments.getModel(); - listModel.setSize(0); - listModel.trimToSize(); - ui.getDetail().setVisible(false); - ((DetailTableModel) ui.getDetailTable().getModel()).setData(null); - } - - public static void updateDetailNavigationTree(JDetailTab ui, HistoryModel<EntityTreeNode> model) { - // push it in tree model - ((DefaultTreeModel) ui.getNavigationTree().getModel()).setRoot(model.getCurrent()); - // by default select the root node - if (ui.getNavigationTree().getModel().getRoot() != null) { - ui.getNavigationTree().setSelectionRow(0); - } - boolean enabled; - enabled = model.size() > 1 && model.hasPrevious(); - MainUIRefreshHelper.UpdateButton(ui.getHistoryPrevious(), enabled, !enabled ? null : model.getPrevious()); - enabled = model.size() > 1 && model.hasNext(); - MainUIRefreshHelper.UpdateButton(ui.getHistoryNext(), enabled, !enabled ? null : model.getNext()); - } - - public static void updateDetailPanel(Integer index, final JDetailTab ui, DetailTabModel model, LoggableElement selectedNode) { - MetaData detail = model.getDetail(); - ui.getDetailVersions().setVisible(true); - if (ui.getDetailVersions().getItemCount() > 0) { - ui.getDetailVersions().setSelectedIndex(index); - } - ui.getDetailHeader().setText(selectedNode.getMetaData().getName()); - ui.getDetailDescriptorsHeader().setText(_("simexplorer.node.descriptors", detail.getDescriptors().size())); - ui.getDetailType().setText(EntityHelper.Type.getLibelle(detail)); - String s = detail.getDescription(); - String tooltip = s; - if (s.length() > 32) { - s = s.substring(0, 32) + "..."; - } - ui.getDetailDescription().setText(s); - if (!s.equals(tooltip)) { - ui.getDetailDescription().setToolTipText(tooltip); - } - ui.getDetailCreationDate().setText(DATE_FORMAT.format(detail.getCreationDate())); - ui.getDetail().setVisible(true); - JTable table = ui.getDetailTable(); - ((DetailTableModel) table.getModel()).setData(detail); - int nbDescriptorRows = table.getRowCount(); - - List<Attachment> attachments = detail.getAttachments(); - JList listAttachments = ui.getDetailAttachments(); - DefaultListModel listModel = (DefaultListModel) listAttachments.getModel(); - listModel.setSize(0); - listModel.trimToSize(); - int nbAttachmentRows; - if (attachments.isEmpty()) { - ui.getDetailAttachmentsHeader().setText(_("simexplorer.node.noattachments")); - ui.getScrollAttachments().setVisible(false); - nbAttachmentRows = 0; - } else { - ui.getDetailAttachmentsHeader().setText(EntityHelper.Type.Attachment.getLibelles() + " (" + attachments.size() + ")"); - for (Attachment attachment : attachments) { - listModel.addElement(attachment); - } - listAttachments.setSelectedIndex(0); - nbAttachmentRows = listModel.getSize(); - ui.getScrollAttachments().setVisible(true); - } - - int[] rows = computeRows(nbDescriptorRows, nbAttachmentRows); - - Dimension dimOneRow = table.getUI().getPreferredSize(table.getTableHeader()); - - ui.getScrollTable().setPreferredSize(new Dimension((int) dimOneRow.getWidth(), 2 + ((rows[0] + 1) * (4 + table.getFont().getSize())))); - //ui.getScrollTable().setPreferredSize(new Dimension((int) table.getSize().getWidth(), 2 + (nbDescriptorRows * (4 + table.getFont().getSize())))); - if (nbAttachmentRows > 0) { - Rectangle rect = listAttachments.getUI().getCellBounds(listAttachments, 0, 0); - ui.getScrollAttachments().setPreferredSize(new Dimension((int) rect.getWidth() - 4, (int) (3 + rows[1] * rect.getHeight()))); - } - - table.invalidate(); - listAttachments.invalidate(); - ui.getScrollPane().invalidate(); - ui.repaint(); - } - - protected static int[] computeRows(int nbDescriptorRows, int nbAttachmentRows) { - int[] result = new int[2]; - int max = 14; - int maxOne = max / 2; - if (nbDescriptorRows == 0) { - result[0] = 0; - result[1] = nbAttachmentRows > max ? max : nbAttachmentRows; - return result; - } - if (nbAttachmentRows == 0) { - result[0] = nbDescriptorRows > max ? max : nbDescriptorRows; - result[1] = 0; - return result; - } - if (nbAttachmentRows < maxOne + 1 && nbDescriptorRows < maxOne + 1) { - result[0] = nbDescriptorRows; - result[1] = nbAttachmentRows; - return result; - } - if (nbDescriptorRows > maxOne && nbAttachmentRows > maxOne) { - result[0] = result[1] = maxOne; - return result; - } - if (nbDescriptorRows < maxOne + 1) { - result[0] = nbDescriptorRows; - int i = max - nbDescriptorRows; - result[1] = nbAttachmentRows < i ? nbAttachmentRows : i; - return result; - } - if (nbAttachmentRows < maxOne + 1) { - int i = max - nbAttachmentRows; - result[0] = nbDescriptorRows < i ? nbDescriptorRows : i; - result[1] = nbAttachmentRows; - return result; - } - throw new IllegalStateException("can not come her :)"); - } - - protected DetailTabRefreshHelper() { - // do not instanciate me please - } -} \ No newline at end of file Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/EntityTreeNodeHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/EntityTreeNodeHelper.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/EntityTreeNodeHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,308 +0,0 @@ -/* -* ##% Copyright (C) 2007, 2008 Code Lutin, -* Tony Chemit, Gabriel Landais -* -* 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 fr.cemagref.simexplorer.is.ui.swing; - -import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Code; -import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Component; -import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Constant; -import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.ConstantValue; -import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.ExplorationData; -import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Library; -import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Structure; -import fr.cemagref.simexplorer.is.entities.EntityVisitable; -import fr.cemagref.simexplorer.is.entities.SimpleEntityVisitor; -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.Constant; -import fr.cemagref.simexplorer.is.entities.data.ConstantValue; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.ExplorationData; -import fr.cemagref.simexplorer.is.entities.data.Library; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.data.Result; -import fr.cemagref.simexplorer.is.entities.data.Structure; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode; - -import javax.swing.AbstractButton; -import javax.swing.JTree; -import javax.swing.tree.TreePath; -import java.util.Collection; - -/** - * La classe responsable de la création des arbres de {@link fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode} - * à partir de {@link LoggableElement} . - * <p/> - * La classe possède une instance cachée par thread qui délègue la construction - * del'arbre de navigation à un visiteur de {@link LoggableElement}. - * <p/> - * - * @author chemit - */ -public class EntityTreeNodeHelper { - - /** L'instance cachée de builder par Thread. */ - protected static final ThreadLocal<EntityVisitorBuilder> builder = - new ThreadLocal<EntityVisitorBuilder>() { - @Override - protected EntityVisitorBuilder initialValue() { - return new EntityVisitorBuilder(); - } - }; - - /** - * Construit un arbre de navigation à partir d'un {@link LoggableElement}. - * - * @param v la donnée à visiter - * @param remote flag pour indiquer si on travaille sur des données locales - * ou en remote. - * @return le noeud parent de l'arbre de nivation construit. - */ - public static EntityTreeNode build(LoggableElement v, boolean remote) { - EntityVisitorBuilder instance; - synchronized (instance = EntityTreeNodeHelper.builder.get()) { - EntityTreeNode result; - // walk - result = instance.visit(v, remote); - return result; - } - } - - public static EntityTreeNode getSelectedNodeOrRootNode(JTree tree) { - EntityTreeNode node = getSelectedNode(tree); - if (node == null) { - return getRootNode(tree); - } - return node; - } - - public static EntityTreeNode getSelectedNode(JTree tree) { - TreePath path = tree.getSelectionPath(); - EntityTreeNode node = null; - if (path != null) { - Object o = path.getLastPathComponent(); - if (o != null && !(o instanceof EntityTreeNode)) { - return null; - } - node = (EntityTreeNode) o; - } - return node; - } - - public static EntityTreeNode getRootNode(JTree tree) { - EntityTreeNode node; - // take the root node - Object root = tree.getModel().getRoot(); - if (root == null || !(root instanceof EntityTreeNode)) { - return null; - } - node = (EntityTreeNode) root; - return node; - } - - public static void refreshTreeActions(AbstractButton collapseButton, AbstractButton expandButton, EntityTreeNode node) { - boolean enabled = node != null && !node.isLeaf() && node.getChildCount() > 0; - Object o = enabled?node.getUserObject():null; - MainUIRefreshHelper.UpdateButton(collapseButton, enabled, o ); - MainUIRefreshHelper.UpdateButton(expandButton, enabled, o); - } - - protected EntityTreeNodeHelper() { - // no instance - } - - /** - * Implantation de {@link SimpleEntityVisitor} pour construire l'arbre - * de navigation d'un {@link LoggableElement}. - * <p/> - * Cette classe est stateless, tous ces états internes doivent être nettoyé - * après une visite, en utilisant la méthode {@link #reset()}. - * <p/> - */ - public static class EntityVisitorBuilder extends SimpleEntityVisitor { - - /** - * le noeud parent de tous les autres. - * <p/> - * Ce noeud est positionné par la méthode - * {@link #markRootNode(EntityTreeNode)}. - */ - protected EntityTreeNode rootNode; - - /** - * flag qui indique si on travaille sur des objet locaux ou distants. - * <p/> - * Cette information est conservé dans les nodes pour permettre de gérer - * de manière transparent des objet locaux ou distants. - */ - protected Boolean remote; - - /** les nodes internes utilisés pendant la visite. */ - protected EntityTreeNode explorationApplication, - component, - explorationData, - components, - explorationDatas, - libraries, - constants, - strutures, - codes, - constantValues; - - public EntityTreeNode visit(EntityVisitable v, boolean remote) { - reset(); - try { - this.remote = remote; - super.visit(v); - EntityTreeNode result; - result = this.rootNode; - return result; - } finally { - reset(); - } - } - - @Override - public void visitMetaData(MetaData v) { - // do not visit meta data (for the moment we dont need thoses - // informations in navigation tree), but it could be interresting - // for example to display attchments here ? - } - - @Override - public void visitExplorationApplication(ExplorationApplication v) { - markRootNode(explorationApplication = new EntityTreeNode(null, v, remote, true)); - super.visitExplorationApplication(v); - } - - @Override - public void visitComponent(Component v) { - markRootNode(component = new EntityTreeNode(components, v, remote, true)); - super.visitComponent(v); - } - - @Override - public void visitExplorationData(ExplorationData v) { - markRootNode(explorationData = new EntityTreeNode(explorationDatas, v, remote, true)); - super.visitExplorationData(v); - } - - @Override - public void visitCodes(Collection<Code> vs) { - codes = new EntityTreeNode(component, Code.getLibelles(), remote, true); - super.visitCodes(vs); - } - - @Override - public void visitComponents(Collection<Component> vs) { - components = new EntityTreeNode(explorationApplication, Component.getLibelles(), remote, true); - super.visitComponents(vs); - } - - @Override - public void visitConstants(Collection<Constant> vs) { - constants = new EntityTreeNode(component, Constant.getLibelles(), remote, true); - super.visitConstants(vs); - } - - @Override - public void visitConstantValues(Collection<ConstantValue> vs) { - constantValues = new EntityTreeNode(explorationData, ConstantValue.getLibelles(), remote, true); - super.visitConstantValues(vs); - } - - @Override - public void visitExplorationDatas(Collection<ExplorationData> vs) { - explorationDatas = new EntityTreeNode(explorationApplication, ExplorationData.getLibelles(), remote, true); - super.visitExplorationDatas(vs); - } - - @Override - public void visitLibraries(Collection<Library> vs) { - libraries = new EntityTreeNode(component, Library.getLibelles(), remote, true); - super.visitLibraries(vs); - } - - @Override - public void visitStructures(Collection<Structure> vs) { - strutures = new EntityTreeNode(component, Structure.getLibelles(), remote, true); - super.visitStructures(vs); - } - - @Override - public void visitConstant(Constant v) { - markRootNode(new EntityTreeNode(constants, v, remote, false)); - } - - @Override - public void visitLibrary(Library v) { - markRootNode(new EntityTreeNode(libraries, v, remote, false)); - } - - @Override - public void visitResult(Result v) { - if (v != null) { - markRootNode(new EntityTreeNode(explorationData, v, remote, false)); - } - } - - @Override - public void visitCode(Code v) { - new EntityTreeNode(codes, v, remote, false); - } - - @Override - public void visitConstantValue(ConstantValue v) { - new EntityTreeNode( - new EntityTreeNode(constantValues, v.getConstant().getName(), remote, true), - v.getValue(), remote, false); - } - - @Override - public void visitStructure(Structure v) { - new EntityTreeNode(strutures, v, remote, false); - } - - /** - * Tente de marquerle node donné comme noeud ancêtre de tous les autres. - * <p/> - * Le positionnement n'a lieu que si on a pas encore de rootNode. - * - * @param node le node a positionner comme rootNode (si nessecaire) - */ - protected void markRootNode(EntityTreeNode node) { - if (rootNode == null) { - rootNode = node; - } - } - - /** - * La méthode pour réinitialiser les états interne de la classe. - * <p/> - * Cette méthode doit être appeler après chaque visite, afin d'assurer - * la propriété stateless de la classe. - */ - protected void reset() { - remote = null; - rootNode = explorationApplication = explorationDatas = explorationData - = components = component = constants = codes = libraries - = constantValues = null; - } - } -} Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ListTabRefreshHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ListTabRefreshHelper.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ListTabRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,176 +0,0 @@ -/* -* ##% 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 -* 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 fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.entities.EntityHelper; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.ui.SimExplorer; -import fr.cemagref.simexplorer.is.ui.swing.model.DataEntityModel; -import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.PaginationModel; - -import javax.swing.JComboBox; -import javax.swing.SwingUtilities; -import javax.swing.ListSelectionModel; - -/** - * Cette classe contient les méthodes utiles et réutilisables pour rafraichir - * les onglets de liste. - * <p/> - * Les méthodes utilisent les données stockées dans les modèles pour rafraichir - * les uis concernées. - * <p/> - * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> - * <p/> - * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) - * mais uniquement à partir de nos modèles. - * - * @author chemit - */ -public class ListTabRefreshHelper { - - /** - * Rafraichit un onglet de type liste à partir de son modèle. - * - * @param ui l'onglet de liste à utiliser - * @param model le modèle de liste à utiliser - */ - public static void refreshListTabUI(final JListTab ui, final ListTabModel model) { - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - - // refresh search text - ui.getSearchText().setText(model.getQuery().getQuery()); - - // refresh search actions - refreshSearchActions(ui, model); - - // refresh pagination actions - refreshPagination(ui, model.getPagination()); - - - ListSelectionModel selectionModel = ui.getTable().getSelectionModel(); - if (!model.isEmpty() && selectionModel.isSelectionEmpty()) { - // always select the first row (to init selectedItem) - selectionModel.setSelectionInterval(0, 0); - } else { - selectionModel.clearSelection(); - } - - // table data model may have changed, must revalidate - ui.getTable().invalidate(); - - // repaint the frame - SimExplorer.getUI().repaint(); - } - }); - } - - public static void refreshListTablePopupMenu(final JListTab ui, final ListTabModel model) { - DataEntityModel item = model.getSelectedItem(); - ui.getTablePopupMenu().setEnabled(item != null); - int index = model.getSelectedIndex(); - if (item == null || index==-1) { - return; - } - MetaData data = model.get(index); - - String text = data.getName() + " [" + data.getVersion() + "]"; - - MainUIRefreshHelper.UpdateButton(ui.getDownloadElement(), EntityHelper.Action.DOWNLOAD.accept(data), text); - - MainUIRefreshHelper.UpdateButton(ui.getDeleteElement(), EntityHelper.Action.DELETE.accept(data), text); - - boolean isConnected = SimExplorer.getContext().isConnected(); - boolean enabled = isConnected && EntityHelper.Action.EXPORT.accept(data); - - MainUIRefreshHelper.refreshExportElement(ui.getExportElement(),enabled, model.isRemote(),data.getName(),data.getVersion().toString()); - - MainUIRefreshHelper.UpdateButton(ui.getShowTab_detail(), true, text); - MainUIRefreshHelper.UpdateButton(ui.getShowTab_synchronize(), isConnected, text); - } - - /** - * Rafraichit les actions de recherche d'un onglet de type liste. - * - * @param ui l'onglet de liste à utiliser - * @param model le modèle de liste à utiliser - */ - public static void refreshSearchActions(JListTab ui, ListTabModel model) { - String text = ui.getSearchText().getText(); - boolean hasQuery = model.getQuery().hasQuery(); - ui.getSearch().setEnabled(hasQuery || !text.isEmpty()); - ui.getResetSearch().setEnabled(hasQuery || !text.isEmpty()); - } - - public static void refreshPagination(JListTab ui, PaginationModel pagination) { - - // refresh changePage combobox - refreshChangePageCombo(ui, pagination); - - // refresh changeSizor combo - refreshChangeSizorCombo(ui, pagination); - - int page = pagination.getCurrentPage(); - boolean notLast = page + 1 < pagination.getNbPages(); - ui.getGoNextPage().setEnabled(notLast); - ui.getGoLastPage().setEnabled(notLast); - boolean notFirstPage = !(pagination.getSize() < 2 || page<1); - ui.getGoFirstPage().setEnabled(notFirstPage); - ui.getGoPreviousPage().setEnabled(notFirstPage); - } - - public static void refreshChangeSizorCombo(JListTab ui, PaginationModel pagination) { - JComboBox combo = ui.getChangeSizor(); - String s = pagination.getWidth() + ""; - if (!s.equals(String.valueOf(combo.getSelectedItem()))) { - combo.setEnabled(false); - combo.setSelectedItem(s); - combo.setEnabled(true); - } - } - - public static void refreshChangePageCombo(JListTab ui, PaginationModel pagination) { - JComboBox combo = ui.getGoPage(); - long size = pagination.getNbPages(); - combo.setEnabled(false); - //System.out.println("page old size : " + combo.getItemCount() + " new size : " + size); - if (size < combo.getItemCount()) { - while (size < combo.getItemCount()) { - combo.removeItemAt(combo.getItemCount() - 1); - } - } else { - while (size > combo.getItemCount()) { - combo.addItem(combo.getItemCount()); - } - } - //System.out.println("new page size : " + combo.getItemCount()); - if (combo.getItemCount()>0) { - combo.setSelectedIndex(pagination.getCurrentPage()); - } - boolean b = combo.getItemCount() > 1; - combo.setEnabled(b); - ui.getCurrentPage().setEnabled(b); - } - - protected ListTabRefreshHelper() { - // do not instanciate me please - } -} \ No newline at end of file Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/MainUIRefreshHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/MainUIRefreshHelper.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/MainUIRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,160 +0,0 @@ -/* -* ##% 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 -* 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 fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.entities.EntityHelper; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.ui.swing.actions.ExportElementAction; -import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractAction; -import static org.codelutin.i18n.I18n._; - -import javax.swing.AbstractButton; - -/** - * Cette classe contient les méthodes utiles et réutilisables pour rafraichit - * les ui. - * <p/> - * Les méthodes utilisent les données stockées dans les modèles pour rafraichir - * les uis concernées. - * <p/> - * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> - * <p/> - * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) - * mais uniquement à partir de nos modèles. - * - * @author chemit - */ -public class MainUIRefreshHelper { - - - public static void refreshExportElement(AbstractButton button, boolean remote, LoggableElement sNode) { - boolean enabled = EntityHelper.Action.EXPORT.accept(sNode); - refreshExportElement(button, enabled, remote, enabled ? sNode.getMetaData().getName() : null, enabled ? sNode.getMetaData().getVersion().toString() : null); - } - - public static void refreshExportElement(AbstractButton button, boolean enabled, boolean remote, String name, String version) { - button.setEnabled(enabled); - String t = null; - if (enabled) { - ExportElementAction action = (ExportElementAction) button.getAction(); - t = _(action.getI18nToolTipText(remote), name, version); - } - button.setToolTipText(t); - } - - protected static void UpdateButton(AbstractButton button, boolean enabled, Object... params) { - button.setEnabled(enabled); - if (!enabled) { - button.setToolTipText(null); - } else { - - } - SimExplorerAbstractAction action = (SimExplorerAbstractAction) button.getAction(); - String t = _(action.getI18nToolTipText(), params); - button.setToolTipText(t); - } - - - protected MainUIRefreshHelper() { - // do not instanciate me please - } - -} - -/** - * Rafraichit les uis après un changement de status de connexion de l'utilisateur. - * <p/> - * Si l'utilisateur est déconnecté, alors toutes les ui et actions liées au - * mode remote sont fermées et les actions correspondantes sont rendues - * inaccessibles. - * - * @param ui l'ui principale - * @param isConnected flag pour indique si l'utiliseur est connecté - * @param history l'historique de l'onglet de detail - */ -/* public static void refreshConnnectState(SimExplorerMainUI ui, final boolean isConnected, HistoryModel<EntityTreeNode> history) { - - //SwingUtilities.invokeLater(new Runnable() { - // public void run() { - ui.getConnect().setEnabled(!isConnected); - ui.getUnconnect().setEnabled(isConnected); - ui.getShowTab_remote().setEnabled(isConnected); - ui.getToggleTab_remote().setEnabled(isConnected); - - JTabbedPane container = ui.getContent(); - DetailTabModel model = (DetailTabModel) SimExplorerTab.detail.getModel(); - JDetailTab tabUI = (JDetailTab) SimExplorerTab.detail.getUI(); - if (!isConnected) { - // close all connected ui - - if (SimExplorerTab.remote.isTabVisible(container)) { - // close tab - SimExplorerTab.remote.closeTab(container); - } - if (SimExplorerTab.synchronize.isTabVisible(container)) { - // close tab - SimExplorerTab.synchronize.closeTab(container); - } - if (SimExplorerTab.detail.isTabVisible(container) && history != null) { - if (history.isEmpty()) { - // close tab, no more history - SimExplorerTab.detail.closeTab(container); - } else { - // select current history element - EntityTreeNode node = history.getCurrent(); - model.synch(node); - //model.setRemote(node.isRemote()); - //model.setRootNode((LoggableElement) node.getUserObject()); - DetailTabRefreshHelper.updateDetailNavigationTree(tabUI, model.getHistory()); - } - } - } - if (SimExplorerTab.detail.isTabVisible(container)) { - DetailTabRefreshHelper.refreshSynchroniseAction(tabUI, model); - DetailTabRefreshHelper.refreshExportAction(tabUI, model); - } - - if (SimExplorerTab.local.isTabVisible(container)) { - ListTabRefreshHelper.refreshListTablePopupMenu((JListTab) SimExplorerTab.local.getUI(), (ListTabModel) SimExplorerTab.local.getModel()); - } - // } - //}); -}*/ - -/** - * Rafraichit les actions i18n dans le menu en fonction de la locale - * actuellement utilisée. - * - * @param ui l'ui principale - */ -/*public static void refreshI18nActions(SimExplorerMainUI ui) { - LanguageEnum language = SimExplorer.getContext().getConfig().getUserLanguage(); - CountryEnum country = SimExplorer.getContext().getConfig().getUserCountry(); - String[] actions = SimExplorerActionManager.getFactory().getActionNames(); - for (String actionName : actions) { - Matcher matcher = ChangeI18nAbstractAction.PATTERN_NAME.matcher(actionName); - if (!matcher.matches()) { - continue; - } - AbstractButton button = (AbstractButton) ui.getObjectById(actionName); - ChangeI18nAbstractAction action = (ChangeI18nAbstractAction) button.getAction(); - boolean enable = !action.equalsLocale(language, country); - button.setEnabled(enable); - } -}*/ \ No newline at end of file Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,91 +0,0 @@ -/* -* ##% 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 -* 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 fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.ui.SimExplorer; -import fr.cemagref.simexplorer.is.ui.swing.actions.util.ChangeI18nAbstractAction; -import org.codelutin.i18n.CountryEnum; -import org.codelutin.i18n.LanguageEnum; - -import javax.swing.AbstractButton; -import javax.swing.JComponent; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.util.regex.Matcher; - -/** - * L'ui principale de l'application - * - * @author chemit - */ -public class SimExplorerMainUI extends SimExplorerUI { - - public SimExplorerMainUI() { - super(); - - // chargement dans l'ui des actions - SimExplorerActionManager.loadActions(this, null); - - // add Ctrl-W to close current tab - getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK), "closeTab"); - getRootPane().getActionMap().put("closeTab", SimExplorerActionManager.newAction("closeTab")); - // override Ctrl-F4 close application - getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_MASK), "quit"); - getRootPane().getActionMap().put("quit", SimExplorerActionManager.newAction("quit")); - - // repaint i18n actions - refreshI18nActions(); - } - - public void setStatus(final String msg) { - - Runnable runnable = new Runnable() { - public void run() { - //TODO il faut enlever le synchronize dans statusBar - //getStatusBar().setStatus(msg); - //System.out.println(msg); - } - }; - SwingUtilities.invokeLater(runnable); - } - - /** - * Rafraichit les actions i18n dans le menu en fonction de la locale - * actuellement utilisée. - */ - public void refreshI18nActions() { - - LanguageEnum language = SimExplorer.getContext().getConfig().getUserLanguage(); - CountryEnum country = SimExplorer.getContext().getConfig().getUserCountry(); - String[] actions = SimExplorerActionManager.getFactory().getActionNames(); - for (String actionName : actions) { - Matcher matcher = ChangeI18nAbstractAction.PATTERN_NAME.matcher(actionName); - if (!matcher.matches()) { - continue; - } - AbstractButton button = (AbstractButton) getObjectById(actionName); - ChangeI18nAbstractAction action = (ChangeI18nAbstractAction) button.getAction(); - boolean enable = !action.equalsLocale(language, country); - button.setEnabled(enable); - } - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTab.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTab.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTab.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,165 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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 fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; -import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel; -import jaxx.runtime.builder.TabContentConfig; -import jaxx.runtime.swing.JAXXTab; - -import javax.swing.JTabbedPane; -import javax.swing.JPopupMenu; -import java.awt.Component; - -/** - * La défintion des onglets utilisés dans l'application - * - * @author tony - */ - -public enum SimExplorerTab { - - @TabContentConfig( - impl = JDetailTab.class, - model = DetailTabModel.class, - parentImpl = JTabbedPane.class, - name = "simexplorer.tab.detail", - shortDescription = "simexplorer.tab.detail.tooltip" - )detail { - public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(U ui, M model) { - DetailTabRefreshHelper.refreshDetailTab((JDetailTab) ui, (DetailTabModel) model); - }}, - - @TabContentConfig( - impl = JListTab.class, - parentImpl = JTabbedPane.class, - model = ListTabModel.class, - useToogle = true, - name = "simexplorer.tab.local", - shortDescription = "simexplorer.tab.local.tooltip" - )local { - public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(U ui, M model) { - ListTabRefreshHelper.refreshListTabUI((JListTab) ui, (ListTabModel) model); - }}, - - @TabContentConfig( - impl = JListTab.class, - parentImpl = JTabbedPane.class, - model = ListTabModel.class, - useToogle = true, - name = "simexplorer.tab.remote", - shortDescription = "simexplorer.tab.remote.tooltip" - )remote { - public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(U ui, M model) { - ListTabRefreshHelper.refreshListTabUI((JListTab) ui, (ListTabModel) model); - }}, - - @TabContentConfig( - impl = JSynchronizeTab.class, - parentImpl = JTabbedPane.class, - model = SynchronizeTabModel.class, - useToogle = false, - name = "simexplorer.tab.synchronize", - shortDescription = "simexplorer.tab.synchronize.tooltip" - )synchronize { - public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(U ui, M model) { - SynchronizeTabRefreshHelper.refreshSynchronizeTab((JSynchronizeTab) ui, (SynchronizeTabModel) model); - } - }; - - /** l'usine de tabs */ - private static SimExplorerTabFactory factory; - - public static SimExplorerTabFactory getFactory() { - if (factory == null) { - factory = new SimExplorerTabFactory(); - } - return factory; - } - - /** - * recherche d'un onglet contenant un component. - * - * @param c le component dont on cherche l'onglet - * @return l'onglet parent du component, ou null si pas de tab trouvé - */ - public static SimExplorerTab findTab(Component c) { - Component parent = c.getParent(); - while (parent != null) { - if (parent instanceof JPopupMenu) { - parent = ((JPopupMenu)parent).getInvoker(); - } - if (parent instanceof JAXXTab) { - // find a JAXXTab - for (SimExplorerTab tab : values()) { - if (parent.equals(tab.getUI())) { - // find the correct tab - return tab; - } - } - break; - } - parent = parent.getParent(); - } - return null; - } - - public abstract <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(U ui, M model); - - public JAXXTab getUI() { - return getFactory().getUI(name()); - } - - public SimExplorerTabModel getModel() { - return getFactory().getModel(name()); - } - - public boolean isTabVisible(JTabbedPane container) { - JAXXTab ui = getUI(); - return ui != null && getFactory().getTabIndex(container, ui) > -1; - } - - public boolean isTabSelected(JTabbedPane container) { - return isTabVisible(container) && getFactory().getTabIndex(container, getUI()) == container.getSelectedIndex(); - } - - public int getTabIndex(JTabbedPane container) { - JAXXTab ui = getUI(); - return ui == null ? -1 : getFactory().getTabIndex(container, ui); - } - - public void showTab(final JTabbedPane container) { - getFactory().showTab(container, name()); - } - - public void closeTab(JTabbedPane container) { - getFactory().closeTab(container, name()); - getModel().setSelectedItem(null); - } - - public void updateUI() { - updateUI(getUI(), getModel()); - } - - public void removePropertyChangeListeners() { - getModel().removePropertyChangeListeners(); - } -} Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,137 +0,0 @@ -/* -* ##% 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 -* 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 fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.ui.SimExplorer; -import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; -import fr.cemagref.simexplorer.is.ui.swing.util.MyTabHeader; -import jaxx.runtime.JAXXObject; -import jaxx.runtime.builder.TabContentConfig; -import jaxx.runtime.builder.TabFactory; -import jaxx.runtime.swing.JAXXTab; -import static org.codelutin.i18n.I18n._; - -import javax.swing.AbstractButton; -import javax.swing.JComponent; -import javax.swing.JTabbedPane; -import java.awt.Component; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.lang.reflect.Field; -import java.util.Map; -import java.util.TreeMap; - -/** - * L'implatantion pour SimExplorer de la factory de Tab - * - * @author chemit - * @see TabFactory - */ -public class SimExplorerTabFactory extends TabFactory { - - protected Map<String, TabContentConfig> initFactory() { - Map<String, TabContentConfig> result = new TreeMap<String, TabContentConfig>(); - for (SimExplorerTab tab : SimExplorerTab.values()) { - try { - String tabName = tab.name(); - Field field = tab.getClass().getField(tabName); - result.put(tabName, field.getAnnotation(TabContentConfig.class)); - } catch (NoSuchFieldException e) { - throw new SimExplorerRuntimeException(e); - } - } - return result; - } - - protected void initTab(JAXXTab tab, String tabName, TabContentConfig config) { - SimExplorerActionManager.loadActions((JAXXObject) tab, getTab(tabName)); - } - - protected SimExplorerTab getTab(String tabName) { - return SimExplorerTab.valueOf(tabName); - } - - @Override - public SimExplorerTabModel getModel(String tabName) { - return (SimExplorerTabModel) super.getModel(tabName); - } - - @Override - protected JComponent addTabHeader(final JTabbedPane container, - String tabName, - TabContentConfig tab, - final JAXXTab comp) { - - final MyTabHeader panel = new MyTabHeader(); - - // add a dynamic reference to tab close button to enable - // dynamic action instanciation - //TODO add the ActionManager mecanism ? - String actionName = panel.getCloseTab().getName() + "_" + tabName; - - panel.get$objectMap().put(actionName, panel.getCloseTab()); - - // chargement dans l'ui des actions - SimExplorerActionManager.loadActions(panel, getTab(tabName)); - - panel.setToolTipText(_(tab.shortDescription())); - panel.getLabel().setText(_(tab.name())); - - panel.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - Component compOld = container.getSelectedComponent(); - if (!comp.equals(compOld)) { - //TODO should use the showTab_XXX action - container.setSelectedComponent(comp); - } - } - }); - return panel; - } - - @Override - public void showTab(final JTabbedPane container, String tabName) { - - super.showTab(container, tabName); - - switchToggleButton(tabName, true); - } - - @Override - public void closeTab(JTabbedPane container, String tabName) { - - super.closeTab(container, tabName); - - switchToggleButton(tabName, false); - } - - protected void switchToggleButton(String tabName, boolean b) { - - TabContentConfig tab = getConfig(tabName); - - if (tab.useToogle()) { - AbstractButton buton; - buton = (AbstractButton) SimExplorer.getUI().getObjectById("toggleTab_" + tabName); - buton.setSelected(b); - } - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SynchronizeTabRefreshHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SynchronizeTabRefreshHelper.java 2008-02-20 18:43:44 UTC (rev 1142) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SynchronizeTabRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -1,109 +0,0 @@ -/* -* ##% 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 -* 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 fr.cemagref.simexplorer.is.ui.swing; - -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel; - -import javax.swing.JTabbedPane; -import javax.swing.JTree; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; - -/** - * Cette classe contient les méthodes utiles et réutilisables pour rafraichir - * les onglets de liste. - * <p/> - * Les méthodes utilisent les données stockées dans les modèles pour rafraichir - * les uis concernées. - * <p/> - * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> - * <p/> - * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) - * mais uniquement à partir de nos modèles. - * - * @author chemit - */ -public class SynchronizeTabRefreshHelper { - - protected static void refreshSynchronizeTab(JSynchronizeTab ui, SynchronizeTabModel model) { - - EntityTreeNodeHelper.refreshTreeActions(ui.getCollapseButton(false), ui.getExpandButton(false), null); - EntityTreeNodeHelper.refreshTreeActions(ui.getCollapseButton(true), ui.getExpandButton(true), null); - - refreshExportElement(ui, model, true); - refreshExportElement(ui, model, false); - - refreshRootNode(ui, model, false); - refreshRootNode(ui, model, true); - } - - public static void updateTree(JTabbedPane container, LoggableElement oldLocalRoot, LoggableElement oldRemoteRoot) { - - SimExplorerTab tab = SimExplorerTab.synchronize; - - SynchronizeTabModel model = (SynchronizeTabModel) tab.getModel(); - if (model.getRootNode(false) == null && model.getRootNode(true) == null) { - // on doit supprimer la vue - tab.closeTab(container); - } - - JSynchronizeTab ui = (JSynchronizeTab) tab.getUI(); - - if (model.getRootNode(false) != oldLocalRoot) { - // rebuild node ? - refreshRootNode(ui, model, false); - } - - if (model.getRootNode(true) != oldRemoteRoot) { - // rebuild node ? - refreshRootNode(ui, model, true); - } - } - - protected static void refreshRootNode(JSynchronizeTab ui, SynchronizeTabModel model, boolean remote) { - - LoggableElement element; - TreeNode root = null; - - element = model.getRootNode(remote); - if (element != null) { - root = EntityTreeNodeHelper.build(element, remote); - } - - JTree tree = ui.getTree(remote); - - ((DefaultTreeModel) tree.getModel()).setRoot(root); - - if (root == null) { - tree.getSelectionModel().clearSelection(); - } else { - tree.setSelectionRow(0); - } - } - - public static void refreshExportElement(JSynchronizeTab ui, SynchronizeTabModel model, boolean remote) { - LoggableElement sNode = model.getSelectedNode(remote); - MainUIRefreshHelper.refreshExportElement(ui.getExportButton(remote), remote, sNode); - } - - protected SynchronizeTabRefreshHelper() { - // do not instanciate me please - } -} \ No newline at end of file Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/DetailTabRefreshHelper.java (from rev 1132, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/DetailTabRefreshHelper.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/DetailTabRefreshHelper.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/DetailTabRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,294 @@ +/* +* ##% 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 +* 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import fr.cemagref.simexplorer.is.entities.EntityHelper; +import fr.cemagref.simexplorer.is.entities.attachment.Attachment; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.ui.swing.ui.JDetailTab; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; +import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.DetailTableModel; +import fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode; +import fr.cemagref.simexplorer.is.ui.swing.model.HistoryModel; +import static org.codelutin.i18n.I18n._; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListModel; +import javax.swing.JList; +import javax.swing.JTable; +import javax.swing.tree.DefaultTreeModel; +import java.awt.Dimension; +import java.awt.Rectangle; +import java.text.SimpleDateFormat; +import java.util.List; + +/** + * Cette classe contient les méthodes utiles et réutilisables pour rafraichir + * l'onglet de detail. + * <p/> + * Les méthodes utilisent les données stockées dans les modèles pour rafraichir + * les uis concernées. + * <p/> + * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> + * <p/> + * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) + * mais uniquement à partir de nos modèles. + * + * @author chemit + */ +public class DetailTabRefreshHelper { + + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS"); + + public static void refreshDetailTab(JDetailTab ui, DetailTabModel model) { + EntityTreeNode root = EntityTreeNodeHelper.build(model.getRootNode(), model.isRemote()); + EntityTreeNode current = model.getHistory().getCurrent(); + //FIXME : if object has different version, it says that this is same!!! + if (current == null || !root.getUserObject().equals(current.getUserObject())) { + model.getHistory().add(root); + } + DetailTabRefreshHelper.updateDetailNavigationTree(ui, model.getHistory()); + } + + /** + * Rafraichit les actions d'un node dans l'arbre de navigation + * + * @param context + * @param ui l'onglet de détail + * @param model le model de d'onglet detail + * @param node le node sélectionné dans l'arbre de navigation + */ + public static void refreshDetailActions(SimExplorerContext context, JDetailTab ui, DetailTabModel model, EntityTreeNode node) { + // refresh synchronize action button + refreshSynchroniseAction(context, ui, model); + // refresh download LoggableElement button + refreshDownloadElementAction(ui, model, node); + // refresh delete button + refreshDeleteAction(ui, model); + // refresh export button + refreshExportAction(context,ui, model); + // refresh download Attachment button + refreshDownloadAttachmentAction(ui, model); + } + + public static void refreshTreeDetailActions(JDetailTab ui, EntityTreeNode node) { + EntityTreeNodeHelper.refreshTreeActions(ui.getCollapseAllDetail(), ui.getExpandAllDetail(), node); + } + + public static void refreshDownloadElementAction(JDetailTab ui, DetailTabModel model, EntityTreeNode node) { + MetaData detail = model.getDetail(); + boolean enabled = EntityHelper.Action.DOWNLOAD.accept(node); + MainUIRefreshHelper.UpdateButton(ui.getDownloadElement(), enabled, enabled ? detail == null ? node.getUserObject() : detail.getName() + " [" + model.getSelectedVersion() + "]" : null); + } + + protected static void refreshDeleteAction(JDetailTab ui, DetailTabModel model) { + MetaData detail = model.getDetail(); + boolean enabled = EntityHelper.Action.DELETE.accept(detail); + MainUIRefreshHelper.UpdateButton(ui.getDeleteElement(), enabled, enabled ? detail.getName() + " [" + model.getSelectedVersion() + "]" : null); + } + + public static void refreshDownloadAttachmentAction(JDetailTab ui, DetailTabModel model) { + Attachment attachment = model.getSelectedAttachment(); + boolean enabled = model.getDetail() != null && attachment != null; + MainUIRefreshHelper.UpdateButton(ui.getDownloadAttachment(), enabled, enabled ? attachment : null); + } + + public static void refreshDetailToTreeAction(JDetailTab ui, DetailTabModel model) { + MetaData detail = model.getDetail(); + EntityTreeNode rootNode = model.getHistory().getCurrent(); + LoggableElement rootElement = (LoggableElement) rootNode.getUserObject(); + MetaData data = rootElement.getMetaData(); + Version version = model.getSelectedVersion(); + if (version == null) { + // la version peut être null, ce qui veut dire que l'on vient d'un changement + // de node dans l'arbre de navigation et donc la version est celle du detai + version = detail.getVersion(); + } + boolean enabled = !(detail.getName().equals(data.getName()) && data.getVersion().equals(version)); + + MainUIRefreshHelper.UpdateButton(ui.getDetailToTree(), enabled, enabled ? detail.getName() + " [" + version + "]" : null); + } + + public static void refreshSynchroniseAction(SimExplorerContext context, JDetailTab ui, DetailTabModel model) { + MetaData detail = model.getDetail(); + boolean enabled = detail != null && context.isConnected(); + MainUIRefreshHelper.UpdateButton(ui.getShowTab_synchronize(), enabled, enabled ? detail.getName() + " [" + model.getSelectedVersion() + "]" : null); + } + + public static void refreshExportAction(SimExplorerContext context, JDetailTab ui, DetailTabModel model) { + LoggableElement sNode = model.getSelectedNode(); + MainUIRefreshHelper.refreshExportElement(context,ui.getExportElement(),model.isRemote(),sNode); + } + + public static void resetHistory(JDetailTab ui, DetailTabModel model, DefaultComboBoxModel historyModel) { + historyModel.removeAllElements(); + LoggableElement selectedNode = model.getSelectedNode(); + Version[] versions = model.getVersions(); + boolean nodetail = versions == null || selectedNode == null; + if (nodetail) { + resetDetailPanel(ui); + } else { + ui.getDetailHeaderFromLocal().setVisible(!model.isRemote()); + ui.getDetailHeaderFromRemote().setVisible(model.isRemote()); + for (Version version : versions) { + historyModel.addElement(version); + } + boolean enabled = ui.getDetailVersions().getItemCount() > 1; + ui.getDetailVersions().setEnabled(enabled); + String text; + text = !enabled ? null : _("simexplorer.action.changeVersion.tooltip"); + ui.getDetailVersions().setToolTipText(text); + } + // can not synchronize to tree + MainUIRefreshHelper.UpdateButton(ui.getDetailToTree(), false); + } + + public static void resetDetailPanel(final JDetailTab ui) { + ui.getDetailVersions().setVisible(false); + ui.getDetailHeader().setText(_("simexplorer.node.nodetail")); + ui.getDetailAttachmentsHeader().setText(_("simexplorer.node.noattachments")); + JList listAttchments = ui.getDetailAttachments(); + listAttchments.clearSelection(); + DefaultListModel listModel = (DefaultListModel) listAttchments.getModel(); + listModel.setSize(0); + listModel.trimToSize(); + ui.getDetail().setVisible(false); + ((DetailTableModel) ui.getDetailTable().getModel()).setData(null); + } + + public static void updateDetailNavigationTree(JDetailTab ui, HistoryModel<EntityTreeNode> model) { + // push it in tree model + ((DefaultTreeModel) ui.getNavigationTree().getModel()).setRoot(model.getCurrent()); + // by default select the root node + if (ui.getNavigationTree().getModel().getRoot() != null) { + ui.getNavigationTree().setSelectionRow(0); + } + boolean enabled; + enabled = model.size() > 1 && model.hasPrevious(); + MainUIRefreshHelper.UpdateButton(ui.getHistoryPrevious(), enabled, !enabled ? null : model.getPrevious()); + enabled = model.size() > 1 && model.hasNext(); + MainUIRefreshHelper.UpdateButton(ui.getHistoryNext(), enabled, !enabled ? null : model.getNext()); + } + + public static void updateDetailPanel(Integer index, final JDetailTab ui, DetailTabModel model, LoggableElement selectedNode) { + MetaData detail = model.getDetail(); + ui.getDetailVersions().setVisible(true); + if (ui.getDetailVersions().getItemCount() > 0) { + ui.getDetailVersions().setSelectedIndex(index); + } + ui.getDetailHeader().setText(selectedNode.getMetaData().getName()); + ui.getDetailDescriptorsHeader().setText(_("simexplorer.node.descriptors", detail.getDescriptors().size())); + ui.getDetailType().setText(EntityHelper.Type.getLibelle(detail)); + String s = detail.getDescription(); + String tooltip = s; + if (s.length() > 32) { + s = s.substring(0, 32) + "..."; + } + ui.getDetailDescription().setText(s); + if (!s.equals(tooltip)) { + ui.getDetailDescription().setToolTipText(tooltip); + } + ui.getDetailCreationDate().setText(DATE_FORMAT.format(detail.getCreationDate())); + ui.getDetail().setVisible(true); + JTable table = ui.getDetailTable(); + ((DetailTableModel) table.getModel()).setData(detail); + int nbDescriptorRows = table.getRowCount(); + + List<Attachment> attachments = detail.getAttachments(); + JList listAttachments = ui.getDetailAttachments(); + DefaultListModel listModel = (DefaultListModel) listAttachments.getModel(); + listModel.setSize(0); + listModel.trimToSize(); + int nbAttachmentRows; + if (attachments.isEmpty()) { + ui.getDetailAttachmentsHeader().setText(_("simexplorer.node.noattachments")); + ui.getScrollAttachments().setVisible(false); + nbAttachmentRows = 0; + } else { + ui.getDetailAttachmentsHeader().setText(EntityHelper.Type.Attachment.getLibelles() + " (" + attachments.size() + ")"); + for (Attachment attachment : attachments) { + listModel.addElement(attachment); + } + listAttachments.setSelectedIndex(0); + nbAttachmentRows = listModel.getSize(); + ui.getScrollAttachments().setVisible(true); + } + + int[] rows = computeRows(nbDescriptorRows, nbAttachmentRows); + + Dimension dimOneRow = table.getUI().getPreferredSize(table.getTableHeader()); + + ui.getScrollTable().setPreferredSize(new Dimension((int) dimOneRow.getWidth(), 2 + ((rows[0] + 1) * (4 + table.getFont().getSize())))); + //ui.getScrollTable().setPreferredSize(new Dimension((int) table.getSize().getWidth(), 2 + (nbDescriptorRows * (4 + table.getFont().getSize())))); + if (nbAttachmentRows > 0) { + Rectangle rect = listAttachments.getUI().getCellBounds(listAttachments, 0, 0); + ui.getScrollAttachments().setPreferredSize(new Dimension((int) rect.getWidth() - 4, (int) (3 + rows[1] * rect.getHeight()))); + } + + table.invalidate(); + listAttachments.invalidate(); + ui.getScrollPane().invalidate(); + ui.repaint(); + } + + protected static int[] computeRows(int nbDescriptorRows, int nbAttachmentRows) { + int[] result = new int[2]; + int max = 14; + int maxOne = max / 2; + if (nbDescriptorRows == 0) { + result[0] = 0; + result[1] = nbAttachmentRows > max ? max : nbAttachmentRows; + return result; + } + if (nbAttachmentRows == 0) { + result[0] = nbDescriptorRows > max ? max : nbDescriptorRows; + result[1] = 0; + return result; + } + if (nbAttachmentRows < maxOne + 1 && nbDescriptorRows < maxOne + 1) { + result[0] = nbDescriptorRows; + result[1] = nbAttachmentRows; + return result; + } + if (nbDescriptorRows > maxOne && nbAttachmentRows > maxOne) { + result[0] = result[1] = maxOne; + return result; + } + if (nbDescriptorRows < maxOne + 1) { + result[0] = nbDescriptorRows; + int i = max - nbDescriptorRows; + result[1] = nbAttachmentRows < i ? nbAttachmentRows : i; + return result; + } + if (nbAttachmentRows < maxOne + 1) { + int i = max - nbAttachmentRows; + result[0] = nbDescriptorRows < i ? nbDescriptorRows : i; + result[1] = nbAttachmentRows; + return result; + } + throw new IllegalStateException("can not come her :)"); + } + + protected DetailTabRefreshHelper() { + // do not instanciate me please + } +} \ No newline at end of file Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java (from rev 1132, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/EntityTreeNodeHelper.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/EntityTreeNodeHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,321 @@ +/* +* ##% Copyright (C) 2007, 2008 Code Lutin, +* Tony Chemit, Gabriel Landais +* +* 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Code; +import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Component; +import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Constant; +import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.ConstantValue; +import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.ExplorationData; +import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Library; +import static fr.cemagref.simexplorer.is.entities.EntityHelper.Type.Structure; +import fr.cemagref.simexplorer.is.entities.EntityVisitable; +import fr.cemagref.simexplorer.is.entities.SimpleEntityVisitor; +import fr.cemagref.simexplorer.is.entities.data.Code; +import fr.cemagref.simexplorer.is.entities.data.Component; +import fr.cemagref.simexplorer.is.entities.data.Constant; +import fr.cemagref.simexplorer.is.entities.data.ConstantValue; +import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; +import fr.cemagref.simexplorer.is.entities.data.ExplorationData; +import fr.cemagref.simexplorer.is.entities.data.Library; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.data.Result; +import fr.cemagref.simexplorer.is.entities.data.Structure; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode; + +import javax.swing.AbstractButton; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.tree.TreePath; +import java.util.Collection; + +/** + * La classe responsable de la création des arbres de {@link fr.cemagref.simexplorer.is.ui.swing.model.EntityTreeNode} + * à partir de {@link LoggableElement} . + * <p/> + * La classe possède une instance cachée par thread qui délègue la construction + * del'arbre de navigation à un visiteur de {@link LoggableElement}. + * <p/> + * + * @author chemit + */ +public class EntityTreeNodeHelper { + + /** L'instance cachée de builder par Thread. */ + protected static final ThreadLocal<EntityVisitorBuilder> builder = + new ThreadLocal<EntityVisitorBuilder>() { + @Override + protected EntityVisitorBuilder initialValue() { + return new EntityVisitorBuilder(); + } + }; + + /** + * Construit un arbre de navigation à partir d'un {@link LoggableElement}. + * + * @param v la donnée à visiter + * @param remote flag pour indiquer si on travaille sur des données locales + * ou en remote. + * @return le noeud parent de l'arbre de nivation construit. + */ + public static EntityTreeNode build(LoggableElement v, boolean remote) { + EntityVisitorBuilder instance; + synchronized (instance = EntityTreeNodeHelper.builder.get()) { + EntityTreeNode result; + // walk + result = instance.visit(v, remote); + return result; + } + } + + public static EntityTreeNode getSelectedNode(TreeSelectionEvent e) { + TreePath path = e.getNewLeadSelectionPath(); + EntityTreeNode node = null; + if (path != null) { + Object o = path.getLastPathComponent(); + if (o instanceof EntityTreeNode) { + node = (EntityTreeNode) o; + } + } + return node; + } + + public static EntityTreeNode getSelectedNodeOrRootNode(JTree tree) { + EntityTreeNode node = getSelectedNode(tree); + if (node == null) { + return getRootNode(tree); + } + return node; + } + + public static EntityTreeNode getSelectedNode(JTree tree) { + TreePath path = tree.getSelectionPath(); + EntityTreeNode node = null; + if (path != null) { + Object o = path.getLastPathComponent(); + if (o != null && !(o instanceof EntityTreeNode)) { + return null; + } + node = (EntityTreeNode) o; + } + return node; + } + + public static EntityTreeNode getRootNode(JTree tree) { + EntityTreeNode node; + // take the root node + Object root = tree.getModel().getRoot(); + if (root == null || !(root instanceof EntityTreeNode)) { + return null; + } + node = (EntityTreeNode) root; + return node; + } + + public static void refreshTreeActions(AbstractButton collapseButton, AbstractButton expandButton, EntityTreeNode node) { + boolean enabled = node != null && !node.isLeaf() && node.getChildCount() > 0; + Object o = enabled ? node.getUserObject() : null; + MainUIRefreshHelper.UpdateButton(collapseButton, enabled, o); + MainUIRefreshHelper.UpdateButton(expandButton, enabled, o); + } + + protected EntityTreeNodeHelper() { + // no instance + } + + /** + * Implantation de {@link SimpleEntityVisitor} pour construire l'arbre + * de navigation d'un {@link LoggableElement}. + * <p/> + * Cette classe est stateless, tous ces états internes doivent être nettoyé + * après une visite, en utilisant la méthode {@link #reset()}. + * <p/> + */ + public static class EntityVisitorBuilder extends SimpleEntityVisitor { + + /** + * le noeud parent de tous les autres. + * <p/> + * Ce noeud est positionné par la méthode + * {@link #markRootNode(EntityTreeNode)}. + */ + protected EntityTreeNode rootNode; + + /** + * flag qui indique si on travaille sur des objet locaux ou distants. + * <p/> + * Cette information est conservé dans les nodes pour permettre de gérer + * de manière transparent des objet locaux ou distants. + */ + protected Boolean remote; + + /** les nodes internes utilisés pendant la visite. */ + protected EntityTreeNode explorationApplication, + component, + explorationData, + components, + explorationDatas, + libraries, + constants, + strutures, + codes, + constantValues; + + public EntityTreeNode visit(EntityVisitable v, boolean remote) { + reset(); + try { + this.remote = remote; + super.visit(v); + EntityTreeNode result; + result = this.rootNode; + return result; + } finally { + reset(); + } + } + + @Override + public void visitMetaData(MetaData v) { + // do not visit meta data (for the moment we dont need thoses + // informations in navigation tree), but it could be interresting + // for example to display attchments here ? + } + + @Override + public void visitExplorationApplication(ExplorationApplication v) { + markRootNode(explorationApplication = new EntityTreeNode(null, v, remote, true)); + super.visitExplorationApplication(v); + } + + @Override + public void visitComponent(Component v) { + markRootNode(component = new EntityTreeNode(components, v, remote, true)); + super.visitComponent(v); + } + + @Override + public void visitExplorationData(ExplorationData v) { + markRootNode(explorationData = new EntityTreeNode(explorationDatas, v, remote, true)); + super.visitExplorationData(v); + } + + @Override + public void visitCodes(Collection<Code> vs) { + codes = new EntityTreeNode(component, Code.getLibelles(), remote, true); + super.visitCodes(vs); + } + + @Override + public void visitComponents(Collection<Component> vs) { + components = new EntityTreeNode(explorationApplication, Component.getLibelles(), remote, true); + super.visitComponents(vs); + } + + @Override + public void visitConstants(Collection<Constant> vs) { + constants = new EntityTreeNode(component, Constant.getLibelles(), remote, true); + super.visitConstants(vs); + } + + @Override + public void visitConstantValues(Collection<ConstantValue> vs) { + constantValues = new EntityTreeNode(explorationData, ConstantValue.getLibelles(), remote, true); + super.visitConstantValues(vs); + } + + @Override + public void visitExplorationDatas(Collection<ExplorationData> vs) { + explorationDatas = new EntityTreeNode(explorationApplication, ExplorationData.getLibelles(), remote, true); + super.visitExplorationDatas(vs); + } + + @Override + public void visitLibraries(Collection<Library> vs) { + libraries = new EntityTreeNode(component, Library.getLibelles(), remote, true); + super.visitLibraries(vs); + } + + @Override + public void visitStructures(Collection<Structure> vs) { + strutures = new EntityTreeNode(component, Structure.getLibelles(), remote, true); + super.visitStructures(vs); + } + + @Override + public void visitConstant(Constant v) { + markRootNode(new EntityTreeNode(constants, v, remote, false)); + } + + @Override + public void visitLibrary(Library v) { + markRootNode(new EntityTreeNode(libraries, v, remote, false)); + } + + @Override + public void visitResult(Result v) { + if (v != null) { + markRootNode(new EntityTreeNode(explorationData, v, remote, false)); + } + } + + @Override + public void visitCode(Code v) { + new EntityTreeNode(codes, v, remote, false); + } + + @Override + public void visitConstantValue(ConstantValue v) { + new EntityTreeNode( + new EntityTreeNode(constantValues, v.getConstant().getName(), remote, true), + v.getValue(), remote, false); + } + + @Override + public void visitStructure(Structure v) { + new EntityTreeNode(strutures, v, remote, false); + } + + /** + * Tente de marquerle node donné comme noeud ancêtre de tous les autres. + * <p/> + * Le positionnement n'a lieu que si on a pas encore de rootNode. + * + * @param node le node a positionner comme rootNode (si nessecaire) + */ + protected void markRootNode(EntityTreeNode node) { + if (rootNode == null) { + rootNode = node; + } + } + + /** + * La méthode pour réinitialiser les états interne de la classe. + * <p/> + * Cette méthode doit être appeler après chaque visite, afin d'assurer + * la propriété stateless de la classe. + */ + protected void reset() { + remote = null; + rootNode = explorationApplication = explorationDatas = explorationData + = components = component = constants = codes = libraries + = constantValues = null; + } + } +} Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabRefreshHelper.java (from rev 1132, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ListTabRefreshHelper.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabRefreshHelper.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/ListTabRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,172 @@ +/* +* ##% 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 +* 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import fr.cemagref.simexplorer.is.entities.EntityHelper; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.ui.swing.ui.JListTab; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; +import fr.cemagref.simexplorer.is.ui.swing.model.DataEntityModel; +import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.PaginationModel; + +import javax.swing.JComboBox; +import javax.swing.ListSelectionModel; +import javax.swing.SwingUtilities; + +/** + * Cette classe contient les méthodes utiles et réutilisables pour rafraichir + * les onglets de liste. + * <p/> + * Les méthodes utilisent les données stockées dans les modèles pour rafraichir + * les uis concernées. + * <p/> + * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> + * <p/> + * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) + * mais uniquement à partir de nos modèles. + * + * @author chemit + */ +public class ListTabRefreshHelper { + + /** + * Rafraichit un onglet de type liste à partir de son modèle. + * + * @param mainUi main ui + * @param ui l'onglet de liste à utiliser + * @param model le modèle de liste à utiliser + */ + public static void refreshListTabUI(final SimExplorerMainUI mainUi, final JListTab ui, final ListTabModel model) { + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + + // refresh search text + ui.getSearchText().setText(model.getQuery().getQuery()); + + // refresh search actions + refreshSearchActions(ui, model); + + // refresh pagination actions + refreshPagination(ui, model.getPagination()); + + + ListSelectionModel selectionModel = ui.getTable().getSelectionModel(); + if (!model.isEmpty() && selectionModel.isSelectionEmpty()) { + // always select the first row (to init selectedItem) + selectionModel.setSelectionInterval(0, 0); + } else { + selectionModel.clearSelection(); + } + + // table data model may have changed, must revalidate + ui.getTable().invalidate(); + + // repaint the frame + mainUi.repaint(); + } + }); + } + + public static void refreshListTablePopupMenu(SimExplorerContext context, final JListTab ui, final ListTabModel model) { + DataEntityModel item = model.getSelectedItem(); + ui.getTablePopupMenu().setEnabled(item != null); + int index = model.getSelectedIndex(); + if (item == null || index == -1) { + return; + } + MetaData data = model.get(index); + + String text = data.getName() + " [" + data.getVersion() + "]"; + + MainUIRefreshHelper.UpdateButton(ui.getDownloadElement(), EntityHelper.Action.DOWNLOAD.accept(data), text); + MainUIRefreshHelper.UpdateButton(ui.getDeleteElement(), EntityHelper.Action.DELETE.accept(data), text); + MainUIRefreshHelper.refreshExportElement(context,ui.getExportElement(), model.isRemote(), data); + MainUIRefreshHelper.UpdateButton(ui.getShowTab_detail(), true, text); + MainUIRefreshHelper.UpdateButton(ui.getShowTab_synchronize(), context.isConnected(), text); + } + + /** + * Rafraichit les actions de recherche d'un onglet de type liste. + * + * @param ui l'onglet de liste à utiliser + * @param model le modèle de liste à utiliser + */ + public static void refreshSearchActions(JListTab ui, ListTabModel model) { + String text = ui.getSearchText().getText(); + boolean hasQuery = model.getQuery().hasQuery(); + ui.getSearch().setEnabled(hasQuery || !text.isEmpty()); + ui.getResetSearch().setEnabled(hasQuery || !text.isEmpty()); + } + + public static void refreshPagination(JListTab ui, PaginationModel pagination) { + + // refresh changePage combobox + refreshChangePageCombo(ui, pagination); + + // refresh changeSizor combo + refreshChangeSizorCombo(ui, pagination); + + int page = pagination.getCurrentPage(); + boolean notLast = page + 1 < pagination.getNbPages(); + ui.getGoNextPage().setEnabled(notLast); + ui.getGoLastPage().setEnabled(notLast); + boolean notFirstPage = !(pagination.getSize() < 2 || page < 1); + ui.getGoFirstPage().setEnabled(notFirstPage); + ui.getGoPreviousPage().setEnabled(notFirstPage); + } + + public static void refreshChangeSizorCombo(JListTab ui, PaginationModel pagination) { + JComboBox combo = ui.getChangeSizor(); + String s = pagination.getWidth() + ""; + if (!s.equals(String.valueOf(combo.getSelectedItem()))) { + combo.setEnabled(false); + combo.setSelectedItem(s); + combo.setEnabled(true); + } + } + + public static void refreshChangePageCombo(JListTab ui, PaginationModel pagination) { + JComboBox combo = ui.getGoPage(); + long size = pagination.getNbPages(); + combo.setEnabled(false); + //System.out.println("page old size : " + combo.getItemCount() + " new size : " + size); + if (size < combo.getItemCount()) { + while (size < combo.getItemCount()) { + combo.removeItemAt(combo.getItemCount() - 1); + } + } else { + while (size > combo.getItemCount()) { + combo.addItem(combo.getItemCount()); + } + } + //System.out.println("new page size : " + combo.getItemCount()); + if (combo.getItemCount() > 0) { + combo.setSelectedIndex(pagination.getCurrentPage()); + } + boolean b = combo.getItemCount() > 1; + combo.setEnabled(b); + ui.getCurrentPage().setEnabled(b); + } + + protected ListTabRefreshHelper() { + // do not instanciate me please + } +} \ No newline at end of file Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/MainUIRefreshHelper.java (from rev 1132, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/MainUIRefreshHelper.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/MainUIRefreshHelper.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/MainUIRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,163 @@ +/* +* ##% 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 +* 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import fr.cemagref.simexplorer.is.entities.EntityHelper; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.ui.swing.actions.ExportElementAction; +import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractAction; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; +import static org.codelutin.i18n.I18n._; + +import javax.swing.AbstractButton; + +/** + * Cette classe contient les méthodes utiles et réutilisables pour rafraichit + * les ui. + * <p/> + * Les méthodes utilisent les données stockées dans les modèles pour rafraichir + * les uis concernées. + * <p/> + * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> + * <p/> + * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) + * mais uniquement à partir de nos modèles. + * + * @author chemit + */ +public class MainUIRefreshHelper { + + + public static void refreshExportElement(SimExplorerContext context, AbstractButton button, boolean remote, LoggableElement sNode) { + boolean enabled = EntityHelper.Action.EXPORT.accept(sNode) && context.isConnected(); + refreshExportElement(context,button, remote, enabled ? sNode.getMetaData(): null); + } + + public static void refreshExportElement(SimExplorerContext context, AbstractButton button, boolean remote, MetaData data) { + boolean enabled = EntityHelper.Action.EXPORT.accept(data) && context.isConnected(); + button.setEnabled(enabled); + String t = null; + if (enabled) { + ExportElementAction action = (ExportElementAction) button.getAction(); + t = _(action.getI18nToolTipText(remote), data.getName(), data.getVersion().toString()); + } + button.setToolTipText(t); + } + + protected static void UpdateButton(AbstractButton button, boolean enabled, Object... params) { + button.setEnabled(enabled); + if (!enabled) { + button.setToolTipText(null); + } else { + + } + SimExplorerAbstractAction action = (SimExplorerAbstractAction) button.getAction(); + String t = _(action.getI18nToolTipText(), params); + button.setToolTipText(t); + } + + + protected MainUIRefreshHelper() { + // do not instanciate me please + } + +} + +/** + * Rafraichit les uis après un changement de status de connexion de l'utilisateur. + * <p/> + * Si l'utilisateur est déconnecté, alors toutes les ui et actions liées au + * mode remote sont fermées et les actions correspondantes sont rendues + * inaccessibles. + * + * @param ui l'ui principale + * @param isConnected flag pour indique si l'utiliseur est connecté + * @param history l'historique de l'onglet de detail + */ +/* public static void refreshConnnectState(SimExplorerMainUI ui, final boolean isConnected, HistoryModel<EntityTreeNode> history) { + + //SwingUtilities.invokeLater(new Runnable() { + // public void run() { + ui.getConnect().setEnabled(!isConnected); + ui.getUnconnect().setEnabled(isConnected); + ui.getShowTab_remote().setEnabled(isConnected); + ui.getToggleTab_remote().setEnabled(isConnected); + + JTabbedPane container = ui.getContent(); + DetailTabModel model = (DetailTabModel) SimExplorerTab.detail.getModel(); + JDetailTab tabUI = (JDetailTab) SimExplorerTab.detail.getUI(); + if (!isConnected) { + // close all connected ui + + if (SimExplorerTab.remote.isTabVisible(container)) { + // close tab + SimExplorerTab.remote.closeTab(container); + } + if (SimExplorerTab.synchronize.isTabVisible(container)) { + // close tab + SimExplorerTab.synchronize.closeTab(container); + } + if (SimExplorerTab.detail.isTabVisible(container) && history != null) { + if (history.isEmpty()) { + // close tab, no more history + SimExplorerTab.detail.closeTab(container); + } else { + // select current history element + EntityTreeNode node = history.getCurrent(); + model.synch(node); + //model.setRemote(node.isRemote()); + //model.setRootNode((LoggableElement) node.getUserObject()); + DetailTabRefreshHelper.updateDetailNavigationTree(tabUI, model.getHistory()); + } + } + } + if (SimExplorerTab.detail.isTabVisible(container)) { + DetailTabRefreshHelper.refreshSynchroniseAction(tabUI, model); + DetailTabRefreshHelper.refreshExportAction(tabUI, model); + } + + if (SimExplorerTab.local.isTabVisible(container)) { + ListTabRefreshHelper.refreshListTablePopupMenu((JListTab) SimExplorerTab.local.getUI(), (ListTabModel) SimExplorerTab.local.getModel()); + } + // } + //}); +}*/ + +/** + * Rafraichit les actions i18n dans le menu en fonction de la locale + * actuellement utilisée. + * + * @param ui l'ui principale + */ +/*public static void refreshI18nActions(SimExplorerMainUI ui) { + LanguageEnum language = SimExplorer.getContext().getConfig().getUserLanguage(); + CountryEnum country = SimExplorer.getContext().getConfig().getUserCountry(); + String[] actions = SimExplorerActionManager.getFactory().getActionNames(); + for (String actionName : actions) { + Matcher matcher = ChangeI18nAbstractAction.PATTERN_NAME.matcher(actionName); + if (!matcher.matches()) { + continue; + } + AbstractButton button = (AbstractButton) ui.getObjectById(actionName); + ChangeI18nAbstractAction action = (ChangeI18nAbstractAction) button.getAction(); + boolean enable = !action.equalsLocale(language, country); + button.setEnabled(enable); + } +}*/ \ No newline at end of file Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java (from rev 1132, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerMainUI.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerMainUI.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,115 @@ +/* +* ##% 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 +* 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import fr.cemagref.simexplorer.is.ui.swing.SimExplorer; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; +import fr.cemagref.simexplorer.is.ui.swing.ui.SimExplorerUI; +import fr.cemagref.simexplorer.is.ui.swing.actions.util.ChangeI18nAbstractAction; +import org.codelutin.i18n.CountryEnum; +import org.codelutin.i18n.LanguageEnum; + +import javax.swing.AbstractButton; +import javax.swing.JComponent; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.util.regex.Matcher; + +/** + * L'ui principale de l'application + * + * @author chemit + */ +public class SimExplorerMainUI extends SimExplorerUI { + /* begin raw body code */ + /** l'ui principale de l'application */ + public static SimExplorerMainUI ui; + + public static SimExplorerMainUI getUI() { + SimExplorer.checkInitContext(); + if (ui == null) { + ui = new SimExplorerMainUI(); + } + return ui; + } + + public void disposeUI() { + super.dispose(); + ui = null; + } + + protected SimExplorerMainUI() { + super(); + finalizeInit(SimExplorer.getContext()); + } + + public void finalizeInit(SimExplorerContext context) { + + // chargement dans l'ui des actions + SimExplorerActionManager.loadActions(this, null); + + // add Ctrl-W to close current tab + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK), "closeTab"); + getRootPane().getActionMap().put("closeTab", SimExplorerActionManager.newAction("closeTab")); + // override Ctrl-F4 close application + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.CTRL_MASK), "quit"); + getRootPane().getActionMap().put("quit", SimExplorerActionManager.newAction("quit")); + + // repaint i18n actions + refreshI18nActions(context); + } + + public void setStatus(final String msg) { + + Runnable runnable = new Runnable() { + public void run() { + //TODO il faut enlever le synchronize dans statusBar + //getStatusBar().setStatus(msg); + //System.out.println(msg); + } + }; + SwingUtilities.invokeLater(runnable); + } + + /** + * Rafraichit les actions i18n dans le menu en fonction de la locale + * actuellement utilisée. + * + * @param context application context + */ + public void refreshI18nActions(SimExplorerContext context) { + + LanguageEnum language = context.getConfig().getUserLanguage(); + CountryEnum country = context.getConfig().getUserCountry(); + String[] actions = SimExplorerActionManager.getFactory().getActionNames(); + for (String actionName : actions) { + Matcher matcher = ChangeI18nAbstractAction.PATTERN_NAME.matcher(actionName); + if (!matcher.matches()) { + continue; + } + AbstractButton button = (AbstractButton) getObjectById(actionName); + ChangeI18nAbstractAction action = (ChangeI18nAbstractAction) button.getAction(); + boolean enable = !action.equalsLocale(language, country); + button.setEnabled(enable); + } + } +} Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java (from rev 1132, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTab.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTab.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,189 @@ +/* +* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import fr.cemagref.simexplorer.is.ui.swing.ui.JDetailTab; +import fr.cemagref.simexplorer.is.ui.swing.ui.JListTab; +import fr.cemagref.simexplorer.is.ui.swing.ui.JSynchronizeTab; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; +import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel; +import jaxx.runtime.builder.TabContentConfig; +import jaxx.runtime.swing.JAXXTab; + +import javax.swing.JPopupMenu; +import javax.swing.JTabbedPane; +import java.awt.Component; + +/** + * La défintion des onglets utilisés dans l'application + * + * @author tony + */ + +public enum SimExplorerTab { + + @TabContentConfig( + impl = JDetailTab.class, + model = DetailTabModel.class, + parentImpl = JTabbedPane.class, + name = "simexplorer.tab.detail", + shortDescription = "simexplorer.tab.detail.tooltip" + )detail { + public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(SimExplorerContext context, SimExplorerMainUI mainUi, U ui, M model) { + DetailTabRefreshHelper.refreshDetailTab((JDetailTab) ui, (DetailTabModel) model); + }}, + + @TabContentConfig( + impl = JListTab.class, + parentImpl = JTabbedPane.class, + model = ListTabModel.class, + useToogle = true, + name = "simexplorer.tab.local", + shortDescription = "simexplorer.tab.local.tooltip" + )local { + public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(SimExplorerContext context, SimExplorerMainUI mainUi, U ui, M model) { + ListTabRefreshHelper.refreshListTabUI(mainUi, (JListTab) ui, (ListTabModel) model); + }}, + + @TabContentConfig( + impl = JListTab.class, + parentImpl = JTabbedPane.class, + model = ListTabModel.class, + useToogle = true, + name = "simexplorer.tab.remote", + shortDescription = "simexplorer.tab.remote.tooltip" + )remote { + public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(SimExplorerContext context, SimExplorerMainUI mainUi, U ui, M model) { + ListTabRefreshHelper.refreshListTabUI(mainUi, (JListTab) ui, (ListTabModel) model); + }}, + + @TabContentConfig( + impl = JSynchronizeTab.class, + parentImpl = JTabbedPane.class, + model = SynchronizeTabModel.class, + useToogle = false, + name = "simexplorer.tab.synchronize", + shortDescription = "simexplorer.tab.synchronize.tooltip" + )synchronize { + public <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(SimExplorerContext context, SimExplorerMainUI mainUi, U ui, M model) { + SynchronizeTabRefreshHelper.refreshSynchronizeTab(context,(JSynchronizeTab) ui, (SynchronizeTabModel) model); + } + }; + + /** l'usine de tabs */ + private static SimExplorerTabFactory factory; + + public static SimExplorerTabFactory getFactory() { + if (factory == null) { + factory = new SimExplorerTabFactory(); + } + return factory; + } + + /** + * recherche d'un onglet contenant un component. + * + * @param c le component dont on cherche l'onglet + * @return l'onglet parent du component, ou null si pas de tab trouvé + */ + public static SimExplorerTab findTab(Component c) { + Component parent = c.getParent(); + while (parent != null) { + if (parent instanceof JPopupMenu) { + parent = ((JPopupMenu) parent).getInvoker(); + } + if (parent instanceof JAXXTab) { + // find a JAXXTab + for (SimExplorerTab tab : values()) { + if (parent.equals(tab.getUI())) { + // find the correct tab + return tab; + } + } + break; + } + parent = parent.getParent(); + } + return null; + } + + public static SimExplorerTab getListTab(boolean remote) { + return remote ? SimExplorerTab.remote : SimExplorerTab.local; + } + + public static JListTab getListUI(boolean remote) { + return (JListTab) getListTab(remote).getUI(); + } + + public static ListTabModel getListModel(boolean remote) { + return (ListTabModel) getListTab(remote).getModel(); + } + + public static void dispose() { + SimExplorerTab.getFactory().resetCache(); + // remove listeners on detail tab model + for (SimExplorerTab tab : SimExplorerTab.values()) { + tab.removePropertyChangeListeners(); + } + } + + public abstract <U extends JAXXTab, M extends SimExplorerTabModel> void updateUI(SimExplorerContext context, SimExplorerMainUI mainUi, U ui, M model); + + public JAXXTab getUI() { + return getFactory().getUI(name()); + } + + public SimExplorerTabModel getModel() { + return getFactory().getModel(name()); + } + + public boolean isTabVisible(JTabbedPane container) { + JAXXTab ui = getUI(); + return ui != null && getFactory().getTabIndex(container, ui) > -1; + } + + public boolean isTabSelected(JTabbedPane container) { + return isTabVisible(container) && getFactory().getTabIndex(container, getUI()) == container.getSelectedIndex(); + } + + public int getTabIndex(JTabbedPane container) { + JAXXTab ui = getUI(); + return ui == null ? -1 : getFactory().getTabIndex(container, ui); + } + + public void showTab(final JTabbedPane container) { + getFactory().showTab(container, name()); + } + + public void closeTab(SimExplorerMainUI mainUi, JTabbedPane container) { + getFactory().closeTab(mainUi, container, name()); + getModel().setSelectedItem(null); + } + + public void updateUI(SimExplorerContext context, SimExplorerMainUI mainUI) { + updateUI(context,mainUI, getUI(), getModel()); + } + + public void removePropertyChangeListeners() { + getModel().removePropertyChangeListeners(); + } +} Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java (from rev 1132, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerTabFactory.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerTabFactory.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,130 @@ +/* +* ##% 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 +* 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerActionManager; +import fr.cemagref.simexplorer.is.ui.swing.model.SimExplorerTabModel; +import fr.cemagref.simexplorer.is.ui.swing.ui.util.MyTabHeader; +import jaxx.runtime.JAXXObject; +import jaxx.runtime.builder.TabContentConfig; +import jaxx.runtime.builder.TabFactory; +import jaxx.runtime.swing.JAXXTab; +import static org.codelutin.i18n.I18n._; + +import javax.swing.AbstractButton; +import javax.swing.JComponent; +import javax.swing.JTabbedPane; +import java.awt.Component; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.lang.reflect.Field; +import java.util.Map; +import java.util.TreeMap; + +/** + * L'implatantion pour SimExplorer de la factory de Tab + * + * @author chemit + * @see TabFactory + */ +public class SimExplorerTabFactory extends TabFactory { + + protected Map<String, TabContentConfig> initFactory() { + Map<String, TabContentConfig> result = new TreeMap<String, TabContentConfig>(); + for (SimExplorerTab tab : SimExplorerTab.values()) { + try { + String tabName = tab.name(); + Field field = tab.getClass().getField(tabName); + result.put(tabName, field.getAnnotation(TabContentConfig.class)); + } catch (NoSuchFieldException e) { + throw new SimExplorerRuntimeException(e); + } + } + return result; + } + + protected void initTab(JAXXTab tab, String tabName, TabContentConfig config) { + SimExplorerActionManager.loadActions((JAXXObject) tab, getTab(tabName)); + } + + protected SimExplorerTab getTab(String tabName) { + return SimExplorerTab.valueOf(tabName); + } + + @Override + public SimExplorerTabModel getModel(String tabName) { + return (SimExplorerTabModel) super.getModel(tabName); + } + + @Override + protected JComponent addTabHeader(final JTabbedPane container, + String tabName, + TabContentConfig tab, + final JAXXTab comp) { + + final MyTabHeader panel = new MyTabHeader(); + + // add a dynamic reference to tab close button to enable + // dynamic action instanciation + //TODO add the ActionManager mecanism ? + String actionName = panel.getCloseTab().getName() + "_" + tabName; + + panel.get$objectMap().put(actionName, panel.getCloseTab()); + + // chargement dans l'ui des actions + SimExplorerActionManager.loadActions(panel, getTab(tabName)); + + panel.setToolTipText(_(tab.shortDescription())); + panel.getLabel().setText(_(tab.name())); + + panel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + Component compOld = container.getSelectedComponent(); + if (!comp.equals(compOld)) { + //TODO should use the showTab_XXX action + container.setSelectedComponent(comp); + } + } + }); + return panel; + } + + + public void showTab(SimExplorerMainUI mainUI, JTabbedPane container, String tabName) { + super.showTab(container, tabName); + switchToggleButton(mainUI, tabName, true); + } + + public void closeTab(SimExplorerMainUI mainUi, JTabbedPane container, String tabName) { + super.closeTab(container, tabName); + switchToggleButton(mainUi, tabName, false); + } + + protected void switchToggleButton(SimExplorerMainUI mainUi, String tabName, boolean b) { + TabContentConfig tab = getConfig(tabName); + if (tab.useToogle()) { + AbstractButton buton; + buton = (AbstractButton) mainUi.getObjectById("toggleTab_" + tabName); + buton.setSelected(b); + } + } + +} Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SynchronizeTabRefreshHelper.java (from rev 1135, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SynchronizeTabRefreshHelper.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SynchronizeTabRefreshHelper.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/ui/SynchronizeTabRefreshHelper.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,111 @@ +/* +* ##% 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 +* 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 fr.cemagref.simexplorer.is.ui.swing.ui; + +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.ui.swing.ui.JSynchronizeTab; +import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; +import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel; + +import javax.swing.JTabbedPane; +import javax.swing.JTree; +import javax.swing.tree.DefaultTreeModel; +import javax.swing.tree.TreeNode; + +/** + * Cette classe contient les méthodes utiles et réutilisables pour rafraichir + * les onglets de liste. + * <p/> + * Les méthodes utilisent les données stockées dans les modèles pour rafraichir + * les uis concernées. + * <p/> + * Note : <b>Dans toutes ces méthodes, NOS modèles ne doivent en aucun cas être modifiés</b> + * <p/> + * Par contre les modèles des ui peuvent être modifiés (par exemple modèle d'arbre, de liste) + * mais uniquement à partir de nos modèles. + * + * @author chemit + */ +public class SynchronizeTabRefreshHelper { + + protected static void refreshSynchronizeTab(SimExplorerContext context, JSynchronizeTab ui, SynchronizeTabModel model) { + + EntityTreeNodeHelper.refreshTreeActions(ui.getCollapseButton(false), ui.getExpandButton(false), null); + EntityTreeNodeHelper.refreshTreeActions(ui.getCollapseButton(true), ui.getExpandButton(true), null); + + refreshExportElement(context, ui, model, true); + refreshExportElement(context, ui, model, false); + + refreshRootNode(ui, model, false); + refreshRootNode(ui, model, true); + } + + public static void updateTree(SimExplorerMainUI mainUi, JTabbedPane container, LoggableElement oldLocalRoot, LoggableElement oldRemoteRoot) { + + SimExplorerTab tab = SimExplorerTab.synchronize; + + SynchronizeTabModel model = (SynchronizeTabModel) tab.getModel(); + if (model.getRootNode(false) == null && model.getRootNode(true) == null) { + // on doit supprimer la vue + tab.closeTab(mainUi, container); + } + + JSynchronizeTab ui = (JSynchronizeTab) tab.getUI(); + + if (model.getRootNode(false) != oldLocalRoot) { + // rebuild node ? + refreshRootNode(ui, model, false); + } + + if (model.getRootNode(true) != oldRemoteRoot) { + // rebuild node ? + refreshRootNode(ui, model, true); + } + } + + protected static void refreshRootNode(JSynchronizeTab ui, SynchronizeTabModel model, boolean remote) { + + LoggableElement element; + TreeNode root = null; + + element = model.getRootNode(remote); + if (element != null) { + root = EntityTreeNodeHelper.build(element, remote); + } + + JTree tree = ui.getTree(remote); + + ((DefaultTreeModel) tree.getModel()).setRoot(root); + + if (root == null) { + tree.getSelectionModel().clearSelection(); + } else { + tree.setSelectionRow(0); + } + } + + public static void refreshExportElement(SimExplorerContext context, JSynchronizeTab ui, SynchronizeTabModel model, boolean remote) { + LoggableElement sNode = model.getSelectedNode(remote); + MainUIRefreshHelper.refreshExportElement(context, ui.getExportButton(remote), remote, sNode); + } + + protected SynchronizeTabRefreshHelper() { + // do not instanciate me please + } +} \ No newline at end of file Added: trunk/simexplorer-is/simexplorer-is-swing/src/test/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerUIRefreshHelperTest.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/test/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerUIRefreshHelperTest.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/test/fr/cemagref/simexplorer/is/ui/swing/ui/SimExplorerUIRefreshHelperTest.java 2008-02-20 18:45:16 UTC (rev 1143) @@ -0,0 +1,78 @@ +package fr.cemagref.simexplorer.is.ui.swing.ui; + +import junit.framework.TestCase; +import fr.cemagref.simexplorer.is.ui.swing.ui.DetailTabRefreshHelper; + +/** + * SimExplorerUIRefreshHelper Tester. + * + * @author chemit + * @version 1.0 + * @since <pre>02/08/2008</pre> + */ +public class SimExplorerUIRefreshHelperTest extends TestCase { + int max = 14; + public SimExplorerUIRefreshHelperTest(String name) { + super(name); + } + + public void testComputeRowLimitCases() throws Exception { + for (int i = 0; i < max+1; i++) { + assertComputeRow(0, i, DetailTabRefreshHelper.computeRows(0, i)); + } + for (int i = 0; i < max+1; i++) { + assertComputeRow(i, 0, DetailTabRefreshHelper.computeRows(i, 0)); + } + assertComputeRow(0, max, DetailTabRefreshHelper.computeRows(0, max+1)); + assertComputeRow(max, 0, DetailTabRefreshHelper.computeRows(max+1, 0)); + } + + + public void testComputeRowDescriptor() throws Exception { + for (int i = 1; i < max-1; i++) { + testComputeRowDescriptor(i); + } + } + + public void testComputeRowAttachment() throws Exception { + for (int i = 1; i < max-1; i++) { + testComputeRowAttachment(i); + } + } + + public void testComputeRowAttachment(int nb) throws Exception { + int pivot = max - nb; + for (int i = 0; i < pivot + 1; i++) { + assertComputeRow(i, nb, DetailTabRefreshHelper.computeRows(i, nb)); + } + for (int i = pivot + 1; i < max+1; i++) { + if (nb + i > max) { + int[] res = DetailTabRefreshHelper.computeRows(i, nb); + assertEquals(max, res[0] + res[1]); + } else { + assertComputeRow(pivot, nb, DetailTabRefreshHelper.computeRows(i, nb)); + } + } + } + + public void testComputeRowDescriptor(int nb) throws Exception { + int pivot = max - nb; + for (int i = 0; i < pivot + 1; i++) { + assertComputeRow(nb, i, DetailTabRefreshHelper.computeRows(nb, i)); + } + for (int i = pivot + 1; i < max+1; i++) { + if (nb + i > max) { + int[] res = DetailTabRefreshHelper.computeRows(nb, i); + assertEquals(max, res[0] + res[1]); + } else { + assertComputeRow(nb, pivot, DetailTabRefreshHelper.computeRows(nb, i)); + } + } + } + + public void assertComputeRow(int expectedOne, int expectedTwo, int[] result) { + assertEquals(expectedOne, result[0]); + assertEquals(expectedTwo, result[1]); + } + +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org