X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.issues.ui%2Fsrc%2Forg%2Fsimantics%2Fissues%2Fui%2Fhandler%2FConfigureIssueSources.java;h=720b9d10beeeacb12eead12496a7c308bf713a63;hp=b168583e4e0fb1cb8bfb9cccfe412e14fb9f1887;hb=1ae2c52a087a20a7fc9c0288b7e2398b4429e20e;hpb=158d6269660a3b415504f1da5a0b8341e761a5be 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..720b9d10b 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 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 @@ -8,6 +8,7 @@ * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation + * Semantum Oy - Reorganization *******************************************************************************/ package org.simantics.issues.ui.handler; @@ -40,12 +41,13 @@ 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.db.request.Write; 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; @@ -67,176 +69,106 @@ public class ConfigureIssueSources extends AbstractHandler { checked = value; } } - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - try { + @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; + } - final List sources = Simantics.getSession().syncRequest(new UniqueRead>() { + public static void executeDefault(Resource indexRoot) throws ExecutionException { - @Override - public List perform(ReadGraph graph) throws DatabaseException { - - Resource activeModel = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource())); - if(activeModel == 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)) { - String name = NameUtils.getSafeLabel(graph, type); - boolean exists = graph.syncRequest(new PossibleObjectWithType(activeModel, L0.ConsistsOf, type)) != null; - boolean deprecated = graph.hasStatement(type, L0.Deprecated); - if(!exists && deprecated) continue; - result.add(new IssueSourceEntry(name, type, exists)); + if (indexRoot == null) + return; + + try { + final List sources = Simantics.getSession().syncRequest(new UniqueRead>() { + + @Override + public List perform(ReadGraph graph) throws DatabaseException { + + if(indexRoot == null) return Collections.emptyList(); + + List result = new ArrayList(); + Layer0 L0 = Layer0.getInstance(graph); + IssueResource ISSUE = IssueResource.getInstance(graph); + for(Resource type : QueryIndexUtils.searchByType(graph, indexRoot, ISSUE.IssueSourceType)) { + String name = NameUtils.getSafeLabel(graph, type); + boolean exists = graph.syncRequest(new PossibleObjectWithType(indexRoot, L0.ConsistsOf, type)) != null; + boolean deprecated = graph.hasStatement(type, L0.Deprecated); + boolean abstract_ = graph.hasStatement(type, L0.Abstract); + if(!exists && (deprecated || abstract_)) continue; + result.add(new IssueSourceEntry(name, type, exists)); + } + return result; } - return result; - } - - }); - - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - ListDialog dialog = new ListDialog( - shell, sources, - Messages.ConfigureIssueSources_SelectAvailableIssueSources, - Messages.ConfigureIssueSources_SelectedSourcesAddRemoveMsg) { - - protected CheckboxTableViewer createViewer(Composite composite) { - CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList( - composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); - final Table table = (Table)viewer.getControl(); - viewer.setCheckStateProvider(new ICheckStateProvider() { - + + }); + + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + ListDialog dialog = new ListDialog( + shell, sources, + Messages.ConfigureIssueSources_SelectAvailableIssueSources, + Messages.ConfigureIssueSources_SelectedSourcesAddRemoveMsg) { + + protected CheckboxTableViewer createViewer(Composite composite) { + CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList( + composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER); + viewer.setCheckStateProvider(new ICheckStateProvider() { @Override - public boolean isGrayed(Object arg0) { + public boolean isGrayed(Object o) { return false; } - @Override - public boolean isChecked(Object arg0) { - IssueSourceEntry entry = (IssueSourceEntry)arg0; + public boolean isChecked(Object o) { + IssueSourceEntry entry = (IssueSourceEntry)o; return entry.isChecked(); } - }); - viewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent arg0) { - IssueSourceEntry entry = (IssueSourceEntry)arg0.getElement(); - entry.setChecked(arg0.getChecked()); - } + viewer.addCheckStateListener(e -> { + IssueSourceEntry entry = (IssueSourceEntry)e.getElement(); + entry.setChecked(e.getChecked()); }); - table.addSelectionListener(new SelectionListener () { - @Override - public void widgetSelected(SelectionEvent e) { - table.deselectAll(); - } - @Override - public void widgetDefaultSelected(SelectionEvent e) {} - }); - return viewer; - } - - }; - int result = dialog.open(); - if (result != Dialog.OK) - return null; - - 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; - + viewer.getTable().addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> { + viewer.getTable().deselectAll(); + })); + return viewer; + } + + }; + int result = dialog.open(); + if (result != Dialog.OK) + return; + + Simantics.getSession().syncRequest((Write) graph -> { + 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()) { RemoverUtil.remove(graph, existing); } - + } - - } - - }); - -// 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; - } - -// 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()); -// } -// }); -// } + + }); + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(e); + } + + } }