diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java index e470332f670..185c962b9cc 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.rse.core.filters; + import java.util.ArrayList; import java.util.Iterator; import java.util.Vector; @@ -28,7 +29,6 @@ import org.eclipse.rse.core.references.IRSEBaseReferencingObject; import org.eclipse.rse.logging.Logger; import org.eclipse.rse.persistence.IRSEPersistenceManager; - // // @@ -91,25 +91,24 @@ import org.eclipse.rse.persistence.IRSEPersistenceManager; /** * @lastgen class SystemFilterPoolManagerImpl Impl implements SystemFilterPoolManager {} */ -public class SystemFilterPoolManager implements ISystemFilterPoolManager -{ +public class SystemFilterPoolManager implements ISystemFilterPoolManager { private ISystemFilterPool[] poolArray = null; // cache for performance private ISystemFilterPoolManagerProvider caller = null; - private Object poolMgrData; - private Vector poolNames; - private boolean initialized = false; + private Object poolMgrData; + private Vector poolNames; + private boolean initialized = false; - private boolean suspendCallbacks = false; - private boolean suspendSave = false; - private Logger logger = null; + private boolean suspendCallbacks = false; + private boolean suspendSave = false; + private Logger logger = null; private ISystemProfile _profile; - + // persistence protected boolean _isDirty = true; - private boolean _wasRestored = false; - + private boolean _wasRestored = false; + public static boolean debug = true; - + /** * The default value of the '{@link #getName() Name}' attribute. * @@ -120,7 +119,6 @@ public class SystemFilterPoolManager implements ISystemFilterPoolManager */ protected static final String NAME_EDEFAULT = null; - protected String name = NAME_EDEFAULT; /** * The default value of the '{@link #isSupportsNestedFilters() Supports Nested Filters}' attribute. @@ -197,237 +195,210 @@ public class SystemFilterPoolManager implements ISystemFilterPoolManager * @generated This field/method will be replaced during code generation. */ protected java.util.List pools = null; - - + /** * Constructor */ - protected SystemFilterPoolManager(ISystemProfile profile) - { + protected SystemFilterPoolManager(ISystemProfile profile) { super(); _profile = profile; } - - public ISystemProfile getSystemProfile() - { + + public ISystemProfile getSystemProfile() { return _profile; } - + /** - * Factory to create a filter pool manager. - * @param logger A logging object into which to log errors as they happen in the framework - * @param caller Objects which instantiate this class should implement the - * SystemFilterPoolManagerProvider 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 mgrFolder the folder that will be the manager folder. This is - * the parent of the filter pool folders the manager folder will hold, or the single - * xmi file for the save policy of one file per manager. This folder will be created - * if it does not already exist. - * @param name the name of the filter pool manager. Typically this is also the name - * of the given folder, but this is not required. For the save policy of one file - * per manager, the name of the file is derived from this. For other save policies, - * the name is not used. - * @param allowNestedFilters true if filters inside filter pools in this manager are - * to allow nested filters. This is the default, but can be overridden at the - * individual filter pool level. - * @param savePolicy The save policy for the filter pools and filters. One of the - * following constants from the - * {@link org.eclipse.rse.core.filters.ISystemFilterConstants SystemFilterConstants} interface: - *
- * Does the following: - *
+ * If a pool of this name already exists, null will be returned. + *
+ * Depending on the save policy, a new folder to hold the pool may be created. Its name will + * be derived from the pool name. + *
+ * If the operation is successful, the pool will be saved to disk. + *
+ * If this operation fails unexpectedly, an exception will be thrown. + *
+ * Calls back to inform provider of this event + */ + public ISystemFilterPool createSystemFilterPool(String poolName, boolean isDeletable) throws Exception { + // always trim the pool name, MOF does not handle trailing or preceding spaces + poolName = poolName.trim(); - /** - * Move the specified filter pool from this manager to another manager. - *
- * Does the following: - *
- * Does the following: - *
- * A filter's type is an arbitrary string that is not interpreted or used by the base framework. This - * is for use entirely by tools who wish to support multiple types of filters and be able to launch unique - * actions per type, say. - * - * @param parent The parent which is either a SystemFilterPool or a SystemFilter - * @param aliasName The name to give the new filter. Must be unique for this pool. - * @param filterStrings The list of String objects that represent the filter strings. - * @param type The type of this filter - */ - public ISystemFilter createSystemFilter(ISystemFilterContainer parent, - String aliasName, Vector filterStrings, String type) - throws Exception - { - boolean oldSuspendSave = suspendSave; - boolean oldSuspendCallbacks = suspendCallbacks; - suspendSave = true; - suspendCallbacks = true; - - ISystemFilter newFilter = createSystemFilter(parent, aliasName, filterStrings); - newFilter.setType(type); + ISystemRegistry registry = RSECorePlugin.getDefault().getSystemRegistry(); + ISystemFilterPool filterPool = registry.getSystemFilterPool(); + pool = filterPool.createSystemFilterPool(poolName, supportsNestedFilters(), isDeletable, ISystemFilterConstants.TRY_TO_RESTORE_NO); - suspendSave = oldSuspendSave; - suspendCallbacks = oldSuspendCallbacks; + if (pool != null) { + pool.setSystemFilterPoolManager(this); + pool.setStringsCaseSensitive(areStringsCaseSensitive()); + if (isSetSupportsDuplicateFilterStrings()) pool.setSupportsDuplicateFilterStrings(supportsDuplicateFilterStrings()); + // add to model + java.util.List pools = getPools(); + pools.add(pool); + //System.out.println("Inside createSFPool for mgr "+getName()+". Pool "+name+" added"); + invalidatePoolCache(); + // save to disk... + commit(pool); + // if caller provider, callback to inform them of this event + if ((caller != null) && !suspendCallbacks) caller.filterEventFilterPoolCreated(pool); + } + return pool; + } - if (!suspendSave) - { - ISystemFilterPool parentPool = null; - if (parent instanceof ISystemFilterPool) - parentPool = (ISystemFilterPool)parent; - else - parentPool = ((ISystemFilter)parent).getParentFilterPool(); - commit(parentPool); - } - // if caller provider, callback to inform them of this event - if ((caller != null) && !suspendCallbacks) - caller.filterEventFilterCreated(newFilter); - return newFilter; - } - /** - * Creates a new system filter that is typed and promptable - * Same as {@link #createSystemFilter(ISystemFilterContainer, String ,Vector, String)} but - * takes a boolean indicating if it is promptable. - *
- * A promptable filter is one in which the user is prompted for information at expand time. - * There is no base filter framework support for this, but tools can query this attribute and - * do their own thing at expand time. - * - * @param parent The parent which is either a SystemFilterPool or a SystemFilter - * @param aliasName The name to give the new filter. Must be unique for this pool. - * @param filterStrings The list of String objects that represent the filter strings. - * @param type The type of this filter - * @param promptable Pass true if this is a promptable filter - */ - public ISystemFilter createSystemFilter(ISystemFilterContainer parent, - String aliasName, Vector filterStrings, String type, boolean promptable) - throws Exception - { - boolean oldSuspendSave = suspendSave; - boolean oldSuspendCallbacks = suspendCallbacks; - suspendSave = true; - suspendCallbacks = true; - - ISystemFilter newFilter = createSystemFilter(parent, aliasName, filterStrings, type); - newFilter.setPromptable(promptable); + /** + * Delete a given filter pool. Dependending on the save policy, the + * appropriate file or folder on disk will also be deleted. + *
+ * Does the following: + *
- * Does the following: - *
- * Does the following: - *
- * A filter's type is an arbitrary string that is not interpreted or used by the base framework. This - * is for use entirely by tools who wish to support multiple types of filters and be able to launch unique - * actions per type, say. - * @param parent The parent which is either a SystemFilterPool or a SystemFilter - * @param type The type of this filter - */ - public void setSystemFilterType(ISystemFilter filter, String newType) - throws Exception - { - filter.setType(newType); - commit(filter.getParentFilterPool()); - } + /** + * Pre-test if we are going to run into any trouble renaming any of the files or folders + * used to persist a filter pool. + * @return true if everything seems ok, false if a file/folder is in use. + */ + public boolean preTestRenameFilterPool(ISystemFilterPool pool) throws Exception { + boolean ok = true; + /* + * DWD this looks like it needs to be modified so that it queries the persistence + * manager to see if the pool can be renamed. The provider is in charge of determining + * pool names in the persistent form. The Manager will have to construct a DOM + * object for this pool and query the appropriate provider. + */ + /* FIXME + if ( (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILEANDFOLDER_PER_POOL) || + (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILE_PER_FILTER) ) + { + String expectedFolderName = derivePoolFolderName(pool.getName()); + boolean ourFolderName = expectedFolderName.equals(pool.getFolder().getName()); + // we must rename the old file... + String poolFileName = SystemFilterPoolImpl.getSaveFileName(getMOFHelpers(),pool); + IFile poolFile = getResourceHelpers().getFile(pool.getFolder(),poolFileName); + IFolder poolFolder = pool.getFolder(); + + // first, pre-test for file-in-use error: + boolean inUse = poolFile.exists() && SystemResourceHelpers.testIfResourceInUse(poolFile); + if (inUse) + { + SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_FILE_INUSE); + msg.makeSubstitution(poolFile.getFullPath()); + throw new SystemMessageException(msg); + } + // next, pre-test for folder-in-use error: + if (ourFolderName) + { + inUse = poolFolder.exists() && SystemResourceHelpers.testIfResourceInUse(poolFolder); + if (inUse) + { + SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_FOLDER_INUSE); + msg.makeSubstitution(poolFolder.getFullPath()); + throw new SystemMessageException(msg); + } + } + } + else if (savePolicy == SystemFilterConstants.SAVE_POLICY_ONE_FILE_PER_POOL_SAME_FOLDER) + { + String poolFileName = SystemFilterPoolImpl.getSaveFileName(getMOFHelpers(),pool); + IFile poolFile = getResourceHelpers().getFile(pool.getFolder(),poolFileName); + // first, pre-test for file-in-use error: + boolean inUse = poolFile.exists() && SystemResourceHelpers.testIfResourceInUse(poolFile); + if (inUse) + { + SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_FILE_INUSE); + msg.makeSubstitution(poolFile.getFullPath()); + throw new SystemMessageException(msg); + } + } + */ + return ok; + } - /** - * Copy a system filter to a pool in this or another filter manager. - */ - public ISystemFilter copySystemFilter(ISystemFilterPool targetPool, ISystemFilter oldFilter, String newName) - throws Exception - { - ISystemFilterPoolManager targetMgr = targetPool.getSystemFilterPoolManager(); - ISystemFilterPool oldPool = oldFilter.getParentFilterPool(); + /** + * Rename a given filter pool. Dependending on the save policy, the + * appropriate file or folder on disk will also be renamed. + *
+ * Does the following: + *
- * Does the following: - *
- * While the framework has all the code necessary to arrange filters and save/restore - * that arrangement, you may choose to use preferences instead of this support. - * In this case, call this method and pass in the saved and sorted filter name list. - *
- * Called by someone after restore. - */ - public void orderSystemFilters(ISystemFilterPool pool, String[] names) throws Exception - { - pool.orderSystemFilters(names); - commit(pool); - } - - // ------------------------------- - // SYSTEM FILTER STRING METHODS... - // ------------------------------- - /** - * Append a new filter string to the given filter's list - *
- * Does the following: - *
- * Does the following: - *
- * Does the following: - *
- * Does the following: - *
- * Does the following: - *
- * Does the following: - *
+ * Does the following: + *
Calls back to inform provider of this event (filterEventFilterCreated) + * @param parent The parent which is either a SystemFilterPool or a SystemFilter + * @param aliasName The name to give the new filter. Must be unique for this pool. + * @param filterStrings The list of String objects that represent the filter strings. + */ + public ISystemFilter createSystemFilter(ISystemFilterContainer parent, String aliasName, Vector filterStrings) throws Exception { + ISystemFilter newFilter = null; + ISystemFilterPool parentPool = null; + if (parent instanceof ISystemFilterPool) + parentPool = (ISystemFilterPool) parent; + else + parentPool = ((ISystemFilter) parent).getParentFilterPool(); + newFilter = parent.createSystemFilter(aliasName, filterStrings); + if (!suspendSave) commit(parentPool); + // if caller provider, callback to inform them of this event + if ((caller != null) && !suspendCallbacks) caller.filterEventFilterCreated(newFilter); + return newFilter; + } - /** - * Move existing filter strings a given number of positions in the same filter - * 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.
- *
- * Does the following: - *
+ * A promptable filter is one in which the user is prompted for information at expand time. + * There is no base filter framework support for this, but tools can query this attribute and + * do their own thing at expand time. + * + * @param parent The parent which is either a SystemFilterPool or a SystemFilter + * @param aliasName The name to give the new filter. Must be unique for this pool. + * @param filterStrings The list of String objects that represent the filter strings. + * @param type The type of this filter + * @param promptable Pass true if this is a promptable filter + */ + public ISystemFilter createSystemFilter(ISystemFilterContainer parent, String aliasName, Vector filterStrings, String type, boolean promptable) throws Exception { + boolean oldSuspendSave = suspendSave; + boolean oldSuspendCallbacks = suspendCallbacks; + suspendSave = true; + suspendCallbacks = true; - - - /** - * Restore filter pools when all are stored in one file - * @param logger The logging object to log errors to - * @param mgrFolder The folder containing the file to restore from. - * @param name The name of the manager, from which the file name is derived. - * @param namingPolicy Naming prefix information for persisted data file names. - */ - protected static ISystemFilterPoolManager restoreFromOneFile(Logger logger, IFolder mgrFolder, String name, IRSEFilterNamingPolicy namingPolicy) - throws Exception - { - /* FIXME - String fileName = getRootSaveFileName(namingPolicy, name); - - java.util.List ext = getMOFHelpers(logger).restore(mgrFolder,fileName); - - SystemFilterPoolManager mgr = null; + ISystemFilter newFilter = createSystemFilter(parent, aliasName, filterStrings, type); + newFilter.setPromptable(promptable); - // should be exactly one system filter pool manager... - Iterator iList = ext.iterator(); - mgr = (SystemFilterPoolManager)iList.next(); - return mgr; - */ - return null; - } + suspendSave = oldSuspendSave; + suspendCallbacks = oldSuspendCallbacks; + if (!suspendSave) { + ISystemFilterPool parentPool = null; + if (parent instanceof ISystemFilterPool) + parentPool = (ISystemFilterPool) parent; + else + parentPool = ((ISystemFilter) parent).getParentFilterPool(); + commit(parentPool); + } + // if caller provider, callback to inform them of this event + if ((caller != null) && !suspendCallbacks) caller.filterEventFilterCreated(newFilter); + return newFilter; + } + /** + * Delete an existing system filter. + * Does the following: + *
+ * Does the following: + *
+ * Does the following: + *
+ * A filter's type is an arbitrary string that is not interpreted or used by the base framework. This + * is for use entirely by tools who wish to support multiple types of filters and be able to launch unique + * actions per type, say. + * @param parent The parent which is either a SystemFilterPool or a SystemFilter + * @param type The type of this filter + */ + public void setSystemFilterType(ISystemFilter filter, String newType) throws Exception { + filter.setType(newType); + commit(filter.getParentFilterPool()); + } + + /** + * Copy a system filter to a pool in this or another filter manager. + */ + public ISystemFilter copySystemFilter(ISystemFilterPool targetPool, ISystemFilter oldFilter, String newName) throws Exception { + ISystemFilterPoolManager targetMgr = targetPool.getSystemFilterPoolManager(); + ISystemFilterPool oldPool = oldFilter.getParentFilterPool(); + + targetMgr.suspendCallbacks(true); + + ISystemFilter newFilter = oldPool.copySystemFilter(targetPool, oldFilter, newName); // creates it in memory + commit(targetPool); // save updated pool to disk + + targetMgr.suspendCallbacks(false); + + targetMgr.getProvider().filterEventFilterCreated(newFilter); + return newFilter; + } + + /** + * Move a system filter to a pool in this or another filter manager. + * Does this by first copying the filter, and only if successful, deleting the old copy. + */ + public ISystemFilter moveSystemFilter(ISystemFilterPool targetPool, ISystemFilter oldFilter, String newName) throws Exception { + ISystemFilter newFilter = copySystemFilter(targetPool, oldFilter, newName); + if (newFilter != null) { + deleteSystemFilter(oldFilter); + } + return newFilter; + } + + /** + * Return the zero-based position of a SystemFilter object within its container + */ + public int getSystemFilterPosition(ISystemFilter filter) { + ISystemFilterContainer container = filter.getParentFilterContainer(); + int position = -1; + boolean match = false; + ISystemFilter[] filters = container.getSystemFilters(); + + for (int idx = 0; !match && (idx < filters.length); idx++) { + if (filters[idx].getName().equals(filter.getName())) { + match = true; + position = idx; + } + } + return position; + } + + /** + * Move existing filters a given number of positions in the same container. + * 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.
+ *
+ * Does the following: + *
+ * While the framework has all the code necessary to arrange filters and save/restore + * that arrangement, you may choose to use preferences instead of this support. + * In this case, call this method and pass in the saved and sorted filter name list. + *
+ * Called by someone after restore. + */ + public void orderSystemFilters(ISystemFilterPool pool, String[] names) throws Exception { + pool.orderSystemFilters(names); + commit(pool); + } + + // ------------------------------- + // SYSTEM FILTER STRING METHODS... + // ------------------------------- + /** + * Append a new filter string to the given filter's list + *
+ * Does the following: + *
+ * Does the following: + *
+ * Does the following: + *
+ * Does the following: + *
+ * Does the following: + *
+ * Does the following: + *
+ *
+ * Does the following: + *