Author: tchemit Date: 2008-02-25 21:43:13 +0000 (Mon, 25 Feb 2008) New Revision: 1239 Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerTabModel.java Log: refactor model de tab Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerTabModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerTabModel.java 2008-02-25 21:43:05 UTC (rev 1238) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/SimExplorerTabModel.java 2008-02-25 21:43:13 UTC (rev 1239) @@ -1,161 +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.model; - -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.SimExplorerTab; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; -import jaxx.runtime.builder.TabModel; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; - -/** - * Le model d'onglet de l'application - * - * @author chemit - * @see TabModel - * @see SimExplorerTab - */ -public abstract class SimExplorerTabModel implements TabModel { - - /** l'onglet associé au model */ - protected SimExplorerTab tab; - - /** le dernier élément sélectionné dans l'onglet */ - protected DataEntityModel selectedItem; - - /** flag pour savoir si la source est remote ou non */ - protected Boolean remote; - - protected final SimExplorerContext context; - - /** support pourles changements des propriétés */ - protected PropertyChangeSupport changeSupport; - - private static final long serialVersionUID = 4136959472154027361L; - - public SimExplorerTabModel(SimExplorerContext context) { - this.context = context; - } - - public String getName() { - return tab.name(); - } - - public boolean isRemote() { - return remote != null && remote; - } - - public void synch(EntityTreeNode node) { - this.remote = node == null ? null : node.isRemote(); - getSelectedItem().synch(node); - } - - public void synch(Boolean remote, LoggableElement selectedElement) { - this.remote = remote; - getSelectedItem().synch(remote, selectedElement); - } - - public void synch(Boolean remote, MetaData selectedMeta) { - this.remote = remote; - getSelectedItem().synch(remote, selectedMeta); - } - - public void synch(Boolean remote, String uuid, Version version) { - this.remote = remote; - getSelectedItem().synch(remote, uuid, version); - } - - public DataEntityModel getSelectedItem() { - if (selectedItem == null) { - selectedItem = new DataEntityModel(); - //selectedItem.setRemote(remote); - } - return selectedItem; - } - - public void setName(String name) { - this.tab = SimExplorerTab.valueOf(name); - } - - public void setSelectedItem(DataEntityModel selectedItem) { - this.selectedItem = selectedItem; - if (selectedItem != null) { - remote = selectedItem.isRemote(); - } - } - - public void reset() { - remote = null; - selectedItem = null; - } - - public synchronized void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { - if (listener == null) { - return; - } - if (changeSupport == null) { - changeSupport = new PropertyChangeSupport(this); - } - changeSupport.addPropertyChangeListener(propertyName, listener); - } - - public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { - if (listener == null) { - return; - } - if (changeSupport == null) { - changeSupport = new PropertyChangeSupport(this); - } - changeSupport.addPropertyChangeListener(listener); - } - - public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { - if (listener == null || changeSupport == null) { - return; - } - changeSupport.removePropertyChangeListener(listener); - } - - public synchronized void removePropertyChangeListeners() { - if (changeSupport == null) { - return; - } - for (PropertyChangeListener listener : getPropertyChangeListeners()) { - changeSupport.removePropertyChangeListener(listener); - } - } - - public synchronized PropertyChangeListener[] getPropertyChangeListeners() { - if (changeSupport == null) { - return new PropertyChangeListener[0]; - } - return changeSupport.getPropertyChangeListeners(); - } - - public void firePropertyChange(String propertyName, Object oldValue, Object newValue) { - if (changeSupport == null || (oldValue == null && newValue == null) || - (oldValue != null && oldValue.equals(newValue))) { - return; - } - changeSupport.firePropertyChange(propertyName, oldValue, newValue); - } -}