diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java index 36b2303e636..b32103c3898 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/RSEUIPlugin.java @@ -1113,8 +1113,7 @@ public class RSEUIPlugin extends SystemBasePlugin implements ISystemMessageProvi } /** - * Returns the persistence manager used for persisting RSE profiles - * @return + * @return the persistence manager used for persisting RSE profiles */ public IRSEPersistenceManager getPersistenceManager() { diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/filters/dialogs/SystemNewFilterWizard.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/filters/dialogs/SystemNewFilterWizard.java index c76acd45991..4d03e98ca87 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/filters/dialogs/SystemNewFilterWizard.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/filters/dialogs/SystemNewFilterWizard.java @@ -460,114 +460,85 @@ public class SystemNewFilterWizard * * @return whether the wizard finished successfully */ - public boolean performFinish() - { - //System.out.println("inside performFinish(): mainPage.performFinish() = " + mainPage.performFinish()); - boolean ok = false; - newFilter = null; + public boolean performFinish() { + boolean ok = false; + newFilter = null; setOutputObject(null); - if (!mainPage.performFinish()) - setPageError(mainPage); - else if (!namePage.performFinish()) - setPageError(namePage); - else - { - Vector filterStrings = mainPage.getFilterStrings(); - String filterName = null; - if (showNamePrompt) - { - filterName = namePage.getFilterName(); - ISystemFilterContainer filterParent = null; - if ((poolsToSelectFrom!=null) || (poolWrapperInformation != null)) - { - filterParent = namePage.getParentSystemFilterPool(); - if (namePage.getUniqueToThisConnection()) - { - // this means the user selected to create this filter in the - // filter pool that is unique to this connection. So now we - // must find, or create, that filter pool: + if (!mainPage.performFinish()) { + setPageError(mainPage); + } else if (!namePage.performFinish()) { + setPageError(namePage); + } else { + Vector filterStrings = mainPage.getFilterStrings(); + String filterName = null; + if (showNamePrompt) { + filterName = namePage.getFilterName(); + // Get the filter parent, i.e. the filter pool for this new filter + ISystemFilterContainer filterParent = null; + if ((poolsToSelectFrom != null) || (poolWrapperInformation != null)) { + filterParent = namePage.getParentSystemFilterPool(); + if (namePage.getUniqueToThisConnection()) { + /* + * this means the user selected to create this filter in the filter pool that is unique to this connection. So now we + * must find, or create, that filter pool. + */ filterParent = provider.getUniqueOwningSystemFilterPool(true); // true -> create if not found - } - else + } else filterParent = namePage.getParentSystemFilterPool(); + } else + filterParent = getFilterContainer(); + // Create the filter and possibly a filter pool reference. + String type = mainPage.getType(); + try { + newFilter = createNewFilter(getShell(), filterParent, filterName, filterStrings, type); + if (newFilter == null) return false; + /* + * We allow users to select a profile to create their filter in. From this we + * select the default filter pool for the particular subsystem in that profile. + * It is possible for the user to pick a profile that this subsystem does not yet reference. + * To solve this we need to add a reference for them. This is only a possibility when called + * from a subsystem's New Filter action, versus that action on a directly on a filter pool. + */ + if ((provider != null) && (filterParent instanceof ISystemFilterPool)) { + ISystemFilterPool parentPool = (ISystemFilterPool) filterParent; + if (provider.getSystemFilterPoolReferenceManager().getReferenceToSystemFilterPool(parentPool) == null) { + provider.getSystemFilterPoolReferenceManager().addReferenceToSystemFilterPool(parentPool); + } + } + } catch (Exception exc) { + SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_EXCEPTION_OCCURRED); + msg.makeSubstitution(exc); + SystemMessageDialog msgDlg = new SystemMessageDialog(getShell(), msg); + msgDlg.openWithDetails(); + return false; } - else - filterParent = getFilterContainer(); - - String type = mainPage.getType(); // query just in case it is changable by user - try - { - newFilter = createNewFilter(getShell(), filterParent, filterName, filterStrings, type); - if (newFilter == null) - return false; - // Because we allow new users to select a profile to create their filter in, from - // which we choose the profile's default filter pool, it is possible the user - // will choose a filter pool that this subsystem does not yet reference. To solve - // this we need to add a reference for them. This is only a possibility when called - // from the subsystem New Filter action, versus from a filter pool say. - if ((provider != null) && (filterParent instanceof ISystemFilterPool)) - { - ISystemFilterPool parentPool = (ISystemFilterPool)filterParent; - if (provider.getSystemFilterPoolReferenceManager().getReferenceToSystemFilterPool(parentPool) == null) - { - provider.getSystemFilterPoolReferenceManager().addReferenceToSystemFilterPool(parentPool); - } - } - - /* Hmm, after much thought I have decided to leave this up to the - * caller. They can do this themselves by overriding createNewFilter in - * their own wizard. - if (!showFilterStrings && (newFilter!=null)) - { - newFilter.setNonChangable(true); - newFilter.setStringsNonChangable(true); - } - */ - } catch (Exception exc) - { - SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_EXCEPTION_OCCURRED); - msg.makeSubstitution(exc); - SystemMessageDialog msgDlg = new SystemMessageDialog(getShell(), msg); - msgDlg.openWithDetails(); - return false; - } - setOutputObject(newFilter); - // special handling to expand the currently selected parent node and reveal the new filter - if ((newFilter != null) && (getInputObject()!=null)) - { - Object selectedObject = getInputObject(); - if ((selectedObject instanceof ISystemFilterPoolReference) || - (selectedObject instanceof ISystemFilterPoolReferenceManagerProvider)) - { - ISystemFilterPoolReferenceManagerProvider provider = null; - if (selectedObject instanceof ISystemFilterPoolReference) - { - ISystemFilterPoolReferenceManager sfprm = ((ISystemFilterPoolReference)selectedObject).getFilterPoolReferenceManager(); - if (sfprm != null) - provider = sfprm.getProvider(); - } - else - provider = (ISystemFilterPoolReferenceManagerProvider)selectedObject; - if (provider != null) - provider.filterEventFilterCreated(selectedObject, newFilter); - } - else if (selectedObject instanceof ISystemFilterReference) - { - ISystemFilterReference ref = (ISystemFilterReference)selectedObject; - ISystemFilterPoolReferenceManagerProvider provider = ref.getProvider(); - provider.filterEventFilterCreated(selectedObject, newFilter); - } - } - ok = (newFilter != null); - } // end if showNamePrompt - else - { - ok = true; - setOutputObject(filterStrings); - } - return ok; - } - return false; + setOutputObject(newFilter); + // special handling to expand the currently selected parent node and reveal the new filter + if ((newFilter != null) && (getInputObject() != null)) { + Object selectedObject = getInputObject(); + if ((selectedObject instanceof ISystemFilterPoolReference) || (selectedObject instanceof ISystemFilterPoolReferenceManagerProvider)) { + ISystemFilterPoolReferenceManagerProvider provider = null; + if (selectedObject instanceof ISystemFilterPoolReference) { + ISystemFilterPoolReferenceManager sfprm = ((ISystemFilterPoolReference) selectedObject).getFilterPoolReferenceManager(); + if (sfprm != null) provider = sfprm.getProvider(); + } else + provider = (ISystemFilterPoolReferenceManagerProvider) selectedObject; + if (provider != null) provider.filterEventFilterCreated(selectedObject, newFilter); + } else if (selectedObject instanceof ISystemFilterReference) { + ISystemFilterReference ref = (ISystemFilterReference) selectedObject; + ISystemFilterPoolReferenceManagerProvider provider = ref.getProvider(); + provider.filterEventFilterCreated(selectedObject, newFilter); + } + } + ok = (newFilter != null); + } // end if showNamePrompt + else { + ok = true; + setOutputObject(filterStrings); + } + return ok; + } + return false; } /** @@ -642,25 +613,22 @@ public class SystemNewFilterWizard * Extendable point for child classes. * Override to create unique SystemFilter object. * By default calls createSystemFilter in subsystem factory. + * @param shell the shell that hosts this wizard. + * @param filterParent the parent of this filter - usually a filter pool + * @param aliasName the name of the filter itself + * @param filterStrings a Vector of string that contain the specification of this filter + * @param type the type of the filter used when interpreting the filter, usually supplied by a subsystem + * @return the ISystemFilter that was created + * @throws Exception if an error occurs */ - public ISystemFilter createNewFilter(Shell shell, ISystemFilterContainer filterParent, String aliasName, Vector filterStrings, String type) - throws Exception - { + public ISystemFilter createNewFilter(Shell shell, ISystemFilterContainer filterParent, String aliasName, Vector filterStrings, String type) throws Exception { ISystemFilter newFilter = null; ISystemFilterPoolManager fpMgr = filterParent.getSystemFilterPoolManager(); - //try { - // create filter - if (type == null) - newFilter = fpMgr.createSystemFilter(filterParent,aliasName,filterStrings); - else - newFilter = fpMgr.createSystemFilter(filterParent,aliasName,filterStrings,type); - //} catch (Exception exc) - //{ - //RSEUIPlugin.logError("Exception in createNewFilter in SystemFilterAbstractNewFilterWizard. ",); - //System.out.println("Exception in createNewFilter in SystemFilterAbstractNewFilterWizard: "+exc.getMessage()); - //exc.printStackTrace(); - //} - return newFilter; + if (type == null) + newFilter = fpMgr.createSystemFilter(filterParent, aliasName, filterStrings); + else + newFilter = fpMgr.createSystemFilter(filterParent, aliasName, filterStrings, type); + return newFilter; } // ----------------------- diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java index 7061392455a..6a0132d5e12 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/ui/view/SystemViewFilterPoolReferenceAdapter.java @@ -200,10 +200,16 @@ public class SystemViewFilterPoolReferenceAdapter /** * Return true if this object has children */ - public boolean hasChildren(Object element) - { + public boolean hasChildren(Object element) { + int count = 0; ISystemFilterPoolReference fpRef = getFilterPoolReference(element); - return (fpRef.getReferencedFilterPool().getSystemFilterCount() > 0); + if (fpRef != null) { + ISystemFilterPool filterPool = fpRef.getReferencedFilterPool(); + if (filterPool != null) { + count = filterPool.getSystemFilterCount(); + } + } + return count > 0; } // Property sheet descriptors defining all the properties we expose in the Property Sheet diff --git a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPool.java b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPool.java index f12df732594..d9926c33e78 100644 --- a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPool.java +++ b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPool.java @@ -77,19 +77,13 @@ public class SystemFilterPool extends SystemPersistableReferencedObject private int savePolicy; private IRSEFilterNamingPolicy namingPolicy = null; private ISystemFilterPoolManager mgr; - //private Vector filters = new Vector(); private SystemFilterContainerCommonMethods helpers = null; private Object filterPoolData = null; private boolean initialized = false; - //private boolean isSharable = false; protected boolean specialCaseNoDataRestored = false; private boolean debug = false; protected static final String DELIMITER = SystemFilterPoolReference.DELIMITER; - // persistence -// protected boolean _isDirty = true; FIXME -// protected boolean _wasRestored = false; FIXME - /** * @generated This field/method will be replaced during code generation. */ @@ -473,6 +467,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void setSupportsDuplicateFilterStringsGen(boolean newSupportsDuplicateFilterStrings) { supportsDuplicateFilterStrings = newSupportsDuplicateFilterStrings; + setDirty(true); } /** @@ -486,6 +481,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject if (filters != null) for (int idx=0; idx @@ -496,6 +492,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject { stringsCaseSensitive = newStringsCaseSensitive; stringsCaseSensitiveESet = true; + setDirty(true); } /** @@ -599,6 +596,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void setDeletable(boolean newDeletable) { deletable = newDeletable; + setDirty(true); } /** @@ -807,7 +805,9 @@ public class SystemFilterPool extends SystemPersistableReferencedObject */ public boolean addSystemFilter(ISystemFilter filter) { - return helpers.addSystemFilter(internalGetFilters(),filter); + boolean result = helpers.addSystemFilter(internalGetFilters(),filter); + if (result) setDirty(true); + return result; } /** * Removes a given filter from the list. @@ -816,6 +816,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void deleteSystemFilter(ISystemFilter filter) { helpers.deleteSystemFilter(internalGetFilters(),filter); + setDirty(true); } /** @@ -825,6 +826,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void renameSystemFilter(ISystemFilter filter, String newName) { helpers.renameSystemFilter(internalGetFilters(),filter, newName); + setDirty(true); } /** @@ -836,6 +838,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void updateSystemFilter(ISystemFilter filter, String newName, String[] newStrings) { helpers.updateSystemFilter(internalGetFilters(), filter, newName, newStrings); + setDirty(true); } /** @@ -845,7 +848,9 @@ public class SystemFilterPool extends SystemPersistableReferencedObject */ public ISystemFilter cloneSystemFilter(ISystemFilter filter, String aliasName) { - return helpers.cloneSystemFilter(internalGetFilters(), filter, aliasName); + ISystemFilter result = helpers.cloneSystemFilter(internalGetFilters(), filter, aliasName); + setDirty(true); + return result; } /** @@ -862,6 +867,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void moveSystemFilter(int pos, ISystemFilter filter) { helpers.moveSystemFilter(internalGetFilters(),pos,filter); + setDirty(true); } /** @@ -1140,6 +1146,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void setType(String newType) { type = newType; + setDirty(true); } /** @@ -1157,7 +1164,8 @@ public class SystemFilterPool extends SystemPersistableReferencedObject { stringsCaseSensitive = STRINGS_CASE_SENSITIVE_EDEFAULT; stringsCaseSensitiveESet = false; - } + setDirty(true); + } /** * @generated This field/method will be replaced during code generation. @@ -1204,6 +1212,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject public void setRelease(int newRelease) { release = newRelease; + setDirty(true); } /** @@ -1236,6 +1245,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject { singleFilterStringOnly = newSingleFilterStringOnly; singleFilterStringOnlyESet = true; + setDirty(true); } /** @@ -1247,6 +1257,7 @@ public class SystemFilterPool extends SystemPersistableReferencedObject { singleFilterStringOnly = SINGLE_FILTER_STRING_ONLY_EDEFAULT; singleFilterStringOnlyESet = false; + setDirty(true); } /** diff --git a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java index b5c7f7d3c1f..ef24c2d0b5d 100644 --- a/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java +++ b/rse/plugins/org.eclipse.rse.ui/filters/org/eclipse/rse/internal/filters/SystemFilterPoolReference.java @@ -157,7 +157,11 @@ public class SystemFilterPoolReference extends SystemPersistableReferencingObjec if (filterPool == null) { String filterPoolName = getReferencedFilterPoolName(); filterPool = filterPoolManager.getSystemFilterPool(filterPoolName); - setReferenceToFilterPool(filterPool); + if (filterPool != null) { + setReferenceToFilterPool(filterPool); + } else { + this.setReferenceBroken(true); + } } return filterPool; } diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java index d189d464909..7caa3c56d09 100644 --- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java +++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java @@ -655,7 +655,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable public boolean commit() { - return RSEUIPlugin.getThePersistenceManager().commit(this.getSystemProfile()); + return RSEUIPlugin.getThePersistenceManager().commit(this); } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/PropertyFileProvider.java b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/PropertyFileProvider.java index d204468559b..34c513d1d13 100644 --- a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/PropertyFileProvider.java +++ b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/PropertyFileProvider.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; import java.util.Vector; import java.util.regex.Pattern; @@ -111,9 +112,9 @@ public class PropertyFileProvider implements IRSEPersistenceProvider { * @see org.eclipse.rse.persistence.IRSEPersistenceProvider#saveRSEDOM(org.eclipse.rse.persistence.dom.RSEDOM, org.eclipse.core.runtime.IProgressMonitor) */ public boolean saveRSEDOM(RSEDOM dom, IProgressMonitor monitor) { - String profileName = dom.getName(); IFolder providerFolder = getProviderFolder(); - //System.out.println("saving profile " + profileName + " to " + providerFolder.getFullPath().toString() + "..."); // DWD debugging +// String profileName = dom.getName(); +// System.out.println("saving profile " + profileName + " to " + providerFolder.getFullPath().toString() + "..."); try { int n = countNodes(dom); if (monitor != null) monitor.beginTask("Saving DOM", n); @@ -441,7 +442,7 @@ public class PropertyFileProvider implements IRSEPersistenceProvider { RSEDOM dom = null; IFolder profileFolder = getProfileFolder(profileName); if (profileFolder.exists()) { - //System.out.println("loading from " + profileFolder.getFullPath().toString() + "..."); // DWD debugging + //System.out.println("loading from " + profileFolder.getFullPath().toString() + "..."); int n = countPropertiesFiles(profileFolder); if (monitor != null) monitor.beginTask("Loading DOM", n); dom = (RSEDOM) loadNode(null, profileFolder, monitor); @@ -547,11 +548,11 @@ public class PropertyFileProvider implements IRSEPersistenceProvider { RSEDOMNode node = (parent == null) ? new RSEDOM(nodeName) : new RSEDOMNode(parent, nodeType, nodeName); node.setRestoring(true); Set keys = properties.keySet(); - int nReferences = 0; - int nChildren = 0; Map attributes = new HashMap(); Map attributeTypes = new HashMap(); Map childPropertiesMap = new HashMap(); + Set childNames = new TreeSet(); // child names are 5 digit strings, a tree set is used to maintain ordering + Set referenceNames = new TreeSet(); // ditto for reference names for (Iterator z = keys.iterator(); z.hasNext();) { String key = (String) z.next(); String[] words = split(key, 2); @@ -563,16 +564,15 @@ public class PropertyFileProvider implements IRSEPersistenceProvider { String type = properties.getProperty(key); attributeTypes.put(words[1], type); } else if (metatype.equals(MT_REFERENCE)) { - int n = Integer.parseInt(words[1]) + 1; - if (nReferences < n) nReferences = n; + String referenceName = words[1]; + referenceNames.add(referenceName); } else if (metatype.equals(MT_CHILD)) { String value = properties.getProperty(key); words = split(words[1], 2); - String indexString = words[0]; + String childName = words[0]; + childNames.add(childName); String newKey = words[1]; - int n = Integer.parseInt(indexString) + 1; - if (nChildren < n) nChildren = n; - Properties p = getProperties(childPropertiesMap, indexString); + Properties p = getProperties(childPropertiesMap, childName); p.put(newKey, value); } } @@ -584,14 +584,14 @@ public class PropertyFileProvider implements IRSEPersistenceProvider { String attributeType = (String) attributeTypes.get(attributeName); node.addAttribute(attributeName, attributeValue, attributeType); } - for (int i = 0; i < nChildren; i++) { - String selector = getIndexString(i); - Properties p = getProperties(childPropertiesMap, selector); + for (Iterator z = childNames.iterator(); z.hasNext();) { + String childName = (String) z.next(); + Properties p = getProperties(childPropertiesMap, childName); makeNode(node, nodeFolder, p, monitor); } - for (int i = 0; i < nReferences; i++) { - String selector = getIndexString(i); - String key = combine(MT_REFERENCE, selector); + for (Iterator z = referenceNames.iterator(); z.hasNext();) { + String referenceName = (String) z.next(); + String key = combine(MT_REFERENCE, referenceName); String childFolderName = properties.getProperty(key); IFolder childFolder = getFolder(nodeFolder, childFolderName); loadNode(node, childFolder, monitor); diff --git a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java index b0233bbd9af..bf07c276657 100644 --- a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java +++ b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java @@ -25,6 +25,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.SystemResourceManager; import org.eclipse.rse.core.subsystems.ISubSystem; @@ -45,15 +46,20 @@ import org.eclipse.rse.persistence.IRSEPersistenceProvider; import org.eclipse.rse.persistence.dom.RSEDOM; import org.eclipse.rse.ui.RSEUIPlugin; +/** + * The persistence manager controls all aspects of persisting the RSE data model. It will both + * save and restore this model. There should be only persistence manager in existence. This instance + * can be retrieved using RSEUIPlugin.getThePersistenceManager. + * @see RSEUIPlugin#getThePersistenceManager() + */ public class RSEPersistenceManager implements IRSEPersistenceManager { - public static final int STATE_NONE = 0; - public static final int STATE_IMPORTING = 1; - public static final int STATE_EXPORTING = 2; + + private static final int STATE_NONE = 0; + private static final int STATE_IMPORTING = 1; + private static final int STATE_EXPORTING = 2; private Map loadedProviders = new HashMap(10); - private int _currentState = STATE_NONE; - private RSEDOMExporter _exporter; private RSEDOMImporter _importer; @@ -282,7 +288,6 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { * wrong, an exception is thrown. */ public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name) { - ISystemFilterPoolManager mgr = SystemFilterPoolManager.createManager(profile); ((SystemFilterPoolManager) mgr).initialize(logger, caller, name); // core data mgr.setWasRestored(false); // DWD let's try this @@ -299,12 +304,16 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { return false; } + public boolean commit(IHost host) { + return commit(host.getSystemProfile()); + } + /** * Loads and restores RSE artifacts from the last session * @param profileManager * @return true if the profiles are loaded */ - public boolean load(ISystemProfileManager profileManager) { + private boolean load(ISystemProfileManager profileManager) { boolean successful = true; if (isExporting() || isImporting()) { successful = false; @@ -336,22 +345,25 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { } /** - * Saves the RSE artifacts from this session + * Writes the RSE model to a DOM and schedules writing of that DOM to disk. + * May, in fact, update an existing DOM instead of creating a new one. + * If in the process of importing, skip writing. + * @return true if the profile is written to a DOM */ - public boolean save(ISystemProfile profile, boolean force) { + private boolean save(ISystemProfile profile, boolean force) { boolean result = false; - if (!isImporting() && !isExporting()) { - - RSEDOM dom = exportRSEDOM(profile, force); - if (dom.needsSave() && !dom.saveScheduled()) { - // IProject project = SystemResourceManager.getRemoteSystemsProject(); - SaveRSEDOMJob job = new SaveRSEDOMJob(this, dom, getRSEPersistenceProvider()); - // job.setRule(project); - job.schedule(0); // TODO dwd control job delay here - dom.markSaveScheduled(); - } else { - //System.out.println("no save required"); - result = true; + if (!isImporting()) { + _currentState = STATE_EXPORTING; + RSEDOM dom = exportRSEDOM(profile, true); // DWD should do merge, but does not handle deletes properly yet + _currentState = STATE_NONE; + result = true; + if (dom.needsSave()) { + Job job = dom.getSaveJob(); + if (job == null) { + job = new SaveRSEDOMJob(dom, getRSEPersistenceProvider()); + dom.setSaveJob(job); + } + job.schedule(3000); // five second delay } } return result; @@ -365,17 +377,16 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { return _currentState == STATE_IMPORTING; } - public void setState(int state) { - _currentState = state; - } +// public void setState(int state) { +// _currentState = state; +// } - public RSEDOM exportRSEDOM(ISystemProfile profile, boolean force) { - _currentState = STATE_EXPORTING; + private RSEDOM exportRSEDOM(ISystemProfile profile, boolean force) { RSEDOM dom = _exporter.createRSEDOM(profile, force); return dom; } - public RSEDOM importRSEDOM(String domName) { + private RSEDOM importRSEDOM(String domName) { RSEDOM dom = null; IRSEPersistenceProvider provider = getRSEPersistenceProvider(); if (provider != null) { @@ -387,8 +398,4 @@ public class RSEPersistenceManager implements IRSEPersistenceManager { return dom; } - public boolean commit(IHost host) { - return commit(host.getSystemProfile()); - } - } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/SaveRSEDOMJob.java b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/SaveRSEDOMJob.java index 2db0e86e9fe..1dadad5e11e 100644 --- a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/SaveRSEDOMJob.java +++ b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/SaveRSEDOMJob.java @@ -23,35 +23,28 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.rse.persistence.IRSEPersistenceProvider; import org.eclipse.rse.persistence.dom.RSEDOM; - - -public class SaveRSEDOMJob extends Job -{ - private RSEPersistenceManager _mgr; +public class SaveRSEDOMJob extends Job { + private RSEDOM _dom; private IRSEPersistenceProvider _provider; - - public SaveRSEDOMJob(RSEPersistenceManager mgr, RSEDOM dom, IRSEPersistenceProvider provider) - { + + public SaveRSEDOMJob(RSEDOM dom, IRSEPersistenceProvider provider) { super("Saving RSE Profile: " + dom.getName()); _dom = dom; - _mgr = mgr; _provider = provider; } - - protected IStatus run(IProgressMonitor monitor) - { - if (_dom.needsSave()) - { - _provider.saveRSEDOM(_dom, monitor); - _dom.markUpdated(); - _mgr.setState(RSEPersistenceManager.STATE_NONE); - return Status.OK_STATUS; - } - else - { - return Status.CANCEL_STATUS; + + protected IStatus run(IProgressMonitor monitor) { + IStatus result = Status.OK_STATUS; + synchronized (_dom) { // synchronize on the DOM to prevent its update while writing + if (_dom.needsSave()) { + _provider.saveRSEDOM(_dom, monitor); + _dom.markUpdated(); + } else { + result = Status.CANCEL_STATUS; + } } + return result; } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMExporter.java b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMExporter.java index 830a6d34856..ca7361dc21c 100644 --- a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMExporter.java +++ b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/internal/persistence/dom/RSEDOMExporter.java @@ -67,7 +67,8 @@ public class RSEDOMExporter implements IRSEDOMExporter { } /** - * Creates the RSE DOM for this profile + * Creates the RSE DOM for this profile. After it has found the DOM it will + * synchronize on the DOM to ensure its integrity while it is being updated. * @param profile the profile for which to create the DOM * @param clean indicates whether to create from scratch or merge with existing DOM * @return The DOM for this profile @@ -79,7 +80,9 @@ public class RSEDOMExporter implements IRSEDOMExporter { _domMap.put(profile, dom); clean = true; } - populateRSEDOM(dom, profile, clean); + synchronized (dom) { + populateRSEDOM(dom, profile, clean); + } return dom; } diff --git a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/IRSEPersistenceManager.java b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/IRSEPersistenceManager.java index 0b7ce3e938b..d873c34202e 100644 --- a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/IRSEPersistenceManager.java +++ b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/IRSEPersistenceManager.java @@ -114,14 +114,6 @@ public interface IRSEPersistenceManager public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name); - /** - * Save the profile externally - * @param profile - * @param clean indicates whether to create from scratch or merger - * @return - */ - public boolean save(ISystemProfile profile, boolean clean); - public boolean isExporting(); public boolean isImporting(); } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOM.java b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOM.java index 22c6d38ddeb..6f3b65b0174 100644 --- a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOM.java +++ b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOM.java @@ -16,6 +16,8 @@ package org.eclipse.rse.persistence.dom; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.rse.internal.persistence.SaveRSEDOMJob; import org.eclipse.rse.model.ISystemProfile; /** @@ -28,7 +30,7 @@ public class RSEDOM extends RSEDOMNode { * Recommended for serializable objects. This should be updated if there is a schema change. */ private static final long serialVersionUID = 1L; - private boolean _saveScheduled = false; + private Job saveJob = null; private transient ISystemProfile _profile; public RSEDOM(ISystemProfile profile) { @@ -54,33 +56,6 @@ public class RSEDOM extends RSEDOMNode { } } - /** - * Indicate that this DOM has been saved - */ - public void markUpdated() { - if (_needsSave) { - _needsSave = false; - _saveScheduled = false; - super.markUpdated(); - } - } - - /** - * @return true if this DOM is scheduled to be saved - */ - public boolean saveScheduled() { - return _saveScheduled; - } - - /** - * Indicate that this DOM is scheduled to be saved - */ - public void markSaveScheduled() { - if (!_saveScheduled) { - _saveScheduled = true; - } - } - /** * @return true if this DOM has the DOM changed since last saved or restored. */ @@ -114,4 +89,12 @@ public class RSEDOM extends RSEDOMNode { System.out.println(indent + "}"); } + public Job getSaveJob() { + return saveJob; + } + + public void setSaveJob(Job saveJob) { + this.saveJob = saveJob; + } + } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOMNode.java b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOMNode.java index db1cbd93dc8..c5a0d40ee78 100644 --- a/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOMNode.java +++ b/rse/plugins/org.eclipse.rse.ui/persistence/org/eclipse/rse/persistence/dom/RSEDOMNode.java @@ -23,8 +23,8 @@ import java.util.List; public class RSEDOMNode implements IRSEDOMConstants, Serializable { - /** - * + /* + * Recommended for serializable objects. This should be updated if there is a schema change. */ private static final long serialVersionUID = 1L; protected String _type; diff --git a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java index 72203f39f63..ea1c9f68574 100644 --- a/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java +++ b/rse/plugins/org.eclipse.rse.ui/subsystems/org/eclipse/rse/core/subsystems/SubSystem.java @@ -616,73 +616,63 @@ public abstract class SubSystem extends RSEModelObject implements IAdaptable, IS { return getConnectionPrivateFilterPool(createIfNotFound); } + /** * Find or create a new filter pool, unique to this subsystem's connection. This will be - * in the same profile as the connection, and it will follow a naming convention that ties - * it to the connection: Filter Pool for xxx, where xxx is the connection name. + * in the same profile as the connection and it will follow a naming convention that ties + * it to the connection. * @param createIfNotFound - true to create the pool if it doesn't exist + * @return the filter pool that was found or created */ - public ISystemFilterPool getConnectionPrivateFilterPool(boolean createIfNotFound) - { + public ISystemFilterPool getConnectionPrivateFilterPool(boolean createIfNotFound) { ISystemFilterPool pool = null; - ISystemFilterPool[] allPoolsInProfile = getSubSystemConfiguration().getFilterPoolManager(getSystemProfile()).getSystemFilterPools(); - if (allPoolsInProfile!=null) - { - for (int idx=0; idxis deletable by user - pool.setNonRenamable(true); // don't allow users to rename this pool - //pool.setNonDeletable(true); hmm, should we or not? - pool.setOwningParentName(getHostAliasName()); - // now it is time to reference this pool in this subsystem - if (getSystemFilterPoolReferenceManager().getReferenceToSystemFilterPool(pool) == null) - { - getSystemFilterPoolReferenceManager().addReferenceToSystemFilterPool(pool); - } - } catch (Exception exc) - { - SystemBasePlugin.logError("Error creating connection-private filter pool for connection: "+getHostAliasName(),exc); - } + String profileName = profile.getName(); + pool = fpm.createSystemFilterPool(getConnectionOwnedFilterPoolName(profileName, hostName), true); // true=>is deletable by user + if (pool != null) { + pool.setNonRenamable(true); + pool.setOwningParentName(hostName); + pool.commit(); + ISystemFilterPoolReferenceManager fprm = getSystemFilterPoolReferenceManager(); + if (fprm.getReferenceToSystemFilterPool(pool) == null) { + fprm.addReferenceToSystemFilterPool(pool); + } + } + } catch (Exception exc) { + SystemBasePlugin.logError("Error creating connection-private filter pool for connection: " + hostName, exc); + } } return pool; } + /** - * Return the name for the connection-owned filter pool. + * Constructs the name of a connection specific filter pool from its parts. + * @param profileName the name of the profile that contains this filter pool. + * @param connectionName the name of the connection the "owns" this filter pool. + * @return the name for the connection-owned filter pool. */ - public String getConnectionOwnedFilterPoolName(String profileName, String connectionName) - { - // Similar to SubSystemConfigurationImpl#getDefaultFilterPoolName(String)... - // System.out.println("ProfileName: " + profileName); - // System.out.println("ConnectionName: " + connectionName); - -// String name = SystemResources.RESID_PERCONNECTION_FILTERPOOL; -// -// StringBuffer profileNameBuffer = new StringBuffer(profileName.toLowerCase()); -// profileNameBuffer.setCharAt(0, Character.toUpperCase(profileNameBuffer.charAt(0))); -// -// name = SystemMessage.sub(name, "%1", profileNameBuffer.toString()); -// name = SystemMessage.sub(name, "%2", connectionName); + public String getConnectionOwnedFilterPoolName(String profileName, String connectionName) { /* - * DWD - Need to keep this name short and not translatable + * Need to keep this name short and not translatable * since it names a team sharable resource. Not qualified by the profile * name since that is implicit by being in a profile. */ - // DWD - does not appear to be used. - String name = "CN-" + connectionName; + String name = "CN-" + connectionName; // $NON-NLS-1$ return name; }