KickJava   Java API By Example, From Geeks To Geeks.

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


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

72         if (dialog.open() == Window.OK) {
73             IPackageFragment fragment= (IPackageFragment)dialog.getFirstResult();
74             fPackageSelectionField.setSelected(fragment);
75         }
76     }
77 }
78
Popular Tags