/*******************************************************************************
- * Copyright (c) 2007, 2016 Association for Decentralized Information Management
+ * Copyright (c) 2007, 2019 Association for Decentralized Information Management
* in Industry THTH ry.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
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;
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;
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;
*/
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")
@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;
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$
}
}
};
@Override
public String getText(Object element) {
if (element==null)
- return "null";
+ return "null"; //$NON-NLS-1$
return element.toString();
}
@Override
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);
}
if (buttonId == SHOW_IN_BROWSER_ID) {
okPressed();
LabeledResource lr = (LabeledResource) getFirstResult();
- ShowInBrowser.defaultExecute(new StructuredSelection(new ResourceWorkbenchSelectionElement(lr.resource)));
+ if (lr != null) {
+ ShowInBrowser.defaultExecute(new StructuredSelection(new ResourceWorkbenchSelectionElement(lr.resource)));
+ }
return;
}
super.buttonPressed(buttonId);
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;
}
}
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;
}
}
} else {
+ String[] terms = pattern.trim().split("\\s+"); //$NON-NLS-1$
+ if (terms.length == 0) return;
+
Resource project = Simantics.peekProjectResource();
if (project != null) {
+ Layer0 L0 = Layer0.getInstance(graph);
IResourceFilter rf = resourceFilter;
- String filter = getFilterForResourceFilter(rf);
+ String filter = getFilterForResourceFilter(L0, rf);
if (!filter.isEmpty())
- filter += " AND ";
- filter += "Name:" + pattern + "*";
-
- Layer0 L0 = Layer0.getInstance(graph);
+ 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$
Set<Resource> indexRoots = new HashSet<>();
indexRoots.addAll(graph.syncRequest(new ObjectsWithType(project, L0.ConsistsOf, L0.IndexRoot)));
@SuppressWarnings("unchecked")
@Override
public String getElementName(Object item) {
- return ((Container<Resource>)item).get().getResourceId()+"";
+ return ((Container<Resource>)item).get().getResourceId()+""; //$NON-NLS-1$
//return item.toString();
}
this.resourceFilter = resourceFilter;
}
- private String getFilterForResourceFilter(IResourceFilter filter) {
+ private String getFilterForResourceFilter(Layer0 l0, IResourceFilter filter) {
if (filter == null || filter == ResourceSearch.FILTER_ALL)
- return "";
+ return ""; //$NON-NLS-1$
if (filter == ResourceSearch.FILTER_RELATIONS)
- return "Types:Relation";
+ return IndexQueries.resourceIdTerm(Dependencies.FIELD_TYPE_RESOURCE, l0.Relation);
if (filter == ResourceSearch.FILTER_TYPES)
- return "Types:Type";
- return "";
+ return IndexQueries.resourceIdTerm(Dependencies.FIELD_TYPE_RESOURCE, l0.Type);
+ return ""; //$NON-NLS-1$
}
}