Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-patch] fix for bug #48783

This patch replaces the previous one and includes fixes for both #48783 and #47571.

Chris Wiebe wrote:

That should be bug #47571.

Chris Wiebe wrote:

This patch validates the "link to file" fields on the class wizard page and disables the finish button if they are empty.

-Chris


------------------------------------------------------------------------

Index: src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties,v
retrieving revision 1.9
diff -u -r1.9 NewWizardMessages.properties
--- src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties 18 Jun 2004 13:58:45 -0000 1.9 +++ src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties 23 Jun 2004 18:22:44 -0000
@@ -174,6 +174,9 @@
 NewClassWizardPage.getProjectClasses.noclasses.title=Class Selection
NewClassWizardPage.getProjectClasses.noclasses.message=No classes available. +NewClassWizardPage.error.EnterHeaderFile=Header file is empty.
+NewClassWizardPage.error.EnterBodyFile=Body file is empty.
+
 # ------- BaseClassSelectionDialog -----
BaseClassSelectionDialog.title=Choose Base Class Index: src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java,v
retrieving revision 1.6
diff -u -r1.6 LinkToFileGroup.java
--- src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java 8 Jun 2004 17:40:04 -0000 1.6 +++ src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java 23 Jun 2004 18:22:44 -0000
@@ -121,8 +121,10 @@
                     browseButton.setEnabled(createLink);
                     variablesButton.setEnabled(createLink);
                     linkTargetField.setEnabled(createLink);
+                    resolveVariable();
                     if (listener != null)
                         listener.handleEvent(new Event());
+                    dialogFieldChanged();
                 }
             };
             linkButton.addSelectionListener(selectionListener);
@@ -138,9 +140,8 @@
         fText= text;
         if (isOkToUse(linkTargetField)) {
             linkTargetField.setText(text);
-        } else {
-            dialogFieldChanged();
- } + }
+        dialogFieldChanged();
     }
public Text getTextControl(Composite parent){
@@ -154,6 +155,7 @@
                     resolveVariable();
                     if (listener != null)
                         listener.handleEvent(new Event());
+                    dialogFieldChanged();
                 }
             });
             if (initialLinkTarget != null)
@@ -273,8 +275,10 @@
dialog.setMessage(WorkbenchMessages.getString("CreateLinkedResourceGroup.targetSelectionLabel")); //$NON-NLS-1$
             selection = dialog.open();
} - if (selection != null)
+        if (selection != null) {
             linkTargetField.setText(selection);
+            dialogFieldChanged();
+        }
     }
     /**
      * Opens a path variable selection dialog
@@ -292,7 +296,10 @@
         if (dialog.open() == IDialogConstants.OK_ID) {
String[] variableNames = (String[]) dialog.getResult(); if (variableNames != null && variableNames.length == 1)
+            {
                 linkTargetField.setText(variableNames[0]);
+                dialogFieldChanged();
+            }
         }
     }
     /**
@@ -301,8 +308,10 @@
      * Displays the resolved value if the entered value is a variable.
      */
     protected void resolveVariable() {
-        if(!linkTargetField.isEnabled())
+        if(!linkTargetField.isEnabled()) {
+            resolvedPathLabelData.setText("");
             return;
+        }
IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
         IPath path = new Path(linkTargetField.getText());
@@ -325,8 +334,10 @@
      */
     public void setLinkTarget(String target) {
         initialLinkTarget = target;
- if (linkTargetField != null && linkTargetField.isDisposed() == false) + if (linkTargetField != null && linkTargetField.isDisposed() == false) {
             linkTargetField.setText(target);
+            dialogFieldChanged();
+        }
     }
     /**
* Validates the type of the given file against the link type specified
Index: src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java,v
retrieving revision 1.21
diff -u -r1.21 NewClassWizardPage.java
--- src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java 4 Jun 2004 21:57:38 -0000 1.21 +++ src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java 23 Jun 2004 18:22:44 -0000
@@ -132,6 +132,8 @@
     private IStatus fCurrStatus;
     protected IStatus fClassNameStatus;
     protected IStatus fBaseClassStatus;
+    protected IStatus fLinkedResourceGroupForHeaderStatus;
+    protected IStatus fLinkedResourceGroupForBodyStatus;
private boolean hasCppNature = false; @@ -179,12 +181,16 @@
         fConstDestButtons.setDialogFieldListener(adapter);
linkedResourceGroupForHeader = new LinkToFileGroup(adapter, this);
+        linkedResourceGroupForHeader.setDialogFieldListener(adapter);
linkedResourceGroupForHeader.setLabelText(NewWizardMessages.getString("NewClassWizardPage.files.header")); //$NON-NLS-1$
         linkedResourceGroupForBody = new LinkToFileGroup(adapter, this);
+        linkedResourceGroupForBody.setDialogFieldListener(adapter);
linkedResourceGroupForBody.setLabelText(NewWizardMessages.getString("NewClassWizardPage.files.body")); //$NON-NLS-1$ fClassNameStatus= new StatusInfo();
         fBaseClassStatus=  new StatusInfo();
+        fLinkedResourceGroupForHeaderStatus=  new StatusInfo();
+        fLinkedResourceGroupForBodyStatus=  new StatusInfo();
     }
public void init() {
@@ -384,7 +390,27 @@
             else{
                 fAccessButtons.setEnabled(false);
} - } + } + + if (field == linkedResourceGroupForHeader) {
+            StatusInfo status = new StatusInfo();
+            String text = linkedResourceGroupForHeader.getText();
+            // must not be empty
+ if (linkedResourceGroupForHeader.linkCreated() && (text == null || text.length() == 0)) { + status.setError(NewWizardMessages.getString("NewClassWizardPage.error.EnterHeaderFile")); //$NON-NLS-1$
+            }
+            fLinkedResourceGroupForHeaderStatus = status;
+        }
+        if (field == linkedResourceGroupForBody) {
+            StatusInfo status = new StatusInfo();
+            String text = linkedResourceGroupForBody.getText();
+            // must not be empty
+ if (linkedResourceGroupForBody.linkCreated() && (text == null || text.length() == 0)) { + status.setError(NewWizardMessages.getString("NewClassWizardPage.error.EnterBodyFile")); //$NON-NLS-1$
+            }
+            fLinkedResourceGroupForBodyStatus = status;
+        }
+ doStatusUpdate(); } @@ -986,7 +1012,9 @@
         IStatus[] status= new IStatus[] {
             fClassNameStatus,
             fBaseClassStatus,
-        };
+            fLinkedResourceGroupForHeaderStatus,
+            fLinkedResourceGroupForBodyStatus
+            };
// the mode severe status will be displayed and the ok button enabled/disabled.
         updateStatus(status);

_______________________________________________
cdt-patch mailing list
cdt-patch@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cdt-patch


Index: src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties,v
retrieving revision 1.9
diff -u -r1.9 NewWizardMessages.properties
--- src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	18 Jun 2004 13:58:45 -0000	1.9
+++ src/org/eclipse/cdt/internal/ui/wizards/NewWizardMessages.properties	23 Jun 2004 19:40:51 -0000
@@ -174,6 +174,11 @@
 NewClassWizardPage.getProjectClasses.noclasses.title=Class Selection
 NewClassWizardPage.getProjectClasses.noclasses.message=No classes available.
 
+NewClassWizardPage.error.EnterHeaderFile=Header file is empty.
+NewClassWizardPage.error.EnterBodyFile=Body file is empty.
+NewClassWizardPage.error.NoHeaderFile=Header file does not exist.
+NewClassWizardPage.error.NoBodyFile=Body file does not exist.
+
 # ------- BaseClassSelectionDialog -----
 
 BaseClassSelectionDialog.title=Choose Base Class
Index: src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java,v
retrieving revision 1.6
diff -u -r1.6 LinkToFileGroup.java
--- src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java	8 Jun 2004 17:40:04 -0000	1.6
+++ src/org/eclipse/cdt/internal/ui/wizards/dialogfields/LinkToFileGroup.java	23 Jun 2004 19:40:51 -0000
@@ -121,8 +121,10 @@
 					browseButton.setEnabled(createLink);
 					variablesButton.setEnabled(createLink);
 					linkTargetField.setEnabled(createLink);
+					resolveVariable();
 					if (listener != null)
 						listener.handleEvent(new Event());
+					dialogFieldChanged();
 				}
 			};
 			linkButton.addSelectionListener(selectionListener);
@@ -138,9 +140,8 @@
 		fText= text;
 		if (isOkToUse(linkTargetField)) {
 			linkTargetField.setText(text);
-		} else {
-			dialogFieldChanged();
-		}	
+		}
+		dialogFieldChanged();
 	}
 	
 	public Text getTextControl(Composite parent){
@@ -154,6 +155,7 @@
 					resolveVariable();
 					if (listener != null)
 						listener.handleEvent(new Event());
+					dialogFieldChanged();
 				}
 			});
 			if (initialLinkTarget != null)
@@ -273,8 +275,10 @@
 			dialog.setMessage(WorkbenchMessages.getString("CreateLinkedResourceGroup.targetSelectionLabel")); //$NON-NLS-1$
 			selection = dialog.open();
 		}					
-		if (selection != null)
+		if (selection != null) {
 			linkTargetField.setText(selection);
+			dialogFieldChanged();
+		}
 	}
 	/**
 	 * Opens a path variable selection dialog
@@ -292,7 +296,10 @@
 		if (dialog.open() == IDialogConstants.OK_ID) {
 			String[] variableNames = (String[]) dialog.getResult();			
 			if (variableNames != null && variableNames.length == 1)
+			{
 				linkTargetField.setText(variableNames[0]);
+				dialogFieldChanged();
+			}
 		}
 	}
 	/**
@@ -301,8 +308,10 @@
 	 * Displays the resolved value if the entered value is a variable.
 	 */
 	protected void resolveVariable() {
-		if(!linkTargetField.isEnabled())
+		if(!linkTargetField.isEnabled()) {
+			resolvedPathLabelData.setText("");
 			return;
+		}
 			
 		IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
 		IPath path = new Path(linkTargetField.getText());
@@ -325,8 +334,10 @@
 	 */
 	public void setLinkTarget(String target) {
 		initialLinkTarget = target;
-		if (linkTargetField != null && linkTargetField.isDisposed() == false)
+		if (linkTargetField != null && linkTargetField.isDisposed() == false) {
 			linkTargetField.setText(target);
+			dialogFieldChanged();
+		}
 	}
 	/**
 	 * Validates the type of the given file against the link type specified
Index: src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java,v
retrieving revision 1.21
diff -u -r1.21 NewClassWizardPage.java
--- src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	4 Jun 2004 21:57:38 -0000	1.21
+++ src/org/eclipse/cdt/ui/wizards/NewClassWizardPage.java	23 Jun 2004 19:40:51 -0000
@@ -12,6 +12,7 @@
 
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.text.MessageFormat;
@@ -132,6 +133,8 @@
 	private IStatus fCurrStatus;
 	protected IStatus fClassNameStatus;
 	protected IStatus fBaseClassStatus;
+	protected IStatus fLinkedResourceGroupForHeaderStatus;
+	protected IStatus fLinkedResourceGroupForBodyStatus;
 
 	private boolean hasCppNature = false;
 	
@@ -179,12 +182,16 @@
 		fConstDestButtons.setDialogFieldListener(adapter);
 				
 		linkedResourceGroupForHeader = new LinkToFileGroup(adapter, this);
+		linkedResourceGroupForHeader.setDialogFieldListener(adapter);
 		linkedResourceGroupForHeader.setLabelText(NewWizardMessages.getString("NewClassWizardPage.files.header")); //$NON-NLS-1$
 		linkedResourceGroupForBody = new LinkToFileGroup(adapter, this);
+		linkedResourceGroupForBody.setDialogFieldListener(adapter);
 		linkedResourceGroupForBody.setLabelText(NewWizardMessages.getString("NewClassWizardPage.files.body")); //$NON-NLS-1$
 
 		fClassNameStatus=  new StatusInfo();
 		fBaseClassStatus=  new StatusInfo();
+		fLinkedResourceGroupForHeaderStatus=  new StatusInfo();
+		fLinkedResourceGroupForBodyStatus=  new StatusInfo();
 	}
 	
 	public void init() {
@@ -384,9 +391,46 @@
 			else{
 				fAccessButtons.setEnabled(false);
 			}							
-		}		
+		}
+		
+		if (field == linkedResourceGroupForHeader) {
+			fLinkedResourceGroupForHeaderStatus = linkedResourceGroupChanged(linkedResourceGroupForHeader, true);
+		}
+		if (field == linkedResourceGroupForBody) {
+			fLinkedResourceGroupForBodyStatus = linkedResourceGroupChanged(linkedResourceGroupForBody, false);
+		}
+		
 		doStatusUpdate();		
 	}		
+
+	IStatus linkedResourceGroupChanged(LinkToFileGroup linkedGroup, boolean isHeader) {
+		StatusInfo status = new StatusInfo();
+		String text = linkedGroup.getText();
+		if (linkedGroup.linkCreated()) {
+			// must not be empty
+			if (text == null || text.length() == 0) {
+				if (isHeader)
+					status.setError(NewWizardMessages.getString("NewClassWizardPage.error.EnterHeaderFile")); //$NON-NLS-1$
+				else
+					status.setError(NewWizardMessages.getString("NewClassWizardPage.error.EnterBodyFile")); //$NON-NLS-1$
+			} else {
+				// check if file exists
+				IPath filePath = getContainerFullPath(linkedGroup);
+				boolean validFile = false;
+				if (filePath != null) {
+					File f = filePath.toFile();
+					validFile = (f != null && f.exists() && f.isFile());
+				}
+				if (!validFile) {
+					if (isHeader)
+						status.setError(NewWizardMessages.getString("NewClassWizardPage.error.NoHeaderFile")); //$NON-NLS-1$
+					else
+						status.setError(NewWizardMessages.getString("NewClassWizardPage.error.NoBodyFile")); //$NON-NLS-1$
+				}
+			}
+		}
+		return status;
+	}
 	
 	// --------------- Helper methods for creating controls -----
 	public boolean selectionIsCpp(){
@@ -986,7 +1030,9 @@
 		IStatus[] status= new IStatus[] {
 			fClassNameStatus,
 			fBaseClassStatus,
-		};
+			fLinkedResourceGroupForHeaderStatus,
+			fLinkedResourceGroupForBodyStatus
+			};
 		
 		// the mode severe status will be displayed and the ok button enabled/disabled.
 		updateStatus(status);

Back to the top