01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.refactoring.reorg;
11:
12: import org.eclipse.core.runtime.Assert;
13:
14: import org.eclipse.swt.widgets.Shell;
15:
16: import org.eclipse.jface.resource.JFaceResources;
17: import org.eclipse.jface.viewers.StructuredSelection;
18: import org.eclipse.jface.wizard.IWizardPage;
19: import org.eclipse.jface.wizard.Wizard;
20: import org.eclipse.jface.wizard.WizardDialog;
21:
22: import org.eclipse.ui.IWorkbenchWizard;
23:
24: import org.eclipse.jdt.internal.corext.refactoring.reorg.ICreateTargetQueries;
25: import org.eclipse.jdt.internal.corext.refactoring.reorg.ICreateTargetQuery;
26:
27: import org.eclipse.jdt.internal.ui.JavaPlugin;
28: import org.eclipse.jdt.internal.ui.util.PixelConverter;
29: import org.eclipse.jdt.internal.ui.wizards.NewPackageCreationWizard;
30:
31: import org.eclipse.jdt.ui.wizards.NewPackageWizardPage;
32:
33: public class CreateTargetQueries implements ICreateTargetQueries {
34:
35: private final Wizard fWizard;
36: private final Shell fShell;
37:
38: public CreateTargetQueries(Wizard wizard) {
39: fWizard = wizard;
40: fShell = null;
41: }
42:
43: public CreateTargetQueries(Shell shell) {
44: fShell = shell;
45: fWizard = null;
46: }
47:
48: private Shell getShell() {
49: Assert.isTrue(fWizard == null || fShell == null);
50: if (fWizard != null)
51: return fWizard.getContainer().getShell();
52: else if (fShell != null)
53: return fShell;
54: else
55: return JavaPlugin.getActiveWorkbenchShell();
56: }
57:
58: public ICreateTargetQuery createNewPackageQuery() {
59: return new ICreateTargetQuery() {
60: public Object getCreatedTarget(Object selection) {
61: IWorkbenchWizard packageCreationWizard = new NewPackageCreationWizard();
62:
63: IWizardPage[] pages = openNewElementWizard(
64: packageCreationWizard, getShell(), selection);
65:
66: NewPackageWizardPage page = (NewPackageWizardPage) pages[0];
67: return page.getNewPackageFragment();
68: }
69:
70: public String getNewButtonLabel() {
71: return ReorgMessages.ReorgMoveWizard_newPackage;
72: }
73: };
74: }
75:
76: private IWizardPage[] openNewElementWizard(IWorkbenchWizard wizard,
77: Shell shell, Object selection) {
78: wizard.init(JavaPlugin.getDefault().getWorkbench(),
79: new StructuredSelection(selection));
80:
81: WizardDialog dialog = new WizardDialog(shell, wizard);
82: PixelConverter converter = new PixelConverter(JFaceResources
83: .getDialogFont());
84: dialog.setMinimumPageSize(converter
85: .convertWidthInCharsToPixels(70), converter
86: .convertHeightInCharsToPixels(20));
87: dialog.create();
88: dialog.open();
89: IWizardPage[] pages = wizard.getPages();
90: return pages;
91: }
92: }
|