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;
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);
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;
}
});
- 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;
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);
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;
}
});
- 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;
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);
--- /dev/null
+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());
+ }
+ }
+}
--- /dev/null
+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;
+ }
+ });
+ }
+}