Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Posts Tagged ‘eclipse ui’

on Apr 25th, 2009Having fun with detached views!

Yesterday, I had fun investigating how to open “detached” views progammatically.

Click to watch:

detached views Having fun with detached views!
http://www.screencast.com/t/5ku89HjBNs

You can find this on Bug #270212, where we are discussing how use this in Eclipse Riena.

on Mar 31st, 2009Riena article on DZone

As a Riena committer, it’s always nice to see people taking interest in Riena. Feedback  at EclipseCon has been very positive. I was also impressed by  RedView – a UI-generator based on EMF and Riena, which is becoming available soon.

Now James Sugrue wrote “Riena – A New Adventure in Eclipse” over on DZone.

riena mail 300x225 Riena article on DZone

The article introduces Riena, walks you through installation, shows how to create and theme an application and explains Riena’s remote services. Go check it out.

Kind regards,
Elias.

on Mar 31st, 2009Replacing the Perspective-Switcher in RCP apps

For simple RCP Applications the Perspective-Switcher widget that ships with Eclipse is overloaded and cumbersome to use.

persp switcher Replacing the Perspective Switcher in RCP apps

We are going to get rid of it and replace it with an equivalent menu and/or toolbar for switching perspectives. Both should have an indicator to show which perspective is currently active.

persp menu and toolbar Replacing the Perspective Switcher in RCP apps

Hiding the Perspective-Switcher

To hide the Perspective-Switcher we go to our ApplicationWorkbenchWindowAdvisor and instruct the IWorkbenchWindowConfigurer to not show the perspective bar.

public void preWindowOpen() {
  IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
   configurer.setShowPerspectiveBar(false);
  // ...
}

 

Using simple commands – not enough

Let’s see how we could contribute a menu / toolbar for switching perspectives. 

The workbench has the command ‘org.eclipse.ui.perspectives.showPerspective’ that can switch to a given perspective. It accepts a parameter ‘org.eclipse.ui.perspectives.showPerspective.perspectiveId’ with the ID of the perspective to show. Optionally a second parameter ‘org.eclipse.ui.perspectives.showPerspective.newWindow’ will open the perspective in a new window if set to ‘true’.

Using  the ‘org.eclipse.ui.menus’ extension point we could contribute a menu with an appropriate <command> for each perspective:

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="menu.perspectivesStatic"
               label="Perspectives">
            <command
                  commandId="org.eclipse.ui.perspectives.showPerspective"
                  icon="/icons/perspA.png"
                  label="Perspective A"
                  style="radio">
               <parameter
                     name="org.eclipse.ui.perspectives.showPerspective.perspectiveId"
                     value="example.perspectiveswitch.simple.PerspectiveA">
               </parameter>
            </command>
            <!-- repeat --!> 

 

Unfortunately this approach has some drawbacks:

  • long xml files
  • the list of available perspectives is static – brittle and requires manual maintenance
  • it is difficult to indicate which perspective is currently selected

Using dynamic contributions – success

Fortunately the <dynamic> element of  ’org.eclipse.ui.menus’ comes to our rescue. It allows us to contribute a Java class that populates the menu/toolbar on the fly (note: use a separate class for each).

Here’s the <dynamic> element that populates the ‘Perspectives’ menu:

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="menu.perspectivesDynamic"
               label="Perspectives">
            <dynamic
                  class="example.perspectiveswitch.PerspectiveSwitcherMenu"
                  id="perspectiveSwitcherMenu">
            </dynamic>
      </menuContribution>
   </extension> 

 

The class PerspectiveSwitcherMenu fills the menu on the fly.

We obtain the array of  IPerspectiveDescriptors from the workbench. For each we create a MenuItem with the perspective’s icon and description. Since we created images, we have to dispose them when the menu item is disposed, using a dispose listener. A selection listener is in charge of switching perspective when a menu item is clicked. To provide indication about the active perspective we use the SWT.RADIO style and select one of the menu items. Since the menu is created on the fly each time it is used, we do not need to track the active perspective icon smile Replacing the Perspective Switcher in RCP apps .

public class PerspectiveSwitcherMenu extends ContributionItem {

public void fill(Menu menu, int index) {
  String activePerspective = getPerspectiveId();
  IPerspectiveDescriptor[] perspectives = PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
  for(int i = 0; i < perspectives.length; i++) {
    IPerspectiveDescriptor descriptor = perspectives[i];
    // i is used as an item index; 0-n will add items to the top of the menu
    MenuItem item = new MenuItem(menu, SWT.RADIO, i);
    item.setData(KEY_PERSPECTIVE_DESCR, descriptor);
    item.setText(descriptor.getLabel());
    final Image image = descriptor.getImageDescriptor().createImage();
    item.setImage(image);
    item.addDisposeListener(new DisposeListener(){
      public void widgetDisposed(DisposeEvent e) {
        image.dispose();
      }
    });
    item.addSelectionListener(menuListener);
    if(descriptor.getId().equals(activePerspective)) {
      item.setSelection(true);
    }
  }
}

public final boolean isDynamic() {
  return true;
}

 

The toolbar contribution is very similar to the above. Using the ‘org.eclipse.ui.menus’ extension point, we add a <dynamic> element to a <toolbar>. We then implement PerspectiveSwitcherToolbar which extends ContributionItem and overrides the fill(Toolbar, int) to create a toolbar on the fly.

Since the toolbar is visible all the time, we have to track the active perspective, so we can update the ‘selected’ (=depressed) state of the toolbar buttons as necessary. This turned out to be quite tricky. Here’s the solution I went for: a listener tracking the active perspective is installed in each window. If the perspective changes, we look-up the toolbar and update the ‘selected’ state. Since windows may come and go, a second listener keeps track of window creation / disposal and installs / removes the perspective listener as necessary. I wish this was a bit easier – but I’m sharing the below code so you can save a bit of time on this.

Source Download

Download the full code here: example perspective switch.zip

Happy hacking,
Elias.  

PS: If you want to trade off more screen real-estate for a fancier switcher you can use a ‘standalone’ view or a composite that is placed around the page contents. Tom Seidel has the details on his blog.

on Mar 18th, 2009Riena 3.5.M6 is out, discuss at EclipseCon

Riena 3.5.M6 is available, just in time for EclipseCon (new and noteworthy). 

riena 300x225 Riena 3.5.M6 is out, discuss at EclipseCon

The Riena highlights at the conference next week:

  • Come to the Riena BOF on Tuesday to discuss the project with the team. As one of the committers behind the UI (Ridgets), I’m looking forward to feedback from developers who consume it or are thinking about using it.
  • If you’re new to Riena I highly recommend Christian’s talk  ’Write a Client/Server application based on Riena in 25 minutes‘  on Wednesday. Christian shows how to write a Riena app quickly including creating the UI, using Ridgets, easy data-binding and access to the server with Remote Services. It’s a quick, hands-on overview of what Riena is about.
     
  • The Riena talk I’m most curious about is Ekke’s and Florian’s presentation ‘Dynamic View for Business Applications (Riena + EMF + oAW)‘ on Thursday. Ekke and Florian are two of the most active members of the Riena community. As far as I can tell they have written a model-driven UI-generator based on Riena+EMF+oAW. Update 3/19: you can read more details here. I’m looking forward to their talk.

See you at EclipseCon,

Elias.

on Mar 4th, 2009Eclipse Riena 1.1.0 M5 shipped

Riena 1.1.0 Milestone 5 shipped today (download). 

Since the 1.0 release a month ago we Riena committers have been busy with several new features:  

  • Riena is now based on Eclipse 3.5 and joined the Galileo Release Train.
  • The Look-and-Feel subsystem can now apply settings to ViewParts as well. To enable this behavior you need to set the system property ‘riena.lnf.update.view’ to ‘true’. By they way, the LnF subsystem provides means to automatically invoke setters on each widget and/or attach renderers (=painting) to them. More info about LnF on the wiki.
  • The CompositeTableRidget allows creating tables with several ridgets in each row. It’s based on the CompositeTable widget from the Nebula project. Thanks Nebula – this rocks!
composite table Eclipse Riena 1.1.0 M5 shipped

CompositeTableRidget

 
ICompositeTableRidget ridget;
WritableList input = new WritableList(PersonFactory.createPersonList(), Person.class);
ridget.bindToModel(input, Person.class, RowRidget.class);

 (full snippet

  • The MasterDetailsRidget automatically binds the selected row of a table to an details area. A prototype is available in M5. Work will continue in M6.
master details Eclipse Riena 1.1.0 M5 shipped

Master Details Ridget

  • The ColumnFormatter for TableRidgets allows adjusting the text, icon, color and font of each column.

table ridget formatter Eclipse Riena 1.1.0 M5 shipped

tableRidget.setColumnFormatter(1, new DateColumnFormatter("MM/dd/yyyy") { //$NON-NLS-1$
  protected Date getDate(Object element) {
     return ((Holiday) element).getDate();
  }
});
tableRidget.bindToModel(new WritableList(createInput(), Holiday.class), Holiday.class, columnPropertyNames, columnHeaders);

(full snippet)  

You’ll find more details in the New & Noteworthy.

Kind regards,
Elias.

© EclipseSource 2008 - 2011