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 org.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.core.runtime.Assert;
24 import org.eclipse.jface.dialogs.Dialog;
25 import org.eclipse.jface.dialogs.IDialogConstants;
26 import org.eclipse.jface.dialogs.IDialogSettings;
27 import org.eclipse.jface.dialogs.TrayDialog;
29 import org.eclipse.ui.PlatformUI;
31 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
32 import org.eclipse.ltk.ui.refactoring.RefactoringUI;
33 import org.eclipse.ltk.ui.refactoring.history.ISortableRefactoringHistoryControl;
34 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration;
36 import org.eclipse.jdt.ui.jarpackager.JarPackageData;
38 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
41 * Dialog to configure the refactorings to export.
45 public final class JarRefactoringDialog extends TrayDialog {
47 /** The sort dialog setting */
48 private static final String SETTING_SORT= "org.eclipse.jdt.ui.jar.export.sortRefactorings"; //$NON-NLS-1$
50 /** The jar package data */
51 public final JarPackageData fData;
53 /** The export structural button */
54 public Button fExportStructural= null;
56 /** The refactoring history */
57 private final RefactoringHistory fHistory;
59 /** The refactoring history control */
60 public ISortableRefactoringHistoryControl fHistoryControl= null;
62 /** The dialog settings */
63 public final IDialogSettings fSettings;
66 * Creates a new jar refactoring dialog.
71 * the dialog settings, or <code>null</code>
73 * the jar package data
75 * the refactoring history
77 public JarRefactoringDialog(final Shell shell, final IDialogSettings settings, final JarPackageData data, final RefactoringHistory history) {
79 Assert.isNotNull(data);
80 Assert.isNotNull(history);
87 * @see org.eclipse.jface.dialogs.Dialog#isResizable()
91 protected boolean isResizable() {
99 protected void buttonPressed(final int buttonId) {
100 if (buttonId == IDialogConstants.OK_ID) {
101 final IDialogSettings settings= fData.generated_7171819013297241706(this);
102 if (settings != null)
103 settings.put(SETTING_SORT, fHistoryControl.isSortByProjects());
105 super.buttonPressed(buttonId);
112 protected void configureShell(final Shell shell) {
113 super.configureShell(shell);
114 shell.setText(JarPackagerMessages.JarRefactoringDialog_dialog_title);
115 PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, IJavaHelpContextIds.JARPACKAGER_REFACTORING_DIALOG);
122 public void create() {
124 getButton(OK).setEnabled(!fHistory.isEmpty());
131 protected Control createDialogArea(final Composite parent) {
132 final Composite container= (Composite) super.createDialogArea(parent);
133 initializeDialogUnits(container);
134 final Composite composite= new Composite(container, SWT.NULL);
135 final GridLayout layout= new GridLayout();
136 layout.marginHeight= 0;
137 layout.marginWidth= 0;
138 composite.setLayout(layout);
139 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));
140 final RefactoringHistoryControlConfiguration configuration= new RefactoringHistoryControlConfiguration(null, true, true) {
143 public final String getWorkspaceCaption() {
144 return JarPackagerMessages.JarRefactoringDialog_workspace_caption;
147 fHistoryControl= (ISortableRefactoringHistoryControl) RefactoringUI.createSortableRefactoringHistoryControl(composite, configuration);
148 fHistoryControl.createControl();
149 boolean sortProjects= true;
150 final IDialogSettings settings= fSettings;
151 if (settings != null)
152 sortProjects= settings.getBoolean(SETTING_SORT);
154 fHistoryControl.sortByProjects();
156 fHistoryControl.sortByDate();
157 GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
158 data.heightHint= convertHeightInCharsToPixels(32);
159 data.widthHint= convertWidthInCharsToPixels(72);
160 fHistoryControl.getControl().setLayoutData(data);
161 fHistoryControl.setInput(fHistory);
162 fHistoryControl.setCheckedDescriptors(fData.getRefactoringDescriptors());
163 createPlainLabel(composite, JarPackagerMessages.JarPackageWizardPage_options_label);
164 createOptionsGroup(composite);
165 Dialog.applyDialogFont(parent);
170 * Create the export option group.
173 * the parent composite
175 protected void createOptionsGroup(Composite parent) {
176 Composite optionsGroup= new Composite(parent, SWT.NONE);
177 GridLayout layout= new GridLayout();
178 layout.marginHeight= 0;
179 optionsGroup.setLayout(layout);
181 fExportStructural= new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
182 fExportStructural.setText(JarPackagerMessages.JarRefactoringDialog_export_structural);
183 fExportStructural.setSelection(fData.isExportStructuralOnly());
187 * Creates a new label.
193 * @return the new label control
195 protected Label createPlainLabel(Composite parent, String text) {
196 Label label= new Label(parent, SWT.NONE);
198 label.setFont(parent.getFont());
199 GridData data= new GridData();
200 data.verticalAlignment= GridData.FILL;
201 data.horizontalAlignment= GridData.FILL;
202 label.setLayoutData(data);