001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.site;
011:
012: import java.io.File;
013:
014: import org.eclipse.jface.dialogs.Dialog;
015: import org.eclipse.pde.internal.ui.IHelpContextIds;
016: import org.eclipse.pde.internal.ui.PDEUIMessages;
017: import org.eclipse.swt.SWT;
018: import org.eclipse.swt.events.ModifyEvent;
019: import org.eclipse.swt.events.ModifyListener;
020: import org.eclipse.swt.events.SelectionAdapter;
021: import org.eclipse.swt.events.SelectionEvent;
022: import org.eclipse.swt.layout.GridData;
023: import org.eclipse.swt.layout.GridLayout;
024: import org.eclipse.swt.widgets.Button;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Group;
027: import org.eclipse.swt.widgets.Label;
028: import org.eclipse.swt.widgets.Text;
029: import org.eclipse.ui.PlatformUI;
030: import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
031:
032: public class NewSiteProjectCreationPage extends
033: WizardNewProjectCreationPage {
034:
035: private Button fWebButton;
036: protected Text fWebText;
037: private Label fWebLabel;
038:
039: /**
040: * Creates a new project creation wizard page.
041: *
042: * @param pageName the name of this page
043: */
044: public NewSiteProjectCreationPage(String pageName) {
045: super (pageName);
046: }
047:
048: /** (non-Javadoc)
049: * Method declared on IDialogPage.
050: */
051: public void createControl(Composite parent) {
052: super .createControl(parent);
053: Composite control = (Composite) getControl();
054: GridLayout layout = new GridLayout();
055: layout.verticalSpacing = 15;
056: control.setLayout(layout);
057:
058: Group webGroup = new Group(control, SWT.NULL);
059: webGroup
060: .setText(PDEUIMessages.NewSiteProjectCreationPage_webTitle);
061:
062: initializeDialogUnits(parent);
063: layout = new GridLayout();
064: layout.numColumns = 2;
065: webGroup.setLayout(layout);
066: webGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
067:
068: fWebButton = new Button(webGroup, SWT.CHECK);
069: fWebButton.setText(PDEUIMessages.SiteHTML_checkLabel);
070: GridData gd = new GridData();
071: gd.horizontalSpan = 2;
072: fWebButton.setLayoutData(gd);
073: fWebButton.addSelectionListener(new SelectionAdapter() {
074: public void widgetSelected(SelectionEvent e) {
075: fWebLabel.setEnabled(fWebButton.getSelection());
076: fWebText.setEnabled(fWebButton.getSelection());
077: setPageComplete(validatePage());
078: }
079: });
080:
081: fWebLabel = new Label(webGroup, SWT.NULL);
082: fWebLabel.setText(PDEUIMessages.SiteHTML_webLabel);
083: fWebLabel.setEnabled(false);
084:
085: fWebText = new Text(webGroup, SWT.BORDER);
086: fWebText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
087: fWebText.setText("web"); //$NON-NLS-1$
088: fWebText.setEnabled(false);
089: fWebText.addModifyListener(new ModifyListener() {
090: public void modifyText(ModifyEvent e) {
091: setPageComplete(validatePage());
092: }
093: });
094:
095: setPageComplete(validatePage());
096: setControl(control);
097: Dialog.applyDialogFont(control);
098: PlatformUI.getWorkbench().getHelpSystem().setHelp(control,
099: IHelpContextIds.NEW_SITE_MAIN);
100: }
101:
102: public String getWebLocation() {
103: if (fWebButton == null)
104: return null;
105:
106: if (!fWebButton.getSelection())
107: return null;
108:
109: String text = fWebText.getText();
110: if (text.startsWith(File.separator) || text.startsWith("/")) //$NON-NLS-1$
111: text = text.substring(1);
112: if (text.endsWith(File.separator) || text.endsWith("/")) //$NON-NLS-1$
113: text = text.substring(0, text.length() - 1);
114: return text.trim();
115: }
116:
117: protected boolean validatePage() {
118: if (!super .validatePage())
119: return false;
120: String webLocation = getWebLocation();
121: if (webLocation != null && webLocation.trim().length() == 0) {
122: setErrorMessage(PDEUIMessages.SiteHTML_webError);
123: return false;
124: }
125: return true;
126: }
127: }
|