|
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 java.text.MessageFormat; |
|
22 import java.util.Collection; |
|
23 import java.util.LinkedList; |
|
24 |
|
25 import org.eclipse.core.databinding.Binding; |
|
26 import org.eclipse.core.databinding.DataBindingContext; |
|
27 import org.eclipse.core.databinding.UpdateValueStrategy; |
|
28 import org.eclipse.core.databinding.observable.value.IObservableValue; |
|
29 import org.eclipse.core.databinding.validation.IValidator; |
|
30 import org.eclipse.core.runtime.IStatus; |
|
31 import org.eclipse.core.runtime.Status; |
|
32 import org.eclipse.jface.databinding.swt.ISWTObservableValue; |
|
33 import org.eclipse.jface.databinding.swt.SWTObservables; |
|
34 import org.eclipse.jface.databinding.wizard.WizardPageSupport; |
|
35 import org.eclipse.jface.wizard.WizardPage; |
|
36 import org.eclipse.swt.SWT; |
|
37 import org.eclipse.swt.layout.GridData; |
|
38 import org.eclipse.swt.layout.GridLayout; |
|
39 import org.eclipse.swt.widgets.Button; |
|
40 import org.eclipse.swt.widgets.Composite; |
|
41 import org.eclipse.swt.widgets.Label; |
|
42 import org.eclipse.swt.widgets.Text; |
|
43 import org.symbian.tools.tmw.ui.project.INewApplicationWizardPage; |
|
44 import org.symbian.tools.tmw.ui.project.IProjectTemplate; |
|
45 import org.symbian.tools.tmw.ui.project.IProjectTemplateContext; |
|
46 import org.symbian.tools.wrttools.Activator; |
|
47 import org.symbian.tools.wrttools.util.CompoundValidator; |
|
48 |
|
49 public class NewFlickrApplicationWizardPage extends WizardPage implements INewApplicationWizardPage { |
|
50 private static class NonEmptyStringValidator implements IValidator { |
|
51 private final String propertyName; |
|
52 |
|
53 public NonEmptyStringValidator(String propertyName) { |
|
54 this.propertyName = propertyName; |
|
55 } |
|
56 |
|
57 public IStatus validate(Object value) { |
|
58 if (value == null || value.toString().trim().length() == 0) { |
|
59 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format("Field {0} is empty", |
|
60 propertyName)); |
|
61 } |
|
62 return Status.OK_STATUS; |
|
63 } |
|
64 } |
|
65 private DataBindingContext bindingContext; |
|
66 private final Collection<Binding> bindings = new LinkedList<Binding>(); |
|
67 private IProjectTemplateContext context; |
|
68 |
|
69 public NewFlickrApplicationWizardPage() { |
|
70 super("FlickrFiles"); |
|
71 setTitle("Application Files"); |
|
72 setDescription("Specify application file names"); |
|
73 } |
|
74 |
|
75 protected void addTemplateControls(Composite root) { |
|
76 createLabel(root, "Flickr URL:"); |
|
77 createText(root, "flickrUrl", "Flickr URL", bindingContext); |
|
78 createLabel(root, ""); |
|
79 createLabel(root, ""); |
|
80 } |
|
81 |
|
82 public void createControl(Composite parent) { |
|
83 Composite root = new Composite(parent, SWT.NONE); |
|
84 WizardPageSupport.create(this, bindingContext); |
|
85 root.setLayout(new GridLayout(2, false)); |
|
86 |
|
87 createLabel(root, "Name of main HTML:"); |
|
88 createText(root, IProjectTemplate.CommonKeys.main_html, "HTML file name", bindingContext); |
|
89 createLabel(root, ""); |
|
90 createLabel(root, ""); |
|
91 createLabel(root, "Name of CSS file:"); |
|
92 createText(root, IProjectTemplate.CommonKeys.main_css, "CSS file name", bindingContext); |
|
93 createLabel(root, ""); |
|
94 createLabel(root, ""); |
|
95 createLabel(root, "Name of JavaScript file:"); |
|
96 createText(root, IProjectTemplate.CommonKeys.main_js, "JavaScript file name", bindingContext); |
|
97 |
|
98 createLabel(root, ""); |
|
99 Button homeScreen = new Button(root, SWT.CHECK); |
|
100 homeScreen.setText("Enable HomeScreen"); |
|
101 |
|
102 createLabel(root, ""); |
|
103 createLabel(root, ""); |
|
104 |
|
105 IObservableValue view = SWTObservables.observeSelection(homeScreen); |
|
106 IObservableValue model = context.getParameterObservable(WizardContext.HOME_SCREEN); |
|
107 bindingContext.bindValue(view, model); |
|
108 |
|
109 addTemplateControls(root); |
|
110 |
|
111 setControl(root); |
|
112 } |
|
113 |
|
114 protected void createLabel(Composite root, String text) { |
|
115 Label label = new Label(root, SWT.NONE); |
|
116 label.setText(text); |
|
117 } |
|
118 |
|
119 protected Text createText(Composite root, String property, String propertyName, DataBindingContext bindingContext, |
|
120 IValidator... validators) { |
|
121 Text text = new Text(root, SWT.BORDER); |
|
122 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
123 ISWTObservableValue view = SWTObservables.observeText(text, SWT.Modify); |
|
124 UpdateValueStrategy strategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE); |
|
125 NonEmptyStringValidator validator = new NonEmptyStringValidator(propertyName); |
|
126 strategy.setBeforeSetValidator(validators.length == 0 ? validator |
|
127 : new CompoundValidator(validator, validators)); |
|
128 bindings.add(bindingContext.bindValue(view, context.getParameterObservable(property), strategy, null)); |
|
129 return text; |
|
130 } |
|
131 |
|
132 public void init(IProjectTemplateContext context, DataBindingContext bindingContext) { |
|
133 this.context = context; |
|
134 this.bindingContext = bindingContext; |
|
135 } |
|
136 |
|
137 public void remove() { |
|
138 for (Binding binding : bindings) { |
|
139 bindingContext.removeBinding(binding); |
|
140 } |
|
141 } |
|
142 } |