|
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.tmw.ui.project; |
|
20 |
|
21 import java.util.Collection; |
|
22 import java.util.LinkedList; |
|
23 |
|
24 import org.eclipse.core.databinding.Binding; |
|
25 import org.eclipse.core.databinding.DataBindingContext; |
|
26 import org.eclipse.core.databinding.UpdateValueStrategy; |
|
27 import org.eclipse.core.databinding.validation.IValidator; |
|
28 import org.eclipse.jface.databinding.swt.ISWTObservableValue; |
|
29 import org.eclipse.jface.databinding.swt.SWTObservables; |
|
30 import org.eclipse.jface.wizard.WizardPage; |
|
31 import org.eclipse.swt.SWT; |
|
32 import org.eclipse.swt.layout.GridData; |
|
33 import org.eclipse.swt.widgets.Composite; |
|
34 import org.eclipse.swt.widgets.Label; |
|
35 import org.eclipse.swt.widgets.Text; |
|
36 import org.symbian.tools.tmw.internal.ui.wizard.CompoundValidator; |
|
37 import org.symbian.tools.tmw.internal.ui.wizard.NonEmptyStringValidator; |
|
38 |
|
39 /** |
|
40 * Boilerplate code to make it easier creating such wizard pages. |
|
41 * |
|
42 * @author Eugene Ostroukhov (eugeneo@symbian.org) |
|
43 */ |
|
44 public abstract class AbstractNewApplicationWizardPage extends WizardPage implements INewApplicationWizardPage { |
|
45 protected DataBindingContext bindingContext; |
|
46 protected final Collection<Binding> bindings = new LinkedList<Binding>(); |
|
47 protected IProjectTemplateContext context; |
|
48 |
|
49 public AbstractNewApplicationWizardPage(String name, String title, String description) { |
|
50 super(name); |
|
51 setTitle(title); |
|
52 setDescription(description); |
|
53 } |
|
54 |
|
55 public void init(IProjectTemplateContext context, DataBindingContext bindingContext) { |
|
56 this.context = context; |
|
57 this.bindingContext = bindingContext; |
|
58 } |
|
59 |
|
60 public void remove() { |
|
61 for (Binding binding : bindings) { |
|
62 bindingContext.removeBinding(binding); |
|
63 } |
|
64 } |
|
65 |
|
66 protected void createLabel(Composite root, String text) { |
|
67 Label label = new Label(root, SWT.NONE); |
|
68 label.setText(text); |
|
69 } |
|
70 |
|
71 protected Text createText(Composite root, String property, String propertyName, DataBindingContext bindingContext, |
|
72 IValidator... validators) { |
|
73 Text text = new Text(root, SWT.BORDER); |
|
74 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
75 ISWTObservableValue view = SWTObservables.observeText(text, SWT.Modify); |
|
76 UpdateValueStrategy strategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE); |
|
77 NonEmptyStringValidator validator = new NonEmptyStringValidator(propertyName); |
|
78 strategy.setBeforeSetValidator(validators.length == 0 ? validator |
|
79 : new CompoundValidator(validator, validators)); |
|
80 bindings.add(bindingContext.bindValue(view, context.getParameterObservable(property), strategy, null)); |
|
81 return text; |
|
82 } |
|
83 } |