[Title] modify to make chart, tableviewer by new logs
authorsanghyunnim.lee <sanghyunnim.lee@samsung.com>
Mon, 7 Nov 2011 03:38:12 +0000 (12:38 +0900)
committersanghyunnim.lee <sanghyunnim.lee@samsung.com>
Mon, 7 Nov 2011 03:38:12 +0000 (12:38 +0900)
[Type]
[Module]
[Priority]
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

com.samsung.dynamicanalyzer/src/com/samsung/dynamicanalyzer/ui/views/AnalysisView.java
com.samsung.dynamicanalyzer/src/com/samsung/dynamicanalyzer/ui/views/lifecycle/APIListTableManager.java [new file with mode: 0644]
com.samsung.dynamicanalyzer/src/com/samsung/dynamicanalyzer/ui/views/lifecycle/LifeCycleSubject.java
com.samsung.dynamicanalyzer/src/com/samsung/dynamicanalyzer/ui/views/lifecycle/OpenedResourceManager.java
com.samsung.dynamicanalyzer/src/com/samsung/dynamicanalyzer/ui/views/lifecycle/ResourceServiceListChartManager.java

index 9128884..47e5931 100644 (file)
@@ -1,17 +1,13 @@
 package com.samsung.dynamicanalyzer.ui.views;\r
 \r
-import org.eclipse.jface.viewers.TableViewer;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.layout.FillLayout;\r
 import org.eclipse.swt.layout.GridData;\r
 import org.eclipse.swt.layout.GridLayout;\r
 import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.swt.widgets.TableColumn;\r
 import org.eclipse.ui.part.ViewPart;\r
-import org.jfree.chart.JFreeChart;\r
-import org.jfree.experimental.chart.swt.ChartComposite;\r
 \r
+import com.samsung.dynamicanalyzer.ui.views.lifecycle.APIListTableManager;\r
 import com.samsung.dynamicanalyzer.ui.views.lifecycle.ResourceServiceListChartManager;\r
 \r
 public class AnalysisView extends ViewPart {\r
@@ -23,42 +19,37 @@ public class AnalysisView extends ViewPart {
 \r
        @Override\r
        public void createPartControl(Composite parent) {\r
-               parent.setLayout(new GridLayout(10, false));\r
-\r
-               makeChartPart(parent);\r
-\r
-               Composite composite = new Composite(parent, SWT.BORDER);\r
-               composite.setLayout(new FillLayout());\r
+               parent.setLayout(new GridLayout(10, true));\r
+               \r
+               Composite chartCompo = new Composite(parent, SWT.NONE);\r
+               chartCompo.setLayout(new FillLayout());\r
                GridData gridData = new GridData(GridData.FILL_BOTH);\r
-               gridData.horizontalSpan = 5;\r
-               composite.setLayoutData(gridData);\r
-\r
-               TableViewer tv = new TableViewer(composite, SWT.NONE);\r
-               Table table = tv.getTable();\r
-               table.setHeaderVisible(true);\r
-\r
-               String[] columnNames = new String[] { "Func name", "Input parameter",\r
-                               "Size", "result", "time", "caller" };\r
-               int[] columnWidths = new int[] { 120, 150, 50, 60, 50, 55 };\r
-               for (int i = 0; i < columnNames.length; i++) {\r
-                       TableColumn tableColumn = new TableColumn(table, SWT.LEFT);\r
-                       tableColumn.setText(columnNames[i]);\r
-                       tableColumn.setWidth(columnWidths[i]);\r
-               }\r
+               gridData.horizontalSpan = 3;\r
+               chartCompo.setLayoutData(gridData);\r
+\r
+               makeChartPart(chartCompo);\r
+\r
+               Composite apiTableCompo = new Composite(parent, SWT.BORDER);\r
+               apiTableCompo.setLayout(new GridLayout(10, true));\r
+               gridData = new GridData(GridData.FILL_BOTH);\r
+               gridData.horizontalSpan = 7;\r
+               apiTableCompo.setLayoutData(gridData);\r
+               \r
+               makeAPIListTablePart(apiTableCompo);\r
        }\r
 \r
        @Override\r
        public void setFocus() {\r
        }\r
 \r
-       private void makeChartPart(Composite parent) {\r
+       private void makeChartPart(Composite composite) {\r
                ResourceServiceListChartManager chartManager = ResourceServiceListChartManager\r
                                .getInstance();\r
-               JFreeChart chart = chartManager.getChart();\r
-               ChartComposite composite = new ChartComposite(parent, SWT.NONE, chart,\r
-                               true);\r
-               GridData gridData = new GridData(GridData.FILL_BOTH);\r
-               gridData.horizontalSpan = 5;\r
-               composite.setLayoutData(gridData);\r
+               chartManager.initChart(composite);\r
+       }\r
+       \r
+       private void makeAPIListTablePart(Composite composite) {\r
+               APIListTableManager apiTableManager = APIListTableManager.getInstance();\r
+               apiTableManager.initTableViewer(composite);\r
        }\r
 }\r
diff --git a/com.samsung.dynamicanalyzer/src/com/samsung/dynamicanalyzer/ui/views/lifecycle/APIListTableManager.java b/com.samsung.dynamicanalyzer/src/com/samsung/dynamicanalyzer/ui/views/lifecycle/APIListTableManager.java
new file mode 100644 (file)
index 0000000..d103c11
--- /dev/null
@@ -0,0 +1,123 @@
+package com.samsung.dynamicanalyzer.ui.views.lifecycle;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+
+public class APIListTableManager implements LifeCycleObserver {
+       private static APIListTableManager apiListTableManager = null;
+       private static String[] columnNames;
+//     private static int[] columnWidths;
+       private TableViewer tableViewer;
+       private Text detail;
+
+       private APIListTableManager() {
+               columnNames = new String[] { "ID", "Sequence\nNumber", "API\nName",
+                               "Time", "Input\nParameter", "Return\nValue", "PC\nAddress",
+                               "Error\nNumber", "Size", "FD\nValue", "FD\nType",
+                               "FD\nAPI Type" };
+//             columnWidths = new int[] { 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100};
+       }
+
+       public static APIListTableManager getInstance() {
+               if (apiListTableManager == null) {
+                       return apiListTableManager = new APIListTableManager();
+               } else {
+                       return apiListTableManager;
+               }
+       }
+
+       public void initTableViewer(Composite composite) {
+               Button button = new Button(composite, SWT.CHECK);
+               button.setText("Failed");
+               GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+               gridData.horizontalSpan = 10;
+               gridData.horizontalAlignment = SWT.END;
+               button.setLayoutData(gridData);
+               
+               tableViewer = new TableViewer(composite, SWT.SINGLE);
+               tableViewer.setLabelProvider(new TableLabelProvider());
+               tableViewer.setContentProvider(new ContentProvider());
+               Table table = tableViewer.getTable();
+               table.setHeaderVisible(true);
+               table.setLinesVisible(true);
+               for (int i = 0; i < columnNames.length; i++) {
+                       TableColumn tableColumn = new TableColumn(table, SWT.LEFT);
+                       tableColumn.setText(columnNames[i]);
+                       tableColumn.setWidth(60);
+               }
+               gridData = new GridData(GridData.FILL_BOTH);
+               gridData.horizontalSpan = 10;
+               table.setLayoutData(gridData);
+               table.addSelectionListener(new SelectionListener() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               TableItem item = (TableItem)e.item;
+                               System.out.println(item.getText(2));
+                       }
+                       
+                       @Override
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                       }
+               });
+               
+               
+               detail = new Text(composite, SWT.MULTI);
+               gridData = new GridData(GridData.FILL_BOTH);
+               gridData.horizontalSpan = 10;
+               detail.setLayoutData(gridData);
+       }
+
+       @Override
+       public void Update(List<List<String>> logs) {
+               tableViewer.add(logs.toArray());
+       }
+       
+       private class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
+               @Override
+               public Image getColumnImage(Object element, int columnIndex) {
+                       return null;
+               }
+
+               @Override
+               public String getColumnText(Object element, int columnIndex) {
+                       List<String> log = (List<String>)element;
+                       String result = "";
+                       result = log.get(columnIndex);
+                       
+                       return result;
+               }
+       }
+       
+       private class ContentProvider implements IStructuredContentProvider {
+
+               @Override
+               public void dispose() {
+               }
+
+               @Override
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               }
+
+               @Override
+               public Object[] getElements(Object inputElement) {
+                       List<List<String>> logs = (List<List<String>>)inputElement;
+                       return logs.toArray();
+               }
+       }
+}
index 048452b..45f83bc 100644 (file)
@@ -12,6 +12,7 @@ public class LifeCycleSubject implements IUpdateLog {
        public LifeCycleSubject() {
                observers = new ArrayList<LifeCycleObserver>();
                attach(ResourceServiceListChartManager.getInstance());
+               attach(APIListTableManager.getInstance());
        }
        
        @Override
@@ -28,8 +29,4 @@ public class LifeCycleSubject implements IUpdateLog {
        private void attach(LifeCycleObserver observer) {
                observers.add(observer);
        }
-       
-//     private void detach(LifeCycleObserver observer) {
-//             observers.remove(observer);
-//     }
 }
index 9bc2c21..a59f5fa 100644 (file)
@@ -6,12 +6,12 @@ import java.util.List;
 public class OpenedResourceManager {
        private HashMap<String, LifeCycleResource> opendResources;
        private ClosedResourceManager closedResourceManager;
-
+       
        public OpenedResourceManager(ClosedResourceManager closedResourceManager) {
                opendResources = new HashMap<String, LifeCycleResource>();
                this.closedResourceManager = closedResourceManager;
        }
-
+       
        public void processNewLogs(List<List<String>> logs) {
                for(List<String> log : logs) {
                        String fdValue = log.get(LifeCycleLogIndex.FD_VAL.ordinal());
@@ -39,7 +39,7 @@ public class OpenedResourceManager {
 //                     System.out.println(resource.toString());
 //             }
        }
-
+       
        private void moveToClosed(String fdValue, List<String> log) {
                LifeCycleResource opendResource = opendResources.get(fdValue);
                int time = Integer.parseInt(log.get(LifeCycleLogIndex.TIME.ordinal()));
@@ -48,7 +48,7 @@ public class OpenedResourceManager {
                closedResourceManager.processNewResource(opendResource);
                opendResources.remove(fdValue);
        }
-
+       
        private void addNewResource(List<String> log) {
                String fdValue = log.get(LifeCycleLogIndex.FD_VAL.ordinal());
                int time = Integer.parseInt(log.get(LifeCycleLogIndex.TIME.ordinal()));
@@ -56,7 +56,7 @@ public class OpenedResourceManager {
                LifeCycleResource resource = new LifeCycleResource(fdValue, time);
                opendResources.put(fdValue, resource);
        }
-
+       
        private boolean isCloseAPI(List<String> log) {
                if(log.get(LifeCycleLogIndex.API_NAME.ordinal()).equals("close")) {
                        return true;
@@ -65,7 +65,7 @@ public class OpenedResourceManager {
                        return false;
                }
        }
-
+       
        private boolean isOpenAPI(List<String> log) {
                if(log.get(LifeCycleLogIndex.API_NAME.ordinal()).equals("open")) {
                        return true;
index 08ccbf2..b789930 100644 (file)
@@ -2,128 +2,191 @@ package com.samsung.dynamicanalyzer.ui.views.lifecycle;
 
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Font;
 import java.util.List;
 
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
 import org.jfree.chart.ChartFactory;
+import org.jfree.chart.ChartMouseEvent;
+import org.jfree.chart.ChartMouseListener;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.annotations.XYPointerAnnotation;
+import org.jfree.chart.axis.SymbolAxis;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.chart.plot.XYPlot;
 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
+import org.jfree.data.xy.XYDataItem;
 import org.jfree.data.xy.XYSeries;
 import org.jfree.data.xy.XYSeriesCollection;
+import org.jfree.experimental.chart.swt.ChartComposite;
 
-
-public class ResourceServiceListChartManager implements LifeCycleObserver{
-       public static final int itemNum = 3;
+public class ResourceServiceListChartManager implements LifeCycleObserver {
+       public static final int itemNum = 10;
+       private static final double chartRange = 1000.0;
+       private static final double chartMargin = 100.0;
        private static ResourceServiceListChartManager resourceServiceListChartManager = null;
        private JFreeChart chart;
        private XYSeriesCollection dataSet;
-       
+
        private OpenedResourceManager opendResourceManager;
        private ClosedResourceManager closedResourceManager;
-       
+
        private ResourceServiceListChartManager() {
                closedResourceManager = new ClosedResourceManager();
                opendResourceManager = new OpenedResourceManager(closedResourceManager);
                dataSet = new XYSeriesCollection();
-               makeChart();
        }
-       
+
        public static ResourceServiceListChartManager getInstance() {
-               if(resourceServiceListChartManager == null) {
-                       resourceServiceListChartManager = new ResourceServiceListChartManager();
+               if (resourceServiceListChartManager == null) {
+                       return resourceServiceListChartManager = new ResourceServiceListChartManager();
+               } else {
                        return resourceServiceListChartManager;
                }
-               else { 
-                return resourceServiceListChartManager;
-               }
-       }
-       
-       private void makeChart() {
-                chart = ChartFactory.createXYLineChart(
-                           null,                               // chart title
-                           null,                      // x axis label
-                           null,                      // y axis label
-                           dataSet,                  // data
-                           PlotOrientation.VERTICAL,
-                           false,                     // include legend
-                           true,                     // tooltips
-                           false                     // urls
-                       );
-                
-                chart.setBackgroundPaint(Color.WHITE);
-                chart.setBorderVisible(true);
-                
-                initPlot();
        }
-       
-       public JFreeChart getChart() {
-               return chart;
+
+       public void initChart(Composite composite) {
+               chart = ChartFactory.createXYLineChart(null, // chart title
+                               null, // x axis label
+                               null, // y axis label
+                               dataSet, // data
+                               PlotOrientation.VERTICAL, false, // include legend
+                               true, // tooltips
+                               false // urls
+                               );
+
+               chart.setBackgroundPaint(Color.WHITE);
+               chart.setBorderVisible(true);
+
+               initPlot();
+
+               ChartComposite chartComposite = new ChartComposite(composite, SWT.NONE,
+                               chart, true);
+               chartComposite.setDomainZoomable(false);
+               chartComposite.setRangeZoomable(false);
+
+               chartComposite.addChartMouseListener(new ChartMouseListener() {
+                       @Override
+                       public void chartMouseMoved(ChartMouseEvent arg0) {
+                       }
+
+                       @Override
+                       public void chartMouseClicked(ChartMouseEvent arg0) {
+                               System.out.println("mouse clicked");
+                       }
+               });
        }
-       
+
        private void initPlot() {
-               XYPlot plot  = chart.getXYPlot();
-               
+               XYPlot plot = chart.getXYPlot();
+
                plot.setBackgroundPaint(Color.WHITE);
                plot.setOutlineVisible(false);
-               
+
                plot.setDomainGridlinesVisible(false);
                plot.setRangeGridlinesVisible(false);
-               
-//             plot.getRangeAxis().setVisible(false);
-//             plot.getDomainAxis().setVisible(false);
+
+               // plot.getRangeAxis().setVisible(false);
+               plot.getDomainAxis().setVisible(false);
        }
 
        @Override
        public void Update(List<List<String>> logs) {
                opendResourceManager.processNewLogs(logs);
                closedResourceManager.printClosedResources();
-               
+
                int bottom = closedResourceManager.getBottom();
-               LifeCycleResource[] closedResources = closedResourceManager.getClosedResources();
-               try{
+               LifeCycleResource[] closedResources = closedResourceManager
+                               .getClosedResources();
                dataSet.removeAllSeries();
-               }catch(Exception e)
-               {
-                       System.out.println("상현아 에러난다");
-                       System.out.println("ResourceServiceListChartManager.java 85 line invalid thread access ");
-                       return;
+
+               String[] symbols = new String[itemNum + 2];
+               for (int i = 0; i <= itemNum + 1; i++) {
+                       symbols[i] = "";
                }
-               
-               for(int i = bottom; i >=0; i--) {
+
+               for (int i = 0; i <= bottom; i++) {
                        XYSeries usedSeries = new XYSeries(closedResources[i].getFdValue());
-                       usedSeries.add(calcFirstLocationPercentage(closedResources[i]) * 1000, i + 1);
-                       usedSeries.add(calcLastLocationPercentage(closedResources[i]) * 1000, i + 1);
-                       
-                       XYSeries unusedSeries = new XYSeries(closedResources[i].getFdValue());
-                       unusedSeries.add(0, i + 1);
-                       unusedSeries.add(1000, i + 1);
-                       
+                       usedSeries.add(calcFirstLocationPercentage(closedResources[i])
+                                       * chartRange + chartMargin, itemNum - i);
+                       usedSeries.add(calcLastLocationPercentage(closedResources[i])
+                                       * chartRange + chartMargin, itemNum - i);
+
+                       XYSeries unusedSeries = new XYSeries(
+                                       closedResources[i].getFdValue());
+                       unusedSeries.add(chartMargin, itemNum - i);
+                       unusedSeries.add(chartRange + chartMargin, itemNum - i);
+
                        dataSet.addSeries(usedSeries);
                        dataSet.addSeries(unusedSeries);
+
+                       symbols[itemNum - i] = "fd " + closedResources[i].getFdValue();
                }
-               
+
+               int seriesCount = dataSet.getSeriesCount();
                final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
-               for(int i = 0; i < dataSet.getSeriesCount(); i++){
-               renderer.setSeriesStroke(i, new BasicStroke(3f));
-               renderer.setSeriesOutlineStroke(i, new BasicStroke(2.0f));
-               renderer.setSeriesShape(i, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
-               
-               if(i % 2 == 0) {
-                       renderer.setSeriesPaint(i, Color.black);
-               }
-               else {
-                       renderer.setSeriesPaint(i, Color.red);
-               }
-        }
+               for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {
+                       renderer.setSeriesStroke(seriesIndex, new BasicStroke(3f));
+                       renderer.setSeriesOutlineStroke(seriesIndex, new BasicStroke(2.0f));
+                       renderer.setSeriesShape(seriesIndex,
+                                       new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D));
+
+                       if (seriesIndex % 2 == 0) {
+                               renderer.setSeriesPaint(seriesIndex, Color.black);
+                       } else {
+                               renderer.setSeriesPaint(seriesIndex, Color.red);
+                       }
+
+                       XYSeries series = dataSet.getSeries(seriesIndex);
+                       int itemSize = series.getItemCount();
+                       for (int itemIndex = 0; itemIndex < itemSize; itemIndex++) {
+                               XYDataItem item = (XYDataItem) (series.getItems()
+                                               .get(itemIndex));
+                               
+                               String label = "";
+                               if(seriesIndex % 2 == 0) {
+                                       if(itemIndex == 0) {
+                                               label = ((Integer)(closedResources[seriesIndex / 2].getFirstTime())).toString();
+                                       } else {
+                                               label = ((Integer)(closedResources[seriesIndex / 2].getLastTime())).toString();
+                                       }
+                               } else {
+                                       if(itemIndex == 0) {
+                                               label = ((Integer)(closedResources[seriesIndex / 2].getOpenTime())).toString();
+                                       } else {
+                                               label = ((Integer)(closedResources[seriesIndex / 2].getCloseTime())).toString();
+                                       }
+                               }
+                               XYPointerAnnotation annotation = new XYPointerAnnotation(
+                                               label,
+                                               item.getXValue(), item.getYValue(),
+                                               90 * (Math.PI / 180.0));
+                               annotation.setTipRadius(2D);
+                               annotation.setBaseRadius(17D);
+                               annotation.setFont(new Font(null, 0, 9));
+                               chart.getXYPlot().addAnnotation(annotation);
+                       }
+               }
+
+               chart.getXYPlot().setRangeAxis(new SymbolAxis(null, symbols));
+               chart.getXYPlot().getDomainAxis()
+                               .setRange(0, chartRange + chartMargin + chartMargin);
+               chart.getXYPlot().getRangeAxis().setRange(0, itemNum + 1);
                chart.getXYPlot().setRenderer(renderer);
        }
-       
+
        private double calcFirstLocationPercentage(LifeCycleResource resource) {
-               return (resource.getFirstTime() - resource.getOpenTime()) / (resource.getCloseTime() - resource.getOpenTime());
+               double numerator = resource.getFirstTime() - resource.getOpenTime();
+               double denominator = resource.getCloseTime() - resource.getOpenTime();
+
+               return numerator / denominator;
        }
-       
+
        private double calcLastLocationPercentage(LifeCycleResource resource) {
-               return (resource.getLastTime() - resource.getOpenTime()) / (resource.getCloseTime() - resource.getOpenTime());
+               double numerator = resource.getLastTime() - resource.getOpenTime();
+               double denominator = resource.getCloseTime() - resource.getOpenTime();
+
+               return numerator / denominator;
        }
 }