New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AADL Navigator: Double click on expanded file content doesn't open text editor #1432

Closed
lwrage opened this Issue Aug 3, 2018 · 12 comments

Comments

Projects
None yet
2 participants
@lwrage
Contributor

lwrage commented Aug 3, 2018

No description provided.

@lwrage

This comment has been minimized.

Contributor

lwrage commented Aug 15, 2018

But single click does when link with editor is active.

@lwrage lwrage added next in progress and removed backlog next labels Aug 18, 2018

@lwrage lwrage self-assigned this Aug 18, 2018

@lwrage lwrage added next and removed in progress labels Aug 20, 2018

@lwrage lwrage removed their assignment Aug 20, 2018

@lwrage lwrage added this to the 2.3.6 milestone Aug 29, 2018

@lwrage

This comment has been minimized.

Contributor

lwrage commented Aug 31, 2018

Single click should no longer open the file. Opening on double click happens automatically if there is an open command.

@lwrage lwrage self-assigned this Sep 1, 2018

@AaronGreenhouse AaronGreenhouse added in progress and removed next labels Sep 26, 2018

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 26, 2018

Actually I cannot get single click to open a file

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 26, 2018

If the editor is open, a single click jumps to the syntactic item. This is from the link helper.

@lwrage

This comment has been minimized.

Contributor

lwrage commented Sep 26, 2018

Open on single click was fixed in connection with fixing a couple of issues in the link helper.

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 26, 2018

We have this in the plugin.xml to open the contributed aadl files:

      <actionProvider
            class="org.osate.ui.navigator.AadlNavigatorActionProvider"
            id="org.osate.ui.navigator.openContributed">
         <enablement>
            <instanceof
                  value="org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage">
            </instanceof>
         </enablement>
      </actionProvider>

Probably need something similar for the model elements

@lwrage

This comment has been minimized.

Contributor

lwrage commented Sep 26, 2018

Double click is handled in ComonNavigator.handleDoubleClick(). Not sure how to register an open command with the global action handler. Action provider may be the way to go...

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 27, 2018

Okay, yes, so the above is the key.
We need to register an action provider. Thta provider needs to have global action action handler for the OPEN event.

Here is that the above org.osate.ui.navigator.AadlNavigatorActionProvider has:

public class AadlNavigatorActionProvider extends CommonActionProvider {
	private final IURIEditorOpener editorOpener;

	public AadlNavigatorActionProvider() {
		Injector injector = Aadl2Activator.getInstance().getInjector(Aadl2Activator.ORG_OSATE_XTEXT_AADL2_AADL2);
		editorOpener = injector.getInstance(IURIEditorOpener.class);
	}

	@Override
	public void fillActionBars(IActionBars actionBars) {
		super.fillActionBars(actionBars);
		actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, new Action() {
			@Override
			public void run() {
				Object[] selectedElements = getActionSite().getStructuredViewer().getStructuredSelection().toArray();
				Stream<ContributedAadlStorage> files = Arrays.stream(selectedElements)
						.filter(file -> file instanceof ContributedAadlStorage)
						.map(file -> (ContributedAadlStorage) file);
				files.forEach(file -> editorOpener.open(file.getUri(), true));
			}
		});
	}
}

We need something a bit different because we want to target the editor to a particular location.

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 27, 2018

Actually, the open method takes a URI, so it shouldn't be too hard.

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 27, 2018

Did the following:

  1. Changed the enablement of the above action provider to include AObject (provided by the AadlElementContentProvider):
         <enablement>
         	<or>
	            <instanceof
	                  value="org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage"/>
	            <instanceof
	                  value="org.osate.aadl2.parsesupport.AObject"/>
            </or>
         </enablement>
  1. Added the "open" command to the context menu in the action provider:

	@Override
	public void fillContextMenu(final IMenuManager aMenu) {
		if (getContext().getSelection().isEmpty()) {
			return;
		}

		if (openFileAction.isEnabled()) {
			aMenu.insertAfter(ICommonMenuConstants.GROUP_OPEN, openFileAction);
		}
	}
  1. Updated the action itself to handle both ContributedAadlStorage and AObject:
		openFileAction = new Action() {
			{
				setText("&Open");
				setToolTipText("Open the contributed library in an AADL editor");
			}

			@Override
			public void run() {
				Object[] selectedElements = getActionSite().getStructuredViewer().getStructuredSelection().toArray();
				for (Object selected : selectedElements) {
					if (selected instanceof ContributedAadlStorage) {
						editorOpener.open(((ContributedAadlStorage) selected).getUri(), true);
					} else if (selected instanceof AObject) {
						editorOpener.open(EcoreUtil.getURI((AObject) selected), true);
					}
				}
			}
		};

And viola it's done.

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 28, 2018

Doesn't work for instance models.

Tracing through the debugger and seen open() does, the problem comes up in GlobalURIEditorOpener.selectAndReveal() where it tries to adapt the editor into an XTextEditor. This fails for Aadl2ModelEditor, and thus it cannot jump to the URI fragment.

@AaronGreenhouse

This comment has been minimized.

AaronGreenhouse commented Sep 28, 2018

Tried replacing

					} else if (selected instanceof AObject) {
						editorOpener.open(EcoreUtil.getURI((AObject) selected), true);
					}

with

					} else if (selected instanceof Element) {
						UiUtil.openEditorFor((Element) selected);
					}

but this doesn't jump to the correct node either.

Need to add method to UIUtil that opens the editor, adapts the EditorPart to an ISelectionProvider and sets the selection to the Element. I don't know if this will force the selection to be visible though.

@lwrage lwrage modified the milestones: 2.3.6, 2.3.5 Oct 1, 2018

@lwrage lwrage closed this in #1558 Oct 10, 2018

@wafflebot wafflebot bot removed the review label Oct 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment