Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-13 11:48:21 +0000
committerEike Stepper2012-09-13 11:48:21 +0000
commit240559c52a4962ed329281c2a406497d59a6e5fc (patch)
treee340d892ecec82da2e13304b2be9f52434a5e42d /plugins
parentef5ba89f34d14882fc82127fe79e64e8f492fda0 (diff)
downloadcdo-240559c52a4962ed329281c2a406497d59a6e5fc.tar.gz
cdo-240559c52a4962ed329281c2a406497d59a6e5fc.tar.xz
cdo-240559c52a4962ed329281c2a406497d59a6e5fc.zip
[388928] Develop a resource transfer framework
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388928
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferTypeContentProvider.java55
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/widgets/TransferDetailsComposite.java70
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransfer.java58
-rw-r--r--plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java29
4 files changed, 156 insertions, 56 deletions
diff --git a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferTypeContentProvider.java b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferTypeContentProvider.java
new file mode 100644
index 0000000000..dbf9a2e9da
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/TransferTypeContentProvider.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.transfer.ui;
+
+import org.eclipse.emf.cdo.transfer.CDOTransferType;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * @author Eike Stepper
+ */
+public class TransferTypeContentProvider implements IStructuredContentProvider
+{
+ public static final CDOTransferType[] NO_TANSFER_TYPES = {};
+
+ public TransferTypeContentProvider()
+ {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
+ {
+ // Do nothing
+ }
+
+ public void dispose()
+ {
+ // Do nothing
+ }
+
+ public Object[] getElements(Object inputElement)
+ {
+ if (inputElement instanceof CDOTransferType)
+ {
+ CDOTransferType transferType = (CDOTransferType)inputElement;
+ return new CDOTransferType[] { transferType };
+ }
+
+ if (inputElement instanceof CDOTransferType[])
+ {
+ CDOTransferType[] transferTypes = (CDOTransferType[])inputElement;
+ return transferTypes;
+ }
+
+ return NO_TANSFER_TYPES;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/widgets/TransferDetailsComposite.java b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/widgets/TransferDetailsComposite.java
index d89216914d..05305752d9 100644
--- a/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/widgets/TransferDetailsComposite.java
+++ b/plugins/org.eclipse.emf.cdo.transfer.ui/src/org/eclipse/emf/cdo/transfer/ui/widgets/TransferDetailsComposite.java
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.transfer.CDOTransfer;
import org.eclipse.emf.cdo.transfer.CDOTransferElement;
import org.eclipse.emf.cdo.transfer.CDOTransferMapping;
import org.eclipse.emf.cdo.transfer.CDOTransferType;
+import org.eclipse.emf.cdo.transfer.ui.TransferTypeContentProvider;
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.StringUtil;
@@ -26,9 +27,13 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
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.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -42,9 +47,8 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Set;
/**
@@ -59,13 +63,15 @@ public class TransferDetailsComposite extends Composite implements IListener
private CDOTransfer transfer;
+ private CDOTransferType[] transferTypes;
+
private CDOTransferMapping mapping;
private Text sourcePath;
private Text targetPath;
- private Combo transferType;
+ private ComboViewer transferType;
private Text status;
@@ -80,6 +86,7 @@ public class TransferDetailsComposite extends Composite implements IListener
super(parent, style);
this.transfer = transfer;
this.transfer.addListener(this);
+ initTransferTypes(transfer);
GridLayout gl_composite = new GridLayout(4, false);
gl_composite.marginWidth = 10;
@@ -96,34 +103,23 @@ public class TransferDetailsComposite extends Composite implements IListener
transferTypeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
transferTypeLabel.setText("Type:");
- transferType = new Combo(this, SWT.NONE);
- transferType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
- transferType.addSelectionListener(new SelectionAdapter()
+ transferType = new ComboViewer(this, SWT.NONE);
+ transferType.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
+ transferType.setContentProvider(new TransferTypeContentProvider());
+ transferType.setLabelProvider(new LabelProvider());
+ transferType.addSelectionChangedListener(new ISelectionChangedListener()
{
- @Override
- public void widgetSelected(SelectionEvent e)
+ public void selectionChanged(SelectionChangedEvent event)
{
if (mapping != null)
{
- String text = transferType.getText();
- CDOTransferType type = CDOTransferType.REGISTRY.get(text);
+ IStructuredSelection selection = (IStructuredSelection)transferType.getSelection();
+ CDOTransferType type = (CDOTransferType)selection.getFirstElement();
mapping.setTransferType(type);
}
}
});
- Set<CDOTransferType> usedTransferTypes = transfer.getUsedTransferTypes();
- usedTransferTypes.addAll(CDOTransferType.STANDARD_TYPES);
- usedTransferTypes.addAll(CDOTransferType.STANDARD_TYPES);
-
- List<CDOTransferType> transferTypes = new ArrayList<CDOTransferType>(usedTransferTypes);
- Collections.sort(transferTypes);
-
- for (CDOTransferType type : transferTypes)
- {
- transferType.add(type.toString());
- }
-
Label targetPathLabel = new Label(this, SWT.NONE);
targetPathLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
targetPathLabel.setText("Target Path:");
@@ -327,17 +323,23 @@ public class TransferDetailsComposite extends Composite implements IListener
{
sourcePath.setText(mapping.getSource().getPath().toString());
targetPath.setText(mapping.getFullPath().toString());
- transferType.setText(mapping.getTransferType().toString());
status.setText(mapping.getStatus().toString());
relativePath.setText(mapping.getRelativePath().toString());
+
+ CDOTransferType type = mapping.getTransferType();
+ transferType.setInput(type != CDOTransferType.FOLDER ? transferTypes : CDOTransferType.FOLDER);
+ transferType.setSelection(new StructuredSelection(type));
+ transferType.getCombo().setEnabled(type != CDOTransferType.FOLDER);
}
else
{
sourcePath.setText(StringUtil.EMPTY);
targetPath.setText(StringUtil.EMPTY);
- transferType.setText(StringUtil.EMPTY);
status.setText(StringUtil.EMPTY);
relativePath.setText(StringUtil.EMPTY);
+
+ transferType.setInput(TransferTypeContentProvider.NO_TANSFER_TYPES);
+ transferType.setSelection(StructuredSelection.EMPTY);
}
}
}
@@ -352,7 +354,7 @@ public class TransferDetailsComposite extends Composite implements IListener
return targetPath;
}
- public Combo getTransferType()
+ public ComboViewer getTransferType()
{
return transferType;
}
@@ -400,14 +402,15 @@ public class TransferDetailsComposite extends Composite implements IListener
if (event instanceof CDOTransfer.TransferTypeChangedEvent)
{
CDOTransfer.TransferTypeChangedEvent e = (CDOTransfer.TransferTypeChangedEvent)event;
- final String value = e.getNewType().toString();
+ final CDOTransferType newType = e.getNewType();
getDisplay().asyncExec(new Runnable()
{
public void run()
{
- if (!ObjectUtil.equals(value, transferType.getText()))
+ Object currentType = ((IStructuredSelection)transferType.getSelection()).getFirstElement();
+ if (currentType != newType)
{
- transferType.setText(value);
+ transferType.setSelection(new StructuredSelection(newType));
}
unmappedModels.refresh();
@@ -432,6 +435,15 @@ public class TransferDetailsComposite extends Composite implements IListener
}
}
+ protected void initTransferTypes(final CDOTransfer transfer)
+ {
+ Set<CDOTransferType> set = new HashSet<CDOTransferType>(CDOTransferType.REGISTRY.values());
+ set.remove(CDOTransferType.FOLDER);
+
+ transferTypes = set.toArray(new CDOTransferType[set.size()]);
+ Arrays.sort(transferTypes);
+ }
+
/**
* @author Eike Stepper
*/
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 dedc0d42d9..867bb0171d 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
@@ -22,7 +22,6 @@ 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.Resource.Factory;
-import org.eclipse.emf.ecore.resource.Resource.Factory.Registry;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
@@ -607,11 +606,15 @@ public class CDOTransfer implements INotifier
{
CDOTransferElement element = mapping.getSource();
Resource resource = elementResources.remove(element);
- resourceElements.remove(resource);
- resource.unload();
+ if (resource != null)
+ {
+ resourceElements.remove(resource);
+ resource.unload();
+
+ ResourceSet resourceSet = getSourceResourceSet();
+ resourceSet.getResources().remove(resource);
+ }
- ResourceSet resourceSet = getSourceResourceSet();
- resourceSet.getResources().remove(resource);
unmappedModels = null;
}
@@ -631,34 +634,17 @@ public class CDOTransfer implements INotifier
protected ResourceSet createResourceSet(CDOTransferSystem system)
{
- Resource.Factory.Registry registry = new ResourceFactoryRegistryImpl()
- {
- {
- getProtocolToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap());
- getExtensionToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap());
- getContentTypeToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap());
-
- getExtensionToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_EXTENSION);
- getContentTypeToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_CONTENT_TYPE_IDENTIFIER);
- }
-
- @Override
- protected Factory delegatedGetFactory(URI uri, String contentTypeIdentifier)
- {
- return null;
- }
- };
-
ResourceSet resourceSet = new ResourceSetImpl();
- resourceSet.setResourceFactoryRegistry(registry);
+ resourceSet.setResourceFactoryRegistry(new ResourceFactoryRegistryWithoutDefaults());
return resourceSet;
}
protected boolean hasResourceFactory(CDOTransferElement source)
{
URI uri = source.getURI();
+
// TODO Derive resourceSet from element.getSystem()?
- Registry registry = getSourceResourceSet().getResourceFactoryRegistry();
+ Resource.Factory.Registry registry = getSourceResourceSet().getResourceFactoryRegistry();
return registry.getFactory(uri) != null;
}
@@ -689,4 +675,26 @@ public class CDOTransfer implements INotifier
}
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ protected static class ResourceFactoryRegistryWithoutDefaults extends ResourceFactoryRegistryImpl
+ {
+ public ResourceFactoryRegistryWithoutDefaults()
+ {
+ getProtocolToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getProtocolToFactoryMap());
+ getExtensionToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap());
+ getContentTypeToFactoryMap().putAll(Resource.Factory.Registry.INSTANCE.getContentTypeToFactoryMap());
+
+ getExtensionToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_EXTENSION);
+ getContentTypeToFactoryMap().remove(Resource.Factory.Registry.DEFAULT_CONTENT_TYPE_IDENTIFIER);
+ }
+
+ @Override
+ protected Factory delegatedGetFactory(URI uri, String contentTypeIdentifier)
+ {
+ return null;
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java
index 86a19be097..40b7d5b08d 100644
--- a/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java
+++ b/plugins/org.eclipse.emf.cdo.transfer/src/org/eclipse/emf/cdo/transfer/CDOTransferType.java
@@ -10,8 +10,11 @@
*/
package org.eclipse.emf.cdo.transfer;
+import org.eclipse.emf.cdo.internal.transfer.bundle.OM;
+
import org.eclipse.net4j.util.ObjectUtil;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -110,17 +113,39 @@ public class CDOTransferType implements Comparable<CDOTransferType>
{
return (Text)type;
}
-
+
if (type == null)
{
Text text = new Text(encoding);
MAP.put(encoding, text);
return text;
}
-
+
throw new IllegalArgumentException("Illegal encoding: " + encoding);
}
+ static
+ {
+ try
+ {
+ for (Charset charset : Charset.availableCharsets().values())
+ {
+ try
+ {
+ text(charset.toString());
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+
/**
* @author Eike Stepper
*/

Back to the top