Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-22 09:23:33 +0000
committerEike Stepper2012-09-22 09:23:33 +0000
commit99862da85768d88a0470978a8a91096afc2b391b (patch)
treef7d6eeb34ee3fa293889de182bb150f491ee104e
parent941e96bbe04dfebd8c75e850b201c2024725d31e (diff)
downloadcdo-99862da85768d88a0470978a8a91096afc2b391b.tar.gz
cdo-99862da85768d88a0470978a8a91096afc2b391b.tar.xz
cdo-99862da85768d88a0470978a8a91096afc2b391b.zip
[388928] Develop a resource transfer framework
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388928
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml2
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml2
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.repository/src/org/eclipse/emf/cdo/transfer/spi/repository/RepositoryTransferSystem.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDialog.java72
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDropAdapter.java66
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferDetailsComposite.java67
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferTreeComposite.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/spi/workspace/WorkspaceTransferSystem.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java29
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java145
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMapping.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF4
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java32
16 files changed, 339 insertions, 181 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
index a8fba54208..c00932fe5d 100644
--- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
+++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
@@ -17,7 +17,7 @@
<property name="overrideUUID" value=""/>
<property name="supportingAudits" value="true"/>
<property name="supportingBranches" value="true"/>
- <property name="supportingEcore" value="false"/>
+ <property name="supportingEcore" value="true"/>
<property name="ensureReferentialIntegrity" value="false"/>
<property name="allowInterruptRunningQueries" value="true"/>
<property name="idGenerationLocation" value="STORE"/> <!-- Possible values: STORE | CLIENT -->
diff --git a/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml b/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
index a8fba54208..c00932fe5d 100644
--- a/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
+++ b/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
@@ -17,7 +17,7 @@
<property name="overrideUUID" value=""/>
<property name="supportingAudits" value="true"/>
<property name="supportingBranches" value="true"/>
- <property name="supportingEcore" value="false"/>
+ <property name="supportingEcore" value="true"/>
<property name="ensureReferentialIntegrity" value="false"/>
<property name="allowInterruptRunningQueries" value="true"/>
<property name="idGenerationLocation" value="STORE"/> <!-- Possible values: STORE | CLIENT -->
diff --git a/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml b/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml
index a8fba54208..c00932fe5d 100644
--- a/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml
+++ b/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml
@@ -17,7 +17,7 @@
<property name="overrideUUID" value=""/>
<property name="supportingAudits" value="true"/>
<property name="supportingBranches" value="true"/>
- <property name="supportingEcore" value="false"/>
+ <property name="supportingEcore" value="true"/>
<property name="ensureReferentialIntegrity" value="false"/>
<property name="allowInterruptRunningQueries" value="true"/>
<property name="idGenerationLocation" value="STORE"/> <!-- Possible values: STORE | CLIENT -->
diff --git a/plugins/org.eclipse.emf.cdo.transfer.repository/src/org/eclipse/emf/cdo/transfer/spi/repository/RepositoryTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer.repository/src/org/eclipse/emf/cdo/transfer/spi/repository/RepositoryTransferSystem.java
index 41568a491d..6f5ddf5586 100644
--- a/plugins/org.eclipse.emf.cdo.transfer.repository/src/org/eclipse/emf/cdo/transfer/spi/repository/RepositoryTransferSystem.java
+++ b/plugins/org.eclipse.emf.cdo.transfer.repository/src/org/eclipse/emf/cdo/transfer/spi/repository/RepositoryTransferSystem.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.transfer.spi.repository;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
import org.eclipse.emf.cdo.common.lob.CDOBlob;
import org.eclipse.emf.cdo.common.lob.CDOClob;
+import org.eclipse.emf.cdo.common.util.CDOException;
import org.eclipse.emf.cdo.eresource.CDOBinaryResource;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
@@ -24,6 +25,7 @@ import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
import org.eclipse.emf.cdo.transfer.CDOTransferType;
import org.eclipse.emf.cdo.util.CDOURIUtil;
+import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.util.io.IORuntimeException;
@@ -32,9 +34,11 @@ import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import java.io.ByteArrayInputStream;
@@ -164,34 +168,66 @@ public class RepositoryTransferSystem extends CDOTransferSystem
}
@Override
- public void createBinary(IPath path, InputStream source)
+ public void createBinary(IPath path, InputStream source, IProgressMonitor monitor)
{
try
{
+ monitor.beginTask("", 1);
+
CDOBlob blob = new CDOBlob(source);
CDOBinaryResource resource = ((CDOTransaction)view).createBinaryResource(path.toString());
resource.setContents(blob);
+
+ monitor.worked(1); // TODO Progress more smoothly
}
catch (IOException ex)
{
throw new IORuntimeException(ex);
}
+ finally
+ {
+ monitor.done();
+ }
}
@Override
- public void createText(IPath path, InputStream source, String encoding)
+ public void createText(IPath path, InputStream source, String encoding, IProgressMonitor monitor)
{
try
{
+ monitor.beginTask("", 1);
+
CDOClob clob = new CDOClob(new InputStreamReader(source, encoding));
CDOTextResource resource = ((CDOTransaction)view).createTextResource(path.toString());
resource.setContents(clob);
resource.setEncoding(encoding);
+
+ monitor.worked(1); // TODO Progress more smoothly
}
catch (IOException ex)
{
throw new IORuntimeException(ex);
}
+ finally
+ {
+ monitor.done();
+ }
+ }
+
+ @Override
+ public void saveModels(EList<Resource> resources, IProgressMonitor monitor)
+ {
+ try
+ {
+ monitor.subTask("Committing to " + this);
+
+ CDOTransaction transaction = (CDOTransaction)view;
+ transaction.commit(monitor);
+ }
+ catch (CommitException ex)
+ {
+ throw new CDOException(ex);
+ }
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDialog.java b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDialog.java
index a8a2807e03..a0735a996b 100644
--- a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDialog.java
+++ b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDialog.java
@@ -14,17 +14,23 @@ import org.eclipse.emf.cdo.transfer.CDOTransfer;
import org.eclipse.emf.cdo.transfer.ui.swt.TransferComposite;
import org.eclipse.emf.cdo.ui.shared.SharedIcons;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
+import java.lang.reflect.InvocationTargetException;
+
/**
* @author Eike Stepper
*/
@@ -34,10 +40,6 @@ public class TransferDialog extends TitleAreaDialog
private TransferComposite transferComposite;
- private InitializationState initializationState = InitializationState.MAPPING;
-
- private Button okButton;
-
public TransferDialog(Shell parentShell, CDOTransfer transfer)
{
super(parentShell);
@@ -55,27 +57,6 @@ public class TransferDialog extends TitleAreaDialog
return transferComposite;
}
- public InitializationState getInitializationState()
- {
- return initializationState;
- }
-
- public void setInitializationState(InitializationState initializationState)
- {
- this.initializationState = initializationState;
-
- if (okButton != null)
- {
- okButton.getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- updateOkButtonEnabledment();
- }
- });
- }
- }
-
@Override
protected Control createDialogArea(Composite parent)
{
@@ -95,14 +76,37 @@ public class TransferDialog extends TitleAreaDialog
@Override
protected void createButtonsForButtonBar(Composite parent)
{
- okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
- updateOkButtonEnabledment();
+ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
}
- protected void updateOkButtonEnabledment()
+ @Override
+ protected void okPressed()
{
- okButton.setEnabled(initializationState == InitializationState.MAPPED);
+ UIUtil.runWithProgress(new IRunnableWithProgress()
+ {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
+ {
+ try
+ {
+ transfer.perform(monitor);
+ }
+ catch (OperationCanceledException ex)
+ {
+ throw new InterruptedException();
+ }
+ catch (RuntimeException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new InvocationTargetException(ex);
+ }
+ }
+ });
+
+ super.okPressed();
}
@Override
@@ -110,12 +114,4 @@ public class TransferDialog extends TitleAreaDialog
{
return new Point(1000, 800);
}
-
- /**
- * @author Eike Stepper
- */
- public static enum InitializationState
- {
- MAPPING, MAPPED, FAILED, CANCELED
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDropAdapter.java b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDropAdapter.java
index 1e17ce8805..7b10dce913 100644
--- a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDropAdapter.java
+++ b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferDropAdapter.java
@@ -15,21 +15,21 @@ import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferSystem;
import org.eclipse.emf.cdo.transfer.spi.ui.TransferUIProvider;
import org.eclipse.emf.cdo.transfer.spi.ui.TransferUIProvider.Factory;
-import org.eclipse.emf.cdo.transfer.ui.TransferDialog.InitializationState;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.IPluginContainer;
+import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.dnd.DNDDropAdapter;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Shell;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -98,71 +98,49 @@ public class TransferDropAdapter extends DNDDropAdapter<Object>
return false;
}
- CDOTransferSystem sourceSystem = sourceElements.get(0).getSystem();
- CDOTransferSystem targetSystem = targetElement.getSystem();
+ final CDOTransferSystem sourceSystem = sourceElements.get(0).getSystem();
+ final CDOTransferSystem targetSystem = targetElement.getSystem();
final CDOTransfer transfer = new CDOTransfer(sourceSystem, targetSystem);
- transfer.getRootMapping().setRelativePath(targetElement.getPath());
+ transfer.setTargetPath(targetElement.getPath());
- Shell shell = getViewer().getControl().getShell();
- final TransferDialog dialog = new TransferDialog(shell, transfer);
-
- new Job("Mapping elements")
+ UIUtil.runWithProgress(new IRunnableWithProgress()
{
- @Override
- protected IStatus run(IProgressMonitor monitor)
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
- monitor.beginTask(getName(), sourceElements.size());
-
try
{
+ monitor.beginTask("Initialize transfer from " + sourceSystem + " to " + targetSystem, sourceElements.size());
+
for (CDOTransferElement sourceElement : sourceElements)
{
- if (monitor.isCanceled() || dialog.getInitializationState() == InitializationState.CANCELED)
- {
- dialog.setInitializationState(InitializationState.CANCELED);
- return Status.OK_STATUS;
- }
-
+ monitor.subTask("Mapping " + sourceElement);
transfer.map(sourceElement);
monitor.worked(1);
}
-
- dialog.setInitializationState(InitializationState.MAPPED);
- return Status.OK_STATUS;
+ }
+ catch (OperationCanceledException ex)
+ {
+ throw new InterruptedException();
}
catch (RuntimeException ex)
{
- dialog.setInitializationState(InitializationState.FAILED);
throw ex;
}
+ catch (Exception ex)
+ {
+ throw new InvocationTargetException(ex);
+ }
finally
{
monitor.done();
}
}
- }.schedule();
+ });
- if (dialog.open() == TransferDialog.OK)
- {
- transfer.perform();
- return true;
- }
-
- return false;
- }
-
- protected boolean performTransfer(CDOTransfer transfer)
- {
Shell shell = getViewer().getControl().getShell();
TransferDialog dialog = new TransferDialog(shell, transfer);
- if (dialog.open() == TransferDialog.OK)
- {
- transfer.perform();
- return true;
- }
-
- return false;
+ return dialog.open() == TransferDialog.OK;
}
protected List<CDOTransferElement> getSourceElements(Object data)
diff --git a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferDetailsComposite.java b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferDetailsComposite.java
index af1a061f17..bafd9a6f22 100644
--- a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferDetailsComposite.java
+++ b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferDetailsComposite.java
@@ -40,6 +40,7 @@ import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.SWTException;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
@@ -438,26 +439,48 @@ public class TransferDetailsComposite extends Composite implements IListener
return relativePath.setFocus();
}
- public void notifyEvent(IEvent event)
+ public void notifyEvent(final IEvent event)
{
- if (event instanceof CDOTransfer.MappingEvent)
+ if (isDisposed())
{
- CDOTransfer.MappingEvent e = (CDOTransfer.MappingEvent)event;
- if (ObjectUtil.equals(e.getMapping(), mapping))
- {
- notifyMappingEvent(e);
- }
+ return;
}
- else if (event instanceof CDOTransfer.UnmappedModelsEvent)
+
+ try
{
getDisplay().asyncExec(new Runnable()
{
public void run()
{
- unmappedModels.refresh();
+ if (!isDisposed())
+ {
+ try
+ {
+ if (event instanceof CDOTransfer.MappingEvent)
+ {
+ CDOTransfer.MappingEvent e = (CDOTransfer.MappingEvent)event;
+ if (ObjectUtil.equals(e.getMapping(), mapping))
+ {
+ notifyMappingEvent(e);
+ }
+ }
+ else if (event instanceof CDOTransfer.UnmappedModelsEvent)
+ {
+ unmappedModels.refresh();
+ }
+ }
+ catch (SWTException ex)
+ {
+ // Ignoredd
+ }
+ }
}
});
}
+ catch (SWTException ex)
+ {
+ // Ignoredd
+ }
}
protected void notifyMappingEvent(CDOTransfer.MappingEvent event)
@@ -466,19 +489,13 @@ public class TransferDetailsComposite extends Composite implements IListener
{
CDOTransfer.TransferTypeChangedEvent e = (CDOTransfer.TransferTypeChangedEvent)event;
final CDOTransferType newType = e.getNewType();
- getDisplay().asyncExec(new Runnable()
+ Object currentType = ((IStructuredSelection)transferType.getSelection()).getFirstElement();
+ if (currentType != newType)
{
- public void run()
- {
- Object currentType = ((IStructuredSelection)transferType.getSelection()).getFirstElement();
- if (currentType != newType)
- {
- transferType.setSelection(new StructuredSelection(newType));
- }
+ transferType.setSelection(new StructuredSelection(newType));
+ }
- unmappedModels.refresh();
- }
- });
+ unmappedModels.refresh();
}
else if (event instanceof CDOTransfer.RelativePathChangedEvent)
{
@@ -486,14 +503,8 @@ public class TransferDetailsComposite extends Composite implements IListener
final String value = e.getNewPath().toString();
if (!ObjectUtil.equals(value, relativePath.getText()))
{
- getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- relativePath.setText(value);
- status.setText(mapping.getStatus().toString());
- }
- });
+ relativePath.setText(value);
+ status.setText(mapping.getStatus().toString());
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferTreeComposite.java b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferTreeComposite.java
index 6332a29803..c9f3830886 100644
--- a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferTreeComposite.java
+++ b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/swt/TransferTreeComposite.java
@@ -73,7 +73,7 @@ public class TransferTreeComposite extends Composite
statusColumn.setWidth(100);
statusColumn.setText("Status");
- viewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS);
+ viewer.setAutoExpandLevel(1);
viewer.setContentProvider(new TransferContentProvider());
viewer.setLabelProvider(new TransferLabelProvider(transfer));
viewer.setInput(transfer.getRootMapping());
diff --git a/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/spi/workspace/WorkspaceTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/spi/workspace/WorkspaceTransferSystem.java
index cf46bf86ec..b55370d40d 100644
--- a/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/spi/workspace/WorkspaceTransferSystem.java
+++ b/plugins/org.eclipse.emf.cdo.transfer.workspace/src/org/eclipse/emf/cdo/transfer/spi/workspace/WorkspaceTransferSystem.java
@@ -27,6 +27,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
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.Path;
import java.io.InputStream;
@@ -151,12 +152,12 @@ public class WorkspaceTransferSystem extends CDOTransferSystem
}
@Override
- public void createBinary(IPath path, InputStream source)
+ public void createBinary(IPath path, InputStream source, IProgressMonitor monitor)
{
try
{
IFile file = ROOT.getFile(path);
- file.create(source, true, null);
+ file.create(source, true, monitor);
}
catch (CoreException ex)
{
@@ -165,12 +166,12 @@ public class WorkspaceTransferSystem extends CDOTransferSystem
}
@Override
- public void createText(IPath path, InputStream source, String encoding)
+ public void createText(IPath path, InputStream source, String encoding, IProgressMonitor monitor)
{
try
{
IFile file = ROOT.getFile(path);
- file.create(source, true, null);
+ file.create(source, true, monitor);
file.setCharset(encoding, null);
}
catch (CoreException ex)
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java
index 0b3ef6caaf..da62a32625 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/spi/transfer/FileSystemTransferSystem.java
@@ -19,6 +19,7 @@ import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.common.util.URI;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import java.io.File;
@@ -89,17 +90,22 @@ public class FileSystemTransferSystem extends CDOTransferSystem
}
@Override
- public void createBinary(IPath path, InputStream source)
+ public void createBinary(IPath path, InputStream source, IProgressMonitor monitor)
{
- File file = getFile(path);
- mkParent(file);
-
OutputStream target = null;
try
{
+ File file = getFile(path);
+ long length = file.length();
+ int totalWork = length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)length;
+ monitor.beginTask("", totalWork);
+
+ mkParent(file);
+
target = new FileOutputStream(file);
IOUtil.copy(source, target);
+ monitor.worked(totalWork); // TODO Progress more smoothly
}
catch (IOException ex)
{
@@ -108,21 +114,27 @@ public class FileSystemTransferSystem extends CDOTransferSystem
finally
{
IOUtil.close(target);
+ monitor.done();
}
}
@Override
- public void createText(IPath path, InputStream source, String encoding)
+ public void createText(IPath path, InputStream source, String encoding, IProgressMonitor monitor)
{
- File file = getFile(path);
- mkParent(file);
-
Writer target = null;
try
{
+ File file = getFile(path);
+ long length = file.length();
+ int totalWork = length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)length;
+ monitor.beginTask("", totalWork);
+
+ mkParent(file);
+
target = new FileWriter(file);
IOUtil.copyCharacter(new InputStreamReader(source, encoding), target);
+ monitor.worked(totalWork); // TODO Progress more smoothly
}
catch (IOException ex)
{
@@ -131,6 +143,7 @@ public class FileSystemTransferSystem extends CDOTransferSystem
finally
{
IOUtil.close(target);
+ monitor.done();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
index c293ed7f14..8c094d1e12 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java
@@ -16,7 +16,6 @@ import org.eclipse.net4j.util.event.Event;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.event.INotifier;
import org.eclipse.net4j.util.event.Notifier;
-import org.eclipse.net4j.util.io.IORuntimeException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.emf.common.notify.Notification;
@@ -31,9 +30,12 @@ import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.SubProgressMonitor;
-import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap;
@@ -102,11 +104,6 @@ public class CDOTransfer implements INotifier
return modelTransferContext;
}
- public final CDOTransferMapping getRootMapping()
- {
- return rootMapping;
- }
-
public final CDOTransferType getDefaultTransferType()
{
return defaultTransferType;
@@ -137,6 +134,31 @@ public class CDOTransfer implements INotifier
return result;
}
+ public final CDOTransferMapping getRootMapping()
+ {
+ return rootMapping;
+ }
+
+ public IPath getTargetPath()
+ {
+ return rootMapping.getRelativePath();
+ }
+
+ public void setTargetPath(IPath targetPath)
+ {
+ rootMapping.setRelativePath(targetPath);
+ }
+
+ public void setTargetPath(String path)
+ {
+ rootMapping.setRelativePath(path);
+ }
+
+ public int getMappingCount()
+ {
+ return mappings.size();
+ }
+
public CDOTransferMapping map(IPath sourcePath)
{
CDOTransferElement source = sourceSystem.getElement(sourcePath);
@@ -209,74 +231,104 @@ public class CDOTransfer implements INotifier
return type;
}
- protected void validate(CDOTransferMapping mapping)
+ protected void validate(CDOTransferMapping mapping, IProgressMonitor monitor)
{
+ if (monitor.isCanceled())
+ {
+ throw new OperationCanceledException();
+ }
+
if (mapping.getStatus() == CDOTransferMapping.Status.CONFLICT)
{
throw new IllegalStateException("Conflict: " + mapping);
}
+ monitor.worked(1);
for (CDOTransferMapping child : mapping.getChildren())
{
- validate(child);
+ validate(child, monitor);
}
}
public void perform()
{
- validate(rootMapping);
- perform(rootMapping);
- modelTransferContext.performFinish();
+ perform(new NullProgressMonitor());
+ }
+
+ public void perform(IProgressMonitor monitor)
+ {
+ try
+ {
+ int mappingCount = getMappingCount();
+ monitor.beginTask("Perform transfer from " + getSourceSystem() + " to " + getTargetSystem(), 5 * mappingCount);
+
+ monitor.subTask("Validating transfer");
+ validate(rootMapping, new SubProgressMonitor(monitor, mappingCount));
+
+ perform(rootMapping, monitor);
+ modelTransferContext.performFinish(new SubProgressMonitor(monitor, 2 * mappingCount));
+ }
+ finally
+ {
+ monitor.done();
+ }
}
- protected void perform(CDOTransferMapping mapping)
+ protected void perform(CDOTransferMapping mapping, IProgressMonitor monitor)
{
+ monitor.subTask("Transferring " + mapping);
+ if (monitor.isCanceled())
+ {
+ throw new OperationCanceledException();
+ }
+
CDOTransferType transferType = mapping.getTransferType();
if (transferType == CDOTransferType.FOLDER)
{
- performFolder(mapping);
+ performFolder(mapping, monitor);
}
else if (transferType == CDOTransferType.MODEL)
{
- performModel(mapping);
+ performModel(mapping, monitor);
}
else if (transferType == CDOTransferType.BINARY)
{
- performBinary(mapping);
+ performBinary(mapping, monitor);
}
else if (transferType instanceof CDOTransferType.Text)
{
String encoding = ((CDOTransferType.Text)transferType).getEncoding();
- performText(mapping, encoding);
+ performText(mapping, encoding, monitor);
}
}
- protected void performFolder(CDOTransferMapping mapping)
+ protected void performFolder(CDOTransferMapping mapping, IProgressMonitor monitor)
{
if (mapping.getStatus() == CDOTransferMapping.Status.NEW)
{
targetSystem.createFolder(mapping.getFullPath());
}
+ monitor.worked(2);
for (CDOTransferMapping child : mapping.getChildren())
{
- perform(child);
+ perform(child, monitor);
}
}
- protected void performModel(CDOTransferMapping mapping)
+ protected void performModel(CDOTransferMapping mapping, IProgressMonitor monitor)
{
- modelTransferContext.perform(mapping);
+ modelTransferContext.perform(mapping, new SubProgressMonitor(monitor, 2));
}
- protected void performBinary(CDOTransferMapping mapping)
+ protected void performBinary(CDOTransferMapping mapping, IProgressMonitor monitor)
{
IPath path = mapping.getFullPath();
InputStream source = mapping.getSource().openInputStream();
try
{
- targetSystem.createBinary(path, source);
+ targetSystem.createBinary(path, source, new SubProgressMonitor(monitor, 2));
}
finally
{
@@ -284,14 +336,14 @@ public class CDOTransfer implements INotifier
}
}
- protected void performText(CDOTransferMapping mapping, String encoding)
+ protected void performText(CDOTransferMapping mapping, String encoding, IProgressMonitor monitor)
{
IPath path = mapping.getFullPath();
InputStream source = mapping.getSource().openInputStream();
try
{
- targetSystem.createText(path, source, encoding);
+ targetSystem.createText(path, source, encoding, new SubProgressMonitor(monitor, 2));
}
finally
{
@@ -709,33 +761,36 @@ public class CDOTransfer implements INotifier
return registry.getFactory(uri) != null;
}
- protected void perform(CDOTransferMapping mapping)
+ protected void perform(CDOTransferMapping mapping, IProgressMonitor monitor)
{
- Resource sourceResource = getSourceResource(mapping);
- Resource targetResource = getTargetResource(mapping); // Create target resource
+ try
+ {
+ monitor.beginTask("", 2);
- EList<EObject> sourceContents = sourceResource.getContents();
- Collection<EObject> targetContents = copier.copyAll(sourceContents);
+ Resource sourceResource = getSourceResource(mapping);
+ Resource targetResource = getTargetResource(mapping); // Create target resource
- EList<EObject> contents = targetResource.getContents();
- contents.addAll(targetContents);
+ EList<EObject> sourceContents = sourceResource.getContents();
+ Collection<EObject> targetContents = copier.copyAll(sourceContents);
+ monitor.worked(1);
+
+ EList<EObject> contents = targetResource.getContents();
+ contents.addAll(targetContents);
+ monitor.worked(1);
+ }
+ finally
+ {
+ monitor.done();
+ }
}
- protected void performFinish()
+ protected void performFinish(IProgressMonitor monitor)
{
+ monitor.subTask("Copying model references");
copier.copyReferences();
- try
- {
- for (Resource resource : getTargetResourceSet().getResources())
- {
- resource.save(null);
- }
- }
- catch (IOException ex)
- {
- throw new IORuntimeException(ex);
- }
+ CDOTransferSystem targetSystem = getTransfer().getTargetSystem();
+ targetSystem.saveModels(getTargetResourceSet().getResources(), monitor);
}
/**
@@ -763,11 +818,13 @@ public class CDOTransfer implements INotifier
{
removeResource(oldValue);
}
+
Resource newValue = (Resource)msg.getNewValue();
if (newValue != null)
{
addResource(newValue);
}
+
break;
}
case Notification.ADD:
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMapping.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMapping.java
index 1a697bab33..72a1f912bb 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMapping.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMapping.java
@@ -36,7 +36,7 @@ public interface CDOTransferMapping extends Comparable<CDOTransferMapping>
public IPath getRelativePath();
- public void setRelativePath(IPath relativePath);
+ public void setRelativePath(IPath path);
public void setRelativePath(String path);
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
index 2bd6b5907d..bcf80020df 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferMappingImpl.java
@@ -115,13 +115,13 @@ class CDOTransferMappingImpl implements CDOTransferMapping
return relativePath;
}
- public void setRelativePath(IPath relativePath)
+ public void setRelativePath(IPath path)
{
- if (!ObjectUtil.equals(this.relativePath, relativePath))
+ if (!ObjectUtil.equals(this.relativePath, path))
{
IPath oldPath = this.relativePath;
- this.relativePath = relativePath;
- transfer.relativePathChanged(this, oldPath, relativePath);
+ this.relativePath = path;
+ transfer.relativePathChanged(this, oldPath, path);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
index 0972286a83..ad20c2cfcf 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferSystem.java
@@ -10,13 +10,19 @@
*/
package org.eclipse.emf.cdo.transfer;
+import org.eclipse.net4j.util.io.IORuntimeException;
+
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
+import java.io.IOException;
import java.io.InputStream;
/**
@@ -73,7 +79,35 @@ public abstract class CDOTransferSystem
return resourceSet.createResource(uri);
}
- public abstract void createBinary(IPath path, InputStream source);
+ public abstract void createBinary(IPath path, InputStream source, IProgressMonitor monitor);
+
+ public abstract void createText(IPath path, InputStream source, String encoding, IProgressMonitor monitor);
- public abstract void createText(IPath path, InputStream source, String encoding);
+ public void saveModels(EList<Resource> resources, IProgressMonitor monitor)
+ {
+ try
+ {
+ monitor.beginTask("", resources.size());
+
+ for (Resource resource : resources)
+ {
+ if (monitor.isCanceled())
+ {
+ throw new OperationCanceledException();
+ }
+
+ monitor.subTask("Saving " + resource.getURI());
+ resource.save(null);
+ monitor.worked(1);
+ }
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
index 2268502109..e1eeabc877 100644
--- a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
@@ -12,6 +12,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)";resolution:=optional;visibility:=reexport,
org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)";resolution:=optional;visibility:=reexport,
+ org.eclipse.core.filesystem;bundle-version="[1.3.0,2.0.0)";resolution:=optional,
org.eclipse.ui.ide;bundle-version="[3.4.0,4.0.0)";resolution:=optional;visibility:=reexport,
org.eclipse.ui;bundle-version="[3.4.0,4.0.0)";visibility:=reexport,
org.eclipse.emf.edit.ui;bundle-version="[2.4.0,3.0.0)";visibility:=reexport,
@@ -21,8 +22,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.cdo;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.emf.cdo.edit;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.emf.cdo.transfer.ui;bundle-version="[4.2.0,5.0.0)";visibility:=reexport,
- org.eclipse.emf.cdo.ui.shared;bundle-version="[4.0.0,5.0.0)",
- org.eclipse.core.filesystem;bundle-version="[1.3.0,2.0.0)";resolution:=optional
+ org.eclipse.emf.cdo.ui.shared;bundle-version="[4.0.0,5.0.0)"
Export-Package: org.eclipse.emf.cdo.internal.ui;version="4.2.0";
x-friends:="org.eclipse.emf.cdo.ui.defs,
org.eclipse.emf.cdo.ui.ide,
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java
index cc20503d32..311e72610e 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/UIUtil.java
@@ -11,11 +11,15 @@
*/
package org.eclipse.net4j.util.ui;
+import org.eclipse.net4j.util.internal.ui.bundle.OM;
import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
import org.eclipse.net4j.util.ui.security.InteractiveCredentialsProvider;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.fieldassist.FieldDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.operation.ModalContext;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
@@ -41,6 +45,7 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
+import java.lang.reflect.InvocationTargetException;
import java.util.List;
/**
@@ -396,6 +401,33 @@ public final class UIUtil
/**
* @since 3.3
*/
+ public static void runWithProgress(final IRunnableWithProgress runnable)
+ {
+ try
+ {
+ IRunnableWithProgress op = new IRunnableWithProgress()
+ {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
+ {
+ ModalContext.run(runnable, true, monitor, PlatformUI.getWorkbench().getDisplay());
+ }
+ };
+
+ PlatformUI.getWorkbench().getProgressService().run(false, true, op);
+ }
+ catch (InvocationTargetException ex)
+ {
+ OM.LOG.error(ex.getCause());
+ }
+ catch (InterruptedException ex)
+ {
+ //$FALL-THROUGH$
+ }
+ }
+
+ /**
+ * @since 3.3
+ */
public static void preserveViewerState(final Viewer viewer, final Runnable runnable)
{
try

Back to the top