### Eclipse Workspace Patch 1.0
#P org.eclipse.ui.ide
Index: src/org/eclipse/ui/internal/ide/messages.properties
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties,v
retrieving revision 1.139
diff -u -r1.139 messages.properties
--- src/org/eclipse/ui/internal/ide/messages.properties 16 Jan 2007 21:50:25 -0000 1.139
+++ src/org/eclipse/ui/internal/ide/messages.properties 24 Jan 2007 23:18:02 -0000
@@ -574,7 +574,7 @@
ContainerGenerator_pathOccupied = Cannot create folder because a file exists at that location: {0}
ResourceGroup_resource = resource
-ResourceGroup_nameExists = The same name already exists.
+ResourceGroup_nameExists = ''{0}'' already exists.
ResourceGroup_folderEmpty = No folder specified.
ResourceGroup_noProject = The specified project does not exist.
ResourceGroup_emptyName = The ''{0}'' name is empty.
Index: extensions/org/eclipse/ui/dialogs/WizardNewFileCreationPage.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/extensions/org/eclipse/ui/dialogs/WizardNewFileCreationPage.java,v
retrieving revision 1.21
diff -u -r1.21 WizardNewFileCreationPage.java
--- extensions/org/eclipse/ui/dialogs/WizardNewFileCreationPage.java 3 Nov 2006 22:07:02 -0000 1.21
+++ extensions/org/eclipse/ui/dialogs/WizardNewFileCreationPage.java 24 Jan 2007 23:18:01 -0000
@@ -100,6 +100,14 @@
// initial value stores
private String initialFileName;
+
+ /**
+ * The file extension to use for this page's file name field when
+ * it does not exist yet.
+ * @see WizardNewFileCreationPage#setFileExtension(String)
+ * @since 3.3
+ */
+ private String initialFileExtension;
private IPath initialContainerFullPath;
@@ -205,6 +213,9 @@
if (initialFileName != null) {
resourceGroup.setResource(initialFileName);
}
+ if (initialFileExtension != null) {
+ resourceGroup.setResourceExtension(initialFileExtension);
+ }
validatePage();
// Show description on opening
setErrorMessage(null);
@@ -448,6 +459,10 @@
/**
* Returns the current file name as entered by the user, or its anticipated
* initial value.
+ *
+ * The current file name will include the file extension if
+ * the preconditions are met.
+ * @see WizardNewFileCreationPage#setFileExtension(String)
*
* @return the file name, its anticipated initial value, or
* null
if no file name is known
@@ -459,6 +474,20 @@
return resourceGroup.getResource();
}
+
+ /**
+ * Returns the file extension.
+ *
+ * @return the file extension or null
.
+ * @see WizardNewFileCreationPage#setFileExtension(String)
+ * @since 3.3
+ */
+ public String getFileExtension() {
+ if (resourceGroup == null) {
+ return initialFileExtension;
+ }
+ return resourceGroup.getResourceExtension();
+ }
/**
* Returns a stream containing the initial contents to be given to new file
@@ -585,6 +614,37 @@
}
/**
+ * Set the only file extension allowed for this page's file name field.
+ * If this page's controls do not exist yet, store it for future use.
+ *
+ * If a file extension is specified, then it will always be
+ * appended with a '.' to the text from the file name field for
+ * validation when the following conditions are met:
+ *
+ * (1) File extension length is greater than 0
+ *
+ * (2) File name field text length is greater than 0
+ *
+ * (3) File name field text does not already end with a '.' and the file
+ * extension specified (case sensitive)
+ *
+ * The file extension will not be reflected in the actual file
+ * name field until the file name field loses focus.
+ *
+ * @param value
+ * The file extension without the '.' prefix
+ * (e.g. 'java', 'xml')
+ * @since 3.3
+ */
+ public void setFileExtension(String value) {
+ if (resourceGroup == null) {
+ initialFileExtension = value;
+ } else {
+ resourceGroup.setResourceExtension(value);
+ }
+ }
+
+ /**
* Checks whether the linked resource target is valid. Sets the error
* message accordingly and returns the status.
*
Index: src/org/eclipse/ui/internal/ide/misc/ResourceAndContainerGroup.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/misc/ResourceAndContainerGroup.java,v
retrieving revision 1.18
diff -u -r1.18 ResourceAndContainerGroup.java
--- src/org/eclipse/ui/internal/ide/misc/ResourceAndContainerGroup.java 21 Jul 2006 20:34:48 -0000 1.18
+++ src/org/eclipse/ui/internal/ide/misc/ResourceAndContainerGroup.java 24 Jan 2007 23:18:02 -0000
@@ -21,6 +21,8 @@
import org.eclipse.jface.fieldassist.FieldAssistColors;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -76,6 +78,13 @@
private ContainerSelectionGroup containerGroup;
private Text resourceNameField;
+
+ /**
+ * The resource extension for the resource name field.
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ * @since 3.3
+ */
+ private String resourceExtension;
// constants
private static final int SIZING_TEXT_FIELD_WIDTH = 250;
@@ -95,7 +104,7 @@
this(parent, client, resourceFieldLabel, resourceType, true);
}
- /**
+ /**
* Create an instance of the group to allow the user
* to enter/select a container and specify a resource
* name.
@@ -190,6 +199,14 @@
// resource name entry field
resourceNameField = new Text(nameGroup, SWT.BORDER);
resourceNameField.addListener(SWT.Modify, this);
+ resourceNameField.addFocusListener(new FocusListener() {
+ public void focusGained(FocusEvent e) {
+ // NO-OP
+ }
+ public void focusLost(FocusEvent e) {
+ handleResourceNameFocusLostEvent();
+ }
+ });
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
| GridData.GRAB_HORIZONTAL);
data.widthHint = SIZING_TEXT_FIELD_WIDTH;
@@ -236,13 +253,69 @@
/**
* Returns a string that is the name of the chosen resource, or an
* empty string if no resource has been entered.
+ *
+ * The name will include the resource extension if the
+ * preconditions are met.
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ *
* @return The resource name
+ * @since 3.3
*/
public String getResource() {
- return resourceNameField.getText();
+ String resource = resourceNameField.getText();
+ if (useResourceExtension()) {
+ return resource + '.' + resourceExtension;
+ }
+ return resource;
+ }
+
+ /**
+ * Returns the resource extension.
+ *
+ * @return The resource extension or null
.
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ * @since 3.3
+ */
+ public String getResourceExtension() {
+ return resourceExtension;
+ }
+
+ /**
+ * Determines whether the resource extension should be added to the
+ * resource name field.
+ *
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ * @return true
if the preconditions are met; otherwise,
+ * false
.
+ * @since 3.3
+ */
+ private boolean useResourceExtension() {
+ String resource = resourceNameField.getText();
+ if ((resourceExtension != null) &&
+ (resourceExtension.length() > 0) &&
+ (resource.length() > 0) &&
+ (resource.endsWith('.' + resourceExtension) == false)) {
+ return true;
+ }
+ return false;
}
/**
+ * Handle the focus lost event from the resource name field.
+ *
+ * Adds the resource extension to the resource name field when it
+ * loses focus (if the preconditions are met).
+ * @see ResourceNameFocusListener
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ * @since 3.3
+ */
+ private void handleResourceNameFocusLostEvent() {
+ if (useResourceExtension()) {
+ setResource(resourceNameField.getText() + '.' + resourceExtension);
+ }
+ }
+
+ /**
* Handles events for all controls in the group.
*
* @param e org.eclipse.swt.widgets.Event
@@ -298,6 +371,33 @@
}
/**
+ * Set the only file extension allowed for the resource name field.
+ *
+ * If a resource extension is specified, then it will always be
+ * appended with a '.' to the text from the resource name field for
+ * validation when the following conditions are met:
+ *
+ * (1) Resource extension length is greater than 0
+ *
+ * (2) Resource name field text length is greater than 0
+ *
+ * (3) Resource name field text does not already end with a '.' and the
+ * resource extension specified (case sensitive)
+ *
+ * The resource extension will not be reflected in the actual
+ * resource name field until the resource name field loses focus.
+ *
+ * @param value
+ * The resource extension without the '.' prefix
+ * (e.g. 'java', 'xml')
+ * @since 3.3
+ */
+ public void setResourceExtension(String value) {
+ resourceExtension = value;
+ validateControls();
+ }
+
+ /**
* Returns a boolean
indicating whether a container name represents
* a valid container resource in the workbench. An error message is stored for
* future reference if the name does not represent a valid container.
@@ -351,7 +451,7 @@
}
IPath path = containerGroup.getContainerFullPath().append(
- resourceNameField.getText());
+ getResource());
return validateFullResourcePath(path);
}
@@ -379,7 +479,7 @@
&& (workspace.getRoot().getFolder(resourcePath).exists() || workspace
.getRoot().getFile(resourcePath).exists())) {
problemType = PROBLEM_RESOURCE_EXIST;
- problemMessage = IDEWorkbenchMessages.ResourceGroup_nameExists;
+ problemMessage = NLS.bind(IDEWorkbenchMessages.ResourceGroup_nameExists, getResource());
return false;
}
return true;
@@ -393,7 +493,7 @@
* @return boolean
indicating validity of the resource name
*/
protected boolean validateResourceName() {
- String resourceName = resourceNameField.getText();
+ String resourceName = getResource();
if (resourceName.length() == 0) {
problemType = PROBLEM_RESOURCE_EMPTY;