KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > nls > PackageSelectionDialogButtonField


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.refactoring.nls;
12
13 import org.eclipse.jdt.core.IJavaProject;
14 import org.eclipse.jdt.core.IPackageFragment;
15 import org.eclipse.jdt.core.IPackageFragmentRoot;
16 import org.eclipse.jdt.core.JavaModelException;
17
18 import org.eclipse.jdt.internal.ui.JavaPlugin;
19 import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaPackageCompletionProcessor;
20 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField;
21
22 import org.eclipse.jdt.ui.JavaElementLabelProvider;
23
24 public final class PackageSelectionDialogButtonField extends StringButtonDialogField {
25
26     private IPackageFragment fPackageFragment;
27
28     public PackageSelectionDialogButtonField(String JavaDoc label, String JavaDoc button, PackageBrowseAdapter adapter, IJavaProject root) {
29         super(adapter);
30         setContentAssistProcessor(new JavaPackageCompletionProcessor(new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_ROOT)));
31
32         IPackageFragmentRoot[] roots;
33         try {
34             roots= root.getAllPackageFragmentRoots();
35             ((JavaPackageCompletionProcessor)getContentAssistProcessor()).setPackageFragmentRoot(roots[0]);
36         } catch (JavaModelException e) {
37             JavaPlugin.log(e);
38             // if exception no content assist .. but thats no problem
39
}
40         setLabelText(label);
41         setButtonLabel(button);
42         adapter.setReceiver(this);
43     }
44
45     public void setPackage(IPackageFragment packageFragment) {
46         fPackageFragment= packageFragment;
47         if (fPackageFragment != null) {
48             setText(fPackageFragment.getElementName());
49
50             JavaPackageCompletionProcessor contentAssist= (JavaPackageCompletionProcessor)getContentAssistProcessor();
51             contentAssist.setPackageFragmentRoot((IPackageFragmentRoot)packageFragment.getParent());
52         }
53     }
54 }
55
Popular Tags