This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
GraphitiModelConnector.java
91 lines (79 loc) · 3.38 KB
/
GraphitiModelConnector.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
* Copyright (c) 2010-2012, Tamas Szabo, Istvan Rath and Daniel Varro
* 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:
* Tamas Szabo - initial API and implementation
*******************************************************************************/
package org.eclipse.incquery.runtime.graphiti.util;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.editor.DiagramEditor;
import org.eclipse.incquery.tooling.ui.queryexplorer.QueryExplorer;
import org.eclipse.incquery.tooling.ui.queryexplorer.content.matcher.MatcherTreeViewerRootKey;
import org.eclipse.incquery.tooling.ui.queryexplorer.handlers.util.EMFModelConnector;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
public class GraphitiModelConnector extends EMFModelConnector {
private IWorkbenchPage workbenchPage;
public GraphitiModelConnector(MatcherTreeViewerRootKey key) {
super(key);
this.workbenchPage = key.getEditorPart().getSite().getPage();
}
@Override
public void loadModel() {
workbenchPage.addPartListener(GraphitiEditorPartListener.getInstance());
if (QueryExplorer.getInstance() != null) {
QueryExplorer.getInstance().getMatcherTreeViewerRoot().addPatternMatcherRoot(key);
}
}
@Override
public void unloadModel() {
workbenchPage.removePartListener(GraphitiEditorPartListener.getInstance());
if (QueryExplorer.getInstance() != null) {
QueryExplorer.getInstance().getMatcherTreeViewerRoot().removePatternMatcherRoot(key);
}
}
@Override
public void showLocation(Object[] locationObjects) {
//reflective set selection is not needed
IStructuredSelection preparedSelection = prepareSelection(locationObjects);
navigateToElements(key.getEditorPart(), preparedSelection);
workbenchPage.bringToTop(key.getEditorPart());
}
@Override
protected TreePath createTreePath(IEditorPart editor, EObject obj) {
if (editor instanceof DiagramEditor) {
Diagram diagram = ((DiagramEditor) editor).getDiagramTypeProvider().getDiagram();
List<PictogramElement> pictogramElements = Graphiti.getLinkService().getPictogramElements(diagram, obj);
if (!pictogramElements.isEmpty()) {
List<EditPart> parts = new ArrayList<EditPart>();
for (PictogramElement element : pictogramElements) {
EditPart part = ((DiagramEditor) editor).getEditPartForPictogramElement(element);
if (part != null) {
parts.add(part);
}
}
return new TreePath(parts.toArray());
}
}
return null;
}
@Override
protected void navigateToElements(IEditorPart editorPart, IStructuredSelection selection) {
if (editorPart instanceof DiagramEditor) {
DiagramEditor providerEditor = (DiagramEditor) editorPart;
providerEditor.getGraphicalViewer().setSelection(selection);
}
}
}