package com.ridgerun.gsttune.handlers;

import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;


/**
 * handler extends AbstractHandler, an IHandler base class.
 * @see org.eclipse.core.commands.IHandler
 * @see org.eclipse.core.commands.AbstractHandler
 */
public class ShowDotHandler extends AbstractHandler {
	
	private static final String COMMAND = "dot -Tpng /home/caguero/0.00.02.742694709-gst-launch.PLAYING_READY.dot -o /home/caguero/output.png";
	private static final String RESULTFILE = "/home/caguero/output.png";
	
	/**
	 * The constructor.
	 */
	public ShowDotHandler() {
	}

	/**
	 * the command has been executed, so extract extract the needed information
	 * from the application context.
	 */
	public Object execute(ExecutionEvent event) throws ExecutionException {
		
		Process p;
		try {
			p = Runtime.getRuntime().exec(COMMAND);
			p.waitFor();
		} catch (Exception e) {
			e.printStackTrace();
		}

		ImageIcon image = new ImageIcon(RESULTFILE);
        JLabel imageLabel = new JLabel(image);
		JFrame frame = new JFrame(""); 
        frame.add(imageLabel);
        frame.setSize(new Dimension(image.getIconWidth(), image.getIconHeight()));
        frame.setVisible(true);
        
        return null;
	}
}

@@ -75,25 +75,80 @@
 java
-x.swing.ImageIcon
+.io.File;%0A%0Aimport javax.swing.ImageIcon;%0Aimport javax.swing.JFileChooser
 ;%0Aim
@@ -353,17 +353,16 @@
 ption;%0A%0A
-%0A
 /**%0A * h
@@ -568,17 +568,16 @@
 ndler %7B%0A
-%09
 %0A%09privat
@@ -581,30 +581,24 @@
 vate static 
-final 
 String COMMA
@@ -603,111 +603,8 @@
 MAND
- = %22dot -Tpng /home/caguero/0.00.02.742694709-gst-launch.PLAYING_READY.dot -o /home/caguero/output.png%22
 ;%0A%09p
@@ -621,14 +621,8 @@
 tic 
-final 
 Stri
@@ -643,20 +643,11 @@
 = %22/
-home/caguero
+tmp
 /out
@@ -656,17 +656,16 @@
 t.png%22;%0A
-%09
 %0A%09/**%0A%09 
@@ -836,24 +836,43 @@
 ntext.%0A%09 */%0A
+%09ImageIcon image;%0A%0A
 %09public Obje
@@ -932,18 +932,516 @@
 ption %7B%0A
+%0A
 %09%09
+JFrame frame = new JFrame(%22%22);%0A%09%09JFileChooser fc = new JFileChooser();%0A%09%09fc.setPreferredSize(new Dimension(800,600));%0A%09%09int returnVal = fc.showOpenDialog(frame); //Where frame is the parent component%0A%0A%09%09File file = null;%0A%09%09if (returnVal == JFileChooser.APPROVE_OPTION) %7B%0A%09%09    file = fc.getSelectedFile();%0A%09%09    //Now you have your file to do whatever you want to do%0A%09%09%7D else %7B%0A%09%09    //User did not choose a valid file%0A%09%09%7D%0A%0A%09%09COMMAND = %22dot -Tpng %22 + file.getAbsolutePath() + %22 -o %22 + RESULTFILE;%0A
 %0A%09%09Proce
@@ -1570,26 +1570,16 @@
 %0A%09%09%7D%0A%0A%09%09
-ImageIcon 
 image = 
@@ -1605,16 +1605,17 @@
 TFILE);%0A
+%0A
         
@@ -1657,42 +1657,8 @@
 e);%0A
-%09%09JFrame frame = new JFrame(%22%22); %0A
     
@@ -1799,24 +1799,25 @@
 (true);%0A
+%0A
         
 %0A       
@@ -1808,16 +1808,188 @@
         
+try %7B%0A            Thread.sleep(500);%0A        %7D catch(InterruptedException ex) %7B%0A            Thread.currentThread().interrupt();%0A        %7D%0A%0A        image.getImage().flush();
 %0A       
@@ -2005,10 +2005,9 @@
 ull;%0A%09%7D%0A
+
 %7D
-%0A

Add feature for opening a dot file from a specific directory