KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > jarpackager > JarRefactoringDialog


1 /*******************************************************************************
2  * Copyright (c) 2006 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 JavaDoc;
14 import java.util.Set JavaDoc;
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 /**
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 JavaDoc 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         setShellStyle(getShellStyle() | SWT.RESIZE);
90         fSettings= settings;
91         fData= data;
92         fHistory= history;
93     }
94
95     /**
96      * {@inheritDoc}
97      */

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 JavaDoc set= new HashSet JavaDoc();
103             IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
104             for (int index= 0; index < descriptors.length; index++) {
105                 final String JavaDoc project= descriptors[index].getProject();
106                 if (project != null && !"".equals(project)) //$NON-NLS-1$
107
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     /**
120      * {@inheritDoc}
121      */

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     /**
129      * {@inheritDoc}
130      */

131     public void create() {
132         super.create();
133         getButton(OK).setEnabled(!fHistory.isEmpty());
134     }
135
136     /**
137      * {@inheritDoc}
138      */

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 JavaDoc 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     /**
177      * Create the export option group.
178      *
179      * @param parent
180      * the parent composite
181      */

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     /**
194      * Creates a new label.
195      *
196      * @param parent
197      * the parent control
198      * @param text
199      * the label text
200      * @return the new label control
201      */

202     protected Label createPlainLabel(Composite parent, String JavaDoc 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