Skip to content

Package: ShareProjectHelper

ShareProjectHelper

nameinstructionbranchcomplexitylinemethod
share(InternalProject, Shell)
M: 66 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 17 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: * Eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.emfstore.internal.ui.handler;
15:
16: import java.util.Collections;
17: import java.util.concurrent.Callable;
18:
19: import org.eclipse.emf.ecp.emfstore.core.internal.EMFStoreProvider;
20: import org.eclipse.emf.ecp.internal.wizards.ShareWizard;
21: import org.eclipse.emf.ecp.spi.core.InternalProject;
22: import org.eclipse.emf.ecp.spi.core.InternalRepository;
23: import org.eclipse.emf.emfstore.client.ESLocalProject;
24: import org.eclipse.emf.emfstore.client.util.RunESCommand;
25: import org.eclipse.emf.emfstore.internal.client.model.ServerInfo;
26: import org.eclipse.emf.emfstore.internal.client.model.impl.api.ESLocalProjectImpl;
27: import org.eclipse.emf.emfstore.internal.client.model.impl.api.ESServerImpl;
28: import org.eclipse.emf.emfstore.internal.client.ui.controller.UIShareProjectController;
29: import org.eclipse.jface.window.Window;
30: import org.eclipse.jface.wizard.WizardDialog;
31: import org.eclipse.swt.widgets.Shell;
32:
33: /**
34: * This is the EMFStore ShareProject Handler delegating to the EMFStore {@link UIShareProjectController}.
35: *
36: * @author Eugen Neufeld
37: *
38: */
39: public final class ShareProjectHelper {
40:
41:         private ShareProjectHelper() {
42:         }
43:
44:         /**
45:          * Shares an {@link InternalProject}. Delegates to {@link UIShareProjectController}.
46:          *
47:          * @param project the {@link InternalProject}
48:          * @param shell the {@link Shell}
49:          */
50:         public static void share(InternalProject project, Shell shell) {
51:                 final ShareWizard rw = new ShareWizard();
52:                 rw.init(project.getProvider());
53:
54:                 final WizardDialog wd = new WizardDialog(shell, rw);
55:                 final int result = wd.open();
56:•                if (result == Window.OK) {
57:                         // TODO internal cast again
58:                         final InternalRepository repository = (InternalRepository) rw.getSelectedRepository();
59:                         project.undispose(repository);
60:                         final ESLocalProject localProject = EMFStoreProvider.INSTANCE.getProjectSpace(project);
61:
62:                         // TODO Ugly
63:•                        if (localProject.getUsersession() == null) {
64:                                 final ESServerImpl server = (ESServerImpl) EMFStoreProvider.INSTANCE.getServerInfo(project
65:                                         .getRepository());
66:                                 final ServerInfo serverInfo = server.toInternalAPI();
67:                                 RunESCommand.run(new Callable<Void>() {
68:                                         @Override
69:                                         public Void call() throws Exception {
70:                                                 ((ESLocalProjectImpl) localProject).toInternalAPI().setUsersession(
71:                                                         serverInfo.getLastUsersession());
72:                                                 return null;
73:                                         }
74:                                 });
75:                         }
76:                         // TODO EMFStore Constructor is missing
77:                         new UIShareProjectController(shell, localProject).execute();
78:
79:                         project.notifyObjectsChanged(Collections.singleton((Object) project), false);
80:                         repository.notifyObjectsChanged(Collections.singleton((Object) repository));
81:                 }
82:         }
83: }