diff --git a/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/CopyObjectAction.java b/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/CopyObjectAction.java index 0836dce5d2..8655127c14 100644 --- a/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/CopyObjectAction.java +++ b/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/CopyObjectAction.java @@ -27,9 +27,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -387,12 +385,21 @@ public class CopyObjectAction { return; } final IPath path = getTestCasePath(newItem, sourceNode); - for (IRepositoryNode testNode : sourceNode.getChildren()) { - Item testItem = testNode.getObject().getProperty().getItem(); - if (!(testItem instanceof ProcessItem)) { - continue; + + if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) { + ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister + .getDefault().getService(ITestContainerProviderService.class); + if (testContainerService != null) { + testContainerService.copyDataFiles(newItem, sourceNode); + for (IRepositoryNode testNode : sourceNode.getChildren()) { + Item testItem = testNode.getObject().getProperty().getItem(); + if (!(testItem instanceof ProcessItem)) { + continue; + } + // testContainerService.copyTestCase(testItem, path, null, false); + testContainerService.copyTestCase(newItem, testItem, path, null, false); + } } - copyTestCase(testItem, path, null, false); } } @@ -427,53 +434,6 @@ public class CopyObjectAction { return true; } - public void copyTestCase(final Item item, final IPath path, final String newName, final boolean isDuplicate) { - final IWorkspaceRunnable op = new IWorkspaceRunnable() { - - @Override - public void run(IProgressMonitor monitor) throws CoreException { - try { - - Item newItem = null; - if (isDuplicate) { - newItem = factory.copy(item, path, newName); - } else { - newItem = factory.copy(item, path, true); - } - if (newItem instanceof ProcessItem) { - RelationshipItemBuilder.getInstance().addOrUpdateItem(newItem); - } - factory.save(newItem); - } catch (PersistenceException e) { - throw new CoreException(new Status(IStatus.ERROR, "org.talend.core.repository", "", e)); - } catch (BusinessException e) { - throw new CoreException(new Status(IStatus.ERROR, "org.talend.core.repository", "", e)); - } - } - }; - IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() { - - @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - try { - ISchedulingRule schedulingRule = workspace.getRoot(); - workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor); - } catch (CoreException e) { - throw new InvocationTargetException(e); - } - - } - }; - try { - new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress); - } catch (InvocationTargetException e) { - ExceptionHandler.process(e); - } catch (InterruptedException e) { - // - } - } - private String getLastestVersion(Set set) { if (set.isEmpty()) { return null; diff --git a/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/DuplicateAction.java b/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/DuplicateAction.java index 044698081c..8ed0beafc8 100644 --- a/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/DuplicateAction.java +++ b/main/plugins/org.talend.core.repository/src/main/java/org/talend/core/repository/ui/actions/DuplicateAction.java @@ -277,24 +277,31 @@ public class DuplicateAction extends AContextualAction { return; } final IPath path = copyObjectAction.getTestCasePath(newItem, sourceNode); - - for (IRepositoryNode testNode : this.sourceNode.getChildren()) { - Item testItem = testNode.getObject().getProperty().getItem(); - if (!(testItem instanceof ProcessItem)) { - continue; + if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) { + ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister + .getDefault().getService(ITestContainerProviderService.class); + if (testContainerService != null) { + testContainerService.copyDataFiles(newItem, sourceNode); + for (IRepositoryNode testNode : this.sourceNode.getChildren()) { + Item testItem = testNode.getObject().getProperty().getItem(); + if (!(testItem instanceof ProcessItem)) { + continue; + } + String initNameValue = "Copy_of_" + testItem.getProperty().getDisplayName(); //$NON-NLS-1$ + String jobNameValue = null; + final TreeSelection selectionInClipboard = (TreeSelection) selection; + ERepositoryObjectType type = ((RepositoryNode) selectionInClipboard.toArray()[0]).getObject() + .getRepositoryObjectType(); + try { + jobNameValue = getDuplicateName((RepositoryNode) testNode, initNameValue, type, selectionInClipboard); + } catch (BusinessException e) { + jobNameValue = ""; //$NON-NLS-1$ + } + testContainerService.copyTestCase(newItem, testItem, path, jobNameValue, true); + } } - String initNameValue = "Copy_of_" + testItem.getProperty().getDisplayName(); //$NON-NLS-1$ - String jobNameValue = null; - final TreeSelection selectionInClipboard = (TreeSelection) selection; - ERepositoryObjectType type = ((RepositoryNode) selectionInClipboard.toArray()[0]).getObject() - .getRepositoryObjectType(); - try { - jobNameValue = getDuplicateName((RepositoryNode) testNode, initNameValue, type, selectionInClipboard); - } catch (BusinessException e) { - jobNameValue = ""; //$NON-NLS-1$ - } - copyObjectAction.copyTestCase(testItem, path, jobNameValue, true); } + } public String getDuplicateName(RepositoryNode node, String value, ERepositoryObjectType type, diff --git a/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/ui/ITestContainerProviderService.java b/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/ui/ITestContainerProviderService.java index 2bc8a520b5..b548184657 100644 --- a/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/ui/ITestContainerProviderService.java +++ b/main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/ui/ITestContainerProviderService.java @@ -27,6 +27,7 @@ import org.talend.core.model.properties.ProcessItem; import org.talend.core.model.repository.ERepositoryObjectType; import org.talend.core.model.repository.IRepositoryViewObject; import org.talend.designer.core.model.utils.emf.talendfile.ProcessType; +import org.talend.repository.model.RepositoryNode; /** * created by hwang on Jan 7, 2015 Detailled comment @@ -79,4 +80,10 @@ public interface ITestContainerProviderService extends IService { public List listExistingTestCases(); public boolean isDuplicateTestCaseOptionSelected(); + + public IPath getWorkspaceTopNodePath(RepositoryNode topLevelNode); + + public void copyTestCase(Item jobItem, Item testItem, IPath path, String newName, boolean isDuplicate); + + public void copyDataFiles(Item newItem, RepositoryNode sourceNode); }