WindowingTable : remove old sql connection. 99/26699/1
authorHyunjong.park <phjwithyou.park@samsung.com>
Thu, 28 Aug 2014 02:36:55 +0000 (11:36 +0900)
committerHyunjong.park <phjwithyou.park@samsung.com>
Thu, 28 Aug 2014 02:36:55 +0000 (11:36 +0900)
Signed-off-by: Hyunjong.park <phjwithyou.park@samsung.com>
Change-Id: I31870f3f2c5acbf0d47c879b93219759c8e78f2d

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/widgets/table/DAWindowingTableComposite.java

index 5aced0e..03a4ef2 100644 (file)
@@ -45,6 +45,7 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.ScrollBar;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.dynamicanalyzer.common.AnalyzerManager;
+import org.tizen.dynamicanalyzer.constant.CommonConstants;
 import org.tizen.dynamicanalyzer.database.SqlConnectionManager;
 import org.tizen.dynamicanalyzer.model.FindProperty;
 import org.tizen.dynamicanalyzer.model.TableInput;
@@ -57,8 +58,9 @@ import org.tizen.dynamicanalyzer.util.CommonUtil;
 import org.tizen.dynamicanalyzer.util.WorkbenchUtil;
 
 public abstract class DAWindowingTableComposite extends DATableComposite {
-       private static final String queryto_GetItemCount = "select count(*) from %s where %s";
-       private static final String queryto_GetLimitedItem = "select limit %s %s %s from %s where %s";
+       private static final String queryto_GetItemCount = "select count(*) from %s where %s";//$NON-NLS-1$
+       private static final String queryto_GetSelectionVScrollbarIndex = "select count(*) from %s where (%s <= %s)";//$NON-NLS-1$
+       private static final String queryto_GetLimitedItem = "select limit %s %s %s from %s where %s";//$NON-NLS-1$
 
        protected Composite scrollComp;
        protected ScrollBar vScrollbar;
@@ -78,8 +80,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
        private List<LogData> queriedLogData = null;
        private List<List<Object>> queriedObjectData = null;
 
-       public DAWindowingTableComposite(Composite parent, int compStyle,
-                       int tableStyle) {
+       public DAWindowingTableComposite(Composite parent, int compStyle, int tableStyle) {
                super(parent, compStyle, tableStyle);
        }
 
@@ -154,8 +155,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                        @Override
                        public void widgetSelected(SelectionEvent e) {
                                GridItem[] ti = ((Grid) e.widget).getSelection();
-                               if (null == ti || ti.length == 0
-                                               || !(ti[0].getData() instanceof DATableDataFormat)) {
+                               if (null == ti || ti.length == 0 || !(ti[0].getData() instanceof DATableDataFormat)) {
                                        return;
                                }
                                GridItem focusedItem = ((Grid) e.widget).getFocusItem();
@@ -163,8 +163,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                                        if (!(focusedItem.getData() instanceof DATableDataFormat)) {
                                                return;
                                        }
-                                       DATableDataFormat td = (DATableDataFormat) focusedItem
-                                                       .getData();
+                                       DATableDataFormat td = (DATableDataFormat) focusedItem.getData();
                                        if (null == td) {
                                                return;
                                        }
@@ -173,8 +172,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                                                selectionStartTime = td.getLogData().getTime();
                                                selectionEndTime = td.getLogData().getTime();
                                        } else {
-                                               selectionStartTime = (Long) td.getData().get(
-                                                               timeColumnIndex);
+                                               selectionStartTime = (Long) td.getData().get(timeColumnIndex);
                                                selectionEndTime = selectionStartTime;
                                        }
 
@@ -208,8 +206,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                                        if (ctrlPressed) {
                                                ctrlPressed = false;
                                                if (findEnabled) {
-                                                       Shell shell = WorkbenchUtil.getWorkbenchWindow()
-                                                                       .getShell();
+                                                       Shell shell = WorkbenchUtil.getWorkbenchWindow().getShell();
                                                        FindDialog dialog = new FindDialog(shell, me);
                                                        dialog.open();
                                                }
@@ -280,12 +277,10 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
        }
 
        protected int getTableLength() {
-               return (this.tableAreaHeigth - table.getHeaderHeight())
-                               / (table.getItemHeight() + 1);
+               return (this.tableAreaHeigth - table.getHeaderHeight()) / (table.getItemHeight() + 1);
        }
 
        public void updateHScrollBar(int tableWidth) {
-               System.out.println("width : " + tableWidth);
                hScrollbar.setMaximum(totalColumnSize);
                hScrollbar.setThumb(tableWidth);
                hScrollbar.setVisible(true);
@@ -321,8 +316,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
 
                for (int i = 0; i < size; i++) {
                        GridItem gridItem = new GridItem(table, SWT.NONE);
-                       DATableDataFormat gridData = (DATableDataFormat) output.get(i)
-                                       .getData();
+                       DATableDataFormat gridData = (DATableDataFormat) output.get(i).getData();
                        gridItem.setData(gridData);
 
                        List<String> text = output.get(i).getText();
@@ -388,10 +382,9 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                        if (totalItemCount == 0) { // open or never trace
                                String tablename = getDBTableName();
                                if (tablename != null && !tablename.isEmpty()) {
-                                       String query = String.format(queryto_GetItemCount,
-                                                       getDBTableName(), getSelectQueryCountOption());
-                                       List<List<Object>> result = SqlConnectionManager
-                                                       .executeQuery(query);
+                                       String query = String.format(queryto_GetItemCount, getDBTableName(),
+                                                       getSelectQueryCountOption());
+                                       List<List<Object>> result = SqlConnectionManager.executeQuery(query);
                                        if (result != null) {
                                                Object object = result.get(0).get(0);
                                                if (object instanceof Integer) {
@@ -440,8 +433,7 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                        }
                }
 
-               if ((isLogData && queriedLogData == null)
-                               || (!isLogData && queriedObjectData == null)) {
+               if ((isLogData && queriedLogData == null) || (!isLogData && queriedObjectData == null)) {
                        return null;
                }
 
@@ -469,12 +461,11 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                for (int i = 0; i < columnsize; i++) {
                        columnString.append(columnNames.get(i));
                        if (i < columnsize - 1)
-                               columnString.append(", ");
+                               columnString.append(", ");//$NON-NLS-1$
                }
 
-               String query = String.format(queryto_GetLimitedItem, scrollSelection,
-                               selectedEndIndex + 1, columnString.toString(), tableName,
-                               getSelectQueryOption());
+               String query = String.format(queryto_GetLimitedItem, scrollSelection, selectedEndIndex + 1,
+                               columnString.toString(), tableName, getSelectQueryOption());
 
                return SqlConnectionManager.executeQuery(query);
        }
@@ -493,9 +484,9 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                if (itemCount <= selectedEndIndex) {
                        selectedEndIndex = itemCount;
                }
-               List<LogData> outputList = SqlManager.getInstance().selectTableData(
-                               tableName, getDBTableColumnNames(), scrollSelection,
-                               selectedEndIndex + 1, getSelectQueryOption());
+               List<LogData> outputList = SqlManager.getInstance().selectTableData(tableName,
+                               getDBTableColumnNames(), scrollSelection, selectedEndIndex + 1,
+                               getSelectQueryOption());
                return outputList;
        }
 
@@ -519,12 +510,11 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                if (null != item) {
                        long inputTime;
                        if (isLogData) {
-                               LogData data = ((DATableDataFormat) item.getData())
-                                               .getLogData();
+                               LogData data = ((DATableDataFormat) item.getData()).getLogData();
                                inputTime = data.getTime();
                        } else {
-                               inputTime = (Long) ((DATableDataFormat) item.getData())
-                                               .getData().get(timeColumnIndex);
+                               inputTime = (Long) ((DATableDataFormat) item.getData()).getData().get(
+                                               timeColumnIndex);
                        }
 
                        if (type == START_TIME) {
@@ -549,10 +539,24 @@ public abstract class DAWindowingTableComposite extends DATableComposite {
                        selectionStartTime = startTime;
                        selectionEndTime = endTime;
 
-                       int selectionIndex = SqlManager.getInstance().getSelectionIndex(
-                                       tableName, getTimeColumnName(), selectionStartTime,
-                                       getSelectQueryCountOption());
-                       vScrollbar.setSelection(selectionIndex - 1);
+                       String query = String.format(queryto_GetSelectionVScrollbarIndex, tableName,
+                                       getTimeColumnName(), Long.toString(startTime));
+                       if (!getSelectQueryCountOption().equals(CommonConstants.EMPTY)) {
+                               query += " and " + CommonConstants.OPEN_BRACKET + getSelectQueryCountOption()//$NON-NLS-1$
+                                               + CommonConstants.CLOSE_BRACKET;
+                       }
+
+                       List<List<Object>> resultList = SqlConnectionManager.executeQuery(query);
+                       if (resultList.size() == 0 || resultList.get(0).size() == 0) {
+                               return;
+                       }
+                       String strSelectionIndex = String.valueOf((Long) resultList.get(0).get(0));
+                       int intSelectionIndex = Integer.parseInt(strSelectionIndex);
+                       if (intSelectionIndex > 0) {
+                               vScrollbar.setSelection(intSelectionIndex - 1);
+                       } else {
+                               vScrollbar.setSelection(0);
+                       }
                }
        }