KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > product > LauncherSection


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.product;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.resources.IWorkspaceRoot;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.jface.dialogs.MessageDialog;
20 import org.eclipse.jface.window.Window;
21 import org.eclipse.pde.core.IModelChangedEvent;
22 import org.eclipse.pde.core.plugin.TargetPlatform;
23 import org.eclipse.pde.internal.core.iproduct.ILauncherInfo;
24 import org.eclipse.pde.internal.core.iproduct.IProduct;
25 import org.eclipse.pde.internal.core.iproduct.IProductModel;
26 import org.eclipse.pde.internal.ui.PDEPlugin;
27 import org.eclipse.pde.internal.ui.PDEPluginImages;
28 import org.eclipse.pde.internal.ui.PDEUIMessages;
29 import org.eclipse.pde.internal.ui.editor.EditorUtilities;
30 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
31 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
32 import org.eclipse.pde.internal.ui.editor.PDEFormPage;
33 import org.eclipse.pde.internal.ui.editor.PDESection;
34 import org.eclipse.pde.internal.ui.editor.validation.TextValidator;
35 import org.eclipse.pde.internal.ui.parts.FormEntry;
36 import org.eclipse.pde.internal.ui.util.FileExtensionFilter;
37 import org.eclipse.pde.internal.ui.util.FileValidator;
38 import org.eclipse.swt.SWT;
39 import org.eclipse.swt.custom.CTabFolder;
40 import org.eclipse.swt.custom.CTabItem;
41 import org.eclipse.swt.custom.StackLayout;
42 import org.eclipse.swt.dnd.Clipboard;
43 import org.eclipse.swt.events.ModifyEvent;
44 import org.eclipse.swt.events.ModifyListener;
45 import org.eclipse.swt.events.SelectionAdapter;
46 import org.eclipse.swt.events.SelectionEvent;
47 import org.eclipse.swt.graphics.Color;
48 import org.eclipse.swt.layout.GridData;
49 import org.eclipse.swt.layout.GridLayout;
50 import org.eclipse.swt.widgets.Button;
51 import org.eclipse.swt.widgets.Composite;
52 import org.eclipse.swt.widgets.Control;
53 import org.eclipse.swt.widgets.Display;
54 import org.eclipse.swt.widgets.Label;
55 import org.eclipse.swt.widgets.Layout;
56 import org.eclipse.swt.widgets.Text;
57 import org.eclipse.ui.IActionBars;
58 import org.eclipse.ui.PartInitException;
59 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
60 import org.eclipse.ui.forms.IFormColors;
61 import org.eclipse.ui.forms.events.HyperlinkEvent;
62 import org.eclipse.ui.forms.widgets.FormToolkit;
63 import org.eclipse.ui.forms.widgets.Section;
64 import org.eclipse.ui.forms.widgets.TableWrapData;
65 import org.eclipse.ui.forms.widgets.TableWrapLayout;
66 import org.eclipse.ui.ide.IDE;
67 import org.eclipse.ui.model.WorkbenchContentProvider;
68 import org.eclipse.ui.model.WorkbenchLabelProvider;
69
70
71 public class LauncherSection extends PDESection {
72     
73     private TextValidator[] fMultipleWinIconValidator;
74     
75     private TextValidator fSingleWinIconValidator;
76     
77     private static final String JavaDoc[] F_WIN_ICON_LABELS = new String JavaDoc[] {
78         PDEUIMessages.LauncherSection_Low16,
79         PDEUIMessages.LauncherSection_High16,
80         PDEUIMessages.LauncherSection_32Low,
81         PDEUIMessages.LauncherSection_32High,
82         PDEUIMessages.LauncherSection_48Low,
83         PDEUIMessages.LauncherSection_48High
84     };
85     public static final int[] F_WIN_ICON_DEPTHS = new int[] {
86         8, 32, 8, 32, 8, 32
87     };
88     public static final int[][] F_WIN_ICON_DIMENSIONS = new int[][] {
89         {16, 16}, {16, 16}, {32, 32}, {32, 32}, {48, 48}, {48, 48}
90     };
91     private static final String JavaDoc[] F_WIN_ICON_IDS = new String JavaDoc[] {
92         ILauncherInfo.WIN32_16_LOW,
93         ILauncherInfo.WIN32_16_HIGH,
94         ILauncherInfo.WIN32_32_LOW,
95         ILauncherInfo.WIN32_32_HIGH,
96         ILauncherInfo.WIN32_48_LOW,
97         ILauncherInfo.WIN32_48_HIGH
98     };
99     
100     private FormEntry fNameEntry;
101     private ArrayList JavaDoc fIcons = new ArrayList JavaDoc();
102     private Button fIcoButton;
103     private Button fBmpButton;
104     private CTabFolder fTabFolder;
105     private Composite fNotebook;
106     private StackLayout fNotebookLayout;
107     private Composite fLinuxSection;
108     private Composite fMacSection;
109     private Composite fSolarisSection;
110     private Composite fWin32Section;
111     
112
113     class IconEntry extends FormEntry {
114         String JavaDoc fIconId;
115         public IconEntry(Composite parent, FormToolkit toolkit, String JavaDoc labelText, String JavaDoc iconId) {
116             super(parent, toolkit, labelText, PDEUIMessages.LauncherSection_browse, isEditable(), 20);
117             fIconId = iconId;
118             addEntryFormListener();
119             setEditable(isEditable());
120         }
121         private void addEntryFormListener() {
122             IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars();
123             setFormEntryListener(new FormEntryAdapter(LauncherSection.this, actionBars) {
124                 public void textValueChanged(FormEntry entry) {
125                     getLauncherInfo().setIconPath(fIconId, entry.getValue());
126                 }
127                 public void browseButtonSelected(FormEntry entry) {
128                     handleBrowse((IconEntry)entry);
129                 }
130                 public void linkActivated(HyperlinkEvent e) {
131                     openImage(IconEntry.this.getValue());
132                 }
133             });
134         }
135         public String JavaDoc getIconId() {
136             return fIconId;
137         }
138     }
139
140     public LauncherSection(PDEFormPage page, Composite parent) {
141         super(page, parent, Section.DESCRIPTION);
142         createClient(getSection(), page.getEditor().getToolkit());
143     }
144
145     /* (non-Javadoc)
146      * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
147      */

148     public void createClient(Section section, FormToolkit toolkit) {
149         
150         section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
151         GridData data = new GridData(GridData.FILL_HORIZONTAL|GridData.VERTICAL_ALIGN_BEGINNING);
152         section.setLayoutData(data);
153         
154         section.setText(PDEUIMessages.LauncherSection_title);
155         section.setDescription(PDEUIMessages.LauncherSection_desc);
156         
157         Composite container = toolkit.createComposite(section);
158         GridLayout layout = FormLayoutFactory.createSectionClientGridLayout(false, 2);
159         layout.verticalSpacing = 10;
160         container.setLayout(layout);
161         container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
162
163         IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars();
164         fNameEntry = new FormEntry(container, toolkit, PDEUIMessages.LauncherSection_launcherName, null, false);
165         fNameEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) {
166             public void textValueChanged(FormEntry entry) {
167                 getLauncherInfo().setLauncherName(entry.getValue());
168             }
169         });
170         
171         createLabel(container, toolkit, PDEUIMessages.LauncherSection_label, 2);
172         
173         fTabFolder = new CTabFolder(container, SWT.FLAT | SWT.TOP);
174         toolkit.adapt(fTabFolder, true, true);
175         GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
176         gd.heightHint = 2;
177         gd.horizontalSpan = 2;
178         fTabFolder.setLayoutData(gd);
179         
180         toolkit.getColors().initializeSectionToolBarColors();
181         Color selectedColor = toolkit.getColors().getColor(IFormColors.TB_BG);
182         fTabFolder.setSelectionBackground(new Color[] {selectedColor,
183                 toolkit.getColors().getBackground()}, new int[] {100}, true);
184
185         fTabFolder.addSelectionListener(new SelectionAdapter() {
186             public void widgetSelected(SelectionEvent e) {
187                 updateTabSelection();
188             }
189         });
190         fTabFolder.setUnselectedImageVisible(false);
191
192         fNotebook = toolkit.createComposite(container);
193         gd = new GridData(GridData.FILL_BOTH);
194         gd.horizontalSpan = 2;
195         fNotebook.setLayoutData(gd);
196         fNotebookLayout = new StackLayout();
197         fNotebook.setLayout(fNotebookLayout);
198
199         fLinuxSection = addLinuxSection(fNotebook, toolkit);
200         fMacSection = addMacSection(fNotebook, toolkit);
201         fSolarisSection = addSolarisSection(fNotebook, toolkit);
202         fWin32Section = addWin32Section(fNotebook, toolkit);
203         
204         createTabs();
205         
206         toolkit.paintBordersFor(container);
207         section.setClient(container);
208         // Register to be notified when the model changes
209
getModel().addModelChangedListener(this);
210     }
211     
212     /* (non-Javadoc)
213      * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
214      */

215     public void dispose() {
216         IProductModel model = getModel();
217         if (model != null) {
218             model.removeModelChangedListener(this);
219         }
220         super.dispose();
221     }
222     
223     private void createTabs() {
224         addTab("linux"); //$NON-NLS-1$
225
addTab("macosx"); //$NON-NLS-1$
226
addTab("solaris"); //$NON-NLS-1$
227
addTab("win32"); //$NON-NLS-1$
228

229         String JavaDoc currentTarget = TargetPlatform.getOS();
230         if ("win32".equals(currentTarget)) { //$NON-NLS-1$
231
fTabFolder.setSelection(3);
232             fNotebookLayout.topControl = fWin32Section;
233         } else if ("macosx".equals(currentTarget)) { //$NON-NLS-1$
234
fTabFolder.setSelection(1);
235             fNotebookLayout.topControl = fMacSection;
236         } else if ("solaris".equals(currentTarget)) { //$NON-NLS-1$
237
fTabFolder.setSelection(2);
238             fNotebookLayout.topControl = fSolarisSection;
239         } else {
240             fTabFolder.setSelection(0);
241             fNotebookLayout.topControl = fLinuxSection;
242         }
243     }
244     
245     private void addTab(String JavaDoc label) {
246         CTabItem item = new CTabItem(fTabFolder, SWT.NULL);
247         item.setText(label);
248         item.setImage(PDEPlugin.getDefault().getLabelProvider().get(
249                 PDEPluginImages.DESC_OPERATING_SYSTEM_OBJ));
250     }
251     
252     private Composite addWin32Section(Composite parent, FormToolkit toolkit) {
253         Composite comp = createComposite(parent, toolkit);
254         
255         fBmpButton = toolkit.createButton(comp, PDEUIMessages.LauncherSection_bmpImages, SWT.RADIO);
256         TableWrapData td = new TableWrapData();
257         td.colspan = 3;
258         fBmpButton.setLayoutData(td);
259         fBmpButton.setEnabled(isEditable());
260         // Store all win icon validators
261
fMultipleWinIconValidator = new TextValidator[F_WIN_ICON_LABELS.length];
262         for (int i = 0; i < F_WIN_ICON_LABELS.length; i++) {
263             final IconEntry ientry = new IconEntry(comp, toolkit, F_WIN_ICON_LABELS[i], F_WIN_ICON_IDS[i]);
264             final int index = i;
265             // Create validator
266
fMultipleWinIconValidator[index] = new TextValidator(
267                     getManagedForm(), ientry.getText(), getProject(), true) {
268                 protected boolean validateControl() {
269                     return validateMultipleWinIcon(ientry, index);
270                 }
271             };
272             // Disable initially
273
fMultipleWinIconValidator[index].setEnabled(false);
274             // Validate on modify
275
ientry.getText().addModifyListener(new ModifyListener() {
276                 public void modifyText(ModifyEvent e) {
277                     fMultipleWinIconValidator[index].validate();
278                 }
279             });
280             
281             fIcons.add(ientry);
282         }
283         
284         fIcoButton = toolkit.createButton(comp, PDEUIMessages.LauncherSection_ico, SWT.RADIO);
285         td = new TableWrapData();
286         td.colspan = 3;
287         fIcoButton.setLayoutData(td);
288         fIcoButton.addSelectionListener(new SelectionAdapter() {
289             public void widgetSelected(SelectionEvent e) {
290                 boolean selected = fIcoButton.getSelection();
291                 getLauncherInfo().setUseWinIcoFile(selected);
292                 updateWinEntries(selected);
293             }
294         });
295         fIcoButton.setEnabled(isEditable());
296         
297         final IconEntry ientry = new IconEntry(comp, toolkit, PDEUIMessages.LauncherSection_file, ILauncherInfo.P_ICO_PATH);
298         // Create validator
299
fSingleWinIconValidator = new TextValidator(getManagedForm(),
300                 ientry.getText(), getProject(), true) {
301             protected boolean validateControl() {
302                 return validateSingleWinIcon(ientry);
303             }
304         };
305         // Disable initially
306
fSingleWinIconValidator.setEnabled(false);
307
308         fIcons.add(ientry);
309         
310         toolkit.paintBordersFor(comp);
311         return comp;
312     }
313     
314     /**
315      * @param ientry
316      * @return
317      */

318     private boolean validateSingleWinIcon(IconEntry ientry) {
319         return EditorUtilities.imageEntryHasValidIco(
320                 fSingleWinIconValidator, ientry, getProduct());
321     }
322     
323     /**
324      * @param ientry
325      * @param index
326      * @return
327      */

328     private boolean validateMultipleWinIcon(IconEntry ientry, int index) {
329         return EditorUtilities.imageEntryHasExactDepthAndSize(
330                 fMultipleWinIconValidator[index],
331                 ientry,
332                 getProduct(),
333                 F_WIN_ICON_DIMENSIONS[index][0],
334                 F_WIN_ICON_DIMENSIONS[index][1],
335                 F_WIN_ICON_DEPTHS[index]);
336     }
337     
338     private void createLabel(Composite parent, FormToolkit toolkit, String JavaDoc text, int span) {
339         Label label = toolkit.createLabel(parent, text, SWT.WRAP);
340         Layout layout = parent.getLayout();
341         if (layout instanceof GridLayout) {
342             GridData gd = new GridData();
343             gd.horizontalSpan = span;
344             label.setLayoutData(gd);
345         }
346         else if (layout instanceof TableWrapLayout) {
347             TableWrapData td = new TableWrapData();
348             td.colspan = span;
349             label.setLayoutData(td);
350         }
351     }
352     
353     private Composite addLinuxSection(Composite parent, FormToolkit toolkit) {
354         Composite comp = createComposite(parent, toolkit);
355         createLabel(comp, toolkit, PDEUIMessages.LauncherSection_linuxLabel, 3);
356         fIcons.add(new IconEntry(comp, toolkit, PDEUIMessages.LauncherSection_icon, ILauncherInfo.LINUX_ICON));
357         toolkit.paintBordersFor(comp);
358         return comp;
359     }
360
361     private Composite addSolarisSection(Composite parent, FormToolkit toolkit) {
362         Composite comp = createComposite(parent, toolkit);
363         createLabel(comp, toolkit, PDEUIMessages.LauncherSection_solarisLabel, 3);
364
365         fIcons.add(new IconEntry(comp, toolkit, PDEUIMessages.LauncherSection_large, ILauncherInfo.SOLARIS_LARGE));
366         fIcons.add(new IconEntry(comp, toolkit, PDEUIMessages.LauncherSection_medium, ILauncherInfo.SOLARIS_MEDIUM));
367         fIcons.add(new IconEntry(comp, toolkit, PDEUIMessages.LauncherSection_small, ILauncherInfo.SOLARIS_SMALL));
368         fIcons.add(new IconEntry(comp, toolkit, PDEUIMessages.LauncherSection_tiny, ILauncherInfo.SOLARIS_TINY));
369         
370         toolkit.paintBordersFor(comp);
371         return comp;
372     }
373     
374     private Composite addMacSection(Composite parent, FormToolkit toolkit) {
375         Composite comp = createComposite(parent, toolkit);
376         createLabel(comp, toolkit, PDEUIMessages.LauncherSection_macLabel, 3);
377         fIcons.add(new IconEntry(comp, toolkit, PDEUIMessages.LauncherSection_file, ILauncherInfo.MACOSX_ICON));
378         toolkit.paintBordersFor(comp);
379         return comp;
380     }
381     
382     private Composite createComposite(Composite parent, FormToolkit toolkit) {
383         Composite comp = toolkit.createComposite(parent);
384         TableWrapLayout layout = new TableWrapLayout();
385         layout.bottomMargin = layout.topMargin = layout.leftMargin = layout.rightMargin = 0;
386         layout.numColumns = 3;
387         comp.setLayout(layout);
388         return comp;
389     }
390     
391     public void refresh() {
392         ILauncherInfo info = getLauncherInfo();
393         fNameEntry.setValue(info.getLauncherName(), true);
394         boolean useIco = info.usesWinIcoFile();
395         fIcoButton.setSelection(useIco);
396         fBmpButton.setSelection(!useIco);
397         
398         // Turn off auto message update until after values are set
399
fSingleWinIconValidator.setRefresh(false);
400         for (int i = 0; i < fIcons.size(); i++) {
401             IconEntry entry = (IconEntry)fIcons.get(i);
402             entry.setValue(info.getIconPath(entry.getIconId()), true);
403         }
404         // Turn back on auto message update
405
fSingleWinIconValidator.setRefresh(true);
406         
407         updateWinEntries(useIco);
408         
409         super.refresh();
410     }
411     
412     private void updateWinEntries(boolean useIco) {
413         for (int i = 0; i < fIcons.size(); i++) {
414             IconEntry entry = (IconEntry)fIcons.get(i);
415             String JavaDoc id = entry.getIconId();
416             if (id.equals(ILauncherInfo.P_ICO_PATH)) {
417                 boolean enabled = isEditable() && useIco;
418                 entry.setEditable(enabled);
419             } else if (id.equals(ILauncherInfo.WIN32_16_HIGH)
420                     || id.equals(ILauncherInfo.WIN32_16_LOW)
421                     || id.equals(ILauncherInfo.WIN32_32_HIGH)
422                     || id.equals(ILauncherInfo.WIN32_32_LOW)
423                     || id.equals(ILauncherInfo.WIN32_48_HIGH)
424                     || id.equals(ILauncherInfo.WIN32_48_LOW)) {
425                 entry.setEditable(isEditable() && !useIco);
426             }
427         }
428         // Update validators
429
updateWinEntryValidators(useIco);
430     }
431     
432     /**
433      * @param useIco
434      */

435     private void updateWinEntryValidators(boolean useIco) {
436         // Turn off auto message update until after values are set
437
fSingleWinIconValidator.setRefresh(false);
438         // Update validator
439
fSingleWinIconValidator.setEnabled(isEditable() && useIco);
440         // Update validators
441
for (int i = 0; i < fMultipleWinIconValidator.length; i++) {
442             fMultipleWinIconValidator[i].setEnabled(isEditable() && !useIco);
443         }
444         // Turn back on auto message update
445
fSingleWinIconValidator.setRefresh(true);
446     }
447
448     private ILauncherInfo getLauncherInfo() {
449         ILauncherInfo info = getProduct().getLauncherInfo();
450         if (info == null) {
451             info = getModel().getFactory().createLauncherInfo();
452             getProduct().setLauncherInfo(info);
453         }
454         return info;
455     }
456     
457     private IProduct getProduct() {
458         return getModel().getProduct();
459     }
460     
461     private IProductModel getModel() {
462         return (IProductModel)getPage().getPDEEditor().getAggregateModel();
463     }
464     
465     public void commit(boolean onSave) {
466         fNameEntry.commit();
467         for (int i = 0; i < fIcons.size(); i++)
468             ((FormEntry)fIcons.get(i)).commit();
469         super.commit(onSave);
470     }
471     
472     public void cancelEdit() {
473         fNameEntry.cancelEdit();
474         for (int i = 0; i < fIcons.size(); i++)
475             ((FormEntry)fIcons.get(i)).commit();
476         super.cancelEdit();
477     }
478     
479     private void handleBrowse(IconEntry entry) {
480         ElementTreeSelectionDialog dialog =
481             new ElementTreeSelectionDialog(
482                 getSection().getShell(),
483                 new WorkbenchLabelProvider(),
484                 new WorkbenchContentProvider());
485                 
486         dialog.setValidator(new FileValidator());
487         dialog.setAllowMultiple(false);
488         dialog.setTitle(PDEUIMessages.LauncherSection_dialogTitle);
489         String JavaDoc extension = getExtension(entry.getIconId());
490         dialog.setMessage(PDEUIMessages.LauncherSection_dialogMessage);
491         dialog.addFilter(new FileExtensionFilter(extension));
492         dialog.setInput(PDEPlugin.getWorkspace().getRoot());
493
494         if (dialog.open() == Window.OK) {
495             IFile file = (IFile)dialog.getFirstResult();
496             entry.setValue(file.getFullPath().toString());
497         }
498     }
499     
500     private void openImage(String JavaDoc value) {
501         IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot();
502         Path path = new Path(value);
503         if(path.isEmpty()){
504             MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.WindowImagesSection_emptyPath); //
505
return;
506         }
507         IResource resource = root.findMember(new Path(value));
508         try {
509             if (resource != null && resource instanceof IFile)
510                 IDE.openEditor(PDEPlugin.getActivePage(), (IFile)resource, true);
511             else
512                 MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(), PDEUIMessages.WindowImagesSection_open, PDEUIMessages.WindowImagesSection_warning); //
513
} catch (PartInitException e) {
514         }
515     }
516
517     private String JavaDoc getExtension(String JavaDoc iconId) {
518         if (iconId.equals(ILauncherInfo.LINUX_ICON))
519             return "xpm"; //$NON-NLS-1$
520
if (iconId.equals(ILauncherInfo.MACOSX_ICON))
521             return "icns"; //$NON-NLS-1$
522
if (iconId.equals(ILauncherInfo.SOLARIS_LARGE))
523             return "l.pm"; //$NON-NLS-1$
524
if (iconId.equals(ILauncherInfo.SOLARIS_MEDIUM))
525             return "m.pm"; //$NON-NLS-1$
526
if (iconId.equals(ILauncherInfo.SOLARIS_SMALL))
527             return "s.pm"; //$NON-NLS-1$
528
if (iconId.equals(ILauncherInfo.SOLARIS_TINY))
529             return "t.pm"; //$NON-NLS-1$
530
if (iconId.equals(ILauncherInfo.P_ICO_PATH))
531             return "ico"; //$NON-NLS-1$
532
return "bmp"; //$NON-NLS-1$
533
}
534     
535     public boolean canPaste(Clipboard clipboard) {
536         Display d = getSection().getDisplay();
537         return (d.getFocusControl() instanceof Text);
538     }
539
540     private void updateTabSelection() {
541         int index = fTabFolder.getSelectionIndex();
542         Control oldPage = fNotebookLayout.topControl;
543         switch (index) {
544         case 0:
545             fNotebookLayout.topControl = fLinuxSection;
546             break;
547         case 1:
548             fNotebookLayout.topControl = fMacSection;
549             break;
550         case 2:
551             fNotebookLayout.topControl = fSolarisSection;
552             break;
553         case 3:
554             fNotebookLayout.topControl = fWin32Section;
555             break;
556         }
557         if (oldPage != fNotebookLayout.topControl)
558             fNotebook.layout();
559     }
560     
561     /* (non-Javadoc)
562      * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
563      */

564     public void modelChanged(IModelChangedEvent e) {
565         // No need to call super, handling world changed event here
566
if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
567             handleModelEventWorldChanged(e);
568         }
569     }
570
571     /**
572      * @param event
573      */

574     private void handleModelEventWorldChanged(IModelChangedEvent event) {
575         refresh();
576         // Note: A deferred selection event is fired from radio buttons when
577
// their value is toggled, the user switches to another page, and the
578
// user switches back to the same page containing the radio buttons
579
// This appears to be a result of a SWT bug.
580
// If the radio button is the last widget to have focus when leaving
581
// the page, an event will be fired when entering the page again.
582
// An event is not fired if the radio button does not have focus.
583
// The solution is to redirect focus to a stable widget.
584
getPage().setLastFocusControl(fNameEntry.getText());
585     }
586 }
587
Popular Tags