blob: edfe37f104de03afc2bf824696492497546680a6 (
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) 2011 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:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.sysml.modelexplorer.tests.utils;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.papyrus.core.services.ServiceException;
import org.eclipse.papyrus.core.services.ServicesRegistry;
import org.eclipse.papyrus.core.utils.ServiceUtils;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
/**
* Utility class for tests
*/
public class EditorUtils {
/**
* Retrieves current active editor
*
* @return current active editor
* @throws Exception
* exception thrown in case of issue
*/
public static IEditorPart getEditor() throws Exception {
return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
}
public static DiagramEditor getDiagramEditor() throws Exception {
ServicesRegistry serviceRegistry = (ServicesRegistry)getEditor().getAdapter(ServicesRegistry.class);
try {
return (DiagramEditor)ServiceUtils.getInstance().getNestedActiveIEditorPart(serviceRegistry);
} catch (ServiceException e) {
throw new Exception("Unable to retrieve service.", e);
} catch (ClassCastException e) {
throw new Exception("Active diagram is not a DiagramEditor." + e.getMessage(), e);
}
}
public static DiagramEditPart getDiagramEditPart() throws Exception {
try {
return getDiagramEditor().getDiagramEditPart();
} catch (NullPointerException e) {
throw new Exception("Could not find diagram edit part.", e);
}
}
}
|