From f1b7fdc822adaf118c1cd146b5a0dbc32a048d83 Mon Sep 17 00:00:00 2001 From: veronie Date: Sat, 30 Jan 2021 01:43:48 +0100 Subject: [PATCH] Layouting of BggUserSourceFilter --- .../icons/noun_switch off_30x30.png | Bin 0 -> 1727 bytes .../icons/noun_switch on_30x30.png | Bin 0 -> 1694 bytes .../bgg/ui/filters/BggUserSourceFilter.java | 168 +----------------- .../composites/BggUserSourceComposite.java | 136 ++++++++++++++ .../composites/FilterFlagComposite.java | 130 ++++++++++++++ 5 files changed, 268 insertions(+), 166 deletions(-) create mode 100644 xyz.veronie.bgg.ui/icons/noun_switch off_30x30.png create mode 100644 xyz.veronie.bgg.ui/icons/noun_switch on_30x30.png create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/BggUserSourceComposite.java create mode 100644 xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/FilterFlagComposite.java diff --git a/xyz.veronie.bgg.ui/icons/noun_switch off_30x30.png b/xyz.veronie.bgg.ui/icons/noun_switch off_30x30.png new file mode 100644 index 0000000000000000000000000000000000000000..345cd2bae292ae672964ff75f767318d2042c90a GIT binary patch literal 1727 zcmV;w20;0VP) zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=KHlH4E+MgLhvmVhLL#Bwl?s_Y=k&&99lo|(KV z`AW4Z0~WH7?*V!yjBj6O_=1Z{=8)7pmz*Q6R8rxJj>qFFdrdLz_3<#yF?zO#dw^jQ zv~oOJJ^d@}`u4W`*x;O7YY8R#6i0?L}1(dmy#!p?`C(iy0n8Rg>knCiwy+fK(l zmGc(cL*GHxb9gi)gGycDCCo!e;$HiafvlUPqFuGf@>^x~J)lW)eG&wD`n;=+@ll{B zk*{8Oum0V8CqCEHF7LF=r$*>}Izall_`Adp6U&_uKM$B(p+1T{XZJbB@pUz2D4Nd| z6~m>@dIydhB$xfQjAFPIecMYx@mOO6oE}@;P#P6tP?>=eb*eOJ>}{il6cZ0Nw9E~l zmd(YuaNCKcRcNwFkuDCFjYj~wBz)&W`@ChJuaRTsPH<&HFv2T8Ea7K^e^SDnZAnDY zZ>^9Qua%257P(c!3qWX|+;kWCDkuKkQ>J3g?+?Fg|cy{#?TISc$0?XfE; zSU&?mBFwEwh6Ds+CQ-^1joFBxqXSSy<}8Uf5Fl0VNRqKLa2^>uuetG#(eBI2nU@)7 z6F{hBF|a980V^fN`my9#LsdnSs%ACyphatzoU-PeEw4kanpiTmY-Vo7s*5LA&u;Es zycRBkGf+z|R=ku_D~F1SDq>amS6DXQWJ{ZFd9%&8veky=(^Auxn>BBx)y`cyj)|VT zb?>FuL1Eye7-{Ip!-kJC>cm=`GSk$Vr%j(_)|=W%^+WjsYIIWLoz(KPn;NXa>Y*nJouUITkwKWg=F+gG4hpjV(*pjV(*pjV*( zAkf4g5BMiGd%gi21>9Hp>Q&qRKDO=p3E+PQuC%7VTmxo4Nv}4w@Db3n4P0C|HF*!X+yVNZbjgq$ z$xlnj=YjV#`lc+v<~F8+`(P2-C`Rx; zv1(7`&iCL`tX(VMZ$#}Z@OTy-_?4KunVj5@ZZxqY6ZSSbLdODJjNZGI;B5;VGiP^3 z%MD>0KHzqa|1B;RDej2^7!2Yv#WxE2_E<*Vf?XN;NN_LO4UMpDFgz$y`Y2a8f5WEW z94Xt>jTd->3mA_f(!z6`k6fiqE^%%xsJdRQKqvEXZijmom37n3KPr9A< z<5Y~g&cvIn-P27xi||g?kANEg-(zokH2GZS5}1jnOD9(0YfPeMOt0^Fg^yJg{{f7K VnazyuzY_oe002ovPDHLkV1hCpHOl}1 literal 0 HcmV?d00001 diff --git a/xyz.veronie.bgg.ui/icons/noun_switch on_30x30.png b/xyz.veronie.bgg.ui/icons/noun_switch on_30x30.png new file mode 100644 index 0000000000000000000000000000000000000000..f0f5201c06c6cc2b83a210e6950003551e64e075 GIT binary patch literal 1694 zcmV;P24VS$P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=KHlH4E+MgLhvmVhLL#Bwl?s_Y=k&&99lo|(KV z`AW4Z0~WH7?*V!yjBj6O_=1Z{=8)7pmz*Q6R8rxJj>qFFdrdLz_3<#yF?zO#dw^jQ zv~oOJJ^d@}`u4W`*x;O7YY8R#6i0?L}1(dmy#!p?`C(iy0n8Rg>knCiwy+fK(l zmGc(cL*GHxb9gi)gGycDCCo!e;$HiafvlUPqFuGf@>^x~J)mK^GJzmZpLew}J___C z^3@CP)xUf1#OHe2<(-!K)CiqV2S`5`f0y`SV!1Qo=K+%|)JKu$>^|o>zOJSWMf16$ zVz|^<@4#_`t_H+gt-;TkbpqUBubg0F&hzdbO5Tz92b@Alt+0EUH z*TO|`25QO0ikDJq4 zC%Tw{7$*X8TLiG6c`=JlDe)q=n8m`_6v{|a7n{&&5d*?Bh;`D} zqKlMxUs7lhoR<9C3(PEVQuP!mMbh#8bp!Mb#)@$hfR<-r}s5Dy(r&{=#5RTTXGE)*xb7 zL>vi-kWs+~O0W>2T_eRrlFp+Z{sG6IAeT(84KQ-dqYM?2;|KqP-?KIIlM`-IFbcH4 z*!IT=5ZDFkRonhPw(a@};C}|Lw5GpY17f%h}|rYz8V3v{izb8DRA^Z`iItd?$ogF|4nK-p^^@9t=w+rK@H`TYQL@p7kg zqS==K000JJOGiWi{{a60|De66lK=n!32;bRa{vGf6951U69E94oEQKA00(qQO+^Rg z0UZ}68LN^QasU7Uq)9|UR7l6|)jwzzK@bM;Ut)~LhtVP_R1ks@EP_JB&LSxSf&{V9 zLhVxtHi1<378*qnvC&EdTd^^splCEj#7eXZM1r6ss3Cvk<=M=Gn?{^k#`V6jOPo)1>i44@^ARUPgnZW%rk3>ftios~5 owt~Wqi1Y)duvWdr75)$W0eq2u%8GP+X8-^I07*qoM6N<$g6!%hkN^Mx literal 0 HcmV?d00001 diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java index 143d1e8..50fd5d8 100644 --- a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java +++ b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/BggUserSourceFilter.java @@ -1,38 +1,17 @@ package xyz.veronie.bgg.ui.filters; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import javax.inject.Inject; import org.eclipse.e4.core.di.annotations.Creatable; 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.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.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.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.CommonControls; /// 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 ResultConfigManager configManager; - private Combo cbUserName; - public void create(Composite parent, int style) { Composite mainCompo = new Composite(parent, SWT.FILL); @@ -54,152 +31,11 @@ public class BggUserSourceFilter { mainCompo.setLayout(gl_mainCompo); 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 subtypes = new ArrayList(); - 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.layout(true, true); parent.pack(); 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 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."); - } - } - } diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/BggUserSourceComposite.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/BggUserSourceComposite.java new file mode 100644 index 0000000..c1e6438 --- /dev/null +++ b/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 getSubtypes() { + List subtypes = new ArrayList(); + for (Subtype st : Subtype.values()) { + subtypes.add(st); + } + return subtypes; + } + + + @Override + protected void checkSubclass() { + // Disable the check that prevents subclassing of SWT components + } +} diff --git a/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/FilterFlagComposite.java b/xyz.veronie.bgg.ui/src/xyz/veronie/bgg/ui/filters/composites/FilterFlagComposite.java new file mode 100644 index 0000000..16a17be --- /dev/null +++ b/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 + } + +}