001: /*
002: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package org.terracotta.dso.editors.chooser;
006:
007: import org.eclipse.jdt.core.IClassFile;
008: import org.eclipse.jdt.core.ICompilationUnit;
009: import org.eclipse.jdt.core.IJavaProject;
010: import org.eclipse.jdt.core.IMethod;
011: import org.eclipse.jdt.core.IPackageFragment;
012: import org.eclipse.jdt.core.IPackageFragmentRoot;
013: import org.eclipse.jdt.core.IType;
014: import org.eclipse.jdt.core.JavaModelException;
015: import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
016: import org.eclipse.jface.viewers.ISelectionChangedListener;
017: import org.eclipse.jface.viewers.SelectionChangedEvent;
018: import org.eclipse.jface.viewers.StructuredSelection;
019: import org.eclipse.jface.viewers.Viewer;
020: import org.eclipse.jface.viewers.ViewerFilter;
021: import org.eclipse.swt.SWT;
022: import org.terracotta.dso.PatternHelper;
023:
024: import java.util.ArrayList;
025: import java.util.Iterator;
026: import java.util.List;
027:
028: public final class MethodBehavior implements NavigatorBehavior {
029:
030: public static final String ADD_MSG = "Enter AspectWerks Method Expression";
031: private static final String SELECT_METHOD = "Select Method";
032: private final List m_selectedValues;
033:
034: public MethodBehavior() {
035: this .m_selectedValues = new ArrayList();
036: }
037:
038: public int style() {
039: return SWT.MULTI;
040: }
041:
042: public String getTitle() {
043: return SELECT_METHOD;
044: }
045:
046: public ViewerFilter getFilter(final IJavaProject javaProject) {
047: return new ViewerFilter() {
048: public boolean select(Viewer viewer, Object parentElement,
049: Object element) {
050: if (element instanceof IJavaProject)
051: return true;
052: if (element instanceof ClassPathContainer
053: || element instanceof ICompilationUnit
054: || element instanceof IType
055: || element instanceof IPackageFragmentRoot
056: || element instanceof IClassFile
057: || element instanceof IMethod) {
058: return true;
059: }
060: if (element instanceof IPackageFragment) {
061: try {
062: return ((IPackageFragment) element)
063: .containsJavaResources();
064: } catch (JavaModelException jme) {/**/
065: }
066: }
067: return false;
068: }
069: };
070: }
071:
072: public ISelectionChangedListener getSelectionChangedListener(
073: final PackageNavigator nav) {
074: return new ISelectionChangedListener() {
075: public void selectionChanged(SelectionChangedEvent event) {
076: m_selectedValues.removeAll(m_selectedValues);
077: StructuredSelection selection = (StructuredSelection) event
078: .getSelection();
079: List selectedMethods = new ArrayList();
080: if (!selection.isEmpty()) {
081: Object element;
082: for (Iterator i = selection.iterator(); i.hasNext();) {
083: if ((element = i.next()) instanceof IMethod) {
084: IMethod method = (IMethod) element;
085: m_selectedValues.add(PatternHelper
086: .getExecutionPattern(method));
087: selectedMethods.add(element);
088: }
089: }
090: }
091: if (selectedMethods.size() > 0)
092: nav.okButtonEnabled(true);
093: else
094: nav.okButtonEnabled(false);
095: }
096: };
097: }
098:
099: public Object getValues() {
100: return m_selectedValues.toArray(new String[0]);
101: }
102: }
|