capint
1/18/2016 - 6:09 PM

Eclipse >> Handler

Eclipse >> Handler

A HANDLER is the implementation of a COMMAND's behaviour. Any plugin can contribute a handler implementation for any command. 
The workbench uses CORE EXPRESSIONs and programmatic scoping rules to determine which handler is active at any time. 
There can either be one handler active for the command, or no handlers active for the command (the command is effectively disabled). 
When the command has an active handler, we say the command is handled. 

Source: http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_cmd_handlers.htm
<activeWhen>
  <with variable="selection">
      <and>
          <count value="2"/>
          <iterate ifEmpty="false" operator="and">
            <test forcePluginActivation="true"
                  property="com.thalesgroup.mde.melody.transition.xlsmodel.xmImport">
            </test>
          </iterate>
      </and>
  </with>
</activeWhen>

<extension point="org.eclipse.core.expressions.propertyTesters">
  <propertyTester
      id="com.thalesgroup.mde.melody.transition.xlsmodel.graphicalProperty"
      type="org.eclipse.core.resources.IFile"
      namespace="com.thalesgroup.mde.melody.transition.xlsmodel"
      properties="xmImport,xmExport"
      class="com.thalesgroup.mde.melody.xlsmodel.ui.testers.CommandTester">
  </propertyTester>
</extension>

public class CommandTester extends PropertyTester {
  @Override
  public boolean test(Object object_p, String propertyName_p, Object[] params_p, Object testedValue_p) {
    //...
  }
}
<activeWhen>
 <with variable="selection">
  <count value="1" />
  <iterate operator="and">
   <adapt type="org.eclipse.core.resources.IResource" />
  </iterate>
 </with>
</activeWhen>

<!-- List of available variables: https://wiki.eclipse.org/Command_Core_Expressions#Variables_and_the_Command_Framework -->
public abstract class AbstractReHandler extends AbstractHandler {
  public Object execute(final ExecutionEvent event_p) throws ExecutionException {
    return null;
  }
}
<extension point="org.eclipse.ui.handlers"> <!-- should be named org.eclipse.core.handlers -->
     <handler commandId="org.polarsys.capella.common.re.createRec"
            class="org.polarsys.capella.core.re.ui.handlers.CreateRecUiHandler">
         <activeWhen>
            <and>
                <test forcePluginActivation="true" property="org.polarsys.capella.core.re.activation" value="true" />
                <reference definitionId="org.polarsys.capella.core.isInCapellaContext" />
            </and>
         </activeWhen>
     </handler>
</extension>