[Title] Support to sort repository and package table in package
authordonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 6 Sep 2012 08:47:56 +0000 (17:47 +0900)
committerdonghyuk.yang <donghyuk.yang@samsung.com>
Thu, 6 Sep 2012 08:47:56 +0000 (17:47 +0900)
manager

Change-Id: Ia0784eebb60dc2f59d35dcbfe9b1c5beaac54f77

org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/BuildSystemTab.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/DeviceTab.java
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/PackageTableSelectionAdapter.java [new file with mode: 0644]
org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/RepoTableSelectionAdapter.java [new file with mode: 0644]

index 3bf957d..2a4f00c 100644 (file)
@@ -16,9 +16,13 @@ import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
@@ -65,7 +69,7 @@ public class BuildSystemTab {
        private String previousFilterPath = null;
        private String selectedFileList;
        private CopyOnWriteArrayList<Package> pkgs;
-       private SmartBuildInterface sbi = null;
+       private SmartBuildInterface sbi = null; 
 
        private final String BUNDLE_NAME = BuildSystemTab.class.getPackage().getName() + ".PkgMgrUIMessages";//$NON-NLS-1$
        private final ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_NAME);
@@ -745,9 +749,11 @@ public class BuildSystemTab {
                String[] titles = {"Name", "Reposity URL"};
                int[] bounds = { 200, 600 };
 
-               TableViewerColumn colInstallType = createTableViewerColumn( repoViewer, titles[0], bounds[0], SWT.NONE);
+               TableViewerColumn colName = createTableViewerColumn( repoViewer, titles[0], bounds[0], SWT.NONE);
+               TableColumn column = colName.getColumn();
+               column.addSelectionListener(new RepoTableSelectionAdapter(repoViewer));         
 
-               colInstallType.setLabelProvider(new ColumnLabelProvider() {
+               colName.setLabelProvider(new ColumnLabelProvider() {
                        @Override
                        public String getText(Object element) {
                                Repository repo = (Repository)element;
@@ -755,9 +761,11 @@ public class BuildSystemTab {
                        }
                });
 
-               TableViewerColumn colPackage = createTableViewerColumn( repoViewer, titles[1], bounds[1], SWT.NONE);
+               TableViewerColumn colUrl = createTableViewerColumn( repoViewer, titles[1], bounds[1], SWT.NONE);
+               column = colUrl.getColumn();
+               column.addSelectionListener(new RepoTableSelectionAdapter(repoViewer));
 
-               colPackage.setLabelProvider(new ColumnLabelProvider() {
+               colUrl.setLabelProvider(new ColumnLabelProvider() {
                        @Override
                        public String getText(Object element) {
                                Repository repo = (Repository)element;
@@ -769,7 +777,8 @@ public class BuildSystemTab {
        private TableViewerColumn createTableViewerColumn(TableViewer viewer, String title, int bound, int Style) {
 
                final TableViewerColumn viewerColumn = new TableViewerColumn( viewer,   Style);
-               final TableColumn column = viewerColumn.getColumn();
+               final TableColumn column = viewerColumn.getColumn();            
+               column.addSelectionListener(new PackageTableSelectionAdapter(pkgViewer));
                column.setText(title);
                column.setWidth(bound);
                column.setResizable(true);
index c0d44cd..625e75d 100644 (file)
@@ -748,9 +748,11 @@ public class DeviceTab {
                String[] titles = {"Name", "Reposity URL"};
                int[] bounds = { 200, 600 };
 
-               TableViewerColumn colInstallType = createTableViewerColumn( repoViewer, titles[0], bounds[0], SWT.NONE);
+               TableViewerColumn colName = createTableViewerColumn( repoViewer, titles[0], bounds[0], SWT.NONE);
+               TableColumn column = colName.getColumn();
+               column.addSelectionListener(new RepoTableSelectionAdapter(repoViewer));
 
-               colInstallType.setLabelProvider(new ColumnLabelProvider() {
+               colName.setLabelProvider(new ColumnLabelProvider() {
                        @Override
                        public String getText(Object element) {
                                Repository repo = (Repository)element;
@@ -758,9 +760,11 @@ public class DeviceTab {
                        }
                });
 
-               TableViewerColumn colPackage = createTableViewerColumn( repoViewer, titles[1], bounds[1], SWT.NONE);
+               TableViewerColumn colUrl = createTableViewerColumn( repoViewer, titles[1], bounds[1], SWT.NONE);
+               column = colUrl.getColumn();
+               column.addSelectionListener(new RepoTableSelectionAdapter(repoViewer));
 
-               colPackage.setLabelProvider(new ColumnLabelProvider() {
+               colUrl.setLabelProvider(new ColumnLabelProvider() {
                        @Override
                        public String getText(Object element) {
                                Repository repo = (Repository)element;
@@ -773,6 +777,7 @@ public class DeviceTab {
 
                final TableViewerColumn viewerColumn = new TableViewerColumn( viewer,   Style);
                final TableColumn column = viewerColumn.getColumn();
+               column.addSelectionListener(new PackageTableSelectionAdapter(pkgViewer));
                column.setText(title);
                column.setWidth(bound);
                column.setResizable(true);
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/PackageTableSelectionAdapter.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/PackageTableSelectionAdapter.java
new file mode 100644 (file)
index 0000000..143f62e
--- /dev/null
@@ -0,0 +1,98 @@
+package org.tizen.nativeplatform.pkgmgr.ui;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+
+import org.tizen.nativeplatform.pkgmgr.model.Package;
+
+public class PackageTableSelectionAdapter extends SelectionAdapter {
+       private TableViewer repoViewer;
+       private int selectedColumn = 0;
+       public PackageTableSelectionAdapter(TableViewer v) {
+               super();
+               this.repoViewer = v;                    
+       }
+       
+       public void widgetSelected(SelectionEvent e) {                          
+               selectedColumn = repoViewer.getTable().indexOf((TableColumn) e.widget);
+               repoViewer.getTable().setSortColumn((TableColumn)e.widget);
+               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {                                             
+                       repoViewer.getTable().setSortDirection(SWT.UP);
+               } else {
+                       repoViewer.getTable().setSortDirection(SWT.DOWN);
+               }                       
+               
+               repoViewer.setSorter(new ViewerSorter() {
+                       public int compare(Viewer viewer, Object e1, Object e2) {
+                               int result = 0;
+                               
+                               Package entry_1 = (Package)e1;
+                               Package entry_2 = (Package)e2;
+                               
+                               switch (selectedColumn) {
+                                       case 0:                                                                 
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getPkgType().compareTo(entry_2.getPkgType());
+                                               } else {
+                                                       result = entry_2.getPkgType().compareTo(entry_1.getPkgType());
+                                               }
+                                               break;
+                                       case 1:
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getName().compareTo(entry_2.getName());
+                                               } else {
+                                                       result = entry_2.getName().compareTo(entry_1.getName());
+                                               }
+                                               break;                                          
+                                       case 2:
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getArch().compareTo(entry_2.getArch());
+                                               } else {
+                                                       result = entry_2.getArch().compareTo(entry_1.getArch());
+                                               }
+                                               break;
+                                       case 3:
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getNewVersion().compareTo(entry_2.getNewVersion());
+                                               } else {
+                                                       result = entry_2.getNewVersion().compareTo(entry_1.getNewVersion());
+                                               }
+                                               break;
+                                       case 4:
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getInstalledVersion().compareTo(entry_2.getInstalledVersion());
+                                               } else {
+                                                       result = entry_2.getInstalledVersion().compareTo(entry_1.getInstalledVersion());
+                                               }
+                                               break;
+                                       case 5:
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getInstallInfo().toString().compareTo(entry_2.getInstallInfo().toString());
+                                               } else {
+                                                       result = entry_2.getInstallInfo().toString().compareTo(entry_1.getInstallInfo().toString());
+                                               }
+                                               break;                                          
+                               }                                       
+                               
+                               return result;
+                       }
+               });
+               updateCheck();
+       }
+       
+       private void updateCheck() {            
+               int recentTableIndex = repoViewer.getTable().getItemCount();            
+               
+               for (int i = 0; i < recentTableIndex; i++) {
+                       TableItem item = repoViewer.getTable().getItem(i);                      
+                       Package pkg = (Package)item.getData();
+                       item.setChecked(pkg.getCheckColumn());                  
+               }       
+       }
+}
diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/RepoTableSelectionAdapter.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkgmgr/ui/RepoTableSelectionAdapter.java
new file mode 100644 (file)
index 0000000..0b030c0
--- /dev/null
@@ -0,0 +1,57 @@
+package org.tizen.nativeplatform.pkgmgr.ui;
+
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.TableColumn;
+import org.tizen.nativeplatform.pkgmgr.model.Repository;
+
+public class RepoTableSelectionAdapter extends SelectionAdapter {
+       private TableViewer repoViewer;
+       private int selectedColumn = 0;
+       public RepoTableSelectionAdapter(TableViewer v) {
+               super();
+               this.repoViewer = v;                    
+       }
+       
+       public void widgetSelected(SelectionEvent e) {                          
+               selectedColumn = repoViewer.getTable().indexOf((TableColumn) e.widget);
+               repoViewer.getTable().setSortColumn((TableColumn)e.widget);
+               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {                                             
+                       repoViewer.getTable().setSortDirection(SWT.UP);
+               } else {
+                       repoViewer.getTable().setSortDirection(SWT.DOWN);
+               }                       
+               
+               repoViewer.setSorter(new ViewerSorter() {
+                       public int compare(Viewer viewer, Object e1, Object e2) {
+                               int result = 0;
+                               
+                               Repository entry_1 = (Repository)e1;
+                               Repository entry_2 = (Repository)e2;
+                               
+                               switch (selectedColumn) {
+                                       case 0:                                                                 
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getName().compareTo(entry_2.getName());
+                                               } else {
+                                                       result = entry_2.getName().compareTo(entry_1.getName());
+                                               }
+                                               break;
+                                       case 1:
+                                               if (repoViewer.getTable().getSortDirection() == SWT.DOWN) {
+                                                       result = entry_1.getUri().compareTo(entry_2.getUri());
+                                               } else {
+                                                       result = entry_2.getUri().compareTo(entry_1.getUri());
+                                               }
+                                               break;                                          
+                               }                                       
+                               
+                               return result;
+                       }
+               });                     
+       }
+}