Skip to content

Package: ECPFileDialogHelperImpl

ECPFileDialogHelperImpl

nameinstructionbranchcomplexitylinemethod
ECPFileDialogHelperImpl()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getPathForExport(Shell, String)
M: 45 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
getPathForImport(Shell)
M: 39 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * Johannes Faltermeier - initial API and refactorings
13: * David Soto Setzke - initial implementation
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.internal.ui.util;
16:
17: import java.io.File;
18:
19: import org.eclipse.emf.ecp.internal.ui.PreferenceHelper;
20: import org.eclipse.swt.SWT;
21: import org.eclipse.swt.widgets.FileDialog;
22: import org.eclipse.swt.widgets.Shell;
23: import org.osgi.service.component.annotations.Component;
24:
25: /**
26: * {@link ECPFileDialogHelper} using the SWT implementation of the {@link FileDialog}.
27: *
28: * @author jfaltermeier
29: *
30: */
31: @Component
32: public class ECPFileDialogHelperImpl implements ECPFileDialogHelper {
33:
34:         private static final String IMPORT_MODEL_PATH = "org.eclipse.emf.emfstore.client.ui.importModelPath"; //$NON-NLS-1$
35:         private static final String EXPORT_MODEL_PATH = "org.eclipse.emf.emfstore.client.ui.exportModelPath"; //$NON-NLS-1$
36:         private static final String FILE_EXTENSION = "xmi"; //$NON-NLS-1$
37:
38:         /**
39:          *
40:          * {@inheritDoc}
41:          *
42:          * @see org.eclipse.emf.ecp.internal.ui.util.ECPFileDialogHelper#getPathForImport(org.eclipse.swt.widgets.Shell)
43:          */
44:         public String getPathForImport(Shell shell) {
45:                 final FileDialog dialog = new FileDialog(shell,
46:                         SWT.OPEN);
47:                 dialog.setFilterNames(ECPImportHandlerHelper.FILTER_NAMES);
48:                 dialog.setFilterExtensions(ECPImportHandlerHelper.FILTER_EXTS);
49:                 final String initialPath = PreferenceHelper.getPreference(IMPORT_MODEL_PATH, System.getProperty("user.home")); //$NON-NLS-1$
50:                 dialog.setFilterPath(initialPath);
51:
52:                 final String fileName = dialog.open();
53:
54:•                if (fileName == null) {
55:                         return null;
56:                 }
57:
58:                 final File file = new File(fileName);
59:
60:                 PreferenceHelper.setPreference(IMPORT_MODEL_PATH, file.getParent());
61:
62:                 return file.getAbsolutePath();
63:         }
64:
65:         /**
66:          *
67:          * {@inheritDoc}
68:          *
69:          * @see org.eclipse.emf.ecp.internal.ui.util.ECPFileDialogHelper#getPathForExport(org.eclipse.swt.widgets.Shell,
70:          * java.lang.String)
71:          */
72:         public String getPathForExport(Shell shell, String fileName) {
73:                 final FileDialog dialog = new FileDialog(shell,
74:                         SWT.SAVE);
75:                 dialog.setFilterNames(ECPExportHandlerHelper.FILTER_NAMES);
76:                 dialog.setFilterExtensions(ECPExportHandlerHelper.FILTER_EXTS);
77:                 final String initialPath = PreferenceHelper.getPreference(EXPORT_MODEL_PATH, System.getProperty("user.home")); //$NON-NLS-1$
78:                 dialog.setFilterPath(initialPath);
79:                 dialog.setOverwrite(true);
80:
81:                 try {
82:                         final String initialFileName = "ModelElement_" + fileName + "." + FILE_EXTENSION; //$NON-NLS-1$ //$NON-NLS-2$
83:                         dialog.setFileName(initialFileName);
84:                 } catch (final NullPointerException e) {
85:                         // do nothing
86:                 }
87:
88:                 final String filePath = dialog.open();
89:                 return filePath;
90:         }
91:
92: }