diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface')
7 files changed, 0 insertions, 845 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java deleted file mode 100644 index a4874cf6bd..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractItemLabelProvider.java +++ /dev/null @@ -1,164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProvider; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.swt.graphics.Image; - -/** - * Implementation of {@link ItemLabelProvider} that provides updating - * label information for a Model object. - * - * The typical subclass will override the following methods: - * #buildTextModel() - * return a {@link PropertyValueModel} that represents the text for the represented - * model object. - * #buildImageModel() - * return a {@link PropertyValueModel} that represents the image for the represented - * model object - * - * Other methods may be overridden, but take care to preserve the logic provided - * by this class. - */ -public abstract class AbstractItemLabelProvider implements ItemLabelProvider -{ - private DelegatingContentAndLabelProvider labelProvider; - - private Model model; - - private PropertyValueModel<String> textModel; - - private PropertyValueModel<Image> imageModel; - - private PropertyChangeListener labelChangeListener; - - - protected AbstractItemLabelProvider( - Model model, DelegatingContentAndLabelProvider labelProvider) { - this.model = model; - this.labelProvider = labelProvider; - this.labelChangeListener = buildLabelChangeListener(); - } - - - /** - * Construct a listener to update the viewer (through the label provider) - * if the text or image changes - */ - protected PropertyChangeListener buildLabelChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - labelProvider().updateLabel(model()); - } - }; - } - - /** - * Return the text value model - * (lazy and just-in-time initialized) - */ - protected PropertyValueModel<String> textModel() { - if (textModel == null) { - textModel = buildTextModel(); - engageTextModel(); - } - return textModel; - } - - /** - * Construct a text value model - */ - protected abstract PropertyValueModel<String> buildTextModel(); - - /** - * Should only be overridden with a call to super.engageTextModel() before - * subclass logic - */ - protected void engageTextModel() { - textModel.addPropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); - } - - /** - * Should only be overridden with a call to super.disengageTextModel() after - * subclass logic - */ - protected void disengageTextModel() { - if (textModel != null) { - textModel.removePropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); - } - } - - /** - * Return the image value model - * (lazy and just-in-time initialized) - */ - protected PropertyValueModel<Image> imageModel() { - if (imageModel == null) { - imageModel = buildImageModel(); - engageImageModel(); - } - return imageModel; - } - - /** - * Construct an image model - */ - protected abstract PropertyValueModel<Image> buildImageModel(); - - /** - * Should only be overridden with a call to super.engageImageModel() before - * subclass logic - */ - protected void engageImageModel() { - imageModel.addPropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); - } - - /** - * Should only be overridden with a call to super.disengageImageModel() after - * subclass logic - */ - protected void disengageImageModel() { - if (imageModel != null) { - imageModel.removePropertyChangeListener(PropertyValueModel.VALUE, labelChangeListener); - } - } - - /** - * Return the model object represented by this item - */ - public Model model() { - return model; - } - - /** - * Return the label provider that delegates to this item - */ - public DelegatingContentAndLabelProvider labelProvider() { - return labelProvider; - } - - public String getText() { - return textModel().getValue(); - } - - public Image getImage() { - return imageModel().getValue(); - } - - public void dispose() { - disengageTextModel(); - disengageImageModel(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractTreeItemContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractTreeItemContentProvider.java deleted file mode 100644 index 50bba359a8..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/AbstractTreeItemContentProvider.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import java.util.Iterator; - -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.ListCollectionValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.NullCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; - -/** - * Implementation of {@link TreeItemContentProvider} that provides updating - * children information for a Model object. - * - * The typical subclass will override the following methods: - * #getParent() - * the default behavior for this method is to return null. there is no - * property value model for this as this should not be changing for a given - * node. all such changes will be provided by the parent side of the relationship. - * #buildChildrenModel() - * return a {@link ListValueModel} that represents the children for the represented - * model object. #buildChildrenModel(CollectionValueModel) and - * #buildChildrenModel(PropertyValueModel) are provided if the children are more - * easily represented as a collection or as a property (single child) - * the default behavior is to return a {@link NullListValueModel} - * - * Other methods may be overridden, but take care to preserve the logic provided - * by this class. - */ -public abstract class AbstractTreeItemContentProvider<E> - implements TreeItemContentProvider -{ - private DelegatingTreeContentAndLabelProvider treeContentProvider; - - private Model model; - - private CollectionValueModel<E> childrenModel; - - private CollectionChangeListener childrenListener; - - - protected AbstractTreeItemContentProvider( - Model model, DelegatingTreeContentAndLabelProvider treeContentProvider) { - this.model = model; - this.treeContentProvider = treeContentProvider; - this.childrenListener = buildChildrenListener(); - } - - /** - * Construct a listener to refresh the tree (through the tree content provider) - * if the children change - */ - protected CollectionChangeListener buildChildrenListener() { - return new CollectionChangeListener() { - - public void itemsAdded(CollectionChangeEvent event) { - getTreeContentProvider().updateContent(getModel()); - } - - public void itemsRemoved(CollectionChangeEvent event) { - getTreeContentProvider().updateContent(getModel()); - for (Iterator<?> stream = event.items(); stream.hasNext(); ) { - getTreeContentProvider().dispose(stream.next()); - } - } - - public void collectionChanged(CollectionChangeEvent event) { - getTreeContentProvider().updateContent(getModel()); - // in the case of a list changed event, we don't have - // access to the removed objects, so we can't dispose them. - // keep a watch on this to see if this becomes a problem. - } - - public void collectionCleared(CollectionChangeEvent event) { - getTreeContentProvider().updateContent(getModel()); - // in the case of a list cleared event, we don't have - // access to the removed objects, so we can't dispose them. - // keep a watch on this to see if this becomes a problem. - } - }; - } - - /** - * Return the children model - * (lazy and just-in-time initialized) - */ - protected Iterator<E> childrenModel() { - if (this.childrenModel == null) { - this.childrenModel = buildChildrenModel(); - engageChildren(); - } - return this.childrenModel.iterator(); - } - - /** - * Construct a children model - */ - protected CollectionValueModel<E> buildChildrenModel() { - return new NullCollectionValueModel<E>(); - } - - /** - * Utility method that can be used if the children model is better represented - * as a collection. - * This wraps the children collection model and uses it internally as a list - * model. - */ - protected CollectionValueModel<E> buildChildrenModel(ListValueModel<E> childrenModel) { - return new ListCollectionValueModelAdapter<E>(childrenModel); - } - - /** - * Utility method that can be used if the children model is better represented - * as a single value property. - * This wraps the children (child) property model and uses it internally as a list - * model. - */ - protected ListValueModel<E> buildChildrenModel(PropertyValueModel<E> childrenModel) { - return new PropertyListValueModelAdapter<E>(childrenModel); - } - - /** - * Return the model object represented by this node - */ - public Model getModel() { - return this.model; - } - - /** - * Return the tree content provider that delegates to this node - */ - public DelegatingTreeContentAndLabelProvider getTreeContentProvider() { - return this.treeContentProvider; - } - - public Object getParent() { - return null; - } - - public Object[] getElements() { - return getChildren(); - } - - public Object[] getChildren() { - return CollectionTools.array(this.childrenModel()); - } - - /** - * Override with potentially more efficient logic - */ - public boolean hasChildren() { - return this.childrenModel().hasNext(); - } - - /** - * Should only be overridden with a call to super.dispose() - */ - public void dispose() { - for (Object child : getChildren()) { - getTreeContentProvider().dispose(child); - } - disengageChildren(); - } - - /** - * Should only be overridden with a call to super.engageChildren() before - * subclass logic - */ - protected void engageChildren() { - this.childrenModel.addCollectionChangeListener(CollectionValueModel.VALUES, this.childrenListener); - } - - /** - * Should only be overridden with a call to super.disengageChildren() after - * subclass logic - */ - protected void disengageChildren() { - if (this.childrenModel != null) { - this.childrenModel.removeCollectionChangeListener(CollectionValueModel.VALUES, this.childrenListener); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java deleted file mode 100644 index 8b74901db1..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/DelegatingTreeContentAndLabelProvider.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jpt.ui.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; -import org.eclipse.jpt.ui.jface.TreeItemContentProvider; -import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; - -/** - * Extension of {@link DelegatingContentAndLabelProvider} that provides an extension - * to provide tree content - */ -public class DelegatingTreeContentAndLabelProvider extends DelegatingContentAndLabelProvider - implements ITreeContentProvider -{ - public DelegatingTreeContentAndLabelProvider( - TreeItemContentProviderFactory treeItemContentProviderFactory) { - super(treeItemContentProviderFactory); - } - - public DelegatingTreeContentAndLabelProvider( - TreeItemContentProviderFactory treeItemContentProviderFactory, - ItemLabelProviderFactory itemLabelProviderFactory) { - super(treeItemContentProviderFactory, itemLabelProviderFactory); - } - - - protected TreeItemContentProvider itemContentProvider(Object item) { - return (TreeItemContentProvider) super.itemContentProvider(item); - } - - public Object[] getChildren(Object parentElement) { - TreeItemContentProvider provider = itemContentProvider(parentElement); - return (provider == null) ? new Object[0] : provider.getChildren(); - } - - public Object getParent(Object element) { - TreeItemContentProvider provider = itemContentProvider(element); - return (provider == null) ? null : provider.getParent(); - } - - public boolean hasChildren(Object element) { - TreeItemContentProvider provider = itemContentProvider(element); - return (provider == null) ? false : provider.hasChildren(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ImageImageDescriptor.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ImageImageDescriptor.java deleted file mode 100644 index 4b69fd205c..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ImageImageDescriptor.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; - -/** - * Image descriptor for an image. - */ -public class ImageImageDescriptor extends ImageDescriptor -{ - - private Image fImage; - - /** - * Constructor for ImagImageDescriptor. - */ - public ImageImageDescriptor(Image image) { - super(); - this.fImage = image; - } - - @Override - public boolean equals(Object obj) { - return (obj != null) && getClass().equals(obj.getClass()) && this.fImage.equals(((ImageImageDescriptor) obj).fImage); - } - - @Override - public ImageData getImageData() { - return this.fImage.getImageData(); - } - - @Override - public int hashCode() { - return this.fImage.hashCode(); - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java deleted file mode 100644 index 8483d32948..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullLabelProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.swt.graphics.Image; - -/** - * Null implementation of the ILabelProvider interface. - * Implemented as a singleton. - */ -public final class NullLabelProvider - implements ILabelProvider -{ - public static final NullLabelProvider INSTANCE = new NullLabelProvider(); - - public static ILabelProvider instance() { - return INSTANCE; - } - - /** - * Ensure a single instance. - */ - private NullLabelProvider() { - super(); - } - - public Image getImage(Object element) { - return null; - } - - public String getText(Object element) { - return null; - } - - public void addListener(ILabelProviderListener listener) { - // do nothing - } - - public void dispose() { - // do nothing - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java deleted file mode 100644 index fdb7e0ad36..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/NullTreeContentProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/** - * Null implementation of the ILabelProvider interface. - * Implemented as a singleton. - */ -public final class NullTreeContentProvider - implements ITreeContentProvider -{ - private static final Object[] EMPTY_ARRAY = new Object[0]; - public static final NullTreeContentProvider INSTANCE = new NullTreeContentProvider(); - - public static ITreeContentProvider instance() { - return INSTANCE; - } - - /** - * Ensure a single instance. - */ - private NullTreeContentProvider() { - super(); - } - - public Object[] getChildren(Object parentElement) { - return EMPTY_ARRAY; - } - - public Object getParent(Object element) { - return null; - } - - public boolean hasChildren(Object element) { - return false; - } - - public Object[] getElements(Object inputElement) { - return EMPTY_ARRAY; - } - - public void dispose() { - // do nothing - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // do nothing - } - -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/StructuredContentProviderAdapter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/StructuredContentProviderAdapter.java deleted file mode 100644 index 12ab567c04..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/StructuredContentProviderAdapter.java +++ /dev/null @@ -1,261 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.internal.jface; - -import java.util.ListIterator; -import org.eclipse.jface.viewers.AbstractListViewer; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jpt.ui.internal.listeners.SWTListChangeListenerWrapper; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * This adapter can be used to keep an AbstractListViewer - * (e.g. a ListViewer or ComboViewer) in synch with a ListValueModel - * (or a CollectionValueModel). - */ -public class StructuredContentProviderAdapter - implements IStructuredContentProvider -{ - /** The underlying model list. */ - protected ListValueModel listHolder; - - /** The list viewer we keep in synch with the model list. */ - protected final AbstractListViewer listViewer; - - /** A listener that allows us to forward changes made to the underlying model list. */ - protected final ListChangeListener listChangeListener; - - - // ********** static ********** - - /** - * Adapt the specified list viewer to the specified list holder so they - * stay in synch. - */ - public static StructuredContentProviderAdapter adapt(AbstractListViewer listViewer, ListValueModel listHolder) { - // we need only construct the adapter and it will hook up to the list viewer etc. - return new StructuredContentProviderAdapter(listViewer, listHolder); - } - - /** - * Adapt the specified list viewer to the specified list holder so they - * stay in synch. - */ - public static StructuredContentProviderAdapter adapt(AbstractListViewer listViewer, CollectionValueModel collectionHolder) { - // we need only construct the adapter and it will hook up to the list viewer etc. - return new StructuredContentProviderAdapter(listViewer, collectionHolder); - } - - - // ********** constructors ********** - - /** - * Constructor. - */ - protected StructuredContentProviderAdapter(AbstractListViewer listViewer, ListValueModel listHolder) { - super(); - this.listChangeListener = this.buildListChangeListener(); - this.listViewer = listViewer; - this.listViewer.setContentProvider(this); - // the list viewer will call back to #inputChanged(Viewer, Object, Object) - this.listViewer.setInput(listHolder); - } - - /** - * Constructor. - */ - protected StructuredContentProviderAdapter(AbstractListViewer listViewer, CollectionValueModel collectionHolder) { - this(listViewer, new CollectionListValueModelAdapter(collectionHolder)); - } - - - // ********** initialization ********** - - protected ListChangeListener buildListChangeListener() { - return new SWTListChangeListenerWrapper(this.buildListChangeListener_()); - } - - protected ListChangeListener buildListChangeListener_() { - return new ListChangeListener() { - public void itemsAdded(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsAdded(e); - } - public void itemsRemoved(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsRemoved(e); - } - public void itemsReplaced(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsReplaced(e); - } - public void itemsMoved(ListChangeEvent e) { - StructuredContentProviderAdapter.this.itemsMoved(e); - } - public void listCleared(ListChangeEvent e) { - StructuredContentProviderAdapter.this.listCleared(); - } - public void listChanged(ListChangeEvent e) { - StructuredContentProviderAdapter.this.listChanged(); - } - @Override - public String toString() { - return "list listener"; - } - }; - } - - - // ********** IStructuredContentProvider implementation ********** - - public Object[] getElements(Object inputElement) { - if (inputElement != this.listHolder) { - throw new IllegalArgumentException("invalid input element: " + inputElement); - } - return this.listHolder.toArray(); - } - - /** - * This is called by the list viewer, so don't update the list viewer here. - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - if (viewer != this.listViewer) { - throw new IllegalArgumentException("invalid viewer: " + viewer); - } - if (oldInput != this.listHolder) { - throw new IllegalArgumentException("invalid old input: " + oldInput); - } - this.modelChanged((ListValueModel) oldInput, (ListValueModel) newInput); - } - - public void dispose() { - // do nothing - listeners should've already been removed in #inputChanged(Viewer, Object, Object) - } - - - // ********** internal methods ********** - - protected void modelChanged(ListValueModel oldModel, ListValueModel newModel) { - if (oldModel != null) { - this.listHolder.removeListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); - } - this.listHolder = newModel; - if (newModel != null) { - this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.listChangeListener); - } - } - - - // ********** public API ********** - - /** - * Return the underlying list model. - */ - public ListValueModel model() { - return this.listHolder; - } - - /** - * Set the underlying list model. - */ - public void setModel(ListValueModel listHolder) { - // the list viewer will call back to #inputChanged(Viewer, Object, Object) - this.listViewer.setInput(listHolder); - } - - /** - * Set the underlying collection model. - */ - public void setModel(CollectionValueModel collectionHolder) { - this.setModel(new CollectionListValueModelAdapter(collectionHolder)); - } - - - // ********** list change support ********** - - /** - * Items were added to the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsAdded(ListChangeEvent e) { - int i = e.getIndex(); - for (@SuppressWarnings("unchecked") ListIterator stream = e.items(); stream.hasNext(); i++) { - this.listViewer.insert(stream.next(), i); - } - } - - /** - * Items were removed from the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsRemoved(ListChangeEvent e) { - this.listViewer.remove(CollectionTools.array(e.items(), e.itemsSize())); - } - - /** - * Items were replaced in the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsReplaced(ListChangeEvent e) { - this.listViewer.remove(CollectionTools.array(e.replacedItems(), e.itemsSize())); - int i = e.getIndex(); - for (@SuppressWarnings("unchecked") ListIterator stream = e.items(); stream.hasNext(); i++) { - this.listViewer.insert(stream.next(), i); - } - } - - /** - * Items were moved in the underlying model list. - * Synchronize the list viewer. - */ - protected void itemsMoved(ListChangeEvent e) { - int len = e.getMoveLength(); - Object[] items = new Object[len]; - int offset = e.getSourceIndex(); - for (int i = 0; i < len; i++) { - items[i] = this.listHolder.get(offset + i); - } - this.listViewer.remove(items); - - offset = e.getTargetIndex(); - for (int i = 0; i < len; i++) { - this.listViewer.insert(items[i], offset + i); - } - } - - /** - * The underlying model list was cleared. - * Synchronize the list viewer. - */ - protected void listCleared() { - this.listViewer.refresh(); - } - - /** - * The underlying model list has changed "dramatically". - * Synchronize the list viewer. - */ - protected void listChanged() { - this.listViewer.refresh(); - } - - - // ********** Object overrides ********** - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.listHolder); - } - -} |