소스 검색

Layouting of BggUserSourceFilter

pull/2/head
veronie 4 년 전
부모
커밋
f1b7fdc822
5개의 변경된 파일268개의 추가작업 그리고 166개의 파일을 삭제
  1. BIN
      xyz.veronie.bgg.ui/icons/noun_switch off_30x30.png
  2. BIN
      xyz.veronie.bgg.ui/icons/noun_switch on_30x30.png
  3. +2
    -166
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java
  4. +136
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/BggUserSourceComposite.java
  5. +130
    -0
      xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/FilterFlagComposite.java

BIN
xyz.veronie.bgg.ui/icons/noun_switch off_30x30.png 파일 보기

Before After
Width: 30  |  Height: 30  |  Size: 1.7KB

BIN
xyz.veronie.bgg.ui/icons/noun_switch on_30x30.png 파일 보기

Before After
Width: 30  |  Height: 30  |  Size: 1.7KB

+ 2
- 166
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java 파일 보기

@@ -1,38 +1,17 @@
package xyz.veronie.bgg.ui.filters; package xyz.veronie.bgg.ui.filters;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Creatable; import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.core.services.events.IEventBroker; import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import xyz.veronie.bgg.result.ResultConfigManager; import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.FilterFlagState;
import xyz.veronie.bgg.types.Subtype;
import xyz.veronie.bgg.types.UserFlag;
import xyz.veronie.bgg.types.UserFlagEvent;
import xyz.veronie.bgg.ui.filters.composites.BggUserSourceComposite;
import xyz.veronie.bgg.ui.helpers.BatLayouts; import xyz.veronie.bgg.ui.helpers.BatLayouts;
import xyz.veronie.bgg.ui.helpers.CommonControls;
/// These are the controls to retrieve thing IDs for a given BGG user /// These are the controls to retrieve thing IDs for a given BGG user
@@ -44,8 +23,6 @@ public class BggUserSourceFilter {
@Inject private IEventBroker eventBroker; @Inject private IEventBroker eventBroker;
@Inject private ResultConfigManager configManager; @Inject private ResultConfigManager configManager;
private Combo cbUserName;
public void create(Composite parent, int style) { public void create(Composite parent, int style) {
Composite mainCompo = new Composite(parent, SWT.FILL); Composite mainCompo = new Composite(parent, SWT.FILL);
@@ -54,152 +31,11 @@ public class BggUserSourceFilter {
mainCompo.setLayout(gl_mainCompo); mainCompo.setLayout(gl_mainCompo);
mainCompo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); mainCompo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Label lblUser = new Label(mainCompo, SWT.LEFT);
lblUser.setText("User name: ");
lblUser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
// // Define field assists for the text widget
// // use "." and " " activate the content proposals
// char[] autoActivationCharacters = new char[] { '.', ' ' };
// KeyStroke keyStroke;
// try {
// keyStroke = KeyStroke.getInstance("Ctrl+Space");
// new ContentProposalAdapter(text, new TextContentAdapter(),
// new SimpleContentProposalProvider(new String[] { "ProposalOne", "ProposalTwo", "ProposalThree" }),
// keyStroke, autoActivationCharacters);
// } catch (ParseException e1) {
// e1.printStackTrace();
// }
cbUserName = new Combo(mainCompo, SWT.DROP_DOWN);
GridData gd = new GridData(SWT.FILL, SWT.FILL, false, false);
gd.widthHint = 100;
cbUserName.setLayoutData(gd);
cbUserName.setText(configManager.getResultConfig().user);
cbUserName.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
setUser(cbUserName.getText());
}
});
cbUserName.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
setUser(cbUserName.getText());
}
@Override
public void focusGained(FocusEvent e) {
// nothing
}
});
CommonControls.makeEmptySpace(mainCompo, 1);
// Button btEditUsers = new Button(parent, SWT.PUSH);
// btEditUsers.setText("edit users");
// btEditUsers.setEnabled(false);
// btEditUsers.setVisible(false);
// btEditUsers.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
// TODO: implement edit users
// choose the thing sub-type
Label lblSubtype = new Label(mainCompo, SWT.LEFT);
lblSubtype.setText("Subtypes: ");
lblSubtype.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false));
ComboViewer cbSubtypes = new ComboViewer(mainCompo, SWT.READ_ONLY);
cbSubtypes.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
cbSubtypes.setContentProvider(ArrayContentProvider.getInstance());
List<Subtype> subtypes = new ArrayList<Subtype>();
for (Subtype st : Subtype.values()) {
subtypes.add(st);
}
cbSubtypes.setInput(subtypes);
cbSubtypes.setSelection(new StructuredSelection(configManager.getResultConfig().subtype));
cbSubtypes.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
eventBroker.send(EventConstants.TOPIC_SUBTYPE_CHANGED, selection.getFirstElement());
}
});
Composite flagsComposite = new Composite(mainCompo, SWT.FILL);
GridLayout layout = new GridLayout(4,false);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
gridData.horizontalSpan = 5;
flagsComposite.setLayoutData(gridData);
layout.horizontalSpacing = 16;
flagsComposite.setLayout(layout);
Label infoLabel = new Label(flagsComposite, SWT.LEFT);
infoLabel.setText("Select which flags are used as filter. Filters follow 'AND' rule.");
GridData gdInfo = new GridData(SWT.FILL, SWT.FILL, true, false);
gdInfo.horizontalSpan = 4;
infoLabel.setLayoutData(gdInfo);
makeFilter(flagsComposite, UserFlag.OWN);
makeFilter(flagsComposite, UserFlag.WTP);
makeFilter(flagsComposite, UserFlag.PREVIOUSLY_OWNED);
makeFilter(flagsComposite, UserFlag.WTB);
makeFilter(flagsComposite, UserFlag.TRADE);
makeFilter(flagsComposite, UserFlag.WISHLIST);
makeFilter(flagsComposite, UserFlag.WANT);
makeFilter(flagsComposite, UserFlag.PREORDERED);
makeFilter(flagsComposite, UserFlag.RATED);
makeFilter(flagsComposite, UserFlag.COMMENT);
makeFilter(flagsComposite, UserFlag.PLAYED);
new BggUserSourceComposite(mainCompo, SWT.NONE, eventBroker, configManager);
mainCompo.pack(); mainCompo.pack();
//mainCompo.layout(true, true);
parent.pack(); parent.pack();
parent.layout(true, true); parent.layout(true, true);
} }
/// Create a control for a filter.
// Filters are tri-state: include iff has flag, include iff it does not have the flag,
// don't care if it has that flag.
// TODO: create a three-way toggle button instead.
private void makeFilter(Composite parent, final UserFlag key) {
ComboViewer filterCombo = new ComboViewer(parent, SWT.READ_ONLY);
filterCombo.setContentProvider(ArrayContentProvider.getInstance());
List<FilterFlagState> states = Arrays.asList(new FilterFlagState[] {
FilterFlagState.IS, FilterFlagState.ISNOT, FilterFlagState.IGNORE
});
filterCombo.setInput(states);
filterCombo.setSelection(new StructuredSelection(configManager.getResultConfig().userFlags.get(key)));
filterCombo.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
UserFlagEvent ufe = new UserFlagEvent();
ufe.flag = key;
ufe.state = (FilterFlagState)selection.getFirstElement();
eventBroker.send(EventConstants.TOPIC_USERFLAG_CHANGED, ufe);
}
});
Label filterLabel = new Label(parent, SWT.LEFT);
filterLabel.setText(key.toString());
filterLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
}
public void setUser(String user) {
if(eventBroker != null) {
eventBroker.post(EventConstants.TOPIC_USER_CHANGED, user);
} else {
System.out.println("setGeeklistId: eventBroker is null.");
}
}
} }

+ 136
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/BggUserSourceComposite.java 파일 보기

@@ -0,0 +1,136 @@
package xyz.veronie.bgg.ui.filters.composites;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.Subtype;
import xyz.veronie.bgg.types.UserFlag;
public class BggUserSourceComposite extends Composite {
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;
Composite main = new Composite(parent, SWT.FILL);
main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
main.setLayout(new GridLayout(1, false));
Composite topRowComposite = new Composite(main, SWT.NONE);
topRowComposite.setLayout(new GridLayout(5, false));
topRowComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false, 1, 1));
Label lblUserName = new Label(topRowComposite, SWT.NONE);
lblUserName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblUserName.setText("User name:");
ComboViewer comboViewerUserName = new ComboViewer(topRowComposite, SWT.NONE);
Combo cbUserName = comboViewerUserName.getCombo();
cbUserName.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
setUser(cbUserName.getText());
}
});
GridData gd_cbUserName = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
gd_cbUserName.widthHint = 100;
cbUserName.setLayoutData(gd_cbUserName);
cbUserName.setText(configManager.getResultConfig().user);
new Label(topRowComposite, SWT.NONE);
Label lblSubtype = new Label(topRowComposite, SWT.NONE);
lblSubtype.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblSubtype.setText("Subtypes:");
ComboViewer comboViewerSubtypes = new ComboViewer(topRowComposite, SWT.NONE);
Combo cbSubtypes = comboViewerSubtypes.getCombo();
cbSubtypes.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
comboViewerSubtypes.setContentProvider(new ArrayContentProvider());
comboViewerSubtypes.setInput(getSubtypes());
comboViewerSubtypes.setSelection(new StructuredSelection(configManager.getResultConfig().subtype));
comboViewerSubtypes.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
eventBroker.send(EventConstants.TOPIC_SUBTYPE_CHANGED, selection.getFirstElement());
}
});
Composite centerComposite = new Composite(main, SWT.NONE);
centerComposite.setLayout(new GridLayout(1, false));
centerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
// centerComposite.setLayout(new FillLayout(SWT.VERTICAL));
Label infoLabel = new Label(centerComposite, SWT.LEFT);
infoLabel.setText("Select which flags are used as filter. Filters follow 'AND' rule.");
GridData gdInfo = new GridData(SWT.FILL, SWT.FILL, true, false);
infoLabel.setLayoutData(gdInfo);
new FilterFlagComposite(centerComposite, UserFlag.OWN, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.PREORDERED, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.WISHLIST, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.WTB, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.WTP, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.WANT, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.PREVIOUSLY_OWNED, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.PLAYED, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.TRADE, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.RATED, configManager, eventBroker);
new FilterFlagComposite(centerComposite, UserFlag.COMMENT, configManager, eventBroker);
this.pack();
}
private void setUser(String user) {
if(eventBroker != null) {
eventBroker.post(EventConstants.TOPIC_USER_CHANGED, user);
} else {
System.out.println("setGeeklistId: eventBroker is null.");
}
}
public List<Subtype> getSubtypes() {
List<Subtype> subtypes = new ArrayList<Subtype>();
for (Subtype st : Subtype.values()) {
subtypes.add(st);
}
return subtypes;
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}

+ 130
- 0
xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/FilterFlagComposite.java 파일 보기

@@ -0,0 +1,130 @@
package xyz.veronie.bgg.ui.filters.composites;
import org.eclipse.e4.core.services.events.IEventBroker;
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;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.wb.swt.ResourceManager;
import xyz.veronie.bgg.result.ResultConfigManager;
import xyz.veronie.bgg.types.EventConstants;
import xyz.veronie.bgg.types.FilterFlagState;
import xyz.veronie.bgg.types.UserFlag;
import xyz.veronie.bgg.types.UserFlagEvent;
public class FilterFlagComposite extends Composite {
private Button btnFlagSwitch;
/**
* Create the composite.
* @param parent
* @param style
*/
public FilterFlagComposite(Composite parent, UserFlag flag,
ResultConfigManager configManager, IEventBroker eventBroker)
{
super(parent, SWT.NONE);
this.setLayout(new GridLayout(2, false));
this.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
// get current state from config to initialize
FilterFlagState flagState = configManager.getResultConfig().userFlags.get(flag);
boolean isTurnedOn = !flagState.equals(FilterFlagState.IGNORE);
Button btnCheckFlag = new Button(this, SWT.CHECK);
btnCheckFlag.setText(flag.toString());
btnCheckFlag.setSelection(isTurnedOn);
GridData gd_btnCheckFlag = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
gd_btnCheckFlag.widthHint = 100;
btnCheckFlag.setLayoutData(gd_btnCheckFlag);
btnFlagSwitch = new Button(this, SWT.TOGGLE);
GridData gd_btnFlagSwitch = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_btnFlagSwitch.widthHint = 30;
btnFlagSwitch.setEnabled(isTurnedOn);
if(isTurnedOn) {
if(flagState.equals(FilterFlagState.IS)) {
setSwitchOn();
} else { // IS_NOT
setSwitchOff();
}
} else {
setSwitchOn();
}
btnFlagSwitch.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Button source = (Button)e.getSource();
UserFlagEvent ufe = new UserFlagEvent();
ufe.flag = flag;
boolean isSelected = source.getSelection();
if(isSelected) {
ufe.state = FilterFlagState.IS;
setSwitchOn();
} else {
ufe.state = FilterFlagState.ISNOT;
setSwitchOff();
}
eventBroker.send(EventConstants.TOPIC_USERFLAG_CHANGED, ufe);
}
});
btnCheckFlag.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Button source = (Button)e.getSource();
boolean isSelected = source.getSelection();
UserFlagEvent ufe = new UserFlagEvent();
ufe.flag = flag;
if(!isSelected) {
ufe.state = FilterFlagState.IGNORE;
setSwitchOn();
btnFlagSwitch.setEnabled(false);
} else {
if(btnFlagSwitch.getSelection()) {
ufe.state = FilterFlagState.IS;
} else {
ufe.state = FilterFlagState.ISNOT;
}
btnFlagSwitch.setEnabled(true);
}
eventBroker.send(EventConstants.TOPIC_USERFLAG_CHANGED, ufe);
}
});
this.pack();
this.getParent().layout(true, true);
}
private void setSwitchOn() {
btnFlagSwitch.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/noun_switch on_30x30.png"));
btnFlagSwitch.setSelection(true);
}
private void setSwitchOff() {
btnFlagSwitch.setImage(ResourceManager.getPluginImage("xyz.veronie.bgg.ui", "icons/noun_switch off_30x30.png"));
btnFlagSwitch.setSelection(false);
}
@Override
protected void checkSubclass() {
// Disable the check that prevents subclassing of SWT components
}
}

불러오는 중...
취소
저장