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