Skip to content

Package: ExportProjectHelper

ExportProjectHelper

nameinstructionbranchcomplexitylinemethod
exportProject(InternalProject, Shell)
M: 34 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
getFilePathByFileDialog(Shell, String)
M: 24 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 32 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.emfstore.internal.ui.handler;
15:
16: import java.io.File;
17: import java.io.IOException;
18:
19: import org.eclipse.core.runtime.NullProgressMonitor;
20: import org.eclipse.emf.ecp.emfstore.core.internal.EMFStoreProvider;
21: import org.eclipse.emf.ecp.emfstore.internal.ui.Activator;
22: import org.eclipse.emf.ecp.internal.ui.util.ECPExportHandlerHelper;
23: import org.eclipse.emf.ecp.internal.ui.util.ECPFileDialogHelper;
24: import org.eclipse.emf.ecp.spi.core.InternalProject;
25: import org.eclipse.emf.emfstore.client.ESLocalProject;
26: import org.eclipse.emf.emfstore.internal.client.importexport.ExportImportControllerExecutor;
27: import org.eclipse.emf.emfstore.internal.client.importexport.ExportImportControllerFactory;
28: import org.eclipse.emf.emfstore.internal.client.importexport.impl.ExportImportDataUnits;
29: import org.eclipse.emf.emfstore.internal.client.model.impl.api.ESLocalProjectImpl;
30: import org.eclipse.swt.widgets.Shell;
31: import org.osgi.framework.BundleContext;
32: import org.osgi.framework.FrameworkUtil;
33: import org.osgi.framework.ServiceReference;
34:
35: /**
36: * A helper class that can be used to export projects.
37: *
38: * @author Eugen Neufeld, David Soto Setzke
39: *
40: */
41: public final class ExportProjectHelper {
42:
43:         private static final String FILE_EXTENSION = ExportImportDataUnits.ProjectSpace.getExtension();
44:
45:         /**
46:          * These filter names are used to filter which files are displayed.
47:          */
48:         public static final String[] FILTER_NAMES = { "Model Files (*" + FILE_EXTENSION + ")" }; //$NON-NLS-1$ //$NON-NLS-2$
49:
50:         /**
51:          * These filter extensions are used to filter which files are displayed.
52:          */
53:         public static final String[] FILTER_EXTS = { "*" + FILE_EXTENSION }; //$NON-NLS-1$
54:
55:         private ExportProjectHelper() {
56:         }
57:
58:         /**
59:          * Exports a given project.
60:          *
61:          * @param internalProject The project that should be exported
62:          * @param shell The active shell
63:          */
64:         public static void exportProject(InternalProject internalProject, Shell shell) {
65:                 final ESLocalProject localProject = EMFStoreProvider.INSTANCE.getProjectSpace(internalProject);
66:
67:                 final String filePath = getFilePathByFileDialog(shell, internalProject.getName());
68:•                if (filePath == null) {
69:                         return;
70:                 }
71:                 try {
72:                         new ExportImportControllerExecutor(new File(filePath), new NullProgressMonitor())
73:                                 .execute(ExportImportControllerFactory.Export
74:                                         .getExportProjectSpaceController(((ESLocalProjectImpl) localProject).toInternalAPI()));
75:
76:                 } catch (final IOException ex) {
77:                         Activator.log(ex);
78:                 }
79:         }
80:
81:         private static String getFilePathByFileDialog(Shell shell, String modelElementName) {
82:                 final BundleContext bundleContext = FrameworkUtil.getBundle(ECPExportHandlerHelper.class).getBundleContext();
83:                 final ServiceReference<ECPFileDialogHelper> serviceReference = bundleContext
84:                         .getServiceReference(ECPFileDialogHelper.class);
85:                 final ECPFileDialogHelper fileDialogHelper = bundleContext.getService(serviceReference);
86:                 final String result = fileDialogHelper.getPathForExport(shell, modelElementName);
87:                 bundleContext.ungetService(serviceReference);
88:                 return result;
89:         }
90:
91: }