KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > site > NewSiteProjectCreationPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.wizards.site;
12
13 import java.io.File JavaDoc;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.pde.internal.ui.IHelpContextIds;
17 import org.eclipse.pde.internal.ui.PDEUIMessages;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.events.ModifyEvent;
20 import org.eclipse.swt.events.ModifyListener;
21 import org.eclipse.swt.events.SelectionAdapter;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Button;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Group;
28 import org.eclipse.swt.widgets.Label;
29 import org.eclipse.swt.widgets.Text;
30 import org.eclipse.ui.PlatformUI;
31 import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
32
33 public class NewSiteProjectCreationPage extends WizardNewProjectCreationPage {
34     
35     private Button fWebButton;
36     protected Text fWebText;
37     private Label fWebLabel;
38         
39     /**
40      * Creates a new project creation wizard page.
41      *
42      * @param pageName the name of this page
43      */

44     public NewSiteProjectCreationPage(String JavaDoc pageName) {
45         super(pageName);
46     }
47     
48     /** (non-Javadoc)
49      * Method declared on IDialogPage.
50      */

51     public void createControl(Composite parent) {
52         super.createControl(parent);
53         Composite control = (Composite)getControl();
54         GridLayout layout = new GridLayout();
55         layout.verticalSpacing = 15;
56         control.setLayout(layout);
57         
58         Group webGroup = new Group(control, SWT.NULL);
59         webGroup.setText(PDEUIMessages.NewSiteProjectCreationPage_webTitle);
60         
61         initializeDialogUnits(parent);
62         layout = new GridLayout();
63         layout.numColumns = 2;
64         webGroup.setLayout(layout);
65         webGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
66
67         fWebButton = new Button(webGroup, SWT.CHECK);
68         fWebButton.setText(PDEUIMessages.SiteHTML_checkLabel);
69         GridData gd = new GridData();
70         gd.horizontalSpan = 2;
71         fWebButton.setLayoutData(gd);
72         fWebButton.addSelectionListener(new SelectionAdapter(){
73             public void widgetSelected(SelectionEvent e){
74                 fWebLabel.setEnabled(fWebButton.getSelection());
75                 fWebText.setEnabled(fWebButton.getSelection());
76                 setPageComplete(validatePage());
77             }
78         });
79         
80         fWebLabel = new Label(webGroup, SWT.NULL);
81         fWebLabel.setText(PDEUIMessages.SiteHTML_webLabel);
82         fWebLabel.setEnabled(false);
83         
84         fWebText = new Text(webGroup, SWT.BORDER);
85         fWebText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
86         fWebText.setText("web"); //$NON-NLS-1$
87
fWebText.setEnabled(false);
88         fWebText.addModifyListener(new ModifyListener() {
89             public void modifyText(ModifyEvent e) {
90                 setPageComplete(validatePage());
91             }
92         });
93
94         setPageComplete(validatePage());
95         setControl(webGroup);
96         Dialog.applyDialogFont(webGroup);
97         PlatformUI.getWorkbench().getHelpSystem().setHelp(control, IHelpContextIds.NEW_SITE_MAIN);
98     }
99
100     public String JavaDoc getWebLocation(){
101         if (fWebButton == null)
102             return null;
103         
104         if (!fWebButton.getSelection())
105             return null;
106         
107         String JavaDoc text = fWebText.getText();
108         if (text.startsWith(File.separator) || text.startsWith("/")) //$NON-NLS-1$
109
text = text.substring(1);
110         if (text.endsWith(File.separator) || text.endsWith("/")) //$NON-NLS-1$
111
text = text.substring(0,text.length()-1);
112         return text.trim();
113     }
114
115     protected boolean validatePage() {
116         if (!super.validatePage())
117             return false;
118         String JavaDoc webLocation = getWebLocation();
119         if (webLocation != null && webLocation.trim().length() == 0){
120             setErrorMessage(PDEUIMessages.SiteHTML_webError);
121             return false;
122         }
123         return true;
124     }
125 }
126
Popular Tags