summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-12-19 04:52:50 (EST)
committerEike Stepper2007-12-19 04:52:50 (EST)
commitbefcf5be6404649485ee3751d2101046ec63a33e (patch)
tree29f1ea260c77976584215df8d87dc17e30617932
parent71ac65f69ce520bd179c0f9fd1fb9b969f6a01d0 (diff)
downloadcdo-befcf5be6404649485ee3751d2101046ec63a33e.zip
cdo-befcf5be6404649485ee3751d2101046ec63a33e.tar.gz
cdo-befcf5be6404649485ee3751d2101046ec63a33e.tar.bz2
[213417] Provide action to import resources
https://bugs.eclipse.org/bugs/show_bug.cgi?id=213417
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ExportResourceAction.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ImportResourceAction.java171
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOActionBarContributor.java69
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java29
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java31
6 files changed, 221 insertions, 82 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ExportResourceAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ExportResourceAction.java
index 190df98..0a408ae 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ExportResourceAction.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ExportResourceAction.java
@@ -3,6 +3,7 @@ package org.eclipse.emf.cdo.internal.ui.actions;
/**
* @author Eike Stepper
*/
+@Deprecated
public class ExportResourceAction extends EditingDomainAction
{
public static final String ID = "export-resource";
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ImportResourceAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ImportResourceAction.java
new file mode 100644
index 0000000..a7c1c3b
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ImportResourceAction.java
@@ -0,0 +1,171 @@
+package org.eclipse.emf.cdo.internal.ui.actions;
+
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.CDOView;
+
+import org.eclipse.emf.common.ui.dialogs.ResourceDialog;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchPage;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Eike Stepper
+ */
+public class ImportResourceAction extends ViewAction
+{
+ public static final String ID = "import-resource";
+
+ private static final String TITLE = "Import Resource";
+
+ private URI sourceURI;
+
+ private String targetPath;
+
+ public ImportResourceAction(IWorkbenchPage page, CDOView view)
+ {
+ super(page, TITLE + INTERACTIVE, "Import a CDO resource", null, view);
+ setId(ID);
+ }
+
+ @Override
+ protected void preRun() throws Exception
+ {
+ ImportResourceDialog dialog = new ImportResourceDialog(getShell(), TITLE, SWT.OPEN);
+ if (dialog.open() == ImportResourceDialog.OK)
+ {
+ List<URI> uris = dialog.getURIs();
+ if (uris.size() == 1)
+ {
+ sourceURI = uris.get(0);
+ targetPath = dialog.getTargetPath();
+ }
+ else
+ {
+ MessageDialog.openError(getShell(), TITLE, "A single URI must be entered!");
+ cancel();
+ }
+ }
+ else
+ {
+ cancel();
+ }
+ }
+
+ @Override
+ protected void doRun() throws Exception
+ {
+ CDOTransaction transaction = getTransaction();
+ Resource source = transaction.getResourceSet().getResource(sourceURI, true);
+ Resource target = transaction.createResource(targetPath);
+
+ List<EObject> contents = new ArrayList<EObject>(source.getContents());
+ for (EObject root : contents)
+ {
+ target.getContents().add(root);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ImportResourceDialog extends ResourceDialog
+ {
+ private String targetPath = "/";
+
+ private Text targetText;
+
+ public ImportResourceDialog(Shell parent, String title, int style)
+ {
+ super(parent, title, style);
+ }
+
+ public String getTargetPath()
+ {
+ return targetPath;
+ }
+
+ public void setTargetPath(String targetPath)
+ {
+ this.targetPath = targetPath;
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent)
+ {
+ Composite composite = (Composite)super.createDialogArea(parent);
+
+ Label separatorLabel1 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ {
+ FormData data = new FormData();
+ data.top = new FormAttachment(uriField, (int)(1.5 * CONTROL_OFFSET));
+ data.left = new FormAttachment(0, -CONTROL_OFFSET);
+ data.right = new FormAttachment(100, CONTROL_OFFSET);
+ separatorLabel1.setLayoutData(data);
+ }
+
+ Label label = new Label(composite, SWT.NONE);
+ label.setText("Target path:");
+ {
+ FormData data = new FormData();
+ data.top = new FormAttachment(separatorLabel1, CONTROL_OFFSET);
+ data.left = new FormAttachment(0, CONTROL_OFFSET);
+ data.right = new FormAttachment(100, -CONTROL_OFFSET);
+ label.setLayoutData(data);
+ }
+
+ targetText = new Text(composite, SWT.BORDER);
+ {
+ FormData data = new FormData();
+ data.top = new FormAttachment(label, CONTROL_OFFSET);
+ data.left = new FormAttachment(0, CONTROL_OFFSET);
+ data.right = new FormAttachment(100, -CONTROL_OFFSET);
+ targetText.setLayoutData(data);
+ }
+
+ Label separatorLabel2 = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
+ {
+ FormData data = new FormData();
+ data.top = new FormAttachment(targetText, (int)(1.5 * CONTROL_OFFSET));
+ data.left = new FormAttachment(0, -CONTROL_OFFSET);
+ data.right = new FormAttachment(100, CONTROL_OFFSET);
+ separatorLabel2.setLayoutData(data);
+ }
+
+ return composite;
+
+ // Composite composite = UIUtil.createGridComposite(parent, 1);
+ // Control source = super.createDialogArea(composite);
+ // source.setLayoutData(UIUtil.createGridData(true, false));
+ //
+ // Composite line = UIUtil.createGridComposite(composite, 2);
+ // new Label(line, SWT.NONE).setText("Enter target path:");
+ //
+ // targetText = new Text(line, SWT.BORDER);
+ // targetText.setLayoutData(UIUtil.createGridData(true, false));
+ // targetText.setText(targetPath);
+ // targetText.addModifyListener(new ModifyListener()
+ // {
+ // public void modifyText(ModifyEvent e)
+ // {
+ // targetPath = targetText.getText();
+ // }
+ // });
+ //
+ // return source;
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOActionBarContributor.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOActionBarContributor.java
index c5e616e..c79704e 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOActionBarContributor.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/editor/CDOActionBarContributor.java
@@ -7,7 +7,6 @@
package org.eclipse.emf.cdo.internal.ui.editor;
import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.internal.ui.actions.ExportResourceAction;
import org.eclipse.emf.cdo.internal.ui.actions.ImportRootsAction;
import org.eclipse.emf.cdo.internal.ui.actions.ReloadObjectsAction;
@@ -64,12 +63,7 @@ public class CDOActionBarContributor extends EditingDomainActionBarContributor i
/**
* @ADDED
*/
- protected ImportRootsAction importResourceAction;
-
- /**
- * @ADDED
- */
- protected ExportResourceAction exportResourceAction;
+ protected ImportRootsAction importRootsAction;
/**
* @ADDED
@@ -183,8 +177,8 @@ public class CDOActionBarContributor extends EditingDomainActionBarContributor i
loadResourceAction = new LoadResourceAction();
loadResourceAction.setId(LOAD_RESOURCE_ID);
- importResourceAction = new ImportRootsAction();
- importResourceAction.setId(ImportRootsAction.ID);
+ importRootsAction = new ImportRootsAction();
+ importRootsAction.setId(ImportRootsAction.ID);
// exportResourceAction = new ExportResourceAction(); // TODO
// exportResourceAction.setId(EXPORT_RESOURCE_ID);
@@ -376,15 +370,15 @@ public class CDOActionBarContributor extends EditingDomainActionBarContributor i
newChildDescriptors = domain.getNewChildDescriptors(object, null);
newSiblingDescriptors = domain.getNewChildDescriptors(null, object);
- if (importResourceAction != null)
+ if (importRootsAction != null)
{
if (object instanceof CDOResource)
{
- importResourceAction.setTargetResource((CDOResource)object);
+ importRootsAction.setTargetResource((CDOResource)object);
}
else
{
- importResourceAction.setTargetResource(null);
+ importRootsAction.setTargetResource(null);
}
}
}
@@ -564,26 +558,16 @@ public class CDOActionBarContributor extends EditingDomainActionBarContributor i
if (loadResourceAction != null)
{
- if (exportResourceAction != null)
- {
- menuManager.insertAfter(loadResourceAction.getId(), exportResourceAction);
- }
-
- if (importResourceAction != null)
+ if (importRootsAction != null)
{
- menuManager.insertAfter(loadResourceAction.getId(), importResourceAction);
+ menuManager.insertAfter(loadResourceAction.getId(), importRootsAction);
}
}
else
{
- if (importResourceAction != null)
- {
- menuManager.insertBefore("additions-end", importResourceAction);
- }
-
- if (exportResourceAction != null)
+ if (importRootsAction != null)
{
- menuManager.insertAfter("additions-end", exportResourceAction);
+ menuManager.insertBefore("additions-end", importRootsAction);
}
menuManager.insertBefore("additions-end", new Separator());
@@ -608,25 +592,20 @@ public class CDOActionBarContributor extends EditingDomainActionBarContributor i
@Override
public void activate()
{
- if (importResourceAction != null)
+ if (importRootsAction != null)
{
- importResourceAction.setActiveWorkbenchPart(activeEditor);
+ importRootsAction.setActiveWorkbenchPart(activeEditor);
Object input = ((CDOEditor)getActiveEditor()).getViewer().getInput();
if (input instanceof CDOResource)
{
- importResourceAction.setTargetResource((CDOResource)input);
+ importRootsAction.setTargetResource((CDOResource)input);
}
else
{
- importResourceAction.setTargetResource(null);
+ importRootsAction.setTargetResource(null);
}
}
- if (exportResourceAction != null)
- {
- exportResourceAction.setActiveWorkbenchPart(activeEditor);
- }
-
if (reloadObjectsAction != null)
{
reloadObjectsAction.setActiveWorkbenchPart(activeEditor);
@@ -641,15 +620,10 @@ public class CDOActionBarContributor extends EditingDomainActionBarContributor i
@Override
public void deactivate()
{
- if (importResourceAction != null)
+ if (importRootsAction != null)
{
- importResourceAction.setActiveWorkbenchPart(null);
- importResourceAction.setTargetResource(null);
- }
-
- if (exportResourceAction != null)
- {
- exportResourceAction.setActiveWorkbenchPart(null);
+ importRootsAction.setActiveWorkbenchPart(null);
+ importRootsAction.setTargetResource(null);
}
if (reloadObjectsAction != null)
@@ -667,14 +641,9 @@ public class CDOActionBarContributor extends EditingDomainActionBarContributor i
public void update()
{
super.update();
- if (importResourceAction != null)
- {
- importResourceAction.update();
- }
-
- if (exportResourceAction != null)
+ if (importRootsAction != null)
{
- exportResourceAction.update();
+ importRootsAction.update();
}
if (reloadObjectsAction != null)
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
index 588cc49..19965bd 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
@@ -22,6 +22,7 @@ import org.eclipse.emf.cdo.internal.ui.actions.CloseSessionAction;
import org.eclipse.emf.cdo.internal.ui.actions.CloseViewAction;
import org.eclipse.emf.cdo.internal.ui.actions.CommitTransactionAction;
import org.eclipse.emf.cdo.internal.ui.actions.CreateResourceAction;
+import org.eclipse.emf.cdo.internal.ui.actions.ImportResourceAction;
import org.eclipse.emf.cdo.internal.ui.actions.LoadResourceAction;
import org.eclipse.emf.cdo.internal.ui.actions.ManagePackagesAction;
import org.eclipse.emf.cdo.internal.ui.actions.OpenAuditAction;
@@ -347,6 +348,7 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
if (view.getViewType() == CDOView.Type.TRANSACTION)
{
manager.add(new CreateResourceAction(page, view));
+ manager.add(new ImportResourceAction(page, view));
manager.add(new CommitTransactionAction(page, view));
manager.add(new RollbackTransactionAction(page, view));
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
index 8c1620d..0a4d805 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOCallbackImpl.java
@@ -10,15 +10,11 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo;
-import org.eclipse.emf.cdo.CDOView;
-
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.impl.CDOAware;
import org.eclipse.emf.ecore.impl.CDOCallback;
import org.eclipse.emf.ecore.impl.EObjectImpl;
-import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
@@ -145,29 +141,4 @@ public class CDOCallbackImpl extends CDOLegacyImpl implements CDOCallback
}
}
}
-
- public static InternalCDOObject adapt(Object object, CDOView view) throws Throwable
- {
- if (object instanceof CDOAware)
- {
- CDOAware aware = (CDOAware)object;
- CDOCallbackImpl callback = (CDOCallbackImpl)aware.getCDOCallback();
- if (callback == null)
- {
- InternalEObject instance = (InternalEObject)aware;
- if (instance.eIsProxy())
- {
- instance = (InternalEObject)EcoreUtil.resolve(instance, view.getResourceSet());
- }
-
- callback = new CDOCallbackImpl(instance);
- aware.setCDOCallback(callback);
- instance.eAdapters().add(callback);
- }
-
- return callback;
- }
-
- return null;
- }
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
index 0dcb093..baddc47 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/FSMUtil.java
@@ -20,7 +20,6 @@ import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EGenericType;
import org.eclipse.emf.ecore.EModelElement;
import org.eclipse.emf.ecore.InternalEObject;
-import org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.internal.cdo.CDOAdapterImpl;
import org.eclipse.emf.internal.cdo.CDOMetaImpl;
@@ -63,7 +62,7 @@ public final class FSMUtil
}
if (object instanceof EModelElement || object instanceof EGenericType
- || object instanceof EStringToStringMapEntryImpl)
+ || object instanceof org.eclipse.emf.ecore.impl.EStringToStringMapEntryImpl)
{
InternalEObject eObject = (InternalEObject)object;
if (view == null)
@@ -85,7 +84,7 @@ public final class FSMUtil
try
{
- InternalCDOObject callback = org.eclipse.emf.internal.cdo.CDOCallbackImpl.adapt(object, view);
+ InternalCDOObject callback = adaptLegacy(object, view);
if (callback != null)
{
return callback;
@@ -112,6 +111,32 @@ public final class FSMUtil
return null;
}
+ public static InternalCDOObject adaptLegacy(Object object, CDOView view) throws Throwable
+ {
+ if (object instanceof org.eclipse.emf.ecore.impl.CDOAware)
+ {
+ org.eclipse.emf.ecore.impl.CDOAware aware = (org.eclipse.emf.ecore.impl.CDOAware)object;
+ org.eclipse.emf.internal.cdo.CDOCallbackImpl callback = (org.eclipse.emf.internal.cdo.CDOCallbackImpl)aware
+ .getCDOCallback();
+ if (callback == null)
+ {
+ InternalEObject instance = (InternalEObject)aware;
+ if (instance.eIsProxy())
+ {
+ instance = (InternalEObject)EcoreUtil.resolve(instance, view.getResourceSet());
+ }
+
+ callback = new org.eclipse.emf.internal.cdo.CDOCallbackImpl(instance);
+ aware.setCDOCallback(callback);
+ instance.eAdapters().add(callback);
+ }
+
+ return callback;
+ }
+
+ return null;
+ }
+
public static Iterator<InternalCDOObject> iterator(Collection<?> instances, final CDOViewImpl view)
{
final Iterator<?> delegate = instances.iterator();