Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Saturday, October 09, 2010

Headless testing of RCP application

A week ago or so I needed to add a Unit Test invocation as part of my Eclipse RCP application headless build. My original PDE build configuration consisted of a single target for .product with "runPackager=true". I was too lazy to create an additional one for the test feature that contains Unit Tests plug-ins (which would cost me in a longer build time, BTW).

So, I decided to include the test feature in a .product, and remove dependency on it after all tests were executed. This simple piece of Ant code does whole the magic:



It needs to be executed twice: once in a prePackage target, and another time in a postBuild target in order to fix the resulted p2 repository as well.

Wednesday, September 22, 2010

GEF: Creating a connection on mouse drag

This tip shows how to implement a connection creation when dragging a mouse from EditPart, thus saving user's time (one click instead of three: activating connection creation tool, clicking on EditPart, restoring selection tool).

What you need is to return a ConnectionDragCreationTool from your EditPart:

public DragTracker getDragTracker(Request request) {
   return new ConnectionDragCreationTool();
}

The problem begins if your EditPart has a Direct Edit policy, Direct Edit commands won't be handled anymore. The following solution supports both: creating a connection on mouse drag and Direct Edit:

Create a proxy that implements DragTracker by delegating to ConnectionDragCreationTool and to SelectEditPartTracker:

public class DragConnectionCreationProxy implements DragTracker {

  private ConnectionDragCreationTool connectionTool;
  private SelectEditPartTracker editPartTracker;

  public DragConnectionCreation(EditPart editPart) {
    this.connectionTool = new ConnectionDragCreationTool();
    this.editPartTracker = new SelectEditPartTracker(editPart);
  }

  public void commitDrag() {
    connectionTool.commitDrag();
    editPartTracker.commitDrag();
  }

  // Implement all other methods ...
}

Then return this class instance from your EditPart:

public DragTracker getDragTracker(Request request) {
  return new DragConnectionCreationProxy(this);
}

Tuesday, January 19, 2010

Using animated GIF in CLabel

Have you ever tried to use animated GIF in Eclipse RCP? Unlike using regular image you have to provide your own mechanism that switches between image frames when using animated GIF (more about this is here). Fortunately, you can save in implementing your own thread by using org.eclipse.ui.internal.ImageCycleFeedbackBase and org.eclipse.ui.internal.AnimationEngine (though these classes are still in internal package). Let's say we need to add an animated image to a CLabel. First of all, we extend ImageCycleFeedbackBase:

public class AnimatedLabelFeedback extends ImageCycleFeedbackBase {
 private CLabel label;

 public AnimatedLabelFeedback(Shell parentShell, CLabel item, Image[] images) {
  super(parentShell, images);
  label = item;
 }

 public void initialize(AnimationEngine engine) {
  background = label.getParent().getBackground();
  display = label.getParent().getDisplay();
 }

 public void saveStoppedImage() {
  stoppedImage = label.getImage();
 }

 public void setStoppedImage(Image image) {
  label.setImage(image);
 }

 public void showImage(Image image) {
  if (!label.isDisposed()) {
   label.setImage(image);
  }
 }
}

This is how we attach animated GIF to the newly created CLabel:
label = new CLabel(parent, SWT.SHADOW_NONE);
Image[] images = loadAnimatedGIF(parent.getDisplay(), "icons/obj16/animated.gif");
AnimatedLabelFeedback feedback = new AnimatedLabelFeedback(parent.getShell(), label, images));
animation = new AnimationEngine(feedback,
  -1, // endless
  100 // delay between frames in milliseconds);
animation.schedule();

loadAnimatedGIF() is implemented as follows:
private void loadAnimatedGIF(Display display, String imagePath) {
  URL url = FileLocator.find(Activator.getDefault().getBundle(),
    new Path(imagePath), null);
  ImageLoader imageLoader = new ImageLoader();
  imageLoader.load(url.openStream());
  images = new Image[imageLoader.data.length];
  for (int i = 0; i < imageLoader.data.length; ++i) {
    ImageData nextFrameData = imageLoader.data[i];
    images[i] = new Image(display, nextFrameData);
  }
}
Dispose animation engine when it's not needed anymore (usually in dispose() method):
animation.cancelAnimation();

PS: @since 3.3

Tuesday, May 19, 2009

Continuous Integration for Eclipse-based product: thoughts

I've been thinking what is the best way to create a fully bottom-up build infrastructure for Eclipse-based product. What I mean by "fully" is:
  1. Developer commits code.
  2. A new build starts automatically.
  3. If the build succeeds - run tests.
  4. If tests are successful - tag the code.
Advantages of this scheme are the following:
  1. I'll always know what's the status of the product in CVS.
  2. I can choose the "best" package and promote it without invoking any builds.
Looks simple, isn't it? Now, how would I achieve this with what I have in my hands... In my hands I have:
  • CVS repository
  • Hudson
  • Eclipse
Unfortunately, Hudson can't be used for 100% when building Eclipse plug-ins, since it's rather used as a wrapper to the Eclipse PDE builder. Here, I don't use the ability of Hudson to poll SCM, checkout & tag, present history, etc... OK, I can setup some CVS handler that invokes build in Hudson by accessing URL. So, the first two problems are solved. Hudson executes build script that uses PDE headless builder to build & test my plug-ins. If the build & test where unsuccessful, then I'll see very sad Mr. Hudson and everything is good so far.  But if the build was OK, and number of failed tests is less or equal than in the previous build - then I have to tag the sources. And here I miss the "Team -> Release" action in Ant :-) Even if there was such an action the problem still remains, since plug-ins are versioned with 'HEAD' (and I don't want to use common timestamp version for all plug-ins, but rather for those that have changed from the last tag). 

As a conclusion: I see a lot of black magic work and hacks to get this done. Or... am I missing some pretty solution here? 



Thursday, March 26, 2009

Good bye, EclipseCon '09!

One more EclipseCon is over. A lot of new thoughts I'm taking away with me. Having a lot of "fun" with PDE builder in the past I was inspired by having a chance to learn about PDE builder wrappers: Dash Athena and Buckminster. Both projects look very interesting, though I haven't tested them yet (Buckminster should be the first one to start with due to .product file support).
I'm still under the impression of Single sourcing RCP and RAP and Runtime Riena and SOA. These give you to understand that Eclipse can be used as a platform for creating simple (or even complex) information systems very quickly. Trying both technologies is "a must", and I gonna do that in a near feature.

There where things that I'm not convinced still in their necessity. For example, who will need a Real Time Shared Editing? Don't tell me about pair programming. I'm in doubt that simultaneous typing can have some benefits. Usually, it's one who's typing and another who's staring at the code behind the shoulder. Another example - Cloud IDE Principle. It would be nice to have something like that (and the reason is NOT, since we don't want to bring source code to the local machine, and then deploy it back), but wait, is Web technology strong enough for that? People are used to rely too much on a single XMLHttpRequest... 

Anyway, it's good that world global crisis does not apply on a public interest in Eclipse. It applies on a number of free T-shirts and bags though - I'm coming back without presents...

Sunday, January 25, 2009

PHP 5.3 support in PDT: 1st stage is completed

For those of you who are desperately waiting for the PHP 5.3 support in PDT - check out tommorrow's nightly build for the 2.1/HEAD branch. Here's a list of basic features that where defined for the first stage:

Choosing PHP version when creating a new PHP project...



Basic code assit for new keywords...



PHP 5.3 syntax support: syntax highlighting, no errors in Problem View; sorry for the mess - I tried to put all new language features into one PHP code snippet :-) 



The next stage will be modeling namespaces... Be prepared, DLTK...

PS: you know the address where you can report bugs, right? :)

Saturday, January 10, 2009

Pedal for Code Assist

Following many complains about unusability of code assist in Eclipse I thought about some interesting construction... Just imaging yourself: your fingers are always free for writing code! No more embarassing CTRL+space shortcuts! Just connect your pedal to the computer, and configure it in the Eclipse preferences:



Do you think this idea can be developed? :)

Tuesday, January 06, 2009

On improving the PHP Inference Engine...

Just committed a new Type Inference "rule" into the PDT 2.1 branch. The following picture illustrates it better :)



Sunday, January 04, 2009

PDT 2.0 Released!

4 days ago PHP Development Tools 2.0 was released, and 20,000 of "early birds" had downloaded and started evaluating its new features. If I'd characterize this release in a few words, I'd concentrate on the following topics:
  • PHP Inference Engine: code based Completion and Navigation Engines, Type Hierarchy, Marc Occurrences, Override Indicators, and more...
  • Improved Performance and Scallability: faster startup; RAM usage is limited, irregardless how many projects are open.
  • Build Path: separate project resources from your source code.
And the most important thing is that we're really getting a lot of help from the community: people participate in the newsgroup, ask and answer questions in the IRC channel, report bugs. I really appreciate your help!