blob: 624257964ccc2737348c6f3cc5cc287978196de6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
/*****************************************************************************
* Copyright (c) 2012 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.infra.ui.util;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils;
import org.eclipse.ui.IWorkbenchPage;
/**
* A ServiceUtils implementation for manipulating the Papyrus services from an IWorkbenchPage
*
* @author Camille Letavernier
*
*/
public class ServiceUtilsForWorkbenchPage extends AbstractServiceUtils<IWorkbenchPage> {
@Override
public ServicesRegistry getServiceRegistry(IWorkbenchPage from) throws ServiceException {
IAdaptable adaptable = null;
if (from instanceof IAdaptable) {
adaptable = (IAdaptable) from;
} else if (from != null) {
// 421392: [Model Explorer] Link with Editor does not work properly
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421392
// Since Eclipse 4.4, the concrete WorkbenchPage is not IAdaptable anymore.
// Try the ActivePart
adaptable = from.getActivePart();
}
if (adaptable != null) {
ServicesRegistry registry = (ServicesRegistry) adaptable.getAdapter(ServicesRegistry.class);
if (registry != null) {
return registry;
}
}
throw new ServiceException("Cannot resolve the ServiceRegistry from the IWorkbenchPage. Page: " + from); //$NON-NLS-1$
}
public static ServiceUtilsForWorkbenchPage getInstance() {
return instance;
}
private static ServiceUtilsForWorkbenchPage instance = new ServiceUtilsForWorkbenchPage();
private ServiceUtilsForWorkbenchPage() {
// Singleton
}
}
|