1 11 package org.eclipse.update.internal.ui.wizards; 12 import org.eclipse.jface.dialogs.Dialog; 13 import org.eclipse.jface.wizard.WizardPage; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.SelectionAdapter; 16 import org.eclipse.swt.events.SelectionEvent; 17 import org.eclipse.swt.layout.GridData; 18 import org.eclipse.swt.layout.GridLayout; 19 import org.eclipse.swt.widgets.Button; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Table; 22 import org.eclipse.swt.widgets.TableItem; 23 import org.eclipse.swt.widgets.Text; 24 import org.eclipse.ui.*; 25 import org.eclipse.update.core.IFeature; 26 import org.eclipse.update.internal.ui.UpdateUI; 27 import org.eclipse.update.internal.ui.UpdateUIImages; 28 import org.eclipse.update.internal.ui.UpdateUIMessages; 29 import org.eclipse.update.operations.IInstallFeatureOperation; 30 31 public class LicensePage extends WizardPage implements IDynamicPage { 32 private boolean multiLicenseMode = false; 33 private IInstallFeatureOperation[] jobs; 34 private IInstallFeatureOperation[] oldjJobs; 35 private Text text; 36 private Table table; 37 private Button acceptButton; 38 private Button declineButton; 39 40 43 public LicensePage(boolean multiLicenseMode) { 44 super("License"); setTitle(UpdateUIMessages.InstallWizard_LicensePage_title); 46 setPageComplete(false); 47 this.multiLicenseMode = multiLicenseMode; 48 UpdateUI.getDefault().getLabelProvider().connect(this); 49 setDescription(multiLicenseMode ?UpdateUIMessages.InstallWizard_LicensePage_desc2 : 50 UpdateUIMessages.InstallWizard_LicensePage_desc); 51 } 52 public void dispose() { 53 UpdateUI.getDefault().getLabelProvider().disconnect(this); 54 super.dispose(); 55 } 56 57 public LicensePage(IInstallFeatureOperation job) { 58 this(false); 59 setJobs(new IInstallFeatureOperation[] { job }); 60 } 61 62 public void setJobs(IInstallFeatureOperation[] jobs) { 63 this.jobs = jobs; 64 } 65 66 public void createControl(Composite parent) { 67 Composite client = new Composite(parent, SWT.NULL); 68 client.setLayoutData(new GridData(GridData.FILL_BOTH)); 69 GridLayout layout = new GridLayout(); 70 client.setLayout(layout); 71 72 PlatformUI.getWorkbench().getHelpSystem().setHelp(client, "org.eclipse.update.ui.LicensePage2"); 74 if (multiLicenseMode) { 75 layout.numColumns = 3; 76 layout.makeColumnsEqualWidth = true; 77 78 table = new Table(client, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); 79 80 table.addSelectionListener(new SelectionAdapter() { 81 public void widgetSelected(SelectionEvent e) { 82 if (e.item != null) { 83 Object data = e.item.getData(); 84 text.setText((data == null) ? "" : (String ) data); } 86 } 87 }); 88 GridData gd = new GridData(GridData.FILL_BOTH); 89 gd.heightHint = 200; 90 table.setLayoutData(gd); 91 } 92 text = 93 new Text( 94 client, 95 SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP | SWT.READ_ONLY); 96 97 GridData gd = new GridData(GridData.FILL_BOTH); 98 gd.heightHint = 200; 99 if (multiLicenseMode) 100 gd.horizontalSpan = 2; 101 text.setLayoutData(gd); 102 text.setBackground(text.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); 103 104 Composite buttonContainer = new Composite(client, SWT.NULL); 105 gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL); 106 if (multiLicenseMode) 107 gd.horizontalSpan = 3; 108 buttonContainer.setLayout(new GridLayout()); 109 buttonContainer.setLayoutData(gd); 110 111 acceptButton = new Button(buttonContainer, SWT.RADIO); 112 acceptButton.setText(multiLicenseMode?UpdateUIMessages.InstallWizard_LicensePage_accept2 113 : UpdateUIMessages.InstallWizard_LicensePage_accept); 114 acceptButton.addSelectionListener(new SelectionAdapter() { 115 public void widgetSelected(SelectionEvent e) { 116 setPageComplete(acceptButton.getSelection()); 117 } 118 }); 119 declineButton = new Button(buttonContainer, SWT.RADIO); 120 declineButton.setText(multiLicenseMode?UpdateUIMessages.InstallWizard_LicensePage_decline2 121 : UpdateUIMessages.InstallWizard_LicensePage_decline); 122 declineButton.addSelectionListener(new SelectionAdapter() { 123 public void widgetSelected(SelectionEvent e) { 124 setPageComplete(acceptButton.getSelection()); 125 } 126 }); 127 setControl(client); 128 129 Dialog.applyDialogFont(parent); 130 } 131 132 public void setVisible(boolean visible) { 134 boolean jobsChanged = didJobsChange(jobs); 135 declineButton.setSelection(!jobsChanged && declineButton.getSelection()); 136 acceptButton.setSelection(!jobsChanged && acceptButton.getSelection()); 137 138 if (jobs.length == 1) { 139 acceptButton.setText(UpdateUIMessages.InstallWizard_LicensePage_accept); 140 declineButton.setText(UpdateUIMessages.InstallWizard_LicensePage_decline); 141 } else if (jobs.length > 1) { 142 acceptButton.setText(UpdateUIMessages.InstallWizard_LicensePage_accept2); 143 declineButton.setText(UpdateUIMessages.InstallWizard_LicensePage_decline2); 144 } 145 146 if (visible) { 147 if (multiLicenseMode) { 148 TableItem item; 149 for (int i = 0; i < jobs.length; i++) { 150 IFeature feature = jobs[i].getFeature(); 151 item = new TableItem(table, SWT.NONE); 152 String label = 153 feature.getLabel() 154 + " " + feature.getVersionedIdentifier().getVersion().toString(); 156 item.setText(label); 157 item.setImage( 158 UpdateUI.getDefault().getLabelProvider().get( 159 feature.isPatch() 160 ? UpdateUIImages.DESC_EFIX_OBJ 161 : UpdateUIImages.DESC_FEATURE_OBJ)); 162 String license = feature.getLicense().getAnnotation(); 163 item.setData(license); 165 } 166 167 table.setSelection(0); 168 } 169 showLicenseText(); 170 } else { 171 if (multiLicenseMode) { 172 TableItem items[] = table.getItems(); 173 for (int i = items.length - 1; i >= 0; i--) { 174 table.getItem(i).dispose(); 175 } 176 } 177 } 178 super.setVisible(visible); 179 oldjJobs = jobs; 180 181 } 182 183 private void showLicenseText() { 184 if (!multiLicenseMode) { 185 text.setText(jobs[0].getFeature().getLicense().getAnnotation()); 186 return; 187 } 188 TableItem[] selectedItems = table.getSelection(); 189 if (selectedItems.length == 0) { 190 text.setText(""); } else { 192 Object data = selectedItems[0].getData(); 193 text.setText((data == null) ? "" : (String ) data); } 195 } 196 197 private boolean didJobsChange(IInstallFeatureOperation[] jobs){ 198 199 if ( (jobs == null) || (oldjJobs == null) || (jobs.length == 0) || (oldjJobs.length == 0) ) 200 return true; 201 202 boolean foundIt = false; 203 204 for ( int i = 0; i < jobs.length; i++) { 205 foundIt = false; 206 for ( int j = 0; j < oldjJobs.length; j++) { 207 if (jobs[i].getFeature().getVersionedIdentifier().equals(oldjJobs[j].getFeature().getVersionedIdentifier()) ) { 208 foundIt = true; 209 break; 210 } 211 } 212 if (!foundIt) { 213 return true; 214 } 215 } 216 return false; 217 } 218 } 219 | Popular Tags |