plugins/org.symbian.tools.tmw.ui/src/org/symbian/tools/tmw/internal/ui/importwizard/ApplicationImportWizardPage.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Wed, 01 Sep 2010 16:27:43 -0700
changeset 481 e908ec135fa1
child 483 109da596fa9d
permissions -rw-r--r--
Application import wizard was refactored into extensible code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
481
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
package org.symbian.tools.tmw.internal.ui.importwizard;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
import java.io.File;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
import java.net.URI;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
import java.text.MessageFormat;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
import java.util.Map;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
import java.util.Map.Entry;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
import java.util.TreeMap;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
import org.eclipse.core.resources.IFile;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
import org.eclipse.core.resources.IProject;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
import org.eclipse.core.resources.IResource;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
import org.eclipse.core.resources.IWorkspace;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
import org.eclipse.core.resources.ResourcesPlugin;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
import org.eclipse.core.runtime.IPath;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
import org.eclipse.core.runtime.IStatus;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
import org.eclipse.core.runtime.Path;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
import org.eclipse.jface.dialogs.Dialog;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
import org.eclipse.jface.layout.GridDataFactory;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
import org.eclipse.jface.viewers.ComboViewer;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    21
import org.eclipse.jface.viewers.ISelection;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import org.eclipse.jface.viewers.ISelectionChangedListener;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    23
import org.eclipse.jface.viewers.IStructuredContentProvider;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    24
import org.eclipse.jface.viewers.IStructuredSelection;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    25
import org.eclipse.jface.viewers.LabelProvider;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    26
import org.eclipse.jface.viewers.SelectionChangedEvent;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
import org.eclipse.jface.viewers.StructuredSelection;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
import org.eclipse.jface.viewers.Viewer;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
import org.eclipse.jface.wizard.WizardPage;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
import org.eclipse.swt.SWT;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
import org.eclipse.swt.events.ModifyEvent;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
import org.eclipse.swt.events.ModifyListener;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
import org.eclipse.swt.events.SelectionAdapter;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
import org.eclipse.swt.events.SelectionEvent;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
import org.eclipse.swt.layout.GridData;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
import org.eclipse.swt.layout.GridLayout;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
import org.eclipse.swt.widgets.Button;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
import org.eclipse.swt.widgets.Composite;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
import org.eclipse.swt.widgets.Event;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
import org.eclipse.swt.widgets.FileDialog;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
import org.eclipse.swt.widgets.Label;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
import org.eclipse.swt.widgets.Listener;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    43
import org.eclipse.swt.widgets.Text;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    44
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    45
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    46
import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    47
import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    48
import org.symbian.tools.tmw.core.runtimes.IMobileWebRuntime;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    49
import org.symbian.tools.tmw.ui.TMWCoreUI;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    50
import org.symbian.tools.tmw.ui.project.IApplicationImporter;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    51
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    52
@SuppressWarnings("restriction")
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    53
public class ApplicationImportWizardPage extends WizardPage {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    54
    public class MapContentProvider implements IStructuredContentProvider {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    55
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    56
        public void dispose() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    57
            // Do nothing
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    58
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    59
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    60
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    61
            // Do nothing
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    62
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    63
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    64
        @SuppressWarnings("unchecked")
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    65
        public Object[] getElements(Object inputElement) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    66
            return ((Map<String, IApplicationImporter>) inputElement).entrySet().toArray();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    67
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    68
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    69
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    70
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    71
    // constants
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    72
    private static final int SIZING_TEXT_FIELD_WIDTH = 250;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    73
    private final IFile file;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    74
    // initial value stores
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    75
    private String initialProjectFieldValue;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    76
    private ProjectContentsLocationArea locationArea;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    77
    private final Listener nameModifyListener = new Listener() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    78
        public void handleEvent(Event e) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    79
            setLocationForSelection();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    80
            boolean valid = validatePage();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    81
            setPageComplete(valid);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    82
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    83
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    84
    };
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    85
    // widgets
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    86
    private Text projectNameField;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    87
    private Text fileName;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    88
    private ComboViewer runtimes;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    89
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    90
    protected ApplicationImportWizardPage(IFile file) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    91
        super("ImportApplication");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    92
        this.file = file;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    93
        setTitle("Import Mobile Web Application");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    94
        setDescription("Create mobile web application project from application package file");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    95
        setPageComplete(false);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    96
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    97
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    98
    protected void browse() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    99
        FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   100
        String path = fileName.getText();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   101
        path = path.trim().length() > 0 ? path.trim() : TMWCoreUI.getDefault().getPreferenceStore()
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   102
                .getString(ApplicationImportWizard.RECENT_IMPORT_PATH);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   103
        fileDialog.setFilterPath(path);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   104
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   105
        final Map<String, String> filters = new TreeMap<String, String>();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   106
        filters.put("*", "All files (*.*)");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   107
        final IApplicationImporter[] importers = TMWCoreUI.getApplicationImporters();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   108
        for (IApplicationImporter importer : importers) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   109
            filters.putAll(importer.getFileFilters());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   110
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   111
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   112
        final String[] extensions = filters.keySet().toArray(new String[filters.size()]);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   113
        final String[] names = filters.values().toArray(new String[filters.size()]);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   114
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   115
        fileDialog.setFilterExtensions(extensions);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   116
        fileDialog.setFilterNames(names);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   117
        String res = fileDialog.open();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   118
        if (res != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   119
            updateWgzName(path.trim(), res);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   120
            fileName.setText(res);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   121
            setPageComplete(validatePage());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   122
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   123
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   124
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   125
    public void createControl(Composite parent) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   126
        Composite composite = new Composite(parent, SWT.NULL);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   127
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   128
        initializeDialogUnits(parent);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   129
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   130
        composite.setLayout(new GridLayout());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   131
        composite.setLayoutData(new GridData(GridData.FILL_BOTH));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   132
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   133
        createProjectNameGroup(composite);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   134
        locationArea = new ProjectContentsLocationArea(getErrorReporter(), composite);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   135
        if (initialProjectFieldValue != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   136
            locationArea.updateProjectName(initialProjectFieldValue);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   137
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   138
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   139
        // Scale the button based on the rest of the dialog
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   140
        setButtonLayoutData(locationArea.getBrowseButton());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   141
        if (file != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   142
            fileName.setText(file.getLocation().toOSString());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   143
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   144
        setPageComplete(validatePage());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   145
        // Show description on opening
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   146
        setErrorMessage(null);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   147
        setMessage(null);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   148
        setControl(composite);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   149
        Dialog.applyDialogFont(composite);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   150
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   151
        setControl(composite);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   152
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   153
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   154
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   155
     * Creates the project name specification controls.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   156
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   157
     * @param parent
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   158
     *            the parent composite
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   159
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   160
    private final void createProjectNameGroup(Composite parent) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   161
        // project specification group
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   162
        Composite projectGroup = new Composite(parent, SWT.NONE);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   163
        GridLayout layout = new GridLayout();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   164
        layout.numColumns = 2;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   165
        projectGroup.setLayout(layout);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   166
        projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   167
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   168
        Label label = new Label(projectGroup, SWT.NONE);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   169
        label.setText("WGZ archive:");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   170
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   171
        Composite buttonText = new Composite(projectGroup, SWT.NONE);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   172
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   173
        buttonText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   174
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   175
        GridLayout gridLayout = new GridLayout(2, false);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   176
        gridLayout.marginWidth = 0;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   177
        gridLayout.marginHeight = 0;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   178
        buttonText.setLayout(gridLayout);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   179
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   180
        fileName = new Text(buttonText, SWT.BORDER);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   181
        fileName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   182
        fileName.addModifyListener(new ModifyListener() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   183
            public void modifyText(ModifyEvent e) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   184
                String val = fileName.getData() != null ? fileName.getData().toString() : "";
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   185
                String name = fileName.getText().trim();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   186
                updateWgzName(val, name);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   187
                fileName.setData(name);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   188
                setPageComplete(validatePage());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   189
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   190
        });
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   191
        Button browse = new Button(buttonText, SWT.NONE);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   192
        browse.setText("Browse...");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   193
        browse.addSelectionListener(new SelectionAdapter() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   194
            @Override
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   195
            public void widgetSelected(SelectionEvent e) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   196
                browse();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   197
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   198
        });
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   199
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   200
        new Label(projectGroup, SWT.NONE).setText("Targeted runtime:");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   201
        runtimes = new ComboViewer(projectGroup, SWT.BORDER | SWT.READ_ONLY);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   202
        runtimes.getCombo().setEnabled(false);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   203
        runtimes.setContentProvider(new MapContentProvider());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   204
        runtimes.setLabelProvider(new LabelProvider() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   205
            @SuppressWarnings("unchecked")
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   206
            @Override
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   207
            public String getText(Object element) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   208
                return ((Map.Entry<String, IApplicationImporter>) element).getKey().toString();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   209
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   210
        });
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   211
        runtimes.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   212
        runtimes.addSelectionChangedListener(new ISelectionChangedListener() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   213
            public void selectionChanged(SelectionChangedEvent event) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   214
                setPageComplete(validatePage());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   215
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   216
        });
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   217
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   218
        Label separator = new Label(projectGroup, SWT.NONE);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   219
        GridDataFactory.generate(separator, 2, 2);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   220
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   221
        // new project label
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   222
        Label projectLabel = new Label(projectGroup, SWT.NONE);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   223
        projectLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   224
        projectLabel.setFont(parent.getFont());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   225
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   226
        // new project name entry field
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   227
        projectNameField = new Text(projectGroup, SWT.BORDER);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   228
        GridData data = new GridData(GridData.FILL_HORIZONTAL);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   229
        data.widthHint = SIZING_TEXT_FIELD_WIDTH;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   230
        projectNameField.setLayoutData(data);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   231
        projectNameField.setFont(parent.getFont());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   232
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   233
        // Set the initial value first before listener
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   234
        // to avoid handling an event during the creation.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   235
        if (initialProjectFieldValue != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   236
            projectNameField.setText(initialProjectFieldValue);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   237
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   238
        projectNameField.addListener(SWT.Modify, nameModifyListener);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   239
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   240
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   241
    public String getArchiveFile() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   242
        return fileName.getText().trim();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   243
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   244
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   245
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   246
     * Get an error reporter for the receiver.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   247
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   248
     * @return IErrorMessageReporter
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   249
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   250
    private IErrorMessageReporter getErrorReporter() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   251
        return new IErrorMessageReporter() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   252
            /*
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   253
             * (non-Javadoc)
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   254
             * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   255
             * @see
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   256
             * org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   257
             * .IErrorMessageReporter#reportError(java.lang.String)
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   258
             */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   259
            public void reportError(String errorMessage, boolean infoOnly) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   260
                if (infoOnly) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   261
                    setMessage(errorMessage, IStatus.INFO);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   262
                    setErrorMessage(null);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   263
                } else {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   264
                    setErrorMessage(errorMessage);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   265
                }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   266
                boolean valid = errorMessage == null;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   267
                if (valid) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   268
                    valid = validatePage();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   269
                }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   270
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   271
                setPageComplete(valid);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   272
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   273
        };
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   274
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   275
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   276
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   277
     * Returns the current project location path as entered by the user, or its
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   278
     * anticipated initial value. Note that if the default has been returned the
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   279
     * path in a project description used to create a project should not be set.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   280
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   281
     * @return the project location path or its anticipated initial value.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   282
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   283
    public IPath getLocationPath() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   284
        return new Path(locationArea.getProjectLocation());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   285
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   286
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   287
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   288
     * /** Returns the current project location URI as entered by the user, or
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   289
     * <code>null</code> if a valid project location has not been entered.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   290
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   291
     * @return the project location URI, or <code>null</code>
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   292
     * @since 3.2
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   293
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   294
    public URI getLocationURI() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   295
        return locationArea.getProjectLocationURI();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   296
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   297
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   298
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   299
     * Creates a project resource handle for the current project name field
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   300
     * value. The project handle is created relative to the workspace root.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   301
     * <p>
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   302
     * This method does not create the project resource; this is the
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   303
     * responsibility of <code>IProject::create</code> invoked by the new
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   304
     * project resource wizard.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   305
     * </p>
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   306
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   307
     * @return the new project resource handle
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   308
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   309
    public IProject getProjectHandle() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   310
        return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   311
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   312
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   313
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   314
     * Returns the current project name as entered by the user, or its
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   315
     * anticipated initial value.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   316
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   317
     * @return the project name, its anticipated initial value, or
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   318
     *         <code>null</code> if no project name is known
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   319
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   320
    public String getProjectName() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   321
        if (projectNameField == null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   322
            return initialProjectFieldValue;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   323
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   324
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   325
        return getProjectNameFieldValue();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   326
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   327
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   328
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   329
     * Returns the value of the project name field with leading and trailing
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   330
     * spaces removed.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   331
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   332
     * @return the project name in the field
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   333
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   334
    private String getProjectNameFieldValue() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   335
        if (projectNameField == null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   336
            return ""; //$NON-NLS-1$
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   337
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   338
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   339
        return projectNameField.getText().trim();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   340
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   341
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   342
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   343
     * Sets the initial project name that this page will use when created. The
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   344
     * name is ignored if the createControl(Composite) method has already been
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   345
     * called. Leading and trailing spaces in the name are ignored. Providing
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   346
     * the name of an existing project will not necessarily cause the wizard to
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   347
     * warn the user. Callers of this method should first check if the project
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   348
     * name passed already exists in the workspace.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   349
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   350
     * @param name
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   351
     *            initial project name for this page
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   352
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   353
     * @see IWorkspace#validateName(String, int)
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   354
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   355
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   356
    public void setInitialProjectName(String name) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   357
        if (name == null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   358
            initialProjectFieldValue = null;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   359
        } else {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   360
            initialProjectFieldValue = name.trim();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   361
            if (locationArea != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   362
                locationArea.updateProjectName(name.trim());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   363
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   364
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   365
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   366
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   367
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   368
     * Set the location to the default location if we are set to useDefaults.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   369
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   370
    void setLocationForSelection() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   371
        locationArea.updateProjectName(getProjectNameFieldValue());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   372
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   373
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   374
    private void updateWgzName(String oldValue, String newValue) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   375
        String project = projectNameField.getText().trim();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   376
        if (project.length() == 0 || project.equals(new Path(oldValue).removeFileExtension().lastSegment())) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   377
            String projectName = new Path(newValue).removeFileExtension().lastSegment();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   378
            projectNameField.setText(projectName);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   379
            locationArea.updateProjectName(projectName);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   380
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   381
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   382
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   383
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   384
     * Returns the useDefaults.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   385
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   386
     * @return boolean
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   387
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   388
    public boolean useDefaults() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   389
        return locationArea.isDefault();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   390
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   391
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   392
    private boolean validating = false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   393
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   394
    /**
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   395
     * Returns whether this page's controls currently all contain valid values.
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   396
     * 
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   397
     * @return <code>true</code> if all controls are valid, and
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   398
     *         <code>false</code> if at least one is invalid
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   399
     */
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   400
    protected synchronized boolean validatePage() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   401
        if (validating) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   402
            return true;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   403
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   404
        validating = true;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   405
        try {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   406
            final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   407
            final String archive = fileName.getText().trim();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   408
            if (archive.equals("")) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   409
                setErrorMessage(null);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   410
                setMessage("Archive name must be specified");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   411
                return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   412
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   413
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   414
            final File f = new File(archive);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   415
            if (!isValidArchive(f)) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   416
                setErrorMessage(MessageFormat.format("{0} is not a valid application archive", archive));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   417
                return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   418
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   419
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   420
            final String projectFieldContents = getProjectNameFieldValue();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   421
            if (projectFieldContents.equals("")) { //$NON-NLS-1$
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   422
                setErrorMessage(null);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   423
                setMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   424
                return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   425
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   426
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   427
            final IStatus nameStatus = workspace.validateName(projectFieldContents, IResource.PROJECT);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   428
            if (!nameStatus.isOK()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   429
                setErrorMessage(nameStatus.getMessage());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   430
                return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   431
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   432
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   433
            final IProject handle = getProjectHandle();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   434
            if (handle.exists()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   435
                setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   436
                return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   437
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   438
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   439
            final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectNameFieldValue());
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   440
            locationArea.setExistingProject(project);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   441
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   442
            final String validLocationMessage = locationArea.checkValidLocation();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   443
            if (validLocationMessage != null) { // there is no destination location given
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   444
                setErrorMessage(validLocationMessage);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   445
                return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   446
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   447
            if (runtimes.getSelection().isEmpty()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   448
                setErrorMessage("Select target runtime");
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   449
                return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   450
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   451
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   452
            setErrorMessage(null);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   453
            setMessage(null);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   454
            return true;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   455
        } finally {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   456
            validating = false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   457
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   458
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   459
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   460
    private boolean isValidArchive(File f) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   461
        if (f.isFile()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   462
            final Map<String, IApplicationImporter> importers = new TreeMap<String, IApplicationImporter>();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   463
            final IApplicationImporter[] applicationImporters = TMWCoreUI.getApplicationImporters();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   464
            for (IApplicationImporter importer : applicationImporters) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   465
                final IMobileWebRuntime runtime = importer.getApplicationRuntime(f);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   466
                if (runtime != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   467
                    importers.put(runtime.getName(), importer);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   468
                }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   469
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   470
            final ISelection selection = runtimes.getSelection();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   471
            Object sel = null;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   472
            if (!selection.isEmpty()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   473
                @SuppressWarnings("unchecked")
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   474
                Map.Entry<String, IApplicationImporter> entry = (Entry<String, IApplicationImporter>) ((IStructuredSelection) selection)
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   475
                        .getFirstElement();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   476
                for (Entry<String, IApplicationImporter> ent : importers.entrySet()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   477
                    if (ent.getKey().equals(entry.getKey())) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   478
                        sel = ent;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   479
                    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   480
                }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   481
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   482
            runtimes.setInput(importers);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   483
            if (sel != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   484
                runtimes.setSelection(new StructuredSelection(sel));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   485
            } else if (importers.size() == 1) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   486
                runtimes.setSelection(new StructuredSelection(importers.entrySet().iterator().next()));
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   487
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   488
            runtimes.getControl().setEnabled(importers.size() > 1);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   489
            return !runtimes.getSelection().isEmpty();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   490
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   491
        return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   492
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   493
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   494
    public IApplicationImporter getImporter() {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   495
        if (runtimes == null || runtimes.getControl().isDisposed()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   496
            return null;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   497
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   498
        @SuppressWarnings("unchecked")
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   499
        final Map.Entry<String, IApplicationImporter> element = (Entry<String, IApplicationImporter>) ((IStructuredSelection) runtimes
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   500
                .getSelection()).getFirstElement();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   501
        return element.getValue();
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   502
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   503
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
   504
}