package net.pterodactylus.jsite.core;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/** Logger. */
private static final Logger logger = Logging.getLogger(InsertManager.class.getName());
- /** The insert listeners. */
- private final List<InsertListener> insertListeners = new ArrayList<InsertListener>();
+ /** The insert listener support. */
+ private final InsertListenerSupport insertListenerSupport = new InsertListenerSupport();
/** Mapping from insert IDs to inserts. */
private final Map<String, Insert> inserts = new HashMap<String, Insert>();
*/
public void addInsertListener(InsertListener insertListener) {
logger.log(Level.FINEST, "addInsertListener(insertListener=" + insertListener + ")");
- synchronized (insertListeners) {
- insertListeners.add(insertListener);
- }
+ insertListenerSupport.addListener(insertListener);
}
/**
*/
public void removeInsertListener(InsertListener insertListener) {
logger.log(Level.FINEST, "removeInsertListener(insertListener=" + insertListener + ")");
- synchronized (insertListeners) {
- insertListeners.remove(insertListener);
- }
- }
-
- /**
- * Notifies all listeners that an insert was added.
- *
- * @param insert
- * The insert that was added
- */
- private void fireInsertAdded(Insert insert) {
- synchronized (insertListeners) {
- for (InsertListener insertListener : insertListeners) {
- insertListener.insertAdded(insert);
- }
- }
- }
-
- /**
- * Notifies all listeners that an insert was removed.
- *
- * @param insert
- * The insert that was removes
- */
- @SuppressWarnings("unused")
- private void fireInsertRemoved(Insert insert) {
- synchronized (insertListeners) {
- for (InsertListener insertListener : insertListeners) {
- insertListener.insertRemoved(insert);
- }
- }
- }
-
- /**
- * Notifies all listeners that an insert was started.
- *
- * @param insert
- * The insert that was started
- */
- @SuppressWarnings("unused")
- private void fireInsertStarted(Insert insert) {
- synchronized (insertListeners) {
- for (InsertListener insertListener : insertListeners) {
- insertListener.insertStarted(insert);
- }
- }
- }
-
- /**
- * Notifies all listeners that an insert made some progress
- *
- * @param insert
- * The insert that made some progress
- */
- @SuppressWarnings("unused")
- private void fireInsertProgressed(Insert insert) {
- synchronized (insertListeners) {
- for (InsertListener insertListener : insertListeners) {
- insertListener.insertProgressed(insert);
- }
- }
- }
-
- /**
- * Notifies all listeners that an insert generated a URI.
- *
- * @param insert
- * The insert that generated a URI
- * @param uri
- * The generated URI
- */
- @SuppressWarnings("unused")
- private void fireInsertGeneratedURI(Insert insert, String uri) {
- synchronized (insertListeners) {
- for (InsertListener insertListener : insertListeners) {
- insertListener.insertGeneratedURI(insert, uri);
- }
- }
- }
-
- /**
- * Notifies all listeners that an insert has finished.
- *
- * @param insert
- * The insert that has finished
- */
- @SuppressWarnings("unused")
- private void fireInsertFinished(Insert insert) {
- synchronized (insertListeners) {
- for (InsertListener insertListener : insertListeners) {
- insertListener.insertFinished(insert);
- }
- }
+ insertListenerSupport.removeListener(insertListener);
}
//
Insert newInsert = new Insert(project, insertNode, insertId);
inserts.put(insertId, newInsert);
saveConfiguration();
- fireInsertAdded(newInsert);
+ insertListenerSupport.fireInsertAdded(newInsert);
/* TODO - start insert */
}