Skip to main content
summaryrefslogtreecommitdiffstats
blob: 52fe8a879623b884c6d4d478a7dd9886905a0485 (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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************************
 * Copyright (c) 2010 itemis AG (http://www.itemis.eu) 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
 *******************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.xtext.glue.partialEditing;

import java.lang.reflect.Constructor;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.papyrus.infra.gmfdiag.xtext.glue.edit.part.IXtextEMFReconciler;
import org.eclipse.xtext.ui.editor.XtextSourceViewer;
import org.eclipse.xtext.ui.editor.XtextSourceViewerConfiguration;
import org.eclipse.xtext.ui.editor.model.XtextDocument;
import org.eclipse.xtext.ui.editor.validation.IValidationIssueProcessor;

import com.google.inject.Injector;

/**
 * 
 */
public class SourceViewerHandle {
	protected IValidationIssueProcessor issueProcessor;
	protected final XtextSourceViewer viewer;
	protected final ISyntheticResourceProvider resourceProvider;
	protected final XtextDocument document;
	protected final XtextSourceViewerConfiguration configuration;
	protected static Class partialModelEditorClass = null ;
	private Class defaultModelEditorClass = PartialModelEditor.class ;
	protected EObject semanticElement ;
	protected IXtextEMFReconciler modelReconciler ;
	
	SourceViewerHandle(XtextDocument document, XtextSourceViewer viewer, XtextSourceViewerConfiguration configuration, ISyntheticResourceProvider resourceProvider, Injector xtextInjector) {
		this.document = document;
		this.viewer = viewer;
		this.configuration = configuration;
		this.resourceProvider = resourceProvider;
	}

	/**
	 * @param issueProcessor 
	 *
	 */
	public void setIssueProcessor(IValidationIssueProcessor issueProcessor) {
		this.issueProcessor = issueProcessor;
	}
	
	/**
	 * @return IValidationIssueProcessor
	 *
	 */
	public IValidationIssueProcessor getIssueProcessor() {
		return issueProcessor;
	}
	
	/**
	 * @return XtextSourceViewer
	 *
	 */
	public XtextSourceViewer getViewer() {
		return viewer;
	}
	
	/**
	 * @return XtextDocument
	 *
	 */
	public XtextDocument getDocument() {
		return document;
	}
	
	/**
	 * @return XtextSourceViewerConfiguration
	 *
	 */
	public XtextSourceViewerConfiguration getConfiguration() {
		return configuration;
	}
	
	/**
	 * @param prefix 
	 * @param editablePart 
	 * @param suffix 
	 * @param semanticElement 
	 * @param modelReconciler 
	 * @return PartialModelEditor
	 *
	 */
	public PartialModelEditor createPartialEditor(String prefix, String editablePart, String suffix, EObject semanticElement, IXtextEMFReconciler modelReconciler) {
		//PartialModelEditor result = new PartialModelEditor(viewer, resourceProvider, false);
		PartialModelEditor result = null;
		try {
			if (partialModelEditorClass == null)
				partialModelEditorClass = defaultModelEditorClass ;
			Constructor c = partialModelEditorClass.getConstructor(SourceViewer.class, 
											   ISyntheticResourceProvider.class,
											   boolean.class,
											   EObject.class,
											   IXtextEMFReconciler.class
											   ) ;
			this.semanticElement = semanticElement ;
			this.modelReconciler = modelReconciler ;
			result = (PartialModelEditor)c.newInstance(viewer, resourceProvider, false, semanticElement, modelReconciler) ;
			result.setModel(getDocument(), prefix, editablePart, suffix);
		}
		catch (Exception e) {
			e.printStackTrace() ;
		}
		// result.setModel(getDocument(), prefix, editablePart, suffix);
		return result;
	}
	
	/**
	 * @param modelEditorClass 
	 *
	 */
	public static void bindPartialModelEditorClass(Class modelEditorClass) {
		partialModelEditorClass = modelEditorClass ;
	}
	
	/**
	 * @return PartialModelEditor
	 *
	 */
	public PartialModelEditor createPartialEditor() {
		return createPartialEditor("", "", "", null, null);
	}
}

Back to the top