Lines 1-5
Link Here
|
1 |
/** |
1 |
/** |
2 |
* Copyright (c) 2003,2008 Craig Setera and others. |
2 |
* Copyright (c) 2003,2009 Craig Setera and others. |
3 |
* |
3 |
* |
4 |
* All rights reserved. This program and the accompanying materials |
4 |
* All rights reserved. This program and the accompanying materials |
5 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* are made available under the terms of the Eclipse Public License v1.0 |
Lines 11-25
Link Here
|
11 |
* Diego Sandin (Motorola) - Refactoring package name to follow eclipse |
11 |
* Diego Sandin (Motorola) - Refactoring package name to follow eclipse |
12 |
* standards |
12 |
* standards |
13 |
* Gang Ma (Sybase) - Refactoring the page to add expansibilities |
13 |
* Gang Ma (Sybase) - Refactoring the page to add expansibilities |
14 |
* Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874] |
14 |
* Diego Sandin (Motorola) - Use Eclipse Message Bundles [Bug 255874] |
|
|
15 |
* Jon Dearden (Research In Motion) - Move fields from JADOTAPropertiesEditorPage |
16 |
* and JADPushRegistryEditorPage onto this page |
17 |
* [Bug 284452] |
15 |
*/ |
18 |
*/ |
16 |
package org.eclipse.mtj.internal.ui.editors.jad.form.pages; |
19 |
package org.eclipse.mtj.internal.ui.editors.jad.form.pages; |
17 |
|
20 |
|
|
|
21 |
import java.util.ArrayList; |
22 |
import java.util.Arrays; |
23 |
import java.util.List; |
24 |
|
25 |
import org.eclipse.core.runtime.IProgressMonitor; |
26 |
import org.eclipse.core.runtime.IStatus; |
27 |
import org.eclipse.jdt.core.IJavaProject; |
28 |
import org.eclipse.jdt.core.IType; |
29 |
import org.eclipse.jdt.core.JavaModelException; |
30 |
import org.eclipse.jface.action.Action; |
31 |
import org.eclipse.jface.action.IToolBarManager; |
32 |
import org.eclipse.jface.preference.FieldEditor; |
33 |
import org.eclipse.jface.preference.IPreferenceStore; |
34 |
import org.eclipse.jface.util.IPropertyChangeListener; |
35 |
import org.eclipse.jface.viewers.CellEditor; |
36 |
import org.eclipse.jface.viewers.ColumnWeightData; |
37 |
import org.eclipse.jface.viewers.DialogCellEditor; |
38 |
import org.eclipse.jface.viewers.ICellModifier; |
39 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
40 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
41 |
import org.eclipse.jface.viewers.LabelProvider; |
42 |
import org.eclipse.jface.viewers.TableLayout; |
43 |
import org.eclipse.jface.viewers.TableViewer; |
44 |
import org.eclipse.jface.viewers.TextCellEditor; |
45 |
import org.eclipse.jface.viewers.Viewer; |
46 |
import org.eclipse.jface.window.Window; |
47 |
import org.eclipse.mtj.core.project.midp.DescriptorPropertyDescription; |
48 |
import org.eclipse.mtj.internal.core.project.midp.JADAttributesRegistry; |
49 |
import org.eclipse.mtj.internal.core.util.Utils; |
50 |
import org.eclipse.mtj.internal.core.util.log.MTJLogger; |
18 |
import org.eclipse.mtj.internal.ui.MTJUIMessages; |
51 |
import org.eclipse.mtj.internal.ui.MTJUIMessages; |
|
|
52 |
import org.eclipse.mtj.internal.ui.MTJUIPluginImages; |
53 |
import org.eclipse.mtj.internal.ui.editors.FormLayoutFactory; |
19 |
import org.eclipse.mtj.internal.ui.editors.jad.form.JADFormEditor; |
54 |
import org.eclipse.mtj.internal.ui.editors.jad.form.JADFormEditor; |
|
|
55 |
import org.eclipse.mtj.internal.ui.util.MidletSelectionDialogCreator; |
20 |
import org.eclipse.mtj.ui.editors.jad.JADPropertiesEditorPage; |
56 |
import org.eclipse.mtj.ui.editors.jad.JADPropertiesEditorPage; |
|
|
57 |
import org.eclipse.swt.SWT; |
58 |
import org.eclipse.swt.events.SelectionAdapter; |
59 |
import org.eclipse.swt.events.SelectionEvent; |
60 |
import org.eclipse.swt.graphics.Image; |
61 |
import org.eclipse.swt.layout.FillLayout; |
62 |
import org.eclipse.swt.layout.GridData; |
63 |
import org.eclipse.swt.layout.GridLayout; |
64 |
import org.eclipse.swt.widgets.Button; |
65 |
import org.eclipse.swt.widgets.Combo; |
21 |
import org.eclipse.swt.widgets.Composite; |
66 |
import org.eclipse.swt.widgets.Composite; |
|
|
67 |
import org.eclipse.swt.widgets.Control; |
68 |
import org.eclipse.swt.widgets.Label; |
69 |
import org.eclipse.swt.widgets.Table; |
70 |
import org.eclipse.swt.widgets.TableColumn; |
71 |
import org.eclipse.swt.widgets.TableItem; |
72 |
import org.eclipse.ui.IEditorInput; |
22 |
import org.eclipse.ui.PlatformUI; |
73 |
import org.eclipse.ui.PlatformUI; |
|
|
74 |
import org.eclipse.ui.dialogs.SelectionDialog; |
75 |
import org.eclipse.ui.forms.IManagedForm; |
76 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
77 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
78 |
import org.eclipse.ui.forms.widgets.ScrolledForm; |
79 |
import org.eclipse.ui.forms.widgets.Section; |
23 |
|
80 |
|
24 |
/** |
81 |
/** |
25 |
* JAD editor page for handling the optional properties. |
82 |
* JAD editor page for handling the optional properties. |
Lines 27-33
Link Here
|
27 |
* @author Craig Setera |
84 |
* @author Craig Setera |
28 |
*/ |
85 |
*/ |
29 |
public class JADOptionalPropertiesEditorPage extends JADPropertiesEditorPage { |
86 |
public class JADOptionalPropertiesEditorPage extends JADPropertiesEditorPage { |
30 |
|
87 |
|
31 |
/** |
88 |
/** |
32 |
* The unique page identifier. |
89 |
* The unique page identifier. |
33 |
*/ |
90 |
*/ |
Lines 38-43
Link Here
|
38 |
*/ |
95 |
*/ |
39 |
public JADOptionalPropertiesEditorPage() { |
96 |
public JADOptionalPropertiesEditorPage() { |
40 |
super(ID, MTJUIMessages.JADOptionalPropertiesEditorPage_title); |
97 |
super(ID, MTJUIMessages.JADOptionalPropertiesEditorPage_title); |
|
|
98 |
pushRegEntries = new ArrayList<PushRegEntry>(); |
41 |
} |
99 |
} |
42 |
|
100 |
|
43 |
/** |
101 |
/** |
Lines 47-52
Link Here
|
47 |
*/ |
105 |
*/ |
48 |
public JADOptionalPropertiesEditorPage(JADFormEditor editor) { |
106 |
public JADOptionalPropertiesEditorPage(JADFormEditor editor) { |
49 |
super(editor, ID, MTJUIMessages.JADOptionalPropertiesEditorPage_title); |
107 |
super(editor, ID, MTJUIMessages.JADOptionalPropertiesEditorPage_title); |
|
|
108 |
pushRegEntries = new ArrayList<PushRegEntry>(); |
50 |
} |
109 |
} |
51 |
|
110 |
|
52 |
/* (non-Javadoc) |
111 |
/* (non-Javadoc) |
Lines 56-62
Link Here
|
56 |
public String getTitle() { |
115 |
public String getTitle() { |
57 |
return MTJUIMessages.JADOptionalPropertiesEditorPage_title; |
116 |
return MTJUIMessages.JADOptionalPropertiesEditorPage_title; |
58 |
} |
117 |
} |
59 |
|
118 |
|
60 |
/* (non-Javadoc) |
119 |
/* (non-Javadoc) |
61 |
* @see org.eclipse.mtj.ui.editors.jad.JADPropertiesEditorPage#addContextHelp(org.eclipse.swt.widgets.Composite) |
120 |
* @see org.eclipse.mtj.ui.editors.jad.JADPropertiesEditorPage#addContextHelp(org.eclipse.swt.widgets.Composite) |
62 |
*/ |
121 |
*/ |
Lines 79-85
Link Here
|
79 |
*/ |
138 |
*/ |
80 |
@Override |
139 |
@Override |
81 |
protected String getSectionDescription() { |
140 |
protected String getSectionDescription() { |
82 |
return MTJUIMessages.JADOptionalPropertiesEditorPage_description; |
141 |
return null; |
83 |
} |
142 |
} |
84 |
|
143 |
|
85 |
/* (non-Javadoc) |
144 |
/* (non-Javadoc) |
Lines 87-92
Link Here
|
87 |
*/ |
146 |
*/ |
88 |
@Override |
147 |
@Override |
89 |
protected String getSectionTitle() { |
148 |
protected String getSectionTitle() { |
90 |
return MTJUIMessages.JADOptionalPropertiesEditorPage_SectionTitle; |
149 |
return null; |
|
|
150 |
} |
151 |
|
152 |
@Override |
153 |
protected void createFormContent( IManagedForm managedForm ) { |
154 |
final ScrolledForm form = managedForm.getForm(); |
155 |
FormToolkit toolkit = managedForm.getToolkit(); |
156 |
form.setText( getTitle() ); |
157 |
toolkit.decorateFormHeading( form.getForm() ); |
158 |
createErrorMessageHandler( managedForm ); |
159 |
/* |
160 |
* launch the help system UI, displaying the documentation identified by |
161 |
* the href parameter. |
162 |
*/ |
163 |
final String href = getHelpResource(); |
164 |
if (href != null) { |
165 |
IToolBarManager manager = form.getToolBarManager(); |
166 |
Action helpAction = new Action("help") { //$NON-NLS-1$ |
167 |
@Override |
168 |
public void run() { |
169 |
PlatformUI.getWorkbench().getHelpSystem() |
170 |
.displayHelpResource(href); |
171 |
} |
172 |
}; |
173 |
helpAction.setImageDescriptor(MTJUIPluginImages.DESC_LINKTOHELP); |
174 |
manager.add(helpAction); |
175 |
} |
176 |
form.updateToolBar(); |
177 |
createSectionContent( managedForm, managedForm.getForm().getBody(), this ); |
178 |
} |
179 |
|
180 |
@Override |
181 |
protected void createSectionContent(IManagedForm managedForm, |
182 |
Composite composite, IPropertyChangeListener propertyChangeListener) { |
183 |
|
184 |
FormToolkit toolkit = managedForm.getToolkit(); |
185 |
Composite body = managedForm.getForm().getBody(); |
186 |
body.setLayoutData(new GridData(GridData.FILL_BOTH)); |
187 |
body.setLayout(new GridLayout(2, true)); |
188 |
|
189 |
new Label(body, SWT.NONE); |
190 |
new Label(body, SWT.NONE); |
191 |
|
192 |
Section optionalSection = createStaticBasicSection(toolkit, body, |
193 |
MTJUIMessages.JADOptionalPropertiesEditorPage_SectionTitle, |
194 |
MTJUIMessages.JADOptionalPropertiesEditorPage_description); |
195 |
Composite optionalSectionClient = createStaticSectionClient(toolkit, |
196 |
optionalSection, "optional"); //$NON-NLS-1$ |
197 |
optionalSection.setLayoutData(new GridData( |
198 |
GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL)); |
199 |
optionalSection.setLayout(new GridLayout()); |
200 |
|
201 |
Section otaSection = createStaticBasicSection(toolkit, body, |
202 |
MTJUIMessages.JADOTAPropertiesEditorPage_SectionTitle, |
203 |
MTJUIMessages.JADOTAPropertiesEditorPage_SectionDescription); |
204 |
Composite otaSectionClient = createStaticSectionClient(toolkit, |
205 |
otaSection, "ota"); //$NON-NLS-1$ |
206 |
otaSection.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING |
207 |
| GridData.FILL_HORIZONTAL)); |
208 |
otaSection.setLayout(new GridLayout()); |
209 |
|
210 |
Composite[] sectionClients = new Composite[] { optionalSectionClient, otaSectionClient }; |
211 |
createSectionsContent(managedForm, sectionClients, this); |
212 |
|
213 |
optionalSection.setClient(optionalSectionClient); |
214 |
otaSection.setClient(otaSectionClient); |
215 |
|
216 |
new Label(body, SWT.NONE); |
217 |
new Label(body, SWT.NONE); |
218 |
|
219 |
Section pushSection = toolkit.createSection(body, Section.DESCRIPTION |
220 |
| ExpandableComposite.TITLE_BAR); |
221 |
pushSection.setText(MTJUIMessages.JADPushRegistryEditorPage_sectionTitle); |
222 |
pushSection.setDescription(MTJUIMessages.JADPushRegistryEditorPage_sectionDescription); |
223 |
|
224 |
GridData gd = new GridData(GridData.FILL_BOTH); |
225 |
gd.horizontalSpan = 2; |
226 |
pushSection.setLayoutData(gd); |
227 |
pushSection.setLayout(new GridLayout()); |
228 |
|
229 |
Composite pushSectionClient = toolkit.createComposite(pushSection, SWT.NONE); |
230 |
pushSectionClient.setLayout(new GridLayout(2, false)); |
231 |
pushSection.setClient(pushSectionClient); |
232 |
|
233 |
createTableViewer(toolkit, pushSectionClient); |
234 |
createButtons(toolkit, pushSectionClient); |
235 |
addContextHelp(composite); |
236 |
} |
237 |
|
238 |
/** |
239 |
* This method creates all sections on the page at one time |
240 |
* so that the fieldEditors array is populated only once. |
241 |
*/ |
242 |
private void createSectionsContent(IManagedForm managedForm, |
243 |
Composite[] sections, IPropertyChangeListener propertyChangeListener) { |
244 |
|
245 |
for (int i = 0; i < sections.length; i++) { |
246 |
sections[i].setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2)); |
247 |
new Label(sections[i], SWT.NONE); |
248 |
new Label(sections[i], SWT.NONE); |
249 |
} |
250 |
|
251 |
DescriptorPropertyDescription[] theDescriptors = getDescriptors(); |
252 |
|
253 |
if (fieldEditors == null) { |
254 |
fieldEditors = new FieldEditor[theDescriptors.length]; |
255 |
} |
256 |
|
257 |
FormToolkit toolkit = managedForm.getToolkit(); |
258 |
Composite sectionComp = null; |
259 |
|
260 |
for (int i = 0; i < theDescriptors.length; i++) { |
261 |
|
262 |
for (int j = 0; j < sections.length; j++) { |
263 |
if (theDescriptors[i].getSectionId().equals((String) sections[j].getData())) { |
264 |
sectionComp = sections[j]; |
265 |
break; |
266 |
} |
267 |
} |
268 |
|
269 |
if (sectionComp == null) { |
270 |
throw new Error("sectionComp should not be null"); //$NON-NLS-1$ |
271 |
} |
272 |
|
273 |
switch (theDescriptors[i].getDataType()) { |
274 |
case DescriptorPropertyDescription.DATATYPE_INT: |
275 |
fieldEditors[i] = createIntegerFieldEditor(toolkit, |
276 |
sectionComp, theDescriptors[i]); |
277 |
break; |
278 |
case DescriptorPropertyDescription.DATATYPE_LIST: |
279 |
fieldEditors[i] = createComboFieldEditor(toolkit, sectionComp, |
280 |
theDescriptors[i]); |
281 |
break; |
282 |
case DescriptorPropertyDescription.DATATYPE_URL: |
283 |
case DescriptorPropertyDescription.DATATYPE_STRING: |
284 |
default: |
285 |
fieldEditors[i] = createStringFieldEditor(toolkit, sectionComp, |
286 |
theDescriptors[i]); |
287 |
break; |
288 |
} |
289 |
|
290 |
Label label = fieldEditors[i].getLabelControl(sectionComp); |
291 |
toolkit.adapt(label, false, false); |
292 |
|
293 |
// Listen for property change events on the editor |
294 |
fieldEditors[i].setPropertyChangeListener(propertyChangeListener); |
295 |
} |
296 |
|
297 |
for (int i = 0; i < sections.length; i++) { |
298 |
// Adapt the Combo instances... |
299 |
Control[] children = sections[i].getChildren(); |
300 |
for (Control control : children) { |
301 |
if (control instanceof Combo) { |
302 |
toolkit.adapt(control, false, false); |
303 |
} |
304 |
} |
305 |
} |
306 |
|
307 |
updateEditComponents(); |
308 |
} |
309 |
|
310 |
@Override |
311 |
protected DescriptorPropertyDescription[] doGetDescriptors() { |
312 |
DescriptorPropertyDescription[] optionalDescriptors; |
313 |
optionalDescriptors = JADAttributesRegistry |
314 |
.getJADAttrDescriptorsByPage(getId() + ".optional"); //$NON-NLS-1$ |
315 |
DescriptorPropertyDescription[] otaDescriptors; |
316 |
otaDescriptors = JADAttributesRegistry |
317 |
.getJADAttrDescriptorsByPage(getId() + ".ota"); //$NON-NLS-1$ |
318 |
DescriptorPropertyDescription[] result |
319 |
= new DescriptorPropertyDescription[optionalDescriptors.length + otaDescriptors.length]; |
320 |
System.arraycopy(optionalDescriptors, 0, result, 0, |
321 |
optionalDescriptors.length); |
322 |
System.arraycopy(otaDescriptors, 0, result, optionalDescriptors.length, |
323 |
otaDescriptors.length); |
324 |
return result; |
325 |
} |
326 |
|
327 |
/* (non-Javadoc) |
328 |
* @see org.eclipse.mtj.ui.editors.jad.AbstractJADEditorPage#isManagingProperty(java.lang.String) |
329 |
*/ |
330 |
@Override |
331 |
public boolean isManagingProperty(String property) { |
332 |
boolean manages = property.startsWith(PUSH_REGISTRY_PREFIX); |
333 |
if (manages) { |
334 |
String value = property.substring(PUSH_REGISTRY_PREFIX.length()); |
335 |
try { |
336 |
Integer.parseInt(value); |
337 |
} catch (NumberFormatException e) { |
338 |
manages = false; |
339 |
} |
340 |
} |
341 |
|
342 |
return manages; |
343 |
} |
344 |
|
345 |
/* (non-Javadoc) |
346 |
* @see org.eclipse.ui.forms.editor.FormPage#setFocus() |
347 |
*/ |
348 |
@Override |
349 |
public void setFocus() { |
350 |
tableViewer.getTable().setFocus(); |
351 |
} |
352 |
|
353 |
/** |
354 |
* Add a new item to the table. |
355 |
*/ |
356 |
private void addItem() { |
357 |
PushRegEntry midletDefinition = new PushRegEntry( |
358 |
MTJUIMessages.JADPushRegistryEditorPage_new_pushReg, |
359 |
Utils.EMPTY_STRING, "*"); //$NON-NLS-1$ |
360 |
pushRegEntries.add(midletDefinition); |
361 |
tableViewer.refresh(); |
362 |
setDirty(true); |
363 |
} |
364 |
|
365 |
/** |
366 |
* Create the add and remove buttons to the composite. |
367 |
* |
368 |
* @param toolkit the Eclipse Form's toolkit |
369 |
* @param parent |
370 |
*/ |
371 |
private void createButtons(FormToolkit toolkit, Composite parent) { |
372 |
Composite composite = toolkit.createComposite(parent); |
373 |
FillLayout layout = new FillLayout(); |
374 |
layout.type = SWT.VERTICAL; |
375 |
composite.setLayout(layout); |
376 |
|
377 |
addButton = toolkit |
378 |
.createButton(composite, |
379 |
MTJUIMessages.JADPushRegistryEditorPage_add_btn_label, |
380 |
SWT.PUSH); |
381 |
addButton.addSelectionListener(new SelectionAdapter() { |
382 |
@Override |
383 |
public void widgetSelected(SelectionEvent se) { |
384 |
addItem(); |
385 |
} |
386 |
}); |
387 |
|
388 |
toolkit.createLabel(composite, Utils.EMPTY_STRING); |
389 |
|
390 |
removeButton = toolkit.createButton(composite, |
391 |
MTJUIMessages.JADPushRegistryEditorPage_remove_btn_label, |
392 |
SWT.PUSH); |
393 |
removeButton.setEnabled(false); |
394 |
removeButton.addSelectionListener(new SelectionAdapter() { |
395 |
@Override |
396 |
public void widgetSelected(SelectionEvent se) { |
397 |
removeSelectedItems(); |
398 |
} |
399 |
}); |
400 |
} |
401 |
|
402 |
/** |
403 |
* Create the table viewer for this editor. |
404 |
* |
405 |
* @param toolkit The Eclipse form's toolkit |
406 |
* @param parent |
407 |
*/ |
408 |
private void createTableViewer(FormToolkit toolkit, Composite parent) { |
409 |
|
410 |
String[] columns = new String[] { |
411 |
MTJUIMessages.JADPushRegistryEditorPage_connection_column, |
412 |
MTJUIMessages.JADPushRegistryEditorPage_class_column, |
413 |
MTJUIMessages.JADPushRegistryEditorPage_sender_column, }; |
414 |
|
415 |
// Setup the table |
416 |
int styles = SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER |
417 |
| SWT.FULL_SELECTION; |
418 |
Table table = toolkit.createTable(parent, styles); |
419 |
table.setHeaderVisible(true); |
420 |
table.setLinesVisible(true); |
421 |
|
422 |
table.setLayoutData(new GridData(GridData.FILL_BOTH)); |
423 |
|
424 |
table.addSelectionListener(new SelectionAdapter() { |
425 |
@Override |
426 |
public void widgetSelected(SelectionEvent e) { |
427 |
TableItem selected = (TableItem) e.item; |
428 |
removeButton.setEnabled(selected.getParent() |
429 |
.getSelectionCount() > 0); |
430 |
} |
431 |
}); |
432 |
tableViewer = new TableViewer(table); |
433 |
|
434 |
// Set the table layout on the table |
435 |
TableLayout layout = new TableLayout(); |
436 |
|
437 |
int width = 100 / columns.length; |
438 |
for (String element : columns) { |
439 |
TableColumn column = new TableColumn(table, SWT.NONE); |
440 |
column.setText(element); |
441 |
layout.addColumnData(new ColumnWeightData(width)); |
442 |
} |
443 |
table.setLayout(layout); |
444 |
|
445 |
// Set the content providers |
446 |
tableViewer.setContentProvider(new TableContentProvider()); |
447 |
tableViewer.setLabelProvider(new TableLabelProvider()); |
448 |
|
449 |
// Wire up the cell modification handling |
450 |
tableViewer.setCellModifier(new CellModifier()); |
451 |
tableViewer.setColumnProperties(PROPERTIES); |
452 |
tableViewer.setCellEditors(new CellEditor[] { |
453 |
new TextCellEditor(table), new MidletCellEditor(table), |
454 |
new TextCellEditor(table), }); |
455 |
|
456 |
// Get some data into the viewer |
457 |
tableViewer.setInput(getEditorInput()); |
458 |
tableViewer.refresh(); |
459 |
} |
460 |
|
461 |
/** |
462 |
* Load the Push Registry Entries from the current preference store. |
463 |
*/ |
464 |
private void loadPushRegistryEntries() { |
465 |
pushRegEntries.clear(); |
466 |
IPreferenceStore store = getPreferenceStore(); |
467 |
|
468 |
// This is sort of ugly, but IPreferenceStore does not |
469 |
// allow getting the complete list of preference keys |
470 |
for (int i = 1; i < 1000; i++) { |
471 |
String propName = PUSH_REGISTRY_PREFIX + i; |
472 |
|
473 |
if (store.contains(propName)) { |
474 |
String propValue = store.getString(propName); |
475 |
pushRegEntries.add(new PushRegEntry(propValue)); |
476 |
} else { |
477 |
break; |
478 |
} |
479 |
} |
480 |
|
481 |
storedEntriesCount = pushRegEntries.size(); |
482 |
if (tableViewer != null) { |
483 |
tableViewer.refresh(); |
484 |
} |
485 |
} |
486 |
|
487 |
/** |
488 |
* Remove the items currently selected within the table. |
489 |
*/ |
490 |
private void removeSelectedItems() { |
491 |
int[] indices = tableViewer.getTable().getSelectionIndices(); |
492 |
|
493 |
for (int i = indices.length; i > 0; i--) { |
494 |
int index = indices[i - 1]; |
495 |
pushRegEntries.remove(index); |
496 |
} |
497 |
|
498 |
setDirty(true); |
499 |
tableViewer.refresh(); |
500 |
} |
501 |
|
502 |
/** The prefix of all push registry definition properties */ |
503 |
public static final String PUSH_REGISTRY_PREFIX = "MIDlet-Push-"; //$NON-NLS-1$ |
504 |
|
505 |
private static final String PROP_CLASS = "class"; //$NON-NLS-1$ |
506 |
|
507 |
// Column property names |
508 |
private static final String PROP_CONNSTR = "connection string"; //$NON-NLS-1$ |
509 |
|
510 |
private static final String PROP_SENDER = "allowed sender"; //$NON-NLS-1$ |
511 |
|
512 |
// All of the properties in order |
513 |
private static final String[] PROPERTIES = new String[] { PROP_CONNSTR, |
514 |
PROP_CLASS, PROP_SENDER }; |
515 |
|
516 |
private static final List<String> PROPERTY_LIST = Arrays.asList(PROPERTIES); |
517 |
|
518 |
// Buttons |
519 |
private Button addButton; |
520 |
|
521 |
// The collections of entries representing the MIDlets to be registered |
522 |
private ArrayList<PushRegEntry> pushRegEntries; |
523 |
private Button removeButton; |
524 |
|
525 |
// The number of MIDlets registered |
526 |
private int storedEntriesCount; |
527 |
|
528 |
// The table viewer in use |
529 |
private TableViewer tableViewer; |
530 |
|
531 |
/* (non-Javadoc) |
532 |
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput) |
533 |
*/ |
534 |
@Override |
535 |
protected void setInput(IEditorInput input) { |
536 |
super.setInput(input); |
537 |
if (tableViewer != null) { |
538 |
tableViewer.setInput(input); |
539 |
} |
540 |
|
541 |
setDirty(false); |
542 |
loadPushRegistryEntries(); |
543 |
} |
544 |
|
545 |
/* (non-Javadoc) |
546 |
* @see org.eclipse.ui.forms.editor.FormPage#doSave(org.eclipse.core.runtime.IProgressMonitor) |
547 |
*/ |
548 |
@Override |
549 |
public void doSave(IProgressMonitor monitor) { |
550 |
// Save push registry entries |
551 |
monitor.setTaskName(getTitle()); |
552 |
IPreferenceStore store = getPreferenceStore(); |
553 |
// Add the push registry entries to the store |
554 |
int i; |
555 |
int currentEntriesCount = pushRegEntries.size(); |
556 |
|
557 |
for (i = 0; i < currentEntriesCount; i++) { |
558 |
PushRegEntry def = pushRegEntries.get(i); |
559 |
store.setValue(PUSH_REGISTRY_PREFIX + (i + 1), def.toString()); |
560 |
} |
561 |
// Removing deleted entries |
562 |
for (; i < storedEntriesCount; i++) { |
563 |
store.setToDefault(PUSH_REGISTRY_PREFIX + (i + 1)); |
564 |
} |
565 |
storedEntriesCount = currentEntriesCount; |
566 |
// Save other fields |
567 |
super.doSave(monitor); |
568 |
} |
569 |
|
570 |
/** |
571 |
* Implementation of the ICellModifier interface. |
572 |
*/ |
573 |
private class CellModifier implements ICellModifier { |
574 |
|
575 |
/* (non-Javadoc) |
576 |
* @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String) |
577 |
*/ |
578 |
public boolean canModify(Object element, String property) { |
579 |
// All columns are modifiable |
580 |
return true; |
581 |
} |
582 |
|
583 |
/* (non-Javadoc) |
584 |
* @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String) |
585 |
*/ |
586 |
public Object getValue(Object element, String property) { |
587 |
Object value = null; |
588 |
|
589 |
if (element instanceof PushRegEntry) { |
590 |
PushRegEntry entry = (PushRegEntry) element; |
591 |
|
592 |
int fieldIndex = getFieldIndex(property); |
593 |
if (fieldIndex != -1) { |
594 |
value = entry.fields[fieldIndex]; |
595 |
} |
596 |
} |
597 |
|
598 |
return value; |
599 |
} |
600 |
|
601 |
/* (non-Javadoc) |
602 |
* @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object) |
603 |
*/ |
604 |
public void modify(Object element, String property, Object value) { |
605 |
if (element instanceof TableItem) { |
606 |
Object data = ((TableItem) element).getData(); |
607 |
String newValue = (String) value; |
608 |
|
609 |
if (data instanceof PushRegEntry) { |
610 |
int fieldIndex = getFieldIndex(property); |
611 |
PushRegEntry entry = (PushRegEntry) data; |
612 |
|
613 |
if (fieldIndex != -1) { |
614 |
updateField(entry, property, fieldIndex, newValue); |
615 |
} |
616 |
} |
617 |
} |
618 |
} |
619 |
|
620 |
/** |
621 |
* Return the field index to match the specified property name. |
622 |
* |
623 |
* @param property property name to search for |
624 |
* @return the index that matchs the specified property name. |
625 |
* <code>-1</code> if the property is not recognized. |
626 |
*/ |
627 |
private int getFieldIndex(String property) { |
628 |
return PROPERTY_LIST.indexOf(property); |
629 |
} |
630 |
|
631 |
/** |
632 |
* Update the specified field as necessary. |
633 |
* |
634 |
* @param entry the Push Registry entry to be updated |
635 |
* @param property property of entry to be updated |
636 |
* @param fieldIndex the index of the field to be updated in entry |
637 |
* @param newValue the new value to be set |
638 |
*/ |
639 |
private void updateField(PushRegEntry entry, String property, |
640 |
int fieldIndex, String newValue) { |
641 |
if (!entry.fields[fieldIndex].equals(newValue)) { |
642 |
entry.fields[fieldIndex] = newValue; |
643 |
setDirty(true); |
644 |
tableViewer.update(entry, new String[] { property }); |
645 |
} |
646 |
} |
647 |
} |
648 |
|
649 |
/** |
650 |
* A cell editor implementation that allows for selection of a midlet class. |
651 |
*/ |
652 |
private class MidletCellEditor extends DialogCellEditor { |
653 |
/** Construct a new cell editor */ |
654 |
MidletCellEditor(Composite parent) { |
655 |
super(parent); |
656 |
} |
657 |
|
658 |
/* (non-Javadoc) |
659 |
* @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control) |
660 |
*/ |
661 |
@Override |
662 |
protected Object openDialogBox(Control cellEditorWindow) { |
663 |
Object value = null; |
664 |
|
665 |
try { |
666 |
IJavaProject javaProject = getJavaProject(); |
667 |
SelectionDialog dialog = MidletSelectionDialogCreator |
668 |
.createMidletSelectionDialog( |
669 |
cellEditorWindow.getShell(), |
670 |
getSite().getPage().getWorkbenchWindow(), |
671 |
javaProject, |
672 |
false, |
673 |
MTJUIMessages.JADPushRegistryEditorPage_choose_MIDlet); |
674 |
|
675 |
if (dialog.open() == Window.OK) { |
676 |
Object[] results = dialog.getResult(); |
677 |
if ((results != null) && (results.length > 0)) { |
678 |
IType type = (IType) results[0]; |
679 |
if (type != null) { |
680 |
value = type.getFullyQualifiedName(); |
681 |
} |
682 |
} |
683 |
} |
684 |
} catch (JavaModelException e) { |
685 |
MTJLogger.log(IStatus.ERROR, "openDialogBox", e); //$NON-NLS-1$ |
686 |
} |
687 |
|
688 |
return value; |
689 |
} |
690 |
} |
691 |
|
692 |
/** |
693 |
* Implementation of the table's content provider. |
694 |
*/ |
695 |
private class TableContentProvider implements IStructuredContentProvider { |
696 |
|
697 |
/* (non-Javadoc) |
698 |
* @see org.eclipse.jface.viewers.IContentProvider#dispose() |
699 |
*/ |
700 |
public void dispose() { |
701 |
} |
702 |
|
703 |
/* (non-Javadoc) |
704 |
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
705 |
*/ |
706 |
public Object[] getElements(Object inputElement) { |
707 |
return pushRegEntries.toArray(new Object[pushRegEntries.size()]); |
708 |
} |
709 |
|
710 |
/* (non-Javadoc) |
711 |
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) |
712 |
*/ |
713 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
714 |
} |
715 |
} |
716 |
|
717 |
/** |
718 |
* Implementation of the table's label provider. |
719 |
*/ |
720 |
private static class TableLabelProvider extends LabelProvider implements |
721 |
ITableLabelProvider { |
722 |
|
723 |
/* (non-Javadoc) |
724 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) |
725 |
*/ |
726 |
public Image getColumnImage(Object element, int columnIndex) { |
727 |
return null; |
728 |
} |
729 |
|
730 |
/* (non-Javadoc) |
731 |
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) |
732 |
*/ |
733 |
public String getColumnText(Object element, int columnIndex) { |
734 |
return ((PushRegEntry) element).fields[columnIndex]; |
735 |
} |
736 |
} |
737 |
|
738 |
static class PushRegEntry { |
739 |
public String[] fields; |
740 |
|
741 |
PushRegEntry(String entryString) { |
742 |
fields = new String[3]; |
743 |
String[] tokens = entryString.split(","); //$NON-NLS-1$ |
744 |
|
745 |
for (int i = 0; i < 3; i++) { |
746 |
fields[i] = (i > tokens.length) ? Utils.EMPTY_STRING |
747 |
: tokens[i]; |
748 |
} |
749 |
} |
750 |
|
751 |
PushRegEntry(String connStr, String className, String allowedSender) { |
752 |
fields = new String[3]; |
753 |
|
754 |
fields[0] = connStr; |
755 |
fields[1] = className; |
756 |
fields[2] = allowedSender; |
757 |
} |
758 |
|
759 |
/* (non-Javadoc) |
760 |
* @see java.lang.Object#toString() |
761 |
*/ |
762 |
@Override |
763 |
public String toString() { |
764 |
StringBuffer sb = new StringBuffer(); |
765 |
if (fields != null) { |
766 |
for (int i = 0; i < fields.length; i++) { |
767 |
if (i != 0) { |
768 |
sb.append(","); //$NON-NLS-1$ |
769 |
} |
770 |
sb.append(fields[i]); |
771 |
} |
772 |
} |
773 |
return sb.toString(); |
774 |
} |
775 |
|
91 |
} |
776 |
} |
92 |
} |
777 |
} |