001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.product;
011:
012: import java.util.ArrayList;
013:
014: import org.eclipse.core.resources.IFile;
015: import org.eclipse.core.resources.IResource;
016: import org.eclipse.core.resources.IWorkspaceRoot;
017: import org.eclipse.core.runtime.Path;
018: import org.eclipse.jface.dialogs.MessageDialog;
019: import org.eclipse.jface.window.Window;
020: import org.eclipse.pde.core.IModelChangedEvent;
021: import org.eclipse.pde.core.plugin.TargetPlatform;
022: import org.eclipse.pde.internal.core.iproduct.ILauncherInfo;
023: import org.eclipse.pde.internal.core.iproduct.IProduct;
024: import org.eclipse.pde.internal.core.iproduct.IProductModel;
025: import org.eclipse.pde.internal.ui.PDEPlugin;
026: import org.eclipse.pde.internal.ui.PDEPluginImages;
027: import org.eclipse.pde.internal.ui.PDEUIMessages;
028: import org.eclipse.pde.internal.ui.editor.EditorUtilities;
029: import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
030: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
031: import org.eclipse.pde.internal.ui.editor.PDEFormPage;
032: import org.eclipse.pde.internal.ui.editor.PDESection;
033: import org.eclipse.pde.internal.ui.editor.validation.TextValidator;
034: import org.eclipse.pde.internal.ui.parts.FormEntry;
035: import org.eclipse.pde.internal.ui.util.FileExtensionFilter;
036: import org.eclipse.pde.internal.ui.util.FileValidator;
037: import org.eclipse.swt.SWT;
038: import org.eclipse.swt.custom.CTabFolder;
039: import org.eclipse.swt.custom.CTabItem;
040: import org.eclipse.swt.custom.StackLayout;
041: import org.eclipse.swt.dnd.Clipboard;
042: import org.eclipse.swt.events.ModifyEvent;
043: import org.eclipse.swt.events.ModifyListener;
044: import org.eclipse.swt.events.SelectionAdapter;
045: import org.eclipse.swt.events.SelectionEvent;
046: import org.eclipse.swt.graphics.Color;
047: import org.eclipse.swt.layout.GridData;
048: import org.eclipse.swt.layout.GridLayout;
049: import org.eclipse.swt.widgets.Button;
050: import org.eclipse.swt.widgets.Composite;
051: import org.eclipse.swt.widgets.Control;
052: import org.eclipse.swt.widgets.Display;
053: import org.eclipse.swt.widgets.Label;
054: import org.eclipse.swt.widgets.Layout;
055: import org.eclipse.swt.widgets.Text;
056: import org.eclipse.ui.IActionBars;
057: import org.eclipse.ui.PartInitException;
058: import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
059: import org.eclipse.ui.forms.IFormColors;
060: import org.eclipse.ui.forms.events.HyperlinkEvent;
061: import org.eclipse.ui.forms.widgets.FormToolkit;
062: import org.eclipse.ui.forms.widgets.Section;
063: import org.eclipse.ui.forms.widgets.TableWrapData;
064: import org.eclipse.ui.forms.widgets.TableWrapLayout;
065: import org.eclipse.ui.ide.IDE;
066: import org.eclipse.ui.model.WorkbenchContentProvider;
067: import org.eclipse.ui.model.WorkbenchLabelProvider;
068:
069: public class LauncherSection extends PDESection {
070:
071: private TextValidator[] fMultipleWinIconValidator;
072:
073: private TextValidator fSingleWinIconValidator;
074:
075: private static final String[] F_WIN_ICON_LABELS = new String[] {
076: PDEUIMessages.LauncherSection_Low16,
077: PDEUIMessages.LauncherSection_High16,
078: PDEUIMessages.LauncherSection_32Low,
079: PDEUIMessages.LauncherSection_32High,
080: PDEUIMessages.LauncherSection_48Low,
081: PDEUIMessages.LauncherSection_48High };
082: public static final int[] F_WIN_ICON_DEPTHS = new int[] { 8, 32, 8,
083: 32, 8, 32 };
084: public static final int[][] F_WIN_ICON_DIMENSIONS = new int[][] {
085: { 16, 16 }, { 16, 16 }, { 32, 32 }, { 32, 32 }, { 48, 48 },
086: { 48, 48 } };
087: private static final String[] F_WIN_ICON_IDS = new String[] {
088: ILauncherInfo.WIN32_16_LOW, ILauncherInfo.WIN32_16_HIGH,
089: ILauncherInfo.WIN32_32_LOW, ILauncherInfo.WIN32_32_HIGH,
090: ILauncherInfo.WIN32_48_LOW, ILauncherInfo.WIN32_48_HIGH };
091:
092: private FormEntry fNameEntry;
093: private ArrayList fIcons = new ArrayList();
094: private Button fIcoButton;
095: private Button fBmpButton;
096: private CTabFolder fTabFolder;
097: private Composite fNotebook;
098: private StackLayout fNotebookLayout;
099: private Composite fLinuxSection;
100: private Composite fMacSection;
101: private Composite fSolarisSection;
102: private Composite fWin32Section;
103:
104: class IconEntry extends FormEntry {
105: String fIconId;
106:
107: public IconEntry(Composite parent, FormToolkit toolkit,
108: String labelText, String iconId) {
109: super (parent, toolkit, labelText,
110: PDEUIMessages.LauncherSection_browse, isEditable(),
111: 20);
112: fIconId = iconId;
113: addEntryFormListener();
114: setEditable(isEditable());
115: }
116:
117: private void addEntryFormListener() {
118: IActionBars actionBars = getPage().getPDEEditor()
119: .getEditorSite().getActionBars();
120: setFormEntryListener(new FormEntryAdapter(
121: LauncherSection.this , actionBars) {
122: public void textValueChanged(FormEntry entry) {
123: getLauncherInfo().setIconPath(fIconId,
124: entry.getValue());
125: }
126:
127: public void browseButtonSelected(FormEntry entry) {
128: handleBrowse((IconEntry) entry);
129: }
130:
131: public void linkActivated(HyperlinkEvent e) {
132: openImage(IconEntry.this .getValue());
133: }
134: });
135: }
136:
137: public String getIconId() {
138: return fIconId;
139: }
140: }
141:
142: public LauncherSection(PDEFormPage page, Composite parent) {
143: super (page, parent, Section.DESCRIPTION);
144: createClient(getSection(), page.getEditor().getToolkit());
145: }
146:
147: /* (non-Javadoc)
148: * @see org.eclipse.pde.internal.ui.editor.PDESection#createClient(org.eclipse.ui.forms.widgets.Section, org.eclipse.ui.forms.widgets.FormToolkit)
149: */
150: public void createClient(Section section, FormToolkit toolkit) {
151:
152: section.setLayout(FormLayoutFactory.createClearGridLayout(
153: false, 1));
154: GridData data = new GridData(GridData.FILL_HORIZONTAL
155: | GridData.VERTICAL_ALIGN_BEGINNING);
156: section.setLayoutData(data);
157:
158: section.setText(PDEUIMessages.LauncherSection_title);
159: section.setDescription(PDEUIMessages.LauncherSection_desc);
160:
161: Composite container = toolkit.createComposite(section);
162: GridLayout layout = FormLayoutFactory
163: .createSectionClientGridLayout(false, 2);
164: layout.verticalSpacing = 10;
165: container.setLayout(layout);
166: container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
167:
168: IActionBars actionBars = getPage().getPDEEditor()
169: .getEditorSite().getActionBars();
170: fNameEntry = new FormEntry(container, toolkit,
171: PDEUIMessages.LauncherSection_launcherName, null, false);
172: fNameEntry.setFormEntryListener(new FormEntryAdapter(this ,
173: actionBars) {
174: public void textValueChanged(FormEntry entry) {
175: getLauncherInfo().setLauncherName(entry.getValue());
176: }
177: });
178:
179: createLabel(container, toolkit,
180: PDEUIMessages.LauncherSection_label, 2);
181:
182: fTabFolder = new CTabFolder(container, SWT.FLAT | SWT.TOP);
183: toolkit.adapt(fTabFolder, true, true);
184: GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
185: gd.heightHint = 2;
186: gd.horizontalSpan = 2;
187: fTabFolder.setLayoutData(gd);
188:
189: toolkit.getColors().initializeSectionToolBarColors();
190: Color selectedColor = toolkit.getColors().getColor(
191: IFormColors.TB_BG);
192: fTabFolder.setSelectionBackground(new Color[] { selectedColor,
193: toolkit.getColors().getBackground() },
194: new int[] { 100 }, true);
195:
196: fTabFolder.addSelectionListener(new SelectionAdapter() {
197: public void widgetSelected(SelectionEvent e) {
198: updateTabSelection();
199: }
200: });
201: fTabFolder.setUnselectedImageVisible(false);
202:
203: fNotebook = toolkit.createComposite(container);
204: gd = new GridData(GridData.FILL_BOTH);
205: gd.horizontalSpan = 2;
206: fNotebook.setLayoutData(gd);
207: fNotebookLayout = new StackLayout();
208: fNotebook.setLayout(fNotebookLayout);
209:
210: fLinuxSection = addLinuxSection(fNotebook, toolkit);
211: fMacSection = addMacSection(fNotebook, toolkit);
212: fSolarisSection = addSolarisSection(fNotebook, toolkit);
213: fWin32Section = addWin32Section(fNotebook, toolkit);
214:
215: createTabs();
216:
217: toolkit.paintBordersFor(container);
218: section.setClient(container);
219: // Register to be notified when the model changes
220: getModel().addModelChangedListener(this );
221: }
222:
223: /* (non-Javadoc)
224: * @see org.eclipse.ui.forms.AbstractFormPart#dispose()
225: */
226: public void dispose() {
227: IProductModel model = getModel();
228: if (model != null) {
229: model.removeModelChangedListener(this );
230: }
231: super .dispose();
232: }
233:
234: private void createTabs() {
235: addTab("linux"); //$NON-NLS-1$
236: addTab("macosx"); //$NON-NLS-1$
237: addTab("solaris"); //$NON-NLS-1$
238: addTab("win32"); //$NON-NLS-1$
239:
240: String currentTarget = TargetPlatform.getOS();
241: if ("win32".equals(currentTarget)) { //$NON-NLS-1$
242: fTabFolder.setSelection(3);
243: fNotebookLayout.topControl = fWin32Section;
244: } else if ("macosx".equals(currentTarget)) { //$NON-NLS-1$
245: fTabFolder.setSelection(1);
246: fNotebookLayout.topControl = fMacSection;
247: } else if ("solaris".equals(currentTarget)) { //$NON-NLS-1$
248: fTabFolder.setSelection(2);
249: fNotebookLayout.topControl = fSolarisSection;
250: } else {
251: fTabFolder.setSelection(0);
252: fNotebookLayout.topControl = fLinuxSection;
253: }
254: }
255:
256: private void addTab(String label) {
257: CTabItem item = new CTabItem(fTabFolder, SWT.NULL);
258: item.setText(label);
259: item.setImage(PDEPlugin.getDefault().getLabelProvider().get(
260: PDEPluginImages.DESC_OPERATING_SYSTEM_OBJ));
261: }
262:
263: private Composite addWin32Section(Composite parent,
264: FormToolkit toolkit) {
265: Composite comp = createComposite(parent, toolkit);
266:
267: fBmpButton = toolkit.createButton(comp,
268: PDEUIMessages.LauncherSection_bmpImages, SWT.RADIO);
269: TableWrapData td = new TableWrapData();
270: td.colspan = 3;
271: fBmpButton.setLayoutData(td);
272: fBmpButton.setEnabled(isEditable());
273: // Store all win icon validators
274: fMultipleWinIconValidator = new TextValidator[F_WIN_ICON_LABELS.length];
275: for (int i = 0; i < F_WIN_ICON_LABELS.length; i++) {
276: final IconEntry ientry = new IconEntry(comp, toolkit,
277: F_WIN_ICON_LABELS[i], F_WIN_ICON_IDS[i]);
278: final int index = i;
279: // Create validator
280: fMultipleWinIconValidator[index] = new TextValidator(
281: getManagedForm(), ientry.getText(), getProject(),
282: true) {
283: protected boolean validateControl() {
284: return validateMultipleWinIcon(ientry, index);
285: }
286: };
287: // Disable initially
288: fMultipleWinIconValidator[index].setEnabled(false);
289: // Validate on modify
290: ientry.getText().addModifyListener(new ModifyListener() {
291: public void modifyText(ModifyEvent e) {
292: fMultipleWinIconValidator[index].validate();
293: }
294: });
295:
296: fIcons.add(ientry);
297: }
298:
299: fIcoButton = toolkit.createButton(comp,
300: PDEUIMessages.LauncherSection_ico, SWT.RADIO);
301: td = new TableWrapData();
302: td.colspan = 3;
303: fIcoButton.setLayoutData(td);
304: fIcoButton.addSelectionListener(new SelectionAdapter() {
305: public void widgetSelected(SelectionEvent e) {
306: boolean selected = fIcoButton.getSelection();
307: getLauncherInfo().setUseWinIcoFile(selected);
308: updateWinEntries(selected);
309: }
310: });
311: fIcoButton.setEnabled(isEditable());
312:
313: final IconEntry ientry = new IconEntry(comp, toolkit,
314: PDEUIMessages.LauncherSection_file,
315: ILauncherInfo.P_ICO_PATH);
316: // Create validator
317: fSingleWinIconValidator = new TextValidator(getManagedForm(),
318: ientry.getText(), getProject(), true) {
319: protected boolean validateControl() {
320: return validateSingleWinIcon(ientry);
321: }
322: };
323: // Disable initially
324: fSingleWinIconValidator.setEnabled(false);
325:
326: fIcons.add(ientry);
327:
328: toolkit.paintBordersFor(comp);
329: return comp;
330: }
331:
332: /**
333: * @param ientry
334: * @return
335: */
336: private boolean validateSingleWinIcon(IconEntry ientry) {
337: return EditorUtilities.imageEntryHasValidIco(
338: fSingleWinIconValidator, ientry, getProduct());
339: }
340:
341: /**
342: * @param ientry
343: * @param index
344: * @return
345: */
346: private boolean validateMultipleWinIcon(IconEntry ientry, int index) {
347: return EditorUtilities.imageEntryHasExactDepthAndSize(
348: fMultipleWinIconValidator[index], ientry, getProduct(),
349: F_WIN_ICON_DIMENSIONS[index][0],
350: F_WIN_ICON_DIMENSIONS[index][1],
351: F_WIN_ICON_DEPTHS[index]);
352: }
353:
354: private void createLabel(Composite parent, FormToolkit toolkit,
355: String text, int span) {
356: Label label = toolkit.createLabel(parent, text, SWT.WRAP);
357: Layout layout = parent.getLayout();
358: if (layout instanceof GridLayout) {
359: GridData gd = new GridData();
360: gd.horizontalSpan = span;
361: label.setLayoutData(gd);
362: } else if (layout instanceof TableWrapLayout) {
363: TableWrapData td = new TableWrapData();
364: td.colspan = span;
365: label.setLayoutData(td);
366: }
367: }
368:
369: private Composite addLinuxSection(Composite parent,
370: FormToolkit toolkit) {
371: Composite comp = createComposite(parent, toolkit);
372: createLabel(comp, toolkit,
373: PDEUIMessages.LauncherSection_linuxLabel, 3);
374: fIcons.add(new IconEntry(comp, toolkit,
375: PDEUIMessages.LauncherSection_icon,
376: ILauncherInfo.LINUX_ICON));
377: toolkit.paintBordersFor(comp);
378: return comp;
379: }
380:
381: private Composite addSolarisSection(Composite parent,
382: FormToolkit toolkit) {
383: Composite comp = createComposite(parent, toolkit);
384: createLabel(comp, toolkit,
385: PDEUIMessages.LauncherSection_solarisLabel, 3);
386:
387: fIcons.add(new IconEntry(comp, toolkit,
388: PDEUIMessages.LauncherSection_large,
389: ILauncherInfo.SOLARIS_LARGE));
390: fIcons.add(new IconEntry(comp, toolkit,
391: PDEUIMessages.LauncherSection_medium,
392: ILauncherInfo.SOLARIS_MEDIUM));
393: fIcons.add(new IconEntry(comp, toolkit,
394: PDEUIMessages.LauncherSection_small,
395: ILauncherInfo.SOLARIS_SMALL));
396: fIcons.add(new IconEntry(comp, toolkit,
397: PDEUIMessages.LauncherSection_tiny,
398: ILauncherInfo.SOLARIS_TINY));
399:
400: toolkit.paintBordersFor(comp);
401: return comp;
402: }
403:
404: private Composite addMacSection(Composite parent,
405: FormToolkit toolkit) {
406: Composite comp = createComposite(parent, toolkit);
407: createLabel(comp, toolkit,
408: PDEUIMessages.LauncherSection_macLabel, 3);
409: fIcons.add(new IconEntry(comp, toolkit,
410: PDEUIMessages.LauncherSection_file,
411: ILauncherInfo.MACOSX_ICON));
412: toolkit.paintBordersFor(comp);
413: return comp;
414: }
415:
416: private Composite createComposite(Composite parent,
417: FormToolkit toolkit) {
418: Composite comp = toolkit.createComposite(parent);
419: TableWrapLayout layout = new TableWrapLayout();
420: layout.bottomMargin = layout.topMargin = layout.leftMargin = layout.rightMargin = 0;
421: layout.numColumns = 3;
422: comp.setLayout(layout);
423: return comp;
424: }
425:
426: public void refresh() {
427: ILauncherInfo info = getLauncherInfo();
428: fNameEntry.setValue(info.getLauncherName(), true);
429: boolean useIco = info.usesWinIcoFile();
430: fIcoButton.setSelection(useIco);
431: fBmpButton.setSelection(!useIco);
432:
433: // Turn off auto message update until after values are set
434: fSingleWinIconValidator.setRefresh(false);
435: for (int i = 0; i < fIcons.size(); i++) {
436: IconEntry entry = (IconEntry) fIcons.get(i);
437: entry.setValue(info.getIconPath(entry.getIconId()), true);
438: }
439: // Turn back on auto message update
440: fSingleWinIconValidator.setRefresh(true);
441:
442: updateWinEntries(useIco);
443:
444: super .refresh();
445: }
446:
447: private void updateWinEntries(boolean useIco) {
448: for (int i = 0; i < fIcons.size(); i++) {
449: IconEntry entry = (IconEntry) fIcons.get(i);
450: String id = entry.getIconId();
451: if (id.equals(ILauncherInfo.P_ICO_PATH)) {
452: boolean enabled = isEditable() && useIco;
453: entry.setEditable(enabled);
454: } else if (id.equals(ILauncherInfo.WIN32_16_HIGH)
455: || id.equals(ILauncherInfo.WIN32_16_LOW)
456: || id.equals(ILauncherInfo.WIN32_32_HIGH)
457: || id.equals(ILauncherInfo.WIN32_32_LOW)
458: || id.equals(ILauncherInfo.WIN32_48_HIGH)
459: || id.equals(ILauncherInfo.WIN32_48_LOW)) {
460: entry.setEditable(isEditable() && !useIco);
461: }
462: }
463: // Update validators
464: updateWinEntryValidators(useIco);
465: }
466:
467: /**
468: * @param useIco
469: */
470: private void updateWinEntryValidators(boolean useIco) {
471: // Turn off auto message update until after values are set
472: fSingleWinIconValidator.setRefresh(false);
473: // Update validator
474: fSingleWinIconValidator.setEnabled(isEditable() && useIco);
475: // Update validators
476: for (int i = 0; i < fMultipleWinIconValidator.length; i++) {
477: fMultipleWinIconValidator[i].setEnabled(isEditable()
478: && !useIco);
479: }
480: // Turn back on auto message update
481: fSingleWinIconValidator.setRefresh(true);
482: }
483:
484: private ILauncherInfo getLauncherInfo() {
485: ILauncherInfo info = getProduct().getLauncherInfo();
486: if (info == null) {
487: info = getModel().getFactory().createLauncherInfo();
488: getProduct().setLauncherInfo(info);
489: }
490: return info;
491: }
492:
493: private IProduct getProduct() {
494: return getModel().getProduct();
495: }
496:
497: private IProductModel getModel() {
498: return (IProductModel) getPage().getPDEEditor()
499: .getAggregateModel();
500: }
501:
502: public void commit(boolean onSave) {
503: fNameEntry.commit();
504: for (int i = 0; i < fIcons.size(); i++)
505: ((FormEntry) fIcons.get(i)).commit();
506: super .commit(onSave);
507: }
508:
509: public void cancelEdit() {
510: fNameEntry.cancelEdit();
511: for (int i = 0; i < fIcons.size(); i++)
512: ((FormEntry) fIcons.get(i)).commit();
513: super .cancelEdit();
514: }
515:
516: private void handleBrowse(IconEntry entry) {
517: ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(
518: getSection().getShell(), new WorkbenchLabelProvider(),
519: new WorkbenchContentProvider());
520:
521: dialog.setValidator(new FileValidator());
522: dialog.setAllowMultiple(false);
523: dialog.setTitle(PDEUIMessages.LauncherSection_dialogTitle);
524: String extension = getExtension(entry.getIconId());
525: dialog.setMessage(PDEUIMessages.LauncherSection_dialogMessage);
526: dialog.addFilter(new FileExtensionFilter(extension));
527: dialog.setInput(PDEPlugin.getWorkspace().getRoot());
528:
529: if (dialog.open() == Window.OK) {
530: IFile file = (IFile) dialog.getFirstResult();
531: entry.setValue(file.getFullPath().toString());
532: }
533: }
534:
535: private void openImage(String value) {
536: IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot();
537: Path path = new Path(value);
538: if (path.isEmpty()) {
539: MessageDialog.openWarning(PDEPlugin
540: .getActiveWorkbenchShell(),
541: PDEUIMessages.WindowImagesSection_open,
542: PDEUIMessages.WindowImagesSection_emptyPath); //
543: return;
544: }
545: IResource resource = root.findMember(new Path(value));
546: try {
547: if (resource != null && resource instanceof IFile)
548: IDE.openEditor(PDEPlugin.getActivePage(),
549: (IFile) resource, true);
550: else
551: MessageDialog.openWarning(PDEPlugin
552: .getActiveWorkbenchShell(),
553: PDEUIMessages.WindowImagesSection_open,
554: PDEUIMessages.WindowImagesSection_warning); //
555: } catch (PartInitException e) {
556: }
557: }
558:
559: private String getExtension(String iconId) {
560: if (iconId.equals(ILauncherInfo.LINUX_ICON))
561: return "xpm"; //$NON-NLS-1$
562: if (iconId.equals(ILauncherInfo.MACOSX_ICON))
563: return "icns"; //$NON-NLS-1$
564: if (iconId.equals(ILauncherInfo.SOLARIS_LARGE))
565: return "l.pm"; //$NON-NLS-1$
566: if (iconId.equals(ILauncherInfo.SOLARIS_MEDIUM))
567: return "m.pm"; //$NON-NLS-1$
568: if (iconId.equals(ILauncherInfo.SOLARIS_SMALL))
569: return "s.pm"; //$NON-NLS-1$
570: if (iconId.equals(ILauncherInfo.SOLARIS_TINY))
571: return "t.pm"; //$NON-NLS-1$
572: if (iconId.equals(ILauncherInfo.P_ICO_PATH))
573: return "ico"; //$NON-NLS-1$
574: return "bmp"; //$NON-NLS-1$
575: }
576:
577: public boolean canPaste(Clipboard clipboard) {
578: Display d = getSection().getDisplay();
579: return (d.getFocusControl() instanceof Text);
580: }
581:
582: private void updateTabSelection() {
583: int index = fTabFolder.getSelectionIndex();
584: Control oldPage = fNotebookLayout.topControl;
585: switch (index) {
586: case 0:
587: fNotebookLayout.topControl = fLinuxSection;
588: break;
589: case 1:
590: fNotebookLayout.topControl = fMacSection;
591: break;
592: case 2:
593: fNotebookLayout.topControl = fSolarisSection;
594: break;
595: case 3:
596: fNotebookLayout.topControl = fWin32Section;
597: break;
598: }
599: if (oldPage != fNotebookLayout.topControl)
600: fNotebook.layout();
601: }
602:
603: /* (non-Javadoc)
604: * @see org.eclipse.pde.internal.ui.editor.PDESection#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
605: */
606: public void modelChanged(IModelChangedEvent e) {
607: // No need to call super, handling world changed event here
608: if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
609: handleModelEventWorldChanged(e);
610: }
611: }
612:
613: /**
614: * @param event
615: */
616: private void handleModelEventWorldChanged(IModelChangedEvent event) {
617: refresh();
618: // Note: A deferred selection event is fired from radio buttons when
619: // their value is toggled, the user switches to another page, and the
620: // user switches back to the same page containing the radio buttons
621: // This appears to be a result of a SWT bug.
622: // If the radio button is the last widget to have focus when leaving
623: // the page, an event will be fired when entering the page again.
624: // An event is not fired if the radio button does not have focus.
625: // The solution is to redirect focus to a stable widget.
626: getPage().setLastFocusControl(fNameEntry.getText());
627: }
628: }
|