]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.issues.ui/src/org/simantics/issues/ui/handler/ConfigureIssueSources.java
Externalize strings
[simantics/platform.git] / bundles / org.simantics.issues.ui / src / org / simantics / issues / ui / handler / ConfigureIssueSources.java
index 797a74ef5e702e2d5321da9e756b962b35d345ac..b168583e4e0fb1cb8bfb9cccfe412e14fb9f1887 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.issues.ui.handler;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.List;\r
-\r
-import org.eclipse.core.commands.AbstractHandler;\r
-import org.eclipse.core.commands.ExecutionEvent;\r
-import org.eclipse.core.commands.ExecutionException;\r
-import org.eclipse.jface.dialogs.Dialog;\r
-import org.eclipse.jface.viewers.CheckStateChangedEvent;\r
-import org.eclipse.jface.viewers.CheckboxTableViewer;\r
-import org.eclipse.jface.viewers.ICheckStateListener;\r
-import org.eclipse.jface.viewers.ICheckStateProvider;\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.SelectionEvent;\r
-import org.eclipse.swt.events.SelectionListener;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Table;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.simantics.Simantics;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.NamedResource;\r
-import org.simantics.db.common.request.PossibleObjectWithType;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.PossibleActiveModel;\r
-import org.simantics.db.layer0.util.RemoverUtil;\r
-import org.simantics.issues.common.IssueUtils;\r
-import org.simantics.issues.ontology.IssueResource;\r
-import org.simantics.layer0.Layer0;\r
-import org.simantics.modeling.ModelingUtils;\r
-import org.simantics.utils.ui.ErrorLogger;\r
-import org.simantics.utils.ui.dialogs.ListDialog;\r
-\r
-/**\r
- * @author Antti Villberg\r
- */\r
-public class ConfigureIssueSources extends AbstractHandler {\r
-\r
-       private static class IssueSourceEntry extends NamedResource {\r
-               private boolean checked;\r
-               public IssueSourceEntry(String name, Resource resource, boolean checked) {\r
-                       super(name, resource);\r
-                       this.checked = checked;\r
-               }\r
-               public boolean isChecked() {\r
-                       return checked;\r
-               }\r
-               public void setChecked(boolean value) {\r
-                       checked = value;\r
-               }\r
-       }\r
-       \r
-    @Override\r
-    public Object execute(ExecutionEvent event) throws ExecutionException {\r
-\r
-      try {\r
-\r
-       final List<IssueSourceEntry> sources = Simantics.getSession().syncRequest(new UniqueRead<List<IssueSourceEntry>>() {\r
-\r
-                       @Override\r
-                       public List<IssueSourceEntry> perform(ReadGraph graph) throws DatabaseException {\r
-                               \r
-                               Resource activeModel = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));\r
-                               if(activeModel == null) return Collections.emptyList();\r
-                               \r
-                               List<IssueSourceEntry> result = new ArrayList<IssueSourceEntry>();\r
-                               Layer0 L0 = Layer0.getInstance(graph);\r
-                               IssueResource ISSUE = IssueResource.getInstance(graph);\r
-                               for(Resource type : ModelingUtils.searchByType(graph, activeModel, ISSUE.IssueSourceType)) {\r
-                                       String name = NameUtils.getSafeLabel(graph, type);\r
-                                       boolean exists = graph.syncRequest(new PossibleObjectWithType(activeModel, L0.ConsistsOf, type)) != null;\r
-                                       boolean deprecated = graph.hasStatement(type, L0.Deprecated);\r
-                                       if(!exists && deprecated) continue;\r
-                                       result.add(new IssueSourceEntry(name, type, exists));\r
-                               }\r
-                               return result;\r
-                       }\r
-               \r
-       });\r
-       \r
-        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();\r
-         ListDialog<IssueSourceEntry> dialog = new ListDialog<IssueSourceEntry>(\r
-                 shell, sources,\r
-                 "Select available issue sources",\r
-                 "Selected sources will be used and existing deselected sources will be removed.") {\r
-                \r
-                   protected CheckboxTableViewer createViewer(Composite composite) {\r
-                       CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList(\r
-                               composite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);\r
-                       final Table table = (Table)viewer.getControl();\r
-                       viewer.setCheckStateProvider(new ICheckStateProvider() {\r
-                                               \r
-                                               @Override\r
-                                               public boolean isGrayed(Object arg0) {\r
-                                                       return false;\r
-                                               }\r
-                                               \r
-                                               @Override\r
-                                               public boolean isChecked(Object arg0) {\r
-                                                       IssueSourceEntry entry = (IssueSourceEntry)arg0;\r
-                                                       return entry.isChecked();\r
-                                               }\r
-                                               \r
-                                       });\r
-                       viewer.addCheckStateListener(new ICheckStateListener() {\r
-                                               \r
-                                               @Override\r
-                                               public void checkStateChanged(CheckStateChangedEvent arg0) {\r
-                                                       IssueSourceEntry entry = (IssueSourceEntry)arg0.getElement();\r
-                                                       entry.setChecked(arg0.getChecked());\r
-                                               }\r
-                                       });\r
-                       table.addSelectionListener(new SelectionListener () {\r
-                               @Override\r
-                               public void widgetSelected(SelectionEvent e) {\r
-                                       table.deselectAll();\r
-                               }\r
-                               @Override\r
-                               public void widgetDefaultSelected(SelectionEvent e) {}\r
-                       });\r
-                       return viewer;\r
-                   }\r
-\r
-         };\r
-         int result = dialog.open();\r
-         if (result != Dialog.OK)\r
-             return null;\r
-       \r
-       Simantics.getSession().syncRequest(new WriteRequest() {\r
-\r
-                       @Override\r
-                       public void perform(WriteGraph graph) throws DatabaseException {\r
-                               \r
-                               Resource activeModel = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));\r
-                               if(activeModel == null) return;\r
-                               \r
-                               Layer0 L0 = Layer0.getInstance(graph);\r
-\r
-                               for(IssueSourceEntry entry : sources) {\r
-\r
-                                       Resource existing = graph.syncRequest(new PossibleObjectWithType(activeModel, L0.ConsistsOf, entry.getResource())); \r
-                                       \r
-                                       if(existing == null && entry.isChecked()) {\r
-                                               String name = NameUtils.getSafeLabel(graph, entry.getResource());\r
-                                               IssueUtils.addIssueSource(graph, activeModel, entry.getResource(), name);\r
-                                       }\r
-                                       \r
-                                       if(existing != null && !entry.isChecked()) {\r
-                                               RemoverUtil.remove(graph, existing);\r
-                                       }\r
-                                       \r
-                               }\r
-                               \r
-                       }\r
-               \r
-       });\r
-         \r
-//        try {\r
-//            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {\r
-//                @Override\r
-//                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {\r
-//                    try {\r
-//                        purgeResolvedIssues(monitor);\r
-//                    } catch (DatabaseException e) {\r
-//                        throw new InvocationTargetException(e);\r
-//                    } finally {\r
-//                        monitor.done();\r
-//                    }\r
-//                }\r
-//            });\r
-//        } catch (InvocationTargetException e) {\r
-//            ErrorLogger.defaultLogError(e);\r
-        } catch (DatabaseException e) {\r
-            ErrorLogger.defaultLogError(e);\r
-        }\r
-        return null;\r
-    }\r
-\r
-//    private void purgeResolvedIssues(IProgressMonitor monitor) throws DatabaseException {\r
-//        Session session = Simantics.getSession();\r
-//        final Resource project = Simantics.getProjectResource();\r
-//        if (project == null)\r
-//            return;\r
-//\r
-//        final SubMonitor mon = SubMonitor.convert(monitor, "Purging resolved issues...", 100);\r
-//\r
-//        session.syncRequest(new DelayedWriteRequest() {\r
-//            @Override\r
-//            public void perform(WriteGraph graph) throws DatabaseException {\r
-//                graph.markUndoPoint();\r
-//                IssueResource ISSUE = IssueResource.getInstance(graph);\r
-//                Set<Resource> toBeRemoved = new HashSet<Resource>();\r
-//                Map<Resource, Boolean> sourceIsContinuous = new THashMap<Resource, Boolean>(); \r
-//                for (Resource activeIssue : graph.syncRequest(new AllActiveIssues(project))) {\r
-//                    if (graph.hasStatement(activeIssue, ISSUE.Resolved)) {\r
-//                        Resource managedBy = graph.getPossibleObject(activeIssue, ISSUE.IssueSource_Manages_Inverse);\r
-//                        if (managedBy != null) {\r
-//                            Boolean isContinuous = sourceIsContinuous.get(managedBy);\r
-//                            if (isContinuous == null) {\r
-//                                isContinuous = graph.isInstanceOf(managedBy, ISSUE.ContinuousIssueSource);\r
-//                                sourceIsContinuous.put(managedBy, isContinuous);\r
-//                            }\r
-//                            if (isContinuous)\r
-//                                continue;\r
-//                        }\r
-//                        toBeRemoved.add(activeIssue);\r
-//                    }\r
-//                }\r
-//\r
-//                mon.setTaskName("Purging " + toBeRemoved.size() + " resolved batch issues...");\r
-//                mon.setWorkRemaining(toBeRemoved.size());\r
-//                StringBuilder sb = new StringBuilder();\r
-//                sb.append("Purged " + toBeRemoved.size() + " resolved batch issue(s)");\r
-//                for (Resource remove : toBeRemoved) {\r
-//                    //sb.append(NameUtils.getSafeLabel(graph, remove) + " ");\r
-//                    RemoverUtil.remove(graph, remove);\r
-//                    mon.worked(1);\r
-//                }\r
-//                Layer0Utils.addCommentMetadata(graph, sb.toString());\r
-//            }\r
-//        });\r
-//    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.issues.ui.handler;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ICheckStateProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.PlatformUI;
+import org.simantics.Simantics;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.NamedResource;
+import org.simantics.db.common.request.PossibleObjectWithType;
+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.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;
+
+/**
+ * @author Antti Villberg
+ */
+public class ConfigureIssueSources extends AbstractHandler {
+
+       private static class IssueSourceEntry extends NamedResource {
+               private boolean checked;
+               public IssueSourceEntry(String name, Resource resource, boolean checked) {
+                       super(name, resource);
+                       this.checked = checked;
+               }
+               public boolean isChecked() {
+                       return checked;
+               }
+               public void setChecked(boolean value) {
+                       checked = value;
+               }
+       }
+       
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+      try {
+
+       final List<IssueSourceEntry> sources = Simantics.getSession().syncRequest(new UniqueRead<List<IssueSourceEntry>>() {
+
+                       @Override
+                       public List<IssueSourceEntry> perform(ReadGraph graph) throws DatabaseException {
+                               
+                               Resource activeModel = graph.syncRequest(new PossibleActiveModel(Simantics.getProjectResource()));
+                               if(activeModel == 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)) {
+                                       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));
+                               }
+                               return result;
+                       }
+               
+       });
+       
+        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+         ListDialog<IssueSourceEntry> dialog = new ListDialog<IssueSourceEntry>(
+                 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() {
+                                               
+                                               @Override
+                                               public boolean isGrayed(Object arg0) {
+                                                       return false;
+                                               }
+                                               
+                                               @Override
+                                               public boolean isChecked(Object arg0) {
+                                                       IssueSourceEntry entry = (IssueSourceEntry)arg0;
+                                                       return entry.isChecked();
+                                               }
+                                               
+                                       });
+                       viewer.addCheckStateListener(new ICheckStateListener() {
+                                               
+                                               @Override
+                                               public void checkStateChanged(CheckStateChangedEvent arg0) {
+                                                       IssueSourceEntry entry = (IssueSourceEntry)arg0.getElement();
+                                                       entry.setChecked(arg0.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;
+                               
+                               Layer0 L0 = Layer0.getInstance(graph);
+
+                               for(IssueSourceEntry entry : sources) {
+
+                                       Resource existing = graph.syncRequest(new PossibleObjectWithType(activeModel, L0.ConsistsOf, entry.getResource())); 
+                                       
+                                       if(existing == null && entry.isChecked()) {
+                                               String name = NameUtils.getSafeLabel(graph, entry.getResource());
+                                               IssueUtils.addIssueSource(graph, activeModel, 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<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());
+//            }
+//        });
+//    }
+
+}