diff --git a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java index 37e05073012..c9303ddd7dc 100644 --- a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java +++ b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/filters/SystemFilterPoolReferenceManager.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.rse.filters; + import java.util.Vector; import org.eclipse.core.resources.IFile; @@ -38,7 +39,6 @@ import org.eclipse.rse.internal.filters.SystemFilter; import org.eclipse.rse.internal.filters.SystemFilterPoolReference; import org.eclipse.rse.internal.references.SystemPersistableReferenceManager; - /** * This class manages a persistable list of objects each of which reference * a filter pool. This class builds on the parent class SystemPersistableReferenceManager, @@ -48,10 +48,9 @@ import org.eclipse.rse.internal.references.SystemPersistableReferenceManager; /** * @lastgen class SystemFilterPoolReferenceManagerImpl extends SystemPersistableReferenceManagerImpl implements SystemFilterPoolReferenceManager, SystemPersistableReferenceManager {} */ -public class SystemFilterPoolReferenceManager extends SystemPersistableReferenceManager implements ISystemFilterPoolReferenceManager -{ +public class SystemFilterPoolReferenceManager extends SystemPersistableReferenceManager implements ISystemFilterPoolReferenceManager { //private SystemFilterPoolManager[] poolMgrs = null; - private ISystemFilterPoolManagerProvider poolMgrProvider = null; + private ISystemFilterPoolManagerProvider poolMgrProvider = null; private ISystemFilterPoolManager defaultPoolMgr = null; private ISystemFilterPoolReferenceManagerProvider caller = null; private IRSEFilterNamingPolicy namingPolicy = null; @@ -65,365 +64,313 @@ public class SystemFilterPoolReferenceManager extends SystemPersistableReference private ISystemFilterPoolReference[] fpRefsArray = null; private static final ISystemFilterPoolReference[] emptyFilterPoolRefArray = new ISystemFilterPoolReference[0]; -/** + /** * Default constructor. Typically called by MOF factory methods. */ - public SystemFilterPoolReferenceManager() - { + public SystemFilterPoolReferenceManager() { super(); } + /** - * Create a SystemFilterPoolReferenceManager instance. - * @param caller Objects which instantiate this class should implement the - * SystemFilterPoolReferenceManagerProvider interface, and pass "this" for this parameter. - * Given any filter framework object, it is possible to retrieve the caller's - * object via the getProvider method call. - * @param relatedPoolManagers The managers that owns the master list of filter pools that - * this manager will contain references to. - * @param mgrFolder the folder that will hold the persisted file. This is used when - * the save policy is SAVE_POLICY_ONE_FILE_PER_MANAGER. For SAVE_POLICY_NONE, this - * is not used. If it is used, it is created if it does not already exist. - * @param name the name of the filter pool reference manager. This is used when - * the save policy is SAVE_POLICY_ONE_FILE_PER_MANAGER, to deduce the file name. - * @param savePolicy The save policy for the filter pool references list. One of the - * following from the {@link org.eclipse.rse.core.filters.ISystemFilterConstants SystemFilterConstants} - * interface: - * - * @param namingPolicy The names to use for file and folders when persisting to disk. Pass - * null to just use the defaults, or if using SAVE_POLICY_NONE. - */ - public static ISystemFilterPoolReferenceManager createSystemFilterPoolReferenceManager( - ISystemFilterPoolReferenceManagerProvider caller, - ISystemFilterPoolManagerProvider relatedPoolManagerProvider, - IFolder mgrFolder, - String name, - int savePolicy, - IRSEFilterNamingPolicy namingPolicy) - { - SystemFilterPoolReferenceManager mgr = null; - - if (mgrFolder != null) - SystemResourceHelpers.getResourceHelpers().ensureFolderExists(mgrFolder); - if (namingPolicy == null) - namingPolicy = SystemFilterNamingPolicy.getNamingPolicy(); - try - { - if (savePolicy != ISystemFilterSavePolicies.SAVE_POLICY_NONE) - mgr = (SystemFilterPoolReferenceManager)restore(caller, mgrFolder, name, namingPolicy); - } - catch (Exception exc) // real error trying to restore, versus simply not found. - { - // todo: something. Log the exception somewhere? - } - if (mgr == null) // not found or some serious error. - { - mgr = createManager(); - } - if (mgr != null) - { - mgr.initialize(caller, mgrFolder, name, savePolicy, namingPolicy, relatedPoolManagerProvider); - } - - return mgr; - } + * Create a SystemFilterPoolReferenceManager instance. + * @param caller Objects which instantiate this class should implement the + * SystemFilterPoolReferenceManagerProvider interface, and pass "this" for this parameter. + * Given any filter framework object, it is possible to retrieve the caller's + * object via the getProvider method call. + * @param relatedPoolManagers The managers that owns the master list of filter pools that + * this manager will contain references to. + * @param mgrFolder the folder that will hold the persisted file. This is used when + * the save policy is SAVE_POLICY_ONE_FILE_PER_MANAGER. For SAVE_POLICY_NONE, this + * is not used. If it is used, it is created if it does not already exist. + * @param name the name of the filter pool reference manager. This is used when + * the save policy is SAVE_POLICY_ONE_FILE_PER_MANAGER, to deduce the file name. + * @param savePolicy The save policy for the filter pool references list. One of the + * following from the {@link org.eclipse.rse.core.filters.ISystemFilterConstants SystemFilterConstants} + * interface: + * + * @param namingPolicy The names to use for file and folders when persisting to disk. Pass + * null to just use the defaults, or if using SAVE_POLICY_NONE. + */ + public static ISystemFilterPoolReferenceManager createSystemFilterPoolReferenceManager(ISystemFilterPoolReferenceManagerProvider caller, + ISystemFilterPoolManagerProvider relatedPoolManagerProvider, IFolder mgrFolder, String name, int savePolicy, IRSEFilterNamingPolicy namingPolicy) { + SystemFilterPoolReferenceManager mgr = null; - /* - * Private helper method. - * Uses MOF to create an instance of this class. - */ - protected static SystemFilterPoolReferenceManager createManager() - { - ISystemFilterPoolReferenceManager mgr = new SystemFilterPoolReferenceManager(); - // FIXME SystemFilterImpl.initMOF().createSystemFilterPoolReferenceManager(); - return (SystemFilterPoolReferenceManager)mgr; - } - + if (mgrFolder != null) SystemResourceHelpers.getResourceHelpers().ensureFolderExists(mgrFolder); + if (namingPolicy == null) namingPolicy = SystemFilterNamingPolicy.getNamingPolicy(); + try { + if (savePolicy != ISystemFilterSavePolicies.SAVE_POLICY_NONE) mgr = (SystemFilterPoolReferenceManager) restore(caller, mgrFolder, name, namingPolicy); + } catch (Exception exc) // real error trying to restore, versus simply not found. + { + // todo: something. Log the exception somewhere? + } + if (mgr == null) // not found or some serious error. + { + mgr = createManager(); + } + if (mgr != null) { + mgr.initialize(caller, mgrFolder, name, savePolicy, namingPolicy, relatedPoolManagerProvider); + } + return mgr; + } - /* - * Private helper method to initialize state - */ - protected void initialize(ISystemFilterPoolReferenceManagerProvider caller, - IFolder folder, - String name, - int savePolicy, - IRSEFilterNamingPolicy namingPolicy, - ISystemFilterPoolManagerProvider relatedPoolManagerProvider) - { - if (!initialized) - initialize(caller, folder, name, savePolicy, namingPolicy); // core data - //setSystemFilterPoolManagers(relatedPoolManagers); - setSystemFilterPoolManagerProvider(relatedPoolManagerProvider); - } + /* + * Private helper method. + * Uses MOF to create an instance of this class. + */ + protected static SystemFilterPoolReferenceManager createManager() { + ISystemFilterPoolReferenceManager mgr = new SystemFilterPoolReferenceManager(); + // FIXME SystemFilterImpl.initMOF().createSystemFilterPoolReferenceManager(); + return (SystemFilterPoolReferenceManager) mgr; + } - /* - * Private helper method to do core initialization. - * Might be called from either the static factory method or the static restore method. - */ - protected void initialize(ISystemFilterPoolReferenceManagerProvider caller, - IFolder folder, - String name, - int savePolicy, - IRSEFilterNamingPolicy namingPolicy) - { - this.mgrFolder = folder; - setProvider(caller); - setName(name); - this.savePolicy = savePolicy; - setNamingPolicy(namingPolicy); - initialized = true; - } - - private void invalidateFilterPoolReferencesCache() - { - fpRefsArray = null; - invalidateCache(); - } + /* + * Private helper method to initialize state + */ + protected void initialize(ISystemFilterPoolReferenceManagerProvider caller, IFolder folder, String name, int savePolicy, IRSEFilterNamingPolicy namingPolicy, + ISystemFilterPoolManagerProvider relatedPoolManagerProvider) { + if (!initialized) initialize(caller, folder, name, savePolicy, namingPolicy); // core data + //setSystemFilterPoolManagers(relatedPoolManagers); + setSystemFilterPoolManagerProvider(relatedPoolManagerProvider); + } - // ------------------------------------------------------------ - // Methods for setting and querying attributes - // ------------------------------------------------------------ - /** - * Set the associated master pool manager provider. Note the provider - * typically manages multiple pool managers and we manage references - * across those. - */ - public void setSystemFilterPoolManagerProvider(ISystemFilterPoolManagerProvider poolMgrProvider) - { - this.poolMgrProvider = poolMgrProvider; - } - /** - * Get the associated master pool manager provider. Note the provider - * typically manages multiple pool managers and we manage references - * across those. - */ - public ISystemFilterPoolManagerProvider getSystemFilterPoolManagerProvider() - { - return poolMgrProvider; - } - /* - * Set the managers of the master list of filter pools, from which - * objects in this list reference. - * - public void setSystemFilterPoolManagers(SystemFilterPoolManager[] mgrs) - { - this.poolMgrs = mgrs; - }*/ - - /** - * Get the managers of the master list of filter pools, from which - * objects in this list reference. - */ - public ISystemFilterPoolManager[] getSystemFilterPoolManagers() - { - //return poolMgrs; - return poolMgrProvider.getSystemFilterPoolManagers(); - } - /** - * Get the managers of the master list of filter pools, from which - * objects in this list reference, but which are not in the list of - * managers our pool manager supplier gives us. That is, these are - * references to filter pools outside the expected list. - */ - public ISystemFilterPoolManager[] getAdditionalSystemFilterPoolManagers() - { - ISystemFilterPoolManager[] poolMgrs = getSystemFilterPoolManagers(); - Vector v = new Vector(); - - ISystemFilterPoolReference[] fpRefs = getSystemFilterPoolReferences(); - for (int idx=0; idx 0) - { - additionalMgrs = new ISystemFilterPoolManager[v.size()]; - for (int idx=0; idx 0) { + additionalMgrs = new ISystemFilterPoolManager[v.size()]; + for (int idx = 0; idx < v.size(); idx++) + additionalMgrs[idx] = (ISystemFilterPoolManager) v.elementAt(idx); + } + return additionalMgrs; + } + + private boolean managerExists(ISystemFilterPoolManager[] mgrs, ISystemFilterPoolManager mgr) { + boolean match = false; + for (int idx = 0; !match && (idx < mgrs.length); idx++) + if (mgr == mgrs[idx]) match = true; + return match; + } + + /** + * Set the default manager of the master list of filter pools, from which + * objects in this list reference. + */ + public void setDefaultSystemFilterPoolManager(ISystemFilterPoolManager mgr) { + defaultPoolMgr = mgr; + } + + /** + * Get the default manager of the master list of filter pools, from which + * objects in this list reference. + */ + public ISystemFilterPoolManager getDefaultSystemFilterPoolManager() { + return defaultPoolMgr; + } + + /** + * Get the object which instantiated this instance of the filter pool reference manager. + * This is also available from any filter reference framework object. + */ + public ISystemFilterPoolReferenceManagerProvider getProvider() { + return caller; + } + + /** + * Set the object which instantiated this instance of the filter pool reference manager. + * This makes it available to retrieve from any filter reference framework object, + * via the ubiquitous getProvider interface method. + */ + public void setProvider(ISystemFilterPoolReferenceManagerProvider caller) { + this.caller = caller; + } + + /** + * Turn off callbacks to the provider until turned on again. + */ + public void setProviderEventNotification(boolean fireEvents) { + this.fireEvents = fireEvents; + } + + /** + * Set the naming policy used when saving data to disk. + * @see org.eclipse.rse.core.filters.IRSEFilterNamingPolicy + */ + public void setNamingPolicy(IRSEFilterNamingPolicy namingPolicy) { + this.namingPolicy = namingPolicy; + } + + /** + * Get the naming policy currently used when saving data to disk. + * @see org.eclipse.rse.core.filters.IRSEFilterNamingPolicy + */ + public IRSEFilterNamingPolicy getNamingPolicy() { + return namingPolicy; + } - /** - * Get the naming policy currently used when saving data to disk. - * @see org.eclipse.rse.core.filters.IRSEFilterNamingPolicy - */ - public IRSEFilterNamingPolicy getNamingPolicy() - { - return namingPolicy; - } - /** * This is to set transient data that is subsequently queryable. */ - public void setSystemFilterPoolReferenceManagerData(Object data) - { + public void setSystemFilterPoolReferenceManagerData(Object data) { this.mgrData = data; } - + /** * Return transient data set via setFilterPoolData. */ - public Object getSystemFilterPoolReferenceManagerData() - { + public Object getSystemFilterPoolReferenceManagerData() { return mgrData; - } + } - /** - * Set the name. This is an override of mof-generated method - * in order to potentially rename the disk file for a save - * policy of SAVE_POLICY_ONE_FILE_PER_MANAGER. - */ - public void setName(String name) - { - /* - * DWD Setting a name should schedule a save. Is this the same as a rename? - */ -// String oldName = getName(); - if (savePolicy == ISystemFilterSavePolicies.SAVE_POLICY_ONE_FILE_PER_MANAGER) - { - IFile file = getResourceHelpers().getFile(getFolder(), getSaveFileName()); - super.setName(name); - String newFileName = getSaveFileName(); - try { - getResourceHelpers().renameFile(file, newFileName); - } catch (Exception exc) - { - } - } - else - super.setName(name); - } - - // --------------------------------------------------- - // Methods that work on FilterPool referencing objects - // --------------------------------------------------- - /** - * Ask each referenced pool for its name, and update it. - * Called after the name of the pool or its manager changes. - */ - public void regenerateReferencedSystemFilterPoolNames() - { - ISystemFilterPoolReference[] fpRefs = getSystemFilterPoolReferences(); - for (int idx=0; idxCalls back to inform provider * @param array of filter pool reference objects to set the list to. - * @param deReference true to first de-reference all objects in the existing list. + * @param deReference true to first de-reference all objects in the existing list. */ - public void setSystemFilterPoolReferences(ISystemFilterPoolReference[] filterPoolReferences, - boolean deReference) - { - super.setReferencingObjects(filterPoolReferences, deReference); - invalidateFilterPoolReferencesCache(); + public void setSystemFilterPoolReferences(ISystemFilterPoolReference[] filterPoolReferences, boolean deReference) { + super.setReferencingObjects(filterPoolReferences, deReference); + invalidateFilterPoolReferencesCache(); // callback to provider so they can fire events in their GUI - if (fireEvents && (caller != null)) - caller.filterEventFilterPoolReferencesReset(); + if (fireEvents && (caller != null)) caller.filterEventFilterPoolReferencesReset(); quietSave(); - } + } - /** + /** * Create a filter pool reference. This creates a raw reference that must be added to the managed * lists by the caller. */ @@ -431,9 +378,9 @@ public class SystemFilterPoolReferenceManager extends SystemPersistableReference ISystemFilterPoolReference filterPoolReference = new SystemFilterPoolReference(filterPool); invalidateFilterPoolReferencesCache(); return filterPoolReference; - } + } - /** + /** * Create a filter pool reference. This creates an unresolved raw reference that * must be added to the managed lists by the caller. * That will be attempted to be resolved on first use. @@ -443,17 +390,16 @@ public class SystemFilterPoolReferenceManager extends SystemPersistableReference ISystemFilterPoolReference filterPoolReference = new SystemFilterPoolReference(filterPoolManager, filterPoolName); invalidateFilterPoolReferencesCache(); return filterPoolReference; - } + } - /** + /** * Add a filter pool referencing object to the list. * @return the new count of referencing objects */ - public int addSystemFilterPoolReference(ISystemFilterPoolReference filterPoolReference) - { + public int addSystemFilterPoolReference(ISystemFilterPoolReference filterPoolReference) { int count = addReferencingObject(filterPoolReference); filterPoolReference.setParentReferenceManager(this); // DWD - should be done in the addReferencingObject method - invalidateFilterPoolReferencesCache(); + invalidateFilterPoolReferencesCache(); quietSave(); return count; } @@ -461,122 +407,110 @@ public class SystemFilterPoolReferenceManager extends SystemPersistableReference /** * Reset the filter pool a reference points to. Called on a move-filter-pool operation */ - public void resetSystemFilterPoolReference(ISystemFilterPoolReference filterPoolReference, ISystemFilterPool newPool) - { + public void resetSystemFilterPoolReference(ISystemFilterPoolReference filterPoolReference, ISystemFilterPool newPool) { filterPoolReference.removeReference(); filterPoolReference.setReferencedObject(newPool); - if (fireEvents && (caller != null)) - caller.filterEventFilterPoolReferenceReset(filterPoolReference); + if (fireEvents && (caller != null)) caller.filterEventFilterPoolReferenceReset(filterPoolReference); quietSave(); // don't think we need to invalidate the cache } + /** * Remove a filter pool referencing object from the list. * @param filterPool Reference the reference to remove * @param deReference true if we want to dereference the referenced object (call removeReference on it) * @return the new count of referencing objects */ - public int removeSystemFilterPoolReference(ISystemFilterPoolReference filterPoolReference, - boolean deReference) - { + public int removeSystemFilterPoolReference(ISystemFilterPoolReference filterPoolReference, boolean deReference) { int count = 0; if (!deReference) - count = super.removeReferencingObject(filterPoolReference); - else - count = super.removeAndDeReferenceReferencingObject(filterPoolReference); + count = super.removeReferencingObject(filterPoolReference); + else + count = super.removeAndDeReferenceReferencingObject(filterPoolReference); filterPoolReference.setParentReferenceManager(null); // DWD should be done in remove - invalidateFilterPoolReferencesCache(); + invalidateFilterPoolReferencesCache(); // callback to provider so they can fire events in their GUI - if (fireEvents && (caller != null)) - caller.filterEventFilterPoolReferenceDeleted(filterPoolReference); + if (fireEvents && (caller != null)) caller.filterEventFilterPoolReferenceDeleted(filterPoolReference); quietSave(); return count; } + /** * Return count of referenced filter pools */ - public int getSystemFilterPoolReferenceCount() - { + public int getSystemFilterPoolReferenceCount() { return super.getReferencingObjectCount(); - } - - /** - * Return the zero-based position of a SystemFilterPoolReference object within this list - */ - public int getSystemFilterPoolReferencePosition(ISystemFilterPoolReference filterPoolRef) - { - return super.getReferencingObjectPosition(filterPoolRef); - } + } - /** - * Move a given filter pool reference to a given zero-based location - * Calls back to inform provider of the event - */ - public void moveSystemFilterPoolReference(ISystemFilterPoolReference filterPoolRef, int pos) - { - int oldPos = super.getReferencingObjectPosition(filterPoolRef); - super.moveReferencingObjectPosition(pos, filterPoolRef); - invalidateFilterPoolReferencesCache(); - // callback to provider so they can fire events in their GUI - if (!noSave) - quietSave(); - if (fireEvents && (caller != null) && !noEvents) - { - ISystemFilterPoolReference[] refs = new ISystemFilterPoolReference[1]; - refs[0] = filterPoolRef; - caller.filterEventFilterPoolReferencesRePositioned(refs, pos-oldPos); - } - } - /** - * Move existing filter pool references a given number of positions. - * If the delta is negative, they are all moved up by the given amount. If - * positive, they are all moved down by the given amount.

- *

- * Calls back to inform provider - * @param filterPoolRefs Array of SystemFilterPoolReferences to move. - * @param newPosition new zero-based position for the filter pool references. - */ - public void moveSystemFilterPoolReferences(ISystemFilterPoolReference[] filterPoolRefs, int delta) - { - int[] oldPositions = new int[filterPoolRefs.length]; - noEvents = noSave = true; - for (int idx=0; idx 0) // moving down, process backwards - for (int idx=filterPoolRefs.length-1; idx>=0; idx--) - moveSystemFilterPoolReference(filterPoolRefs[idx], oldPositions[idx]+delta); - else - for (int idx=0; idx + *

+ * Calls back to inform provider + * @param filterPoolRefs Array of SystemFilterPoolReferences to move. + * @param newPosition new zero-based position for the filter pool references. + */ + public void moveSystemFilterPoolReferences(ISystemFilterPoolReference[] filterPoolRefs, int delta) { + int[] oldPositions = new int[filterPoolRefs.length]; + noEvents = noSave = true; + for (int idx = 0; idx < filterPoolRefs.length; idx++) + oldPositions[idx] = getSystemFilterPoolReferencePosition(filterPoolRefs[idx]); + if (delta > 0) // moving down, process backwards + for (int idx = filterPoolRefs.length - 1; idx >= 0; idx--) + moveSystemFilterPoolReference(filterPoolRefs[idx], oldPositions[idx] + delta); + else + for (int idx = 0; idx < filterPoolRefs.length; idx++) + moveSystemFilterPoolReference(filterPoolRefs[idx], oldPositions[idx] + delta); + invalidateFilterPoolReferencesCache(); + noEvents = noSave = false; + quietSave(); + if (fireEvents && (caller != null)) caller.filterEventFilterPoolReferencesRePositioned(filterPoolRefs, delta); + } - // ---------------------------------------------- - // Methods that work on FilterPool master objects - // ---------------------------------------------- - /** - * Return array of filter pools currently referenced by this manager + // ---------------------------------------------- + // Methods that work on FilterPool master objects + // ---------------------------------------------- + /** + * Return array of filter pools currently referenced by this manager * Result will never be null, although it may be an array of length zero. - */ - public ISystemFilterPool[] getReferencedSystemFilterPools() - { - ISystemFilterPoolReference[] refs = getSystemFilterPoolReferences(); - ISystemFilterPool[] pools = new ISystemFilterPool[refs.length]; - for (int idx=0; idx Calls back to inform provider - */ - public void renameReferenceToSystemFilterPool(ISystemFilterPool pool) - { - ISystemFilterPoolReference poolRef = null; - IRSEBasePersistableReferencingObject[] refs = getReferencingObjects(); - for (int idx=0; (poolRef==null) && (idx Calls back to inform provider + */ + public void renameReferenceToSystemFilterPool(ISystemFilterPool pool) { + ISystemFilterPoolReference poolRef = null; + IRSEBasePersistableReferencingObject[] refs = getReferencingObjects(); + for (int idx = 0; (poolRef == null) && (idx < refs.length); idx++) + if (refs[idx].getReferencedObject() == pool) poolRef = (ISystemFilterPoolReference) refs[idx]; + + if (poolRef != null) { + String oldName = poolRef.getReferencedObjectName(); + poolRef.resetReferencedFilterPoolName(pool.getReferenceName()); + invalidateFilterPoolReferencesCache(); + quietSave(); + // callback to provider so they can fire events in their GUI + if (fireEvents && (caller != null)) caller.filterEventFilterPoolReferenceRenamed(poolRef, oldName); + } + } + /** * In one shot, set the filter pool references to new references to supplied filter pools. * @param array of filter pool objects to create references for - * @param deReference true to first de-reference all objects in the existing list. + * @param deReference true to first de-reference all objects in the existing list. */ - public void setSystemFilterPoolReferences(ISystemFilterPool[] filterPools, - boolean deReference) - { - if (deReference) - super.removeAndDeReferenceAllReferencingObjects(); + public void setSystemFilterPoolReferences(ISystemFilterPool[] filterPools, boolean deReference) { + if (deReference) + super.removeAndDeReferenceAllReferencingObjects(); else - removeAllReferencingObjects(); - - // add current - if (filterPools != null) - { - for (int idx=0; idx - * This method is called after restore and for each restored object in the list must: - *

    - *
  1. Do what is necessary to find the referenced object, and set the internal reference pointer. - *
  2. Call addReference(this) on that object so it can maintain it's in-memory list - * of all referencing objects. - *
  3. Set the important transient variables - *
- * @param relatedManagers the filter pool managers that hold filter pools we reference - * @param provider the host of this reference manager, so you can later call getProvider - * @return A Vector of SystemFilterPoolReferences that were not successfully resolved, or null if all - * were resolved. - */ - public Vector resolveReferencesAfterRestore(ISystemFilterPoolManagerProvider relatedPoolMgrProvider, - ISystemFilterPoolReferenceManagerProvider provider) - { - setSystemFilterPoolManagerProvider(relatedPoolMgrProvider); // sets poolMgrs = relatedManagers - setProvider(provider); - ISystemFilterPoolManager[] relatedManagers = getSystemFilterPoolManagers(); - if (relatedManagers != null) - { - Vector badRefs = new Vector(); - ISystemFilterPoolReference[] poolRefs = getSystemFilterPoolReferences(); - if (poolRefs != null) - { - for (int idx=0; idx - * @param mgrs The list of filter pool managers to scan for the given filter pool. - * @param mgrName The name of the manager to restrict the search to - * @param poolReferenceName The name of the filter pool as stored on disk. It may be qualified somehow - * to incorporate the manager name too. - */ - public static ISystemFilterPool getFilterPool(ISystemFilterPoolManager[] mgrs, String mgrName, String poolName) - { - ISystemFilterPoolManager mgr = getFilterPoolManager(mgrs, mgrName); - if (mgr == null) - return null; - return mgr.getSystemFilterPool(poolName); - } - /** - * Utility method to scan across all filter pool managers for a match on a give name. - *

- * @param mgrs The list of filter pool managers to scan for the given name - * @param mgrName The name of the manager to restrict the search to - */ - public static ISystemFilterPoolManager getFilterPoolManager(ISystemFilterPoolManager[] mgrs, String mgrName) - { - ISystemFilterPoolManager mgr = null; - for (int idx=0; (mgr==null)&&(idx + * This method is called after restore and for each restored object in the list must: + *

    + *
  1. Do what is necessary to find the referenced object, and set the internal reference pointer. + *
  2. Call addReference(this) on that object so it can maintain it's in-memory list + * of all referencing objects. + *
  3. Set the important transient variables + *
+ * @param relatedManagers the filter pool managers that hold filter pools we reference + * @param provider the host of this reference manager, so you can later call getProvider + * @return A Vector of SystemFilterPoolReferences that were not successfully resolved, or null if all + * were resolved. + */ + public Vector resolveReferencesAfterRestore(ISystemFilterPoolManagerProvider relatedPoolMgrProvider, ISystemFilterPoolReferenceManagerProvider provider) { + setSystemFilterPoolManagerProvider(relatedPoolMgrProvider); // sets poolMgrs = relatedManagers + setProvider(provider); + ISystemFilterPoolManager[] relatedManagers = getSystemFilterPoolManagers(); + if (relatedManagers != null) { + Vector badRefs = new Vector(); + ISystemFilterPoolReference[] poolRefs = getSystemFilterPoolReferences(); + if (poolRefs != null) { + for (int idx = 0; idx < poolRefs.length; idx++) { + String poolName = poolRefs[idx].getReferencedFilterPoolName(); + String mgrName = poolRefs[idx].getReferencedFilterPoolManagerName(); + ISystemFilterPool refdPool = getFilterPool(relatedManagers, mgrName, poolName); + if ((refdPool == null) && (getFilterPoolManager(relatedManagers, mgrName) == null)) { + //System.out.println("...looking for broken reference for "+mgrName+"."+poolName); + refdPool = relatedPoolMgrProvider.getSystemFilterPoolForBrokenReference(this, mgrName, poolName); + } - /** - * If saving all info in one file, this returns the fully qualified name of that file, - * given the unadorned manager name and the prefix (if any) to adorn with. - */ - protected static String getSaveFilePathAndName(IFolder mgrFolder, String name, IRSEFilterNamingPolicy namingPolicy) - { - return SystemFilter.addPathTerminator(getFolderPath(mgrFolder)) - + getSaveFileName(namingPolicy.getReferenceManagerSaveFileName(name)); - } - /** - * Derive and return the unqualified file name used to store this to disk. - * It is unqualified. - */ - protected static String getSaveFileName(String fileNameNoSuffix) - { - return fileNameNoSuffix + ISystemFilterConstants.SAVEFILE_SUFFIX; - } - /** - * non-static version. - */ - protected String getSaveFilePathAndName() - { - return SystemFilter.addPathTerminator(getFolderPath(mgrFolder)) - + getSaveFileName(); - } - /** - * non-static version. - */ - protected String getSaveFileName() - { - return getSaveFileName(namingPolicy.getReferenceManagerSaveFileName(getName())); - } - + if (refdPool != null) { + poolRefs[idx].setReferenceToFilterPool(refdPool); // calls refdPool.addReference(poolRef) + } else { - /** - * Return the folder that this manager is contained in. - */ - public IFolder getFolder() - { - return mgrFolder; - } + badRefs.addElement(poolRefs[idx]); + } + } + if (badRefs.size() == 0) + return null; + else { + for (int idx = 0; idx < badRefs.size(); idx++) { + ISystemFilterPoolReference badRef = (ISystemFilterPoolReference) badRefs.elementAt(idx); + //badRef.setReferenceBroken(true); + super.removeReferencingObject(badRef); + } + invalidateFilterPoolReferencesCache(); + quietSave(); + //System.out.println("End of resolveReferencesAfterRestore for provider " + getName()); + return badRefs; + } + } + } + return null; + } - /** - * Reset the folder that this manager is contained in. - */ - public void resetManagerFolder(IFolder newFolder) - { - mgrFolder = newFolder; - } + /** + * Utility method to scan across all filter pools in a given named filter pool manager, for a match + * on a given filter pool name. + *

+ * @param mgrs The list of filter pool managers to scan for the given filter pool. + * @param mgrName The name of the manager to restrict the search to + * @param poolReferenceName The name of the filter pool as stored on disk. It may be qualified somehow + * to incorporate the manager name too. + */ + public static ISystemFilterPool getFilterPool(ISystemFilterPoolManager[] mgrs, String mgrName, String poolName) { + ISystemFilterPoolManager mgr = getFilterPoolManager(mgrs, mgrName); + if (mgr == null) return null; + return mgr.getSystemFilterPool(poolName); + } - /** - * Return the path of the folder - */ - public String getFolderPath() - { - return getResourceHelpers().getFolderPath(mgrFolder); - } - /** - * Return the path of the given folder - */ - public static String getFolderPath(IFolder folder) - { - return SystemResourceHelpers.getResourceHelpers().getFolderPath(folder); - } + /** + * Utility method to scan across all filter pool managers for a match on a give name. + *

+ * @param mgrs The list of filter pool managers to scan for the given name + * @param mgrName The name of the manager to restrict the search to + */ + public static ISystemFilterPoolManager getFilterPoolManager(ISystemFilterPoolManager[] mgrs, String mgrName) { + ISystemFilterPoolManager mgr = null; + for (int idx = 0; (mgr == null) && (idx < mgrs.length); idx++) + if (mgrs[idx].getName().equals(mgrName)) mgr = mgrs[idx]; + return mgr; + } - /* - * To reduce typing... - */ - private SystemResourceHelpers getResourceHelpers() - { - return SystemResourceHelpers.getResourceHelpers(); - } + // ------------------ + // HELPER METHODS... + // ------------------ + /** + * If saving all info in one file, this returns the fully qualified name of that file, + * given the unadorned manager name and the prefix (if any) to adorn with. + */ + protected static String getSaveFilePathAndName(IFolder mgrFolder, String name, IRSEFilterNamingPolicy namingPolicy) { + return SystemFilter.addPathTerminator(getFolderPath(mgrFolder)) + getSaveFileName(namingPolicy.getReferenceManagerSaveFileName(name)); + } + /** + * Derive and return the unqualified file name used to store this to disk. + * It is unqualified. + */ + protected static String getSaveFileName(String fileNameNoSuffix) { + return fileNameNoSuffix + ISystemFilterConstants.SAVEFILE_SUFFIX; + } + /** + * non-static version. + */ + protected String getSaveFilePathAndName() { + return SystemFilter.addPathTerminator(getFolderPath(mgrFolder)) + getSaveFileName(); + } + /** + * non-static version. + */ + protected String getSaveFileName() { + return getSaveFileName(namingPolicy.getReferenceManagerSaveFileName(getName())); + } + /** + * Return the folder that this manager is contained in. + */ + public IFolder getFolder() { + return mgrFolder; + } - public String toString() - { - return getName(); - } + /** + * Reset the folder that this manager is contained in. + */ + public void resetManagerFolder(IFolder newFolder) { + mgrFolder = newFolder; + } + + /** + * Return the path of the folder + */ + public String getFolderPath() { + return getResourceHelpers().getFolderPath(mgrFolder); + } + + /** + * Return the path of the given folder + */ + public static String getFolderPath(IFolder folder) { + return SystemResourceHelpers.getResourceHelpers().getFolderPath(folder); + } + + /* + * To reduce typing... + */ + private SystemResourceHelpers getResourceHelpers() { + return SystemResourceHelpers.getResourceHelpers(); + } + + public String toString() { + return getName(); + } } \ No newline at end of file