1 11 package org.eclipse.jdt.internal.ui.jarpackager; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.runtime.Assert; 17 18 import org.eclipse.core.resources.IProject; 19 import org.eclipse.core.resources.IWorkspaceRoot; 20 import org.eclipse.core.resources.ResourcesPlugin; 21 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Button; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.swt.widgets.Label; 29 import org.eclipse.swt.widgets.Shell; 30 31 import org.eclipse.jface.dialogs.Dialog; 32 import org.eclipse.jface.dialogs.IDialogConstants; 33 import org.eclipse.jface.dialogs.IDialogSettings; 34 import org.eclipse.jface.dialogs.TrayDialog; 35 36 import org.eclipse.ui.PlatformUI; 37 38 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 39 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; 40 import org.eclipse.ltk.ui.refactoring.RefactoringUI; 41 import org.eclipse.ltk.ui.refactoring.history.ISortableRefactoringHistoryControl; 42 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration; 43 44 import org.eclipse.jdt.ui.jarpackager.JarPackageData; 45 46 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 47 48 53 public final class JarRefactoringDialog extends TrayDialog { 54 55 56 private static final String SETTING_SORT= "org.eclipse.jdt.ui.jar.export.sortRefactorings"; 58 59 private final JarPackageData fData; 60 61 62 private Button fExportStructural= null; 63 64 65 private final RefactoringHistory fHistory; 66 67 68 private ISortableRefactoringHistoryControl fHistoryControl= null; 69 70 71 private final IDialogSettings fSettings; 72 73 85 public JarRefactoringDialog(final Shell shell, final IDialogSettings settings, final JarPackageData data, final RefactoringHistory history) { 86 super(shell); 87 Assert.isNotNull(data); 88 Assert.isNotNull(history); 89 setShellStyle(getShellStyle() | SWT.RESIZE); 90 fSettings= settings; 91 fData= data; 92 fHistory= history; 93 } 94 95 98 protected void buttonPressed(final int buttonId) { 99 if (buttonId == IDialogConstants.OK_ID) { 100 fData.setRefactoringAware(true); 101 final RefactoringDescriptorProxy[] descriptors= fHistoryControl.getCheckedDescriptors(); 102 Set set= new HashSet (); 103 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); 104 for (int index= 0; index < descriptors.length; index++) { 105 final String project= descriptors[index].getProject(); 106 if (project != null && !"".equals(project)) set.add(root.getProject(project)); 108 } 109 fData.setRefactoringProjects((IProject[]) set.toArray(new IProject[set.size()])); 110 fData.setRefactoringDescriptors(descriptors); 111 fData.setExportStructuralOnly(fExportStructural.getSelection()); 112 final IDialogSettings settings= fSettings; 113 if (settings != null) 114 settings.put(SETTING_SORT, fHistoryControl.isSortByProjects()); 115 } 116 super.buttonPressed(buttonId); 117 } 118 119 122 protected void configureShell(final Shell shell) { 123 super.configureShell(shell); 124 shell.setText(JarPackagerMessages.JarRefactoringDialog_dialog_title); 125 PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.JARPACKAGER_REFACTORING_DIALOG); 126 } 127 128 131 public void create() { 132 super.create(); 133 getButton(OK).setEnabled(!fHistory.isEmpty()); 134 } 135 136 139 protected Control createDialogArea(final Composite parent) { 140 final Composite container= (Composite) super.createDialogArea(parent); 141 initializeDialogUnits(container); 142 final Composite composite= new Composite(container, SWT.NULL); 143 final GridLayout layout= new GridLayout(); 144 layout.marginHeight= 0; 145 layout.marginWidth= 0; 146 composite.setLayout(layout); 147 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL)); 148 final RefactoringHistoryControlConfiguration configuration= new RefactoringHistoryControlConfiguration(null, true, true) { 149 150 public final String getWorkspaceCaption() { 151 return JarPackagerMessages.JarRefactoringDialog_workspace_caption; 152 } 153 }; 154 fHistoryControl= (ISortableRefactoringHistoryControl) RefactoringUI.createSortableRefactoringHistoryControl(composite, configuration); 155 fHistoryControl.createControl(); 156 boolean sortProjects= true; 157 final IDialogSettings settings= fSettings; 158 if (settings != null) 159 sortProjects= settings.getBoolean(SETTING_SORT); 160 if (sortProjects) 161 fHistoryControl.sortByProjects(); 162 else 163 fHistoryControl.sortByDate(); 164 GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); 165 data.heightHint= convertHeightInCharsToPixels(32); 166 data.widthHint= convertWidthInCharsToPixels(72); 167 fHistoryControl.getControl().setLayoutData(data); 168 fHistoryControl.setInput(fHistory); 169 fHistoryControl.setCheckedDescriptors(fData.getRefactoringDescriptors()); 170 createPlainLabel(composite, JarPackagerMessages.JarPackageWizardPage_options_label); 171 createOptionsGroup(composite); 172 Dialog.applyDialogFont(parent); 173 return composite; 174 } 175 176 182 protected void createOptionsGroup(Composite parent) { 183 Composite optionsGroup= new Composite(parent, SWT.NONE); 184 GridLayout layout= new GridLayout(); 185 layout.marginHeight= 0; 186 optionsGroup.setLayout(layout); 187 188 fExportStructural= new Button(optionsGroup, SWT.CHECK | SWT.LEFT); 189 fExportStructural.setText(JarPackagerMessages.JarRefactoringDialog_export_structural); 190 fExportStructural.setSelection(fData.isExportStructuralOnly()); 191 } 192 193 202 protected Label createPlainLabel(Composite parent, String text) { 203 Label label= new Label(parent, SWT.NONE); 204 label.setText(text); 205 label.setFont(parent.getFont()); 206 GridData data= new GridData(); 207 data.verticalAlignment= GridData.FILL; 208 data.horizontalAlignment= GridData.FILL; 209 label.setLayoutData(data); 210 return label; 211 } 212 } | Popular Tags |