1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug #205214: extending wizard page from "WizardNewProjectCreationPage".

This commit is contained in:
Oleg Krasilnikov 2007-10-05 06:38:13 +00:00
parent 112824a214
commit 284d5d60f0

View file

@ -15,8 +15,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@ -24,12 +22,10 @@ import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
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.dialogs.DialogPage;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.accessibility.AccessibleAdapter;
import org.eclipse.swt.accessibility.AccessibleEvent;
@ -40,23 +36,18 @@ 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.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.ui.newui.PageLayout;
import org.eclipse.cdt.ui.newui.ProjectContentsArea;
import org.eclipse.cdt.ui.newui.UIMessages;
import org.eclipse.cdt.ui.newui.ProjectContentsArea.IErrorMessageReporter;
import org.eclipse.cdt.internal.ui.CPluginImages;
public class CDTMainWizardPage extends WizardPage implements IWizardItemsListListener {
public class CDTMainWizardPage extends WizardNewProjectCreationPage implements IWizardItemsListListener {
private static final Image IMG_CATEGORY = CPluginImages.get(CPluginImages.IMG_OBJS_SEARCHFOLDER);
private static final Image IMG_ITEM = CPluginImages.get(CPluginImages.IMG_OBJS_VARIABLE);
@ -65,22 +56,14 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.CDTWizard"; //$NON-NLS-1$
private static final String ELEMENT_NAME = "wizard"; //$NON-NLS-1$
private static final String CLASS_NAME = "class"; //$NON-NLS-1$
private static final String HELP_CTX = "org.eclipse.ui.ide.new_project_wizard_page_context"; //$NON-NLS-1$
public static final String DESC = "EntryDescriptor"; //$NON-NLS-1$
// constants
private static final int SIZING_TEXT_FIELD_WIDTH = 250;
// initial value stores
private String initialProjectFieldValue;
// widgets
private Text projectNameField;
private Tree tree;
private Composite right;
private Button show_sup;
private Label right_label;
private ProjectContentsArea locationArea;
public CWizardHandler h_selected = null;
/**
@ -97,34 +80,15 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
* Method declared on IDialogPage.
*/
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setFont(parent.getFont());
initializeDialogUnits(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, HELP_CTX);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
createProjectNameGroup(composite);
locationArea = new ProjectContentsArea(getErrorReporter(), composite);
if(initialProjectFieldValue != null) {
locationArea.updateProjectName(initialProjectFieldValue);
}
// Scale the button based on the rest of the dialog
setButtonLayoutData(locationArea.getBrowseButton());
createDynamicGroup(composite);
super.createControl(parent);
createDynamicGroup((Composite)getControl());
switchTo(updateData(tree, right, show_sup, CDTMainWizardPage.this, getWizard()),
getDescriptor(tree));
setPageComplete(validatePage());
// Show description on opening
setErrorMessage(null);
setMessage(null);
setControl(composite);
}
private void createDynamicGroup(Composite parent) {
@ -178,139 +142,16 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
show_sup.setSelection(!CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOSUPP));
}
/**
* Get an error reporter for the receiver.
* @return IErrorMessageReporter
*/
private IErrorMessageReporter getErrorReporter() {
return new IErrorMessageReporter(){
public void reportError(String errorMessage) {
setErrorMessage(errorMessage);
boolean valid = errorMessage == null;
if(valid) valid = validatePage();
setPageComplete(valid);
}
};
}
public IWizardPage getNextPage() {
if (h_selected == null) // cannot continue
return null;
return h_selected.getSpecificPage();
return (h_selected == null) ? null : h_selected.getSpecificPage();
}
/**
* Creates the project name specification controls.
*
* @param parent the parent composite
*/
private final void createProjectNameGroup(Composite parent) {
// 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.setText(UIMessages.getString("CMainWizardPage.8")); //$NON-NLS-1$
projectLabel.setFont(parent.getFont());
// 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(parent.getFont());
// Set the initial value first before listener
// to avoid handling an event during the creation.
if (initialProjectFieldValue != null) {
projectNameField.setText(initialProjectFieldValue);
}
projectNameField.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event e) {
locationArea.updateProjectName(getProjectNameFieldValue());
setPageComplete(validatePage());
}
});
}
/**
* Creates a project resource handle for the current project name field value.
* <p>
* This method does not create the project resource; this is the responsibility
* of <code>IProject::create</code> invoked by the new project resource wizard.
* </p>
*
* @return the new project resource handle
*/
private IProject getProjectHandle() {
return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
}
/**
* Returns the current project name as entered by the user, or its anticipated
* initial value.
*
* @return the project name, its anticipated initial value, or <code>null</code>
* if no project name is known
*/
public String getProjectName() {
if (projectNameField == null) {
return initialProjectFieldValue;
}
return getProjectNameFieldValue();
}
public IPath getProjectLocation() {
if (locationArea.isDefault()) return null;
return new Path(locationArea.getProjectLocation());
return useDefaults() ? null : getLocationPath();
}
public String getProjectLocationPath() {
return locationArea.getProjectLocation();
}
/**
* Returns the value of the project name field
* with leading and trailing spaces removed.
*
* @return the project name in the field
*/
private String getProjectNameFieldValue() {
if (projectNameField == null) {
return ""; //$NON-NLS-1$
}
return projectNameField.getText().trim();
}
/**
* Sets the initial project name that this page will use when
* created. The name is ignored if the createControl(Composite)
* method has already been called. Leading and trailing spaces
* in the name are ignored.
* Providing the name of an existing project will not necessarily
* cause the wizard to warn the user. Callers of this method
* should first check if the project name passed already exists
* in the workspace.
*
* @param name initial project name for this page
*
* @see IWorkspace#validateName(String, int)
*
*/
public void setInitialProjectName(String name) {
if (name == null) {
initialProjectFieldValue = null;
} else {
initialProjectFieldValue = name.trim();
if(locationArea != null) {
locationArea.updateProjectName(name.trim());
}
}
return getLocationPath().toOSString();
}
/**
@ -321,28 +162,15 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
* <code>false</code> if at least one is invalid
*/
protected boolean validatePage() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
setMessage(null);
if (!super.validatePage())
return false;
String projectFieldContents = getProjectNameFieldValue();
if (projectFieldContents.length() == 0) {
setErrorMessage(UIMessages.getString("CMainWizardPage.9")); //$NON-NLS-1$
return false;
}
IStatus nameStatus = workspace.validateName(projectFieldContents,
IResource.PROJECT);
if (!nameStatus.isOK()) {
setErrorMessage(nameStatus.getMessage());
return false;
}
if (projectFieldContents.indexOf('#') >= 0) {
if (getProjectName().indexOf('#') >= 0) {
setErrorMessage(UIMessages.getString("CDTMainWizardPage.0")); //$NON-NLS-1$
return false;
}
boolean bad = true; // should we treat existing project as error
IProject handle = getProjectHandle();
@ -376,9 +204,9 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
}
}
if (!locationArea.isDefault()) {
IStatus locationStatus = workspace.validateProjectLocationURI(handle,
locationArea.getProjectLocationURI());
if (!useDefaults()) {
IStatus locationStatus = ResourcesPlugin.getWorkspace().validateProjectLocationURI(handle,
getLocationURI());
if (!locationStatus.isOK()) {
setErrorMessage(locationStatus.getMessage());
return false;
@ -406,22 +234,15 @@ import org.eclipse.cdt.internal.ui.CPluginImages;
return true;
}
/*
* see @DialogPage.setVisible(boolean)
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
if (visible) projectNameField.setFocus();
}
/**
* Returns the useDefaults.
* @return boolean
*
* @param tree
* @param right
* @param show_sup
* @param ls
* @param wizard
* @return : selected Wizard Handler.
*/
public boolean useDefaults() {
return locationArea.isDefault();
}
public static CWizardHandler updateData(Tree tree, Composite right, Button show_sup, IWizardItemsListListener ls, IWizard wizard) {
// remember selected item
TreeItem[] sel = tree.getSelection();