KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > PreferenceImportExportSettingsSelectionPage


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

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 /**
29  * @since 3.0
30  */

31 class PreferenceImportExportSettingsSelectionPage extends AbstractPreferenceImportExportPage {
32     
33     /**
34      * The message to display when there are no errors on this page.
35      */

36     private static final String JavaDoc EXPORT_MESSAGE = WorkbenchMessages.getString("ImportExportPages.exportSettingsSelect"); //$NON-NLS-1$
37
/**
38      * The message to display when there are no errors on this page.
39      */

40     private static final String JavaDoc IMPORT_MESSAGE = WorkbenchMessages.getString("ImportExportPages.importSettingsSelect"); //$NON-NLS-1$
41
/**
42      * The name of this page -- used to find the page later.
43      */

44     private static final String JavaDoc NAME = "org.eclipse.ui.preferences.importExportSettingsSelectionPage"; //$NON-NLS-1$
45

46     /**
47      * The table containing the list of settings to choose from.
48      */

49     private Table settingsTable;
50     
51     /**
52      * Constructs a new instance of a settings selection page with the given
53      * mode.
54      * @param exportWizard Whether the preference selection if for an export
55      * operation.
56      */

57     PreferenceImportExportSettingsSelectionPage(boolean exportWizard) {
58         super(NAME, exportWizard);
59     }
60     
61     /**
62      * This page can always finish. If no items are selected, it simply means
63      * that nothing will be exported.
64      * @return <code>true</code>.
65      */

66     boolean canFinish() {
67         return true;
68     }
69     
70     /**
71      * This page is always the last page, and so you cannot flip to the next
72      * page.
73      * @return <code>false</code>.
74      */

75     public boolean canFlipToNextPage() {
76         return false;
77     }
78     
79     /*
80      * (non-Javadoc)
81      *
82      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
83      */

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         // Set-up the title, subtitle and icon.
92
if (export) {
93             setTitle(EXPORT_TITLE);
94             setMessage(EXPORT_MESSAGE);
95             setImageDescriptor(getImageDescriptor("wizban/export_wiz.gif")); //$NON-NLS-1$
96
} else {
97             setTitle(IMPORT_TITLE);
98             setMessage(IMPORT_MESSAGE);
99             setImageDescriptor(getImageDescriptor("wizban/import_wiz.gif")); //$NON-NLS-1$
100
}
101
102         GridData layoutData;
103
104         // Set-up the table and its columns.
105
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 JavaDoc[] { "", "org.eclipse.sample.preference", "Sample value (ignore)" }); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
118
item.setChecked(true);
119         }
120         
121         columnName.setText(WorkbenchMessages.getString("ImportExportPages.name")); //$NON-NLS-1$
122
columnValue.setText(WorkbenchMessages.getString("ImportExportPages.value")); //$NON-NLS-1$
123
columnChecked.pack();
124         columnName.pack();
125         columnValue.pack();
126
127         // Set-up the select all button.
128
final Button selectAllButton = new Button(page, SWT.PUSH);
129         selectAllButton.setFont(parentFont);
130         layoutData = new GridData();
131         selectAllButton.setText(WorkbenchMessages.getString("ImportExportPages.selectAll")); //$NON-NLS-1$
132
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         // Set-up the deselect all button.
143
final Button deselectAllButton = new Button(page, SWT.PUSH);
144         deselectAllButton.setFont(parentFont);
145         layoutData = new GridData();
146         deselectAllButton.setText(WorkbenchMessages.getString("ImportExportPages.deselectAll")); //$NON-NLS-1$
147
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         // Set-up the invert selection button.
158
final Button invertSelectionButton = new Button(page, SWT.PUSH);
159         invertSelectionButton.setFont(parentFont);
160         layoutData = new GridData();
161         invertSelectionButton.setText(WorkbenchMessages.getString("ImportExportPages.invertSelection")); //$NON-NLS-1$
162
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         // Remember the composite as the top-level control.
173
setControl(page);
174         
175         // Restore all the controls to their previous values.
176
init();
177     }
178     
179     /**
180      * Initializes all of the controls to their previous values. This page
181      * doesn't really remember anything right now, so this just checks all of
182      * the table items.
183      */

184     private void init() {
185         setCheckAll(true);
186     }
187     
188     /**
189      * Inverts the current selection (checked state) of all the settings.
190      */

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     /**
200      * This sets the checked state on all the settings to the given value. This
201      * can be used as either a select all or a deselect all.
202      * @param checked The state to set.
203      */

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