Kategorie: Programmieren

C#–Read STDOUT from a console application

Recently I needed to start a console application from C#, wait until the execution has finished and read the output back. Here is a simple way this can be done. The first thing is to run the process and attach an EventHandler for the finish of the process: Process process = new Process(); process.StartInfo.FileName = …

weiterlesen »

Java: Check if your code is running in Eclipse

Sometimes, for example during debugging, it is useful to check if your code is running from the Eclipse IDE to exclude certain code from execution. How can this be done? Here is an example: public class mainClass { public static void main(String[] args) { String inEclipse = System.getProperty("ineclipse"); if ((inEclipse == null) || (!inEclipse.equals("true"))) { …

weiterlesen »

RCP Application Set Title of Application Window

To dynamically set the title of a RCP application, the following code snippet is useful: private String fileName = "unknown.daf"; public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { IWorkbenchWindowConfigurer windowConfigurer = configurer; String title = "DA-FormMaker – " + fileName; windowConfigurer.setTitle(title); return new ApplicationWorkbenchWindowAdvisor(configurer); } The window title can be set via the “_IWorkbenchWindowConfigurer”. You can get a …

weiterlesen »

Java – Load text file to string

Most common in programming is to load text files to a string. Since this usually involves some lines of code, here is a snippet for that: /** * Loads a file to String * @param fileName – file name for example "C:\\MeineFile.txt" * @return * @throws IOException */ private String loadFileToString(String fileName) throws IOException { …

weiterlesen »

Java/SWT GUI Access from Thread

A thread in Java cannot directly access the GUI. With the following snippet, the access is possible: Call from the thread: @Override public void run() { html = „<h1>Huhu</h1>“; dlg.setSomeStuffToGui(html); } Method in the GUI: public void setSomeStuffToGui(final String html) { Display display = getDisplay(); display.asyncExec(new Runnable() { public void run() { //your stuff goes …

weiterlesen »

Set title for JFace dialog

The following snippet sets the title for a JFace dialog: @Override protected void configureShell(Shell shell) { super.configureShell(shell); shell.setText("My Dialog Title"); } However the following error might occur: This can be resolved if you change the setting from “error” to “warning” in the Eclipse preferences.

weiterlesen »

Get plugin path

This snippets gets the local folder for a plugin: public static File getPluginFolder() { if(pluginFolder == null) { URL url = Platform.getBundle("my.plugin.id").getEntry("/"); try { url = Platform.resolve(url); } catch(IOException ex) { ex.printStackTrace(); } pluginFolder = new File(url.getPath()); } return pluginFolder; }

weiterlesen »