plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/wizard/WizardContext.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 31 Aug 2010 11:58:53 -0700
changeset 479 518afa7c6d2f
parent 478 6c07c755d0c7
child 480 b6d992b9b998
permissions -rw-r--r--
Minor refactoring to make API more clear
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;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    58
    private String widgetId;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
    private String widgetName;
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
    60
    private final Collection<String> jsIncludes = new TreeSet<String>();
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
    public WizardContext() {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
        IMobileWebRuntime[] runtimes = TMWCore.getRuntimesManager().getAllRuntimes();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
        if (runtimes.length > 0) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
            runtime = runtimes[0];
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
466
129c94e78375 Project creation from the templates was implemented
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 465
diff changeset
    69
    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
    70
            throws CoreException {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    71
        monitor.beginTask(name.toOSString(), 100);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    72
        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
    73
        if (!file.exists()) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    74
            create(file.getParent());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    75
        }
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
    76
        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
    77
        monitor.done();
466
129c94e78375 Project creation from the templates was implemented
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 465
diff changeset
    78
        return file;
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    79
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    80
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
    public void addPropertyChangeListener(PropertyChangeListener arg0) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
        propertySupport.addPropertyChangeListener(arg0);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
    public void addPropertyChangeListener(String arg0, PropertyChangeListener arg1) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
        propertySupport.addPropertyChangeListener(arg0, arg1);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    89
    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
    90
        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
    91
            create(parent.getParent());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    92
            ((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
    93
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
    94
    }
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
    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
    97
            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
    98
        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
    99
        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
   100
        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
   101
        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
   102
        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
   103
        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
   104
                : new CompoundValidator(validator, validators));
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   105
        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
   106
        return text;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   107
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   108
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   109
    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
   110
            AbstractDataBindingPage page, IValidator... validators) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   111
        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
   112
                validators);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   113
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   114
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   115
    private IProjectTemplate getDefaultTemplate(IMobileWebRuntime runtime) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   116
        return TMWCoreUI.getProjectTemplateManager().getDefaultTemplate(runtime);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   117
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   118
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   119
    private String getDefaultWidgetId() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   120
        String name = Util.removeSpaces(getWidgetName());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   121
        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
   122
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   123
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   124
    public Map<String, Object> getExtensions() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   125
        return extensions;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   126
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   127
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   128
    public Object getParameter(String parameter) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   129
        return getTemplateVars().get(parameter);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   130
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   131
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   132
    public String[] getParameterNames() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   133
        Set<String> keys = getTemplateVars().keySet();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   134
        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
   135
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   136
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   137
    public IObservableValue getParameterObservable(String name) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   138
        IObservableValue value = observables.get(name);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   139
        if (value == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   140
            value = new ObservableParameter(name);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   141
            observables.put(name, value);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   142
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   143
        return 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
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   146
    public String getProjectName() {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   147
        return projectName;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   148
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   149
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   150
    public IMobileWebRuntime getRuntime() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   151
        return runtime;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   152
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   153
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   154
    public IProjectTemplate getTemplate() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   155
        if (template == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   156
            return getDefaultTemplate(getRuntime());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   157
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   158
        return template;
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
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   161
    public IProjectTemplate[] getTemplates() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   162
        return TMWCoreUI.getProjectTemplateManager().getProjectTemplates(getRuntime());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   163
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   164
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   165
    private Map<String, Object> getTemplateVars() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   166
        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
   167
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   168
        if (runtime != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   169
            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
   170
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   171
        final IProjectTemplate t = getTemplate();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   172
        if (t != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   173
            vars.putAll(t.getDefaultParameterValues());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   174
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   175
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   176
        vars.put("widgetName", getWidgetName());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   177
        vars.put("widgetId", getWidgetId());
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   178
        vars.put("jsIncludes", jsIncludes);
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   179
        vars.putAll(extensions);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   180
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   181
        return vars;
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
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   184
    public String getWidgetId() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   185
        if (widgetId == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   186
            return getDefaultWidgetId();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   187
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   188
        return widgetId;
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
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   191
    public String getWidgetName() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   192
        return widgetName == null ? getProjectName() : widgetName;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   193
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   194
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   195
    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
   196
        final IProjectTemplate template = getTemplate();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   197
        if (template != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   198
            template.init(project, this, monitor);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   199
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   200
    }
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
    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
   203
        if (value != null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   204
            extensions.put(key, value);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   205
        } else {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   206
            extensions.remove(key);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   207
        }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   208
    }
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
    public void removePropertyChangeListener(PropertyChangeListener arg0) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   211
        propertySupport.removePropertyChangeListener(arg0);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   212
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   213
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   214
    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
   215
        propertySupport.removePropertyChangeListener(arg0, arg1);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   216
    }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   217
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   218
    public void setProjectName(String projectName) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   219
        String prev = getProjectName();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   220
        String prevId = getWidgetId();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   221
        String prevName = getWidgetName();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   222
        this.projectName = projectName;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   223
        propertySupport.firePropertyChange(PROJECT_NAME, getProjectName(), prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   224
        if (widgetName == null) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   225
            propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prevName);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   226
            if (widgetId == null) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   227
                propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prevId);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   228
            }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   229
        }
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
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   232
    public void setRuntime(IMobileWebRuntime runtime) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   233
        final IProjectTemplate[] prevTemplates = getTemplates();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   234
        final IProjectTemplate prevTemplate;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   235
        if (template == null) {
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   236
            prevTemplate = getTemplate();
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   237
        } else {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   238
            prevTemplate = null;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   239
        }
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   240
        final IMobileWebRuntime prev = this.runtime;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   241
        this.runtime = runtime;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   242
        propertySupport.firePropertyChange(RUNTIME, prev, runtime);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   243
        propertySupport.firePropertyChange(TEMPLATES, prevTemplates, getTemplates());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   244
        if (prevTemplate == null) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   245
            propertySupport.firePropertyChange(TEMPLATE, prevTemplate, getTemplate());
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   246
        }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   247
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   248
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   249
    public void setTemplate(IProjectTemplate template) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   250
        IProjectTemplate prev = this.template;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   251
        this.template = template;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   252
        propertySupport.firePropertyChange(TEMPLATE, template, prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   253
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   254
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   255
    public void setWidgetId(String widgetId) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   256
        String prev = getWidgetId();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   257
        if (getDefaultWidgetId().equals(widgetId)) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   258
            widgetId = null;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   259
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   260
        this.widgetId = widgetId;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   261
        propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   262
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   263
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   264
    public void setWidgetName(String widgetName) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   265
        String prevId = getWidgetId();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   266
        String prev = getWidgetName();
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   267
        if (widgetName == getProjectName()) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   268
            this.widgetName = null;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   269
        } else {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   270
            this.widgetName = widgetName;
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   271
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   272
        propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), prev);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   273
        if (widgetId == null) {
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   274
            propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prevId);
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   275
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   276
    }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   277
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   278
    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
   279
        private final String name;
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   280
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   281
        public ObservableParameter(String name) {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   282
            this.name = name;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   283
        }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   284
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   285
        public Object getValueType() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   286
            return Object.class;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   287
        }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   288
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   289
        @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   290
        protected Object doGetValue() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   291
            return getParameter(name);
464
0b02f3d6f52c Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 463
diff changeset
   292
        }
0b02f3d6f52c Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 463
diff changeset
   293
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   294
        @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   295
        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
   296
            final Object prev = getParameter(name);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   297
            putParameter(name, value);
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   298
            fireValueChange(new ValueDiff() {
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   299
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   300
                @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   301
                public Object getOldValue() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   302
                    return prev;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   303
                }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   304
465
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   305
                @Override
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   306
                public Object getNewValue() {
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   307
                    return value;
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   308
                }
87920e15f8eb Added a way to contribute wizard pages for templates
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 464
diff changeset
   309
            });
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   310
        }
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   311
    }
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   312
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   313
    private static final class NonClosingStream extends FilterInputStream {
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   314
        private NonClosingStream(InputStream in) {
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   315
            super(in);
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   316
        }
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   317
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   318
        @Override
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   319
        public void close() throws IOException {
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   320
            // Avoid closing ZIP file
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   321
        }
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   322
    }
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   323
479
518afa7c6d2f Minor refactoring to make API more clear
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 478
diff changeset
   324
    public void addIncludedJsFile(IProject project, IFile file) {
467
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   325
        jsIncludes.add(file.getProjectRelativePath().makeRelative().toString());
5a2901872fcf WRTKit facet was introduced
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 466
diff changeset
   326
    }
463
aea4c83725d8 Project template work-in-progress
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   327
}