summaryrefslogtreecommitdiff
path: root/src/plugins/android/src/com/motorola/studio/android/wizards/widget/NewAndroidWidgetProjectMainPage.java
blob: 011212072262a45b2384fe4d303ea1ca9ebafb85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.motorola.studio.android.wizards.widget;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.PlatformUI;

import com.motorola.studio.android.AndroidPlugin;
import com.motorola.studio.android.i18n.AndroidNLS;
import com.motorola.studio.android.model.AndroidProject;
import com.motorola.studio.android.model.IWizardModel;
import com.motorola.studio.android.wizards.elements.ApplicationGroup;
import com.motorola.studio.android.wizards.elements.ProjectNameGroup;
import com.motorola.studio.android.wizards.elements.SdkTargetSelector;
import com.motorola.studio.android.wizards.elements.WidgetLocationGroup;

/**
 * Class that represents the main page in the New Widget Project Wizard
 */
public class NewAndroidWidgetProjectMainPage extends WizardPage
{

    private static final String PAGE_NAME = "Main Page";

    private final AndroidProject project;

    private final String NEW_WIDGET_PROJECT_HELP = AndroidPlugin.PLUGIN_ID + ".newwdgproj";

    /**
     * Listener for the wizard changes
     */
    private final Listener modelListener = new Listener()
    {
        public void handleEvent(Event arg0)
        {
            IStatus status = project.getStatus();
            int severity = status.getSeverity();
            setPageComplete(severity != IStatus.ERROR);

            int msgType;
            switch (severity)
            {
                case IStatus.OK:
                    msgType = DialogPage.NONE;
                    break;
                case IStatus.ERROR:
                    msgType = DialogPage.ERROR;
                    break;
                case IStatus.WARNING:
                    msgType = DialogPage.WARNING;
                    break;
                default:
                    msgType = DialogPage.NONE;
                    break;
            }
            String defaultMessage =
                    AndroidNLS.UI_NewAndroidWidgetProjectMainPage_SubtitleCreateProject;
            setMessage(status.isOK() ? defaultMessage : status.getMessage(), msgType);
        }
    };

    /**
     * Constructor
     * 
     * @param project The selected project 
     */
    public NewAndroidWidgetProjectMainPage(AndroidProject project)
    {
        super(PAGE_NAME);
        this.project = project;
        setTitle(AndroidNLS.UI_NewAndroidWidgetProjectMainPage_TitleCreateProject);
        setDescription(AndroidNLS.UI_NewAndroidWidgetProjectMainPage_WizardProjectDescription);
        setPageComplete(false);

    }

    /**
     * Create the page SWT controls.
     * 
     * @param parent The parent composite
     */
    public void createControl(Composite parent)
    {
        Composite composite = new Composite(parent, SWT.NULL);
        composite.setFont(parent.getFont());

        initializeDialogUnits(parent);

        composite.setLayout(new GridLayout());
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        //only put the project and location groups: no vertical resize, no vertical style

        ProjectNameGroup projectNameGroup = new ProjectNameGroup(composite, project);
        projectNameGroup.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

        // Create Location Group
        Group groupForLocation = new Group(composite, SWT.SHADOW_ETCHED_IN);
        // Layout has 1 column
        groupForLocation.setLayout(new GridLayout());
        groupForLocation.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
        groupForLocation.setFont(composite.getFont());
        groupForLocation.setText(AndroidNLS.UI_NewAndroidWidgetProjectMainPage_LabelContents);

        WidgetLocationGroup locationGroup =
                new WidgetLocationGroup(groupForLocation, project, this);
        // End of Location Group

        // Create SDK Group
        //create sdk group with vertical resize, grabbing excedding space
        Group groupForTarget = new Group(composite, SWT.SHADOW_ETCHED_IN);
        groupForTarget.setLayout(new GridLayout());
        groupForTarget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        groupForTarget.setFont(composite.getFont());
        groupForTarget.setText(AndroidNLS.UI_NewAndroidProjectMainPage_LabelTarget);

        final SdkTargetSelector mSdkTargetSelector = new SdkTargetSelector(groupForTarget, project);
        //End of Target Creation

        // Create Package Group
        Group group = new Group(composite, SWT.SHADOW_ETCHED_IN);

        // Layout has 1 column
        group.setLayout(new GridLayout());
        group.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
        group.setFont(composite.getFont());
        group.setText(AndroidNLS.UI_NewAndroidProjectMainPage_LabelApplication);

        final ApplicationGroup applicationGroup = new ApplicationGroup(group, project);

        Listener listener = new Listener()
        {

            public void handleEvent(Event arg0)
            {
                applicationGroup.updateDefaultName();
                applicationGroup.updateMinSdkVersion();
                getContainer().updateButtons();
            }
        };

        projectNameGroup.addListener(IWizardModel.MODIFIED, modelListener);
        projectNameGroup.addListener(IWizardModel.MODIFIED, listener);
        locationGroup.addListener(IWizardModel.MODIFIED, listener);
        locationGroup.addListener(IWizardModel.MODIFIED, modelListener);
        applicationGroup.addListener(IWizardModel.MODIFIED, modelListener);
        mSdkTargetSelector.addListener(IWizardModel.MODIFIED, modelListener);
        mSdkTargetSelector.addListener(IWizardModel.MODIFIED, listener);

        //create application group with no vertical resize
        setPageComplete(false);

        // Show description the first time
        setErrorMessage(null);
        setMessage(null);

        projectNameGroup.forceFocus();
        setControl(composite);
        composite.layout(true);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, NEW_WIDGET_PROJECT_HELP);
    }

    /*
     * (non-Javadoc)
     * @see org.eclipse.jface.dialogs.DialogPage#setButtonLayoutData(org.eclipse.swt.widgets.Button)
     */
    @Override
    public GridData setButtonLayoutData(Button button)
    {
        return super.setButtonLayoutData(button);
    }

}