Archive for June, 2010

Eclipse Plugin : Programatically Export/Create/Build WAR file

June 14, 2010
import org.eclipse.core.commands.ExecutionEvent; 

import org.eclipse.core.commands.ExecutionException; 

import org.eclipse.jst.j2ee.internal.web.archive.operations.WebComponentExportDataModelProvider; 

import org.eclipse.jst.j2ee.web.datamodel.properties.IWebComponentExportDataModelProperties; 

import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; 

import org.eclipse.wst.common.frameworks.datamodel.IDataModel; 

public class SomeClass{

/**

*

* @param projectName – Name of the web project

* @param destinationPath – Destination path to create the war (eg: C:\temp\webapp.war)

*/

public void export(String projectName, String destinationPath) throws ExecutionException {

IDataModel model = DataModelFactory.createDataModel(new WebComponentExportDataModelProvider());

model.setProperty(IWebComponentExportDataModelProperties.PROJECT_NAME,projectName);

model.setProperty(IWebComponentExportDataModelProperties.ARCHIVE_DESTINATION, destinationPath);

model.getDefaultOperation().execute( null, null );

}

}
Many thanx to http://www.eclipse.org/webtools/jst/components/j2ee/scenarios/WTPApis.html

Guardians of My Mother Lanka

June 5, 2010

Eclipse Plugin: Adding an overlay to an ImageDescriptor

June 2, 2010

Here’s the class. This will overlay to the bottom right corner.

import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;

public class OverlayImageDescriptor extends CompositeImageDescriptor {
private ImageDescriptor imageDescriptor;
private ImageDescriptor overlayImage;
Point size;
Point overlaySize;

public OverlayImageDescriptor(ImageDescriptor imgDescriptor,ImageDescriptor overlayImage) {
setImageDescriptor(imgDescriptor);
setOverlayImage(overlayImage);
}

protected void drawCompositeImage(int arg0, int arg1) {
drawImage(getImageDescriptor().getImageData(), 0, 0);
ImageData overlayImageData = getOverlayImage().getImageData();
int xValue = size.x-overlaySize.x;
int yValue = size.y-overlaySize.y;;
drawImage(overlayImageData, xValue, yValue);
}

protected Point getSize() {
return size;
}

public void setImageDescriptor(ImageDescriptor imageDescriptor) {
this.imageDescriptor = imageDescriptor;
Rectangle bounds = imageDescriptor.createImage().getBounds();
size=new Point(bounds.width,bounds.height);
}

public ImageDescriptor getImageDescriptor() {
return imageDescriptor;
}

public void setOverlayImage(ImageDescriptor overlayImage) {
this.overlayImage = overlayImage;
Rectangle bounds = overlayImage.createImage().getBounds();
overlaySize=new Point(bounds.width,bounds.height);
}

public ImageDescriptor getOverlayImage() {
return overlayImage;
}

}