01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.dso.editors.chooser;
06:
07: import org.eclipse.core.resources.IFile;
08: import org.eclipse.core.resources.IFolder;
09: import org.eclipse.jdt.core.IJavaProject;
10: import org.eclipse.jdt.core.IPackageFragment;
11: import org.eclipse.jdt.core.IPackageFragmentRoot;
12: import org.eclipse.jface.viewers.ISelectionChangedListener;
13: import org.eclipse.jface.viewers.SelectionChangedEvent;
14: import org.eclipse.jface.viewers.StructuredSelection;
15: import org.eclipse.jface.viewers.Viewer;
16:
17: public class ConfigFileBehavior extends FileBehavior {
18: private static final String SELECT_CONFIG_FILE_LOCATION = "Select Config File Location";
19: private static final String DEFAULT_CONFIG_FILE_NAME = "tc-config.xml";
20:
21: public String getTitle() {
22: return SELECT_CONFIG_FILE_LOCATION;
23: }
24:
25: protected boolean filterSelect(Viewer viewer, Object parentElement,
26: Object element) {
27: if (element instanceof IPackageFragment
28: || element instanceof IPackageFragmentRoot)
29: return false;
30: boolean result = super .filterSelect(viewer, parentElement,
31: element);
32: if (result && element instanceof IFile) {
33: result = "xml".equals(((IFile) element).getFileExtension());
34: }
35: return result;
36: }
37:
38: public ISelectionChangedListener getSelectionChangedListener(
39: final PackageNavigator nav) {
40: return new ISelectionChangedListener() {
41: public void selectionChanged(SelectionChangedEvent event) {
42: nav.okButtonEnabled(true);
43: StructuredSelection selection = (StructuredSelection) event
44: .getSelection();
45: if (!selection.isEmpty()) {
46: Object element = selection.getFirstElement();
47: if (element != null) {
48: if (element instanceof IJavaProject) {
49: m_selectedValue = DEFAULT_CONFIG_FILE_NAME;
50: } else if (element instanceof IFolder) {
51: IFolder folder = (IFolder) element;
52: m_selectedValue = folder
53: .getProjectRelativePath().append(
54: DEFAULT_CONFIG_FILE_NAME)
55: .toOSString();
56: } else if (element instanceof IFile) {
57: IFile file = (IFile) element;
58: m_selectedValue = file
59: .getProjectRelativePath()
60: .toOSString();
61: }
62: }
63: }
64: }
65: };
66: }
67: }
|