use of org.osate.ge.ba.ui.properties.EditableEmbeddedTextValue in project osate2 by osate.
the class EmbeddedTextEditor method createControls.
private void createControls(final GridData styledTextLayoutData) {
// Create styled text
styledText = new StyledText(this, styledTextStyle);
styledText.setEditable(false);
// Set empty caret so that the caret will not show.
// Makes sure users know it is not editable.
// Note: If caret is set to null, exception may occur
// when used with the StyledTextXtextAdapter.
final Caret emptyCaret = new Caret(getShell(), SWT.NONE);
styledText.setCaret(emptyCaret);
styledText.setLayoutData(styledTextLayoutData);
styledText.addDisposeListener(e -> emptyCaret.dispose());
editBtn = new Button(this, SWT.PUSH);
editBtn.setText("Edit...");
editBtn.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
final EditableEmbeddedTextValue embeddedTextValue = xtextAdapter.getEmbeddedTextValue();
final NamedElement ne = embeddedTextValue.getElementToModify();
final EditEmbeddedTextDialog dlg = new EditEmbeddedTextDialog(Display.getCurrent().getActiveShell(), embeddedTextValue, styledTextStyle, styledTextLayoutData);
if (dlg.open() == Window.OK) {
// Edit condition
BehaviorAnnexSelectionUtil.getActiveEditor().ifPresent(editorPart -> {
final ActionService actionService = Adapters.adapt(editorPart, ActionService.class);
final ModelChangeNotifier modelChangeNotifier = Objects.requireNonNull(editorPart.getAdapter(ModelChangeNotifier.class), "Unable to get model change notifier");
final IXtextDocument xtextDocument = getXtextDocument(ne).orElse(null);
if (xtextDocument != null) {
// Execute modification with xtext document
actionService.execute(embeddedTextValue.getModificationLabel(), ExecutionMode.NORMAL, new EmbeddedTextModificationAction(xtextDocument, modelChangeNotifier, dlg.getResult().getFullSource()));
} else {
final XtextResource xtextResource = getXtextResource(ne).orElseThrow();
embeddedTextValue.setEditableText(dlg.getResult().getPartialSource());
// Execute modification with xtext resource
actionService.execute(embeddedTextValue.getModificationLabel(), ExecutionMode.NORMAL, new EmbeddedTextModificationAction(xtextResource, modelChangeNotifier, embeddedTextValue));
}
});
}
}));
}
Aggregations