KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > reorg > CreateTargetQueries


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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
12 package org.eclipse.jdt.internal.ui.refactoring.reorg;
13
14 import org.eclipse.core.runtime.Assert;
15
16 import org.eclipse.swt.widgets.Shell;
17
18 import org.eclipse.jface.resource.JFaceResources;
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.jface.wizard.IWizardPage;
21 import org.eclipse.jface.wizard.Wizard;
22 import org.eclipse.jface.wizard.WizardDialog;
23
24 import org.eclipse.ui.IWorkbenchWizard;
25
26 import org.eclipse.jdt.internal.corext.refactoring.reorg.ICreateTargetQueries;
27 import org.eclipse.jdt.internal.corext.refactoring.reorg.ICreateTargetQuery;
28
29 import org.eclipse.jdt.internal.ui.JavaPlugin;
30 import org.eclipse.jdt.internal.ui.util.PixelConverter;
31 import org.eclipse.jdt.internal.ui.wizards.NewPackageCreationWizard;
32
33 import org.eclipse.jdt.ui.wizards.NewPackageWizardPage;
34
35 public class CreateTargetQueries implements ICreateTargetQueries {
36
37     private final Wizard fWizard;
38     private final Shell fShell;
39
40     public CreateTargetQueries(Wizard wizard) {
41         fWizard= wizard;
42         fShell= null;
43     }
44     
45     public CreateTargetQueries(Shell shell) {
46         fShell = shell;
47         fWizard= null;
48     }
49
50     private Shell getShell() {
51         Assert.isTrue(fWizard == null || fShell == null);
52         if (fWizard != null)
53             return fWizard.getContainer().getShell();
54         else if (fShell != null)
55             return fShell;
56         else
57             return JavaPlugin.getActiveWorkbenchShell();
58     }
59     
60     public ICreateTargetQuery createNewPackageQuery() {
61         return new ICreateTargetQuery() {
62             public Object JavaDoc getCreatedTarget(Object JavaDoc selection) {
63                 IWorkbenchWizard packageCreationWizard= new NewPackageCreationWizard();
64                 
65                 IWizardPage[] pages= openNewElementWizard(packageCreationWizard, getShell(), selection);
66                 
67                 NewPackageWizardPage page= (NewPackageWizardPage) pages[0];
68                 return page.getNewPackageFragment();
69             }
70             
71             public String JavaDoc getNewButtonLabel() {
72                 return ReorgMessages.ReorgMoveWizard_newPackage;
73             }
74         };
75     }
76     
77     private IWizardPage[] openNewElementWizard(IWorkbenchWizard wizard, Shell shell, Object JavaDoc selection) {
78         wizard.init(JavaPlugin.getDefault().getWorkbench(), new StructuredSelection(selection));
79         
80         WizardDialog dialog= new WizardDialog(shell, wizard);
81         PixelConverter converter= new PixelConverter(JFaceResources.getDialogFont());
82         dialog.setMinimumPageSize(converter.convertWidthInCharsToPixels(70), converter.convertHeightInCharsToPixels(20));
83         dialog.create();
84         dialog.open();
85         IWizardPage[] pages= wizard.getPages();
86         return pages;
87     }
88 }
89
Popular Tags