22
33import java .util .Arrays ;
44
5- import com .google .gwt .user .client .rpc .AsyncCallback ;
65import com .smartgwt .client .types .MultipleAppearance ;
7- import com .smartgwt .client .util .BooleanCallback ;
8- import com .smartgwt .client .util .SC ;
9- import com .smartgwt .client .widgets .IButton ;
10- import com .smartgwt .client .widgets .events .ClickEvent ;
11- import com .smartgwt .client .widgets .events .ClickHandler ;
126import com .smartgwt .client .widgets .form .fields .BooleanItem ;
137import com .smartgwt .client .widgets .form .fields .CheckboxItem ;
148import com .smartgwt .client .widgets .form .fields .SelectItem ;
159import com .smartgwt .client .widgets .form .fields .TextItem ;
10+
1611import fr .insalyon .creatis .vip .application .client .ApplicationConstants ;
1712import fr .insalyon .creatis .vip .application .client .bean .Tag ;
18- import fr .insalyon .creatis .vip .application .client .rpc .ApplicationService ;
19- import fr .insalyon .creatis .vip .core .client .view .CoreConstants ;
2013import fr .insalyon .creatis .vip .core .client .view .common .AbstractFormLayout ;
21- import fr .insalyon .creatis .vip .core .client .view .layout .Layout ;
2214import fr .insalyon .creatis .vip .core .client .view .util .FieldUtil ;
23- import fr .insalyon .creatis .vip .core .client .view .util .WidgetUtil ;
2415
2516public class EditTagLayout extends AbstractFormLayout {
26- private Tag actualTag ;
27-
2817 private TextItem keyField ;
2918 private TextItem valueField ;
3019 private SelectItem typeField ;
31- private TextItem applicationField ;
32- private TextItem versionField ;
20+ private SelectItem appVersionField ;
3321 private CheckboxItem visibleField ;
3422 private CheckboxItem boutiquesField ;
3523
36- private IButton saveButton ;
37- private IButton removeButton ;
38-
3924 public EditTagLayout () {
4025 super (480 , 200 );
4126 addTitle ("Edit tag" , ApplicationConstants .ICON_TAG );
@@ -57,102 +42,28 @@ private void configure() {
5742 .toArray (String []::new ));
5843 typeField .setWidth (350 );
5944
60- applicationField = FieldUtil .getTextItem (350 , null );
61- applicationField .setDisabled (true );
62-
63- versionField = FieldUtil .getTextItem (350 , null );
64- versionField .setDisabled (true );
65-
66- saveButton = WidgetUtil .getIButton ("Save" , CoreConstants .ICON_SAVED ,
67- new ClickHandler () {
68- @ Override
69- public void onClick (ClickEvent event ) {
70- if (keyField .validate () && valueField .validate () && applicationField .validate () && versionField .validate ()) {
71- save (tagFromFields ());
72- }
73- }
74- });
75-
76- removeButton = WidgetUtil .getIButton ("Remove" , CoreConstants .ICON_DELETE ,
77- new ClickHandler () {
78- @ Override
79- public void onClick (ClickEvent event ) {
80- SC .ask ("Do you really want to remove this tag?" , new BooleanCallback () {
81- @ Override
82- public void execute (Boolean value ) {
83- if (value ) {
84- remove (tagFromFields ());
85- }
86- }
87- });
88- }
89- });
90- removeButton .setDisabled (true );
45+ appVersionField = new SelectItem ();
46+ appVersionField .setShowTitle (false );
47+ appVersionField .setMultiple (true );
48+ appVersionField .setMultipleAppearance (MultipleAppearance .GRID );
49+ appVersionField .setWidth (350 );
9150
9251 addField ("Key" , keyField );
9352 addField ("Value" , valueField );
9453 addField ("Type" , typeField );
95- addField ("Application" , applicationField );
96- addField ("Version" , versionField );
54+ addField ("AppVersions" , appVersionField );
9755 addField ("Visible" , visibleField );
9856 addField ("Boutiques" , boutiquesField );
99- addButtons (saveButton , removeButton );
10057 }
10158
102- public void setTag (Tag tag ) {
59+ public void setTag (Tag tag , String [] appVersions ) {
10360 if (tag != null ) {
104- this .actualTag = tag ;
10561 this .keyField .setValue (tag .getKey ());
10662 this .valueField .setValue (tag .getValue ());
10763 this .typeField .setValue (tag .getType ().toString ());
108- this .applicationField .setValue (tag .getApplication ());
109- this .versionField .setValue (tag .getVersion ());
64+ this .appVersionField .setValueMap (appVersions );
11065 this .visibleField .setValue (tag .isVisible ());
11166 this .boutiquesField .setValue (tag .isBoutiques ());
112- this .removeButton .setDisabled (false );
11367 }
11468 }
115-
116- private void save (Tag tag ) {
117- WidgetUtil .setLoadingIButton (saveButton , "Saving..." );
118- ApplicationService .Util .getInstance ().updateTag (actualTag , tag , getCallback ("update" ));
119- }
120-
121- private void remove (Tag tag ) {
122- WidgetUtil .setLoadingIButton (removeButton , "Removing..." );
123- ApplicationService .Util .getInstance ().removeTag (tag , getCallback ("remove" ));
124- }
125-
126- private AsyncCallback <Void > getCallback (final String text ) {
127- return new AsyncCallback <Void >() {
128- @ Override
129- public void onFailure (Throwable caught ) {
130- WidgetUtil .resetIButton (saveButton , "Save" , CoreConstants .ICON_SAVED );
131- WidgetUtil .resetIButton (removeButton , "Remove" , CoreConstants .ICON_DELETE );
132- Layout .getInstance ().setWarningMessage ("Unable to " + text + " tag:<br />" + caught .getMessage ());
133- }
134-
135- @ Override
136- public void onSuccess (Void result ) {
137- WidgetUtil .resetIButton (saveButton , "Save" , CoreConstants .ICON_SAVED );
138- WidgetUtil .resetIButton (removeButton , "Remove" , CoreConstants .ICON_DELETE );
139- setTag (null );
140- ManageTagsTab tab = (ManageTagsTab ) Layout .getInstance ().
141- getTab (ApplicationConstants .TAB_MANAGE_TAG );
142- tab .loadTags ();
143- }
144- };
145- }
146-
147- private Tag tagFromFields () {
148- return new Tag (
149- keyField .getValueAsString ().trim (),
150- valueField .getValueAsString ().trim (),
151- Tag .ValueType .valueOf (typeField .getValueAsString ()),
152- applicationField .getValueAsString (),
153- versionField .getValueAsString ().trim (),
154- visibleField .getValueAsBoolean (),
155- boutiquesField .getValueAsBoolean ()
156- );
157- }
15869}
0 commit comments