Skip to content

Package: ListMigrationDialogLabelProvider

ListMigrationDialogLabelProvider

nameinstructionbranchcomplexitylinemethod
ListMigrationDialogLabelProvider()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getText(Object)
M: 4 C: 46
92%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 9
90%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2015 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: * Alexandra Buzila - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.ide.editor.view;
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.ide.editor.view.messages.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 view models that should be migrated.
30: *
31: * @since 1.8.0
32: */
33: public final class MigrationDialogHelper {
34:         private MigrationDialogHelper() {
35:         }
36:
37:         /**
38:          * Returns a {@link ListSelectionDialog} for selecting view model that should be migrated.
39:          *
40:          * @param parentShell the parent shell of the dialog
41:          * @param input the list of view model URI to be presented to the user.´
42:          * @return the dialog
43:          */
44:         public static ListSelectionDialog getViewModelListMigrationDialog(Shell parentShell, List<URI> input) {
45:                 final IStructuredContentProvider contentProvider = new ArrayContentProvider();
46:                 final ILabelProvider labelProvider = new ListMigrationDialogLabelProvider();
47:                 final ListSelectionDialog dialog = new ListSelectionDialog(parentShell, input, contentProvider, labelProvider,
48:                         Messages.MigrationDialog_Description);
49:                 dialog.setTitle(Messages.MigrationDialog_Title);
50:                 dialog.setHelpAvailable(false);
51:                 dialog.setInitialElementSelections(input);
52:                 return dialog;
53:         }
54:
55:         /**
56:          * Returns a {@link ListSelectionDialog} for selecting template models that should be migrated.
57:          *
58:          * @param parentShell the parent shell of the dialog
59:          * @param input the list of template model URIs to be presented to the user
60:          * @return the dialog
61:          */
62:         public static ListSelectionDialog getTemplateModelListMigrationDialog(Shell parentShell, List<URI> input) {
63:                 final IStructuredContentProvider contentProvider = new ArrayContentProvider();
64:                 final ILabelProvider labelProvider = new ListMigrationDialogLabelProvider();
65:                 final ListSelectionDialog dialog = new ListSelectionDialog(parentShell, input, contentProvider, labelProvider,
66:                         Messages.MigrationDialogHelper_TemplatesTitle);
67:                 dialog.setTitle(Messages.MigrationDialogHelper_TemplatesDescription);
68:                 dialog.setHelpAvailable(false);
69:                 dialog.setInitialElementSelections(input);
70:                 return dialog;
71:         }
72: }
73:
74: /** Label provider for the Migration ListSelectionDialog. */
75: class ListMigrationDialogLabelProvider extends LabelProvider {
76:
77:         @Override
78:         public String getText(Object element) {
79:•                if (!URI.class.isInstance(element)) {
80:                         return super.getText(element);
81:                 }
82:                 final URI uri = (URI) element;
83:                 final String filePath = uri.devicePath();
84:                 final String platformPath = Platform.getLocation().toString();
85:                 String text = filePath;
86:•                if (filePath.contains(platformPath)) {
87:                         final int startIndex = filePath.indexOf(platformPath);
88:                         text = filePath.substring(startIndex + 1 + platformPath.length());
89:                 }
90:                 return String.format("%s [%s]", uri.lastSegment(), text); //$NON-NLS-1$
91:         }
92:
93: }