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.IJavaElement;
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.jface.window.Window;
18:
19: import org.eclipse.ui.dialogs.ElementListSelectionDialog;
20:
21: import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
22: import org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter;
23:
24: import org.eclipse.jdt.ui.JavaElementLabelProvider;
25:
26: class PackageSelectionStringButtonAdapter implements
27: IStringButtonAdapter {
28:
29: private final SourceFirstPackageSelectionDialogField fPackageSelectionField;
30: private String fEmtpyListMessage;
31: private String fMessage;
32: private String fTitle;
33:
34: PackageSelectionStringButtonAdapter(
35: SourceFirstPackageSelectionDialogField field, String title,
36: String message, String emtpyListMessage) {
37: fPackageSelectionField = field;
38: fTitle = title;
39: fMessage = message;
40: fEmtpyListMessage = emtpyListMessage;
41: }
42:
43: public void changeControlPressed(DialogField field) {
44: IPackageFragmentRoot root = fPackageSelectionField
45: .getSelectedFragmentRoot();
46:
47: IJavaElement[] packages = null;
48: try {
49: if (root != null && root.exists()) {
50: packages = root.getChildren();
51: }
52: } catch (JavaModelException e) {
53: // no need to react
54: }
55:
56: if (packages == null) {
57: packages = new IJavaElement[0];
58: }
59:
60: ElementListSelectionDialog dialog = new ElementListSelectionDialog(
61: field.getLabelControl(null).getShell(),
62: new JavaElementLabelProvider(
63: JavaElementLabelProvider.SHOW_DEFAULT));
64: dialog.setIgnoreCase(true);
65:
66: dialog.setTitle(fTitle);
67: dialog.setMessage(fMessage);
68: dialog.setEmptyListMessage(fEmtpyListMessage);
69: dialog.setElements(packages);
70:
71: // TODO initial selection
72: // List selection = new ArrayList();
73: // selection.add(fPackageSelectionField.fPackageSelection.getPackageFragment());
74: // dialog.setInitialElementSelections(selection);
75:
76: if (dialog.open() == Window.OK) {
77: IPackageFragment fragment = (IPackageFragment) dialog
78: .getFirstResult();
79: fPackageSelectionField.setSelected(fragment);
80: }
81: }
82: }
|