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

Last change on this file since 93 was 89, checked in by boris, 19 years ago
  • removed tracing printouts
  • created org.modelica.mdt.ui package and put stuff there
File size: 5.2 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.ui;
43
44import org.modelica.mdt.MdtPlugin;
45import org.modelica.mdt.core.ModelicaCore;
46
47import org.eclipse.core.resources.IProject;
48import org.eclipse.core.resources.IResource;
49import org.eclipse.core.resources.ResourcesPlugin;
50import org.eclipse.core.runtime.IStatus;
51import org.eclipse.jface.dialogs.DialogPage;
52import org.eclipse.jface.viewers.IStructuredSelection;
53import org.eclipse.jface.wizard.Wizard;
54import org.eclipse.jface.wizard.WizardPage;
55import org.eclipse.swt.SWT;
56import org.eclipse.swt.events.ModifyEvent;
57import org.eclipse.swt.events.ModifyListener;
58import org.eclipse.swt.layout.GridData;
59import org.eclipse.swt.layout.GridLayout;
60import org.eclipse.swt.widgets.Composite;
61import org.eclipse.swt.widgets.Label;
62import org.eclipse.swt.widgets.Text;
63import org.eclipse.ui.INewWizard;
64import org.eclipse.ui.IWorkbench;
65
66public class NewProjectWizard extends Wizard implements INewWizard
67{
68    public static final String PROJECT_NAME_TAG = "projectNameTag";
69   
70    public class NewProjectPage extends WizardPage
71    {
72        private Text projectName;       
73
74        public NewProjectPage()
75        {
76            super("");
77        }
78       
79        public void createControl(Composite parent)
80        {
81            setPageComplete(false);
82            /*
83             * configure description of this page
84             */
85            setTitle("Create a Modelica project");
86            setDescription("Create a Modelica project in the workspace.");
87           
88            // TODO set image descriptor           
89            //setImageDescriptor(...);
90           
91            /*
92             * setup widgets for this page
93             */
94            Composite composite= new Composite(parent, SWT.NONE);
95            setControl(composite);
96            composite.setFont(parent.getFont());
97           
98            GridLayout layout = new GridLayout();
99            layout.numColumns = 2;
100            composite.setLayout(layout);
101           
102            GridData gd;
103
104            /* project name field */
105            Label l = new Label(composite, SWT.LEFT | SWT.WRAP);
106            l.setText("Project name:");
107            gd = new GridData();
108            gd.horizontalAlignment = GridData.BEGINNING;
109            l.setLayoutData(gd);
110           
111            projectName = new Text(composite, SWT.SINGLE | SWT.BORDER);
112            gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
113            projectName.setLayoutData(gd);
114            MdtPlugin.tag(projectName, PROJECT_NAME_TAG);
115           
116            projectName.addModifyListener(new ModifyListener()
117            {
118                /* check if entered classname is valid */
119                public void modifyText(ModifyEvent e)
120                {
121                    validateProjectName(projectName.getText());
122                }
123            });
124
125        }
126
127        public void validateProjectName(String name)
128        {
129            IStatus res = ResourcesPlugin.getWorkspace().validateName(name, IResource.PROJECT);
130            if (res.isOK())
131            {
132                projectPage.setPageComplete(true);
133                setMessage(null);
134            }
135            else
136            {
137                projectPage.setPageComplete(false);
138                setMessage(res.getMessage(), DialogPage.ERROR);
139            }           
140        }
141
142
143
144    }
145
146    private NewProjectPage projectPage = new NewProjectPage();
147   
148    public void init(IWorkbench workbench, IStructuredSelection selection)
149    {
150        setWindowTitle("New Modelica Project");
151    }   
152   
153
154    @Override
155    public boolean performFinish()
156    {
157        IProject proj = 
158            ModelicaCore.createProject(projectPage.projectName.getText(), this.getContainer());
159       
160        return proj != null;
161    }
162   
163    @Override
164    public void addPages()
165    {
166        addPage(projectPage);
167    }
168}
Note: See TracBrowser for help on using the repository browser.