001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.jarpackager;
011:
012: import java.util.HashSet;
013: import java.util.Set;
014:
015: import org.eclipse.core.runtime.Assert;
016:
017: import org.eclipse.core.resources.IProject;
018: import org.eclipse.core.resources.IWorkspaceRoot;
019: import org.eclipse.core.resources.ResourcesPlugin;
020:
021: import org.eclipse.swt.SWT;
022: import org.eclipse.swt.layout.GridData;
023: import org.eclipse.swt.layout.GridLayout;
024: import org.eclipse.swt.widgets.Button;
025: import org.eclipse.swt.widgets.Composite;
026: import org.eclipse.swt.widgets.Control;
027: import org.eclipse.swt.widgets.Label;
028: import org.eclipse.swt.widgets.Shell;
029:
030: import org.eclipse.jface.dialogs.Dialog;
031: import org.eclipse.jface.dialogs.IDialogConstants;
032: import org.eclipse.jface.dialogs.IDialogSettings;
033: import org.eclipse.jface.dialogs.TrayDialog;
034:
035: import org.eclipse.ui.PlatformUI;
036:
037: import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
038: import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
039: import org.eclipse.ltk.ui.refactoring.RefactoringUI;
040: import org.eclipse.ltk.ui.refactoring.history.ISortableRefactoringHistoryControl;
041: import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration;
042:
043: import org.eclipse.jdt.ui.jarpackager.JarPackageData;
044:
045: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
046:
047: /**
048: * Dialog to configure the refactorings to export.
049: *
050: * @since 3.2
051: */
052: public final class JarRefactoringDialog extends TrayDialog {
053:
054: /** The sort dialog setting */
055: private static final String SETTING_SORT = "org.eclipse.jdt.ui.jar.export.sortRefactorings"; //$NON-NLS-1$
056:
057: /** The jar package data */
058: private final JarPackageData fData;
059:
060: /** The export structural button */
061: private Button fExportStructural = null;
062:
063: /** The refactoring history */
064: private final RefactoringHistory fHistory;
065:
066: /** The refactoring history control */
067: private ISortableRefactoringHistoryControl fHistoryControl = null;
068:
069: /** The dialog settings */
070: private final IDialogSettings fSettings;
071:
072: /**
073: * Creates a new jar refactoring dialog.
074: *
075: * @param shell
076: * the parent shell
077: * @param settings
078: * the dialog settings, or <code>null</code>
079: * @param data
080: * the jar package data
081: * @param history
082: * the refactoring history
083: */
084: public JarRefactoringDialog(final Shell shell,
085: final IDialogSettings settings, final JarPackageData data,
086: final RefactoringHistory history) {
087: super (shell);
088: Assert.isNotNull(data);
089: Assert.isNotNull(history);
090: setShellStyle(getShellStyle() | SWT.RESIZE);
091: fSettings = settings;
092: fData = data;
093: fHistory = history;
094: }
095:
096: /**
097: * {@inheritDoc}
098: */
099: protected void buttonPressed(final int buttonId) {
100: if (buttonId == IDialogConstants.OK_ID) {
101: fData.setRefactoringAware(true);
102: final RefactoringDescriptorProxy[] descriptors = fHistoryControl
103: .getCheckedDescriptors();
104: Set set = new HashSet();
105: IWorkspaceRoot root = ResourcesPlugin.getWorkspace()
106: .getRoot();
107: for (int index = 0; index < descriptors.length; index++) {
108: final String project = descriptors[index].getProject();
109: if (project != null && !"".equals(project)) //$NON-NLS-1$
110: set.add(root.getProject(project));
111: }
112: fData.setRefactoringProjects((IProject[]) set
113: .toArray(new IProject[set.size()]));
114: fData.setRefactoringDescriptors(descriptors);
115: fData.setExportStructuralOnly(fExportStructural
116: .getSelection());
117: final IDialogSettings settings = fSettings;
118: if (settings != null)
119: settings.put(SETTING_SORT, fHistoryControl
120: .isSortByProjects());
121: }
122: super .buttonPressed(buttonId);
123: }
124:
125: /**
126: * {@inheritDoc}
127: */
128: protected void configureShell(final Shell shell) {
129: super .configureShell(shell);
130: shell
131: .setText(JarPackagerMessages.JarRefactoringDialog_dialog_title);
132: PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
133: IJavaHelpContextIds.JARPACKAGER_REFACTORING_DIALOG);
134: }
135:
136: /**
137: * {@inheritDoc}
138: */
139: public void create() {
140: super .create();
141: getButton(OK).setEnabled(!fHistory.isEmpty());
142: }
143:
144: /**
145: * {@inheritDoc}
146: */
147: protected Control createDialogArea(final Composite parent) {
148: final Composite container = (Composite) super
149: .createDialogArea(parent);
150: initializeDialogUnits(container);
151: final Composite composite = new Composite(container, SWT.NULL);
152: final GridLayout layout = new GridLayout();
153: layout.marginHeight = 0;
154: layout.marginWidth = 0;
155: composite.setLayout(layout);
156: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
157: | GridData.FILL_VERTICAL));
158: final RefactoringHistoryControlConfiguration configuration = new RefactoringHistoryControlConfiguration(
159: null, true, true) {
160:
161: public final String getWorkspaceCaption() {
162: return JarPackagerMessages.JarRefactoringDialog_workspace_caption;
163: }
164: };
165: fHistoryControl = (ISortableRefactoringHistoryControl) RefactoringUI
166: .createSortableRefactoringHistoryControl(composite,
167: 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
178: | GridData.FILL_VERTICAL);
179: data.heightHint = convertHeightInCharsToPixels(32);
180: data.widthHint = convertWidthInCharsToPixels(72);
181: fHistoryControl.getControl().setLayoutData(data);
182: fHistoryControl.setInput(fHistory);
183: fHistoryControl.setCheckedDescriptors(fData
184: .getRefactoringDescriptors());
185: createPlainLabel(composite,
186: JarPackagerMessages.JarPackageWizardPage_options_label);
187: createOptionsGroup(composite);
188: Dialog.applyDialogFont(parent);
189: return composite;
190: }
191:
192: /**
193: * Create the export option group.
194: *
195: * @param parent
196: * the parent composite
197: */
198: protected void createOptionsGroup(Composite parent) {
199: Composite optionsGroup = new Composite(parent, SWT.NONE);
200: GridLayout layout = new GridLayout();
201: layout.marginHeight = 0;
202: optionsGroup.setLayout(layout);
203:
204: fExportStructural = new Button(optionsGroup, SWT.CHECK
205: | SWT.LEFT);
206: fExportStructural
207: .setText(JarPackagerMessages.JarRefactoringDialog_export_structural);
208: fExportStructural.setSelection(fData.isExportStructuralOnly());
209: }
210:
211: /**
212: * Creates a new label.
213: *
214: * @param parent
215: * the parent control
216: * @param text
217: * the label text
218: * @return the new label control
219: */
220: protected Label createPlainLabel(Composite parent, String text) {
221: Label label = new Label(parent, SWT.NONE);
222: label.setText(text);
223: label.setFont(parent.getFont());
224: GridData data = new GridData();
225: data.verticalAlignment = GridData.FILL;
226: data.horizontalAlignment = GridData.FILL;
227: label.setLayoutData(data);
228: return label;
229: }
230: }
|