[jbosstools-commits] JBoss Tools SVN: r6733 - in trunk/seam/plugins/org.jboss.tools.seam.ui: META-INF and 5 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Mar 6 16:02:35 EST 2008


Author: vrubezhny
Date: 2008-03-06 16:02:35 -0500 (Thu, 06 Mar 2008)
New Revision: 6733

Added:
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
Modified:
   trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF
   trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
   trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam variable names

Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF	2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF	2008-03-06 21:02:35 UTC (rev 6733)
@@ -52,7 +52,9 @@
  org.eclipse.wst.server.core,
  org.eclipse.wst.server.ui,
  org.eclipse.debug.ui,
- org.jboss.tools.jst.web
+ org.jboss.tools.jst.web,
+ org.eclipse.search,
+ org.jboss.tools.jst.jsp
 Eclipse-LazyStart: true
 Export-Package: org.jboss.tools.seam.ui,
  org.jboss.tools.seam.ui.actions,

Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml	2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml	2008-03-06 21:02:35 UTC (rev 6733)
@@ -333,6 +333,27 @@
    	</javaCompletionProposalComputer>
 	</extension>
 
+   <extension
+         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+      <hyperlinkDetector
+            class="org.jboss.tools.seam.ui.text.java.JavaStringHyperlinkDetector"
+            id="org.jboss.tools.seam.ui.text.java.JavaStringHyperlinkDetector"
+            name="Java String"
+            targetId="org.eclipse.jdt.ui.javaCode">
+      </hyperlinkDetector>
+   </extension>
+
+	<!--======================================================================================-->
+	<!-- queryParticipant to participate in java serches                                     -->
+	<!--======================================================================================-->
+	<!-- extension point="org.eclipse.jdt.ui.queryParticipants">
+		<queryParticipant
+			name="Seam Query_Participant_Extension_Element"
+			nature="org.eclipse.jdt.core.javanature"
+			class="org.jboss.tools.seam.ui.text.java.search.SeamQueryParticipant"
+			id="org.jboss.tools.seam.ui.java.search.ui.SeamQueryParticipant" />
+	</extension -->
+	
 	<extension 
 		point="org.jboss.tools.common.text.xml.contentAssistProcessor"
 		id="org.jboss.tools.seam.ui.contentAssistProcessor"
@@ -436,6 +457,28 @@
                toolbarPath="org.eclipse.search.searchActionSet/Search"
                tooltip="Open Seam Component">
          </action>
+         <action
+               class="org.jboss.tools.seam.ui.actions.FindSeamDeclarationsAction"
+               definitionId="org.jboss.tools.seam.ui.find.declarations"
+               helpContextId="org.eclipse.jdt.ui.find_declarations_action"
+               icon="icons/open_seam_component.gif"
+               id="findDeclarations"
+               label="Find Seam Declarations"
+               menubarPath="navigate/open.ext2"
+               toolbarPath="org.eclipse.search.searchActionSet/Search"
+               tooltip="Find Seam Declarations">
+         </action>
+         <action
+               class="org.jboss.tools.seam.ui.actions.FindSeamReferencesAction"
+               definitionId="org.jboss.tools.seam.ui.find.references"
+               helpContextId="org.eclipse.jdt.ui.find_references_action"
+               icon="icons/open_seam_component.gif"
+               id="findReferences"
+               label="Find Seam References"
+               menubarPath="navigate/open.ext2"
+               toolbarPath="org.eclipse.search.searchActionSet/Search"
+               tooltip="Find Seam References">
+         </action>
       </actionSet>
    </extension>
    <extension
@@ -446,6 +489,18 @@
             id="org.jboss.tools.seam.ui.open.component"
             name="Open Seam Component">
       </command>
+      <command
+            categoryId="org.eclipse.ui.category.navigate"
+            description="Find Declarations"
+            id="org.jboss.tools.seam.ui.find.declarations"
+            name="Find Seam Declarations">
+      </command>
+      <command
+            categoryId="org.eclipse.ui.category.navigate"
+            description="Find References"
+            id="org.jboss.tools.seam.ui.find.references"
+            name="Find Seam References">
+      </command>
    </extension>
    <extension
          point="org.eclipse.ui.bindings">
@@ -454,5 +509,25 @@
             schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
             sequence="M1+M2+Z">
       </key>
+      <key
+            commandId="org.jboss.tools.seam.ui.find.declarations"
+            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+            sequence="M1+G">
+      </key>
+      <key
+            commandId="org.jboss.tools.seam.ui.find.references"
+            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+            sequence="M1+M2+G">
+      </key>
    </extension>
+   
+   <extension
+			id="SeamSearchResultPage"
+			point="org.eclipse.search.searchResultViewPages">
+		<viewPage
+			id="org.jboss.tools.seam.ui.search.SeamSearchResultPage"
+			searchResultClass="org.jboss.tools.seam.ui.search.SeamSearchResult"
+			class="org.jboss.tools.seam.ui.search.SeamSearchResultPage">
+		</viewPage>
+	</extension>
 </plugin>

Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java	2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -412,7 +412,36 @@
 	public static String RUNTIME_DELETE_NOT_USED_CONFIRM;
 
 	public static String RUNTIME_DELETE_USED_CONFIRM;
+	
+	public static String FIND_DECLARATIONS_ACTION_ACTION_NAME;
+	public static String FIND_DECLARATIONS_ACTION_DESCRIPTION;
+	public static String FIND_DECLARATIONS_ACTION_MESSAGE;
+	public static String FIND_DECLARATIONS_ACTION_TOOL_TIP;
 
+	public static String FIND_REFERENCES_ACTION_ACTION_NAME;
+	public static String FIND_REFERENCES_ACTION_DESCRIPTION;
+	public static String FIND_REFERENCES_ACTION_MESSAGE;
+	public static String FIND_REFERENCES_ACTION_TOOL_TIP;
+
+	public static String SeamSearchQuery_task_label;
+	public static String SeamSearchQuery_label;
+	public static String SeamSearchQuery_error_unsupported_pattern;
+
+	public static String SeamSearchQuery_singularPatternWithLimitTo;
+	public static String SeamSearchQuery_pluralPatternWithLimitTo;
+
+	public static String SeamSearchScope_scope_empty;
+	public static String SeamSearchScope_scope_single;
+	public static String SeamSearchScope_scope_double;
+	public static String SeamSearchScope_scope_multiple;
+
+	public static String SeamSearchScope_scope_LimitToDeclarations;
+	public static String SeamSearchScope_scope_LimitToReferences;
+	public static String SeamSearchQuery_pluralPattern;
+	public static String SeamSearchQuery_singularLabel;
+
+	public static String SeamSearchVisitor_scanning;
+
 	static {
 		// load message values from bundle file
 		NLS.initializeMessages(BUNDLE_NAME, SeamUIMessages.class);		

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,323 @@
+package org.jboss.tools.seam.ui.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
+import org.eclipse.jdt.internal.ui.search.SearchMessages;
+import org.eclipse.jdt.internal.ui.search.SearchUtil;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionDelegate2;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.el.ELOperandToken;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
+import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
+import org.jboss.tools.seam.internal.core.el.SeamELOperandTokenizer;
+import org.jboss.tools.seam.internal.core.el.SeamELOperandTokenizerForward;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.search.SeamSearchQuery;
+import org.jboss.tools.seam.ui.search.SeamSearchScope;
+
+abstract public class FindSeamAction extends Action implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
+
+	protected FindSeamAction() {
+	}
+
+	public void run() {
+		runWithEvent(null);
+	}
+	
+	private Shell getShell() {
+		try {
+			return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+		} catch (Throwable x) {
+			return null;
+		}
+	}
+	
+	public void runWithEvent(Event e) {
+		IEditorPart editor = ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+		IEditorInput input = editor.getEditorInput();
+		IDocument document = null;
+		
+
+		ISourceViewer viewer = null;
+		
+		if (editor instanceof JSPMultiPageEditor) {
+			viewer = ((JSPMultiPageEditor)editor).getJspEditor().getTextViewer();
+		} else if (editor instanceof CompilationUnitEditor) {
+			viewer = ((CompilationUnitEditor)editor).getViewer();
+		}
+		
+		if (viewer == null)
+			return;
+		
+		
+		document = viewer.getDocument();
+		
+		ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+		if (selection.isEmpty())
+			return;
+		
+		
+		int selectionOffset = 0;
+		if (selection instanceof ITextSelection) {
+			ITextSelection tSel = (ITextSelection)selection;
+			selectionOffset = tSel.getOffset();
+		} else {
+			return;
+		}
+		
+		IFile file = null;
+		
+		if (input instanceof IFileEditorInput) {
+			file = ((IFileEditorInput)input).getFile();
+		}
+
+		IProject project = (file == null ? null : file.getProject());
+
+		ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+		if (seamProject == null)
+			return;
+
+		SeamELCompletionEngine engine= new SeamELCompletionEngine();
+
+		int elStart = getELStart(document, selectionOffset);
+		
+		if (elStart == -1) 
+			elStart = selectionOffset;
+		
+		SeamELOperandTokenizerForward tokenizer = new SeamELOperandTokenizerForward(document, elStart);
+		List<ELOperandToken> tokens = tokenizer.getTokens();
+
+		if (tokens == null || tokens.size() == 0)
+			return; // No EL Operand found
+		
+		List<List<ELOperandToken>> variations = SeamELCompletionEngine.getPossibleVarsFromPrefix(tokens);
+
+		// Define the Seam project variables to search for declarations 
+		List<ISeamContextVariable> variables = new ArrayList<ISeamContextVariable>();
+		
+		for (List<ELOperandToken> variation : variations) {
+			try {
+				int start = variation.get(0).getStart();
+				int end = variation.get(variation.size() - 1).getStart() + 
+								variation.get(variation.size() - 1).getLength();
+				String variationText = document.get(start, end - start);
+				
+				Set<ISeamContextVariable> vars = seamProject.getVariablesByName(variationText);
+				variables.addAll(vars);
+			} catch (BadLocationException e1) {
+				SeamGuiPlugin.getPluginLog().logError(e1);
+			}
+		}
+
+		if (variables.size() != 0) {
+			// Some variable/variables are found - perform search for their declarations
+			String[] varNamesToSearch = new String[variables.size()];
+			for (int i = 0; i < variables.size(); i++) {
+				varNamesToSearch[i] = variables.get(i).getName(); 
+			}
+			
+			try {
+				performNewSearch(varNamesToSearch, project);
+			} catch (JavaModelException jme) {
+				SeamGuiPlugin.getPluginLog().logError(jme);
+			} catch (InterruptedException ie) {
+				SeamGuiPlugin.getPluginLog().logError(ie);
+			}
+			return;
+		}
+
+		// Try to look into "var"/"variable" attributes (if we're in the XML-like document)
+		
+		if ("java".equalsIgnoreCase(file.getFileExtension())) { //$NON-NLS-1$
+			return;
+		}
+		ElVarSearcher varSearcher = new ElVarSearcher(seamProject, file, engine);
+		List<Var> allVars = ElVarSearcher.findAllVars(viewer, selectionOffset);
+		if (allVars == null || allVars.size() == 0)
+			return;
+		
+		int start = tokens.get(0).getStart();
+		int end = tokens.get(tokens.size() - 1).getStart() + 
+						tokens.get(tokens.size() - 1).getLength();
+		
+		String elText;
+		try {
+			elText = document.get(start, end - start);
+		} catch (BadLocationException ble) {
+			SeamGuiPlugin.getPluginLog().logError(ble);
+			return;
+		}
+		if (elText == null || elText.length() == 0)
+			return;
+		
+		Var var = varSearcher.findVarForEl(elText, allVars, false);
+		if (var == null)
+			return;
+		try {
+			performNewLocalSearch(var, file);
+		} catch (JavaModelException jme) {
+			SeamGuiPlugin.getPluginLog().logError(jme);
+		} catch (InterruptedException ie) {
+			SeamGuiPlugin.getPluginLog().logError(ie);
+		}		
+	}
+
+	
+
+	// ---- IWorkbenchWindowActionDelegate
+	// ------------------------------------------------
+
+	public void run(IAction action) {
+		run();
+	}
+
+	public void dispose() {
+		// do nothing.
+	}
+
+	public void init(IWorkbenchWindow window) {
+		// do nothing.
+	}
+
+	public void selectionChanged(IAction action, ISelection selection) {
+		// do nothing. Action doesn't depend on selection.
+	}
+	
+	// ---- IActionDelegate2
+	// ------------------------------------------------
+
+	public void runWithEvent(IAction action, Event event) {
+		runWithEvent(event);
+	}
+	
+	public void init(IAction action) {
+		// do nothing.
+	}
+
+	/* 
+	 * Scans the document from the offset to the beginning to find start of Seam EL operand
+	 * Returns the start position of first Seam EL operand token 
+	 */
+	private int getELStart(IDocument document, int offset) {
+		SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(document, offset);
+		List<ELOperandToken> tokens = tokenizer.getTokens();
+
+		if (tokens == null || tokens.size() == 0)
+			return -1;
+		
+		ELOperandToken firstToken = tokens.get(0);
+		return firstToken.getStart();
+	}
+	
+	/* 
+	 * Scans the document from the offset to the beginning to find start of Seam EL operand
+	 * Returns the end position of last Seam EL operand token 
+	 */
+	private int getELEnd(IDocument document, int offset) {
+		SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizerForward(document, offset);
+		List<ELOperandToken> tokens = tokenizer.getTokens();
+
+		if (tokens == null || tokens.size() == 0)
+			return -1;
+		
+		ELOperandToken lastToken = tokens.get(tokens.size() - 1);
+		return lastToken.getStart() + lastToken.getLength();
+	}
+
+	private SeamSearchQuery createQuery(String[] patterns, IProject root) throws JavaModelException, InterruptedException {
+		
+		SeamSearchScope scope  = new SeamSearchScope(new IProject[] {root}, getLimitTo());
+
+		return new SeamSearchQuery(patterns, scope);
+	}
+
+	private SeamSearchQuery createQuery(Var var, IFile root) throws JavaModelException, InterruptedException {
+		
+		SeamSearchScope scope  = new SeamSearchScope(new IFile[] {root}, getLimitTo());
+
+		return new SeamSearchQuery(var, scope);
+	}
+
+	abstract protected int getLimitTo();
+	
+	private void performNewSearch(String[] patterns, IProject root) throws JavaModelException, InterruptedException {
+		SeamSearchQuery query= createQuery(patterns, root);
+		if (query.canRunInBackground()) {
+			/*
+			 * This indirection with Object as parameter is needed to prevent the loading
+			 * of the Search plug-in: the VM verifies the method call and hence loads the
+			 * types used in the method signature, eventually triggering the loading of
+			 * a plug-in (in this case ISearchQuery results in Search plug-in being loaded).
+			 */
+			SearchUtil.runQueryInBackground(query);
+		} else {
+			IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
+			/*
+			 * This indirection with Object as parameter is needed to prevent the loading
+			 * of the Search plug-in: the VM verifies the method call and hence loads the
+			 * types used in the method signature, eventually triggering the loading of
+			 * a plug-in (in this case it would be ISearchQuery).
+			 */
+			IStatus status= SearchUtil.runQueryInForeground(progressService, query);
+			if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
+				ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status); 
+			}
+		}
+	}
+
+	private void performNewLocalSearch(Var var, IFile root) throws JavaModelException, InterruptedException {
+		SeamSearchQuery query= createQuery(var, root);
+		if (query.canRunInBackground()) {
+			/*
+			 * This indirection with Object as parameter is needed to prevent the loading
+			 * of the Search plug-in: the VM verifies the method call and hence loads the
+			 * types used in the method signature, eventually triggering the loading of
+			 * a plug-in (in this case ISearchQuery results in Search plug-in being loaded).
+			 */
+			SearchUtil.runQueryInBackground(query);
+		} else {
+			IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
+			/*
+			 * This indirection with Object as parameter is needed to prevent the loading
+			 * of the Search plug-in: the VM verifies the method call and hence loads the
+			 * types used in the method signature, eventually triggering the loading of
+			 * a plug-in (in this case it would be ISearchQuery).
+			 */
+			IStatus status= SearchUtil.runQueryInForeground(progressService, query);
+			if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
+				ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status); 
+			}
+		}
+	}
+
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,17 @@
+package org.jboss.tools.seam.ui.actions;
+
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.search.SeamSearchScope;
+
+public class FindSeamDeclarationsAction extends FindSeamAction {
+
+	public FindSeamDeclarationsAction() {
+		setText(SeamUIMessages.FIND_DECLARATIONS_ACTION_ACTION_NAME);
+		setDescription(SeamUIMessages.FIND_DECLARATIONS_ACTION_DESCRIPTION);
+		setToolTipText(SeamUIMessages.FIND_DECLARATIONS_ACTION_TOOL_TIP);
+	}
+
+	protected int getLimitTo() {
+		return SeamSearchScope.SEARCH_FOR_DECLARATIONS;
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,17 @@
+package org.jboss.tools.seam.ui.actions;
+
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.search.SeamSearchScope;
+
+public class FindSeamReferencesAction extends FindSeamAction {
+
+	public FindSeamReferencesAction() {
+		setText(SeamUIMessages.FIND_REFERENCES_ACTION_ACTION_NAME);
+		setDescription(SeamUIMessages.FIND_REFERENCES_ACTION_DESCRIPTION);
+		setToolTipText(SeamUIMessages.FIND_REFERENCES_ACTION_TOOL_TIP);
+	}
+
+	protected int getLimitTo() {
+		return SeamSearchScope.SEARCH_FOR_REFERENCES;
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties	2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties	2008-03-06 21:02:35 UTC (rev 6733)
@@ -202,4 +202,30 @@
 OPEN_SEAM_COMPONENT_ACTION_MESSAGE=Enter seam component name prefix or pattern (? = any character, * = any string):
 OPEN_SEAM_COMPONENT_DIALOG_LOADING=Seam components loading
 OPEN_SEAM_COMPONENT_DIALOG_NAME=OpenSeamComponentDialog
-SEAM_SETTINGS_PREFERENCES_PAGE_SEAM_PROJECT=Main Seam Project:
\ No newline at end of file
+SEAM_SETTINGS_PREFERENCES_PAGE_SEAM_PROJECT=Main Seam Project:
+FIND_DECLARATIONS_ACTION_ACTION_NAME=Find Seam Declarations
+FIND_DECLARATIONS_ACTION_DESCRIPTION=Find Seam Declarations
+FIND_DECLARATIONS_ACTION_TOOL_TIP=Find Seam Declarations
+FIND_DECLARATIONS_ACTION_MESSAGE=&Choose a name of the seam variable or pattern (? = any character, * = any string):
+FIND_REFERENCES_ACTION_ACTION_NAME=Find Seam References
+FIND_REFERENCES_ACTION_DESCRIPTION=Find Seam References
+FIND_REFERENCES_ACTION_TOOL_TIP=Find Seam References
+FIND_REFERENCES_ACTION_MESSAGE=&Choose a name of the seam variable or pattern (? = any character, * = any string):
+SeamSearchQuery_task_label=Searching for ''{0}''...
+SeamSearchQuery_label=Seam {0} Search
+SeamSearchQuery_error_unsupported_pattern=Unsupported search pattern: "{0}"
+# The first argument will be replaced by the pattern, the second by the scope, last by limitTo patterns
+SeamSearchQuery_singularPatternWithLimitTo= ''{0}'' - 1 match in {1} ({2})
+# The first argument will be replaced by the pattern, the second by the count and the third by the scope, last by limitTo patterns
+SeamSearchQuery_pluralPatternWithLimitTo=''{0}'' - {1} matches in {2} ({3})
+SeamSearchScope_scope_empty=empty scope
+SeamSearchScope_scope_single=''{0}''
+SeamSearchScope_scope_double=''{0}'', ''{1}''
+SeamSearchScope_scope_multiple=''{0}'', ''{1}'', ...
+SeamSearchScope_scope_LimitToDeclarations=Declarations
+SeamSearchScope_scope_LimitToReferences=References
+# The first argument will be replaced by the pattern, the second by the count and the third by the scope
+SeamSearchQuery_pluralPattern= ''{0}'' - {1} matches in {2} ({3})
+# The first argument will be replaced by the pattern, the second by the scope
+SeamSearchQuery_singularLabel= ''{0}'' - 1 match in {1} ({2})
+SeamSearchVisitor_scanning= Scanning Seam project {1} of {2}: {0}

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,49 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+
+public class SeamElementMatch extends Match {
+	private long fCreationTimeStamp;
+	
+	public SeamElementMatch(ISeamElement element) {
+		super(element, 0, 0);
+		fCreationTimeStamp= element.getResource().getModificationStamp();
+	}
+
+	public SeamElementMatch(ISeamJavaSourceReference element) {
+		super(element, 0, 0);
+		fCreationTimeStamp= element.getSourceMember().getResource().getModificationStamp();
+	}
+
+	public SeamElementMatch(ISeamDeclaration element) {
+		super(element, 0, 0);
+		fCreationTimeStamp= element.getResource().getModificationStamp();
+	}
+
+	public SeamElementMatch(IFile element, int offset, int length) {
+		super(element, offset, length);
+		fCreationTimeStamp= ((IFile)element).getModificationStamp();
+	}
+	
+	public IFile getFile() {
+		if (getElement() instanceof ISeamJavaSourceReference) {
+			return (IFile) ((ISeamJavaSourceReference)getElement()).getSourceMember().getResource(); 
+		} else if (getElement() instanceof ISeamDeclaration) {
+			return (IFile) ((ISeamDeclaration)getElement()).getResource(); 
+		} else if (getElement() instanceof IFile) {
+			return (IFile)getElement();
+		}
+		return (IFile) ((ISeamElement)getElement()).getResource();
+	}
+
+	public long getCreationTimeStamp() {
+		return fCreationTimeStamp;
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,67 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+import org.eclipse.core.resources.IFile;
+
+import org.eclipse.search.core.text.TextSearchRequestor;
+import org.eclipse.search.core.text.TextSearchEngine;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.ui.SearchPlugin;
+
+public abstract class SeamSearchEngine {
+	
+	/**
+	 * Creates an instance of the search engine. By default this is the default text search engine (see {@link #createDefault()}),
+	 * but extensions can offer more sophisticated search engine implementations.
+	 * @return the created {@link TextSearchEngine}.
+	 */
+	public static SeamSearchEngine create() {
+		return createDefault();
+	}
+
+	/**
+	 * Creates the default, built-in, text search engine that implements a brute-force search, not using
+	 * any search index.
+	 * Note that clients should always use the search engine provided by {@link #create()}.
+	 * @return an instance of the default text search engine {@link TextSearchEngine}.
+	 */
+	public static SeamSearchEngine createDefault() {
+		return new SeamSearchEngine() {
+			public IStatus search(TextSearchScope scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor) {
+				return new SeamSearchVisitor(requestor, searchPatterns).search(scope, monitor);
+			}
+			
+//			public IStatus search(IFile[] scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor) {
+//				 return new SeamSearchVisitor(requestor, searchPatterns).search(scope, monitor);
+//			}
+		};
+	}
+	
+	/**
+	 * Uses a given search pattern to find matches in the content of workspace file resources. If a file is open in an editor, the
+	 * editor buffer is searched.
+
+	 * @param requestor the search requestor that gets the search results
+	 * @param scope the scope defining the resources to search in
+	 * 	@param searchPattern The search pattern used to find matches in the file contents.
+	 * @param monitor the progress monitor to use
+	 * @return the status containing information about problems in resources searched.
+	 */
+	public abstract IStatus search(TextSearchScope scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor);
+
+	/**
+	 * Uses a given search pattern to find matches in the content of workspace file resources. If a file is open in an editor, the
+	 * editor buffer is searched.
+
+	 * @param requestor the search requestor that gets the search results
+	 * @param scope the files to search in
+	 * 	@param searchPattern The search pattern used to find matches in the file contents.
+	 * @param monitor the progress monitor to use
+	 * @return the status containing information about problems in resources searched.
+	 */
+//	public abstract IStatus search(IFile[] scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor);
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,278 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.ui.search.ElementQuerySpecification;
+import org.eclipse.jdt.ui.search.IMatchPresentation;
+import org.eclipse.jdt.ui.search.IQueryParticipant;
+import org.eclipse.jdt.ui.search.ISearchRequestor;
+import org.eclipse.jdt.ui.search.QuerySpecification;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.search.core.text.TextSearchEngine;
+import org.eclipse.search.core.text.TextSearchMatchAccess;
+import org.eclipse.search.core.text.TextSearchRequestor;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.core.text.PatternConstructor;
+import org.eclipse.search.internal.core.text.TextSearchVisitor;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.text.FileMatch;
+import org.eclipse.search.internal.ui.text.FileSearchResult;
+import org.eclipse.search.internal.ui.text.SearchResultUpdater;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.FileTextSearchScope;
+import org.eclipse.search.ui.text.IFileMatchAdapter;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+
+public class SeamSearchQuery implements ISearchQuery {
+	
+	private final static class SeamSearchResultCollector extends SeamSearchRequestor {
+		private final AbstractTextSearchResult fResult;
+//		private final boolean fSearchInBinaries;
+		private ArrayList fCachedMatches;
+		
+		private SeamSearchResultCollector(AbstractTextSearchResult result) {
+			fResult= result;
+//			fSearchInBinaries= searchInBinaries;
+			
+		}
+		
+		public boolean acceptFile(IFile file) throws CoreException {
+//			if (fIsFileSearchOnly) {
+//				fResult.addMatch(new FileMatch(file, 0, 0));
+//			}
+			flushMatches();
+			return true;
+		}
+		
+		/* (non-Javadoc)
+		 * @see org.eclipse.search.core.text.TextSearchRequestor#reportBinaryFile(org.eclipse.core.resources.IFile)
+		 */
+		public boolean reportBinaryFile(IFile file) {
+			return false;
+		}
+
+		public boolean acceptPatternMatch(TextSearchMatchAccess matchRequestor) throws CoreException {
+			fCachedMatches.add(new FileMatch(matchRequestor.getFile(), matchRequestor.getMatchOffset(), matchRequestor.getMatchLength()));
+			return true;
+		}
+
+		public boolean acceptSeamDeclarationSourceReferenceMatch(ISeamJavaSourceReference element) throws CoreException {
+			fCachedMatches.add(new SeamElementMatch(element));
+			return true;
+		}
+		
+		public boolean acceptSeamDeclarationMatch(ISeamDeclaration element) throws CoreException {
+			fCachedMatches.add(new SeamElementMatch(element));
+			return true;
+		}
+
+		public void beginReporting() {
+			fCachedMatches= new ArrayList();
+		}
+		
+		public void endReporting() {
+			flushMatches();
+			fCachedMatches= null;
+		}
+
+		private void flushMatches() {
+			if (!fCachedMatches.isEmpty()) {
+				fResult.addMatches((Match[]) fCachedMatches.toArray(new Match[fCachedMatches.size()]));
+				fCachedMatches.clear();
+			}
+		}
+	}
+	
+	private final SeamSearchScope fScope;
+	private final String[] fVariables;
+	private final Var fVar;
+	private SeamSearchResult fResult;
+	
+	public SeamSearchQuery(String[] variables, SeamSearchScope scope) {
+		fVariables = variables;
+		fVar = null;
+		fScope= scope;
+	}
+
+	public SeamSearchQuery(Var var, SeamSearchScope scope) {
+		fVariables = null;
+		fVar = var;
+		fScope= scope;
+	}
+	
+	public SeamSearchScope getSearchScope() {
+		return fScope;
+	}
+	
+	public boolean canRunInBackground() {
+		return true;
+	}
+
+	
+	public IStatus run(final IProgressMonitor monitor) {
+		AbstractTextSearchResult textResult= (AbstractTextSearchResult) getSearchResult();
+		textResult.removeAll();
+		
+		if (fVariables != null) {
+			Pattern[] searchPatterns = new Pattern[fVariables == null ? 0 : fVariables.length];
+			for (int i = 0; i < searchPatterns.length; i++) { 
+				searchPatterns[i]= getSearchPattern(fVariables[i]);
+			}
+			SeamSearchResultCollector collector= new SeamSearchResultCollector(textResult);
+			return SeamSearchEngine.create().search(fScope, collector, searchPatterns, monitor);
+		} else if (fVar != null) {
+			if (fScope.isLimitToDeclarations()) {
+				textResult.addMatch(new SeamElementMatch((IFile)fScope.getRoots()[0], fVar.getDeclarationOffset(), fVar.getDeclarationLength()));
+			} else {
+				Pattern[] searchPatterns = new Pattern[fVar == null ? 0 : 1];
+				if (searchPatterns.length > 0) {
+					searchPatterns[0]= getSearchPattern(fVar.getName());
+				}
+				SeamSearchResultCollector collector= new SeamSearchResultCollector(textResult);
+				return SeamSearchEngine.create().search(fScope, collector, searchPatterns, monitor);
+				
+			}
+			return Status.OK_STATUS;
+		}
+		return Status.OK_STATUS;
+	}
+	
+	private boolean isScopeAllFileTypes() {
+		String[] fileNamePatterns= fScope.getFileNamePatterns();
+		if (fileNamePatterns == null)
+			return true;
+		for (int i= 0; i < fileNamePatterns.length; i++) {
+			if ("*".equals(fileNamePatterns[i])) { //$NON-NLS-1$
+				return true;
+			}
+		}
+		return false;
+	}
+	
+
+	public String getLabel() {
+		Object[] args= { fScope.getLimitToDescription() };
+		return Messages.format(SeamUIMessages.SeamSearchQuery_label, args);
+	}
+	
+	public String getSearchString() {
+		String searchString = "";
+		if (fVariables != null) {
+			StringBuffer buf= new StringBuffer();
+			for (int i= 0; i < fVariables.length; i++) {
+				if (i > 0) {
+					buf.append(", "); //$NON-NLS-1$
+				}
+				buf.append(fVariables[i]);
+			}
+			searchString = buf.toString();
+		} else if (fVar != null) {
+			searchString = fVar.getName();
+		}
+		return searchString;
+	}
+	
+	public String getResultLabel(int nMatches) {
+		String searchString= getSearchString();
+		if (searchString.length() > 0) {
+			if (fScope.isLimitToDeclarations()) {
+				// search is limited to declarations only
+				if (nMatches == 1) {
+					Object[] args= { searchString, fScope.getDescription(), fScope.getLimitToDescription() };
+					return Messages.format(SeamUIMessages.SeamSearchQuery_singularPatternWithLimitTo, args);
+				}
+				Object[] args= { searchString, new Integer(nMatches), fScope.getDescription(), fScope.getLimitToDescription() };
+				return Messages.format(SeamUIMessages.SeamSearchQuery_pluralPatternWithLimitTo, args);
+			}
+			if (fScope.isLimitToReferences()) {
+				// text search
+				if (isScopeAllFileTypes()) {
+					// search all file extensions
+					if (nMatches == 1) {
+						Object[] args= { searchString, fScope.getDescription(), fScope.getLimitToDescription() };
+						return Messages.format(SeamUIMessages.SeamSearchQuery_singularLabel, args);
+					}
+					Object[] args= { searchString, new Integer(nMatches), fScope.getDescription(), fScope.getLimitToDescription() };
+					return Messages.format(SeamUIMessages.SeamSearchQuery_pluralPattern, args); 
+				}
+			}
+			// text search
+			if (isScopeAllFileTypes()) {
+				// search all file extensions
+				if (nMatches == 1) {
+					Object[] args= { searchString, fScope.getDescription() };
+					return Messages.format(SearchMessages.FileSearchQuery_singularLabel, args);
+				}
+				Object[] args= { searchString, new Integer(nMatches), fScope.getDescription() };
+				return Messages.format(SearchMessages.FileSearchQuery_pluralPattern, args); 
+			}
+			// search selected file extensions
+			if (nMatches == 1) {
+				Object[] args= { searchString, fScope.getDescription(), fScope.getFilterDescription() };
+				return Messages.format(SearchMessages.FileSearchQuery_singularPatternWithFileExt, args);
+			}
+			Object[] args= { searchString, new Integer(nMatches), fScope.getDescription(), fScope.getFilterDescription() };
+			return Messages.format(SearchMessages.FileSearchQuery_pluralPatternWithFileExt, args);
+		}
+		// file search
+		if (nMatches == 1) {
+			Object[] args= { fScope.getFilterDescription(), fScope.getDescription() };
+			return Messages.format(SearchMessages.FileSearchQuery_singularLabel_fileNameSearch, args); 
+		}
+		Object[] args= { fScope.getFilterDescription(), new Integer(nMatches), fScope.getDescription() };
+		return Messages.format(SearchMessages.FileSearchQuery_pluralPattern_fileNameSearch, args); 
+	}
+
+	/**
+	 * @param result all result are added to this search result
+	 * @param monitor the progress monitor to use
+	 * @param file the file to search in
+	 * @return returns the status of the operation
+	 */
+/*	public IStatus searchInFile(final AbstractTextSearchResult result, final IProgressMonitor monitor, IFile file) {
+		FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] { file }, new String[] { "*" }, true); //$NON-NLS-1$
+		
+		Pattern[] searchPatterns= new Pattern[fVariables == null ? 0 : fVariables.length];
+		for (int i = 0; fVariables != null && i < fVariables.length; i++) {
+			searchPatterns[i]= getSearchPattern(fVariables[i]);
+		}
+		SeamSearchResultCollector collector= new SeamSearchResultCollector(result, true);
+		
+		return SeamSearchEngine.create().search(scope, collector, searchPatterns, monitor);
+	}
+*/	
+	protected Pattern getSearchPattern(String variableName) {
+		return PatternConstructor.createPattern(variableName, true, false);
+	}
+	
+	public boolean canRerun() {
+		return true;
+	}
+
+	public ISearchResult getSearchResult() {
+		if (fResult == null) {
+			fResult= new SeamSearchResult(this);
+			new SearchResultUpdater(fResult);
+		}
+		return fResult;
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,46 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.search.core.text.TextSearchRequestor;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+
+public class SeamSearchRequestor extends TextSearchRequestor {
+
+	/**
+	 * Notification sent before search starts in the given Seam Java Source Reference. This method is called for all Seam Java Source References are contained
+	 * in the search scope.
+	 * Implementors can decide if the Seam Java Source Reference's content should be searched for search matches or not.
+	 * <p>
+	 * The default behaviour is to search the file for matches.
+	 * </p>
+	 * @param Seam Java Source Reference the file resource to be searched.
+	 * @return If false, no pattern matches will be reported for the content of this file.
+	 * @throws CoreException implementors can throw a {@link CoreException} if accessing the resource fails or another
+	 * problem prevented the processing of the search match.
+	 */
+	public boolean acceptSeamDeclarationSourceReferenceMatch(ISeamJavaSourceReference reference) throws CoreException {
+		return true;
+	}
+
+	/**
+	 * Notification sent before search starts in the given Seam Element. This method is called for all Seam Java Source References are contained
+	 * in the search scope.
+	 * Implementors can decide if the Seam Java Source Reference's content should be searched for search matches or not.
+	 * <p>
+	 * The default behaviour is to search the file for matches.
+	 * </p>
+	 * @param Seam Java Source Reference the file resource to be searched.
+	 * @return If false, no pattern matches will be reported for the content of this file.
+	 * @throws CoreException implementors can throw a {@link CoreException} if accessing the resource fails or another
+	 * problem prevented the processing of the search match.
+	 */
+	public boolean acceptSeamDeclarationMatch(ISeamDeclaration element) throws CoreException {
+		return true;
+	}
+
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,79 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.ui.search.IMatchPresentation;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.search.internal.ui.SearchPluginImages;
+import org.eclipse.search.internal.ui.text.FileSearchQuery;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.ISearchResultListener;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.IEditorMatchAdapter;
+import org.eclipse.search.ui.text.IFileMatchAdapter;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+
+public class SeamSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
+	private final Match[] EMPTY_ARR= new Match[0];
+	
+	private SeamSearchQuery fQuery;
+
+	public SeamSearchResult(SeamSearchQuery job) {
+		fQuery= job;
+	}
+	public ImageDescriptor getImageDescriptor() {
+		return SearchPluginImages.DESC_OBJ_TSEARCH_DPDN;
+	}
+	public String getLabel() {
+		return fQuery.getResultLabel(getMatchCount());
+	}
+	public String getTooltip() {
+		return getLabel();
+	}
+
+	public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
+		return getMatches(file);
+	}
+
+	public IFile getFile(Object element) {
+		if (element instanceof IFile)
+			return (IFile)element;
+		return null;
+	}
+
+	public boolean isShownInEditor(Match match, IEditorPart editor) {
+		IEditorInput ei= editor.getEditorInput();
+		if (ei instanceof IFileEditorInput) {
+			IFileEditorInput fi= (IFileEditorInput) ei;
+			return match.getElement().equals(fi.getFile());
+		}
+		return false;
+	}
+	
+	public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
+		IEditorInput ei= editor.getEditorInput();
+		if (ei instanceof IFileEditorInput) {
+			IFileEditorInput fi= (IFileEditorInput) ei;
+			return getMatches(fi.getFile());
+		}
+		return EMPTY_ARR;
+	}
+
+	public ISearchQuery getQuery() {
+		return fQuery;
+	}
+	
+	public IFileMatchAdapter getFileMatchAdapter() {
+		return this;
+	}
+	
+	public IEditorMatchAdapter getEditorMatchAdapter() {
+		return this;
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,342 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.HashMap;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.text.EditorOpener;
+import org.eclipse.search.internal.ui.text.FileLabelProvider;
+import org.eclipse.search.internal.ui.text.FileSearchPage;
+import org.eclipse.search.internal.ui.text.FileSearchQuery;
+import org.eclipse.search.internal.ui.text.FileTableContentProvider;
+import org.eclipse.search.internal.ui.text.FileTreeContentProvider;
+import org.eclipse.search.internal.ui.text.IFileSearchContentProvider;
+import org.eclipse.search.internal.ui.text.NewTextSearchActionGroup;
+//import org.eclipse.search.internal.ui.text.ReplaceAction2;
+import org.eclipse.search.internal.ui.text.ResourceTransferDragAdapter;
+import org.eclipse.search.internal.ui.text.SortAction;
+import org.eclipse.search.internal.ui.text.TextSearchPage;
+import org.eclipse.search.internal.ui.text.FileSearchPage.DecoratorIgnoringViewerSorter;
+import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.ISearchResultPage;
+import org.eclipse.search.ui.ISearchResultViewPart;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.search2.internal.ui.OpenSearchPreferencesAction;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.IShowInTargetList;
+import org.eclipse.ui.part.ResourceTransfer;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.seam.core.IOpenableElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+
+public class SeamSearchResultPage extends AbstractTextSearchViewPage implements IAdaptable {
+	
+	public static class DecoratorIgnoringViewerSorter extends ViewerComparator {
+		private final ILabelProvider fLabelProvider;
+		
+		public DecoratorIgnoringViewerSorter(ILabelProvider labelProvider) {
+			fLabelProvider= labelProvider;
+		}
+		
+		/* (non-Javadoc)
+		 * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
+		 */
+		public int category(Object element) {
+			if (element instanceof IContainer) {
+				return 1;
+			}
+			return 2;
+		}
+		
+	    public int compare(Viewer viewer, Object e1, Object e2) {
+	        int cat1 = category(e1);
+	        int cat2 = category(e2);
+
+	        if (cat1 != cat2) {
+				return cat1 - cat2;
+			}
+	    	
+	        String name1= fLabelProvider.getText(e1);
+	        String name2= fLabelProvider.getText(e2);
+	        if (name1 == null)
+	            name1 = "";//$NON-NLS-1$
+	        if (name2 == null)
+	            name2 = "";//$NON-NLS-1$
+	        return getComparator().compare(name1, name2);
+	    }
+	}
+	
+	private static final String KEY_SORTING= "org.eclipse.search.resultpage.sorting"; //$NON-NLS-1$
+	private static final String KEY_LIMIT= "org.eclipse.search.resultpage.limit"; //$NON-NLS-1$
+	
+	private static final int DEFAULT_ELEMENT_LIMIT = 1000;
+
+	private ActionGroup fActionGroup;
+	private IFileSearchContentProvider fContentProvider;
+	private int fCurrentSortOrder;
+//	private SortAction fSortByNameAction;
+//	private SortAction fSortByPathAction;
+	
+	private EditorOpener fEditorOpener= new EditorOpener();
+
+		
+	private static final String[] SHOW_IN_TARGETS= new String[] { IPageLayout.ID_RES_NAV };
+	private  static final IShowInTargetList SHOW_IN_TARGET_LIST= new IShowInTargetList() {
+		public String[] getShowInTargetIds() {
+			return SHOW_IN_TARGETS;
+		}
+	};
+
+	public SeamSearchResultPage() {
+//		fSortByNameAction= new SortAction(SearchMessages.FileSearchPage_sort_name_label, this, FileLabelProvider.SHOW_LABEL_PATH); 
+//		fSortByPathAction= new SortAction(SearchMessages.FileSearchPage_sort_path_label, this, FileLabelProvider.SHOW_PATH_LABEL); 
+
+		setElementLimit(new Integer(DEFAULT_ELEMENT_LIMIT));
+	}
+	
+	public void setElementLimit(Integer elementLimit) {
+		super.setElementLimit(elementLimit);
+		int limit= elementLimit.intValue();
+		getSettings().put(KEY_LIMIT, limit);
+	}	
+	
+	public StructuredViewer getViewer() {
+		return super.getViewer();
+	}
+	
+	private void addDragAdapters(StructuredViewer viewer) {
+		Transfer[] transfers= new Transfer[] { ResourceTransfer.getInstance() };
+		int ops= DND.DROP_COPY | DND.DROP_LINK;
+		viewer.addDragSupport(ops, transfers, new ResourceTransferDragAdapter(viewer));
+	}	
+
+	protected void configureTableViewer(TableViewer viewer) {
+		viewer.setUseHashlookup(true);
+		SeamSearchViewLabelProvider innerLabelProvider= new SeamSearchViewLabelProvider(this, FileLabelProvider.SHOW_LABEL_PATH);
+		viewer.setLabelProvider(new DecoratingLabelProvider(innerLabelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
+		viewer.setContentProvider(new SeamTableContentProvider(this));
+		viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
+		fContentProvider= (IFileSearchContentProvider) viewer.getContentProvider();
+		addDragAdapters(viewer);
+	}
+
+	protected void configureTreeViewer(TreeViewer viewer) {
+		viewer.setUseHashlookup(true);
+		SeamSearchViewLabelProvider innerLabelProvider= new SeamSearchViewLabelProvider(this, FileLabelProvider.SHOW_LABEL_PATH);
+		viewer.setLabelProvider(new DecoratingLabelProvider(innerLabelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
+		viewer.setContentProvider(new SeamTreeContentProvider(this, viewer));
+		viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
+		fContentProvider= (IFileSearchContentProvider) viewer.getContentProvider();
+		addDragAdapters(viewer);
+	}
+
+	protected void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
+		if (match.getElement() instanceof ISeamJavaSourceReference) {
+			IJavaElement javaElement = ((ISeamJavaSourceReference)match.getElement()).getSourceMember();
+			try {
+				IEditorPart part = JavaUI.openInEditor(javaElement);
+				if (part != null) {
+					JavaUI.revealInEditor(part, (IJavaElement)javaElement);
+				}
+			} catch (PartInitException e) {
+//				SeamExtPlugin.getPluginLog().logError(e);  
+			} catch (JavaModelException e) {
+				// Ignore. It is probably because of Java element is not found 
+			}
+		} else if (match.getElement() instanceof IOpenableElement) {
+			((IOpenableElement)match.getElement()).open();
+		} else if (match.getElement() instanceof IFile) {
+			IFile file= (IFile) match.getElement();
+			IEditorPart editor= fEditorOpener.open(file, activate);
+			offset = match.getOffset();
+			length = match.getLength();
+			if (offset != 0 && length != 0) {
+				if (editor instanceof ITextEditor) {
+					ITextEditor textEditor= (ITextEditor) editor;
+					textEditor.selectAndReveal(offset, length);
+				} else if (editor != null) {
+					showWithMarker(editor, file, offset, length);
+				}
+			}
+		}
+	}
+	
+	private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
+		IMarker marker= null;
+		try {
+			marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
+			HashMap attributes= new HashMap(4);
+			attributes.put(IMarker.CHAR_START, new Integer(offset));
+			attributes.put(IMarker.CHAR_END, new Integer(offset + length));
+			marker.setAttributes(attributes);
+			IDE.gotoMarker(editor, marker);
+		} catch (CoreException e) {
+			throw new PartInitException(SearchMessages.FileSearchPage_error_marker, e); 
+		} finally {
+			if (marker != null)
+				try {
+					marker.delete();
+				} catch (CoreException e) {
+					// ignore
+				}
+		}
+	}
+
+	protected void fillContextMenu(IMenuManager mgr) {
+		super.fillContextMenu(mgr);
+		addSortActions(mgr);
+		fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
+		fActionGroup.fillContextMenu(mgr);
+		FileSearchQuery query= (FileSearchQuery) getInput().getQuery();
+		if (!"".equals(query.getSearchString())) { //$NON-NLS-1$
+//		ReplaceAction2 replaceAction= new ReplaceAction2(this, (IStructuredSelection) getViewer().getSelection());
+//		if (replaceAction.isEnabled())
+//			mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAction);
+				
+//		ReplaceAction2 replaceAll= new ReplaceAction2(this);
+//		if (replaceAll.isEnabled())
+//			mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll);
+		}
+	}
+	
+	private void addSortActions(IMenuManager mgr) {
+		if (getLayout() != FLAG_LAYOUT_FLAT)
+			return;
+		MenuManager sortMenu= new MenuManager(SearchMessages.FileSearchPage_sort_by_label); 
+//		sortMenu.add(fSortByNameAction);
+//		sortMenu.add(fSortByPathAction);
+		
+//		fSortByNameAction.setChecked(fCurrentSortOrder == fSortByNameAction.getSortOrder());
+//		fSortByPathAction.setChecked(fCurrentSortOrder == fSortByPathAction.getSortOrder());
+		
+		mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu);
+	}
+
+	public void setViewPart(ISearchResultViewPart part) {
+		super.setViewPart(part);
+		fActionGroup= new NewTextSearchActionGroup(part);
+	}
+	
+	public void init(IPageSite site) {
+		super.init(site);
+		IMenuManager menuManager = site.getActionBars().getMenuManager();
+		menuManager.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, new OpenSearchPreferencesAction());
+	}
+	
+	public void dispose() {
+		fActionGroup.dispose();
+		super.dispose();
+	}
+
+	protected void elementsChanged(Object[] objects) {
+		if (fContentProvider != null)
+			fContentProvider.elementsChanged(objects);
+	}
+
+	protected void clear() {
+		if (fContentProvider != null)
+			fContentProvider.clear();
+	}
+
+	public void setSortOrder(int sortOrder) {
+		fCurrentSortOrder= sortOrder;
+		DecoratingLabelProvider lpWrapper= (DecoratingLabelProvider) getViewer().getLabelProvider();
+		((FileLabelProvider) lpWrapper.getLabelProvider()).setOrder(sortOrder);
+		getViewer().refresh();
+		getSettings().put(KEY_SORTING, fCurrentSortOrder);
+	}
+	
+	public void restoreState(IMemento memento) {
+		super.restoreState(memento);
+		try {
+			fCurrentSortOrder= getSettings().getInt(KEY_SORTING);
+		} catch (NumberFormatException e) {
+//			fCurrentSortOrder= fSortByNameAction.getSortOrder();
+		}
+		int elementLimit= DEFAULT_ELEMENT_LIMIT;
+		try {
+			elementLimit= getSettings().getInt(KEY_LIMIT);
+		} catch (NumberFormatException e) {
+		}
+		if (memento != null) {
+			Integer value= memento.getInteger(KEY_SORTING);
+			if (value != null)
+				fCurrentSortOrder= value.intValue();
+			
+			value= memento.getInteger(KEY_LIMIT);
+			if (value != null)
+				elementLimit= value.intValue();
+		}
+		setElementLimit(new Integer(elementLimit));
+	}
+	public void saveState(IMemento memento) {
+		super.saveState(memento);
+		memento.putInteger(KEY_SORTING, fCurrentSortOrder);
+		memento.putInteger(KEY_LIMIT, getElementLimit().intValue());
+	}
+	
+	public Object getAdapter(Class adapter) {
+		if (IShowInTargetList.class.equals(adapter)) {
+			return SHOW_IN_TARGET_LIST;
+		}
+		return null;
+	}
+	
+	public String getLabel() {
+		String label= super.getLabel();
+		StructuredViewer viewer= getViewer();
+		if (viewer instanceof TableViewer) {
+			TableViewer tv= (TableViewer) viewer;
+
+			AbstractTextSearchResult result= getInput();
+			if (result != null) {
+				int itemCount= ((IStructuredContentProvider) tv.getContentProvider()).getElements(getInput()).length;
+				int fileCount= getInput().getElements().length;
+				if (itemCount < fileCount) {
+					String format= SearchMessages.FileSearchPage_limited_format; 
+					return Messages.format(format, new Object[]{label, new Integer(itemCount), new Integer(fileCount)});
+				}
+			}
+		}
+		return label;
+	}
+
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,156 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.core.text.FilesOfScopeCalculator;
+import org.eclipse.search.internal.core.text.PatternConstructor;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.WorkingSetComparator;
+import org.eclipse.search.internal.ui.util.FileTypeEditor;
+import org.eclipse.search.ui.text.FileTextSearchScope;
+import org.eclipse.ui.IWorkingSet;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+
+public class SeamSearchScope extends TextSearchScope {
+	public static final int SEARCH_FOR_DECLARATIONS = 0;
+	public static final int SEARCH_FOR_REFERENCES = 1;
+	
+	private static final String[] FILE_NAMES = new String[] {
+		"*" 
+	};
+	
+	int fLimitTo;
+	String fDescription;
+	FileTextSearchScope fFileTextSearchScope;
+
+	public SeamSearchScope(IResource[] resources, int limitTo) {
+		fFileTextSearchScope = FileTextSearchScope.newSearchScope(resources, 
+				FILE_NAMES, true);
+
+		String description;
+
+		if (resources.length == 0) {
+			description= SeamUIMessages.SeamSearchScope_scope_empty;
+		} else if (resources.length == 1) {
+			String label= SeamUIMessages.SeamSearchScope_scope_single;
+			description= Messages.format(label, resources[0].getName());
+		} else if (resources.length == 2) {
+			String label= SeamUIMessages.SeamSearchScope_scope_double;
+			description= Messages.format(label, new String[] { resources[0].getName(), resources[1].getName()});
+		} else {
+			String label= SeamUIMessages.SeamSearchScope_scope_multiple;
+			description= Messages.format(label, new String[] { resources[0].getName(), resources[1].getName()});
+		}
+
+		fLimitTo = limitTo;
+	}
+	
+	public int getLimitTo() {
+		return fLimitTo;
+	}
+	
+	public boolean isLimitToDeclarations() {
+		return (SEARCH_FOR_DECLARATIONS == fLimitTo);
+	}
+
+	public boolean isLimitToReferences() {
+		return (SEARCH_FOR_REFERENCES == fLimitTo);
+	}
+	
+	@Override
+	public boolean contains(IResourceProxy proxy) {
+		return fFileTextSearchScope.contains(proxy);
+	}
+	
+	/**
+	 * Returns the file name pattern configured for this scope or <code>null</code> to match
+	 * all file names.
+	 * 
+	 * @return the file name pattern strings
+	 */
+	public String[] getFileNamePatterns() {
+		return fFileTextSearchScope.getFileNamePatterns();
+	}
+
+	/**
+	 * Returns the description of the scope
+	 * 
+	 * @return the description of the scope
+	 */
+	public String getDescription() {
+		return fFileTextSearchScope.getDescription();
+	}
+
+	/**
+	 * Returns the description of the scope
+	 * 
+	 * @return the description of the scope
+	 */
+	public String getLimitToDescription() {
+		return isLimitToDeclarations() ?
+			SeamUIMessages.SeamSearchScope_scope_LimitToDeclarations : 
+			SeamUIMessages.SeamSearchScope_scope_LimitToReferences;
+	}
+
+	/**
+	 * Returns a description describing the file name patterns and content types.
+	 * 
+	 * @return the description of the scope
+	 */
+	public String getFilterDescription() {
+		return fFileTextSearchScope.getFilterDescription();
+	}
+	
+	/**
+	 * Returns the resources that form the root. Roots can not contain each other. Root elements are only part of the
+	 * scope if they are also accepted by {@link #contains(IResourceProxy)}.
+	 * 
+	 * @return returns the set of root resources. The default behavior is to return the workspace root.
+	 */
+	public IResource[] getRoots() {
+		return fFileTextSearchScope.getRoots();
+	}
+
+	
+	/**
+	 * Evaluates all Seam Projects in this scope.
+	 * 
+	 * @param status a {@link MultiStatus} to collect the error status that occurred while collecting resources.
+	 * @return returns the files in the scope.
+	 */
+	public ISeamProject[] evaluateSeamProjectsInScope(MultiStatus status) {
+		IFile[] files = evaluateFilesInScope(status);
+		ArrayList<IProject> projects = new ArrayList<IProject>();
+		ArrayList<ISeamProject> seamProjects = new ArrayList<ISeamProject>();
+		
+		for (int i = 0; files != null && i < files.length; i++) {
+			IProject project = (files[i] == null ? null : files[i].getProject());
+			if (project == null || projects.contains(project)) 
+				continue;
+			ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+			if (seamProject != null && !seamProjects.contains(seamProject)) {
+				projects.add(project);
+				seamProjects.add(seamProject);
+			}
+		}
+		return (ISeamProject[]) seamProjects.toArray(new ISeamProject[seamProjects.size()]);
+	}
+
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,81 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.search.internal.ui.text.FileLabelProvider;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.ui.views.SeamLabelProvider;
+
+public class SeamSearchViewLabelProvider extends LabelProvider {
+	private FileLabelProvider fFileLabelProvider;
+	private SeamLabelProvider fSeamLabelProvider;
+	private AbstractTextSearchViewPage fPage;
+	private int fOrderFlag;
+	
+	public SeamSearchViewLabelProvider(AbstractTextSearchViewPage page, int orderFlag) {
+		fPage = page;
+		fOrderFlag = orderFlag;
+		fFileLabelProvider = new FileLabelProvider(page, orderFlag);
+		fSeamLabelProvider = new SeamLabelProvider();
+	}
+	
+	@Override
+	public Image getImage(Object element) {
+		if (element instanceof ISeamContextVariable ||
+				element instanceof ISeamJavaSourceReference) {
+			return fSeamLabelProvider.getImage(element);
+		}
+		if (element instanceof ISeamElement) {
+			return fSeamLabelProvider.getImage(element);
+		}
+		if (element instanceof IProject) {
+			ISeamProject seamProject = SeamCorePlugin.getSeamProject((IProject)element, false);
+			if (seamProject != null) {
+				return fSeamLabelProvider.getImage(seamProject);
+			} 
+			return fFileLabelProvider.getImage(element);
+		}
+		if (element instanceof IFolder) {
+			return fFileLabelProvider.getImage(element);
+		}
+		if (element instanceof IFile) {
+			return fFileLabelProvider.getImage(element);
+		}
+		return null;
+	}
+
+	@Override
+	public String getText(Object element) {
+		if (element instanceof ISeamContextVariable ||
+				element instanceof ISeamJavaSourceReference) {
+			return fSeamLabelProvider.getText(element);
+		}
+		if (element instanceof ISeamElement) {
+			return fSeamLabelProvider.getText(element);
+		}
+		if (element instanceof IProject) {
+			ISeamProject seamProject = SeamCorePlugin.getSeamProject((IProject)element, false);
+			if (seamProject != null) {
+				return fSeamLabelProvider.getText(seamProject);
+			} 
+			return fFileLabelProvider.getText(element);
+		}
+		
+		if (element instanceof IFile) {
+			return fFileLabelProvider.getText(element);
+		}
+		if (element instanceof IFolder) {
+			return fFileLabelProvider.getText(element);
+		}
+		return null;
+	}
+
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,858 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.io.IOException;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.core.text.DocumentCharSequence;
+import org.eclipse.search.internal.core.text.FileCharSequenceProvider;
+import org.eclipse.search.internal.core.text.FilesOfScopeCalculator;
+import org.eclipse.search.internal.core.text.TextSearchVisitor;
+import org.eclipse.search.internal.core.text.TextSearchVisitor.ReusableMatchAccess;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.SearchPlugin;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.seam.core.BijectedAttributeType;
+import org.jboss.tools.seam.core.IBijectedAttribute;
+import org.jboss.tools.seam.core.IOpenableElement;
+import org.jboss.tools.seam.core.IRole;
+import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamContextShortVariable;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamFactory;
+import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.ISeamScope;
+import org.jboss.tools.seam.core.ISeamTextSourceReference;
+import org.jboss.tools.seam.core.ISeamXmlFactory;
+import org.jboss.tools.seam.core.SeamCoreMessages;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.core.SeamPreferences;
+import org.jboss.tools.seam.internal.core.AbstractSeamDeclaration;
+import org.jboss.tools.seam.internal.core.BijectedAttribute;
+import org.jboss.tools.seam.internal.core.Role;
+import org.jboss.tools.seam.internal.core.SeamComponent;
+import org.jboss.tools.seam.internal.core.SeamJavaContextVariable;
+import org.jboss.tools.seam.internal.core.el.ELOperandToken;
+import org.jboss.tools.seam.internal.core.el.ELStringToken;
+import org.jboss.tools.seam.internal.core.el.ELToken;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
+import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
+import org.jboss.tools.seam.internal.core.el.SeamELOperandTokenizerForward;
+import org.jboss.tools.seam.internal.core.el.SeamELStringTokenizer;
+import org.jboss.tools.seam.internal.core.el.SeamELTokenizer;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class SeamSearchVisitor {
+	private final Matcher[] fMatchers;
+	private final SeamSearchRequestor fCollector;
+
+	private final MultiStatus fStatus;
+	private IProgressMonitor fProgressMonitor;
+	private int fNumberOfScannedFiles;
+	private int fNumberOfFilesToScan;
+	private ISeamProject fCurrentSeamProject;
+	private Map fDocumentsInEditors;
+	private final TextSearchVisitor.ReusableMatchAccess fMatchAccess;
+
+	private IFile fCurrentFile;
+	private final FileCharSequenceProvider fFileCharSequenceProvider;
+	private final SeamELCompletionEngine fCompletionEngine;
+	
+	public SeamSearchVisitor(SeamSearchRequestor collector,
+			Pattern[] searchPatterns) {
+		fCollector= collector;
+		fStatus= new MultiStatus(NewSearchUI.PLUGIN_ID, IStatus.OK, SearchMessages.TextSearchEngine_statusMessage, null);
+		fMatchers = new Matcher[searchPatterns == null ? 0 : searchPatterns.length];
+		for (int i = 0; searchPatterns != null && i < searchPatterns.length; i++) {
+			fMatchers[i]= searchPatterns[i].pattern().length() == 0 ? null : searchPatterns[i].matcher(new String());
+		}
+		fFileCharSequenceProvider= new FileCharSequenceProvider();
+		fMatchAccess= new ReusableMatchAccess();
+		fCompletionEngine = new SeamELCompletionEngine();
+	}
+
+	SeamSearchScope fCurrentScope = null;
+	public IStatus search(TextSearchScope scope, IProgressMonitor monitor) {
+		try {
+			if (scope instanceof SeamSearchScope) {
+				fCurrentScope = (SeamSearchScope)scope;
+				if (((SeamSearchScope)scope).isLimitToDeclarations()) {
+					return searchForDeclarations(((SeamSearchScope)scope).evaluateSeamProjectsInScope(fStatus), monitor);
+				} else {
+					return searchForReferences(((SeamSearchScope)scope).evaluateSeamProjectsInScope(fStatus), monitor);
+				}
+				
+			}
+		} finally {
+			fCurrentScope = null;
+		}
+		return Status.OK_STATUS;
+    }
+
+	public IStatus searchForDeclarations(ISeamProject[] projects, IProgressMonitor monitor) {
+		fProgressMonitor= monitor == null ? new NullProgressMonitor() : monitor;
+        fNumberOfScannedFiles= 0;
+        fNumberOfFilesToScan= projects.length;
+        fCurrentSeamProject= null;
+        
+        Job monitorUpdateJob= new MonitorUpdateJob();
+
+        try {
+            fProgressMonitor.beginTask(getTaskName(), fNumberOfFilesToScan);
+            monitorUpdateJob.setSystem(true);
+            monitorUpdateJob.schedule();
+            try {
+	            fCollector.beginReporting();
+	            processSeamProjects(projects, true);
+	            return fStatus;
+            } finally {
+                monitorUpdateJob.cancel();
+            }
+        } finally {
+            fProgressMonitor.done();
+            fCollector.endReporting();
+        }
+	}
+
+	private void processSeamProjects(ISeamProject[] projects, boolean searchDeclarations) {
+        for (int i= 0; i < projects.length; i++) {
+        	fCurrentSeamProject= projects[i];
+            boolean res= searchDeclarations ? processSeamDeclarationsInProject(fCurrentSeamProject) :
+            	processSeamReferencesInProject(fCurrentSeamProject);
+            if (!res)
+            	break;
+		}
+	}
+
+	private ElVarSearcher fELVarSearcher;
+	public boolean processSeamReferencesInProject(ISeamProject project) {
+		IFile[] files = fCurrentScope == null ? null :
+					fCurrentScope.evaluateFilesInScope(fStatus);
+		
+		
+		
+		fELVarSearcher = new ElVarSearcher(project, fCompletionEngine);
+		fDocumentsInEditors= evalNonFileBufferDocuments();
+		boolean res= true;
+		for (int i = 0; files != null && i < files.length; i++) {
+            res= processSeamReferencesInFile(files[i]);
+            if (!res)
+            	break;
+			
+		}
+		fDocumentsInEditors= null;
+		fELVarSearcher = null;
+		return res;
+	}
+
+	private boolean processSeamReferencesInFile(IFile file) {
+		try {
+		    if (!fCollector.acceptFile(file) || fMatchers == null) {
+		       return true;
+		    }
+		        
+			IDocument document= getOpenDocument(file);
+			
+			if (document != null) {
+				DocumentCharSequence documentCharSequence= new DocumentCharSequence(document);
+				// assume all documents are non-binary
+				locateMatches(file, documentCharSequence);
+			} else {
+				CharSequence seq= null;
+				try {
+					seq= fFileCharSequenceProvider.newCharSequence(file);
+					if (hasBinaryContent(seq, file) && !fCollector.reportBinaryFile(file)) {
+						return true;
+					}
+					locateMatches(file, seq);
+				} catch (FileCharSequenceProvider.FileCharSequenceException e) {
+					e.throwWrappedException();
+				} finally {
+					if (seq != null) {
+						try {
+							fFileCharSequenceProvider.releaseCharSequence(seq);
+						} catch (IOException e) {
+							SearchPlugin.log(e);
+						}
+					}
+				}
+			}
+		} catch (UnsupportedCharsetException e) {
+			String[] args= { getCharSetName(file), file.getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_unsupportedcharset, args); 
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+		} catch (IllegalCharsetNameException e) {
+			String[] args= { getCharSetName(file), file.getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_illegalcharset, args);
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+		} catch (IOException e) {
+			String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_error, args); 
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+		} catch (CoreException e) {
+			String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_error, args); 
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+		} catch (StackOverflowError e) {
+			String message= SearchMessages.TextSearchVisitor_patterntoocomplex0;
+			fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
+			return false;
+		} finally {
+			fNumberOfScannedFiles++;
+		}
+		if (fProgressMonitor.isCanceled())
+			throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
+
+		return true;
+	}
+	
+	
+	private void locateMatches(IFile file, CharSequence searchInput) throws CoreException {
+		fELVarSearcher.setFile(file);
+		if("java".equalsIgnoreCase(file.getFileExtension())) { //$NON-NLS-1$
+			locateMatchesInJava(file, searchInput);
+		} else {
+			locateMatchesInDom(file, searchInput);
+		}
+	}
+
+	private List<Var> varListForCurentValidatedNode = new ArrayList<Var>();
+	private void locateMatchesInDom(IFile file, CharSequence content) {
+		varListForCurentValidatedNode.clear();
+		IModelManager manager = StructuredModelManager.getModelManager();
+		if(manager == null) {
+			// this can happen if plugin org.eclipse.wst.sse.core 
+			// is stopping or uninstalled, that is Eclipse is shutting down.
+			// there is no need to report it, just stop validation.
+			return;
+		}
+		IStructuredModel model = null;		
+		try {
+			model = manager.getModelForRead(file);
+			if (model instanceof IDOMModel) {
+				IDOMModel domModel = (IDOMModel) model;
+				IDOMDocument document = domModel.getDocument();
+				locateMatchesInChildNodes(file, document, content);
+			}
+		} catch (CoreException e) {
+			SeamCorePlugin.getDefault().logError(SeamCoreMessages.SEAM_EL_VALIDATOR_ERROR_VALIDATING_SEAM_EL, e);
+        } catch (IOException e) {
+        	SeamCorePlugin.getDefault().logError(SeamCoreMessages.SEAM_EL_VALIDATOR_ERROR_VALIDATING_SEAM_EL, e);
+		} finally {
+			if (model != null) {
+				model.releaseFromRead();
+			}
+		}
+		return;
+	}
+
+	private void locateMatchesInChildNodes(IFile file, Node parent, CharSequence content) 
+			throws CoreException {
+		Var var = ElVarSearcher.findVar(parent);
+		if(var!=null) {
+			varListForCurentValidatedNode.add(var);
+		}
+		NodeList children = parent.getChildNodes();
+		for(int i=0; i<children.getLength(); i++) {
+			Node curentValidatedNode = children.item(i);
+			if(Node.ELEMENT_NODE == curentValidatedNode.getNodeType()) {
+				locateMatchesInNodeContent(file, ((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(), DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, content);
+			} else if(Node.TEXT_NODE == curentValidatedNode.getNodeType()) {
+				locateMatchesInNodeContent(file, ((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(), DOMRegionContext.XML_CONTENT, content);
+			}
+			locateMatchesInChildNodes(file, curentValidatedNode, content);
+		}
+		if(var!=null) {
+			varListForCurentValidatedNode.remove(var);
+		}
+	}
+
+	private void locateMatchesInNodeContent(IFile file, IStructuredDocumentRegion node, 
+			String regionType, CharSequence content) throws CoreException {
+		ITextRegionList regions = node.getRegions();
+		for(int i=0; i<regions.size(); i++) {
+			ITextRegion region = regions.get(i);
+			if(region.getType() == regionType) {
+				String text = node.getFullText(region);
+				if(text.indexOf("{")>-1) { //$NON-NLS-1$
+					int offset = node.getStartOffset() + region.getStart();
+					locateMatchesInString(file, text, offset, content);
+				}
+			}
+		}
+	}
+	
+	private void locateMatchesInJava(IFile file, CharSequence content) throws CoreException {
+		try {
+			FastJavaPartitionScanner scaner = new FastJavaPartitionScanner();
+			Document document = new Document(content.subSequence(0, content.length()).toString());
+			scaner.setRange(document, 0, document.getLength());
+			IToken token = scaner.nextToken();
+			while(token!=null && token!=Token.EOF) {
+				if(IJavaPartitions.JAVA_STRING.equals(token.getData())) {
+					int length = scaner.getTokenLength();
+					int offset = scaner.getTokenOffset();
+					String value = document.get(offset, length);
+					if(value.indexOf('{')>-1) {
+						locateMatchesInString(file, value, offset, content);
+					} else if (false) {
+						// TODO: Insert here the check for named Seam annotations 
+						
+					} else if (true) {
+						
+					}
+				}
+				token = scaner.nextToken();
+			}
+		} catch (BadLocationException e) {
+			SeamGuiPlugin.getDefault().logError(e);
+		}
+	}
+
+	/**
+	 * @param offset - offset of string in file
+	 * @param length - length of string in file
+	 */
+	private void locateMatchesInString(IFile file, String string, int offset, CharSequence content) throws CoreException {
+		int startEl = string.indexOf("#{"); //$NON-NLS-1$
+		if(startEl>-1) {
+			SeamELStringTokenizer st = new SeamELStringTokenizer(string);
+			List<ELStringToken> tokens = st.getTokens();
+			for (ELStringToken stringToken : tokens) {
+				stringToken.setStart(offset + stringToken.getStart() + 2);
+				locateMatchesInEL(file, stringToken, content);
+			}
+		}
+	}
+
+	private void locateMatchesInEL(IFile file, ELStringToken el, CharSequence content) throws CoreException {
+		String exp = el.getBody();
+		SeamELTokenizer elTokenizer = new SeamELTokenizer(exp);
+		List<ELToken> tokens = elTokenizer.getTokens();
+		for (ELToken token : tokens) {
+			if(token.getType()==ELToken.EL_VARIABLE_TOKEN) {
+//				validateElOperand(file, token, el.getStart());
+				String operand = token.getText();
+				String varName = operand;
+				int offsetOfToken = el.getStart() + token.getStart();
+				SeamELOperandTokenizerForward forwardTokenizer = new SeamELOperandTokenizerForward(operand, 0);
+				List<ELOperandToken>operandTokens = forwardTokenizer.getTokens();
+				List<List<ELOperandToken>> variations = SeamELCompletionEngine.getPossibleVarsFromPrefix(operandTokens);
+
+				for (List<ELOperandToken> variation : variations) {
+					int start = variation.get(0).getStart();
+					int end = variation.get(variation.size() - 1).getStart() + 
+									variation.get(variation.size() - 1).getLength();
+					String variationText = operand.substring(start, end);
+					
+					if (!matches(variationText)) 
+						continue;
+
+					int offsetOfOperandToken = offsetOfToken + start;
+					int lengthOfOperandToken = end - start;
+					fMatchAccess.initialize(file, offsetOfOperandToken, lengthOfOperandToken, content);
+					boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+					if (!res) {
+						return; // no further reporting requested
+					}
+					
+					System.out.println("");
+				}
+			}
+		}
+	}
+
+	
+	
+	public boolean processSeamDeclarationsInProject(ISeamProject project) {
+		try {
+			Set<ISeamContextVariable> variables = project.getVariables(true);
+			Set<String> namesToExclude = new HashSet<String>();
+			boolean continueSearch = true; // Is to be set to false in case of at least one component or role/out/databinder declaration is found
+			
+			// Search for Seam components and @Name, @Role, @Out/DataBinder  
+			for (ISeamContextVariable variable : variables) {
+				String varName = variable.getName();
+				ISeamContextVariable origin = variable;
+				
+				if (!matches(varName)) 
+					continue;
+
+				if (variable instanceof ISeamContextShortVariable) {
+					variable = ((ISeamContextShortVariable)variable).getOriginal();
+				}
+				
+				if (variable instanceof SeamComponent) {
+					namesToExclude.add(varName);
+					SeamComponent comp = (SeamComponent)variable;
+					Set<ISeamComponentDeclaration> declarations = comp.getAllDeclarations();
+					for (ISeamComponentDeclaration decl : declarations) {
+						if (decl instanceof ISeamJavaSourceReference) {
+							ISeamJavaSourceReference sourceRef = (ISeamJavaSourceReference)decl;
+							IResource resource = sourceRef.getSourceMember().getResource();
+							IJavaElement sourceMember = sourceRef.getSourceMember();
+							String name = sourceRef.getSourceMember().getElementName();
+							int offset = sourceRef.getStartPosition();
+							int length = sourceRef.getLength();
+							//fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+							boolean res= fCollector.acceptSeamDeclarationSourceReferenceMatch(sourceRef);
+							if (!res) {
+								return true; // no further reporting requested
+							}
+							continueSearch = false;
+						} else if (decl instanceof IOpenableElement) {
+							IResource resource = decl.getResource();
+							String name = decl.getName();
+							
+							ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+							int offset = textSourceReference == null ? decl.getStartPosition() : textSourceReference.getStartPosition();
+							int length = textSourceReference == null ? decl.getLength() : textSourceReference.getLength();
+
+							fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+							boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+							if (!res) {
+								return true; // no further reporting requested
+							}
+							continueSearch = false;
+						}
+					}
+				} else if (variable instanceof IRole) {
+					namesToExclude.add(varName);
+					// add the declaration
+					ISeamDeclaration decl = (ISeamDeclaration)variable;
+					IResource resource = decl.getResource();
+					String name = decl.getName();
+					
+					ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+					if (textSourceReference != null) {
+						int offset = textSourceReference.getStartPosition();
+						int length = textSourceReference.getLength();
+						fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+						boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+						if (!res) {
+							return true; // no further reporting requested
+						}
+						continueSearch = false;
+					}					
+					
+				} else if (variable instanceof IBijectedAttribute) {
+					namesToExclude.add(varName);
+					IBijectedAttribute ba = (IBijectedAttribute)variable;
+					BijectedAttributeType[] types = ba.getTypes();
+					boolean hasDeclarationType = false;
+					for (int i = 0; !hasDeclarationType && types != null && i < types.length; i++) {
+						if (types[i] == BijectedAttributeType.OUT ||
+								types[i] == BijectedAttributeType.DATA_BINDER ||
+								types[i] == BijectedAttributeType.DATA_MODEL_SELECTION) {
+							hasDeclarationType = true;
+						}
+					}
+					if (hasDeclarationType) {
+						// add the declaration
+						ISeamDeclaration decl = (ISeamDeclaration)variable;
+						IResource resource = decl.getResource();
+						String name = decl.getName();
+						
+						ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+						if (textSourceReference != null) {
+							int offset = textSourceReference.getStartPosition();
+							int length = textSourceReference.getLength();
+
+							fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+							boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+							if (!res) {
+								return true; // no further reporting requested
+							}
+							continueSearch = false;
+						}					
+					}
+				}
+			}
+			if (continueSearch) {
+				// Search for Seam factories 
+				for (ISeamContextVariable variable : variables) {
+					String varName = variable.getName();
+					if (namesToExclude.contains(varName)) // Do not process used names
+						continue;
+					if (!matches(varName)) 
+						continue;
+	
+					if (variable instanceof ISeamDeclaration) {
+						ISeamDeclaration decl = (ISeamDeclaration)variable;
+						IResource resource = decl.getResource();
+						String name = decl.getName();
+						
+						ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+						if (textSourceReference != null) {
+							int offset = textSourceReference.getStartPosition();
+							int length = textSourceReference.getLength();
+	
+							boolean res= fCollector.acceptSeamDeclarationMatch(decl);
+							if (!res) {
+								return true; // no further reporting requested
+							}
+						}					
+					}
+				}
+			}
+		} catch (CoreException ce) {
+			String[] args= { getExceptionMessage(ce), project.getResource().getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_error, args); 
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, ce));
+		}
+		if (fProgressMonitor.isCanceled())
+			throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
+		
+		return true;
+/*		
+		IFile file = null; // was a parameter
+		try {
+		    if (!fCollector.acceptFile(file) || fMatcher == null) {
+		       return true;
+		    }
+		        
+			IDocument document= getOpenDocument(file);
+			
+			if (document != null) {
+				DocumentCharSequence documentCharSequence= new DocumentCharSequence(document);
+				// assume all documents are non-binary
+				locateMatches(file, documentCharSequence);
+			} else {
+				CharSequence seq= null;
+				try {
+					seq= fFileCharSequenceProvider.newCharSequence(file);
+					if (hasBinaryContent(seq, file) && !fCollector.reportBinaryFile(file)) {
+						return true;
+					}
+					locateMatches(file, seq);
+				} catch (FileCharSequenceProvider.FileCharSequenceException e) {
+					e.throwWrappedException();
+				} finally {
+					if (seq != null) {
+						try {
+							fFileCharSequenceProvider.releaseCharSequence(seq);
+						} catch (IOException e) {
+							SearchPlugin.log(e);
+						}
+					}
+				}
+			}
+		} catch (UnsupportedCharsetException e) {
+			String[] args= { getCharSetName(file), file.getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_unsupportedcharset, args); 
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+		} catch (IOException e) {
+			String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_error, args); 
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+		} catch (CoreException e) {
+			String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+			String message= Messages.format(SearchMessages.TextSearchVisitor_error, args); 
+			fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+		} catch (StackOverflowError e) {
+			String message= SearchMessages.TextSearchVisitor_patterntoocomplex0;
+			fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
+			return false;
+		} finally {
+			fNumberOfScannedFiles++;
+		}
+		if (fProgressMonitor.isCanceled())
+			throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
+		
+		return true;
+	*/
+	}
+
+	private class MonitorUpdateJob extends Job {
+    	private int fLastNumberOfScannedFiles= 0;
+    	
+    	MonitorUpdateJob() {
+    		super(SearchMessages.TextSearchVisitor_progress_updating_job);
+		}
+    	
+    	public IStatus run(IProgressMonitor inner) {
+    		while (!inner.isCanceled()) {
+				ISeamProject seamProject= fCurrentSeamProject;
+				if (seamProject != null) {
+					String seamProjectName= seamProject.getProject().getName();
+					Object[] args= { seamProjectName, new Integer(fNumberOfScannedFiles), new Integer(fNumberOfFilesToScan)};
+					fProgressMonitor.subTask(Messages.format(SeamUIMessages.SeamSearchVisitor_scanning, args));
+					int steps= fNumberOfScannedFiles - fLastNumberOfScannedFiles;
+					fProgressMonitor.worked(steps);
+					fLastNumberOfScannedFiles += steps;
+				}
+				try {
+					Thread.sleep(100);
+				} catch (InterruptedException e) {
+					return Status.OK_STATUS;
+				}
+			}
+			return Status.OK_STATUS;
+    	}
+	}
+	
+	private String getTaskName() {
+    	String taskName= fMatchers[0] == null ? SearchMessages.TextSearchVisitor_filesearch_task_label :  Messages.format(SearchMessages.TextSearchVisitor_textsearch_task_label, fMatchers[0].pattern());
+    	
+    	return taskName;
+	}
+	
+	public IStatus searchForReferences(ISeamProject[] projects, IProgressMonitor monitor) {
+		fProgressMonitor= monitor == null ? new NullProgressMonitor() : monitor;
+        fNumberOfScannedFiles= 0;
+        fNumberOfFilesToScan= projects.length;
+        fCurrentSeamProject= null;
+        
+        Job monitorUpdateJob= new MonitorUpdateJob();
+
+        try {
+            fProgressMonitor.beginTask(getTaskName(), fNumberOfFilesToScan);
+            monitorUpdateJob.setSystem(true);
+            monitorUpdateJob.schedule();
+            try {
+	            fCollector.beginReporting();
+	            processSeamProjects(projects, false);
+	            return fStatus;
+            } finally {
+                monitorUpdateJob.cancel();
+            }
+        } finally {
+            fProgressMonitor.done();
+            fCollector.endReporting();
+        }
+	}
+	
+	
+	
+	private boolean matches(CharSequence searchInput) {
+		try {
+			for (int i = 0; fMatchers != null && i < fMatchers.length; i++) {
+				if (fMatchers[i] == null)
+					continue;
+				fMatchers[i].reset(searchInput);
+				if (fMatchers[i].find() && fMatchers[i].group().equals(searchInput)) {
+					return true;
+				}
+			}
+		} finally {
+//			fMatcher.reset();
+		}
+		return false;
+	}
+	
+	private String getExceptionMessage(Exception e) {
+		String message= e.getLocalizedMessage();
+		if (message == null) {
+			return e.getClass().getName();
+		}
+		return message;
+	}
+
+	private boolean hasBinaryContent(CharSequence seq, IFile file) throws CoreException {
+		IContentDescription desc= file.getContentDescription();
+		if (desc != null) {
+			IContentType contentType= desc.getContentType();
+			if (contentType != null && contentType.isKindOf(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT))) {
+				return false;
+			}
+		}
+		
+		// avoid calling seq.length() at it runs through the complete file,
+		// thus it would do so for all binary files.
+		try {
+			int limit= FileCharSequenceProvider.BUFFER_SIZE;
+			for (int i= 0; i < limit; i++) {
+				if (seq.charAt(i) == '\0') {
+					return true;
+				}
+			}
+		} catch (IndexOutOfBoundsException e) {
+		}
+		return false;
+	}
+
+	/**
+	 * @return returns a map from IFile to IDocument for all open, dirty editors
+	 */
+	private Map evalNonFileBufferDocuments() {
+		Map result= new HashMap();
+		IWorkbench workbench= SearchPlugin.getDefault().getWorkbench();
+		IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
+		for (int i= 0; i < windows.length; i++) {
+			IWorkbenchPage[] pages= windows[i].getPages();
+			for (int x= 0; x < pages.length; x++) {
+				IEditorReference[] editorRefs= pages[x].getEditorReferences();
+				for (int z= 0; z < editorRefs.length; z++) {
+					IEditorPart ep= editorRefs[z].getEditor(false);
+					if (ep instanceof ITextEditor && ep.isDirty()) { // only dirty editors
+						evaluateTextEditor(result, ep);
+					}
+				}
+			}
+		}
+		return result;
+	}
+
+	private void evaluateTextEditor(Map result, IEditorPart ep) {
+		IEditorInput input= ep.getEditorInput();
+		if (input instanceof IFileEditorInput) {
+			IFile file= ((IFileEditorInput) input).getFile();
+			if (!result.containsKey(file)) { // take the first editor found
+				ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
+				ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
+				if (textFileBuffer != null) {
+					// file buffer has precedence
+					result.put(file, textFileBuffer.getDocument());
+				} else {
+					// use document provider
+					IDocument document= ((ITextEditor) ep).getDocumentProvider().getDocument(input);
+					if (document != null) {
+						result.put(file, document);
+					}
+				}
+			}
+		}
+	}
+
+	private IDocument getOpenDocument(IFile file) {
+		IDocument document= (IDocument) fDocumentsInEditors.get(file);
+		if (document == null) {
+			ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
+			ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
+			if (textFileBuffer != null) {
+				document= textFileBuffer.getDocument();
+			}
+		}
+		return document;
+	}
+	
+	private String getCharSetName(IFile file) {
+		try {
+			return file.getCharset();
+		} catch (CoreException e) {
+			return "unknown"; //$NON-NLS-1$
+		}
+	}
+
+	/**
+	 * Evaluates all files in this scope.
+	 * 
+	 * @param status a {@link MultiStatus} to collect the error status that occurred while collecting resources.
+	 * @return returns the files in the scope.
+	 */
+	public IFile[] evaluateProjectFilesInScope(IProject project, MultiStatus status) {
+		return new ProjectFilesOfScopeCalculator(project, fCurrentScope, status).process();
+	}
+
+	class ProjectFilesOfScopeCalculator implements IResourceProxyVisitor {
+		private final IProject fProject;
+		private final TextSearchScope fScope;
+		private final MultiStatus fStatus;
+		private ArrayList fFiles;
+
+		public ProjectFilesOfScopeCalculator(IProject project, SeamSearchScope scope, MultiStatus status) {
+			fProject = project;
+			fScope = scope;
+			fStatus= status;
+		}
+		
+		public boolean visit(IResourceProxy proxy) {
+			if (fScope == null)
+				return false;
+			boolean inScope= fScope.contains(proxy);
+
+			if (inScope && proxy.getType() == IResource.FILE && 
+					fProject == proxy.requestResource().getProject()) {
+				fFiles.add(proxy.requestResource());
+			}
+			return inScope;
+		}
+		
+		public IFile[] process() {
+			fFiles= new ArrayList();
+			try {
+				IResource[] roots= fScope.getRoots();
+				for (int i= 0; i < roots.length; i++) {
+					try {
+						IResource resource= roots[i];
+						if (resource.isAccessible()) {
+							resource.accept(this, 0);
+						}
+					} catch (CoreException ex) {
+						// report and ignore
+						fStatus.add(ex.getStatus());
+					}
+				}
+				return (IFile[]) fFiles.toArray(new IFile[fFiles.size()]);
+			} finally {
+				fFiles= null;
+			}
+		}
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,72 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.search.internal.ui.text.IFileSearchContentProvider;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+
+public class SeamTableContentProvider implements IStructuredContentProvider, IFileSearchContentProvider {
+	
+	private final Object[] EMPTY_ARR= new Object[0];
+	
+	private SeamSearchResultPage fPage;
+	private AbstractTextSearchResult fResult;
+
+	public SeamTableContentProvider(SeamSearchResultPage page) {
+		fPage= page;
+	}
+	
+	public void dispose() {
+		// nothing to do
+	}
+	
+	public Object[] getElements(Object inputElement) {
+		if (inputElement instanceof SeamSearchResult) {
+			int elementLimit= getElementLimit();
+			Object[] elements= ((SeamSearchResult)inputElement).getElements();
+			if (elementLimit != -1 && elements.length > elementLimit) {
+				Object[] shownElements= new Object[elementLimit];
+				System.arraycopy(elements, 0, shownElements, 0, elementLimit);
+				return shownElements;
+			}
+			return elements;
+		}
+		return EMPTY_ARR;
+	}
+	
+	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+		if (newInput instanceof SeamSearchResult) {
+			fResult= (SeamSearchResult) newInput;
+		}
+	}
+	
+	public void elementsChanged(Object[] updatedElements) {
+		TableViewer viewer= getViewer();
+		int elementLimit= getElementLimit();
+		boolean tableLimited= elementLimit != -1;
+		for (int i= 0; i < updatedElements.length; i++) {
+			if (fResult.getMatchCount(updatedElements[i]) > 0) {
+				if (viewer.testFindItem(updatedElements[i]) != null)
+					viewer.update(updatedElements[i], null);
+				else {
+					if (!tableLimited || viewer.getTable().getItemCount() < elementLimit)
+						viewer.add(updatedElements[i]);
+				}
+			} else
+				viewer.remove(updatedElements[i]);
+		}
+	}
+
+	private int getElementLimit() {
+		return fPage.getElementLimit().intValue();
+	}
+
+	private TableViewer getViewer() {
+		return (TableViewer) fPage.getViewer();
+	}
+	
+	public void clear() {
+		getViewer().refresh();
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,187 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.search.internal.ui.text.IFileSearchContentProvider;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.jboss.tools.seam.core.IRole;
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamPackage;
+import org.jboss.tools.seam.core.ISeamScope;
+
+public class SeamTreeContentProvider implements ITreeContentProvider, IFileSearchContentProvider {
+
+	private final Object[] EMPTY_ARR= new Object[0];
+
+	private AbstractTextSearchResult fResult;
+	private SeamSearchResultPage fPage;
+	private AbstractTreeViewer fTreeViewer;
+	private Map fChildrenMap;
+	
+	SeamTreeContentProvider(SeamSearchResultPage page, AbstractTreeViewer viewer) {
+		fPage= page;
+		fTreeViewer= viewer;
+	}
+	
+	public Object[] getElements(Object inputElement) {
+		Object[] children= getChildren(inputElement);
+		int elementLimit= getElementLimit();
+		if (elementLimit != -1 && elementLimit < children.length) {
+			Object[] limitedChildren= new Object[elementLimit];
+			System.arraycopy(children, 0, limitedChildren, 0, elementLimit);
+			return limitedChildren;
+		}
+		return children;
+	}
+	
+	private int getElementLimit() {
+		return fPage.getElementLimit().intValue();
+	}
+	
+	public void dispose() {
+		// nothing to do
+	}
+	
+	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+		if (newInput instanceof SeamSearchResult) {
+			initialize((SeamSearchResult) newInput);
+		}
+	}
+	
+
+	protected synchronized void initialize(AbstractTextSearchResult result) {
+		fResult= result;
+		fChildrenMap= new HashMap();
+		if (result != null) {
+			Object[] elements= result.getElements();
+			for (int i= 0; i < elements.length; i++) {
+				insert(elements[i],  false);
+			}
+		}
+	}
+
+	protected void insert(Object child, boolean refreshViewer) {
+
+		Object parent= getParent(child);
+		while (parent != null) {
+			if (insertChild(parent, child)) {
+				if (refreshViewer)
+					fTreeViewer.add(parent, child);
+			} else {
+				if (refreshViewer)
+					fTreeViewer.refresh(parent);
+				return;
+			}
+			child= parent;
+			parent= getParent(child);
+		}
+		if (insertChild(fResult, child)) {
+			if (refreshViewer)
+				fTreeViewer.add(fResult, child);
+		}
+	}
+
+	/**
+	 * returns true if the child already was a child of parent.
+	 * 
+	 * @param parent
+	 * @param child
+	 * @return Returns <code>trye</code> if the child was added
+	 */
+	private boolean insertChild(Object parent, Object child) {
+		Set children= (Set) fChildrenMap.get(parent);
+		if (children == null) {
+			children= new HashSet();
+			fChildrenMap.put(parent, children);
+		}
+		return children.add(child);
+	}
+
+	protected void remove(Object element, boolean refreshViewer) {
+		// precondition here:  fResult.getMatchCount(child) <= 0
+	
+		if (hasChildren(element)) {
+			if (refreshViewer)
+				fTreeViewer.refresh(element);
+		} else {
+			if (fResult.getMatchCount(element) == 0) {
+				fChildrenMap.remove(element);
+				Object parent= getParent(element);
+				if (parent != null) {
+					removeFromSiblings(element, parent);
+					remove(parent, refreshViewer);
+				} else {
+					removeFromSiblings(element, fResult);
+					if (refreshViewer)
+						fTreeViewer.refresh();
+				}
+			} else {
+				if (refreshViewer) {
+					fTreeViewer.refresh(element);
+				}
+			}
+		}
+	}
+
+	private void removeFromSiblings(Object element, Object parent) {
+		Set siblings= (Set) fChildrenMap.get(parent);
+		if (siblings != null) {
+			siblings.remove(element);
+		}
+	}
+
+	public Object[] getChildren(Object parentElement) {
+		Set children= (Set) fChildrenMap.get(parentElement);
+		if (children == null)
+			return EMPTY_ARR;
+		return children.toArray();
+	}
+
+	public boolean hasChildren(Object element) {
+		return getChildren(element).length > 0;
+	}
+
+	public synchronized void elementsChanged(Object[] updatedElements) {
+		for (int i= 0; i < updatedElements.length; i++) {
+			if (fResult.getMatchCount(updatedElements[i]) > 0)
+				insert(updatedElements[i], true);
+			else
+				remove(updatedElements[i], true);
+		}
+	}
+
+	public void clear() {
+		initialize(fResult);
+		fTreeViewer.refresh();
+	}
+
+	public Object getParent(Object element) {
+		if (element instanceof IProject)
+			return null;
+		if (element instanceof IResource) {
+			IResource resource = (IResource) element;
+			return resource.getParent();
+		}
+		if(element instanceof IRole) {
+			ISeamElement p = ((IRole)element).getParent();
+			return p == null ? p : p.getParent();
+		} else if(element instanceof ISeamElement) {
+			if(element instanceof ISeamComponent) {
+				ISeamComponent c = (ISeamComponent)element;
+				return c.getSeamProject().getPackage(c);
+			}
+			return ((ISeamElement)element).getParent();
+		}
+
+		return null;
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,357 @@
+/******************************************************************************* 
+ * Copyright (c) 2007 Red Hat, Inc. 
+ * Distributed under license by Red Hat, Inc. All rights reserved. 
+ * This program is made available under the terms of the 
+ * Eclipse Public License v1.0 which accompanies this distribution, 
+ * and is available at http://www.eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors: 
+ * Red Hat, Inc. - initial API and implementation 
+ ******************************************************************************/ 
+
+package org.jboss.tools.seam.ui.text.java;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.MemberValuePair;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.seam.core.IOpenableElement;
+import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamContextShortVariable;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamFactory;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.BijectedAttribute;
+import org.jboss.tools.seam.internal.core.Role;
+import org.jboss.tools.seam.internal.core.SeamComponent;
+import org.jboss.tools.seam.internal.core.SeamJavaContextVariable;
+import org.jboss.tools.seam.internal.core.scanner.ScannerException;
+import org.jboss.tools.seam.internal.core.scanner.java.AnnotatedASTNode;
+import org.jboss.tools.seam.internal.core.scanner.java.ResolvedAnnotation;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.text.java.scanner.JavaAnnotationScanner;
+
+/**
+ * @author Jeremy
+ */
+public class JavaStringHyperlinkDetector extends AbstractHyperlinkDetector {
+
+	/*
+	 * If the hyperlink is performed from the @Factory annotation value 
+	 * the declaration of the variable will be openned in the editor
+	 * 
+	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
+	 */
+	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
+		ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
+		if (region == null || canShowMultipleHyperlinks || !(textEditor instanceof JavaEditor))
+			return null;
+
+		int offset= region.getOffset();
+
+		IJavaElement input= EditorUtility.getEditorInputJavaElement(textEditor, false);
+		if (input == null)
+			return null;
+
+		if (input.getResource() == null || input.getResource().getProject() == null)
+			return null;
+
+		ISeamProject seamProject = SeamCorePlugin.getSeamProject(input.getResource().getProject(), true);
+		
+		IDocument document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+		IRegion wordRegion= JavaWordFinder.findWord(document, offset);
+		if (wordRegion == null)
+			return null;
+				
+		JavaAnnotationScanner annotationScanner = new JavaAnnotationScanner();
+		Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> loadedAnnotations = null;
+		IType loadedType = null;
+		
+		try {
+			annotationScanner.parse((ICompilationUnit)input);
+			loadedAnnotations = annotationScanner.getResolvedAnnotations();
+			loadedType = annotationScanner.getResolvedType();
+			
+		} catch (ScannerException e) {
+			SeamGuiPlugin.getPluginLog().logError(e);
+			return null;
+		}
+		
+		ResolvedAnnotation a = findAnnotationByValueOffset(loadedAnnotations, offset);
+		if (!isAnnotationOfType(a, SeamAnnotations.FACTORY_ANNOTATION_TYPE))
+			return null;
+
+		String value = getAnnotationValue(a);
+
+		// Look at the annotated method:
+		// If its return type is not void - the Declaration is the factory itself
+		// If its return type is void - search for the declarations
+		AnnotatedASTNode<ASTNode> node = loadedAnnotations.get(a);
+		if (!(node.getNode() instanceof MethodDeclaration))
+			return null;
+		
+		MethodDeclaration mDecl = (MethodDeclaration)node.getNode();
+		IMember member = findMethod(loadedType, mDecl);
+		IMethod method = (member instanceof IMethod ? (IMethod)member : null);
+		if (method == null)
+			return null;
+		
+		String returnType = null;
+		try {
+			returnType = method.getReturnType();
+		} catch (JavaModelException e) {
+			SeamGuiPlugin.getPluginLog().logError(e);
+			return null;
+		}
+
+		if ("V".equals(returnType)) {
+			// search for the declaration of the variable 
+			Set<ISeamContextVariable> variables = seamProject.getVariablesByName(value);
+			if (variables != null && !variables.isEmpty()) {
+				for (ISeamContextVariable var : variables) {
+					if (var instanceof ISeamContextShortVariable) {
+						// Extract the original variable 
+						var = ((ISeamContextShortVariable)var).getOriginal();
+					}
+					
+					if (var instanceof SeamComponent) {
+						SeamComponent comp = (SeamComponent)var;
+						Set<ISeamComponentDeclaration> declarations = comp.getAllDeclarations();
+						for (ISeamComponentDeclaration decl : declarations) {
+							if (decl instanceof IOpenableElement)
+							   return new IHyperlink[] {new SeamOpenableElementHyperlink(wordRegion, (IOpenableElement)decl)};
+					   }
+					}
+					if (var instanceof BijectedAttribute || 
+							var instanceof Role) {
+						return new IHyperlink[] {new JavaMemberHyperlink(wordRegion, ((SeamJavaContextVariable)var).getSourceMember())};
+					}
+				}
+			}
+			return null;
+		} 
+		
+		// open the factory method itself as the declaration
+		return new IHyperlink[] {new JavaMemberHyperlink(wordRegion, method)};
+	}
+
+	/*
+	 * Finds the IMethod in IType by its MethodDeclaration
+	 * 
+	 * @param type 
+	 * @param m
+	 * 
+	 * @return IMethod found
+	 */
+	public IMethod findMethod(IType type, MethodDeclaration m) {
+		if(m == null || m.getName() == null) return null;
+		IMethod[] ms = null;
+		try {
+			ms = type.getMethods();
+		} catch (JavaModelException e) {
+			//ignore
+		}
+		String name = m.getName().getIdentifier();
+		if(ms != null) for (int i = 0; i < ms.length; i++) {
+			if(!name.equals(ms[i].getElementName())) continue;
+			int s = m.getStartPosition() + m.getLength() / 2;
+			try {
+				ISourceRange range = ms[i].getSourceRange();
+				if(range == null) {
+					//no source and we cannot check position.
+					return ms[i];
+				}
+				int b = range.getOffset();
+				int e = b + range.getLength();
+				if(s >= b && s <= e) return ms[i];
+			} catch (JavaModelException e) {
+				return ms[i];
+			}
+		}
+		return null;
+	}
+
+	/*
+	 * Detects if the type of annotation equals to the selected SeamAnnotations' type
+	 * 
+	 * @param annotation
+	 * @param typeName
+	 * 
+	 * @return 
+	 */
+	private boolean isAnnotationOfType(ResolvedAnnotation annotation, String typeName) {
+		if (annotation == null || typeName == null)
+			return false;
+		
+		return (typeName.equals(annotation.getType()));
+	}
+	
+	/*
+	 * Returns the annotation's value text
+	 * 
+	 * @param annotation
+	 * @return
+	 */
+	private String getAnnotationValue(ResolvedAnnotation annotation) {
+		if (annotation.getAnnotation() instanceof SingleMemberAnnotation) {
+			SingleMemberAnnotation sma = (SingleMemberAnnotation)annotation.getAnnotation();
+			Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
+			if (vpd instanceof StringLiteral) {
+				return ((StringLiteral)vpd).getLiteralValue();
+			} 
+			return vpd.toString();
+		} else if (annotation.getAnnotation() instanceof NormalAnnotation) {
+			NormalAnnotation na = (NormalAnnotation)annotation.getAnnotation();
+			Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
+			if (vpd instanceof List) {
+				for (Object item : (List)vpd) {
+					if (item instanceof ASTNode) {
+						ASTNode node = (ASTNode)item;
+						if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR) 
+							continue;
+						MemberValuePair mvp = (MemberValuePair)node;
+						SimpleName name = mvp.getName();
+						if (!"value".equals(name.getIdentifier())) {
+							continue;
+						}
+						return ((StringLiteral)mvp.getValue()).getLiteralValue();
+					}
+				}
+			}
+		}
+		
+		return null;
+	}
+	
+	private ResolvedAnnotation findAnnotationByValueOffset(Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> annotations, int offset) {
+		if (annotations == null)
+			return null;
+
+		for (ResolvedAnnotation a : annotations.keySet()) {
+			if (a.getAnnotation() instanceof SingleMemberAnnotation) {
+				SingleMemberAnnotation sma = (SingleMemberAnnotation)a.getAnnotation();
+				Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
+				if (vpd instanceof ASTNode) {
+					ASTNode node = (ASTNode)vpd;
+					int start = node.getStartPosition();
+					int length = node.getLength();
+					if (offset >= start && offset < start + length) {
+						return a;
+					}
+				}
+			} else if (a.getAnnotation() instanceof NormalAnnotation) {
+				NormalAnnotation na = (NormalAnnotation)a.getAnnotation();
+				Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
+				if (vpd instanceof List) {
+					for (Object item : (List)vpd) {
+						if (item instanceof ASTNode) {
+							ASTNode node = (ASTNode)item;
+							if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR) 
+								continue;
+							MemberValuePair mvp = (MemberValuePair)node;
+							SimpleName name = mvp.getName();
+							if (!"value".equals(name.getIdentifier())) {
+								continue;
+							}
+							int start = node.getStartPosition();
+							int length = node.getLength();
+							if (offset >= start && offset < start + length) {
+								return a;
+							}
+						}
+					}
+				}
+			}
+		}
+		return null;
+	}
+	
+	
+	class JavaMemberHyperlink implements IHyperlink {
+
+		private final IRegion fRegion;
+		private final IMember fMember;
+		
+		IMember member;
+		public JavaMemberHyperlink(IRegion region, IMember member) {
+			this.fRegion = region;
+			this.fMember = member;
+		}
+
+		public IRegion getHyperlinkRegion() {
+			return fRegion;
+		}
+		public String getHyperlinkText() {
+			return null;
+		}
+		public String getTypeLabel() {
+			return null;
+		}
+
+		public void open() {
+			try {
+				IEditorPart part = JavaUI.openInEditor(fMember);
+				if (part != null) {
+					JavaUI.revealInEditor(part, (IJavaElement)fMember);
+				}
+			} catch (PartInitException e) {
+//				SeamExtPlugin.getPluginLog().logError(e);  
+			} catch (JavaModelException e) {
+				// Ignore. It is probably because of Java element is not found 
+			}
+		}
+	}
+	
+	class SeamOpenableElementHyperlink implements IHyperlink {
+		private final IRegion fRegion;
+		private final IOpenableElement fOpenable;
+		
+		IMember member;
+		public SeamOpenableElementHyperlink(IRegion region, IOpenableElement openable) {
+			this.fRegion = region;
+			this.fOpenable = openable;
+		}
+
+		public IRegion getHyperlinkRegion() {
+			return fRegion;
+		}
+		public String getHyperlinkText() {
+			return null;
+		}
+		public String getTypeLabel() {
+			return null;
+		}
+
+		public void open() {
+			fOpenable.open();
+		}
+	}
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java	                        (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java	2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,244 @@
+package org.jboss.tools.seam.ui.text.java.scanner;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ASTRequestor;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.seam.core.SeamCoreMessages;
+import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
+import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
+import org.jboss.tools.seam.internal.core.scanner.ScannerException;
+import org.jboss.tools.seam.internal.core.scanner.Util;
+import org.jboss.tools.seam.internal.core.scanner.java.ASTVisitorImpl;
+import org.jboss.tools.seam.internal.core.scanner.java.AnnotatedASTNode;
+import org.jboss.tools.seam.internal.core.scanner.java.ComponentBuilder;
+import org.jboss.tools.seam.internal.core.scanner.java.JavaScanner;
+import org.jboss.tools.seam.internal.core.scanner.java.ResolvedAnnotation;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
+
+public class JavaAnnotationScanner {
+	
+	public JavaAnnotationScanner() {}
+
+	/**
+	 * Returns component or list of component
+	 * TODO change return type
+	 * @param f
+	 * @return
+	 * @throws ScannerException
+	 */
+/*	public LoadedDeclarations parse(IFile f) throws ScannerException {
+		ICompilationUnit u = null;
+		try {
+			u = getCompilationUnit(f);
+		} catch (CoreException e) {
+			throw new ScannerException(
+					NLS.bind(SeamCoreMessages.JAVA_SCANNER_CANNOT_GET_COMPILATION_UNIT_FOR,f), e);
+		}
+		if(u == null) return null;
+		ASTRequestorImpl requestor = new ASTRequestorImpl(f);
+		ICompilationUnit[] us = new ICompilationUnit[]{u};
+		ASTParser p = ASTParser.newParser(AST.JLS3);
+		p.setSource(u);
+		p.setResolveBindings(true);
+		p.createASTs(us, new String[0], requestor, null);
+		return requestor.getDeclarations();
+	}
+*/
+	/**
+	 * Returns component or list of component
+	 * TODO change return type
+	 * @param u
+	 * @return
+	 * @throws ScannerException
+	 */
+	public void parse(ICompilationUnit u) throws ScannerException {
+		resolvedAnnotations = null;
+		resolvedType = null;
+		if(u == null) return;
+		ASTRequestorImpl requestor = new ASTRequestorImpl(u);
+		ICompilationUnit[] us = new ICompilationUnit[]{u};
+		ASTParser p = ASTParser.newParser(AST.JLS3);
+		p.setSource(u);
+		p.setResolveBindings(true);
+		p.createASTs(us, new String[0], requestor, null);
+		resolvedType = requestor.getType();
+		resolvedAnnotations = requestor.getAnnotations();
+	}
+
+	Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> resolvedAnnotations = null;
+	IType resolvedType = null;
+	
+	public Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> getResolvedAnnotations() {
+		return resolvedAnnotations;
+	}
+
+	public IType getResolvedType() {
+		return resolvedType;
+	}
+	
+	
+	private ICompilationUnit getCompilationUnit(IFile f) throws CoreException {
+		IProject project = f.getProject();
+		IJavaProject javaProject = (IJavaProject)project.getNature(JavaCore.NATURE_ID);
+		IResource[] rs = EclipseResourceUtil.getJavaSourceRoots(project);
+		for (int i = 0; i < rs.length; i++) {
+			if(rs[i].getFullPath().isPrefixOf(f.getFullPath())) {
+				IPath path = f.getFullPath().removeFirstSegments(rs[i].getFullPath().segmentCount());
+				IJavaElement e = javaProject.findElement(path);
+				if(e instanceof ICompilationUnit) {
+					return (ICompilationUnit)e;
+				}
+			}
+		}
+		return null;
+	}
+
+
+	class ASTRequestorImpl extends ASTRequestor {
+		private ASTVisitorImpl visitor = new ASTVisitorImpl();
+//		LoadedDeclarations ds = new LoadedDeclarations();
+		List<ResolvedAnnotation> annotations = new ArrayList<ResolvedAnnotation>();
+		IResource resource;
+		IPath sourcePath;
+		ICompilationUnit unit;
+		
+		public ASTRequestorImpl(IResource resource) {
+			this.resource = resource;
+			this.sourcePath = resource.getFullPath();
+		}
+		public ASTRequestorImpl(ICompilationUnit unit) {
+			this.unit = unit;
+			this.resource = unit.getResource();
+			this.sourcePath = resource.getFullPath();
+		}
+
+//		public LoadedDeclarations getDeclarations() {
+//			return ds;
+//		}
+		
+		public Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> getAnnotations() {
+			return annotationMap;
+		}
+		
+		public IType getType() {
+			return type;
+		}
+		
+		public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
+			IType[] ts = null;
+			try {
+				ts = source.getTypes();
+			} catch (JavaModelException e) {
+				//ignore
+			}
+			if(ts == null || ts.length == 0) return;
+			for (int i = 0; i < ts.length; i++) {
+				visitor.setType(null);
+				int f = 0;
+				try {
+					f = ts[i].getFlags();
+				} catch (JavaModelException e) {
+					//ignore
+					continue;
+				}
+				if(Flags.isPublic(f)) {
+					visitor.setType(ts[i]);
+					ast.accept(visitor);
+					if(!visitor.hasSeamComponent()) continue;
+					processTypeData(visitor.root);
+				}
+			}
+		}
+		
+		IType type = null;
+		AnnotatedASTNode<TypeDeclaration> annotatedType = null;
+		Set<AnnotatedASTNode<FieldDeclaration>> annotatedFields = null;
+		Set<AnnotatedASTNode<MethodDeclaration>> annotatedMethods = null;
+		
+		Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> annotationMap = new HashMap<ResolvedAnnotation, AnnotatedASTNode<ASTNode>>();
+		
+		private void processTypeData(ASTVisitorImpl.TypeData data) {
+			type = data.type;
+			annotatedType = data.annotatedType;
+			annotatedFields = data.annotatedFields;
+			annotatedMethods = data.annotatedMethods;
+
+			ResolvedAnnotation[] annotations = annotatedType.getAnnotations();
+			for (int i = 0; annotations != null && i < annotations.length; i++) {
+				annotationMap.put(annotations[i], (AnnotatedASTNode)annotatedType);
+			}
+			
+			if (annotatedMethods != null) {
+				for (AnnotatedASTNode annotatedMethod : annotatedMethods) {
+					annotations = annotatedMethod.getAnnotations();
+					for (int i = 0; annotations != null && i < annotations.length; i++) {
+						annotationMap.put(annotations[i], (AnnotatedASTNode)annotatedMethod);
+					}
+				}
+			}
+
+			if (annotatedFields != null) {
+				for (AnnotatedASTNode annotatedField : annotatedFields) {
+					annotations = annotatedField.getAnnotations();
+					for (int i = 0; annotations != null && i < annotations.length; i++) {
+						annotationMap.put(annotations[i], (AnnotatedASTNode)annotatedField);
+					}
+				}
+			}
+//			this.annotations = annotations;
+		}
+	}
+	
+	static String getResolvedType(IType type, String n) {
+
+		String[][] rs;
+		try {
+			rs = type.resolveType(n);
+			if(rs != null && rs.length > 0) {
+				return (rs[0][0].length() == 0) ? rs[0][1] : rs[0][0] + "." + rs[0][1]; //$NON-NLS-1$
+			}
+		} catch (JavaModelException e) {
+			// ignore
+		}
+
+		return n;
+	}
+
+}


Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the jbosstools-commits mailing list