plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/WizardContext.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Mon, 23 Aug 2010 17:20:11 -0700
changeset 474 e2f461f0a9e0
parent 470 d4809db37847
child 478 6c07c755d0c7
permissions -rw-r--r--
All templates are ported to a new framework
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
package org.symbian.tools.tmw.internal.ui.wizard;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
import java.beans.PropertyChangeListener;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
import java.beans.PropertyChangeSupport;
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
     5
import java.io.FilterInputStream;
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
     6
import java.io.IOException;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
import java.io.InputStream;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
import java.text.MessageFormat;
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
     9
import java.util.Collection;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
import java.util.Map;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
import java.util.Set;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
import java.util.TreeMap;
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
    13
import java.util.TreeSet;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
import org.eclipse.core.databinding.DataBindingContext;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
import org.eclipse.core.databinding.UpdateValueStrategy;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
import org.eclipse.core.databinding.beans.BeansObservables;
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    18
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
import org.eclipse.core.databinding.observable.value.IObservableValue;
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    20
import org.eclipse.core.databinding.observable.value.ValueDiff;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import org.eclipse.core.databinding.validation.IValidator;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import org.eclipse.core.resources.IContainer;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import org.eclipse.core.resources.IFile;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import org.eclipse.core.resources.IFolder;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
import org.eclipse.core.resources.IProject;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
import org.eclipse.core.runtime.CoreException;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
import org.eclipse.core.runtime.IPath;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
import org.eclipse.core.runtime.IProgressMonitor;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
import org.eclipse.core.runtime.NullProgressMonitor;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
import org.eclipse.core.runtime.SubProgressMonitor;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
import org.eclipse.jface.databinding.swt.SWTObservables;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
import org.eclipse.swt.SWT;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
import org.eclipse.swt.layout.GridData;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
import org.eclipse.swt.widgets.Composite;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
import org.eclipse.swt.widgets.Text;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
import org.symbian.tools.tmw.core.TMWCore;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
import org.symbian.tools.tmw.internal.util.Util;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
import org.symbian.tools.tmw.ui.TMWCoreUI;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
import org.symbian.tools.tmw.ui.project.IProjectTemplate;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
import org.symbian.tools.tmw.ui.project.IProjectTemplateContext;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
public class WizardContext implements IProjectTemplateContext {
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    45
    public static final String PROJECT_NAME = "projectName";
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    46
    public static final String RUNTIME = "runtime";
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
    public static final String TEMPLATE = "template";
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    48
    public static final String TEMPLATES = "templates";
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
    public static final String WIDGET_ID = "widgetId";
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
    public static final String WIDGET_NAME = "widgetName";
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    52
    private final Map<String, Object> extensions = new TreeMap<String, Object>();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    53
    private final Map<String, IObservableValue> observables = new TreeMap<String, IObservableValue>();
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
    private String projectName = "";
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
    private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this);
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    56
    private IMobileWebRuntime runtime;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
    private IProjectTemplate template = null;
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    58
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
    private String widgetId;
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    60
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
    private String widgetName;
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
    62
    private final Collection<String> jsIncludes = new TreeSet<String>();
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
    public WizardContext() {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
        IMobileWebRuntime[] runtimes = TMWCore.getRuntimesManager().getAllRuntimes();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
        if (runtimes.length > 0) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
            runtime = runtimes[0];
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    69
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    70
466
129c94e78375 Project creation from the templates was implemented
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 465
diff changeset
    71
    public IFile addFile(IProject project, IPath name, InputStream contents, IProgressMonitor monitor)
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    72
            throws CoreException {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    73
        monitor.beginTask(name.toOSString(), 100);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    74
        final IFile file = project.getFile(name);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    75
        if (!file.exists()) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    76
            create(file.getParent());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    77
        }
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
    78
        file.create(new NonClosingStream(contents), false, new SubProgressMonitor(monitor, 100));
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    79
        monitor.done();
466
129c94e78375 Project creation from the templates was implemented
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 465
diff changeset
    80
        return file;
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    81
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    82
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
    public void addPropertyChangeListener(PropertyChangeListener arg0) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
        propertySupport.addPropertyChangeListener(arg0);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
    public void addPropertyChangeListener(String arg0, PropertyChangeListener arg1) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
        propertySupport.addPropertyChangeListener(arg0, arg1);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    89
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    90
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    91
    private void create(IContainer parent) throws CoreException {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    92
        if (!parent.exists() && parent instanceof IFolder) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    93
            create(parent.getParent());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    94
            ((IFolder) parent).create(false, true, new NullProgressMonitor());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    95
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    96
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    97
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    98
    private Text createText(Composite root, IObservableValue model, String propertyName,
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    99
            DataBindingContext bindingContext, AbstractDataBindingPage page, IValidator... validators) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   100
        Text text = new Text(root, SWT.BORDER);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   101
        text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   102
        ISWTObservableValue view = SWTObservables.observeText(text, SWT.Modify);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   103
        UpdateValueStrategy strategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
474
e2f461f0a9e0 All templates are ported to a new framework
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
   104
        NonEmptyStringValidator validator = new NonEmptyStringValidator(propertyName);
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   105
        strategy.setBeforeSetValidator(validators.length == 0 ? validator
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   106
                : new CompoundValidator(validator, validators));
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   107
        bindingContext.bindValue(view, model, strategy, null);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   108
        return text;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   109
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   110
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   111
    protected Text createText(Composite root, String property, String propertyName, DataBindingContext bindingContext,
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   112
            AbstractDataBindingPage page, IValidator... validators) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   113
        return createText(root, BeansObservables.observeValue(this, property), propertyName, bindingContext, page,
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   114
                validators);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   115
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   116
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   117
    private IProjectTemplate getDefaultTemplate(IMobileWebRuntime runtime) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   118
        return TMWCoreUI.getProjectTemplateManager().getDefaultTemplate(runtime);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   119
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   120
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   121
    private String getDefaultWidgetId() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   122
        String name = Util.removeSpaces(getWidgetName());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   123
        return MessageFormat.format("com.company.{0}", name.length() > 0 ? name : "ApplicationName");
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   124
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   125
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   126
    public Map<String, Object> getExtensions() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   127
        return extensions;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   128
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   129
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   130
    public Object getParameter(String parameter) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   131
        return getTemplateVars().get(parameter);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   132
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   133
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   134
    public String[] getParameterNames() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   135
        Set<String> keys = getTemplateVars().keySet();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   136
        return keys.toArray(new String[keys.size()]);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   137
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   138
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   139
    public IObservableValue getParameterObservable(String name) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   140
        IObservableValue value = observables.get(name);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   141
        if (value == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   142
            value = new ObservableParameter(name);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   143
            observables.put(name, value);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   144
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   145
        return value;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   146
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   147
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   148
    public String getProjectName() {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   149
        return projectName;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   150
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   151
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   152
    public IMobileWebRuntime getRuntime() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   153
        return runtime;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   154
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   155
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   156
    public IProjectTemplate getTemplate() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   157
        if (template == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   158
            return getDefaultTemplate(getRuntime());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   159
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   160
        return template;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   161
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   162
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   163
    public IProjectTemplate[] getTemplates() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   164
        return TMWCoreUI.getProjectTemplateManager().getProjectTemplates(getRuntime());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   165
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   166
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   167
    private Map<String, Object> getTemplateVars() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   168
        Map<String, Object> vars = new TreeMap<String, Object>();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   169
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   170
        if (runtime != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   171
            vars.putAll(TMWCoreUI.getProjectTemplateManager().getDefaultTemplateParameterValues(runtime));
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   172
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   173
        final IProjectTemplate t = getTemplate();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   174
        if (t != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   175
            vars.putAll(t.getDefaultParameterValues());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   176
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   177
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   178
        vars.put("widgetName", getWidgetName());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   179
        vars.put("widgetId", getWidgetId());
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   180
        vars.put("jsIncludes", jsIncludes);
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   181
        vars.putAll(extensions);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   182
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   183
        return vars;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   184
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   185
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   186
    public String getWidgetId() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   187
        if (widgetId == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   188
            return getDefaultWidgetId();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   189
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   190
        return widgetId;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   191
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   192
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   193
    public String getWidgetName() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   194
        return widgetName == null ? getProjectName() : widgetName;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   195
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   196
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   197
    public void initialize(IProject project, IProgressMonitor monitor) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   198
        final IProjectTemplate template = getTemplate();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   199
        if (template != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   200
            template.init(project, this, monitor);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   201
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   202
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   203
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   204
    public void putParameter(String key, Object value) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   205
        if (value != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   206
            extensions.put(key, value);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   207
        } else {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   208
            extensions.remove(key);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   209
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   210
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   211
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   212
    public void removePropertyChangeListener(PropertyChangeListener arg0) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   213
        propertySupport.removePropertyChangeListener(arg0);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   214
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   215
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   216
    public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   217
        propertySupport.removePropertyChangeListener(arg0, arg1);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   218
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   219
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   220
    public void setProjectName(String projectName) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   221
        String prev = getProjectName();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   222
        String prevId = getWidgetId();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   223
        String prevName = getWidgetName();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   224
        this.projectName = projectName;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   225
        propertySupport.firePropertyChange(PROJECT_NAME, getProjectName(), prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   226
        if (widgetName == null) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   227
            propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prevName);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   228
            if (widgetId == null) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   229
                propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prevId);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   230
            }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   231
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   232
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   233
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   234
    public void setRuntime(IMobileWebRuntime runtime) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   235
        final IProjectTemplate[] prevTemplates = getTemplates();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   236
        final IProjectTemplate prevTemplate;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   237
        if (template == null) {
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   238
            prevTemplate = getTemplate();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   239
        } else {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   240
            prevTemplate = null;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   241
        }
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   242
        final IMobileWebRuntime prev = this.runtime;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   243
        this.runtime = runtime;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   244
        propertySupport.firePropertyChange(RUNTIME, prev, runtime);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   245
        propertySupport.firePropertyChange(TEMPLATES, prevTemplates, getTemplates());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   246
        if (prevTemplate == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   247
            propertySupport.firePropertyChange(TEMPLATE, prevTemplate, getTemplate());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   248
        }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   249
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   250
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   251
    public void setTemplate(IProjectTemplate template) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   252
        IProjectTemplate prev = this.template;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   253
        this.template = template;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   254
        propertySupport.firePropertyChange(TEMPLATE, template, prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   255
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   256
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   257
    public void setWidgetId(String widgetId) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   258
        String prev = getWidgetId();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   259
        if (getDefaultWidgetId().equals(widgetId)) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   260
            widgetId = null;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   261
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   262
        this.widgetId = widgetId;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   263
        propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   264
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   265
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   266
    public void setWidgetName(String widgetName) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   267
        String prevId = getWidgetId();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   268
        String prev = getWidgetName();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   269
        if (widgetName == getProjectName()) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   270
            this.widgetName = null;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   271
        } else {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   272
            this.widgetName = widgetName;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   273
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   274
        propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   275
        if (widgetId == null) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   276
            propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prevId);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   277
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   278
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   279
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   280
    private final class ObservableParameter extends AbstractObservableValue {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   281
        private final String name;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   282
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   283
        public ObservableParameter(String name) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   284
            this.name = name;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   285
        }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   286
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   287
        public Object getValueType() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   288
            return Object.class;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   289
        }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   290
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   291
        @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   292
        protected Object doGetValue() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   293
            return getParameter(name);
464
0b02f3d6f52c Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 463
diff changeset
   294
        }
0b02f3d6f52c Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 463
diff changeset
   295
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   296
        @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   297
        protected void doSetValue(final Object value) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   298
            final Object prev = getParameter(name);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   299
            putParameter(name, value);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   300
            fireValueChange(new ValueDiff() {
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   301
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   302
                @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   303
                public Object getOldValue() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   304
                    return prev;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   305
                }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   306
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   307
                @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   308
                public Object getNewValue() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   309
                    return value;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   310
                }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   311
            });
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   312
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   313
    }
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   314
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   315
    private static final class NonClosingStream extends FilterInputStream {
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   316
        private NonClosingStream(InputStream in) {
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   317
            super(in);
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   318
        }
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   319
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   320
        @Override
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   321
        public void close() throws IOException {
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   322
            // Avoid closing ZIP file
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   323
        }
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   324
    }
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   325
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   326
    public void addIncludedJsFile(IFile file) {
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   327
        jsIncludes.add(file.getProjectRelativePath().makeRelative().toString());
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   328
    }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   329
}