1 11 package org.eclipse.update.internal.ui.wizards; 12 13 import org.eclipse.jface.dialogs.Dialog; 14 import org.eclipse.jface.dialogs.IDialogSettings; 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.events.SelectionAdapter; 17 import org.eclipse.swt.events.SelectionEvent; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Button; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.swt.widgets.Control; 23 import org.eclipse.swt.widgets.Label; 24 import org.eclipse.ui.PlatformUI; 25 import org.eclipse.update.internal.operations.UpdateUtils; 26 import org.eclipse.update.internal.ui.UpdateUI; 27 import org.eclipse.update.internal.ui.UpdateUIMessages; 28 import org.eclipse.update.search.UpdateSearchRequest; 29 30 32 public class ModeSelectionPage extends BannerPage implements ISearchProvider { 33 private boolean updateMode=true; 34 private Button updatesButton; 35 private Button newFeaturesButton; 36 private UpdateSearchRequest searchRequest; 37 private static final String SECTION_ID = "ModeSelectionPage"; private static final String P_NEW_FEATURES_MODE = "new-features-mode"; 40 public ModeSelectionPage(UpdateSearchRequest searchRequest) { 41 super("modeSelection"); setTitle(UpdateUIMessages.ModeSelectionPage_title); 43 setDescription(UpdateUIMessages.ModeSelectionPage_desc); 44 this.searchRequest = searchRequest; 45 } 46 47 public UpdateSearchRequest getSearchRequest() { 48 initializeSearch(); 49 return searchRequest; 50 } 51 52 private IDialogSettings getSettings() { 53 IDialogSettings master = UpdateUI.getDefault().getDialogSettings(); 54 IDialogSettings section = master.getSection(SECTION_ID); 55 if (section==null) 56 section = master.addNewSection(SECTION_ID); 57 return section; 58 } 59 60 private void initializeSearch() { 61 if (searchRequest!=null) return; 62 searchRequest = UpdateUtils.createNewUpdatesRequest(null, false); 63 } 64 65 68 protected Control createContents(Composite parent) { 69 Composite composite = new Composite(parent, SWT.NULL); 70 GridLayout layout = new GridLayout(); 71 composite.setLayout(layout); 72 updatesButton = new Button(composite, SWT.RADIO); 73 updatesButton.setText(UpdateUIMessages.ModeSelectionPage_updates); 74 updateMode = !getSettings().getBoolean(P_NEW_FEATURES_MODE); 75 updatesButton.setSelection(updateMode); 76 77 final Label updatesText = new Label(composite, SWT.WRAP); 78 updatesText.setText(UpdateUIMessages.ModeSelectionPage_updatesText); 79 GridData gd = new GridData(GridData.FILL_HORIZONTAL); 80 gd.widthHint = 100; 81 updatesText.setLayoutData(gd); 82 83 updatesButton.addSelectionListener(new SelectionAdapter() { 84 public void widgetSelected(SelectionEvent e) { 85 updateMode = true; 86 getWizard().getContainer().updateButtons(); 87 } 88 }); 89 new Label(composite, SWT.NULL); 91 newFeaturesButton = new Button(composite, SWT.RADIO); 92 newFeaturesButton.setSelection(!updateMode); 93 newFeaturesButton.setText(UpdateUIMessages.ModeSelectionPage_newFeatures); 94 newFeaturesButton.addSelectionListener(new SelectionAdapter() { 95 public void widgetSelected(SelectionEvent e) { 96 updateMode = false; 97 getWizard().getContainer().updateButtons(); 98 } 99 }); 100 101 final Label newFeaturesText = new Label(composite, SWT.WRAP); 102 newFeaturesText.setText(UpdateUIMessages.ModeSelectionPage_newFeaturesText); 103 gd = new GridData(GridData.FILL_HORIZONTAL); 104 gd.widthHint = 100; 105 newFeaturesText.setLayoutData(gd); 106 107 119 120 Dialog.applyDialogFont(parent); 121 122 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, "org.eclipse.update.ui.ModeSelectionPage"); 124 return composite; 125 } 126 127 public void saveSettings() { 128 boolean updateMode = updatesButton.getSelection(); 129 getSettings().put(P_NEW_FEATURES_MODE, !updateMode); 130 } 131 132 public boolean isUpdateMode() { 133 return updateMode; 134 } 135 136 public boolean isPageComplete() { 137 return updateMode && super.isPageComplete(); 138 } 139 140 protected boolean isCurrentPage() { 141 return super.isCurrentPage(); 142 } 143 144 public boolean canFlipToNextPage() { 145 return !updateMode; 146 } 147 148 149 150 } 151 | Popular Tags |