source: trunk/org.modelica.mdt/src/org/modelica/mdt/NewProjectWizard.java @ 64

Last change on this file since 64 was 64, checked in by boris, 19 years ago
  • added some tests for new class wizard
File size: 5.1 KB
Line 
1/*
2 * This file is part of Modelica Development Tooling.
3 *
4 * Copyright (c) 2005, Linköpings universitet, Department of
5 * Computer and Information Science, PELAB
6 *
7 * All rights reserved.
8 *
9 * (The new BSD license, see also
10 * http://www.opensource.org/licenses/bsd-license.php)
11 *
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are
15 * met:
16 *
17 * * Redistributions of source code must retain the above copyright
18 *   notice, this list of conditions and the following disclaimer.
19 *
20 * * Redistributions in binary form must reproduce the above copyright
21 *   notice, this list of conditions and the following disclaimer in
22 *   the documentation and/or other materials provided with the
23 *   distribution.
24 *
25 * * Neither the name of Linköpings universitet nor the names of its
26 *   contributors may be used to endorse or promote products derived from
27 *   this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42package org.modelica.mdt;
43
44import org.modelica.mdt.core.Utility;
45
46import org.eclipse.core.resources.IProject;
47import org.eclipse.core.resources.IResource;
48import org.eclipse.core.resources.ResourcesPlugin;
49import org.eclipse.core.runtime.IStatus;
50import org.eclipse.jface.dialogs.DialogPage;
51import org.eclipse.jface.viewers.IStructuredSelection;
52import org.eclipse.jface.wizard.Wizard;
53import org.eclipse.jface.wizard.WizardPage;
54import org.eclipse.swt.SWT;
55import org.eclipse.swt.events.ModifyEvent;
56import org.eclipse.swt.events.ModifyListener;
57import org.eclipse.swt.layout.GridData;
58import org.eclipse.swt.layout.GridLayout;
59import org.eclipse.swt.widgets.Composite;
60import org.eclipse.swt.widgets.Label;
61import org.eclipse.swt.widgets.Text;
62import org.eclipse.ui.INewWizard;
63import org.eclipse.ui.IWorkbench;
64
65public class NewProjectWizard extends Wizard implements INewWizard
66{
67    public static final String PROJECT_NAME_TAG = "projectNameTag";
68   
69    public class NewProjectPage extends WizardPage
70    {
71        private Text projectName;       
72
73        public NewProjectPage()
74        {
75            super("");
76        }
77       
78        public void createControl(Composite parent)
79        {
80            setPageComplete(false);
81            /*
82             * configure description of this page
83             */
84            setTitle("Create a Modelica project");
85            setDescription("Create a Modelica project in the workspace.");
86           
87            // TODO set image descriptor           
88            //setImageDescriptor(...);
89           
90            /*
91             * setup widgets for this page
92             */
93            Composite composite= new Composite(parent, SWT.NONE);
94            setControl(composite);
95            composite.setFont(parent.getFont());
96           
97            GridLayout layout = new GridLayout();
98            layout.numColumns = 2;
99            composite.setLayout(layout);
100           
101            GridData gd;
102
103            /* project name field */
104            Label l = new Label(composite, SWT.LEFT | SWT.WRAP);
105            l.setText("Project name:");
106            gd = new GridData();
107            gd.horizontalAlignment = GridData.BEGINNING;
108            l.setLayoutData(gd);
109           
110            projectName = new Text(composite, SWT.SINGLE | SWT.BORDER);
111            gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
112            projectName.setLayoutData(gd);
113            MdtPlugin.tag(projectName, PROJECT_NAME_TAG);
114           
115            projectName.addModifyListener(new ModifyListener()
116            {
117                /* check if entered classname is valid */
118                public void modifyText(ModifyEvent e)
119                {
120                    validateProjectName(projectName.getText());
121                }
122            });
123
124        }
125
126        public void validateProjectName(String name)
127        {
128            IStatus res = ResourcesPlugin.getWorkspace().validateName(name, IResource.PROJECT);
129            if (res.isOK())
130            {
131                projectPage.setPageComplete(true);
132                setMessage(null);
133            }
134            else
135            {
136                projectPage.setPageComplete(false);
137                setMessage(res.getMessage(), DialogPage.ERROR);
138            }           
139        }
140
141
142
143    }
144
145    private NewProjectPage projectPage = new NewProjectPage();
146   
147    public void init(IWorkbench workbench, IStructuredSelection selection)
148    {
149        setWindowTitle("New Modelica Project");
150    }   
151   
152
153    @Override
154    public boolean performFinish()
155    {
156        IProject proj = 
157            Utility.createProject(projectPage.projectName.getText(), this.getContainer());
158       
159        return proj != null;
160    }
161   
162    @Override
163    public void addPages()
164    {
165        addPage(projectPage);
166    }
167}
Note: See TracBrowser for help on using the repository browser.