import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.simantics.scl.db.SCLExpressionTableEntry;
public class SCLExpressionItemFilter extends ViewerFilter {
import org.simantics.db.Resource;
import org.simantics.db.exception.DatabaseException;
import org.simantics.modeling.ui.Activator;
+import org.simantics.scl.db.SCLExpressionTableEntry;
+import org.simantics.scl.db.UsedSCLExpressionsRequest;
import org.simantics.ui.workbench.action.DefaultActions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class SCLExpressionView extends ViewPart {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SCLExpressionView.class);
+
private TableViewer tableViewer;
private TableViewerColumn expressionColumn;
private TableViewerColumn locationColumn;
});
return Status.OK_STATUS;
} catch (DatabaseException e) {
- e.printStackTrace();
+ LOGGER.error("Could not update SCL expressions", e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not update SCL expressions", e);
}
}
+++ /dev/null
-package org.simantics.modeling.ui.scl.expressions;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.simantics.Simantics;
-import org.simantics.db.ReadGraph;
-import org.simantics.db.Resource;
-import org.simantics.db.Statement;
-import org.simantics.db.common.request.UniqueRead;
-import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.util.Layer0Utils;
-import org.simantics.layer0.Layer0;
-import org.simantics.modeling.ModelingUtils;
-import org.simantics.structural.stubs.StructuralResource2;
-
-public class UsedSCLExpressionsRequest extends UniqueRead<Collection<SCLExpressionTableEntry>> {
-
- @Override
- public Collection<SCLExpressionTableEntry> perform(ReadGraph graph) throws DatabaseException {
- Collection<SCLExpressionTableEntry> result = new ArrayList<>();
- Layer0 L0 = Layer0.getInstance(graph);
-
- Set<Resource> indexRoots = new TreeSet<Resource>();
- for(Resource ontology : Layer0Utils.listOntologies(graph)) {
- if (graph.isInstanceOf(ontology, L0.SharedOntology)) {
- indexRoots.add(ontology);
- }
- }
-
- for(Resource child : graph.getObjects(Simantics.getProjectResource(), L0.ConsistsOf)) {
- if (graph.isInstanceOf(child, L0.IndexRoot)) {
- indexRoots.add(child);
- }
- }
-
- for (Resource ontology : indexRoots) {
-// List<Resource> modules = ModelingUtils.searchByTypeShallow(graph, ontology, L0.SCLModule);
-// for (Resource module : modules) {
-// String definition = graph.getPossibleRelatedValue2(module, L0.SCLModule_definition);
-// Matcher matcher = pattern.matcher(definition);
-// while (matcher.find()) {
-// int index = matcher.start();
-// int line = 1;
-// int pos = 0;
-// while ((pos = definition.indexOf("\n", pos) + 1) > 0 && pos <= index) {
-// line++;
-// }
-// String position = graph.getPossibleURI(module) + ":" + line;
-// int lineBeginIndex = definition.lastIndexOf("\n", index);
-// if (lineBeginIndex == -1) lineBeginIndex = 0;
-// int lineEndIndex = definition.indexOf("\n", index);
-// if (lineEndIndex <= 0) lineEndIndex = definition.length();
-// String content = definition.substring(lineBeginIndex, lineEndIndex).trim();
-//
-// result.add(new SCLExpressionTableEntry(content, position));
-// }
-// }
-
- StructuralResource2 STR = StructuralResource2.getInstance(graph);
-
- List<Resource> components = ModelingUtils.searchByTypeShallow(graph, ontology, STR.Component);
- for (Resource component : components) {
- for (Statement propertyStatement : graph.getStatements(component, L0.HasProperty)) {
- if (graph.isInstanceOf(propertyStatement.getObject(), L0.SCLValue)) {
- Resource sclValue = propertyStatement.getObject();
- String expression = graph.getPossibleRelatedValue2(sclValue, L0.SCLValue_expression);
- Resource source = graph.getPossibleObject(sclValue, L0.PropertyOf);
- if (source != null) {
- String uri = graph.getPossibleURI(source);
- String pred = graph.getRelatedValue2(propertyStatement.getPredicate(), L0.HasName);
-
- if (uri != null) {
-// SCLReporting.print();
-// SCLReporting.printError(expression + "\n");
-
- result.add(new SCLExpressionTableEntry(expression, uri + "#" + pred, source));
- }
- }
- }
- }
- }
- }
- return result;
- }
-
-}
-package org.simantics.modeling.ui.scl.expressions;
+package org.simantics.scl.db;
import org.simantics.db.Resource;
--- /dev/null
+package org.simantics.scl.db;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.procedure.adapter.TransientCacheListener;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.QueryIndexUtils;
+import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.layer0.Layer0;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UsedSCLExpressionsRequest extends UniqueRead<Collection<SCLExpressionTableEntry>> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(UsedSCLExpressionsRequest.class);
+
+ private static final String structuralResourceComponentURI = "http://www.simantics.org/Structural-1.2/Component";
+
+ @Override
+ public Collection<SCLExpressionTableEntry> perform(ReadGraph graph) throws DatabaseException {
+ Collection<SCLExpressionTableEntry> result = new ArrayList<>();
+ Layer0 L0 = Layer0.getInstance(graph);
+
+ Set<Resource> indexRoots = new TreeSet<Resource>();
+ for(Resource ontology : Layer0Utils.listOntologies(graph)) {
+ if (graph.isInstanceOf(ontology, L0.SharedOntology)) {
+ indexRoots.add(ontology);
+ }
+ }
+ for(Resource child : graph.getObjects(Simantics.getProjectResource(), L0.ConsistsOf)) {
+ if (graph.isInstanceOf(child, L0.IndexRoot)) {
+ indexRoots.add(child);
+ }
+ }
+
+ Resource componentResource = graph.getPossibleResource(structuralResourceComponentURI);
+ if (componentResource != null) {
+ for (Resource ontology : indexRoots) {
+ List<Resource> components = QueryIndexUtils.searchByTypeShallow(graph, ontology, componentResource);
+ for (Resource component : components) {
+ for (Statement propertyStatement : graph.getStatements(component, L0.HasProperty)) {
+ if (graph.isInstanceOf(propertyStatement.getObject(), L0.SCLValue)) {
+ Resource sclValue = propertyStatement.getObject();
+ String expression = graph.getPossibleRelatedValue2(sclValue, L0.SCLValue_expression);
+ Resource source = graph.getPossibleObject(sclValue, L0.PropertyOf);
+ if (source != null) {
+ String uri = graph.getPossibleURI(source);
+ String pred = graph.getRelatedValue2(propertyStatement.getPredicate(), L0.HasName);
+
+ if (uri != null) {
+ result.add(new SCLExpressionTableEntry(expression, uri + "#" + pred, source));
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ LOGGER.info("{} is not available for finding expressions in component properties", structuralResourceComponentURI);
+ }
+ return result;
+ }
+
+ public static Collection<SCLExpressionTableEntry> execute() {
+ try {
+ return Simantics.getSession().syncRequest(new UsedSCLExpressionsRequest(), TransientCacheListener.instance());
+ } catch (DatabaseException e) {
+ e.printStackTrace();
+ return Collections.emptyList();
+ }
+ }
+
+}
com.ibm.icu,
org.slf4j.api,
org.eclipse.search;bundle-version="3.11.100",
- org.eclipse.ui.views
+ org.eclipse.ui.views,
+ org.simantics.scl.db;bundle-version="0.1.3",
+ org.simantics.ui
Export-Package: org.simantics.scl.ui.console,
org.simantics.scl.ui.editor,
org.simantics.scl.ui.editor2,
package org.simantics.scl.ui.search;
import java.util.ArrayList;
+import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.simantics.scl.compiler.module.debug.ModuleDebugInfo;
import org.simantics.scl.compiler.module.debug.SymbolReference;
import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.db.SCLExpressionTableEntry;
+import org.simantics.scl.db.UsedSCLExpressionsRequest;
import org.simantics.scl.osgi.SCLOsgi;
import gnu.trove.procedure.TObjectProcedure;
return true;
}
});
+
+ Collection<SCLExpressionTableEntry> results = UsedSCLExpressionsRequest.execute();
+ for (SCLExpressionTableEntry entry : results) {
+ if (entry.getContent().contains(valueName.name)) {
+ result.addMatch(new Match(entry, Match.UNIT_LINE, -1, 1));
+ }
+ }
+
return Status.OK_STATUS;
}
import org.eclipse.ui.PlatformUI;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.scl.compiler.module.debug.SymbolReference;
+import org.simantics.scl.db.SCLExpressionTableEntry;
import org.simantics.scl.ui.editor2.OpenSCLDefinition;
+import org.simantics.ui.workbench.action.DefaultActions;
public class SCLSearchResultPage extends AbstractTextSearchViewPage {
private static final ViewerComparator comparator = new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
- SymbolReference r1 = (SymbolReference)e1;
- SymbolReference r2 = (SymbolReference)e2;
- int c = r1.referrer.toString().compareTo(r2.referrer.toString());
- if (c != 0) {
- return c;
+ if (e1 instanceof SymbolReference && e2 instanceof SymbolReference) {
+ SymbolReference r1 = (SymbolReference)e1;
+ SymbolReference r2 = (SymbolReference)e2;
+ int c = r1.referrer.toString().compareTo(r2.referrer.toString());
+ if (c != 0) {
+ return c;
+ } else {
+ return Integer.compare(Locations.beginOf(r1.referenceLocation), Locations.beginOf(r2.referenceLocation));
+ }
+ } else if (e1 instanceof SymbolReference && e2 instanceof SCLExpressionTableEntry) {
+ return 1;
+ } else if (e2 instanceof SymbolReference && e1 instanceof SCLExpressionTableEntry) {
+ return -1;
} else {
- return Integer.compare(Locations.beginOf(r1.referenceLocation), Locations.beginOf(r2.referenceLocation));
+ SCLExpressionTableEntry r1 = (SCLExpressionTableEntry)e1;
+ SCLExpressionTableEntry r2 = (SCLExpressionTableEntry)e2;
+ return r1.getContent().compareTo(r2.getContent());
}
}
};
protected void handleOpen(OpenEvent event) {
Object selection = ((StructuredSelection)event.getSelection()).getFirstElement();
if (selection != null) {
- SymbolReference reference = (SymbolReference) selection;
- OpenSCLDefinition.scheduleOpenDefinition(reference.referrer.module, reference.referenceLocation);
+ open(selection);
}
}
@Override
protected void showMatch(Match match, int currentOffset, int currentLength) throws PartInitException {
- SymbolReference reference = (SymbolReference) match.getElement();
- OpenSCLDefinition.openDefinition(reference.referrer.module, reference.referenceLocation);
+ open(match.getElement());
+ }
+
+ private void open(Object selection) {
+ if (selection instanceof SymbolReference) {
+ SymbolReference reference = (SymbolReference) selection;
+ OpenSCLDefinition.scheduleOpenDefinition(reference.referrer.module, reference.referenceLocation);
+ } else if (selection instanceof SCLExpressionTableEntry) {
+ SCLExpressionTableEntry entry = (SCLExpressionTableEntry) selection;
+ DefaultActions.performDefaultAction(getControl().getDisplay().getActiveShell(), new StructuredSelection(entry.getResource()));
+ }
}
public static class SCLSearchResultContentProvider extends DecoratingStyledCellLabelProvider implements ITreeContentProvider, ILabelProvider {
@Override
public String getText(Object element) {
- SymbolReference ref = (SymbolReference) element;
- return ref.referrer.toString();
+ if (element instanceof SymbolReference) {
+ SymbolReference ref = (SymbolReference) element;
+ return ref.referrer.toString();
+ } else if (element instanceof SCLExpressionTableEntry) {
+ SCLExpressionTableEntry entry = (SCLExpressionTableEntry) element;
+ return entry.getContent();
+ } else {
+ return "unsupported element " + String.valueOf(element);
+ }
}
}
@Override
public StyledString getStyledText(Object element) {
- SymbolReference ref = (SymbolReference) element;
- return new StyledString(ref.referrer.toString()); //+ " " + ref.referred + " " + ref.referenceLocation);
+ return new StyledString(getText(element)); //+ " " + ref.referred + " " + ref.referenceLocation);
}
@Override
@Override
public String getText(Object element) {
- return null;
+ if (element instanceof SymbolReference) {
+ SymbolReference ref = (SymbolReference) element;
+ return ref.referrer.toString();
+ } else if (element instanceof SCLExpressionTableEntry) {
+ SCLExpressionTableEntry entry = (SCLExpressionTableEntry) element;
+ return entry.getContent();
+ } else {
+ return "unsupported element " + String.valueOf(element);
+ }
}
}