1 /*******************************************************************************
2 * Copyright (c) 2006, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.jarpackager;
13 import java.util.HashSet;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Shell;
25 import org.eclipse.core.runtime.Assert;
27 import org.eclipse.core.resources.IProject;
28 import org.eclipse.core.resources.IWorkspaceRoot;
29 import org.eclipse.core.resources.ResourcesPlugin;
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;
36 import org.eclipse.ui.PlatformUI;
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;
44 import org.eclipse.jdt.ui.jarpackager.JarPackageData;
46 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
49 * Dialog to configure the refactorings to export.
53 public final class JarRefactoringDialog extends TrayDialog {
55 /** The sort dialog setting */
56 private static final String SETTING_SORT= "org.eclipse.jdt.ui.jar.export.sortRefactorings"; //$NON-NLS-1$
58 /** The jar package data */
59 private final JarPackageData fData;
61 /** The export structural button */
62 private Button fExportStructural= null;
64 /** The refactoring history */
65 private final RefactoringHistory fHistory;
67 /** The refactoring history control */
68 private ISortableRefactoringHistoryControl fHistoryControl= null;
70 /** The dialog settings */
71 private final IDialogSettings fSettings;
74 * Creates a new jar refactoring dialog.
79 * the dialog settings, or <code>null</code>
81 * the jar package data
83 * the refactoring history
85 public JarRefactoringDialog(final Shell shell, final IDialogSettings settings, final JarPackageData data, final RefactoringHistory history) {
87 Assert.isNotNull(data);
88 Assert.isNotNull(history);
95 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
99 protected boolean isResizable() {
107 protected void buttonPressed(final int buttonId) {
108 if (buttonId == IDialogConstants.OK_ID) {
109 fData.setRefactoringAware(true);
110 final RefactoringDescriptorProxy[] descriptors= fHistoryControl.getCheckedDescriptors();
111 Set<IProject> set= new HashSet<IProject>();
112 IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
113 for (int index= 0; index < descriptors.length; index++) {
114 final String project= descriptors[index].getProject();
115 if (project != null && !"".equals(project)) //$NON-NLS-1$
116 set.add(root.getProject(project));
118 fData.setRefactoringProjects(set.toArray(new IProject[set.size()]));
119 fData.setRefactoringDescriptors(descriptors);
120 fData.setExportStructuralOnly(fExportStructural.getSelection());
121 final IDialogSettings settings= fSettings;
122 if (settings != null)
123 settings.put(SETTING_SORT, fHistoryControl.isSortByProjects());
125 super.buttonPressed(buttonId);
132 protected void configureShell(final Shell shell) {
133 super.configureShell(shell);
134 shell.setText(JarPackagerMessages.JarRefactoringDialog_dialog_title);
135 PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.JARPACKAGER_REFACTORING_DIALOG);
142 public void create() {
144 getButton(OK).setEnabled(!fHistory.isEmpty());
151 protected Control createDialogArea(final Composite parent) {
152 final Composite container= (Composite) super.createDialogArea(parent);
153 initializeDialogUnits(container);
154 final Composite composite= new Composite(container, SWT.NULL);
155 final GridLayout layout= new GridLayout();
156 layout.marginHeight= 0;
157 layout.marginWidth= 0;
158 composite.setLayout(layout);
159 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
160 final RefactoringHistoryControlConfiguration configuration= new RefactoringHistoryControlConfiguration(null, true, true) {
163 public final String getWorkspaceCaption() {
164 return JarPackagerMessages.JarRefactoringDialog_workspace_caption;
167 fHistoryControl= (ISortableRefactoringHistoryControl) RefactoringUI.createSortableRefactoringHistoryControl(composite, configuration);
168 fHistoryControl.createControl();
169 boolean sortProjects= true;
170 final IDialogSettings settings= fSettings;
171 if (settings != null)
172 sortProjects= settings.getBoolean(SETTING_SORT);
174 fHistoryControl.sortByProjects();
176 fHistoryControl.sortByDate();
177 GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
178 data.heightHint= convertHeightInCharsToPixels(32);
179 data.widthHint= convertWidthInCharsToPixels(72);
180 fHistoryControl.getControl().setLayoutData(data);
181 fHistoryControl.setInput(fHistory);
182 fHistoryControl.setCheckedDescriptors(fData.getRefactoringDescriptors());
183 createPlainLabel(composite, JarPackagerMessages.JarPackageWizardPage_options_label);
184 createOptionsGroup(composite);
185 Dialog.applyDialogFont(parent);
190 * Create the export option group.
193 * the parent composite
195 protected void createOptionsGroup(Composite parent) {
196 Composite optionsGroup= new Composite(parent, SWT.NONE);
197 GridLayout layout= new GridLayout();
198 layout.marginHeight= 0;
199 optionsGroup.setLayout(layout);
201 fExportStructural= new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
202 fExportStructural.setText(JarPackagerMessages.JarRefactoringDialog_export_structural);
203 fExportStructural.setSelection(fData.isExportStructuralOnly());
207 * Creates a new label.
213 * @return the new label control
215 protected Label createPlainLabel(Composite parent, String text) {
216 Label label= new Label(parent, SWT.NONE);
218 label.setFont(parent.getFont());
219 GridData data= new GridData();
220 data.verticalAlignment= GridData.FILL;
221 data.horizontalAlignment= GridData.FILL;
222 label.setLayoutData(data);