|
1 /** |
|
2 * Copyright (c) 2010 Symbian Foundation 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 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 */ |
|
19 package org.symbian.tools.wrttools.wizards; |
|
20 |
|
21 import org.eclipse.core.databinding.DataBindingContext; |
|
22 import org.eclipse.core.databinding.beans.BeansObservables; |
|
23 import org.eclipse.core.databinding.observable.set.IObservableSet; |
|
24 import org.eclipse.jface.databinding.viewers.IViewerObservableSet; |
|
25 import org.eclipse.jface.databinding.viewers.ViewersObservables; |
|
26 import org.eclipse.jface.viewers.ArrayContentProvider; |
|
27 import org.eclipse.jface.viewers.CheckStateChangedEvent; |
|
28 import org.eclipse.jface.viewers.CheckboxTableViewer; |
|
29 import org.eclipse.jface.viewers.ICheckStateListener; |
|
30 import org.eclipse.jface.viewers.LabelProvider; |
|
31 import org.eclipse.jface.wizard.WizardPage; |
|
32 import org.eclipse.swt.SWT; |
|
33 import org.eclipse.swt.graphics.Image; |
|
34 import org.eclipse.swt.widgets.Composite; |
|
35 import org.symbian.tools.wrttools.Activator; |
|
36 import org.symbian.tools.wrttools.core.libraries.JSLibrary; |
|
37 |
|
38 public class WRTProjectLibraryWizardPage extends WizardPage { |
|
39 public static final class LibraryCheckStateListener implements ICheckStateListener { |
|
40 private final WizardContext context; |
|
41 |
|
42 public LibraryCheckStateListener(WizardContext context) { |
|
43 this.context = context; |
|
44 } |
|
45 |
|
46 public void checkStateChanged(CheckStateChangedEvent event) { |
|
47 if (!event.getChecked() && context.isRequiredLibrary((JSLibrary) event.getElement())) { |
|
48 event.getCheckable().setChecked(event.getElement(), true); |
|
49 } |
|
50 } |
|
51 |
|
52 } |
|
53 private static final class LibraryLabelProvider extends LabelProvider { |
|
54 @Override |
|
55 public String getText(Object element) { |
|
56 return ((JSLibrary) element).getName(); |
|
57 } |
|
58 |
|
59 @Override |
|
60 public Image getImage(Object element) { |
|
61 return ((JSLibrary) element).getImage(); |
|
62 } |
|
63 } |
|
64 private CheckboxTableViewer list; |
|
65 private final WizardContext context; |
|
66 private final DataBindingContext bindingContext; |
|
67 |
|
68 public WRTProjectLibraryWizardPage(WizardContext context, DataBindingContext bindingContext) { |
|
69 super("ProjectLibraries", "WRT Project Libraries", null); |
|
70 this.context = context; |
|
71 this.bindingContext = bindingContext; |
|
72 setDescription("Select libraries to add to your project"); |
|
73 } |
|
74 |
|
75 public void createControl(Composite parent) { |
|
76 list = CheckboxTableViewer.newCheckList(parent, SWT.BORDER); |
|
77 list.setLabelProvider(new LibraryLabelProvider()); |
|
78 list.setContentProvider(new ArrayContentProvider()); |
|
79 list.setInput(Activator.getJSLibraries()); |
|
80 list.addCheckStateListener(new LibraryCheckStateListener(context)); |
|
81 IViewerObservableSet ui = ViewersObservables.observeCheckedElements(list, JSLibrary.class); |
|
82 IObservableSet model = BeansObservables.observeSet(context, WizardContext.LIBRARIES); |
|
83 bindingContext.bindSet(model, ui); |
|
84 setControl(list.getControl()); |
|
85 } |
|
86 |
|
87 } |