work in progress. New command 'load', new LoadGameListDialog, new HandleLoadGamelist.pull/14/head
| @@ -16,7 +16,9 @@ | |||||
| </trimBars> | </trimBars> | ||||
| </children> | </children> | ||||
| <handlers xmi:id="_a0tuEGAUEeuNUoCJDLJTzQ" elementId="xyz.veronie.bgg.ui.handler.save" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.HandleSaveGamelist" command="_lA5t8F9TEeuvNqpgCDWpdQ"/> | <handlers xmi:id="_a0tuEGAUEeuNUoCJDLJTzQ" elementId="xyz.veronie.bgg.ui.handler.save" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.HandleSaveGamelist" command="_lA5t8F9TEeuvNqpgCDWpdQ"/> | ||||
| <handlers xmi:id="_xJXjUG3zEeuCP7xCflu8WA" elementId="xyz.veronie.bgg.ui.handler.load" contributionURI="bundleclass://xyz.veronie.bgg.ui/xyz.veronie.bgg.ui.handlers.HandleLoadGamelist" command="_qyrHAG3zEeuCP7xCflu8WA"/> | |||||
| <commands xmi:id="_lA5t8F9TEeuvNqpgCDWpdQ" elementId="xyz.veronie.bgg.ui.command.save" commandName="Save" description="save game list"/> | <commands xmi:id="_lA5t8F9TEeuvNqpgCDWpdQ" elementId="xyz.veronie.bgg.ui.command.save" commandName="Save" description="save game list"/> | ||||
| <commands xmi:id="_qyrHAG3zEeuCP7xCflu8WA" elementId="xyz.veronie.bgg.ui.command.load" commandName="Load" description="load game list"/> | |||||
| <addons xmi:id="_Lw_ZsUqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/> | <addons xmi:id="_Lw_ZsUqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/> | ||||
| <addons xmi:id="_Lw_ZskqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/> | <addons xmi:id="_Lw_ZskqSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/> | ||||
| <addons xmi:id="_Lw_Zs0qSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/> | <addons xmi:id="_Lw_Zs0qSEeqT5sxfmvJ5Tg" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/> | ||||
| @@ -1,11 +1,9 @@ | |||||
| package xyz.veronie.bgg.localdb; | package xyz.veronie.bgg.localdb; | ||||
| import java.sql.SQLException; | import java.sql.SQLException; | ||||
| import java.util.ArrayList; | |||||
| import java.util.List; | import java.util.List; | ||||
| import xyz.veronie.bgg.result.Thing; | import xyz.veronie.bgg.result.Thing; | ||||
| import xyz.veronie.bgg.result.ThingMetaData; | |||||
| public class LocalDbAdapterService { | public class LocalDbAdapterService { | ||||
| private SqliteController sqliteController; | private SqliteController sqliteController; | ||||
| @@ -28,10 +26,11 @@ public class LocalDbAdapterService { | |||||
| sqliteController.addToThingList(name, things); | sqliteController.addToThingList(name, things); | ||||
| } | } | ||||
| /// retrieve a list of things with the given name | |||||
| public List<ThingMetaData> retrieveThingList(String name) { | |||||
| // TODO: implement retrieve thing list | |||||
| return new ArrayList<ThingMetaData>(); | |||||
| public List<Thing> loadThingList(String name) throws SQLException { | |||||
| if(sqliteController.hasThingList(name)) { | |||||
| return sqliteController.getThingList(name); | |||||
| } | |||||
| return null; | |||||
| } | } | ||||
| @@ -203,5 +203,10 @@ public class SqliteController { | |||||
| } | } | ||||
| public List<Thing> getThingList(String name) { | |||||
| // TODO: implement this | |||||
| return null; | |||||
| } | |||||
| } | } | ||||
| @@ -92,6 +92,12 @@ public class ThingProvider { | |||||
| localDbAdapterService.storeThingList(this.things, listName); | localDbAdapterService.storeThingList(this.things, listName); | ||||
| } | } | ||||
| public void loadList(String name) throws SQLException { | |||||
| // TODO: handle unsaved current list | |||||
| this.things = localDbAdapterService.loadThingList(name); | |||||
| } | |||||
| public int numberOfThings() { | public int numberOfThings() { | ||||
| return things.size(); | return things.size(); | ||||
| } | } | ||||
| @@ -101,5 +107,6 @@ public class ThingProvider { | |||||
| return things; | return things; | ||||
| } | } | ||||
| } | } | ||||
| @@ -32,4 +32,6 @@ public interface EventConstants { | |||||
| String TOPIC_THINGS_SAVED = "THINGS_SAVED"; | String TOPIC_THINGS_SAVED = "THINGS_SAVED"; | ||||
| String TOPIC_THINGS_LOADED = "THINGS_LOADED"; | |||||
| } | } | ||||
| @@ -0,0 +1,89 @@ | |||||
| package xyz.veronie.bgg.ui.dialogs; | |||||
| import org.eclipse.jface.dialogs.Dialog; | |||||
| import org.eclipse.jface.dialogs.IDialogConstants; | |||||
| import org.eclipse.swt.SWT; | |||||
| import org.eclipse.swt.graphics.Point; | |||||
| import org.eclipse.swt.layout.GridLayout; | |||||
| import org.eclipse.swt.widgets.Button; | |||||
| import org.eclipse.swt.widgets.Composite; | |||||
| import org.eclipse.swt.widgets.Control; | |||||
| import org.eclipse.swt.widgets.Label; | |||||
| import org.eclipse.swt.widgets.Shell; | |||||
| import org.eclipse.wb.swt.SWTResourceManager; | |||||
| import xyz.veronie.bgg.ui.helpers.BatColors; | |||||
| public class LoadGameListDialog extends Dialog { | |||||
| private Button btnOk; | |||||
| private String selectedName; | |||||
| /** | |||||
| * Create the dialog. | |||||
| * @param parentShell | |||||
| */ | |||||
| public LoadGameListDialog(Shell parentShell) { | |||||
| super(parentShell); | |||||
| setShellStyle(SWT.APPLICATION_MODAL); | |||||
| } | |||||
| /** | |||||
| * Create contents of the dialog. | |||||
| * @param parent | |||||
| */ | |||||
| @Override | |||||
| protected Control createDialogArea(Composite parent) { | |||||
| parent.setBackground(BatColors.getBackgroundColor()); | |||||
| Composite container = (Composite) super.createDialogArea(parent); | |||||
| container.setFont(SWTResourceManager.getFont("Segoe UI", 11, SWT.NORMAL)); | |||||
| container.setBackground(BatColors.getBackgroundColor()); | |||||
| GridLayout gl_container = new GridLayout(1, false); | |||||
| gl_container.verticalSpacing = 24; | |||||
| gl_container.marginWidth = 24; | |||||
| gl_container.marginTop = 24; | |||||
| gl_container.marginRight = 24; | |||||
| gl_container.marginLeft = 24; | |||||
| gl_container.marginHeight = 24; | |||||
| gl_container.marginBottom = 24; | |||||
| gl_container.horizontalSpacing = 24; | |||||
| container.setLayout(gl_container); | |||||
| Label lblEnterAName = new Label(container, SWT.NONE); | |||||
| lblEnterAName.setFont(SWTResourceManager.getFont("Segoe UI", 11, SWT.NORMAL)); | |||||
| lblEnterAName.setText("Select a game list:"); | |||||
| // textField.setFont(SWTResourceManager.getFont("Segoe UI", 11, SWT.NORMAL)); | |||||
| // textField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); | |||||
| return container; | |||||
| } | |||||
| /** | |||||
| * Create contents of the button bar. | |||||
| * @param parent | |||||
| */ | |||||
| @Override | |||||
| protected void createButtonsForButtonBar(Composite parent) { | |||||
| parent.setBackground(BatColors.getBackgroundColor()); | |||||
| btnOk = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); | |||||
| btnOk.setEnabled(false); | |||||
| createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); | |||||
| } | |||||
| /** | |||||
| * Return the initial size of the dialog. | |||||
| */ | |||||
| @Override | |||||
| protected Point getInitialSize() { | |||||
| return new Point(450, 300); | |||||
| } | |||||
| public String getSelectedName() { | |||||
| return selectedName; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,51 @@ | |||||
| package xyz.veronie.bgg.ui.handlers; | |||||
| import javax.inject.Inject; | |||||
| import org.eclipse.e4.core.di.annotations.CanExecute; | |||||
| import org.eclipse.e4.core.di.annotations.Execute; | |||||
| import org.eclipse.e4.core.services.events.IEventBroker; | |||||
| import org.eclipse.jface.dialogs.Dialog; | |||||
| import org.eclipse.swt.SWT; | |||||
| import org.eclipse.swt.widgets.MessageBox; | |||||
| import org.eclipse.swt.widgets.Shell; | |||||
| import xyz.veronie.bgg.result.ThingProvider; | |||||
| import xyz.veronie.bgg.types.EventConstants; | |||||
| import xyz.veronie.bgg.ui.dialogs.LoadGameListDialog; | |||||
| public class HandleLoadGamelist { | |||||
| @Inject | |||||
| ThingProvider thingProvider; | |||||
| @Execute | |||||
| public void execute(Shell shell, IEventBroker eventBroker) { | |||||
| LoadGameListDialog loadDialog = new LoadGameListDialog(shell); | |||||
| loadDialog.open(); | |||||
| int returnCode = loadDialog.getReturnCode(); | |||||
| if(returnCode == Dialog.OK) { | |||||
| String name = loadDialog.getSelectedName(); | |||||
| try { | |||||
| thingProvider.loadList(name); | |||||
| eventBroker.post(EventConstants.TOPIC_THINGS_LOADED, name); | |||||
| } | |||||
| catch (Exception e) { | |||||
| MessageBox msgBox = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK); | |||||
| msgBox.setMessage("Could not load game list."); | |||||
| msgBox.open(); | |||||
| e.printStackTrace(); | |||||
| } | |||||
| } | |||||
| } | |||||
| @CanExecute | |||||
| public boolean canExecute() { | |||||
| return thingProvider != null; | |||||
| } | |||||
| } | |||||
| @@ -46,7 +46,8 @@ import xyz.veronie.bgg.ui.helpers.BatLayouts; | |||||
| // TODO: load thing list from DB | // TODO: load thing list from DB | ||||
| // TODO: image sizes | |||||
| // TODO: import result.txt from bggtool | |||||
| // TODO: image sizes in result table | |||||
| // TODO: display current thinglist name | // TODO: display current thinglist name | ||||
| // TODO: fetch details from BGG | // TODO: fetch details from BGG | ||||
| // TODO: export to results.txt format | // TODO: export to results.txt format | ||||
| @@ -132,9 +133,21 @@ public class BatMain { | |||||
| btnSave.setEnabled(false); | btnSave.setEnabled(false); | ||||
| Button btnLoad = new Button(buttonRow, SWT.NONE); | Button btnLoad = new Button(buttonRow, SWT.NONE); | ||||
| btnLoad.addMouseListener(new MouseAdapter() { | |||||
| @Override | |||||
| public void mouseUp(MouseEvent e) { | |||||
| ParameterizedCommand cmd = | |||||
| commandService.createCommand("xyz.veronie.bgg.ui.command.load", null); | |||||
| if (handlerService.canExecute(cmd)){ | |||||
| handlerService.executeHandler(cmd); | |||||
| } | |||||
| } | |||||
| }); | |||||
| btnLoad.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/noun_open_60x60.png")); | btnLoad.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/noun_open_60x60.png")); | ||||
| btnLoad.setToolTipText("Load list of games"); | btnLoad.setToolTipText("Load list of games"); | ||||
| btnUndo = new Button(buttonRow, SWT.NONE); | btnUndo = new Button(buttonRow, SWT.NONE); | ||||
| btnUndo.setToolTipText("Undo game list operation"); | btnUndo.setToolTipText("Undo game list operation"); | ||||
| btnUndo.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/noun_Undo_60x60.png")); | btnUndo.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/noun_Undo_60x60.png")); | ||||