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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
/*******************************************************************************
* Copyright (c) 2003, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* yyyymmdd bug Email and other contact information
* -------- -------- -----------------------------------------------------------
* 20060227 124392 rsinha@ca.ibm.com - Rupam Kuehner
* 20060515 141398 cbrealey@ca.ibm.com - Chris Brealey
*******************************************************************************/
package org.eclipse.jst.ws.internal.consumption.ui.preferences;
import java.util.Vector;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jst.ws.internal.consumption.ui.plugin.WebServiceConsumptionUIPlugin;
import org.eclipse.jst.ws.internal.ui.WSUIPluginMessages;
import org.eclipse.jst.ws.internal.ui.plugin.WebServiceUIPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
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.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
public class ProjectTopologyPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, SelectionListener
{
/*CONTEXT_ID PTPP0001 for the Project Topology Preference Page*/
private String INFOPOP_PTPP_PAGE = WebServiceUIPlugin.ID + ".PPTP0001";
private TableViewer serviceTypeViewer_;
private Button serviceMoveUp_;
private Button serviceMoveDown_;
private Vector serviceTypes_;
private TableViewer clientTypeViewer_;
private Button moveUp_;
private Button moveDown_;
private Vector clientTypes_;
private Button twoEAR_;
/**
* Creates preference page controls on demand.
* @param parent the parent for the preference page
*/
protected Control createContents(Composite superparent)
{
Composite parent = new Composite( superparent, SWT.NONE );
GridLayout layout = new GridLayout();
layout.numColumns = 1;
parent.setLayout( layout );
parent.setToolTipText(WSUIPluginMessages.TOOLTIP_PTPP_PAGE);
parent.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,INFOPOP_PTPP_PAGE);
Group serviceTypeComposite = new Group( parent, SWT.NONE );
GridLayout servicegl = new GridLayout();
servicegl.numColumns = 2;
servicegl.marginHeight = 0;
servicegl.marginWidth = 0;
serviceTypeComposite.setLayout(servicegl);
serviceTypeComposite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ));
serviceTypeComposite.setText(WSUIPluginMessages.LABEL_SERVICE_TYPE_NAME);
Table serviceTable= new Table(serviceTypeComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
GridData servicegd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
servicegd.widthHint = 256;
serviceTable.setLayoutData(servicegd);
serviceTable.setToolTipText(WSUIPluginMessages.TOOLTIP_SERVICE_TYPE_TABLE_VIEWER);
serviceTypes_ = new Vector();
serviceTypeViewer_ = new TableViewer(serviceTable);
serviceTypeViewer_.setContentProvider(new ClientTypeContentProvider());
serviceTypeViewer_.setLabelProvider(new ClientTypeLabelProvider());
serviceTypeViewer_.setInput(serviceTypes_);
TableLayout serviceTableLayout = new TableLayout();
TableColumn serviceTableColumn = new TableColumn(serviceTable, SWT.NONE);
serviceTableColumn.setText(WSUIPluginMessages.LABEL_SERVICE_TYPE_NAME);
ColumnWeightData serviceColumnData = new ColumnWeightData(256, 256, false);
serviceTableLayout.addColumnData(serviceColumnData);
serviceTable.setLayout(serviceTableLayout);
Composite servicec = new Composite(serviceTypeComposite, SWT.NONE);
servicegl = new GridLayout();
servicegl.numColumns = 1;
servicegl.marginHeight = 10;
servicegl.marginWidth = 0;
servicec.setLayout(servicegl);
serviceMoveUp_ = new Button(servicec, SWT.PUSH);
serviceMoveUp_.setText(WSUIPluginMessages.LABEL_MOVE_UP);
serviceMoveUp_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
serviceMoveUp_.addSelectionListener(this);
serviceMoveUp_.setToolTipText(WSUIPluginMessages.TOOLTIP_MOVE_UP);
serviceMoveDown_ = new Button(servicec, SWT.PUSH);
serviceMoveDown_.setText(WSUIPluginMessages.LABEL_MOVE_DOWN);
serviceMoveDown_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
serviceMoveDown_.addSelectionListener(this);
serviceMoveDown_.setToolTipText(WSUIPluginMessages.TOOLTIP_MOVE_DOWN);
Group clientTypeComposite = new Group( parent, SWT.NONE );
GridLayout gl = new GridLayout();
gl.numColumns = 2;
gl.marginHeight = 0;
gl.marginWidth = 0;
clientTypeComposite.setLayout(gl);
clientTypeComposite.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ));
clientTypeComposite.setText(WSUIPluginMessages.LABEL_CLIENT_TYPE_NAME);
Table table= new Table(clientTypeComposite, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
gd.widthHint = 256;
table.setLayoutData(gd);
table.setToolTipText(WSUIPluginMessages.TOOLTIP_CLIENT_TYPE_TABLE_VIEWER);
clientTypes_ = new Vector();
clientTypeViewer_ = new TableViewer(table);
clientTypeViewer_.setContentProvider(new ClientTypeContentProvider());
clientTypeViewer_.setLabelProvider(new ClientTypeLabelProvider());
clientTypeViewer_.setInput(clientTypes_);
TableLayout tableLayout = new TableLayout();
TableColumn tableColumn = new TableColumn(table, SWT.NONE);
tableColumn.setText(WSUIPluginMessages.LABEL_CLIENT_TYPE_NAME);
ColumnWeightData columnData = new ColumnWeightData(256, 256, false);
tableLayout.addColumnData(columnData);
table.setLayout(tableLayout);
Composite c = new Composite(clientTypeComposite, SWT.NONE);
gl = new GridLayout();
gl.numColumns = 1;
gl.marginHeight = 10;
gl.marginWidth = 0;
c.setLayout(gl);
moveUp_ = new Button(c, SWT.PUSH);
moveUp_.setText(WSUIPluginMessages.LABEL_MOVE_UP_2);
moveUp_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
moveUp_.addSelectionListener(this);
moveUp_.setToolTipText(WSUIPluginMessages.TOOLTIP_MOVE_UP);
moveDown_ = new Button(c, SWT.PUSH);
moveDown_.setText(WSUIPluginMessages.LABEL_MOVE_DOWN_2);
moveDown_.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
moveDown_.addSelectionListener(this);
moveDown_.setToolTipText(WSUIPluginMessages.TOOLTIP_MOVE_DOWN);
twoEAR_ = new Button(parent, SWT.CHECK | SWT.WRAP );
twoEAR_.setText(WSUIPluginMessages.LABEL_ENABLE_TWO_EARS);
twoEAR_.setToolTipText(WSUIPluginMessages.TOOLTIP_ENABLE_TWO_EARS);
initializeValues();
org.eclipse.jface.dialogs.Dialog.applyDialogFont(superparent);
return parent;
}
/**
* Does anything necessary because the default button has been pressed.
*/
protected void performDefaults()
{
super.performDefaults();
initializeDefaults();
}
/**
* Do anything necessary because the OK button has been pressed.
* @return whether it is okay to close the preference page
*/
public boolean performOk()
{
storeValues();
return true;
}
protected void performApply()
{
performOk();
}
/**
* @see IWorkbenchPreferencePage
*/
public void init(IWorkbench workbench) { }
/**
* Adds the String elements of array a into Vector v. If String array b contains any elements
* that are not already in array a, appends these elements from array b to the end of Vector v.
* @param a a String array
* @param b a String array
* @param v a non-null Vector
*/
private void setVectorContentsFromTwoArrays(String[] a, String[] b, Vector v)
{
for (int i = 0; i < a.length; i++)
{
v.add(a[i]);
}
for (int i = 0; i < b.length; i++)
{
if (v.indexOf(b[i]) == -1)
{
v.add(b[i]);
}
}
}
/**
* Initializes states of the controls to their burned-in defaults.
*/
private void initializeDefaults()
{
ProjectTopologyContext context = WebServiceConsumptionUIPlugin.getInstance().getProjectTopologyContext();
serviceTypes_.clear();
String[] defaultServiceTypes = context.getDefaultServiceTypes();
String[] allServiceTypes = ProjectTopologyDefaults.getServiceTypes();
setVectorContentsFromTwoArrays(defaultServiceTypes, allServiceTypes, serviceTypes_);
serviceTypeViewer_.refresh();
clientTypes_.clear();
String[] defaultClientTypes = context.getDefaultClientTypes();
String[] allClientTypes = ProjectTopologyDefaults.getClientTypes();
setVectorContentsFromTwoArrays(defaultClientTypes, allClientTypes, clientTypes_);
clientTypeViewer_.refresh();
twoEAR_.setSelection(true);
}
/**
* Initializes states of the controls from the preference helper.
*/
private void initializeValues()
{
//Initial service project types.
ProjectTopologyContext context = WebServiceConsumptionUIPlugin.getInstance().getProjectTopologyContext();
String[] serviceTypesFromContext = context.getServiceTypes();
String[] allServiceTypes = ProjectTopologyDefaults.getServiceTypes();
setVectorContentsFromTwoArrays(serviceTypesFromContext, allServiceTypes, serviceTypes_);
if (allServiceTypes.length > serviceTypesFromContext.length)
{
String[] serviceTypesArray = new String[serviceTypes_.size()];
serviceTypes_.copyInto(serviceTypesArray);
context.setServiceTypes(serviceTypesArray);
}
// refresh viewer
serviceTypeViewer_.refresh();
//Initialize client project types.
String[] clientTypesFromContext = context.getClientTypes();
String[] allClientTypes = ProjectTopologyDefaults.getClientTypes();
setVectorContentsFromTwoArrays(clientTypesFromContext, allClientTypes, clientTypes_);
if (allClientTypes.length > clientTypesFromContext.length)
{
String[] clientTypesArray = new String[clientTypes_.size()];
clientTypes_.copyInto(clientTypesArray);
context.setClientTypes(clientTypesArray);
}
// refresh viewer
clientTypeViewer_.refresh();
twoEAR_.setSelection(context.isUseTwoEARs());
}
/**
* Stores the values of the controls back to the preference helper.
*/
private void storeValues()
{
ProjectTopologyContext context = WebServiceConsumptionUIPlugin.getInstance().getProjectTopologyContext();
String[] serviceTypesArray = new String[serviceTypes_.size()];
serviceTypes_.copyInto(serviceTypesArray);
context.setServiceTypes(serviceTypesArray);
String[] types = new String[clientTypes_.size()];
clientTypes_.copyInto(types);
context.setClientTypes(types);
context.setUseTwoEARs(twoEAR_.getSelection());
}
public void widgetDefaultSelected(SelectionEvent e)
{
}
public void widgetSelected(SelectionEvent e)
{
if (e.widget == serviceMoveUp_ || e.widget == serviceMoveDown_)
{
int index = serviceTypeViewer_.getTable().getSelectionIndex();
if (index != -1)
{
if (e.widget == serviceMoveUp_ && index > 0)
{
Object object = serviceTypes_.remove(index);
serviceTypes_.insertElementAt(object, index-1);
serviceTypeViewer_.refresh();
}
else if (e.widget == serviceMoveDown_ && index < serviceTypes_.size()-1)
{
Object object = serviceTypes_.remove(index);
serviceTypes_.insertElementAt(object, index+1);
serviceTypeViewer_.refresh();
}
}
}
else if (e.widget == moveUp_ || e.widget == moveDown_)
{
int index = clientTypeViewer_.getTable().getSelectionIndex();
if (index != -1)
{
if (e.widget == moveUp_ && index > 0)
{
Object object = clientTypes_.remove(index);
clientTypes_.insertElementAt(object, index - 1);
clientTypeViewer_.refresh();
} else if (e.widget == moveDown_ && index < clientTypes_.size() - 1)
{
Object object = clientTypes_.remove(index);
clientTypes_.insertElementAt(object, index + 1);
clientTypeViewer_.refresh();
}
}
}
}
private class ClientTypeContentProvider implements IStructuredContentProvider
{
/**
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(Object)
*/
public Object[] getElements(Object value)
{
return ((Vector)value).toArray(new String[0]);
}
/**
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose()
{
}
/**
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(Viewer, Object, Object)
*/
public void inputChanged(Viewer arg0, Object arg1, Object arg2)
{
}
}
private class ClientTypeLabelProvider extends LabelProvider
{
public ClientTypeLabelProvider()
{
}
/**
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
*/
public Image getImage(Object arg0)
{
return null;
}
/**
* @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
*/
public String getText(Object value)
{
IFacetedProjectTemplate template = ProjectFacetsManager.getTemplate( (String)value );
return template.getLabel();
}
}
}
|