-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOld.java.java
More file actions
276 lines (201 loc) · 6.96 KB
/
Old.java.java
File metadata and controls
276 lines (201 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package codelearninternship;
//import javax.swing.table.TableColumn;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
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.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
public class ViewPart13 extends ViewPart {
private static URL URLObj;
private static URLConnection connect;
public ViewPart13() {
// TODO Auto-generated constructor stub
}
int totalcount=0;
String[] time=new String[200];
String[] city={"bangalore","chennai","delhi","mumbai","goa","cochin","hyderabad","ahmedabad"};
@Override
public void createPartControl(final Composite parent)
{
final Table table ;
parent.setLayout(new GridLayout(3,false));
Label label = new Label(parent, SWT.NONE);
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
false));
label.setText("From");
final Text SenderEmail = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
SenderEmail.setLayoutData(new GridData(200,20));
SenderEmail.setText("");
final Label Elabel = new Label(parent, SWT.NONE);
Elabel.setLayoutData(new GridData(200,20));
Elabel.setText("");
final Label label1 = new Label(parent, SWT.NONE);
label1.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
false));
label1.setText("To");
final Text Subject = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
Subject.setLayoutData(new GridData(200,20));
Subject.setText("");
final Label Elabel1 = new Label(parent, SWT.NONE);
Elabel1.setLayoutData(new GridData(200,20));
Elabel1.setText("");
//Elabel.setForeground();
org.eclipse.swt.widgets.Button button = new org.eclipse.swt.widgets.Button(
parent, SWT.PUSH);
button.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
false));
button.setText("Send");
final Label Elabel2 = new Label(parent, SWT.NONE);
Elabel2.setLayoutData(new GridData(200,20));
Elabel2.setText("");
parent.setLayout( new GridLayout(1,false));
table = new Table(parent ,SWT.NONE);
table.setVisible(false);
table.setLinesVisible(true);
table.setHeaderVisible(true);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = 200;
table.setLayoutData(data);
final String[] titles = { "From", "To", "Airline","FlightNo","Depart-Arrive" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText(titles[i]);
table.getColumn(i).pack();
}
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String b="true";//validate(SenderEmail.getText().trim());
if(check(SenderEmail.getText())==false )
{
Elabel.setText("invalid");
}
else if(check(Subject.getText())==false)
{
Elabel1.setText("invalid");
}
else if(cmp(SenderEmail.getText(),Subject.getText())==false)
{
Elabel.setText("Same");
Elabel1.setText("Same");
//Elabel2.setText("");
//check(SenderEmail.getText(),Subject.getText());
}
else
{
Elabel.setText("");
Elabel1.setText("");
/*if(totalcount !=0)
{
for (int i = 0 ; i<=totalcount ; i++){
table.remove(i);
}
}*/
table.removeAll();
totalcount=0;
getTime(SenderEmail.getText(), Subject.getText());
for (int i = 0 ; i<=totalcount-1 ; i+=5){
TableItem item = new TableItem(table, SWT.NONE);
item.setText (0, time[i]);
item.setText (1, time[i+1]);
item.setText (2, time[i+2]);
item.setText (3, time[i+3]);
item.setText (4, time[i+4]);
}
for (int i=0; i<titles.length; i++) {
table.getColumn (i).pack ();
}
table.setVisible(true);
}
}
});
}
public void getTime(String from,String to)
{
try {
// private static URL URLObj;
// Establish a URL and open a connection to it. Set it to output mode.
URL URLObj = new URL("http://www.makemytrip.com/flights/"+from.toLowerCase()+"-"+to.toLowerCase()+"-cheap-airtickets.html");
connect = URLObj.openConnection();
connect.setDoOutput(true);
}
catch (Exception ex)
{
System.out.println("An exception occurred. " + ex.getMessage());
System.exit(1);
}
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream()));
String lineRead = "";
// Read all available lines of data from the URL and print them to screen.
while ((lineRead = reader.readLine()) != null)
{
if(lineRead.contains(" <tr ") ==true)
{
lineRead=reader.readLine();
int count=0;
while(count<=4)
{
String s=lineRead.substring(lineRead.indexOf(">")+1,lineRead.lastIndexOf("<"));
time[totalcount]=s;
totalcount++;
//System.out.print(s+" ");
lineRead=reader.readLine();
count++;
}
System.out.println();
}
}
reader.close();
}
catch (Exception ex) {
System.out.println("There was an error reading or writing to the URL: " + ex.getMessage());
}
}
public boolean cmp(String from,String to)
{
if(from.toLowerCase().equals(to.toLowerCase())==true)
{
return false;
}
else
{
return true;
}
}
public boolean check(String s)
{
boolean avail=false;
if(s.trim().equals("")){return false;}
for(int i=0;i<7;i++)
{
if(city[i].equals(s.toLowerCase().trim())==true)
{
avail=true;
break;
}
}
if (s.toLowerCase().matches("[a-z]+$")==false) {
return false;
}
if(avail==false){return false;}
return true;
}
@Override
public void setFocus() {
// TODO Auto-generated method stub
}
}