From: Tuukka Lehtonen Date: Mon, 9 Jan 2017 09:16:21 +0000 (+0200) Subject: Merge "Cluster sets are written to wrong directory until first snapshot is made" X-Git-Tag: v1.27.0~32 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=81169c54002f4a9f89db5b6821f3e5a70dad2da7;hp=dc4ea7660e4a7fe9e9f8d0f23cdd53de9968b104;p=simantics%2Fplatform.git Merge "Cluster sets are written to wrong directory until first snapshot is made" --- diff --git a/bundles/org.simantics.acorn/META-INF/MANIFEST.MF b/bundles/org.simantics.acorn/META-INF/MANIFEST.MF index 9152acafd..28c851cb0 100644 --- a/bundles/org.simantics.acorn/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.acorn/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java index b2a30953c..c414dd2b6 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java @@ -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 currentChanges = new ArrayList(); @@ -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)) { diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java index 5726b5130..cc978e7e8 100644 --- a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java +++ b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/NatTableGraphExplorer.java @@ -1517,10 +1517,14 @@ public class NatTableGraphExplorer extends GraphExplorerImplBase implements Grap columnAccessor = new GEColumnAccessor(this); IDataProvider dataProvider = new ListDataProvider(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); diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java index 407fbff3b..713b28297 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultExplorerSelectionListener.java @@ -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) diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerViewBase.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerViewBase.java index 72307b32f..4b1d8ffef 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerViewBase.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/GraphExplorerViewBase.java @@ -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 getAdapter(Class 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); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityInstances.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityInstances.java index ef5acc97b..488545c5f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityInstances.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/EntityInstances.java @@ -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() { diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OntologiesFromLibrary.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OntologiesFromLibrary.java index c715a6401..774c6465a 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OntologiesFromLibrary.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/migration/OntologiesFromLibrary.java @@ -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> { @@ -32,12 +33,20 @@ public class OntologiesFromLibrary extends ResourceRead> { Layer0 L0 = Layer0.getInstance(graph); ArrayList result = new ArrayList(); 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; + } + } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java index 53df7072c..2baadba19 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/RemoverUtil.java @@ -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(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 rs, List removers) throws DatabaseException { if (removers == null) - removers = new ArrayList(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 aux = new HashMap(); - List errors = new ArrayList(2); + Map aux = new HashMap<>(); + List 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 removers = new ArrayList(rs.size()); + List 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 principalTypes = null; - for (Resource r : rs) { - Collection 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 differentTypes = new HashSet(); - Set typeNames = new TreeSet(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 removers = new ArrayList(); - Map removedResources = new HashMap(); + List removers = new ArrayList<>(); + Map 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 aux = new HashMap(); - List errors = new ArrayList(removers.size()); + Map aux = new HashMap<>(); + List errors = new ArrayList<>(removers.size()); for (Remover remover : removers) { String error = remover.canRemove(graph, aux); if (error != null) diff --git a/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF b/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF index 20c651f5c..f21b3e776 100644 --- a/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.graph.db/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java index edcbc51d8..bdfd3de6e 100644 --- a/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java +++ b/bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java @@ -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 { diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/AbstractCommandConsole.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/AbstractCommandConsole.java index b4260b47b..bd011689f 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/AbstractCommandConsole.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/console/AbstractCommandConsole.java @@ -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( - 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( + commandHistory.subList(COMMAND_HISTORY_SIZE, COMMAND_HISTORY_SIZE*2)); + } commandHistoryPos = commandHistory.size(); // Print it into output area diff --git a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java index b41e9c754..277b10cb0 100644 --- a/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java +++ b/bundles/org.simantics.spreadsheet.graph/src/org/simantics/spreadsheet/graph/SpreadsheetBook.java @@ -316,7 +316,7 @@ public class SpreadsheetBook implements SpreadsheetElement> { configurationByUid.clear(); pendingRemoval.clear(); } + + public boolean hasPendingRemovals() { + return !pendingRemoval.isEmpty(); + } } diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java index a3edea09e..9ec63c061 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/ModuleUpdaterBase.java @@ -19,6 +19,7 @@ abstract public class ModuleUpdaterBase> { new THashMap>(); public boolean isUserComponent; public boolean isComposite; + public String subprocessType; public ModuleUpdaterBase(String moduleType) { this.moduleType = moduleType; diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/Solver.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/Solver.java index a4d19283a..6bda54418 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/Solver.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/Solver.java @@ -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 getConcreteSolver(); diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java index d2eb50f22..94bfbf896 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/SynchronizationEventHandlerBase.java @@ -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 parentSolverComponentName, getSubprocessName(name, properties)); try { - solver.addSubprocess(subprocessName); + solver.addSubprocess(subprocessName, updater.subprocessType); } catch(Exception e) { reportProblem("Exception while adding subprocess.", e); } diff --git a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java index d32331152..0c051ecef 100644 --- a/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java +++ b/bundles/org.simantics.structural.synchronization.client/src/org/simantics/structural/synchronization/base/UpdateComponentUids.java @@ -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ö * @author Tuukka Lehtonen */ @@ -21,10 +23,11 @@ public class UpdateComponentUids> { void componentsDone(int components, int componentCount); } + private THashMap 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> { 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> { } } - public static > void update(ReadGraph graph, T component, Variable variable) throws DatabaseException { - update(null, graph, component, variable); + public static > THashMap update(ReadGraph graph, T component, Variable variable) throws DatabaseException { + return update(null, graph, component, variable); } - public static > void update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException { - new UpdateComponentUids(monitor, graph, countComponents(component)).update(component, variable); + public static > THashMap update(IProgressMonitor monitor, ReadGraph graph, T component, Variable variable) throws DatabaseException { + UpdateComponentUids updateComponentUids = new UpdateComponentUids(monitor, graph, countComponents(component)); + updateComponentUids.update(component, variable); + return updateComponentUids.oldToNewUids; } public static > int countComponents(T component) { diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java index e1ec2f521..b33137b52 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorInput2.java @@ -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 getAdapter(Class 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) diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorSupport.java b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorSupport.java index 54a697a72..4075e1e11 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorSupport.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/workbench/ResourceEditorSupport.java @@ -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 getAdapter(Class 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 true for valid inputs - * and false for non-existent or invalid inputs. + * A read request that returns an {@link Evaluation} of the current state of + * editorPart. + * + *

+ * 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 validationRequest(IEditorPart editorPart) { - return new UnaryRead(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 { + @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 { + private static class InputListener extends ListenerAdapter { 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); }); } diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/MultiLineInputDialog.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/MultiLineInputDialog.java index 4ed8abfdc..5537b436b 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/MultiLineInputDialog.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/dialogs/MultiLineInputDialog.java @@ -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)); diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java b/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java index 11d37e305..be31244da 100644 --- a/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java +++ b/bundles/org.simantics.utils/src/org/simantics/utils/format/FormattingUtils.java @@ -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 != '.')