use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.
the class STextJavaValidator method checkReactionTriggerRegularEvent.
@Check(CheckType.FAST)
public void checkReactionTriggerRegularEvent(ReactionTrigger reactionTrigger) {
for (int i = 0; i < reactionTrigger.getTriggers().size(); i++) {
EventSpec eventSpec = reactionTrigger.getTriggers().get(i);
if (eventSpec instanceof RegularEventSpec) {
EObject element = unwrap(((RegularEventSpec) eventSpec).getEvent());
if (element != null && (!(element instanceof Event))) {
String elementName = "";
if (element instanceof NamedElement) {
elementName = "'" + ((NamedElement) element).getName() + "' ";
}
error("Trigger " + elementName + "is no event.", StextPackage.Literals.REACTION_TRIGGER__TRIGGERS, i, TRIGGER_IS_NO_EVENT);
}
}
}
}
use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.
the class RenameRefactoring method internalExecute.
@Override
protected void internalExecute() {
NamedElement element = getContextObject();
Collection<EObject> elementReferers = findReferers(element);
element.setName(newName);
for (EObject referer : elementReferers) {
if (referer instanceof FeatureCall) {
FeatureCall featureCall = (FeatureCall) referer;
featureCall.setFeature(element);
} else if (referer instanceof ElementReferenceExpression) {
ElementReferenceExpression expr = (ElementReferenceExpression) referer;
expr.setReference(element);
}
}
}
use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.
the class RenameElementHandler method findElementForFakeInStatechart.
private NamedElement findElementForFakeInStatechart(NamedElement fakeElement) {
Resource resource = fakeElement.eResource();
// only do something if element is really from fake resource
if (resource instanceof LazyLinkingResource) {
Statechart sct = getStatechartFromFakeResource((LazyLinkingResource) resource);
EList<Scope> scopes = sct.getScopes();
for (Scope scope : scopes) {
// check all declarations
EList<Declaration> declarations = scope.getDeclarations();
for (Declaration decl : declarations) {
if (decl.eClass().getName().equals(fakeElement.eClass().getName()) && decl.getName().equals(fakeElement.getName())) {
return decl;
}
}
// check scope itself it is a named one
if (scope instanceof NamedElement) {
NamedElement namedScope = (NamedElement) scope;
if (namedScope.eClass().getName().equals(fakeElement.eClass().getName()) && namedScope.getName().equals(fakeElement.getName())) {
return namedScope;
}
}
}
}
return fakeElement;
}
use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.
the class RenameElementHandler method unwrap.
/**
* Unwraps the given selection into a state sgraph element
*
* @param selection the current selection
* @return the state sgraph element for the given selection
*/
public NamedElement unwrap(ISelection selection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
EObject selectedElement = (EObject) structuredSelection.getFirstElement();
// We need to find the actual element in our statechart for this fake element
if (selectedElement instanceof FeatureCall) {
return findElementForFakeInStatechart((NamedElement) ((FeatureCall) selectedElement).getFeature());
} else if (selectedElement instanceof ElementReferenceExpression) {
return findElementForFakeInStatechart((NamedElement) ((ElementReferenceExpression) selectedElement).getReference());
}
if (selectedElement instanceof NamedElement)
return findElementForFakeInStatechart((NamedElement) selectedElement);
return null;
}
use of org.yakindu.base.base.NamedElement in project statecharts by Yakindu.
the class RenameElementHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
NamedElement element = refactoring.getContextObject();
if (element != null) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
InputDialog dialog = new InputDialog(window.getShell(), "Rename..", "Please enter new name:", element.getName(), new NameUniquenessValidator(element));
if (dialog.open() == Window.OK) {
String newName = dialog.getValue();
if (newName != null) {
((RenameRefactoring) refactoring).setNewName(newName);
refactoring.execute();
}
}
}
return null;
}
Aggregations