capint
1/17/2016 - 5:40 PM

GMF >> Edit Policy >> Add an additional edit policy

GMF >> Edit Policy >> Add an additional edit policy

public class TabbedPropertiesWizardEditPolicy extends AbstractEditPolicy {
  /**
   * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#getCommand(org.eclipse.gef.Request)
   */
  @Override
  public Command getCommand(final Request request) {
    if (RequestConstants.REQ_OPEN.equals(request.getType())) {
      Command cmd = new ICommandProxy(new GMFCommandWrapper(getEditingDomain(), new IdentityCommand(getEditingDomain()) {

          @Override
          public void execute() {
            new OpenCustomWizardCommand(modelElement).run();
          }

          @Override
          public String getLabel() {
            return Messages.CustomWizardHandler_Command_Title;
          }

        }));

        return cmd;
    }
    return null;
  }
}
public class TabbedPropertiesEditPolicyProvider implements IEditPolicyProvider {

  /**
   * @see org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider#createEditPolicies(org.eclipse.gef.EditPart)
   */
  public void createEditPolicies(final EditPart editPart) {
        final CompoundEditPolicy compoundEditPolicy = new CompoundEditPolicy();
        compoundEditPolicy.setAllowNullCommand(false);

        //*** This line gets the edit policy for the open command on a GMF edit part
        final EditPolicy existingPolicy = diagramElementEditPart.getEditPolicy(EditPolicyRoles.OPEN_ROLE);
        if (existingPolicy != null) {
          compoundEditPolicy.addEditPolicy(existingPolicy);
        }

        //*** This 2 lines adds another EditPolicy when an edit part is opened (by double click on it for example) 
        compoundEditPolicy.addEditPolicy(new TabbedPropertiesWizardEditPolicy());
        diagramElementEditPart.installEditPolicy(EditPolicyRoles.OPEN_ROLE, compoundEditPolicy);
  }
}
<extension
         point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
      <editpolicyProvider
            class="org.polarsys.capella.core.ui.properties.policies.TabbedPropertiesEditPolicyProvider">
         <Priority
               name="Highest">
         </Priority>
      </editpolicyProvider>
   </extension>