Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Collapse All/Expand All for Outline View
Collapse All/Expand All for Outline View [message #803405] Tue, 21 February 2012 09:49 Go to next message
Sreekanth SC is currently offline Sreekanth SCFriend
Messages: 14
Registered: January 2011
Junior Member
Currently I am working on XText based Editor and Outline, and I have an editor defined for xtext and an outline view to show the elements in the editor. Its the normal eclipse outline view and it has options A-Z sorting and Link with editor toolbar buttons.
Now I have a requirement to add Collapse_All and Expand_All toolbar buttons to this Outline view. I tried some options with eclipse ui ViewActions, but no luck with it.
Is there any way I can do this?

Any help in this regard is appreciated. Thanks Smile
Re: Collapse All/Expand All for Outline View [message #804298 is a reply to message #803405] Wed, 22 February 2012 12:49 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Should be simple
1) implement the desired behavior in an org.eclipse.jface.action.Action
that implements IOutlineContribution
2) bind it to the IOutlineContribution interface with a new binding
annotation in the UI module of your language

1) is not very Xtext specific. The IOC allows you to access the
OutlinePage and its TreeViewer
2) could look like

public void configureExpandAction(Binder binder) {
binder.bind(org.eclipse.jface.viewers.ILabelProvider.class)
.annotatedWith(Names.named("expandOutline")
.to(MyExpandAction.class);
}



Am 21.02.12 10:49, schrieb Chikki Mising name:
> Currently I am working on XText based Editor and Outline, and I have an
> editor defined for xtext and an outline view to show the elements in the
> editor. Its the normal eclipse outline view and it has options A-Z
> sorting and Link with editor toolbar buttons.
> Now I have a requirement to add Collapse_All and Expand_All toolbar
> buttons to this Outline view. I tried some options with eclipse ui
> ViewActions, but no luck with it.
> Is there any way I can do this?
> Any help in this regard is appreciated. Thanks :)


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Re: Collapse All/Expand All for Outline View [message #805227 is a reply to message #804298] Thu, 23 February 2012 14:18 Go to previous messageGo to next message
John J. Camilleri is currently offline John J. CamilleriFriend
Messages: 33
Registered: November 2011
Location: Göteborg
Member
I too struggled with this for a while, but managed to get it working.
My full code snippets:

ExpandAllAction.java
package mydsl.ui.editor.outline;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.xtext.ui.editor.outline.impl.OutlinePage;
import org.eclipse.xtext.ui.editor.outline.actions.IOutlineContribution;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;

public class ExpandAllAction extends Action implements IOutlineContribution {
  
  private Action action;
  
  TreeViewer treeViewer;

  protected Action getAction() {
    if (action == null) {
      action = this;
      configureAction(action);
    }
    return action;
  }

  protected void configureAction(Action action) {
    action.setText("Expand All");
    action.setToolTipText("Expand All");
    action.setDescription("Expand All");
    action.setImageDescriptor(...);
    action.setDisabledImageDescriptor(...);
  }

  @Override
  public void run() {
    treeViewer.expandAll();
  }
  
  public void initialize(IPreferenceStoreAccess access) {
  }
  
  public void register(OutlinePage outlinePage) {
    IToolBarManager toolBarManager = outlinePage.getSite().getActionBars().getToolBarManager();
    toolBarManager.add(getAction());
    treeViewer = outlinePage.getTreeViewer();
  }

  public void deregister(OutlinePage outlinePage) {
    treeViewer = null;
  }  
}


MyDSLUiModule.java
import org.eclipse.xtext.ui.editor.outline.actions.IOutlineContribution;
import mydsl.ui.editor.outline.ExpandAllAction;

public void configureExpandAction(Binder binder) {
  binder.bind(IOutlineContribution.class).annotatedWith(Names.named("expandOutline")).to(ExpandAllAction.class);
}

Re: Collapse All/Expand All for Outline View [message #805776 is a reply to message #805227] Fri, 24 February 2012 05:45 Go to previous message
Sreekanth SC is currently offline Sreekanth SCFriend
Messages: 14
Registered: January 2011
Junior Member
Hi Jan and John,

Thanks for the replies. I followed the steps and it worked Smile Thanks again!.
Previous Topic:When to use createLiveScopeResourceDescriptions?
Next Topic:Terminals vs Datatypes vs Rules
Goto Forum:
  


Current Time: Thu Apr 09 21:23:36 GMT 2020

Powered by FUDForum. Page generated in 0.05892 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top