Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Commit [c2d873] Maximize Restore History

wip

ocm ocm 2012-11-04

1 2 3 .. 7 > >> (Page 1 of 7)
added trunk/OCMCore/src/org/ocm/core/cachestore/CacheStoreException.java
added trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTMapWidget.java
added trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheStorePicker.java
added trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheStorePicker.java
added trunk/OCMDesktop/src/org/ocm/ui/widgets/MainWindow.java
changed trunk/OCMCore/src/org/ocm/core/cachestore/CacheStore.java
changed trunk/OCMDesktop/src/org/ocm/core/cachestore/internal/SQLLiteStore.java
changed trunk/OCMDesktop/src/org/ocm/ui/widgets/MapWidget.java
changed trunk/OCMDesktop/src/org/ocm/OCMDesktop.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/CacheMap.java -> trunk/OCMDesktop/src/org/ocm/ui/DatabaseManager.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/CacheTableWidget.java -> trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheList.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/MainWindow.java -> trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTMainWindow.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/QuickInfoWidget.java -> trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTQuickInfo.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/TableViewWidget.java -> trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheTableView.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheTableRenderer.java -> trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheList.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/QuickInfoRenderer.java -> trunk/OCMDesktop/src/org/ocm/ui/widgets/QuickInfo.java
copied trunk/OCMDesktop/src/org/ocm/ui/widgets/ViewWidget.java -> trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheTableView.java
trunk/OCMCore/src/org/ocm/core/cachestore/CacheStoreException.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTMapWidget.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheStorePicker.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheStorePicker.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/ui/widgets/MainWindow.java Diff Switch to side-by-side view
Loading...
trunk/OCMCore/src/org/ocm/core/cachestore/CacheStore.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/core/cachestore/internal/SQLLiteStore.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/ui/widgets/MapWidget.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/OCMDesktop.java Diff Switch to side-by-side view
Loading...
trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/CacheMap.java to trunk/OCMDesktop/src/org/ocm/ui/DatabaseManager.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/CacheMap.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/DatabaseManager.java
@@ -13,81 +13,50 @@
  *    See the License for the specific language governing permissions and
  *    limitations under the License.
  */
-package org.ocm.ui.widgets.swt;
+package org.ocm.ui;
 
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.browser.ProgressEvent;
-import org.eclipse.swt.browser.ProgressListener;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.Composite;
+import org.joda.time.DateTime;
+import org.ocm.core.cachestore.CacheStore;
 import org.ocm.core.cachestore.CacheTable;
-import org.ocm.core.cachestore.CacheTableItem;
-import org.ocm.ui.widgets.CacheTableItemSelectionListener;
-import org.ocm.ui.widgets.CacheTableRenderer;
+import org.ocm.core.cachestore.StoreFilter;
+import org.ocm.ui.widgets.CacheStorePicker;
+import org.ocm.ui.widgets.CacheTableView;
 
 /**
  * @author ocm
- *
+ * 
  */
-public class CacheMap extends Composite implements CacheTableRenderer {
-	
-	Browser browserWidget;
-	
-	protected CacheMap(Composite parent, int options){
-		super(parent, options);
-		this.setLayout(new FillLayout());
-		browserWidget = new Browser(this, SWT.WEBKIT);
-		browserWidget.setUrl(this.getClass().getResource("/res/map/wpt_viewer.html").toString());
-		browserWidget.addProgressListener(new ProgressListener() {
-			
-			@Override
-			public void completed(ProgressEvent event) {
-				addMapType();
-				
-			}
-			
-			@Override
-			public void changed(ProgressEvent event) {
-				// TODO Auto-generated method stub
-				
-			}
-		});
-	}
-	
-	private void addMapType(){
-		if (!browserWidget.execute("addMapRenderer(new OpenLayers.Layer.OSM( \"OSM: Mapnik\"))"))
-			System.out.println("OOPS!");
+public class DatabaseManager {
+
+	private final CacheStore store;
+	private final CacheStorePicker storePicker;
+	private CacheTableView viewWidget;
+	private StoreFilter filter;
+
+	public DatabaseManager(CacheStorePicker picker, CacheStore store, StoreFilter filter) {
+		this.store = store;
+		this.storePicker = picker;
+		this.filter = filter;
 	}
 
-	@Override
-	public void addItemSelectionListener(CacheTableItemSelectionListener listener) {
-		// TODO Auto-generated method stub
-
+	public void openCacheStore() {
+		String fileName = storePicker.getStoreFileName();
+		if (null != fileName) {
+			store.close();
+			store.open("jdbc:sqlite:" + fileName);
+			CacheTable table = store.getCacheTable(DateTime.now(), 30, 30, filter);
+			viewWidget.setCacheTable(table);
+		}
 	}
 
-	@Override
-	public void removeItemSelectionListener(CacheTableItemSelectionListener listener) {
-		// TODO Auto-generated method stub
-
+	public void registerViewWidget(CacheTableView renderer) {
+		viewWidget = renderer;
 	}
 
-	@Override
-	public void setTable(CacheTable table) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public void setSelectedItemByCode(String code) {
-		// TODO Auto-generated method stub
-
-	}
-
-	@Override
-	public CacheTableItem getSelectedItem() {
-		// TODO Auto-generated method stub
-		return null;
+	public void setFilter(StoreFilter filter) {
+		this.filter = filter;
+		CacheTable table = store.getCacheTable(DateTime.now(), 30, 30, filter);
+		viewWidget.setCacheTable(table);
 	}
 
 }
trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/CacheTableWidget.java to trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheList.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/CacheTableWidget.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheList.java
@@ -37,7 +37,7 @@
 import org.ocm.ui.Messages;
 import org.ocm.ui.widgets.CacheSelectionEvent;
 import org.ocm.ui.widgets.CacheTableItemSelectionListener;
-import org.ocm.ui.widgets.CacheTableRenderer;
+import org.ocm.ui.widgets.CacheList;
 
 /**
  * SWT Control for displaying a {@link CacheTable}
@@ -45,7 +45,7 @@
  * @author ocm
  * 
  */
-public class CacheTableWidget extends Composite implements CacheTableRenderer {
+public class SWTCacheList extends Composite implements CacheList {
 
 	Table tableWidget;
 	CacheTable cacheTable;
@@ -54,7 +54,7 @@
 	final Color darkOrangeColor;
 	final Color paleGreenColor;
 
-	protected CacheTableWidget(Composite parent, int style) {
+	protected SWTCacheList(Composite parent, int style) {
 		super(parent, style);
 		this.setLayout(new GridLayout());
 		initializeTable();
trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/MainWindow.java to trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTMainWindow.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/MainWindow.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTMainWindow.java
@@ -16,11 +16,11 @@
 package org.ocm.ui.widgets.swt;
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
@@ -31,13 +31,12 @@
 import org.eclipse.swt.widgets.Menu;
 import org.eclipse.swt.widgets.MenuItem;
 import org.eclipse.swt.widgets.Shell;
-import org.joda.time.DateTime;
 import org.ocm.core.cachestore.CacheStore;
-import org.ocm.core.cachestore.CacheTable;
 import org.ocm.core.cachestore.FilterFactory;
 import org.ocm.core.cachestore.FilterFactory.PredefinedFilter;
 import org.ocm.core.cachestore.internal.StoreModule;
 import org.ocm.core.geographic.CoordinateFactory;
+import org.ocm.ui.DatabaseManager;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -46,7 +45,7 @@
  * @author ocm
  * 
  */
-public class MainWindow {
+public class SWTMainWindow {
 
 	Display disp;
 	Shell mainShell;
@@ -55,41 +54,51 @@
 	MenuItem fileMenuHeader;
 	MenuItem fileOpen;
 	MenuItem fileExit;
-	TableViewWidget tableView;
+	SWTCacheTableView tableWidget;
 	CacheStore store;
 	CoolBar toolbar;
+	Injector inject;
+	private DatabaseManager manager;
 
-	public MainWindow(Display disp) {
+	public SWTMainWindow(Display disp) {
 		try {
-			Injector inject = Guice.createInjector(new StoreModule());
-			FilterFactory factory = inject.getInstance(FilterFactory.class);
+			inject = Guice.createInjector(new StoreModule());
 			this.disp = disp;
 			this.store = inject.getInstance(CacheStore.class);
-			store.open("jdbc:sqlite:/home/ocm/Dropbox/Ocm Dbs/home_synced.ocm");
-			CacheTable table = store.getCacheTable(DateTime.now(), 100, 100, factory.getFilter(PredefinedFilter.ALL, 100, 100));
-			table.setOrigin(inject.getInstance(CoordinateFactory.class).create(45.375, -75.375));
 			mainShell = new Shell(disp);
-			mainShell.setLayout(new FormLayout());
+			mainShell.setText("OCM");
+			manager = new DatabaseManager(new SWTCacheStorePicker(mainShell), store, inject.getInstance(FilterFactory.class).getFilter(PredefinedFilter.UNFOUND, 30, 30));
+			mainShell.addDisposeListener(new DisposeListener() {
+
+				@Override
+				public void widgetDisposed(DisposeEvent e) {
+					dispose();
+				}
+			});
+			FormLayout layout = new FormLayout();
+			layout.marginHeight = 5;
+			layout.marginWidth = 5;
+			mainShell.setLayout(layout);
 			layoutMenuBar();
 			layoutToolbar();
-			layoutView(table);
+			layoutView();
+			manager.registerViewWidget(tableWidget);
 
 		} catch (Exception e) {
-			// TODO Auto-generated catch block
 			e.printStackTrace();
+			System.exit(-1);
 		}
 	}
 
-	private void layoutView(CacheTable table) {
+	private void layoutView() {
+		tableWidget = new SWTCacheTableView(mainShell, SWT.NONE, inject.getInstance(CoordinateFactory.class));
 		FormData data;
-		tableView = new TableViewWidget(mainShell, SWT.NONE);
 		data = new FormData();
-		data.top = new FormAttachment(toolbar);
+		data.top = new FormAttachment(toolbar, 5);
 		data.left = new FormAttachment(0);
-		data.bottom = new FormAttachment(100);
+		data.bottom = new FormAttachment(100, -10);
 		data.right = new FormAttachment(100);
-		tableView.setLayoutData(data);
-		tableView.setCacheTable(table);
+		tableWidget.setLayoutData(data);
 	}
 
 	private void layoutToolbar() {
@@ -121,6 +130,19 @@
 		fileMenuHeader.setMenu(fileMenu);
 		fileOpen = new MenuItem(fileMenu, SWT.PUSH);
 		fileOpen.setText("&Open Database...");
+		fileOpen.addSelectionListener(new SelectionListener() {
+			
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				manager.openCacheStore();				
+			}
+			
+			@Override
+			public void widgetDefaultSelected(SelectionEvent e) {
+				// TODO Auto-generated method stub
+				
+			}
+		});
 		createFileExit();
 	}
 
@@ -149,4 +171,14 @@
 		}
 
 	}
+
+	public void dispose() {
+		mainMenuBar.dispose();
+		fileMenu.dispose();
+		fileMenuHeader.dispose();
+		fileOpen.dispose();
+		fileExit.dispose();
+		tableWidget.dispose();
+		toolbar.dispose();
+	}
 }
trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/QuickInfoWidget.java to trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTQuickInfo.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/QuickInfoWidget.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTQuickInfo.java
@@ -28,13 +28,13 @@
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Link;
 import org.ocm.core.cachestore.CacheTableItem;
-import org.ocm.ui.widgets.QuickInfoRenderer;
+import org.ocm.ui.widgets.QuickInfo;
 
 /**
  * @author ocm
  * 
  */
-public class QuickInfoWidget extends Composite implements QuickInfoRenderer {
+public class SWTQuickInfo extends Composite implements QuickInfo {
 
 	Label terrainAndDifficultyLabel;
 	Label statusLabel;
@@ -52,7 +52,7 @@
 	final Color darkOrangeColor;
 	final Color paleGreenColor;
 
-	protected QuickInfoWidget(Composite parent, int style) {
+	protected SWTQuickInfo(Composite parent, int style) {
 		super(parent, SWT.NONE);
 		this.goldColor = new Color(getDisplay(), 255, 215, 0);
 		this.darkOrangeColor = new Color(getDisplay(), 255, 140, 0);
@@ -128,7 +128,7 @@
 	private void layoutCacheType() {
 		FormData data;
 		data = new FormData();
-		data.top = new FormAttachment(cacheImage);
+		data.top = new FormAttachment(cacheTitle);
 		cacheType = new Label(this, SWT.NONE);
 		cacheType.setFont(boldFont);
 		cacheType.setLayoutData(data);
@@ -139,7 +139,7 @@
 		cacheImage = new Label(this, SWT.NONE);
 		data.top = new FormAttachment(this);
 		cacheImage.setLayoutData(data);
-		cacheTitle = new Label(this, SWT.NONE);
+		cacheTitle = new Label(this, SWT.WRAP);
 		data = new FormData();
 		data.left = new FormAttachment(cacheImage, 5);
 		data.right = new FormAttachment(100, -5);
trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/TableViewWidget.java to trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheTableView.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/TableViewWidget.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/widgets/swt/SWTCacheTableView.java
@@ -16,40 +16,99 @@
 package org.ocm.ui.widgets.swt;
 
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
 import org.eclipse.swt.custom.SashForm;
 import org.eclipse.swt.events.ControlEvent;
 import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.CoolItem;
 import org.ocm.core.cachestore.CacheTable;
+import org.ocm.core.cachestore.CacheTable.SortType;
+import org.ocm.core.geographic.Coordinate;
+import org.ocm.core.geographic.CoordinateFactory;
 import org.ocm.ui.widgets.CacheSelectionEvent;
 import org.ocm.ui.widgets.CacheTableItemSelectionListener;
-import org.ocm.ui.widgets.ViewWidget;
+import org.ocm.ui.widgets.CacheTableView;
 
 /**
  * @author ocm
  * 
  */
-public class TableViewWidget extends Composite implements ViewWidget {
+public class SWTCacheTableView extends Composite implements CacheTableView {
 
 	SashForm form;
-	CacheTableWidget tableWidget;
-	QuickInfoWidget infoWidget;
+	SWTCacheList tableWidget;
+	SWTQuickInfo infoWidget;
 	CacheTable table;
+	SWTMapWidget cacheMap;
+	CTabFolder tabFolder;
+	CTabItem listItem;
+	CTabItem mapItem;
+	Image mapIcon;
+	Image listIcon;
 	int parentWidth;
 	int infoWidth;
 	ControlListener paneListener;
-	private final int MIN_INFO_WIDTH = 250;
+	private final int MIN_INFO_WIDTH = 350;
+	
+	CoordinateFactory factory;
 
-	public TableViewWidget(Composite parent, int style) {
+	SWTCacheTableView(Composite parent, int style, CoordinateFactory factory) {
 		super(parent, style);
 		this.setLayout(new FillLayout());
+		this.factory = factory;
 		form = new SashForm(this, SWT.HORIZONTAL | SWT.SMOOTH);
-		infoWidget = new QuickInfoWidget(form, SWT.NONE);
+		infoWidget = new SWTQuickInfo(form, SWT.NONE);
 		infoWidth = MIN_INFO_WIDTH;
-		tableWidget = new CacheTableWidget(form, SWT.NONE);
 		parentWidth = parent.getBounds().width;
+		layoutTabs();
+		resetBounds();
+		handleFormResize();
+		handleLeftPaneResize();
+	}
+	
+	
+	@Override
+	public void setCacheTable(CacheTable table) {
+		this.table = table;
+		Coordinate coord = factory.create(45.375, -75.375);
+		table.setOrigin(coord);
+		table.sort(SortType.DISTANCE, CacheTable.SortOrder.ASC);
+		this.tableWidget.setTable(table);
+		this.cacheMap.setTable(table);
+	}
+
+	@Override
+	public CoolItem getViewToolBar() {
+		return null;
+	}
+	
+	@Override
+	public void dispose() {
+		// TODO Auto-generated method stub
+		super.dispose();
+	}
+	
+	private void layoutTabs(){
+		tabFolder = new CTabFolder(form, SWT.BORDER);
+		
+		mapIcon = new Image(getDisplay(), this.getClass().getResourceAsStream("/res/ic_action_mapmode.png"));
+		cacheMap = new SWTMapWidget(tabFolder, SWT.NONE, factory);
+		mapItem = new CTabItem(tabFolder, SWT.NONE);
+		mapItem.setText("Map");
+		mapItem.setControl(cacheMap);
+		mapItem.setImage(mapIcon);
+
+		listIcon = new Image(getDisplay(), this.getClass().getResourceAsStream("/res/ic_action_list.png"));
+		listItem = new CTabItem(tabFolder, SWT.NONE);
+		tableWidget = new SWTCacheList(tabFolder, SWT.NONE);		
+		listItem.setControl(tableWidget);
+		listItem.setText("List");
+		listItem.setImage(listIcon);
+		
 		tableWidget.addItemSelectionListener(new CacheTableItemSelectionListener() {
 
 			@Override
@@ -58,9 +117,8 @@
 				layout(true, true);
 			}
 		});
-		resetBounds();
-		handleFormResize();
-		handleLeftPaneResize();
+
+		tabFolder.setSelection(mapItem);
 	}
 
 	private void handleLeftPaneResize() {
@@ -117,32 +175,25 @@
 	}
 
 	private void resetBounds() {
+		if (isDisposed())
+			return;
 
 		getDisplay().asyncExec(new Runnable() {
 			@Override
 			public void run() {
-				if (form.getBounds().width <=0)
+				if (form.getBounds().width <= 0)
 					return;
 				// Calculate new ratio for sashes weights
 				double ratio = (double) MIN_INFO_WIDTH / form.getBounds().width;
 				double percent = ratio * 100;
 
 				final int percentRounded = (int) Math.floor(percent);
+				System.out.println(percentRounded);
 				form.setWeights(new int[] { percentRounded, 100 - percentRounded });
 				form.layout(true, true);
 			}
 		});
 	}
 
-	@Override
-	public void setCacheTable(CacheTable table) {
-		this.table = table;
-		this.tableWidget.setTable(table);
-	}
-
-	@Override
-	public CoolItem getViewToolBar() {
-		return null;
-	}
 
 }
trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheTableRenderer.java to trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheList.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheTableRenderer.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheList.java
@@ -22,7 +22,7 @@
  * @author ocm
  *
  */
-public interface CacheTableRenderer {
+public interface CacheList {
 	
 	/**
 	 * Registers an item selection listener
trunk/OCMDesktop/src/org/ocm/ui/widgets/QuickInfoRenderer.java to trunk/OCMDesktop/src/org/ocm/ui/widgets/QuickInfo.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/QuickInfoRenderer.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/widgets/QuickInfo.java
@@ -21,7 +21,7 @@
  * @author ocm
  * 
  */
-public interface QuickInfoRenderer {
+public interface QuickInfo {
 
 	void setCacheTableItem(CacheTableItem item);
 
trunk/OCMDesktop/src/org/ocm/ui/widgets/ViewWidget.java to trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheTableView.java
--- a/trunk/OCMDesktop/src/org/ocm/ui/widgets/ViewWidget.java
+++ b/trunk/OCMDesktop/src/org/ocm/ui/widgets/CacheTableView.java
@@ -22,7 +22,7 @@
  * @author ocm
  * 
  */
-public interface ViewWidget {
+public interface CacheTableView {
 
 	void setCacheTable(CacheTable table);
 
1 2 3 .. 7 > >> (Page 1 of 7)