1 11 12 package org.eclipse.ui.internal.dialogs; 13 14 import org.eclipse.jface.dialogs.IDialogConstants; 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.graphics.Font; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Button; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Table; 24 import org.eclipse.swt.widgets.TableColumn; 25 import org.eclipse.swt.widgets.TableItem; 26 import org.eclipse.ui.internal.WorkbenchMessages; 27 28 31 class PreferenceImportExportSettingsSelectionPage extends AbstractPreferenceImportExportPage { 32 33 36 private static final String EXPORT_MESSAGE = WorkbenchMessages.getString("ImportExportPages.exportSettingsSelect"); 40 private static final String IMPORT_MESSAGE = WorkbenchMessages.getString("ImportExportPages.importSettingsSelect"); 44 private static final String NAME = "org.eclipse.ui.preferences.importExportSettingsSelectionPage"; 46 49 private Table settingsTable; 50 51 57 PreferenceImportExportSettingsSelectionPage(boolean exportWizard) { 58 super(NAME, exportWizard); 59 } 60 61 66 boolean canFinish() { 67 return true; 68 } 69 70 75 public boolean canFlipToNextPage() { 76 return false; 77 } 78 79 84 public void createControl(Composite parent) { 85 Font parentFont = parent.getFont(); 86 final Composite page = new Composite(parent, SWT.NONE); 87 GridLayout layout = new GridLayout(2, false); 88 page.setLayout(layout); 89 initializeDialogUnits(page); 90 91 if (export) { 93 setTitle(EXPORT_TITLE); 94 setMessage(EXPORT_MESSAGE); 95 setImageDescriptor(getImageDescriptor("wizban/export_wiz.gif")); } else { 97 setTitle(IMPORT_TITLE); 98 setMessage(IMPORT_MESSAGE); 99 setImageDescriptor(getImageDescriptor("wizban/import_wiz.gif")); } 101 102 GridData layoutData; 103 104 settingsTable = new Table(page, SWT.CHECK | SWT.BORDER); 106 settingsTable.setFont(parentFont); 107 layoutData = new GridData(GridData.FILL_BOTH); 108 layoutData.verticalSpan = 3; 109 settingsTable.setLayoutData(layoutData); 110 settingsTable.setLinesVisible(true); 111 settingsTable.setHeaderVisible(true); 112 final TableColumn columnChecked = new TableColumn(settingsTable, SWT.LEFT, 0); 113 final TableColumn columnName = new TableColumn(settingsTable, SWT.LEFT, 1); 114 final TableColumn columnValue = new TableColumn(settingsTable, SWT.LEFT, 2); 115 for (int i = 0; i < 50; i++) { 116 TableItem item = new TableItem(settingsTable, SWT.NULL); 117 item.setText(new String [] { "", "org.eclipse.sample.preference", "Sample value (ignore)" }); item.setChecked(true); 119 } 120 121 columnName.setText(WorkbenchMessages.getString("ImportExportPages.name")); columnValue.setText(WorkbenchMessages.getString("ImportExportPages.value")); columnChecked.pack(); 124 columnName.pack(); 125 columnValue.pack(); 126 127 final Button selectAllButton = new Button(page, SWT.PUSH); 129 selectAllButton.setFont(parentFont); 130 layoutData = new GridData(); 131 selectAllButton.setText(WorkbenchMessages.getString("ImportExportPages.selectAll")); layoutData.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); 133 layoutData.widthHint = computePushButtonWidthHint(selectAllButton); 134 layoutData.verticalAlignment = GridData.BEGINNING; 135 selectAllButton.setLayoutData(layoutData); 136 selectAllButton.addSelectionListener(new SelectionAdapter() { 137 public final void widgetSelected(SelectionEvent event) { 138 setCheckAll(true); 139 } 140 }); 141 142 final Button deselectAllButton = new Button(page, SWT.PUSH); 144 deselectAllButton.setFont(parentFont); 145 layoutData = new GridData(); 146 deselectAllButton.setText(WorkbenchMessages.getString("ImportExportPages.deselectAll")); layoutData.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); 148 layoutData.widthHint = computePushButtonWidthHint(deselectAllButton); 149 layoutData.verticalAlignment = GridData.BEGINNING; 150 deselectAllButton.setLayoutData(layoutData); 151 deselectAllButton.addSelectionListener(new SelectionAdapter() { 152 public final void widgetSelected(SelectionEvent event) { 153 setCheckAll(false); 154 } 155 }); 156 157 final Button invertSelectionButton = new Button(page, SWT.PUSH); 159 invertSelectionButton.setFont(parentFont); 160 layoutData = new GridData(); 161 invertSelectionButton.setText(WorkbenchMessages.getString("ImportExportPages.invertSelection")); layoutData.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT); 163 layoutData.widthHint = computePushButtonWidthHint(invertSelectionButton); 164 layoutData.verticalAlignment = GridData.BEGINNING; 165 invertSelectionButton.setLayoutData(layoutData); 166 invertSelectionButton.addSelectionListener(new SelectionAdapter() { 167 public final void widgetSelected(SelectionEvent event) { 168 invertSelection(); 169 } 170 }); 171 172 setControl(page); 174 175 init(); 177 } 178 179 184 private void init() { 185 setCheckAll(true); 186 } 187 188 191 private void invertSelection() { 192 final TableItem[] items = settingsTable.getItems(); 193 for (int i = 0; i < items.length; i++) { 194 TableItem item = items[i]; 195 item.setChecked(!item.getChecked()); 196 } 197 } 198 199 204 private void setCheckAll(final boolean checked) { 205 TableItem[] items = settingsTable.getItems(); 206 for (int i = 0; i < items.length; i++) { 207 items[i].setChecked(checked); 208 } 209 } 210 211 boolean validate() { 212 return true; 213 } 214 } 215 | Popular Tags |