Thursday, May 2, 2013

Copy Resources from Eclipse Plug-in to Local File System

If we need to read a resource from an eclipse plugin and want to save it to local file system we can use following code :





















Following code will copy basicTemplate.diagram to local-file system:


private void copyTemplateToLocalDirectory() {

URI diagramTemplateFileUri = URI.createPlatformPluginURI(
"/dk.bording.viking.rcp.ui.till.editor/templates/basicTemplate.diagram", true);

URIConverter uriConverter = new ExtensibleURIConverterImpl();
try {

InputStream infile =  uriConverter.createInputStream(diagramTemplateFileUri);
FileOutputStream file = new FileOutputStream( new File(Platform.getInstanceLocation().getURL().getPath()+File.separator+NewFileName.diagram"));
file.write(ByteStreams.toByteArray(infile));
file.close();

} catch (IOException e1) {

e1.printStackTrace();
}

}





PopertyTesters : Requesting Evaluation of Expressions

The command framework is quite lazy. It doesn't really care about your expressions and your wishes about when handlers should be enabled or not. It’s your duty to refresh the enabled state of your handlers by telling the IEvaluationService. It’s not wise to refresh the commands regularly as it can be quite expensive. Instead triggering the refresh on events is the way to go.

using the following code we can Request Evalueation of our Expressoin:


 protected void requestRefresh() {
  IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
  if (evaluationService != null) {
   evaluationService.requestEvaluation(PROPERTY_NAMESPACE + "." + PROPERTY_CAN_FOO);
   evaluationService.requestEvaluation(PROPERTY_NAMESPACE + "." + PROPERTY_CAN_BAR);
  }
 }


More information can be found:
http://www.robertwloch.net/2011/01/eclipse-tips-tricks-property-testers-with-command-core-expressions/

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...