Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Capella/Tutorials/Extensibility/Quick Fixes

< Capella‎ | Tutorials
Revision as of 12:16, 31 January 2017 by Christophe.gatti@thalesgroup.com (Talk) (Source code =)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Quick Fixes

Introduction

Capella offers a quick fix functionality. This functionality helps users to resolve some problems thrown by model validation warnings or errors. The quick fixes are available through a contextual menu command on a selected message (in the view Information) that provides one, or several, resolution proposals. The set of resolution proposals can be extended with additional specific quick fixes that can be contributed through an extension point.

Extension point description

An Eclipse extension point allows plug-ins to contribute constraints into the Capella quick fix framework. The extension point is provided by the plug-in org.polarsys.capella.core.validation.ui.ide and its identifier is capellaQuickFix.

Provided by bundle: org.polarsys.capella.core.validation.ui.ide


Here is an example of contribution declaration (see in plugin.xml file):

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension point="org.polarsys.capella.core.validation.ui.ide.capellaQuickFix">
      <resolver
            class=""
            desc=""
            icon=""
            label="">
         <rules ruleId=""/>
      </resolver>
   </extension>
</plugin>


with:

  • class: the resolver class (generated, see below for more details)
  • icon: path to the icon to override the default one
  • label: a short name for the quick fix
  • ruleId: the identifier of the rule the quick fix is related to

Quick fix implementation

In this example quick fix, we fill all the CapellaElement that do not have any description or any summary with a dummy text.

  • Create a new plug-in project in Capella Studio or Eclipse (with Capella TP configured)
  • The plug-in perspective opens and plugin.xml file is displayed in the editor
  • Select Extensions tab
  • Select Add...
  • Uncheck Show only extensions points from the required plug-ins box
  • Enter org.polarsys.capella.core.validation.ui.ide.capellaQuickFix
  • Finish
  • Accept to add the required plug-in as dependency when prompted

A resolver is created. Select it and in the right part of the window, click on the keyword class*:. It opens a wizard to create the class. Click on Finish. The class is created.

  • Open the MANIFEST.MF file in META-INF directory of the project
  • Add the missing Required-Bundle: as follow:
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.polarsys.capella.core.validation.ui.ide,
 org.eclipse.emf.ecore,
 org.eclipse.core.resources,
 org.polarsys.capella.common.helpers,
 org.polarsys.capella.common.ef,
 org.polarsys.capella.core.data.gen


  • Save the file
  • Open the previously generated class and fill it as follow:
package org.polarsys.capella.myquickfix;

import java.util.List;

import org.eclipse.core.resources.IMarker;
import org.eclipse.emf.ecore.EObject;
import org.polarsys.capella.common.ef.command.AbstractReadWriteCommand;
import org.polarsys.capella.common.helpers.TransactionHelper;
import org.polarsys.capella.common.mdsofa.common.constant.ICommonConstants;
import org.polarsys.capella.core.data.capellacore.CapellaElement;

public class AbstractCapellaMarkerResolution
		extends org.polarsys.capella.core.validation.ui.ide.quickfix.AbstractCapellaMarkerResolution {
	  /**
	   * @see org.eclipse.ui.IMarkerResolution#run(org.eclipse.core.resources.IMarker)
	   */
	  @Override
	  public void run(final IMarker marker_p) {
	    final List<EObject> modelElements = getModelElements(marker_p);
	    if (!modelElements.isEmpty()) {
	      // execute a read write command
	      TransactionHelper.getExecutionManager(modelElements).execute(new AbstractReadWriteCommand() {
	        /**
	         * @see java.lang.Runnable#run()
	         */
	        public void run() {
	          for (EObject obj : modelElements) {
	            if (obj instanceof CapellaElement) {
	              CapellaElement element = (CapellaElement) obj;
	              String summary = element.getSummary();
	              if ((null == summary) || ICommonConstants.EMPTY_STRING.equals(summary)) {
	                element.setSummary("generated summary"); //$NON-NLS-1$
	              }
	              String description = element.getDescription();
	              if ((null == description) || ICommonConstants.EMPTY_STRING.equals(description)) {
	                element.setDescription("generated description"); //$NON-NLS-1$
	              }
	            }
	          }
	        }
	      });
	    }
	  }

}


  • Open the plugin.xml file with text editor and add the ruleId of the previous post validation rule as follow:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.polarsys.capella.core.validation.ui.ide.capellaQuickFix">
      <resolver
            class="org.polarsys.capella.myquickfix.AbstractCapellaMarkerResolution"
            label="fix summary n description">
         <rules
               ruleId="DWF_PA_99">
         </rules>
      </resolver>
   </extension>
</plugin>


  • Start Capella using Run Configuration... and run a product: org.polarsys.capella.core.platform.sirius.ui.perspective.product
  • Create a Capella project within Capella
  • Add a new Capella element (a new Physical Function in the Physical Architecture)
  • Add the validation rule DWF_PA_99 in the preferences (Windows > Preferences > Model Validation > Constraints > Capella > Design > Well-formedness > Data and close the preferences
  • Launch the model validation using the contextual menu on the child level of the aird
  • A window is displayed, close it
  • The validation report is displayed in the Information view
  • Expand the validation reports and right-click on the result of the rule of interest


Quickfix.png

  • Select the quickfix
  • Go back the the Physical Function
  • Open the Properties view
  • In tab Capella, check that the summary has been filled
  • In tab description, check that the description has been filled

Source code

Please find attached the source code of the example.

File:Sample quickfix.zip

Back to the top