View | Details | Raw Unified | Return to bug 170932
Collapse All | Expand All

(-)src/org/eclipse/rse/internal/core/filters/SystemFilterPoolReferenceManager.java (-8 / +17 lines)
Lines 16-21 Link Here
16
16
17
package org.eclipse.rse.internal.core.filters;
17
package org.eclipse.rse.internal.core.filters;
18
18
19
import java.util.ArrayList;
20
import java.util.List;
19
import java.util.Vector;
21
import java.util.Vector;
20
22
21
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IFile;
Lines 384-392 Link Here
384
	 * Create a filter pool reference. This creates an unresolved raw reference that
386
	 * Create a filter pool reference. This creates an unresolved raw reference that
385
	 * must be added to the managed lists by the caller.
387
	 * must be added to the managed lists by the caller.
386
	 * That will be attempted to be resolved on first use.
388
	 * That will be attempted to be resolved on first use.
389
	 * @param filterPoolName the fully qualified filter pool name
387
	 */
390
	 */
388
	private ISystemFilterPoolReference createSystemFilterPoolReference(ISystemFilterPoolManager filterPoolManager, String filterPoolName) {
391
	private ISystemFilterPoolReference createSystemFilterPoolReference(String filterPoolName) {
389
		ISystemFilterPoolReference filterPoolReference = new SystemFilterPoolReference(filterPoolManager, filterPoolName);
392
		ISystemFilterPoolReference filterPoolReference = new SystemFilterPoolReference(filterPoolName);
390
		invalidateFilterPoolReferencesCache();
393
		invalidateFilterPoolReferencesCache();
391
		return filterPoolReference;
394
		return filterPoolReference;
392
	}
395
	}
Lines 503-512 Link Here
503
	 */
506
	 */
504
	public ISystemFilterPool[] getReferencedSystemFilterPools() {
507
	public ISystemFilterPool[] getReferencedSystemFilterPools() {
505
		ISystemFilterPoolReference[] refs = getSystemFilterPoolReferences();
508
		ISystemFilterPoolReference[] refs = getSystemFilterPoolReferences();
506
		ISystemFilterPool[] pools = new ISystemFilterPool[refs.length];
509
		List pools = new ArrayList(refs.length);
507
		for (int idx = 0; idx < pools.length; idx++)
510
		for (int idx = 0; idx < refs.length; idx++) {
508
			pools[idx] = refs[idx].getReferencedFilterPool();
511
			ISystemFilterPool pool = refs[idx].getReferencedFilterPool();
509
		return pools;
512
			if (pool != null) {
513
				pools.add(pool);
514
			}
515
		}
516
		ISystemFilterPool[] result = new ISystemFilterPool[pools.size()];
517
		pools.toArray(result);
518
		return result;
510
	}
519
	}
511
520
512
	/**
521
	/**
Lines 542-549 Link Here
542
	/* (non-Javadoc)
551
	/* (non-Javadoc)
543
	 * @see org.eclipse.rse.filters.ISystemFilterPoolReferenceManager#addReferenceToSystemFilterPool(org.eclipse.rse.filters.ISystemFilterPoolManager, java.lang.String)
552
	 * @see org.eclipse.rse.filters.ISystemFilterPoolReferenceManager#addReferenceToSystemFilterPool(org.eclipse.rse.filters.ISystemFilterPoolManager, java.lang.String)
544
	 */
553
	 */
545
	public ISystemFilterPoolReference addReferenceToSystemFilterPool(ISystemFilterPoolManager filterPoolManager, String filterPoolName) {
554
	public ISystemFilterPoolReference addReferenceToSystemFilterPool(String filterPoolName) {
546
		ISystemFilterPoolReference filterPoolReference = createSystemFilterPoolReference(filterPoolManager, filterPoolName);
555
		ISystemFilterPoolReference filterPoolReference = createSystemFilterPoolReference(filterPoolName);
547
		addReferencingObject(filterPoolReference);
556
		addReferencingObject(filterPoolReference);
548
		filterPoolReference.setParentReferenceManager(this);
557
		filterPoolReference.setParentReferenceManager(this);
549
		invalidateFilterPoolReferencesCache();
558
		invalidateFilterPoolReferencesCache();
(-)src/org/eclipse/rse/internal/core/filters/SystemFilterPoolReference.java (-44 / +51 lines)
Lines 16-24 Link Here
16
16
17
package org.eclipse.rse.internal.core.filters;
17
package org.eclipse.rse.internal.core.filters;
18
18
19
import java.util.regex.Matcher;
20
import java.util.regex.Pattern;
21
22
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.rse.core.RSECorePlugin;
21
import org.eclipse.rse.core.RSECorePlugin;
Lines 35-40 Link Here
35
import org.eclipse.rse.core.model.ISystemProfile;
32
import org.eclipse.rse.core.model.ISystemProfile;
36
import org.eclipse.rse.core.model.ISystemRegistry;
33
import org.eclipse.rse.core.model.ISystemRegistry;
37
import org.eclipse.rse.core.subsystems.ISubSystem;
34
import org.eclipse.rse.core.subsystems.ISubSystem;
35
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
38
import org.eclipse.rse.internal.references.SystemPersistableReferencingObject;
36
import org.eclipse.rse.internal.references.SystemPersistableReferencingObject;
39
37
40
/**
38
/**
Lines 66-78 Link Here
66
	
64
	
67
	/**
65
	/**
68
	 * Constructs a new filter pool reference. This is an unresolved reference.
66
	 * Constructs a new filter pool reference. This is an unresolved reference.
69
	 * It is resolved on first use by using the supplied filterPoolManager.
70
	 * @param filterPoolManager the manager used to resolve the reference.
71
	 * @param filterPoolName the name of the filter pool.
67
	 * @param filterPoolName the name of the filter pool.
72
	 */
68
	 */
73
	public SystemFilterPoolReference(ISystemFilterPoolManager filterPoolManager, String filterPoolName) {
69
	public SystemFilterPoolReference(String filterPoolName) {
74
		this();
70
		this();
75
		this.filterPoolManager = filterPoolManager;
76
		setReferencedObjectName(filterPoolName);
71
		setReferencedObjectName(filterPoolName);
77
	}
72
	}
78
73
Lines 105-132 Link Here
105
	 * @see org.eclipse.rse.core.filters.ISystemFilterPoolReference#getReferencedFilterPoolName()
100
	 * @see org.eclipse.rse.core.filters.ISystemFilterPoolReference#getReferencedFilterPoolName()
106
	 */
101
	 */
107
	public String getReferencedFilterPoolName() {
102
	public String getReferencedFilterPoolName() {
108
		String savedName = super.getReferencedObjectName();
103
		/*
109
		String poolName = null;
104
		 * A filter pool reference stores the name of the filter pool it references in the form managerName___filterPoolName.
110
		int idx = savedName.indexOf(DELIMITER);
105
		 * or in the unqualified form of filterPoolName which references a locally defined filter pool.
111
		if (idx >= 0)
106
		 * ___ is the delimiter. Absence of the delimiter indicates an unqualified name.
112
			poolName = savedName.substring(idx + DELIMITER_LENGTH);
107
		 * The filter pool manager name is the same as its owning profile.
113
		else
108
		 */
114
			poolName = savedName;
109
		String savedName = getReferencedObjectName();
115
		return poolName;
110
		String[] parts = savedName.split(DELIMITER, 2);
111
		String result = parts[0];
112
		if (parts.length == 2) {
113
			result = parts[1];
114
		}
115
		return result;
116
	}
116
	}
117
117
118
	/* (non-Javadoc)
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.rse.core.filters.ISystemFilterPoolReference#getReferencedFilterPoolManagerName()
119
	 * @see org.eclipse.rse.core.filters.ISystemFilterPoolReference#getReferencedFilterPoolManagerName()
120
	 */
120
	 */
121
	public String getReferencedFilterPoolManagerName() {
121
	public String getReferencedFilterPoolManagerName() {
122
		String savedName = super.getReferencedObjectName();
122
		/*
123
		String mgrName = null;
123
		 * A filter pool reference stores the name of the filter pool it references in the form managerName___filterPoolName.
124
		int idx = savedName.indexOf(DELIMITER);
124
		 * or in the unqualified form of filterPoolName which references a locally defined filter pool.
125
		if (idx >= 0)
125
		 * ___ is the delimiter. Absence of the delimiter indicates an unqualified name.
126
			mgrName = savedName.substring(0, idx);
126
		 * The filter pool manager name is the same as its owning profile.
127
		else
127
		 */
128
			mgrName = savedName;
128
		String result = null;
129
		return mgrName;
129
		String savedName = getReferencedObjectName();
130
		String[] parts = savedName.split(DELIMITER, 2);
131
		if (parts.length == 2) {
132
			result = parts[0];
133
		} else {
134
			ISystemFilterPoolReferenceManagerProvider provider = getProvider();
135
			if (provider instanceof ISubSystem) {
136
				ISubSystem subsystem = (ISubSystem) provider;
137
				ISystemProfile profile = subsystem.getSystemProfile();
138
				result = profile.getName();
139
			}
140
		}
141
		if (result == null) {
142
			RSECorePlugin.getDefault().getLogger().logWarning("Unexpected condition: filter pool manager name not found.", null); //$NON-NLS-1$
143
		}
144
		return result;
130
	}
145
	}
131
146
132
	/* (non-Javadoc)
147
	/* (non-Javadoc)
Lines 150-177 Link Here
150
		ISystemFilterPool filterPool = (ISystemFilterPool) getReferencedObject();
165
		ISystemFilterPool filterPool = (ISystemFilterPool) getReferencedObject();
151
		if (filterPool == null) {
166
		if (filterPool == null) {
152
			String filterPoolName = getReferencedFilterPoolName();
167
			String filterPoolName = getReferencedFilterPoolName();
168
			String profileName = getReferencedFilterPoolManagerName();
169
			ISystemRegistry registry = RSECorePlugin.getDefault().getSystemRegistry();
170
			ISystemProfile profile = registry.getSystemProfile(profileName);
171
			ISubSystem subsystem = (ISubSystem) getProvider();
172
			ISubSystemConfiguration config = subsystem.getSubSystemConfiguration();
173
			filterPoolManager = config.getFilterPoolManager(profile);
153
			filterPool = filterPoolManager.getSystemFilterPool(filterPoolName);
174
			filterPool = filterPoolManager.getSystemFilterPool(filterPoolName);
154
			if (filterPool == null) {
155
				Pattern p = Pattern.compile("(^.*):"); //$NON-NLS-1$
156
				Matcher m = p.matcher(filterPoolName);
157
				if (m.find()) {
158
					String profileName = m.group(1);
159
					ISystemRegistry registry = RSECorePlugin.getDefault().getSystemRegistry();
160
					ISystemProfile profile = registry.getSystemProfile(profileName);
161
					if (profile != null) {
162
						ISystemFilterPool[] pools = profile.getFilterPools();
163
						for (int i = 0; i < pools.length && filterPool == null; i++) {
164
							ISystemFilterPool pool = pools[i];
165
							if (filterPoolName.equals(pool.getName())) filterPool = pool;
166
						}
167
					}
168
				}
169
			}
170
			if (filterPool != null) {
171
				setReferenceToFilterPool(filterPool);
172
			}
173
		}
175
		}
174
		setReferenceBroken(filterPool == null);
176
		if (filterPool != null) {
177
			setReferenceToFilterPool(filterPool);
178
			setReferenceBroken(false);
179
		} else {
180
			setReferenceBroken(true);
181
		}
175
		return filterPool;
182
		return filterPool;
176
	}
183
	}
177
184
Lines 234-240 Link Here
234
	 * @see org.eclipse.rse.core.filters.ISystemFilterPoolReference#getFullName()
241
	 * @see org.eclipse.rse.core.filters.ISystemFilterPoolReference#getFullName()
235
	 */
242
	 */
236
	public String getFullName() {
243
	public String getFullName() {
237
		return super.getReferencedObjectName();
244
		return getReferencedObjectName();
238
	}
245
	}
239
246
240
	/* (non-Javadoc)
247
	/* (non-Javadoc)
(-)src/org/eclipse/rse/internal/core/filters/SystemFilterPool.java (-89 / +8 lines)
Lines 256-358 Link Here
256
	 * @generated This field/method will be replaced during code generation.
256
	 * @generated This field/method will be replaced during code generation.
257
	 */
257
	 */
258
	protected java.util.List filters = null;
258
	protected java.util.List filters = null;
259
	private static SystemFilterPool _instance;
259
260
/**
260
	/**
261
	 * Default constructor
261
	 * Default constructor
262
	 */
262
	 */
263
	protected SystemFilterPool() 
263
	public SystemFilterPool(String poolName, boolean allowNestedFilters, boolean isDeletable) 
264
	{
264
	{
265
		super();
265
		super();
266
		helpers = new SystemFilterContainerCommonMethods();
266
		helpers = new SystemFilterContainerCommonMethods();
267
	}
267
	   	setRelease(RSECorePlugin.CURRENT_RELEASE);
268
	
268
		if (!initialized) {
269
	public static SystemFilterPool getDefault()
269
			initialize(poolName, savePolicy, namingPolicy);
270
	{
271
		if (_instance == null)
272
		{
273
			_instance = new SystemFilterPool();
274
		}
270
		}
275
		return _instance;
276
	}
277
	
278
	/**
279
	 * Static factory method for creating a new filter pool. Will
280
	 * first try to restore it, and if that fails will create a new instance and
281
	 * return it.
282
	 * <p>
283
	 * Use this method only if you are not using a SystemFilterPoolManager, else
284
	 *  use the createSystemFilterPool method in that class.
285
	 * 
286
     *   This folder will be created if it does not already exist.
287
     * @param name the name of the filter pool. Typically this is also the name
288
     *   of the given folder, but this is not required. For the save policy of one file
289
     *   per pool, the name of the file is derived from this.
290
     * @param allowNestedFilters true if filters inside this filter pool are
291
     *   to allow nested filters. 
292
     * @param isDeletable true if this filter pool is allowed to be deleted by users.
293
     * @param tryToRestore true to attempt a restore first, false if a pure create operation.
294
	 */
295
	public ISystemFilterPool createSystemFilterPool(
296
	                                                      String name,
297
	                                                      boolean allowNestedFilters, 
298
	                                                      boolean isDeletable,
299
	                                                      boolean tryToRestore)
300
	{    	  
301
     	  
302
     	  
303
    	SystemFilterPool pool = null;
304
    	if (tryToRestore)
305
    	{
306
    	  try
307
    	  {
308
             pool = (SystemFilterPool)RSECorePlugin.getThePersistenceManager().restoreFilterPool(name);
309
    	  }
310
    	  catch (Exception exc) // real error trying to restore, versus simply not found.
311
    	  {
312
    	     // todo: something? Log the exception somewhere?
313
    	  }
314
    	}
315
        if (pool == null) // not found or some serious error.
316
        {
317
    	  pool = createPool();    	
318
        }
319
    	if (pool != null)
320
    	{    	   
321
    	  pool.initialize(name, allowNestedFilters, isDeletable);
322
    	}
323
    	return pool;
324
	}
325
	
326
	// temporary!
327
	//public boolean isSharable() {return isSharable; }
328
	//public void setIsSharable(boolean is) { isSharable = is; }
329
330
    /*
331
     * Private helper method.
332
     * Uses MOF to create an instance of this class.
333
     */
334
    protected static SystemFilterPool createPool()
335
    {
336
    	ISystemFilterPool pool = new SystemFilterPool();
337
    		// FIXME SystemFilterImpl.initMOF().createSystemFilterPool();
338
    	pool.setRelease(RSECorePlugin.CURRENT_RELEASE);
339
    	return (SystemFilterPool)pool;    	
340
    }
341
342
    /*
343
     * Private helper method to initialize attributes
344
     */
345
	protected void initialize(String name,
346
	                          boolean allowNestedFilters, 
347
	                          boolean isDeletable)
348
	{
349
		if (!initialized)
350
		  initialize(name, savePolicy, namingPolicy);
351
        setDeletable(isDeletable); // mof attribute
271
        setDeletable(isDeletable); // mof attribute
352
		//System.out.println("In initialize() for filter pool " + getName() + ". isDeletable= " + isDeletable);        
353
        setSupportsNestedFilters(allowNestedFilters); // cascades to each filter
272
        setSupportsNestedFilters(allowNestedFilters); // cascades to each filter
354
	}
273
 	}
355
274
	
356
    /*
275
    /*
357
     * Private helper method to core initialization, from either createXXX or restore.
276
     * Private helper method to core initialization, from either createXXX or restore.
358
     */
277
     */
(-)src/org/eclipse/rse/internal/core/filters/SystemFilterString.java (-1 lines)
Lines 18-24 Link Here
18
18
19
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.rse.core.RSECorePlugin;
22
import org.eclipse.rse.core.filters.ISystemFilter;
21
import org.eclipse.rse.core.filters.ISystemFilter;
23
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
22
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
24
import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider;
23
import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider;
(-)src/org/eclipse/rse/core/model/RSEPersistableObject.java (-29 / +9 lines)
Lines 1-11 Link Here
1
package org.eclipse.rse.core.model;
1
package org.eclipse.rse.core.model;
2
2
3
3
public abstract class RSEPersistableObject implements IRSEPersistableContainer {
4
public abstract class RSEPersistableObject implements IRSEPersistableContainer {
4
5
5
	private boolean _isDirty = false;
6
	private boolean _isDirty = false;
6
	private boolean _wasRestored = false;
7
	private boolean _wasRestored = false;
7
	private boolean _isTainted = false;
8
	private boolean _isTainted = false;
8
	private boolean _restoring = false;
9
9
10
	public RSEPersistableObject() {
10
	public RSEPersistableObject() {
11
		super();
11
		super();
Lines 16-36 Link Here
16
	}
16
	}
17
17
18
	public final void setDirty(boolean flag) {
18
	public final void setDirty(boolean flag) {
19
		if (!_restoring) {
19
		_isDirty = flag;
20
			_isDirty = flag;
20
		setTainted(flag);
21
			if (flag) {
22
				setTainted(true);
23
			}
24
		}
25
	}
26
27
	public final void beginRestore() {
28
		_restoring = true;
29
	}
30
31
	public final void endRestore() {
32
		_restoring = false;
33
		setWasRestored(true);
34
	}
21
	}
35
22
36
	public final boolean wasRestored() {
23
	public final boolean wasRestored() {
Lines 46-64 Link Here
46
	}
33
	}
47
34
48
	public final void setTainted(boolean flag) {
35
	public final void setTainted(boolean flag) {
49
		if (!_restoring) {
36
		boolean taintParent = flag && !_isTainted;
50
			_isTainted = flag;
37
		_isTainted = flag;
51
			if (_isTainted) {
38
		if (taintParent) {
52
				IRSEPersistableContainer parent = getPersistableParent();
39
			IRSEPersistableContainer parent = getPersistableParent();
53
				if (parent != null) {
40
			if (parent != null) {
54
					parent.setTainted(true);
41
				parent.setTainted(true);
55
				}
56
			} else {
57
				IRSEPersistableContainer[] children = getPersistableChildren();
58
				for (int i = 0; i < children.length; i++) {
59
					IRSEPersistableContainer child = children[i];
60
					child.setTainted(false);
61
				}
62
			}
42
			}
63
		}
43
		}
64
	}
44
	}
(-)src/org/eclipse/rse/core/model/ISystemRegistry.java (-3 lines)
Lines 22-28 Link Here
22
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.jobs.ISchedulingRule;
23
import org.eclipse.core.runtime.jobs.ISchedulingRule;
24
import org.eclipse.rse.core.IRSESystemType;
24
import org.eclipse.rse.core.IRSESystemType;
25
import org.eclipse.rse.core.filters.ISystemFilterPool;
26
import org.eclipse.rse.core.filters.ISystemFilterStartHere;
25
import org.eclipse.rse.core.filters.ISystemFilterStartHere;
27
import org.eclipse.rse.core.subsystems.IConnectorService;
26
import org.eclipse.rse.core.subsystems.IConnectorService;
28
import org.eclipse.rse.core.subsystems.ISubSystem;
27
import org.eclipse.rse.core.subsystems.ISubSystem;
Lines 44-51 Link Here
44
43
45
	public ISystemFilterStartHere getSystemFilterStartHere();
44
	public ISystemFilterStartHere getSystemFilterStartHere();
46
45
47
	public ISystemFilterPool getSystemFilterPool();
48
49
	// ----------------------------------
46
	// ----------------------------------
50
	// UI METHODS...
47
	// UI METHODS...
51
	// ----------------------------------
48
	// ----------------------------------
(-)src/org/eclipse/rse/core/model/ISystemProfileManager.java (-2 / +11 lines)
Lines 16-21 Link Here
16
16
17
package org.eclipse.rse.core.model;
17
package org.eclipse.rse.core.model;
18
18
19
import java.util.List;
19
import java.util.Vector;
20
import java.util.Vector;
20
21
21
/**
22
/**
Lines 44-54 Link Here
44
	public void makeSystemProfileActive(ISystemProfile profile, boolean makeActive);
45
	public void makeSystemProfileActive(ISystemProfile profile, boolean makeActive);
45
46
46
	/**
47
	/**
47
	 * @return an array of all existing profiles.
48
	 * @return an array of all existing profiles. This is guaranteed to contain the
49
	 * default private profile.
48
	 */
50
	 */
49
	public ISystemProfile[] getSystemProfiles();
51
	public ISystemProfile[] getSystemProfiles();
50
52
51
	/**
53
	/**
54
	 * @return the number of profiles known to this manager.
55
	 */
56
	public int getSize();
57
58
	/**
52
	 * @return an array of all existing profile names.
59
	 * @return an array of all existing profile names.
53
	 */
60
	 */
54
	public String[] getSystemProfileNames();
61
	public String[] getSystemProfileNames();
Lines 129-135 Link Here
129
	 * @return The list of profiles known to this manager. This list is generated
136
	 * @return The list of profiles known to this manager. This list is generated
130
	 * at the point of this call and may thus be manipulated by the caller.
137
	 * at the point of this call and may thus be manipulated by the caller.
131
	 */
138
	 */
132
	java.util.List getProfiles();
139
	public List getProfiles();
140
	
141
	public void addSystemProfile(ISystemProfile profile);
133
142
134
	//	/**
143
	//	/**
135
	//	 * Reusable method to return a name validator for renaming a profile.
144
	//	 * Reusable method to return a name validator for renaming a profile.
(-)src/org/eclipse/rse/core/model/RSEModelOperation.java (-3 / +1 lines)
Lines 74-83 Link Here
74
	 * Ends a transaction. Schedules all changed profiles for save.
74
	 * Ends a transaction. Schedules all changed profiles for save.
75
	 */
75
	 */
76
	private static void endTransaction() {
76
	private static void endTransaction() {
77
		ISystemRegistry registry = RSECorePlugin.getDefault().getSystemRegistry();
78
		ISystemProfileManager profileManager = registry.getSystemProfileManager();
79
		IRSEPersistenceManager persistenceManager = RSECorePlugin.getDefault().getPersistenceManager();
77
		IRSEPersistenceManager persistenceManager = RSECorePlugin.getDefault().getPersistenceManager();
80
		persistenceManager.commit(profileManager);
78
		persistenceManager.commitProfiles();
81
	}
79
	}
82
80
83
	/**
81
	/**
(-)src/org/eclipse/rse/core/model/IRSEPersistableContainer.java (-18 / +2 lines)
Lines 49-70 Link Here
49
	 * @param flag true if the object was restored.
49
	 * @param flag true if the object was restored.
50
	 */
50
	 */
51
	public void setWasRestored(boolean flag);
51
	public void setWasRestored(boolean flag);
52
	
52
		
53
	/**
54
	 * Notifies the object that it is being restored. Typically this will
55
	 * suppress any marking of the object as dirty and related objects as 
56
	 * tainted while the restore is taking place. Should be used only by
57
	 * persistence providers.
58
	 */
59
	public void beginRestore();
60
	
61
	/**
62
	 * Notifies the object that it is has been restored. This will
63
	 * enable the object to be marked as dirty if subsequent changes
64
	 * are made to it. Should be used only by persistence providers.
65
	 */
66
	public void endRestore();
67
	
68
	/**
53
	/**
69
	 * An object is dirty if a change has been made to it that requires
54
	 * An object is dirty if a change has been made to it that requires
70
	 * it to be persisted.
55
	 * it to be persisted.
Lines 106-113 Link Here
106
	 * Sets the tainted attribute for this object. This should set to 
91
	 * Sets the tainted attribute for this object. This should set to 
107
	 * true only by child objects when they have been marked dirty or tainted.
92
	 * true only by child objects when they have been marked dirty or tainted.
108
	 * Setting this to true will cause all parent objects in the containment
93
	 * Setting this to true will cause all parent objects in the containment
109
	 * hierarchy to be marked tainted. Setting this to false will cause all
94
	 * hierarchy to be marked tainted.
110
	 * children to be marked as not tainted.
111
	 * It should be set to false only by a persistence manager when the
95
	 * It should be set to false only by a persistence manager when the
112
	 * object has been committed.
96
	 * object has been committed.
113
	 * @param flag the tainted state of the object.
97
	 * @param flag the tainted state of the object.
(-)src/org/eclipse/rse/core/filters/SystemFilterPoolManager.java (-96 / +48 lines)
Lines 18-23 Link Here
18
18
19
import java.util.ArrayList;
19
import java.util.ArrayList;
20
import java.util.Iterator;
20
import java.util.Iterator;
21
import java.util.List;
21
import java.util.Vector;
22
import java.util.Vector;
22
23
23
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IFile;
Lines 25-39 Link Here
25
import org.eclipse.rse.core.RSECorePlugin;
26
import org.eclipse.rse.core.RSECorePlugin;
26
import org.eclipse.rse.core.model.IRSEPersistableContainer;
27
import org.eclipse.rse.core.model.IRSEPersistableContainer;
27
import org.eclipse.rse.core.model.ISystemProfile;
28
import org.eclipse.rse.core.model.ISystemProfile;
28
import org.eclipse.rse.core.model.ISystemRegistry;
29
import org.eclipse.rse.core.model.RSEPersistableObject;
29
import org.eclipse.rse.core.model.RSEPersistableObject;
30
import org.eclipse.rse.core.references.IRSEBaseReferencingObject;
30
import org.eclipse.rse.core.references.IRSEBaseReferencingObject;
31
import org.eclipse.rse.internal.core.filters.ISystemFilterConstants;
31
import org.eclipse.rse.internal.core.filters.ISystemFilterConstants;
32
import org.eclipse.rse.internal.core.filters.SystemFilterPool;
32
import org.eclipse.rse.logging.Logger;
33
import org.eclipse.rse.logging.Logger;
33
import org.eclipse.rse.persistence.IRSEPersistenceManager;
34
35
//
36
//
37
34
38
/**
35
/**
39
 * A filter pool manager manages filter pools.
36
 * A filter pool manager manages filter pools.
Lines 190-199 Link Here
190
	 */
187
	 */
191
	protected boolean singleFilterStringOnly = SINGLE_FILTER_STRING_ONLY_EDEFAULT;
188
	protected boolean singleFilterStringOnly = SINGLE_FILTER_STRING_ONLY_EDEFAULT;
192
189
193
	/**
190
	protected List pools = null;
194
	 * @generated This field/method will be replaced during code generation.
195
	 */
196
	protected java.util.List pools = null;
197
191
198
	/**
192
	/**
199
	 * Constructor
193
	 * Constructor
Lines 224-230 Link Here
224
	 *   individual filter pool level.
218
	 *   individual filter pool level.
225
	 * @param savePolicy The save policy for the filter pools and filters. One of the
219
	 * @param savePolicy The save policy for the filter pools and filters. One of the
226
	 *   following constants from the 
220
	 *   following constants from the 
227
	 *   {@link org.eclipse.rse.internal.core.filters.ISystemFilterConstants SystemFilterConstants} interface:
221
	 *   {@link ISystemFilterConstants} interface:
228
	 *   <ul>
222
	 *   <ul>
229
	 *     <li>SAVE_POLICY_NONE - no files, all save/restore handled elsewhere
223
	 *     <li>SAVE_POLICY_NONE - no files, all save/restore handled elsewhere
230
	 *     <li>SAVE_POLICY_ONE_FILE_PER_MANAGER - one file: mgrName.xmi
224
	 *     <li>SAVE_POLICY_ONE_FILE_PER_MANAGER - one file: mgrName.xmi
Lines 238-263 Link Here
238
	public static ISystemFilterPoolManager createSystemFilterPoolManager(ISystemProfile profile, Logger logger, 
232
	public static ISystemFilterPoolManager createSystemFilterPoolManager(ISystemProfile profile, Logger logger, 
239
			ISystemFilterPoolManagerProvider caller, String name, boolean allowNestedFilters,
233
			ISystemFilterPoolManagerProvider caller, String name, boolean allowNestedFilters,
240
			int savePolicy, IRSEFilterNamingPolicy namingPolicy) {
234
			int savePolicy, IRSEFilterNamingPolicy namingPolicy) {
241
235
		SystemFilterPoolManager mgr = SystemFilterPoolManager.createManager(profile);
242
		SystemFilterPoolManager mgr = null;
236
		mgr.initialize(logger, caller, name, allowNestedFilters);
243
		if (namingPolicy == null) namingPolicy = SystemFilterNamingPolicy.getNamingPolicy();
244
		try {
245
			mgr = (SystemFilterPoolManager) RSECorePlugin.getThePersistenceManager().restoreFilterPoolManager(profile, logger, caller, name);
246
			/*
247
			 if (savePolicy != SystemFilterConstants.SAVE_POLICY_NONE)
248
			 mgr = (SystemFilterPoolManagerImpl)restore(;
249
			 */
250
		} catch (Exception exc) // real error trying to restore, versus simply not found.
251
		{
252
			// todo: something. Log the exception somewhere?
253
		}
254
		if (mgr == null) // not found or some serious error.
255
		{
256
			mgr = createManager(profile);
257
		}
258
		if (mgr != null) {
259
			mgr.initialize(logger, caller, name, allowNestedFilters);
260
		}
261
		return mgr;
237
		return mgr;
262
	}
238
	}
263
239
Lines 276-305 Link Here
276
	 * Private helper method to initialize state
252
	 * Private helper method to initialize state
277
	 */
253
	 */
278
	public void initialize(Logger logger, ISystemFilterPoolManagerProvider caller, String name, boolean allowNestedFilters) {
254
	public void initialize(Logger logger, ISystemFilterPoolManagerProvider caller, String name, boolean allowNestedFilters) {
279
		if (!initialized) initialize(logger, caller, name); // core data
255
		if (!initialized) {
280
256
			initialize(logger, caller, name); // core data
281
		{
282
			java.util.List pools = getPools();
283
			ISystemFilterPool pool = null;
284
			Vector poolNames = getSystemFilterPoolNamesVector();
285
			for (int idx = 0; idx < poolNames.size(); idx++) {
286
				String poolName = (String) poolNames.elementAt(idx);
287
				pool = RSECorePlugin.getThePersistenceManager().restoreFilterPool(poolName);
288
				pool.setSystemFilterPoolManager(this);
289
				pools.add(pool);
290
291
				/** FIXME test
292
				 if (pool.specialCaseNoDataRestored)
293
				 {
294
				 pool.setDeletable(true); // what else to do?
295
				 //pool.setSupportsNestedFilters(allowNestedFilters); will be cascaded down anyway
296
				 }
297
				 */
298
			}
299
300
		}
257
		}
301
		setSupportsNestedFilters(allowNestedFilters); // cascade it down    	
258
		setSupportsNestedFilters(allowNestedFilters); // cascade it down    	
302
		invalidatePoolCache();
259
		invalidatePoolCache();
260
//		List pools = getPools();
261
//		ISystemFilterPool pool = null;
262
//		Vector poolNames = getSystemFilterPoolNamesVector();
263
//		for (int idx = 0; idx < poolNames.size(); idx++) {
264
//			String poolName = (String) poolNames.elementAt(idx);
265
////			pool = RSECorePlugin.getThePersistenceManager().restoreFilterPool(poolName);
266
//			pool = null; // that's what the above returned
267
//			pool.setSystemFilterPoolManager(this);
268
//			pools.add(pool);
269
//
270
//			/** FIXME test
271
//			 if (pool.specialCaseNoDataRestored)
272
//			 {
273
//			 pool.setDeletable(true); // what else to do?
274
//			 //pool.setSupportsNestedFilters(allowNestedFilters); will be cascaded down anyway
275
//			 }
276
//			 */
277
//		}
303
	}
278
	}
304
279
305
	/*
280
	/*
Lines 309-315 Link Here
309
	public void initialize(Logger logger, ISystemFilterPoolManagerProvider caller, String name) {
284
	public void initialize(Logger logger, ISystemFilterPoolManagerProvider caller, String name) {
310
		this.logger = logger;
285
		this.logger = logger;
311
		setProvider(caller);
286
		setProvider(caller);
312
		setNameGen(name);
287
		setName(name);
313
		setFilterPoolManager(); // cascade it down
288
		setFilterPoolManager(); // cascade it down
314
		initialized = true;
289
		initialized = true;
315
	}
290
	}
Lines 331-344 Link Here
331
306
332
	/**
307
	/**
333
	 * Set the name of this manager.
308
	 * Set the name of this manager.
334
	 * Intercepted so the file get be renamed for SAVE_POLICY_ONE_FILE_PER_MANAGER.
335
	 */
309
	 */
336
	public void setName(String name) {
310
	public void setName(String newName) {
337
		String oldName = getName();
311
		if ((name == null && newName != null) || !name.equals(newName)) {
338
		if (oldName != null) {
312
			this.name = newName;
339
			if (!oldName.equals(name)) {
313
			setDirty(true);
340
				this.name = name;
341
			}
342
		}
314
		}
343
	}
315
	}
344
316
Lines 473-479 Link Here
473
	public ISystemFilterPool[] getSystemFilterPools() {
445
	public ISystemFilterPool[] getSystemFilterPools() {
474
		//System.out.println("Inside getSFPools for mgr "+getName()+". poolArray null? "+(poolArray==null));
446
		//System.out.println("Inside getSFPools for mgr "+getName()+". poolArray null? "+(poolArray==null));
475
		if ((poolArray == null) || (getPools().size() != poolArray.length)) {
447
		if ((poolArray == null) || (getPools().size() != poolArray.length)) {
476
			java.util.List pools = getPools();
448
			List pools = getPools();
477
			poolArray = new ISystemFilterPool[pools.size()];
449
			poolArray = new ISystemFilterPool[pools.size()];
478
			Iterator i = pools.iterator();
450
			Iterator i = pools.iterator();
479
			int idx = 0;
451
			int idx = 0;
Lines 499-505 Link Here
499
	 * Get list of filter pool names currently existing.
471
	 * Get list of filter pool names currently existing.
500
	 */
472
	 */
501
	public Vector getSystemFilterPoolNamesVector() {
473
	public Vector getSystemFilterPoolNamesVector() {
502
		java.util.List pools = getPools();
474
		List pools = getPools();
503
		if ((poolNames == null) || (poolNames.size() != pools.size())) // been invalidated?
475
		if ((poolNames == null) || (poolNames.size() != pools.size())) // been invalidated?
504
		{
476
		{
505
			poolNames = new Vector();
477
			poolNames = new Vector();
Lines 540-569 Link Here
540
	 * Calls back to inform provider of this event
512
	 * Calls back to inform provider of this event
541
	 */
513
	 */
542
	public ISystemFilterPool createSystemFilterPool(String poolName, boolean isDeletable) throws Exception {
514
	public ISystemFilterPool createSystemFilterPool(String poolName, boolean isDeletable) throws Exception {
543
		// always trim the pool name, MOF does not handle trailing or preceding spaces
544
		poolName = poolName.trim();
545
546
		if (getSystemFilterPool(poolName) != null) return null;
547
548
		ISystemFilterPool pool = null;
515
		ISystemFilterPool pool = null;
549
516
		poolName = poolName.trim();
550
		ISystemRegistry registry = RSECorePlugin.getDefault().getSystemRegistry();
517
		if (getSystemFilterPool(poolName) == null) {
551
		ISystemFilterPool filterPool = registry.getSystemFilterPool();
518
			pool = new SystemFilterPool(poolName, supportsNestedFilters(), isDeletable);
552
		pool = filterPool.createSystemFilterPool(poolName, supportsNestedFilters(), isDeletable, ISystemFilterConstants.TRY_TO_RESTORE_NO);
553
554
		if (pool != null) {
555
			pool.setSystemFilterPoolManager(this);
519
			pool.setSystemFilterPoolManager(this);
556
			pool.setStringsCaseSensitive(areStringsCaseSensitive());
520
			pool.setStringsCaseSensitive(areStringsCaseSensitive());
557
			if (isSetSupportsDuplicateFilterStrings()) pool.setSupportsDuplicateFilterStrings(supportsDuplicateFilterStrings());
521
			pool.setSupportsDuplicateFilterStrings(isSetSupportsDuplicateFilterStrings() && supportsDuplicateFilterStrings());
558
			// add to model
522
			List pools = getPools();
559
			java.util.List pools = getPools();
560
			pools.add(pool);
523
			pools.add(pool);
561
			//System.out.println("Inside createSFPool for mgr "+getName()+". Pool "+name+" added");
562
			invalidatePoolCache();
524
			invalidatePoolCache();
563
			// save to disk...
564
			commit(pool);
525
			commit(pool);
565
			// if caller provider, callback to inform them of this event
526
			if ((caller != null) && !suspendCallbacks) {
566
			if ((caller != null) && !suspendCallbacks) caller.filterEventFilterPoolCreated(pool);
527
				caller.filterEventFilterPoolCreated(pool);
528
			}
567
		}
529
		}
568
		return pool;
530
		return pool;
569
	}
531
	}
Lines 601-608 Link Here
601
		// DWD removing a pool should mark its parent profile as dirty and cause a save to be "scheduled"
563
		// DWD removing a pool should mark its parent profile as dirty and cause a save to be "scheduled"
602
564
603
		// remove from model
565
		// remove from model
604
		java.util.List pools = getPools();
566
		List pools = getPools();
605
		pools.remove(pool);
567
		pools.remove(pool);
568
		invalidatePoolCache();
606
569
607
		/* FIXME
570
		/* FIXME
608
		 // now in EMF, the pools are "owned" by the Resource, and only referenced by this pool manager,
571
		 // now in EMF, the pools are "owned" by the Resource, and only referenced by this pool manager,
Lines 1530-1536 Link Here
1530
		/* FIXME
1493
		/* FIXME
1531
		 String fileName = getRootSaveFileName(namingPolicy, name);
1494
		 String fileName = getRootSaveFileName(namingPolicy, name);
1532
		 
1495
		 
1533
		 java.util.List ext = getMOFHelpers(logger).restore(mgrFolder,fileName);
1496
		 List ext = getMOFHelpers(logger).restore(mgrFolder,fileName);
1534
		 
1497
		 
1535
		 SystemFilterPoolManager mgr = null;
1498
		 SystemFilterPoolManager mgr = null;
1536
1499
Lines 1652-1661 Link Here
1652
	/**
1615
	/**
1653
	 * @generated This field/method will be replaced during code generation 
1616
	 * @generated This field/method will be replaced during code generation 
1654
	 */
1617
	 */
1655
	public java.util.List getPools() {
1618
	public List getPools() {
1656
		if (pools == null) {
1619
		if (pools == null) {
1657
			pools = new ArrayList();
1620
			pools = new ArrayList();
1658
			//FIXME new EObjectResolvingeList(SystemFilterPool.class, this, FiltersPackage.SYSTEM_FILTER_POOL_MANAGER__POOLS);
1659
		}
1621
		}
1660
		return pools;
1622
		return pools;
1661
	}
1623
	}
Lines 1663-1679 Link Here
1663
	/**
1625
	/**
1664
	 * @generated This field/method will be replaced during code generation.
1626
	 * @generated This field/method will be replaced during code generation.
1665
	 */
1627
	 */
1666
	public void setNameGen(String newName) {
1667
		String oldName = name;
1668
		if (oldName != newName) {
1669
			name = newName;
1670
			setDirty(true);
1671
		}
1672
	}
1673
1674
	/**
1675
	 * @generated This field/method will be replaced during code generation.
1676
	 */
1677
	public void setSupportsNestedFiltersGen(boolean newSupportsNestedFilters) {
1628
	public void setSupportsNestedFiltersGen(boolean newSupportsNestedFilters) {
1678
		supportsNestedFilters = newSupportsNestedFilters;
1629
		supportsNestedFilters = newSupportsNestedFilters;
1679
	}
1630
	}
Lines 1727-1734 Link Here
1727
	 * Uses the save policy specified in this manager's factory method.
1678
	 * Uses the save policy specified in this manager's factory method.
1728
	 */
1679
	 */
1729
	public boolean commit() {
1680
	public boolean commit() {
1730
		IRSEPersistenceManager mgr = RSECorePlugin.getThePersistenceManager();
1681
		ISystemProfile profile = getSystemProfile();
1731
		return mgr.commit(this);
1682
		boolean result = profile.commit();
1683
		return result;
1732
	}
1684
	}
1733
1685
1734
	/**
1686
	/**
(-)src/org/eclipse/rse/core/filters/ISystemFilterPool.java (-2 / +1 lines)
Lines 337-342 Link Here
337
	 * @generated
337
	 * @generated
338
	 */
338
	 */
339
	void setNonRenamable(boolean value);
339
	void setNonRenamable(boolean value);
340
340
	
341
	public ISystemFilterPool createSystemFilterPool(String name, boolean allowNestedFilters, boolean isDeletable, boolean tryToRestore);
342
}
341
}
(-)src/org/eclipse/rse/core/filters/ISystemFilterPoolReferenceManager.java (-2 / +1 lines)
Lines 201-211 Link Here
201
	 * Given a filter pool name, create a referencing object and add it to the list.
201
	 * Given a filter pool name, create a referencing object and add it to the list.
202
	 * This creates an unresolved reference to that filter pool. It will be resolved on first use.
202
	 * This creates an unresolved reference to that filter pool. It will be resolved on first use.
203
	 * <p> Calls back to inform provider
203
	 * <p> Calls back to inform provider
204
	 * @param filterPoolManager the manager that can be used to resolve the reference.
205
	 * @param filterPoolName the name of the filter pool being referenced.
204
	 * @param filterPoolName the name of the filter pool being referenced.
206
	 * @return new filter pool reference
205
	 * @return new filter pool reference
207
	 */
206
	 */
208
	public ISystemFilterPoolReference addReferenceToSystemFilterPool(ISystemFilterPoolManager filterPoolManager, String filterPoolName);
207
	public ISystemFilterPoolReference addReferenceToSystemFilterPool(String filterPoolName);
209
208
210
	/**
209
	/**
211
	 * Given a filter pool, locate the referencing object for it and remove it from the list.
210
	 * Given a filter pool, locate the referencing object for it and remove it from the list.
(-)src/org/eclipse/rse/persistence/dom/RSEDOMNode.java (-4 / +10 lines)
Lines 21-30 Link Here
21
import java.util.List;
21
import java.util.List;
22
22
23
public class RSEDOMNode implements Serializable {
23
public class RSEDOMNode implements Serializable {
24
	/*
24
25
	 * Recommended for serializable objects. This should be updated if there is a schema change. 
25
	private static final long serialVersionUID = 1L; // This should be updated if there is a schema change.
26
	 */
27
	private static final long serialVersionUID = 1L;
28
	protected String _type;
26
	protected String _type;
29
	protected String _name;
27
	protected String _name;
30
	protected RSEDOMNode _parent;
28
	protected RSEDOMNode _parent;
Lines 219-223 Link Here
219
	public void setRestoring(boolean restoring) {
217
	public void setRestoring(boolean restoring) {
220
		this.restoring = restoring;
218
		this.restoring = restoring;
221
	}
219
	}
220
	
221
	public void setName(String name) {
222
		_name = name;
223
	}
224
	
225
	public void setType(String type) {
226
		_type = type;
227
	}
222
228
223
}
229
}
(-)src/org/eclipse/rse/internal/persistence/dom/RSEDOMExporter.java (-11 / +4 lines)
Lines 31-37 Link Here
31
import org.eclipse.rse.core.model.IPropertyType;
31
import org.eclipse.rse.core.model.IPropertyType;
32
import org.eclipse.rse.core.model.IRSEModelObject;
32
import org.eclipse.rse.core.model.IRSEModelObject;
33
import org.eclipse.rse.core.model.ISystemProfile;
33
import org.eclipse.rse.core.model.ISystemProfile;
34
import org.eclipse.rse.core.model.ISystemRegistry;
35
import org.eclipse.rse.core.subsystems.IConnectorService;
34
import org.eclipse.rse.core.subsystems.IConnectorService;
36
import org.eclipse.rse.core.subsystems.IDelegatingConnectorService;
35
import org.eclipse.rse.core.subsystems.IDelegatingConnectorService;
37
import org.eclipse.rse.core.subsystems.IServerLauncherProperties;
36
import org.eclipse.rse.core.subsystems.IServerLauncherProperties;
Lines 41-51 Link Here
41
import org.eclipse.rse.persistence.dom.RSEDOMNode;
40
import org.eclipse.rse.persistence.dom.RSEDOMNode;
42
41
43
public class RSEDOMExporter implements IRSEDOMExporter {
42
public class RSEDOMExporter implements IRSEDOMExporter {
43
	
44
	private static RSEDOMExporter _instance = new RSEDOMExporter();
44
	private static RSEDOMExporter _instance = new RSEDOMExporter();
45
	private Map _domMap;
45
	private Map _domMap;
46
46
47
	//	private ISystemRegistry _registry;
48
49
	/**
47
	/**
50
	 * Constructor to create a new DOM exporter.
48
	 * Constructor to create a new DOM exporter.
51
	 */
49
	 */
Lines 53-62 Link Here
53
		_domMap = new HashMap();
51
		_domMap = new HashMap();
54
	}
52
	}
55
53
56
	public void setSystemRegistry(ISystemRegistry registry) {
57
		//		_registry = registry;
58
	}
59
60
	/**
54
	/**
61
	 * @return the singleton instance of this exporter
55
	 * @return the singleton instance of this exporter
62
	 */
56
	 */
Lines 401-413 Link Here
401
	 */
395
	 */
402
	public RSEDOMNode createNode(RSEDOMNode parent, ISystemFilterPoolReference filterPoolReference, boolean clean) {
396
	public RSEDOMNode createNode(RSEDOMNode parent, ISystemFilterPoolReference filterPoolReference, boolean clean) {
403
		RSEDOMNode node = findOrCreateNode(parent, IRSEDOMConstants.TYPE_FILTER_POOL_REFERENCE, filterPoolReference, clean);
397
		RSEDOMNode node = findOrCreateNode(parent, IRSEDOMConstants.TYPE_FILTER_POOL_REFERENCE, filterPoolReference, clean);
404
398
		String name = filterPoolReference.getFullName();
399
		node.setName(name); // filter pool references must write out the fully qualified name of their referenced filter pool
405
		if (clean || node.isDirty()) {
400
		if (clean || node.isDirty()) {
406
			ISystemFilterPool filterPool = filterPoolReference.getReferencedFilterPool();
401
			ISystemFilterPool filterPool = filterPoolReference.getReferencedFilterPool();
407
			String refId = (filterPool != null) ? filterPool.getId() : "unknown"; //$NON-NLS-1$
402
			String refId = (filterPool != null) ? filterPool.getId() : "unknown"; //$NON-NLS-1$
408
			node.addAttribute(IRSEDOMConstants.ATTRIBUTE_REF_ID, refId);
403
			node.addAttribute(IRSEDOMConstants.ATTRIBUTE_REF_ID, refId);
409
		}
404
		}
410
411
		createPropertySetNodes(node, filterPoolReference, clean);
405
		createPropertySetNodes(node, filterPoolReference, clean);
412
		node.setDirty(false);
406
		node.setDirty(false);
413
		return node;
407
		return node;
Lines 430-437 Link Here
430
				node.setDirty(true);
424
				node.setDirty(true);
431
			}
425
			}
432
		}
426
		}
433
		boolean newNode = (node == null);
427
		if (node == null) {
434
		if (newNode) {
435
			node = new RSEDOMNode(parent, type, name);
428
			node = new RSEDOMNode(parent, type, name);
436
		}
429
		}
437
		return node;
430
		return node;
(-)src/org/eclipse/rse/internal/persistence/dom/RSEDOMImporter.java (-54 / +30 lines)
Lines 30-36 Link Here
30
import org.eclipse.rse.core.model.IPropertyType;
30
import org.eclipse.rse.core.model.IPropertyType;
31
import org.eclipse.rse.core.model.IRSEModelObject;
31
import org.eclipse.rse.core.model.IRSEModelObject;
32
import org.eclipse.rse.core.model.ISystemProfile;
32
import org.eclipse.rse.core.model.ISystemProfile;
33
import org.eclipse.rse.core.model.ISystemProfileManager;
34
import org.eclipse.rse.core.model.ISystemRegistry;
33
import org.eclipse.rse.core.model.ISystemRegistry;
35
import org.eclipse.rse.core.model.PropertyType;
34
import org.eclipse.rse.core.model.PropertyType;
36
import org.eclipse.rse.core.subsystems.IConnectorService;
35
import org.eclipse.rse.core.subsystems.IConnectorService;
Lines 40-52 Link Here
40
import org.eclipse.rse.core.subsystems.ISubSystem;
39
import org.eclipse.rse.core.subsystems.ISubSystem;
41
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
40
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
42
import org.eclipse.rse.core.subsystems.SubSystemFilterNamingPolicy;
41
import org.eclipse.rse.core.subsystems.SubSystemFilterNamingPolicy;
43
import org.eclipse.rse.internal.core.filters.ISystemFilterConstants;
42
import org.eclipse.rse.internal.core.model.SystemProfile;
43
import org.eclipse.rse.internal.core.model.SystemProfileManager;
44
import org.eclipse.rse.persistence.dom.IRSEDOMConstants;
44
import org.eclipse.rse.persistence.dom.IRSEDOMConstants;
45
import org.eclipse.rse.persistence.dom.RSEDOM;
45
import org.eclipse.rse.persistence.dom.RSEDOM;
46
import org.eclipse.rse.persistence.dom.RSEDOMNode;
46
import org.eclipse.rse.persistence.dom.RSEDOMNode;
47
import org.eclipse.rse.persistence.dom.RSEDOMNodeAttribute;
47
import org.eclipse.rse.persistence.dom.RSEDOMNodeAttribute;
48
48
49
public class RSEDOMImporter implements IRSEDOMImporter {
49
public class RSEDOMImporter {
50
	private static RSEDOMImporter _instance = new RSEDOMImporter();
50
	private static RSEDOMImporter _instance = new RSEDOMImporter();
51
	private ISystemRegistry _registry;
51
	private ISystemRegistry _registry;
52
52
Lines 63-82 Link Here
63
63
64
	/**
64
	/**
65
	 * Restores the profile represented by dom
65
	 * Restores the profile represented by dom
66
	 * @param profileManager
67
	 * @param dom
66
	 * @param dom
68
	 * @return the restored profile
67
	 * @return the restored profile
69
	 */
68
	 */
70
	public ISystemProfile restoreProfile(ISystemProfileManager profileManager, RSEDOM dom) {
69
	public ISystemProfile restoreProfile(RSEDOM dom) {
71
		// create the profile
72
		String profileName = dom.getName();
70
		String profileName = dom.getName();
73
		boolean defaultPrivate = getBooleanValue(dom.getAttribute(IRSEDOMConstants.ATTRIBUTE_DEFAULT_PRIVATE).getValue());
71
		boolean defaultPrivate = getBooleanValue(dom.getAttribute(IRSEDOMConstants.ATTRIBUTE_DEFAULT_PRIVATE).getValue());
74
		boolean isActive = getBooleanValue(dom.getAttribute(IRSEDOMConstants.ATTRIBUTE_IS_ACTIVE).getValue());
72
		boolean isActive = getBooleanValue(dom.getAttribute(IRSEDOMConstants.ATTRIBUTE_IS_ACTIVE).getValue());
75
		ISystemProfile profile = profileManager.createSystemProfile(profileName, isActive);
73
		ISystemProfile profile = new SystemProfile(profileName, isActive);
76
77
		if (profile != null) {
74
		if (profile != null) {
78
			profile.setDefaultPrivate(defaultPrivate);
75
			profile.setDefaultPrivate(defaultPrivate);
79
			profileManager.makeSystemProfileActive(profile, isActive);
76
			SystemProfileManager.getDefault().addSystemProfile(profile);
80
			// restore the children for the profile
77
			// restore the children for the profile
81
			RSEDOMNode[] children = dom.getChildren();
78
			RSEDOMNode[] children = dom.getChildren();
82
			for (int i = 0; i < children.length; i++) {
79
			for (int i = 0; i < children.length; i++) {
Lines 130-136 Link Here
130
				restorePropertySet(host, child);
127
				restorePropertySet(host, child);
131
			}
128
			}
132
		}
129
		}
133
		
134
		return host;
130
		return host;
135
	}
131
	}
136
132
Lines 194-200 Link Here
194
	}
190
	}
195
191
196
	public IServerLauncherProperties restoreServerLauncher(IConnectorService service, RSEDOMNode serverLauncherNode, IServerLauncherProperties sl) {
192
	public IServerLauncherProperties restoreServerLauncher(IConnectorService service, RSEDOMNode serverLauncherNode, IServerLauncherProperties sl) {
197
		//		 restore all property sets
193
		// restore all property sets
198
		RSEDOMNode[] psChildren = serverLauncherNode.getChildren(IRSEDOMConstants.TYPE_PROPERTY_SET);
194
		RSEDOMNode[] psChildren = serverLauncherNode.getChildren(IRSEDOMConstants.TYPE_PROPERTY_SET);
199
		for (int p = 0; p < psChildren.length; p++) {
195
		for (int p = 0; p < psChildren.length; p++) {
200
			RSEDOMNode psChild = psChildren[p];
196
			RSEDOMNode psChild = psChildren[p];
Lines 232-238 Link Here
232
					subSystem = existingSubSystems[0];
228
					subSystem = existingSubSystems[0];
233
				}
229
				}
234
			}
230
			}
235
231
			
236
			if (subSystem == null) {
232
			if (subSystem == null) {
237
				// subSystem = factory.createSubSystemInternal(host);
233
				// subSystem = factory.createSubSystemInternal(host);
238
				ISubSystem[] createdSystems = _registry.createSubSystems(host, new ISubSystemConfiguration[]{factory});
234
				ISubSystem[] createdSystems = _registry.createSubSystems(host, new ISubSystemConfiguration[]{factory});
Lines 243-249 Link Here
243
			subSystem.setSubSystemConfiguration(factory);
239
			subSystem.setSubSystemConfiguration(factory);
244
			subSystem.setName(factory.getName());
240
			subSystem.setName(factory.getName());
245
			subSystem.setConfigurationId(factory.getId());
241
			subSystem.setConfigurationId(factory.getId());
246
			subSystem.setWasRestored(true);
247
242
248
			if (factory.supportsFilters()) {
243
			if (factory.supportsFilters()) {
249
				ISystemFilterStartHere startHere = _registry.getSystemFilterStartHere();
244
				ISystemFilterStartHere startHere = _registry.getSystemFilterStartHere();
Lines 267-272 Link Here
267
				restorePropertySet(subSystem, psChild);
262
				restorePropertySet(subSystem, psChild);
268
			}
263
			}
269
		}
264
		}
265
		subSystem.wasRestored();
270
		return subSystem;
266
		return subSystem;
271
	}
267
	}
272
268
Lines 304-313 Link Here
304
300
305
		// create the filter
301
		// create the filter
306
		ISystemFilter filter = filterPool.createSystemFilter(name, filterStrings);
302
		ISystemFilter filter = filterPool.createSystemFilter(name, filterStrings);
307
308
		filter.setWasRestored(true);
309
310
		// set filter attributes
311
		filter.setSupportsNestedFilters(supportsNestedFilters);
303
		filter.setSupportsNestedFilters(supportsNestedFilters);
312
		filter.setRelativeOrder(relativeOrder);
304
		filter.setRelativeOrder(relativeOrder);
313
		filter.setDefault(isDefault);
305
		filter.setDefault(isDefault);
Lines 361-386 Link Here
361
					filterPool = mgr.getSystemFilterPool(name);
353
					filterPool = mgr.getSystemFilterPool(name);
362
				}
354
				}
363
				if (filterPool == null) {
355
				if (filterPool == null) {
364
					filterPool = _registry.getSystemFilterPool().createSystemFilterPool(name, supportsNestedFilters, isDeletable, ISystemFilterConstants.TRY_TO_RESTORE_NO);
356
					filterPool = mgr.createSystemFilterPool(name, isDeletable);
365
357
//					filterPool = new SystemFilterPool(name, supportsNestedFilters, isDeletable);
366
					if (filterPool != null) {
358
//					filterPool.setSystemFilterPoolManager(mgr);
367
						filterPool.setSystemFilterPoolManager(mgr);
359
//					mgr.getPools().add(filterPool);
368
						// add to model
369
						mgr.getPools().add(filterPool);
370
					}
371
				}
372
				if (filterPool != null) {
373
					filterPool.setType(type);
374
					filterPool.setDefault(isDefault);
375
					filterPool.setSupportsNestedFilters(supportsNestedFilters);
376
					filterPool.setStringsCaseSensitive(isSetStringsCaseSensitive);
377
					filterPool.setSupportsDuplicateFilterStrings(isSetSupportsDuplicateFilterStrings);
378
					filterPool.setRelease(release);
379
					filterPool.setSingleFilterStringOnly(isSetSingleFilterStringOnly);
380
					filterPool.setOwningParentName(owningParentName);
381
					filterPool.setNonRenamable(isNonRenamable);
382
					filterPool.setWasRestored(true);
383
				}
360
				}
361
				filterPool.setType(type);
362
				filterPool.setDefault(isDefault);
363
				filterPool.setSupportsNestedFilters(supportsNestedFilters);
364
				filterPool.setStringsCaseSensitive(isSetStringsCaseSensitive);
365
				filterPool.setSupportsDuplicateFilterStrings(isSetSupportsDuplicateFilterStrings);
366
				filterPool.setRelease(release);
367
				filterPool.setSingleFilterStringOnly(isSetSingleFilterStringOnly);
368
				filterPool.setOwningParentName(owningParentName);
369
				filterPool.setNonRenamable(isNonRenamable);
370
//				filterPool.wasRestored();
384
			}
371
			}
385
		} catch (Exception e) {
372
		} catch (Exception e) {
386
			e.printStackTrace();
373
			e.printStackTrace();
Lines 407-432 Link Here
407
	 */
394
	 */
408
	public ISystemFilterPoolReference restoreFilterPoolReference(ISubSystem subsystem, RSEDOMNode node) {
395
	public ISystemFilterPoolReference restoreFilterPoolReference(ISubSystem subsystem, RSEDOMNode node) {
409
		ISystemFilterPoolReference filterPoolReference = null;
396
		ISystemFilterPoolReference filterPoolReference = null;
410
		String subsystemName = node.getAttribute(IRSEDOMConstants.ATTRIBUTE_REF_ID).getValue();
411
		String filterPoolName = node.getName();
397
		String filterPoolName = node.getName();
412
		ISubSystemConfiguration configuration = getSubSystemConfiguration(subsystemName);
398
		String[] part = filterPoolName.split("___", 2); //$NON-NLS-1$
413
		if (configuration != null) {
399
		if (part.length == 1) { // name is unqualified and refers to a filter pool in the current profile, ensure it is qualified
414
			ISystemProfile profile = subsystem.getSystemProfile(); // DWD are there cases where this may be null?
400
			ISystemProfile profile = subsystem.getSystemProfile();
415
			ISystemFilterPoolManager filterPoolManager = configuration.getFilterPoolManager(profile);
401
			String profileName = profile.getName();
416
			ISystemFilterPool filterPool = filterPoolManager.getSystemFilterPool(filterPoolName);
402
			filterPoolName = profileName + "___" + filterPoolName; //$NON-NLS-1$
417
			ISystemFilterPoolReferenceManager referenceManager = subsystem.getFilterPoolReferenceManager();
418
			/*
419
			 * DWD filterpool can be null when restoring since there can be forward references. 
420
			 * A profile may be being restored that has references to a filter pool in a profile that doesn't yet exist. 
421
			 * Need to create an "unresolved" reference instead of a null object and then patch them up on first access.
422
			 */
423
			// create reference to the filterpool
424
			if (filterPool != null) {
425
				filterPoolReference = referenceManager.addReferenceToSystemFilterPool(filterPool);
426
			} else {
427
				filterPoolReference = referenceManager.addReferenceToSystemFilterPool(filterPoolManager, filterPoolName);
428
			}
429
		}
403
		}
404
		ISystemFilterPoolReferenceManager referenceManager = subsystem.getFilterPoolReferenceManager();
405
		filterPoolReference = referenceManager.addReferenceToSystemFilterPool(filterPoolName);
430
		return filterPoolReference;
406
		return filterPoolReference;
431
	}
407
	}
432
408
(-)src/org/eclipse/rse/internal/persistence/RSEPersistenceManager.java (-255 / +187 lines)
Lines 16-26 Link Here
16
16
17
package org.eclipse.rse.internal.persistence;
17
package org.eclipse.rse.internal.persistence;
18
18
19
import java.util.ArrayList;
19
import java.util.HashMap;
20
import java.util.HashMap;
21
import java.util.List;
20
import java.util.Map;
22
import java.util.Map;
23
import java.util.Set;
21
24
22
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IConfigurationElement;
27
import org.eclipse.core.runtime.IConfigurationElement;
26
import org.eclipse.core.runtime.IExtensionRegistry;
28
import org.eclipse.core.runtime.IExtensionRegistry;
Lines 29-47 Link Here
29
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Platform;
30
import org.eclipse.core.runtime.Preferences;
32
import org.eclipse.core.runtime.Preferences;
31
import org.eclipse.core.runtime.jobs.Job;
33
import org.eclipse.core.runtime.jobs.Job;
32
import org.eclipse.core.runtime.preferences.IPreferencesService;
33
import org.eclipse.rse.core.IRSEPreferenceNames;
34
import org.eclipse.rse.core.IRSEPreferenceNames;
34
import org.eclipse.rse.core.RSECorePlugin;
35
import org.eclipse.rse.core.RSECorePlugin;
35
import org.eclipse.rse.core.SystemResourceManager;
36
import org.eclipse.rse.core.SystemResourceManager;
36
import org.eclipse.rse.core.filters.ISystemFilterPool;
37
import org.eclipse.rse.core.model.IRSEPersistableContainer;
37
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
38
import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider;
39
import org.eclipse.rse.core.filters.SystemFilterPoolManager;
40
import org.eclipse.rse.core.model.IHost;
41
import org.eclipse.rse.core.model.ISystemHostPool;
42
import org.eclipse.rse.core.model.ISystemProfile;
38
import org.eclipse.rse.core.model.ISystemProfile;
43
import org.eclipse.rse.core.model.ISystemProfileManager;
44
import org.eclipse.rse.core.model.ISystemRegistry;
39
import org.eclipse.rse.core.model.ISystemRegistry;
40
import org.eclipse.rse.internal.core.model.SystemProfileManager;
45
import org.eclipse.rse.internal.persistence.dom.RSEDOMExporter;
41
import org.eclipse.rse.internal.persistence.dom.RSEDOMExporter;
46
import org.eclipse.rse.internal.persistence.dom.RSEDOMImporter;
42
import org.eclipse.rse.internal.persistence.dom.RSEDOMImporter;
47
import org.eclipse.rse.logging.Logger;
43
import org.eclipse.rse.logging.Logger;
Lines 58-404 Link Here
58
public class RSEPersistenceManager implements IRSEPersistenceManager {
54
public class RSEPersistenceManager implements IRSEPersistenceManager {
59
55
60
	private static final int STATE_NONE = 0;
56
	private static final int STATE_NONE = 0;
61
	private static final int STATE_IMPORTING = 1;
57
	private static final int STATE_LOADING = 1;
62
	private static final int STATE_EXPORTING = 2;
58
	private static final int STATE_SAVING = 2;
63
59
64
	private static IProject remoteSystemsProject = null;
60
	private static IProject remoteSystemsProject = null;
65
	public static final String RESOURCE_PROJECT_NAME = "RemoteSystemsConnections"; //$NON-NLS-1$
61
66
	/**
62
	/**
67
	 * Get the default remote systems project.
63
	 * Get the default remote systems project.
68
	 * @return IProject handle of the project. Use exists() to test existence.
64
	 * @return IProject handle of the project.
69
	 */
65
	 */
70
	public static IProject getRemoteSystemsProject() {
66
	public static IProject getRemoteSystemsProject() {
71
		if (remoteSystemsProject == null) 
67
		if (remoteSystemsProject == null) 
72
		{
68
		{
73
			remoteSystemsProject = SystemResourceManager.getRemoteSystemsProject();
69
			remoteSystemsProject = SystemResourceManager.getRemoteSystemsProject();
74
		}
70
		}
75
76
		return remoteSystemsProject;
71
		return remoteSystemsProject;
77
	}
72
	}
78
	private Map loadedProviders = new HashMap(10);
79
73
74
	private Map knownProviders = new HashMap(10);
80
	private int _currentState = STATE_NONE;
75
	private int _currentState = STATE_NONE;
81
	private RSEDOMExporter _exporter;
76
	private RSEDOMExporter _exporter;
82
83
	private RSEDOMImporter _importer;
77
	private RSEDOMImporter _importer;
84
78
85
	public RSEPersistenceManager(ISystemRegistry registry) {
79
	public RSEPersistenceManager(ISystemRegistry registry) {
86
		//		_registry = registry;
87
		_exporter = RSEDOMExporter.getInstance();
80
		_exporter = RSEDOMExporter.getInstance();
88
		_exporter.setSystemRegistry(registry);
89
		_importer = RSEDOMImporter.getInstance();
81
		_importer = RSEDOMImporter.getInstance();
90
		_importer.setSystemRegistry(registry);
82
		_importer.setSystemRegistry(registry);
83
		getProviderExtensions();
91
	}
84
	}
92
85
93
	public boolean commit(ISystemFilterPoolManager filterPoolManager) {
86
	public boolean isExporting() {
94
		if (filterPoolManager.isDirty()) {
87
		return _currentState == STATE_SAVING;
95
			commit(filterPoolManager.getSystemProfile());
88
	}
96
			filterPoolManager.setDirty(false);
89
97
		}
90
	public boolean isImporting() {
98
		return false;
91
		return _currentState == STATE_LOADING;
99
	}
92
	}
100
93
101
	public boolean commit(ISystemHostPool connectionPool) {
94
	public void registerPersistenceProvider(String id, IRSEPersistenceProvider provider) {
102
		if (connectionPool.isDirty()) {
95
		knownProviders.put(id, provider);
103
			commit(connectionPool.getSystemProfile());
104
			connectionPool.setDirty(false);
105
		}
106
		/*
107
		 Host[] connections = connectionPool.getHosts();
108
		 for (int idx = 0; idx < connections.length; idx++)
109
		 {
110
		 if (!saveHost(connectionPool, connections[idx]))
111
		 {
112
		 return false;
113
		 }
114
		 }
115
		 return true;
116
		 */
117
		return false; // all persistence should be at profile level
118
	}
96
	}
119
97
120
	/**
98
	/**
121
	 * Attempt to save single profile to disk.
99
	 * Attempt to save single profile to disk.
122
	 */
100
	 */
123
	public boolean commit(ISystemProfile profile) {
101
	public boolean commitProfile(ISystemProfile profile) {
102
		boolean result = false;
124
		if (profile != null) {
103
		if (profile != null) {
125
			return save(profile, false);
104
			result = save(profile, false);
126
		}
105
		}
127
		return false;
106
		return result;
128
	}
107
	}
129
108
130
	/**
109
	public boolean commitProfiles() {
131
	 * Save all profiles to disk
110
		boolean ok = true;
132
	 */
111
		ISystemProfile[] profiles = RSECorePlugin.getDefault().getSystemRegistry().getAllSystemProfiles();
133
	public boolean commit(ISystemProfileManager profileManager) {
112
		for (int idx = 0; idx < profiles.length && ok; idx++) {
134
135
		ISystemProfile[] profiles = profileManager.getSystemProfiles();
136
		for (int idx = 0; idx < profiles.length; idx++) {
137
			try {
113
			try {
138
				commit(profiles[idx]);
114
				ok = commitProfile(profiles[idx]);
139
			} catch (Exception exc) {
115
			} catch (Exception exc) {
140
				Logger logger = RSECorePlugin.getDefault().getLogger();
116
				Logger logger = RSECorePlugin.getDefault().getLogger();
141
				String profileName = profiles[idx].getName();
117
				String profileName = profiles[idx].getName();
142
				String message = "Error saving profile " + profileName; //$NON-NLS-1$
118
				String message = "Error saving profile " + profileName; //$NON-NLS-1$
143
				logger.logError(message, exc);
119
				logger.logError(message, exc);
144
				return false;
120
				ok = false;
145
			}
121
			}
146
		}
122
		}
147
123
		return ok;
148
		return true;
124
	}
125
	
126
	/* (non-Javadoc)
127
	 * @see org.eclipse.rse.persistence.IRSEPersistenceManager#migrateProfile(org.eclipse.rse.core.model.ISystemProfile, org.eclipse.rse.persistence.IRSEPersistenceProvider)
128
	 */
129
	public void migrateProfile(ISystemProfile profile, IRSEPersistenceProvider persistenceProvider) {
130
		IRSEPersistenceProvider oldProvider = profile.getPersistenceProvider();
131
		oldProvider = (oldProvider == null) ? getDefaultPersistenceProvider() : oldProvider;
132
		IRSEPersistenceProvider newProvider = persistenceProvider;
133
		newProvider = (newProvider == null) ? getDefaultPersistenceProvider() : newProvider;
134
		if (oldProvider != newProvider) {
135
			profile.setPersistenceProvider(newProvider);
136
			profile.commit();
137
			deleteProfile(oldProvider, profile.getName());
138
		}
149
	}
139
	}
150
140
151
	/* (non-Javadoc)
141
	/* (non-Javadoc)
152
	 * @see org.eclipse.rse.persistence.IRSEPersistenceManager#deleteProfile(java.lang.String)
142
	 * @see org.eclipse.rse.persistence.IRSEPersistenceManager#deleteProfile(java.lang.String)
153
	 */
143
	 */
154
	public void deleteProfile(final String profileName) {
144
	public void deleteProfile(final IRSEPersistenceProvider persistenceProvider, final String profileName) {
155
		Job job = new Job(Messages.RSEPersistenceManager_DeleteProfileJobName) {
145
		Job job = new Job(Messages.RSEPersistenceManager_DeleteProfileJobName) {
156
			protected IStatus run(IProgressMonitor monitor) {
146
			protected IStatus run(IProgressMonitor monitor) {
157
				IRSEPersistenceProvider provider = getRSEPersistenceProvider();
147
				IRSEPersistenceProvider p = persistenceProvider != null ? persistenceProvider : getDefaultPersistenceProvider();
158
				IStatus result = provider.deleteProfile(profileName, monitor);
148
				IStatus result = p.deleteProfile(profileName, monitor);
159
				return result;
149
				return result;
160
			}
150
			}
161
		};
151
		};
162
		job.schedule();
152
		job.schedule();
163
	}
153
	}
164
154
165
	private RSEDOM exportRSEDOM(ISystemProfile profile, boolean force) {
155
	/* (non-Javadoc)
166
		RSEDOM dom = _exporter.createRSEDOM(profile, force);
156
	 * @see org.eclipse.rse.persistence.IRSEPersistenceManager#restoreProfiles()
167
		return dom;
157
	 */
158
	public ISystemProfile[] restoreProfiles() {
159
		List profiles = loadProfiles();
160
		ISystemProfile[] result = new ISystemProfile[profiles.size()];
161
		profiles.toArray(result);
162
		return result;
163
	}
164
	
165
	public ISystemProfile restoreProfile(IRSEPersistenceProvider provider, String profileName) {
166
		ISystemProfile result = load(provider, profileName);
167
		return result;
168
	}
168
	}
169
169
170
	/**
170
	/**
171
	 * Returns the persistence provider denoted by the id. Only one instance of this 
172
	 * persistence provider is created.
173
	 * @param id The id of the persistence provider, as denoted by the id attribute on its declaration.
174
	 * @return an IRSEPersistenceProvider which may be null if this id is not found.
175
	 */
176
	public IRSEPersistenceProvider getPersistenceProvider(String id) {
177
		IRSEPersistenceProvider provider = null;
178
		Object providerCandidate = knownProviders.get(id);
179
		if (providerCandidate instanceof IConfigurationElement) {
180
			IConfigurationElement element = (IConfigurationElement) providerCandidate;
181
			try {
182
				provider = (IRSEPersistenceProvider) element.createExecutableExtension("class"); //$NON-NLS-1$
183
			} catch (CoreException e) {
184
				Logger logger = RSECorePlugin.getDefault().getLogger();
185
				logger.logError("Exception loading persistence provider", e); //$NON-NLS-1$
186
			}
187
			if (provider != null) {
188
				knownProviders.put(id, provider);
189
			}
190
		} else if (providerCandidate instanceof IRSEPersistenceProvider) {
191
			provider = (IRSEPersistenceProvider) providerCandidate;
192
		}
193
		return provider;
194
	}
195
	
196
	/* (non-Javadoc)
197
	 * @see org.eclipse.rse.persistence.IRSEPersistenceManager#getPersistenceProviderIds()
198
	 */
199
	public String[] getPersistenceProviderIds() {
200
		Set ids = knownProviders.keySet();
201
		String[] result = new String[ids.size()];
202
		ids.toArray(result);
203
		return result;
204
	}
205
	
206
	/**
171
	 * Retrieves the default persistence provider for this workbench configuration.
207
	 * Retrieves the default persistence provider for this workbench configuration.
172
	 * Several persistence providers may be registered, but the default one is used for all
208
	 * Several persistence providers may be registered, but the default one is used for all
173
	 * profiles that do not have one explicitly specified.
209
	 * profiles that do not have one explicitly specified.
174
	 * This persistence provider's identifier is specified in the org.eclipse.rse.core/defaultPersistenceProvider
210
	 * This persistence provider's identifier is specified in the org.eclipse.rse.core/DEFAULT_PERSISTENCE_PROVIDER
175
	 * preference and can be specified a product's plugin_customization.ini file.
211
	 * preference and can be specified a product's plugin_customization.ini file.
176
	 * @see IRSEPreferenceNames
212
	 * @see IRSEPreferenceNames
177
	 * @return the default IRSEPersistenceProvider for this installation.
213
	 * @return the default IRSEPersistenceProvider for this installation.
178
	 */
214
	 */
179
	public IRSEPersistenceProvider getRSEPersistenceProvider() {
215
	private IRSEPersistenceProvider getDefaultPersistenceProvider() {
180
		Preferences preferences = RSECorePlugin.getDefault().getPluginPreferences();
216
		Preferences preferences = RSECorePlugin.getDefault().getPluginPreferences();
181
		String providerName = preferences.getString(IRSEPreferenceNames.DEFAULT_PERSISTENCE_PROVIDER);
217
		String providerId = preferences.getString(IRSEPreferenceNames.DEFAULT_PERSISTENCE_PROVIDER);
182
		IRSEPersistenceProvider provider = getRSEPersistenceProvider(providerName);
218
		IRSEPersistenceProvider provider = getPersistenceProvider(providerId);
183
		return provider;
219
		return provider;
184
	}
220
	}
185
221
186
	/**
222
	/**
187
	 * Returns the persistence provider denoted by the id. Only one instance of this 
223
	 * Loads the map of known providers from the extensions made by all the plugins. 
188
	 * persistence provider is created.
224
	 * This is done once at initialization of the manager. As these ids are resolved to 
189
	 * @param id The id of the persistence provider, as denoted by the id attribute on its declaration.
225
	 * their providers as needed, the configuration elements are replaced in the map
190
	 * @return an IRSEPersistenceProvider which may be null if this id is not found.
226
	 * by the persistence providers they reference.
191
	 */
227
	 */
192
	public IRSEPersistenceProvider getRSEPersistenceProvider(String id) {
228
	private void getProviderExtensions() {
193
		Logger logger = RSECorePlugin.getDefault().getLogger();
229
		Logger logger = RSECorePlugin.getDefault().getLogger();
194
		IRSEPersistenceProvider provider = (IRSEPersistenceProvider) loadedProviders.get(id);
230
		IExtensionRegistry registry = Platform.getExtensionRegistry();
195
		if (provider == null) {
231
		IConfigurationElement[] providerCandidates = registry.getConfigurationElementsFor("org.eclipse.rse.core", "persistenceProviders"); //$NON-NLS-1$ //$NON-NLS-2$
196
			IExtensionRegistry registry = Platform.getExtensionRegistry();
232
		for (int j = 0; j < providerCandidates.length; j++) {
197
			IConfigurationElement[] providerCandidates = registry.getConfigurationElementsFor("org.eclipse.rse.core", "persistenceProviders"); //$NON-NLS-1$ //$NON-NLS-2$
233
			IConfigurationElement configurationElement = providerCandidates[j];
198
			for (int j = 0; j < providerCandidates.length; j++) {
234
			if (configurationElement.getName().equals("persistenceProvider")) { //$NON-NLS-1$
199
				IConfigurationElement providerCandidate = providerCandidates[j];
235
				String candidateId = configurationElement.getAttribute("id"); //$NON-NLS-1$
200
				if (providerCandidate.getName().equals("persistenceProvider")) { //$NON-NLS-1$
236
				if (candidateId != null) {
201
					String candidateId = providerCandidate.getAttribute("id"); //$NON-NLS-1$
237
					knownProviders.put(candidateId, configurationElement);
202
					if (candidateId != null) {
203
						if (candidateId.equals(id)) {
204
							try {
205
								provider = (IRSEPersistenceProvider) providerCandidate.createExecutableExtension("class"); //$NON-NLS-1$
206
							} catch (CoreException e) {
207
								logger.logError("Exception loading persistence provider", e); //$NON-NLS-1$
208
							}
209
						}
210
					} else {
211
						logger.logError("Missing id attribute in persistenceProvider element", null); //$NON-NLS-1$
212
					}
213
				} else {
238
				} else {
214
					logger.logError("Invalid element in persistenceProviders extension point", null); //$NON-NLS-1$
239
					logger.logError("Missing id attribute in persistenceProvider element", null); //$NON-NLS-1$
215
				}
240
				}
241
			} else {
242
				logger.logError("Invalid element in persistenceProviders extension point", null); //$NON-NLS-1$
216
			}
243
			}
217
			if (provider == null) {
218
				logger.logError("Persistence provider not found.", null); //$NON-NLS-1$
219
			}
220
			loadedProviders.put(id, provider); // even if provider is null
221
		}
244
		}
222
		return provider;
223
	}
245
	}
224
246
225
	private RSEDOM importRSEDOM(String domName) {
247
	private List loadProfiles() {
226
		RSEDOM dom = null;
248
		List profiles = new ArrayList(10);
227
		IRSEPersistenceProvider provider = getRSEPersistenceProvider();
249
		String[] ids = getPersistenceProviderIds();
228
		if (provider != null) {
250
		for (int i = 0; i < ids.length; i++) {
229
			dom = provider.loadRSEDOM(domName, null);
251
			String id = ids[i];
230
		} else {
252
			IRSEPersistenceProvider provider = getPersistenceProvider(id);
231
			Logger logger = RSECorePlugin.getDefault().getLogger();
253
			if (provider != null) {
232
			logger.logError("Persistence provider is not available.", null); //$NON-NLS-1$
254
				profiles.addAll(loadProfiles(provider));
255
			}
233
		}
256
		}
234
		return dom;
257
		return profiles;
235
	}
258
	}
236
259
237
	public synchronized boolean isExporting() {
260
	private List loadProfiles(IRSEPersistenceProvider persistenceProvider) {
238
		return _currentState == STATE_EXPORTING;
261
		List profiles = new ArrayList(10);
239
	}
262
		String[] profileNames = persistenceProvider.getSavedProfileNames();
240
263
		for (int i = 0; i < profileNames.length; i++) {
241
	public synchronized boolean isImporting() {
264
			String profileName = profileNames[i];
242
		return _currentState == STATE_IMPORTING;
265
			ISystemProfile profile = load(persistenceProvider, profileName);
266
			profiles.add(profile);
267
		}
268
		return profiles;
243
	}
269
	}
244
270
245
	/**
271
	/**
246
	 * Loads and restores RSE artifacts from the last session
272
	 * Loads a profile of the given name using the given persistence provider. If the provider cannot 
247
	 * @param profileManager
273
	 * find a profile with that name, return null.
248
	 * @return true if the profiles are loaded
274
	 * @param provider the persistence provider that understands the name and can produce a profile.
249
	 */
275
	 * @param profileName the name of the profile to produce
250
	private boolean load(ISystemProfileManager profileManager) {
276
	 * @return the profile or null
251
		boolean successful = true;
277
	 */
252
		synchronized(this) {
278
	private synchronized ISystemProfile load(IRSEPersistenceProvider provider, String profileName) {
253
			if (isExporting() || isImporting()) {
279
		ISystemProfile profile = null;
254
				successful = false;
280
		if (_currentState == STATE_NONE) {
255
			} else {
281
			_currentState = STATE_LOADING;
256
				setState(STATE_IMPORTING);
282
			RSEDOM dom = provider.loadRSEDOM(profileName, null);
257
			}
283
			if (dom != null) {
258
		}
284
				SystemProfileManager.getDefault().setRestoring(true);
259
		if(successful) {
285
				profile = _importer.restoreProfile(dom);
260
			try {
286
				SystemProfileManager.getDefault().setRestoring(false);
261
				IProject project = getRemoteSystemsProject();
287
				profile.setPersistenceProvider(provider);
262
				if (!project.isSynchronized(IResource.DEPTH_ONE)) project.refreshLocal(IResource.DEPTH_ONE, null);
288
				cleanTree(profile);
263
				IRSEPersistenceProvider persistenceProvider = getRSEPersistenceProvider();
264
				String[] profileNames = persistenceProvider.getSavedProfileNames();
265
				for (int i = 0; i < profileNames.length; i++) {
266
					String profileName = profileNames[i];
267
					RSEDOM dom = importRSEDOM(profileName);
268
					if (dom != null) {
269
						ISystemProfile restoredProfile = _importer.restoreProfile(profileManager, dom);
270
						if (restoredProfile == null) {
271
							successful = false;
272
						}
273
					} else {
274
						successful = false;
275
					}
276
				}
277
			} catch (Exception e) {
278
				e.printStackTrace();
279
				successful = false;
280
			} finally {
281
				setState(STATE_NONE);
282
			}
289
			}
290
			_currentState = STATE_NONE;
283
		}
291
		}
284
		return successful;
292
		return profile;
285
	}
286
287
	public void registerRSEPersistenceProvider(String id, IRSEPersistenceProvider provider) {
288
		loadedProviders.put(id, provider);
289
	}
290
291
	public boolean restore(ISystemFilterPool filterPool) {
292
		//System.out.println("restore filterpool");
293
		// DWD function Is this method really needed?
294
		return false;
295
	}
293
	}
296
294
	
297
	public boolean restore(ISystemHostPool connectionPool) {
298
		return false;
299
	}
300
301
	public boolean restore(ISystemProfileManager profileManager) {
302
		return load(profileManager);
303
	}
304
305
	public ISystemFilterPool restoreFilterPool(String name) {
306
		//System.out.println("restore filter pool "+name);
307
		// DWD function is this method really needed?
308
		return null;
309
	}
310
311
	/**
312
	 * Creates a filter pool manager for a particular SubSystemConfiguration and SystemProfile. Called
313
	 * "restore" for historcal reasons.
314
	 * @param profile the profile that will own this ISystemFilterPoolManager. There is one of these per profile.
315
	 * @param logger the logging object for logging errors. Each ISystemFilterPoolManager has one of these.
316
	 * @param caller The creator/owner of this ISystemFilterPoolManager, this ends up being a SubSystemConfiguration. 
317
	 * @param name the name of the manager to restore. File name is derived from it when saving to one file.
318
	 * @return the "restored" manager.
319
	 */
320
	public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name) {
321
		SystemFilterPoolManager mgr = SystemFilterPoolManager.createManager(profile);
322
		mgr.initialize(logger, caller, name); // core data
323
		mgr.setWasRestored(false); // managers are not "restored from disk" since they are not persistent of themselves
324
		return mgr;
325
	}
326
327
	/**
295
	/**
328
	 * Restore a connection of a given name from disk...
296
	 * Writes a profile to a DOM and schedules writing of that DOM to disk.
329
	 */
330
	protected IHost restoreHost(ISystemHostPool hostPool, String connectionName) throws Exception {
331
		/*
332
		 * FIXME //System.out.println("in SystemConnectionPoolImpl#restore for
333
		 * connection " + connectionName); String fileName =
334
		 * getRootSaveFileName(connectionName);
335
		 * //System.out.println(".......fileName = " + fileName);
336
		 * //System.out.println(".......folderName = " +
337
		 * getConnectionFolder(connectionName).getName()); java.util.List ext =
338
		 * getMOFHelpers().restore(getConnectionFolder(connectionName),fileName);
339
		 *  // should be exactly one profile... Iterator iList = ext.iterator();
340
		 * SystemConnection connection = (SystemConnection)iList.next(); if
341
		 * (connection != null) { if
342
		 * (!connection.getAliasName().equalsIgnoreCase(connectionName)) {
343
		 * RSEUIPlugin.logDebugMessage(this.getClass().getName(),"Incorrect
344
		 * alias name found in connections.xmi file for " + connectionName+".
345
		 * Name was reset"); connection.setAliasName(connectionName); // just in
346
		 * case! } internalAddConnection(connection); } return connection;
347
		 */
348
		return null;
349
	}
350
351
	/**
352
	 * Restore a profile of a given name from disk...
353
	 */
354
	protected ISystemProfile restoreProfile(ISystemProfileManager mgr, String name) throws Exception {
355
		/*
356
		 * FIXME String fileName = mgr.getRootSaveFileName(name); java.util.List
357
		 * ext = null;//FIXME
358
		 * getMOFHelpers().restore(SystemResourceManager.getProfileFolder(name),fileName);
359
		 *  // should be exactly one profile... Iterator iList = ext.iterator();
360
		 * SystemProfile profile = (SystemProfile)iList.next();
361
		 * mgr.initialize(profile, name); return profile;
362
		 */
363
		return null;
364
	}
365
366
	/**
367
	 * Writes the RSE model to a DOM and schedules writing of that DOM to disk.
368
	 * May, in fact, update an existing DOM instead of creating a new one.
297
	 * May, in fact, update an existing DOM instead of creating a new one.
369
	 * If in the process of importing, skip writing.
298
	 * If in the process of importing, skip writing.
370
	 * @return true if the profile is written to a DOM
299
	 * @return true if the profile is written to a DOM
371
	 */
300
	 */
372
	private boolean save(ISystemProfile profile, boolean force) {
301
	private synchronized boolean save(ISystemProfile profile, boolean force) {
373
		boolean result = false;
302
		if (_currentState == STATE_NONE) {
374
		boolean acquiredLock = false;
303
			_currentState = STATE_SAVING;
375
		synchronized(this) {
304
			IRSEPersistenceProvider provider = profile.getPersistenceProvider();
376
			if (!isImporting()) {
305
			if (provider == null) {
377
				setState(STATE_EXPORTING);
306
				provider = getDefaultPersistenceProvider();
378
				acquiredLock = true;
307
				profile.setPersistenceProvider(provider);
379
			}
308
			}
380
		}
309
			RSEDOM dom = null; // DWD should do merge, but does not handle deletes properly yet
381
		if (acquiredLock) {
310
			dom = _exporter.createRSEDOM(profile, force);
382
			try {
311
			cleanTree(profile);
383
				RSEDOM dom = exportRSEDOM(profile, true); // DWD should do merge, but does not handle deletes properly yet
312
			if (dom.needsSave()) {
384
				result = true;
313
				Job job = dom.getSaveJob();
385
				if (dom.needsSave()) {
314
				if (job == null) {
386
					Job job = dom.getSaveJob();
315
					job = new SaveRSEDOMJob(dom, getDefaultPersistenceProvider());
387
					if (job == null) {
316
					dom.setSaveJob(job);
388
						job = new SaveRSEDOMJob(dom, getRSEPersistenceProvider());
389
						dom.setSaveJob(job);
390
					}
391
					job.schedule(3000); // three second delay
392
				}
317
				}
393
			} finally {
318
				job.schedule(3000); // three second delay
394
				setState(STATE_NONE);
395
			}
319
			}
320
			_currentState = STATE_NONE;
396
		}
321
		}
397
		return result;
322
		return true;
398
	}
323
	}
399
324
	
400
	private synchronized void setState(int state) {
325
	private void cleanTree(IRSEPersistableContainer node) {
401
		_currentState = state;
326
		node.setWasRestored(true);
327
		node.setTainted(false);
328
		node.setDirty(false);
329
		IRSEPersistableContainer[] children = node.getPersistableChildren();
330
		for (int i = 0; i < children.length; i++) {
331
			IRSEPersistableContainer child = children[i];
332
			cleanTree(child);
333
		}
402
	}
334
	}
403
335
404
}
336
}
(-)src/org/eclipse/rse/core/subsystems/AbstractConnectorService.java (-2 / +4 lines)
Lines 22-28 Link Here
22
import java.util.Vector;
22
import java.util.Vector;
23
23
24
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.rse.core.RSECorePlugin;
26
import org.eclipse.rse.core.model.IHost;
25
import org.eclipse.rse.core.model.IHost;
27
import org.eclipse.rse.core.model.IRSEPersistableContainer;
26
import org.eclipse.rse.core.model.IRSEPersistableContainer;
28
import org.eclipse.rse.core.model.RSEModelObject;
27
import org.eclipse.rse.core.model.RSEModelObject;
Lines 253-259 Link Here
253
	
252
	
254
	public IRSEPersistableContainer[] getPersistableChildren() {
253
	public IRSEPersistableContainer[] getPersistableChildren() {
255
		List children = new ArrayList(20);
254
		List children = new ArrayList(20);
256
		children.add(getRemoteServerLauncherProperties());
255
		IServerLauncherProperties launcherProperties = getRemoteServerLauncherProperties();
256
		if (launcherProperties != null) {
257
			children.add(getRemoteServerLauncherProperties());
258
		}
257
		children.addAll(_registeredSubSystems);
259
		children.addAll(_registeredSubSystems);
258
		IRSEPersistableContainer[] result = new IRSEPersistableContainer[children.size()];
260
		IRSEPersistableContainer[] result = new IRSEPersistableContainer[children.size()];
259
		children.toArray(result);
261
		children.toArray(result);
(-)src/org/eclipse/rse/core/subsystems/AbstractDelegatingConnectorService.java (-17 / +12 lines)
Lines 18-24 Link Here
18
import org.eclipse.rse.core.model.IHost;
18
import org.eclipse.rse.core.model.IHost;
19
import org.eclipse.rse.core.model.IPropertySet;
19
import org.eclipse.rse.core.model.IPropertySet;
20
import org.eclipse.rse.core.model.IRSEPersistableContainer;
20
import org.eclipse.rse.core.model.IRSEPersistableContainer;
21
import org.eclipse.rse.core.model.RSEPersistableObject;
22
21
23
public abstract class AbstractDelegatingConnectorService implements IDelegatingConnectorService 
22
public abstract class AbstractDelegatingConnectorService implements IDelegatingConnectorService 
24
{
23
{
Lines 752-757 Link Here
752
		return false;
751
		return false;
753
	}
752
	}
754
	
753
	
754
	/* (non-Javadoc)
755
	 * @see org.eclipse.rse.core.model.IRSEPersistableContainer#isTainted()
756
	 */
755
	public boolean isTainted() {
757
	public boolean isTainted() {
756
		IConnectorService conServ = getRealConnectorService();
758
		IConnectorService conServ = getRealConnectorService();
757
		if (conServ != null)
759
		if (conServ != null)
Lines 761-766 Link Here
761
		return false;
763
		return false;
762
	}
764
	}
763
	
765
	
766
	/* (non-Javadoc)
767
	 * @see org.eclipse.rse.core.model.IRSEPersistableContainer#setTainted(boolean)
768
	 */
764
	public void setTainted(boolean flag) {
769
	public void setTainted(boolean flag) {
765
		IConnectorService conServ = getRealConnectorService();
770
		IConnectorService conServ = getRealConnectorService();
766
		if (conServ != null)
771
		if (conServ != null)
Lines 769-794 Link Here
769
		}
774
		}
770
	}
775
	}
771
	
776
	
777
	/* (non-Javadoc)
778
	 * @see org.eclipse.rse.core.model.IRSEPersistableContainer#getPersistableParent()
779
	 */
772
	public IRSEPersistableContainer getPersistableParent() {
780
	public IRSEPersistableContainer getPersistableParent() {
773
		return getHost();
781
		return getHost();
774
	}
782
	}
775
	
783
	
776
	public void beginRestore() {
784
	/* (non-Javadoc)
777
		IConnectorService conServ = getRealConnectorService();
785
	 * @see org.eclipse.rse.core.model.IRSEPersistableContainer#getPersistableChildren()
778
		if (conServ != null)
786
	 */
779
		{
780
			conServ.beginRestore();
781
		}
782
	}
783
	
784
	public void endRestore() {
785
		IConnectorService conServ = getRealConnectorService();
786
		if (conServ != null)
787
		{
788
			conServ.endRestore();
789
		}
790
	}
791
	
792
	public IRSEPersistableContainer[] getPersistableChildren() {
787
	public IRSEPersistableContainer[] getPersistableChildren() {
793
		IConnectorService conServ = getRealConnectorService();
788
		IConnectorService conServ = getRealConnectorService();
794
		if (conServ != null)
789
		if (conServ != null)
(-)src/org/eclipse/rse/core/SystemResourceManager.java (-14 lines)
Lines 274-290 Link Here
274
    }
274
    }
275
    */
275
    */
276
276
277
    // -----------------------------------
278
    // GET A SPECIFIC PROFILE FOLDER...
279
    // -----------------------------------
280
    /**
281
     * Get profiles folder for a given profile
282
     */
283
    public static IFolder getProfileFolder(ISystemProfile profile)
284
    {
285
    	return getProfileFolder(profile.getName());
286
    }
287
288
    /**
277
    /**
289
     * Get profiles folder for a given profile name
278
     * Get profiles folder for a given profile name
290
     */
279
     */
Lines 293-301 Link Here
293
        return getResourceHelpers().getOrCreateFolder(getRemoteSystemsProject(),profileName);      	
282
        return getResourceHelpers().getOrCreateFolder(getRemoteSystemsProject(),profileName);      	
294
    }
283
    }
295
284
296
297
  
298
   
299
    /*
285
    /*
300
     * --------------------------------------------------------------------------------------------------------------------------------
286
     * --------------------------------------------------------------------------------------------------------------------------------
301
     * USER ACTIONS SUBTREE FOLDER METHODS...
287
     * USER ACTIONS SUBTREE FOLDER METHODS...
(-)src/org/eclipse/rse/persistence/IRSEPersistenceManager.java (-43 / +48 lines)
Lines 16-99 Link Here
16
16
17
package org.eclipse.rse.persistence;
17
package org.eclipse.rse.persistence;
18
18
19
import org.eclipse.rse.core.filters.ISystemFilterPool;
20
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
21
import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider;
22
import org.eclipse.rse.core.model.ISystemHostPool;
23
import org.eclipse.rse.core.model.ISystemProfile;
19
import org.eclipse.rse.core.model.ISystemProfile;
24
import org.eclipse.rse.core.model.ISystemProfileManager;
25
import org.eclipse.rse.logging.Logger;
26
20
27
public interface IRSEPersistenceManager {
21
public interface IRSEPersistenceManager {
28
22
29
	public boolean commit(ISystemFilterPoolManager filterPoolManager);
30
31
	/**
23
	/**
32
	 * Save all connections in the connection pool
24
	 * Save a particular profile. If the profile has an existing persistence provider
33
	 * @param connectionPool
25
	 * it is saved by that persistence provider. If the profile has no persistence provider
26
	 * then the default persistence provider is used.
27
	 * @param profile the profile to save
34
	 * @return true if successful
28
	 * @return true if successful
35
	 */
29
	 */
36
	public boolean commit(ISystemHostPool connectionPool);
30
	public boolean commitProfile(ISystemProfile profile);
37
31
38
	/**
32
	/**
39
	 * Save this profile
33
	 * Save all profiles.
40
	 * @param profile
41
	 * @return true if successful
34
	 * @return true if successful
42
	 */
35
	 */
43
	public boolean commit(ISystemProfile profile);
36
	public boolean commitProfiles();
44
37
45
	/**
38
	/**
46
	 * Save all profiles
39
	 * Restore all profiles
47
	 * @param profileManager
40
	 * @return an array of restored profiles.
48
	 * @return true if successful
41
	 */
42
	public ISystemProfile[] restoreProfiles();
43
44
	/**
45
	 * Restore a profiles particular provider by name.
46
	 * @param provider a persistence provider
47
	 * @param profileName the name of the profile to restore
48
	 * @return the restored profile or null if no profile of that name is known to this provider.
49
	 */
49
	 */
50
	public boolean commit(ISystemProfileManager profileManager);
50
	public ISystemProfile restoreProfile(IRSEPersistenceProvider provider, String profileName);
51
51
52
	/**
52
	/**
53
	 * Delete the persistent form of a profile.
53
	 * Delete the persistent form of a profile.
54
	 * @param persistenceProvider the persistence provider to use to delete the profile.
55
	 * If this is null the default persistence provider is used.
54
	 * @param profileName The name of the profile to delete
56
	 * @param profileName The name of the profile to delete
55
	 */
57
	 */
56
	public void deleteProfile(String profileName);
58
	public void deleteProfile(IRSEPersistenceProvider persistenceProvider, String profileName);
57
59
	
58
	public boolean isExporting();
60
	/**
59
61
	 * Migrates a profile to a new persistence provider. It will delete the persistent form known to its previous
60
	public boolean isImporting();
62
	 * persistence provider. If the new provider and the previous provider are the same this does nothing.
63
	 * @param profile the system profile to be migrated
64
	 * @param persistenceProvider the persistence provider to which this profile will be migrated.
65
	 */
66
	public void migrateProfile(ISystemProfile profile, IRSEPersistenceProvider persistenceProvider);
61
67
62
	/**
68
	/**
63
	 * Register the persistence provider to be used when saving and restoring RSE doms.
69
	 * Register the persistence provider to be used when saving and restoring RSE doms.
64
	 * The provider is registered under the provided id.
70
	 * The provider is registered under the provided id.
71
	 * If the id has already been registered, this provider replaces the previous provider
72
	 * with that id.
65
	 * @param id the provider id.
73
	 * @param id the provider id.
66
	 * @param provider the provider.
74
	 * @param provider the provider.
67
	 */
75
	 */
68
	public void registerRSEPersistenceProvider(String id, IRSEPersistenceProvider provider);
76
	public void registerPersistenceProvider(String id, IRSEPersistenceProvider provider);
69
77
	
70
	/**
78
	/**
71
	 * Restore all the filters for the filter pool
79
	 * @return an array of persistence provider ids known to this workbench. These may have been
72
	 * @param filterPool
80
	 * provided by extension point or by registering them using 
73
	 * @return true if sucessful
81
	 * {@link #registerPersistenceProvider(String, IRSEPersistenceProvider)}
74
	 */
82
	 */
75
	public boolean restore(ISystemFilterPool filterPool);
83
	public String[] getPersistenceProviderIds();
76
84
	
77
	/**
85
	/**
78
	 * Restore all connections in the connection pool
86
	 * Retrieves the persistence provider named by a particular id. It can return null if there
79
	 * @param connectionPool
87
	 * is no provider known by that id. This may have the effect of activating the plugin that 
80
	 * @return true if successful
88
	 * contains this provider.
89
	 * @param id the id of the persistence provider to locate
90
	 * @return the persistence provider or null
81
	 */
91
	 */
82
	public boolean restore(ISystemHostPool connectionPool);
92
	public IRSEPersistenceProvider getPersistenceProvider(String id);
83
93
84
	/**
94
	/**
85
	 * Restore all profiles
95
	 * @return true if this instance of the persistence manager is currently exporting a profile.
86
	 * @param profileManager
87
	 * @return true if successful
88
	 */
96
	 */
89
	public boolean restore(ISystemProfileManager profileManager);
97
	public boolean isExporting();
90
98
91
	/**
99
	/**
92
	 * Restore the filter pool
100
	 * @return true if this instance of the persistence manager is currently importing a profile.
93
	 * @param name
94
	 * @return the filter pool if successful
95
	 */
101
	 */
96
	public ISystemFilterPool restoreFilterPool(String name);
102
	public boolean isImporting();
97
103
98
	public ISystemFilterPoolManager restoreFilterPoolManager(ISystemProfile profile, Logger logger, ISystemFilterPoolManagerProvider caller, String name);
99
}
104
}
(-)src/org/eclipse/rse/internal/core/model/SystemProfileManager.java (+476 lines)
Added Link Here
1
/********************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight, Kushal Munir, 
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * 
13
 * Contributors:
14
 * David Dykstal (IBM) - created and used RSEPreferencesManager
15
 *                     - moved SystemPreferencesManager to a new plugin
16
 ********************************************************************************/
17
18
package org.eclipse.rse.internal.core.model;
19
20
import java.util.ArrayList;
21
import java.util.Arrays;
22
import java.util.Iterator;
23
import java.util.List;
24
import java.util.Vector;
25
26
import org.eclipse.rse.core.RSECorePlugin;
27
import org.eclipse.rse.core.RSEPreferencesManager;
28
import org.eclipse.rse.core.model.ISystemProfile;
29
import org.eclipse.rse.core.model.ISystemProfileManager;
30
import org.eclipse.rse.logging.Logger;
31
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
32
33
/**
34
 * A class that manages a list of SystemProfile objects.
35
 * This should be used as a singleton.
36
 */
37
public class SystemProfileManager implements ISystemProfileManager {
38
39
	private List _profiles = new ArrayList(10);
40
//	private String[] profileNames = null;
41
//	private Vector profileNamesVector = null;
42
	private static SystemProfileManager singleton = null;
43
	private boolean restoring = false;
44
45
	/**
46
	 * Ordinarily there should be only one instance of a SystemProfileManager
47
	 * created on the system, so the static method {@link #getDefault()} is 
48
	 * preferred to using this.
49
	 */
50
	private SystemProfileManager() {
51
	}
52
53
	/**
54
	 * @return (and create if necessary) the singleton instance of this class.
55
	 */
56
	public static SystemProfileManager getDefault() {
57
		if (singleton == null) {
58
			singleton = new SystemProfileManager();
59
			RSECorePlugin.getThePersistenceManager().restoreProfiles();
60
		}
61
		return singleton;
62
	}
63
64
	/**
65
	 * Clear the default after a team sychronization say
66
	 */
67
	public static void clearDefault() {
68
		singleton = null;
69
	}
70
71
	/**
72
	 * Create a new profile with the given name, and add to the list.
73
	 * The name must be unique within the existing list.
74
	 * <p>
75
	 * The underlying folder is created in the file system.
76
	 * <p>
77
	 * @param name What to name this profile
78
	 * @param makeActive true if this profile is to be added to the active profile list.
79
	 * @return new profile, or null if name not unique.
80
	 * @see ISystemProfileManager#createSystemProfile(String, boolean)
81
	 */
82
	public ISystemProfile createSystemProfile(String name, boolean makeActive) {
83
		ISystemProfile existingProfile = getSystemProfile(name);
84
		if (existingProfile != null) {
85
			deleteSystemProfile(existingProfile, false); // replace the existing one with a new profile
86
		}
87
		ISystemProfile newProfile = internalCreateSystemProfile(name);
88
		if (makeActive) {
89
			RSEPreferencesManager.addActiveProfile(name);
90
			((SystemProfile) newProfile).setActive(makeActive);
91
		}
92
		newProfile.commit();
93
		return newProfile;
94
	}
95
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#makeSystemProfileActive(org.eclipse.rse.core.model.ISystemProfile, boolean)
98
	 */
99
	public void makeSystemProfileActive(ISystemProfile profile, boolean makeActive) {
100
		boolean wasActive = isSystemProfileActive(profile.getName());
101
		if (wasActive && !makeActive)
102
			RSEPreferencesManager.deleteActiveProfile(profile.getName());
103
		else if (makeActive && !wasActive) RSEPreferencesManager.addActiveProfile(profile.getName());
104
		((SystemProfile) profile).setActive(makeActive);
105
	}
106
107
	/* (non-Javadoc)
108
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfiles()
109
	 */
110
	public ISystemProfile[] getSystemProfiles() {
111
		return getSystemProfiles(!restoring);
112
	}
113
114
	/* (non-Javadoc)
115
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfileNames()
116
	 */
117
	public String[] getSystemProfileNames() {
118
		ISystemProfile[] profiles = getSystemProfiles();
119
		String[] profileNames = new String[profiles.length];
120
		for (int i = 0; i < profiles.length; i++) {
121
			ISystemProfile profile = profiles[i];
122
			profileNames[i] = profile.getName();
123
		}
124
		return profileNames;
125
//		if (profileNames == null) {
126
//			ISystemProfile[] profiles = getSystemProfiles();
127
//			profileNames = new String[profiles.length];
128
//			for (int idx = 0; idx < profiles.length; idx++)
129
//				profileNames[idx] = profiles[idx].getName();
130
//		}
131
//		return profileNames;
132
	}
133
134
	/* (non-Javadoc)
135
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfileNamesVector()
136
	 */
137
	public Vector getSystemProfileNamesVector() {
138
		List names = Arrays.asList(getSystemProfileNames()); 
139
		Vector result = new Vector(names.size());
140
		result.addAll(names);
141
		return result;
142
//		if (profileNamesVector == null) {
143
//			ISystemProfile[] profiles = getSystemProfiles();
144
//			profileNamesVector = new Vector(profiles.length);
145
//			for (int idx = 0; idx < profiles.length; idx++)
146
//				profileNamesVector.addElement(profiles[idx].getName());
147
//		}
148
//		return profileNamesVector;
149
	}
150
151
//	/**
152
//	 * Something changed so invalide cache of profiles so it will be regenerated
153
//	 */
154
//	protected void invalidateCache() {
155
//		profileNames = null;
156
//		profileNamesVector = null;
157
//	}
158
//
159
	/* (non-Javadoc)
160
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfile(java.lang.String)
161
	 */
162
	public ISystemProfile getSystemProfile(String name) {
163
		ISystemProfile[] profiles = getSystemProfiles();
164
		if ((profiles == null) || (profiles.length == 0)) return null;
165
		ISystemProfile match = null;
166
		for (int idx = 0; (match == null) && (idx < profiles.length); idx++)
167
			if (profiles[idx].getName().equals(name)) match = profiles[idx];
168
		return match;
169
	}
170
171
	/* (non-Javadoc)
172
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#renameSystemProfile(org.eclipse.rse.core.model.ISystemProfile, java.lang.String)
173
	 */
174
	public void renameSystemProfile(ISystemProfile profile, String newName) {
175
		boolean isActive = isSystemProfileActive(profile.getName());
176
		String oldName = profile.getName();
177
		profile.setName(newName);
178
		if (isActive) RSEPreferencesManager.renameActiveProfile(oldName, newName);
179
//		invalidateCache();
180
		// FIXME RSEUIPlugin.getThePersistenceManager().save(this);
181
	}
182
183
	/* (non-Javadoc)
184
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#deleteSystemProfile(org.eclipse.rse.core.model.ISystemProfile, boolean)
185
	 */
186
	public void deleteSystemProfile(ISystemProfile profile, boolean persist) {
187
		String oldName = profile.getName();
188
		boolean isActive = isSystemProfileActive(oldName);
189
		_profiles.remove(profile);
190
		/* FIXME in EMF the profiles are "owned" by the Resource, and only referenced by the profile manager,
191
		 * so just removing it from the manager is not enough, it must also be removed from its resource.
192
		 * No longer needed since EMF is not in use.
193
		 * Resource res = profile.eResource();
194
		 * if (res != null)
195
		 * res.getContents().remove(profile);
196
		 */
197
		if (isActive) RSEPreferencesManager.deleteActiveProfile(oldName);
198
//		invalidateCache();
199
		if (persist) {
200
			IRSEPersistenceProvider provider = profile.getPersistenceProvider();
201
			RSECorePlugin.getThePersistenceManager().deleteProfile(provider, oldName);
202
		}
203
	}
204
205
	/* (non-Javadoc)
206
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#cloneSystemProfile(org.eclipse.rse.core.model.ISystemProfile, java.lang.String)
207
	 */
208
	public ISystemProfile cloneSystemProfile(ISystemProfile profile, String newName) {
209
		ISystemProfile newProfile = createSystemProfile(newName, false);
210
		return newProfile;
211
	}
212
213
	/* (non-Javadoc)
214
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#isSystemProfileActive(java.lang.String)
215
	 */
216
	public boolean isSystemProfileActive(String profileName) {
217
		String[] activeProfiles = getActiveSystemProfileNames();
218
		boolean match = false;
219
		for (int idx = 0; !match && (idx < activeProfiles.length); idx++) {
220
			if (activeProfiles[idx].equals(profileName)) match = true;
221
		}
222
		return match;
223
	}
224
225
	/* (non-Javadoc)
226
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getActiveSystemProfiles()
227
	 */
228
	public ISystemProfile[] getActiveSystemProfiles() {
229
		String[] profileNames = getActiveSystemProfileNames();
230
		ISystemProfile[] profiles = new ISystemProfile[profileNames.length];
231
		for (int idx = 0; idx < profileNames.length; idx++) {
232
			profiles[idx] = getOrCreateSystemProfile(profileNames[idx]);
233
			((SystemProfile) profiles[idx]).setActive(true);
234
		}
235
		return profiles;
236
	}
237
238
	/* (non-Javadoc)
239
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getActiveSystemProfileNames()
240
	 */
241
	public String[] getActiveSystemProfileNames() {
242
		String[] activeProfileNames = RSEPreferencesManager.getActiveProfiles();
243
		// dy: defect 48355, need to sync this with the actual profile list.  If the user
244
		// imports old preference settings or does a team sync and a profile is deleted then
245
		// it is possible an active profile no longer exists.
246
		// String[] systemProfileNames = getSystemProfileNames();
247
		ISystemProfile[] systemProfiles = getSystemProfiles();
248
		boolean found;
249
		boolean found_team = false;
250
		boolean found_private = false;
251
		boolean changed = false;
252
		String defaultProfileName = RSEPreferencesManager.getDefaultPrivateSystemProfileName();
253
254
		for (int activeIdx = 0; activeIdx < activeProfileNames.length; activeIdx++) {
255
			// skip Team and Private profiles
256
			String activeProfileName = activeProfileNames[activeIdx];
257
			if (activeProfileName.equals(defaultProfileName)) {
258
				found_private = true;
259
			} else if (activeProfileName.equals(RSEPreferencesManager.getDefaultTeamProfileName())) {
260
				found_team = true;
261
			} else {
262
				found = false;
263
				for (int systemIdx = 0; systemIdx < systemProfiles.length && !found; systemIdx++) {
264
					if (activeProfileNames[activeIdx].equals(systemProfiles[systemIdx].getName())) {
265
						found = true;
266
					}
267
				}
268
269
				if (!found) {
270
					// The active profile no longer exists so remove it from the active list
271
					RSEPreferencesManager.deleteActiveProfile(activeProfileNames[activeIdx]);
272
					changed = true;
273
				}
274
			}
275
		}
276
277
		for (int systemIdx = 0; systemIdx < systemProfiles.length && !changed; systemIdx++) {
278
			boolean matchesBoth = false;
279
			String name = systemProfiles[systemIdx].getName();
280
281
			for (int activeIdx = 0; activeIdx < activeProfileNames.length && !matchesBoth; activeIdx++) {
282
				String aname = activeProfileNames[activeIdx];
283
				if (name.equals(aname)) {
284
					matchesBoth = true;
285
				}
286
287
			}
288
			if (!matchesBoth && found_private) {
289
				if (systemProfiles[systemIdx].isActive() || systemProfiles[systemIdx].isDefaultPrivate()) {
290
					RSEPreferencesManager.addActiveProfile(name);
291
					RSEPreferencesManager.deleteActiveProfile(RSECorePlugin.getLocalMachineName());
292
					activeProfileNames = RSEPreferencesManager.getActiveProfiles();
293
				}
294
			}
295
		}
296
297
		// the active profiles list needed to be changed because of an external update, also
298
		// check if Default profile needs to be added back to the list
299
		if (changed || !found_team || !found_private) {
300
			if (systemProfiles.length == 0) {
301
				// First time user, make sure default is in the active list, the only time it wouldn't
302
				// be is if the pref_store.ini was modified (because the user imported old preferences)
303
				if (!found_team) {
304
					RSEPreferencesManager.addActiveProfile(RSEPreferencesManager.getDefaultTeamProfileName());
305
					changed = true;
306
				}
307
308
				if (!found_private) {
309
					RSEPreferencesManager.addActiveProfile(RSECorePlugin.getLocalMachineName());
310
					changed = true;
311
				}
312
			} else {
313
				ISystemProfile defaultProfile = getDefaultPrivateSystemProfile();
314
				if (defaultProfile != null && !found_private) {
315
					RSEPreferencesManager.addActiveProfile(defaultProfile.getName());
316
					changed = true;
317
				}
318
			}
319
320
			if (changed) {
321
				activeProfileNames = RSEPreferencesManager.getActiveProfiles();
322
			}
323
		}
324
325
		return activeProfileNames;
326
	}
327
328
	/**
329
	 * @return the profile names currently selected by the user as "active" profiles
330
	 */
331
	public Vector getActiveSystemProfileNamesVector() {
332
		String[] profileNames = RSEPreferencesManager.getActiveProfiles();
333
		Vector v = new Vector(profileNames.length);
334
		for (int idx = 0; idx < profileNames.length; idx++)
335
			v.addElement(profileNames[idx]);
336
		return v;
337
	}
338
339
	/* (non-Javadoc)
340
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getActiveSystemProfilePosition(java.lang.String)
341
	 */
342
	public int getActiveSystemProfilePosition(String profileName) {
343
		String[] profiles = getActiveSystemProfileNames();
344
		int pos = -1;
345
		for (int idx = 0; (pos < 0) && (idx < profiles.length); idx++) {
346
			if (profiles[idx].equals(profileName)) pos = idx;
347
		}
348
		return pos;
349
	}
350
351
	/* (non-Javadoc)
352
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getDefaultPrivateSystemProfile()
353
	 */
354
	public ISystemProfile getDefaultPrivateSystemProfile() {
355
		return getSystemProfile(RSEPreferencesManager.getDefaultPrivateSystemProfileName());
356
	}
357
358
	/* (non-Javadoc)
359
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getDefaultTeamSystemProfile()
360
	 */
361
	public ISystemProfile getDefaultTeamSystemProfile() {
362
		return getSystemProfile(RSEPreferencesManager.getDefaultTeamProfileName());
363
	}
364
365
	/* (non-Javadoc)
366
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getProfiles()
367
	 */
368
	public List getProfiles() {
369
		List result = new ArrayList(_profiles.size());
370
		result.addAll(_profiles);
371
		return result;
372
	}
373
	
374
	/* (non-Javadoc)
375
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSize()
376
	 */
377
	public int getSize() {
378
		return _profiles.size();
379
	}
380
	
381
	/**
382
	 * Adds a newly restored profile to this manager
383
	 * @param profile the profile to add
384
	 */
385
	public void addSystemProfile(ISystemProfile profile) {
386
		_profiles.add(profile);
387
		String name = profile.getName();
388
		if (profile.isActive()) {
389
			RSEPreferencesManager.addActiveProfile(name);
390
		}
391
		profile.setDefaultPrivate(name.equalsIgnoreCase(RSEPreferencesManager.getDefaultPrivateSystemProfileName()));
392
	}
393
394
	private ISystemProfile[] getSystemProfiles(boolean ensureDefaultPrivateProfileExists) {
395
		if (ensureDefaultPrivateProfileExists) {
396
			ensureDefaultPrivateProfile();
397
		}
398
		ISystemProfile[] result = new ISystemProfile[_profiles.size()];
399
		_profiles.toArray(result);
400
		return result;
401
	}
402
403
	public void setRestoring(boolean flag) {
404
		restoring = flag;
405
	}
406
407
	private ISystemProfile internalCreateSystemProfile(String name) {
408
			ISystemProfile newProfile = new SystemProfile();
409
			newProfile.setName(name);
410
			newProfile.setProfileManager(this);
411
			_profiles.add(newProfile);
412
	//		invalidateCache();
413
			newProfile.setDefaultPrivate(name.equalsIgnoreCase(RSEPreferencesManager.getDefaultPrivateSystemProfileName()));
414
			return newProfile;
415
		}
416
417
	private void ensureDefaultPrivateProfile() {
418
		// Ensure that one Profile is the default Profile - defect 48995 NH	
419
		boolean defaultProfileExists = false;
420
		for (Iterator z = _profiles.iterator(); z.hasNext() && !defaultProfileExists;) {
421
			ISystemProfile profile = (ISystemProfile) z.next();
422
			defaultProfileExists = profile.isDefaultPrivate();
423
		}
424
		if (!defaultProfileExists) {
425
			// find one with the right name
426
			String defaultPrivateProfileName = RSEPreferencesManager.getDefaultPrivateSystemProfileName();
427
			for (Iterator z = _profiles.iterator(); z.hasNext() && !defaultProfileExists;) {
428
				ISystemProfile profile = (ISystemProfile) z.next();
429
				if (profile.getName().equals(defaultPrivateProfileName)) {
430
					profile.setDefaultPrivate(true);
431
					defaultProfileExists = true;
432
				}
433
			}
434
		}
435
		if (!defaultProfileExists) {
436
			// Find the first profile that is not the Team profile and make it the default private profile 	
437
			String defaultTeamProfileName = RSEPreferencesManager.getDefaultTeamProfileName();
438
			for (Iterator z = _profiles.iterator(); z.hasNext() && !defaultProfileExists;) {
439
				ISystemProfile profile = (ISystemProfile) z.next();
440
				if (!profile.getName().equals(defaultTeamProfileName)) {
441
					profile.setDefaultPrivate(true);
442
					defaultProfileExists = true;
443
				}
444
			}
445
		}
446
		if (!defaultProfileExists) {
447
			// If Team is the only profile - then put a message in the log and create the default private profile
448
			Logger logger = RSECorePlugin.getDefault().getLogger();
449
			logger.logWarning("Only one Profile Team exists - there is no Default Profile"); //$NON-NLS-1$
450
			createDefaultPrivateProfile();
451
		}
452
	}
453
454
	private void createDefaultPrivateProfile() {
455
		ISystemProfile profile = new SystemProfile();
456
		String initProfileName = RSEPreferencesManager.getDefaultPrivateSystemProfileName();
457
		profile.setName(initProfileName);
458
		profile.setDefaultPrivate(true);
459
		_profiles = new ArrayList();
460
		_profiles.add(profile);
461
	}
462
463
	/**
464
	 * Instantiate a user profile given its name.
465
	 * @param userProfileName the name of the profile to find or create
466
	 * @return the profile that was found or created.
467
	 */
468
	private ISystemProfile getOrCreateSystemProfile(String userProfileName) {
469
		ISystemProfile userProfile = getSystemProfile(userProfileName);
470
		if (userProfile == null) {
471
			userProfile = internalCreateSystemProfile(userProfileName);
472
		}
473
		return userProfile;
474
	}
475
476
}
(-)src/org/eclipse/rse/internal/core/model/SystemProfile.java (+240 lines)
Added Link Here
1
/********************************************************************************
2
 * Copyright (c) 2002, 2007 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight, Kushal Munir, 
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * 
13
 * Contributors:
14
 * David Dykstal (IBM) - 142806: refactoring persistence framework
15
 ********************************************************************************/
16
17
package org.eclipse.rse.internal.core.model;
18
import java.util.Vector;
19
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.rse.core.RSECorePlugin;
23
import org.eclipse.rse.core.filters.ISystemFilterPool;
24
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
25
import org.eclipse.rse.core.model.IHost;
26
import org.eclipse.rse.core.model.IRSEPersistableContainer;
27
import org.eclipse.rse.core.model.ISystemProfile;
28
import org.eclipse.rse.core.model.ISystemProfileManager;
29
import org.eclipse.rse.core.model.ISystemRegistry;
30
import org.eclipse.rse.core.model.RSEModelObject;
31
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
32
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
33
34
/**
35
 * A profile contains hosts and filter pools. It is the unit of save/restore for RSE model 
36
 * objects. All model objects are contained within a profile.
37
 */
38
public class SystemProfile extends RSEModelObject implements ISystemProfile, IAdaptable
39
{
40
41
	private ISystemProfileManager mgr = null;
42
	private IRSEPersistenceProvider provider = null;
43
	private boolean isActive = true;
44
	private String name = null;
45
	private boolean defaultPrivate = false;
46
47
	/**
48
	 * Default constructor
49
	 */
50
	protected SystemProfile() 
51
	{
52
		super();
53
	}
54
	
55
	public SystemProfile(String name, boolean isActive) {
56
		this.name = name;
57
		this.isActive = isActive;
58
	}
59
60
	/**
61
     * Set the in-memory pointer back to the parent system profile manager
62
     */
63
    public void setProfileManager(ISystemProfileManager mgr)
64
    {
65
    	this.mgr = mgr;
66
    }
67
68
    /**
69
     * Get the in-memory pointer back to the parent system profile manager
70
     */
71
    public ISystemProfileManager getProfileManager()
72
    {
73
    	return mgr;
74
    }
75
    
76
    /**
77
     * Convenience method for create a new connection within this profile.
78
     * Shortcut for {@link ISystemRegistry#createHost(String,String,String,String)}
79
     */
80
    public IHost createHost(String systemType, String connectionName, String hostName, String description) throws Exception
81
    {
82
		return RSECorePlugin.getDefault().getSystemRegistry().createHost(getName(), systemType, connectionName,  hostName, description);
83
    }
84
    
85
	/**
86
	 * Return all connections for this profile
87
	 */
88
	public IHost[] getHosts()
89
	{
90
		return RSECorePlugin.getDefault().getSystemRegistry().getHostsByProfile(this);
91
	}
92
93
	/**
94
	 * Return all filter pools for this profile
95
	 */
96
	public ISystemFilterPool[] getFilterPools()
97
	{
98
		ISubSystemConfiguration[] ssFactories = RSECorePlugin.getDefault().getSystemRegistry().getSubSystemConfigurations();
99
		Vector poolsVector = new Vector();
100
		for (int idx = 0; idx < ssFactories.length; idx++)
101
		{
102
			ISystemFilterPoolManager poolMgr = ssFactories[idx].getFilterPoolManager(this);
103
			ISystemFilterPool[] pools = poolMgr.getSystemFilterPools();
104
			for (int ydx=0; ydx<pools.length; ydx++)
105
			{
106
				poolsVector.add(pools[ydx]);
107
			}
108
		}
109
		ISystemFilterPool[] allPools = new ISystemFilterPool[poolsVector.size()];
110
		poolsVector.toArray(allPools);
111
		return allPools;
112
	}
113
114
	/**
115
	 * Return all filter pools for this profile, scoped by a given subsystem factory
116
	 */
117
	public ISystemFilterPool[] getFilterPools(ISubSystemConfiguration ssf)
118
	{
119
		ISystemFilterPoolManager poolMgr = ssf.getFilterPoolManager(this);
120
		return poolMgr.getSystemFilterPools();
121
	}
122
123
	/**
124
	 * Return true if this profile is currently active.
125
	 */
126
	public boolean isActive()
127
	{
128
		return isActive;
129
	}
130
	/**
131
	 * Reset whether this profile is currently active.
132
	 */
133
	public void setActive(boolean active)
134
	{
135
		this.isActive = active;
136
		setDirty(true);
137
	}
138
139
    /**
140
 	 * This is the method required by the IAdaptable interface.
141
	 * Given an adapter class type, return an object castable to the type, or
142
	 *  null if this is not possible.
143
	 */
144
    public Object getAdapter(Class adapterType)
145
    {
146
   	    return Platform.getAdapterManager().getAdapter(this, adapterType);	
147
    }   
148
149
    //For debugging
150
	public String toString() {
151
		String result = getName();
152
		if (result == null) {
153
			StringBuffer buf = new StringBuffer(super.toString());
154
			buf.append("Profile(name: "); //$NON-NLS-1$
155
			buf.append(name);
156
			buf.append(", defaultPrivate: "); //$NON-NLS-1$
157
			buf.append(defaultPrivate);
158
			buf.append(')');
159
			result = buf.toString();
160
		}
161
		return result;
162
	}
163
164
	/**
165
	 * @generated This field/method will be replaced during code generation 
166
	 */
167
	public String getName()
168
	{
169
		return name;
170
	}
171
	
172
	public String getDescription()
173
	{
174
		return RSEModelResources.RESID_MODELOBJECTS_PROFILE_DESCRIPTION;
175
	}
176
177
	/**
178
	 * @generated This field/method will be replaced during code generation.
179
	 */
180
	public void setName(String newName)
181
	{
182
		name = newName;
183
		setDirty(true);
184
	}
185
186
	/**
187
	 * @generated This field/method will be replaced during code generation 
188
	 * Is this profile created automatically, and is it the profile
189
	 * that is unique for this developer?
190
	 */
191
	public boolean isDefaultPrivate()
192
	{
193
		return defaultPrivate;
194
	}
195
196
	/**
197
	 * @generated This field/method will be replaced during code generation.
198
	 */
199
	public void setDefaultPrivate(boolean newDefaultPrivate)
200
	{
201
		defaultPrivate = newDefaultPrivate;
202
		setDirty(true);
203
	}
204
	
205
	public boolean commit() 
206
	{
207
		return RSECorePlugin.getThePersistenceManager().commitProfile(this);
208
	}
209
	
210
	/**
211
	 * The SystemProfile is the top of the persistence hierarchy.
212
	 * @return null
213
	 */
214
	public IRSEPersistableContainer getPersistableParent() {
215
		return null;
216
	}
217
	
218
	public IRSEPersistableContainer[] getPersistableChildren() {
219
		ISystemFilterPool[] pools = getFilterPools();
220
		IHost[] hosts = getHosts();
221
		IRSEPersistableContainer[] result = new IRSEPersistableContainer[pools.length + hosts.length];
222
		System.arraycopy(pools, 0, result, 0, pools.length);
223
		System.arraycopy(hosts, 0, result, pools.length, hosts.length);
224
		return result;	
225
	}
226
	
227
	/* (non-Javadoc)
228
	 * @see org.eclipse.rse.core.model.ISystemProfile#getPersistenceProvider()
229
	 */
230
	public IRSEPersistenceProvider getPersistenceProvider() {
231
		return provider;
232
	}
233
	
234
	public void setPersistenceProvider(IRSEPersistenceProvider provider) {
235
		this.provider = provider;
236
	}
237
	
238
	
239
240
}
(-)UI/org/eclipse/rse/ui/validators/ValidatorUniqueString.java (-12 / +5 lines)
Lines 124-144 Link Here
124
	/**
124
	/**
125
	 * Reset the existing names list. 
125
	 * Reset the existing names list. 
126
	 */
126
	 */
127
	public void setExistingNamesList(Vector existingList)
127
	public void setExistingNamesList(Vector newList)
128
	{		
128
	{		
129
		if (existingList == null)
129
		if (newList == null)
130
		  this.existingList = null;
130
		  existingList = null;
131
		else
131
		else
132
		{
132
		{
133
		  String newList[] = new String[existingList.size()];
133
		  existingList = new String[newList.size()];
134
		  for (int idx=0; idx<existingList.size(); idx++)
134
		  newList.toArray(existingList);
135
		  {
136
		     if (!caseSensitive)
137
		       newList[idx] = existingList.elementAt(idx).toString().toLowerCase();		
138
		     else
139
		       newList[idx] = existingList.elementAt(idx).toString(); 
140
		  }
141
		  init(newList, true); // don't redo the toLowerCase calls		
142
		}
135
		}
143
	}
136
	}
144
	/**
137
	/**
(-)UI/org/eclipse/rse/internal/ui/view/team/SystemTeamViewMakeActiveProfileAction.java (-2 / +2 lines)
Lines 19-25 Link Here
19
import org.eclipse.rse.core.model.ISystemProfile;
19
import org.eclipse.rse.core.model.ISystemProfile;
20
import org.eclipse.rse.core.model.ISystemProfileManager;
20
import org.eclipse.rse.core.model.ISystemProfileManager;
21
import org.eclipse.rse.core.model.ISystemRegistry;
21
import org.eclipse.rse.core.model.ISystemRegistry;
22
import org.eclipse.rse.internal.model.SystemProfileManager;
22
import org.eclipse.rse.internal.core.model.SystemProfileManager;
23
import org.eclipse.rse.internal.ui.SystemResources;
23
import org.eclipse.rse.internal.ui.SystemResources;
24
import org.eclipse.rse.ui.ISystemContextMenuConstants;
24
import org.eclipse.rse.ui.ISystemContextMenuConstants;
25
import org.eclipse.rse.ui.ISystemIconConstants;
25
import org.eclipse.rse.ui.ISystemIconConstants;
Lines 60-66 Link Here
60
		if (!(currsel instanceof ISystemProfile))
60
		if (!(currsel instanceof ISystemProfile))
61
			return false;
61
			return false;
62
		ISystemProfile profile = (ISystemProfile)currsel;
62
		ISystemProfile profile = (ISystemProfile)currsel;
63
		ISystemProfileManager mgr = SystemProfileManager.getSystemProfileManager();
63
		ISystemProfileManager mgr = SystemProfileManager.getDefault();
64
		boolean allActive = true;
64
		boolean allActive = true;
65
		while (profile != null)
65
		while (profile != null)
66
		{
66
		{
(-)UI/org/eclipse/rse/internal/ui/view/team/SystemTeamViewMakeInActiveProfileAction.java (-2 / +2 lines)
Lines 19-25 Link Here
19
import org.eclipse.rse.core.model.ISystemProfile;
19
import org.eclipse.rse.core.model.ISystemProfile;
20
import org.eclipse.rse.core.model.ISystemProfileManager;
20
import org.eclipse.rse.core.model.ISystemProfileManager;
21
import org.eclipse.rse.core.model.ISystemRegistry;
21
import org.eclipse.rse.core.model.ISystemRegistry;
22
import org.eclipse.rse.internal.model.SystemProfileManager;
22
import org.eclipse.rse.internal.core.model.SystemProfileManager;
23
import org.eclipse.rse.internal.ui.SystemResources;
23
import org.eclipse.rse.internal.ui.SystemResources;
24
import org.eclipse.rse.ui.ISystemContextMenuConstants;
24
import org.eclipse.rse.ui.ISystemContextMenuConstants;
25
import org.eclipse.rse.ui.ISystemIconConstants;
25
import org.eclipse.rse.ui.ISystemIconConstants;
Lines 60-66 Link Here
60
		if (!(currsel instanceof ISystemProfile))
60
		if (!(currsel instanceof ISystemProfile))
61
			return false;
61
			return false;
62
		ISystemProfile profile = (ISystemProfile)currsel;
62
		ISystemProfile profile = (ISystemProfile)currsel;
63
		ISystemProfileManager mgr = SystemProfileManager.getSystemProfileManager();
63
		ISystemProfileManager mgr = SystemProfileManager.getDefault();
64
		boolean allInActive = true;
64
		boolean allInActive = true;
65
		while (profile != null)
65
		while (profile != null)
66
		{
66
		{
(-)UI/org/eclipse/rse/internal/ui/view/team/SystemTeamViewProfileAdapter.java (-1 / +5 lines)
Lines 16-26 Link Here
16
16
17
package org.eclipse.rse.internal.ui.view.team;
17
package org.eclipse.rse.internal.ui.view.team;
18
import java.util.Hashtable;
18
import java.util.Hashtable;
19
import java.util.Vector;
19
20
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.jface.resource.ImageDescriptor;
23
import org.eclipse.jface.resource.ImageDescriptor;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.viewers.IStructuredSelection;
25
import org.eclipse.rse.core.RSECorePlugin;
24
import org.eclipse.rse.core.SystemResourceManager;
26
import org.eclipse.rse.core.SystemResourceManager;
25
import org.eclipse.rse.core.model.ISystemProfile;
27
import org.eclipse.rse.core.model.ISystemProfile;
26
import org.eclipse.rse.internal.ui.SystemResources;
28
import org.eclipse.rse.internal.ui.SystemResources;
Lines 371-377 Link Here
371
	 */
373
	 */
372
    public ISystemValidator getNameValidator(Object element)
374
    public ISystemValidator getNameValidator(Object element)
373
    {
375
    {
374
		return new ValidatorProfileName(RSEUIPlugin.getTheSystemRegistry().getSystemProfileManager().getSystemProfileNamesVector());
376
    	Vector names = RSECorePlugin.getDefault().getSystemRegistry().getSystemProfileManager().getSystemProfileNamesVector();
377
    	ISystemValidator validator = new ValidatorProfileName(names);
378
		return validator;
375
    }
379
    }
376
    /**
380
    /**
377
     * Parent override.
381
     * Parent override.
(-)UI/org/eclipse/rse/internal/ui/view/team/SystemTeamViewActiveProfileAction.java (-2 / +2 lines)
Lines 19-25 Link Here
19
import org.eclipse.rse.core.model.ISystemProfile;
19
import org.eclipse.rse.core.model.ISystemProfile;
20
import org.eclipse.rse.core.model.ISystemProfileManager;
20
import org.eclipse.rse.core.model.ISystemProfileManager;
21
import org.eclipse.rse.core.model.ISystemRegistry;
21
import org.eclipse.rse.core.model.ISystemRegistry;
22
import org.eclipse.rse.internal.model.SystemProfileManager;
22
import org.eclipse.rse.internal.core.model.SystemProfileManager;
23
import org.eclipse.rse.internal.ui.SystemResources;
23
import org.eclipse.rse.internal.ui.SystemResources;
24
import org.eclipse.rse.ui.ISystemContextMenuConstants;
24
import org.eclipse.rse.ui.ISystemContextMenuConstants;
25
import org.eclipse.rse.ui.ISystemIconConstants;
25
import org.eclipse.rse.ui.ISystemIconConstants;
Lines 61-67 Link Here
61
		ISystemProfile profile = (ISystemProfile)getFirstSelection();
61
		ISystemProfile profile = (ISystemProfile)getFirstSelection();
62
		if (profile == null)
62
		if (profile == null)
63
		  return false;
63
		  return false;
64
		ISystemProfileManager mgr = SystemProfileManager.getSystemProfileManager();
64
		ISystemProfileManager mgr = SystemProfileManager.getDefault();
65
		// todo... we need to have two actions, one to make active, and one to make inactive.
65
		// todo... we need to have two actions, one to make active, and one to make inactive.
66
		while (profile != null)
66
		while (profile != null)
67
		{
67
		{
(-)subsystems/org/eclipse/rse/core/subsystems/SubSystemConfiguration.java (-12 / +8 lines)
Lines 55-61 Link Here
55
import org.eclipse.rse.core.references.IRSEBaseReferencingObject;
55
import org.eclipse.rse.core.references.IRSEBaseReferencingObject;
56
import org.eclipse.rse.internal.core.filters.SystemFilterPoolWrapperInformation;
56
import org.eclipse.rse.internal.core.filters.SystemFilterPoolWrapperInformation;
57
import org.eclipse.rse.internal.core.filters.SystemFilterStartHere;
57
import org.eclipse.rse.internal.core.filters.SystemFilterStartHere;
58
import org.eclipse.rse.internal.model.SystemProfileManager;
58
import org.eclipse.rse.internal.core.model.SystemProfileManager;
59
import org.eclipse.rse.internal.ui.SystemPropertyResources;
59
import org.eclipse.rse.internal.ui.SystemPropertyResources;
60
import org.eclipse.rse.internal.ui.SystemResources;
60
import org.eclipse.rse.internal.ui.SystemResources;
61
import org.eclipse.rse.internal.ui.subsystems.SubSystemConfigurationProxyAdapter;
61
import org.eclipse.rse.internal.ui.subsystems.SubSystemConfigurationProxyAdapter;
Lines 773-779 Link Here
773
	 */
773
	 */
774
	public ISystemProfile getSystemProfile(String name)
774
	public ISystemProfile getSystemProfile(String name)
775
	{
775
	{
776
		return SystemProfileManager.getSystemProfileManager().getSystemProfile(name);
776
		return SystemProfileManager.getDefault().getSystemProfile(name);
777
	}
777
	}
778
778
779
	/**
779
	/**
Lines 1001-1008 Link Here
1001
		}
1001
		}
1002
		if ((subsystems == null) || (subsystems.length != getSubSystemList().size()))
1002
		if ((subsystems == null) || (subsystems.length != getSubSystemList().size()))
1003
		{
1003
		{
1004
			java.util.List alist = null;
1004
			List alist = null;
1005
			if (SystemProfileManager.getSystemProfileManager().getSystemProfileNamesVector().size() > 0) // 42913
1005
			if (SystemProfileManager.getDefault().getSize() > 0) // 42913
1006
				alist = getSubSystemList();
1006
				alist = getSubSystemList();
1007
			if (alist == null)
1007
			if (alist == null)
1008
				return new ISubSystem[0];
1008
				return new ISubSystem[0];
Lines 1803-1814 Link Here
1803
	 */
1803
	 */
1804
	protected boolean isUserPrivateProfile(ISystemFilterPoolManager mgr)
1804
	protected boolean isUserPrivateProfile(ISystemFilterPoolManager mgr)
1805
	{
1805
	{
1806
		//System.out.println("mgr name = " + mgr.getName());
1806
		ISystemProfile profile = mgr.getSystemProfile();
1807
		//String name = mgr.getName();
1807
		boolean result = profile.isDefaultPrivate() || mgr.getName().equalsIgnoreCase("private"); //$NON-NLS-1$
1808
		//return name.equalsIgnoreCase("private");
1808
		return result;
1809
		ISystemProfile profile = getSystemProfile(mgr);
1810
		//System.out.println("Testing for user private profile for mgr " + mgr.getName() + ": " + profile.isDefaultPrivate());;
1811
		return profile.isDefaultPrivate() || mgr.getName().equalsIgnoreCase("private"); //$NON-NLS-1$
1812
	}
1809
	}
1813
1810
1814
	/**
1811
	/**
Lines 2538-2544 Link Here
2538
	public ISubSystem[] testForActiveReferences(ISystemProfile profile)
2535
	public ISubSystem[] testForActiveReferences(ISystemProfile profile)
2539
	{
2536
	{
2540
		Vector v = new Vector();
2537
		Vector v = new Vector();
2541
		ISystemProfileManager profileMgr = SystemProfileManager.getSystemProfileManager();
2538
		ISystemProfileManager profileMgr = SystemProfileManager.getDefault();
2542
		ISystemFilterPoolManager sfpm = getFilterPoolManager(profile);
2539
		ISystemFilterPoolManager sfpm = getFilterPoolManager(profile);
2543
		String profileName = profile.getName();
2540
		String profileName = profile.getName();
2544
		if (sfpm != null)
2541
		if (sfpm != null)
Lines 3022-3028 Link Here
3022
		if (filterPoolManagerList == null)
3019
		if (filterPoolManagerList == null)
3023
		{
3020
		{
3024
			filterPoolManagerList = new ArrayList();
3021
			filterPoolManagerList = new ArrayList();
3025
			//FIXMEnew EObjectContainmenteList(SystemFilterPoolManager.class, this, SubsystemsPackage.SUB_SYSTEM_FACTORY__FILTER_POOL_MANAGER_LIST);
3026
		}
3022
		}
3027
		return filterPoolManagerList;
3023
		return filterPoolManagerList;
3028
	}
3024
	}
(-)subsystems/org/eclipse/rse/core/subsystems/SubSystem.java (-1 / +6 lines)
Lines 3249-3256 Link Here
3249
	}
3249
	}
3250
	
3250
	
3251
	public IRSEPersistableContainer[] getPersistableChildren() {
3251
	public IRSEPersistableContainer[] getPersistableChildren() {
3252
		IRSEPersistableContainer[] result = null;
3252
		ISystemFilterPoolReferenceManager manager = getSystemFilterPoolReferenceManager();
3253
		ISystemFilterPoolReferenceManager manager = getSystemFilterPoolReferenceManager();
3253
		IRSEPersistableContainer[] result = manager.getReferencedSystemFilterPools();
3254
		if (manager != null) {
3255
			result = manager.getReferencedSystemFilterPools();
3256
		} else {
3257
			result = new IRSEPersistableContainer[0];
3258
		}
3254
		return result;
3259
		return result;
3255
	}
3260
	}
3256
	
3261
	
(-)UI/org/eclipse/rse/internal/ui/SystemProfileForm.java (-6 / +2 lines)
Lines 17-29 Link Here
17
package org.eclipse.rse.internal.ui;
17
package org.eclipse.rse.internal.ui;
18
import org.eclipse.jface.wizard.WizardPage;
18
import org.eclipse.jface.wizard.WizardPage;
19
import org.eclipse.rse.core.model.ISystemProfile;
19
import org.eclipse.rse.core.model.ISystemProfile;
20
import org.eclipse.rse.internal.model.SystemProfileManager;
21
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
20
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
22
import org.eclipse.rse.ui.RSEUIPlugin;
23
import org.eclipse.rse.ui.SystemWidgetHelpers;
21
import org.eclipse.rse.ui.SystemWidgetHelpers;
24
import org.eclipse.rse.ui.dialogs.SystemPromptDialog;
22
import org.eclipse.rse.ui.dialogs.SystemPromptDialog;
25
import org.eclipse.rse.ui.messages.ISystemMessageLine;
23
import org.eclipse.rse.ui.messages.ISystemMessageLine;
26
import org.eclipse.rse.ui.validators.ISystemValidator;
24
import org.eclipse.rse.ui.validators.ISystemValidator;
25
import org.eclipse.rse.ui.validators.ValidatorFactory;
27
import org.eclipse.rse.ui.validators.ValidatorProfileName;
26
import org.eclipse.rse.ui.validators.ValidatorProfileName;
28
import org.eclipse.swt.events.ModifyEvent;
27
import org.eclipse.swt.events.ModifyEvent;
29
import org.eclipse.swt.events.ModifyListener;
28
import org.eclipse.swt.events.ModifyListener;
Lines 79-88 Link Here
79
		this.showVerbiage = showVerbiage;
78
		this.showVerbiage = showVerbiage;
80
		callerInstanceOfWizardPage = (caller instanceof WizardPage);
79
		callerInstanceOfWizardPage = (caller instanceof WizardPage);
81
		callerInstanceOfSystemPromptDialog = (caller instanceof SystemPromptDialog);	
80
		callerInstanceOfSystemPromptDialog = (caller instanceof SystemPromptDialog);	
82
		
81
		nameValidator = ValidatorFactory.getProfileNameValidator(profile.getName());
83
		// FIXME cast to SystemProfileManager is temporary to get at api - need to use an adapter for getting validators
84
		SystemProfileManager mgr = (SystemProfileManager)RSEUIPlugin.getTheSystemRegistry().getSystemProfileManager();
85
		nameValidator = mgr.getProfileNameValidator(profile);
86
	}
82
	}
87
	
83
	
88
	/**
84
	/**
(-)model/org/eclipse/rse/internal/model/SystemProfile.java (-233 lines)
Removed Link Here
1
/********************************************************************************
2
 * Copyright (c) 2002, 2007 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight, Kushal Munir, 
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * 
13
 * Contributors:
14
 * David Dykstal (IBM) - 142806: refactoring persistence framework
15
 ********************************************************************************/
16
17
package org.eclipse.rse.internal.model;
18
import java.util.Vector;
19
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.rse.core.filters.ISystemFilterPool;
23
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
24
import org.eclipse.rse.core.model.IHost;
25
import org.eclipse.rse.core.model.IRSEPersistableContainer;
26
import org.eclipse.rse.core.model.ISystemProfile;
27
import org.eclipse.rse.core.model.ISystemProfileManager;
28
import org.eclipse.rse.core.model.ISystemRegistry;
29
import org.eclipse.rse.core.model.RSEModelObject;
30
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
31
import org.eclipse.rse.internal.core.model.RSEModelResources;
32
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
33
import org.eclipse.rse.ui.RSEUIPlugin;
34
35
/**
36
 * A profile contains hosts and filter pools. It is the unit of save/restore for RSE model 
37
 * objects. All model objects are contained within a profile.
38
 */
39
public class SystemProfile extends RSEModelObject implements ISystemProfile, IAdaptable
40
{
41
42
	private ISystemProfileManager mgr;
43
	private IRSEPersistenceProvider provider;
44
	private boolean active;
45
	private String name = null;
46
	private boolean defaultPrivate = false;
47
48
	/**
49
	 * Default constructor
50
	 */
51
	protected SystemProfile() 
52
	{
53
		super();
54
	}
55
56
	/**
57
     * Set the in-memory pointer back to the parent system profile manager
58
     */
59
    public void setProfileManager(ISystemProfileManager mgr)
60
    {
61
    	this.mgr = mgr;
62
    }
63
64
    /**
65
     * Get the in-memory pointer back to the parent system profile manager
66
     */
67
    public ISystemProfileManager getProfileManager()
68
    {
69
    	return mgr;
70
    }
71
    
72
    /**
73
     * Convenience method for create a new connection within this profile.
74
     * Shortcut for {@link ISystemRegistry#createHost(String,String,String,String)}
75
     */
76
    public IHost createHost(String systemType, String connectionName, String hostName, String description) throws Exception
77
    {
78
		return RSEUIPlugin.getTheSystemRegistry().createHost(getName(), systemType, connectionName,  hostName, description);
79
    }
80
    
81
	/**
82
	 * Return all connections for this profile
83
	 */
84
	public IHost[] getHosts()
85
	{
86
		return RSEUIPlugin.getTheSystemRegistry().getHostsByProfile(this);
87
	}
88
89
	/**
90
	 * Return all filter pools for this profile
91
	 */
92
	public ISystemFilterPool[] getFilterPools()
93
	{
94
		ISubSystemConfiguration[] ssFactories = RSEUIPlugin.getTheSystemRegistry().getSubSystemConfigurations();
95
		Vector poolsVector = new Vector();
96
		for (int idx = 0; idx < ssFactories.length; idx++)
97
		{
98
			ISystemFilterPoolManager poolMgr = ssFactories[idx].getFilterPoolManager(this);
99
			ISystemFilterPool[] pools = poolMgr.getSystemFilterPools();
100
			for (int ydx=0; ydx<pools.length; ydx++)
101
			{
102
				poolsVector.add(pools[ydx]);
103
			}
104
		}
105
		ISystemFilterPool[] allPools = new ISystemFilterPool[poolsVector.size()];
106
		poolsVector.toArray(allPools);
107
		return allPools;
108
	}
109
110
	/**
111
	 * Return all filter pools for this profile, scoped by a given subsystem factory
112
	 */
113
	public ISystemFilterPool[] getFilterPools(ISubSystemConfiguration ssf)
114
	{
115
		ISystemFilterPoolManager poolMgr = ssf.getFilterPoolManager(this);
116
		return poolMgr.getSystemFilterPools();
117
	}
118
119
	/**
120
	 * Return true if this profile is currently active.
121
	 */
122
	public boolean isActive()
123
	{
124
		return active;
125
	}
126
	/**
127
	 * Reset whether this profile is currently active.
128
	 */
129
	public void setActive(boolean active)
130
	{
131
		this.active = active;
132
	}
133
134
    /**
135
 	 * This is the method required by the IAdaptable interface.
136
	 * Given an adapter class type, return an object castable to the type, or
137
	 *  null if this is not possible.
138
	 */
139
    public Object getAdapter(Class adapterType)
140
    {
141
   	    return Platform.getAdapterManager().getAdapter(this, adapterType);	
142
    }   
143
144
    //For debugging
145
	public String toString() {
146
		String result = getName();
147
		if (result == null) {
148
			StringBuffer buf = new StringBuffer(super.toString());
149
			buf.append("Profile(name: "); //$NON-NLS-1$
150
			buf.append(name);
151
			buf.append(", defaultPrivate: "); //$NON-NLS-1$
152
			buf.append(defaultPrivate);
153
			buf.append(')');
154
			result = buf.toString();
155
		}
156
		return result;
157
	}
158
159
	/**
160
	 * @generated This field/method will be replaced during code generation 
161
	 */
162
	public String getName()
163
	{
164
		return name;
165
	}
166
	
167
	public String getDescription()
168
	{
169
		return RSEModelResources.RESID_MODELOBJECTS_PROFILE_DESCRIPTION;
170
	}
171
172
	/**
173
	 * @generated This field/method will be replaced during code generation.
174
	 */
175
	public void setName(String newName)
176
	{
177
		name = newName;
178
	}
179
180
	/**
181
	 * @generated This field/method will be replaced during code generation 
182
	 * Is this profile created automatically, and is it the profile
183
	 * that is unique for this developer?
184
	 */
185
	public boolean isDefaultPrivate()
186
	{
187
		return defaultPrivate;
188
	}
189
190
	/**
191
	 * @generated This field/method will be replaced during code generation.
192
	 */
193
	public void setDefaultPrivate(boolean newDefaultPrivate)
194
	{
195
		defaultPrivate = newDefaultPrivate;
196
	}
197
	
198
	public boolean commit() 
199
	{
200
		return RSEUIPlugin.getThePersistenceManager().commit(this);
201
	}
202
	
203
	/**
204
	 * The SystemProfile is the top of the persistence hierarchy.
205
	 * @return null
206
	 */
207
	public IRSEPersistableContainer getPersistableParent() {
208
		return null;
209
	}
210
	
211
	public IRSEPersistableContainer[] getPersistableChildren() {
212
		ISystemFilterPool[] pools = getFilterPools();
213
		IHost[] hosts = getHosts();
214
		IRSEPersistableContainer[] result = new IRSEPersistableContainer[pools.length + hosts.length];
215
		System.arraycopy(pools, 0, result, 0, pools.length);
216
		System.arraycopy(hosts, 0, result, pools.length, hosts.length);
217
		return result;	
218
	}
219
	
220
	/* (non-Javadoc)
221
	 * @see org.eclipse.rse.core.model.ISystemProfile#getPersistenceProvider()
222
	 */
223
	public IRSEPersistenceProvider getPersistenceProvider() {
224
		return provider;
225
	}
226
	
227
	public void setPersistenceProvider(IRSEPersistenceProvider provider) {
228
		this.provider = provider;
229
	}
230
	
231
	
232
233
}
(-)model/org/eclipse/rse/internal/model/SystemHostPool.java (-3 / +6 lines)
Lines 34-39 Link Here
34
import org.eclipse.rse.core.model.ISystemProfile;
34
import org.eclipse.rse.core.model.ISystemProfile;
35
import org.eclipse.rse.core.model.RSEModelObject;
35
import org.eclipse.rse.core.model.RSEModelObject;
36
import org.eclipse.rse.internal.core.model.RSEModelResources;
36
import org.eclipse.rse.internal.core.model.RSEModelResources;
37
import org.eclipse.rse.internal.core.model.SystemProfileManager;
37
import org.eclipse.rse.ui.RSESystemTypeAdapter;
38
import org.eclipse.rse.ui.RSESystemTypeAdapter;
38
39
39
40
Lines 102-108 Link Here
102
     */
103
     */
103
    public ISystemProfile getSystemProfile()
104
    public ISystemProfile getSystemProfile()
104
    {
105
    {
105
    	return SystemProfileManager.getSystemProfileManager().getSystemProfile(getName());
106
    	return SystemProfileManager.getDefault().getSystemProfile(getName());
106
    }	
107
    }	
107
	
108
	
108
	/**
109
	/**
Lines 408-414 Link Here
408
    	conn.deletingHost(); // let connection do any necessary cleanup
409
    	conn.deletingHost(); // let connection do any necessary cleanup
409
        getHostList().remove(conn);
410
        getHostList().remove(conn);
410
        setDirty(true);
411
        setDirty(true);
411
        RSECorePlugin.getThePersistenceManager().commit(conn.getSystemProfile());
412
        conn.getSystemProfile().commit();
412
    }
413
    }
413
414
414
    /**
415
    /**
Lines 648-654 Link Here
648
	 */
649
	 */
649
	public boolean commit()
650
	public boolean commit()
650
	{
651
	{
651
		return RSECorePlugin.getThePersistenceManager().commit(this);
652
		ISystemProfile profile = getSystemProfile();
653
		boolean result = profile.commit();
654
		return result;
652
	}
655
	}
653
656
654
	/**
657
	/**
(-)model/org/eclipse/rse/internal/model/SystemProfileManager.java (-529 lines)
Removed Link Here
1
/********************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation. All rights reserved.
3
 * This program and the accompanying materials are made available under the terms
4
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Initial Contributors:
8
 * The following IBM employees contributed to the Remote System Explorer
9
 * component that contains this file: David McKnight, Kushal Munir, 
10
 * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
11
 * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
 * 
13
 * Contributors:
14
 * David Dykstal (IBM) - created and used RSEPreferencesManager
15
 *                     - moved SystemPreferencesManager to a new plugin
16
 ********************************************************************************/
17
18
package org.eclipse.rse.internal.model;
19
20
import java.util.ArrayList;
21
import java.util.List;
22
import java.util.Vector;
23
24
import org.eclipse.rse.core.RSECorePlugin;
25
import org.eclipse.rse.core.RSEPreferencesManager;
26
import org.eclipse.rse.core.SystemBasePlugin;
27
import org.eclipse.rse.core.model.ISystemProfile;
28
import org.eclipse.rse.core.model.ISystemProfileManager;
29
import org.eclipse.rse.model.SystemStartHere;
30
import org.eclipse.rse.ui.RSEUIPlugin;
31
import org.eclipse.rse.ui.validators.ISystemValidator;
32
import org.eclipse.rse.ui.validators.ValidatorProfileName;
33
34
/**
35
 * A class that manages a list of SystemProfile objects.
36
 * This should be used as a singleton.
37
 */
38
public class SystemProfileManager implements ISystemProfileManager {
39
	private List _profiles = null;
40
	private String[] profileNames = null;
41
	private Vector profileNamesVector = null;
42
	private static ISystemProfileManager singleton = null;
43
	private static final String PROFILE_FILE_NAME = "profile"; //$NON-NLS-1$
44
45
	/**
46
	 * Ordinarily there should be only one instance of a SystemProfileManager
47
	 * created on the system, so the static method {@link #getSystemProfileManager()} is 
48
	 * preferred to using this.
49
	 */
50
	private SystemProfileManager() {
51
		super();
52
	}
53
54
	/**
55
	 * @return (and create if necessary) the singleton instance of this class.
56
	 */
57
	public static ISystemProfileManager getSystemProfileManager() {
58
		if (singleton == null) {
59
			singleton = new SystemProfileManager();
60
			RSEUIPlugin.getThePersistenceManager().restore(singleton); // restores all of RSE
61
		}
62
		return singleton;
63
	}
64
65
	/**
66
	 * Clear the default after a team sychronization say
67
	 */
68
	public static void clearDefault() {
69
		singleton = null;
70
	}
71
72
	/**
73
	 * Create a new profile with the given name, and add to the list.
74
	 * The name must be unique within the existing list.
75
	 * <p>
76
	 * The underlying folder is created in the file system.
77
	 * <p>
78
	 * @param name What to name this profile
79
	 * @param makeActive true if this profile is to be added to the active profile list.
80
	 * @return new profile, or null if name not unique.
81
	 * @see ISystemProfileManager#createSystemProfile(String, boolean)
82
	 */
83
	public ISystemProfile createSystemProfile(String name, boolean makeActive) {
84
		// FIXME - used to use MOF
85
		ISystemProfile existingProfile = getSystemProfile(name);
86
		if (existingProfile != null) {
87
			deleteSystemProfile(existingProfile, false); // replace the existing one with a new profile
88
		}
89
90
		ISystemProfile newProfile = internalCreateSystemProfileAndFolder(name);
91
		if (makeActive) {
92
			RSEPreferencesManager.addActiveProfile(name);
93
			((SystemProfile) newProfile).setActive(makeActive);
94
		}
95
		RSEUIPlugin.getThePersistenceManager().commit(this);
96
		return newProfile;
97
	}
98
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#makeSystemProfileActive(org.eclipse.rse.core.model.ISystemProfile, boolean)
101
	 */
102
	public void makeSystemProfileActive(ISystemProfile profile, boolean makeActive) {
103
		boolean wasActive = isSystemProfileActive(profile.getName());
104
		if (wasActive && !makeActive)
105
			RSEPreferencesManager.deleteActiveProfile(profile.getName());
106
		else if (makeActive && !wasActive) RSEPreferencesManager.addActiveProfile(profile.getName());
107
		((SystemProfile) profile).setActive(makeActive);
108
	}
109
110
	/*
111
	 * private version that avoids name collision check
112
	 */
113
	private ISystemProfile internalCreateSystemProfile(String name) {
114
		ISystemProfile profile = new SystemProfile();
115
		initialize(profile, name);
116
		profile.setDefaultPrivate(name.equalsIgnoreCase(RSEPreferencesManager.getDefaultPrivateSystemProfileName()));
117
		return profile;
118
	}
119
120
	/*
121
	 * private version that avoids name collision check
122
	 */
123
	private ISystemProfile internalCreateSystemProfileAndFolder(String name) {
124
		ISystemProfile profile = internalCreateSystemProfile(name);
125
		// FIXME This is where the old style folders get created for profiles.
126
		// This is no longer needed but 
127
		// SystemResourceManager.getProfileFolder(profile); // creates proj/profileName folder
128
		return profile;
129
	}
130
131
	/*
132
	 * private method to initialize state for new profile
133
	 */
134
	private void initialize(ISystemProfile profile, String name) {
135
		profile.setName(name);
136
		profile.setProfileManager(this);
137
		getProfiles().add(profile);
138
		invalidateCache();
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfiles()
143
	 */
144
	public ISystemProfile[] getSystemProfiles() {
145
		List profiles = getProfiles();
146
147
		// Ensure that one Profile is the default Profile - defect 48995 NH	
148
		boolean defaultProfileExist = false;
149
		for (int idx = 0; (!defaultProfileExist) && (idx < profiles.size()); idx++) {
150
			ISystemProfile profile = (ISystemProfile) profiles.get(idx);
151
			if (profile.isDefaultPrivate()) {
152
				defaultProfileExist = true;
153
			}
154
		}
155
		if (!defaultProfileExist) {
156
			// Check if the Profile exists with name same as the LocalMachine Name - this is the default we give
157
			// when creating connections. 	
158
			for (int idx = 0; (!defaultProfileExist) && (idx < profiles.size()); idx++) {
159
				ISystemProfile profile = (ISystemProfile) profiles.get(idx);
160
				String initProfileName = RSEPreferencesManager.getDefaultPrivateSystemProfileName();
161
				if (profile.getName().equalsIgnoreCase(initProfileName)) {
162
					profile.setDefaultPrivate(true);
163
					defaultProfileExist = true;
164
				}
165
			}
166
167
			// If did not find such a profile then the first profile found besides Team is set to be the default profile 	
168
			if (!defaultProfileExist) {
169
				for (int idx = 0; (!defaultProfileExist) && (idx < profiles.size()); idx++) {
170
					ISystemProfile profile = (ISystemProfile) profiles.get(idx);
171
					if (!profile.getName().equalsIgnoreCase(RSEPreferencesManager.getDefaultTeamProfileName())) {
172
						profile.setDefaultPrivate(true);
173
174
						RSEUIPlugin.getThePersistenceManager().commit(SystemStartHere.getSystemProfileManager());
175
						defaultProfileExist = true;
176
					}
177
				}
178
			}
179
			if (!defaultProfileExist) {
180
				// If Team is the only profile - then put a message in the log - do not make Team to be default
181
				if (profiles.size() == 1 && ((ISystemProfile) profiles.get(0)).getName().equalsIgnoreCase("Team")) //$NON-NLS-1$  
182
				{
183
					SystemBasePlugin.logWarning("Only one Profile Team exists - there is no Default Profile"); //$NON-NLS-1$
184
				} else {
185
					// sonething must have gone wrong - it should not come here
186
					SystemBasePlugin.logWarning("Something went wrong and the default profile is not set"); //$NON-NLS-1$
187
				}
188
			}
189
		}
190
		return (ISystemProfile[]) profiles.toArray(new ISystemProfile[profiles.size()]);
191
	}
192
193
	/* (non-Javadoc)
194
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfileNames()
195
	 */
196
	public String[] getSystemProfileNames() {
197
		if (profileNames == null) {
198
			ISystemProfile[] profiles = getSystemProfiles();
199
			profileNames = new String[profiles.length];
200
			for (int idx = 0; idx < profiles.length; idx++)
201
				profileNames[idx] = profiles[idx].getName();
202
		}
203
		return profileNames;
204
	}
205
206
	/* (non-Javadoc)
207
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfileNamesVector()
208
	 */
209
	public Vector getSystemProfileNamesVector() {
210
		if (profileNamesVector == null) {
211
			ISystemProfile[] profiles = getSystemProfiles();
212
			profileNamesVector = new Vector(profiles.length);
213
			for (int idx = 0; idx < profiles.length; idx++)
214
				profileNamesVector.addElement(profiles[idx].getName());
215
		}
216
		return profileNamesVector;
217
	}
218
219
	/**
220
	 * Something changed so invalide cache of profiles so it will be regenerated
221
	 */
222
	protected void invalidateCache() {
223
		//DY	profiles = null;
224
		profileNames = null;
225
		profileNamesVector = null;
226
	}
227
228
	/* (non-Javadoc)
229
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getSystemProfile(java.lang.String)
230
	 */
231
	public ISystemProfile getSystemProfile(String name) {
232
		ISystemProfile[] profiles = getSystemProfiles();
233
		if ((profiles == null) || (profiles.length == 0)) return null;
234
		ISystemProfile match = null;
235
		for (int idx = 0; (match == null) && (idx < profiles.length); idx++)
236
			if (profiles[idx].getName().equals(name)) match = profiles[idx];
237
		return match;
238
	}
239
240
	/* (non-Javadoc)
241
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#renameSystemProfile(org.eclipse.rse.core.model.ISystemProfile, java.lang.String)
242
	 */
243
	public void renameSystemProfile(ISystemProfile profile, String newName) {
244
		boolean isActive = isSystemProfileActive(profile.getName());
245
		String oldName = profile.getName();
246
		profile.setName(newName);
247
		if (isActive) RSEPreferencesManager.renameActiveProfile(oldName, newName);
248
		invalidateCache();
249
		// FIXME RSEUIPlugin.getThePersistenceManager().save(this);
250
	}
251
252
	/* (non-Javadoc)
253
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#deleteSystemProfile(org.eclipse.rse.core.model.ISystemProfile, boolean)
254
	 */
255
	public void deleteSystemProfile(ISystemProfile profile, boolean persist) {
256
		String oldName = profile.getName();
257
		boolean isActive = isSystemProfileActive(oldName);
258
		getProfiles().remove(profile);
259
		/* FIXME in EMF the profiles are "owned" by the Resource, and only referenced by the profile manager,
260
		 * so just removing it from the manager is not enough, it must also be removed from its resource.
261
		 * No longer needed since EMF is not in use.
262
		 * Resource res = profile.eResource();
263
		 * if (res != null)
264
		 * res.getContents().remove(profile);
265
		 */
266
		if (isActive) RSEPreferencesManager.deleteActiveProfile(oldName);
267
		invalidateCache();
268
		if (persist) {
269
			RSEUIPlugin.getThePersistenceManager().deleteProfile(oldName);
270
		}
271
	}
272
273
	/* (non-Javadoc)
274
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#cloneSystemProfile(org.eclipse.rse.core.model.ISystemProfile, java.lang.String)
275
	 */
276
	public ISystemProfile cloneSystemProfile(ISystemProfile profile, String newName) {
277
		ISystemProfile newProfile = createSystemProfile(newName, false);
278
		return newProfile;
279
	}
280
281
	/* (non-Javadoc)
282
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#isSystemProfileActive(java.lang.String)
283
	 */
284
	public boolean isSystemProfileActive(String profileName) {
285
		String[] activeProfiles = getActiveSystemProfileNames();
286
		boolean match = false;
287
		for (int idx = 0; !match && (idx < activeProfiles.length); idx++) {
288
			if (activeProfiles[idx].equals(profileName)) match = true;
289
		}
290
		return match;
291
	}
292
293
	/* (non-Javadoc)
294
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getActiveSystemProfiles()
295
	 */
296
	public ISystemProfile[] getActiveSystemProfiles() {
297
		String[] profileNames = getActiveSystemProfileNames();
298
		ISystemProfile[] profiles = new ISystemProfile[profileNames.length];
299
		for (int idx = 0; idx < profileNames.length; idx++) {
300
			profiles[idx] = getOrCreateSystemProfile(profileNames[idx]);
301
			((SystemProfile) profiles[idx]).setActive(true);
302
		}
303
		return profiles;
304
	}
305
306
	/* (non-Javadoc)
307
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getActiveSystemProfileNames()
308
	 */
309
	public String[] getActiveSystemProfileNames() {
310
		String[] activeProfileNames = RSEPreferencesManager.getActiveProfiles();
311
		// dy: defect 48355, need to sync this with the actual profile list.  If the user
312
		// imports old preference settings or does a team sync and a profile is deleted then
313
		// it is possible an active profile no longer exists.
314
		// String[] systemProfileNames = getSystemProfileNames();
315
		ISystemProfile[] systemProfiles = getSystemProfiles();
316
		boolean found;
317
		boolean found_team = false;
318
		boolean found_private = false;
319
		boolean changed = false;
320
		String defaultProfileName = RSEPreferencesManager.getDefaultPrivateSystemProfileName();
321
322
		for (int activeIdx = 0; activeIdx < activeProfileNames.length; activeIdx++) {
323
			// skip Team and Private profiles
324
			String activeProfileName = activeProfileNames[activeIdx];
325
			if (activeProfileName.equals(defaultProfileName)) {
326
				found_private = true;
327
			} else if (activeProfileName.equals(RSEPreferencesManager.getDefaultTeamProfileName())) {
328
				found_team = true;
329
			} else {
330
				found = false;
331
				for (int systemIdx = 0; systemIdx < systemProfiles.length && !found; systemIdx++) {
332
					if (activeProfileNames[activeIdx].equals(systemProfiles[systemIdx].getName())) {
333
						found = true;
334
					}
335
				}
336
337
				if (!found) {
338
					// The active profile no longer exists so remove it from the active list
339
					RSEPreferencesManager.deleteActiveProfile(activeProfileNames[activeIdx]);
340
					changed = true;
341
				}
342
			}
343
		}
344
345
		for (int systemIdx = 0; systemIdx < systemProfiles.length && !changed; systemIdx++) {
346
			boolean matchesBoth = false;
347
			String name = systemProfiles[systemIdx].getName();
348
349
			for (int activeIdx = 0; activeIdx < activeProfileNames.length && !matchesBoth; activeIdx++) {
350
				String aname = activeProfileNames[activeIdx];
351
				if (name.equals(aname)) {
352
					matchesBoth = true;
353
				}
354
355
			}
356
			if (!matchesBoth && found_private) {
357
				if (systemProfiles[systemIdx].isActive() || systemProfiles[systemIdx].isDefaultPrivate()) {
358
					RSEPreferencesManager.addActiveProfile(name);
359
					RSEPreferencesManager.deleteActiveProfile(RSECorePlugin.getLocalMachineName());
360
					activeProfileNames = RSEPreferencesManager.getActiveProfiles();
361
				}
362
			}
363
		}
364
365
		// the active profiles list needed to be changed because of an external update, also
366
		// check if Default profile needs to be added back to the list
367
		if (changed || !found_team || !found_private) {
368
			if (systemProfiles.length == 0) {
369
				// First time user, make sure default is in the active list, the only time it wouldn't
370
				// be is if the pref_store.ini was modified (because the user imported old preferences)
371
				if (!found_team) {
372
					RSEPreferencesManager.addActiveProfile(RSEPreferencesManager.getDefaultTeamProfileName());
373
					changed = true;
374
				}
375
376
				if (!found_private) {
377
					RSEPreferencesManager.addActiveProfile(RSECorePlugin.getLocalMachineName());
378
					changed = true;
379
				}
380
			} else {
381
				ISystemProfile defaultProfile = getDefaultPrivateSystemProfile();
382
				if (defaultProfile != null && !found_private) {
383
					RSEPreferencesManager.addActiveProfile(defaultProfile.getName());
384
					changed = true;
385
				}
386
			}
387
388
			if (changed) {
389
				activeProfileNames = RSEPreferencesManager.getActiveProfiles();
390
			}
391
		}
392
393
		return activeProfileNames;
394
	}
395
396
	/**
397
	 * @return the profile names currently selected by the user as "active" profiles
398
	 */
399
	public Vector getActiveSystemProfileNamesVector() {
400
		String[] profileNames = RSEPreferencesManager.getActiveProfiles();
401
		Vector v = new Vector(profileNames.length);
402
		for (int idx = 0; idx < profileNames.length; idx++)
403
			v.addElement(profileNames[idx]);
404
		return v;
405
	}
406
407
	/* (non-Javadoc)
408
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getActiveSystemProfilePosition(java.lang.String)
409
	 */
410
	public int getActiveSystemProfilePosition(String profileName) {
411
		String[] profiles = getActiveSystemProfileNames();
412
		int pos = -1;
413
		for (int idx = 0; (pos < 0) && (idx < profiles.length); idx++) {
414
			if (profiles[idx].equals(profileName)) pos = idx;
415
		}
416
		return pos;
417
	}
418
419
	/* (non-Javadoc)
420
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getDefaultPrivateSystemProfile()
421
	 */
422
	public ISystemProfile getDefaultPrivateSystemProfile() {
423
		return getSystemProfile(RSEPreferencesManager.getDefaultPrivateSystemProfileName());
424
	}
425
426
	/* (non-Javadoc)
427
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getDefaultTeamSystemProfile()
428
	 */
429
	public ISystemProfile getDefaultTeamSystemProfile() {
430
		return getSystemProfile(RSEPreferencesManager.getDefaultTeamProfileName());
431
	}
432
433
	/**
434
	 * Instantiate a user profile given its name.
435
	 * @param userProfileName the name of the profile to find or create
436
	 * @return the profile that was found or created.
437
	 */
438
	protected ISystemProfile getOrCreateSystemProfile(String userProfileName) {
439
		ISystemProfile userProfile = getSystemProfile(userProfileName);
440
		if (userProfile == null) {
441
			userProfile = internalCreateSystemProfileAndFolder(userProfileName);
442
		}
443
		return userProfile;
444
	}
445
446
	/**
447
	 * No longer used.
448
	 * @param profileName the name of the profile from which to construct the name
449
	 * @return the unqualified save file name with the extension .xmi
450
	 */
451
	public static String getSaveFileName(String profileName) {
452
		return null;
453
		//FIXME SystemMOFHelpers.getSaveFileName(getRootSaveFileName(profileName)); no longer needed.
454
	}
455
456
	/**
457
	 * No longer used.
458
	 * @param profile the profile from which to construct the name 
459
	 * @return the unqualified save file name with the extension .xmi
460
	 */
461
	public static String getSaveFileName(ISystemProfile profile) {
462
		return null;
463
		//FIXME SystemMOFHelpers.getSaveFileName(getRootSaveFileName(profile)); no longer needed.
464
	}
465
466
	/**
467
	 * No longer used.
468
	 * @param profile the profile from which to retrieve the root.
469
	 * @return the root save file name without the extension .xmi
470
	 */
471
	protected static String getRootSaveFileName(ISystemProfile profile) {
472
		return getRootSaveFileName(profile.getName());
473
	}
474
475
	/**
476
	 * No longer used.
477
	 * @param profileName the name of the profile
478
	 * @return the root save file name without the extension .xmi
479
	 */
480
	protected static String getRootSaveFileName(String profileName) {
481
		//String fileName = profileName; // may be a bad idea to include manager name in it!
482
		String fileName = PROFILE_FILE_NAME;
483
		return fileName;
484
	}
485
486
	/**
487
	 * Reusable method to return a name validator for renaming a profile.
488
	 * @param profileName the current profile name on updates. Can be null for new profiles. Used
489
	 * to remove from the existing name list the current connection.
490
	 * @return the validator
491
	 */
492
	public ISystemValidator getProfileNameValidator(String profileName) {
493
		//Vector v = getActiveSystemProfileNamesVector();
494
		Vector v = getSystemProfileNamesVector();
495
		if (profileName != null) v.removeElement(profileName);
496
		ISystemValidator nameValidator = new ValidatorProfileName(v);
497
		return nameValidator;
498
	}
499
500
	/**
501
	 * Reusable method to return a name validator for renaming a profile.
502
	 * @param profile the current profile object on updates. Can be null for new profiles. Used
503
	 * to remove from the existing name list the current connection.
504
	 * @return the validator
505
	 */
506
	public ISystemValidator getProfileNameValidator(ISystemProfile profile) {
507
		if (profile != null)
508
			return getProfileNameValidator(profile.getName());
509
		else
510
			return getProfileNameValidator((String) null);
511
	}
512
513
	/* (non-Javadoc)
514
	 * @see org.eclipse.rse.core.model.ISystemProfileManager#getProfiles()
515
	 */
516
	public List getProfiles() {
517
		if (_profiles == null) {
518
			ISystemProfile profile = new SystemProfile();
519
			String initProfileName = RSEPreferencesManager.getDefaultPrivateSystemProfileName();
520
			profile.setName(initProfileName);
521
			profile.setDefaultPrivate(true);
522
			_profiles = new ArrayList();
523
			_profiles.add(profile);
524
			//profiles = null;//FIXME new EObjectResolvingeList(SystemProfile.class, this, ModelPackage.SYSTEM_PROFILE_MANAGER__PROFILES);
525
		}
526
		return _profiles;
527
	}
528
529
}
(-)UI/org/eclipse/rse/ui/actions/SystemBaseCopyAction.java (-2 / +2 lines)
Lines 23-29 Link Here
23
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.rse.core.model.ISystemProfileManager;
24
import org.eclipse.rse.core.model.ISystemProfileManager;
25
import org.eclipse.rse.core.model.ISystemRegistry;
25
import org.eclipse.rse.core.model.ISystemRegistry;
26
import org.eclipse.rse.internal.model.SystemProfileManager;
26
import org.eclipse.rse.internal.core.model.SystemProfileManager;
27
import org.eclipse.rse.internal.ui.SystemResources;
27
import org.eclipse.rse.internal.ui.SystemResources;
28
import org.eclipse.rse.model.SystemRegistry;
28
import org.eclipse.rse.model.SystemRegistry;
29
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
29
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
Lines 87-93 Link Here
87
		            : RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_MOVE_ID)), 
87
		            : RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_MOVE_ID)), 
88
		      parent);
88
		      parent);
89
		this.mode = mode;
89
		this.mode = mode;
90
		mgr = SystemProfileManager.getSystemProfileManager();
90
		mgr = SystemProfileManager.getDefault();
91
		sr = RSEUIPlugin.getTheSystemRegistry();
91
		sr = RSEUIPlugin.getTheSystemRegistry();
92
		allowOnMultipleSelection(true);
92
		allowOnMultipleSelection(true);
93
        setProcessAllSelections(true);
93
        setProcessAllSelections(true);
(-)UI/org/eclipse/rse/internal/ui/actions/SystemProfileNameSelectAction.java (-2 / +2 lines)
Lines 18-24 Link Here
18
import org.eclipse.rse.core.model.ISystemProfile;
18
import org.eclipse.rse.core.model.ISystemProfile;
19
import org.eclipse.rse.core.model.ISystemProfileManager;
19
import org.eclipse.rse.core.model.ISystemProfileManager;
20
import org.eclipse.rse.core.model.ISystemRegistry;
20
import org.eclipse.rse.core.model.ISystemRegistry;
21
import org.eclipse.rse.internal.model.SystemProfileManager;
21
import org.eclipse.rse.internal.core.model.SystemProfileManager;
22
import org.eclipse.rse.ui.RSEUIPlugin;
22
import org.eclipse.rse.ui.RSEUIPlugin;
23
import org.eclipse.rse.ui.actions.SystemBaseAction;
23
import org.eclipse.rse.ui.actions.SystemBaseAction;
24
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.swt.widgets.Shell;
Lines 38-44 Link Here
38
	{
38
	{
39
		super(profile.getName(),parent);
39
		super(profile.getName(),parent);
40
		this.profile = profile;
40
		this.profile = profile;
41
		ISystemProfileManager mgr = SystemProfileManager.getSystemProfileManager();
41
		ISystemProfileManager mgr = SystemProfileManager.getDefault();
42
		setChecked(mgr.isSystemProfileActive(profile.getName()));
42
		setChecked(mgr.isSystemProfileActive(profile.getName()));
43
        setSelectionSensitive(false);
43
        setSelectionSensitive(false);
44
        
44
        
(-)UI/org/eclipse/rse/internal/ui/dialogs/SystemCopyProfileDialog.java (-5 / +2 lines)
Lines 18-24 Link Here
18
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.rse.core.model.ISystemProfile;
20
import org.eclipse.rse.core.model.ISystemProfile;
21
import org.eclipse.rse.internal.model.SystemProfileManager;
22
import org.eclipse.rse.internal.ui.SystemResources;
21
import org.eclipse.rse.internal.ui.SystemResources;
23
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
22
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
24
import org.eclipse.rse.ui.RSEUIPlugin;
23
import org.eclipse.rse.ui.RSEUIPlugin;
Lines 27-32 Link Here
27
import org.eclipse.rse.ui.dialogs.SystemSimpleContentElement;
26
import org.eclipse.rse.ui.dialogs.SystemSimpleContentElement;
28
import org.eclipse.rse.ui.messages.ISystemMessageLine;
27
import org.eclipse.rse.ui.messages.ISystemMessageLine;
29
import org.eclipse.rse.ui.validators.ISystemValidator;
28
import org.eclipse.rse.ui.validators.ISystemValidator;
29
import org.eclipse.rse.ui.validators.ValidatorFactory;
30
import org.eclipse.rse.ui.validators.ValidatorProfileName;
30
import org.eclipse.rse.ui.validators.ValidatorProfileName;
31
import org.eclipse.swt.events.ModifyEvent;
31
import org.eclipse.swt.events.ModifyEvent;
32
import org.eclipse.swt.events.ModifyListener;
32
import org.eclipse.swt.events.ModifyListener;
Lines 71-80 Link Here
71
		{		
71
		{		
72
		   setInputObject(profile);
72
		   setInputObject(profile);
73
		}
73
		}
74
		
74
		nameValidator = ValidatorFactory.getProfileNameValidator((String)null);		
75
		// FIXME cast to SystemProfileManager is temporary to get at api - need to use an adapter for getting validators
76
		SystemProfileManager mgr = (SystemProfileManager)RSEUIPlugin.getTheSystemRegistry().getSystemProfileManager();
77
		nameValidator = mgr.getProfileNameValidator((String)null);		
78
		//pack();
75
		//pack();
79
		setHelp(RSEUIPlugin.HELPPREFIX+"drnp0000"); //$NON-NLS-1$
76
		setHelp(RSEUIPlugin.HELPPREFIX+"drnp0000"); //$NON-NLS-1$
80
	}
77
	}
(-)model/org/eclipse/rse/model/SystemRegistry.java (-15 / +8 lines)
Lines 35-45 Link Here
35
import org.eclipse.jface.viewers.Viewer;
35
import org.eclipse.jface.viewers.Viewer;
36
import org.eclipse.rse.core.IRSESystemType;
36
import org.eclipse.rse.core.IRSESystemType;
37
import org.eclipse.rse.core.IRSEUserIdConstants;
37
import org.eclipse.rse.core.IRSEUserIdConstants;
38
import org.eclipse.rse.core.RSECorePlugin;
39
import org.eclipse.rse.core.SystemAdapterHelpers;
38
import org.eclipse.rse.core.SystemAdapterHelpers;
40
import org.eclipse.rse.core.SystemBasePlugin;
39
import org.eclipse.rse.core.SystemBasePlugin;
41
import org.eclipse.rse.core.filters.ISystemFilter;
40
import org.eclipse.rse.core.filters.ISystemFilter;
42
import org.eclipse.rse.core.filters.ISystemFilterPool;
43
import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManager;
41
import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManager;
44
import org.eclipse.rse.core.filters.ISystemFilterReference;
42
import org.eclipse.rse.core.filters.ISystemFilterReference;
45
import org.eclipse.rse.core.filters.ISystemFilterStartHere;
43
import org.eclipse.rse.core.filters.ISystemFilterStartHere;
Lines 66-79 Link Here
66
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
64
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
67
import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy;
65
import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy;
68
import org.eclipse.rse.core.subsystems.util.ISubSystemConfigurationAdapter;
66
import org.eclipse.rse.core.subsystems.util.ISubSystemConfigurationAdapter;
69
import org.eclipse.rse.internal.core.filters.SystemFilterPool;
70
import org.eclipse.rse.internal.core.filters.SystemFilterStartHere;
67
import org.eclipse.rse.internal.core.filters.SystemFilterStartHere;
68
import org.eclipse.rse.internal.core.model.SystemProfileManager;
71
import org.eclipse.rse.internal.model.SystemHostPool;
69
import org.eclipse.rse.internal.model.SystemHostPool;
72
import org.eclipse.rse.internal.model.SystemModelChangeEvent;
70
import org.eclipse.rse.internal.model.SystemModelChangeEvent;
73
import org.eclipse.rse.internal.model.SystemModelChangeEventManager;
71
import org.eclipse.rse.internal.model.SystemModelChangeEventManager;
74
import org.eclipse.rse.internal.model.SystemPostableEventNotifier;
72
import org.eclipse.rse.internal.model.SystemPostableEventNotifier;
75
import org.eclipse.rse.internal.model.SystemPreferenceChangeManager;
73
import org.eclipse.rse.internal.model.SystemPreferenceChangeManager;
76
import org.eclipse.rse.internal.model.SystemProfileManager;
77
import org.eclipse.rse.internal.model.SystemRemoteChangeEventManager;
74
import org.eclipse.rse.internal.model.SystemRemoteChangeEventManager;
78
import org.eclipse.rse.internal.model.SystemResourceChangeManager;
75
import org.eclipse.rse.internal.model.SystemResourceChangeManager;
79
import org.eclipse.rse.internal.model.SystemScratchpad;
76
import org.eclipse.rse.internal.model.SystemScratchpad;
Lines 764-770 Link Here
764
	 */
761
	 */
765
	public ISystemProfileManager getSystemProfileManager()
762
	public ISystemProfileManager getSystemProfileManager()
766
	{
763
	{
767
		return SystemProfileManager.getSystemProfileManager();
764
		return SystemProfileManager.getDefault();
768
	}
765
	}
769
766
770
	/**
767
	/**
Lines 795-806 Link Here
795
	{
792
	{
796
		return getSystemProfileManager().getSystemProfileNames();
793
		return getSystemProfileManager().getSystemProfileNames();
797
	}
794
	}
795
798
	/**
796
	/**
799
	 * Return all defined profile names as a vector
797
	 * Return all defined profile names as a vector
800
	 */
798
	 */
801
	public Vector getAllSystemProfileNamesVector()
799
	public Vector getAllSystemProfileNamesVector()
802
	{
800
	{
803
		return getSystemProfileManager().getSystemProfileNamesVector();
801
		Vector v = getSystemProfileManager().getSystemProfileNamesVector();
802
		return v;
804
	}
803
	}
805
804
806
	/**
805
	/**
Lines 2843-2849 Link Here
2843
	public void disconnectAllSubSystems(IHost conn)
2842
	public void disconnectAllSubSystems(IHost conn)
2844
	{
2843
	{
2845
		// FIXME - save profile
2844
		// FIXME - save profile
2846
		save();
2845
//		save();
2847
		
2846
		
2848
		ISubSystem[] subsystems = getSubSystemsLazily(conn);
2847
		ISubSystem[] subsystems = getSubSystemsLazily(conn);
2849
		if (subsystems == null)
2848
		if (subsystems == null)
Lines 3346-3353 Link Here
3346
	 */
3345
	 */
3347
	public boolean save()
3346
	public boolean save()
3348
	{
3347
	{
3349
		ISystemProfileManager profileManager = getSystemProfileManager();
3348
		return RSEUIPlugin.getThePersistenceManager().commitProfiles();
3350
		return RSEUIPlugin.getThePersistenceManager().commit(profileManager);
3351
	}
3349
	}
3352
3350
3353
	/**
3351
	/**
Lines 3356-3362 Link Here
3356
	 */
3354
	 */
3357
	public boolean saveHostPool(ISystemHostPool pool)
3355
	public boolean saveHostPool(ISystemHostPool pool)
3358
	{
3356
	{
3359
		return RSEUIPlugin.getThePersistenceManager().commit(pool);
3357
		return pool.commit();
3360
	}
3358
	}
3361
3359
3362
	/**
3360
	/**
Lines 3414-3422 Link Here
3414
		return SystemFilterStartHere.getDefault();
3412
		return SystemFilterStartHere.getDefault();
3415
	} 
3413
	} 
3416
	
3414
	
3417
	public ISystemFilterPool getSystemFilterPool()
3418
	{
3419
		return SystemFilterPool.getDefault();
3420
	}
3421
	
3422
}//SystemRegistryImpl
3415
}//SystemRegistryImpl
(-)model/org/eclipse/rse/model/SystemStartHere.java (-2 / +2 lines)
Lines 21-27 Link Here
21
import org.eclipse.rse.core.model.ISystemRegistry;
21
import org.eclipse.rse.core.model.ISystemRegistry;
22
import org.eclipse.rse.core.subsystems.ISubSystem;
22
import org.eclipse.rse.core.subsystems.ISubSystem;
23
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
23
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
24
import org.eclipse.rse.internal.model.SystemProfileManager;
24
import org.eclipse.rse.internal.core.model.SystemProfileManager;
25
import org.eclipse.rse.ui.RSEUIPlugin;
25
import org.eclipse.rse.ui.RSEUIPlugin;
26
26
27
27
Lines 161-167 Link Here
161
	*/
161
	*/
162
   public static ISystemProfileManager getSystemProfileManager()
162
   public static ISystemProfileManager getSystemProfileManager()
163
   {
163
   {
164
	   return SystemProfileManager.getSystemProfileManager();
164
	   return SystemProfileManager.getDefault();
165
   }
165
   }
166
166
167
    /**
167
    /**
(-)UI/org/eclipse/rse/internal/ui/view/SystemViewFilterPoolReferenceAdapter.java (-34 / +31 lines)
Lines 25-30 Link Here
25
import org.eclipse.rse.core.SystemAdapterHelpers;
25
import org.eclipse.rse.core.SystemAdapterHelpers;
26
import org.eclipse.rse.core.filters.ISystemFilterPool;
26
import org.eclipse.rse.core.filters.ISystemFilterPool;
27
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
27
import org.eclipse.rse.core.filters.ISystemFilterPoolManager;
28
import org.eclipse.rse.core.filters.ISystemFilterPoolManagerProvider;
28
import org.eclipse.rse.core.filters.ISystemFilterPoolReference;
29
import org.eclipse.rse.core.filters.ISystemFilterPoolReference;
29
import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManagerProvider;
30
import org.eclipse.rse.core.filters.ISystemFilterPoolReferenceManagerProvider;
30
import org.eclipse.rse.core.subsystems.ISubSystem;
31
import org.eclipse.rse.core.subsystems.ISubSystem;
Lines 89-95 Link Here
89
		  	 menu.add(menuGroup, action);
90
		  	 menu.add(menuGroup, action);
90
		  }   
91
		  }   
91
		}    	  
92
		}    	  
92
		actions = adapter.getFilterPoolReferenceActions(menu, selection, shell, menuGroup, ssFactory, getFilterPoolReference(element));
93
		actions = adapter.getFilterPoolReferenceActions(menu, selection, shell, menuGroup, ssFactory, (ISystemFilterPoolReference)element);
93
		if (actions != null)
94
		if (actions != null)
94
		{
95
		{
95
		  //menu.addSeparator();
96
		  //menu.addSeparator();
Lines 112-146 Link Here
112
	 */ 	
113
	 */ 	
113
	public ISubSystem getSubSystem(Object element)
114
	public ISubSystem getSubSystem(Object element)
114
	{
115
	{
115
		return ((ISubSystem)getFilterPoolReference(element).getProvider());
116
		ISystemFilterPoolReference ref = (ISystemFilterPoolReference)element;
117
		return (ISubSystem)ref.getProvider();
116
	}
118
	}
117
	
119
	
118
	/**
120
	/**
119
	 * Returns an image descriptor for the image. More efficient than getting the image.
121
	 * Returns an image descriptor for the image. More efficient than getting the image.
120
	 * @param element The element for which an image is desired
122
	 * @param element The element for which an image is desired
121
	 */
123
	 */
122
	public ImageDescriptor getImageDescriptor(Object element)
124
	public ImageDescriptor getImageDescriptor(Object element) {
123
	{
125
		ImageDescriptor poolImage = null;
124
    	ImageDescriptor poolImage = null;
126
		ISystemFilterPool pool = getFilterPool(element);
125
    	ISystemFilterPool pool = getFilterPool(element);
127
		if (pool != null) {
126
    	if (pool.getProvider() != null)
128
			ISystemFilterPoolManagerProvider provider = pool.getProvider();
127
    	{
129
			if (provider != null) {
128
    		ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter)pool.getProvider().getAdapter(ISubSystemConfigurationAdapter.class);
130
				ISubSystemConfigurationAdapter adapter = (ISubSystemConfigurationAdapter) provider.getAdapter(ISubSystemConfigurationAdapter.class);
129
          poolImage = adapter.getSystemFilterPoolImage(pool); 
131
				poolImage = adapter.getSystemFilterPoolImage(pool);
130
    	}
132
			}
131
    	if (poolImage == null)
133
		}
132
    	  poolImage = RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_FILTERPOOL_ID);
134
		if (poolImage == null) {
133
    	return poolImage;  	
135
			poolImage = RSEUIPlugin.getDefault().getImageDescriptor(ISystemIconConstants.ICON_SYSTEM_FILTERPOOL_ID);
134
	}
136
		}
135
	
137
		return poolImage;
136
	private ISystemFilterPoolReference getFilterPoolReference(Object element)
137
	{
138
		return (ISystemFilterPoolReference)element; // get referenced object
139
	}
138
	}
140
	
139
	
141
	private ISystemFilterPool getFilterPool(Object element)
140
	private ISystemFilterPool getFilterPool(Object element)
142
	{
141
	{
143
		return getFilterPoolReference(element).getReferencedFilterPool(); // get master object
142
		ISystemFilterPoolReference ref = (ISystemFilterPoolReference)element;
143
		ISystemFilterPool pool = ref.getReferencedFilterPool();
144
		return pool; // get master object
144
	}
145
	}
145
146
146
	/**
147
	/**
Lines 148-163 Link Here
148
	 * @return the label for this filter pool reference.
149
	 * @return the label for this filter pool reference.
149
	 */
150
	 */
150
	public String getText(Object element) {
151
	public String getText(Object element) {
151
		String result = "unknown"; // $NON-NLS-1$ //$NON-NLS-1$
152
		ISystemFilterPoolReference reference = (ISystemFilterPoolReference) element;
153
		String result = reference.getName();
152
		ISystemFilterPool pool = getFilterPool(element);
154
		ISystemFilterPool pool = getFilterPool(element);
153
		if (pool != null) {
155
		if (pool != null) {
154
			result = pool.getName();
156
			result = pool.getName();
155
// the following looks like it was copied from the host adapter and not really needed here.
156
//			boolean qualifyNames = RSEUIPlugin.getTheSystemRegistry().getQualifiedHostNames();
157
//			if (qualifyNames) {
158
//				String prefix = SubSystemHelpers.getParentSystemProfile(pool).getName();
159
//				result =  prefix + "." + result;
160
//			}
161
		}
157
		}
162
		return result;
158
		return result;
163
	}
159
	}
Lines 178-190 Link Here
178
	public String getAbsoluteName(Object element)
174
	public String getAbsoluteName(Object element)
179
	{
175
	{
180
		//TODO consider caching the absolute name in the FilterPoolReference to avoid unnecessary String operations - the name won't ever change 
176
		//TODO consider caching the absolute name in the FilterPoolReference to avoid unnecessary String operations - the name won't ever change 
181
		ISystemFilterPoolReference filterPoolRef = getFilterPoolReference(element);
177
		ISystemFilterPoolReference filterPoolRef = (ISystemFilterPoolReference)element;
182
		ISystemFilterPoolReferenceManagerProvider subSystem = filterPoolRef.getProvider();
178
		ISystemFilterPoolReferenceManagerProvider subSystem = filterPoolRef.getProvider();
183
		ISystemViewElementAdapter adapter = SystemAdapterHelpers.getViewAdapter(subSystem);
179
		ISystemViewElementAdapter adapter = SystemAdapterHelpers.getViewAdapter(subSystem);
184
		String parentAbsoluteName = (adapter != null) ?	adapter.getAbsoluteName(subSystem) : ""; //$NON-NLS-1$
180
		String parentAbsoluteName = (adapter != null) ?	adapter.getAbsoluteName(subSystem) : ""; //$NON-NLS-1$
185
		return parentAbsoluteName + "." +  //$NON-NLS-1$
181
		String referenceName = filterPoolRef.getName();
186
			filterPoolRef.getReferencedFilterPool().getSystemFilterPoolManager().getName() + "." +  //$NON-NLS-1$
182
		String managerName = filterPoolRef.getReferencedFilterPoolManagerName();
187
			filterPoolRef.getName();
183
		String absoluteName = parentAbsoluteName + "." + managerName + "." +  referenceName; //$NON-NLS-1$ //$NON-NLS-2$
184
		return absoluteName;
188
	}
185
	}
189
	
186
	
190
	/**
187
	/**
Lines 202-208 Link Here
202
	 */
199
	 */
203
	public Object getParent(Object element)
200
	public Object getParent(Object element)
204
	{
201
	{
205
		ISystemFilterPoolReference fpr = getFilterPoolReference(element);
202
		ISystemFilterPoolReference fpr = (ISystemFilterPoolReference)element;
206
		return SubSystemHelpers.getParentSubSystem(fpr);
203
		return SubSystemHelpers.getParentSubSystem(fpr);
207
	}	
204
	}	
208
	
205
	
Lines 212-218 Link Here
212
	 */
209
	 */
213
	public Object[] getChildren(IProgressMonitor monitor, IAdaptable element)
210
	public Object[] getChildren(IProgressMonitor monitor, IAdaptable element)
214
	{
211
	{
215
		ISystemFilterPoolReference fpRef = getFilterPoolReference(element);
212
		ISystemFilterPoolReference fpRef = (ISystemFilterPoolReference)element;
216
		ISubSystem ss = getSubSystem(element);
213
		ISubSystem ss = getSubSystem(element);
217
		return fpRef.getSystemFilterReferences(ss);
214
		return fpRef.getSystemFilterReferences(ss);
218
	}
215
	}
Lines 222-228 Link Here
222
	 */
219
	 */
223
	public boolean hasChildren(IAdaptable element) {
220
	public boolean hasChildren(IAdaptable element) {
224
		int count = 0;
221
		int count = 0;
225
		ISystemFilterPoolReference fpRef = getFilterPoolReference(element);
222
		ISystemFilterPoolReference fpRef = (ISystemFilterPoolReference)element;
226
		if (fpRef != null) {
223
		if (fpRef != null) {
227
			ISystemFilterPool filterPool = fpRef.getReferencedFilterPool();
224
			ISystemFilterPool filterPool = fpRef.getReferencedFilterPool();
228
			if (filterPool != null) {
225
			if (filterPool != null) {
(-)UI/org/eclipse/rse/ui/RSEUIPlugin.java (-3 / +3 lines)
Lines 44-52 Link Here
44
import org.eclipse.rse.core.model.ISystemRegistry;
44
import org.eclipse.rse.core.model.ISystemRegistry;
45
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
45
import org.eclipse.rse.core.subsystems.ISubSystemConfiguration;
46
import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy;
46
import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy;
47
import org.eclipse.rse.internal.core.model.SystemProfileManager;
47
import org.eclipse.rse.internal.core.subsystems.SubSystemConfigurationProxy;
48
import org.eclipse.rse.internal.core.subsystems.SubSystemConfigurationProxy;
48
import org.eclipse.rse.internal.core.subsystems.SubSystemConfigurationProxyComparator;
49
import org.eclipse.rse.internal.core.subsystems.SubSystemConfigurationProxyComparator;
49
import org.eclipse.rse.internal.model.SystemProfileManager;
50
import org.eclipse.rse.internal.ui.RSESystemTypeAdapterFactory;
50
import org.eclipse.rse.internal.ui.RSESystemTypeAdapterFactory;
51
import org.eclipse.rse.internal.ui.SystemResources;
51
import org.eclipse.rse.internal.ui.SystemResources;
52
import org.eclipse.rse.internal.ui.actions.SystemDynamicPopupMenuExtensionManager;
52
import org.eclipse.rse.internal.ui.actions.SystemDynamicPopupMenuExtensionManager;
Lines 114-120 Link Here
114
					if (systemType != null) {
114
					if (systemType != null) {
115
						RSESystemTypeAdapter adapter = (RSESystemTypeAdapter)(systemType.getAdapter(IRSESystemType.class));
115
						RSESystemTypeAdapter adapter = (RSESystemTypeAdapter)(systemType.getAdapter(IRSESystemType.class));
116
						if (adapter != null && adapter.isEnabled(systemType)) {
116
						if (adapter != null && adapter.isEnabled(systemType)) {
117
							ISystemProfileManager profileManager = SystemProfileManager.getSystemProfileManager();
117
							ISystemProfileManager profileManager = SystemProfileManager.getDefault();
118
							ISystemProfile profile = profileManager.getDefaultPrivateSystemProfile();
118
							ISystemProfile profile = profileManager.getDefaultPrivateSystemProfile();
119
							String userName = System.getProperty("user.name"); //$NON-NLS-1$
119
							String userName = System.getProperty("user.name"); //$NON-NLS-1$
120
							registry.createLocalHost(profile, SystemResources.TERM_LOCAL, userName);
120
							registry.createLocalHost(profile, SystemResources.TERM_LOCAL, userName);
Lines 761-767 Link Here
761
	 */
761
	 */
762
	public static ISystemProfileManager getTheSystemProfileManager()
762
	public static ISystemProfileManager getTheSystemProfileManager()
763
	{
763
	{
764
		return SystemProfileManager.getSystemProfileManager();
764
		return SystemProfileManager.getDefault();
765
	}
765
	}
766
766
767
    /**
767
    /**
(-)UI/org/eclipse/rse/ui/validators/ValidatorFactory.java (+27 lines)
Added Link Here
1
package org.eclipse.rse.ui.validators;
2
3
import java.util.Vector;
4
5
import org.eclipse.rse.core.RSECorePlugin;
6
import org.eclipse.rse.core.model.ISystemProfileManager;
7
8
/**
9
 * This class constructs validators for various bits of the user interface.
10
 */
11
public class ValidatorFactory {
12
13
	/**
14
	 * Reusable method to return a name validator for renaming a profile.
15
	 * @param profileName the current profile name on updates. Can be null for new profiles. Used
16
	 * to remove from the existing name list the current connection.
17
	 * @return the validator
18
	 */
19
	public static ISystemValidator getProfileNameValidator(String profileName) {
20
		ISystemProfileManager manager = RSECorePlugin.getDefault().getSystemRegistry().getSystemProfileManager();
21
		Vector profileNames = manager.getSystemProfileNamesVector();
22
		if (profileName != null) profileNames.remove(profileName);
23
		ISystemValidator nameValidator = new ValidatorProfileName(profileNames);
24
		return nameValidator;
25
	}
26
27
}

Return to bug 170932