Skip to content

Commit

Permalink
#9 Add quickfix to remove references to out of scope elements
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Dorner <[email protected]>
  • Loading branch information
felixdo committed Jun 2, 2021
1 parent 30f7c9e commit 83d84e0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ Automatic-Module-Name: org.polarsys.capella.vp.ms.validation
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.emf.validation;bundle-version="1.8.0",
org.polarsys.capella.core.validation;bundle-version="[1.4.0,1.5.0)",
org.polarsys.capella.vp.ms
org.polarsys.capella.vp.ms,
org.polarsys.capella.core.validation.ui.ide
Export-Package: org.polarsys.capella.vp.ms.validation
11 changes: 11 additions & 0 deletions plugins/org.polarsys.capella.vp.ms.validation/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,16 @@
</constraints>
</constraintProvider>
</extension>
<extension
point="org.polarsys.capella.core.validation.ui.ide.capellaQuickFix">
<resolver
class="org.polarsys.capella.vp.ms.validation.ConfigurationElementsInScope$Quickfix"
desc="Remove the reference to the element not in scope"
label="Remove reference to element">
<rules
ruleId="ElementsMustBeInScope">
</rules>
</resolver>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.emf.validation.EMFEventType;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.emf.validation.model.ConstraintStatus;
import org.polarsys.capella.core.validation.rule.AbstractValidationRule;
import org.polarsys.capella.core.validation.ui.ide.quickfix.AbstractCapellaMarkerResolution;
import org.polarsys.capella.vp.ms.CSConfiguration;

public class ConfigurationElementsInScope extends AbstractValidationRule {
Expand Down Expand Up @@ -53,4 +59,22 @@ public IStatus validate(IValidationContext ctx) {
return ctx.createSuccessStatus();
}

public static class Quickfix extends AbstractCapellaMarkerResolution {
@Override
public void run(IMarker marker) {
List<EObject> e = getModelElements(marker);
CSConfiguration c = (CSConfiguration) e.remove(0);
TransactionalEditingDomain d = TransactionUtil.getEditingDomain(c);
d.getCommandStack().execute(new RecordingCommand(d) {
@Override
protected void doExecute() {
c.getIncluded().removeAll(e);
c.getExcluded().removeAll(e);
}
});
deleteMarker(marker);
}

}

}

0 comments on commit 83d84e0

Please sign in to comment.