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);
|
1818
|
114 |
TableViewerColumn featureColumn = new TableViewerColumn(viewer,
|
|
115 |
SWT.CENTER);
|
1824
|
116 |
featureColumn.getColumn().setText(Messages.AbstractImportExportPage_FeatureColTitle);
|
1810
|
117 |
featureColumn.setLabelProvider(new ColumnLabelProvider() {
|
|
118 |
@Override
|
|
119 |
public Image getImage(Object element) {
|
|
120 |
return featureImg;
|
|
121 |
}
|
1818
|
122 |
|
1810
|
123 |
@Override
|
|
124 |
public String getText(Object element) {
|
|
125 |
if (element instanceof FeatureInfo)
|
|
126 |
return ((FeatureInfo) element).getId();
|
|
127 |
return null;
|
|
128 |
}
|
|
129 |
});
|
1818
|
130 |
TableViewerColumn versionColumn = new TableViewerColumn(viewer,
|
|
131 |
SWT.CENTER);
|
1824
|
132 |
versionColumn.getColumn().setText(Messages.AbstractImportExportPage_VersionColTitle);
|
1810
|
133 |
versionColumn.setLabelProvider(new ColumnLabelProvider() {
|
|
134 |
@Override
|
|
135 |
public String getText(Object element) {
|
|
136 |
if (element instanceof FeatureInfo) {
|
|
137 |
return ((FeatureInfo) element).getVersion().toString();
|
|
138 |
}
|
|
139 |
return null;
|
|
140 |
}
|
|
141 |
});
|
1818
|
142 |
|
1810
|
143 |
viewer.getControl().setLayoutData(
|
1818
|
144 |
new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL
|
|
145 |
| GridData.GRAB_VERTICAL));
|
1810
|
146 |
viewer.setContentProvider(new ArrayContentProvider());
|
|
147 |
viewer.getTable().setHeaderVisible(true);
|
1818
|
148 |
|
1810
|
149 |
Composite buttonComposite = new Composite(parent, SWT.NONE);
|
1818
|
150 |
GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING)
|
|
151 |
.applyTo(buttonComposite);
|
1810
|
152 |
buttonComposite.setLayout(new GridLayout());
|
1826
|
153 |
checkAllButton = new Button(buttonComposite, SWT.PUSH);
|
1824
|
154 |
checkAllButton.setText(Messages.AbstractImportExportPage_CheckAllLabel);
|
1810
|
155 |
setButtonLayoutData(checkAllButton);
|
|
156 |
checkAllButton.addSelectionListener(new SelectionAdapter() {
|
|
157 |
@Override
|
|
158 |
public void widgetSelected(SelectionEvent e) {
|
|
159 |
viewer.setAllChecked(true);
|
1826
|
160 |
enableButtons();
|
|
161 |
setPageComplete(validatePage());
|
1810
|
162 |
}
|
|
163 |
});
|
1826
|
164 |
checkNoneButton = new Button(buttonComposite, SWT.PUSH);
|
1824
|
165 |
checkNoneButton.setText(Messages.AbstractImportExportPage_CheckNoneLabel);
|
1810
|
166 |
setButtonLayoutData(checkNoneButton);
|
|
167 |
checkNoneButton.addSelectionListener(new SelectionAdapter() {
|
|
168 |
@Override
|
|
169 |
public void widgetSelected(SelectionEvent e) {
|
|
170 |
viewer.setAllChecked(false);
|
1826
|
171 |
enableButtons();
|
|
172 |
setPageComplete(validatePage());
|
|
173 |
}
|
|
174 |
});
|
|
175 |
viewer.addCheckStateListener(new ICheckStateListener() {
|
|
176 |
public void checkStateChanged(CheckStateChangedEvent event) {
|
|
177 |
enableButtons();
|
|
178 |
setPageComplete(validatePage());
|
1810
|
179 |
}
|
|
180 |
});
|
|
181 |
}
|
1818
|
182 |
|
1810
|
183 |
protected abstract boolean validatePage();
|
|
184 |
|
|
185 |
public Collection<FeatureInfo> getSelectedFeatures() {
|
|
186 |
Object[] checkedElements = viewer.getCheckedElements();
|
|
187 |
List<FeatureInfo> infos = new ArrayList<FeatureInfo>();
|
|
188 |
for (Object o : checkedElements) {
|
|
189 |
infos.add((FeatureInfo) o);
|
|
190 |
}
|
|
191 |
return infos;
|
|
192 |
}
|
1818
|
193 |
|
1810
|
194 |
protected void packColumns() {
|
|
195 |
TableColumn[] columns = viewer.getTable().getColumns();
|
|
196 |
for (TableColumn column : columns) {
|
|
197 |
column.pack();
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
protected void updateViewer() {
|
|
202 |
packColumns();
|
|
203 |
viewer.setAllChecked(true);
|
1826
|
204 |
enableButtons();
|
1810
|
205 |
setPageComplete(validatePage());
|
|
206 |
}
|
1818
|
207 |
|
1826
|
208 |
private void enableButtons() {
|
|
209 |
checkAllButton.setEnabled(viewer.getTable().getItemCount() > viewer.getCheckedElements().length);
|
|
210 |
checkNoneButton.setEnabled(viewer.getCheckedElements().length > 0);
|
|
211 |
}
|
|
212 |
|
1810
|
213 |
@Override
|
|
214 |
public void dispose() {
|
|
215 |
super.dispose();
|
|
216 |
featureImg.dispose();
|
|
217 |
}
|
|
218 |
} |