How to use SWT Designer with UDOP ViewPartBase

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

How to use SWT Designer with UDOP ViewPartBase

Postby P38 » Thu Apr 14, 2011 10:53 am

Background
My client uses a special plug in framework called UDOP: User Defined Output Perspectives. Basically, it's Eclipse plug-ins.

To make views, instead of extending ViewPart, we are being asked to extend ViewPartBase, a base class their framework provides us.

Problem
SWT Designer works fine when our view extends ViewPart. Once we change that to ViewPartBase, SWT Designer cannot parse it.

It seems that all that ViewPartBase does is is have us add three additional methods:

Code: Select all
   @Override
   protected void addToMenuBar(IMenuManager arg0) {
   }

   @Override
   protected void addToToolBar(IToolBarManager arg0) {
   }

   @Override
   public void createContent(Composite arg0) {
   }

Amazingly, the hopelessly buggy Jigloo GUI editor manages to parse and edit ViewPartBase's, so my colleagues are pressuring me to use it instead.

What can I do?

The following is the entire class:

Code: Select all
package com.df_nn.udop.blackboard_utility.views;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.PlatformUI;

import com.tdkc.udop.extensionpoints.views.ViewPartBase;

/**
* This sample class demonstrates how to plug-in a new workbench view. The view shows data obtained from the model. The
* sample creates a dummy model on the fly, but a real implementation would connect to the model available either in
* this or another plug-in (e.g. the workspace). The view is connected to the model using a content provider.
* <p>
* The view uses a label provider to define how model objects should be presented in the view. Each view can present the
* same model objects using different labels and icons, if needed. Alternatively, a single label provider can be shared
* between views in order to ensure that objects of the same type are presented in the same way everywhere.
* <p>
*/

public class MainView extends ViewPartBase {

   /**
    * The ID of the view as specified by the extension.
    */
   public static final String ID = "com.df_nn.udop.blackboard_utility.views.MainView";

   private TableViewer viewer;
   private Action action1;
   private Action action2;
   private Action doubleClickAction;

   /*
    * The content provider class is responsible for providing objects to the view. It can wrap existing objects in
    * adapters or simply return objects as-is. These objects may be sensitive to the current input of the view, or
    * ignore it and always show the same content (like Task List, for example).
    */

   class ViewContentProvider implements IStructuredContentProvider {
      @Override
      public void inputChanged(Viewer v, Object oldInput, Object newInput) {
      }

      @Override
      public void dispose() {
      }

      @Override
      public Object[] getElements(Object parent) {
         return new String[] { "One", "Two", "Three" };
      }
   }

   class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
      @Override
      public String getColumnText(Object obj, int index) {
         return getText(obj);
      }

      @Override
      public Image getColumnImage(Object obj, int index) {
         return getImage(obj);
      }

      @Override
      public Image getImage(Object obj) {
         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
      }
   }

   class NameSorter extends ViewerSorter {
   }

   /**
    * The constructor.
    */
   public MainView() {
   }

   /**
    * This is a callback that will allow us to create the viewer and initialize it.
    */
   @Override
   public void createPartControl(Composite parent) {
      {
         parent.setSize(317, 254);
      }
      viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
      viewer.setContentProvider(new ViewContentProvider());
      viewer.setLabelProvider(new ViewLabelProvider());
      viewer.setSorter(new NameSorter());
      viewer.setInput(getViewSite());

      // Create the help context id for the viewer's control
      PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
         "com.df_nn.udop.blackboard_utility.viewer");
      makeActions();
      hookContextMenu();
      hookDoubleClickAction();
      contributeToActionBars();
   }

   private void hookContextMenu() {
      MenuManager menuMgr = new MenuManager("#PopupMenu");
      menuMgr.setRemoveAllWhenShown(true);
      menuMgr.addMenuListener(new IMenuListener() {
         @Override
         public void menuAboutToShow(IMenuManager manager) {
            MainView.this.fillContextMenu(manager);
         }
      });
      Menu menu = menuMgr.createContextMenu(viewer.getControl());
      viewer.getControl().setMenu(menu);
      getSite().registerContextMenu(menuMgr, viewer);
   }

   private void contributeToActionBars() {
      IActionBars bars = getViewSite().getActionBars();
      fillLocalPullDown(bars.getMenuManager());
      fillLocalToolBar(bars.getToolBarManager());
   }

   private void fillLocalPullDown(IMenuManager manager) {
      manager.add(action1);
      manager.add(new Separator());
      manager.add(action2);
   }

   private void fillContextMenu(IMenuManager manager) {
      manager.add(action1);
      manager.add(action2);
      // Other plug-ins can contribute there actions here
      manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
   }

   private void fillLocalToolBar(IToolBarManager manager) {
      manager.add(action1);
      manager.add(action2);
   }

   private void makeActions() {
      action1 = new Action() {
         @Override
         public void run() {
            showMessage("Action 1 executed");
         }
      };
      action1.setText("Action 1");
      action1.setToolTipText("Action 1 tooltip");
      action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
         ISharedImages.IMG_OBJS_INFO_TSK));

      action2 = new Action() {
         @Override
         public void run() {
            showMessage("Action 2 executed");
         }
      };
      action2.setText("Action 2");
      action2.setToolTipText("Action 2 tooltip");
      action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(
         ISharedImages.IMG_OBJS_INFO_TSK));
      doubleClickAction = new Action() {
         @Override
         public void run() {
            ISelection selection = viewer.getSelection();
            Object obj = ((IStructuredSelection) selection).getFirstElement();
            showMessage("Double-click detected on " + obj.toString());
         }
      };
   }

   private void hookDoubleClickAction() {
      viewer.addDoubleClickListener(new IDoubleClickListener() {
         @Override
         public void doubleClick(DoubleClickEvent event) {
            doubleClickAction.run();
         }
      });
   }

   private void showMessage(String message) {
      MessageDialog.openInformation(viewer.getControl().getShell(), "Blackboard Utility", message);
   }

   /**
    * Passing the focus request to the viewer's control.
    */
   @Override
   public void setFocus() {
      viewer.getControl().setFocus();
   }

   @Override
   protected void addToMenuBar(IMenuManager arg0) {
   }

   @Override
   protected void addToToolBar(IToolBarManager arg0) {
   }

   @Override
   public void createContent(Composite arg0) {
   }
}
P38
 
Posts: 8
Joined: Wed Feb 09, 2011 11:35 am

Re: How to use SWT Designer with UDOP ViewPartBase

Postby Eric Clayberg » Thu Apr 14, 2011 2:06 pm

What do you mean by "SWT Designer cannot parse it"?

I tried your example, and once I added a dummy ViewPartBase class between MainView and ViewPart, I was able to edit the class just fine.

Can you provide the complete ViewPartBase class?

Also, what exact build of SWT Designer are you using?
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: How to use SWT Designer with UDOP ViewPartBase -- versio

Postby P38 » Wed Apr 20, 2011 9:48 am

Thanks for the reply.

Looking in Eclipse, Installed Software, I see:
SWT Designer 8.1.1.r36x...
and
SWT Designer 0.9.0.r36x...

I think I put one of your betas in there.

Please advise which version I should use.
P38
 
Posts: 8
Joined: Wed Feb 09, 2011 11:35 am

Re: How to use SWT Designer with UDOP ViewPartBase

Postby P38 » Wed Apr 20, 2011 9:53 am

Thanks for the reply.

I ended up doing something similar-- I did all my SWT Designer work in a separate Composite which I included manually into the ViewPartBase class.

But doing things manually to enable a tool that frees you from doing manually is not why I enjoy and advocate SWT Designer.

I am doing another plug-in with the UDOP framework and its ViewPartBase class, and all of a sudden, SWT Designer cannot parse that.

I must have done something wrong, but may not have the time to prepare something to send in here, as much as I do appreciate the terrific support.

Eventually, I'll have to get to the bottom of this.

Thanks for the support.
P38
 
Posts: 8
Joined: Wed Feb 09, 2011 11:35 am

Re: How to use SWT Designer with UDOP ViewPartBase

Postby Eric Clayberg » Wed Apr 20, 2011 10:17 am

I would start by having only one version of SWT Designer installed at at time. I'm not sure what sort of conflict might happen by having both loaded.

I would recommend always using the latest build from here...

BTW, as I said above, your example edited just fine on my end.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

cron