Vishal Sharnagat
Vishal Sharnagat

Reputation: 83

Eclipse UML2 migration issue

The Eclipse platform for RCP application is migrated from 4.6.3 to 4.23 (it's too old version but got the support till next year). With this change, the Eclipse UML2 is also migrated from 3.x to 5.x. Luckily, there are not many code changes introduced as part of this migration. Only createNode() has to be replaced with createOwnedNode() as below:

umlNode = (InitialNode)getActivity().createOwnedNode(name = (name != null)? name : GRAPH_NODE_INITIAL, UMLPackage.eINSTANCE.getInitialNode());

However, with this change/migration, the nodes are not getting created in Activity Diagram Editor with below exception:

!ENTRY org.eclipse.ui 4 0 2024-09-23 09:10:49.257
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NullPointerException
    at org.eclipse.epf.diagram.core.actions.CreateElementAction.run(CreateElementAction.java:51)
    at org.eclipse.jface.action.Action.runWithEvent(Action.java:474)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:580)
    at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:414)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4243)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1063)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1087)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1072)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:775)
    at org.eclipse.jface.action.ActionContributionItem.lambda$8(ActionContributionItem.java:1207)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4243)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1063)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4060)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3632)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
    at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)

Upon debugging, it is learnt that the below line returns null command:

    Command cmd = getDiagramEditPart().getCommand(req);

I compared the returned command with older UML2 3.x libraries and found that it was returning command of type ICommandProxy which has executable property. The command object created by new UML2 5.x is not executable and returns null from below class and method:

    class org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy extends AbstractEditPolicy

    /**
 * Method getCreateElementAndViewCommand.
 * 
 * @param request
 * @return Command Which creates the sematnic and the view command for the
 *         given CreateViewAndElementRequest
 */
protected Command getCreateElementAndViewCommand(CreateViewAndElementRequest request) {
    // get the element descriptor
    CreateElementRequestAdapter requestAdapter =
        request.getViewAndElementDescriptor().getCreateElementRequestAdapter();

    // get the semantic request
    CreateElementRequest createElementRequest =
        (CreateElementRequest) requestAdapter.getAdapter(
            CreateElementRequest.class);

    if (createElementRequest.getContainer() == null) {
        // complete the semantic request by filling in the host's semantic
        // element as the context
        View view = (View)getHost().getModel();
        EObject hostElement = ViewUtil.resolveSemanticElement(view);
        
        if (hostElement == null && view.getElement() == null) {
            hostElement = view;
        }           

        // Returns null if host is unresolvable so that trying to create a
        // new element in an unresolved shape will not be allowed.
        if (hostElement == null) {
            return null;
        }
        createElementRequest.setContainer(hostElement);
    }

    // get the create element command based on the elementdescriptor's
    // request
    Command createElementCommand =
        getHost().getCommand(
            new EditCommandRequestWrapper(
                (CreateElementRequest)requestAdapter.getAdapter(
                    CreateElementRequest.class), request.getExtendedData()));

    if (createElementCommand == null) { 
        return UnexecutableCommand.INSTANCE;
    }       
    if(!createElementCommand.canExecute()){
        return createElementCommand;
    }
    // create the semantic create wrapper command
    SemanticCreateCommand semanticCommand =
        new SemanticCreateCommand(requestAdapter, createElementCommand);
    Command viewCommand = getCreateCommand(request);

    Command refreshConnectionCommand =
        getHost().getCommand(
            new RefreshConnectionsRequest(((List)request.getNewObject())));


    // form the compound command and return
    CompositeCommand cc = new CompositeCommand(semanticCommand.getLabel());
    cc.compose(semanticCommand);
    cc.compose(new CommandProxy(viewCommand));
    if ( refreshConnectionCommand != null ) {
        cc.compose(new CommandProxy(refreshConnectionCommand));
    }

    return new ICommandProxy(cc);
}

The code returns non executable object from below lines of code and nodes are not getting created in activity diagram:

    if(!createElementCommand.canExecute()){
       return createElementCommand;
    }

May I know if:

  1. Am I missing something in the migration from UML2 3.x to UML2 5.x?
  2. Any pointers on how to get nodes created would be helpful.

Thanks in advance.

Upvotes: 1

Views: 24

Answers (0)

Related Questions