Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » strange behaviour of SearchUI ( search result view)
strange behaviour of SearchUI ( search result view) [message #190467] Fri, 06 February 2004 05:03 Go to next message
Eclipse UserFriend
Originally posted by: mirk.tonia.ch

I'm trying to integrate search support into my plugin.

i wrote a own search page and now i want to display the results in the search view.

i took a look at the help search page implementation to find out how this is done.

the search operation runs without an exception but the search result is not
displayed. only after i run a second search i can display the first search by
using the "previous search result" button in the search result view's toolbar.
after that the search result is diplayed corectly. but when i try to remove a search
result with the the "remove selected match" or "remove all matches" action of the search
result view, the match won't go away ( it is still displayed but trying to run the gotoaction
results in in a org.eclipse.core.internal.resources.ResourceException: Marker id: 1824 not found.)

below i posted my performAction method ( SearchPage implementation ) and
my implementation of the searchoperation ( BSPSearchOperation )

thanks for your help

ps im using
Version: 2.1.1
Build id: 200306271545
on linux ( gtk version )
i have not tryed on other platforms so far

my perform action looks like this

public boolean performAction() {
SearchUI.activateSearchResultView();

// get the runnableContext
IRunnableContext context= null;
context= getContainer().getRunnableContext();

if (context == null)
context= new ProgressMonitorDialog(getControl().getShell());


BSPSearchOperation op = new BSPSearchOperation(
new EOFetchSpecification( AntragSteller.ENTITY_NAME(), qualifierPart.getQualifier(), null),
PAGE_ID
);


try {
context.run(true, true, op);
} catch (InvocationTargetException ex) {
ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.search.title"),SearchMessages.getString( "Search.Error.search.message")); //$NON-NLS-2$ //$NON-NLS-1$
return false;
} catch (InterruptedException e) {
return false;
}
IStatus status= op.getStatus();
if (status != null && !status.isOK()) {
String title= SearchMessages.getString("Search.Problems.title"); //$NON-NLS-1$
ErrorDialog.openError(getShell(), title, null, status); //$NON-NLS-1$
}
return true;

}


// the search operation implementation class

package ch.oekoso.bsp;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.internal.resources.MarkerInfo;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.search.ui.IActionGroupFactory;
import org.eclipse.search.ui.IGroupByKeyComputer;
import org.eclipse.search.ui.ISearchResultView;
import org.eclipse.search.ui.ISearchResultViewEntry;
import org.eclipse.search.ui.SearchUI;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.WorkspaceModifyOperation;

import stuff.GlobalUtils;

import com.sun.corba.se.internal.CosNaming.NSORB;
import com.webobjects.eocontrol.EOEditingContext;
import com.webobjects.eocontrol.EOEnterpriseObject;
import com.webobjects.eocontrol.EOFetchSpecification;
import com.webobjects.eocontrol.EOGlobalID;
import com.webobjects.eocontrol.EOQualifier;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSDictionary;

/**
* @author mirko
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class BSPSearchOperation extends WorkspaceModifyOperation {
private EOFetchSpecification spec;
private String page_id;

private IAction goToAction;
private ILabelProvider labelProvider;
private IGroupByKeyComputer groupByKeyComputer;
private IActionGroupFactory actionGroupFactory;

// main constructor
public BSPSearchOperation( EOFetchSpecification spec, String page_id, ILabelProvider labelProvider, IAction goToAction, IGroupByKeyComputer computer, IActionGroupFactory factory ) {
this.spec = spec;
this.page_id = page_id;

createLabelProvider(labelProvider);
createGoToAction(goToAction);
createGroupByKeyComputer(computer);
createActionGroupFactory(factory);
}

// simple constructor
public BSPSearchOperation ( EOFetchSpecification spec, String page_id ) {
this(spec, page_id, null, null, null, null);
}

private void createLabelProvider (ILabelProvider provider) {
if ( provider != null ) {
labelProvider = provider;
return;
}

this.labelProvider = new LabelProvider() {
public String getText(Object element) {
try {
ISearchResultViewEntry entry =
(ISearchResultViewEntry) element;
return (String) entry.getSelectedMarker().getAttribute(
BSPSearchSupport.MARKER_KEY_LABEL);
} catch (CoreException ce) {
}
return "";
}
public Image getImage(Object element) {
return Bespielungsplan.getImages().getImage(BSPImages.ICON_ENTITY_P ERSON);
}
};
}

private void createGoToAction (IAction action) {
if ( action != null ) {
this.goToAction = action;
return;
}

goToAction = new org.eclipse.jface.action.Action() {
public void run() {
ISearchResultView view = SearchUI.getSearchResultView();
view.getSelection();
ISelection selection = view.getSelection();
Object element = null;
if (selection instanceof IStructuredSelection)
element =
((IStructuredSelection) selection).getFirstElement();
if (element instanceof ISearchResultViewEntry) {
ISearchResultViewEntry entry =
(ISearchResultViewEntry) element;
try {
EOEnterpriseObject eo = BSPSearchSupport.eoFromMarker(
new EOEditingContext(),
entry.getSelectedMarker()
);
Bespielungsplan.getDefault().getEditorRegistry().openEditor( eo);



} catch (Exception e) {
System.out.println(e);
}
}
}
};
}

private void createGroupByKeyComputer ( IGroupByKeyComputer computer ) {
if ( computer != null ) {
this.groupByKeyComputer = computer;
return;
}

this.groupByKeyComputer =new IGroupByKeyComputer() {
public Object computeGroupByKey(IMarker marker) {
try {
if (marker
.getAttribute(BSPSearchSupport.MARKER_KEY_GID)
!= null)

return marker.getAttribute(
BSPSearchSupport.MARKER_KEY_GID);
} catch (CoreException ce) {
ce.printStackTrace();
}

return "UNKNOWN" + System.currentTimeMillis();
}
};
}

private void createActionGroupFactory ( IActionGroupFactory factory ) {
this.actionGroupFactory = factory;
}

protected void execute(IProgressMonitor monitor)
throws CoreException, InvocationTargetException, InterruptedException {

try {
SearchUI.activateSearchResultView();
ISearchResultView sView = SearchUI.getSearchResultView();

NSArray eos = Session.session().defaultEditingContext().objectsWithFetchSp ecification(spec);

displayResults(eos, sView);

} catch (InvocationTargetException iex ) {
monitor.done();
throw iex;
} catch (OperationCanceledException oce) {
monitor.done();
throw oce;
} catch (InterruptedException oce) {
monitor.done();
throw oce;
}

monitor.done();
}

private void displayResults(NSArray results, ISearchResultView sView) throws CoreException, InvocationTargetException, InterruptedException {

ImageDescriptor imgDesc = Bespielungsplan.getImages().getImageDescriptor(BSPImages.ICO N_ENTITY_PERSON);

String qualiString = spec.qualifier().toString();
qualiString = qualiString.substring(1);
String label = qualiString + " - " + results.count() + " " + spec.entityName();

if (sView != null) {

sView.searchStarted(
(IActionGroupFactory) actionGroupFactory,
label,
label,
imgDesc,
page_id,
labelProvider,
goToAction,
groupByKeyComputer,
this
);
}

// Delete all previous results

Bespielungsplan.getDefault().getResource().deleteMarkers(
BSPSearchSupport.MARKER_ID,
true,
IResource.DEPTH_INFINITE);

createResultsMarkers(results, sView);
sView.searchFinished();
}

private void createResultsMarkers(NSArray results, ISearchResultView sView) {

for (int i = 0; i < results.count(); i++) {
EOEnterpriseObject eo = (EOEnterpriseObject)results.objectAtIndex(i);
EOGlobalID gid = eo.editingContext().globalIDForObject(eo);

NSDictionary dict = GlobalUtils.eoutils().primaryKeyForObject(eo.editingContext( ), eo);


//System.out.println(gid);
try {
IMarker marker = null;
marker = BSPSearchSupport.createMarker(eo);

sView.addMatch(
eo.userPresentableDescription(),
marker.getAttribute(BSPSearchSupport.MARKER_KEY_GID),
marker.getResource(),
marker);
} catch (CoreException ce) {
}
}
}

public IStatus getStatus() {
return null;
}
}
Re: strange behaviour of SearchUI ( search result view) [message #191443 is a reply to message #190467] Mon, 09 February 2004 10:38 Go to previous message
Eclipse UserFriend
Originally posted by: thomas_maeder.ch.ibm.com

I see that you catch CoreException around the creation of your search
results (markers, etc). Did you actually debug across marker creation?

Thomas
Previous Topic:gnome keybindings override eclipse
Next Topic:how do you run eclipse off a cdrom/move workspace
Goto Forum:
  


Current Time: Sat Jul 19 10:07:58 EDT 2025

Powered by FUDForum. Page generated in 0.05267 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top