瀏覽代碼

Using a card layout to manage which filter is displayed.

pull/2/head
veronie 4 年之前
父節點
當前提交
33b9237e81
共有 6 個文件被更改,包括 134 次插入151 次删除
  1. +1
    -0
      xyz.veronie.bgg.ui/META-INF/MANIFEST.MF
  2. +0
    -41
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java
  3. +13
    -21
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilterComposite.java
  4. +4
    -2
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilterComposite.java
  5. +4
    -2
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilterComposite.java
  6. +112
    -85
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/FetchPart.java

+ 1
- 0
xyz.veronie.bgg.ui/META-INF/MANIFEST.MF 查看文件

@@ -21,6 +21,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
javax.inject;version="1.0.0",
org.eclipse.e4.core.commands,
org.eclipse.e4.core.contexts;version="1.7.0",
org.eclipse.e4.ui.model.application.descriptor.basic,
org.eclipse.e4.ui.model.application.ui.basic
Automatic-Module-Name: de.wt.secondtry

+ 0
- 41
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java 查看文件

@@ -1,41 +0,0 @@
package xyz.veronie.bgg.ui.filters;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.core.services.events.IEventBroker;
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.ResultConfigManager;
import xyz.veronie.bgg.ui.filters.composites.BggUserSourceComposite;
import xyz.veronie.bgg.ui.helpers.BatLayouts;
/// These are the controls to retrieve thing IDs for a given BGG user
/// Filters can be set for the state of the thing in the user's collection
/// (i.e. owned, previously owned, wishlist, etc.)
@Creatable
public class BggUserSourceFilter {
@Inject private IEventBroker eventBroker;
@Inject private ResultConfigManager configManager;
public void create(Composite parent, int style) {
Composite mainCompo = new Composite(parent, SWT.FILL);
GridLayout gl_mainCompo = new GridLayout(5, false);
BatLayouts.applyZeroSpacing(gl_mainCompo);
mainCompo.setLayout(gl_mainCompo);
mainCompo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
new BggUserSourceComposite(mainCompo, SWT.NONE, eventBroker, configManager);
mainCompo.pack();
parent.pack();
parent.layout(true, true);
}
}

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/BggUserSourceComposite.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilterComposite.java 查看文件

@@ -1,8 +1,11 @@
package xyz.veronie.bgg.ui.filters.composites;
package xyz.veronie.bgg.ui.filters;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
@@ -23,22 +26,15 @@ import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.Subtype;
import xyz.veronie.bgg.types.UserFlag;
import xyz.veronie.bgg.ui.filters.composites.FilterFlagComposite;
public class BggUserSourceComposite extends Composite {
public class BggUserSourceFilterComposite {
private IEventBroker eventBroker;
/**
* Create the composite.
* @param parent
* @param style
*/
public BggUserSourceComposite(Composite parent, int style,
IEventBroker eventBroker, ResultConfigManager configManager)
{
super(parent, style);
this.eventBroker = eventBroker;
@Inject private IEventBroker eventBroker;
@Inject private ResultConfigManager configManager;
@PostConstruct
public void postConstruct(Composite parent) {
Composite main = new Composite(parent, SWT.FILL);
main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
main.setLayout(new GridLayout(1, false));
@@ -108,7 +104,8 @@ public class BggUserSourceComposite extends Composite {
new FilterFlagComposite(centerComposite, UserFlag.RATED, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.COMMENT, configManager, eventBroker);
this.pack();
parent.pack();
parent.layout(true, true);
}
@@ -128,9 +125,4 @@ public class BggUserSourceComposite extends Composite {
return subtypes;
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilter.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/FamilySourceFilterComposite.java 查看文件

@@ -3,6 +3,7 @@ package xyz.veronie.bgg.ui.filters;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Creatable;
@@ -34,14 +35,15 @@ import xyz.veronie.bgg.ui.helpers.BatLayouts;
/// These are the controls to retrieve thing IDs for a given family ID
@Creatable
public class FamilySourceFilter {
public class FamilySourceFilterComposite {
@Inject private IEventBroker eventBroker;
@Inject private ResultConfigManager configManager;
private StyledText confLabel;
private Combo cbFamilyId;
public void create(Composite parent, int style) {
@PostConstruct
public void postConstruct(Composite parent) {
Composite mainCompo = new Composite(parent, SWT.FILL);
GridLayout gl_mainCompo = new GridLayout(2, false);
BatLayouts.applyZeroSpacing(gl_mainCompo);

xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilter.java → xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/GeeklistSourceFilterComposite.java 查看文件

@@ -1,5 +1,6 @@
package xyz.veronie.bgg.ui.filters;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Creatable;
@@ -24,7 +25,7 @@ import xyz.veronie.bgg.ui.helpers.BatLayouts;
/// These are the controls to retrieve thing IDs for a given family ID
@Creatable
public class GeeklistSourceFilter {
public class GeeklistSourceFilterComposite {
@Inject private IEventBroker eventBroker;
@Inject private ResultConfigManager configManager;
@@ -32,7 +33,8 @@ public class GeeklistSourceFilter {
private StyledText confLabel;
private Combo cbGeeklistId;
public void create(Composite parent, int style) {
@PostConstruct
public void postConstruct(Composite parent) {
Composite mainCompo = new Composite(parent, SWT.FILL);
GridLayout gl_mainCompo = new GridLayout(2, false);
BatLayouts.applyZeroSpacing(gl_mainCompo);

+ 112
- 85
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/parts/FetchPart.java 查看文件

@@ -7,6 +7,9 @@ import java.util.List;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
@@ -15,13 +18,15 @@ import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
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.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;
@@ -33,9 +38,9 @@ import xyz.veronie.bgg.result.ThingProvider;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.ResultAction;
import xyz.veronie.bgg.types.SourceFilter;
import xyz.veronie.bgg.ui.filters.BggUserSourceFilter;
import xyz.veronie.bgg.ui.filters.FamilySourceFilter;
import xyz.veronie.bgg.ui.filters.GeeklistSourceFilter;
import xyz.veronie.bgg.ui.filters.BggUserSourceFilterComposite;
import xyz.veronie.bgg.ui.filters.FamilySourceFilterComposite;
import xyz.veronie.bgg.ui.filters.GeeklistSourceFilterComposite;
import xyz.veronie.bgg.ui.helpers.BatColors;
import xyz.veronie.bgg.ui.helpers.BatLayouts;
@@ -44,14 +49,12 @@ public class FetchPart {
@Inject
private ResultConfigManager configManager;
// inject all source filter composites
@Inject private BggUserSourceFilter bggUserSourceFilter;
@Inject private GeeklistSourceFilter geeklistSourceFilter;
@Inject private FamilySourceFilter familySourceFilter;
@Inject
private IEventBroker eventBroker;
@Inject
private IEclipseContext context;
@Inject
private MApplication application;
@@ -74,6 +77,16 @@ public class FetchPart {
private Composite main;
private Composite filterComposite;
private Composite userFilterPage;
private Composite familyPage;
private StackLayout filterLayout;
private Composite geeklistPage;
private Composite centerComposite;
@Inject
public FetchPart() {
@@ -106,47 +119,26 @@ public class FetchPart {
btnGeeklist = new Button(buttonRow, SWT.NONE);
btnGeeklist.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/noun_List_60x60.png"));
btnBggUser.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
selectFilter(SourceFilter.BGG_USER);
}
});
btnFamily.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
selectFilter(SourceFilter.FAMILY);
}
});
btnGeeklist.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
selectFilter(SourceFilter.GEEKLIST);
}
});
Composite centerComposite = new Composite(main, SWT.NONE);
centerComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));
centerComposite = new Composite(main, SWT.NONE);
centerComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
GridLayout gl_centerComposite = new GridLayout(1, false);
BatLayouts.applyStandardSpacing(gl_centerComposite);
centerComposite.setLayout(gl_centerComposite);
createFilterComposites(centerComposite);
filterComposite = new Composite(centerComposite, SWT.NONE);
filterComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
filterComposite.setBackgroundMode(SWT.INHERIT_FORCE);
filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
GridLayout gl_filterComposite = new GridLayout(1, false);
BatLayouts.applyStandardSpacing(gl_filterComposite);
filterComposite.setLayout(gl_filterComposite);
// init filter using config manager
SourceFilter source = configManager.getResultConfig().source;
selectSource(source);
createApplyToResultRow();
}
private void createApplyToResultRow() {
Composite applyComposite = new Composite(main, SWT.NONE);
GridLayout gl_applyComposite = new GridLayout(5, false);
BatLayouts.applyStandardSpacing(gl_applyComposite);
@@ -202,75 +194,110 @@ public class FetchPart {
fetchEntries(ResultAction.SUBTRACT);
}
});
// init filter using config manager
SourceFilter source = configManager.getResultConfig().source;
selectFilter(source);
showFilter(filterComposite, source);
}
private void selectFilter(SourceFilter source) {
configManager.getResultConfig().source = source;
private void createFilterComposites(Composite parent) {
filterComposite = new Composite(parent, SWT.NONE);
filterComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND));
filterComposite.setBackgroundMode(SWT.INHERIT_FORCE);
filterLayout = new StackLayout();
filterComposite.setLayout(filterLayout);
filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
userFilterPage = new Composite(filterComposite, SWT.FILL);
GridLayout gl_userFilter = new GridLayout(2, false);
BatLayouts.applyZeroSpacing(gl_userFilter);
userFilterPage.setLayout(gl_userFilter);
userFilterPage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
IEclipseContext userFilterCtx = EclipseContextFactory.create();
userFilterCtx.set(Composite.class, userFilterPage); // parent
ContextInjectionFactory.make(BggUserSourceFilterComposite.class, context, userFilterCtx);
btnBggUser.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
selectSource(SourceFilter.BGG_USER);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {}
});
familyPage = new Composite(filterComposite, SWT.FILL);
GridLayout gl_familyFilter = new GridLayout(2, false);
BatLayouts.applyZeroSpacing(gl_familyFilter);
familyPage.setLayout(gl_familyFilter);
familyPage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
IEclipseContext familyFilterCtx = EclipseContextFactory.create();
familyFilterCtx.set(Composite.class, familyPage); // parent
ContextInjectionFactory.make(FamilySourceFilterComposite.class, context, familyFilterCtx);;
btnFamily.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
selectSource(SourceFilter.FAMILY);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {}
});
geeklistPage = new Composite(filterComposite, SWT.FILL);
GridLayout gl_geeklistFilter = new GridLayout(2, false);
BatLayouts.applyZeroSpacing(gl_geeklistFilter);
geeklistPage.setLayout(gl_geeklistFilter);
geeklistPage.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
IEclipseContext geeklistFilterCtx = EclipseContextFactory.create();
geeklistFilterCtx.set(Composite.class, geeklistPage); // parent
ContextInjectionFactory.make(GeeklistSourceFilterComposite.class, context, geeklistFilterCtx);
btnGeeklist.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
selectSource(SourceFilter.GEEKLIST);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {}
});
}
private void selectSource(SourceFilter source) {
switch(source) {
default:
case BGG_USER:
btnBggUser.setFocus();
filterLayout.topControl = userFilterPage;
btnBggUser.setBackground(BatColors.getButtonBgColor());
btnFamily.setBackground(null);
btnGeeklist.setBackground(null);
break;
case FAMILY:
btnFamily.setFocus();
filterLayout.topControl = familyPage;
btnBggUser.setBackground(null);
btnFamily.setBackground(BatColors.getButtonBgColor());
btnGeeklist.setBackground(null);
break;
case GEEKLIST:
btnGeeklist.setFocus();
filterLayout.topControl = geeklistPage;
btnBggUser.setBackground(null);
btnFamily.setBackground(null);
btnGeeklist.setBackground(BatColors.getButtonBgColor());
break;
}
showFilter(filterComposite, source);
filterComposite.pack();
centerComposite.layout(true,true);
eventBroker.send(EventConstants.TOPIC_SOURCE_CHANGED, source);
}
/// show different filter controls depending on selection in cbSource ComboViewer
private void showFilter(Composite parent, SourceFilter source) {
// clean up
for(Control child : parent.getChildren()) {
child.dispose();
}
// create a new filter area based on selection:
switch(source) {
default:
case BGG_USER:
System.out.println("construct " + source);
bggUserSourceFilter.create(parent, SWT.FILL);
break;
case GEEKLIST:
System.out.println("construct " + source);
geeklistSourceFilter.create(parent, SWT.FILL);
break;
case FAMILY:
System.out.println("construct " + source);
familySourceFilter.create(parent, SWT.FILL);
break;
}
main.pack();
main.layout(true, true);
}
private void fetchEntries(ResultAction action) {
Object fetchId = getFetchId();
if(fetchId == null) return;


Loading…
取消
儲存