Skip to content

Package: ListMigrationDialogLabelProvider

ListMigrationDialogLabelProvider

nameinstructionbranchcomplexitylinemethod
ListMigrationDialogLabelProvider()
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%
getText(Object)
M: 50 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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: * lucas - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.template.internal.tooling.util;
15:
16: import java.util.List;
17:
18: import org.eclipse.core.runtime.Platform;
19: import org.eclipse.emf.common.util.URI;
20: import org.eclipse.emf.ecp.view.template.internal.tooling.Messages;
21: import org.eclipse.jface.viewers.ArrayContentProvider;
22: import org.eclipse.jface.viewers.ILabelProvider;
23: import org.eclipse.jface.viewers.IStructuredContentProvider;
24: import org.eclipse.jface.viewers.LabelProvider;
25: import org.eclipse.swt.widgets.Shell;
26: import org.eclipse.ui.dialogs.ListSelectionDialog;
27:
28: /**
29: * Helper class that provides a ListSelectionDialog for selecting template models that should be migrated.
30: *
31: * @author Lucas Koehler
32: *
33: */
34: // TODO this is in parts duplicated from the org.eclipse.emf.ecp.ide.editor.view bundle and should be refactored in the
35: // future
36: public final class MigrationDialogHelper {
37:
38:         private MigrationDialogHelper() {
39:         }
40:
41:         /**
42:          * Returns a {@link ListSelectionDialog} for selecting template models that should be migrated.
43:          *
44:          * @param parentShell the parent shell of the dialog
45:          * @param input the list of template model URIs to be presented to the user
46:          * @return the dialog
47:          */
48:         public static ListSelectionDialog getTemplateModelListMigrationDialog(Shell parentShell, List<URI> input) {
49:                 final IStructuredContentProvider contentProvider = new ArrayContentProvider();
50:                 final ILabelProvider labelProvider = new ListMigrationDialogLabelProvider();
51:                 final ListSelectionDialog dialog = new ListSelectionDialog(parentShell, input, contentProvider, labelProvider,
52:                         Messages.MigrationDialogHelper_TemplatesTitle);
53:                 dialog.setTitle(Messages.MigrationDialogHelper_TemplatesDescription);
54:                 dialog.setHelpAvailable(false);
55:                 dialog.setInitialElementSelections(input);
56:                 return dialog;
57:         }
58: }
59:
60: /** Label provider for the Migration ListSelectionDialog. */
61: class ListMigrationDialogLabelProvider extends LabelProvider {
62:
63:         @Override
64:         public String getText(Object element) {
65:•                if (!URI.class.isInstance(element)) {
66:                         return super.getText(element);
67:                 }
68:                 final URI uri = (URI) element;
69:                 final String filePath = uri.devicePath();
70:                 final String platformPath = Platform.getLocation().toString();
71:                 String text = filePath;
72:•                if (filePath.contains(platformPath)) {
73:                         final int startIndex = filePath.indexOf(platformPath);
74:                         text = filePath.substring(startIndex + 1 + platformPath.length());
75:                 }
76:                 return String.format("%s [%s]", uri.lastSegment(), text); //$NON-NLS-1$
77:         }
78:
79: }