X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.debug.ui%2Fsrc%2Forg%2Fsimantics%2Fdebug%2Fui%2FSearchResourceDialog.java;h=06710f6e29bd03a3dec4ecbdc50d5f4afdbd4b64;hp=4eca4e550638513f0d65d00ecf45ab57540a32a4;hb=5e340942bc7de041b75c6ba281617eb0c800f30a;hpb=3c524553c98b56075d854f355bc7bab2e3ae17f7 diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java index 4eca4e550..06710f6e2 100644 --- a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java +++ b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/SearchResourceDialog.java @@ -13,6 +13,7 @@ package org.simantics.debug.ui; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -23,6 +24,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -56,6 +58,8 @@ import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.uri.UnescapedChildMapOfResource; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.genericrelation.Dependencies; +import org.simantics.db.layer0.genericrelation.IndexQueries; import org.simantics.db.layer0.migration.OntologiesFromLibrary; import org.simantics.db.layer0.variable.Variables.Role; import org.simantics.db.request.Read; @@ -85,13 +89,13 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { */ private static final int DEFAULT_MAX_INDEX_HITS = 1000; - private static final Pattern ID_PATTERN = Pattern.compile("\\$([0-9]+)"); + private static final Pattern ID_PATTERN = Pattern.compile("\\$([0-9]+)"); //$NON-NLS-1$ private static final String SEARCH_RESOURCE_DIALOG = "SearchResourceDialog"; //$NON-NLS-1$ private static final int SHOW_IN_BROWSER_ID = IDialogConstants.CLIENT_ID + 1; - private static final String SHOW_IN_BROWSER_LABEL = "Show In Browser"; + private static final String SHOW_IN_BROWSER_LABEL = Messages.SearchResourceDialog_ShowInBrowser; private Session session; @SuppressWarnings("unused") @@ -103,7 +107,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { @Override public String getText(Object element) { if (element == null) - return "null"; + return "null"; //$NON-NLS-1$ // This may happen if multiple choice is enabled if (element instanceof String) return (String) element; @@ -117,15 +121,15 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { String name = NameUtils.getSafeName(g, r); String uri = DebugUtils.getPossibleRootRelativePath(g, r); return - "[" + r.getResourceId() + "] - " + "[" + r.getResourceId() + "] - " //$NON-NLS-1$ //$NON-NLS-2$ + name - + (uri != null ? " - " : "") - + (uri != null ? uri : ""); + + (uri != null ? " - " : "") //$NON-NLS-1$ //$NON-NLS-2$ + + (uri != null ? uri : ""); //$NON-NLS-1$ } }); } catch (DatabaseException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Resource label provider failed unexpectedly.", e)); - return ""; + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.SearchResourceDialog_ActivatorResourceLabelProviderFailed, e)); + return ""; //$NON-NLS-1$ } } }; @@ -137,7 +141,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { @Override public String getText(Object element) { if (element==null) - return "null"; + return "null"; //$NON-NLS-1$ return element.toString(); } @Override @@ -162,19 +166,19 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { this.session = s; this.selection = selection; this.labelProvider = new ElementLabelProvider(shell.getDisplay()); - setMessage("Enter name, resource URI or ID"); + setMessage(Messages.SearchResourceDialog_EnterNameResURIOrId); setListLabelProvider(labelProvider); setDetailsLabelProvider(detailsLabelProvider); setTitle(title); //setInitialPattern("*", FilteredItemsSelectionDialog.FULL_SELECTION); setSelectionHistory(new ResourceSelectionHistory()); - setSeparatorLabel("Previously selected above, others below"); + setSeparatorLabel(Messages.SearchResourceDialog_SeperatorLblPreviouslySelected); } @Override protected void configureShell(Shell shell) { this.resourceManager = new LocalResourceManager(JFaceResources.getResources(), shell); - setImage((Image) resourceManager.get(BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"))); + setImage((Image) resourceManager.get(BundleUtils.getImageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/cog_blue.png"))); //$NON-NLS-1$ super.configureShell(shell); } @@ -221,16 +225,16 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { try { return DebugUtils.getSafeLabel(g, r); } catch (Exception ex) { - System.out.println("Exception thrown from restoreItemFromMemento"); + System.out.println("Exception thrown from restoreItemFromMemento"); //$NON-NLS-1$ } } catch (Throwable t) {} - return "" + r.getResourceId(); + return "" + r.getResourceId(); //$NON-NLS-1$ } }); if (name==null) return null; return new LabeledResource(name, r); } catch (NumberFormatException | DatabaseException e) { - LOGGER.info("Search memento restoration failed.", e); + LOGGER.info("Search memento restoration failed.", e); //$NON-NLS-1$ return null; } } @@ -266,7 +270,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { public ItemsFilterWithSearchResults() { final String pattern = getPattern(); - final boolean findUris = pattern.trim().startsWith("http:/"); + final boolean findUris = pattern.trim().startsWith("http:/"); //$NON-NLS-1$ final long referencedResourceId = referencedResourceId(pattern); final boolean findIds = referencedResourceId != 0; @@ -302,13 +306,19 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { } } } else { + String[] terms = pattern.trim().split("\\s+"); //$NON-NLS-1$ + if (terms.length == 0) return; + Resource project = Simantics.peekProjectResource(); if (project != null) { IResourceFilter rf = resourceFilter; String filter = getFilterForResourceFilter(rf); if (!filter.isEmpty()) - filter += " AND "; - filter += "Name:" + pattern + "*"; + filter += " AND "; //$NON-NLS-1$ + + filter += Dependencies.FIELD_NAME_SEARCH + ":("; //$NON-NLS-1$ + filter += Arrays.stream(terms).map(term -> "+" + IndexQueries.escape(term.toLowerCase(), false) + "*").collect(Collectors.joining(" ")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + filter +=")"; //$NON-NLS-1$ Layer0 L0 = Layer0.getInstance(graph); @@ -438,7 +448,7 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { @SuppressWarnings("unchecked") @Override public String getElementName(Object item) { - return ((Container)item).get().getResourceId()+""; + return ((Container)item).get().getResourceId()+""; //$NON-NLS-1$ //return item.toString(); } @@ -464,12 +474,12 @@ public class SearchResourceDialog extends FilteredItemsSelectionDialog { private String getFilterForResourceFilter(IResourceFilter filter) { if (filter == null || filter == ResourceSearch.FILTER_ALL) - return ""; + return ""; //$NON-NLS-1$ if (filter == ResourceSearch.FILTER_RELATIONS) - return "Types:Relation"; + return "Types:Relation"; //$NON-NLS-1$ if (filter == ResourceSearch.FILTER_TYPES) - return "Types:Type"; - return ""; + return "Types:Type"; //$NON-NLS-1$ + return ""; //$NON-NLS-1$ } }