Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 166025 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/hyades/test/ui/navigator/actions/RenamerUIStatus.java (+1 lines)
Lines 31-36 Link Here
31
 * 
31
 * 
32
 * @author jgout
32
 * @author jgout
33
 * @since 3.3
33
 * @since 3.3
34
 * @deprecated this class is no longer needed
34
 */
35
 */
35
public class RenamerUIStatus {
36
public class RenamerUIStatus {
36
37
(-)src/org/eclipse/hyades/test/ui/navigator/actions/IProxyNodeRenamer.java (+1 lines)
Lines 17-22 Link Here
17
 * 
17
 * 
18
 * @author jgout
18
 * @author jgout
19
 * @since 3.3
19
 * @since 3.3
20
 * @deprecated client should use IProxyNodeRenamer2 instead.
20
 */
21
 */
21
public interface IProxyNodeRenamer {
22
public interface IProxyNodeRenamer {
22
	
23
	
(-)src/org/eclipse/hyades/test/ui/navigator/actions/RenamerUIInlineEditor.java (+1 lines)
Lines 15-20 Link Here
15
/** This class is returned by IProxyNodeRenamer.performUserInteraction() when the default rename UI should be used.
15
/** This class is returned by IProxyNodeRenamer.performUserInteraction() when the default rename UI should be used.
16
 * @author jgout
16
 * @author jgout
17
 * @since 3.3
17
 * @since 3.3
18
 * @deprecated this class is no longer needed
18
 */
19
 */
19
public class RenamerUIInlineEditor extends RenamerUIStatus {
20
public class RenamerUIInlineEditor extends RenamerUIStatus {
20
	
21
	
(-)src/org/eclipse/hyades/test/ui/navigator/actions/RenamerUICancel.java (+1 lines)
Lines 15-20 Link Here
15
/** This class is returned by IProxyNodeRenamer.performUserInteraction() when the user clicks the cancel button.
15
/** This class is returned by IProxyNodeRenamer.performUserInteraction() when the user clicks the cancel button.
16
 * @author jgout
16
 * @author jgout
17
 * @since 3.3
17
 * @since 3.3
18
 * @deprecated this class is no longer needed
18
 */
19
 */
19
public class RenamerUICancel extends RenamerUIStatus {
20
public class RenamerUICancel extends RenamerUIStatus {
20
	
21
	
(-)src/org/eclipse/hyades/test/ui/navigator/actions/RenamerUIOk.java (+1 lines)
Lines 15-20 Link Here
15
/** This class is returned by IProxyNodeRenamer.performUserInteraction() when the user clicks the ok button.
15
/** This class is returned by IProxyNodeRenamer.performUserInteraction() when the user clicks the ok button.
16
 * @author jgout
16
 * @author jgout
17
 * @since 3.3
17
 * @since 3.3
18
 * @deprecated this class is no longer needed
18
 */
19
 */
19
public class RenamerUIOk extends RenamerUIStatus {
20
public class RenamerUIOk extends RenamerUIStatus {
20
	
21
	
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/ExecutionFileProxyNode.java (-1 / +20 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
17
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.TestUIImages;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
20
21
Lines 36-43 Link Here
36
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_EXECUTION);
37
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_EXECUTION);
37
	}
38
	}
38
	
39
	
40
	public String getFactoryID() {
41
		return EMFResourceProxyFactory.ID;
42
	}
43
	
44
	public boolean saveState(IMemento memento) { 
45
		//- data to retrieve the correct object 
46
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.EXECUTION_FILE_NODE);
47
		//- data from EMFResourceProxyNode
48
		memento.putString(TestUIConstants.TAG_NAME, getText());
49
		IProxyNode [] children = getChildren();
50
		for (int i = 0; i < children.length; i++) {
51
			if(!saveChildState(memento, children[i])) {
52
				return false;
53
			}
54
		}
55
		return true;
56
	}
57
	
39
	protected String getNodeKind() {
58
	protected String getNodeKind() {
40
    	return TestUIConstants.EXECUTION_FILE_NODE;
59
    	return TestUIConstants.EXECUTION_FILE_NODE;
41
    }
60
    }
42
61
	
43
}
62
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/DefaultExecutionResultProxyNode.java (-7 / +39 lines)
Lines 15-26 Link Here
15
import org.eclipse.hyades.models.common.testprofile.TPFExecutionEvent;
15
import org.eclipse.hyades.models.common.testprofile.TPFExecutionEvent;
16
import org.eclipse.hyades.models.common.testprofile.TPFExecutionResult;
16
import org.eclipse.hyades.models.common.testprofile.TPFExecutionResult;
17
import org.eclipse.hyades.models.common.testprofile.TPFTest;
17
import org.eclipse.hyades.models.common.testprofile.TPFTest;
18
import org.eclipse.hyades.models.common.testprofile.TPFTestSuite;
18
import org.eclipse.hyades.test.ui.TestUIConstants;
19
import org.eclipse.hyades.test.ui.TestUIConstants;
19
import org.eclipse.hyades.test.ui.TestUIImages;
20
import org.eclipse.hyades.test.ui.TestUIImages;
20
import org.eclipse.hyades.test.ui.internal.model.EventUtil;
21
import org.eclipse.hyades.test.ui.internal.model.EventUtil;
21
import org.eclipse.hyades.test.ui.navigator.IExecutionResultProxyNode;
22
import org.eclipse.hyades.test.ui.navigator.IExecutionResultProxyNode;
22
import org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode;
23
import org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode;
23
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
24
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
25
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
24
import org.eclipse.hyades.test.ui.navigator.ProxyNeedToBeRebuiltException;
26
import org.eclipse.hyades.test.ui.navigator.ProxyNeedToBeRebuiltException;
25
import org.eclipse.hyades.test.ui.navigator.TypedElementProxyNode;
27
import org.eclipse.hyades.test.ui.navigator.TypedElementProxyNode;
26
import org.eclipse.swt.graphics.Image;
28
import org.eclipse.swt.graphics.Image;
Lines 74-84 Link Here
74
				name = testName;
76
				name = testName;
75
			}
77
			}
76
		}
78
		}
77
		setName(name);
79
        if((er.getTest() != null) && (((er.getTest()).getName()) != null)) {
78
		if (!(parent instanceof IExecutionResultProxyNode)) {
80
            if (test instanceof TPFTestSuite) {
79
			if (er.getExecutionHistory().getExecutionEvents() != null && er.getExecutionHistory().getExecutionEvents().size()>0) {
81
                if (er.getExecutionHistory().getExecutionEvents()!=null && er.getExecutionHistory().getExecutionEvents().size()>0) {
80
				timestamp = ((TPFExecutionEvent)er.getExecutionHistory().getExecutionEvents().get(0)).getTimestamp();
82
                	timestamp = ((TPFExecutionEvent)er.getExecutionHistory().getExecutionEvents().get(0)).getTimestamp();
81
			}
83
                    String dateStamp = EventUtil.getTime(timestamp);
84
                    name += " ["+dateStamp+"]";  //$NON-NLS-1$//$NON-NLS-2$
85
                }
86
                //- add the link between execution and test suite.
87
                IProxyNode proxy = FileProxyNodeCache.getInstance().getCorrespondingProxy(test);
88
                if (proxy != null) {
89
                	addBidirectionalReference("TestLog2TestSuite", (IReferencerProxyNode)proxy, "TestSuite2TestLog");  //$NON-NLS-1$//$NON-NLS-2$
90
				}
91
            } else {
92
                name += " [" + (er.getTest()).getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
93
            }
82
		}
94
		}
83
        verdict = er.getVerdict().getValue();
95
        verdict = er.getVerdict().getValue();
84
	}
96
	}
Lines 174-179 Link Here
174
    	return TestUIConstants.EXECUTION_RESULT_NODE;
186
    	return TestUIConstants.EXECUTION_RESULT_NODE;
175
    }
187
    }
176
    
188
    
189
    public String getFactoryID() {
190
        return EMFResourceProxyFactory.ID; 
191
    }
192
 
193
// was :     
194
//    public boolean saveState(IMemento memento) {
195
//        //- data to retrieve the correct object 
196
//        memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.EXECUTION_RESULT_NODE);
197
//        memento.putInteger(TestUIConstants.TAG_VERDICT, getVerdict());
198
//        //- children (testcases)
199
//        for (int i = 0; i < children.length; i++) {
200
//            DefaultExecutionResultProxyNode child = (DefaultExecutionResultProxyNode)children[i];
201
//            IMemento childMemento = memento.createChild(TestUIConstants.TAG_CHILD);
202
//            if(!child.saveState(childMemento)) {
203
//                return false;
204
//            }
205
//        }
206
//        return super.saveState(memento);
207
//    }
208
    
209
210
    
177
    public boolean saveState(IMemento memento) {
211
    public boolean saveState(IMemento memento) {
178
        //- data to retrieve the correct object 
212
        //- data to retrieve the correct object 
179
        memento.putInteger(TAG_VERDICT, getVerdict());
213
        memento.putInteger(TAG_VERDICT, getVerdict());
Lines 188-193 Link Here
188
//        }
222
//        }
189
        return super.saveState(memento);
223
        return super.saveState(memento);
190
    }
224
    }
191
    
192
    
193
}
225
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/DefaultTestCaseProxyNode.java (+10 lines)
Lines 75-80 Link Here
75
		}
75
		}
76
	}
76
	}
77
	
77
	
78
	public String getFactoryID() {
79
		return EMFResourceProxyFactory.ID; 
80
	}
81
	
82
	public boolean saveState(IMemento memento) {
83
		//- data to retrieve the correct object 
84
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.TESTCASE_NODE);
85
		return super.saveState(memento);
86
	}
87
		
78
	protected String getNodeKind() {
88
	protected String getNodeKind() {
79
		return TestUIConstants.TESTCASE_NODE;
89
		return TestUIConstants.TESTCASE_NODE;
80
	}
90
	}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/DatapoolFileProxyNode.java (+19 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
17
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.TestUIImages;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
20
21
Lines 36-41 Link Here
36
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_DATAPOOL);
37
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_DATAPOOL);
37
	}
38
	}
38
	
39
	
40
	public String getFactoryID() {
41
		return EMFResourceProxyFactory.ID; 
42
	}
43
	
44
	public boolean saveState(IMemento memento) {
45
		//- data to retrieve the correct object 
46
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.DATAPOOL_FILE_NODE);
47
		//- data from EMFResourceProxyNode
48
		memento.putString(TestUIConstants.TAG_NAME, getText());
49
		IProxyNode [] children = getChildren();
50
		for (int i = 0; i < children.length; i++) {
51
			if(!saveChildState(memento, children[i])) {
52
				return false;
53
			}
54
		}
55
		return true;
56
	}
57
	
39
	protected String getNodeKind() {
58
	protected String getNodeKind() {
40
		return TestUIConstants.DATAPOOL_FILE_NODE;
59
		return TestUIConstants.DATAPOOL_FILE_NODE;
41
	}
60
	}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/ArtifactProxyNode.java (-1 / +22 lines)
Lines 11-21 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
13
13
14
import java.util.Iterator;
15
14
import org.eclipse.hyades.models.common.configuration.CFGArtifact;
16
import org.eclipse.hyades.models.common.configuration.CFGArtifact;
17
import org.eclipse.hyades.models.common.configuration.CFGClass;
15
import org.eclipse.hyades.test.ui.TestUIConstants;
18
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIImages;
19
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.navigator.CMNNamedElementProxyNode;
20
import org.eclipse.hyades.test.ui.navigator.CMNNamedElementProxyNode;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
21
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
22
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
19
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.ui.IMemento;
24
import org.eclipse.ui.IMemento;
21
25
Lines 39-44 Link Here
39
	 */
43
	 */
40
	public ArtifactProxyNode(CFGArtifact artifact, Object parent) {
44
	public ArtifactProxyNode(CFGArtifact artifact, Object parent) {
41
		super(artifact, parent);
45
		super(artifact, parent);
46
		//- add references on tets.
47
		for (Iterator it = artifact.getDeployableInstances().iterator(); it.hasNext();) {
48
			CFGClass test = (CFGClass) it.next();
49
			IProxyNode proxy = FileProxyNodeCache.getInstance().getCorrespondingProxy(test);
50
			if(proxy != null && proxy instanceof IReferencerProxyNode) {
51
				addBidirectionalReference("Artifact2Test", (IReferencerProxyNode) proxy, "Test2Artifact"); //$NON-NLS-1$ //$NON-NLS-2$
52
			}
53
		}
42
	}
54
	}
43
	
55
	
44
	public Image getImage() {
56
	public Image getImage() {
Lines 50-57 Link Here
50
		return new IProxyNode[0];
62
		return new IProxyNode[0];
51
	}
63
	}
52
	
64
	
65
	public String getFactoryID() {
66
		return EMFResourceProxyFactory.ID;
67
	}
68
	
69
	public boolean saveState(IMemento memento) { 
70
		//- data to retrieve the correct object
71
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.ARTIFACT_NODE);
72
		return super.saveState(memento);
73
	}
74
	
53
	protected String getNodeKind() {
75
	protected String getNodeKind() {
54
		return TestUIConstants.ARTIFACT_NODE;
76
		return TestUIConstants.ARTIFACT_NODE;
55
	}
77
	}
56
	
57
}
78
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/FileProxyNodeCache.java (+94 lines)
Lines 27-40 Link Here
27
import org.eclipse.core.resources.IResourceDelta;
27
import org.eclipse.core.resources.IResourceDelta;
28
import org.eclipse.core.resources.IResourceDeltaVisitor;
28
import org.eclipse.core.resources.IResourceDeltaVisitor;
29
import org.eclipse.core.resources.ResourcesPlugin;
29
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.runtime.Assert;
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IAdaptable;
33
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.hyades.test.ui.UiPlugin;
34
import org.eclipse.hyades.test.ui.UiPlugin;
32
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigator;
35
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigator;
33
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
36
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
34
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.SynchronizedAccess;
37
import org.eclipse.hyades.test.ui.internal.navigator.proxy.async.SynchronizedAccess;
38
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceRegistry;
35
import org.eclipse.hyades.test.ui.navigator.FileProxyNode;
39
import org.eclipse.hyades.test.ui.navigator.FileProxyNode;
36
import org.eclipse.hyades.test.ui.navigator.IFileProxyFactory;
40
import org.eclipse.hyades.test.ui.navigator.IFileProxyFactory;
37
import org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode;
41
import org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode;
42
import org.eclipse.hyades.test.ui.navigator.IProxy;
38
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
43
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
39
import org.eclipse.swt.graphics.Image;
44
import org.eclipse.swt.graphics.Image;
40
import org.eclipse.ui.IMemento;
45
import org.eclipse.ui.IMemento;
Lines 193-199 Link Here
193
        return proxies.keySet().iterator();
198
        return proxies.keySet().iterator();
194
    }
199
    }
195
    
200
    
201
    /**
202
     * Saves the given proxy if it is possible (if it is a <code>org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode</code>).
203
     * @param proxy the proxy node to save.
204
     */
205
	public void saveProxy(IProxyNode proxy) {
206
		if (proxy instanceof IPersistableProxyNode) {
207
			IPersistableProxyNode pProxy = (IPersistableProxyNode) proxy;
208
			IResource underlyingResource = proxy.getUnderlyingResource();
209
			if (underlyingResource instanceof IFile) {
210
				saveProxy((IFile)underlyingResource, pProxy);
211
			} else {
212
				UiPlugin.logWarning("Unable to save proxy because its underlying resource is not a file"); //$NON-NLS-1$
213
			}
214
		}
215
	}
196
216
217
    
197
    /**
218
    /**
198
     * Returns the proxy node associated to the given file.<br>
219
     * Returns the proxy node associated to the given file.<br>
199
     * If the proxy has already been built the same instance will be returned. 
220
     * If the proxy has already been built the same instance will be returned. 
Lines 284-289 Link Here
284
            //- use the unbounded parent marker instance as parent.
305
            //- use the unbounded parent marker instance as parent.
285
            proxy = factory.create(file, unboundedParent);
306
            proxy = factory.create(file, unboundedParent);
286
            if (proxy != null) {
307
            if (proxy != null) {
308
            	Assert.isLegal(file.equals(proxy.getAdapter(IFile.class)), "invalid proxy returned by factory"); //$NON-NLS-1$
287
                break;
309
                break;
288
            }
310
            }
289
        }
311
        }
Lines 321-326 Link Here
321
    public void removeResourceListener(IResourceChangeListener listener) {
343
    public void removeResourceListener(IResourceChangeListener listener) {
322
		resourceListeners.remove(listener);
344
		resourceListeners.remove(listener);
323
    }
345
    }
346
     
347
	/** Returns the proxy which has the given uid. This search starts from the given proxy node and cross its complete sub tree of proxies.
348
	 * 
349
	 * @param proxy root of the proxy tree where the search is done. 
350
	 * @param uid the uid of the searched proxy.
351
	 * @return a proxy node which has the given uid or <code>null</code> if there is no such proxy found in the complete given tree of proxy.
352
	 */
353
	public IProxyNode findProxyByID(IProxyNode proxy, String uid) {
354
		if(proxy == null) return proxy;
355
		//- only for root node that has no fragment part
356
		if(uid.length() > 0) {
357
			//- proxy found ?
358
			if(proxy.getIdentifier().equals(uid)) return proxy;
359
			else {
360
				//- search in its children array
361
				IProxyNode[] children = proxy.getChildren();
362
				for (int i = 0; i < children.length; i++) {
363
					proxy = findProxyByID(children[i], uid);
364
					if(proxy != null) {
365
						//- found !!
366
						return proxy;
367
					}
368
				}
369
				//- not found in this sub tree
370
				return null;
371
			}
372
		} else return proxy;
373
	}
374
375
	/** 
376
     * Retrieves the node using its underlying resource and its identifier. 
377
	 * @param fileName name of the underlying resource of the searched proxy
378
	 * @param identifier identifier of the searched proxy
379
	 * @return a proxy node or <code>null</code> if not found.
380
	 */
381
	public IProxyNode getCorrespondingProxy(String fileName, String identifier) {
382
		return getCorrespondingProxy(new Proxy(fileName, identifier));
383
	}
384
385
	/** 
386
     * Retrieves the node associated to the given object. 
387
	 * This parameter is adapted to a IProxy in order to retrieve the node
388
	 * representing it.
389
	 * 
390
	 * @param object An object adaptable to IProxy.
391
	 * @return the proxy associated to the given object or <code>null</code> if such proxy node does not exist.
392
	 */
393
	public IProxyNode getCorrespondingProxy(Object object) {
394
		IProxy proxy;
395
		if (object instanceof IProxy) {
396
			proxy = (IProxy) object;
397
		} else if (object instanceof IAdaptable) {
398
			proxy = (IProxy) ((IAdaptable)object).getAdapter(IProxy.class);
399
		} else {
400
			proxy = (IProxy) Platform.getAdapterManager().getAdapter(object, IProxy.class);
401
		}
402
		if (proxy != null) {
403
			IResource res = proxy.getUnderlyingResource();
404
			if (res instanceof IFile) {
405
				IFile file = (IFile)res;
406
				IProxyNode fileProxy = getProxy(file);
407
				if (fileProxy != null) {
408
					return findProxyByID(fileProxy, proxy.getIdentifier());
409
				}
410
			}
411
		}
412
		return null;
413
	}
414
    
324
    
415
    
325
    /**
416
    /**
326
     * Invoked when a project is closed. This method cleans up the map and removes any
417
     * Invoked when a project is closed. This method cleans up the map and removes any
Lines 388-393 Link Here
388
				IResource res = delta.getResource();
479
				IResource res = delta.getResource();
389
				if (res.getType() == IResource.FILE) {
480
				if (res.getType() == IResource.FILE) {
390
					FileProxyNodeCache.this.remove((IFile)res);
481
					FileProxyNodeCache.this.remove((IFile)res);
482
					ReferenceRegistry.getInstance().removeReferences((IFile)res);
483
				} else if(res.getType() == IResource.PROJECT){
484
					ReferenceRegistry.getInstance().removeProjectReferenceRegistry((IProject)res);
391
				} else {
485
				} else {
392
					return true;
486
					return true;
393
				}
487
				}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/TestSuiteFileProxyNode.java (-1 / +20 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
17
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.TestUIImages;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
20
21
Lines 36-43 Link Here
36
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_TEST_SUITE);
37
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_TEST_SUITE);
37
	}
38
	}
38
	
39
	
40
	public String getFactoryID() {
41
		return EMFResourceProxyFactory.ID; 
42
	}
43
	
44
	public boolean saveState(IMemento memento) {
45
		//- data to retrieve the correct object 
46
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.TESTSUITE_FILE_NODE);
47
		//- data from EMFResourceProxyNode
48
		memento.putString(TestUIConstants.TAG_NAME, getText());
49
		IProxyNode [] children = getChildren();
50
		for (int i = 0; i < children.length; i++) {
51
			if(!saveChildState(memento, children[i])) {
52
				return false;
53
			}
54
		}
55
		return true;
56
	}
57
	
39
	protected String getNodeKind() {
58
	protected String getNodeKind() {
40
    	return TestUIConstants.TESTSUITE_FILE_NODE;
59
    	return TestUIConstants.TESTSUITE_FILE_NODE;
41
    }
60
    }
42
61
	
43
}
62
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/DeploymentFileProxyNode.java (+19 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
17
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.TestUIImages;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
20
21
Lines 36-41 Link Here
36
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_DEPLOYMENT);
37
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_DEPLOYMENT);
37
	}
38
	}
38
39
40
	public String getFactoryID() {
41
		return EMFResourceProxyFactory.ID; 
42
	}
43
	
44
	public boolean saveState(IMemento memento) {
45
		//- data to retrieve the correct object 
46
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.DEPLOY_FILE_NODE);
47
		//- data from EMFResourceProxyNode
48
		memento.putString(TestUIConstants.TAG_NAME, getText());
49
		IProxyNode [] children = getChildren();
50
		for (int i = 0; i < children.length; i++) {
51
			if(!saveChildState(memento, children[i])) {
52
				return false;
53
			}
54
		}
55
		return true;
56
	}
57
	
39
	protected String getNodeKind() {
58
	protected String getNodeKind() {
40
		return TestUIConstants.DEPLOY_FILE_NODE;
59
		return TestUIConstants.DEPLOY_FILE_NODE;
41
	}
60
	}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/FileFactoryManager.java (-2 / +2 lines)
Lines 151-157 Link Here
151
			if (value instanceof IConfigurationElement) {
151
			if (value instanceof IConfigurationElement) {
152
				//- if the factory has not yet been loaded
152
				//- if the factory has not yet been loaded
153
				IConfigurationElement element = (IConfigurationElement) value;
153
				IConfigurationElement element = (IConfigurationElement) value;
154
				IFileProxyFactory factory; //$NON-NLS-1$
154
				IFileProxyFactory factory;
155
				try {
155
				try {
156
					if(element.getName().equals("file")) { //$NON-NLS-1$
156
					if(element.getName().equals("file")) { //$NON-NLS-1$
157
						//- old extension point
157
						//- old extension point
Lines 166-172 Link Here
166
				} catch (CoreException e) {
166
				} catch (CoreException e) {
167
					//- remove this element since we can not create a factory from it
167
					//- remove this element since we can not create a factory from it
168
					factories.remove(id);
168
					factories.remove(id);
169
					UiPlugin.logError("Enable to create the factory instance from configuration element");  //$NON-NLS-1$//$NON-NLS-2$
169
					UiPlugin.logError("Enable to create the factory instance from configuration element");  //$NON-NLS-1$
170
					return null;
170
					return null;
171
				}
171
				}
172
			} else if(value instanceof IFileProxyFactory) {
172
			} else if(value instanceof IFileProxyFactory) {
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/LocationFileProxyNode.java (-1 / +20 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
17
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.TestUIImages;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
20
21
Lines 35-42 Link Here
35
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_LOCATION);
36
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_LOCATION);
36
	}
37
	}
37
	
38
	
39
	public String getFactoryID() {
40
		return EMFResourceProxyFactory.ID;
41
	}
42
	
43
	public boolean saveState(IMemento memento) {
44
		//- data to retrieve the correct object 
45
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.LOCATION_FILE_NODE);
46
		//- data from EMFResourceProxyNode
47
		memento.putString(TestUIConstants.TAG_NAME, getText());
48
		IProxyNode [] children = getChildren();
49
		for (int i = 0; i < children.length; i++) {
50
			if(!saveChildState(memento, children[i])) {
51
				return false;
52
			}
53
		}
54
		return true;
55
	}	
56
	
38
	protected String getNodeKind() {
57
	protected String getNodeKind() {
39
    	return TestUIConstants.LOCATION_FILE_NODE;
58
    	return TestUIConstants.LOCATION_FILE_NODE;
40
    }
59
    }
41
60
	
42
}
61
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/FileProxyMetadataPersister.java (-1 / +4 lines)
Lines 26-31 Link Here
26
import java.util.zip.GZIPOutputStream;
26
import java.util.zip.GZIPOutputStream;
27
27
28
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.runtime.Assert;
29
import org.eclipse.core.runtime.IPath;
30
import org.eclipse.core.runtime.IPath;
30
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.core.runtime.Platform;
31
import org.eclipse.hyades.test.ui.TestUIConstants;
32
import org.eclipse.hyades.test.ui.TestUIConstants;
Lines 126-132 Link Here
126
        if(factory != null) {
127
        if(factory != null) {
127
            if(factory instanceof IPersistableFileProxyFactory) {
128
            if(factory instanceof IPersistableFileProxyFactory) {
128
                try {
129
                try {
129
                    return ((IPersistableFileProxyFactory)factory).recreate(memento, file, FileProxyNodeCache.unboundedParent);
130
                    IProxyNode proxy = ((IPersistableFileProxyFactory)factory).recreate(memento, file, FileProxyNodeCache.unboundedParent);
131
                    Assert.isLegal(file.equals(proxy.getAdapter(IFile.class)), "invalid proxy returned by factory"); //$NON-NLS-1$
132
					return proxy;
130
                } catch (IllegalArgumentException e) {
133
                } catch (IllegalArgumentException e) {
131
                    //- problem encountered during load
134
                    //- problem encountered during load
132
                    return null;
135
                    return null;
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/ArtifactFileProxyNode.java (+19 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
17
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.TestUIImages;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
20
21
Lines 36-41 Link Here
36
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_ARTIFACT);
37
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_ARTIFACT);
37
	}
38
	}
38
39
40
	public String getFactoryID() {
41
		return EMFResourceProxyFactory.ID;
42
	}
43
	
44
	public boolean saveState(IMemento memento) {
45
		//- data to retrieve the correct object 
46
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.ARTIFACT_FILE_NODE);
47
		//- data from EMFResourceProxyNode
48
		memento.putString(TestUIConstants.TAG_NAME, getText());
49
		IProxyNode [] children = getChildren();
50
		for (int i = 0; i < children.length; i++) {
51
			if(!saveChildState(memento, children[i])) {
52
				return false;
53
			}
54
		}
55
		return true;
56
	}
57
	
39
	public String getNodeKind() {
58
	public String getNodeKind() {
40
		return TestUIConstants.ARTIFACT_FILE_NODE;
59
		return TestUIConstants.ARTIFACT_FILE_NODE;
41
	}
60
	}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/EObjectProxyAdapterFactory.java (-26 lines)
Lines 12-18 Link Here
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
13
13
14
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.IAdapterFactory;
15
import org.eclipse.core.runtime.IAdapterFactory;
17
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.ecore.resource.Resource;
17
import org.eclipse.emf.ecore.resource.Resource;
Lines 26-56 Link Here
26
 */
25
 */
27
public class EObjectProxyAdapterFactory implements IAdapterFactory {
26
public class EObjectProxyAdapterFactory implements IAdapterFactory {
28
27
29
	private static class Proxy implements IProxy {
30
31
		private String identifier;
32
		private IResource underlyingResource;
33
34
		/**
35
		 * @param identifier
36
		 * @param underlyingResource
37
		 */
38
		public Proxy(IResource underlyingResource, String identifier) {
39
			super();
40
			this.identifier = identifier;
41
			this.underlyingResource = underlyingResource;
42
		}
43
		
44
		public IResource getUnderlyingResource() {
45
			return underlyingResource;
46
		}
47
48
		public String getIdentifier() {
49
			return identifier;
50
		}
51
		
52
	}
53
	
54
	/* (non-Javadoc)
28
	/* (non-Javadoc)
55
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
29
	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
56
	 */
30
	 */
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/FileProxyMarkerPersister.java (-7 / +12 lines)
Lines 21-26 Link Here
21
import org.eclipse.core.resources.IMarker;
21
import org.eclipse.core.resources.IMarker;
22
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.WorkspaceJob;
23
import org.eclipse.core.resources.WorkspaceJob;
24
import org.eclipse.core.runtime.Assert;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IStatus;
27
import org.eclipse.core.runtime.IStatus;
Lines 47-57 Link Here
47
	private static final String TAG_FACTORY_ID = "factoryID"; //$NON-NLS-1$
48
	private static final String TAG_FACTORY_ID = "factoryID"; //$NON-NLS-1$
48
    private static final String TAG_PROXY_STATE = "proxyState"; //$NON-NLS-1$
49
    private static final String TAG_PROXY_STATE = "proxyState"; //$NON-NLS-1$
49
    private static final String TAG_LAST_SAVE_STAMP = "lastSaveStamp"; //$NON-NLS-1$
50
    private static final String TAG_LAST_SAVE_STAMP = "lastSaveStamp"; //$NON-NLS-1$
50
    private static final String MARKER_PROXYSTATE = "org.eclipse.hyades.test.ui.proxyStateMarker"; //$NON-NLS-1$
51
    public static final String MARKER_PROXYSTATE = "org.eclipse.hyades.test.ui.proxyStateMarker"; //$NON-NLS-1$
52
    
51
    
53
    
52
    private FileProxyMetadataPersister fallbackPersister = new FileProxyMetadataPersister();
54
    private FileProxyMetadataPersister fallbackPersister = new FileProxyMetadataPersister();
53
55
54
    /* (non-Javadoc)
56
    /*
55
	 * @see org.eclipse.hyades.test.ui.internal.navigator.proxy.IFileProxyPersister#loadProxy(org.eclipse.core.resources.IFile)
57
	 * @see org.eclipse.hyades.test.ui.internal.navigator.proxy.IFileProxyPersister#loadProxy(org.eclipse.core.resources.IFile)
56
	 */
58
	 */
57
    public IProxyNode loadProxy(IFile file) {
59
    public IProxyNode loadProxy(IFile file) {
Lines 99-105 Link Here
99
        if(factory != null) {
101
        if(factory != null) {
100
            if(factory instanceof IPersistableFileProxyFactory) {
102
            if(factory instanceof IPersistableFileProxyFactory) {
101
                try {
103
                try {
102
                    return ((IPersistableFileProxyFactory)factory).recreate(memento, file, FileProxyNodeCache.unboundedParent);
104
                    IProxyNode proxy = ((IPersistableFileProxyFactory)factory).recreate(memento, file, FileProxyNodeCache.unboundedParent);
105
                    Assert.isLegal(file.equals(proxy.getAdapter(IFile.class)), "invalid proxy returned by factory"); //$NON-NLS-1$
106
					return proxy;
103
                } catch (IllegalArgumentException e) {
107
                } catch (IllegalArgumentException e) {
104
                    //- problem encountered during load
108
                    //- problem encountered during load
105
                    return null;
109
                    return null;
Lines 123-140 Link Here
123
                    } catch (IllegalArgumentException e) {
127
                    } catch (IllegalArgumentException e) {
124
                        //- problem encountered during load
128
                        //- problem encountered during load
125
                        return null;
129
                        return null;
130
                    } catch (ProxyNeedToBeRebuiltException e) {
131
                        //- the factory encountered a problem retrieving information form memento.
132
                        //- this can be due to the fact that the persisted memento is an obsolete one.
133
                        return null;
126
                    }
134
                    }
127
                } else {
135
                } else {
128
                    //- saved marker contains id of a factory which can not recreate elements
136
                    //- saved marker contains id of a factory which can not recreate elements
129
                    UiPlugin.logError("The factory id: "+factoryID+" should be instanceof IPersistableTypedElementProxyFactory");  //$NON-NLS-1$//$NON-NLS-2$
137
                    UiPlugin.logError("The factory id: "+factoryID+" should be instanceof IPersistableTypedElementProxyFactory");  //$NON-NLS-1$//$NON-NLS-2$
130
                    return null;                            
138
                    return null;                            
131
                }
139
                }
132
            } else {
133
                //- saved marker contains an unknown id of a factory
134
                UiPlugin.logError("The persisted proxy for file: "+file.getName()+" contains an unknown factory ID");  //$NON-NLS-1$//$NON-NLS-2$
135
                return null;
136
            }
140
            }
137
        }
141
        }
142
        return null;
138
    }
143
    }
139
144
140
    /* (non-Javadoc)
145
    /* (non-Javadoc)
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/TypedElementFactoryManager.java (+1 lines)
Lines 111-116 Link Here
111
	 */
111
	 */
112
	public ITypedElementProxyFactory getFactoryFromID(String factoryID) {
112
	public ITypedElementProxyFactory getFactoryFromID(String factoryID) {
113
		Object value = factories.get(factoryID);
113
		Object value = factories.get(factoryID);
114
		if(value == null) return null;
114
		if (value instanceof IConfigurationElement) {
115
		if (value instanceof IConfigurationElement) {
115
			//- if the factory has not yet been loaded
116
			//- if the factory has not yet been loaded
116
			IConfigurationElement element = (IConfigurationElement) value;
117
			IConfigurationElement element = (IConfigurationElement) value;
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/EMFResourceProxyFactory.java (-1 / +1 lines)
Lines 40-46 Link Here
40
	/**
40
	/**
41
	 * Factory id.
41
	 * Factory id.
42
	 */
42
	 */
43
	public final static String ID = "EMFResourceProxyFactory"; //$NON-NLS-1$
43
	public final static String ID = "EMFResourceProxyFactory_4.3"; //$NON-NLS-1$
44
	
44
	
45
	/** This method is called to build a node that contains multiple EMF objects as children.
45
	/** This method is called to build a node that contains multiple EMF objects as children.
46
	 *  The object created depends of the extension of the file (.datapool -> DatapoolFileProxyNode)
46
	 *  The object created depends of the extension of the file (.datapool -> DatapoolFileProxyNode)
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/TestComponentFileProxyNode.java (-1 / +19 lines)
Lines 15-20 Link Here
15
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.resource.Resource;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIConstants;
17
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.TestUIImages;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.swt.graphics.Image;
19
import org.eclipse.ui.IMemento;
20
import org.eclipse.ui.IMemento;
20
21
Lines 36-43 Link Here
36
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_TEST_COMPONENT);
37
		return TestUIImages.INSTANCE.getImage(TestUIImages.IMG_TEST_COMPONENT);
37
	}
38
	}
38
	
39
	
40
	public String getFactoryID() {
41
		return EMFResourceProxyFactory.ID;
42
	}
43
	
44
	public boolean saveState(IMemento memento) {
45
		//- data to retrieve the correct object 
46
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.TESTCOMPONENT_FILE_NODE);
47
		//- data from EMFResourceProxyNode
48
		memento.putString(TestUIConstants.TAG_NAME, getText());
49
		IProxyNode [] children = getChildren();
50
		for (int i = 0; i < children.length; i++) {
51
			if(!saveChildState(memento, children[i]))
52
				return false;
53
		}
54
		return true;
55
	}
56
	
39
	protected String getNodeKind() {
57
	protected String getNodeKind() {
40
    	return TestUIConstants.TESTCOMPONENT_FILE_NODE;
58
    	return TestUIConstants.TESTCOMPONENT_FILE_NODE;
41
    }
59
    }
42
60
	
43
}
61
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/DatapoolProxyNode.java (+10 lines)
Lines 49-54 Link Here
49
		return new IProxyNode[0];
49
		return new IProxyNode[0];
50
	}
50
	}
51
	
51
	
52
	public String getFactoryID() {
53
		return EMFResourceProxyFactory.ID; 
54
	}
55
	
56
	public boolean saveState(IMemento memento) {
57
		//- data to retrieve the correct object 
58
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.DATAPOOL_NODE);
59
		return super.saveState(memento);
60
	}
61
	
52
	protected String getNodeKind() {
62
	protected String getNodeKind() {
53
		return TestUIConstants.DATAPOOL_NODE;
63
		return TestUIConstants.DATAPOOL_NODE;
54
	}
64
	}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/DeploymentProxyNode.java (+27 lines)
Lines 11-21 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
13
13
14
import java.util.Iterator;
15
16
import org.eclipse.hyades.models.common.configuration.CFGArtifact;
17
import org.eclipse.hyades.models.common.configuration.CFGLocation;
14
import org.eclipse.hyades.models.common.testprofile.TPFDeployment;
18
import org.eclipse.hyades.models.common.testprofile.TPFDeployment;
15
import org.eclipse.hyades.test.ui.TestUIConstants;
19
import org.eclipse.hyades.test.ui.TestUIConstants;
16
import org.eclipse.hyades.test.ui.TestUIImages;
20
import org.eclipse.hyades.test.ui.TestUIImages;
17
import org.eclipse.hyades.test.ui.navigator.CMNNamedElementProxyNode;
21
import org.eclipse.hyades.test.ui.navigator.CMNNamedElementProxyNode;
18
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
22
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
23
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
19
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.ui.IMemento;
25
import org.eclipse.ui.IMemento;
21
26
Lines 30-35 Link Here
30
	 */
35
	 */
31
	public DeploymentProxyNode(TPFDeployment deploy, Object parent) {
36
	public DeploymentProxyNode(TPFDeployment deploy, Object parent) {
32
		super(deploy, parent);
37
		super(deploy, parent);
38
		for (Iterator it = deploy.getArtifacts().iterator(); it.hasNext();) {
39
			IProxyNode artifact = FileProxyNodeCache.getInstance().getCorrespondingProxy( (CFGArtifact)it.next());
40
			if(artifact != null) {
41
				addBidirectionalReference("Deploy2Artifact", (IReferencerProxyNode) artifact, "Artifact2Deploy");  //$NON-NLS-1$//$NON-NLS-2$
42
			}
43
		}
44
		for (Iterator it = deploy.getLocations().iterator(); it.hasNext();) {
45
			IProxyNode location = FileProxyNodeCache.getInstance().getCorrespondingProxy((CFGLocation)it.next());
46
			if(location != null) {
47
				addBidirectionalReference("Deploy2Location", (IReferencerProxyNode) location, "Location2Deploy"); //$NON-NLS-1$ //$NON-NLS-2$
48
			}
49
		}
33
	}
50
	}
34
51
35
	/**
52
	/**
Lines 49-54 Link Here
49
		return new IProxyNode[0];
66
		return new IProxyNode[0];
50
	}
67
	}
51
	
68
	
69
	public String getFactoryID() {
70
		return EMFResourceProxyFactory.ID; 
71
	}
72
	
73
	public boolean saveState(IMemento memento) {
74
		//- data to retrieve the correct object 
75
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.DEPLOY_NODE);
76
		return super.saveState(memento);	
77
	}
78
	
52
	protected String getNodeKind() {
79
	protected String getNodeKind() {
53
    	return TestUIConstants.DEPLOY_NODE;
80
    	return TestUIConstants.DEPLOY_NODE;
54
    }
81
    }
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/FileProxyManager.java (-55 / +5 lines)
Lines 13-27 Link Here
13
13
14
import java.util.Collections;
14
import java.util.Collections;
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.Map;
16
import java.util.Map;
18
17
19
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
19
import org.eclipse.hyades.test.ui.navigator.IFileProxyManager;
24
import org.eclipse.hyades.test.ui.navigator.IProxy;
25
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
20
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
26
21
27
/**
22
/**
Lines 119-143 Link Here
119
	 * @return a proxy node which has the given uid or <code>null</code> if there is no such proxy found in the complete given tree of proxy.
114
	 * @return a proxy node which has the given uid or <code>null</code> if there is no such proxy found in the complete given tree of proxy.
120
	 */
115
	 */
121
	public IProxyNode findProxyByID(IProxyNode proxy, String uid) {
116
	public IProxyNode findProxyByID(IProxyNode proxy, String uid) {
122
		if(proxy == null) return proxy;
117
		return fileProxyNodeCache.findProxyByID(proxy, uid);
123
		//- only for root node that has no fragment part
124
		if(uid.length() > 0) {
125
			//- proxy found ?
126
			if(proxy.getIdentifier().equals(uid)) return proxy;
127
			else {
128
				//- search in its children array
129
				IProxyNode[] children = proxy.getChildren();
130
				for (int i = 0; i < children.length; i++) {
131
					proxy = findProxyByID(children[i], uid);
132
					if(proxy != null) {
133
						//- found !!
134
						return proxy;
135
					}
136
				}
137
				//- not found in this sub tree
138
				return null;
139
			}
140
		} else return proxy;
141
	}
118
	}
142
119
143
	/** 
120
	/** 
Lines 161-183 Link Here
161
	 * @return the proxy associated to the given object or <code>null</code> if such proxy node does not exist.
138
	 * @return the proxy associated to the given object or <code>null</code> if such proxy node does not exist.
162
	 */
139
	 */
163
	public IProxyNode getCorrespondingProxy(Object object) {
140
	public IProxyNode getCorrespondingProxy(Object object) {
164
		IProxy proxy;
141
		return fileProxyNodeCache.getCorrespondingProxy(object);
165
		if (object instanceof IAdaptable) {
166
			proxy = (IProxy) ((IAdaptable)object).getAdapter(IProxy.class);
167
		} else {
168
			proxy = (IProxy) Platform.getAdapterManager().getAdapter(object, IProxy.class);
169
		}
170
		if (proxy != null) {
171
			IResource res = proxy.getUnderlyingResource();
172
			if (res instanceof IFile) {
173
				IFile file = (IFile)res;
174
				IProxyNode fileProxy = getProxy(file, null);
175
				if (fileProxy != null) {
176
					return findProxyByID(fileProxy, proxy.getIdentifier());
177
				}
178
			}
179
		}
180
		return null;
181
	}
142
	}
182
	
143
	
183
	/** 
144
	/** 
Lines 185-206 Link Here
185
	 * @param fileName name of the underlying resource of the searched proxy
146
	 * @param fileName name of the underlying resource of the searched proxy
186
	 * @param identifier identifier of the searched proxy
147
	 * @param identifier identifier of the searched proxy
187
	 * @return a proxy node or <code>null</code> if not found.
148
	 * @return a proxy node or <code>null</code> if not found.
149
	 * @deprecated use {@link #getCorrespondingProxy(new Proxy(fileName, String))} instead.
188
	 */
150
	 */
189
	public IProxyNode getCorrespondingProxy(String fileName, String identifier) {
151
	public IProxyNode getCorrespondingProxy(String fileName, String identifier) {
190
		IProxyNode root = null;
152
		return getCorrespondingProxy(new Proxy(fileName, identifier));
191
		for (Iterator it = fileProxyNodeCache.filesIterator(); it.hasNext();) {
153
	}
192
			IFile file = (IFile) it.next();
193
			if(fileName.equals(file.getLocation().toOSString())) {
194
                //- since file is retrieve from the proxy cache, getProxy method will find the proxy in the cache.
195
				root = fileProxyNodeCache.getProxy(file);
196
				break;
197
			}
198
		}
199
		if(root != null) {
200
			return findProxyByID(root, identifier);
201
		}
202
		return null;
203
 	}
204
    
154
    
205
    /**
155
    /**
206
     * Returns the parent of the given proxy node.
156
     * Returns the parent of the given proxy node.
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/LocationProxyNode.java (-1 / +11 lines)
Lines 49-56 Link Here
49
		return new IProxyNode[0];
49
		return new IProxyNode[0];
50
	}
50
	}
51
	
51
	
52
	public String getFactoryID() {
53
		return EMFResourceProxyFactory.ID; 
54
	}
55
	
56
	public boolean saveState(IMemento memento) {
57
		//- data to retrieve the correct object 
58
		memento.putString(TestUIConstants.TAG_NODE_KIND, TestUIConstants.LOCATION_NODE);
59
		return super.saveState(memento);	
60
	}
61
	
52
	protected String getNodeKind() {
62
	protected String getNodeKind() {
53
    	return TestUIConstants.LOCATION_NODE;
63
    	return TestUIConstants.LOCATION_NODE;
54
    }
64
    }
55
65
	
56
}
66
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/TestNavigatorActionGroup.java (-56 / +36 lines)
Lines 60-66 Link Here
60
import org.eclipse.ui.actions.AddBookmarkAction;
60
import org.eclipse.ui.actions.AddBookmarkAction;
61
import org.eclipse.ui.actions.AddTaskAction;
61
import org.eclipse.ui.actions.AddTaskAction;
62
import org.eclipse.ui.actions.CloseResourceAction;
62
import org.eclipse.ui.actions.CloseResourceAction;
63
import org.eclipse.ui.actions.DeleteResourceAction;
64
import org.eclipse.ui.actions.OpenResourceAction;
63
import org.eclipse.ui.actions.OpenResourceAction;
65
import org.eclipse.ui.actions.RefreshAction;
64
import org.eclipse.ui.actions.RefreshAction;
66
import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
65
import org.eclipse.ui.actions.WorkingSetFilterActionGroup;
Lines 96-103 Link Here
96
	protected CloseResourceAction closeProjectAction;
95
	protected CloseResourceAction closeProjectAction;
97
	protected StopAction stopAction;
96
	protected StopAction stopAction;
98
97
99
	protected DeleteResourceAction deleteResourceAction;
98
	protected DeleteAction deleteAction;
100
	protected RemoveChildrenAction deleteChildEObject;
101
	
99
	
102
	protected NavigatorSorterActionGroup sorterActionGroup;
100
	protected NavigatorSorterActionGroup sorterActionGroup;
103
	protected NewActionGroup newActionGroup;
101
	protected NewActionGroup newActionGroup;
Lines 106-111 Link Here
106
	protected RenameAction renameAction;
104
	protected RenameAction renameAction;
107
	protected CopyAction copyAction;
105
	protected CopyAction copyAction;
108
	protected PasteAction pasteAction;
106
	protected PasteAction pasteAction;
107
	protected MoveAction moveAction;
109
    protected OpenWithActionGroup openWithActionGroup;
108
    protected OpenWithActionGroup openWithActionGroup;
110
	 	
109
	 	
111
	
110
	
Lines 133-138 Link Here
133
		renameAction.dispose();
132
		renameAction.dispose();
134
		stopAction.dispose();
133
		stopAction.dispose();
135
		pasteAction.dispose();
134
		pasteAction.dispose();
135
		moveAction.dispose();
136
		if(clipboard != null) {
136
		if(clipboard != null) {
137
			clipboard.dispose();
137
			clipboard.dispose();
138
			clipboard = null;
138
			clipboard = null;
Lines 186-217 Link Here
186
		TestUIImages.INSTANCE.setImageDescriptors(toggleEObjectChildren, TestUIImages.ACT_SHOW_EOBJECT_CHILDREN);
186
		TestUIImages.INSTANCE.setImageDescriptors(toggleEObjectChildren, TestUIImages.ACT_SHOW_EOBJECT_CHILDREN);
187
187
188
		ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
188
		ISharedImages images = PlatformUI.getWorkbench().getSharedImages();
189
		deleteResourceAction = new DeleteResourceAction(shell);
189
		deleteAction = new DeleteAction(shell);
190
		deleteResourceAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
190
		deleteAction.setDisabledImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
191
		deleteResourceAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));		
191
		deleteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));		
192
		deleteResourceAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
192
		deleteAction.setHoverImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
193
		
194
		deleteChildEObject = new RemoveChildrenAction(true)
195
		{
196
			protected List saveResources(Set changedResources)
197
			{
198
				TestNavigator testNavigator = (TestNavigator)getNavigator();
199
				testNavigator.getTreeViewer().remove(getStructuredSelection().toArray());
200
				
201
				testNavigator.setMonitoringResourceChange(false);
202
				try
203
				{
204
					return super.saveResources(changedResources);
205
				}
206
				finally
207
				{
208
					testNavigator.setMonitoringResourceChange(true);
209
				}
210
			}
211
		};
212
		deleteChildEObject.setStructuredViewer(((TestNavigator)getNavigator()).getViewer());
213
		deleteChildEObject.setShowErrorDialog(true);
214
		
215
		openReportAction = new OpenReportAction();	
193
		openReportAction = new OpenReportAction();	
216
		generateAction = new GenerateAction();	
194
		generateAction = new GenerateAction();	
217
        generateAction.setImageDescriptor(TestUIImages.INSTANCE.getImageDescriptor("e", TestUIImages.GENERATE_TEST));//$NON-NLS-1$ 
195
        generateAction.setImageDescriptor(TestUIImages.INSTANCE.getImageDescriptor("e", TestUIImages.GENERATE_TEST));//$NON-NLS-1$ 
Lines 222-233 Link Here
222
		stopAction = new StopAction();	
200
		stopAction = new StopAction();	
223
		renameAction = new RenameAction((TreeNavigator)getNavigator());
201
		renameAction = new RenameAction((TreeNavigator)getNavigator());
224
		pasteAction = new PasteAction(shell, clipboard);
202
		pasteAction = new PasteAction(shell, clipboard);
225
		pasteAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
203
		pasteAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
226
		pasteAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
204
		pasteAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED));
227
		copyAction = new CopyAction(clipboard);
205
		copyAction = new CopyAction(clipboard);
228
		copyAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
206
		copyAction.setImageDescriptor(images.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
229
		copyAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
207
		copyAction.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
230
		
208
		moveAction = new MoveAction(shell);
231
	}
209
	}
232
210
233
	/**
211
	/**
Lines 346-384 Link Here
346
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, stopAction);
324
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, stopAction);
347
			stopAction.setEnabled(stopAction.isApplicableForEnablement());
325
			stopAction.setEnabled(stopAction.isApplicableForEnablement());
348
		}
326
		}
349
		
327
		boolean isResourceTestNav = ((TestNavigator)getNavigator()).getCurrentViewIndex()==TestNavigator.VIEW_ID_RESOURCE;
350
		copyAction.selectionChanged(selection);
328
		copyAction.selectionChanged(selection, isResourceTestNav);
351
		if(copyAction.isApplicableForSelection()){
329
		if(copyAction.isApplicableForSelection()){
352
				menu.appendToGroup(INavigatorContribution.GROUP_DELETE, copyAction);
330
				menu.appendToGroup(INavigatorContribution.GROUP_DELETE, copyAction);
353
		}
331
		}
354
		
332
		
355
		pasteAction.selectionChanged(selection);
333
		pasteAction.selectionChanged(selection, isResourceTestNav);
356
		if(pasteAction.isApplicableForSelection()){
334
		if(pasteAction.isApplicableForSelection()){
357
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, pasteAction);
335
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, pasteAction);
358
		}
336
		}
359
					
337
					
360
		deleteResourceAction.setEnabled(false);		
338
		moveAction.selectionChanged(selection, isResourceTestNav);
361
		if(resSelection.size() == selection.size())
339
		if(moveAction.isApplicableForSelection()){
362
		{
340
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, moveAction);
363
			deleteResourceAction.selectionChanged(resSelection);
364
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, deleteResourceAction);
365
			
366
			addBookmarkAction.selectionChanged(resSelection);
367
			if(addBookmarkAction.isEnabled())
368
				menu.appendToGroup(INavigatorContribution.GROUP_DELETE, addBookmarkAction);
369
		}
341
		}
370
		if(!deleteResourceAction.isEnabled()){
342
		
371
			menu.add(new Separator());
343
		deleteAction.selectionChanged(selection);
372
			deleteChildEObject.selectionChanged(selection);
344
		if(deleteAction.isEnabled()) {
373
			if(deleteChildEObject.isEnabled())
345
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, deleteAction);
374
				menu.add(deleteChildEObject);
375
		}
346
		}
376
347
		
377
		renameAction.selectionChanged(selection);
348
		renameAction.selectionChanged(selection);
378
		if(renameAction.isApplicableForSelection())	{
349
		if(renameAction.isApplicableForSelection())	{
379
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, renameAction);
350
			menu.appendToGroup(INavigatorContribution.GROUP_DELETE, renameAction);
380
		}
351
		}
381
352
353
		if(resSelection.size() == selection.size() && selection.size() > 0)
354
		{
355
			addBookmarkAction.selectionChanged(resSelection);
356
			if(addBookmarkAction.isEnabled())
357
				menu.appendToGroup(INavigatorContribution.GROUP_DELETE, addBookmarkAction);
358
		}
359
382
		if(selection.size() == 1) {
360
		if(selection.size() == 1) {
383
			propertyDialogAction.selectionChanged(selection);
361
			propertyDialogAction.selectionChanged(selection);
384
			if(propertyDialogAction.isApplicableForSelection())
362
			if(propertyDialogAction.isApplicableForSelection())
Lines 394-400 Link Here
394
		actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(),	propertyDialogAction);
372
		actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(),	propertyDialogAction);
395
		actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), addBookmarkAction);
373
		actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), addBookmarkAction);
396
		actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), addTaskAction);
374
		actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), addTaskAction);
397
		actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteResourceAction);
375
		actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction);
398
376
399
		frameListActionGroup.fillActionBars(actionBars);
377
		frameListActionGroup.fillActionBars(actionBars);
400
		newActionGroup.fillActionBars(actionBars);
378
		newActionGroup.fillActionBars(actionBars);
Lines 432-444 Link Here
432
		
410
		
433
		propertyDialogAction.setEnabled(structuredSelection.size() == 1);
411
		propertyDialogAction.setEnabled(structuredSelection.size() == 1);
434
		addBookmarkAction.selectionChanged(resourceStructuredSelection);
412
		addBookmarkAction.selectionChanged(resourceStructuredSelection);
435
		deleteResourceAction.selectionChanged(resourceStructuredSelection);
413
		deleteAction.selectionChanged(resourceStructuredSelection);
436
		addTaskAction.selectionChanged(structuredSelection);	
414
		addTaskAction.selectionChanged(structuredSelection);	
437
		refreshAction.selectionChanged(structuredSelection);
415
		refreshAction.selectionChanged(structuredSelection);
438
		openProjectAction.selectionChanged(structuredSelection);
416
		openProjectAction.selectionChanged(structuredSelection);
439
		closeProjectAction.selectionChanged(structuredSelection);
417
		closeProjectAction.selectionChanged(structuredSelection);
440
		copyAction.selectionChanged(structuredSelection);
418
		boolean isResourceTestNav = ((TestNavigator)getNavigator()).getCurrentViewIndex()==TestNavigator.VIEW_ID_RESOURCE;
441
		pasteAction.selectionChanged(structuredSelection);
419
		copyAction.selectionChanged(structuredSelection, isResourceTestNav);
420
		pasteAction.selectionChanged(structuredSelection, isResourceTestNav);
421
		moveAction.selectionChanged(structuredSelection, isResourceTestNav);
442
		renameAction.selectionChanged(structuredSelection);
422
		renameAction.selectionChanged(structuredSelection);
443
423
444
	
424
	
Lines 465-472 Link Here
465
	{
445
	{
466
		if(event.character == SWT.DEL && (event.stateMask == SWT.None))
446
		if(event.character == SWT.DEL && (event.stateMask == SWT.None))
467
		{
447
		{
468
			if(deleteResourceAction.isEnabled())
448
			if(deleteAction.isEnabled())
469
				deleteResourceAction.run();
449
				deleteAction.run();
470
				//- Swallow the event.
450
				//- Swallow the event.
471
				event.doit = false;
451
				event.doit = false;
472
		}
452
		}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/RenameAction.java (-24 / +153 lines)
Lines 19-43 Link Here
19
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.SubProgressMonitor;
21
import org.eclipse.core.runtime.SubProgressMonitor;
22
import org.eclipse.hyades.test.ui.UiPlugin;
22
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
23
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
24
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.RenameRefactoring;
23
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
25
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
26
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
24
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer;
27
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer;
28
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer2;
25
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIStatus;
29
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIStatus;
26
import org.eclipse.hyades.ui.internal.navigator.TreeNavigator;
30
import org.eclipse.hyades.ui.internal.navigator.TreeNavigator;
27
import org.eclipse.hyades.ui.util.IDisposable;
31
import org.eclipse.hyades.ui.util.IDisposable;
28
import org.eclipse.jface.action.Action;
32
import org.eclipse.jface.action.Action;
33
import org.eclipse.jface.dialogs.Dialog;
29
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
34
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
30
import org.eclipse.jface.viewers.IStructuredSelection;
35
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.jface.viewers.StructuredSelection;
36
import org.eclipse.jface.viewers.StructuredSelection;
37
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
38
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
39
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
32
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.custom.TreeEditor;
41
import org.eclipse.swt.custom.TreeEditor;
34
import org.eclipse.swt.events.FocusAdapter;
42
import org.eclipse.swt.events.FocusAdapter;
35
import org.eclipse.swt.events.FocusEvent;
43
import org.eclipse.swt.events.FocusEvent;
44
import org.eclipse.swt.events.ModifyEvent;
45
import org.eclipse.swt.events.ModifyListener;
36
import org.eclipse.swt.graphics.Point;
46
import org.eclipse.swt.graphics.Point;
47
import org.eclipse.swt.layout.GridData;
48
import org.eclipse.swt.layout.GridLayout;
37
import org.eclipse.swt.widgets.Composite;
49
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Display;
50
import org.eclipse.swt.widgets.Display;
39
import org.eclipse.swt.widgets.Event;
51
import org.eclipse.swt.widgets.Event;
52
import org.eclipse.swt.widgets.Label;
40
import org.eclipse.swt.widgets.Listener;
53
import org.eclipse.swt.widgets.Listener;
54
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.swt.widgets.Text;
55
import org.eclipse.swt.widgets.Text;
42
import org.eclipse.swt.widgets.Tree;
56
import org.eclipse.swt.widgets.Tree;
43
import org.eclipse.swt.widgets.TreeItem;
57
import org.eclipse.swt.widgets.TreeItem;
Lines 60-65 Link Here
60
	protected TreeNavigator navigator;
74
	protected TreeNavigator navigator;
61
	protected IContainer renamedResource;
75
	protected IContainer renamedResource;
62
76
77
	private class RenameRefactoringWizard extends RefactoringWizard {
78
		private RenameRefactoringNewNameInputPage page;
79
80
		private RenameRefactoringWizard(RenameRefactoring refactoring, String name) {
81
			super(refactoring, DIALOG_BASED_USER_INTERFACE/* | NONE*/);
82
			this.page = new RenameRefactoringNewNameInputPage(refactoring, name);
83
		}
84
85
		protected void addUserInputPages() {
86
			addPage(page);
87
		}
88
	}
89
90
	class RenameRefactoringNewNameInputPage extends UserInputWizardPage {
91
		private RenameRefactoring refactoring;
92
		private Text nameText;
93
		private String oldName;
94
		private String newName;
95
		
96
		public RenameRefactoringNewNameInputPage(RenameRefactoring refactoring, String oldName) {
97
			super(""); //$NON-NLS-1$
98
			this.oldName = oldName;
99
			this.refactoring = refactoring;
100
		}
101
102
		public void createControl(Composite parent) {
103
			Composite result= new Composite(parent, SWT.NONE);
104
			setControl(result);
105
			result.setLayout(new GridLayout(2, false));
106
			
107
			Label label= new Label(result, SWT.NONE);
108
			label.setText(ActionMessages.RENAME_NEW_NAME_LABEL);
109
			nameText = new Text(result, SWT.SINGLE | SWT.BORDER);
110
			nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
111
			nameText.setText(oldName);
112
			nameText.addModifyListener(new ModifyListener() {
113
				public void modifyText(ModifyEvent e) {
114
					newName = nameText.getText();
115
					refactoring.setNewName(newName);
116
					setPageComplete(isPageComplete());
117
				}
118
			});
119
			nameText.selectAll();
120
			Dialog.applyDialogFont(result);
121
		}
122
123
		public boolean isPageComplete() {
124
			return newName != null && newName.length() > 0 && !newName.equals(oldName);
125
		}
126
	}
127
	
63
	public RenameAction(TreeNavigator treeNav) {
128
	public RenameAction(TreeNavigator treeNav) {
64
		super(TestNavigatorMessages.RenameAction_ActionName);
129
		super(TestNavigatorMessages.RenameAction_ActionName);
65
		this.navigator = treeNav;
130
		this.navigator = treeNav;
Lines 82-97 Link Here
82
			return true;
147
			return true;
83
		} else if (objSelected instanceof IProxyNode) {
148
		} else if (objSelected instanceof IProxyNode) {
84
			IProxyNode proxy = (IProxyNode) objSelected;
149
			IProxyNode proxy = (IProxyNode) objSelected;
85
			IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class);
150
			IProxyNodeRenamer2 renamer2 = (IProxyNodeRenamer2)proxy.getAdapter(IProxyNodeRenamer2.class);
86
			if (renamer != null) {
151
			if(renamer2 != null) {
87
				return renamer.isApplicableFor();
152
				return true;
88
			} else {
89
				//- this means that there is no renamer for this proxy
90
				return false;
91
			}
153
			}
92
		} else {
154
			oldActionValidation(proxy);
93
			return false;
94
		}
155
		}
156
		return false;
157
	}
158
159
	/**
160
	 * @param proxy
161
	 * @return
162
	 * @deprecated
163
	 */
164
	private boolean oldActionValidation(IProxyNode proxy) {
165
		IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class);
166
		if (renamer != null) {
167
			return renamer.isApplicableFor();
168
		}
169
		return false;
95
	}
170
	}
96
171
97
	/**
172
	/**
Lines 111-117 Link Here
111
	 * Create the text editor widget.
186
	 * Create the text editor widget.
112
	 * This code has been imported from RenameResourceAction
187
	 * This code has been imported from RenameResourceAction
113
	 * @param renamer
188
	 * @param renamer
114
	 * 
189
	 * @deprecated
115
	 */
190
	 */
116
	private void createTextEditor(final IProxyNodeRenamer renamer) {
191
	private void createTextEditor(final IProxyNodeRenamer renamer) {
117
		//- Create text editor parent.  This draws a nice bounding rect.
192
		//- Create text editor parent.  This draws a nice bounding rect.
Lines 165-170 Link Here
165
			textActionHandler.addText(textEditor);
240
			textActionHandler.addText(textEditor);
166
	}
241
	}
167
242
243
	/**
244
	 * 
245
	 * @param renamer
246
	 * @param newName
247
	 * @deprecated
248
	 */
168
	protected void performRename(final IProxyNodeRenamer renamer, final String newName) {
249
	protected void performRename(final IProxyNodeRenamer renamer, final String newName) {
169
		Runnable query = new Runnable() {
250
		Runnable query = new Runnable() {
170
			public void run() {
251
			public void run() {
Lines 242-247 Link Here
242
	 * This code is inspired from RenameResourceAction
323
	 * This code is inspired from RenameResourceAction
243
	 * @param oldName current value of the selected item
324
	 * @param oldName current value of the selected item
244
	 * @param renamer
325
	 * @param renamer
326
	 * @deprecated
245
	 */
327
	 */
246
	private void getNewNameInline(String oldName, IProxyNodeRenamer renamer) {
328
	private void getNewNameInline(String oldName, IProxyNodeRenamer renamer) {
247
		//- Make sure text editor is created only once. 
329
		//- Make sure text editor is created only once. 
Lines 265-292 Link Here
265
		Object objSelected = selection.getFirstElement();
347
		Object objSelected = selection.getFirstElement();
266
		if (objSelected instanceof IContainer) {
348
		if (objSelected instanceof IContainer) {
267
			renamedResource = (IContainer)objSelected;
349
			renamedResource = (IContainer)objSelected;
268
			//- reuse the inline editor to rename a project or folder node
350
			preformContainerRefactoringRename(renamedResource);
269
			getNewNameInline(((IContainer)objSelected).getName(), null);
270
		} else if (objSelected instanceof IProxyNode) {
351
		} else if (objSelected instanceof IProxyNode) {
271
			IProxyNode proxy = (IProxyNode) objSelected;
352
			IProxyNode proxy = (IProxyNode) objSelected;
272
			IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class);
353
			IProxyNodeRenamer2 renamer2 = (IProxyNodeRenamer2)proxy.getAdapter(IProxyNodeRenamer2.class);
273
			if (renamer != null) {
354
			if(renamer2 != null) {
274
				RenamerUIStatus status = renamer.performUserInteraction(proxy.getText());
355
				performProxyRefactoringRename(proxy);
275
				switch (status.getStatus()) {
356
			} else {
276
					case RenamerUIStatus.OK :
357
				IReferencerProxyNode ref = (IReferencerProxyNode)proxy.getAdapter(IReferencerProxyNode.class);
277
						performRename(renamer, status.getNewName());
358
				if(ref != null) {
278
						break;
359
					performProxyRefactoringRename(proxy);
279
					case RenamerUIStatus.CANCEL :
360
				} else {
280
						//- nothing to do 
361
					performOldRename(proxy);
281
						break;
282
					case RenamerUIStatus.INLINE_EDITOR :
283
						getNewNameInline(proxy.getText(), renamer);
284
						break;
285
				}
362
				}
286
			}
363
			}
287
		}
364
		}
288
	}
365
	}
289
366
367
	/**
368
	 * @param proxy
369
	 * @deprecated
370
	 */
371
	private void performOldRename(IProxyNode proxy) {
372
		//- this code will be removed in 5.0
373
		IProxyNodeRenamer renamer = (IProxyNodeRenamer) proxy.getAdapter(IProxyNodeRenamer.class);
374
		if (renamer != null) {
375
			RenamerUIStatus status = renamer.performUserInteraction(proxy.getText());
376
			switch (status.getStatus()) {
377
			case RenamerUIStatus.OK :
378
				performRename(renamer, status.getNewName());
379
				break;
380
			case RenamerUIStatus.CANCEL :
381
				//- nothing to do 
382
				break;
383
			case RenamerUIStatus.INLINE_EDITOR :
384
				getNewNameInline(proxy.getText(), renamer);
385
				break;
386
			}
387
		}
388
	}
389
390
	private void preformContainerRefactoringRename(IContainer container) {
391
		RenameRefactoring refactoring = new RenameRefactoring(container);
392
		performRefactoringRename(refactoring, container.getName());
393
	}
394
395
	private void performProxyRefactoringRename(IProxyNode proxy) {
396
		RenameRefactoring refactoring = new RenameRefactoring(proxy);
397
		performRefactoringRename(refactoring, proxy.getText());
398
	}
399
400
	private void performRefactoringRename(final RenameRefactoring refactoring, final String oldName) {
401
		Shell shell = Display.getCurrent().getActiveShell();
402
		if (! canActivate(shell))
403
			return;
404
		RefactoringWizard wizard = new RenameRefactoringWizard(refactoring, oldName);
405
		wizard.setDefaultPageTitle(ActionMessages.RENAME_ACTION_NAME);
406
		wizard.setNeedsProgressMonitor(true);
407
		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
408
		try {
409
			op.run(shell , ""); //$NON-NLS-1$
410
		} catch (InterruptedException e) {
411
			UiPlugin.logError(e);
412
		}
413
	}
414
415
	private boolean canActivate(Shell shell) {
416
		return EditorUtil.saveEditors(shell);
417
	}
418
290
	public void selectionChanged(IStructuredSelection structuredSelection) {
419
	public void selectionChanged(IStructuredSelection structuredSelection) {
291
		selection = structuredSelection;
420
		selection = structuredSelection;
292
	}
421
	}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/FileProxyInContainerPaste.java (-2 / +3 lines)
Lines 29-37 Link Here
29
 * Paste action for the resource mode.
29
 * Paste action for the resource mode.
30
 * @author jgout
30
 * @author jgout
31
 * @since 3.3
31
 * @since 3.3
32
 * @deprecated
32
 */
33
 */
33
public class FileProxyInContainerPaste implements IPaster {
34
public class FileProxyInContainerPaste implements IPaster {
34
35
	
35
	private IResource [] getResourceFromClipboard(final Clipboard clipboard) {
36
	private IResource [] getResourceFromClipboard(final Clipboard clipboard) {
36
		final IResource[][] clipboardData = new IResource[1][];
37
		final IResource[][] clipboardData = new IResource[1][];
37
		Display.getCurrent().syncExec(new Runnable() {
38
		Display.getCurrent().syncExec(new Runnable() {
Lines 65-71 Link Here
65
		}
66
		}
66
		return false;
67
		return false;
67
	}
68
	}
68
69
	
69
	public boolean performPaste(Clipboard clipboard, Object selection) {
70
	public boolean performPaste(Clipboard clipboard, Object selection) {
70
		// - check for internal copy (inside eclipse)
71
		// - check for internal copy (inside eclipse)
71
		IResource [] res = getResourceFromClipboard(clipboard);
72
		IResource [] res = getResourceFromClipboard(clipboard);
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/PasteAction.java (-6 / +15 lines)
Lines 13-18 Link Here
13
13
14
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.IPasterExtended;
16
import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle;
17
import org.eclipse.hyades.test.ui.internal.resources.UiPluginResourceBundle;
17
import org.eclipse.hyades.test.ui.navigator.actions.IPaster;
18
import org.eclipse.hyades.test.ui.navigator.actions.IPaster;
18
import org.eclipse.hyades.ui.util.IDisposable;
19
import org.eclipse.hyades.ui.util.IDisposable;
Lines 31-36 Link Here
31
	protected Clipboard clipboard;
32
	protected Clipboard clipboard;
32
	private IStructuredSelection selection;
33
	private IStructuredSelection selection;
33
	private Shell shell;
34
	private Shell shell;
35
	private boolean isResourceNav;
34
	
36
	
35
	public PasteAction(Shell shell, Clipboard clipboard) {
37
	public PasteAction(Shell shell, Clipboard clipboard) {
36
		super(UiPluginResourceBundle.command_Paste); 
38
		super(UiPluginResourceBundle.command_Paste); 
Lines 40-45 Link Here
40
		if (clipboard == null)
42
		if (clipboard == null)
41
			throw new IllegalArgumentException("Unable to perform paste action due to 'clipboard == null'"); //$NON-NLS-1$
43
			throw new IllegalArgumentException("Unable to perform paste action due to 'clipboard == null'"); //$NON-NLS-1$
42
		this.clipboard = clipboard;
44
		this.clipboard = clipboard;
45
		this.isResourceNav = false;
43
	}
46
	}
44
	
47
	
45
	public void dispose() {
48
	public void dispose() {
Lines 49-61 Link Here
49
		clipboard = null;
52
		clipboard = null;
50
		shell = null;
53
		shell = null;
51
	}
54
	}
52
	
55
		
53
	public void run() {
56
	public void run() {
54
		Object target = selection != null ? selection.getFirstElement() : null;
57
		Object target = selection != null ? selection.getFirstElement() : null;
55
		if(target != null) {
58
		if(target != null) {			
56
			IPaster [] pasters = PasteExtensionManager.getInstance().getPasters(target);
59
			IPaster [] pasters = PasteExtensionManager.getInstance().getPasters(target);			
57
			for (int i = 0; i < pasters.length; i++) {
60
			for (int i = 0; i < pasters.length; i++) {
58
				IPaster paster = pasters[i];
61
				IPaster paster = pasters[i];
62
				if (paster instanceof IPasterExtended) {
63
					((IPasterExtended)paster).setShell(shell);
64
				}
59
				if(paster.performPaste(clipboard, target)) {
65
				if(paster.performPaste(clipboard, target)) {
60
					return;
66
					return;
61
				}
67
				}
Lines 82-89 Link Here
82
			}
88
			}
83
		});
89
		});
84
		return clipboardData[0];
90
		return clipboardData[0];
85
	}
91
	}	
86
	
92
87
	private boolean doesClipboardContainProjects() {
93
	private boolean doesClipboardContainProjects() {
88
		//- if clipboard contains a project, paste is valid if project is open
94
		//- if clipboard contains a project, paste is valid if project is open
89
		IResource [] res = getResourceFromClipboard();
95
		IResource [] res = getResourceFromClipboard();
Lines 100-105 Link Here
100
	}
106
	}
101
	
107
	
102
	public boolean isApplicableForSelection() {
108
	public boolean isApplicableForSelection() {
109
		//- paste action is only allowed for resource view of the test navigator
110
		if(!isResourceNav) return false;
103
		//- regardless the selection if clipboard contains a project, this is possible to paste it.
111
		//- regardless the selection if clipboard contains a project, this is possible to paste it.
104
		if (doesClipboardContainProjects()) {
112
		if (doesClipboardContainProjects()) {
105
			return true;
113
			return true;
Lines 116-122 Link Here
116
		return false;
124
		return false;
117
	}
125
	}
118
	
126
	
119
	public void selectionChanged(IStructuredSelection structuredSelection) {
127
	public void selectionChanged(IStructuredSelection structuredSelection, boolean isResourceNav) {
120
		selection = structuredSelection;
128
		selection = structuredSelection;
129
		this.isResourceNav = isResourceNav;
121
	}
130
	}
122
}
131
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/CopyAction.java (-48 / +47 lines)
Lines 49-54 Link Here
49
public class CopyAction extends Action implements IDisposable {
49
public class CopyAction extends Action implements IDisposable {
50
	private Clipboard clipboard;
50
	private Clipboard clipboard;
51
	private IStructuredSelection selection;
51
	private IStructuredSelection selection;
52
	private boolean isResourceNav;
52
	
53
	
53
	static class ClipboardManager {
54
	static class ClipboardManager {
54
		private Map clipboardContent;
55
		private Map clipboardContent;
Lines 138-143 Link Here
138
			throw new IllegalArgumentException("Unable to perform copy action due to 'clipboard == null'"); //$NON-NLS-1$
139
			throw new IllegalArgumentException("Unable to perform copy action due to 'clipboard == null'"); //$NON-NLS-1$
139
		}
140
		}
140
		this.clipboard = clipboard;
141
		this.clipboard = clipboard;
142
		this.isResourceNav = false;
141
	}
143
	}
142
	
144
	
143
	public void dispose() {
145
	public void dispose() {
Lines 158-186 Link Here
158
		}
160
		}
159
	}
161
	}
160
162
161
	private boolean copyResources() {
163
	private void copyOneResource(IResource res) {
162
		if(selection.getFirstElement() instanceof IResource) {
164
		IPath location = res.getLocation();
163
			ClipboardManager.getInstance().clear();
165
		if (location != null) {
164
			List selectedResources = selection.toList();
166
			//- file path to be used in external copy
165
			for (Iterator it = selectedResources.iterator(); it.hasNext();) {
167
			ClipboardManager.getInstance().addFile(location.toOSString());
166
				IResource res = (IResource) it.next();
168
		}
167
				IPath location = res.getLocation();
169
		//- file name to by used in textual context copy 
168
				if (location != null) {
170
		ClipboardManager.getInstance().addText(res.getName());
169
					//- file path to be used in external copy
171
		//- resource itself to be used in internal copy (inside Eclipse)
170
					ClipboardManager.getInstance().addFile(location.toOSString());
172
		ClipboardManager.getInstance().addResource(res);
171
				}
172
				//- file name to by used in textual context copy 
173
				ClipboardManager.getInstance().addText(res.getName());
174
				//- resource itself to be used in internal copy (inside Eclipse)
175
				ClipboardManager.getInstance().addResource(res);
176
			}
177
			setClipboard();
178
			return true;
179
		} else {
180
			return false;
181
		}
182
	}
173
	}
183
174
	
184
	/** Tests whether the given proxy is a proxy of file or not
175
	/** Tests whether the given proxy is a proxy of file or not
185
	 * @param proxy
176
	 * @param proxy
186
	 * @return true if this proxy replaces a file
177
	 * @return true if this proxy replaces a file
Lines 190-226 Link Here
190
		return proxy instanceof FileProxyNode || parent instanceof IContainer;
181
		return proxy instanceof FileProxyNode || parent instanceof IContainer;
191
	}
182
	}
192
183
193
	private void copyProxies() {
184
	private void copyOneProxy(IProxyNode proxy) {
194
		if(selection.getFirstElement() instanceof IProxyNode) {
185
		if(isAFileProxy(proxy)) {
195
			ClipboardManager.getInstance().clear();
186
			IResource res = proxy.getUnderlyingResource();
196
			List proxies = selection.toList();
187
			IPath location = res.getLocation();
197
			for (Iterator it = proxies.iterator(); it.hasNext();) {
188
			if (location != null) {
198
				IProxyNode proxy = (IProxyNode) it.next();
189
				//- external file path of the underlying resource to be used in external copy
199
				if(isAFileProxy(proxy)) {
190
				ClipboardManager.getInstance().addFile(location.toOSString());
200
					IResource res = proxy.getUnderlyingResource();
191
			}
201
					IPath location = res.getLocation();
192
			//- underlying resource to be used in internal copy (inside Eclipse)
202
					if (location != null) {
193
			ClipboardManager.getInstance().addResource(res);
203
						//- external file path of the underlying resource to be used in external copy
194
		}
204
						ClipboardManager.getInstance().addFile(location.toOSString());
195
		//- Fully qualified proxy name to by used in textual context copy 
205
					}
196
		ClipboardManager.getInstance().addText(proxy.getClass().getName()+"::"+proxy.getText()); //$NON-NLS-1$
206
					//- underlying resource to be used in internal copy (inside Eclipse)
197
207
					ClipboardManager.getInstance().addResource(res);
198
		//- proxy itself for test navigator context copy
199
		ClipboardManager.getInstance().addProxy(proxy);
200
	}
201
		
202
	private void copySelection() {
203
		ClipboardManager.getInstance().clear();
204
		List allSelected = selection.toList();
205
		for (Iterator it = allSelected.iterator(); it.hasNext();) {
206
			Object item = (it.next());
207
			if (item instanceof IResource) {
208
				copyOneResource((IResource)item);
209
			} else {
210
				if (item instanceof IProxyNode) {
211
					copyOneProxy((IProxyNode)item);
208
				}
212
				}
209
				//- Fully qualified proxy name to by used in textual context copy 
210
				ClipboardManager.getInstance().addText(proxy.getClass().getName()+"::"+proxy.getText()); //$NON-NLS-1$
211
212
				//- proxy itself for test navigator context copy
213
				ClipboardManager.getInstance().addProxy(proxy);
214
			}
213
			}
215
			setClipboard();
216
		}
214
		}
215
		setClipboard();
217
	}
216
	}
218
217
219
	public void run() {
218
	public void run() {
220
		if(copyResources()) {
219
		copySelection();
221
			return;
222
		} 
223
		copyProxies();
224
	}
220
	}
225
221
226
	private boolean selectionIsHomogeneous() {
222
	private boolean selectionIsHomogeneous() {
Lines 283-288 Link Here
283
	}
279
	}
284
280
285
	public boolean isApplicableForSelection() {
281
	public boolean isApplicableForSelection() {
282
		//- Copy action only allowed if the navigator is presenting its resource mode
283
		if(!isResourceNav) return false;
286
		if (selection == null || selection.isEmpty()) {
284
		if (selection == null || selection.isEmpty()) {
287
			return false;
285
			return false;
288
		}	
286
		}	
Lines 297-303 Link Here
297
		return true;
295
		return true;
298
	}
296
	}
299
	
297
	
300
	public void selectionChanged(IStructuredSelection structuredSelection) {
298
	public void selectionChanged(IStructuredSelection structuredSelection, boolean isResourceNav) {
301
		selection = structuredSelection;
299
		selection = structuredSelection;
300
		this.isResourceNav = isResourceNav;
302
	}
301
	}
303
}
302
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/FileFolderInContainerPaste.java (+1 lines)
Lines 42-47 Link Here
42
 * Paste action for the resource mode.
42
 * Paste action for the resource mode.
43
 * @author jgout
43
 * @author jgout
44
 * @since 3.3
44
 * @since 3.3
45
 * @deprecated
45
 */
46
 */
46
public class FileFolderInContainerPaste implements IPaster {
47
public class FileFolderInContainerPaste implements IPaster {
47
48
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/PasteExtensionManager.java (-2 / +2 lines)
Lines 42-48 Link Here
42
		public PasterExtensionInfo (String target, boolean strict, IConfigurationElement element) {
42
		public PasterExtensionInfo (String target, boolean strict, IConfigurationElement element) {
43
			this.strict = strict;
43
			this.strict = strict;
44
			try {
44
			try {
45
				this.target = Platform.getBundle(element.getDeclaringExtension().getNamespace()).loadClass(target);
45
				this.target = Platform.getBundle(element.getDeclaringExtension().getNamespaceIdentifier()).loadClass(target);
46
			} catch (ClassNotFoundException e) {
46
			} catch (ClassNotFoundException e) {
47
				UiPlugin.logError(e);
47
				UiPlugin.logError(e);
48
			}
48
			}
Lines 126-132 Link Here
126
		return false;
126
		return false;
127
	}
127
	}
128
	
128
	
129
	/** Retruns all registered paster that can deal with the given target object.
129
	/** Returns all registered paster that can deal with the given target object.
130
	 * 
130
	 * 
131
	 * @param selection the current selection (location where the user wants to paste)
131
	 * @param selection the current selection (location where the user wants to paste)
132
	 * @return IPaster [] the array of pasters registered for the given selection.
132
	 * @return IPaster [] the array of pasters registered for the given selection.
(-)META-INF/MANIFEST.MF (-1 / +10 lines)
Lines 82-94 Link Here
82
 org.eclipse.ui.workbench.texteditor;bundle-version="[3.2.0,4.0.0)",
82
 org.eclipse.ui.workbench.texteditor;bundle-version="[3.2.0,4.0.0)",
83
 org.eclipse.ui.editors;bundle-version="[3.2.0,4.0.0)",
83
 org.eclipse.ui.editors;bundle-version="[3.2.0,4.0.0)",
84
 org.eclipse.xsd;bundle-version="[2.2.0,3.0.0)",
84
 org.eclipse.xsd;bundle-version="[2.2.0,3.0.0)",
85
 org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
85
 org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
86
 org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
86
 org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
87
 org.eclipse.jdt.core;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
88
 org.eclipse.jdt.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
87
 org.eclipse.tptp.platform.models;bundle-version="[4.2.0,5.0.0)",
89
 org.eclipse.tptp.platform.models;bundle-version="[4.2.0,5.0.0)",
88
 org.eclipse.hyades.test.core;bundle-version="[4.2.0,5.0.0)",
90
 org.eclipse.hyades.test.core;bundle-version="[4.2.0,5.0.0)",
89
 org.eclipse.hyades.trace.ui;bundle-version="[4.2.0,5.0.0)";resolution:=optional,
91
 org.eclipse.hyades.trace.ui;bundle-version="[4.2.0,5.0.0)";resolution:=optional,
90
 org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)",
92
 org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)",
93
 org.eclipse.help.ui;bundle-version="[3.2.0,4.0.0)",
94
 org.eclipse.ui.cheatsheets;bundle-version="[3.2.0,4.0.0)",
95
 org.eclipse.pde.ui;bundle-version="[3.2.0,4.0.0)";resolution:=optional,
91
 org.eclipse.search;bundle-version="[3.2.0,4.0.0)",
96
 org.eclipse.search;bundle-version="[3.2.0,4.0.0)",
92
 org.eclipse.birt.chart.engine;bundle-version="[2.1.0,3.0.0)";resolution:=optional
97
 org.eclipse.birt.chart.engine;bundle-version="[2.1.0,3.0.0)";resolution:=optional,
98
 org.eclipse.birt.core;bundle-version="[2.1.0,3.0.0)";resolution:=optional,
99
 org.eclipse.ui.browser;bundle-version="[3.2.0,4.0.0)",
100
 org.eclipse.ltk.core.refactoring;bundle-version="[3.2.0,4.0.0)",
101
 org.eclipse.ltk.ui.refactoring;bundle-version="[3.2.0,4.0.0)"
93
Eclipse-LazyStart: true
102
Eclipse-LazyStart: true
94
Bundle-RequiredExecutionEnvironment: J2SE-1.4
103
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)src/org/eclipse/hyades/test/ui/forms/editor/BaseFormEditor.java (-1 / +1 lines)
Lines 514-520 Link Here
514
		// Bugzilla_152218 preserve the selection after reload.
514
		// Bugzilla_152218 preserve the selection after reload.
515
		String fragment = null;
515
		String fragment = null;
516
		IStructuredSelection structuredSelection = (IStructuredSelection)getSelection();
516
		IStructuredSelection structuredSelection = (IStructuredSelection)getSelection();
517
		if(structuredSelection.size() == 1)
517
		if(structuredSelection != null && structuredSelection.size() == 1)
518
		{
518
		{
519
			Object selection = structuredSelection.getFirstElement();
519
			Object selection = structuredSelection.getFirstElement();
520
			if(selection instanceof EObject)
520
			if(selection instanceof EObject)
(-)src/org/eclipse/hyades/test/ui/navigator/CMNNamedElementProxyNode.java (-10 / +114 lines)
Lines 12-25 Link Here
12
package org.eclipse.hyades.test.ui.navigator;
12
package org.eclipse.hyades.test.ui.navigator;
13
13
14
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.OperationCanceledException;
19
import org.eclipse.core.runtime.Path;
15
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.emf.ecore.resource.Resource;
17
import org.eclipse.hyades.models.common.common.CMNNamedElement;
22
import org.eclipse.hyades.models.common.common.CMNNamedElement;
18
import org.eclipse.hyades.test.core.util.EMFUtil;
23
import org.eclipse.hyades.test.core.util.EMFUtil;
24
import org.eclipse.hyades.test.ui.TestUIConstants;
19
import org.eclipse.hyades.test.ui.UiPlugin;
25
import org.eclipse.hyades.test.ui.UiPlugin;
26
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.EMFRefactoringTransaction;
27
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.MoveModelChange;
28
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.RefactoringMessages;
20
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer;
29
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer;
30
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer2;
31
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
21
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIInlineEditor;
32
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIInlineEditor;
22
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIStatus;
33
import org.eclipse.hyades.test.ui.navigator.actions.RenamerUIStatus;
34
import org.eclipse.ltk.core.refactoring.Change;
35
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
36
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.ui.IEditorInput;
37
import org.eclipse.ui.IEditorInput;
24
import org.eclipse.ui.IEditorPart;
38
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.IEditorReference;
39
import org.eclipse.ui.IEditorReference;
Lines 33-43 Link Here
33
 * Proxy node for <code>CMNNamedElement</code> element.
47
 * Proxy node for <code>CMNNamedElement</code> element.
34
 * @author jgout
48
 * @author jgout
35
 */
49
 */
36
public abstract class CMNNamedElementProxyNode extends EObjectProxyNode implements IProxyNodeRenamer  {
50
/**
51
 * @author jgout
52
 * @since 
53
 */
54
public abstract class CMNNamedElementProxyNode extends EObjectProxyNode implements IProxyNodeRenamer2, IProxyNodeRenamer  {
37
	
55
	
38
	private final static String TAG_NAME = "name"; //$NON-NLS-1$
56
	private final static String TAG_NAME = "name"; //$NON-NLS-1$
39
	private final static String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
57
	private final static String TAG_DESCRIPTION = "description"; //$NON-NLS-1$
40
	
58
41
	private String name;
59
	private String name;
42
	private String description;
60
	private String description;
43
61
Lines 89-94 Link Here
89
		this.name = name;
107
		this.name = name;
90
	}
108
	}
91
	
109
	
110
 	/**
111
 	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
112
 	 */
113
 	public Object getAdapter(Class adapter) {
114
 		if (adapter == IProxyNodeRenamer2.class) {
115
			return this;
116
		} if (adapter == IProxyNodeRenamer.class) {
117
			return this;
118
		} else {
119
			return super.getAdapter(adapter);
120
		}
121
	}
122
92
	/**
123
	/**
93
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
124
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
94
	 */
125
	 */
Lines 104-110 Link Here
104
	public String getDescription() {
135
	public String getDescription() {
105
		return this.description;
136
		return this.description;
106
	}
137
	}
107
108
	/** 
138
	/** 
109
	 * @see org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer#isApplicableFor()
139
	 * @see org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer#isApplicableFor()
110
	 */
140
	 */
Lines 168-185 Link Here
168
    
198
    
169
	/**
199
	/**
170
	 * @see org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer#performUserInteraction(java.lang.String)
200
	 * @see org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer#performUserInteraction(java.lang.String)
201
	 * @deprecated
171
	 */
202
	 */
172
	public RenamerUIStatus performUserInteraction(String oldName) {
203
	public RenamerUIStatus performUserInteraction(String oldName) {
173
		return new RenamerUIInlineEditor();
204
		return new RenamerUIInlineEditor();
174
	}
205
	}
175
	
206
	
176
	/**
207
	public boolean saveState(IMemento memento) {
177
	 * @see org.eclipse.hyades.test.ui.navigator.EObjectProxyNode#saveState(org.eclipse.ui.IMemento)
208
		if (this instanceof IPersistableProxyNode) {
178
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
209
			//- data from CMNNamedElementProxyNode
179
	 */
210
			memento.putString(TestUIConstants.TAG_NAME, getText());
180
	public boolean saveState(IMemento memento) { 
211
			return super.saveState(memento);
181
		memento.putString(TAG_NAME, getName());
212
		}	
182
		return super.saveState(memento);
213
		return false;
214
	}
215
216
	public Change createRenameChange(IRefactoringContext context, String newName) {
217
		if(getAdapter(IFile.class) != null) {
218
			IPath oldPath = getUnderlyingResource().getFullPath();
219
			IPath newPath = oldPath.removeLastSegments(1).append(new Path(newName+'.'+oldPath.getFileExtension()));
220
			return new RenameModelChange(this, context, newPath, newName);
221
		} else {
222
			return new RenameElementChange(this, context, newName);
223
		}
224
	}
225
	
226
	protected class RenameElementChange extends Change {
227
		private EMFRefactoringTransaction context;
228
		private String newName;
229
		private CMNNamedElementProxyNode proxy;
230
		
231
		public RenameElementChange(CMNNamedElementProxyNode node, IRefactoringContext context, String newName) {
232
			this.proxy = node;
233
			this.context = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
234
			this.newName = newName;
235
		}
236
		
237
		public Change perform(IProgressMonitor pm) throws CoreException {
238
			if(context != null) {
239
				EObject object = context.getResourceSet().getEObject(getOriginatorURI(), true);
240
				((CMNNamedElement)object).setName(newName);
241
				context.addResourceToSave(object.eResource());
242
			}
243
			return null;
244
		}
245
246
		public Object getModifiedElement() {
247
			return proxy;
248
		}
249
250
		public String getName() {
251
			return NLS.bind(RefactoringMessages.RENAME_PROXY, proxy.getText(), newName);		
252
		}
253
254
		public void initializeValidationData(IProgressMonitor pm) {
255
		}
256
257
		public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
258
			return new RefactoringStatus();
259
		}
183
	}
260
	}
184
	
261
	
262
	protected class RenameModelChange extends MoveModelChange {
263
		private IRefactoringContext context;
264
		private String newName;
265
		public RenameModelChange(IProxyNode node, IRefactoringContext context, IPath destinationPath, String newName) {
266
			super(node, context, destinationPath);
267
			this.context = context;
268
			this.newName = newName;
269
		}
270
		public Change perform(IProgressMonitor pm) throws CoreException {
271
			Change change = super.perform(pm);
272
			EMFRefactoringTransaction t = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
273
			if(t != null) {
274
				EObject object = t.getResourceSet().getEObject(getOriginatorURI(), false);
275
				((CMNNamedElement)object).setName(newName);
276
			}
277
			return change;
278
		}
279
		
280
		protected void handleFileAlreadyExists(RefactoringStatus status) {
281
			//- this is actually a rename but there is a conflict name, this is an error.
282
			status.addError(NLS.bind(RefactoringMessages.ALREADY_EXISTS_PROXY_DURING_RENAME, destination.toPortableString()));
283
		}
284
285
		public String getName() {
286
			return NLS.bind(RefactoringMessages.RENAME_PROXY, proxy.getText(), destination.removeFileExtension().lastSegment());		
287
		}
288
	}
185
}
289
}
(-)src/org/eclipse/hyades/test/ui/navigator/DefaultTestSuiteProxyNode.java (-1 / +163 lines)
Lines 13-31 Link Here
13
13
14
import java.util.Iterator;
14
import java.util.Iterator;
15
import java.util.LinkedList;
15
import java.util.LinkedList;
16
import java.util.List;
16
17
18
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.debug.core.DebugPlugin;
22
import org.eclipse.debug.core.ILaunchConfiguration;
23
import org.eclipse.debug.core.ILaunchConfigurationType;
17
import org.eclipse.emf.common.util.EList;
24
import org.eclipse.emf.common.util.EList;
25
import org.eclipse.emf.common.util.URI;
18
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.ecore.EObject;
27
import org.eclipse.hyades.models.common.datapool.DPLDatapool;
28
import org.eclipse.hyades.models.common.facades.behavioral.IBlock;
29
import org.eclipse.hyades.models.common.facades.behavioral.IDecision;
30
import org.eclipse.hyades.models.common.facades.behavioral.ILoop;
31
import org.eclipse.hyades.models.common.facades.behavioral.ITest;
32
import org.eclipse.hyades.models.common.facades.behavioral.ITestInvocation;
19
import org.eclipse.hyades.models.common.testprofile.TPFTestCase;
33
import org.eclipse.hyades.models.common.testprofile.TPFTestCase;
20
import org.eclipse.hyades.models.common.testprofile.TPFTestSuite;
34
import org.eclipse.hyades.models.common.testprofile.TPFTestSuite;
35
import org.eclipse.hyades.test.core.launch.configurations.TestLaunchConfigurationFacade;
21
import org.eclipse.hyades.test.ui.TestUIConstants;
36
import org.eclipse.hyades.test.ui.TestUIConstants;
22
import org.eclipse.hyades.test.ui.TestUIExtension;
37
import org.eclipse.hyades.test.ui.TestUIExtension;
23
import org.eclipse.hyades.test.ui.TestUIImages;
38
import org.eclipse.hyades.test.ui.TestUIImages;
39
import org.eclipse.hyades.test.ui.UiPlugin;
40
import org.eclipse.hyades.test.ui.internal.navigator.proxy.EMFResourceProxyFactory;
41
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
24
import org.eclipse.hyades.test.ui.internal.navigator.proxy.TypedElementFactoryManager;
42
import org.eclipse.hyades.test.ui.internal.navigator.proxy.TypedElementFactoryManager;
43
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.DeleteTestInvocationChange;
44
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.LaunchConfigurationDeleteChange;
45
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.LaunchConfigurationUpdateChange;
46
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
25
import org.eclipse.hyades.ui.extension.IAssociationConstants;
47
import org.eclipse.hyades.ui.extension.IAssociationConstants;
26
import org.eclipse.hyades.ui.extension.IAssociationDescriptor;
48
import org.eclipse.hyades.ui.extension.IAssociationDescriptor;
27
import org.eclipse.hyades.ui.extension.IAssociationMapping;
49
import org.eclipse.hyades.ui.extension.IAssociationMapping;
28
import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry;
50
import org.eclipse.hyades.ui.internal.extension.AssociationMappingRegistry;
51
import org.eclipse.ltk.core.refactoring.Change;
52
import org.eclipse.ltk.core.refactoring.CompositeChange;
29
import org.eclipse.swt.graphics.Image;
53
import org.eclipse.swt.graphics.Image;
30
import org.eclipse.ui.IMemento;
54
import org.eclipse.ui.IMemento;
31
55
Lines 64-70 Link Here
64
				tcProxies.add(proxy);
88
				tcProxies.add(proxy);
65
			}
89
			}
66
		}
90
		}
67
		testCases = (CMNNamedElementProxyNode[]) tcProxies.toArray(new CMNNamedElementProxyNode[tcProxies.size()]);	
91
		testCases = (CMNNamedElementProxyNode[]) tcProxies.toArray(new CMNNamedElementProxyNode[tcProxies.size()]);
92
		//- add references on associated datapools
93
		for (Iterator it = ts.getDatapools().iterator(); it.hasNext();) {
94
			DPLDatapool dp = (DPLDatapool) it.next();
95
			IProxyNode dpProxy = FileProxyNodeCache.getInstance().getCorrespondingProxy(dp);
96
			if(dpProxy != null) {
97
				addBidirectionalReference("Test2Datapool", (IReferencerProxyNode)dpProxy, "Datapool2Test");  //$NON-NLS-1$ //$NON-NLS-2$
98
			}
99
		}
100
		//- add references on invocations
101
		addInvocationReferences(ts.getImplementor().getBlock());
102
	}
103
104
	private void addInvocationReferences(IBlock block) {
105
		if (block != null) {
106
			List actions = block.getActions();
107
			for (Iterator it = actions.iterator(); it.hasNext();) {
108
				Object action = it.next();
109
				if (action instanceof ILoop) {
110
					addInvocationReferences(((ILoop) action).getBlock());
111
				} else if (action instanceof IDecision) {
112
					IDecision ifAction = (IDecision) action;
113
					addInvocationReferences(ifAction.getFailureBlock());
114
					addInvocationReferences(ifAction.getSuccessBlock());
115
				} else if (action instanceof ITestInvocation) {
116
					ITestInvocation invocationAction = (ITestInvocation) action;
117
					ITest invokedTest = invocationAction.getInvokedTest();
118
					if (((EObject) invocationAction).eResource() != ((EObject) invokedTest).eResource()) {
119
						IProxyNode invokedProxy = FileProxyNodeCache.getInstance().getCorrespondingProxy(invokedTest);
120
						if (invokedProxy != null) {
121
							addBidirectionalReference("TestInvoker2TestInvoked", (IReferencerProxyNode) invokedProxy, "TestInvoked2TestInvoker"); //$NON-NLS-1$ //$NON-NLS-2$
122
						}
123
					}
124
				}
125
			}
126
		}		
68
	}
127
	}
69
128
70
    /**
129
    /**
Lines 136-141 Link Here
136
		}
195
		}
137
	}
196
	}
138
	
197
	
198
    /**
199
     * Returns the ID of the factory that is used to recreate this proxy node.
200
     * @return the ID of the factory that is used to recreate this proxy node.
201
     */
202
	public String getFactoryID() {
203
		return EMFResourceProxyFactory.ID; 
204
	}
205
	
139
	/**
206
	/**
140
	 * @see org.eclipse.hyades.test.ui.navigator.EObjectProxyNode#getNodeKind()
207
	 * @see org.eclipse.hyades.test.ui.navigator.EObjectProxyNode#getNodeKind()
141
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
208
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
Lines 166-169 Link Here
166
		}
233
		}
167
		return true;
234
		return true;
168
	}	
235
	}	
236
237
	private void launchConfigurationUpdateChanges(CompositeChange composite, URI newURI) {
238
		ILaunchConfigurationType configsType = TestLaunchConfigurationFacade.getLaunchConfigurationType();
239
		ILaunchConfiguration[] configs = new ILaunchConfiguration[0];
240
		try {
241
			configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configsType);
242
		} catch (CoreException e) {
243
			UiPlugin.logError("Unable to get Launch Configuraions", e); //$NON-NLS-1$
244
		}
245
		for (int i = 0; i < configs.length; i++) {
246
			try {
247
				URI originatorURI = getOriginatorURI();
248
				if (TestLaunchConfigurationFacade.isTestURI(configs[i], originatorURI)) {
249
					composite.add(new LaunchConfigurationUpdateChange(configs[i], newURI.appendFragment(originatorURI.fragment())));;
250
				}
251
			} catch (CoreException e) {
252
				UiPlugin.logError("Unable to update Launch Configuraions", e); //$NON-NLS-1$
253
			}		
254
		}
255
	}
256
257
	private void launchConfigurationDeleteChanges(CompositeChange composite) {
258
		ILaunchConfigurationType configsType = TestLaunchConfigurationFacade.getLaunchConfigurationType();
259
		ILaunchConfiguration[] configs = new ILaunchConfiguration[0];
260
		try {
261
			configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configsType);
262
		} catch (CoreException e) {
263
			UiPlugin.logError("Unable to get Launch Configuraions", e); //$NON-NLS-1$
264
		}
265
		for (int i = 0; i < configs.length; i++) {
266
			try {
267
				URI originatorURI = getOriginatorURI();
268
				if (TestLaunchConfigurationFacade.isTestURI(configs[i], originatorURI)) {
269
					composite.add(new LaunchConfigurationDeleteChange(configs[i]));
270
				}
271
			} catch (CoreException e) {
272
				UiPlugin.logError("Unable to delete Launch Configuraions", e); //$NON-NLS-1$
273
			}		
274
		}
275
	}	
276
277
	public Change createRenameChange(IRefactoringContext context, String newName) {
278
		CompositeChange composite = new CompositeChange(""); //$NON-NLS-1$
279
		Change superChange = super.createRenameChange(context, newName);
280
		if (superChange != null && superChange instanceof RenameModelChange) {
281
			launchConfigurationUpdateChanges(composite, ((RenameModelChange)superChange).getNewURI());
282
			composite.add(superChange);
283
		}
284
		composite.markAsSynthetic();
285
		return composite;
286
	}
287
288
	public Change createMoveChange(IRefactoringContext context, IPath destinationPath) {
289
		CompositeChange composite = new CompositeChange(""); //$NON-NLS-1$
290
		launchConfigurationUpdateChanges(composite, URI.createPlatformResourceURI(destinationPath.toPortableString()));
291
		Change superChange = super.createMoveChange(context, destinationPath);
292
		if (superChange != null) {
293
			composite.add(superChange);
294
		}
295
		composite.markAsSynthetic();
296
		return composite;
297
	}
298
299
	public Change createUpdateChange(IRefactoringContext context, IContainer container, IPath destinationPath) {
300
		CompositeChange composite = new CompositeChange(""); //$NON-NLS-1$
301
		launchConfigurationUpdateChanges(composite, URI.createPlatformResourceURI(destinationPath.toPortableString()));
302
		Change superChange = super.createUpdateChange(context, container, destinationPath);
303
		if (superChange != null) {
304
			composite.add(superChange);
305
		}
306
		composite.markAsSynthetic();
307
		return composite;
308
	}
309
310
	public Change createUpdateChange(IRefactoringContext context, IReferencerProxyNode referenced, String refType, IPath destinationPath) {
311
		if(destinationPath == null) {
312
			if("TestInvoked2TestInvoker".equals(refType)) { //$NON-NLS-1$
313
				//- remove the link to referenced in this (clean invocation)
314
				return new DeleteTestInvocationChange(context, this, referenced);
315
			}
316
		}
317
		return super.createUpdateChange(context, referenced, refType, destinationPath);
318
	}
319
320
	public Change createDeleteChange(IRefactoringContext context) {
321
		CompositeChange composite = new CompositeChange(""); //$NON-NLS-1$
322
		launchConfigurationDeleteChanges(composite);
323
		Change superChange = super.createDeleteChange(context);
324
		if(superChange != null) {
325
			composite.add(superChange);
326
		}
327
		composite.markAsSynthetic();
328
		return composite;
329
	}
330
169
}
331
}
(-)src/org/eclipse/hyades/test/ui/navigator/ProxyNodeTransfer.java (-1 / +1 lines)
Lines 67-73 Link Here
67
		String identifier = dataIn.readUTF();
67
		String identifier = dataIn.readUTF();
68
		return ResourceTestNavigatorProvider.getSharedFileProxyManager().getCorrespondingProxy(fileName, identifier);
68
		return ResourceTestNavigatorProvider.getSharedFileProxyManager().getCorrespondingProxy(fileName, identifier);
69
	}
69
	}
70
70
	
71
	/**
71
	/**
72
	 * @see org.eclipse.swt.dnd.Transfer#javaToNative(java.lang.Object, org.eclipse.swt.dnd.TransferData)
72
	 * @see org.eclipse.swt.dnd.Transfer#javaToNative(java.lang.Object, org.eclipse.swt.dnd.TransferData)
73
	 */
73
	 */
(-)src/org/eclipse/hyades/test/ui/navigator/EObjectProxyNode.java (-14 / +117 lines)
Lines 11-18 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.hyades.test.ui.navigator;
12
package org.eclipse.hyades.test.ui.navigator;
13
13
14
import java.util.Collection;
15
import java.util.Set;
16
17
import org.eclipse.core.resources.IContainer;
18
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.core.runtime.Path;
22
import org.eclipse.core.runtime.Path;
17
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.emf.common.util.URI;
24
import org.eclipse.emf.common.util.URI;
Lines 23-28 Link Here
23
import org.eclipse.hyades.test.ui.TestUIConstants;
29
import org.eclipse.hyades.test.ui.TestUIConstants;
24
import org.eclipse.hyades.test.ui.internal.navigator.proxy.EMFResourceProxyFactory;
30
import org.eclipse.hyades.test.ui.internal.navigator.proxy.EMFResourceProxyFactory;
25
import org.eclipse.hyades.test.ui.internal.navigator.proxy.IExtendedProxyNode;
31
import org.eclipse.hyades.test.ui.internal.navigator.proxy.IExtendedProxyNode;
32
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyManager.IUnboundedParent;
33
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceRegistry;
34
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.DeleteModelElementChange;
35
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.ModelPathChange;
36
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.MoveModelChange;
37
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.PasteModelChange;
38
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.UpdateModelChange;
39
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeDeleter;
40
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeMover;
41
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodePaster;
42
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeUpdater;
43
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
44
import org.eclipse.ltk.core.refactoring.Change;
26
import org.eclipse.ui.IMemento;
45
import org.eclipse.ui.IMemento;
27
46
28
/** EMF object proxy element for the test navigator.
47
/** EMF object proxy element for the test navigator.
Lines 30-49 Link Here
30
 * EMF objects wrapped by subclasses will be stored in the test navigator resource set
49
 * EMF objects wrapped by subclasses will be stored in the test navigator resource set
31
 * @author jgout
50
 * @author jgout
32
 */
51
 */
33
public abstract class EObjectProxyNode implements IPersistableProxyNode, IExtendedProxyNode {
52
public abstract class EObjectProxyNode extends AbstractProxy implements IPersistableProxyNode, IExtendedProxyNode, 
53
	IReferencerProxyNode, IProxyNodeMover, IProxyNodeUpdater, IProxyNodeDeleter,IProxyNodePaster {
34
	
54
	
35
	private static final String TAG_URI_FRAGMENT = "uriFragment"; //$NON-NLS-1$
55
	private static final String TAG_URI_FRAGMENT = "uriFragment"; //$NON-NLS-1$
36
	
56
		
37
	private URI originatorURI;
57
	private URI originatorURI;
38
	private Object parent;
58
	private Object parent;
59
	private static final String VERSION = "4.3"; //$NON-NLS-1$
60
	private static final String TAG_STATE_VERSION = "stateVersion"; //$NON-NLS-1$
39
	
61
	
40
    /**
62
	/**
41
     * Constructor used to load a persisted proxy. 
63
     * Constructor used to load a persisted proxy. 
42
     * @param memento the memento containing the saved state of the proxy.
64
     * @param memento the memento containing the saved state of the proxy.
43
     * @param parent the parent node of the proxy node.
65
     * @param parent the parent node of the proxy node.
44
     */
66
     */
45
	public EObjectProxyNode(IMemento memento,  Object parent) {
67
	public EObjectProxyNode(IMemento memento,  Object parent) {
46
        String uriFragmentName;
68
        String uriFragmentName;
69
        checkVersion(VERSION, memento);
47
        //- backward compatibility of the existing persisted proxy node states
70
        //- backward compatibility of the existing persisted proxy node states
48
        String uri = memento.getString(TestUIConstants.TAG_URI);
71
        String uri = memento.getString(TestUIConstants.TAG_URI);
49
        if(uri != null) {
72
        if(uri != null) {
Lines 53-62 Link Here
53
        } else {
76
        } else {
54
            uriFragmentName = memento.getString(TAG_URI_FRAGMENT);
77
            uriFragmentName = memento.getString(TAG_URI_FRAGMENT);
55
        }
78
        }
56
		//- this data is not persisted but added by the proxy node loader (FileProxyManager#buildProxy)
79
		//- this data is not persisted but added by the proxy node loader (FileProxyNodeCache#buildProxyFromSavedState)
57
        String uriRootName = memento.getString(TestUIConstants.TAG_URI_ROOT);
80
        String uriRootName = memento.getString(TestUIConstants.TAG_URI_ROOT);
58
        try {
81
        try {
59
            URI uriRoot = URI.createPlatformResourceURI(uriRootName);
82
            URI uriRoot = URI.createPlatformResourceURI(uriRootName,false);
60
            this.originatorURI = uriRoot.appendFragment(uriFragmentName);
83
            this.originatorURI = uriRoot.appendFragment(uriFragmentName);
61
        } catch (IllegalArgumentException e) {
84
        } catch (IllegalArgumentException e) {
62
            throw new IllegalArgumentException("Malformed saved proxy state: unable to retrieve uri field"); //$NON-NLS-1$        }
85
            throw new IllegalArgumentException("Malformed saved proxy state: unable to retrieve uri field"); //$NON-NLS-1$        }
Lines 64-69 Link Here
64
 		this.parent = parent;
87
 		this.parent = parent;
65
	}
88
	}
66
	
89
	
90
	protected void checkVersion(String version, IMemento memento) {
91
		String savedVersion = memento.getString(TAG_STATE_VERSION);
92
		if(savedVersion == null || !VERSION.equals(savedVersion)) {
93
			throw new ProxyNeedToBeRebuiltException();
94
		}
95
	}
96
67
	/**
97
	/**
68
	 *  Creates a proxy node from a emf object.
98
	 *  Creates a proxy node from a emf object.
69
	 *  CAUTION: this object should be stored in a EMF resource in order to get its URI
99
	 *  CAUTION: this object should be stored in a EMF resource in order to get its URI
Lines 101-107 Link Here
101
	
131
	
102
	/** 
132
	/** 
103
     * Identifier for an EMF object is its URI fragment part. 
133
     * Identifier for an EMF object is its URI fragment part. 
104
     * If there is no fragment identifier is empty, this means that the object is a root object.  
134
     * If there is the fragment identifier is empty, this means that the object is a root object.  
105
	 * @return the identifier of the proxy node.
135
	 * @return the identifier of the proxy node.
106
	 */
136
	 */
107
	public String getIdentifier() {
137
	public String getIdentifier() {
Lines 144-160 Link Here
144
     * @retrun an adapted object for the given class using the global plateform adapter manager.
174
     * @retrun an adapted object for the given class using the global plateform adapter manager.
145
	 */
175
	 */
146
	public Object getAdapter(Class adapter) {
176
	public Object getAdapter(Class adapter) {
147
		return Platform.getAdapterManager().getAdapter(this, adapter);
177
		//- this proxy is adaptable in IFile if it has been placed instead of a file
178
		if(adapter.isAssignableFrom(IFile.class) && getParent() instanceof IUnboundedParent) {
179
		    return getUnderlyingResource();
180
 		} else if(adapter == IProxyNodeUpdater.class 
181
 			|| adapter == IProxyNodeMover.class 
182
 			|| adapter == IProxyNodeDeleter.class
183
 			|| adapter == IProxyNodePaster.class) {
184
 			return this;
185
	 	} else {
186
			return Platform.getAdapterManager().getAdapter(this, adapter);
187
		}
148
	}
188
	}
149
189
150
	/**
190
	public void addReference(String refType, IProxy proxyRef) {
151
	 * @see org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode#getFactoryID()
191
		IResource ur = proxyRef.getUnderlyingResource();
152
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
192
		if(ur instanceof IFile) {
153
	 */
193
			ReferenceRegistry.getInstance().addReference((IFile)getUnderlyingResource(), refType, (IFile)ur);
154
	public String getFactoryID() {
194
		}
155
		return EMFResourceProxyFactory.ID;
195
	}
196
197
	public void addBidirectionalReference(String refType, IReferencerProxyNode proxyRef, String oppositeRefType) {
198
		IResource ur = proxyRef.getUnderlyingResource();
199
		if(ur instanceof IFile) {
200
			ReferenceRegistry.getInstance().addBidirectionalReference((IFile)getUnderlyingResource(), refType, (IFile)ur, oppositeRefType);
201
		}
202
	}
203
	
204
	public void removeReference(IProxyNode proxyRef) {
205
		IResource ur = proxyRef.getUnderlyingResource();
206
		if(ur instanceof IFile) {
207
			ReferenceRegistry.getInstance().removeReference((IFile)getUnderlyingResource(), (IFile)ur);
208
		}
209
	}
210
211
	public Collection getReferences(String refType) {
212
		return ReferenceRegistry.getInstance().getReferences((IFile)getUnderlyingResource(), refType);
156
	}
213
	}
157
	
214
	
215
	public Set getReferenceTypes() {
216
		return ReferenceRegistry.getInstance().getReferenceTypes((IFile)getUnderlyingResource());
217
	}
218
158
	/**
219
	/**
159
	 * @see org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode#saveState(org.eclipse.ui.IMemento)
220
	 * @see org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode#saveState(org.eclipse.ui.IMemento)
160
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
221
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
Lines 164-169 Link Here
164
		memento.putString(TAG_URI_FRAGMENT, getOriginatorURI().fragment());
225
		memento.putString(TAG_URI_FRAGMENT, getOriginatorURI().fragment());
165
		return true;
226
		return true;
166
	}
227
	}
228
229
	public Change createMoveChange(IRefactoringContext context, IPath destinationPath) {
230
		return this.getAdapter(IFile.class) != null ? new MoveModelChange(this, context, destinationPath) : null;
231
	}
232
233
	public Change createUpdateChange(IRefactoringContext context, IReferencerProxyNode referenced, String refType, IPath destinationPath) {
234
		return new UpdateModelChange(this, context);
235
	}
236
237
	public Change createUpdateChange(IRefactoringContext context, IContainer container, IPath destinationPath) {
238
		return new ModelPathChange(this, context, destinationPath);
239
	}
240
241
	public Change createDeleteChange(IRefactoringContext context) {
242
		return new DeleteModelElementChange(context, this);
243
	}
244
	
245
	public Change createPasteChange(IRefactoringContext context, IPath destinationPath,String [] targetName) {
246
		return new PasteModelChange(context,this,destinationPath,targetName);
247
	}
248
	
249
	//- overwrite AbstractProxy.equals to avoid to access to the underlying resource
250
	public boolean equals(Object arg0) {
251
		if(arg0 instanceof EObjectProxyNode) {
252
			URI argURI = ((EObjectProxyNode)arg0).originatorURI;
253
			return (originatorURI == null && argURI == null)  
254
				|| (originatorURI != null && originatorURI.equals(argURI));
255
		}
256
		return false;
257
	}
258
259
	//- overwrite AbstractProxy.hashCode to avoid to access to the underlying resource
260
	public int hashCode() {
261
		return originatorURI != null ? originatorURI.hashCode() : -2;
262
	}
263
264
	/**
265
	 * @see org.eclipse.hyades.test.ui.navigator.IPersistableProxyNode#getFactoryID()
266
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
267
	 */
268
	public String getFactoryID() {
269
		return EMFResourceProxyFactory.ID;
270
	}
167
	
271
	
168
	/**
272
	/**
169
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
273
	 * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
Lines 176-180 Link Here
176
	public IResource getCorrespondingResource() {
280
	public IResource getCorrespondingResource() {
177
		return getUnderlyingResource();
281
		return getUnderlyingResource();
178
	}
282
	}
179
180
}
283
}
(-)src/org/eclipse/hyades/test/ui/navigator/IPersistableFileProxyFactory.java (+2 lines)
Lines 29-34 Link Here
29
     * @param file The file that the proxy node is the placeholder.
29
     * @param file The file that the proxy node is the placeholder.
30
     * @param parent The parent of the new created proxy node in the test navigator. 
30
     * @param parent The parent of the new created proxy node in the test navigator. 
31
     * @return The proxy node built based on the content of the given memento.
31
     * @return The proxy node built based on the content of the given memento.
32
	 * The returned node must meet the following condition:
33
	 * <code>file.equals(factory.create(file, parent).getAdapter(IFile.class))</code>
32
	 */
34
	 */
33
	public IProxyNode recreate(IMemento memento, IFile file, Object parent);
35
	public IProxyNode recreate(IMemento memento, IFile file, Object parent);
34
	
36
	
(-)src/org/eclipse/hyades/test/ui/navigator/TypedElementProxyNode.java (-4 / +7 lines)
Lines 81-88 Link Here
81
     * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
81
     * @provisional As of TPTP V4.4.0, this is stable provisional API (see http://www.eclipse.org/tptp/home/documents/process/development/api_contract.html).
82
     */
82
     */
83
    public boolean saveState(IMemento memento) {
83
    public boolean saveState(IMemento memento) {
84
        memento.putString(TAG_TYPE, getType());
84
		if (this instanceof IPersistableProxyNode) {
85
        return super.saveState(memento);
85
			//- data from TypedElementProxyNode
86
    }
86
			memento.putString(TAG_TYPE, getType());
87
    
87
			return super.saveState(memento);
88
		}
89
		return false;
90
	}
88
}
91
}
(-)src/org/eclipse/hyades/test/ui/navigator/IFileProxyFactory.java (+2 lines)
Lines 25-30 Link Here
25
	 * @param file the file to convert in proxy.
25
	 * @param file the file to convert in proxy.
26
	 * @param parent an existing object (proxy node or not) which is the parent of the file proxy node in the proxy node hierarchy.
26
	 * @param parent an existing object (proxy node or not) which is the parent of the file proxy node in the proxy node hierarchy.
27
	 * @return a proxy which is used in the test navigator instead of the file itself.
27
	 * @return a proxy which is used in the test navigator instead of the file itself.
28
	 * The returned node must meet the following condition:
29
	 * <code>file.equals(factory.create(file, parent).getAdapter(IFile.class))</code>
28
	 */
30
	 */
29
	public IProxyNode create(IFile file, Object parent);
31
	public IProxyNode create(IFile file, Object parent);
30
	
32
	
(-)src/org/eclipse/hyades/test/ui/navigator/FileProxyNode.java (-2 / +2 lines)
Lines 43-50 Link Here
43
 * @author jgout
43
 * @author jgout
44
 * @since 3.2
44
 * @since 3.2
45
 */
45
 */
46
public abstract class FileProxyNode implements IProxyNodeRenamer, IExtendedProxyNode {
46
public abstract class FileProxyNode extends AbstractProxy implements IProxyNodeRenamer, IExtendedProxyNode {
47
47
	
48
	private IFile file;
48
	private IFile file;
49
49
50
    /**
50
    /**
(-)src/org/eclipse/hyades/test/ui/navigator/IFileProxyManager.java (+1 lines)
Lines 72-77 Link Here
72
     * @param fileName name of the underlying resource of the searched proxy
72
     * @param fileName name of the underlying resource of the searched proxy
73
     * @param identifier identifier of the searched proxy
73
     * @param identifier identifier of the searched proxy
74
     * @return a proxy node or <code>null</code> if not found.
74
     * @return a proxy node or <code>null</code> if not found.
75
     * @deprecated use {@link #getCorrespondingProxy(new Proxy(fileName, String))} instead.
75
     */
76
     */
76
    public IProxyNode getCorrespondingProxy(String fileName, String identifier);
77
    public IProxyNode getCorrespondingProxy(String fileName, String identifier);
77
78
(-)src/org/eclipse/hyades/test/ui/navigator/IProxy.java (+2 lines)
Lines 15-20 Link Here
15
15
16
/**
16
/**
17
 * Lightweight object that represents an arbitrary element within a resource.
17
 * Lightweight object that represents an arbitrary element within a resource.
18
 * Two instances of this class should be equal if and only if they have equal
19
 * underlying resource and identifier.
18
 * @author jcanches
20
 * @author jcanches
19
 * @since 4.0
21
 * @since 4.0
20
 */
22
 */
(-)src/org/eclipse/hyades/test/ui/navigator/IProxyNode.java (-1 / +4 lines)
Lines 15-21 Link Here
15
import org.eclipse.swt.graphics.Image;
15
import org.eclipse.swt.graphics.Image;
16
16
17
/**
17
/**
18
 * Main interface to wrap objects into the test navigator
18
 * Main interface to wrap objects into the test navigator.
19
 * Instances of this interface must meet the following condition:
20
 * <code>getAdapter(IFile.class) == null || getAdapter(IFile.class) == getUnderlyingResource() </code>
21
 * 
19
 * @author jgout
22
 * @author jgout
20
 */
23
 */
21
public interface IProxyNode extends IAdaptable, IProxy {
24
public interface IProxyNode extends IAdaptable, IProxy {
(-)src/org/eclipse/hyades/test/ui/UiPlugin.java (-1 / +14 lines)
Lines 4-10 Link Here
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: UiPlugin.java,v 1.40 2007/06/01 14:52:02 jgout Exp $
7
 * $Id: UiPlugin.java,v 1.33 2006/08/28 05:05:22 sleeloy Exp $
8
 *
8
 *
9
 * Contributors:
9
 * Contributors:
10
 * IBM - Initial API and implementation
10
 * IBM - Initial API and implementation
Lines 376-381 Link Here
376
		Status status = new Status(IStatus.INFO, getID(), 0, text, new Throwable(text));
376
		Status status = new Status(IStatus.INFO, getID(), 0, text, new Throwable(text));
377
		instance.getLog().log(status);
377
		instance.getLog().log(status);
378
	}
378
	}
379
	
380
	public static void logWarning(String text)
381
	{
382
		Status status = new Status(IStatus.WARNING, getID(), 0, text, new Throwable(text));
383
		instance.getLog().log(status);
384
	}
385
	
386
	public static void logWarning(String text, Throwable throwable)
387
	{
388
		Status status = new Status(IStatus.WARNING, getID(), 0, text, throwable);
389
		instance.getLog().log(status);
390
	}
391
	
379
	// TestGen info
392
	// TestGen info
380
	public static String getPreference(String key)
393
	public static String getPreference(String key)
381
	{
394
	{
(-)src/org/eclipse/hyades/test/ui/TestUIConstants.java (-1 / +1 lines)
Lines 4-10 Link Here
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: TestUIConstants.java,v 1.8 2006/12/15 17:05:50 jcanches Exp $
7
 * $Id: TestUIConstants.java,v 1.7 2005/10/13 09:32:56 jcanches Exp $
8
 * 
8
 * 
9
 * Contributors:
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
10
 *     IBM Corporation - initial API and implementation
(-)src/org/eclipse/hyades/test/ui/forms/actions/OpenJavaScriptAction.java (-1 / +1 lines)
Lines 18-26 Link Here
18
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.hyades.loaders.util.RegistryReader;
20
import org.eclipse.hyades.loaders.util.RegistryReader;
21
import org.eclipse.hyades.log.ui.internal.navigator.EMFUtil;
22
import org.eclipse.hyades.models.common.common.CMNExtendedProperty;
21
import org.eclipse.hyades.models.common.common.CMNExtendedProperty;
23
import org.eclipse.hyades.models.common.testprofile.TPFExecutionEvent;
22
import org.eclipse.hyades.models.common.testprofile.TPFExecutionEvent;
23
import org.eclipse.hyades.test.core.util.EMFUtil;
24
import org.eclipse.hyades.test.core.util.JavaUtil;
24
import org.eclipse.hyades.test.core.util.JavaUtil;
25
import org.eclipse.hyades.test.ui.UiPlugin;
25
import org.eclipse.hyades.test.ui.UiPlugin;
26
import org.eclipse.hyades.test.ui.forms.extensions.IEventAction;
26
import org.eclipse.hyades.test.ui.forms.extensions.IEventAction;
(-)plugin.properties (+39 lines)
Lines 144-149 Link Here
144
144
145
NewRecordingWizardPage.TITLE 	= Create New Test From Recording
145
NewRecordingWizardPage.TITLE 	= Create New Test From Recording
146
146
147
RecLocationWizardPage.TITLE = Select Location For Recording
148
RecLocationWizardPage.DESCRIPTION=Select existing recording from which to create a test.
149
RecLocationWizardPage.FILENAME_LABEL=&Recording file name:
150
151
TestsuiteLocationWizardPage.TITLE = Select Location For Test Suite
152
TestsuiteLocationWizardPage.DESCRIPTION=Select project and file name for test
153
TestsuiteLocationWizardPage.FILENAME_LABEL=&Test file name:
154
155
DefaultRecWizardProvider.FILES_EXIST_TITLE=Warning
156
DefaultRecWizardProvider.TESTSUITE_EXISTS=The generated test already exists and will be overwritten.  Proceed?
157
DefaultRecWizardProvider.REC_EXISTS=The trace file already exists and will be overwritten.  Proceed?
158
DefaultRecWizardProvider.BOTH_EXIST=Both the trace file and generated test already exist and will be overwritten.  Proceed?
159
160
RecorderClientUI.INIT_JOB = Initializing Recorder...
161
RecorderClientUI.RECORDING_ABORTED_DUE_TO_EXCEPTION_MESSAGE=IWAT3042E recording aborted due to exception:
162
163
showAdvanced = &Advanced >>
164
hideAdvanced = << &Advanced
165
166
TEST_FROM_RECORDING = Test From Recording
167
GENERIC_RECORDING = Generic Recording
168
GENERIC_RECORDING_ACTION_SET = Action Set for Generic Recording Framework
169
GEN_RECORDER_TOOLTIP = Create a Test From Recording
170
171
W_NAME = Name
172
W_DESCRIPTION = Description
173
174
TestSuite2TestLog_NAME=Associated Test Logs
175
TestLog2TestSuite_NAME=Source Test Suite
176
TestInvoker2TestInvoked_NAME=Invoked tests
177
TestInvoked2TestInvoker_NAME=Test Invocations
178
Test2Datapool_NAME=Associated Datapools
179
Datapool2Test_NAME=Associated Tests
180
Artifact2Test_NAME=Associated Tests
181
Test2Artifact_NAME=Associated Artifacts
182
Deploy2Artifact_NAME=Associated Artifacts
183
Artifact2Deploy_NAME=Associated Deployments
184
Deploy2Location_NAME=Associated Locations
185
Location2Deploy_NAME=Associated Deployments# Add support for importing test log files
147
# Add support for importing test log files
186
# Add support for importing test log files
148
TEST_LOG_FILE= Test Log File
187
TEST_LOG_FILE= Test Log File
149
IMP_TEST_LOG_DSC= Import a test log file from the local file system into the workspace.
188
IMP_TEST_LOG_DSC= Import a test log file from the local file system into the workspace.
(-)schema/testNavigatorPasteExtension.exsd (-8 / +8 lines)
Lines 11-16 Link Here
11
   </annotation>
11
   </annotation>
12
12
13
   <element name="extension">
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element deprecated="true"/>
17
         </appInfo>
18
         <documentation>
19
            deprecated : for specific paste behavior on proxy node, implement IProxyNodePaster interface instead
20
         </documentation>
21
      </annotation>
14
      <complexType>
22
      <complexType>
15
         <sequence>
23
         <sequence>
16
            <element ref="paster" minOccurs="1" maxOccurs="unbounded"/>
24
            <element ref="paster" minOccurs="1" maxOccurs="unbounded"/>
Lines 104-116 Link Here
104
      </documentation>
112
      </documentation>
105
   </annotation>
113
   </annotation>
106
114
107
   <annotation>
108
      <appInfo>
109
         <meta.section type="copyright"/>
110
      </appInfo>
111
      <documentation>
112
         
113
      </documentation>
114
   </annotation>
115
115
116
</schema>
116
</schema>
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/IResourceSetRefactoringContext.java (+66 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Set;
15
16
import org.eclipse.emf.common.util.URI;
17
import org.eclipse.emf.ecore.resource.Resource;
18
import org.eclipse.emf.ecore.resource.ResourceSet;
19
20
/**
21
 * Interface used to collect and postpone change to perform on EMF models.
22
 * This interface is not intended to be implemented by clients.
23
 * 
24
 * @author jgout
25
 * @since 4.3
26
 */
27
public interface IResourceSetRefactoringContext {
28
29
	/**
30
	 * Adds the given resource into the set of resources that have been loaded.
31
	 * @param res a resource
32
	 */
33
	public void addResourceToSave(Resource res);
34
	
35
	/**
36
	 * Returns the set of resources that are to be saved.
37
	 * @return the set of resources that are to be saved.
38
	 */
39
	public Set getResourcesToSave();
40
	
41
	/**
42
	 * Returns the resource set in which the resource have been loaded.
43
	 * @return the resource set in which the resource have been loaded.
44
	 */
45
	public ResourceSet getResourceSet();
46
	
47
	/**
48
	 * Gathers the resource which the URI has to be changed at the end.
49
	 * @param res the resource which the URI should be changed
50
	 * @param newURI the new URI to set.
51
	 */
52
	public void addChangedURI(Resource res, URI newURI);
53
	
54
	/**
55
	 * Gets the new URI for the given resource
56
	 * @param res a resource which a new URI should be set.
57
	 * @return the new URI.
58
	 */
59
	public URI getNewURI(Resource res);
60
	
61
	/**
62
	 * Returns the set of resources that which URI should be changed.
63
	 * @return the set of resources that which URI should be changed.
64
	 */
65
	public Set getResourcesToMove();
66
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/MoveModelChange.java (+97 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Date;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.OperationCanceledException;
23
import org.eclipse.emf.common.util.URI;
24
import org.eclipse.emf.ecore.resource.Resource;
25
import org.eclipse.hyades.test.ui.navigator.EObjectProxyNode;
26
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
27
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
28
import org.eclipse.ltk.core.refactoring.Change;
29
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
30
import org.eclipse.osgi.util.NLS;
31
32
public class MoveModelChange extends Change {
33
	private EMFRefactoringTransaction context;
34
	protected IPath destination;
35
	protected IProxyNode proxy;
36
	private boolean shouldBeRenamed;
37
	private RefactoringStatus status;
38
39
	public MoveModelChange(IProxyNode node, IRefactoringContext context, IPath destinationPath) {
40
		this.proxy = node;
41
		this.destination = destinationPath;
42
		this.context = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
43
		Assert.isNotNull(this.context);
44
		this.status = new RefactoringStatus();
45
		IFile destFile = ResourcesPlugin.getWorkspace().getRoot().getFile(destination);
46
		if (destFile.exists()) {
47
			handleFileAlreadyExists(this.status);
48
		}
49
	}
50
51
	public Object getModifiedElement() {
52
		return proxy;
53
	}
54
55
	public String getName() {
56
		String fileName = proxy.getUnderlyingResource().getFullPath().toPortableString();
57
		return NLS.bind(RefactoringMessages.MOVE_FILE, fileName, destination.removeLastSegments(1));
58
	}
59
60
	public void initializeValidationData(IProgressMonitor pm) {
61
	}
62
63
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
64
		return this.status;
65
	}
66
67
	protected void handleFileAlreadyExists(RefactoringStatus status) {
68
		status.addInfo(NLS.bind(RefactoringMessages.ALREADY_EXISTS_PROXY_DURING_MOVE, destination.toPortableString()));
69
		shouldBeRenamed = true;
70
	}
71
	
72
	public Change perform(IProgressMonitor pm) throws CoreException {
73
		if (proxy instanceof EObjectProxyNode) {
74
			//- load the referencer
75
			Resource res = context.getResourceSet().getResource(((EObjectProxyNode)proxy).getOriginatorURI().trimFragment(), true);
76
			context.addResourceToSave(res);
77
			context.addChangedURI(res, getNewURI());
78
		}
79
		return null;
80
	}
81
82
	public URI getNewURI() {
83
		return URI.createPlatformResourceURI(getNewName(),false);
84
	}
85
86
	private String getNewName() {
87
		if(shouldBeRenamed) {
88
			String fullFileName = destination.lastSegment();
89
			int dotIndex = fullFileName.lastIndexOf('.');
90
			long number = new Date().getTime();
91
			String newName = fullFileName.substring(0, dotIndex-1)+number+fullFileName.substring(dotIndex);
92
			return destination.removeLastSegments(1).append(newName).toPortableString();
93
		} else {
94
			return destination.toPortableString();
95
		}
96
	}	
97
}
(-)src/org/eclipse/hyades/test/ui/navigator/actions/IProxyNodePaster.java (+38 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator.actions;
13
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.ltk.core.refactoring.Change;
16
17
/**
18
 * Interface that allows to describe the paste behavior of a proxy node.
19
 * 
20
 * @author jbozier
21
 * @since 4.5
22
 */
23
public interface IProxyNodePaster {
24
	/**
25
	 * Returns the refactoring change when pasting this instance to the new destination path.
26
	 * The given context can be used if the local change cannot be perform without a global context.
27
	 * This can be performed using an IRefactoringTransaction (retrieved by its domain Id) to collect 
28
	 * data. Such refactoring transaction will performed changes in one time.
29
	 * create a new proxy on dest location + copy proxy link if any
30
	 *   
31
	 * @param context a context that contains all IRefactoringTransaction instances defined by clients.
32
	 * @param newPath the destination path of this proxy node.
33
	 * @param targetName a 1 element array that will contain newly pasted proxy file name after call
34
	 * @return the change that performs the paste of the proxy node to the given destination path.
35
	 */
36
	public Change createPasteChange(IRefactoringContext context, IPath destinationPath,String [] targetName);
37
38
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/messages.properties (+59 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2006 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials 
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
# $Id$
8
# 
9
# Contributors:
10
#     IBM Corporation - initial API and implementation
11
###############################################################################
12
13
# NLS_MESSAGEFORMAT_VAR
14
# NLS_ENCODING=UTF-8
15
16
DELETE_FOLDER = Delete folder ''{0}''
17
MOVE_FOLDER = Move folder ''{0}'' into ''{1}''
18
PASTE_FOLDER = Paste folder ''{0}'' into ''{1}''
19
MOVE_FILE = Move file ''{0}'' into ''{1}''
20
PASTE_FILE = Paste file ''{0}'' into ''{1}''
21
DELETE_PROXY = Delete ''{0}''
22
DELETE_INVOCATION = Remove invocation of ''{0}'' from ''{1}''
23
DELETE_CONFIRM_1 = Are you sure you want to delete ''{0}'' from the file system?
24
DELETE_CONFIRM_N = Are you sure you want to delete {0} selected elements from the file system?
25
DELETE_DEEP_REMOVE = Delete owned referenced assets as well (forces preview)
26
MOVE_PROXY = Move ''{0}'' into ''{1}''
27
PASTE_PROXY = Copy ''{0}'' into ''{1}''
28
NO_FOLDER=Folder does not exist
29
NO_PROJECT=Project does not exist or not open.
30
READ_ONLY_FOLDER=Folder is read-only
31
READ_ONLY_PROJECT=Project is read-only
32
ALREADY_EXISTS_FOLDER=Folder ''{0}'' already exists.
33
ALREADY_EXISTS_PROJECT=Project ''{0}'' already exists.
34
MOVE_CHOOSE_DESTINATION_SINGLE=&Choose destination for ''{0}'':
35
MOVE_CHOOSE_DESTINATION_MULTI=&Choose destination for ''{0}'' selected elements:
36
PASTE_CHOOSE_DESTINATION_SINGLE=&Choose destination for ''{0}'':
37
PASTE_CHOOSE_DESTINATION_MULTI=&Choose destination for ''{0}'' selected elements:
38
MOVE_ERROR=The selected element cannot be the destination of this operation.
39
PASTE_ERROR=The selected element cannot be the destination of this operation.
40
UPDATE_PROXY=Update ''{0}''
41
CHANGES_FOR_UPDATING=Changes for updating ''{0}''
42
UPDATE_PROXY_PATH_CHANGED=Update references in ''{0}''
43
UPDATE_REFERENCES=Update references in ''{0}''
44
UPDATE_OWNED_RESSOURCES_REFERENCES=Update references for owned resources
45
NO_FILE=File does not exist
46
READ_ONLY_FILE=File is read-only
47
ALREADY_EXISTS_FILE= File ''{0}'' already exists, it will overwritten.
48
ALREADY_EXISTS_PROXY_DURING_MOVE = File ''{0}'' will be renamed because a file with the same name exists in the destination folder.
49
ALREADY_EXISTS_PROXY_DURING_PASTE = File ''{0}'' will be renamed because a file with the same name exists in the destination folder.
50
ALREADY_EXISTS_PROXY_DURING_RENAME = File ''{0}'' already exists.
51
INNER_FOLDER_MOVE_ERROR=Unable to move a folder into one of its descendents.
52
INNER_FOLDER_PASTE_ERROR=Unable to copy a folder into one of its descendents.
53
RENAME_FILE= Rename File ''{0}'' in ''{1}''
54
RENAME_PROXY=Rename ''{0}'' in ''{1}'' 
55
RENAME_CONTAINER=Rename ''{0}'' in ''{1}'' 
56
ProxyNodeScanner_PM_LABEL=Searching for references...
57
ReorgRefactoring_CANCELED_OPERATION_MSG=Operation canceled by user
58
LaunchConfigurationUpdateChange_NAME=Update Launch Configuration ''{0}''
59
LaunchConfigurationDeleteChange_NAME=Delete Launch Configuration ''{0}''
(-)src/org/eclipse/hyades/test/ui/navigator/IReferencerProxyNode.java (+48 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator;
13
14
import java.util.Collection;
15
import java.util.Set;
16
17
/**
18
 * Interface to set references between proxy nodes.
19
 * 
20
 * @author jgout
21
 * @since 4.4
22
 */
23
public interface IReferencerProxyNode extends IProxyNode {	
24
	/**
25
	 * Gets the reference collection of the given type. The content of this list is populated using {@link addReference} or {@link addBidirectionalReference}.
26
	 * @param refType the type of the reference to retrieve.
27
	 * @return a collection containing all the references (IProxyNode) of the 
28
	 * given type found in the current implementor. An empty 
29
	 * collection is returned in case of no such typed reference has been found.
30
	 */
31
	public Collection getReferences(String refType);
32
	
33
	/**
34
	 * Returns the set of the reference types (as <code>String</code>) contained in the implementor proxy node.
35
	 * @return the set of the reference types (as <code>String</code>) contained in the implementor proxy node.
36
	 */
37
	public Set getReferenceTypes();
38
	
39
	
40
//	/**
41
//	 * repair references when proxy is copied with an owned node
42
//	 * @param nodeB : owned node
43
//	 * @param nodeC : copy of current proxy
44
//	 * @param nodeD : copy of owned node
45
//	 */
46
//	public void replaceReference(IReferencerProxyNode nodeB,IReferencerProxyNode nodeC,IReferencerProxyNode nodeD);
47
//	
48
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/reference/ReferenceRegistry.java (+201 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy.reference;
13
14
import java.util.Collection;
15
import java.util.Collections;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.Map;
19
import java.util.Set;
20
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.ISaveContext;
24
import org.eclipse.core.resources.ISaveParticipant;
25
import org.eclipse.core.resources.ISavedState;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.hyades.test.ui.UiPlugin;
30
31
public class ReferenceRegistry implements ISaveParticipant {
32
	
33
	private static ReferenceRegistry instance;
34
	//- Map (project, ProjectReferenceRegistry)
35
	private Map projectRegistries;
36
	private IReferenceRegistrySavedState internalSavedState;
37
	
38
	private class SavedState implements IReferenceRegistrySavedState {
39
		private ISavedState savedState;
40
		public SavedState(ISavedState state) {
41
			savedState = state;
42
		}
43
		public IPath lookup(IPath path) {
44
			return savedState.lookup(path);
45
		}
46
	}
47
	
48
	public static ReferenceRegistry getInstance() {
49
		if(instance == null) {
50
			instance = new ReferenceRegistry();
51
		}
52
		return instance;
53
	}
54
	
55
	private ReferenceRegistry() {
56
		 projectRegistries = new HashMap();
57
		 try {
58
	        ISavedState lastState = ResourcesPlugin.getWorkspace().addSaveParticipant(UiPlugin.getDefault(), this);
59
	        this.internalSavedState = (lastState != null) ? new SavedState(lastState) : null;
60
		} catch (CoreException e) {
61
			//- unable to retrieve the previous saved state, start with empty state.
62
		}
63
	}
64
	
65
	private ProjectReferenceRegistry getRegistry(IFile referencer) {
66
		IProject project = referencer.getProject();
67
		if (project.isAccessible()) {
68
			return getProjectReferenceRegistry(project);
69
		}
70
		return null;
71
	}
72
73
	public ProjectReferenceRegistry getProjectReferenceRegistry(IProject project) {
74
		ProjectReferenceRegistry registry =	(ProjectReferenceRegistry)this.projectRegistries.get(project);
75
		if (registry == null) {
76
			//- Not initialized yet
77
			registry = new ProjectReferenceRegistry(project, this.internalSavedState);
78
			this.projectRegistries.put(project, registry);
79
		}
80
		return registry;
81
	}
82
83
	public void removeProjectReferenceRegistry(IProject project) {
84
		projectRegistries.remove(project); 
85
	}
86
	
87
	public void addReference(IFile referencer, String refType, IFile referenced) {
88
		ProjectReferenceRegistry registry = getRegistry(referencer);
89
		if (registry != null) {
90
			registry.addReference(referencer, refType, referenced);
91
		}
92
	}
93
		
94
	public void addBidirectionalReference(IFile referencer, String refType, IFile referenced, String oppositeRefType) {
95
		ProjectReferenceRegistry registryReferencer = getRegistry(referencer);
96
		ProjectReferenceRegistry registryReferenced = getRegistry(referenced);
97
		if (registryReferencer != null) {
98
			registryReferencer.addReference(referencer, refType, referenced);
99
		}
100
		if (registryReferenced != null) {
101
			registryReferenced.addReference(referenced, oppositeRefType, referencer);
102
		}
103
	}
104
	
105
	public void removeReference(IFile referencer, IFile referenced) {
106
		ProjectReferenceRegistry registry = getRegistry(referencer);
107
		if (registry != null) {
108
			registry.removeReference(referencer, referenced);
109
		}
110
	}
111
	
112
	public Collection getReferences(IFile referencer, String refType) {
113
		ProjectReferenceRegistry registry = getRegistry(referencer);
114
		if (registry != null) {
115
			return registry.getReferences(referencer, refType);
116
		}
117
		return Collections.EMPTY_LIST;
118
	}
119
	
120
	public Set getReferenceTypes(IFile referencer) {
121
		ProjectReferenceRegistry registry = getRegistry(referencer);
122
		if (registry != null) {
123
			return registry.getReferenceTypes(referencer);
124
		}
125
		return Collections.EMPTY_SET;
126
	}
127
	
128
	//- Persistence methods, delegation to project focused registries
129
	
130
	public void doneSaving(ISaveContext context) {
131
		if (context.getKind() == ISaveContext.PROJECT_SAVE) {
132
			IProject project = context.getProject();
133
			ProjectReferenceRegistry registry =	(ProjectReferenceRegistry)projectRegistries.get(project);
134
			if (registry != null) {
135
				registry.doneSaving(context);
136
			}
137
		} else {
138
			Iterator it = projectRegistries.values().iterator();
139
			while (it.hasNext()) {
140
				ProjectReferenceRegistry registry = (ProjectReferenceRegistry) it.next();
141
				registry.doneSaving(context);
142
			}
143
		}			
144
	}
145
146
	public void prepareToSave(ISaveContext context) throws CoreException {
147
		if (context.getKind() == ISaveContext.PROJECT_SAVE) {
148
			IProject project = context.getProject();
149
			ProjectReferenceRegistry registry =	(ProjectReferenceRegistry)projectRegistries.get(project);
150
			if (registry != null) {
151
				registry.prepareToSave(context);
152
			}
153
		} else {
154
			Iterator it = projectRegistries.values().iterator();
155
			while (it.hasNext()) {
156
				ProjectReferenceRegistry registry = (ProjectReferenceRegistry) it.next();
157
				registry.prepareToSave(context);
158
			}
159
		}	
160
	}
161
162
	public void rollback(ISaveContext context) {
163
		if (context.getKind() == ISaveContext.PROJECT_SAVE) {
164
			IProject project = context.getProject();
165
			ProjectReferenceRegistry registry =	(ProjectReferenceRegistry)projectRegistries.get(project);
166
			if (registry != null) {
167
				registry.rollback(context);
168
			}
169
		} else {
170
			Iterator it = projectRegistries.values().iterator();
171
			while (it.hasNext()) {
172
				ProjectReferenceRegistry registry = (ProjectReferenceRegistry) it.next();
173
				registry.rollback(context);
174
			}
175
		}
176
	}
177
178
	public void saving(ISaveContext context) throws CoreException {
179
		if (context.getKind() == ISaveContext.PROJECT_SAVE) {
180
			IProject project = context.getProject();
181
			ProjectReferenceRegistry registry =	(ProjectReferenceRegistry)projectRegistries.get(project);
182
			if (registry != null) {
183
				registry.saving(context);
184
			}
185
		} else {
186
			Iterator it = projectRegistries.values().iterator();
187
			while (it.hasNext()) {
188
				ProjectReferenceRegistry registry = (ProjectReferenceRegistry) it.next();
189
				registry.saving(context);
190
			}
191
		}
192
	}
193
194
	public void removeReferences(IFile referencer) {
195
		ProjectReferenceRegistry registry = getRegistry(referencer);
196
		if (registry != null) {
197
			registry.removeReferences(referencer);
198
		}
199
	}
200
201
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteModelChange.java (+152 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.List;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.core.resources.IWorkspaceRoot;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.OperationCanceledException;
24
import org.eclipse.core.runtime.Path;
25
import org.eclipse.emf.common.util.URI;
26
import org.eclipse.emf.ecore.EObject;
27
import org.eclipse.emf.ecore.resource.Resource;
28
import org.eclipse.hyades.models.common.common.CMNNamedElement;
29
import org.eclipse.hyades.test.core.util.EMFUtil;
30
import org.eclipse.hyades.test.ui.UiPlugin;
31
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
32
import org.eclipse.hyades.test.ui.navigator.EObjectProxyNode;
33
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
34
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
35
import org.eclipse.ltk.core.refactoring.Change;
36
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
37
import org.eclipse.osgi.util.NLS;
38
39
/**
40
 * change to apply to perform a model paste
41
 * 
42
 * @author jbozier
43
 * @since 4.5
44
 */
45
//TODO : real similar to move, check if we can simplify this
46
public class PasteModelChange extends Change {
47
	private EMFRefactoringTransaction context;
48
	protected IPath destination;
49
	protected IProxyNode proxy;
50
	private boolean shouldBeRenamed;
51
	private RefactoringStatus status;
52
	private String newName = null;
53
	private String newBaseName = null;
54
	
55
	
56
	public PasteModelChange(IRefactoringContext context,IProxyNode node, IPath destinationPath,String [] targetName) {
57
		this.proxy = node;
58
		this.destination = destinationPath;
59
		this.context = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
60
		Assert.isNotNull(this.context);
61
		this.status = new RefactoringStatus();
62
		IFile destFile = ResourcesPlugin.getWorkspace().getRoot().getFile(destination);
63
		if (destFile.exists()) {
64
			handleFileAlreadyExists(this.status);
65
		}
66
		this.newName = getNewName(); 
67
		if ((targetName != null) && (targetName.length > 0)) {
68
			targetName[0] = newName;
69
		}
70
	}
71
72
	public Object getModifiedElement() {
73
		return proxy;
74
	}
75
76
	public String getName() {
77
		String fileName = proxy.getUnderlyingResource().getFullPath().toPortableString();
78
		return NLS.bind(RefactoringMessages.PASTE_FILE, fileName, newName /*destination.removeLastSegments(1)*/);
79
	}
80
81
	public void initializeValidationData(IProgressMonitor pm) {
82
	}
83
84
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
85
		return this.status;
86
	}
87
88
	protected void handleFileAlreadyExists(RefactoringStatus status) {
89
	//	status.addInfo(NLS.bind(RefactoringMessages.ALREADY_EXISTS_PROXY_DURING_PASTE, destination.toPortableString()));
90
		shouldBeRenamed = true;
91
	}
92
	
93
	public Change perform(IProgressMonitor pm) throws CoreException {
94
		if (proxy instanceof EObjectProxyNode) {
95
			//- load the referencer
96
			Resource res = context.getResourceSet().getResource(((EObjectProxyNode)proxy).getOriginatorURI().trimFragment(), true);
97
			res.setURI(getNewURI());
98
			try {
99
				EMFUtil.save(res);
100
				EMFUtil.getWorkspaceFile(res).refreshLocal(0, pm);
101
				if (shouldBeRenamed) {
102
					if(context != null) {
103
						List objects = res.getContents();
104
						if (!objects.isEmpty()) {
105
							EObject object = (EObject)objects.get(0);
106
							if (object instanceof CMNNamedElement) {
107
								((CMNNamedElement)object).setName(newBaseName);
108
								EMFUtil.save(res);
109
								EMFUtil.getWorkspaceFile(res).refreshLocal(0, pm);
110
							}	
111
						}
112
					}
113
				}				
114
			} catch (Exception e) {
115
				UiPlugin.logError(e);
116
			}
117
		}
118
		return null;
119
	}
120
	
121
	public URI getNewURI() {
122
		return URI.createPlatformResourceURI(newName,false);
123
	}
124
125
	// call it one time only, because can be sometime a bit slow
126
	private String getNewName() {
127
		if(shouldBeRenamed) {
128
			boolean done = false;		
129
			String fullFileName = destination.lastSegment();
130
			int dotIndex = fullFileName.lastIndexOf('.');
131
			String basePart = fullFileName.substring(0, dotIndex);
132
			String endPart = fullFileName.substring(dotIndex);
133
			String newFullName = null;
134
			String ret = null;
135
			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
136
			for (int i=0; (!done); i++) {
137
				 if (i != 0) {
138
					 newBaseName = NLS.bind(TestNavigatorMessages.FileFolderInContainerPaste_NameTwoArg,new Integer(i),basePart);
139
				 } else {
140
					 newBaseName = NLS.bind(TestNavigatorMessages.FileFolderInContainerPaste_NameOneArg,basePart);					 
141
				 }
142
				newFullName = newBaseName+endPart;
143
				ret = destination.removeLastSegments(1).append(newFullName).toPortableString();
144
				IPath newpath = new Path(ret);
145
				done = (!root.getFolder(newpath).exists()) && (!root.getFile(newpath).exists());
146
			}
147
			return ret;
148
		} else {
149
			return destination.toPortableString();
150
		}
151
	}
152
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/RenameFileChange.java (+76 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.OperationCanceledException;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.ltk.core.refactoring.Change;
21
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
22
import org.eclipse.osgi.util.NLS;
23
24
public class RenameFileChange extends Change {
25
	private IFile file;
26
	private String name;
27
28
	public RenameFileChange(IFile file, String name) {
29
		this.file = file;
30
		this.name = name;
31
	}
32
33
	public Object getModifiedElement() {
34
		return file;
35
	}
36
37
	public String getName() {
38
		String newPathName = file.getParent().getFullPath().append(new Path(name)).toOSString();
39
		return NLS.bind(RefactoringMessages.RENAME_FILE, file.getName(), newPathName);
40
	}
41
42
	public void initializeValidationData(IProgressMonitor pm) {
43
	}
44
45
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,	OperationCanceledException {
46
		RefactoringStatus status = new RefactoringStatus();
47
		IFile destFile = file.getParent().getFile(new Path(name));
48
		if (!file.exists()) {
49
			status.addError(RefactoringMessages.NO_FILE);
50
		}
51
		if (file.isReadOnly()) {
52
			status.addWarning(RefactoringMessages.READ_ONLY_FILE);
53
		}
54
		if(destFile.exists()) {
55
			status.addWarning(NLS.bind(RefactoringMessages.ALREADY_EXISTS_FILE, destFile.getFullPath().toPortableString()));
56
		}
57
		return status;
58
	}
59
60
	public Change perform(IProgressMonitor pm) throws CoreException {
61
		Change undo = null;
62
		try {
63
			pm.beginTask("", 1);  //$NON-NLS-1$
64
			IContainer parent = file.getParent();
65
			if (parent != null) {
66
				undo = new RenameFileChange(file, file.getName());
67
			}
68
			file.move(parent.getFullPath().append(new Path(name)), false, true, pm);
69
			pm.worked(1);
70
			return undo;
71
		} finally {
72
			pm.done();
73
		}
74
	}
75
76
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/MoveFolderCompositeChange.java (+72 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IFolder;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.SubProgressMonitor;
19
import org.eclipse.ltk.core.refactoring.Change;
20
import org.eclipse.ltk.core.refactoring.CompositeChange;
21
import org.eclipse.ltk.core.refactoring.NullChange;
22
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
23
24
public class MoveFolderCompositeChange extends CompositeChange {
25
	private IFolder folder;
26
	private MoveFolderChange root;
27
28
	public MoveFolderCompositeChange(IFolder folder, IPath newPath) {
29
		super(""); //$NON-NLS-1$
30
		this.folder = folder;
31
		this.root = new MoveFolderChange(folder, newPath);
32
	}
33
34
	public Object getModifiedElement() {
35
		return folder;
36
	}
37
38
	public String getName() {
39
		return root.getName();
40
	}
41
42
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
43
		RefactoringStatus status = root.isValid(pm);
44
		if(folder.getFullPath().isPrefixOf(root.getDestinationPath())) {
45
			status.addFatalError(RefactoringMessages.INNER_FOLDER_MOVE_ERROR);
46
		}
47
		status.merge(super.isValid(pm));
48
		return status;
49
	}
50
51
	public Change perform(IProgressMonitor pm) throws CoreException {
52
		pm.beginTask("", getChildren().length+1);  //$NON-NLS-1$
53
		try {
54
			//- children are update changes
55
			super.perform(new SubProgressMonitor(pm, getChildren().length));
56
			//- move the folder and all its content
57
			root.perform(new SubProgressMonitor(pm, 1));
58
			return null;
59
		} finally {
60
			pm.done();
61
		}
62
	}
63
	
64
	public void freeze() {
65
		if(getChildren().length == 0) {
66
			markAsSynthetic();
67
			//- add a dummy child in order to keep the composite alive
68
			add(new NullChange(getName()));
69
		}
70
	}
71
72
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/DeleteModelElementChange.java (+81 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.OperationCanceledException;
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.hyades.test.core.internal.changes.DeleteFileChange;
22
import org.eclipse.hyades.test.core.util.EMFUtil;
23
import org.eclipse.hyades.test.ui.navigator.EObjectProxyNode;
24
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
25
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
26
import org.eclipse.ltk.core.refactoring.Change;
27
import org.eclipse.ltk.core.refactoring.NullChange;
28
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
29
import org.eclipse.osgi.util.NLS;
30
31
public class DeleteModelElementChange extends Change {
32
	private IProxyNode proxy;
33
	protected EMFRefactoringTransaction context;
34
	private Change fileChange;
35
	
36
	public DeleteModelElementChange(IRefactoringContext context, EObjectProxyNode node) {
37
		this.proxy = node;
38
		this.context = (EMFRefactoringTransaction)context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
39
		//- if the proxy node can be adpated in IFile we need to remove the file as well.
40
		Object file = node.getAdapter(IFile.class);
41
		if(file != null) {
42
			this.fileChange = new DeleteFileChange((IFile) file);
43
		} else {
44
			this.fileChange = new NullChange(NLS.bind(RefactoringMessages.UPDATE_PROXY, proxy.getUnderlyingResource().getFullPath().toPortableString()));
45
		}
46
	}
47
48
	public Object getModifiedElement() {
49
		return null;
50
	}
51
52
	public String getName() {
53
		return fileChange.getName();
54
	}
55
56
	public void initializeValidationData(IProgressMonitor pm) {
57
	}
58
59
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,	OperationCanceledException {
60
		return fileChange.isValid(pm);
61
	}
62
63
	public Change perform(IProgressMonitor pm) throws CoreException {
64
		URI uri = ((EObjectProxyNode)proxy).getOriginatorURI();
65
 		Resource res = context.getResourceSet().getResource(uri.trimFragment(), true);
66
 		EObject eObject = res.getEObject(uri.fragment());
67
		
68
//		EObject eObject = context.getResourceSet().getEObject(uri, true);
69
//		Resource res = eObject.eResource();
70
		if (eObject != null) {
71
			EMFUtil.remove(eObject);
72
		}
73
		if (fileChange instanceof NullChange) {
74
			context.addResourceToSave(res);
75
		} else {
76
			fileChange.perform(pm);
77
		}
78
		return null;
79
	}
80
81
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/Proxy.java (+47 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
13
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.runtime.Path;
17
import org.eclipse.hyades.test.ui.navigator.AbstractProxy;
18
import org.eclipse.hyades.test.ui.navigator.IProxy;
19
20
public class Proxy extends AbstractProxy implements IProxy {
21
	private IResource res;
22
	private String id;
23
	
24
	public Proxy(IResource res, String id) {
25
		this.res = res;
26
		this.id = id;
27
	}
28
29
	/**
30
	 * Creates a proxy
31
	 * @param resName the workspace relative path of the underlying resource of the proxy
32
	 * @param id identifier of the proxy
33
	 */
34
	public Proxy(String resName, String id) {
35
		this.res = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(resName));
36
		this.id = id;
37
	}
38
39
	public String getIdentifier() {
40
		return id;
41
	}
42
43
	public IResource getUnderlyingResource() {
44
		return res;
45
	}
46
47
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/ReorgRefactoring.java (+150 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Iterator;
15
import java.util.LinkedList;
16
import java.util.List;
17
18
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.OperationCanceledException;
26
import org.eclipse.core.runtime.SubProgressMonitor;
27
import org.eclipse.hyades.test.ui.UiPlugin;
28
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
29
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.CompositeReferencerProxyNode;
30
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceTypeRegistry;
31
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
32
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
33
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeUpdater;
34
import org.eclipse.ltk.core.refactoring.Change;
35
import org.eclipse.ltk.core.refactoring.CompositeChange;
36
import org.eclipse.ltk.core.refactoring.Refactoring;
37
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
38
import org.eclipse.osgi.util.NLS;
39
40
/**
41
 * Common refactoring between move and rename.
42
 * @author jgout
43
 * @since 4.3
44
 */
45
public abstract class ReorgRefactoring extends Refactoring {
46
	protected Change change;
47
	protected List seenElements;
48
	protected RefactoringContext context;
49
	
50
	public ReorgRefactoring() {
51
		this.seenElements = new LinkedList();
52
		this.context = new RefactoringContext();
53
	}
54
55
	public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
56
		pm.beginTask("", 3); //$NON-NLS-1$
57
		try {
58
			ProxyNodeScanner scanner = new ProxyNodeScanner(ResourcesPlugin.getWorkspace().getRoot());
59
			try {
60
				scanner.scan(new SubProgressMonitor(pm, 1));
61
			} catch (OperationCanceledException e) {
62
				return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.ReorgRefactoring_CANCELED_OPERATION_MSG);
63
			}			
64
			change = createChange(new SubProgressMonitor(pm, 1));
65
			pm.worked(1);
66
			return change.isValid(new SubProgressMonitor(pm, 1));
67
		} finally {
68
			pm.done();
69
		}
70
	}
71
72
	public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
73
		pm.beginTask("", 1); //$NON-NLS-1$
74
		try {
75
			pm.worked(1);
76
			return new RefactoringStatus();
77
		} finally {
78
			pm.done();
79
		}
80
	}
81
82
	public String getName() {
83
		return "";  //$NON-NLS-1$
84
	}
85
86
	protected Change performContainerChildren(CompositeChange change, IContainer source, IPath newPath) {
87
		if(source.isAccessible()) {
88
			IResource[] resources;
89
			try {
90
				resources = source.members();
91
			} catch (CoreException e) {
92
				UiPlugin.logError("Unable to get members of container: "+source.getFullPath().toOSString(), e); //$NON-NLS-1$
93
				return null;
94
			}
95
			for (int i = 0; i < resources.length; i++) {
96
				if (resources[i] instanceof IFile) {
97
					IFile file = (IFile)resources[i];
98
					IProxyNode proxy = FileProxyNodeCache.getInstance().getProxy(file);
99
					if (proxy != null) {
100
						if(!seenElements.contains(proxy)) {
101
							seenElements.add(proxy);
102
							//- is this proxy adaptable to updater ?
103
							Change updateChange = null;
104
							IProxyNodeUpdater updater = (IProxyNodeUpdater)proxy.getAdapter(IProxyNodeUpdater.class);
105
							if(updater != null) {
106
								updateChange = updater.createUpdateChange(context, source, newPath.append(file.getName()));
107
							}
108
							CompositeChange composite = new CompositeChange(NLS.bind(RefactoringMessages.CHANGES_FOR_UPDATING, proxy.getText()));
109
							if(updateChange != null) {
110
								composite.add(updateChange);
111
							}
112
							//- process all references
113
							if (proxy instanceof IReferencerProxyNode) {
114
								CompositeReferencerProxyNode ref = new CompositeReferencerProxyNode(proxy);
115
								for (Iterator it = ref.getReferenceTypes().iterator(); it.hasNext();) {
116
									createRenameReferencerTypeChildren(composite, ref, (String)it.next());
117
								}
118
							}
119
							change.add(composite);
120
						}
121
					}
122
				} else {
123
					performContainerChildren(change, (IContainer)resources[i], newPath.append(resources[i].getName()));
124
				}
125
			}
126
		}
127
		return change;
128
	}
129
130
	private void createRenameReferencerTypeChildren(CompositeChange change, CompositeReferencerProxyNode ref, String type) {
131
		String oppType = ReferenceTypeRegistry.getInstance().getOppositeReferenceType(type);
132
		if(ReferenceTypeRegistry.getInstance().isExplicit(oppType)) {
133
			CompositeChange c = new CompositeChange(ReferenceTypeRegistry.getInstance().getName(type));
134
			for (Iterator it = ref.getReferences(type).iterator(); it.hasNext();) {
135
				IProxyNodeUpdater updater = (IProxyNodeUpdater) ((IProxyNode)it.next()).getAdapter(IProxyNodeUpdater.class);
136
				if (updater != null) {
137
					IPath destPath = ref.getUnderlyingResource().getFullPath();
138
					Change updateChange = updater.createUpdateChange(context, ref, type, destPath);
139
					if (updateChange != null) {
140
						c.add(updateChange);
141
					}						
142
				}
143
			}
144
			if(c.getChildren().length > 0) {
145
				change.add(c);
146
			}
147
		}
148
	}
149
150
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/IPasterExtended.java (+29 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.hyades.test.ui.navigator.actions.IPaster;
15
import org.eclipse.swt.widgets.Shell;
16
17
/**
18
 * interface for graphical paster
19
 * @author jbozier
20
 *
21
 */
22
public interface IPasterExtended extends IPaster {
23
24
	/**
25
	 * set the shell for graphical paster
26
	 * @param shell
27
	 */
28
	public void setShell(Shell shell);
29
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/RenameRefactoring.java (+135 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Iterator;
15
16
import org.eclipse.core.resources.IContainer;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.core.runtime.SubProgressMonitor;
23
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.CompositeReferencerProxyNode;
24
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceTypeRegistry;
25
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
26
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
27
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeRenamer2;
28
import org.eclipse.ltk.core.refactoring.Change;
29
import org.eclipse.ltk.core.refactoring.CompositeChange;
30
31
public class RenameRefactoring extends ReorgRefactoring {
32
	private IProxyNode proxy;
33
	private IContainer container;
34
	private String name;
35
36
	public RenameRefactoring(IProxyNode node) {
37
		super();
38
		this.proxy = node;
39
	}
40
41
	public RenameRefactoring(IContainer cont) {
42
		super();
43
		this.container = cont;
44
	}
45
46
	public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
47
		if (change != null) {
48
			return change;
49
		}
50
		try {
51
			pm.beginTask("", 1);  //$NON-NLS-1$
52
			RefactoringTransactionRootChange c = new RefactoringTransactionRootChange(context);
53
			if(container != null) {
54
				Change containerChange = createRenameContainerChange(new SubProgressMonitor(pm, 1));
55
				if (containerChange != null) {
56
					c.add(containerChange);
57
				}
58
			} else if(proxy != null) {
59
				Change proxyChange = createRenameProxyNodeChange();
60
				if (proxyChange != null) {
61
					c.add(proxyChange);
62
				}
63
				pm.worked(1);
64
			}
65
			c.markAsSynthetic();
66
			return c;
67
		} finally {
68
			pm.done();
69
		}
70
	}
71
72
	private Change createRenameProxyNodeChange() {
73
		if (!seenElements.contains(proxy)) {
74
			seenElements.add(proxy);
75
			if (proxy instanceof IReferencerProxyNode) {
76
				return createRenameModelChange();
77
			} else {
78
				createShallowRenameProxyChange();
79
			}
80
		}		
81
		return null;
82
	}
83
	
84
	private Change createShallowRenameProxyChange() {
85
		IProxyNodeRenamer2 renamer = (IProxyNodeRenamer2)proxy.getAdapter(IProxyNodeRenamer2.class);
86
		if (renamer != null) {
87
			return renamer.createRenameChange(context, name);
88
		} else {
89
			IResource res = proxy.getUnderlyingResource();
90
			if (res instanceof IFile) {
91
				return new RenameFileChange((IFile) res, name);
92
			}
93
		}
94
		return null;
95
	}
96
97
	private Change createRenameModelChange() {
98
		CompositeChange composite = new CompositeChange(""); //$NON-NLS-1$
99
		Change renameNode = createShallowRenameProxyChange();
100
		if(renameNode != null) {
101
			composite.add(renameNode);
102
		}
103
		CompositeReferencerProxyNode ref = new CompositeReferencerProxyNode(proxy);
104
		for (Iterator it = ref.getReferenceTypes().iterator(); it.hasNext();) {
105
			String type = (String)it.next();
106
			String oppType = ReferenceTypeRegistry.getInstance().getOppositeReferenceType(type);
107
			if(ReferenceTypeRegistry.getInstance().isExplicit(oppType)) {
108
				composite.add(createUpdateReferenceTypeChange(ref, type));
109
			}
110
		}
111
		composite.markAsSynthetic();
112
		return composite;
113
	}
114
115
	private Change createUpdateReferenceTypeChange(CompositeReferencerProxyNode ref, String type) {
116
		CompositeChange change = new CompositeChange(ReferenceTypeRegistry.getInstance().getName(type));
117
		for (Iterator it = ref.getReferences(type).iterator(); it.hasNext();) {
118
			change.add(new UpdateModelChange((IProxyNode)it.next(), context));
119
		}
120
		return change;
121
	}
122
	
123
	private Change createRenameContainerChange(IProgressMonitor pm) {
124
		RenameContainerChange change = new RenameContainerChange(container, name);
125
		performContainerChildren(change, container, container.getFullPath().removeLastSegments(1).append(name));
126
		change.freeze();
127
		return change;
128
	}
129
130
	public void setNewName(String text) {
131
		name = text;
132
		change = null;
133
		seenElements.clear();
134
	}
135
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/IProxyNodeAdapterFactory.java (+36 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy;
13
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.IAdapterFactory;
16
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.DefaultProxyNodeDeleter;
17
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeDeleter;
19
20
public class IProxyNodeAdapterFactory implements IAdapterFactory {
21
22
	public Object getAdapter(Object adaptableObject, Class adapterType) {
23
		if (adaptableObject instanceof IProxyNode && IProxyNodeDeleter.class.equals(adapterType)) {
24
			IProxyNode proxy = (IProxyNode) adaptableObject;
25
			if(proxy.getAdapter(IFile.class) != null) {
26
				return new DefaultProxyNodeDeleter(proxy);
27
			}
28
		}
29
		return null;
30
	}
31
32
	public Class[] getAdapterList() {
33
		return new Class[] { IProxyNodeDeleter.class };
34
	}
35
36
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFolderCompositeChange.java (+79 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IFolder;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.SubProgressMonitor;
19
import org.eclipse.ltk.core.refactoring.Change;
20
import org.eclipse.ltk.core.refactoring.CompositeChange;
21
import org.eclipse.ltk.core.refactoring.NullChange;
22
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
23
24
/**
25
 * change to apply to perform a folder paste when it have childrens 
26
 * children paste don't appear in refactoring view
27
 * 
28
 * @author jbozier
29
 * @since 4.5
30
 */
31
//TODO : real similar to move, check if we can simplify this
32
public class PasteFolderCompositeChange extends CompositeChange {
33
	private IFolder folder;
34
	private PasteFolderChange root;
35
36
	public PasteFolderCompositeChange(IFolder folder, IPath newPath,IPath [] targetPath) {
37
		super(""); //$NON-NLS-1$
38
		this.folder = folder;
39
		this.root = new PasteFolderChange(folder, newPath,targetPath);
40
	}
41
42
	public Object getModifiedElement() {
43
		return folder;
44
	}
45
46
	public String getName() {
47
		return root.getName();
48
	}
49
50
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
51
		RefactoringStatus status = root.isValid(pm);
52
		if(folder.getFullPath().isPrefixOf(root.getDestinationPath())) {
53
			status.addFatalError(RefactoringMessages.INNER_FOLDER_PASTE_ERROR);
54
		}
55
		status.merge(super.isValid(pm));
56
		return status;
57
	}
58
59
	public Change perform(IProgressMonitor pm) throws CoreException {
60
		pm.beginTask("", getChildren().length+1);  //$NON-NLS-1$
61
		try {
62
			//- paste the folder and all its content
63
			root.perform(new SubProgressMonitor(pm, 1));
64
			//- children are update changes
65
			super.perform(new SubProgressMonitor(pm, getChildren().length));
66
			return null;
67
		} finally {
68
			pm.done();
69
		}
70
	}
71
	
72
	public void freeze() {
73
		if(getChildren().length == 0) {
74
			markAsSynthetic();
75
			//- add a dummy child in order to keep the composite alive
76
			add(new NullChange(getName()));
77
		}
78
	}
79
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/reference/CompositeReferencerProxyNode.java (+125 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy.reference;
13
14
import java.util.Collection;
15
import java.util.HashMap;
16
import java.util.Iterator;
17
import java.util.Map;
18
import java.util.Set;
19
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.hyades.internal.execution.local.control.NotImplementedException;
22
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
23
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
24
import org.eclipse.swt.graphics.Image;
25
26
/**
27
 * Wrapper class around a (referencer or not) proxy node.
28
 * The proxy node part is same as the wrapped one.
29
 * The references of this proxy node is built by grouping all references found of the whole proxy node hierarchy.
30
 * 
31
 * @author jgout
32
 * @since 4.3
33
 */
34
public class CompositeReferencerProxyNode implements IReferencerProxyNode {
35
	private IProxyNode proxy;
36
	//- map that associate a type name to the collection of referenced elements for this type of reference
37
	//- (typeName, Set(Referenced))
38
	private Map types;
39
	
40
	public CompositeReferencerProxyNode(IProxyNode proxy) {
41
		super();
42
		this.proxy = proxy;
43
		types = new HashMap();
44
		getDeepReferences(proxy);
45
	}
46
47
	public Set getReferenceTypes() {
48
		return types.keySet();
49
	}
50
51
	public Collection getReferences(String refType) {
52
		return (Collection) types.get(refType);
53
	}
54
55
	private void getDeepReferences(IProxyNode p) {
56
		if (p instanceof IReferencerProxyNode) {
57
			//- first, add all its references
58
			IReferencerProxyNode referencer = (IReferencerProxyNode) p;
59
			for (Iterator it = referencer.getReferenceTypes().iterator(); it.hasNext();) {
60
				String type = (String) it.next();
61
				types.put(type, referencer.getReferences(type));
62
			}
63
		}
64
		//- next, add those contained by its children
65
		IProxyNode[] children = p.getChildren();
66
		for (int i = 0; i < children.length; i++) {
67
			getDeepReferences(children[i]);
68
		}
69
	}
70
71
	/**
72
	 * This method is not intended to be called in this extender.
73
	 * Throws a NotImplementedException.
74
	 */
75
	public void removeReference(IProxyNode reference) {
76
		throw new NotImplementedException();
77
	}
78
	
79
	public String getIdentifier() {
80
		return proxy.getIdentifier();
81
	}
82
83
	public IResource getUnderlyingResource() {
84
		return proxy.getUnderlyingResource();
85
	}
86
87
	public IProxyNode[] getChildren() {
88
		return proxy.getChildren();
89
	}
90
91
	public Image getImage() {
92
		return proxy.getImage();
93
	}
94
95
	public Object getParent() {
96
		return proxy.getParent();
97
	}
98
99
	public String getText() {
100
		return proxy.getText();
101
	}
102
103
	public Object getAdapter(Class adapter) {
104
		if(adapter == IProxyNode.class) {
105
			return proxy;
106
		}
107
		return proxy.getAdapter(adapter);
108
	}
109
110
	public boolean equals(Object obj) {
111
		if (obj instanceof CompositeReferencerProxyNode) {
112
			CompositeReferencerProxyNode c = (CompositeReferencerProxyNode) obj;
113
			return proxy.equals(c.proxy);
114
		}
115
		return false;
116
	}
117
118
	public int hashCode() {
119
		return proxy.hashCode();
120
	}
121
122
	public IProxyNode getProxy() {
123
		return proxy;
124
	}
125
}
(-)src/org/eclipse/hyades/test/ui/navigator/AbstractProxy.java (+40 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator;
13
14
import org.eclipse.core.resources.IResource;
15
16
/**
17
 * Partial implementation of the IProxy interface that manages the <code>equals</code> and <code>hashcode</code> methods.
18
 * 
19
 * @author jgout
20
 * @since 4.4
21
 */
22
public abstract class AbstractProxy implements IProxy {
23
24
	public boolean equals(Object arg0) {
25
		if(arg0 instanceof IProxy) {
26
			IResource resThis=this.getUnderlyingResource();
27
			IResource resArg = ((IProxy)arg0).getUnderlyingResource();
28
			String idThis = this.getIdentifier();
29
			String idArg = ((IProxy)arg0).getIdentifier();
30
			return ((resThis != null && resThis.equals(resArg)) || (resThis == null && resArg == null)) 
31
				&& ((idThis != null && idThis.equals(idArg)) || (idThis == null && idArg == null));
32
		}
33
		return false;
34
	}
35
36
	public int hashCode() {
37
		IResource resThis=this.getUnderlyingResource();
38
		return resThis != null ? resThis.hashCode() :  -1;
39
	}
40
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/DeleteAction.java (+71 lines)
Added Link Here
1
package org.eclipse.hyades.test.ui.internal.navigator.action;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
6
import org.eclipse.core.resources.IContainer;
7
import org.eclipse.hyades.test.ui.UiPlugin;
8
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.DeleteRefactoring;
9
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.DeleteRefactoringWizard;
10
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
11
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeDeleter;
12
import org.eclipse.hyades.ui.util.IDisposable;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
15
import org.eclipse.swt.widgets.Shell;
16
import org.eclipse.ui.actions.SelectionListenerAction;
17
18
public class DeleteAction extends SelectionListenerAction implements IDisposable {
19
	private Shell shell;
20
	private LinkedList containers;
21
	private LinkedList proxies;
22
	
23
	public DeleteAction(Shell shell) {
24
		super(ActionMessages.DELETE_ACTION_NAME); 
25
		this.shell = shell;
26
		containers = new LinkedList();
27
		proxies = new LinkedList();
28
	}
29
30
	public void run() {
31
		if (! canActivate(shell))
32
			return;
33
		DeleteRefactoring refactoring = new DeleteRefactoring(containers, proxies);
34
		DeleteRefactoringWizard wizard = new DeleteRefactoringWizard(refactoring);
35
		wizard.setDefaultPageTitle(ActionMessages.DELETE_ACTION_NAME);
36
		wizard.setNeedsProgressMonitor(true);
37
		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
38
		try {
39
			op.run(shell , ""); //$NON-NLS-1$
40
		} catch (InterruptedException e) {
41
			UiPlugin.logError(e);
42
		}
43
	}
44
45
	private boolean canActivate(Shell shell) {
46
		return EditorUtil.saveEditors(shell);
47
	}
48
49
	public void dispose() {
50
	}
51
52
	protected boolean updateSelection(IStructuredSelection selection) {
53
		boolean selOk = true;
54
		containers.clear();
55
		proxies.clear();
56
		for (Iterator it = selection.iterator(); it.hasNext() && selOk;) {
57
			Object o = it.next();
58
			if (o instanceof IContainer) {
59
				containers.add((IContainer) o);
60
			} else if (o instanceof IProxyNode) {
61
				IProxyNodeDeleter deleter = (IProxyNodeDeleter) ((IProxyNode) o).getAdapter(IProxyNodeDeleter.class);
62
				selOk &= deleter != null;
63
				proxies.add(deleter);
64
			} else {
65
				selOk = false;
66
			}
67
		}
68
		return selOk;
69
	}
70
	
71
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/ActionMessages.java (+25 lines)
Added Link Here
1
package org.eclipse.hyades.test.ui.internal.navigator.action;
2
3
import org.eclipse.osgi.util.NLS;
4
5
public class ActionMessages extends NLS {
6
	private static final String BUNDLE_NAME = "org.eclipse.hyades.test.ui.internal.navigator.action.messages"; //$NON-NLS-1$
7
8
	public static String MOVE_ACTION_NAME;
9
	public static String DELETE_ACTION_NAME;
10
	public static String RENAME_ACTION_NAME;
11
	public static String RENAME_NEW_NAME_LABEL;
12
	public static String PASTE_ACTION_NAME;
13
14
	public static String SAVE_ALL_DIALOG_MESSAGE;
15
16
	public static String SAVE_ALL_DIALOG_NAME;
17
	
18
	static {
19
		// initialize resource bundle
20
		NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
21
	}
22
23
	private ActionMessages() {
24
	}
25
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/DeleteTestInvocationChange.java (+101 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Collection;
15
import java.util.Iterator;
16
17
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.OperationCanceledException;
21
import org.eclipse.emf.common.util.URI;
22
import org.eclipse.emf.ecore.resource.Resource;
23
import org.eclipse.emf.ecore.util.EcoreUtil;
24
import org.eclipse.hyades.models.common.facades.behavioral.IBlock;
25
import org.eclipse.hyades.models.common.facades.behavioral.IDecision;
26
import org.eclipse.hyades.models.common.facades.behavioral.ILoop;
27
import org.eclipse.hyades.models.common.facades.behavioral.ITestInvocation;
28
import org.eclipse.hyades.models.common.testprofile.TPFTest;
29
import org.eclipse.hyades.models.common.testprofile.TPFTestSuite;
30
import org.eclipse.hyades.test.ui.navigator.DefaultTestSuiteProxyNode;
31
import org.eclipse.hyades.test.ui.navigator.EObjectProxyNode;
32
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
33
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
34
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
35
import org.eclipse.ltk.core.refactoring.Change;
36
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
37
import org.eclipse.osgi.util.NLS;
38
39
public class DeleteTestInvocationChange extends Change {
40
	private EMFRefactoringTransaction context;
41
	private IProxyNode invokee;
42
	private DefaultTestSuiteProxyNode test;
43
	
44
	public DeleteTestInvocationChange(IRefactoringContext context, DefaultTestSuiteProxyNode node, IReferencerProxyNode referenced) {
45
		this.context = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
46
		Assert.isNotNull(this.context);
47
		this.test = node;
48
		this.invokee = (IProxyNode) referenced.getAdapter(IProxyNode.class);
49
	}
50
51
	public Object getModifiedElement() {
52
		return test;
53
	}
54
55
	public String getName() {
56
		return NLS.bind(RefactoringMessages.DELETE_INVOCATION, invokee.getText(), test.getText());
57
	}
58
59
	public void initializeValidationData(IProgressMonitor pm) {
60
	}
61
62
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
63
		return new RefactoringStatus();
64
	}
65
66
	private void removeTestInvocation(IBlock block, URI invokeeURI) {
67
		if (block != null) {
68
			Collection actions = block.getActions();
69
			for (Iterator it = actions.iterator(); it.hasNext();) {
70
				Object action = it.next();
71
				if (action instanceof ILoop) {
72
					removeTestInvocation(((ILoop) action).getBlock(), invokeeURI);
73
				} else if (action instanceof IDecision) {
74
					IDecision ifAction = (IDecision) action;
75
					removeTestInvocation(ifAction.getFailureBlock(), invokeeURI);
76
					removeTestInvocation(ifAction.getSuccessBlock(), invokeeURI);
77
				} else if (action instanceof ITestInvocation) {
78
					ITestInvocation invocationAction = (ITestInvocation) action;
79
					TPFTest invokedTest = (TPFTest)invocationAction.getInvokedTest();
80
					if (EcoreUtil.getURI(invokedTest).equals(invokeeURI)) {
81
						it.remove();
82
					}
83
				}
84
			}
85
		}
86
	}
87
	
88
	public Change perform(IProgressMonitor pm) throws CoreException {
89
		if (invokee instanceof EObjectProxyNode) {
90
			URI invokeeURI = ((EObjectProxyNode)invokee).getOriginatorURI();
91
			//- load the test
92
			Resource res = context.getResourceSet().getResource(test.getOriginatorURI().trimFragment(), true);
93
			TPFTestSuite testObject = (TPFTestSuite) res.getEObject(test.getOriginatorURI().fragment());
94
			//- remove all invocations of invokee contained in test
95
			removeTestInvocation(testObject.getImplementor().getBlock(), invokeeURI);
96
			context.addResourceToSave(res);
97
		}
98
		return null;
99
	}
100
101
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/reference/ReferenceTypeRegistry.java (+147 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy.reference;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.IConfigurationElement;
18
import org.eclipse.core.runtime.IExtensionPoint;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.hyades.test.ui.UiPlugin;
21
22
/**
23
 * Registry to manage reference types (<code>ReferenceType</code>).
24
 * @author jgout
25
 * @since 4.3
26
 */
27
public class ReferenceTypeRegistry {
28
29
	private static ReferenceTypeRegistry instance;
30
	private Map types;
31
	
32
	static class ReferenceType {
33
34
		private String name;
35
		private boolean owns;
36
		private boolean isExplicit;
37
		private String oppositeId;
38
39
		public ReferenceType(String name, boolean owns, boolean isExplicit, String oppositeId) {
40
			this.name = name;
41
			this.owns = owns;
42
			this.isExplicit = isExplicit;
43
			this.oppositeId = oppositeId;
44
		}
45
46
		public boolean owns() {
47
			return owns;
48
		}
49
50
		public boolean isExplicit() {
51
			return isExplicit;
52
		}
53
54
		public String getOppositeId() {
55
			return oppositeId;
56
		}
57
58
		public String getName() {
59
			return name;
60
		}
61
	}
62
	
63
	private ReferenceTypeRegistry() {
64
		types = new HashMap();
65
		IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(UiPlugin.getID() + ".testNavigatorReferenceTypes"); //$NON-NLS-1$
66
		if (extPoint != null) {
67
			IConfigurationElement[] members = extPoint.getConfigurationElements();
68
			for (int i = 0; i < members.length; i++) {
69
				IConfigurationElement element = members[i];
70
				if ("type".equals(element.getName())) { //$NON-NLS-1$
71
					String id = element.getAttribute("id"); //$NON-NLS-1$
72
					String name = element.getAttribute("name"); //$NON-NLS-1$
73
					boolean owns = Boolean.valueOf(element.getAttribute("owns")).booleanValue(); //$NON-NLS-1$
74
					boolean isExplicit = Boolean.valueOf(element.getAttribute("isExplicit")).booleanValue(); //$NON-NLS-1$
75
					String oppositeId = element.getAttribute("oppositeReferenceTypeId"); //$NON-NLS-1$
76
					types.put(id, new ReferenceType(name, owns, isExplicit, oppositeId));
77
				}
78
			}
79
		}
80
	}
81
	
82
	public static ReferenceTypeRegistry getInstance() {
83
		if(instance == null) {
84
			instance = new ReferenceTypeRegistry();
85
		}
86
		return instance;
87
	}
88
	
89
	/**
90
	 * Tests whether the reference type (given through its id) owns.
91
	 * @param refTypeId the id of the reference type
92
	 * @return <code>true</code> if the reference type (given through its id) owns or <code>false</code> otherwise.
93
	 */
94
	public boolean owns(String refTypeId) {
95
		ReferenceType type = (ReferenceType)types.get(refTypeId);
96
		if(type != null) {
97
			return type.owns();
98
		}
99
		UiPlugin.logWarning("Unable to find reference type: "+refTypeId+" default setting is applied."); //$NON-NLS-1$  //$NON-NLS-2$
100
		return false;
101
	}
102
	
103
	/**
104
	 * Tests whether the reference type (given through its id) is explicit.
105
	 * @param refTypeId the id of the reference type
106
	 * @return <code>true</code> if the reference type (given through its id) is explicit or <code>false</code> otherwise.
107
	 */
108
	public boolean isExplicit(String refTypeId) {
109
		if (refTypeId != null) {
110
			ReferenceType type = (ReferenceType) types.get(refTypeId);
111
			if (type != null) {
112
				return type.isExplicit();
113
			}
114
			UiPlugin.logWarning("Unable to find reference type: " + refTypeId + " default setting is applied."); //$NON-NLS-1$ //$NON-NLS-2$
115
		}		
116
		return false;
117
	}
118
	
119
	/**
120
	 * Returns the human readable name of the given reference type. 
121
	 * @param refTypeId the id of the reference type.
122
	 * @return the human readable name of the given reference type. 
123
	 */
124
	public String getName(String refTypeId) {
125
		ReferenceType type = (ReferenceType)types.get(refTypeId);
126
		if(type != null) {
127
			return type.getName();
128
		}
129
		UiPlugin.logWarning("Unable to find reference type: "+refTypeId+" default setting is applied."); //$NON-NLS-1$ //$NON-NLS-2$
130
		return "Unknown reference"; //$NON-NLS-1$
131
	}
132
	
133
	/**
134
	 * Returns the opposite reference type id of a given one if it has been defined or <code>null</code> otherwise.
135
	 * @param refTypeId the reference type id 
136
	 * @return the opposite reference type id of a given one if it has been defined or <code>null</code> otherwise.
137
	 */
138
	public String getOppositeReferenceType(String refTypeId) {
139
		ReferenceType type = (ReferenceType)types.get(refTypeId);
140
		if(type != null) {
141
			return type.getOppositeId();
142
		}
143
		UiPlugin.logWarning("Unable to find reference type: "+refTypeId+" default setting is applied."); //$NON-NLS-1$ //$NON-NLS-2$
144
		return "Unknown reference"; //$NON-NLS-1$
145
	}
146
	
147
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/RefactoringMessages.java (+65 lines)
Added Link Here
1
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
2
3
import org.eclipse.osgi.util.NLS;
4
5
public class RefactoringMessages extends NLS {
6
	private static final String BUNDLE_NAME = "org.eclipse.hyades.test.ui.internal.navigator.refactoring.messages"; //$NON-NLS-1$
7
8
	public static String DELETE_FOLDER;
9
	public static String DELETE_PROXY;
10
	public static String DELETE_INVOCATION;
11
	public static String DELETE_CONFIRM_1;
12
	public static String DELETE_CONFIRM_N;
13
	public static String DELETE_DEEP_REMOVE;
14
15
	public static String NO_FOLDER;
16
	public static String NO_PROJECT;
17
18
	public static String ProxyNodeScanner_PM_LABEL;
19
	public static String READ_ONLY_FOLDER;
20
	public static String READ_ONLY_PROJECT;
21
	public static String ALREADY_EXISTS_FOLDER;
22
	public static String ALREADY_EXISTS_PROJECT;
23
	public static String MOVE_FOLDER;
24
	public static String MOVE_CHOOSE_DESTINATION_SINGLE;
25
	public static String MOVE_CHOOSE_DESTINATION_MULTI;
26
	public static String MOVE_ERROR;
27
	public static String MOVE_FILE;
28
	public static String MOVE_PROXY;
29
	
30
	public static String PASTE_FILE;
31
	public static String PASTE_FOLDER;
32
	public static String PASTE_PROXY;
33
	public static String PASTE_CHOOSE_DESTINATION_SINGLE;
34
	public static String PASTE_CHOOSE_DESTINATION_MULTI;
35
	public static String PASTE_ERROR;
36
37
	public static String ReorgRefactoring_CANCELED_OPERATION_MSG;
38
	public static String UPDATE_PROXY;
39
	public static String CHANGES_FOR_UPDATING;
40
	public static String UPDATE_PROXY_PATH_CHANGED;
41
	public static String UPDATE_REFERENCES;
42
	public static String UPDATE_OWNED_RESSOURCES_REFERENCES;
43
	public static String NO_FILE;
44
	public static String ALREADY_EXISTS_FILE;
45
	public static String READ_ONLY_FILE;
46
	public static String ALREADY_EXISTS_PROXY_DURING_MOVE;
47
	public static String ALREADY_EXISTS_PROXY_DURING_RENAME;
48
	public static String ALREADY_EXISTS_PROXY_DURING_PASTE;
49
	public static String RENAME_FILE;
50
	public static String RENAME_PROXY;
51
	public static String RENAME_CONTAINER;
52
	public static String INNER_FOLDER_MOVE_ERROR;
53
	public static String INNER_FOLDER_PASTE_ERROR;
54
	
55
	public static String LaunchConfigurationUpdateChange_NAME;
56
	public static String LaunchConfigurationDeleteChange_NAME;
57
	
58
	static {
59
		// initialize resource bundle
60
		NLS.initializeMessages(BUNDLE_NAME, RefactoringMessages.class);
61
	}
62
63
	private RefactoringMessages() {
64
	}
65
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/ReorgContainerChange.java (+95 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.ResourceAttributes;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.OperationCanceledException;
23
import org.eclipse.core.runtime.SubProgressMonitor;
24
import org.eclipse.ltk.core.refactoring.Change;
25
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
26
27
/**
28
 * Abstract class for handling the change for deletion or move of a container.
29
 * This change has no children. 
30
 * 
31
 * @author jgout
32
 * @since 4.3
33
 */
34
public abstract class ReorgContainerChange extends Change {
35
	private IPath path;
36
	
37
	public ReorgContainerChange(IContainer cont) {
38
		path = getPath(cont);
39
	}
40
	
41
	public static IPath getPath(IContainer container){
42
		return container.getFullPath().removeFirstSegments(ResourcesPlugin.getWorkspace().getRoot().getFullPath().segmentCount());
43
	}
44
	
45
	private IContainer getContainer(IPath path) {
46
		if(path.segmentCount() == 1) {
47
			//- this the path of a project
48
			return ResourcesPlugin.getWorkspace().getRoot().getProject(path.lastSegment());
49
		} else {
50
			//- this the path of a folder
51
			return ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
52
		}
53
	}
54
55
	public IPath getPath() {
56
		return path;
57
	}
58
	
59
	public Object getModifiedElement() {
60
		return getContainer(path);
61
	}
62
63
	public abstract String getName();
64
65
	public void initializeValidationData(IProgressMonitor pm) {
66
	}
67
68
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,	OperationCanceledException {
69
		RefactoringStatus status = new RefactoringStatus();
70
		IFolder folder = (IFolder)getModifiedElement();
71
		if (!folder.exists()) {
72
			status.addError(RefactoringMessages.NO_FOLDER);
73
		}
74
		ResourceAttributes resAtt = folder.getResourceAttributes();
75
		if (resAtt.isReadOnly()) {
76
			status.addWarning(RefactoringMessages.READ_ONLY_FOLDER);
77
		}
78
		return status;
79
	}
80
81
	public Change perform(IProgressMonitor pm) throws CoreException {
82
		IContainer container = getContainer(path);
83
		Assert.isTrue(container.isAccessible());
84
		pm.beginTask("", 1); //$NON-NLS-1$
85
		try {
86
			reorgFolder(container, new SubProgressMonitor(pm, 1));
87
			return null;
88
		} finally {
89
			pm.done();
90
		}
91
	}
92
93
	abstract public void reorgFolder(IContainer container, SubProgressMonitor monitor);
94
95
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/RenameContainerChange.java (+147 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProjectDescription;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.ResourceAttributes;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.OperationCanceledException;
25
import org.eclipse.core.runtime.Path;
26
import org.eclipse.core.runtime.SubProgressMonitor;
27
import org.eclipse.hyades.test.ui.UiPlugin;
28
import org.eclipse.ltk.core.refactoring.Change;
29
import org.eclipse.ltk.core.refactoring.CompositeChange;
30
import org.eclipse.ltk.core.refactoring.NullChange;
31
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
32
import org.eclipse.osgi.util.NLS;
33
34
public class RenameContainerChange extends CompositeChange {
35
	private IContainer container;
36
	private boolean isFolder;
37
	private String newName;
38
39
	public RenameContainerChange(IContainer container, String newName) {
40
		super(""); //$NON-NLS-1$
41
		this.container = container;
42
		this.newName = newName;
43
		this.isFolder = container.getFullPath().segmentCount() > 1;
44
	}
45
	
46
	public Object getModifiedElement() {
47
		return container;
48
	}
49
50
	public String getName() {
51
		return NLS.bind(RefactoringMessages.RENAME_CONTAINER, container.getName(), newName);
52
	}
53
54
	public void initializeValidationData(IProgressMonitor pm) {
55
	}
56
57
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
58
		RefactoringStatus status = new RefactoringStatus();
59
		IContainer newContainer = getNewContainer();
60
		if (!container.isAccessible()) {
61
			if(isFolder) {
62
				status.addError(RefactoringMessages.NO_FOLDER);
63
			} else {
64
				status.addError(RefactoringMessages.NO_PROJECT);
65
			}
66
		}
67
		ResourceAttributes att = container.getResourceAttributes();
68
		if(att != null && att.isReadOnly()) {
69
			if(isFolder) {
70
				status.addError(RefactoringMessages.READ_ONLY_FOLDER);
71
			} else {
72
				status.addError(RefactoringMessages.READ_ONLY_PROJECT);
73
			}
74
		}
75
		if(newContainer.exists()) {
76
			if(isFolder) {
77
				status.addError(NLS.bind(RefactoringMessages.ALREADY_EXISTS_FOLDER, newContainer.getName()));
78
			} else {
79
				status.addError(NLS.bind(RefactoringMessages.ALREADY_EXISTS_PROJECT, newContainer.getName()));
80
			}
81
		}
82
83
		return status;
84
	}
85
86
	private IContainer getNewContainer() {
87
		if(isFolder) {
88
			return container.getParent().getFolder(new Path(newName));
89
		} else {
90
			return ResourcesPlugin.getWorkspace().getRoot().getProject(newName);
91
		}
92
	}
93
94
	public Change perform(IProgressMonitor pm) throws CoreException {
95
		if(isFolder) {
96
			return performFolder(pm);
97
		} else {
98
			return performProject(pm);
99
		}
100
	}
101
102
	private Change performProject(IProgressMonitor pm) {
103
		pm.beginTask("", 2); //$NON-NLS-1$
104
		try {
105
			IProject project = (IProject) container;
106
			try {
107
				//- first process all children
108
				super.perform(new SubProgressMonitor(pm, 1));
109
				IProjectDescription description = project.getDescription();
110
				IPath newPath = container.getFullPath().removeLastSegments(1).append(newName);
111
				description.setName(newPath.segment(0));
112
		        project.move(description, IResource.FORCE | IResource.SHALLOW, new SubProgressMonitor(pm, 1));
113
			} catch (CoreException e) {
114
				UiPlugin.logError(e);
115
			}
116
			return null;
117
		} finally {
118
			pm.done();
119
		}		
120
	}
121
	
122
	private Change performFolder(IProgressMonitor pm) {
123
		pm.beginTask("", 2); //$NON-NLS-1$
124
		try {
125
			IFolder folder = (IFolder) container;
126
			try {
127
				//- first process all children
128
				super.perform(new SubProgressMonitor(pm, 1));
129
				IPath newPath = folder.getFullPath().removeLastSegments(1).append(newName);
130
				folder.move(newPath, IResource.KEEP_HISTORY, new SubProgressMonitor(pm, 1));
131
			} catch (CoreException e) {
132
				UiPlugin.logError(e);
133
			}
134
			return null;
135
		} finally {
136
			pm.done();
137
		}		
138
	}
139
	
140
	public void freeze() {
141
		if(getChildren().length == 0) {
142
			markAsSynthetic();
143
			//- add a dummy child in order to keep the composite alive
144
			add(new NullChange(getName()));
145
		}
146
	}
147
}
(-)src/org/eclipse/hyades/test/ui/internal/dialog/ListDialog.java (+94 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.dialog;
13
14
import org.eclipse.jface.dialogs.IDialogConstants;
15
import org.eclipse.jface.viewers.ILabelProvider;
16
import org.eclipse.jface.viewers.IStructuredContentProvider;
17
import org.eclipse.jface.viewers.TableViewer;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.widgets.Composite;
21
import org.eclipse.swt.widgets.Control;
22
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Table;
24
import org.eclipse.ui.dialogs.SelectionDialog;
25
26
public class ListDialog extends SelectionDialog {
27
28
	private IStructuredContentProvider fContentProvider;
29
	private ILabelProvider fLabelProvider;
30
	private Object fInput;
31
	private TableViewer fTableViewer;
32
	private boolean fAddCancelButton;
33
	
34
	public ListDialog(Shell parent) {
35
		super(parent);
36
		fAddCancelButton= false;
37
	}
38
39
	public void setInput(Object input) {
40
		fInput= input;
41
	}
42
	
43
	public void setContentProvider(IStructuredContentProvider sp){
44
		fContentProvider= sp;
45
	}
46
	
47
	public void setLabelProvider(ILabelProvider lp){
48
		fLabelProvider= lp;
49
	}
50
51
	public void setAddCancelButton(boolean addCancelButton) {
52
		fAddCancelButton= addCancelButton;
53
	}
54
	
55
	public TableViewer getTableViewer(){
56
		return fTableViewer;
57
	}
58
			
59
	public boolean hasFilters(){
60
		return fTableViewer.getFilters() != null && fTableViewer.getFilters().length != 0;
61
	}
62
	
63
	public void create() {
64
		setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE);
65
		super.create();
66
	}
67
	
68
	protected void createButtonsForButtonBar(Composite parent) {
69
		if (! fAddCancelButton)
70
			createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
71
		else
72
			super.createButtonsForButtonBar(parent);	
73
	}	
74
	
75
	protected Control createDialogArea(Composite container) {
76
		Composite parent= (Composite) super.createDialogArea(container);
77
		createMessageArea(parent);
78
		fTableViewer= new TableViewer(parent, getTableStyle());
79
		fTableViewer.setContentProvider(fContentProvider);
80
		Table table= fTableViewer.getTable();
81
		fTableViewer.setLabelProvider(fLabelProvider);
82
		fTableViewer.setInput(fInput);
83
		GridData gd= new GridData(GridData.FILL_BOTH);
84
		gd.heightHint= convertHeightInCharsToPixels(15);
85
		gd.widthHint= convertWidthInCharsToPixels(55);
86
		table.setLayoutData(gd);
87
		applyDialogFont(parent);		
88
		return parent;
89
	}
90
	
91
	protected int getTableStyle() {
92
		return SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER;
93
	}
94
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/DeleteRefactoring.java (+305 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Collection;
15
import java.util.HashSet;
16
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.core.resources.IContainer;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.OperationCanceledException;
27
import org.eclipse.core.runtime.SubProgressMonitor;
28
import org.eclipse.hyades.test.core.internal.changes.DeleteFileChange;
29
import org.eclipse.hyades.test.ui.UiPlugin;
30
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
31
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.CompositeReferencerProxyNode;
32
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceTypeRegistry;
33
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
34
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
35
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeDeleter;
36
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeUpdater;
37
import org.eclipse.ltk.core.refactoring.Change;
38
import org.eclipse.ltk.core.refactoring.CompositeChange;
39
import org.eclipse.ltk.core.refactoring.Refactoring;
40
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
41
import org.eclipse.osgi.util.NLS;
42
43
public class DeleteRefactoring extends Refactoring {
44
	private List containers; 
45
	private List proxies; 
46
	private List seenElements;
47
	private Change change;
48
	private RefactoringContext context;
49
	private boolean deepRemove;
50
	private Collection nodesToUpdateLater;
51
52
	private class NodeToUpdateLater {
53
		private CompositeChange composite;
54
		private String refType;
55
		private CompositeReferencerProxyNode node;
56
		
57
		public NodeToUpdateLater(CompositeChange composite, String refType, CompositeReferencerProxyNode node) {
58
			this.composite = composite;
59
			this.refType = refType;
60
			this.node = node;
61
		}
62
63
		public CompositeChange getComposite() {
64
			return composite;
65
		}
66
67
		public CompositeReferencerProxyNode getNode() {
68
			return node;
69
		}
70
71
		public String getRefType() {
72
			return refType;
73
		}
74
	}
75
	
76
	public List getContainers() {
77
		return containers;
78
	}
79
80
	public List getProxies() {
81
		return proxies;
82
	}
83
84
	public DeleteRefactoring(List containers, List proxies) {
85
		this.containers = containers;
86
		this.proxies = proxies;
87
		this.seenElements = new LinkedList();
88
		this.context = new RefactoringContext();
89
		this.deepRemove = false;
90
		this.nodesToUpdateLater = new HashSet();
91
	}
92
93
	private List getReferencers() {
94
		List proxyReferencers = new LinkedList();
95
		for (Iterator it = proxies.iterator(); it.hasNext();) {
96
			proxyReferencers.add(new CompositeReferencerProxyNode((IProxyNode) it.next()));
97
		}
98
		return proxyReferencers;
99
	}
100
	
101
	public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
102
		pm.beginTask("", 3); //$NON-NLS-1$
103
		try {
104
			ProxyNodeScanner scanner = new ProxyNodeScanner(ResourcesPlugin.getWorkspace().getRoot());
105
			try {
106
				scanner.scan(new SubProgressMonitor(pm, 1));
107
			} catch (OperationCanceledException e) {
108
				return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.ReorgRefactoring_CANCELED_OPERATION_MSG);
109
			}			
110
			change = createChange(new SubProgressMonitor(pm, 1));
111
			RefactoringStatus valid = change.isValid(new SubProgressMonitor(pm, 1));
112
			if(!valid.isOK()) {
113
				change = null;
114
			}
115
			return valid;
116
		} finally {
117
			pm.done();
118
		}
119
	}
120
121
	public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
122
		pm.beginTask("", 1); //$NON-NLS-1$
123
		try {
124
			return new RefactoringStatus();
125
		} finally {
126
			pm.done();
127
		}
128
	}
129
130
	public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
131
		if (change != null) {
132
			return change;
133
		}
134
		pm.beginTask("", containers.size()+proxies.size()+1); //$NON-NLS-1$
135
		try {
136
			RefactoringTransactionRootChange c = new RefactoringTransactionRootChange(context);
137
			for (Iterator it = containers.iterator(); it.hasNext();) {
138
				Change containerChange = createDeleteContainerChange((IContainer) it.next());
139
				if (containerChange != null) {
140
					c.add(containerChange);
141
				}
142
				pm.worked(1);
143
			}
144
			for (Iterator it = getReferencers().iterator(); it.hasNext();) {
145
				CompositeReferencerProxyNode ref = (CompositeReferencerProxyNode) it.next();
146
				if (!seenElements.contains(ref)) {
147
					Change refChange = createDeleteReferencerChange(ref);
148
					if (refChange != null) {
149
						c.add(refChange);
150
					}
151
				}		
152
				pm.worked(1);
153
			}
154
			processNodesToUpdateLater();
155
			c.markAsSynthetic();
156
			return c;
157
		} finally {
158
			pm.done();
159
		}
160
	}
161
	
162
	/**
163
	 * Adds the given change as the first children of the given composite change.
164
	 * @param composite
165
	 * @param c
166
	 */
167
	private static void insertFirst(CompositeChange composite, Change c) {
168
		composite.add(c);
169
		Change[] children = composite.getChildren();
170
		for (int i = 0; i < children.length-1; i++) {
171
			composite.remove(children[i]);
172
			composite.add(children[i]);
173
		}
174
	}
175
	
176
	/**
177
	 * Completes delete proxy composite change by adding update changes only 
178
	 * for cases where the element to update still exists
179
	 */
180
	private void processNodesToUpdateLater() {
181
		for (Iterator it = nodesToUpdateLater.iterator(); it.hasNext();) {
182
			NodeToUpdateLater element = (NodeToUpdateLater) it.next();
183
			Change updateTypeChange = createUpdateReferenceTypeChange(element.getRefType(), element.getNode());
184
			if (updateTypeChange != null) {
185
				insertFirst(element.getComposite(), updateTypeChange);
186
			}			
187
		}
188
	}
189
190
	private Change createDeleteReferencerChange(CompositeReferencerProxyNode node) {
191
		IProxyNodeDeleter deleter = (IProxyNodeDeleter) node.getAdapter(IProxyNodeDeleter.class);
192
		if(deleter != null) {
193
			CompositeChange composite = new CompositeChange(NLS.bind(RefactoringMessages.DELETE_PROXY, node.getText()));
194
			seenElements.add(node);
195
			//- we need to add as children all referenced elements from ref type with owns flag set to true.
196
			for (Iterator it = node.getReferenceTypes().iterator(); it.hasNext();) {
197
				String refType = (String) it.next();
198
				String oppType = ReferenceTypeRegistry.getInstance().getOppositeReferenceType(refType);
199
				if (deepRemove && ReferenceTypeRegistry.getInstance().owns(refType)) {
200
					Change referenceTypeChange = createDeleteReferenceTypeChange(refType, node);
201
					if(referenceTypeChange != null) {
202
						composite.add(referenceTypeChange);
203
						continue;
204
					}
205
				}
206
				//- opposite explicit references need to be updated according to the deletion of node
207
				if (ReferenceTypeRegistry.getInstance().isExplicit(oppType)) {
208
					nodesToUpdateLater.add(new NodeToUpdateLater(composite, refType, node));
209
				}
210
			}
211
			composite.add(deleter.createDeleteChange(context));
212
			return composite;
213
		}
214
		return null;
215
	}
216
217
	private Change createUpdateReferenceTypeChange(String refType, CompositeReferencerProxyNode node) {
218
		CompositeChange composite = new CompositeChange(ReferenceTypeRegistry.getInstance().getName(refType));
219
		Collection references = node.getReferences(refType);
220
		for (Iterator it = references.iterator(); it.hasNext();) {
221
			IProxyNode proxy = (IProxyNode) it.next();
222
			if (!seenElements.contains(new CompositeReferencerProxyNode(proxy))) {
223
				IProxyNodeUpdater updater = (IProxyNodeUpdater) proxy.getAdapter(IProxyNodeUpdater.class);
224
				if (updater != null) {
225
					composite.add(updater.createUpdateChange(context, node, refType, null));
226
				}
227
			}						
228
		}		
229
		return composite.getChildren().length > 0 ? composite : null;
230
	}
231
	
232
	private Change createDeleteReferenceTypeChange(String refType, CompositeReferencerProxyNode node) {
233
		CompositeChange composite = new CompositeChange(ReferenceTypeRegistry.getInstance().getName(refType));
234
		Collection references = node.getReferences(refType);
235
		for (Iterator it = references.iterator(); it.hasNext();) {
236
			IProxyNode proxy = (IProxyNode) it.next();
237
			if (proxy.getAdapter(IFile.class) != null) {
238
				//- if the referenced proxy is a referencer itself we need to get its references as well.
239
				if (proxy instanceof IReferencerProxyNode) {
240
					CompositeReferencerProxyNode referenced = new CompositeReferencerProxyNode((IReferencerProxyNode) proxy);
241
					//- we need to check that the referenced element was not previously processed.
242
					//- this check is needed because of bidirectional/circular references.
243
					if (!seenElements.contains(referenced)) {
244
						Change refChange = createDeleteReferencerChange(referenced);
245
						if (refChange != null) {
246
							composite.add(refChange);
247
						}						
248
					}
249
				} else {
250
					// - the referenced element is not a referencer
251
					if (!seenElements.contains(proxy)) {
252
						composite.add(new DeleteFileChange((IFile) proxy.getUnderlyingResource()));
253
					}
254
				}
255
			}			
256
		}		
257
		return composite.getChildren().length > 0 ? composite : null;
258
	}
259
260
	private Change createDeleteContainerChange(IContainer container) {
261
		DeleteContainerCompositeChange contChange = new DeleteContainerCompositeChange(container);
262
		if(container.isAccessible()) {
263
			IResource[] resources;
264
			try {
265
				resources = container.members();
266
			} catch (CoreException e) {
267
				UiPlugin.logWarning("Unable to get members of container: "+container.getFullPath().toOSString(), e); //$NON-NLS-1$
268
				return null;
269
			}
270
			for (int i = 0; i < resources.length; i++) {
271
				if (resources[i] instanceof IFile) {
272
					IFile file = (IFile)resources[i];
273
					IProxyNode proxy = FileProxyNodeCache.getInstance().getProxy(file);
274
					if (proxy != null) {
275
						Change refChange = createDeleteReferencerChange(new CompositeReferencerProxyNode(proxy));
276
						if (refChange != null) {
277
							contChange.add(refChange);
278
							if(proxies.contains(proxy)) {
279
								//- this means that the current proxy (found inside the folder) 
280
								//- was in the original selection as well. We need to remove it to not duplicate change.
281
								proxies.remove(proxy);
282
							}
283
						}		
284
					} else {
285
						//- plain file that are not displayed by the navigator,
286
						//- those files should be shown in the refactoring since they are potentially deleted
287
						contChange.add(new DeleteFileChange(file));
288
					}
289
				} else {
290
					contChange.add(createDeleteContainerChange((IContainer)resources[i]));
291
				}
292
			}
293
		}
294
		return contChange.getChildren().length > 0 ? contChange : contChange.getDeleteContainerChange();
295
	}
296
297
	public String getName() {
298
		return "";  //$NON-NLS-1$
299
	}
300
301
	public void setDeepRemove(boolean deepRemove) {
302
		this.deepRemove = deepRemove;
303
	}
304
305
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/DefaultProxyNodeDeleter.java (+41 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.hyades.test.core.internal.changes.DeleteFileChange;
17
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
18
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeDeleter;
19
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
20
import org.eclipse.ltk.core.refactoring.Change;
21
22
/**
23
 * This class stands as the default deleter for proxy node.
24
 * This class shoudl only be used on proxy nodes that are adaptable in IFile.
25
 * This class is not intented to be used/subclassed by clients.
26
 * 
27
 * @author jgout
28
 * @since 4.4
29
 */
30
public class DefaultProxyNodeDeleter implements IProxyNodeDeleter {
31
	private IFile proxyFile;
32
	
33
	public DefaultProxyNodeDeleter(IProxyNode proxy) {
34
		this.proxyFile = (IFile) proxy.getAdapter(IFile.class);
35
		Assert.isNotNull(proxyFile);
36
	}
37
38
	public Change createDeleteChange(IRefactoringContext context) {
39
		return new DeleteFileChange(proxyFile);
40
	}
41
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/ResourceSetRefactoring.java (+61 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.Map;
17
import java.util.Set;
18
19
import org.eclipse.emf.common.util.URI;
20
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.emf.ecore.resource.ResourceSet;
22
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
23
24
/**
25
 * @deprecated
26
 */
27
class ResourceSetRefactoring implements IResourceSetRefactoringContext {
28
	private Set resources;
29
	private Map newURIs;
30
	private ResourceSet resourceSet;
31
	
32
	public ResourceSetRefactoring() {
33
		this.resources = new HashSet();
34
		this.newURIs = new HashMap();
35
		this.resourceSet = new ResourceSetImpl();
36
	}
37
38
	public void addChangedURI(Resource res, URI newURI) {
39
		newURIs.put(res, newURI);
40
	}
41
42
	public void addResourceToSave(Resource res) {
43
		resources.add(res);
44
	}
45
46
	public URI getNewURI(Resource res) {
47
		return (URI)newURIs.get(res);
48
	}
49
50
	public ResourceSet getResourceSet() {
51
		return resourceSet;
52
	}
53
54
	public Set getResourcesToSave() {
55
		return resources;
56
	}
57
58
	public Set getResourcesToMove() {
59
		return newURIs.keySet();
60
	}
61
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/ProxyNodeScanner.java (+98 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IMarker;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.core.runtime.SubProgressMonitor;
23
import org.eclipse.hyades.test.ui.TestUIConstants;
24
import org.eclipse.hyades.test.ui.UiPlugin;
25
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigator;
26
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyMarkerPersister;
27
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
28
import org.eclipse.hyades.test.ui.internal.navigator.proxy.TypedElementFactoryManager;
29
import org.eclipse.hyades.test.ui.navigator.IFileProxyFactory;
30
import org.eclipse.hyades.test.ui.navigator.ITypedElementProxyFactory;
31
32
public class ProxyNodeScanner {
33
34
	private IContainer root;
35
	
36
	public ProxyNodeScanner(IContainer root) {
37
		this.root = root;
38
	}
39
40
	public void scan(IProgressMonitor pm) {
41
		scanContainer(root, pm);
42
	}
43
	
44
	private void scanContainer(IContainer container, IProgressMonitor pm) {
45
		Assert.isNotNull(container);
46
		try {
47
			if (container.isAccessible()) {
48
				IResource [] resources;
49
				try {
50
					resources = container.members();
51
				} catch (Exception e) {
52
					UiPlugin.logError("Unable to retrieve content of " + container.getName(), e); //$NON-NLS-1$
53
					return;
54
				}
55
				pm.beginTask(RefactoringMessages.ProxyNodeScanner_PM_LABEL, resources.length);
56
				for (int i = 0; i < resources.length; i++) {
57
					if (pm.isCanceled()) {
58
						throw new OperationCanceledException();
59
					}
60
					IResource res = resources[i];
61
					if (res instanceof IFile) {
62
						processFile((IFile) res);
63
						pm.worked(1);
64
					} else if (res instanceof IContainer) {
65
						scanContainer((IContainer) res, new SubProgressMonitor(pm, 1));
66
					}
67
				}
68
			}
69
		} finally{
70
			pm.done();
71
		}		
72
	}
73
74
	private void processFile(IFile file) {
75
		if(file.exists()) {
76
			IMarker[] markers;
77
			try {
78
				markers = file.findMarkers(FileProxyMarkerPersister.MARKER_PROXYSTATE, false, IResource.DEPTH_ZERO);
79
				if(markers.length == 0) {
80
					//- no proxy has ever been persisted for this file, load it in cache
81
					FileProxyNodeCache.getInstance().getProxy(file);
82
				} else {
83
					String factoryID = markers[0].getAttribute(TestUIConstants.TAG_FACTORY_ID, null);
84
					IFileProxyFactory fileFactory = TestNavigator.getFileFactoryManager().getFactory(factoryID);
85
					ITypedElementProxyFactory typedElementFactory = TypedElementFactoryManager.getInstance().getFactoryFromID(factoryID);
86
					if(fileFactory == null && typedElementFactory == null) {
87
						//- this is an old version of persisted proxy node or the tool that produced it is no longer installed
88
						//- we need to load it in cache
89
						FileProxyNodeCache.getInstance().getProxy(file);
90
					}
91
				}
92
			} catch (CoreException e) {
93
				//- this should never appear, since the file exists.
94
			}
95
        }
96
	}
97
98
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/RefactoringContext.java (+130 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.Map;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IConfigurationElement;
20
import org.eclipse.core.runtime.IExtensionPoint;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.SubProgressMonitor;
24
import org.eclipse.hyades.test.ui.UiPlugin;
25
import org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction;
26
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
27
import org.eclipse.ltk.core.refactoring.Change;
28
import org.eclipse.ltk.core.refactoring.CompositeChange;
29
30
public class RefactoringContext implements IRefactoringTransaction,	IRefactoringContext {
31
	//- internal storage (domainId, IConfigurationElement)
32
	private static Map knownTransactions;
33
	//- loaded transaction for this instance (domainId, IRefactoringTransaction)
34
	private Map transactions;
35
	
36
	static {
37
		knownTransactions = new HashMap();
38
	}
39
	
40
	public RefactoringContext() {
41
		transactions = new HashMap();
42
	}
43
44
	public void beginChanges(IProgressMonitor pm) {
45
		pm.beginTask("", transactions.values().size()); //$NON-NLS-1$
46
		try {
47
			for (Iterator it = transactions.values().iterator(); it.hasNext();) {
48
				IRefactoringTransaction transaction = (IRefactoringTransaction) it.next();
49
				transaction.beginChanges(new SubProgressMonitor(pm, 1));
50
			}
51
		} finally {
52
			pm.done();
53
		}		
54
	}
55
56
	public void cancelChanges(IProgressMonitor pm) {
57
		pm.beginTask("", transactions.values().size()); //$NON-NLS-1$
58
		try {
59
			for (Iterator it = transactions.values().iterator(); it.hasNext();) {
60
				IRefactoringTransaction transaction = (IRefactoringTransaction) it.next();
61
				transaction.cancelChanges(new SubProgressMonitor(pm, 1));
62
			}
63
		} finally {
64
			pm.done();
65
		}		
66
	}
67
68
	public Change commitChanges(IProgressMonitor pm) throws CoreException {
69
		CompositeChange c = new CompositeChange(""); //$NON-NLS-1$
70
		pm.beginTask("", transactions.values().size()); //$NON-NLS-1$
71
		try {
72
			for (Iterator it = transactions.values().iterator(); it.hasNext();) {
73
				IRefactoringTransaction transaction = (IRefactoringTransaction) it.next();
74
				c.add(transaction.commitChanges(new SubProgressMonitor(pm, 1)));
75
			}
76
			return c;
77
		} finally {
78
			pm.done();
79
		}		
80
	}
81
82
	public IRefactoringTransaction getRefactoringTransaction(String domainId) {
83
		IRefactoringTransaction t = (IRefactoringTransaction) transactions.get(domainId);
84
		if (t != null) {
85
			return t;
86
		} else {
87
			//- need to load from internal storage
88
			try {
89
				t = internalGetRefactoringTransaction(domainId);
90
				if (t != null) {
91
					//- save this transaction in this instance.
92
					transactions.put(domainId, t);
93
					return t;
94
				}
95
			} catch (CoreException e) {
96
				UiPlugin.logError(e);
97
			}
98
			return null;
99
		}
100
	}
101
102
	private static IRefactoringTransaction internalGetRefactoringTransaction(String domainId) throws CoreException {
103
		IConfigurationElement e = (IConfigurationElement)knownTransactions.get(domainId);
104
		if(e == null) {
105
			//- need to load from extension points.
106
			IExtensionPoint extPoint = Platform.getExtensionRegistry().getExtensionPoint(UiPlugin.getID() + ".testNavigatorRefactoringTransactions"); //$NON-NLS-1$
107
			if (extPoint != null) {
108
				IConfigurationElement[] members = extPoint.getConfigurationElements();
109
				for (int i = 0; i < members.length; i++) {
110
					IConfigurationElement element = members[i];
111
					if ("transaction".equals(element.getName())) { //$NON-NLS-1$
112
						String id = element.getAttribute("domainId"); //$NON-NLS-1$
113
						if(id != null) {
114
							knownTransactions.put(id, element);
115
						}
116
					}
117
				}
118
				//- once extensions have been loaded try to retrieve the asked refactoring transaction
119
				e = (IConfigurationElement)knownTransactions.get(domainId);
120
				if(e == null) {
121
					//- this domainId is unknown
122
					UiPlugin.logError("Unable to find a registered refactoring transaction with the domain Id: '"+domainId+'\''); //$NON-NLS-1$
123
					return null;
124
				}
125
			}
126
		}
127
		return (IRefactoringTransaction) e.createExecutableExtension("class"); //$NON-NLS-1$
128
	}
129
130
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFileChange.java (+119 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IWorkspaceRoot;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.OperationCanceledException;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.hyades.test.core.internal.changes.DeleteFileChange;
24
import org.eclipse.hyades.test.core.util.EMFUtil;
25
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
26
import org.eclipse.ltk.core.refactoring.Change;
27
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
28
import org.eclipse.osgi.util.NLS;
29
30
/**
31
 * change to apply to perform a file paste
32
 * 
33
 * @author jbozier
34
 * @since 4.5
35
 */
36
//TODO : real similar to move, check if we can simplify this
37
public class PasteFileChange extends Change {
38
39
	private IFile file;	
40
	private IContainer destFolder;
41
	private String destName = null;
42
43
	public PasteFileChange(IFile file, IContainer destination) {
44
		super();
45
		this.file = file;
46
		this.destFolder = destination;
47
		this.destName = getNewName(destFolder.getFullPath().append(file.getName()));
48
	}
49
50
	public Object getModifiedElement() {
51
		return file;
52
	}
53
54
	public String getName() {
55
		return NLS.bind(RefactoringMessages.PASTE_FILE, file.getName(), destName);
56
	}
57
58
	public void initializeValidationData(IProgressMonitor pm) {
59
	}
60
61
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
62
		RefactoringStatus status = new RefactoringStatus();
63
//		IFile destFile = destFolder.getFile(new Path(file.getName()));
64
		if (!file.exists()) {
65
			status.addError(RefactoringMessages.NO_FILE);
66
		}
67
//		if(destFile.exists()) {
68
//			status.addWarning(NLS.bind(RefactoringMessages.ALREADY_EXISTS_FILE, destFile.getFullPath().toPortableString()));
69
//		}
70
		return status;
71
	}
72
73
	private String getNewName(IPath destination) {
74
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
75
		if ( (root.getFolder(destination).exists()) || (root.getFile(destination).exists())) {
76
			String newBaseName = null;
77
			boolean done = false;		
78
			String fullFileName = destination.lastSegment();
79
			int dotIndex = fullFileName.lastIndexOf('.');
80
			String basePart = fullFileName.substring(0, dotIndex);
81
			String endPart = fullFileName.substring(dotIndex);
82
			String newFullName = null;
83
			String ret = null;
84
			for (int i=0; (!done); i++) {
85
				if (i != 0) {
86
					newBaseName = NLS.bind(TestNavigatorMessages.FileFolderInContainerPaste_NameTwoArg,new Integer(i),basePart);
87
				} else {
88
					newBaseName = NLS.bind(TestNavigatorMessages.FileFolderInContainerPaste_NameOneArg,basePart);					 
89
				}
90
				newFullName = newBaseName+endPart;
91
				ret = destination.removeLastSegments(1).append(newFullName).toPortableString();
92
				IPath newpath = new Path(ret);
93
				done = (!root.getFolder(newpath).exists()) && (!root.getFile(newpath).exists());
94
			}
95
			return ret;
96
		} else {
97
			return destination.toPortableString();
98
		}
99
	}
100
		
101
	public Change perform(IProgressMonitor pm) throws CoreException {
102
		Change undo = null;
103
		pm.beginTask("", 1);  //$NON-NLS-1$
104
		try {
105
			IContainer parent = file.getParent();
106
			file.copy(new Path(destName), false, pm);
107
			if (parent != null) {
108
				IFile destFile = destFolder.getFile(new Path(destName));
109
				undo = new DeleteFileChange(destFile);
110
			}
111
			file.refreshLocal(0, pm);
112
			pm.worked(1);
113
			return undo;
114
		} finally {
115
			pm.done();
116
		}
117
	}
118
119
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/DeleteContainerChange.java (+38 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.SubProgressMonitor;
17
import org.eclipse.hyades.test.ui.UiPlugin;
18
import org.eclipse.osgi.util.NLS;
19
20
public class DeleteContainerChange extends ReorgContainerChange {
21
22
	public DeleteContainerChange(IContainer cont) {
23
		super(cont);
24
	}
25
26
	public void reorgFolder(IContainer container, SubProgressMonitor monitor) {
27
		try {
28
			container.delete(false, monitor);
29
		} catch (CoreException e) {
30
			UiPlugin.logError(e);
31
		}
32
	}
33
34
	public String getName() {
35
		return NLS.bind(RefactoringMessages.DELETE_FOLDER, getPath().toOSString());
36
	}
37
38
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/MoveFileChange.java (+77 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.OperationCanceledException;
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.ltk.core.refactoring.Change;
21
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
22
import org.eclipse.osgi.util.NLS;
23
24
public class MoveFileChange extends Change {
25
26
	private IFile file;
27
	private IContainer destFolder;
28
29
	public MoveFileChange(IFile file, IContainer destination) {
30
		super();
31
		this.file = file;
32
		this.destFolder = destination;
33
	}
34
35
	public Object getModifiedElement() {
36
		return file;
37
	}
38
39
	public String getName() {
40
		return NLS.bind(RefactoringMessages.MOVE_FILE, file.getName(), destFolder.getFullPath().toOSString());
41
	}
42
43
	public void initializeValidationData(IProgressMonitor pm) {
44
	}
45
46
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
47
		RefactoringStatus status = new RefactoringStatus();
48
		IFile destFile = destFolder.getFile(new Path(file.getName()));
49
		if (!file.exists()) {
50
			status.addError(RefactoringMessages.NO_FILE);
51
		}
52
		if(destFile.exists()) {
53
			status.addWarning(NLS.bind(RefactoringMessages.ALREADY_EXISTS_FILE, destFile.getFullPath().toPortableString()));
54
		}
55
		if (file.isReadOnly()) {
56
			status.addWarning(RefactoringMessages.READ_ONLY_FILE);
57
		}
58
		return status;
59
	}
60
61
	public Change perform(IProgressMonitor pm) throws CoreException {
62
		Change undo = null;
63
		pm.beginTask("", 1);  //$NON-NLS-1$
64
		try {
65
			IContainer parent = file.getParent();
66
			if (parent != null) {
67
				undo = new MoveFileChange(file, parent);
68
			}
69
			file.move(destFolder.getFullPath().append(file.getName()), false, true, pm);
70
			pm.worked(1);
71
			return undo;
72
		} finally {
73
			pm.done();
74
		}
75
	}
76
77
}
(-)src/org/eclipse/hyades/test/ui/navigator/actions/IProxyNodeUpdater.java (+56 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator.actions;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.runtime.IPath;
16
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
17
import org.eclipse.ltk.core.refactoring.Change;
18
19
/**
20
 * Interface that allows to describe the update behavior of a proxy node.
21
 * 
22
 * @author jgout
23
 * @since 4.4
24
 */
25
public interface IProxyNodeUpdater {
26
27
	/**
28
	 * Returns the refactoring change when an instance need to be updated according the move/delete of a referencer proxy node.
29
	 * The given context can be used if the local change cannot be perform without a global context.
30
	 * This can be performed using an IRefactoringTransaction (retrieved by its domain Id) to collect 
31
	 * data. Such refactoring transaction will performed changes in one time.
32
	 * The destination path can be <code>null</code>, this means that this instance need to be updated according to the deletion of the given <code>referencer</code>.
33
	 * For instance a test can update its state when one of its invoked test is deleted.
34
	 *  
35
	 * @param context a context that contains all IRefactoringTransaction instances defined by clients.
36
	 * @param referencer the proxy node that has changed and implies the update of this instance. (<code>referencer.getReferences(refType).contains(this) == true</code>)
37
	 * @param refType the type of the reference between this instance and <code>referencer</code>. 
38
	 * @param newPath the destination path of this proxy node. This parameter is <code>null</code> when the reason of the update is a delete.
39
	 * @return the change that performs the update of instance following a move of a reference to itself.
40
	 */
41
	public Change createUpdateChange(IRefactoringContext context, IReferencerProxyNode referencer, String refType, IPath destinationPath);
42
	
43
	/**
44
	 * Returns the refactoring change when an instance need to be updated according the change of its container.
45
	 * The given context can be used if the local change cannot be perform without a global context.
46
	 * This can be performed using an IRefactoringTransaction (retrieved by its domain Id) to collect 
47
	 * data. Such refactoring transaction will performed changes in one time.
48
	 * 
49
	 * @param context a context that contains all IRefactoringTransaction instances defined by clients.
50
	 * @param container the container that has changed and that implies the update of this instance.
51
	 * @param destinationPath the new path of the instance.
52
	 * @return the change that performs the update of instance following a rename of the given container to the given path.
53
	 */
54
	public Change createUpdateChange(IRefactoringContext context, IContainer container, IPath destinationPath);
55
56
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/MoveAction.java (+104 lines)
Added Link Here
1
package org.eclipse.hyades.test.ui.internal.navigator.action;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
6
import org.eclipse.core.resources.IFile;
7
import org.eclipse.core.resources.IFolder;
8
import org.eclipse.core.runtime.IAdaptable;
9
import org.eclipse.hyades.test.ui.UiPlugin;
10
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
11
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.MoveRefactoring;
12
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.MoveRefactoringWizard;
13
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
14
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeMover;
15
import org.eclipse.hyades.ui.util.IDisposable;
16
import org.eclipse.jface.viewers.IStructuredSelection;
17
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
18
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.ui.actions.SelectionListenerAction;
20
21
public class MoveAction extends SelectionListenerAction implements IDisposable {
22
	
23
	private Shell shell;
24
	private LinkedList folders;
25
	private LinkedList proxies;
26
	private boolean isResourceNav;
27
	
28
	public MoveAction(Shell shell) {
29
		super(ActionMessages.MOVE_ACTION_NAME); 
30
		this.shell = shell;
31
		folders = new LinkedList();
32
		proxies = new LinkedList();
33
		isResourceNav = false;
34
	}
35
36
	public void run() {
37
		if (! canActivate(shell))
38
			return;
39
		MoveRefactoring refactoring = new MoveRefactoring(folders, proxies);
40
		MoveRefactoringWizard wizard = new MoveRefactoringWizard(refactoring);
41
		wizard.setDefaultPageTitle(ActionMessages.MOVE_ACTION_NAME);
42
		wizard.setNeedsProgressMonitor(true);
43
		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
44
		try {
45
			op.run(shell , ""); //$NON-NLS-1$
46
		} catch (InterruptedException e) {
47
			UiPlugin.logError(e);
48
		}
49
	}
50
51
	private boolean canActivate(Shell shell) {
52
		return EditorUtil.saveEditors(shell);
53
	}
54
55
	/**
56
	 * Selected elements should be only instances of IFile or IContainer (project/folder)
57
	 */
58
	private void sortSelectedElements() {
59
		folders.clear();
60
		proxies.clear();
61
		IStructuredSelection sel = getStructuredSelection();
62
		for (Iterator it = sel.iterator(); it.hasNext();) {
63
			Object o = it.next();
64
			if (o instanceof IProxyNode) {
65
				proxies.add(o);
66
			} else if (o instanceof IFile) {
67
				IProxyNode proxy = FileProxyNodeCache.getInstance().getProxy((IFile)o);
68
				if (proxy != null) {
69
					proxies.add(proxy);
70
				}				
71
			} else if (o instanceof IAdaptable) {
72
				IAdaptable a = (IAdaptable) o;
73
				o = a.getAdapter(IFolder.class);
74
				if(o != null) {
75
					folders.add((IFolder) o);
76
				}
77
			}
78
		}
79
	}
80
81
	public void dispose() {
82
	}
83
84
	public void selectionChanged(IStructuredSelection structuredSelection, boolean isResourceTestNav) {
85
		this.isResourceNav = isResourceTestNav;
86
		super.selectionChanged(structuredSelection);
87
		sortSelectedElements();
88
	}
89
90
	public boolean isApplicableForSelection() {
91
		//- Move action is only allowed for the resource view of the test navigator
92
		if(!isResourceNav) return false;
93
		return folders.size() > 0 || areProxiesMovable();
94
	}
95
96
	private boolean areProxiesMovable() {
97
		boolean res = true;
98
		for (Iterator it = proxies.iterator(); it.hasNext();) {
99
			IProxyNode proxy = (IProxyNode)it.next();
100
			res &= proxy.getAdapter(IFile.class) != null && proxy instanceof IProxyNodeMover;
101
		}
102
		return res;
103
	}
104
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/MoveRefactoring.java (+153 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.core.resources.IContainer;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.OperationCanceledException;
25
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.CompositeReferencerProxyNode;
26
import org.eclipse.hyades.test.ui.internal.navigator.proxy.reference.ReferenceTypeRegistry;
27
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
28
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
29
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeMover;
30
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodeUpdater;
31
import org.eclipse.ltk.core.refactoring.Change;
32
import org.eclipse.ltk.core.refactoring.CompositeChange;
33
import org.eclipse.osgi.util.NLS;
34
35
public class MoveRefactoring extends ReorgRefactoring {
36
	private List folders; 
37
	private List proxies; 
38
	private IContainer destination;
39
	
40
	public MoveRefactoring(List folders, List proxies) {
41
		super();
42
		this.folders = folders;
43
		this.proxies = proxies;
44
	}
45
46
	public List getContainers() {
47
		return folders;
48
	}
49
50
	public List getProxies() {
51
		return proxies;
52
	}
53
	
54
	public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
55
		if (change != null) {
56
			return change;
57
		}
58
		pm.beginTask("", folders.size() + proxies.size()); //$NON-NLS-1$
59
		try {
60
			RefactoringTransactionRootChange c = new RefactoringTransactionRootChange(context);
61
			for (Iterator it = folders.iterator(); it.hasNext();) {
62
				Change containerChange = createMoveContainerChange((IFolder) it.next(), destination);
63
				if (containerChange != null) {
64
					c.add(containerChange);
65
				}
66
				pm.worked(1);
67
			}
68
			for (Iterator it = proxies.iterator(); it.hasNext();) {
69
				Change refChange = createMoveProxyChange((IProxyNode) it.next(), destination);
70
				if (refChange != null) {
71
					c.add(refChange);
72
				}
73
				pm.worked(1);
74
			}
75
			c.markAsSynthetic();
76
			return c;
77
		} finally {
78
			pm.done();
79
		}
80
	}
81
82
	public String getName() {
83
		return "";  //$NON-NLS-1$
84
	}
85
	
86
	public void setDestination(IContainer container) {
87
		this.destination = container;
88
		change = null;
89
		seenElements.clear();
90
	}
91
92
	protected Change createMoveProxyChange(IProxyNode node, IContainer dest) {
93
		if (!seenElements.contains(node)) {
94
			seenElements.add(node);
95
			if (node instanceof IReferencerProxyNode) {
96
				return createMoveReferencerChange(node, dest);
97
			} else {
98
				return createShallowMoveProxyChange(node, dest);
99
			}
100
		}		
101
		return null;
102
	}
103
104
	private Change createShallowMoveProxyChange(IProxyNode node, IContainer dest) {
105
		IResource res = node.getUnderlyingResource();
106
		IProxyNodeMover mover = (IProxyNodeMover)node.getAdapter(IProxyNodeMover.class);
107
		if (mover != null) {
108
			return mover.createMoveChange(context, dest.getFullPath().append(res.getName()));
109
		} else {
110
			if (res instanceof IFile) {
111
				return new MoveFileChange((IFile) res, dest);
112
			}
113
		}
114
		return null;
115
	}
116
117
	private Change createMoveReferencerChange(final IProxyNode node, final IContainer dest) {
118
		CompositeChange composite = new CompositeChange(NLS.bind(RefactoringMessages.MOVE_PROXY, node.getText(), dest.getName()));
119
		Change moveNode = createShallowMoveProxyChange(node, dest);
120
		CompositeReferencerProxyNode ref = new CompositeReferencerProxyNode(node);
121
		for (Iterator it = ref.getReferenceTypes().iterator(); it.hasNext();) {
122
			String type = (String)it.next();
123
			String oppType = ReferenceTypeRegistry.getInstance().getOppositeReferenceType(type);
124
			if(ReferenceTypeRegistry.getInstance().isExplicit(oppType)) {
125
				composite.add(createUpdateReferenceTypeChange(ref, type, dest));
126
			}
127
		}
128
		if(moveNode != null) {
129
			composite.add(moveNode);
130
		}
131
		return composite;
132
	}
133
134
	private Change createUpdateReferenceTypeChange(CompositeReferencerProxyNode ref, String type, IContainer dest) {
135
		CompositeChange change = new CompositeChange(ReferenceTypeRegistry.getInstance().getName(type));
136
		for (Iterator it = ref.getReferences(type).iterator(); it.hasNext();) {
137
			IProxyNode proxy = (IProxyNode)it.next();
138
			IProxyNodeUpdater updater = (IProxyNodeUpdater) proxy.getAdapter(IProxyNodeUpdater.class);
139
			if (updater != null) {
140
				IPath destPath = dest.getFullPath().append(ref.getUnderlyingResource().getName());
141
				change.add(updater.createUpdateChange(context, ref, type, destPath));
142
			}
143
		}
144
		return change;
145
	}
146
147
	private Change createMoveContainerChange(IFolder folder, IContainer dest) {
148
		MoveFolderCompositeChange change = new MoveFolderCompositeChange(folder, dest.getFullPath());
149
		performContainerChildren(change, (IContainer)folder, dest.getFullPath().append(folder.getName()));
150
		change.freeze();
151
		return change;
152
	}
153
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/UpdateModelChange.java (+62 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.OperationCanceledException;
18
import org.eclipse.emf.ecore.resource.Resource;
19
import org.eclipse.emf.ecore.util.EcoreUtil;
20
import org.eclipse.hyades.test.ui.navigator.EObjectProxyNode;
21
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
22
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
23
import org.eclipse.ltk.core.refactoring.Change;
24
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
25
import org.eclipse.osgi.util.NLS;
26
27
public class UpdateModelChange extends Change {
28
	private IProxyNode referencer;
29
	private EMFRefactoringTransaction context;
30
31
	public UpdateModelChange(IProxyNode node, IRefactoringContext context) {
32
		this.referencer = node;
33
		this.context = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
34
		Assert.isNotNull(this.context);
35
	}
36
37
	public String getName() {
38
		return NLS.bind(RefactoringMessages.UPDATE_REFERENCES, referencer.getText());
39
	}
40
41
	public Change perform(IProgressMonitor pm) throws CoreException {
42
		if (referencer instanceof EObjectProxyNode) {
43
			//- load the referencer
44
			Resource res = context.getResourceSet().getResource(((EObjectProxyNode)referencer).getOriginatorURI().trimFragment(), true);
45
			EcoreUtil.resolveAll(res); 
46
			context.addResourceToSave(res);
47
		}
48
		return null;
49
	}
50
51
	public Object getModifiedElement() {
52
		return referencer;
53
	}
54
55
	public void initializeValidationData(IProgressMonitor pm) {
56
	}
57
58
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
59
		return new RefactoringStatus();
60
	}
61
62
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/reference/ProjectReferenceRegistry.java (+332 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy.reference;
13
14
import java.io.BufferedInputStream;
15
import java.io.BufferedOutputStream;
16
import java.io.File;
17
import java.io.FileInputStream;
18
import java.io.FileOutputStream;
19
import java.io.IOException;
20
import java.io.InputStream;
21
import java.io.InputStreamReader;
22
import java.io.OutputStreamWriter;
23
import java.util.Collection;
24
import java.util.Collections;
25
import java.util.HashMap;
26
import java.util.HashSet;
27
import java.util.Iterator;
28
import java.util.LinkedList;
29
import java.util.List;
30
import java.util.Map;
31
import java.util.Set;
32
import java.util.zip.GZIPInputStream;
33
import java.util.zip.GZIPOutputStream;
34
35
import org.eclipse.core.resources.IFile;
36
import org.eclipse.core.resources.IProject;
37
import org.eclipse.core.resources.ISaveContext;
38
import org.eclipse.core.resources.ISaveParticipant;
39
import org.eclipse.core.resources.ResourcesPlugin;
40
import org.eclipse.core.runtime.Assert;
41
import org.eclipse.core.runtime.CoreException;
42
import org.eclipse.core.runtime.IPath;
43
import org.eclipse.core.runtime.Path;
44
import org.eclipse.hyades.test.ui.TestUIConstants;
45
import org.eclipse.hyades.test.ui.UiPlugin;
46
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
47
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
48
import org.eclipse.ui.IMemento;
49
import org.eclipse.ui.WorkbenchException;
50
import org.eclipse.ui.XMLMemento;
51
52
/**
53
 * This class is used to store proxy references for a given project.
54
 * Its persistency is made using a save participant.
55
 * 
56
 * @author jgout
57
 * @since 4.3
58
 */
59
public class ProjectReferenceRegistry implements ISaveParticipant {
60
	
61
	public static final String TAG_REFERENCE = "reference"; //$NON-NLS-1$
62
	public static final String TAG_REFERENCER = "referencer"; //$NON-NLS-1$
63
	public static final String TAG_REF_TYPE = "refType"; //$NON-NLS-1$
64
	
65
	//- (proxy, Set(Reference))
66
	private Map references;
67
	private boolean hasChanged;
68
	private IProject project;
69
	
70
	class Reference {
71
		private String type;
72
		private IFile referenced;
73
74
		public Reference(String typeRef, IFile referenced) {
75
			this.type = typeRef;
76
			this.referenced = referenced;
77
		}
78
79
		public IFile getReferenced() {
80
			return referenced;
81
		}
82
83
		public String getType() {
84
			return type;
85
		}
86
		
87
		public boolean equals(Object arg0) {
88
			if(arg0 == this) return true;
89
			if (arg0 instanceof Reference) {
90
				Reference ref = (Reference) arg0;
91
				if (ref != null) {
92
					if(type != null && referenced != null) {
93
						return type.equals(ref.type) && referenced.equals(ref.referenced);
94
					} else if((type == null && ref.type == null) || (referenced == null && ref.referenced == null)) {
95
						return true;
96
					}
97
				}
98
			}
99
			return false;
100
		}
101
102
		public int hashCode() {
103
			return referenced != null ? referenced.hashCode() : -1;
104
		}
105
	}
106
	
107
	public ProjectReferenceRegistry(IProject project, IReferenceRegistrySavedState savedState) {
108
		this.references = new HashMap();
109
		this.hasChanged = false;
110
		this.project = project;
111
		if (savedState != null) {
112
			IPath refsFilePath = savedState.lookup(getSavedStateFileKey());
113
			if (refsFilePath != null) {
114
				File dependenciesFile = UiPlugin.getDefault().getStateLocation().append(refsFilePath).toFile();
115
				try {
116
					load(new GZIPInputStream(new BufferedInputStream(new FileInputStream(dependenciesFile))));
117
				} catch (Throwable t) {
118
					//- Oops, let's forget anything and start with a clean registry
119
					clear();
120
					UiPlugin.logWarning("Unable to load proxy node references file for project " + this.project.getName(), t); //$NON-NLS-1$
121
				}
122
			}
123
		}
124
	}
125
126
	private void addReference(IFile referencer, Reference ref) {
127
		Assert.isNotNull(ref);
128
		Collection refs = (Collection) references.get(referencer);
129
		if(refs == null) {
130
			//- this proxy has not yet references
131
			refs = new HashSet();
132
			references.put(referencer, refs);
133
		}
134
		refs.add(ref);
135
		hasChanged = true;
136
	}
137
	
138
	public void addReference(IFile referencer, String refType, IFile referenced) {
139
		addReference(referencer, new Reference(refType, referenced));
140
	}
141
	
142
	public void addBidirectionalReference(IFile referencer, String refType, IFile referenced, String oppositeRefType) {
143
		addReference(referencer, refType, referenced);
144
		addReference(referenced, oppositeRefType, referencer);
145
	}
146
147
	public void removeReference(IFile referencer, IFile referenced) {
148
		Assert.isNotNull(referenced);
149
		Collection refs = (Collection) references.get(referencer);
150
		if(refs != null) {
151
			for (Iterator it = refs.iterator(); it.hasNext();) {
152
				Reference ref = (Reference) it.next();
153
				if(referenced.equals(ref.getReferenced())) {
154
					it.remove();
155
					hasChanged = true;
156
				}
157
			}
158
		}
159
	}
160
161
	public void removeReferences(IFile referencer) {
162
		references.remove(referencer);
163
	}
164
	
165
	/**
166
	 * Returns the list of referenced proxy node associated to the given referencer.
167
	 * Only references matching with the given type are considered
168
	 * @param referencer
169
	 * @param refType
170
	 * @return
171
	 */
172
	public Collection getReferences(IFile referencer, String refType) {
173
		Assert.isNotNull(refType,"type should be not null"); //$NON-NLS-1$
174
		Collection refs = (Collection) references.get(referencer);
175
		if(refs != null) {
176
			List res = new LinkedList();
177
			for (Iterator it = refs.iterator(); it.hasNext();) {
178
				Reference ref = (Reference) it.next();
179
				if(refType.equals(ref.getType())) {
180
					IProxyNode proxy = FileProxyNodeCache.getInstance().getProxy(ref.getReferenced());
181
					if(proxy == null) {
182
						it.remove();
183
					} else {
184
						res.add(proxy);
185
					}
186
				}
187
			}
188
			return res;
189
		} else {
190
			return Collections.EMPTY_LIST;
191
		}
192
	}
193
	
194
	/**
195
	 * Returns all references of type {@link Reference} registered for the given referencer.
196
	 * This method is used to persistence.
197
	 * @param referencer
198
	 * @return all references of type {@link Reference} registered for the given referencer.
199
	 */
200
	private Collection getAllReferences(IFile referencer) {
201
		Collection list = (Collection) references.get(referencer);
202
		return list != null ? list : Collections.EMPTY_LIST;
203
	}
204
	
205
	public Set getReferenceTypes(IFile referencer) {
206
		Set res = new HashSet();
207
		Collection refs = (Collection) references.get(referencer);
208
		if(refs != null) {
209
			for (Iterator it = refs.iterator(); it.hasNext();) {
210
				Reference ref = (Reference) it.next();
211
				res.add(ref.getType());
212
			}
213
		}
214
		return res;
215
	}
216
	
217
	/**
218
	 * Clears the registry
219
	 */
220
	public void clear() {
221
		references.clear();
222
		hasChanged = false;
223
	}
224
225
	/**
226
	 * Returns the File to use for saving and restoring the last built state for the given project.
227
	 */
228
	private File getPersistenceFile(int saveNumber) {
229
		if (!project.exists()) return null;
230
		String depsFileName = project.getName() + ".references-" + Integer.toString(saveNumber); //$NON-NLS-1$
231
		return UiPlugin.getDefault().getStateLocation().append(depsFileName).toFile();
232
	}
233
	
234
	private IPath getSavedStateFileKey() {
235
		return new Path("references").append(project.getName()); //$NON-NLS-1$
236
	}
237
238
	public void doneSaving(ISaveContext context) {
239
		if(hasChanged) {
240
			hasChanged = false;
241
			//- cleanup previous saved file
242
			File depsFile = getPersistenceFile(context.getPreviousSaveNumber());
243
			if (depsFile.exists()) {
244
				depsFile.delete();
245
			}
246
		}
247
	}
248
249
	public void prepareToSave(ISaveContext context) throws CoreException {
250
		//- nop
251
	}
252
253
	public void rollback(ISaveContext context) {
254
		//- Remove the file we generated
255
		File file = getPersistenceFile(context.getSaveNumber());
256
		if (file.exists()) {
257
			file.delete();
258
		}
259
	}
260
261
	public void saving(ISaveContext context) throws CoreException {
262
		//- if context.getKind() == ISaveContext.PROJECT_SAVE then only 
263
		//- the instance of this class that has this.project == context.getProject is called
264
		if(hasChanged && project.exists()) {
265
			int saveNumber = context.getSaveNumber();
266
			File depsFile = getPersistenceFile(saveNumber);
267
			try {
268
				save(depsFile);
269
				context.map(getSavedStateFileKey(), new Path(depsFile.getName()));
270
				context.needSaveNumber();
271
			} catch (IOException e) {
272
				UiPlugin.logError("Unexpected exception during references saving operation.", e); //$NON-NLS-1$
273
			}			
274
		}
275
	}
276
277
	private void load(InputStream stream) throws WorkbenchException, IOException {
278
		InputStreamReader reader = new InputStreamReader(stream);
279
		IMemento memento = XMLMemento.createReadRoot(reader);
280
		reader.close();
281
		IMemento [] referencers = memento.getChildren(TAG_REFERENCER);
282
		for (int i = 0; i < referencers.length; i++) {
283
			String underlyingResName = referencers[i].getString(TestUIConstants.TAG_UNDERLYING_RESOURCE);
284
			IFile refFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(underlyingResName));
285
			if(refFile != null) {
286
				loadProxyReferences(refFile, referencers[i]);
287
			}
288
		}
289
	}
290
291
	private void loadProxyReferences(IFile file, IMemento memento) {
292
		//- retrieving references
293
		IMemento [] refStates = memento.getChildren(TAG_REFERENCE);
294
		IFile refFile;
295
		for (int j = 0; j < refStates.length; j++) {
296
			IMemento refMemento = refStates[j];
297
			String underlyingResName = refMemento.getString(TestUIConstants.TAG_UNDERLYING_RESOURCE);
298
			String refType = refMemento.getString(TAG_REF_TYPE);
299
			refFile = ResourcesPlugin.getWorkspace().getRoot().getFile(Path.fromPortableString(underlyingResName));
300
			if(refFile.exists()) {
301
				addReference(file, new Reference(refType, refFile));
302
			} else {
303
				//- be sure that next save will purge this dead entry
304
				hasChanged = true;
305
			}
306
		} 
307
	}
308
309
	private void save(File depsFile) throws IOException {
310
		OutputStreamWriter writer = new OutputStreamWriter(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(depsFile))));
311
		IMemento memento = XMLMemento.createWriteRoot("references"); //$NON-NLS-1$
312
		for (Iterator it = references.keySet().iterator(); it.hasNext();) {
313
			saveProxyReferences((IFile) it.next(), memento);
314
		}
315
		((XMLMemento) memento).save(writer);
316
		writer.close();
317
	}
318
319
	private void saveProxyReferences(IFile file, IMemento memento) {
320
		//- save the referencer proxy itself
321
		IMemento referencerMemento = memento.createChild(TAG_REFERENCER);
322
		referencerMemento.putString(TestUIConstants.TAG_UNDERLYING_RESOURCE, file.getFullPath().toPortableString());
323
		//- save references as well
324
		for (Iterator it = getAllReferences(file).iterator(); it.hasNext();) {
325
			Reference ref = (Reference) it.next();
326
			IMemento referenceMemento = referencerMemento.createChild(TAG_REFERENCE);
327
			referenceMemento.putString(TAG_REF_TYPE, ref.getType());
328
			referenceMemento.putString(TestUIConstants.TAG_UNDERLYING_RESOURCE, ref.getReferenced().getFullPath().toPortableString());
329
		}
330
331
	}
332
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/reference/Reference.java (+79 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy.reference;
13
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
17
import org.eclipse.hyades.test.ui.internal.navigator.proxy.Proxy;
18
import org.eclipse.hyades.test.ui.navigator.IProxy;
19
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
20
21
public class Reference {
22
	private String type;
23
	private String proxyId;
24
	private IFile proxyFile;
25
	
26
	public Reference(String type, String proxyId, IFile proxyFile) {
27
		if(type == null || proxyId == null || proxyFile == null) {
28
			throw new IllegalArgumentException("Can not create reference with null value"); //$NON-NLS-1$
29
		}
30
		this.type = type;
31
		this.proxyId = proxyId;
32
		this.proxyFile = proxyFile;
33
	}
34
	
35
	public Reference(String type, IProxy proxy) {
36
		IResource ulr = proxy.getUnderlyingResource();
37
		if (ulr instanceof IFile) {
38
			this.proxyFile = (IFile) ulr;
39
		}
40
		this.type = type;
41
		this.proxyId = proxy.getIdentifier();
42
	}
43
44
	/**
45
	 * Returns the referenced proxy node.
46
	 * @return the referenced proxy node or <code>null</code> 
47
	 * if the file that was containing it no longer exists. 
48
	 */
49
	public IProxyNode getReferencedProxy() {
50
		return FileProxyNodeCache.getInstance().getCorrespondingProxy(new Proxy(proxyFile, proxyId));
51
	}
52
53
	public String getType() {
54
		return type;
55
	}
56
	
57
	public IFile getProxyFile() {
58
		return proxyFile;
59
	}
60
	
61
	public String getProxyId() {
62
		return proxyId;
63
	}
64
65
	public boolean equals(Object arg0) {
66
		if(arg0 == this) return true;
67
		if (arg0 instanceof Reference) {
68
			Reference ref = (Reference) arg0;
69
			if (ref != null) {
70
				return ref.type.equals(type) && ref.proxyId.equals(proxyId) && ref.proxyFile.equals(proxyFile);
71
			}
72
		}
73
		return false;
74
	}
75
76
	public int hashCode() {
77
		return proxyFile.hashCode();
78
	}
79
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteRefactoring.java (+208 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Iterator;
15
import java.util.LinkedList;
16
import java.util.List;
17
18
import org.eclipse.core.resources.IContainer;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFolder;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.OperationCanceledException;
27
import org.eclipse.core.runtime.SubProgressMonitor;
28
import org.eclipse.hyades.test.ui.UiPlugin;
29
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
30
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
31
import org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode;
32
import org.eclipse.hyades.test.ui.navigator.actions.IProxyNodePaster;
33
import org.eclipse.ltk.core.refactoring.Change;
34
import org.eclipse.ltk.core.refactoring.CompositeChange;
35
import org.eclipse.ltk.core.refactoring.Refactoring;
36
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
37
import org.eclipse.osgi.util.NLS;
38
39
/**
40
 * refactoring for paste
41
 * 
42
 * @author jbozier
43
 * @since 4.5
44
 */
45
46
public class PasteRefactoring extends Refactoring {
47
	private Change change;
48
	private IContainer destination;
49
	private RefactoringContext context;
50
	protected List seenElements;
51
	private List folders; 
52
	private List proxies; 
53
54
	public PasteRefactoring(List folders, List proxies) {
55
		super();
56
		this.seenElements = new LinkedList();
57
		this.context = new RefactoringContext();
58
		this.folders = folders;
59
		this.proxies = proxies;
60
	}
61
	
62
	public List getContainers() {
63
		return folders;
64
	}
65
66
	public List getProxies() {
67
		return proxies;
68
	}
69
	
70
	public String getName() {
71
		return RefactoringMessages.UPDATE_OWNED_RESSOURCES_REFERENCES;  
72
	}
73
	
74
	public void setDestination(IContainer container) {
75
		this.destination = container;
76
		change = null;
77
	}
78
79
	public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
80
		pm.beginTask("", 3); //$NON-NLS-1$
81
		try {
82
			ProxyNodeScanner scanner = new ProxyNodeScanner(ResourcesPlugin.getWorkspace().getRoot());
83
			try {
84
				scanner.scan(new SubProgressMonitor(pm, 1));
85
			} catch (OperationCanceledException e) {
86
				return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.ReorgRefactoring_CANCELED_OPERATION_MSG);
87
			}			
88
			change = createChange(new SubProgressMonitor(pm, 1));
89
			RefactoringStatus valid = change.isValid(new SubProgressMonitor(pm, 1));
90
			if(!valid.isOK()) {
91
				change = null;
92
			}
93
			return valid;
94
		} finally {
95
			pm.done();
96
		}
97
	}
98
99
	public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
100
		pm.beginTask("", 1); //$NON-NLS-1$
101
		try {
102
			return new RefactoringStatus();
103
		} finally {
104
			pm.done();
105
		}
106
	}
107
108
	public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
109
		if (change != null) {
110
			return change;
111
		}
112
		pm.beginTask("", folders.size() + proxies.size()); //$NON-NLS-1$ 
113
		try {
114
			RefactoringTransactionRootChange c = new RefactoringTransactionRootChange(context);
115
			for (Iterator it = folders.iterator(); it.hasNext();) {
116
				Change containerChange = createPasteContainerChange((IFolder) it.next(), destination);
117
				if (containerChange != null) {
118
					c.add(containerChange);
119
				}
120
				pm.worked(1);
121
			}
122
			for (Iterator it = proxies.iterator(); it.hasNext();) {
123
				Change refChange = createPasteProxyChange((IProxyNode) it.next(), destination);
124
				if (refChange != null) {
125
					c.add(refChange);
126
				}
127
				pm.worked(1);
128
			}
129
			c.markAsSynthetic();
130
			return c;
131
		} finally {
132
			pm.done();
133
		}
134
	}
135
	
136
	private Change createPasteContainerChange(IFolder folder, IContainer dest) {
137
		IPath [] finalPath = new IPath[1]; 
138
		PasteFolderCompositeChange change = new PasteFolderCompositeChange(folder, dest.getFullPath(),finalPath);
139
		performContainerChildren(change, (IContainer)folder, finalPath[0]);
140
		change.freeze();
141
		return change;
142
	}
143
	
144
	private Change performContainerChildren(CompositeChange change, IContainer source, IPath newPath) {
145
		if(source.isAccessible()) {
146
	//		EMFRefactoringTransaction trans = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
147
			IResource[] resources;
148
			try {
149
				resources = source.members();
150
			} catch (CoreException e) {
151
				UiPlugin.logError("Unable to get members of container: "+source.getFullPath().toOSString(), e); //$NON-NLS-1$
152
				return null;
153
			}
154
			for (int i = 0; i < resources.length; i++) {
155
				if (resources[i] instanceof IFile) {
156
					IFile file = (IFile)resources[i];
157
					IProxyNode proxy = FileProxyNodeCache.getInstance().getProxy(file);
158
					if (proxy != null) {
159
						// add here stuff to memorize changed children
160
					}
161
				} else {
162
					performContainerChildren(change, (IContainer)resources[i], newPath.append(resources[i].getName()));
163
				}
164
			}
165
		}
166
		return change;
167
	}
168
	
169
	// physical paste in case there is no link
170
	// create a new proxy on dest location + copy proxy link if any
171
	private Change createShallowPasteProxyChange(IProxyNode node, IContainer dest,String [] targetName) {
172
		IResource res = node.getUnderlyingResource();
173
		IProxyNodePaster paster = (IProxyNodePaster)node.getAdapter(IProxyNodePaster.class);
174
		if (paster != null) {
175
			IPath newPath = dest.getFullPath().append(res.getName());
176
			Change change = paster.createPasteChange(context, newPath,targetName);
177
			return change;
178
		} else {			
179
			if (res instanceof IFile) {
180
				return new PasteFileChange((IFile) res, dest);
181
			}
182
		}
183
		return null;
184
	}
185
	
186
	protected Change createPasteProxyChange(IProxyNode node, IContainer dest) {
187
		if (!seenElements.contains(node)) {
188
			seenElements.add(node);
189
			if (node instanceof IReferencerProxyNode) {
190
				Change change = createPasteReferencerChange((IReferencerProxyNode)node, dest,new String[1]);
191
				return change;
192
			} else {
193
				return createShallowPasteProxyChange(node, dest,new String[1]);
194
			}
195
		}		
196
		return null;
197
	}
198
	
199
	// logical paste in case there is links
200
	private Change createPasteReferencerChange(IReferencerProxyNode nodeA,IContainer dest,String [] targetName) {
201
		CompositeChange composite = new CompositeChange(NLS.bind(RefactoringMessages.PASTE_PROXY, nodeA.getText(), dest.getName()));
202
		Change pasteNode = createShallowPasteProxyChange(nodeA, dest,targetName); 
203
		if(pasteNode != null) {
204
			composite.add(pasteNode);
205
		}				
206
		return composite;
207
	}
208
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/EMFRefactoringTransaction.java (+116 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.List;
19
import java.util.Map;
20
import java.util.Set;
21
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.runtime.Assert;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.SubProgressMonitor;
27
import org.eclipse.emf.common.util.URI;
28
import org.eclipse.emf.ecore.resource.Resource;
29
import org.eclipse.emf.ecore.resource.ResourceSet;
30
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
31
import org.eclipse.hyades.test.core.util.EMFUtil;
32
import org.eclipse.hyades.test.ui.UiPlugin;
33
import org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction;
34
import org.eclipse.ltk.core.refactoring.Change;
35
36
public class EMFRefactoringTransaction implements IRefactoringTransaction {
37
	public static final String Id = "org.eclipse.hyades.test.ui.EMFRefactoringTransaction"; //$NON-NLS-1$
38
	private Set resources;
39
	private Map newURIs;
40
	private ResourceSet resourceSet;
41
42
	public EMFRefactoringTransaction() {
43
		this.resources = new HashSet();
44
		this.newURIs = new HashMap();
45
		this.resourceSet = new ResourceSetImpl();
46
	}
47
	
48
	public void addChangedURI(Resource res, URI newURI) {
49
		newURIs.put(res, newURI);
50
	}
51
	
52
	public void addResourceToSave(Resource res) {
53
		Assert.isNotNull(res);
54
		if(!resources.contains(res)) {
55
			resources.add(res);
56
		}
57
	}
58
59
	public URI getNewURI(Resource res) {
60
		return (URI)newURIs.get(res);
61
	}
62
	
63
	public ResourceSet getResourceSet() {
64
		return resourceSet;
65
	}
66
67
	public Set getResourcesToSave() {
68
		return resources;
69
	}
70
71
	public Set getResourcesToMove() {
72
		return newURIs.keySet();
73
	}
74
	
75
	public void beginChanges(IProgressMonitor monitor) { /* NOP	*/ }
76
77
	public void cancelChanges(IProgressMonitor monitor) { /* NOP	*/ }
78
	
79
	public Change commitChanges(IProgressMonitor pm) throws CoreException {
80
		List files = new LinkedList();
81
		pm.beginTask("", getResourcesToMove().size()+getResourcesToSave().size()+/*getResourcesToCopy().size()*/+1); //$NON-NLS-1$
82
		try {
83
			//- change the URI of resources that should move
84
			for (Iterator it = getResourcesToMove().iterator(); it.hasNext();) {
85
				Resource res = (Resource) it.next();
86
				if (res != null) {
87
					//- change its URI 
88
					IFile file = EMFUtil.getWorkspaceFile(res);
89
					res.setURI(getNewURI(res));
90
					if (file != null) {
91
						files.add(file);
92
					}
93
				}
94
				pm.worked(1);
95
			}
96
			//- save all EMF resources loaded that need to be saved.
97
			for (Iterator it = getResourcesToSave().iterator(); it.hasNext();) {
98
				Resource res = (Resource) it.next();
99
				try {
100
					EMFUtil.save(res);
101
					EMFUtil.getWorkspaceFile(res).refreshLocal(0, pm);
102
				} catch (Exception e) {
103
					UiPlugin.logError(e);
104
				}
105
				pm.worked(1);
106
			}
107
			//- delete files that moved
108
			for (Iterator it = files.iterator(); it.hasNext();) {
109
				((IFile) it.next()).delete(false, new SubProgressMonitor(pm, 1));
110
			}
111
			return null;
112
		} finally {
113
			pm.done();
114
		}		
115
	}
116
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/LaunchConfigurationUpdateChange.java (+59 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.OperationCanceledException;
17
import org.eclipse.debug.core.ILaunchConfiguration;
18
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19
import org.eclipse.emf.common.util.URI;
20
import org.eclipse.hyades.test.core.launch.configurations.TestLaunchConfigurationFacade;
21
import org.eclipse.ltk.core.refactoring.Change;
22
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
23
import org.eclipse.osgi.util.NLS;
24
25
public class LaunchConfigurationUpdateChange extends Change {
26
27
	private ILaunchConfiguration config;
28
	private URI newURI;
29
	
30
	public LaunchConfigurationUpdateChange(ILaunchConfiguration config, URI newURI) {
31
		super();
32
		this.config = config;
33
		this.newURI = newURI;
34
	}
35
36
	public Object getModifiedElement() {
37
		return this.config;
38
	}
39
40
	public String getName() {
41
		return NLS.bind(RefactoringMessages.LaunchConfigurationUpdateChange_NAME, config.getName());
42
	}
43
44
	public void initializeValidationData(IProgressMonitor pm) {
45
	}
46
47
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
48
		RefactoringStatus status = new RefactoringStatus();
49
		return status;
50
	}
51
52
	public Change perform(IProgressMonitor pm) throws CoreException {
53
		ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
54
		TestLaunchConfigurationFacade.updateTestURI(workingCopy, newURI);
55
		workingCopy.doSave();
56
		return null;
57
	}
58
59
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/ModelPathChange.java (+65 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.OperationCanceledException;
19
import org.eclipse.emf.common.util.URI;
20
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.hyades.test.ui.navigator.EObjectProxyNode;
22
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
23
import org.eclipse.hyades.test.ui.navigator.actions.IRefactoringContext;
24
import org.eclipse.ltk.core.refactoring.Change;
25
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
26
import org.eclipse.osgi.util.NLS;
27
28
public class ModelPathChange extends Change {
29
	private IProxyNode referenced;
30
	private EMFRefactoringTransaction context;
31
	private IPath newPath;
32
33
	public ModelPathChange(EObjectProxyNode node, IRefactoringContext context, IPath destinationPath) {
34
		this.referenced = node;
35
		this.context = (EMFRefactoringTransaction) context.getRefactoringTransaction(EMFRefactoringTransaction.Id);
36
		this.newPath = destinationPath;
37
		Assert.isNotNull(this.context);
38
	}
39
40
	public Object getModifiedElement() {
41
		return referenced;
42
	}
43
44
	public String getName() {
45
		return NLS.bind(RefactoringMessages.UPDATE_PROXY_PATH_CHANGED, referenced.getText());
46
	}
47
48
	public void initializeValidationData(IProgressMonitor pm) {
49
	}
50
51
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,	OperationCanceledException {
52
		return new RefactoringStatus();
53
	}
54
55
	public Change perform(IProgressMonitor pm) throws CoreException {
56
		if (referenced instanceof EObjectProxyNode) {
57
			//- load the referenced
58
			Resource res = context.getResourceSet().getResource(((EObjectProxyNode)referenced).getOriginatorURI().trimFragment(), true);
59
			context.addResourceToSave(res);
60
			context.addChangedURI(res, URI.createPlatformResourceURI(newPath.toPortableString(),false));
61
		}
62
		return null;
63
	}
64
65
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/RefactoringTransactionRootChange.java (+75 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IWorkspaceRunnable;
15
import org.eclipse.core.resources.ResourcesPlugin;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.SubProgressMonitor;
19
import org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction;
20
import org.eclipse.ltk.core.refactoring.Change;
21
import org.eclipse.ltk.core.refactoring.CompositeChange;
22
23
/**
24
 * Root change of move and rename action. 
25
 * The performChange implementation has a transactional behavior according to the following pattern:
26
 *  - context.beginChanges()
27
 *  - Children perfomChange()
28
 *  - context.commitChanges()
29
 *  That way, it is guarantee that refactoring transactions (stored in the context) 
30
 *  commit their changes after children ones. 
31
 * @author jgout
32
 * @since 4.3
33
 */
34
public class RefactoringTransactionRootChange extends CompositeChange {
35
	private IRefactoringTransaction context;
36
37
	private final class SaveResourceSetRunnable implements IWorkspaceRunnable {
38
		private Change undoChange;
39
		
40
		public void run(IProgressMonitor monitor) throws CoreException {
41
			undoChange = RefactoringTransactionRootChange.super.perform(monitor);
42
		}
43
		
44
		public Change getUndoChange() {
45
			return undoChange;
46
		}
47
	}
48
49
	public RefactoringTransactionRootChange(IRefactoringTransaction context) {
50
		super(""); //$NON-NLS-1$
51
		this.context = context;
52
	}
53
54
	public Change perform(IProgressMonitor pm) throws CoreException {
55
		pm.beginTask("", 3); //$NON-NLS-1$
56
		try {
57
			CompositeChange undo = new CompositeChange("");//$NON-NLS-1$
58
			context.beginChanges(new SubProgressMonitor(pm, 1));
59
			try {
60
				//- Children performChange()
61
				SaveResourceSetRunnable action = new SaveResourceSetRunnable();
62
				ResourcesPlugin.getWorkspace().run(action, new SubProgressMonitor(pm, 1));
63
				undo.add(action.getUndoChange());
64
			} catch (CoreException t) {
65
				context.cancelChanges(pm);
66
				throw t;
67
			}		
68
			undo.add(context.commitChanges(new SubProgressMonitor(pm, 1)));
69
			return undo;
70
		} finally {
71
			pm.done();
72
		}		
73
	}
74
75
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/DeleteRefactoringWizard.java (+117 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.ltk.core.refactoring.Refactoring;
18
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
19
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionAdapter;
23
import org.eclipse.swt.events.SelectionEvent;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Label;
30
31
public class DeleteRefactoringWizard extends RefactoringWizard {
32
	private DeleteRefactoringInputPage page;
33
	
34
	private class DeleteRefactoringInputPage extends UserInputWizardPage {
35
		private static final String DEEP_REMOVE_CHECK_STATE= "DeepRemoveCheckState"; //$NON-NLS-1$
36
		private DeleteRefactoring refactoring;
37
		
38
		public DeleteRefactoringInputPage(Refactoring ref) {
39
			super(""); //$NON-NLS-1$
40
			this.refactoring = (DeleteRefactoring) ref;
41
		}
42
43
		public void createControl(Composite parent) {
44
			initializeDialogUnits(parent);
45
			Composite result= new Composite(parent, SWT.NONE);
46
			setControl(result);
47
			result.setLayout(new GridLayout());
48
			addLabel(result);
49
			addDeleteRemoveCheckBox(result);
50
			Dialog.applyDialogFont(result);
51
		}
52
53
		private void addDeleteRemoveCheckBox(Composite parent) {
54
			final Button check = new Button(parent, SWT.CHECK);
55
			boolean deepRemove = getBooleanSetting(DEEP_REMOVE_CHECK_STATE, false);
56
			check.setText(RefactoringMessages.DELETE_DEEP_REMOVE);
57
			check.setSelection(deepRemove);
58
			updateRefactoring(deepRemove);
59
			check.addSelectionListener(new SelectionAdapter() {
60
				public void widgetSelected(SelectionEvent e) {
61
					saveBooleanSetting(DEEP_REMOVE_CHECK_STATE, check);
62
					updateRefactoring(check.getSelection());
63
				}
64
			});
65
		}
66
67
		protected void updateRefactoring(boolean deepRemove) {
68
			DeleteRefactoringWizard.this.setForcePreviewReview(deepRemove);
69
			refactoring.setDeepRemove(deepRemove);			
70
		}
71
72
		private Control addLabel(Composite parent) {
73
			Label label= new Label(parent, SWT.NONE);
74
			String text;
75
			int containers= refactoring.getContainers().size();
76
			int proxies= refactoring.getProxies().size();
77
78
			if (containers == 0 && proxies == 1) {
79
				text= NLS.bind(RefactoringMessages.DELETE_CONFIRM_1, ((IProxyNode)refactoring.getProxies().get(0)).getText());
80
			} else if (containers == 1 && proxies == 0) {
81
				text= NLS.bind(RefactoringMessages.DELETE_CONFIRM_1, ((IResource)refactoring.getContainers().get(0)).getName());
82
			} else {
83
				text= NLS.bind(RefactoringMessages.DELETE_CONFIRM_N, String.valueOf(containers + proxies));
84
			}
85
			label.setText(text);
86
			label = new Label(parent, SWT.NONE); //- spacing the first label
87
			label.setLayoutData(new GridData(SWT.BEGINNING, GridData.FILL, false, true));
88
			return label;
89
		}
90
		
91
		protected boolean getBooleanSetting(String key, boolean defaultValue) {
92
			String value= getRefactoringSettings().get(key);
93
			if (value != null)
94
				return Boolean.valueOf(value).booleanValue();
95
			else
96
				return defaultValue;
97
		}
98
		
99
		protected void saveBooleanSetting(String key, Button checkBox) {
100
			if (checkBox != null)
101
				getRefactoringSettings().put(key, checkBox.getSelection());
102
		}
103
	}
104
	
105
	public DeleteRefactoringWizard(Refactoring refactoring) {
106
		super(refactoring, DIALOG_BASED_USER_INTERFACE | NONE);
107
	}
108
	
109
	protected void addUserInputPages() {
110
		page = new DeleteRefactoringInputPage(getRefactoring());
111
		addPage(page);
112
	}
113
	
114
	public boolean deepRemove() {
115
		return page.getBooleanSetting(DeleteRefactoringInputPage.DEEP_REMOVE_CHECK_STATE, false);
116
	}
117
}
(-)src/org/eclipse/hyades/test/ui/navigator/actions/IRefactoringContext.java (+32 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator.actions;
13
14
import org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction;
15
16
/**
17
 * Global context that contents all domain specific refactoring transactions defined using 
18
 * the extension point <code>org.eclipse.hyades.test.ui.testNavigatorRefactoringTransactions</code>
19
 * This interface is not intented to be implemented by clients.
20
 * 
21
 * @author jgout
22
 * @since 4.4
23
 */
24
public interface IRefactoringContext {
25
26
	/**
27
	 * Returns the refactoring transaction given its domain id.
28
	 * @param domainId a domain id.
29
	 * @return the refactoring transaction given its domain id or <code>null</code> if the domain id is unknown.
30
	 */
31
	public IRefactoringTransaction getRefactoringTransaction(String domainId);
32
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/messages.properties (+7 lines)
Added Link Here
1
DELETE_ACTION_NAME=Delete
2
MOVE_ACTION_NAME=Move
3
PASTE_ACTION_NAME=Paste
4
RENAME_ACTION_NAME=Rename
5
RENAME_NEW_NAME_LABEL=New Name:
6
SAVE_ALL_DIALOG_NAME=Save All Modified Resources
7
SAVE_ALL_DIALOG_MESSAGE=All modified resources must be saved before this operation.
(-)schema/testNavigatorReferenceTypes.exsd (+152 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.hyades.test.ui">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.hyades.test.ui" id="testNavigatorReferenceTypes" name="Test Navigator Reference Types"/>
7
      </appInfo>
8
      <documentation>
9
         Extension point that allows to declare proxy node reference types.
10
Proxy nodes can reference other proxy nodes using references (see &lt;code&gt;org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode&lt;/code&gt;)
11
Those references are typed and should be declared using this extension point.
12
      </documentation>
13
   </annotation>
14
15
   <element name="extension">
16
      <complexType>
17
         <sequence minOccurs="1" maxOccurs="unbounded">
18
            <element ref="type"/>
19
         </sequence>
20
         <attribute name="point" type="string" use="required">
21
            <annotation>
22
               <documentation>
23
                  
24
               </documentation>
25
            </annotation>
26
         </attribute>
27
         <attribute name="id" type="string">
28
            <annotation>
29
               <documentation>
30
                  
31
               </documentation>
32
            </annotation>
33
         </attribute>
34
         <attribute name="name" type="string">
35
            <annotation>
36
               <documentation>
37
                  
38
               </documentation>
39
               <appInfo>
40
                  <meta.attribute translatable="true"/>
41
               </appInfo>
42
            </annotation>
43
         </attribute>
44
      </complexType>
45
   </element>
46
47
   <element name="type">
48
      <complexType>
49
         <attribute name="id" type="string" use="required">
50
            <annotation>
51
               <documentation>
52
                  Id of the type. This Id is used in &lt;code&gt;org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode.addReference()&lt;/code&gt;
53
               </documentation>
54
            </annotation>
55
         </attribute>
56
         <attribute name="name" type="string" use="required">
57
            <annotation>
58
               <documentation>
59
                  A human readable name for this type. This name is displayed in the refactoring wizards.
60
               </documentation>
61
            </annotation>
62
         </attribute>
63
         <attribute name="isExplicit" type="boolean" use="required">
64
            <annotation>
65
               <documentation>
66
                  This flag determines whether the proxy node reference is explicit inside the underneath EMF objects.
67
               </documentation>
68
            </annotation>
69
         </attribute>
70
         <attribute name="owns" type="boolean" use="required">
71
            <annotation>
72
               <documentation>
73
                  This flag is used to describe whether the referencer proxy node (which contains references of this type) owns the referenced element or just reference it.
74
This relation is equivalent to the composition relation in UML.
75
               </documentation>
76
            </annotation>
77
         </attribute>
78
         <attribute name="oppositeReferenceTypeId" type="string">
79
            <annotation>
80
               <documentation>
81
                  The type id of the opposite reference if such a reference has been defined.
82
This is an optional attribute.
83
               </documentation>
84
            </annotation>
85
         </attribute>
86
      </complexType>
87
   </element>
88
89
   <annotation>
90
      <appInfo>
91
         <meta.section type="since"/>
92
      </appInfo>
93
      <documentation>
94
         4.3
95
      </documentation>
96
   </annotation>
97
98
   <annotation>
99
      <appInfo>
100
         <meta.section type="examples"/>
101
      </appInfo>
102
      <documentation>
103
         &lt;pre&gt;
104
       &lt;extension
105
             point=&quot;org.eclipse.hyades.test.ui.testNavigatorReferenceTypes&quot;&gt;
106
          &lt;type
107
                id=&quot;TestSuite2TestLog&quot;
108
                isExplicit=&quot;false&quot;
109
                name=&quot;Dependent Test Logs&quot;
110
                oppositeReferenceTypeId=&quot;TestLog2TestSuite&quot;
111
                owns=&quot;true&quot;/&gt;
112
          &lt;type
113
                id=&quot;TestLog2TestSuite&quot;
114
                isExplicit=&quot;true&quot;
115
                name=&quot;Source Test Suite&quot;
116
                oppositeReferenceTypeId=&quot;TestSuite2TestLog&quot;
117
                owns=&quot;false&quot;/&gt;
118
       &lt;/extension&gt;
119
&lt;/pre&gt;
120
      </documentation>
121
   </annotation>
122
123
   <annotation>
124
      <appInfo>
125
         <meta.section type="apiInfo"/>
126
      </appInfo>
127
      <documentation>
128
         
129
      </documentation>
130
   </annotation>
131
132
   <annotation>
133
      <appInfo>
134
         <meta.section type="implementation"/>
135
      </appInfo>
136
      <documentation>
137
         
138
      </documentation>
139
   </annotation>
140
141
   <annotation>
142
      <appInfo>
143
         <meta.section type="copyright"/>
144
      </appInfo>
145
      <documentation>
146
         Copyright (c) 2006 IBM Corporation and others.&lt;br&gt;
147
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
148
&lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
149
      </documentation>
150
   </annotation>
151
152
</schema>
(-)src/org/eclipse/hyades/test/ui/navigator/actions/IProxyNodeRenamer2.java (+35 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator.actions;
13
14
import org.eclipse.ltk.core.refactoring.Change;
15
16
/**
17
 * Interface that allows to describe the rename behavior of a proxy node.
18
 * 
19
 * @author jgout
20
 * @since 4.4
21
 */
22
public interface IProxyNodeRenamer2 {
23
24
	/**
25
	 * Returns the refactoring change when renaming this instance with the new name.
26
	 * The given context can be used if the local change cannot be perform without a global context.
27
	 * This can be performed using an IRefactoringTransaction (retrieved by its domain Id) to collect 
28
	 * data. Such refactoring transaction will performed changes in one time.
29
	 *   
30
	 * @param context a context that contains all IRefactoringTransaction instances defined by clients.
31
	 * @param newName the new name of this proxy node.
32
	 * @return the change that performs the rename of the proxy node using the given new name.
33
	 */
34
	public Change createRenameChange(IRefactoringContext context, String newName);
35
}
(-)schema/testNavigatorRefactoringTransactions.exsd (+124 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.hyades.test.ui">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.hyades.test.ui" id="testNavigatorRefactoringTransactions" name="Test Navigator Refactoring Transactions"/>
7
      </appInfo>
8
      <documentation>
9
         Test navigator supports refactoring for actions such as Move or Rename.
10
Those refactoring operations are based upon the references stored in &lt;code&gt;org.eclipse.hyades.test.ui.navigator.IReferencerProxyNode&lt;/code&gt;. That allows to propagate move or rename refactoring operations on several linked elements (e.g. Test logs and the test that produced them).
11
Such operations may follow a transactional behavior, in the sense that all derived changes of operations may need to be performed in a global common context (e.g a common ResourceSet for changing EMF links).
12
This extension point allows clients to define a refactoring transaction which is used in those refactoring operations.
13
      </documentation>
14
   </annotation>
15
16
   <element name="extension">
17
      <complexType>
18
         <sequence minOccurs="1" maxOccurs="unbounded">
19
            <element ref="transaction"/>
20
         </sequence>
21
         <attribute name="point" type="string" use="required">
22
            <annotation>
23
               <documentation>
24
                  
25
               </documentation>
26
            </annotation>
27
         </attribute>
28
         <attribute name="id" type="string">
29
            <annotation>
30
               <documentation>
31
                  
32
               </documentation>
33
            </annotation>
34
         </attribute>
35
         <attribute name="name" type="string">
36
            <annotation>
37
               <documentation>
38
                  
39
               </documentation>
40
               <appInfo>
41
                  <meta.attribute translatable="true"/>
42
               </appInfo>
43
            </annotation>
44
         </attribute>
45
      </complexType>
46
   </element>
47
48
   <element name="transaction">
49
      <complexType>
50
         <attribute name="domainId" type="string" use="required">
51
            <annotation>
52
               <documentation>
53
                  The id of the transaction domain. This id should be used to retrieve the &lt;code&gt;org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction&lt;/code&gt; from &lt;code&gt;org.eclipse.hyades.test.ui.navigator.IRefactoringContext&lt;/code&gt;
54
               </documentation>
55
            </annotation>
56
         </attribute>
57
         <attribute name="class" type="string" use="required">
58
            <annotation>
59
               <documentation>
60
                  Instance of &lt;code&gt;org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction&lt;/code&gt;.
61
               </documentation>
62
               <appInfo>
63
                  <meta.attribute kind="java" basedOn="org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction"/>
64
               </appInfo>
65
            </annotation>
66
         </attribute>
67
      </complexType>
68
   </element>
69
70
   <annotation>
71
      <appInfo>
72
         <meta.section type="since"/>
73
      </appInfo>
74
      <documentation>
75
         4.3
76
      </documentation>
77
   </annotation>
78
79
   <annotation>
80
      <appInfo>
81
         <meta.section type="examples"/>
82
      </appInfo>
83
      <documentation>
84
         &lt;pre&gt;
85
       &lt;extension
86
             point=&quot;org.eclipse.hyades.test.ui.testNavigatorRefactoringTransactions&quot;&gt;
87
          &lt;transaction
88
                class=&quot;org.eclipse.hyades.test.ui.internal.navigator.refactoring.EMFRefactoringTransaction&quot;
89
                domainId=&quot;org.eclipse.hyades.test.ui.EMFRefactoringTransaction&quot;/&gt;
90
       &lt;/extension&gt;
91
&lt;/pre&gt;
92
      </documentation>
93
   </annotation>
94
95
   <annotation>
96
      <appInfo>
97
         <meta.section type="apiInfo"/>
98
      </appInfo>
99
      <documentation>
100
         Instances used in the class attribute should implement  &lt;code&gt;org.eclipse.hyades.test.ui.navigator.IRefactoringTransaction&lt;/code&gt;.
101
      </documentation>
102
   </annotation>
103
104
   <annotation>
105
      <appInfo>
106
         <meta.section type="implementation"/>
107
      </appInfo>
108
      <documentation>
109
         
110
      </documentation>
111
   </annotation>
112
113
   <annotation>
114
      <appInfo>
115
         <meta.section type="copyright"/>
116
      </appInfo>
117
      <documentation>
118
         Copyright (c) 2006 IBM Corporation and others.&lt;br&gt;
119
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at
120
&lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
121
      </documentation>
122
   </annotation>
123
124
</schema>
(-)src/org/eclipse/hyades/test/ui/navigator/actions/IProxyNodeDeleter.java (+26 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator.actions;
13
14
import org.eclipse.ltk.core.refactoring.Change;
15
16
/**
17
 * Interface that allows to describe the delete behavior of a proxy node.
18
 * 
19
 * @author jgout
20
 * @since 4.4
21
 */
22
public interface IProxyNodeDeleter {
23
24
	public Change createDeleteChange(IRefactoringContext context);
25
26
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/proxy/reference/IReferenceRegistrySavedState.java (+35 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.proxy.reference;
13
14
import org.eclipse.core.runtime.IPath;
15
16
/**
17
 * Generic interface that provides the common feature of Eclipse ISavedState
18
 * and ISaveContext methods. It provides a lookup feature for retrieving the
19
 * real file associated to a symbolic file in a given save state.
20
 * @author jcanches
21
 * @see org.eclipse.core.resources.ISavedState
22
 * @see org.eclipse.core.resources.ISaveContext
23
 * @since 4.3
24
 */
25
public interface IReferenceRegistrySavedState {
26
27
28
	/**
29
	 * @see org.eclipse.core.resources.ISavedState#lookup(org.eclipse.core.runtime.IPath)
30
	 * @see org.eclipse.core.resources.ISaveContext#lookup(org.eclipse.core.runtime.IPath)
31
	 */
32
	public IPath lookup(IPath path);
33
		
34
35
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/FileAndFolderPaster.java (+109 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.action;
13
14
import java.util.LinkedList;
15
16
import org.eclipse.core.resources.IContainer;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFolder;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.hyades.test.ui.UiPlugin;
22
import org.eclipse.hyades.test.ui.internal.navigator.proxy.FileProxyNodeCache;
23
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.IPasterExtended;
24
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.PasteRefactoring;
25
import org.eclipse.hyades.test.ui.internal.navigator.refactoring.PasteRefactoringWizard;
26
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
27
import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
28
import org.eclipse.swt.dnd.Clipboard;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.ui.part.ResourceTransfer;
31
32
public class FileAndFolderPaster implements IPasterExtended {
33
34
	private LinkedList folders;
35
	private LinkedList proxies;
36
	private Clipboard clipboard;
37
	private Shell shell;
38
39
	public FileAndFolderPaster() {
40
		folders = new LinkedList();
41
		clipboard = null;
42
		proxies = new LinkedList();
43
		shell = null;
44
	}
45
	
46
	public boolean isPasteAllowedFor(Clipboard clipboard, Object selection) {		
47
		return (selection instanceof IContainer);
48
	}
49
50
	public void setShell(Shell shell) {
51
		this.shell = shell;
52
	}
53
	
54
	private void sortClipboardElements() {
55
		folders.clear();
56
		proxies.clear();
57
		IResource [] res = getResourceFromClipboard();
58
		for (int i=0; i<res.length; i++) {
59
			if (res[i] instanceof IFile) {
60
				IProxyNode proxy = FileProxyNodeCache.getInstance().getProxy((IFile)res[i]);
61
				if (proxy != null) {
62
					proxies.add(proxy);
63
				}				
64
			} else if (res[i] instanceof IAdaptable) {
65
				IAdaptable a = (IAdaptable) res[i];
66
				Object o = a.getAdapter(IFolder.class);
67
				if(o != null) {
68
					folders.add((IFolder) o);
69
				}
70
			}
71
		}
72
	}
73
	
74
	
75
	private IResource [] getResourceFromClipboard() {
76
		final IResource[][] clipboardData = new IResource[1][];
77
		shell.getDisplay().syncExec(new Runnable() {
78
			public void run() {
79
				//- clipboard must have resources or files
80
				ResourceTransfer resTransfer = ResourceTransfer.getInstance();
81
				clipboardData[0] = (IResource[]) clipboard.getContents(resTransfer);
82
			}
83
		});
84
		return clipboardData[0];
85
	}
86
	
87
	private boolean canActivate(Shell shell) {
88
		return EditorUtil.saveEditors(shell);
89
	}
90
	
91
	public boolean performPaste(Clipboard clipboard, Object selection) {
92
		if (! canActivate(shell))
93
			return false;
94
		this.clipboard = clipboard;
95
		sortClipboardElements();
96
		PasteRefactoring refactoring = new PasteRefactoring(folders,proxies);
97
		PasteRefactoringWizard wizard = new PasteRefactoringWizard(refactoring,selection);
98
		wizard.setDefaultPageTitle(ActionMessages.PASTE_ACTION_NAME);
99
		wizard.setNeedsProgressMonitor(true);
100
		RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
101
		try {
102
			op.run(shell , ""); //$NON-NLS-1$
103
		} catch (InterruptedException e) {
104
			UiPlugin.logError(e);
105
		}
106
		return true;
107
	}
108
109
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/DeleteContainerCompositeChange.java (+34 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.ltk.core.refactoring.Change;
16
import org.eclipse.osgi.util.NLS;
17
18
public class DeleteContainerCompositeChange extends ReorgContainerCompositeChange {
19
	private DeleteContainerChange delChange;
20
	
21
	public DeleteContainerCompositeChange(IContainer container) {
22
		super(NLS.bind(RefactoringMessages.DELETE_FOLDER, container.getFullPath().toOSString()), container);
23
		delChange = new DeleteContainerChange(container);
24
	}
25
26
	public Change getDeleteContainerChange() {
27
		return delChange;
28
	}
29
30
	public Change getRootChange() {
31
		return delChange;
32
	}
33
	
34
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteFolderChange.java (+98 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2008 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IWorkspaceRoot;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.SubProgressMonitor;
24
import org.eclipse.hyades.test.ui.UiPlugin;
25
import org.eclipse.hyades.test.ui.internal.navigator.TestNavigatorMessages;
26
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
27
import org.eclipse.osgi.util.NLS;
28
29
/**
30
 * change to apply to perform a folder paste
31
 * 
32
 * @author jbozier
33
 * @since 4.5
34
 */
35
36
// TODO : real similar to move, check if we can simplify this
37
public class PasteFolderChange extends ReorgContainerChange {
38
	private IPath destPath;
39
	private IPath targetPath;
40
	private RefactoringStatus status;
41
42
	public PasteFolderChange(IFolder folder, IPath destPath,IPath [] finalPath) {
43
		super(folder);
44
		this.destPath = destPath;
45
		this.status = new RefactoringStatus();
46
		this.targetPath = handleFolderAlreadyExists(folder,destPath);
47
		if ((finalPath != null) && (finalPath.length > 0)) {
48
			finalPath[0] = targetPath;
49
		}
50
	}
51
52
	// update target path in case of conflict
53
	private IPath handleFolderAlreadyExists(IFolder folder, IPath destPath) {
54
		IPath path = destPath.append(folder.getName());
55
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
56
		if ((root.getFolder(path).exists()) || (root.getFile(path).exists())) {
57
			boolean done = false;		
58
			String folderName = path.lastSegment();
59
			String ret = null;
60
			String newName = null;
61
			for (int i=0; (!done); i++) {
62
				 if (i != 0) {
63
					 newName = NLS.bind(TestNavigatorMessages.FileFolderInContainerPaste_NameTwoArg,new Integer(i),folderName);
64
				 } else {
65
					 newName = NLS.bind(TestNavigatorMessages.FileFolderInContainerPaste_NameOneArg,folderName);					 
66
				 }
67
				 ret = path.removeLastSegments(1).append(newName).toPortableString();
68
				 IPath newpath = new Path(ret);
69
				 done = (!root.getFolder(newpath).exists()) && (!root.getFile(newpath).exists());
70
			}
71
			path = destPath.append(newName);
72
		} 
73
		return path;
74
	}
75
	
76
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
77
		return this.status;
78
	}
79
	
80
	public IPath getDestinationPath() {
81
		return destPath;
82
	}
83
	
84
	public String getName() {
85
		IPath path = getPath().removeFirstSegments(ResourcesPlugin.getWorkspace().getRoot().getFullPath().segmentCount());
86
		return NLS.bind(RefactoringMessages.PASTE_FOLDER, path.toOSString(), targetPath.toOSString());
87
	}
88
89
	public void reorgFolder(IContainer container, SubProgressMonitor monitor) {
90
		try {
91
			container.copy(targetPath, 0, monitor);
92
			container.refreshLocal(IResource.DEPTH_INFINITE, monitor);
93
		} catch (CoreException e) {
94
			UiPlugin.logError("Unable to copy container", e); //$NON-NLS-1$
95
		}
96
	}
97
98
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/action/EditorUtil.java (+148 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.action;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.HashSet;
17
import java.util.List;
18
import java.util.Set;
19
20
import org.eclipse.core.resources.IWorkspace;
21
import org.eclipse.core.resources.IWorkspaceDescription;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.NullProgressMonitor;
25
import org.eclipse.hyades.test.ui.UiPlugin;
26
import org.eclipse.hyades.test.ui.internal.dialog.ListDialog;
27
import org.eclipse.hyades.ui.adapter.ISynchronizedEditorAdapter;
28
import org.eclipse.hyades.ui.editor.IEditorExtension;
29
import org.eclipse.hyades.ui.internal.editor.HyadesEditorPart;
30
import org.eclipse.jface.viewers.ArrayContentProvider;
31
import org.eclipse.jface.viewers.ILabelProvider;
32
import org.eclipse.jface.viewers.LabelProvider;
33
import org.eclipse.jface.window.Window;
34
import org.eclipse.swt.graphics.Image;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Shell;
38
import org.eclipse.ui.IEditorInput;
39
import org.eclipse.ui.IEditorPart;
40
import org.eclipse.ui.IWorkbench;
41
import org.eclipse.ui.IWorkbenchPage;
42
import org.eclipse.ui.IWorkbenchWindow;
43
import org.eclipse.ui.PlatformUI;
44
45
public class EditorUtil {
46
	
47
	/**
48
	 * Saves all modified editors.
49
	 * @param shell
50
	 * @return <code>true</code> if all saves have been successfully performed and <code>false</code> otherwise. 
51
	 */
52
	public static boolean saveEditors(Shell shell) {
53
		IEditorPart[] dirtyEditors= getDirtyEditors();
54
		if (dirtyEditors.length == 0)
55
			return true;
56
		if (! saveAllDirtyEditors(shell, dirtyEditors))
57
			return false;
58
		try {
59
			// Save isn't cancelable.
60
			IWorkspace workspace= ResourcesPlugin.getWorkspace();
61
			IWorkspaceDescription description= workspace.getDescription();
62
			boolean autoBuild= description.isAutoBuilding();
63
			description.setAutoBuilding(false);
64
			workspace.setDescription(description);
65
			try {
66
				for (int i = 0; i < dirtyEditors.length; i++) {
67
					IEditorPart part = dirtyEditors[i];
68
					if (part instanceof HyadesEditorPart) {
69
						HyadesEditorPart hyadesEditor = (HyadesEditorPart) part;
70
						hyadesEditor.doSave(new NullProgressMonitor());
71
						IEditorExtension extension = hyadesEditor.getEditorExtension();
72
						if (extension instanceof ISynchronizedEditorAdapter) {
73
							((ISynchronizedEditorAdapter) extension).reload();
74
						}
75
					}
76
				}
77
				if (!UiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getWorkbench().saveAllEditors(false))
78
					return false;
79
			} finally {
80
				description.setAutoBuilding(autoBuild);
81
				workspace.setDescription(description);
82
			}
83
			return true;
84
		} catch (CoreException e) {
85
			UiPlugin.logError("Unable to save modified resources", e); //$NON-NLS-1$
86
			return false;
87
		}
88
	}
89
90
	private static boolean saveAllDirtyEditors(Shell shell, IEditorPart[] dirtyEditors) {
91
		ListDialog dialog= new ListDialog(shell) {
92
			protected Control createDialogArea(Composite parent) {
93
				Composite result= (Composite) super.createDialogArea(parent);
94
				applyDialogFont(result);
95
				return result;
96
			}
97
		};
98
		dialog.setTitle(ActionMessages.SAVE_ALL_DIALOG_NAME); 
99
		dialog.setAddCancelButton(true);
100
		dialog.setLabelProvider(createDialogLabelProvider());
101
		dialog.setMessage(ActionMessages.SAVE_ALL_DIALOG_MESSAGE); 
102
		dialog.setContentProvider(new ArrayContentProvider());
103
		dialog.setInput(Arrays.asList(dirtyEditors));
104
		return dialog.open() == Window.OK;
105
	}
106
	
107
	private static ILabelProvider createDialogLabelProvider() {
108
		return new LabelProvider() {
109
			public Image getImage(Object element) {
110
				return ((IEditorPart) element).getTitleImage();
111
			}
112
			public String getText(Object element) {
113
				return ((IEditorPart) element).getTitle();
114
			}
115
		};
116
	}	
117
	
118
	/**
119
	 * Returns an array of all editors that have an unsaved content. If the identical content is 
120
	 * presented in more than one editor, only one of those editor parts is part of the result.
121
	 * (Copied from jdt internal)
122
	 * 
123
	 * @return an array of all dirty editor parts.
124
	 */
125
	private static IEditorPart[] getDirtyEditors() {
126
		Set inputs= new HashSet();
127
		List result= new ArrayList(0);
128
		IWorkbench workbench= PlatformUI.getWorkbench();
129
		IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
130
		for (int i= 0; i < windows.length; i++) {
131
			IWorkbenchPage[] pages= windows[i].getPages();
132
			for (int x= 0; x < pages.length; x++) {
133
				IEditorPart[] editors= pages[x].getDirtyEditors();
134
				for (int z= 0; z < editors.length; z++) {
135
					IEditorPart ep= editors[z];
136
					if (ep instanceof HyadesEditorPart) {
137
						IEditorInput input= ep.getEditorInput();
138
						if (!inputs.contains(input)) {
139
							inputs.add(input);
140
							result.add(ep);
141
						}
142
					}
143
				}
144
			}
145
		}
146
		return (IEditorPart[])result.toArray(new IEditorPart[result.size()]);
147
	}
148
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/MoveRefactoringWizard.java (+158 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import java.util.Collection;
15
import java.util.HashSet;
16
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.core.resources.IContainer;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.hyades.test.ui.navigator.IProxyNode;
24
import org.eclipse.jface.dialogs.Dialog;
25
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.ISelectionChangedListener;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.viewers.SelectionChangedEvent;
29
import org.eclipse.jface.viewers.TreeViewer;
30
import org.eclipse.ltk.core.refactoring.Refactoring;
31
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
32
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
33
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
34
import org.eclipse.osgi.util.NLS;
35
import org.eclipse.swt.SWT;
36
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Control;
40
import org.eclipse.swt.widgets.Label;
41
import org.eclipse.ui.model.BaseWorkbenchContentProvider;
42
import org.eclipse.ui.model.WorkbenchLabelProvider;
43
44
public class MoveRefactoringWizard extends RefactoringWizard {
45
	
46
	private static class MoveRefactoringInputPage extends UserInputWizardPage {
47
		private MoveRefactoring refactoring;
48
		private TreeViewer viewer;
49
		
50
		public MoveRefactoringInputPage(Refactoring ref) {
51
			super(""); //$NON-NLS-1$
52
			this.refactoring = (MoveRefactoring) ref;
53
		}
54
55
		public void createControl(Composite parent) {
56
			initializeDialogUnits(parent);
57
			Composite result= new Composite(parent, SWT.NONE);
58
			setControl(result);
59
			result.setLayout(new GridLayout());
60
			
61
			addLabel(result);
62
			viewer = createViewer(result);
63
			expandSelectionContainer();
64
			viewer.addSelectionChangedListener(new ISelectionChangedListener(){
65
				public void selectionChanged(SelectionChangedEvent event) {
66
					MoveRefactoringInputPage.this.viewerSelectionChanged(event);
67
				}
68
			});
69
			Dialog.applyDialogFont(result);
70
		}
71
		
72
		private void expandSelectionContainer() {
73
			Collection containers = refactoring.getContainers();
74
			Collection proxies = refactoring.getProxies();
75
			Collection parents = new HashSet();
76
			for (Iterator it = containers.iterator(); it.hasNext();) {
77
				parents.add(((IContainer) it.next()).getParent());
78
			}
79
			for (Iterator it = proxies.iterator(); it.hasNext();) {
80
				parents.add(((IProxyNode) it.next()).getUnderlyingResource().getParent());
81
			}
82
			for (Iterator it = parents.iterator(); it.hasNext();) {
83
				viewer.expandToLevel(it.next(), 0);
84
			}
85
		}
86
87
		protected Control addLabel(Composite parent) {
88
			Label label= new Label(parent, SWT.NONE);
89
			String text;
90
			int containers= refactoring.getContainers().size();
91
			int proxies= refactoring.getProxies().size();
92
93
			if (containers == 0 && proxies == 1) {
94
				text= NLS.bind(RefactoringMessages.MOVE_CHOOSE_DESTINATION_SINGLE, ((IProxyNode)refactoring.getProxies().get(0)).getText());
95
			} else if (containers == 1 && proxies == 0) {
96
				text= NLS.bind(RefactoringMessages.MOVE_CHOOSE_DESTINATION_SINGLE, ((IResource)refactoring.getContainers().get(0)).getName());
97
			} else {
98
				text= NLS.bind(RefactoringMessages.MOVE_CHOOSE_DESTINATION_MULTI, String.valueOf(containers + proxies));
99
			}
100
			label.setText(text);
101
			label.setLayoutData(new GridData(SWT.BEGINNING, SWT.END, false, false));
102
			return label;
103
		}
104
		
105
		private TreeViewer createViewer(Composite parent) {
106
			TreeViewer treeViewer= new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
107
			GridData gd= new GridData(GridData.FILL_BOTH);
108
			gd.widthHint= convertWidthInCharsToPixels(40);
109
			gd.heightHint= convertHeightInCharsToPixels(15);
110
			treeViewer.getTree().setLayoutData(gd);
111
			BaseWorkbenchContentProvider provider = new BaseWorkbenchContentProvider() {
112
				public Object[] getChildren(Object element) {
113
					Object[] children = super.getChildren(element);
114
					List resChildren = new LinkedList();
115
					for (int i = 0; i < children.length; i++) {
116
						if (children[i] instanceof IContainer) {
117
							resChildren.add(children[i]);
118
						}
119
					}
120
					return resChildren.toArray();
121
				}
122
			};
123
			treeViewer.setLabelProvider(new WorkbenchLabelProvider());
124
			treeViewer.setContentProvider(provider);
125
			treeViewer.setSorter(null);
126
			treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
127
			return treeViewer;
128
		}
129
130
		private void viewerSelectionChanged(SelectionChangedEvent event) {
131
			ISelection selection= event.getSelection();
132
			if (!(selection instanceof IStructuredSelection))
133
				return;
134
			IStructuredSelection sel= (IStructuredSelection)selection;
135
			setPageComplete(verifyDestination(sel.getFirstElement()));
136
		}
137
138
		protected RefactoringStatus verifyDestination(Object selected) {
139
			RefactoringStatus refactoringStatus = new RefactoringStatus();
140
			if (selected instanceof IContainer)
141
				refactoring.setDestination((IContainer)selected);
142
			else {
143
				refactoringStatus= RefactoringStatus.createFatalErrorStatus(RefactoringMessages.MOVE_ERROR); 
144
			}
145
			return refactoringStatus;
146
		}
147
148
	}
149
	
150
	public MoveRefactoringWizard(Refactoring refactoring) {
151
		super(refactoring, DIALOG_BASED_USER_INTERFACE | NONE);
152
	}
153
	
154
	protected void addUserInputPages() {
155
		MoveRefactoringInputPage page = new MoveRefactoringInputPage(getRefactoring());
156
		addPage(page);
157
	}
158
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/IRefactoringRenamer.java (+22 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
/**
15
 * Interface that allows client to implement rename using refactoring mechanism.
16
 * 
17
 * @author jgout
18
 * @since 4.3
19
 */
20
public interface IRefactoringRenamer {
21
22
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/MoveFolderChange.java (+60 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IFolder;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.OperationCanceledException;
21
import org.eclipse.core.runtime.SubProgressMonitor;
22
import org.eclipse.hyades.test.ui.UiPlugin;
23
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
24
import org.eclipse.osgi.util.NLS;
25
26
public class MoveFolderChange extends ReorgContainerChange {
27
	protected IPath destPath;
28
29
	public MoveFolderChange(IFolder folder, IPath destPath) {
30
		super(folder);
31
		this.destPath = destPath;
32
	}
33
34
	public IPath getDestinationPath() {
35
		return destPath;
36
	}
37
	
38
	public String getName() {
39
		IPath path = getPath().removeFirstSegments(ResourcesPlugin.getWorkspace().getRoot().getFullPath().segmentCount());
40
		return NLS.bind(RefactoringMessages.MOVE_FOLDER, path.toOSString(), destPath.toOSString());
41
	}
42
43
	public void reorgFolder(IContainer container, SubProgressMonitor monitor) {
44
		try {
45
			container.move(destPath.append(container.getName()), false, monitor);
46
		} catch (CoreException e) {
47
			UiPlugin.logError("Unable to move container", e); //$NON-NLS-1$
48
		}
49
	}
50
51
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
52
		RefactoringStatus status = new RefactoringStatus();
53
		IFolder folder = (IFolder) getModifiedElement();
54
		if(!folder.isAccessible()) {
55
			status.addFatalError(RefactoringMessages.NO_FOLDER);
56
		}
57
		return super.isValid(pm);
58
	}
59
60
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/LaunchConfigurationDeleteChange.java (+52 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.OperationCanceledException;
17
import org.eclipse.debug.core.ILaunchConfiguration;
18
import org.eclipse.ltk.core.refactoring.Change;
19
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
20
import org.eclipse.osgi.util.NLS;
21
22
public class LaunchConfigurationDeleteChange extends Change {
23
24
	private ILaunchConfiguration config;
25
	
26
	public LaunchConfigurationDeleteChange(ILaunchConfiguration config) {
27
		super();
28
		this.config = config;
29
	}
30
31
	public Object getModifiedElement() {
32
		return this.config;
33
	}
34
35
	public String getName() {
36
		return NLS.bind(RefactoringMessages.LaunchConfigurationDeleteChange_NAME, config.getName());
37
	}
38
39
	public void initializeValidationData(IProgressMonitor pm) {
40
	}
41
42
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
43
		RefactoringStatus status = new RefactoringStatus();
44
		return status;
45
	}
46
47
	public Change perform(IProgressMonitor pm) throws CoreException {
48
		config.delete();
49
		return null;
50
	}
51
52
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/CompositeChangeWithRoot.java (+119 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.SubProgressMonitor;
18
import org.eclipse.ltk.core.refactoring.Change;
19
import org.eclipse.ltk.core.refactoring.CompositeChange;
20
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
21
22
public class CompositeChangeWithRoot extends CompositeChange {
23
	private Change root;
24
	private String name;
25
26
	public CompositeChangeWithRoot(Change root) {
27
		super(""); //$NON-NLS-1$
28
		Assert.isNotNull(root);
29
		this.root = root;
30
	}
31
	
32
	public CompositeChangeWithRoot(Change root, String name) {
33
		super(name);
34
		//- in this constructor, root can be null 
35
		this.root = root;
36
		if(root == null) {
37
			Assert.isLegal(name != null && name.length() > 0, "Empty name with null root"); //$NON-NLS-1$
38
			this.name = name;
39
		}
40
	}
41
42
//	public Change perform(IProgressMonitor pm) throws CoreException {
43
//		CompositeChange change = new CompositeChange(""); //$NON-NLS-1$
44
//		Change undoChildren = super.perform(pm);
45
//		if (undoChildren != null) {
46
//			change.add(undoChildren);
47
//		}
48
//		if (root != null) {
49
//			Change undoRoot = root.perform(pm);
50
//			if (undoRoot != null) {
51
//				change.add(undoRoot);
52
//			}
53
//		}			
54
//		return change;
55
//	}
56
57
	public String getName() {
58
		return root != null ? root.getName() : name;
59
	}
60
61
	public Change freeze() {
62
		if(getChildren().length == 0) {
63
			return root;
64
		}
65
		if (root instanceof CompositeChange) {
66
			merge((CompositeChange)root);
67
		} else {
68
			add(root);
69
		}
70
		
71
		return this;
72
//		if (root instanceof CompositeChange) {
73
//			freeze((CompositeChange)root);
74
//			merge((CompositeChange)root);
75
//			if (root instanceof CompositeChangeWithRoot) {
76
//				root = ((CompositeChangeWithRoot)root).root;
77
//			}
78
//		}
79
//		if(getChildren().length == 0) {
80
//			return root;
81
//		}
82
//		freezeSimpleCompositeChange(this);
83
//		return this;
84
	}
85
	
86
//	private static void freezeSimpleCompositeChange(CompositeChange change) {
87
//		for (int i = 0; i < change.getChildren().length; i++) {
88
//			Change child = change.getChildren()[i];
89
//			Change newChild = child;
90
//			if (child instanceof CompositeChange) {
91
//				newChild = freeze(((CompositeChange)child));
92
//			}
93
//			change.remove(child);
94
//			change.add(newChild);
95
//		}
96
//	}
97
//	
98
//	public static Change freeze(CompositeChange change) {
99
//		if (change instanceof CompositeChangeWithRoot) {
100
//			return ((CompositeChangeWithRoot)change).freeze();
101
//		}
102
//		freezeSimpleCompositeChange(change);
103
//		return change;
104
//	}
105
106
	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
107
		pm.beginTask("", getChildren().length+1); //$NON-NLS-1$
108
		try {
109
			RefactoringStatus status = super.isValid(new SubProgressMonitor(pm, getChildren().length));
110
			if (root != null) {
111
				status.merge(root.isValid(new SubProgressMonitor(pm, 1)));
112
			}
113
			return status;
114
		} finally {
115
			pm.done();
116
		}
117
	}
118
119
}
(-)src/org/eclipse/hyades/test/ui/navigator/IRefactoringTransaction.java (+50 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.ltk.core.refactoring.Change;
17
18
/**
19
 * Some refactoring operations need to perform its change in a global context.
20
 * This interface allows to declare contexts for grouping refactoring change.
21
 * This interface is used in the extension point 
22
 * <code>org.eclipse.hyades.test.ui.testNavigatorRefactoringTransactions</code>.
23
 * 
24
 * @author jgout
25
 * @since 4.4
26
 */
27
public interface IRefactoringTransaction {
28
29
	/**
30
	 * Starts the refactogring transaction.
31
	 * Implementors can use this method to initialize internal data.
32
	 * @param pm a progress monitor, or <code>null</code> if progress reporting is not desired.
33
	 */
34
	public void beginChanges(IProgressMonitor pm);
35
36
	/**
37
	 * Method called if the transaction is cancelled.
38
	 * Implementors can use this method to dispose internal data.
39
	 * @param pm a progress monitor, or <code>null</code> if progress reporting is not desired.
40
	 */
41
	public void cancelChanges(IProgressMonitor pm);
42
43
	/**
44
	 * Performs changes.
45
	 * @return the undo change that is composed of all committed changes or <code>null</code> if undo change is not possible.
46
	 * @param pm a progress monitor, or <code>null</code> if progress reporting is not desired.
47
	 * @throws <code>CoreException</code> if the operation failed.
48
	 */
49
	public Change commitChanges(IProgressMonitor pm) throws CoreException;
50
}
(-)src/org/eclipse/hyades/test/ui/navigator/actions/IProxyNodeMover.java (+36 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.navigator.actions;
13
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.ltk.core.refactoring.Change;
16
17
/**
18
 * Interface that allows to describe the move behavior of a proxy node.
19
 * 
20
 * @author jgout
21
 * @since 4.4
22
 */
23
public interface IProxyNodeMover {
24
25
	/**
26
	 * Returns the refactoring change when moving this instance to the new destination path.
27
	 * The given context can be used if the local change cannot be perform without a global context.
28
	 * This can be performed using an IRefactoringTransaction (retrieved by its domain Id) to collect 
29
	 * data. Such refactoring transaction will performed changes in one time.
30
	 *   
31
	 * @param context a context that contains all IRefactoringTransaction instances defined by clients.
32
	 * @param newPath the destination path of this proxy node.
33
	 * @return the change that performs the move of the proxy node to the given destination path.
34
	 */
35
	public Change createMoveChange(IRefactoringContext context, IPath destinationPath);
36
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/PasteRefactoringWizard.java (+31 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.ltk.core.refactoring.Refactoring;
16
import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
17
18
public class PasteRefactoringWizard extends RefactoringWizard {
19
	
20
	public PasteRefactoringWizard(Refactoring refactoring,Object selected) {
21
		super(refactoring, DIALOG_BASED_USER_INTERFACE | NONE);
22
23
		PasteRefactoring ref = (PasteRefactoring) getRefactoring();
24
		ref.setDestination((IContainer)selected);
25
26
	}
27
	
28
	protected void addUserInputPages() {	
29
	}
30
	
31
}
(-)src/org/eclipse/hyades/test/ui/internal/navigator/refactoring/ReorgContainerCompositeChange.java (+69 lines)
Added Link Here
1
/********************************************************************** 
2
 * Copyright (c) 2006 IBM Corporation and others. 
3
 * All rights reserved.   This program and the accompanying materials 
4
 * are made available under the terms of the Eclipse Public License v1.0 
5
 * which accompanies this distribution, and is available at 
6
 * http://www.eclipse.org/legal/epl-v10.html 
7
 * $Id: $ 
8
 * 
9
 * Contributors: 
10
 * IBM - Initial API and implementation 
11
 **********************************************************************/
12
package org.eclipse.hyades.test.ui.internal.navigator.refactoring;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.ltk.core.refactoring.Change;
18
import org.eclipse.ltk.core.refactoring.CompositeChange;
19
20
/**
21
 * Abstract class for handling move and delete of a container.
22
 * The resulted change has a root change (move or delete of the folder itself) and children
23
 * whose are move or delete of each container member.
24
 * 
25
 * @author jgout
26
 * @since 4.3
27
 * 
28
 */
29
public abstract class ReorgContainerCompositeChange extends CompositeChange {
30
	private IContainer container;
31
	private Change rootChange;
32
	
33
	public ReorgContainerCompositeChange(String name, IContainer container) {
34
		super(name);
35
		this.container = container;
36
	}
37
	
38
	public Object getModifiedElement() {
39
		return container;
40
	}
41
	
42
	public abstract Change getRootChange();
43
44
	public Change perform(IProgressMonitor pm) throws CoreException {
45
		//- if one of children is not enabled, we do not perform on root
46
		boolean needToPerform = true;
47
		Change[] children = getChildren();
48
		for (int i = 0; i < children.length; i++) {
49
			needToPerform &= ((Change)children[i]).isEnabled();
50
		}
51
		super.perform(pm);
52
		if(needToPerform) {
53
			if (rootChange == null) {
54
				rootChange = getRootChange();
55
			}
56
			rootChange.perform(pm);
57
		}
58
		//- no undo available.
59
		return null; 
60
	}
61
62
	public String getName() {
63
		if(rootChange == null) {
64
			rootChange = getRootChange();
65
		}
66
		return rootChange.getName();
67
	}
68
69
}
(-)src/org/eclipse/hyades/test/core/launch/configurations/TestLaunchConfigurationFacade.java (-2 / +27 lines)
Lines 4-10 Link Here
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * $Id: TestLaunchConfigurationFacade.java,v 1.10 2007/05/03 02:23:44 paules Exp $
7
 * $Id: TestLaunchConfigurationFacade.java,v 1.7 2006/05/19 15:44:10 mddunn Exp $
8
 * 
8
 * 
9
 * Contributors:
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
10
 *     IBM Corporation - initial API and implementation
Lines 16-21 Link Here
16
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.debug.core.ILaunchConfiguration;
17
import org.eclipse.debug.core.ILaunchConfigurationType;
17
import org.eclipse.debug.core.ILaunchConfigurationType;
18
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.resource.ResourceSet;
21
import org.eclipse.emf.ecore.resource.ResourceSet;
21
import org.eclipse.hyades.models.common.testprofile.TPFTest;
22
import org.eclipse.hyades.models.common.testprofile.TPFTest;
Lines 100-106 Link Here
100
	/**
101
	/**
101
	 * Validates a Test launch configuration.
102
	 * Validates a Test launch configuration.
102
	 * The validation is performed by the validator registered in the extension registry
103
	 * The validation is performed by the validator registered in the extension registry
103
	 * using the extension point <code>org.eclipse.hyades.test.core.launchconfigValidator</code>.
104
	 * using the extension point <code>org.eclipse.hyades.test.core.launchConfigValidator</code>.
104
	 * @param configuration A launch configuration.
105
	 * @param configuration A launch configuration.
105
	 * @param resourceSet The resource set that should be used for loading EMF objects,
106
	 * @param resourceSet The resource set that should be used for loading EMF objects,
106
	 * if required.
107
	 * if required.
Lines 135-138 Link Here
135
        return createOKDiagnostic();
136
        return createOKDiagnostic();
136
	}
137
	}
137
	
138
	
139
	/**
140
	 * Returns whether a test launch configuration references a test that has a given URI.
141
	 * @param configuration A test launch configuration.
142
	 * @param uri A URI to compare to.
143
	 * @return <code>true</code> if the test launch configuration references a test with the
144
	 * same URI as <code>uri</code>.
145
	 * @throws CoreException
146
	 */
147
	public static boolean isTestURI(ILaunchConfiguration configuration, URI uri) throws CoreException {
148
		return isSameURI(configuration, PROPERTY_TEST, uri);
149
	}
150
	
151
	/**
152
	 * Updates a test launch configuration by changing its test URI.
153
	 * This API is provided for refactor use cases when a test URI is changed. If the
154
	 * launch configuration's test must be changed, use {@link #setTest(ILaunchConfigurationWorkingCopy, TPFTest)}
155
	 * instead.
156
	 * @param configuration A test launch configuration.
157
	 * @param newURI The new URI of the test.
158
	 * @throws CoreException
159
	 */
160
	public static void updateTestURI(ILaunchConfigurationWorkingCopy configuration, URI newURI) throws CoreException {
161
		updateURI(configuration, PROPERTY_TEST, newURI);
162
	}
138
}
163
}
(-)src/org/eclipse/hyades/test/core/launch/configurations/AbstractLaunchConfigurationFacade.java (-2 / +34 lines)
Lines 72-78 Link Here
72
		} else {
72
		} else {
73
			if (eObject.eResource() == null) {
73
			if (eObject.eResource() == null) {
74
				throw new IllegalArgumentException(
74
				throw new IllegalArgumentException(
75
						"eObject must belong to a resource");
75
						"eObject must belong to a resource"); //$NON-NLS-1$
76
			}
76
			}
77
			uri = eObject.eResource().getURI().toString();
77
			uri = eObject.eResource().getURI().toString();
78
			uriFragment = eObject.eResource().getURIFragment(eObject);
78
			uriFragment = eObject.eResource().getURIFragment(eObject);
Lines 153-159 Link Here
153
					Resource resource = eObject.eResource();
153
					Resource resource = eObject.eResource();
154
					if (resource == null) {
154
					if (resource == null) {
155
						throw new NullPointerException(
155
						throw new NullPointerException(
156
								"Resource object must be non-null");
156
								"Resource object must be non-null"); //$NON-NLS-1$
157
					}
157
					}
158
					uriList.add(eObject.eResource().getURI().toString());
158
					uriList.add(eObject.eResource().getURI().toString());
159
					uriFragmentList.add(eObject.eResource().getURIFragment(
159
					uriFragmentList.add(eObject.eResource().getURIFragment(
Lines 279-283 Link Here
279
		}
279
		}
280
		configuration.setAttribute(property, container);
280
		configuration.setAttribute(property, container);
281
	}
281
	}
282
	
283
	/**
284
	 * Returns whether the given property in a launch configuration is an EMF reference
285
	 * to an object with the same URI as the given URI.
286
	 * @param configuration
287
	 * @param property Name of the property.
288
	 * @param uri The URI to compare to. null is not allowed.
289
	 * @return <code>true</code> if the launch configuration has a property with this name,
290
	 * and if it is an EMF reference to an object with the same URI as <code>uri</code>.
291
	 * @throws CoreException
292
	 */
293
	protected static boolean isSameURI(ILaunchConfiguration configuration, String property, URI uri) throws CoreException {
294
		String uriString = configuration.getAttribute(property
295
				+ PROPERTY_SUFFIX_URI, (String) null);
296
		String uriFragment = configuration.getAttribute(property
297
				+ PROPERTY_SUFFIX_FRAGMENT, (String) null);
298
		return uri.trimFragment().toString().equals(uriString)
299
			&& uri.fragment().equals(uriFragment);
300
	}
301
302
	/**
303
	 * Updates an EMF reference property within a launch configuration by changing its URI.
304
	 * This API is provided for refactor use cases when the URI of a referenced EMF object
305
	 * needs to be updated.
306
	 * @param configuration
307
	 * @param property Name of the property.
308
	 * @param newURI The new URI.
309
	 */
310
	protected static void updateURI(ILaunchConfigurationWorkingCopy configuration, String property, URI newURI) {
311
		configuration.setAttribute(property + PROPERTY_SUFFIX_URI, newURI.trimFragment().toString());
312
		configuration.setAttribute(property + PROPERTY_SUFFIX_FRAGMENT, newURI.fragment());
313
	}
282
314
283
}
315
}

Return to bug 166025