author | dadubrow |
Fri, 20 Aug 2010 15:45:25 -0500 | |
changeset 1865 | f602ce53a86e |
parent 1826 | 48569468eaf3 |
child 1884 | 94c9fe3693ea |
permissions | -rw-r--r-- |
1810 | 1 |
/* |
1818 | 2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
1810 | 17 |
package com.nokia.carbide.internal.discovery.ui.wizard; |
18 |
||
19 |
import java.util.ArrayList; |
|
20 |
import java.util.Collection; |
|
21 |
import java.util.List; |
|
22 |
||
1818 | 23 |
import org.eclipse.jface.dialogs.Dialog; |
1810 | 24 |
import org.eclipse.jface.layout.GridDataFactory; |
25 |
import org.eclipse.jface.layout.GridLayoutFactory; |
|
26 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
27 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
1826 | 28 |
import org.eclipse.jface.viewers.CheckStateChangedEvent; |
1810 | 29 |
import org.eclipse.jface.viewers.CheckboxTableViewer; |
30 |
import org.eclipse.jface.viewers.ColumnLabelProvider; |
|
1826 | 31 |
import org.eclipse.jface.viewers.ICheckStateListener; |
1810 | 32 |
import org.eclipse.jface.viewers.TableViewerColumn; |
33 |
import org.eclipse.jface.wizard.WizardPage; |
|
34 |
import org.eclipse.swt.SWT; |
|
35 |
import org.eclipse.swt.events.ModifyEvent; |
|
36 |
import org.eclipse.swt.events.ModifyListener; |
|
37 |
import org.eclipse.swt.events.SelectionAdapter; |
|
38 |
import org.eclipse.swt.events.SelectionEvent; |
|
39 |
import org.eclipse.swt.graphics.Image; |
|
40 |
import org.eclipse.swt.layout.GridData; |
|
41 |
import org.eclipse.swt.layout.GridLayout; |
|
42 |
import org.eclipse.swt.widgets.Button; |
|
43 |
import org.eclipse.swt.widgets.Composite; |
|
44 |
import org.eclipse.swt.widgets.Label; |
|
45 |
import org.eclipse.swt.widgets.TableColumn; |
|
46 |
import org.eclipse.swt.widgets.Text; |
|
47 |
||
48 |
import com.nokia.carbide.discovery.ui.Activator; |
|
1824 | 49 |
import com.nokia.carbide.discovery.ui.Messages; |
1810 | 50 |
|
51 |
/** |
|
52 |
* Abstract superclass of import and export page |
|
53 |
*/ |
|
54 |
abstract class AbstractImportExportPage extends WizardPage { |
|
55 |
||
56 |
protected Text pathText; |
|
57 |
protected Button browseButton; |
|
58 |
protected CheckboxTableViewer viewer; |
|
1826 | 59 |
protected Button checkAllButton; |
60 |
protected Button checkNoneButton; |
|
1818 | 61 |
protected static final ImageDescriptor FEATURE_IMGDESC = Activator |
62 |
.getImageDescriptor("icons/iu_obj.gif"); //$NON-NLS-1$ |
|
1810 | 63 |
protected Image featureImg; |
64 |
||
65 |
public AbstractImportExportPage(String pageName) { |
|
66 |
super(pageName); |
|
67 |
} |
|
1818 | 68 |
|
1810 | 69 |
public void createControl(Composite parent) { |
1818 | 70 |
initializeDialogUnits(parent); |
71 |
featureImg = FEATURE_IMGDESC.createImage(); |
|
1810 | 72 |
|
1818 | 73 |
Composite composite = new Composite(parent, SWT.NONE); |
74 |
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(composite); |
|
75 |
GridDataFactory.fillDefaults().applyTo(composite); |
|
76 |
composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); |
|
1810 | 77 |
|
1818 | 78 |
Dialog.applyDialogFont(composite); |
79 |
setControl(composite); |
|
1810 | 80 |
} |
81 |
||
82 |
protected void createBrowseGroup(Composite parent, String labelText) { |
|
1818 | 83 |
Composite composite = new Composite(parent, SWT.NONE); |
84 |
GridLayoutFactory.fillDefaults().numColumns(3).applyTo(composite); |
|
85 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING) |
|
86 |
.grab(true, false).applyTo(composite); |
|
87 |
||
88 |
Label label = new Label(composite, SWT.NONE); |
|
89 |
label.setText(labelText); |
|
90 |
||
91 |
pathText = new Text(composite, SWT.BORDER); |
|
92 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER) |
|
93 |
.grab(true, false).hint(250, SWT.DEFAULT).applyTo(pathText); |
|
94 |
pathText.addModifyListener(new ModifyListener() { |
|
1810 | 95 |
public void modifyText(ModifyEvent e) { |
96 |
setPageComplete(validatePage()); |
|
97 |
} |
|
1818 | 98 |
}); |
99 |
browseButton = new Button(composite, SWT.PUSH); |
|
1824 | 100 |
browseButton.setText(Messages.AbstractImportExportPage_BrowseButtonLabel); |
1818 | 101 |
browseButton |
102 |
.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); |
|
103 |
setButtonLayoutData(browseButton); |
|
104 |
||
105 |
new Label(parent, SWT.NONE); // spacer |
|
1810 | 106 |
} |
107 |
||
108 |
protected void createViewerGroup(Composite parent, String labelText) { |
|
109 |
Label label = new Label(parent, SWT.NONE); |
|
110 |
label.setText(labelText); |
|
111 |
GridDataFactory.defaultsFor(label).span(2, 1).applyTo(label); |
|
1818 | 112 |
|
1810 | 113 |
viewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER); |
1865
f602ce53a86e
Don't center columns in import/export wizard + better wording for version checkbox in import wizard
dadubrow
parents:
1826
diff
changeset
|
114 |
TableViewerColumn featureColumn = new TableViewerColumn(viewer, SWT.LEFT); |
1824 | 115 |
featureColumn.getColumn().setText(Messages.AbstractImportExportPage_FeatureColTitle); |
1810 | 116 |
featureColumn.setLabelProvider(new ColumnLabelProvider() { |
117 |
@Override |
|
118 |
public Image getImage(Object element) { |
|
119 |
return featureImg; |
|
120 |
} |
|
1818 | 121 |
|
1810 | 122 |
@Override |
123 |
public String getText(Object element) { |
|
124 |
if (element instanceof FeatureInfo) |
|
125 |
return ((FeatureInfo) element).getId(); |
|
126 |
return null; |
|
127 |
} |
|
128 |
}); |
|
1865
f602ce53a86e
Don't center columns in import/export wizard + better wording for version checkbox in import wizard
dadubrow
parents:
1826
diff
changeset
|
129 |
TableViewerColumn versionColumn = new TableViewerColumn(viewer, SWT.LEFT); |
1824 | 130 |
versionColumn.getColumn().setText(Messages.AbstractImportExportPage_VersionColTitle); |
1810 | 131 |
versionColumn.setLabelProvider(new ColumnLabelProvider() { |
132 |
@Override |
|
133 |
public String getText(Object element) { |
|
134 |
if (element instanceof FeatureInfo) { |
|
135 |
return ((FeatureInfo) element).getVersion().toString(); |
|
136 |
} |
|
137 |
return null; |
|
138 |
} |
|
139 |
}); |
|
1818 | 140 |
|
1810 | 141 |
viewer.getControl().setLayoutData( |
1818 | 142 |
new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL |
143 |
| GridData.GRAB_VERTICAL)); |
|
1810 | 144 |
viewer.setContentProvider(new ArrayContentProvider()); |
145 |
viewer.getTable().setHeaderVisible(true); |
|
1818 | 146 |
|
1810 | 147 |
Composite buttonComposite = new Composite(parent, SWT.NONE); |
1818 | 148 |
GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING) |
149 |
.applyTo(buttonComposite); |
|
1810 | 150 |
buttonComposite.setLayout(new GridLayout()); |
1826 | 151 |
checkAllButton = new Button(buttonComposite, SWT.PUSH); |
1824 | 152 |
checkAllButton.setText(Messages.AbstractImportExportPage_CheckAllLabel); |
1810 | 153 |
setButtonLayoutData(checkAllButton); |
154 |
checkAllButton.addSelectionListener(new SelectionAdapter() { |
|
155 |
@Override |
|
156 |
public void widgetSelected(SelectionEvent e) { |
|
157 |
viewer.setAllChecked(true); |
|
1826 | 158 |
enableButtons(); |
159 |
setPageComplete(validatePage()); |
|
1810 | 160 |
} |
161 |
}); |
|
1826 | 162 |
checkNoneButton = new Button(buttonComposite, SWT.PUSH); |
1824 | 163 |
checkNoneButton.setText(Messages.AbstractImportExportPage_CheckNoneLabel); |
1810 | 164 |
setButtonLayoutData(checkNoneButton); |
165 |
checkNoneButton.addSelectionListener(new SelectionAdapter() { |
|
166 |
@Override |
|
167 |
public void widgetSelected(SelectionEvent e) { |
|
168 |
viewer.setAllChecked(false); |
|
1826 | 169 |
enableButtons(); |
170 |
setPageComplete(validatePage()); |
|
171 |
} |
|
172 |
}); |
|
173 |
viewer.addCheckStateListener(new ICheckStateListener() { |
|
174 |
public void checkStateChanged(CheckStateChangedEvent event) { |
|
175 |
enableButtons(); |
|
176 |
setPageComplete(validatePage()); |
|
1810 | 177 |
} |
178 |
}); |
|
179 |
} |
|
1818 | 180 |
|
1810 | 181 |
protected abstract boolean validatePage(); |
182 |
||
183 |
public Collection<FeatureInfo> getSelectedFeatures() { |
|
184 |
Object[] checkedElements = viewer.getCheckedElements(); |
|
185 |
List<FeatureInfo> infos = new ArrayList<FeatureInfo>(); |
|
186 |
for (Object o : checkedElements) { |
|
187 |
infos.add((FeatureInfo) o); |
|
188 |
} |
|
189 |
return infos; |
|
190 |
} |
|
1818 | 191 |
|
1810 | 192 |
protected void packColumns() { |
193 |
TableColumn[] columns = viewer.getTable().getColumns(); |
|
194 |
for (TableColumn column : columns) { |
|
195 |
column.pack(); |
|
196 |
} |
|
197 |
} |
|
198 |
||
199 |
protected void updateViewer() { |
|
200 |
packColumns(); |
|
201 |
viewer.setAllChecked(true); |
|
1826 | 202 |
enableButtons(); |
1810 | 203 |
setPageComplete(validatePage()); |
204 |
} |
|
1818 | 205 |
|
1826 | 206 |
private void enableButtons() { |
207 |
checkAllButton.setEnabled(viewer.getTable().getItemCount() > viewer.getCheckedElements().length); |
|
208 |
checkNoneButton.setEnabled(viewer.getCheckedElements().length > 0); |
|
209 |
} |
|
210 |
||
1810 | 211 |
@Override |
212 |
public void dispose() { |
|
213 |
super.dispose(); |
|
214 |
featureImg.dispose(); |
|
215 |
} |
|
216 |
} |