]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui/org/eclipse/jdt/internal/ui/jarpackager/JarRefactoringDialog.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / 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 java.util.HashSet;
14 import java.util.Set;
15
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;
24
25 import org.eclipse.core.runtime.Assert;
26
27 import org.eclipse.core.resources.IProject;
28 import org.eclipse.core.resources.IWorkspaceRoot;
29 import org.eclipse.core.resources.ResourcesPlugin;
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 /**
49  * Dialog to configure the refactorings to export.
50  *
51  * @since 3.2
52  */
53 public final class JarRefactoringDialog extends TrayDialog {
54
55         /** The sort dialog setting */
56         private static final String SETTING_SORT= "org.eclipse.jdt.ui.jar.export.sortRefactorings"; //$NON-NLS-1$
57
58         /** The jar package data */
59         private final JarPackageData fData;
60
61         /** The export structural button */
62         private Button fExportStructural= null;
63
64         /** The refactoring history */
65         private final RefactoringHistory fHistory;
66
67         /** The refactoring history control */
68         private ISortableRefactoringHistoryControl fHistoryControl= null;
69
70         /** The dialog settings */
71         private final IDialogSettings fSettings;
72
73         /**
74          * Creates a new jar refactoring dialog.
75          *
76          * @param shell
77          *            the parent shell
78          * @param settings
79          *            the dialog settings, or <code>null</code>
80          * @param data
81          *            the jar package data
82          * @param history
83          *            the refactoring history
84          */
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                 fSettings= settings;
90                 fData= data;
91                 fHistory= history;
92         }
93
94         /*
95          * @see org.eclipse.jface.dialogs.Dialog#isResizable()
96          * @since 3.4
97          */
98         @Override
99         protected boolean isResizable() {
100                 return true;
101         }
102
103         /**
104          * {@inheritDoc}
105          */
106         @Override
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));
117                         }
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());
124                 }
125                 super.buttonPressed(buttonId);
126         }
127
128         /**
129          * {@inheritDoc}
130          */
131         @Override
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);
136         }
137
138         /**
139          * {@inheritDoc}
140          */
141         @Override
142         public void create() {
143                 super.create();
144                 getButton(OK).setEnabled(!fHistory.isEmpty());
145         }
146
147         /**
148          * {@inheritDoc}
149          */
150         @Override
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) {
161
162                         @Override
163                         public final String getWorkspaceCaption() {
164                                 return JarPackagerMessages.JarRefactoringDialog_workspace_caption;
165                         }
166                 };
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);
173                 if (sortProjects)
174                         fHistoryControl.sortByProjects();
175                 else
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);
186                 return composite;
187         }
188
189         /**
190          * Create the export option group.
191          *
192          * @param parent
193          *            the parent composite
194          */
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);
200
201                 fExportStructural= new Button(optionsGroup, SWT.CHECK | SWT.LEFT);
202                 fExportStructural.setText(JarPackagerMessages.JarRefactoringDialog_export_structural);
203                 fExportStructural.setSelection(fData.isExportStructuralOnly());
204         }
205
206         /**
207          * Creates a new label.
208          *
209          * @param parent
210          *            the parent control
211          * @param text
212          *            the label text
213          * @return the new label control
214          */
215         protected Label createPlainLabel(Composite parent, String text) {
216                 Label label= new Label(parent, SWT.NONE);
217                 label.setText(text);
218                 label.setFont(parent.getFont());
219                 GridData data= new GridData();
220                 data.verticalAlignment= GridData.FILL;
221                 data.horizontalAlignment= GridData.FILL;
222                 label.setLayoutData(data);
223                 return label;
224         }
225 }