Transfer Dialog in menu handler

Hello everyone,

I started reading a bit more about the Java classes and found the SelectElementsFromTransferWizard one, which apparently is the one used to select many elements from a specific type of model. I wanted to create a similar dialog to open when my plugin handler is called, like so:

public class InitHandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
	 
		Collection<Session> col_Sessions =  SessionManager.INSTANCE.getSessions();
		List<String> str = new ArrayList<String>();
		for (Session x : col_Sessions) {
			java.lang.System.out.println(x.getID());
			str.add(x.getID());
		}
		ElementListSelectionDialog diag = new ElementListSelectionDialog(window.getShell(), new LabelProvider());
		diag.setElements(col_Sessions.toArray());
		
		diag.setMessage("Please select the session (.aird file)");
		diag.setTitle("Project Selection");
		diag.setMultipleSelection(false);
		Session result = null; 
		if (diag.open() == Window.OK) {
		   result =  (Session)diag.getFirstResult();
		}
		else {
			return null;
		}
	
		SelectElementsFromTransferWizard tranfer_Wizard = new(...)
		// Do stuff with select elements here.
		
		return null;
	}
}

However, it seems that every usage of that class is, in fact, inside an .odesign file, and hacking a direct way to use it doesn’t seem the “Eclipse” way of doing it. Having said that, how should I use an odesign definition alongside my handler?
As an example, here is the oa.odesign tool definition:

<subModelOperations xsi:type="tool:ExternalJavaAction" name="Select Function" forceRefresh="true" id="org.polarsys.capella.core.sirius.analysis.actions.extensions.SelectElementsFromTransferWizard">
                    <parameters name="context" value="aql:container"/>
                    <parameters name="scope" value="aql:self.void2Null(container.getOESScopeInsertEntitiesRoles())"/>
                    <parameters name="initialSelection" value="aql:containerView.eContainerOrSelf(diagram::DDiagram).eAllContents(viewpoint::DSemanticDecorator).target->filter(interaction::InstanceRole).representedInstance"/>
                    <parameters name="wizardMessage" value=""/>
                    <parameters name="resultVariable" value="result"/>
                  </subModelOperations>
                  <subModelOperations xsi:type="tool:For" expression="aql:self.void2Null(result)">
                    <subModelOperations xsi:type="tool:If" conditionExpression="aql:i != 'WIZARD_CANCELED'">
                      <subModelOperations xsi:type="tool:ChangeContext" browseExpression="aql:container">
                        <subModelOperations xsi:type="tool:If" conditionExpression="aql:not (containerView.eContainerOrSelf(diagram::DDiagram).eAllContents(viewpoint::DSemanticDecorator).target->filter(interaction::InstanceRole).representedInstance->includes(i))">
                          <subModelOperations xsi:type="tool:CreateInstance" typeName="interaction.InstanceRole" referenceName="ownedInstanceRoles">
                            <subModelOperations xsi:type="tool:SetValue" featureName="representedInstance" valueExpression="aql:i"/>
                            <subModelOperations xsi:type="tool:SetValue" featureName="name" valueExpression="aql:i.name"/>
                          </subModelOperations>
                          <subModelOperations xsi:type="tool:ChangeContext" browseExpression="aql:self.reorderInstanceRole(instance,predecessor)"/>
                          <subModelOperations xsi:type="tool:ChangeContext" browseExpression="aql:self.ensureCapabilityInvolvment(i.abstractType)"/>
                        </subModelOperations>
                      </subModelOperations>
                    </subModelOperations>
                  </subModelOperations>

As a matter of fact, I found a snippet of code (BrowseRenderer.java) that actually creates the TransferTreeListDialog directly:

Collection<EObject> current = (Collection) propertyContext.getCurrentValue(restraintProperty);
        Collection<EObject> left = new HashSet<EObject>();
        left.addAll((Collection) restraintProperty.getValue(propertyContext));
        left.addAll((Collection) restraintProperty.getChoiceValues(propertyContext));
        left.removeAll(current);
        left.remove(null);
        Collection<EObject> right = new HashSet<EObject>();
        right.addAll(current);
        right.remove(null);

        TransferTreeListDialog dialog = new TransferTreeListDialog(shell, "Selection wizard", "Select elements.");//$NON-NLS-2$
        dialog.setLeftInput(new ArrayList<EObject>(left), null);
        dialog.setRightInput(new ArrayList<EObject>(right), null);
        if (dialog.open() == Window.OK) {
          Object[] dialogResult = dialog.getResult();
          ArrayList<Object> result = new ArrayList<Object>();
          if (dialogResult != null) {
            for (Object res : dialogResult) {
              result.add(res);
            }
          }
          changeValue(property, context, result);
          updatedValue(property, context, result);

I think I will be using this - although I’d like to know if my original approach would be feasible (Java to .odesign definition).

1 Like