-
Notifications
You must be signed in to change notification settings - Fork 11
/
HelperCommands.java
124 lines (114 loc) · 4.89 KB
/
HelperCommands.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
117
118
119
120
121
122
123
124
package org.polarsys.capella.scenario.editor.embeddededitor.commands;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.swt.widgets.Display;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.validation.CheckMode;
import org.eclipse.xtext.validation.IResourceValidator;
import org.eclipse.xtext.validation.Issue;
import org.polarsys.capella.core.data.capellacore.Constraint;
import org.polarsys.capella.core.data.information.datavalue.OpaqueExpression;
import org.polarsys.capella.core.data.interaction.InteractionOperand;
import org.polarsys.capella.core.data.interaction.Scenario;
import org.polarsys.capella.scenario.editor.EmbeddedEditorInstance;
import org.polarsys.capella.scenario.editor.dsl.provider.TextualScenarioProvider;
import org.polarsys.capella.scenario.editor.dsl.textualScenario.Model;
import org.polarsys.capella.scenario.editor.embeddededitor.views.EmbeddedEditorView;
import org.polarsys.capella.scenario.editor.helper.EmbeddedEditorInstanceHelper;
public class HelperCommands {
public static final String DIALOG_TITLE_UNABLE_TO_REFRESH = "Unable to refresh";
public static final String DIALOG_MESSAGE_ERROR_REFRESH = "Error on refreshing data to Textual Editor!";
public static final String DIALOG_TITLE_UNABLE_TO_SAVE = "Unable to save";
public static final String DIALOG_MESSAGE_ERROR_SAVE = "Error on saving data to diagram!";
public static String getExpressionText(InteractionOperand operand) {
Constraint guard = operand.getGuard();
if (guard != null) {
OpaqueExpression expression = (OpaqueExpression) guard.getOwnedSpecification();
return expression.getBodies().isEmpty() ? null : expression.getBodies().get(0);
}
return null;
}
public static List<Issue> getValidationIsuesTextResource(XtextResource resource) {
IResourceValidator validator = resource.getResourceServiceProvider().getResourceValidator();
if(validator != null) {
return validator.validate(resource, CheckMode.ALL, null);
}
return new ArrayList<>();
}
public static String getFormattedIssues(List<Issue> issues) {
StringBuilder sb = new StringBuilder();
String newLine = "\r\n";
int maxDisplay = 3;
sb.append(newLine + newLine + "Found " + issues.size() + " issues:" + newLine);
for (int i = 0; i < maxDisplay && i < issues.size(); i++) {
Issue issue = issues.get(i);
sb.append(
issue.getMessage() + " (line : " + issue.getLineNumber() + " column : " + issue.getColumn() + ")" + newLine);
}
if (issues.size() > maxDisplay) {
sb.append(newLine + "... " + (issues.size() - maxDisplay) + " more!" + newLine);
}
return sb.toString();
}
/**
* get the xtext model
*
* @param embeddedEditorViewPart
* - this is the embedded editor xtext object
* @return - Model the xtext model embedded in this editor view
*/
public static Model getModel(EmbeddedEditorView embeddedEditorViewPart) {
TextualScenarioProvider p = embeddedEditorViewPart.getProvider();
XtextResource resource = p.getResource();
EList<EObject> content = resource.getContents();
Model domainModel = null;
if (!content.isEmpty() && content.get(0) instanceof Model) {
domainModel = (Model) resource.getContents().get(0);
} else {
EmbeddedEditorInstanceHelper.updateModel("scenario {}");
EList<EObject> content1 = resource.getContents();
if (!content1.isEmpty() && content1.get(0) instanceof Model) {
domainModel = (Model) resource.getContents().get(0);
}
}
return domainModel;
}
/**
* clear the elements and participants in the xtext model
*
* @param domainModel
*/
public static void clearModel(Model domainModel) {
if (domainModel != null && domainModel.getParticipants() != null) {
domainModel.getParticipants().clear();
}
if (domainModel != null && domainModel.getElements() != null) {
domainModel.getElements().clear();
}
if (domainModel != null) {
domainModel.setBegin("{");
domainModel.setEnd("}");
}
}
public static void showDialogTextualEditor(String title, String message) {
MessageDialog.openError(Display.getCurrent().getActiveShell(), title, message);
}
/*
* refresh the text editor with the content from diagram
*/
public static void refreshTextEditor(EmbeddedEditorView eeView) {
DDiagram diagram = EmbeddedEditorInstance.getDDiagram();
if(diagram != null) {
Scenario scenario= EmbeddedEditorInstance.getAssociatedScenarioDiagram();
if(scenario != null) {
// refresh the text editor
DiagramToXtextCommands.process(scenario, eeView); // update the embedded editor text view
eeView.refreshTitleBar(scenario.getName());
}
}
}
}