Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0316d2d

Browse files
author
Suresh Tripathi
committed
Code for deleting and adding tag
1 parent 49591f0 commit 0316d2d

7 files changed

Lines changed: 198 additions & 66 deletions

File tree

netview/src/com/prodco/analysis/client/PassthroughFilter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
public class PassthroughFilter implements ViewFilter
55
{
66

7-
@Override
87
public void filter ( String criteria )
98
{
109
// TODO Auto-generated method stub
1110

1211
}
1312

14-
@Override
1513
public String getDescription ()
1614
{
1715
return "None";

netview/src/com/prodco/preferences/client/TagDetailPanel.java

Lines changed: 120 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
import com.extjs.gxt.ui.client.event.Events;
1616
import com.extjs.gxt.ui.client.event.Listener;
1717
import com.extjs.gxt.ui.client.event.SelectionListener;
18+
import com.extjs.gxt.ui.client.widget.ContentPanel;
19+
import com.extjs.gxt.ui.client.widget.Info;
1820
import com.extjs.gxt.ui.client.widget.LayoutContainer;
1921
import com.extjs.gxt.ui.client.widget.button.Button;
2022
import com.extjs.gxt.ui.client.widget.form.FormPanel;
2123
import com.extjs.gxt.ui.client.widget.form.NumberField;
2224
import com.extjs.gxt.ui.client.widget.form.TextField;
25+
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
26+
import com.extjs.gxt.ui.client.widget.layout.FlowData;
2327
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
2428
import com.extjs.gxt.ui.client.widget.layout.FormData;
2529
import com.google.gwt.user.client.Element;
@@ -30,6 +34,8 @@
3034
public class TagDetailPanel extends CommonPanel
3135
{
3236

37+
private ContentPanel panel = new ContentPanel();
38+
3339
private String title = "Tag Detail";
3440

3541
private NumberField tfId = new NumberField();
@@ -43,11 +49,9 @@ public class TagDetailPanel extends CommonPanel
4349
private List<FieldBinding> bindings = new ArrayList<FieldBinding>();
4450

4551
private FormPanel detailPanel = makeFormColumn();
46-
Button btnSave = new Button();
47-
Button btnCancel = new Button( "&nbsp;Cancel" );
4852

4953
private TagEditor parent;
50-
54+
5155
public String getTitle ()
5256
{
5357
return title;
@@ -59,15 +63,28 @@ public String getTitle ()
5963
public TagDetailPanel ( TagEditor parent, List<FormBinding> formBindings )
6064
{
6165

62-
this.parent=parent;
66+
this.parent = parent;
6367
this.formBindings = formBindings;
6468
this.setWidth( 600 );
65-
this.setHeight( 300 );
69+
this.setHeight( 200 );
6670
this.setLayout( new FlowLayout() );
6771
this.setFrame( true );
6872
this.setHeading( getTitle() );
69-
setIconStyle( "icon-home" );
73+
setIconStyle( "icon-home" );
7074
add( createTabPanel() );
75+
76+
SelectionListener<ButtonEvent> l = new SelectionListener<ButtonEvent>() {
77+
78+
@Override
79+
public void componentSelected ( ButtonEvent ce )
80+
{
81+
Info.display( "Click", ce.getButton().getText()
82+
+ " clicked" );
83+
84+
}
85+
86+
};
87+
layout();
7188
}
7289

7390
@Override
@@ -85,6 +102,7 @@ public void redraw_panel ( boolean readOnly )
85102
public void clearPanel ()
86103
{
87104
detailPanel.reset();
105+
tfId.reset();
88106
this.layout();
89107
}
90108

@@ -93,25 +111,25 @@ private LayoutContainer createTabPanel ()
93111
{
94112
FormData fieldWidth = new FormData( "95%" );
95113

96-
tfId.setPropertyEditorType( Integer.class );
97-
tfId.setName( "tagId" );
98-
99114
tfRank.setPropertyEditorType( Integer.class );
100115
tfRank.setName( "tagPref" );
101116
tfRank.setFieldLabel( "Tag Priority" );
102-
tfRank.setLabelSeparator( ":" );
103117
detailPanel.add( tfRank, fieldWidth );
104118

105119
tfTagName.setName( "tagName" );
106-
tfTagName.setFieldLabel( "Tag Name#" );
120+
tfTagName.setFieldLabel( "Tag Name" );
107121
detailPanel.add( tfTagName, fieldWidth );
108122

109123
tfTagRule.setName( "tagRule" );
110124
tfTagRule.setFieldLabel( "Tag Rule" );
111125
detailPanel.add( tfTagRule, fieldWidth );
112126

113-
// When the button is pressed, load new alarms with the date range
114-
btnSave.setText( "&nbsp;&nbsp;Save" );
127+
tfId.setPropertyEditorType( Integer.class );
128+
tfId.setName( "tagId" );
129+
tfId.setVisible( false );
130+
131+
HorizontalAlignment align = HorizontalAlignment.CENTER;
132+
Button btnSave = new Button( "Update/Add" );
115133
btnSave.setIconStyle( "gwt-Button" );
116134
btnSave.addListener( Events.OnClick, new Listener<ComponentEvent>() {
117135
public void handleEvent ( ComponentEvent ce )
@@ -123,9 +141,9 @@ public void handleEvent ( ComponentEvent ce )
123141
}
124142
} );
125143

126-
btnCancel.setIconStyle( "gwt-Button" );
127-
btnCancel.setText( "&nbsp;&nbsp;Cancel" );
128-
btnCancel.addListener( Events.OnClick, new Listener<ComponentEvent>() {
144+
Button btnReset = new Button( "Reset" );
145+
btnReset.setIconStyle( "gwt-Button" );
146+
btnReset.addListener( Events.OnClick, new Listener<ComponentEvent>() {
129147
public void handleEvent ( ComponentEvent ce )
130148
{
131149
if ( ce.getType() == Events.OnClick )
@@ -135,40 +153,113 @@ public void handleEvent ( ComponentEvent ce )
135153
}
136154
} );
137155

138-
detailPanel.add( btnSave );
139-
detailPanel.add( btnCancel );
156+
Button btnDelete = new Button( "Delete" );
157+
btnDelete.setIconStyle( "gwt-Button" );
158+
btnDelete.addListener( Events.OnClick, new Listener<ComponentEvent>() {
159+
public void handleEvent ( ComponentEvent ce )
160+
{
161+
162+
if ( ce.getType() == Events.OnClick )
163+
{
164+
deleteTag();
165+
}
166+
}
140167

141-
detailPanel.setButtonAlign( HorizontalAlignment.CENTER );
168+
} );
142169

143170
bindings.addAll( new FormBinding( detailPanel, true ).getBindings() );
144-
bindings.add( new FieldBinding(tfId,"tagId") );
145-
146-
return detailPanel;
171+
bindings.add( new FieldBinding( tfId, "tagId" ) );
172+
173+
detailPanel.setBorders( true );
174+
panel.add( detailPanel );
175+
panel.addButton( btnSave );
176+
panel.addButton( btnReset );
177+
panel.addButton( btnDelete );
178+
panel.setBorders( true );
179+
panel.setButtonAlign( align );
180+
panel.setSize( 600, 200 );
181+
panel.setLayout( new FitLayout() );
182+
panel.layout();
183+
184+
return panel;
147185
}
148186

149187
public void updateTag ()
188+
{
189+
if ( tfId.getValue() != null )
190+
{
191+
int id = tfId.getValue().intValue();
192+
int rank = tfRank.getValue().intValue();
193+
String tagName = tfTagName.getValue();
194+
String tagRule = tfTagRule.getValue();
195+
AppTag tag = new AppTag( id, rank, tagName, tagRule );
196+
197+
Services.PREFERENCES.saveAppTagForCustomer( 1, tag,
198+
new AsyncCallback<Void>() {
199+
public void onSuccess ( Void args0 )
200+
{
201+
// Window.alert("Successfully changed Tag for customer");
202+
parent.updateStore();
203+
}
204+
205+
public void onFailure ( Throwable caught )
206+
{
207+
Window.alert( "Failed in updating tag:"
208+
+ caught.getMessage() );
209+
}
210+
} );
211+
}
212+
else
213+
{
214+
int rank = tfRank.getValue().intValue();
215+
String tagName = tfTagName.getValue();
216+
String tagRule = tfTagRule.getValue();
217+
218+
AppTag tag = new AppTag( null, rank, tagName, tagRule );
219+
Services.PREFERENCES.saveAppTagForCustomer( 1, tag,
220+
new AsyncCallback<Void>() {
221+
public void onSuccess ( Void args0 )
222+
{
223+
Window.alert( "Successfully Added Tag for customer" );
224+
parent.updateStore();
225+
clearPanel();
226+
}
227+
228+
public void onFailure ( Throwable caught )
229+
{
230+
Window.alert( "Failed in Adding tag:"
231+
+ caught.getMessage() );
232+
}
233+
} );
234+
235+
}
236+
237+
}
238+
239+
private void deleteTag ()
150240
{
151241
int id = tfId.getValue().intValue();
152242
int rank = tfRank.getValue().intValue();
153243
String tagName = tfTagName.getValue();
154-
String tagRule = tfTagRule.getValue();
155-
AppTag tag = new AppTag(id,rank,tagName,tagRule);
156-
157-
Services.PREFERENCES.saveAppTagForCustomer( 1, tag,
244+
String tagRule = tfTagRule.getValue();
245+
246+
AppTag tag = new AppTag( id, rank, tagName, tagRule );
247+
Services.PREFERENCES.deleteAppTagForCustomer( 1, tag,
158248
new AsyncCallback<Void>() {
159249
public void onSuccess ( Void args0 )
160250
{
161-
// Window.alert("Successfully changed Tag for customer");
251+
Window.alert( "Successfully deleted Tag for customer" );
162252
parent.updateStore();
253+
clearPanel();
163254
}
164255

165256
public void onFailure ( Throwable caught )
166257
{
167-
Window.alert("Failed in updating tag:"+caught.getMessage() );
258+
Window.alert( "Failed in Deleting tag:"
259+
+ caught.getMessage() );
168260
}
169261
} );
170262

171-
172263
}
173264

174265
public List<FieldBinding> getFieldBindings ()

netview/src/com/prodco/preferences/client/TagEditor.java

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ protected void onRender ( Element parent, int index )
115115
gridPanel.setHeading( "App Tags" );
116116
gridPanel.setHeaderVisible( true );
117117
gridPanel.setFrame( true );
118-
gridPanel.setCollapsible( true );
119-
gridPanel.setWidth( 600 );
120-
gridPanel.setHeight( 225 );
118+
gridPanel.setCollapsible( true );
121119
gridPanel.add( grid );
122120

123121
LayoutContainer panel = new LayoutContainer();
@@ -126,26 +124,24 @@ protected void onRender ( Element parent, int index )
126124
panel.add( new Image( "images/spacer.gif", 0, 0, 1, 5 ) );
127125
panel.add( detailPanel );
128126
panel.setBorders( true );
129-
panel.setWidth( 650 );
130-
panel.setHeight( 500 );
127+
panel.setWidth( 600 );
128+
panel.setHeight( 400 );
129+
130+
scrollPanel.add( panel );
131+
scrollPanel.setHeight( "450px" );
132+
scrollPanel.setWidth( "600px" );
133+
scrollPanel.setAlwaysShowScrollBars( true );
131134

132135
ContentPanel cp = new ContentPanel();
133136
cp.setHeaderVisible( false );
134137
cp.setFrame( true );
135138
cp.setLayout( new FlowLayout() );
136-
cp.setHeight( 675 );
137-
138-
scrollPanel.add( panel );
139-
scrollPanel.setHeight( "300px" );
140-
scrollPanel.setWidth( "300px" );
141-
scrollPanel.setAlwaysShowScrollBars( true );
142-
143139
cp.add( scrollPanel );
144140
cp.setBorders( true );
145141

146142
add( cp );
147143
setWidth( 700 );
148-
setHeight( 700 );
144+
setHeight( 450 );
149145
layout();
150146

151147
}
@@ -158,14 +154,6 @@ protected void onLoad ()
158154

159155
}
160156

161-
@Override
162-
protected void onShow ()
163-
{
164-
super.onShow();
165-
// detailPanel = new TagDetailPanel( this, formBindings );
166-
Window.alert( "I am in TagEditor.onShow()" );
167-
}
168-
169157
private void loadDetailPanel ( AppTag tag )
170158
{
171159
detailPanel.redraw_panel( true );
@@ -194,13 +182,13 @@ private Grid<BeanModel> createGrid ()
194182
{
195183
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
196184

197-
ColumnConfig column = new ColumnConfig( "tagPref", "Id", 50 );
185+
ColumnConfig column = new ColumnConfig( "tagPref", "Preference", 75 );
198186
configs.add( column );
199187

200-
column = new ColumnConfig( "tagName", "Tag Name", 200 );
188+
column = new ColumnConfig( "tagName", "Tag Name", 150 );
201189
configs.add( column );
202190

203-
column = new ColumnConfig( "tagRule", "Tag Rule", 400 );
191+
column = new ColumnConfig( "tagRule", "Tag Rule", 350 );
204192
configs.add( column );
205193

206194
ColumnModel cm = new ColumnModel( configs );
@@ -209,12 +197,11 @@ private Grid<BeanModel> createGrid ()
209197
GridView gv = grid.getView();
210198
gv.setEmptyText( "No rows returned" );
211199
gv.setViewConfig( new GVC() );
212-
// grid.setAutoHeight( true );
213200
grid.setAutoExpandColumn( "tagRule" );
214201
grid.setStripeRows( true );
215202
grid.setBorders( true );
216-
grid.setWidth( 700 );
217-
grid.setHeight( 300 );
203+
grid.setWidth( 580 );
204+
grid.setHeight( 150 );
218205

219206
// Listen for selection events,
220207
grid.addListener( Events.CellClick, new Listener<GridEvent>() {

netview/src/com/prodco/preferences/client/model/AppTag.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
public class AppTag implements BeanModelTag,Serializable
1010
{
11-
private int tagId;
12-
private int tagPref;
11+
private Integer tagId;
12+
private Integer tagPref;
1313
private String tagName;
1414
private String tagRule;
1515

1616
public AppTag() {}
1717

18-
public AppTag ( int tagId, int tagPref, String tagName, String tagRule )
18+
public AppTag ( Integer tagId, Integer tagPref, String tagName, String tagRule )
1919
{
2020
this.tagId = tagId;
2121
this.tagPref = tagPref;

netview/src/com/prodco/preferences/client/remote/PreferencesRemoteService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ public List<AppTag> findAppTagsByCustomer ( int custId )
1717
public void saveAppTagForCustomer ( int custId, AppTag tag )
1818
throws PreferencesRemoteException;
1919

20+
public void deleteAppTagForCustomer ( int custId, AppTag tag )
21+
throws PreferencesRemoteException;
22+
2023
}

netview/src/com/prodco/preferences/client/remote/PreferencesRemoteServiceAsync.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ public void findAppTagsByCustomer ( int custId,
1717
public void saveAppTagForCustomer ( int custId, AppTag tag,
1818
AsyncCallback<Void> callback );
1919

20+
public void deleteAppTagForCustomer ( int custId, AppTag tag,
21+
AsyncCallback<Void> callback );
22+
2023
}

0 commit comments

Comments
 (0)