import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.common.utils.NameUtils;
import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.QueryIndexUtils;
import org.simantics.db.layer0.request.PossibleActiveModel;
import org.simantics.db.layer0.util.RemoverUtil;
import org.simantics.issues.common.IssueUtils;
import org.simantics.issues.ontology.IssueResource;
import org.simantics.layer0.Layer0;
-import org.simantics.modeling.ModelingUtils;
import org.simantics.utils.ui.ErrorLogger;
import org.simantics.utils.ui.dialogs.ListDialog;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
+ try {
+ Resource indexRoot = Simantics.getSession().syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
+ executeDefault(indexRoot);
+ } catch (DatabaseException e) {
+ throw new ExecutionException("Exception while showing validation configuration dialog", e);
+ }
+ return null;
+ }
+
+ public static void executeDefault(Resource indexRoot) throws ExecutionException {
try {
@Override
public List<IssueSourceEntry> perform(ReadGraph graph) throws DatabaseException {
- Resource activeModel = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
- if(activeModel == null) return Collections.emptyList();
+ if(indexRoot == null) return Collections.emptyList();
List<IssueSourceEntry> result = new ArrayList<IssueSourceEntry>();
Layer0 L0 = Layer0.getInstance(graph);
IssueResource ISSUE = IssueResource.getInstance(graph);
- for(Resource type : ModelingUtils.searchByType(graph, activeModel, ISSUE.IssueSourceType)) {
+ for(Resource type : QueryIndexUtils.searchByType(graph, indexRoot, ISSUE.IssueSourceType)) {
String name = NameUtils.getSafeLabel(graph, type);
- boolean exists = graph.syncRequest(new PossibleObjectWithType(activeModel, L0.ConsistsOf, type)) != null;
+ boolean exists = graph.syncRequest(new PossibleObjectWithType(indexRoot, L0.ConsistsOf, type)) != null;
boolean deprecated = graph.hasStatement(type, L0.Deprecated);
- if(!exists && deprecated) continue;
+ boolean abstract_ = graph.hasStatement(type, L0.Abstract);
+ if(!exists && (deprecated || abstract_)) continue;
result.add(new IssueSourceEntry(name, type, exists));
}
return result;
};
int result = dialog.open();
if (result != Dialog.OK)
- return null;
+ return;
Simantics.getSession().syncRequest(new WriteRequest() {
@Override
public void perform(WriteGraph graph) throws DatabaseException {
- Resource activeModel = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
- if(activeModel == null) return;
+ if(indexRoot == null) return;
Layer0 L0 = Layer0.getInstance(graph);
for(IssueSourceEntry entry : sources) {
- Resource existing = graph.syncRequest(new PossibleObjectWithType(activeModel, L0.ConsistsOf, entry.getResource()));
+ Resource existing = graph.syncRequest(new PossibleObjectWithType(indexRoot, L0.ConsistsOf, entry.getResource()));
if(existing == null && entry.isChecked()) {
String name = NameUtils.getSafeLabel(graph, entry.getResource());
- IssueUtils.addIssueSource(graph, activeModel, entry.getResource(), name);
+ IssueUtils.addIssueSource(graph, indexRoot, entry.getResource(), name);
}
if(existing != null && !entry.isChecked()) {
});
-// try {
-// PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
-// @Override
-// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
-// try {
-// purgeResolvedIssues(monitor);
-// } catch (DatabaseException e) {
-// throw new InvocationTargetException(e);
-// } finally {
-// monitor.done();
-// }
-// }
-// });
-// } catch (InvocationTargetException e) {
-// ErrorLogger.defaultLogError(e);
} catch (DatabaseException e) {
ErrorLogger.defaultLogError(e);
}
- return null;
+ return;
}
-// private void purgeResolvedIssues(IProgressMonitor monitor) throws DatabaseException {
-// Session session = Simantics.getSession();
-// final Resource project = Simantics.getProjectResource();
-// if (project == null)
-// return;
-//
-// final SubMonitor mon = SubMonitor.convert(monitor, "Purging resolved issues...", 100);
-//
-// session.syncRequest(new DelayedWriteRequest() {
-// @Override
-// public void perform(WriteGraph graph) throws DatabaseException {
-// graph.markUndoPoint();
-// IssueResource ISSUE = IssueResource.getInstance(graph);
-// Set<Resource> toBeRemoved = new HashSet<Resource>();
-// Map<Resource, Boolean> sourceIsContinuous = new THashMap<Resource, Boolean>();
-// for (Resource activeIssue : graph.syncRequest(new AllActiveIssues(project))) {
-// if (graph.hasStatement(activeIssue, ISSUE.Resolved)) {
-// Resource managedBy = graph.getPossibleObject(activeIssue, ISSUE.IssueSource_Manages_Inverse);
-// if (managedBy != null) {
-// Boolean isContinuous = sourceIsContinuous.get(managedBy);
-// if (isContinuous == null) {
-// isContinuous = graph.isInstanceOf(managedBy, ISSUE.ContinuousIssueSource);
-// sourceIsContinuous.put(managedBy, isContinuous);
-// }
-// if (isContinuous)
-// continue;
-// }
-// toBeRemoved.add(activeIssue);
-// }
-// }
-//
-// mon.setTaskName("Purging " + toBeRemoved.size() + " resolved batch issues...");
-// mon.setWorkRemaining(toBeRemoved.size());
-// StringBuilder sb = new StringBuilder();
-// sb.append("Purged " + toBeRemoved.size() + " resolved batch issue(s)");
-// for (Resource remove : toBeRemoved) {
-// //sb.append(NameUtils.getSafeLabel(graph, remove) + " ");
-// RemoverUtil.remove(graph, remove);
-// mon.worked(1);
-// }
-// Layer0Utils.addCommentMetadata(graph, sb.toString());
-// }
-// });
-// }
-
}