Index: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowTaskTreeDialog.java
===================================================================
--- trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowTaskTreeDialog.java	(revision 1636)
+++ trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowTaskTreeDialog.java	(revision 2033)
@@ -15,6 +15,8 @@
 package de.ugoe.cs.autoquest.ui.swt;
 
+import java.awt.Frame;
 import java.awt.GraphicsDevice;
 import java.awt.GraphicsEnvironment;
+import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Collections;
@@ -24,5 +26,7 @@
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.awt.SWT_AWT;
 import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.custom.StackLayout;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -30,13 +34,18 @@
 import org.eclipse.swt.events.ShellEvent;
 import org.eclipse.swt.events.ShellListener;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Dialog;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.TabFolder;
@@ -45,4 +54,6 @@
 import org.eclipse.swt.widgets.TreeColumn;
 import org.eclipse.swt.widgets.TreeItem;
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
 
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration;
@@ -60,4 +71,5 @@
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric;
+import de.ugoe.cs.util.console.Console;
 
 /**
@@ -76,5 +88,5 @@
     private ShellListener shellListener;
     
-    /** the tab folder containing the instance tree as well as the model tree */
+    /** the tab folder containing the instance tree, the model tree, and the visualizations list */
     private TabFolder tabFolder;
 
@@ -85,4 +97,16 @@
     private Tree modelTree;
     
+    /** the tree of possible visualizations on the left */
+    private Tree modelVisualizationTree;
+    
+    /** the right hand composite containing either task details or a visualization */
+    private Composite rightHandComposite;
+    
+    /** the stack layout displaying either the task details or a visualization */
+    private StackLayout rightHandLayout;
+    
+    /** the task details composite containing the task details tree, the execution variants, etc.*/
+    private Composite detailsComposite;
+    
     /** the tree of a specific task on the right */
     private Tree taskDetailsTree;
@@ -96,7 +120,13 @@
     /** the table containing the parents tasks of a displayed task */
     private Tree parentTasks;
+    
+    /** the visualization composite on the right hand side toggled with the details composite */
+    private Composite visualizationsComposite;
 
     /** the displayed task model */
     private ITaskModel taskModel;
+    
+    /** a boolean indicating if the CTTE export of a task is possible */
+    private boolean taskExportAvailable = false;
     
     /** default expansion listener */
@@ -122,4 +152,17 @@
      */
     public void open() {
+        // check, if export to CTTE is possible
+        try {
+            Class<?> exportClass = this.getClass().getClassLoader().loadClass
+                ("de.ugoe.cs.autoquest.plugin.exports.tasktree.CTTExportUtils");
+            
+            if (exportClass != null) {
+                taskExportAvailable = true;
+            }
+        }
+        catch (ClassNotFoundException e) {
+            // ignore. No export available
+        }
+        
         open(null);
     }
@@ -201,6 +244,6 @@
         mainSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
         
-        createSessionsAndTasksTabFolder(mainSashForm);
-        createTaskDetailsView(mainSashForm);
+        createLeftHandSideTabs(mainSashForm);
+        createRightHandSideView(mainSashForm);
 
         mainSashForm.setWeights(new int[] { 1, 3 });
@@ -241,5 +284,5 @@
      *
      */
-    private void createSessionsAndTasksTabFolder(SashForm mainSashForm) {
+    private void createLeftHandSideTabs(final SashForm mainSashForm) {
         tabFolder = new TabFolder(mainSashForm, SWT.NONE);
         tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
@@ -247,5 +290,20 @@
             @Override
             public void widgetSelected(SelectionEvent e) {
-                VisualizationUtils.updateColumnWidths(modelTree);
+                if (tabFolder.getSelectionIndex() == 0) {
+                    // task instances tab selected
+                    rightHandLayout.topControl = detailsComposite;
+                }
+                else if (tabFolder.getSelectionIndex() == 1) {
+                    // task model tab selected
+                    rightHandLayout.topControl = detailsComposite;
+                    VisualizationUtils.updateColumnWidths(modelTree);
+                }
+                else {
+                    rightHandLayout.topControl = visualizationsComposite;
+                }
+                
+                rightHandComposite.layout();
+                rightHandComposite.redraw();
+                rightHandComposite.update();
             }
         });
@@ -278,4 +336,15 @@
             }
         });
+        
+        if (taskExportAvailable) {
+            VisualizationUtils.addItemSpecificContextMenu
+                (instanceTree, ITask.class, "export to ConcurTaskTree", new SelectionAdapter()
+            {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    export((ITask) taskDetailsTree.getSelection()[0].getData());
+                }
+            });
+        }
 
         buildInstanceTree();
@@ -305,11 +374,71 @@
         
         modelTreeTab.setControl(modelTree);
-    }
-
+
+        TabItem modelVisualizationTab = new TabItem(tabFolder, SWT.NONE);
+        modelVisualizationTab.setText("Visualizations");
+        
+        modelVisualizationTree = new Tree(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL);
+        
+        TreeItem item1 = new TreeItem(modelVisualizationTree, SWT.NULL);
+        item1.setText(TaskTreePlotUtils.TASK_COUNT__EVENT_COVERAGE_PLOT);
+        
+        item1 = new TreeItem(modelVisualizationTree, SWT.NULL);
+        item1.setText(TaskTreePlotUtils.ORDERED_TASK_COUNT_PLOT);
+        
+        item1 = new TreeItem(modelVisualizationTree, SWT.NULL);
+        item1.setText(TaskTreePlotUtils.CUMULATIVE_TASK_COVERAGE_PLOT);
+        
+        Menu menu = modelVisualizationTree.getMenu();
+        
+        if (menu == null) {
+            menu = new Menu(modelVisualizationTree);
+            modelVisualizationTree.setMenu(menu);
+        }
+       
+        // show visualization if requested
+        modelVisualizationTree.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                clearVisualization();
+                TreeItem[] selectedItems = modelVisualizationTree.getSelection();
+                if (selectedItems.length == 1) {
+                    showVisualization(selectedItems[0].getText());
+                }
+            }
+        });
+        
+        modelVisualizationTab.setControl(modelVisualizationTree);
+        
+        // add a context menu for PDF export
+        final Menu finalMenu = menu;
+        MenuItem newItem = new MenuItem(finalMenu, SWT.NONE);
+        newItem.setText("save as PDF");
+        newItem.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                try {
+                    FileDialog dialog = new FileDialog(shell, SWT.SAVE);
+                    dialog.setFilterExtensions(new String [] {"*.pdf"});
+                    TaskTreePlotUtils.saveChartToPDF
+                        ((JFreeChart) modelVisualizationTree.getSelection()[0].getData(),
+                         dialog.open(), 500, 500);
+                }
+                catch (Exception e1) {
+                    // TODO Auto-generated catch block
+                    e1.printStackTrace();
+                }
+            }
+        });
+    }
+    
     /**
      *
      */
-    private void createTaskDetailsView(SashForm mainSashForm) {
-        Composite detailsComposite = new Composite(mainSashForm, SWT.NO_BACKGROUND);
+    private void createRightHandSideView(SashForm mainSashForm) {
+        rightHandComposite = new Composite(mainSashForm, SWT.NO_BACKGROUND);
+        rightHandLayout = new StackLayout();
+        rightHandComposite.setLayout(rightHandLayout);
+        
+        detailsComposite = new Composite(rightHandComposite, SWT.NO_BACKGROUND);
         detailsComposite.setLayout(new GridLayout(1, false));
         detailsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
@@ -328,6 +457,6 @@
         VisualizationUtils.addExpansionListener(taskDetailsTree, defaultExpansionListener);
         
-        VisualizationUtils.addItemSpecificContextMenu(taskDetailsTree, ITask.class,
-                                                      "show in task list", new SelectionAdapter()
+        VisualizationUtils.addItemSpecificContextMenu
+            (taskDetailsTree, ITask.class, "show in task list", new SelectionAdapter()
         {
             @Override
@@ -336,4 +465,15 @@
             }
         });
+        
+        if (taskExportAvailable) {
+            VisualizationUtils.addItemSpecificContextMenu
+                (taskDetailsTree, ITask.class, "export to ConcurTaskTree", new SelectionAdapter()
+            {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    export((ITask) taskDetailsTree.getSelection()[0].getData());
+                }
+            });
+        }
         
         executionVariantsTree = new Tree(detailsTopSashForm, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
@@ -355,6 +495,6 @@
             (detailsBottomSashForm, "parent tasks", taskModel);
         
-        VisualizationUtils.addItemSpecificContextMenu(parentTasks, ITask.class,
-                                                      "show in task list", new SelectionAdapter()
+        VisualizationUtils.addItemSpecificContextMenu
+            (parentTasks, ITask.class, "show in task list", new SelectionAdapter()
         {
             @Override
@@ -364,6 +504,25 @@
         });
         
+        if (taskExportAvailable) {
+            VisualizationUtils.addItemSpecificContextMenu
+                (parentTasks, ITask.class, "export to ConcurTaskTree", new SelectionAdapter()
+            {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    export((ITask) taskDetailsTree.getSelection()[0].getData());
+                }
+            });
+        }
+        
         involvedTargetsTree =
             VisualizationUtils.createTargetsTree(detailsBottomSashForm, "involved GUI elements");
+        
+        visualizationsComposite = new Composite(rightHandComposite, SWT.NO_BACKGROUND);
+        visualizationsComposite.setLayout(new GridLayout(1, false));
+        visualizationsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+        
+        new Label(visualizationsComposite, SWT.NONE).setText("Visualization:");
+        
+        rightHandLayout.topControl = detailsComposite;
         
         detailsBottomSashForm.setWeights(new int[] { 2, 3 });
@@ -590,4 +749,21 @@
         displayTaskDetails(task);
     }
+
+    /**
+     * 
+     */
+    private void export(ITask task) {
+        try {
+            Class<?> exportClass = this.getClass().getClassLoader().loadClass
+                ("de.ugoe.cs.autoquest.plugin.exports.tasktree.CTTExportUtils");
+            
+            Method method = exportClass.getDeclaredMethod("exportToCTT", ITask.class, String.class);
+            
+            method.invoke(null, task, task.getId() + "_ctte.xml");
+        }
+        catch (Exception e) {
+            Console.logException(e);
+        }
+    }
     
     /**
@@ -680,3 +856,49 @@
         }
     }
+
+    /**
+     *
+     */
+    private void showVisualization(String name) {
+        Color backgroundColor = visualizationsComposite.getBackground();
+        Composite parent = new Composite(visualizationsComposite, SWT.EMBEDDED);
+        parent.setLayout(new GridLayout(1, false));
+        parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+        
+        Frame chartFrame = SWT_AWT.new_Frame(parent);
+        chartFrame.setBackground(new java.awt.Color(backgroundColor.getRed(),
+                                                    backgroundColor.getGreen(),
+                                                    backgroundColor.getBlue()));
+        
+        chartFrame.setLayout(new java.awt.GridLayout());
+        
+        List<ITaskModel> models = new LinkedList<>();
+        models.add(taskModel);
+        
+        List<String> names = new LinkedList<>();
+        names.add(name);
+        
+        List<Integer> groups = new LinkedList<>();
+        groups.add(0);
+
+        JFreeChart chart = TaskTreePlotUtils.createPlot(name, models, names, groups);
+        chartFrame.add(new ChartPanel(chart));
+        
+        modelVisualizationTree.getSelection()[0].setData(chart);
+        
+        rightHandComposite.layout();
+        rightHandComposite.redraw();
+        rightHandComposite.update();
+    }
+
+    /**
+     *
+     */
+    private void clearVisualization() {
+        for (Control child : visualizationsComposite.getChildren()) {
+            child.dispose();
+        }
+        
+        visualizationsComposite.pack();
+    }
 }
