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.internal.resources.Folder;
08: import org.eclipse.jdt.core.IJavaProject;
09: import org.eclipse.jface.viewers.ISelectionChangedListener;
10: import org.eclipse.jface.viewers.SelectionChangedEvent;
11: import org.eclipse.jface.viewers.StructuredSelection;
12: import org.eclipse.jface.viewers.Viewer;
13: import org.eclipse.jface.viewers.ViewerFilter;
14: import org.eclipse.swt.SWT;
15:
16: public final class FolderBehavior implements NavigatorBehavior {
17:
18: private static final String SELECT_FOLDER = "Select Folder";
19: private String m_selectedValue;
20:
21: public int style() {
22: return SWT.SINGLE;
23: }
24:
25: public String getTitle() {
26: return SELECT_FOLDER;
27: }
28:
29: public ViewerFilter getFilter(final IJavaProject javaProject) {
30: return new ViewerFilter() {
31: public boolean select(Viewer viewer, Object parentElement,
32: Object element) {
33: if (element instanceof IJavaProject
34: && element.equals(javaProject))
35: return true;
36: if (element instanceof Folder)
37: return true;
38: return false;
39: }
40: };
41: }
42:
43: public ISelectionChangedListener getSelectionChangedListener(
44: final PackageNavigator nav) {
45: return new ISelectionChangedListener() {
46: public void selectionChanged(SelectionChangedEvent event) {
47: nav.okButtonEnabled(true);
48: StructuredSelection selection = (StructuredSelection) event
49: .getSelection();
50: if (!selection.isEmpty()) {
51: Object element = selection.getFirstElement();
52: if (element != null) {
53: if (element instanceof IJavaProject) {
54: nav.enableSelection(false, this );
55: event.getSelectionProvider().setSelection(
56: null);
57: nav.enableSelection(true, this );
58: nav.okButtonEnabled(false);
59: } else if (element instanceof Folder) {
60: Folder folder = (Folder) element;
61: m_selectedValue = folder
62: .getProjectRelativePath()
63: .toString();
64: nav.okButtonEnabled(true);
65: }
66: }
67: }
68: }
69: };
70: }
71:
72: public Object getValues() {
73: return m_selectedValue;
74: }
75: }
|