Index: editor/tools/plugins/com.google.dart.eclipse.ui/src/com/google/dart/eclipse/wizards/SamplesComposite.java |
=================================================================== |
--- editor/tools/plugins/com.google.dart.eclipse.ui/src/com/google/dart/eclipse/wizards/SamplesComposite.java (revision 41289) |
+++ editor/tools/plugins/com.google.dart.eclipse.ui/src/com/google/dart/eclipse/wizards/SamplesComposite.java (working copy) |
@@ -15,17 +15,20 @@ |
import com.google.dart.tools.core.generator.AbstractSample; |
import com.google.dart.tools.ui.DartToolsPlugin; |
+import com.google.dart.tools.ui.internal.projects.SamplesLabelProvider; |
+import org.eclipse.core.runtime.IProgressMonitor; |
import org.eclipse.jface.dialogs.IDialogSettings; |
import org.eclipse.jface.layout.GridDataFactory; |
import org.eclipse.jface.layout.GridLayoutFactory; |
+import org.eclipse.jface.operation.IRunnableWithProgress; |
import org.eclipse.jface.viewers.ArrayContentProvider; |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
import org.eclipse.jface.viewers.IStructuredSelection; |
-import org.eclipse.jface.viewers.LabelProvider; |
-import org.eclipse.jface.viewers.ListViewer; |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
import org.eclipse.jface.viewers.StructuredSelection; |
+import org.eclipse.jface.viewers.TableViewer; |
+import org.eclipse.jface.wizard.WizardPage; |
import org.eclipse.swt.SWT; |
import org.eclipse.swt.events.SelectionAdapter; |
import org.eclipse.swt.events.SelectionEvent; |
@@ -34,27 +37,33 @@ |
import org.eclipse.swt.layout.GridLayout; |
import org.eclipse.swt.widgets.Button; |
import org.eclipse.swt.widgets.Composite; |
+import org.eclipse.swt.widgets.Display; |
import org.eclipse.swt.widgets.Group; |
import org.eclipse.swt.widgets.Label; |
+import java.lang.reflect.InvocationTargetException; |
+import java.util.ArrayList; |
import java.util.List; |
class SamplesComposite extends Composite { |
- static final String NEW_APPPLICATION_SETTINGS = "newApplicationWizard.settings"; //$NON-NLS-1$ |
+ private static final String NEW_APPPLICATION_SETTINGS = "newApplicationWizard.settings"; //$NON-NLS-1$ |
private static final String CONTENT_GENERATION_DISABLED = "contentGenerationDisabled"; //$NON-NLS-1$ |
+ private WizardPage page; |
private Button addSampleContentCheckbox; |
- private ListViewer samplesListViewer; |
+ private TableViewer samplesViewer; |
- public SamplesComposite(Composite parent, int style) { |
+ public SamplesComposite(WizardPage page, Composite parent, int style) { |
super(parent, style); |
+ this.page = page; |
+ |
initialize(); |
} |
protected AbstractSample getCurrentSample() { |
if (addSampleContentCheckbox.getSelection()) { |
- IStructuredSelection selection = (IStructuredSelection) samplesListViewer.getSelection(); |
+ IStructuredSelection selection = (IStructuredSelection) samplesViewer.getSelection(); |
if (selection.isEmpty()) { |
return null; |
@@ -67,7 +76,6 @@ |
} |
private void createSampleGroup() { |
- |
Group contentGroup = new Group(this, SWT.NONE); |
contentGroup.setText("Sample content"); |
GridDataFactory.fillDefaults().span(3, 1).grab(true, false).applyTo(contentGroup); |
@@ -90,22 +98,28 @@ |
Label spacer = new Label(contentGroup, SWT.SEPARATOR | SWT.HORIZONTAL); |
GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(spacer); |
- samplesListViewer = new ListViewer(contentGroup); |
- samplesListViewer.setLabelProvider(new LabelProvider()); |
- samplesListViewer.setContentProvider(new ArrayContentProvider()); |
- List<AbstractSample> samples = AbstractSample.getAllSamples(); |
- samplesListViewer.setInput(samples); |
- GridDataFactory.fillDefaults().hint(-1, 60).grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo( |
- samplesListViewer.getControl()); |
- samplesListViewer.setSelection(new StructuredSelection(getDefaultSample(samples))); |
- samplesListViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
+ samplesViewer = new TableViewer(contentGroup, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER |
+ | SWT.FULL_SELECTION); |
+ samplesViewer.setLabelProvider(new SamplesLabelProvider()); |
+ samplesViewer.setContentProvider(new ArrayContentProvider()); |
+ samplesViewer.setInput(new ArrayList<AbstractSample>()); |
+ GridDataFactory.fillDefaults().hint(300, 90).grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo( |
+ samplesViewer.getControl()); |
+ samplesViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
@Override |
public void selectionChanged(SelectionChangedEvent event) { |
updateMessageAndEnablement(); |
} |
}); |
- samplesListViewer.getList().setEnabled(addSampleContentCheckbox.getSelection()); |
+ samplesViewer.getTable().setEnabled(addSampleContentCheckbox.getSelection()); |
+ |
+ Display.getDefault().asyncExec(new Runnable() { |
+ @Override |
+ public void run() { |
+ populateSamplesList(); |
+ } |
+ }); |
} |
private AbstractSample getDefaultSample(List<AbstractSample> samples) { |
@@ -148,9 +162,32 @@ |
setSize(new Point(449, 311)); |
} |
+ private void populateSamplesList() { |
+ try { |
+ page.getWizard().getContainer().run(true, false, new IRunnableWithProgress() { |
+ @Override |
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, |
+ InterruptedException { |
+ monitor.beginTask("", IProgressMonitor.UNKNOWN); |
+ final List<AbstractSample> samples = AbstractSample.getAllSamples(); |
+ Display.getDefault().asyncExec(new Runnable() { |
+ @Override |
+ public void run() { |
+ samplesViewer.setInput(samples); |
+ samplesViewer.setSelection(new StructuredSelection(getDefaultSample(samples))); |
+ } |
+ }); |
+ monitor.done(); |
+ } |
+ }); |
+ } catch (InvocationTargetException e) { |
+ DartToolsPlugin.log(e); |
+ } catch (InterruptedException e) { |
+ DartToolsPlugin.log(e); |
+ } |
+ } |
+ |
private void updateMessageAndEnablement() { |
- |
- samplesListViewer.getList().setEnabled(addSampleContentCheckbox.getSelection()); |
+ samplesViewer.getTable().setEnabled(addSampleContentCheckbox.getSelection()); |
} |
- |
} |