diff options
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ImportResourceAction.java')
-rw-r--r-- | plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/ImportResourceAction.java | 218 |
1 files changed, 109 insertions, 109 deletions
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 index 39b3d1acab..6217de18ae 100644 --- 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 @@ -1,109 +1,109 @@ -/*
- * 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
- * Victor Roldan Betancort - maintenance
- */
-package org.eclipse.emf.cdo.internal.ui.actions;
-
-import org.eclipse.emf.cdo.internal.ui.dialogs.ImportResourceDialog;
-import org.eclipse.emf.cdo.internal.ui.messages.Messages;
-import org.eclipse.emf.cdo.transaction.CDOTransaction;
-import org.eclipse.emf.cdo.ui.CDOEditorUtil;
-import org.eclipse.emf.cdo.view.CDOView;
-
-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.emf.ecore.resource.impl.ResourceSetImpl;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.SWT;
-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"; //$NON-NLS-1$
-
- private static final String TITLE = Messages.getString("ImportResourceAction.1"); //$NON-NLS-1$
-
- private URI sourceURI;
-
- private String targetPath;
-
- public ImportResourceAction(IWorkbenchPage page, CDOView view)
- {
- super(page, TITLE + INTERACTIVE, Messages.getString("ImportResourceAction.2"), null, view); //$NON-NLS-1$
- 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, Messages.getString("ImportResourceAction.3")); //$NON-NLS-1$
- cancel();
- }
- }
- else
- {
- cancel();
- }
- }
-
- @Override
- protected void doRun(IProgressMonitor progressMonitor) throws Exception
- {
- CDOTransaction transaction = getTransaction();
-
- // Source ResourceSet
- ResourceSet sourceSet = new ResourceSetImpl();
- sourceSet.setPackageRegistry(transaction.getSession().getPackageRegistry());
-
- // Source Resource
- Resource source = sourceSet.getResource(sourceURI, true);
- List<EObject> sourceContents = new ArrayList<EObject>(source.getContents());
-
- // Target Resource
- Resource target = transaction.createResource(targetPath);
- EList<EObject> targetContents = target.getContents();
-
- // Move contents over
- for (EObject root : sourceContents)
- {
- targetContents.add(root);
- }
-
- getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- CDOEditorUtil.openEditor(getPage(), getView(), targetPath);
- }
- });
- }
-}
+/* + * 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 + * Victor Roldan Betancort - maintenance + */ +package org.eclipse.emf.cdo.internal.ui.actions; + +import org.eclipse.emf.cdo.internal.ui.dialogs.ImportResourceDialog; +import org.eclipse.emf.cdo.internal.ui.messages.Messages; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.ui.CDOEditorUtil; +import org.eclipse.emf.cdo.view.CDOView; + +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.emf.ecore.resource.impl.ResourceSetImpl; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.SWT; +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"; //$NON-NLS-1$ + + private static final String TITLE = Messages.getString("ImportResourceAction.1"); //$NON-NLS-1$ + + private URI sourceURI; + + private String targetPath; + + public ImportResourceAction(IWorkbenchPage page, CDOView view) + { + super(page, TITLE + INTERACTIVE, Messages.getString("ImportResourceAction.2"), null, view); //$NON-NLS-1$ + 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, Messages.getString("ImportResourceAction.3")); //$NON-NLS-1$ + cancel(); + } + } + else + { + cancel(); + } + } + + @Override + protected void doRun(IProgressMonitor progressMonitor) throws Exception + { + CDOTransaction transaction = getTransaction(); + + // Source ResourceSet + ResourceSet sourceSet = new ResourceSetImpl(); + sourceSet.setPackageRegistry(transaction.getSession().getPackageRegistry()); + + // Source Resource + Resource source = sourceSet.getResource(sourceURI, true); + List<EObject> sourceContents = new ArrayList<EObject>(source.getContents()); + + // Target Resource + Resource target = transaction.createResource(targetPath); + EList<EObject> targetContents = target.getContents(); + + // Move contents over + for (EObject root : sourceContents) + { + targetContents.add(root); + } + + getDisplay().asyncExec(new Runnable() + { + public void run() + { + CDOEditorUtil.openEditor(getPage(), getView(), targetPath); + } + }); + } +} |