From e9d2fe08436f36fb780ca323c0b7aa67cd60065a Mon Sep 17 00:00:00 2001 From: veronie Date: Thu, 14 Jan 2021 15:56:07 +0100 Subject: [PATCH] Display of images works now. Started to work on detailed view. Need sqlite driver (maven? gradle? bnd?) --- xyz.veronie.bgg.ui/Application.e4xmi | 12 +- .../bgg/localdb/LocalDbAdapterService.java | 7 +- .../veronie/bgg/localdb/SqliteController.java | 52 ++++++--- .../src/xyz/veronie/bgg/result/Thing.java | 6 +- .../bgg/result/ThingDetailsComposite.java | 74 ++++++++++++ .../xyz/veronie/bgg/types/EventConstants.java | 2 + .../xyz/veronie/bgg/ui/helpers/Resources.java | 14 +-- .../veronie/bgg/ui/parts/BggResultPart.java | 73 +++++++++--- .../ui/parts/DownloadThingDetailsPart.java | 106 +----------------- .../veronie/bgg/ui/parts/ThingListPart.java | 33 ++++++ 10 files changed, 223 insertions(+), 156 deletions(-) create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java diff --git a/xyz.veronie.bgg.ui/Application.e4xmi b/xyz.veronie.bgg.ui/Application.e4xmi index 4ee48d0..389a6e9 100644 --- a/xyz.veronie.bgg.ui/Application.e4xmi +++ b/xyz.veronie.bgg.ui/Application.e4xmi @@ -7,6 +7,11 @@ + + + + + @@ -15,12 +20,7 @@ - - - - - - + diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/LocalDbAdapterService.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/LocalDbAdapterService.java index acf4692..c19c1dd 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/LocalDbAdapterService.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/LocalDbAdapterService.java @@ -15,11 +15,12 @@ public class LocalDbAdapterService { } private void initDb() { - File dbFile = new File(SqliteController.DB_PATH); + sqliteController = SqliteController.getInstance(); + + File dbFile = sqliteController.getDbPath().toFile(); if(!dbFile.exists()) { - SqliteController.getInstance().createSchema(); + sqliteController.createSchema(); } - sqliteController = SqliteController.getInstance(); } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java index eee89ad..0cf80ab 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/localdb/SqliteController.java @@ -1,5 +1,8 @@ package xyz.veronie.bgg.localdb; +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -10,12 +13,13 @@ import java.util.List; import xyz.veronie.bgg.result.Thing; import xyz.veronie.bgg.result.ThingMetaData; +import xyz.veronie.bgg.ui.helpers.Resources; public class SqliteController { private static final SqliteController dbcontroller = new SqliteController(); private static Connection connection; - public static final String DB_PATH = System.getProperty("user.home") + "/" + "bggtool.db"; + private String dbPath; static { try { @@ -26,7 +30,12 @@ public class SqliteController { } } + public Path getDbPath() { + return Paths.get(dbPath); + } + private SqliteController() { + dbPath = Resources.INSTANCE.getTmpDir() + File.separator + "bggtool.db"; initDBConnection(); } @@ -39,12 +48,12 @@ public class SqliteController { if (connection != null) return; System.out.println("Creating Connection to Database..."); - String filename = System.getProperty("user.home") + "/bggtool.db"; - connection = DriverManager.getConnection("jdbc:sqlite:" + filename); + connection = DriverManager.getConnection("jdbc:sqlite:" + dbPath); if (!connection.isClosed()) System.out.println("...Connection established"); } catch (SQLException e) { - throw new RuntimeException(e); + // throw new RuntimeException(e); + System.out.println("Could not init local DB."); } Runtime.getRuntime().addShutdownHook(new Thread() { @@ -64,17 +73,20 @@ public class SqliteController { public void createSchema() { try { - Statement stmt = connection.createStatement(); - stmt.executeUpdate("DROP TABLE IF EXISTS Thing;"); - stmt.executeUpdate("DROP TABLE IF EXISTS ThingList"); - stmt.executeUpdate("DROP TABLE IF EXISTS ThingListToThing"); - - stmt.executeUpdate("CREATE TABLE Thing (ThingId INTEGER PRIMARY KEY, Name, ImgUrl, ThumbUrl, Comment, NumPlays);"); - stmt.executeUpdate("CREATE TABLE ThingList (ListId INTEGER PRIMARY KEY, Name) ON DELETE CASCADE;"); - stmt.executeUpdate("CREATE UNIQUE INDEX idx1 ON ThingList(Name)"); - stmt.executeUpdate("CREATE TABLE ThingListToThing (ListId, ThingId, FOREIGN KEY (ListId) REFERENCES ThingList(ListId), FOREIGN KEY (ThingId) REFERENCES Thing(ThingId));"); - stmt.executeUpdate("CREATE UNIQUE INDEX idx2 ON ThingListToThing(ListId, ThingId)"); - + if(connection != null) { + Statement stmt = connection.createStatement(); + stmt.executeUpdate("DROP TABLE IF EXISTS Thing;"); + stmt.executeUpdate("DROP TABLE IF EXISTS ThingList"); + stmt.executeUpdate("DROP TABLE IF EXISTS ThingListToThing"); + + stmt.executeUpdate("CREATE TABLE Thing (ThingId INTEGER PRIMARY KEY, Name, ImgUrl, ThumbUrl, Comment, NumPlays);"); + stmt.executeUpdate("CREATE TABLE ThingList (ListId INTEGER PRIMARY KEY, Name) ON DELETE CASCADE;"); + stmt.executeUpdate("CREATE UNIQUE INDEX idx1 ON ThingList(Name)"); + stmt.executeUpdate("CREATE TABLE ThingListToThing (ListId, ThingId, FOREIGN KEY (ListId) REFERENCES ThingList(ListId), FOREIGN KEY (ThingId) REFERENCES Thing(ThingId));"); + stmt.executeUpdate("CREATE UNIQUE INDEX idx2 ON ThingListToThing(ListId, ThingId)"); + } else { + System.err.println("ERROR: Couldn't create Schema, connection is null."); + } } catch (SQLException e) { System.err.println("Couldn't create Schema"); e.printStackTrace(); @@ -82,6 +94,11 @@ public class SqliteController { } public void openThingList(String name) { + if(connection == null) { + System.err.println("ERROR: Couldn't create Schema, connection is null."); + return; + } + try { Statement stmt = connection.createStatement(); // insert new thing list if one with that name does not exist already @@ -93,6 +110,11 @@ public class SqliteController { } public void addToThingList(String name, List things) { + if(connection == null) { + System.err.println("ERROR: Couldn't create Schema, connection is null."); + return; + } + try { Statement stmt = connection.createStatement(); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java index 5f16a45..b809827 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/Thing.java @@ -14,7 +14,6 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.ImageLoader; -import xyz.veronie.bgg.ui.helpers.Constants; import xyz.veronie.bgg.ui.helpers.Resources; public class Thing { @@ -68,11 +67,12 @@ public class Thing { Path tmpDir = Resources.INSTANCE.getTmpDir(); if(tmpDir != null) { Path imageFile = Paths.get(Resources.INSTANCE.getThumbsDir().toString() - + File.separator + String.valueOf(thingId)); + + File.separator + String.valueOf(thingId) + ".png"); if(Files.exists(imageFile, LinkOption.NOFOLLOW_LINKS)) { + String filename = imageFile.toString().replace("\\","/"); thumbImage = Resources.INSTANCE.getResourceManager().createImage( - ImageDescriptor.createFromFile(Thing.class, imageFile.toString())); + ImageDescriptor.createFromFile(null, filename)); } else { try { ImageDescriptor descriptor = ImageDescriptor.createFromURL( diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java new file mode 100644 index 0000000..8762ba7 --- /dev/null +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/result/ThingDetailsComposite.java @@ -0,0 +1,74 @@ +package xyz.veronie.bgg.result; + +import java.awt.Label; + +import javax.annotation.PostConstruct; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + +public class ThingDetailsComposite extends Composite { + ThingDetails thingDetails; + private Label nameField; + private Label designerField; + private Label publisherField; + private Label yearField; + + public ThingDetailsComposite(Composite parent, int style) { + super(parent, style); + } + + @PostConstruct + public void create() { + setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + + GridLayout layout = new GridLayout(2, false); + setLayout(layout); + + Label nameLbl = new Label("Name"); + applyLayout(nameLbl); + nameField = new Label(""); + + Label designerLbl = new Label("Designer"); + applyLayout(designerLbl); + designerField = new Label(""); + + Label publisherLbl = new Label("Publisher"); + applyLayout(publisherLbl); + publisherField = new Label(""); + + Label yearLbl = new Label("Publisher"); + applyLayout(yearLbl); + yearField = new Label(""); + + this.getParent().layout(); + } + + + private void applyLayout(Label label) { + label.setAlignment(SWT.RIGHT); + } + + public void selectedThingChanged(Thing thing) { + System.out.println("TOPIC_THING_SELECTION: " + thing); + thingDetails = thing.getDetails(); + + if(thingDetails != null) { + nameField.setText(thingDetails.name); + designerField.setText(thingDetails.designer); + publisherField.setText(thingDetails.publisher); + yearField.setText(Integer.toString(thingDetails.yearpublished)); + } else { + nameField.setText(""); + designerField.setText(""); + publisherField.setText(""); + yearField.setText(""); + + } + this.getParent().layout(); + } + + +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java index 5a206a3..a6c3279 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/types/EventConstants.java @@ -29,6 +29,8 @@ public interface EventConstants { String TOPIC_FAMILY_INFO = "INFO/FAMILY"; String TOPIC_TAG_RESULT = "EVENT_TAG_RESULT"; + + String TOPIC_THING_SELECTION = "SELECTION_CHANGED"; } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/Resources.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/Resources.java index 1c686a8..f27df36 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/Resources.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/helpers/Resources.java @@ -12,23 +12,15 @@ import org.eclipse.jface.resource.LocalResourceManager; public enum Resources { INSTANCE; - private Path prefixPath; private Path tmpDir; private LocalResourceManager resourceManager; private Resources() { try { - if(prefixPath == null) { - tmpDir = Paths.get(Constants.TMP_PREFIX); - if(!Files.exists(tmpDir)) { - Files.createDirectory(tmpDir); - } - } else { - tmpDir = Paths.get(prefixPath + File.separator + Constants.TMP_PREFIX); - if(!Files.exists(tmpDir)) { - Files.createDirectory(tmpDir); - } + tmpDir = Paths.get(System.getProperty("user.home") + File.separator + Paths.get(Constants.TMP_PREFIX)); + if(!Files.exists(tmpDir)) { + Files.createDirectory(tmpDir); } Path thumbPath = getThumbsDir(); if(!Files.exists(thumbPath)) { diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java index a3bf60b..22717da 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/BggResultPart.java @@ -6,24 +6,61 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.ui.di.UIEventTopic; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.OwnerDrawLabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TableViewerColumn; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + import xyz.veronie.bgg.result.Thing; import xyz.veronie.bgg.result.ThingProvider; import xyz.veronie.bgg.types.EventConstants; +abstract class CenterImageLabelProvider extends OwnerDrawLabelProvider { + + protected void measure(Event event, Object element) { + } + + protected void paint(Event event, Object element) { + + Image img = getImage(element); + + if (img != null) { + Rectangle bounds = ((TableItem) event.item).getBounds(event.index); + Rectangle imgBounds = img.getBounds(); + bounds.width /= 2; + bounds.width -= imgBounds.width / 2; + bounds.height /= 2; + bounds.height -= imgBounds.height / 2; + + int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x; + int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y; + + event.gc.drawImage(img, x, y); + } + } + + protected abstract Image getImage(Object element); + +}; + public class BggResultPart { private TableViewer viewer; private Label statsLabel; @@ -31,6 +68,9 @@ public class BggResultPart { @Inject private ThingProvider thingProvider; + @Inject + private IEventBroker eventBroker; + @PostConstruct public void createControls(Composite parent) { Composite main = new Composite(parent, SWT.FILL); @@ -44,10 +84,6 @@ public class BggResultPart { statsLabel = new Label(main, SWT.FILL); statsLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); statsLabel.setText("0 items"); - - - - } @@ -75,16 +111,27 @@ public class BggResultPart { gridData.horizontalAlignment = GridData.FILL; gridData.horizontalSpan = 2; viewer.getControl().setLayoutData(gridData); + + viewer.addSelectionChangedListener(new ISelectionChangedListener() { + @Override + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = viewer.getStructuredSelection(); + Thing thing = (Thing)selection.getFirstElement(); + eventBroker.send(EventConstants.TOPIC_THING_SELECTION, thing); + } + }); } public TableViewer getViewer() { return viewer; } + // This will create the columns for the table private void createColumns(final Composite parent, final TableViewer viewer) { - TableViewerColumn col = createTableViewerColumn(Thing.IdHeader, 100, 0); + // https://stackoverflow.com/questions/12641354/putting-an-image-in-to-a-jface-table-cell-is-causing-gap-for-image-to-appear-in + TableViewerColumn col = createTableViewerColumn(Thing.IdHeader, 250, 0); col.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { @@ -93,17 +140,13 @@ public class BggResultPart { } }); - TableViewerColumn col2 = createTableViewerColumn(Thing.ThumbHeader, 50, 1); + TableViewerColumn col2 = createTableViewerColumn(Thing.ThumbHeader, 150, 1); col2.setLabelProvider(new ColumnLabelProvider() { @Override public Image getImage(Object element) { Thing t = (Thing) element; Image img = t.getThumbnail(); - if(img != null) { - return img; - } else { - return null; - } + return img; } @Override @@ -129,9 +172,11 @@ public class BggResultPart { final TableColumn column = viewerColumn.getColumn(); column.setText(title); column.setWidth(bound); + column.setAlignment(SWT.LEFT); column.setResizable(true); column.setMoveable(true); column.setData(colNumber); + return viewerColumn; } @@ -153,8 +198,10 @@ public class BggResultPart { List things = thingProvider.getThings(); viewer.setInput(things); viewer.refresh(true); - statsLabel.setText(Integer.toString(things.size()) + " items"); - statsLabel.redraw(); + if(things != null) { + statsLabel.setText(Integer.toString(things.size()) + " items"); + statsLabel.redraw(); + } } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java index 2786107..4006848 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/DownloadThingDetailsPart.java @@ -9,7 +9,6 @@ import org.eclipse.core.runtime.jobs.ProgressProvider; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -24,8 +23,6 @@ import xyz.veronie.bgg.ui.result.DownloadProgressMonitor; public class DownloadThingDetailsPart { private DownloadProgressMonitor monitor; - private Button extendedInfoCheck; - private Button downloadAllPlaysCheck; @PostConstruct public void createControls(Composite parent) { @@ -89,107 +86,6 @@ public class DownloadThingDetailsPart { imagesLbl.setText("Images"); ComboViewer imagesCombo = new ComboViewer(optionsGroup); CommonControls.makeEmptySpace(optionsGroup, 1); - - - -// Button onlyNewCheck = new Button(optionsGroup, SWT.CHECK); -// onlyNewCheck.setText("Only new"); -// -// Button usePersNamesCheck = new Button(optionsGroup, SWT.CHECK); -// usePersNamesCheck.setText("Use pers. names"); -// usePersNamesCheck.setEnabled(false); -// -// Button only1DesignerCheck = new Button(optionsGroup, SWT.CHECK); -// only1DesignerCheck.setText("Only one designer"); -// only1DesignerCheck.setEnabled(false); -// -// -// Button withDescCheck = new Button(optionsGroup, SWT.CHECK); -// withDescCheck.setText("With description"); -// -// Button usePersImagesCheck = new Button(optionsGroup, SWT.CHECK); -// usePersImagesCheck.setText("Use pers. images"); -// usePersImagesCheck.setEnabled(false); -// -// Button only1PublisherCheck = new Button(optionsGroup, SWT.CHECK); -// only1PublisherCheck.setText("Only one publisher"); -// only1PublisherCheck.setEnabled(false); -// -// -// Button limitDescCheck = new Button(optionsGroup, SWT.CHECK); -// limitDescCheck.setText("Limit description"); -// -// Button useRecBestInfoCheck = new Button(optionsGroup, SWT.CHECK); -// useRecBestInfoCheck.setText("Use rec./best info"); -// useRecBestInfoCheck.setEnabled(false); -// -// Button only1ArtistCheck = new Button(optionsGroup, SWT.CHECK); -// only1ArtistCheck.setText("Only one artist"); -// only1ArtistCheck.setEnabled(false); -// -// -// -// Button downloadVotesCheck = new Button(optionsGroup, SWT.CHECK); -// downloadVotesCheck.setText("Download votes"); -// downloadVotesCheck.setEnabled(false); -// downloadVotesCheck.addSelectionListener(new SelectionAdapter() { -// @Override -// public void widgetSelected(SelectionEvent e) { -// extendedInfoCheck.setEnabled(true); -// } -// }); -// -// Button brnDetailCheck = new Button(optionsGroup, SWT.CHECK); -// brnDetailCheck.setText("B/R/N detail"); -// brnDetailCheck.setEnabled(false); -// -// Button reloadDataCheck = new Button(optionsGroup, SWT.CHECK); -// reloadDataCheck.setText("Reload data"); -// reloadDataCheck.setEnabled(false); -// -// -// -// extendedInfoCheck = new Button(optionsGroup, SWT.CHECK); -// extendedInfoCheck.setText(" Extended info"); -// extendedInfoCheck.setEnabled(false); // enabled when download votes is checked -// -// Button downloadPlaysCheck = new Button(optionsGroup, SWT.CHECK); -// downloadPlaysCheck.setText("Download plays"); -// downloadPlaysCheck.setEnabled(false); -// downloadPlaysCheck.addSelectionListener(new SelectionAdapter() { -// @Override -// public void widgetSelected(SelectionEvent e) { -// downloadAllPlaysCheck.setEnabled(true); -// } -// }); -// -// Button reloadImagesCheck = new Button(optionsGroup, SWT.CHECK); -// reloadImagesCheck.setText("Reload images"); -// reloadImagesCheck.setEnabled(false); -// -// -// -// Button downloadLangCheck = new Button(optionsGroup, SWT.CHECK); -// downloadLangCheck.setText("Download lang."); -// downloadLangCheck.setEnabled(false); -// -// downloadAllPlaysCheck = new Button(optionsGroup, SWT.CHECK); -// downloadAllPlaysCheck.setText(" Download plays (all)"); -// downloadAllPlaysCheck.setEnabled(false); // enabled when download plays checked -// -// Button ReloadQRCodesCheck = new Button(optionsGroup, SWT.CHECK); -// ReloadQRCodesCheck.setText("Reload QR codes"); -// ReloadQRCodesCheck.setEnabled(false); -// -// -// Button namesImgCheck = new Button(optionsGroup, SWT.CHECK); -// namesImgCheck.setText("Names in images"); -// namesImgCheck.setEnabled(false); -// -// Button useQrCodesCheck = new Button(optionsGroup, SWT.CHECK); -// useQrCodesCheck.setText("Use QR codes"); -// useQrCodesCheck.setEnabled(false); - } private void createRunNanDeckControls(Composite compo) { @@ -203,7 +99,7 @@ public class DownloadThingDetailsPart { private void createLoadGamesControls(Composite compo) { Button loadGamesBtn = new Button(compo, SWT.LEFT); - loadGamesBtn.setText("Load games"); + loadGamesBtn.setText("Download details"); loadGamesBtn.addSelectionListener(new SelectionAdapter() { }); diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java index 60523b6..c2a2cb8 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/ThingListPart.java @@ -1,5 +1,38 @@ package xyz.veronie.bgg.ui.parts; +import javax.annotation.PostConstruct; +import javax.inject.Inject; + +import org.eclipse.e4.core.di.annotations.Optional; +import org.eclipse.e4.ui.di.UIEventTopic; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; + +import xyz.veronie.bgg.result.Thing; +import xyz.veronie.bgg.result.ThingDetailsComposite; +import xyz.veronie.bgg.types.EventConstants; + public class ThingListPart { + private ThingDetailsComposite thingDetailsComposite; + + @PostConstruct + public void createControls(Composite parent) { + Composite main = new Composite(parent, SWT.FILL); + main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + + GridLayout layout = new GridLayout(2, false); + main.setLayout(layout); + + thingDetailsComposite = new ThingDetailsComposite(main, SWT.BORDER); + } + + @Inject + @Optional + private void selectedThingChanged(@UIEventTopic(EventConstants.TOPIC_THING_SELECTION) Thing thing) { + thingDetailsComposite.selectedThingChanged(thing); + } + }