/
EmfTreeEditor.java
116 lines (95 loc) · 3.42 KB
/
EmfTreeEditor.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*******************************************************************************
* Copyright (c) 2013 RCP Vision (http://www.rcp-vision.com) and others.
* 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:
* Lorenzo Bettini - initial API and implementation
*******************************************************************************/
package org.eclipse.emf.parsley.editors;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.presentation.EcoreEditorPlugin;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor;
import org.eclipse.emf.edit.ui.util.EditUIUtil;
import org.eclipse.emf.parsley.resource.LoadResourceResponse;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.widgets.Tree;
/**
* @author Lorenzo Bettini - initial API and implementation
*/
public class EmfTreeEditor extends EmfAbstractEditor {
/**
*
*/
public EmfTreeEditor() {
// nothing to do
}
@Override
public void createPages() {
// Create a page for the selection tree view.
URI resourceURI = EditUIUtil.getURI(getEditorInput());
LoadResourceResponse response = resourceLoader.getResource(
editingDomain, resourceURI);
handleProblems(response);
Tree tree = new Tree(getContainer(), SWT.MULTI);
TreeViewer emfTreeViewer = new TreeViewer(tree);
viewerFactory.initialize(emfTreeViewer, editingDomain);
selectionViewer = emfTreeViewer;
setSelectionOnRoot(selectionViewer);
createAdapterFactoryTreeEditor(emfTreeViewer);
createContextMenuFor(selectionViewer);
selectionViewer.addSelectionChangedListener(createSelectionChangedListener());
int pageIndex = addPage(tree);
setPageText(pageIndex, getString("_UI_SelectionPage_label"));
setActivePage(0);
// Ensures that this editor will only display the page's tab
// area if there are more than one page
//
getContainer().addControlListener(new ControlAdapter() {
boolean guard = false;
@Override
public void controlResized(ControlEvent event) {
if (!guard) {
guard = true;
hideTabs();
guard = false;
}
}
});
updateProblemIndication();
}
protected AdapterFactoryTreeEditor createAdapterFactoryTreeEditor(TreeViewer emfTreeViewer) {
return new AdapterFactoryTreeEditor(emfTreeViewer.getTree(), adapterFactory);
}
protected void handleProblems(LoadResourceResponse response) {
Resource resource = response.getResource();
Exception exception = response.getException();
Diagnostic diagnostic = analyzeResourceProblems(resource, exception);
if (diagnostic.getSeverity() != Diagnostic.OK) {
resourceToDiagnosticMap.put(resource,
analyzeResourceProblems(resource, exception));
}
editingDomain.getResourceSet().eAdapters()
.add(problemIndicationAdapter);
}
/**
* This looks up a string in the plugin's plugin.properties file. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @generated
*/
private static String getString(String key) {
return EcoreEditorPlugin.INSTANCE.getString(key);
}
@Override
protected boolean showOutlineView() {
return true;
}
}