1 11 package org.eclipse.compare.internal.patch; 12 13 import org.eclipse.compare.internal.ICompareContextIds; 14 import org.eclipse.compare.internal.Utilities; 15 import org.eclipse.core.resources.*; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.Path; 18 import org.eclipse.jface.dialogs.Dialog; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.jface.viewers.*; 21 import org.eclipse.jface.wizard.IWizardPage; 22 import org.eclipse.jface.wizard.WizardPage; 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.layout.GridData; 25 import org.eclipse.swt.layout.GridLayout; 26 import org.eclipse.swt.widgets.*; 27 import org.eclipse.ui.PlatformUI; 28 import org.eclipse.ui.model.WorkbenchContentProvider; 29 import org.eclipse.ui.model.WorkbenchLabelProvider; 30 import org.eclipse.ui.views.navigator.ResourceComparator; 31 32 import com.ibm.icu.text.MessageFormat; 33 34 38 public class PatchTargetPage extends WizardPage { 39 40 private boolean fShowError = false; 41 42 private TreeViewer fPatchTargets; 44 private Button useWorkspaceAsTarget; 45 private Button selectTarget; 46 47 protected WorkspacePatcher fPatcher; 48 49 protected final static String PATCHTARGETPAGE_NAME = "PatchTargetPage"; 51 PatchTargetPage(WorkspacePatcher patcher) { 52 super(PATCHTARGETPAGE_NAME, PatchMessages.PatchTargetPage_title, null); 53 setMessage(PatchMessages.PatchTargetPage_message); 54 fPatcher = patcher; 55 } 56 57 61 protected IPath getPathFromText(Text textField) { 62 return (new Path(textField.getText())).makeAbsolute(); 63 } 64 65 public void createControl(Composite parent) { 66 67 Composite composite = new Composite(parent, SWT.NULL); 68 composite.setLayout(new GridLayout()); 69 composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); 70 setControl(composite); 71 72 useWorkspaceAsTarget = createRadioButton(composite, PatchMessages.PatchTargetPage_0, 1); 73 selectTarget = createRadioButton(composite, PatchMessages.InputPatchPage_SelectInput, 1); 74 75 buildInputGroup(composite); 76 77 updateWidgetEnablements(); 78 79 Dialog.applyDialogFont(composite); 80 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ICompareContextIds.PATCH_INPUT_WIZARD_PAGE); 81 82 useWorkspaceAsTarget.addListener(SWT.Selection, new Listener() { 83 public void handleEvent(Event event) { 84 fShowError = true; 85 if (useWorkspaceAsTarget.getSelection()) { 86 fPatchTargets.getTree().setEnabled(false); 87 fPatcher.setTarget(ResourcesPlugin.getWorkspace().getRoot()); 88 } else { 89 fPatchTargets.getTree().setEnabled(true); 90 fPatcher.setTarget(Utilities.getFirstResource(fPatchTargets.getSelection())); 91 } 92 updateWidgetEnablements(); 93 } 94 }); 95 } 96 97 private Button createRadioButton(Composite parent, String label, int span) { 98 Button button = new Button(parent, SWT.RADIO); 99 button.setText(label); 100 GridData data = new GridData(); 101 data.horizontalSpan = span; 102 button.setLayoutData(data); 103 return button; 104 } 105 106 109 public IWizardPage getNextPage() { 110 111 if (fPatcher.getTarget() instanceof IFile && fPatcher.getDiffs().length > 1) { 114 InputPatchPage inputPage = (InputPatchPage) getWizard().getPage(InputPatchPage.INPUTPATCHPAGE_NAME); 115 String source = ""; switch (inputPage.getInputMethod()) { 117 case InputPatchPage.CLIPBOARD : 118 source = PatchMessages.InputPatchPage_Clipboard_title; 119 break; 120 121 case InputPatchPage.FILE : 122 source = PatchMessages.InputPatchPage_PatchFile_title; 123 break; 124 125 case InputPatchPage.WORKSPACE : 126 source = PatchMessages.InputPatchPage_WorkspacePatch_title; 127 break; 128 } 129 String format = PatchMessages.InputPatchPage_SingleFileError_format; 130 String message = MessageFormat.format(format, new String [] {source}); 131 MessageDialog.openInformation(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, message); 132 return this; 133 } 134 135 return super.getNextPage(); 136 } 137 138 141 public boolean canFlipToNextPage() { 142 return isPageComplete(); 145 } 146 147 private void buildInputGroup(Composite parent) { 148 Tree tree = new Tree(parent, SWT.BORDER); 149 GridData gd = new GridData(GridData.FILL_BOTH); 150 gd.heightHint = 200; 151 tree.setLayoutData(gd); 152 153 fPatchTargets = new TreeViewer(tree); 154 fPatchTargets.setLabelProvider(new WorkbenchLabelProvider()); 155 fPatchTargets.setContentProvider(new WorkbenchContentProvider()); 156 fPatchTargets.setComparator(new ResourceComparator(ResourceComparator.NAME)); 157 fPatchTargets.setInput(ResourcesPlugin.getWorkspace().getRoot()); 158 159 IResource target = fPatcher.getTarget(); 160 if (target != null && !(target instanceof IWorkspaceRoot)) { 161 fPatchTargets.expandToLevel(target, 0); 162 fPatchTargets.setSelection(new StructuredSelection(target)); 163 } 164 165 fPatchTargets.addSelectionChangedListener(new ISelectionChangedListener() { 167 public void selectionChanged(SelectionChangedEvent event) { 168 fShowError = true; 169 fPatcher.setTarget(Utilities.getFirstResource(event.getSelection())); 170 updateWidgetEnablements(); 171 } 172 }); 173 174 fPatchTargets.addDoubleClickListener(new IDoubleClickListener() { 175 public void doubleClick(DoubleClickEvent event) { 176 ((PatchWizard)getWizard()).showPage(getNextPage()); 177 } 178 }); 179 } 180 181 184 private void updateWidgetEnablements() { 185 String error = null; 186 187 if (fPatcher.getTarget() == null) { 188 useWorkspaceAsTarget.setSelection(false); 189 selectTarget.setSelection(true); 190 error = PatchMessages.InputPatchPage_NothingSelected_message; 191 setPageComplete(false); 192 if (fShowError) 193 setErrorMessage(error); 194 return; 195 } 196 setErrorMessage(null); 197 useWorkspaceAsTarget.setSelection(fPatcher.getTarget() instanceof IWorkspaceRoot); 198 selectTarget.setSelection(!useWorkspaceAsTarget.getSelection()); 199 setPageComplete(true); 200 } 201 202 209 public boolean finish() { 210 return true; 211 } 212 213 } 214 | Popular Tags |