Skip to content

Package: OpenViewMigrationDialog$2

OpenViewMigrationDialog$2

nameinstructionbranchcomplexitylinemethod
run()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
{...}
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017 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: * Edgar Mueller - initial API and implementation
13: *******************************************************************************/
14: package org.eclipse.emf.ecp.ide.internal.migration;
15:
16: import java.util.Map;
17: import java.util.Set;
18:
19: import org.eclipse.core.commands.AbstractHandler;
20: import org.eclipse.core.commands.ExecutionEvent;
21: import org.eclipse.core.commands.ExecutionException;
22: import org.eclipse.core.resources.IFile;
23: import org.eclipse.core.runtime.IProgressMonitor;
24: import org.eclipse.core.runtime.IStatus;
25: import org.eclipse.core.runtime.Status;
26: import org.eclipse.core.runtime.SubMonitor;
27: import org.eclipse.core.runtime.jobs.Job;
28: import org.eclipse.emf.common.util.Diagnostic;
29: import org.eclipse.emfforms.common.Optional;
30: import org.eclipse.jface.viewers.ISelection;
31: import org.eclipse.jface.viewers.IStructuredSelection;
32: import org.eclipse.jface.window.Window;
33: import org.eclipse.swt.widgets.Display;
34: import org.eclipse.swt.widgets.Shell;
35: import org.eclipse.ui.handlers.HandlerUtil;
36:
37: /**
38: * Opens the {@link ViewMigrationDialog}.
39: *
40: */
41: public class OpenViewMigrationDialog extends AbstractHandler {
42:
43:         /**
44:          * {@inheritDoc}
45:          *
46:          * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
47:          */
48:         @Override
49:         public Object execute(ExecutionEvent event) throws ExecutionException {
50:
51:                 final Shell shell = Display.getCurrent().getActiveShell();
52:                 final ViewMigrationDialog dialog = new ViewMigrationDialog(shell);
53:
54:                 if (dialog.open() == Window.OK) {
55:                         final ISelection sel = HandlerUtil
56:                                 .getActiveWorkbenchWindowChecked(event)
57:                                 .getSelectionService()
58:                                 .getSelection();
59:
60:                         if (sel instanceof IStructuredSelection) {
61:                                 final Job job = new Job(Messages.OpenViewMigrationDialog_JobTitle) {
62:
63:                                         @Override
64:                                         protected IStatus run(IProgressMonitor monitor) {
65:                                                 final SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
66:                                                 subMonitor.setTaskName(Messages.OpenViewMigrationDialog_Find);
67:                                                 final Set<IFile> viewModelFiles = Resources.findAllViewFilesInWorkspace(subMonitor.split(20));
68:                                                 subMonitor.setWorkRemaining(80);
69:                                                 subMonitor.setTaskName(Messages.OpenViewMigrationDialog_Migrate);
70:                                                 try {
71:                                                         final Map<String, Optional<Diagnostic>> diagnostics = new ViewMigrationHandler(
72:                                                                 dialog.getOldNamespaceFragment(),
73:                                                                 dialog.getNewNamespaceFragment()).execute(viewModelFiles, subMonitor.split(80));
74:                                                         showResultDialog(diagnostics, dialog.shouldShowWarning());
75:
76:                                                 } catch (final ViewMigrationException ex) {
77:                                                         return new Status(
78:                                                                 IStatus.ERROR,
79:                                                                 "org.eclipse.emf.ecp.ide.migration", //$NON-NLS-1$
80:                                                                 IStatus.ERROR,
81:                                                                 Messages.OpenUpdateNSDialog_ErrorTitle,
82:                                                                 ex);
83:                                                 }
84:
85:                                                 return Status.OK_STATUS;
86:                                         }
87:
88:                                 };
89:                                 job.schedule();
90:                         }
91:                 }
92:
93:                 return null;
94:         }
95:
96:         private void showResultDialog(final Map<String, Optional<Diagnostic>> diagnostics, final boolean showWarnings) {
97:                 Display.getDefault().syncExec(new Runnable() {
98:                         @Override
99:                         public void run() {
100:                                 final ViewMigrationResultDialog dialog = new ViewMigrationResultDialog(
101:                                         Display.getCurrent().getActiveShell(),
102:                                         diagnostics,
103:                                         showWarnings);
104:                                 dialog.open();
105:                         }
106:                 });
107:         }
108: }