### Eclipse Workspace Patch 1.0 #P org.eclipse.compare Index: compare/org/eclipse/compare/internal/GenerateDiffFileWizard.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/Attic/GenerateDiffFileWizard.java,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 GenerateDiffFileWizard.java --- compare/org/eclipse/compare/internal/GenerateDiffFileWizard.java 18 Mar 2009 12:23:22 -0000 1.1.2.5 +++ compare/org/eclipse/compare/internal/GenerateDiffFileWizard.java 23 Mar 2009 14:49:19 -0000 @@ -35,6 +35,7 @@ import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.resource.ImageDescriptor; @@ -1212,14 +1213,31 @@ public void setVisible(boolean visible) { super.setVisible(visible); + setCustomRoot(visible); + } + + private void setCustomRoot(boolean visible) { if (!initialized && visible) { if (directionSelectionPage.isRightToLeft()) { unified_customRelativeText.setText(rightPath); } else { unified_customRelativeText.setText(leftPath); } + targetFileEdited = true; } + validateCustomPatchRoot(this.getPath()); + } + + private void validateCustomPatchRoot(String path) { + if(this.getRootSelection() == OptionsPage.ROOT_CUSTOM) { + if(!validateFile(path)) { + this.setMessage(CompareMessages.GenerateLocalDiff_4, IMessageProvider.WARNING); + } else + this.setMessage(null); + } + else + this.setMessage(null); } protected void performSpecificActions() { @@ -1237,32 +1255,58 @@ unifiedRadioGroup.setEnablement(false, new int[] { ROOT_WORKSPACE, ROOT_PROJECT, ROOT_SELECTION }); } + + private void createCustomRelativeControl() { + Group unifiedGroup = optionsPage.getUnifiedGroup(); + final RadioButtonGroup unifiedRadioGroup = optionsPage.getUnifiedRadioGroup(); + unified_customRelativeOption = new Button(unifiedGroup, SWT.RADIO); + unified_customRelativeOption.setText(CompareMessages.GenerateDiffFileWizard_13); + unified_customRelativeOption.setSelection(true); + unified_customRelativeOption.setLayoutData(new GridData( + SWT.BEGINNING, SWT.CENTER, false, false, 1, 1)); + + unified_customRelativeText = new Text(unifiedGroup, SWT.BORDER); + unified_customRelativeText.setLayoutData(new GridData( + SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + unified_customRelativeText.addModifyListener(new ModifyListener(){ + + public void modifyText(ModifyEvent e) { + if(e.widget instanceof Text) { + String text = ((Text)e.widget).getText(); + validateCustomPatchRoot(text); + } + } + }); + + optionsPage.getUnifiedRadioGroup().add(OptionsPage.ROOT_CUSTOM, unified_customRelativeOption); + unified_customRelativeOption.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + unifiedRadioGroup.setSelection(OptionsPage.ROOT_CUSTOM, false); + } + }); + optionsPage.updateDiffTypeEnablements(new int[] {OptionsPage.FORMAT_CONTEXT, OptionsPage.FORMAT_STANDARD}, OptionsPage.FORMAT_UNIFIED); + optionsPage.updateUnifiedEnablements(new int[] {OptionsPage.ROOT_PROJECT, OptionsPage.ROOT_WORKSPACE, OptionsPage.ROOT_SELECTION}, OptionsPage.ROOT_CUSTOM); + } }; optionsPage.setDescription(pageDescription); addPage(optionsPage); } - private void createCustomRelativeControl() { - Group unifiedGroup = optionsPage.getUnifiedGroup(); - final RadioButtonGroup unifiedRadioGroup = optionsPage.getUnifiedRadioGroup(); - unified_customRelativeOption = new Button(unifiedGroup, SWT.RADIO); - unified_customRelativeOption.setText(CompareMessages.GenerateDiffFileWizard_13); - unified_customRelativeOption.setSelection(true); - unified_customRelativeOption.setLayoutData(new GridData( - SWT.BEGINNING, SWT.CENTER, false, false, 1, 1)); - - unified_customRelativeText = new Text(unifiedGroup, SWT.BORDER); - unified_customRelativeText.setLayoutData(new GridData( - SWT.FILL, SWT.CENTER, true, false, 1, 1)); - - optionsPage.getUnifiedRadioGroup().add(OptionsPage.ROOT_CUSTOM, unified_customRelativeOption); - unified_customRelativeOption.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - unifiedRadioGroup.setSelection(OptionsPage.ROOT_CUSTOM, false); - } - }); - optionsPage.updateDiffTypeEnablements(new int[] {OptionsPage.FORMAT_CONTEXT, OptionsPage.FORMAT_STANDARD}, OptionsPage.FORMAT_UNIFIED); - optionsPage.updateUnifiedEnablements(new int[] {OptionsPage.ROOT_PROJECT, OptionsPage.ROOT_WORKSPACE, OptionsPage.ROOT_SELECTION}, OptionsPage.ROOT_CUSTOM); + + + /** + * + * @return true if file is in the workspace, false if not. + */ + private boolean validateFile(String path) { + IFile file2; + try { + file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); + return true; + } catch(IllegalArgumentException e) { + return false; + } } /** @@ -1300,26 +1344,6 @@ return false; } - //Validation of patch root - if(optionsPage.getRootSelection() == OptionsPage.ROOT_CUSTOM) { - String path = optionsPage.getPath(); - IFile file2; - try { - file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); - } catch(IllegalArgumentException e) { - final String title = CompareMessages.GenerateLocalDiff_3; - final String msg = CompareMessages.GenerateLocalDiff_4; - final MessageDialog dialog = new MessageDialog(getShell(), title, - null, msg, MessageDialog.ERROR, - new String[] { IDialogConstants.OK_LABEL }, 0); - dialog.open(); - return false; - } - if(!validateFile2(file2)) { - return false; - } - } - // Create the patch generateDiffFile(file); Index: compare/org/eclipse/compare/internal/CompareMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareMessages.properties,v retrieving revision 1.31.2.5 diff -u -r1.31.2.5 CompareMessages.properties --- compare/org/eclipse/compare/internal/CompareMessages.properties 18 Mar 2009 11:50:57 -0000 1.31.2.5 +++ compare/org/eclipse/compare/internal/CompareMessages.properties 23 Mar 2009 14:49:18 -0000 @@ -175,8 +175,6 @@ GenerateLocalDiff_overwriteMsg=A output file with that name already exists. Overwrite? GenerateLocalDiff_1=Read-only file GenerateLocalDiff_2=The specified file is read-only and cannot be overwritten. -GenerateLocalDiff_3=File does not exist. -GenerateLocalDiff_4=Specified root patch file does not exist. GenerateLocalDiff_5=File is not readable. GenerateLocalDiff_6=Specified rot patch file is not readable. GenerateDiffFileWizard_6=&Workspace (Multi-project Apply Patch wizard specific) @@ -220,7 +218,7 @@ GenerateLocalDiff_1=Read-only file GenerateLocalDiff_2=The specified file is read-only and cannot be overwritten. GenerateLocalDiff_3=File does not exist. -GenerateLocalDiff_4=Specified root patch file does not exist. +GenerateLocalDiff_4=Specified root patch is not in the workspace or is not a valid path. GenerateLocalDiff_5=File is not readable. GenerateLocalDiff_6=Specified root patch file is not readable. GenerateDiffFileWizard_6=&Workspace (Multi-project Apply Patch wizard specific)