Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 32bc80d953a105d77d39f6efcd524f871b8a5c69 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*******************************************************************************
 * Copyright (c) 2006 - 2007 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:
 *     CEA LIST - initial API and implementation
 *******************************************************************************/

package org.eclipse.papyrus.views.panels;

import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.papyrus.C_Cpp.Include;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.papyrus.views.cpp.CommandSupport;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.util.UMLUtil;



/**
 * Panel displayed when a Class is selected
 */
public class CppClassPanel extends CppAbstractPanel {

	// document used by the viewer for header include
	private IDocument headerDocument;

	@SuppressWarnings("unused")
	private SourceViewer headerViewer;

	private Group headerGroup;

	// document used by the viewer for body include
	private IDocument bodyDocument;

	@SuppressWarnings("unused")
	private SourceViewer bodyViewer;

	private Group bodyGroup;

	// Current selection
	private Class selectedClass;

	public CppClassPanel(Composite parent, int style) {
		super(parent, style);
	}

	/**
	 * @return Returns the selectedOperation.
	 */
	public org.eclipse.uml2.uml.Class getSelectedElement() {
		return selectedClass;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cea.accordcpp.core.ui.panels.AccordCppAbstractPanel#setSelectedElement(java.lang.Object)
	 */
	@Override
	public void setSelectedElement(Element newElement) {
		super.setSelectedElement(newElement);
		if(newElement instanceof Class) {
			this.selectedClass = (Class)newElement;
		}
		else {
			throw new RuntimeException("bad selection: " + newElement + " should be an uml2 Class");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cea.accorduml.ui.views.panels.AccordUMLAbstractPanel#createContentHI()
	 */
	public Control createContent() {

		///////////////////////////////////////////////////////////////////////
		// Create save reset buttons with superclass method
		///////////////////////////////////////////////////////////////////////    	
		createSaveResetButtons();

		/////////////////////////////////////////////////////////////////////////
		// Create a Group for the header include declarations
		/////////////////////////////////////////////////////////////////////////
		headerDocument = createDocumentC();
		headerGroup = createGroup(
			this
			, "Header include declarations"
			, buttonSave
			, null
			, true
			, 50
			, 0
			, false);
		// Use CDT CEditor coloration
		headerViewer = createViewerC(headerDocument, headerGroup);
		/////////////////////////////////////////////////////////////////////////
		// Create a Group for the body include declarations
		/////////////////////////////////////////////////////////////////////////
		bodyDocument = createDocumentC();
		bodyGroup = createGroup(
			this
			, "Body include declarations"
			, headerGroup
			, null
			, true
			, 0
			, 0
			, true);
		// Use CDT CEditor coloration
		bodyViewer = createViewerC(bodyDocument, bodyGroup);

		/////////////////////////////////////////////////////////////////////////

		return this;
	}

	/**
	 * Saves the include declarations for a '<code>Class</code>'
	 */
	public void save()
	{
		if(selectedClass == null) {
			/* Log.debug("saveBody : selectedOperation is null"); */
		} else {
			CommandSupport.exec("C++ header/body save", new Runnable() {

				public void run() {
					if(headerDocument.get().equals("")
						&& bodyDocument.get().equals("")) {
						StereotypeUtil.unapply(selectedClass, Include.class);
					} else {
						Include cppInclude = StereotypeUtil.applyApp(selectedClass, Include.class);
						cppInclude.setHeader(headerDocument.get());
						cppInclude.setBody(bodyDocument.get());
					}
				}
			});
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cea.accordcpp.core.ui.panels.AccordCppAbstractPanel#entryAction()
	 */
	public void entryAction() {
		super.entryAction();
		reset();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cea.accordcpp.core.ui.panels.AccordCppAbstractPanel#checkModifications()
	 */
	@Override
	public boolean checkModifications() {
		String headerInModel = "";
		String bodyInModel = "";

		Include cppInclude = UMLUtil.getStereotypeApplication(selectedClass, Include.class);
		if(cppInclude != null) {
			headerInModel = cppInclude.getHeader();
			bodyInModel = cppInclude.getBody();
		}

		boolean headerChanged = !headerDocument.get().equals(headerInModel);
		boolean bodyChanged = !bodyDocument.get().equals(bodyInModel);

		return (headerChanged | bodyChanged);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.cea.accordcpp.core.ui.panels.AccordCppAbstractPanel#refreshPanel()
	 */
	@Override
	protected void refreshPanel() {
		if(selectedClass == null) {
		}
		else {
			Include cppInclude = UMLUtil.getStereotypeApplication(selectedClass, Include.class);
			if(cppInclude != null) {
				// get the text in the tagged value
				String currentHI = cppInclude.getHeader();
				headerDocument.set(currentHI);
				String currentBI = cppInclude.getBody();
				bodyDocument.set(currentBI);
			} else {
				headerDocument.set("");
				bodyDocument.set("");
			}
		}
	}
}

Back to the top