1 11 package org.eclipse.ltk.internal.ui.refactoring.scripting; 12 13 import java.net.URI ; 14 15 import org.eclipse.core.runtime.Assert; 16 17 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 18 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; 19 20 import org.eclipse.ltk.internal.ui.refactoring.IRefactoringHelpContextIds; 21 import org.eclipse.ltk.internal.ui.refactoring.history.SortableRefactoringHistoryControl; 22 import org.eclipse.ltk.internal.ui.refactoring.util.PixelConverter; 23 24 import org.eclipse.swt.SWT; 25 import org.eclipse.swt.layout.GridData; 26 import org.eclipse.swt.layout.GridLayout; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.swt.widgets.FileDialog; 29 import org.eclipse.swt.widgets.Group; 30 31 import org.eclipse.jface.dialogs.Dialog; 32 import org.eclipse.jface.dialogs.IDialogSettings; 33 import org.eclipse.jface.viewers.CheckStateChangedEvent; 34 import org.eclipse.jface.viewers.ICheckStateListener; 35 import org.eclipse.jface.wizard.WizardPage; 36 37 import org.eclipse.ui.PlatformUI; 38 39 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration; 40 41 46 public final class CreateRefactoringScriptWizardPage extends WizardPage { 47 48 49 private static final RefactoringDescriptorProxy[] EMPTY_DESCRIPTORS= {}; 50 51 52 private static final String PAGE_NAME= "CreateRefactoringScriptWizardPage"; 54 55 protected static final String SETTING_SORT= "org.eclipse.ltk.ui.refactoring.sortRefactorings"; 57 58 private boolean fFirstTime= true; 59 60 61 private SortableRefactoringHistoryControl fHistoryControl= null; 62 63 64 private RefactoringScriptLocationControl fLocationControl= null; 65 66 67 private final CreateRefactoringScriptWizard fWizard; 68 69 75 public CreateRefactoringScriptWizardPage(final CreateRefactoringScriptWizard wizard) { 76 super(PAGE_NAME); 77 Assert.isNotNull(wizard); 78 fWizard= wizard; 79 setTitle(ScriptingMessages.CreateRefactoringScriptWizard_title); 80 setDescription(ScriptingMessages.CreateRefactoringScriptWizard_description); 81 } 82 83 86 public void createControl(final Composite parent) { 87 initializeDialogUnits(parent); 88 final Composite composite= new Composite(parent, SWT.NULL); 89 composite.setLayout(new GridLayout()); 90 composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); 91 final RefactoringHistoryControlConfiguration configuration= new RefactoringHistoryControlConfiguration(null, true, true) { 92 93 public final String getWorkspaceCaption() { 94 return ScriptingMessages.CreateRefactoringScriptWizardPage_select_caption; 95 } 96 }; 97 fHistoryControl= new SortableRefactoringHistoryControl(composite, configuration) { 98 99 protected final void handleDeselectAll() { 100 super.handleDeselectAll(); 101 fWizard.setRefactoringDescriptors(EMPTY_DESCRIPTORS); 102 } 103 104 protected final void handleSelectAll() { 105 super.handleSelectAll(); 106 final RefactoringHistory history= getInput(); 107 if (history != null) 108 fWizard.setRefactoringDescriptors(history.getDescriptors()); 109 } 110 }; 111 fHistoryControl.createControl(); 112 boolean sortProjects= true; 113 final IDialogSettings settings= fWizard.getDialogSettings(); 114 if (settings != null) 115 sortProjects= settings.getBoolean(SETTING_SORT); 116 if (sortProjects) 117 fHistoryControl.sortByProjects(); 118 else 119 fHistoryControl.sortByDate(); 120 121 GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); 122 data.heightHint= new PixelConverter(parent).convertHeightInCharsToPixels(24); 123 fHistoryControl.setLayoutData(data); 124 final RefactoringHistory history= fWizard.getRefactoringHistory(); 125 fHistoryControl.setInput(history); 126 fHistoryControl.addCheckStateListener(new ICheckStateListener() { 127 128 public void checkStateChanged(final CheckStateChangedEvent event) { 129 fWizard.setRefactoringDescriptors(fHistoryControl.getCheckedDescriptors()); 130 } 131 }); 132 final Group group= new Group(composite, SWT.NONE); 133 group.setText(ScriptingMessages.CreateRefactoringScriptWizardPage_destination_caption); 134 final GridLayout layout= new GridLayout(); 135 layout.marginWidth= 0; 136 group.setLayout(layout); 137 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 138 fLocationControl= new RefactoringScriptLocationControl(fWizard, group) { 139 140 protected void handleBrowseExternalLocation() { 141 final FileDialog file= new FileDialog(getShell(), SWT.OPEN); 142 file.setText(ScriptingMessages.CreateRefactoringScriptWizardPage_browse_destination); 143 file.setFilterNames(new String [] { ScriptingMessages.ScriptLocationControl_filter_name_script, ScriptingMessages.ScriptLocationControl_filter_name_wildcard}); 144 file.setFilterExtensions(new String [] { ScriptingMessages.ScriptLocationControl_filter_extension_script, ScriptingMessages.ScriptLocationControl_filter_extension_wildcard}); 145 String path= file.open(); 146 if (path != null) { 147 if (!path.endsWith(ScriptingMessages.CreateRefactoringScriptWizardPage_script_extension)) 148 path= path + ScriptingMessages.CreateRefactoringScriptWizardPage_script_extension; 149 fExternalLocationControl.setText(path); 150 } 151 } 152 153 protected final void handleClipboardScriptChanged() { 154 super.handleClipboardScriptChanged(); 155 CreateRefactoringScriptWizardPage.this.fWizard.setRefactoringScript(null); 156 CreateRefactoringScriptWizardPage.this.fWizard.setUseClipboard(fFromClipboardButton.getSelection()); 157 setErrorMessage(null); 158 setPageComplete(true); 159 } 160 161 protected final void handleExternalLocationChanged() { 162 super.handleExternalLocationChanged(); 163 CreateRefactoringScriptWizardPage.this.fWizard.setRefactoringScript(null); 164 CreateRefactoringScriptWizardPage.this.fWizard.setUseClipboard(false); 165 setErrorMessage(null); 166 setPageComplete(true); 167 handleLocationChanged(); 168 } 169 }; 170 fLocationControl.loadHistory(); 171 if (history == null || history.isEmpty()) 172 setErrorMessage(ScriptingMessages.CreateRefactoringScriptWizardPage_no_refactorings); 173 fFirstTime= false; 174 setPageComplete(false); 175 setControl(composite); 176 Dialog.applyDialogFont(parent); 177 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IRefactoringHelpContextIds.REFACTORING_CREATE_SCRIPT_PAGE); 178 } 179 180 183 private void handleLocationChanged() { 184 final URI uri= fLocationControl.getRefactoringScript(); 185 if (uri == null) { 186 setErrorMessage(ScriptingMessages.ApplyRefactoringScriptWizardPage_invalid_location); 187 setPageComplete(false); 188 fWizard.setRefactoringScript(null); 189 } else { 190 fWizard.setRefactoringScript(uri); 191 setErrorMessage(null); 192 setPageComplete(true); 193 } 194 } 195 196 199 public void performFinish() { 200 final IDialogSettings settings= fWizard.getDialogSettings(); 201 if (settings != null) 202 settings.put(SETTING_SORT, fHistoryControl.isSortByProjects()); 203 fLocationControl.saveHistory(); 204 } 205 206 209 public void setErrorMessage(final String message) { 210 if (!fFirstTime) 211 super.setErrorMessage(message); 212 else 213 setMessage(message, NONE); 214 } 215 } | Popular Tags |