]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / jarpackager / JarRefactoringDialog.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.jarpackager;
12
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;
21
22 import org.eclipse.core.runtime.Assert;
23
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;
28
29 import org.eclipse.ui.PlatformUI;
30
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;
35
36 import org.eclipse.jdt.ui.jarpackager.JarPackageData;
37
38 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
39
40 /**
41  * Dialog to configure the refactorings to export.
42  *
43  * @since 3.2
44  */
45 public final class JarRefactoringDialog extends TrayDialog {
46
47         /** The sort dialog setting */
48         private static final String SETTING_SORT= "org.eclipse.jdt.ui.jar.export.sortRefactorings"; //$NON-NLS-1$
49
50         /** The jar package data */
51         public final JarPackageData fData;
52
53         /** The export structural button */
54         public Button fExportStructural= null;
55
56         /** The refactoring history */
57         private final RefactoringHistory fHistory;
58
59         /** The refactoring history control */
60         public ISortableRefactoringHistoryControl fHistoryControl= null;
61
62         /** The dialog settings */
63         public final IDialogSettings fSettings;
64
65         /**
66          * Creates a new jar refactoring dialog.
67          *
68          * @param shell
69          *            the parent shell
70          * @param settings
71          *            the dialog settings, or <code>null</code>
72          * @param data
73          *            the jar package data
74          * @param history
75          *            the refactoring history
76          */
77         public JarRefactoringDialog(final Shell shell, final IDialogSettings settings, final JarPackageData data, final RefactoringHistory history) {
78                 super(shell);
79                 Assert.isNotNull(data);
80                 Assert.isNotNull(history);
81                 fSettings= settings;
82                 fData= data;
83                 fHistory= history;
84         }
85
86         /*
87          * @see org.eclipse.jface.dialogs.Dialog#isResizable()
88          * @since 3.4
89          */
90         @Override
91         protected boolean isResizable() {
92                 return true;
93         }
94
95         /**
96          * {@inheritDoc}
97          */
98         @Override
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());
104                 }
105                 super.buttonPressed(buttonId);
106         }
107
108         /**
109          * {@inheritDoc}
110          */
111         @Override
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);
116         }
117
118         /**
119          * {@inheritDoc}
120          */
121         @Override
122         public void create() {
123                 super.create();
124                 getButton(OK).setEnabled(!fHistory.isEmpty());
125         }
126
127         /**
128          * {@inheritDoc}
129          */
130         @Override
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) {
141
142                         @Override
143                         public final String getWorkspaceCaption() {
144                                 return JarPackagerMessages.JarRefactoringDialog_workspace_caption;
145                         }
146                 };
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);
153                 if (sortProjects)
154                         fHistoryControl.sortByProjects();
155                 else
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);
166                 return composite;
167         }
168
169         /**
170          * Create the export option group.
171          *
172          * @param parent
173          *            the parent composite
174          */
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);
180
181                 fExportStructural= new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
182                 fExportStructural.setText(JarPackagerMessages.JarRefactoringDialog_export_structural);
183                 fExportStructural.setSelection(fData.isExportStructuralOnly());
184         }
185
186         /**
187          * Creates a new label.
188          *
189          * @param parent
190          *            the parent control
191          * @param text
192          *            the label text
193          * @return the new label control
194          */
195         protected Label createPlainLabel(Composite parent, String text) {
196                 Label label= new Label(parent, SWT.NONE);
197                 label.setText(text);
198                 label.setFont(parent.getFont());
199                 GridData data= new GridData();
200                 data.verticalAlignment= GridData.FILL;
201                 data.horizontalAlignment= GridData.FILL;
202                 label.setLayoutData(data);
203                 return label;
204         }
205 }