]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Cluster sets are written to wrong directory until first snapshot is made"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 9 Jan 2017 09:16:21 +0000 (11:16 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Mon, 9 Jan 2017 09:16:21 +0000 (11:16 +0200)
21 files changed:
bundles/org.simantics.acorn/META-INF/MANIFEST.MF
bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java
bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java
bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerViewBase.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityInstances.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OntologiesFromLibrary.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java
bundles/org.simantics.graph.db/META-INF/MANIFEST.MF
bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java
bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/AbstractCommandConsole.java
bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/MappingBase.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/Solver.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java
bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java
bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorSupport.java
bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/MultiLineInputDialog.java
bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java

index 9152acafd81bca244dc924c6c94350fc07b0730b..28c851cb0cb291105ea0a5541922695b5db7ba76 100644 (file)
@@ -11,7 +11,8 @@ Require-Bundle: gnu.trove3;bundle-version="3.0.0",
  org.simantics.compressions;bundle-version="1.0.0",
  org.simantics.backup,
  org.eclipse.core.runtime;bundle-version="3.11.1",
- org.simantics.db.procore
+ org.simantics.db.procore,
+ org.slf4j.api;bundle-version="1.7.2"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
 Bundle-Activator: org.simantics.acorn.internal.Activator
index b2a30953cca9e0bff26e72dc69a788139e52a817..c414dd2b601a834a1de15d55be218535721b349d 100644 (file)
@@ -35,8 +35,12 @@ import org.simantics.db.service.ClusterSetsSupport;
 import org.simantics.db.service.ClusterUID;
 import org.simantics.utils.threads.logger.ITask;
 import org.simantics.utils.threads.logger.ThreadLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ClusterManager {
+    
+    final static Logger LOGGER = LoggerFactory.getLogger(ClusterManager.class); 
 
        private ArrayList<String> currentChanges = new ArrayList<String>();
 
@@ -148,7 +152,7 @@ public class ClusterManager {
                    return false;
                }
     
-               System.err.println("makeSnapshot");
+               LOGGER.info("makeSnapshot");
     
                // Schedule writing of all data to disk
             refreshHeadState();
@@ -173,7 +177,7 @@ public class ClusterManager {
     
                amountOfFiles = countFiles(workingDirectory);
                
-               System.err.println(" -finished: amount of files is " + amountOfFiles);
+               LOGGER.info(" -finished: amount of files is {}", amountOfFiles);
     
                workingDirectory = dbFolder.resolve(Integer.toString(mainState.headDir));
                if (!Files.exists(workingDirectory)) {
index 5726b51303879cf301b94ad1b3256dfad2938b18..cc978e7e8b6ce599957ff6fbb859c76ec96a0d96 100644 (file)
@@ -1517,10 +1517,14 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
                columnAccessor = new GEColumnAccessor(this);
                
                IDataProvider dataProvider = new ListDataProvider<TreeNode>(list, columnAccessor);
-               
-               int defaultFontSize = 12;
-               int height = (int)Math.ceil(((double)(defaultFontSize))*getDisplayScale()) + DataLayer.DEFAULT_ROW_HEIGHT-defaultFontSize;
-               dataLayer = new DataLayer(dataProvider, DataLayer.DEFAULT_COLUMN_WIDTH, height);
+
+//      FIXME: NatTable 1.0 required help to work with custom display scaling (Windows 7 display scaling). 
+//             It seems that NatTable 1.4 breaks with the same code in Windows 7, so now the code is disabled.
+//             More testing with different hardware is required...             
+//             int defaultFontSize = 12;
+//             int height = (int)Math.ceil(((double)(defaultFontSize))*getDisplayScale()) + DataLayer.DEFAULT_ROW_HEIGHT-defaultFontSize;
+//             dataLayer = new DataLayer(dataProvider, DataLayer.DEFAULT_COLUMN_WIDTH, height);
+               dataLayer = new DataLayer(dataProvider);
                
                // resizable rows are unnecessary in Sulca report.
                dataLayer.setRowsResizableByDefault(false);
@@ -1535,7 +1539,7 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap
                // Column header layer
                columnHeaderDataProvider = new GEColumnHeaderDataProvider(this, dataLayer); 
                columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
-               columnHeaderDataLayer.setDefaultRowHeight(height);
+               //columnHeaderDataLayer.setDefaultRowHeight(height);
                columnHeaderDataProvider.updateColumnSizes();
                
                //ISortModel sortModel = new EcoSortModel(this, generator,dataLayer);
index 407fbff3ba8fa750ae823c4148aa71c131d9b129..713b28297e67856ba0841f263aeb12a9f0028aa3 100644 (file)
@@ -15,9 +15,10 @@ import org.eclipse.jface.viewers.IPostSelectionProvider;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.ISelectionListener;
 import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.services.IDisposable;
 import org.simantics.browsing.ui.GraphExplorer;
 
-public class DefaultExplorerSelectionListener implements ISelectionListener {
+public class DefaultExplorerSelectionListener implements ISelectionListener, IDisposable {
 
     private static final boolean DEBUG = false;
 
@@ -35,6 +36,13 @@ public class DefaultExplorerSelectionListener implements ISelectionListener {
         this.filter = filter;
     }
 
+    @Override
+    public void dispose() {
+        owner = null;
+        explorer = null;
+        filter = null;
+    }
+
     @Override
     public void selectionChanged(IWorkbenchPart part, ISelection selection) {
         // Always disregard own selections.
@@ -44,6 +52,7 @@ public class DefaultExplorerSelectionListener implements ISelectionListener {
         if (DEBUG)
             System.out.println("[" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
         ISelection s = selection;
+        WorkbenchSelectionFilter filter = this.filter;
         if (filter != null)
             s = filter.filterSelection(part, selection);
 
@@ -52,9 +61,12 @@ public class DefaultExplorerSelectionListener implements ISelectionListener {
                 System.out.println("** [" + owner + "] workbench selection changed: part=" + part + ", selection=" + selection);
                 System.out.println("    SETTING NEW SELECTION");
             }
-            if(!explorer.isDisposed()) {
+            GraphExplorer explorer = this.explorer;
+            if(explorer != null && !explorer.isDisposed()) {
                 IPostSelectionProvider selectionProvider = (IPostSelectionProvider)explorer.getAdapter(IPostSelectionProvider.class);
-                selectionProvider.setSelection(selection);
+                if (selectionProvider != null) {
+                    selectionProvider.setSelection(selection);
+                }
             }
         } else {
             if (DEBUG)
index 72307b32f22ec8371841ed96ef4c469e7d85453a..4b1d8ffef94c1e59d4756ddb994bfd3b293df6af 100644 (file)
@@ -27,6 +27,7 @@ import org.eclipse.ui.IViewSite;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.part.ViewPart;
+import org.eclipse.ui.services.IDisposable;
 import org.simantics.browsing.ui.Column;
 import org.simantics.browsing.ui.GraphExplorer;
 import org.simantics.browsing.ui.NodeContext;
@@ -298,6 +299,8 @@ public abstract class GraphExplorerViewBase extends ViewPart {
         // Remember to remove the installed workbench selection listener
         if (workbenchSelectionListener != null) {
             getSite().getWorkbenchWindow().getSelectionService().removePostSelectionListener(workbenchSelectionListener);
+            if (workbenchSelectionListener instanceof IDisposable)
+                ((IDisposable) workbenchSelectionListener).dispose();
             workbenchSelectionListener = null;
 
             getSite().setSelectionProvider(null);
@@ -520,16 +523,16 @@ public abstract class GraphExplorerViewBase extends ViewPart {
         return true;
     }
 
-    @SuppressWarnings("rawtypes")
+    @SuppressWarnings("unchecked")
     @Override
-    public Object getAdapter(Class adapter) {
+    public <T> T getAdapter(Class<T> adapter) {
 
         if (GraphExplorer.class == adapter)
-            return explorer;
+            return (T) explorer;
         else if(ISessionContextProvider.class == adapter)
-            return getSessionContextProvider();
+            return (T) getSessionContextProvider();
         else if(IPropertyPage.class == adapter)
-            return getPropertyPage();
+            return (T) getPropertyPage();
 
         return super.getAdapter(adapter);
 
index ef5acc97b438d1b06ed627c3c6269a2c3b57af3a..488545c5fec781c80876b9cf7035f8b0eed31c06 100644 (file)
@@ -127,11 +127,10 @@ public class EntityInstances implements Instances {
                return "QueryIndex " + parameter + " " + parameter2 + " " + parameter3;
         }
 
-               @Override
-               public boolean isImmutable(ReadGraph graph) throws DatabaseException {
-                       // TODO Auto-generated method stub
-                       return false;
-               }
+        @Override
+        public boolean isImmutable(ReadGraph graph) throws DatabaseException {
+            return graph.isImmutable(parameter);
+        }
 
                @Override
                public int getType() {
index c715a6401aaa5c52f2329ac4ce808e746d052b72..774c6465a3a327e0da60b73c97a9a645291b6554 100644 (file)
@@ -19,6 +19,7 @@ import org.simantics.db.Resource;
 import org.simantics.db.common.request.ObjectsWithType;
 import org.simantics.db.common.request.ResourceRead;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.RequestFlags;
 import org.simantics.layer0.Layer0;
 
 public class OntologiesFromLibrary extends ResourceRead<List<Resource>> {
@@ -32,12 +33,20 @@ public class OntologiesFromLibrary extends ResourceRead<List<Resource>> {
         Layer0 L0 = Layer0.getInstance(graph);
         ArrayList<Resource> result = new ArrayList<Resource>();
         for(Resource r : graph.syncRequest(new ObjectsWithType(resource, L0.ConsistsOf, L0.Library))) {
-            if(graph.isInstanceOf(r, L0.Ontology))
-                result.add(r);
-            else
+            if(graph.isInstanceOf(r, L0.IndexRoot)) {
+                if(graph.isInstanceOf(r, L0.Ontology)) {
+                    result.add(r);
+                }
+            } else {
                 result.addAll(graph.syncRequest(new OntologiesFromLibrary(r)));
+            }
         }
         return result;
     }
 
+    @Override
+    public int getType() {
+        return RequestFlags.IMMEDIATE_UPDATE;
+    }
+
 }
index 53df7072c66e4abeb257cb6b6fe9ad99fb129afb..2baadba199efd1d9890e4f8ee146be38deaed72b 100644 (file)
@@ -14,11 +14,8 @@ package org.simantics.db.layer0.util;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
 
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
@@ -34,7 +31,6 @@ import org.simantics.db.layer0.adapter.impl.AbstractRemover;
 import org.simantics.db.layer0.adapter.impl.EntityRemover;
 import org.simantics.db.layer0.exception.CannotRemoveException;
 import org.simantics.db.layer0.internal.SimanticsInternal;
-import org.simantics.utils.strings.AlphanumComparator;
 import org.simantics.utils.strings.EString;
 
 /**
@@ -50,7 +46,7 @@ public final class RemoverUtil {
        public static boolean canRemove(ReadGraph graph, Resource resource) throws DatabaseException {
         Remover remover = RemoverUtil.getPossibleRemover(graph, resource);
         if (remover != null) {
-            String problem = remover.canRemove(graph, new HashMap<Object, Object>(4));
+            String problem = remover.canRemove(graph, new HashMap<>(4));
             if (problem != null) return false;
         }
         return true;
@@ -92,7 +88,7 @@ public final class RemoverUtil {
 
     public static String testRemoval(ReadGraph graph, final Collection<Resource> rs, List<Remover> removers) throws DatabaseException {
         if (removers == null)
-            removers = new ArrayList<Remover>(rs.size());
+            removers = new ArrayList<>(rs.size());
 
         for (Resource r : rs) {
             Remover remover = graph.getPossibleAdapter(r, Remover.class);
@@ -100,8 +96,8 @@ public final class RemoverUtil {
                 removers.add(remover);
         }
 
-        Map<Object, Object> aux = new HashMap<Object, Object>();
-        List<String> errors = new ArrayList<String>(2);
+        Map<Object, Object> aux = new HashMap<>();
+        List<String> errors = new ArrayList<>(2);
         for (Remover remover : removers) {
             String error = remover.canRemove(graph, aux);
             if (error != null)
@@ -132,7 +128,7 @@ public final class RemoverUtil {
                     graph.addMetadata(cm.add("Removing " + r + "."));
                 }
 
-                List<Remover> removers = new ArrayList<Remover>(rs.size());
+                List<Remover> removers = new ArrayList<>(rs.size());
                 String error = testRemoval(graph, rs, removers);
                 if (error != null)
                     throw new CannotRemoveException(error);
@@ -167,30 +163,9 @@ public final class RemoverUtil {
             @Override
             public Boolean perform(WriteGraph graph) throws DatabaseException {
                 graph.markUndoPoint();
-                // 1. make sure that all resources are of the same type
-                Collection<Resource> principalTypes = null;
-                for (Resource r : rs) {
-                    Collection<Resource> pts = graph.getPrincipalTypes(r);
-                    if (principalTypes == null) {
-                        principalTypes = pts;
-                    } else if (!principalTypes.equals(pts)) {
-                        //return false;
-                        StringBuilder sb = new StringBuilder();
-                        sb.append("Removing resources of different types at the same time is currently not supported.\n\nThe selection contained resources of the following types:\n");
-                        Set<Resource> differentTypes = new HashSet<Resource>();
-                        Set<String> typeNames = new TreeSet<String>(AlphanumComparator.CASE_INSENSITIVE_COMPARATOR);
-                        for (Resource t : rs)
-                            differentTypes.addAll(graph.getPrincipalTypes(t));
-                        for (Resource t : differentTypes)
-                            typeNames.add(NameUtils.getSafeName(graph, t));
-                        for (String typeName : typeNames)
-                            sb.append("\t").append(typeName).append("\n");
-                        throw new CannotRemoveException(sb.toString());
-                    }
-                }
 
-                List<Remover> removers = new ArrayList<Remover>();
-                Map<Remover, String> removedResources = new HashMap<Remover, String>();
+                List<Remover> removers = new ArrayList<>();
+                Map<Remover, String> removedResources = new HashMap<>();
                 for (Resource r : rs) {
                     Remover remover = graph.getPossibleAdapter(r, Remover.class);
                     if (remover != null) {
@@ -199,8 +174,8 @@ public final class RemoverUtil {
                     }
                 }
 
-                Map<Object, Object> aux = new HashMap<Object, Object>();
-                List<String> errors = new ArrayList<String>(removers.size());
+                Map<Object, Object> aux = new HashMap<>();
+                List<String> errors = new ArrayList<>(removers.size());
                 for (Remover remover : removers) {
                     String error = remover.canRemove(graph, aux);
                     if (error != null)
index 20c651f5c7540592c90a402c9504ca6d1c9c2c30..f21b3e776dd1dd7cd981113b6da07374c1b9c9f4 100644 (file)
@@ -7,7 +7,8 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.simantics.graph;bundle-version="1.0.0";visibility:=reexport,
  org.simantics.db.common;bundle-version="0.8.0",
  gnu.trove3;bundle-version="3.0.3",
- org.simantics.layer0;bundle-version="1.0.0"
+ org.simantics.layer0;bundle-version="1.0.0",
+ org.slf4j.api;bundle-version="1.7.2"
 Export-Package: org.simantics.graph.db,
  org.simantics.graph.db.old
 Bundle-Vendor: VTT Technical Research Centre of Finland
index edcbc51d86499597619ee29b504de0bd087f2d19..bdfd3de6e2ae326ad739468ac913f1f58fcbe274 100644 (file)
@@ -62,11 +62,14 @@ import org.simantics.graph.representation.Identity;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.graph.representation.Value;
 import org.simantics.utils.datastructures.BinaryFunction;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import gnu.trove.list.array.TIntArrayList;
 import gnu.trove.map.hash.TObjectIntHashMap;
 
 public class TransferableGraphs {
+    final static Logger LOGGER = LoggerFactory.getLogger(TransferableGraphs.class); 
 
        public static long[] importGraph(Session session, Object tg, IImportAdvisor advisor) throws DatabaseException, TransferableGraphException {
                if (tg instanceof TransferableGraph1) 
@@ -579,7 +582,7 @@ public class TransferableGraphs {
                });
 
                long end = System.nanoTime();
-               System.err.println("Wrote transferable graph in " + 1e-9*(end-start) + " seconds.");
+               LOGGER.info("Wrote transferable graph in {} seconds.", 1e-9*(end-start));
        }
 
        public static TransferableGraph1 create(ReadGraph graph, TransferableGraphSource source) throws DatabaseException {
index b4260b47b4a07ea01fc2ee2d94a363ce3f22bdea..bd011689f4497f080b86ee86121bb543224ae80d 100644 (file)
@@ -426,10 +426,12 @@ public abstract class AbstractCommandConsole extends Composite {
             return;
         
         // Add command to command history
-        commandHistory.add(command);
-        if(commandHistory.size() > COMMAND_HISTORY_SIZE*2)
-            commandHistory = new ArrayList<String>(
-                    commandHistory.subList(COMMAND_HISTORY_SIZE, COMMAND_HISTORY_SIZE*2));
+        if(commandHistory.isEmpty() || !commandHistory.get(commandHistory.size()-1).equals(command)) {
+            commandHistory.add(command);
+            if(commandHistory.size() > COMMAND_HISTORY_SIZE*2)
+                commandHistory = new ArrayList<String>(
+                        commandHistory.subList(COMMAND_HISTORY_SIZE, COMMAND_HISTORY_SIZE*2));
+        }
         commandHistoryPos = commandHistory.size();
         
         // Print it into output area
index b41e9c754fa751883896ce48b7b007f7edd0ce1d..277b10cb0635f6e8401f78069a175f56104bc037 100644 (file)
@@ -316,7 +316,7 @@ public class SpreadsheetBook implements SpreadsheetElement<SpreadsheetElement, S
        }
 
        @Override
-       public void addSubprocess(String name) {
+       public void addSubprocess(String name, String subprocessType) {
                ensureSubprocess(name);
        }
        
index ae66937764a9865af0cdc3ca3d496e7446969be8..78678b5054d95b2559ef8ff6f37bbc6f7b4650e0 100644 (file)
@@ -214,5 +214,9 @@ abstract public class MappingBase<T extends ComponentBase<T>> {
             configurationByUid.clear();
         pendingRemoval.clear();
     }
+    
+    public boolean hasPendingRemovals() {
+        return !pendingRemoval.isEmpty();
+    }
 
 }
index a3edea09e7ddc8fc89ee7d0b2b03cd4a016cf8f4..9ec63c06167846f619da56d24f939e5603d150ad 100644 (file)
@@ -19,6 +19,7 @@ abstract public class ModuleUpdaterBase<T extends ComponentBase<T>> {
             new THashMap<String, ConnectionUpdateRule<T>>();
     public boolean isUserComponent;
     public boolean isComposite;
+    public String subprocessType;
     
     public ModuleUpdaterBase(String moduleType) {
         this.moduleType = moduleType;
index a4d19283a5174a95984f21e8c22acbee5b0ff0b6..6bda544180077c80cccadef38efd8a0424857579 100644 (file)
@@ -8,7 +8,7 @@ public interface Solver {
        
        public void remove(int id);
        
-       public void addSubprocess(String name);
+       public void addSubprocess(String name, String subprocessType);
        public void includeSubprocess(String parentName, String subprocessName);
        
        public <T> T getConcreteSolver();
index d2eb50f22e30ee1a47448255bb73d98be81aa7a7..94bfbf89626bc1e1230688233dddbb0d8155d2f9 100644 (file)
@@ -1,8 +1,5 @@
 package org.simantics.structural.synchronization.base;
 
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.THashSet;
-
 import java.util.ArrayDeque;
 import java.util.Collection;
 import java.util.Collections;
@@ -19,6 +16,9 @@ import org.simantics.structural.synchronization.protocol.SerializedVariable;
 import org.simantics.structural.synchronization.protocol.SynchronizationEventHandler;
 import org.simantics.structural.synchronization.protocol.SynchronizationException;
 
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.THashSet;
+
 /**
  * Handles synchronization events by updating the simulator designated by the
  * provided {@link Solver} instance.
@@ -186,7 +186,7 @@ public abstract class SynchronizationEventHandlerBase<T extends ComponentBase<T>
                             parentSolverComponentName,
                             getSubprocessName(name, properties));
                     try {
-                       solver.addSubprocess(subprocessName);
+                       solver.addSubprocess(subprocessName, updater.subprocessType);
                     } catch(Exception e) {
                        reportProblem("Exception while adding subprocess.", e);
                     }
index d3233115254aecb5863bd31d2874241849e618a5..0c051ecef9c2445963a957adae56d5c25097239c 100644 (file)
@@ -6,12 +6,14 @@ import org.simantics.db.exception.CancelTransactionException;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.variable.Variable;
 
+import gnu.trove.map.hash.THashMap;
+
 /**
  * Utility for updating UIDs in the given component to correspond
  * the RVIs of the given variable. This operation is needed when
  * the mapping is part of a model that is imported to a new database
  * and resource ids have been changed.
- * 
+ *
  * @author Hannu Niemist&ouml;
  * @author Tuukka Lehtonen
  */
@@ -21,10 +23,11 @@ public class UpdateComponentUids<T extends ComponentBase<T>> {
         void componentsDone(int components, int componentCount);
     }
 
+    private THashMap<String, String> oldToNewUids;
     private IProgressMonitor monitor;
     private ComponentUpdateProgressMonitor componentMonitor;
     private ReadGraph graph;
-       private int componentCount;
+    private int componentCount;
     private int counter;
 
     private UpdateComponentUids(IProgressMonitor monitor, ReadGraph graph, int componentCount) {
@@ -32,10 +35,13 @@ public class UpdateComponentUids<T extends ComponentBase<T>> {
         this.componentMonitor = monitor instanceof ComponentUpdateProgressMonitor ? (ComponentUpdateProgressMonitor) monitor : null;
         this.graph = graph;
         this.componentCount = componentCount;
+        this.oldToNewUids = new THashMap<>(componentCount);
     }
 
     private void update(T component, Variable variable) throws DatabaseException {
-        component.uid = variable.getRVI(graph).toString();
+        String newUid = variable.getRVI(graph).toString();
+        oldToNewUids.put(component.uid, newUid);
+        component.uid = newUid;
 
         // Handle progress monitoring and cancellation
         counter++;
@@ -54,12 +60,14 @@ public class UpdateComponentUids<T extends ComponentBase<T>> {
         }
     }
 
-    public static <T extends ComponentBase<T>> void update(ReadGraph graph, T component, Variable variable) throws DatabaseException {
-        update(null, graph, component, variable);
+    public static <T extends ComponentBase<T>> THashMap<String, String> update(ReadGraph graph, T component, Variable variable) throws DatabaseException {
+        return update(null, graph, component, variable);
     }
 
-    public static <T extends ComponentBase<T>> void update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException {
-        new UpdateComponentUids<T>(monitor, graph, countComponents(component)).update(component, variable);
+    public static <T extends ComponentBase<T>> THashMap<String, String> update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException {
+        UpdateComponentUids<T> updateComponentUids = new UpdateComponentUids<T>(monitor, graph, countComponents(component));
+        updateComponentUids.update(component, variable);
+        return updateComponentUids.oldToNewUids;
     }
 
     public static <T extends ComponentBase<T>> int countComponents(T component) {
index e1ec2f52106cbbcfc4a0ae1d52157e8bf309702b..b33137b529b41def27aaad61d836301d8cdf361c 100644 (file)
@@ -345,9 +345,8 @@ public class ResourceEditorInput2 extends PlatformObject implements IResourceEdi
     /* (non-Javadoc)
      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
      */
-    @SuppressWarnings("rawtypes")
     @Override
-    public Object getAdapter(Class adapter) {
+    public <T> T getAdapter(Class<T> adapter) {
         //System.out.println("[ResourceEditorInput] getAdapter: " + adapter.getName());
         return null;
     }
@@ -421,7 +420,7 @@ public class ResourceEditorInput2 extends PlatformObject implements IResourceEdi
             System.out.println("update(" + this + ")");
 
         try {
-            assertExists(g);
+            //assertExists(g);
 
             name = g.syncRequest(new TitleRequest(editorID, this));
             if (name == null)
index 54a697a72422d191f601dd537ae6031ae5d78dbc..4075e1e11efaec0a6b3161db1bf9cf2b3f67bdba 100644 (file)
@@ -21,19 +21,20 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Session;
 import org.simantics.db.common.procedure.adapter.ListenerAdapter;
 import org.simantics.db.common.request.ParametrizedRead;
-import org.simantics.db.common.request.UnaryRead;
+import org.simantics.db.common.request.UniqueRead;
 import org.simantics.db.event.ChangeEvent;
 import org.simantics.db.event.ChangeListener;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.management.ISessionContext;
 import org.simantics.db.management.ISessionContextProvider;
-import org.simantics.db.request.Read;
 import org.simantics.db.service.GraphChangeListenerSupport;
 import org.simantics.ui.SimanticsUI;
 import org.simantics.utils.datastructures.map.Tuple;
 import org.simantics.utils.ui.ExceptionUtils;
 import org.simantics.utils.ui.SWTUtils;
 import org.simantics.utils.ui.workbench.WorkbenchUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A helper class for easing the attachment of a Simantics database session to
@@ -50,6 +51,9 @@ import org.simantics.utils.ui.workbench.WorkbenchUtils;
  */
 public class ResourceEditorSupport implements IAdaptable, ChangeListener {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(ResourceEditorSupport.class);
+    private static final boolean DEBUG = false;
+
     private IEditorPart                             editorPart;
 
     private ChangeListener                          editorPartChangeListener;
@@ -152,7 +156,7 @@ public class ResourceEditorSupport implements IAdaptable, ChangeListener {
             return;
 
         inputListener = new InputListener();
-        getSession().asyncRequest(validationRequest(editorPart), inputListener);
+        getSession().asyncRequest(new ValidationRequest(), inputListener);
     }
 
     public synchronized void deactivateValidation() {
@@ -161,6 +165,7 @@ public class ResourceEditorSupport implements IAdaptable, ChangeListener {
         if (inputListener == null)
             return;
         inputListener.dispose();
+        inputListener = null;
     }
 
     public ISessionContext getSessionContext() {
@@ -175,19 +180,18 @@ public class ResourceEditorSupport implements IAdaptable, ChangeListener {
         return session;
     }
 
-    @SuppressWarnings("rawtypes")
+    @SuppressWarnings("unchecked")
     @Override
-    public Object getAdapter(Class adapter) {
+    public <T> T getAdapter(Class<T> adapter) {
         if (adapter == ISessionContext.class)
-            return getSessionContext();
+            return (T) getSessionContext();
         if (adapter == Session.class)
-            return getSession();
+            return (T) getSession();
         return null;
     }
 
     @Override
     public void graphChanged(ChangeEvent e) throws DatabaseException {
-        //System.out.println(this + ": graph change: " + e);
         // Only forward the update to the editor if the input is still valid and
         // the editor implements ChangeListener
         if (editorPart instanceof ChangeListener)
@@ -225,44 +229,55 @@ public class ResourceEditorSupport implements IAdaptable, ChangeListener {
     }
 
     /**
-     * @param input
-     * @return a read request that returns <code>true</code> for valid inputs
-     *         and <code>false</code> for non-existent or invalid inputs.
+     * A read request that returns an {@link Evaluation} of the current state of
+     * <code>editorPart</code>.
+     * 
+     * <p>
+     * This request class is not static but has no parameters that could get
+     * stuck in the database client caches. UniqueRead does not need arguments
+     * and without custom hashCode/equals implementations, each instance of this
+     * request is a different one. This is exactly the behaviour we want in this
+     * case.
      */
-    private Read<Evaluation> validationRequest(IEditorPart editorPart) {
-        return new UnaryRead<IEditorPart, Evaluation>(editorPart) {
-            @Override
-            public Evaluation perform(ReadGraph graph) throws DatabaseException {
-                IEditorInput input = parameter.getEditorInput();
-                IResourceEditorInput resourceInput = getResourceInput(parameter);
-
-                //System.out.println(ResourceEditorSupport.this + ": checking input " + input);
-
-                boolean exists = true;
-                boolean valid = true;
-                if (resourceInput != null) {
-                    exists = resourceInput.exists(graph);
-                    if (exists && inputValidator != null) {
-                        valid = graph.syncRequest(inputValidator.get(resourceInput));
-                    }
-                } else {
-                    exists = input.exists();
+    private class ValidationRequest extends UniqueRead<Evaluation> {
+        @Override
+        public Evaluation perform(ReadGraph graph) throws DatabaseException {
+            IEditorPart part = editorPart;
+            if (part == null)
+                return new Evaluation(null, null, InputState.INVALID, "", "");
+
+            IEditorInput input = part.getEditorInput();
+            IResourceEditorInput resourceInput = getResourceInput(part);
+
+            if (DEBUG)
+                LOGGER.trace("ValidationRequest: checking input " + input);
+
+            boolean exists = true;
+            boolean valid = true;
+            if (resourceInput != null) {
+                exists = resourceInput.exists(graph);
+                if (exists && inputValidator != null) {
+                    valid = graph.syncRequest(inputValidator.get(resourceInput));
                 }
+            } else {
+                exists = input.exists();
+            }
 
-                InputState state = InputState.parse(exists, valid);
-                if (state == InputState.VALID) {
-                    // Make sure any cached data in the editor input is up-to-date.
+            InputState state = InputState.parse(exists, valid);
+            if (state == InputState.VALID) {
+                // Make sure any cached data in the editor input is up-to-date.
+                if (resourceInput != null)
                     resourceInput.update(graph);
-                }
-
-                Evaluation eval = new Evaluation(parameter, input, state, input.getName(), input.getToolTipText());
-                //System.out.println(ResourceEditorSupport.this + ": validation evaluation: " + eval);
-                return eval;
             }
-        };
+
+            Evaluation eval = new Evaluation(part, input, state, input.getName(), input.getToolTipText());
+            if (DEBUG)
+                LOGGER.trace("ValidationRequest: evaluation result: " + eval);
+            return eval;
+        }
     }
 
-    private class InputListener extends ListenerAdapter<Evaluation> {
+    private static class InputListener extends ListenerAdapter<Evaluation> {
 
         private boolean disposed = false;
 
@@ -272,11 +287,11 @@ public class ResourceEditorSupport implements IAdaptable, ChangeListener {
 
         @Override
         public void execute(Evaluation evaluation) {
-            //System.out.println("InputListener: " + evaluation);
+            if (DEBUG)
+                LOGGER.trace("InputListener: " + evaluation);
             switch (evaluation.getInputState()) {
                 case VALID:
                     break;
-
                 case INVALID:
                 case NON_EXISTENT:
                     scheduleEditorClose(evaluation.getEditorPart());
@@ -291,18 +306,15 @@ public class ResourceEditorSupport implements IAdaptable, ChangeListener {
 
         @Override
         public boolean isDisposed() {
-            return disposed || ResourceEditorSupport.this.isDisposed();
+            return disposed;
         }
     }
 
-    private void scheduleEditorClose(final IEditorPart editorPart) {
-        SWTUtils.asyncExec(editorPart.getSite().getShell(), new Runnable() {
-            @Override
-            public void run() {
-                // Don't have to check isDisposed since closeEditor
-                // will ignore already closed editor parts.
-                WorkbenchUtils.closeEditor(editorPart, false);
-            }
+    private static void scheduleEditorClose(IEditorPart editorPart) {
+        SWTUtils.asyncExec(editorPart.getSite().getShell(), () -> {
+            // Don't have to check isDisposed since closeEditor
+            // will ignore already closed editor parts.
+            WorkbenchUtils.closeEditor(editorPart, false);
         });
     }
 
index 4ed8abfdc45697a91c24b42ef0d410a6cc4fcb98..5537b436bf0d671bac56a88da16f7f6c107e7fce 100644 (file)
@@ -138,7 +138,6 @@ public class MultiLineInputDialog extends InputDialog {
                 GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
                 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
                 label.setLayoutData(data);
-                label.setFont(parent.getFont());
             }
             texts[i] = new Text(composite, SWT.SINGLE | SWT.BORDER);
             texts[i].setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
index 11d37e305ef2413842ae1a3cb249c582bb3491c2..be31244dae39d7383537a98bc83909f524761e77 100644 (file)
@@ -34,10 +34,18 @@ public class FormattingUtils {
     }
 
     public static Format significantDigitFormat(int withSignificantDigits) {
-        return significantDigitFormat(withSignificantDigits, false);
+        return significantDigitFormat(Locale.getDefault(Locale.Category.FORMAT), withSignificantDigits);
+    }
+
+    public static Format significantDigitFormat(Locale locale, int withSignificantDigits) {
+        return significantDigitFormat(locale, withSignificantDigits, false);
     }
 
     public static Format significantDigitFormat(int withSignificantDigits, boolean stripTrailingZeros) {
+        return significantDigitFormat(Locale.getDefault(Locale.Category.FORMAT), withSignificantDigits, stripTrailingZeros);
+    }
+
+    public static Format significantDigitFormat(Locale locale, int withSignificantDigits, boolean stripTrailingZeros) {
         if (withSignificantDigits < 1)
             throw new IllegalArgumentException("withSignificantDigits must be > 0, got " + withSignificantDigits);
         StringBuilder sb = new StringBuilder(withSignificantDigits + 3);
@@ -45,9 +53,9 @@ public class FormattingUtils {
         for (int i = 0; i < withSignificantDigits-1; i++)
             sb.append("#");
         sb.append("E0");
-        NumberFormat low = new DecimalFormat(sb.toString());
+        NumberFormat low = new DecimalFormat(sb.toString(), DecimalFormatSymbols.getInstance(locale));
         low.setGroupingUsed(false);
-        NumberFormat hi = new SignificantDigitFormat(withSignificantDigits, stripTrailingZeros);
+        NumberFormat hi = new SignificantDigitFormat(locale, withSignificantDigits, stripTrailingZeros);
         Format format = new SwitchFormat(0.1, 1, low, hi, hi);
         return format;
     }
@@ -61,10 +69,10 @@ public class FormattingUtils {
         private boolean fixDecimalSeparator;
         private char decimalSeparator;
 
-        public SignificantDigitFormat(int digits, boolean stripTrailingZeros) {
+        public SignificantDigitFormat(Locale locale, int digits, boolean stripTrailingZeros) {
             this.mc = new MathContext(digits);
             this.stripTrailingZeros = stripTrailingZeros;
-            DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance();
+            DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
             decimalSeparator = symbols.getDecimalSeparator();
             // BigDecimal always formats doubles with '.' as decimal separator.
             if (decimalSeparator != '.')