Search in sources :

Example 1 with AbstractSCTResource

use of org.yakindu.sct.model.sgraph.resource.AbstractSCTResource in project statecharts by Yakindu.

the class DomainSpecificTaskFinder method findTasks.

@Override
public List<Task> findTasks(Resource resource) {
    if (resource instanceof AbstractSCTResource) {
        IDomain domain = DomainRegistry.getDomain((EObject) EcoreUtil2.getObjectByType(resource.getContents(), SGraphPackage.Literals.STATECHART));
        ITaskFinder taskFinder = domain.getInjector(IDomain.FEATURE_RESOURCE).getInstance(ITaskFinder.class);
        if (taskFinder != null)
            return taskFinder.findTasks(resource);
    }
    return Collections.emptyList();
}
Also used : IDomain(org.yakindu.sct.domain.extension.IDomain) AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource) ITaskFinder(org.eclipse.xtext.tasks.ITaskFinder)

Example 2 with AbstractSCTResource

use of org.yakindu.sct.model.sgraph.resource.AbstractSCTResource in project statecharts by Yakindu.

the class ViewBasedRefactoringTest method testRefactoring.

protected void testRefactoring(String pathToInitialSct, String pathToExpectedSct, String contextElementName) {
    Statechart initial = models.loadStatechartFromResource(pathToInitialSct);
    TransactionalEditingDomainImpl.FactoryImpl.INSTANCE.createEditingDomain(initial.eResource().getResourceSet());
    View contextView = getViewForState(initial, contextElementName);
    AbstractRefactoring<View> refactoring = getRefactoring();
    refactoring.setContextObjects(Collections.singletonList(contextView));
    AbstractSCTResource initialRes = (AbstractSCTResource) initial.eResource();
    initialRes.setSerializerEnabled(true);
    refactoring.execute();
    initialRes.setSerializerEnabled(false);
    Statechart expected = models.loadStatechartFromResource(pathToExpectedSct);
    compareStatecharts(initial, expected);
}
Also used : AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource) Statechart(org.yakindu.sct.model.sgraph.Statechart) View(org.eclipse.gmf.runtime.notation.View)

Example 3 with AbstractSCTResource

use of org.yakindu.sct.model.sgraph.resource.AbstractSCTResource in project statecharts by Yakindu.

the class RenameRefactoringTest method testRenaming.

private void testRenaming(Statechart initial, Statechart expected, NamedElement elementToRename, String newName) {
    RenameRefactoring refactoring = new RenameRefactoring();
    refactoring.setContextObjects(Lists.newArrayList(elementToRename));
    refactoring.setNewName(newName);
    AbstractSCTResource initialRes = (AbstractSCTResource) initial.eResource();
    initialRes.setSerializerEnabled(true);
    refactoring.internalExecute();
    initialRes.setSerializerEnabled(false);
    compareStatecharts(initial, expected);
}
Also used : AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource)

Example 4 with AbstractSCTResource

use of org.yakindu.sct.model.sgraph.resource.AbstractSCTResource in project statecharts by Yakindu.

the class StateBasedRefactoringTest method testRefactoringOnState.

protected void testRefactoringOnState(String pathToInitialSct, String pathToExpectedSct, String stateName) {
    Statechart initial = models.loadStatechartFromResource(pathToInitialSct);
    State state = getStateByName(initial, stateName);
    AbstractRefactoring<?> refactoring = getRefactoring(state);
    AbstractSCTResource initialRes = (AbstractSCTResource) initial.eResource();
    initialRes.setSerializerEnabled(true);
    refactoring.executeRefactoring();
    initialRes.setSerializerEnabled(false);
    Statechart expected = models.loadStatechartFromResource(pathToExpectedSct);
    compareStatecharts(initial, expected);
}
Also used : AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource) State(org.yakindu.sct.model.sgraph.State) Statechart(org.yakindu.sct.model.sgraph.Statechart)

Example 5 with AbstractSCTResource

use of org.yakindu.sct.model.sgraph.resource.AbstractSCTResource in project statecharts by Yakindu.

the class DefaultValidationJob method runInternal.

@Override
protected IStatus runInternal(final IProgressMonitor monitor) {
    try {
        if (!resource.isLoaded())
            return Status.CANCEL_STATUS;
        if (resource instanceof AbstractSCTResource) {
            relinkModel(monitor, (AbstractSCTResource) resource);
        }
        if (monitor.isCanceled())
            return Status.CANCEL_STATUS;
        TransactionalValidationRunner runner = new TransactionalValidationRunner(validator, resource, CheckMode.FAST_ONLY, new CancelIndicator() {

            public boolean isCanceled() {
                return monitor.isCanceled();
            }
        });
        TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(resource);
        if (editingDomain == null)
            return Status.CANCEL_STATUS;
        try {
            editingDomain.runExclusive(runner);
        } catch (Throwable ex) {
            // Since xtext 2.8 this may throw an OperationCanceledError
            return Status.CANCEL_STATUS;
        }
        final List<Issue> issues = runner.getResult();
        if (issues == null)
            return Status.CANCEL_STATUS;
        validationIssueProcessor.processIssues(issues, monitor);
    } catch (Exception ex) {
        ex.printStackTrace();
        return new Status(IStatus.ERROR, DiagramActivator.PLUGIN_ID, ex.getMessage());
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) Issue(org.eclipse.xtext.validation.Issue) AbstractSCTResource(org.yakindu.sct.model.sgraph.resource.AbstractSCTResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) ExecutionException(org.eclipse.core.commands.ExecutionException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Aggregations

AbstractSCTResource (org.yakindu.sct.model.sgraph.resource.AbstractSCTResource)7 Statechart (org.yakindu.sct.model.sgraph.Statechart)3 State (org.yakindu.sct.model.sgraph.State)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IStatus (org.eclipse.core.runtime.IStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Status (org.eclipse.core.runtime.Status)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 View (org.eclipse.gmf.runtime.notation.View)1 ITaskFinder (org.eclipse.xtext.tasks.ITaskFinder)1 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)1 Issue (org.eclipse.xtext.validation.Issue)1 Test (org.junit.Test)1 IDomain (org.yakindu.sct.domain.extension.IDomain)1 RefactoringTest (org.yakindu.sct.refactoring.refactor.RefactoringTest)1