From 4102983083ae008760876f72d6d31b01d3867a78 Mon Sep 17 00:00:00 2001 From: Brian Vosburgh Date: Thu, 21 Nov 2013 18:36:40 -0500 Subject: rework ListenerList --- .../core/internal/gen/AbstractJptGenerator.java | 7 +-- .../resource/java/binary/RootBinaryModel.java | 3 +- .../java/source/SourceCompilationUnit.java | 4 +- .../NotifyingRepeatingJobCommandWrapper.java | 3 +- .../common/core/resource/xml/JptXmlResource.java | 6 +- ...AbstractItemStructuredStateProviderManager.java | 3 +- .../internal/jface/AbstractSelectionProvider.java | 3 +- .../ui/internal/swt/AbstractComboModelAdapter.java | 20 +------ .../common/ui/internal/swt/TableModelAdapter.java | 18 +----- .../jpt/common/utility/internal/ListenerList.java | 64 ++++++++++------------ ...ynchronousNotifyingRepeatingCommandWrapper.java | 3 +- .../command/NotifyingRepeatingCommandWrapper.java | 3 +- .../utility/internal/model/ChangeSupport.java | 13 +++-- .../common/utility/internal/model/ModelTools.java | 47 ++++++++++++++++ .../utility/tests/internal/ListenerListTests.java | 20 +++---- .../resource/AbstractJaxbFileResourceModel.java | 6 +- .../internal/utility/CallbackJobSynchronizer.java | 5 +- .../utility/CallbackSynchronousSynchronizer.java | 5 +- .../db/internal/DTPConnectionProfileFactory.java | 3 +- .../db/internal/DTPConnectionProfileWrapper.java | 5 +- .../internal/wizards/DatabaseSchemaWizardPage.java | 5 +- 21 files changed, 135 insertions(+), 111 deletions(-) create mode 100644 common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ModelTools.java diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java index e140be0953..00c554427d 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/gen/AbstractJptGenerator.java @@ -41,6 +41,7 @@ import org.eclipse.jpt.common.core.gen.JptGenerator; import org.eclipse.jpt.common.core.gen.LaunchConfigListener; import org.eclipse.jpt.common.core.internal.plugin.JptCommonCorePlugin; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.osgi.service.datalocation.Location; import org.osgi.framework.Bundle; @@ -54,7 +55,7 @@ public abstract class AbstractJptGenerator implements JptGenerator private final IJavaProject javaProject; private final String projectLocation; - private final ListenerList launchConfigListenerList; + private final ListenerList launchConfigListenerList = ModelTools.listenerList(); private boolean isDebug = false; @@ -64,7 +65,6 @@ public abstract class AbstractJptGenerator implements JptGenerator super(); this.javaProject = javaProject; this.projectLocation = javaProject.getProject().getLocation().toString(); - this.launchConfigListenerList = this.buildLaunchConfigListenerList(); this.initialize(); } @@ -441,9 +441,6 @@ public abstract class AbstractJptGenerator implements JptGenerator this.isDebug = isDebug; } - private ListenerList buildLaunchConfigListenerList() { - return new ListenerList(LaunchConfigListener.class); - } // ********** listener ********** diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/RootBinaryModel.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/RootBinaryModel.java index fc7961cea0..99a30b2cde 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/RootBinaryModel.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/RootBinaryModel.java @@ -16,6 +16,7 @@ import org.eclipse.jpt.common.core.internal.utility.ContentTypeTools; import org.eclipse.jpt.common.core.resource.java.JavaResourceModel; import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageFragmentRoot; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; /** * JAR and external types @@ -28,7 +29,7 @@ abstract class RootBinaryModel private final AnnotationProvider annotationProvider; /** listeners notified whenever the resource model changes */ - private final ListenerList resourceModelListenerList = new ListenerList(JptResourceModelListener.class); + private final ListenerList resourceModelListenerList = ModelTools.listenerList(); // ********** construction ********** diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java index 81eaad7cf3..3d8475f389 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceCompilationUnit.java @@ -22,6 +22,7 @@ import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.core.utility.jdt.AnnotationEditFormatter; import org.eclipse.jpt.common.utility.command.CommandContext; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; /** * Java compilation unit (source file) @@ -43,7 +44,7 @@ public abstract class SourceCompilationUnit private final CommandContext modifySharedDocumentCommandContext; /** listeners notified whenever the resource model changes */ - private final ListenerList resourceModelListenerList; + private final ListenerList resourceModelListenerList = ModelTools.listenerList(); // ********** construction ********** @@ -58,7 +59,6 @@ public abstract class SourceCompilationUnit this.annotationProvider = annotationProvider; this.annotationEditFormatter = annotationEditFormatter; this.modifySharedDocumentCommandContext = modifySharedDocumentCommandContext; - this.resourceModelListenerList = new ListenerList(JptResourceModelListener.class); } void openCompilationUnit() { diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java index 4569c7d2b6..6bad23cc21 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/command/NotifyingRepeatingJobCommandWrapper.java @@ -16,6 +16,7 @@ import org.eclipse.jpt.common.core.utility.command.JobCommandContext; import org.eclipse.jpt.common.core.utility.command.NotifyingRepeatingJobCommand; import org.eclipse.jpt.common.utility.exception.ExceptionHandler; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; /** * @see org.eclipse.jpt.common.utility.internal.command.NotifyingRepeatingCommandWrapper @@ -24,7 +25,7 @@ public class NotifyingRepeatingJobCommandWrapper extends RepeatingJobCommandWrapper implements NotifyingRepeatingJobCommand { - private final ListenerList listenerList = new ListenerList(Listener.class); + private final ListenerList listenerList = ModelTools.listenerList(); // ********** construction ********** diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java index 68909994a5..75c0e7d15d 100644 --- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java +++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/xml/JptXmlResource.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2013 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. @@ -31,6 +31,7 @@ import org.eclipse.jpt.common.core.internal.plugin.JptCommonCorePlugin; import org.eclipse.jpt.common.core.internal.utility.ContentTypeTools; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jst.j2ee.internal.xml.J2EEXmlDtDEntityResolver; import org.eclipse.wst.common.internal.emf.resource.Renderer; import org.eclipse.wst.common.internal.emf.resource.Translator; @@ -69,8 +70,7 @@ public class JptXmlResource protected final Translator rootTranslator; - protected final ListenerList resourceModelListenerList = - new ListenerList(JptResourceModelListener.class); + private final ListenerList resourceModelListenerList = ModelTools.listenerList(); public JptXmlResource(URI uri, Renderer renderer, IContentType contentType, Translator rootTranslator) { diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java index 1791561eb6..08506d72ea 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractItemStructuredStateProviderManager.java @@ -24,6 +24,7 @@ import org.eclipse.jpt.common.ui.jface.StructuredStateProvider; import org.eclipse.jpt.common.utility.exception.ExceptionHandler; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.swt.graphics.Image; import com.ibm.icu.text.MessageFormat; @@ -68,7 +69,7 @@ abstract class AbstractItemStructuredStateProviderManager listenerList = new ListenerList(ILabelProviderListener.class); + private final ListenerList listenerList = ModelTools.listenerList(); private final ExceptionHandler exceptionHandler; /* private-protected */ final static JptCommonUiPlugin PLUG_IN = JptCommonUiPlugin.instance(); diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java index f4dd827af4..2862148d38 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/jface/AbstractSelectionProvider.java @@ -16,6 +16,7 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jpt.common.utility.exception.ExceptionHandler; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; /** * Provide support for {@link ISelectionChangedListener selection change @@ -26,7 +27,7 @@ public abstract class AbstractSelectionProvider implements ISelectionProvider { private final ExceptionHandler exceptionHandler; - private ListenerList listenerList = new ListenerList(ISelectionChangedListener.class); + private final ListenerList listenerList = ModelTools.listenerList(); protected AbstractSelectionProvider(ExceptionHandler exceptionHandler) { diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/AbstractComboModelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/AbstractComboModelAdapter.java index eb5cea5010..010fde9abc 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/AbstractComboModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/AbstractComboModelAdapter.java @@ -16,6 +16,7 @@ import org.eclipse.jpt.common.ui.internal.swt.listeners.SWTListenerTools; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.common.utility.model.event.ListAddEvent; import org.eclipse.jpt.common.utility.model.event.ListChangeEvent; import org.eclipse.jpt.common.utility.model.event.ListClearEvent; @@ -105,14 +106,12 @@ public abstract class AbstractComboModelAdapter { /** * Clients that are interested in selection change events. */ - @SuppressWarnings("unchecked") - protected final ListenerList selectionChangeListenerList; + protected final ListenerList selectionChangeListenerList = ModelTools.listenerList(); /** * Clients that are interested in double click events. */ - @SuppressWarnings("unchecked") - protected final ListenerList doubleClickListenerList; + protected final ListenerList doubleClickListenerList = ModelTools.listenerList(); /** * A listener that allows us to stop listening to stuff when the combo @@ -160,9 +159,6 @@ public abstract class AbstractComboModelAdapter { this.comboHolder.addSelectionListener(this.comboSelectionListener); } - this.selectionChangeListenerList = this.buildSelectionChangeListenerList(); - this.doubleClickListenerList = this.buildDoubleClickListenerList(); - this.comboDisposeListener = this.buildComboDisposeListener(); this.comboHolder.addDisposeListener(this.comboDisposeListener); @@ -242,16 +238,6 @@ public abstract class AbstractComboModelAdapter { }; } - @SuppressWarnings("unchecked") - protected ListenerList buildDoubleClickListenerList() { - return new ListenerList(DoubleClickListener.class); - } - - @SuppressWarnings("unchecked") - protected ListenerList buildSelectionChangeListenerList() { - return new ListenerList(SelectionChangeListener.class); - } - protected DisposeListener buildComboDisposeListener() { return new DisposeListener() { public void widgetDisposed(DisposeEvent event) { diff --git a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/TableModelAdapter.java b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/TableModelAdapter.java index d402a33992..f750d92f9c 100644 --- a/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/TableModelAdapter.java +++ b/common/plugins/org.eclipse.jpt.common.ui/src/org/eclipse/jpt/common/ui/internal/swt/TableModelAdapter.java @@ -20,6 +20,7 @@ import org.eclipse.jpt.common.ui.internal.swt.listeners.SWTListenerTools; import org.eclipse.jpt.common.utility.internal.ArrayTools; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.common.utility.internal.model.value.PropertyCollectionValueModelAdapter; import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent; import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent; @@ -94,12 +95,12 @@ public class TableModelAdapter { /** * Clients that are interested in selection change events. */ - protected final ListenerList> selectionChangeListenerList; + protected final ListenerList> selectionChangeListenerList = ModelTools.listenerList(); /** * Clients that are interested in double click events. */ - protected final ListenerList> doubleClickListenerList; + protected final ListenerList> doubleClickListenerList = ModelTools.listenerList(); /** * A listener that allows us to stop listening to stuff when the table @@ -216,9 +217,6 @@ public class TableModelAdapter { this.tableSelectionListener = this.buildTableSelectionListener(); this.table.addSelectionListener(this.tableSelectionListener); - this.selectionChangeListenerList = this.buildSelectionChangeListenerList(); - this.doubleClickListenerList = this.buildDoubleClickListenerList(); - this.tableDisposeListener = this.buildTableDisposeListener(); this.table.addDisposeListener(this.tableDisposeListener); @@ -299,16 +297,6 @@ public class TableModelAdapter { }; } - @SuppressWarnings({"rawtypes", "unchecked"}) - protected ListenerList> buildDoubleClickListenerList() { - return new ListenerList(DoubleClickListener.class); - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - protected ListenerList> buildSelectionChangeListenerList() { - return new ListenerList(SelectionChangeListener.class); - } - protected DisposeListener buildTableDisposeListener() { return new DisposeListener() { public void widgetDisposed(DisposeEvent event) { diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java index cc870b3038..e2ebddcdc3 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/ListenerList.java @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.internal; -import java.lang.reflect.Array; import java.util.Arrays; import java.util.Iterator; import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools; @@ -20,44 +19,41 @@ import org.eclipse.jpt.common.utility.internal.iterator.IteratorTools; * * @param the type of listeners held by the list */ -public class ListenerList +public final class ListenerList implements Iterable { /** * We can mark this volatile and not synchronize the read * methods because we never change the contents of the array. */ - private transient volatile L[] listeners; + @SuppressWarnings("unchecked") + private transient volatile L[] listeners = (L[]) ObjectTools.EMPTY_OBJECT_ARRAY; /** - * Construct a listener list for listeners of the specified type. + * Construct a listener list initialized with the specified listener. */ - public ListenerList(Class listenerClass) { - super(); - this.listeners = this.buildListenerArray(listenerClass, 0); - } - - /** - * Construct a listener list for listeners of the specified type. - * Add the specified listener to the list. - */ - public ListenerList(Class listenerClass, L listener) { - super(); + @SuppressWarnings("unchecked") + public ListenerList(L listener) { + this(); if (listener == null) { throw new NullPointerException(); } - this.listeners = this.buildListenerArray(listenerClass, 1); - this.listeners[0] = listener; + this.listeners = (L[]) new Object[] { listener }; } - @SuppressWarnings("unchecked") - private L[] buildListenerArray(Class listenerClass, int length) { - return (L[]) Array.newInstance(listenerClass, length); + /** + * Construct an empty listener list. + */ + public ListenerList() { + super(); } /** - * Return the listeners. + * Return the listeners. The returned list will be a "snapshot" of the list + * of listeners at the time this method is called. There is no possibility + * of a {@link java.util.ConcurrentModificationException} with the returned + * iterator. */ public Iterator iterator() { return IteratorTools.iterator(this.listeners); @@ -81,10 +77,14 @@ public class ListenerList * Add the specified listener to the listener list. * Duplicate listeners are not allowed. */ - public synchronized void add(L listener) { + public void add(L listener) { if (listener == null) { throw new NullPointerException(); } + this.add_(listener); + } + + private synchronized void add_(L listener) { if (ArrayTools.contains(this.listeners, listener)) { throw new IllegalArgumentException("duplicate listener: " + listener); //$NON-NLS-1$ } @@ -95,10 +95,11 @@ public class ListenerList * Remove the specified listener from the listener list. * Removing a listener that is not on the list is not allowed. */ - public synchronized void remove(L listener) { - if (listener == null) { - throw new NullPointerException(); - } + public void remove(L listener) { + this.remove_(listener); + } + + private synchronized void remove_(L listener) { int index = ArrayTools.indexOf(this.listeners, listener); if (index == -1) { throw new IllegalArgumentException("unregistered listener: " + listener); //$NON-NLS-1$ @@ -109,16 +110,9 @@ public class ListenerList /** * Clear the listener list. */ - public synchronized void clear() { - this.listeners = ArrayTools.clear(this.listeners); - } - - /** - * Return the type of listeners held by the listener list. - */ @SuppressWarnings("unchecked") - public Class getListenerType() { - return (Class) this.listeners.getClass().getComponentType(); + public synchronized void clear() { + this.listeners = (L[]) ObjectTools.EMPTY_OBJECT_ARRAY; } @Override diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java index 57ff46144d..7fddd1b1ba 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/AsynchronousNotifyingRepeatingCommandWrapper.java @@ -15,6 +15,7 @@ import org.eclipse.jpt.common.utility.command.NotifyingRepeatingCommand; import org.eclipse.jpt.common.utility.exception.ExceptionHandler; import org.eclipse.jpt.common.utility.internal.ConsumerThreadCoordinator; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; /** * Extend the asynchronous repeating command to notify listeners @@ -28,7 +29,7 @@ public class AsynchronousNotifyingRepeatingCommandWrapper extends AsynchronousRepeatingCommandWrapper implements NotifyingRepeatingCommand { - private final ListenerList listenerList = new ListenerList(Listener.class); + private final ListenerList listenerList = ModelTools.listenerList(); /** * This handles any exceptions thrown by the listeners. diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java index 149433c204..df13e091b9 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/command/NotifyingRepeatingCommandWrapper.java @@ -14,6 +14,7 @@ import org.eclipse.jpt.common.utility.command.Command; import org.eclipse.jpt.common.utility.command.CommandContext; import org.eclipse.jpt.common.utility.exception.ExceptionHandler; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; /** * NB: If another execution cycle is initiated while we are @@ -35,7 +36,7 @@ public class NotifyingRepeatingCommandWrapper extends RepeatingCommandWrapper implements NotifyingRepeatingCommand { - private final ListenerList listenerList = new ListenerList(Listener.class); + private final ListenerList listenerList = ModelTools.listenerList(); // ********** construction ********** diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java index d27bf080e9..269b4e9a2e 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ChangeSupport.java @@ -91,7 +91,6 @@ public class ChangeSupport { * Construct support for the specified source of change events. * The source cannot be null. */ - // TODO remove public ChangeSupport(Model source) { this(source, DefaultExceptionHandler.instance()); } @@ -2715,21 +2714,23 @@ public class ChangeSupport { * listeners. */ static abstract class AspectListenerListPair { + private final Class listenerClass; final ListenerList listenerList; AspectListenerListPair(Class listenerClass, L listener) { super(); - this.listenerList = new ListenerList(listenerClass, listener); + this.listenerClass = listenerClass; + this.listenerList = ModelTools.listenerList(listener); } abstract String getAspectName(); - boolean matches(Class listenerClass, @SuppressWarnings("unused") String aspectName) { - return this.listenerList.getListenerType() == listenerClass; + boolean matches(Class listenerType, @SuppressWarnings("unused") String aspectName) { + return this.listenerClass == listenerType; } - boolean matches(Class listenerClass) { - return this.matches(listenerClass, null); + boolean matches(Class listenerType) { + return this.matches(listenerType, null); } @Override diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ModelTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ModelTools.java new file mode 100644 index 0000000000..d6d0563512 --- /dev/null +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/ModelTools.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2005, 2013 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.common.utility.internal.model; + +import org.eclipse.jpt.common.utility.internal.ListenerList; + +public final class ModelTools { + + // ********** listener list ********** + + /** + * Build a listener list that does not allow adding + * duplicate listeners or removing non-listeners. + * @param the type of listeners held by the list + */ + public static ListenerList listenerList() { + return new ListenerList(); + } + + /** + * Build a listener list that does not allow adding + * duplicate listeners or removing non-listeners + * and is initialized with the specified listener. + * @param the type of listeners held by the list + */ + public static ListenerList listenerList(L listener) { + return new ListenerList(listener); + } + + + // ********** constructor ********** + + /** + * Suppress default constructor, ensuring non-instantiability. + */ + private ModelTools() { + super(); + throw new UnsupportedOperationException(); + } +} diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ListenerListTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ListenerListTests.java index 231f653bfc..dd379f48ff 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ListenerListTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/ListenerListTests.java @@ -23,7 +23,7 @@ public class ListenerListTests extends TestCase { } public void testGetListeners() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); Listener listener1 = new LocalListener(); Listener listener2 = new LocalListener(); assertEquals(0, IterableTools.size(listenerList)); @@ -36,7 +36,7 @@ public class ListenerListTests extends TestCase { } public void testSize() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); Listener listener1 = new LocalListener(); Listener listener2 = new LocalListener(); assertEquals(0, listenerList.size()); @@ -47,7 +47,7 @@ public class ListenerListTests extends TestCase { } public void testIsEmpty() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); Listener listener1 = new LocalListener(); Listener listener2 = new LocalListener(); assertTrue(listenerList.isEmpty()); @@ -58,7 +58,7 @@ public class ListenerListTests extends TestCase { } public void testAdd_null() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); boolean exCaught = false; try { listenerList.add(null); @@ -70,7 +70,7 @@ public class ListenerListTests extends TestCase { } public void testAdd_duplicate() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); Listener listener = new LocalListener(); listenerList.add(listener); @@ -85,7 +85,7 @@ public class ListenerListTests extends TestCase { } public void testRemove() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); Listener listener1 = new LocalListener(); Listener listener2 = new LocalListener(); listenerList.add(listener1); @@ -102,19 +102,19 @@ public class ListenerListTests extends TestCase { } public void testRemove_null() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); boolean exCaught = false; try { listenerList.remove(null); fail("invalid listener list: " + listenerList); - } catch (NullPointerException ex) { + } catch (IllegalArgumentException ex) { exCaught = true; } assertTrue(exCaught); } public void testRemove_unregistered() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); Listener listener = new LocalListener(); listenerList.add(listener); listenerList.remove(listener); @@ -130,7 +130,7 @@ public class ListenerListTests extends TestCase { } public void testClear() throws Exception { - ListenerList listenerList = new ListenerList(Listener.class); + ListenerList listenerList = new ListenerList(); Listener listener1 = new LocalListener(); Listener listener2 = new LocalListener(); listenerList.add(listener1); diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java index 5de2a2dab8..a3480813b2 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/resource/AbstractJaxbFileResourceModel.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Oracle. All rights reserved. + * Copyright (c) 2012, 2013 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 @@ -22,6 +22,7 @@ import org.eclipse.jpt.common.core.JptResourceModel; import org.eclipse.jpt.common.core.JptResourceModelListener; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.jaxb.core.internal.plugin.JptJaxbCorePlugin; public abstract class AbstractJaxbFileResourceModel @@ -36,8 +37,7 @@ public abstract class AbstractJaxbFileResourceModel protected final S state; - protected final ListenerList resourceModelListenerList = - new ListenerList(JptResourceModelListener.class); + protected final ListenerList resourceModelListenerList = ModelTools.listenerList(); protected AbstractJaxbFileResourceModel(IFile file) { diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackJobSynchronizer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackJobSynchronizer.java index 8be934d081..593ed81c37 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackJobSynchronizer.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackJobSynchronizer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Oracle. All rights reserved. + * Copyright (c) 2009, 2013 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. @@ -14,6 +14,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.jpt.common.core.utility.command.JobCommand; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.jaxb.core.utility.CallbackSynchronizer; /** @@ -29,7 +30,7 @@ public class CallbackJobSynchronizer extends JobSynchronizer implements CallbackSynchronizer { - private final ListenerList listenerList = new ListenerList(Listener.class); + private final ListenerList listenerList = ModelTools.listenerList(); // ********** construction ********** diff --git a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackSynchronousSynchronizer.java b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackSynchronousSynchronizer.java index 97b2b3a6d6..92a9a7504d 100644 --- a/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackSynchronousSynchronizer.java +++ b/jaxb/plugins/org.eclipse.jpt.jaxb.core/src/org/eclipse/jpt/jaxb/core/internal/utility/CallbackSynchronousSynchronizer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Oracle. All rights reserved. + * Copyright (c) 2009, 2013 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. @@ -11,6 +11,7 @@ package org.eclipse.jpt.jaxb.core.internal.utility; import org.eclipse.jpt.common.utility.command.Command; import org.eclipse.jpt.common.utility.internal.ListenerList; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.jaxb.core.utility.CallbackSynchronizer; /** @@ -34,7 +35,7 @@ public class CallbackSynchronousSynchronizer extends SynchronousSynchronizer implements CallbackSynchronizer { - private final ListenerList listenerList = new ListenerList(Listener.class); + private final ListenerList listenerList = ModelTools.listenerList(); // ********** construction ********** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileFactory.java index 700b718663..f59d4a67b7 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileFactory.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileFactory.java @@ -17,6 +17,7 @@ import org.eclipse.datatools.enablement.jdt.classpath.DriverClasspathContainer; import org.eclipse.jdt.core.IClasspathContainer; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.iterable.IterableTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.transformer.Transformer; import org.eclipse.jpt.jpa.db.ConnectionProfile; @@ -130,7 +131,7 @@ public final class DTPConnectionProfileFactory private static class LocalProfileListener implements IProfileListener1 { - private final ListenerList listenerList = new ListenerList(ConnectionProfileListener.class); + private final ListenerList listenerList = ModelTools.listenerList(); LocalProfileListener() { super(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java index 04fcdac48b..95a809f9cb 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.db/src/org/eclipse/jpt/jpa/db/internal/DTPConnectionProfileWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Oracle. All rights reserved. + * Copyright (c) 2006, 2013 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. @@ -22,6 +22,7 @@ import org.eclipse.datatools.sqltools.core.DatabaseIdentifier; import org.eclipse.datatools.sqltools.core.profile.ProfileUtil; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.ObjectTools; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.jpa.db.ConnectionListener; import org.eclipse.jpt.jpa.db.ConnectionProfile; import org.eclipse.jpt.jpa.db.DatabaseIdentifierAdapter; @@ -392,7 +393,7 @@ final class DTPConnectionProfileWrapper private class LocalConnectionListener implements IManagedConnectionOfflineListener { - private ListenerList listenerList = new ListenerList(ConnectionListener.class); + private ListenerList listenerList = ModelTools.listenerList(); LocalConnectionListener() { super(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java index 4b02e66b00..4314993038 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/DatabaseSchemaWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 Oracle. All rights reserved. + * Copyright (c) 2006, 2013 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. @@ -17,6 +17,7 @@ import org.eclipse.jpt.common.ui.internal.WorkbenchTools; import org.eclipse.jpt.common.ui.internal.swt.widgets.DisplayTools; import org.eclipse.jpt.common.utility.internal.ListenerList; import org.eclipse.jpt.common.utility.internal.iterable.EmptyIterable; +import org.eclipse.jpt.common.utility.internal.model.ModelTools; import org.eclipse.jpt.jpa.core.JpaProject; import org.eclipse.jpt.jpa.db.ConnectionAdapter; import org.eclipse.jpt.jpa.db.ConnectionListener; @@ -52,7 +53,7 @@ public class DatabaseSchemaWizardPage extends WizardPage { final JpaProject jpaProject; - private final ListenerList listenerList = new ListenerList(Listener.class); + private final ListenerList listenerList = ModelTools.listenerList(); private DatabaseGroup databaseGroup; -- cgit v1.2.3