X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.issues.ui%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fui%2Fhandler%2FConfigureIssueSources.java;fp=bundles%2Forg.simantics.issues.ui%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fui%2Fhandler%2FConfigureIssueSources.java;h=1836b8cacc116ee99c7d9adb382f679594e0c0f4;hb=0ffcb1180dcccf28e66a391338885be224ba1c47;hp=b168583e4e0fb1cb8bfb9cccfe412e14fb9f1887;hpb=342a2b006b88330280060c16c2ab50374468a4c6;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/ConfigureIssueSources.java b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/ConfigureIssueSources.java index b168583e4..1836b8cac 100644 --- a/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/ConfigureIssueSources.java +++ b/bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/ConfigureIssueSources.java @@ -40,12 +40,12 @@ import org.simantics.db.common.request.UniqueRead; 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; @@ -70,6 +70,16 @@ public class ConfigureIssueSources extends AbstractHandler { @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 { @@ -78,17 +88,17 @@ public class ConfigureIssueSources extends AbstractHandler { @Override public List 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 result = new ArrayList(); 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; @@ -142,25 +152,24 @@ public class ConfigureIssueSources extends AbstractHandler { }; 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()) { @@ -173,70 +182,10 @@ public class ConfigureIssueSources extends AbstractHandler { }); -// 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 toBeRemoved = new HashSet(); -// Map sourceIsContinuous = new THashMap(); -// 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()); -// } -// }); -// } - }