📄 copiedwizardnewprojectnameandlocationpage.java
字号:
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
* Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog font should be
* activated and used by other components.
*******************************************************************************/
package org.python.pydev.ui.wizards.project;
import java.io.File;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
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.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.python.pydev.ui.PyProjectPythonDetails;
/**
* First page for the new project creation wizard. This page
* collects the name and location of the new project.
* <p>
* Example useage:
* <pre>
* mainPage = new WizardNewProjectNameAndLocationPage("wizardNewProjectNameAndLocationPage");
* mainPage.setTitle("Project");
* mainPage.setDescription("Create a new project.");
* </pre>
* </p>
*
* NOTE: COPIED FROM org.eclipse.ui.internal.ide.dialogs.WizardNewProjectNameAndLocationPage
* Changed to add the details for the python project type
*/
public class CopiedWizardNewProjectNameAndLocationPage extends WizardPage implements SelectionListener {
// Whether to use default or custom project location
private boolean useDefaults = true;
// initial value stores
private String initialProjectFieldValue;
private IPath initialLocationFieldValue;
// the value the user has entered
private String customLocationFieldValue;
// widgets
private Text projectNameField;
private Text locationPathField;
private Label locationLabel;
private Button browseButton;
private PyProjectPythonDetails.RadioController details;
public String getProjectType(){
return details.getSelected();
}
private Listener nameModifyListener = new Listener() {
public void handleEvent(Event e) {
setLocationForSelection();
setPageComplete(validatePage());
}
};
private Listener locationModifyListener = new Listener() {
public void handleEvent(Event e) {
setPageComplete(validatePage());
}
};
private Button checkSrcFolder;
private boolean checkSrcFolderSelected = true;
// constants
private static final int SIZING_TEXT_FIELD_WIDTH = 250;
/**
* Creates a new project creation wizard page.
*
* @param pageName the name of this page
*/
public CopiedWizardNewProjectNameAndLocationPage(String pageName) {
super(pageName);
setPageComplete(false);
initialLocationFieldValue = Platform.getLocation();
customLocationFieldValue = ""; //$NON-NLS-1$
}
/* (non-Javadoc)
* Method declared on IDialogPage.
*/
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setFont(parent.getFont());
createProjectNameGroup(composite);
createProjectLocationGroup(composite);
createProjectDetails(composite);
checkSrcFolder = new Button(composite , SWT.CHECK);
checkSrcFolder.setText("Cr&eate default 'src' folder and add it to the pythonpath?");
checkSrcFolder.setSelection(true);
checkSrcFolder.addSelectionListener(this);
validatePage();
// Show description on opening
setErrorMessage(null);
setMessage(null);
setControl(composite);
}
/**
* @param composite
*/
private void createProjectDetails(Composite parent) {
Font font = parent.getFont();
Composite projectDetails = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
projectDetails.setLayout(layout);
projectDetails.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
projectDetails.setFont(font);
Label projectTypeLabel = new Label(projectDetails, SWT.NONE);
projectTypeLabel.setFont(font);
projectTypeLabel.setText("Project type");
//let him choose the type of the project
details = new PyProjectPythonDetails.RadioController();
Control createdOn = details.doCreateContents(projectDetails);
details.radioPy24.setSelection(true);
GridData data=new GridData(GridData.FILL_HORIZONTAL);
data.grabExcessHorizontalSpace = true;
createdOn.setLayoutData(data);
}
/**
* Creates the project location specification controls.
*
* @param parent the parent composite
*/
private final void createProjectLocationGroup(Composite parent) {
Font font = parent.getFont();
// project specification group
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
projectGroup.setLayout(layout);
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
projectGroup.setFont(font);
// new project label
Label projectContentsLabel = new Label(projectGroup, SWT.NONE);
projectContentsLabel.setFont(font);
projectContentsLabel.setText("Project contents:");
GridData labelData = new GridData();
labelData.horizontalSpan = 3;
projectContentsLabel.setLayoutData(labelData);
final Button useDefaultsButton = new Button(projectGroup, SWT.CHECK
| SWT.RIGHT);
useDefaultsButton.setText("Use &default");
useDefaultsButton.setSelection(useDefaults);
useDefaultsButton.setFont(font);
GridData buttonData = new GridData();
buttonData.horizontalSpan = 3;
useDefaultsButton.setLayoutData(buttonData);
createUserSpecifiedProjectLocationGroup(projectGroup, !useDefaults);
SelectionListener listener = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
useDefaults = useDefaultsButton.getSelection();
browseButton.setEnabled(!useDefaults);
locationPathField.setEnabled(!useDefaults);
locationLabel.setEnabled(!useDefaults);
if (useDefaults) {
customLocationFieldValue = locationPathField.getText();
setLocationForSelection();
} else {
locationPathField.setText(customLocationFieldValue);
}
}
};
useDefaultsButton.addSelectionListener(listener);
}
/**
* Creates the project name specification controls.
*
* @param parent the parent composite
*/
private final void createProjectNameGroup(Composite parent) {
Font font = parent.getFont();
// project specification group
Composite projectGroup = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
projectGroup.setLayout(layout);
projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// new project label
Label projectLabel = new Label(projectGroup, SWT.NONE);
projectLabel.setFont(font);
projectLabel.setText("&Project name:");
// new project name entry field
projectNameField = new Text(projectGroup, SWT.BORDER);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
projectNameField.setLayoutData(data);
projectNameField.setFont(font);
// Set the initial value first before listener
// to avoid handling an event during the creation.
if (initialProjectFieldValue != null)
projectNameField.setText(initialProjectFieldValue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -