From 89ce978addfd07ed5fe44d4fae48c50ebad51ddf Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Sun, 15 Aug 2021 16:39:23 +0700 Subject: [PATCH] Correctly applies new preferences to the last workspace(s); see #3115 **WARNING** first run of this new version will forget about the workspace (whatever its scope is, global or local). --- .../src/msi/gama/application/Application.java | 79 +++-- .../ApplicationWorkbenchAdvisor.java | 86 ++--- .../workspace/PickWorkspaceDialog.java | 132 ++++---- .../workspace/WorkspacePreferences.java | 298 ++++++------------ .../preferences/GamaPreferenceStore.java | 10 +- .../src/ummisco/gama/dev/utils/FLAGS.java | 5 +- 6 files changed, 231 insertions(+), 379 deletions(-) diff --git a/msi.gama.application/src/msi/gama/application/Application.java b/msi.gama.application/src/msi/gama/application/Application.java index 882ded5830..b85e6e5946 100644 --- a/msi.gama.application/src/msi/gama/application/Application.java +++ b/msi.gama.application/src/msi/gama/application/Application.java @@ -1,8 +1,7 @@ /********************************************************************************************* * - * 'Application.java, in plugin msi.gama.application, is part of the source code of the - * GAMA modeling and simulation platform. - * (v. 1.8.1) + * 'Application.java, in plugin msi.gama.application, is part of the source code of the GAMA modeling and simulation + * platform. (v. 1.8.1) * * (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners * @@ -14,8 +13,6 @@ import static java.lang.System.setProperty; import static java.lang.Thread.setDefaultUncaughtExceptionHandler; -import static msi.gama.application.workspace.WorkspacePreferences.applyEclipsePreferences; -import static msi.gama.application.workspace.WorkspacePreferences.applyPrefs; import static msi.gama.application.workspace.WorkspacePreferences.checkWorkspaceDirectory; import static msi.gama.application.workspace.WorkspacePreferences.getLastSetWorkspaceDirectory; import static msi.gama.application.workspace.WorkspacePreferences.getSelectedWorkspaceRootLocation; @@ -30,10 +27,12 @@ import static org.eclipse.ui.PlatformUI.isWorkbenchRunning; import static org.eclipse.ui.internal.util.PrefUtil.getInternalPreferenceStore; import static org.eclipse.ui.internal.util.PrefUtil.saveInternalPrefs; + import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; + import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.app.IApplicationContext; @@ -43,6 +42,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.internal.ide.application.DelayedEventsProcessor; + import msi.gama.application.workbench.ApplicationWorkbenchAdvisor; import msi.gama.application.workspace.PickWorkspaceDialog; import msi.gama.application.workspace.WorkspaceModelsManager; @@ -61,7 +61,7 @@ public class Application implements IApplication { public static final String CLEAR_WORKSPACE = "clearWorkspace"; public static void ClearWorkspace(final boolean clear) { - getInternalPreferenceStore().setValue(CLEAR_WORKSPACE, Boolean.valueOf(clear).toString()); + getInternalPreferenceStore().setValue(CLEAR_WORKSPACE, Boolean.toString(clear)); saveInternalPrefs(); } @@ -81,7 +81,7 @@ public static class OpenDocumentEventProcessor extends DelayedEventsProcessor { @Override public void handleEvent(final Event event) { - if ( event.text != null ) { + if (event.text != null) { filesToOpen.add(event.text); DEBUG.OUT("RECEIVED FILE TO OPEN: " + event.text); } @@ -89,13 +89,12 @@ public void handleEvent(final Event event) { @Override public void catchUp(final Display display) { - if ( filesToOpen.isEmpty() ) - return; + if (filesToOpen.isEmpty()) return; final String[] filePaths = filesToOpen.toArray(new String[filesToOpen.size()]); filesToOpen.clear(); - for ( final String path : filePaths ) { + for (final String path : filePaths) { WorkspaceModelsManager.instance.openModelPassedAsArgument(path); } } @@ -103,8 +102,7 @@ public void catchUp(final Display display) { public static void createProcessor() { final Display display = Display.getDefault(); - if ( display == null ) - return; + if (display == null) return; processor = new OpenDocumentEventProcessor(display); } @@ -112,10 +110,10 @@ public static void createProcessor() { public Object start(final IApplicationContext context) throws Exception { setDefaultUncaughtExceptionHandler((t, e) -> { - if ( e instanceof OutOfMemoryError ) { + if (e instanceof OutOfMemoryError) { final boolean close = openConfirm(null, "Out of memory", - "GAMA is out of memory and will likely crash. Do you want to close now ?"); - if ( close ) { this.stop(); } + "GAMA is out of memory and will likely crash. Do you want to close now ?"); + if (close) { this.stop(); } e.printStackTrace(); } @@ -125,8 +123,7 @@ public Object start(final IApplicationContext context) throws Exception { // DEBUG.OUT(System.getProperties()); createProcessor(); final Object check = checkWorkspace(); - if ( EXIT_OK.equals(check) ) - return EXIT_OK; + if (EXIT_OK.equals(check)) return EXIT_OK; // if ( check == EXIT_RESTART ) { // ClearWorkspace(true); // No need to restart : the value will be checked later @@ -141,20 +138,19 @@ public Object start(final IApplicationContext context) throws Exception { // setProperty("org.eclipse.equinox.launcher.splash.location", splash.replace("bmp", "png")); // } final int returnCode = createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); - if ( returnCode == RETURN_RESTART ) - return EXIT_RESTART; + if (returnCode == RETURN_RESTART) return EXIT_RESTART; return EXIT_OK; } finally { - if ( display != null ) { display.dispose(); } + if (display != null) { display.dispose(); } final Location instanceLoc = Platform.getInstanceLocation(); - if ( instanceLoc != null ) { instanceLoc.release(); } + if (instanceLoc != null) { instanceLoc.release(); } } } private void checkWorkbenchXMI() { final boolean removeWorkbenchXMI = IsClearWorkspace(); - if ( removeWorkbenchXMI ) { + if (removeWorkbenchXMI) { setProperty(CLEAR_PERSISTED_STATE, "true"); ClearWorkspace(false); } @@ -163,21 +159,21 @@ private void checkWorkbenchXMI() { public static Object checkWorkspace() throws IOException, MalformedURLException { final Location instanceLoc = Platform.getInstanceLocation(); - if ( instanceLoc == null ) { + if (instanceLoc == null) { // -data @none was specified but GAMA requires a workspace openError(null, "Error", "A workspace is required to run GAMA"); return EXIT_OK; } boolean remember = false; String lastUsedWs = null; - if ( instanceLoc.isSet() ) { + if (instanceLoc.isSet()) { lastUsedWs = instanceLoc.getURL().getFile(); final String ret = WorkspacePreferences.checkWorkspaceDirectory(lastUsedWs, false, false, false); - if ( ret != null ) { + if (ret != null) { // if ( ret.equals("Restart") ) { return EXIT_RESTART; } /* If we dont or cant remember and the location is set, we cant do anything as we need a workspace */ openError(null, "Error", "The workspace provided cannot be used. Please change it"); - if ( isWorkbenchRunning() ) { getWorkbench().close(); } + if (isWorkbenchRunning()) { getWorkbench().close(); } System.exit(0); return EXIT_OK; } @@ -188,38 +184,36 @@ public static Object checkWorkspace() throws IOException, MalformedURLException /* Get the last used workspace location */ lastUsedWs = getLastSetWorkspaceDirectory(); /* If we have a "remember" but no last used workspace, it's not much to remember */ - if ( remember && (lastUsedWs == null || lastUsedWs.length() == 0) ) { remember = false; } - if ( remember ) { + if (remember && (lastUsedWs == null || lastUsedWs.length() == 0)) { remember = false; } + if (remember) { /* * If there's any problem with the workspace, force a dialog */ final String ret = checkWorkspaceDirectory(lastUsedWs, false, false, false); - // AD Added this check explicitly as the checkWorkspaceDirectory() was not supposed to return null at this stage - if ( ret != null ) { + // AD Added this check explicitly as the checkWorkspaceDirectory() was not supposed to return null at + // this stage + if (ret != null) { remember = "models".equals(ret) && !openQuestion(null, "Different version of the models library", - "The workspace contains a different version of the models library. Do you want to use another workspace ?"); + "The workspace contains a different version of the models library. Do you want to use another workspace ?"); } } } /* If we don't remember the workspace, show the dialog */ - if ( !remember ) { + if (!remember) { final int pick = new PickWorkspaceDialog().open(); /* If the user cancelled, we can't do anything as we need a workspace */ - if ( pick == 1 /* Window.CANCEL */ && getSelectedWorkspaceRootLocation() == null ) { + if (pick == 1 /* Window.CANCEL */ && getSelectedWorkspaceRootLocation() == null) { openError(null, "Error", "The application can not start without a workspace and will now exit."); System.exit(0); return IApplication.EXIT_OK; } /* Tell Eclipse what the selected location was and continue */ instanceLoc.set(new URL("file", null, getSelectedWorkspaceRootLocation()), false); - if ( applyPrefs() ) { applyEclipsePreferences(getSelectedWorkspaceRootLocation()); } - } else { - if ( !instanceLoc.isSet() ) { - /* Set the last used location and continue */ - instanceLoc.set(new URL("file", null, lastUsedWs), false); - } - + // if ( applyPrefs() ) { applyEclipsePreferences(getSelectedWorkspaceRootLocation()); } + } else if (!instanceLoc.isSet()) { + /* Set the last used location and continue */ + instanceLoc.set(new URL("file", null, lastUsedWs), false); } return null; @@ -228,11 +222,10 @@ public static Object checkWorkspace() throws IOException, MalformedURLException @Override public void stop() { final IWorkbench workbench = getWorkbench(); - if ( workbench == null ) - return; + if (workbench == null) return; final Display display = workbench.getDisplay(); display.syncExec(() -> { - if ( !display.isDisposed() ) { workbench.close(); } + if (!display.isDisposed()) { workbench.close(); } }); } diff --git a/msi.gama.application/src/msi/gama/application/workbench/ApplicationWorkbenchAdvisor.java b/msi.gama.application/src/msi/gama/application/workbench/ApplicationWorkbenchAdvisor.java index 3871f1d4ce..afcb5eb742 100644 --- a/msi.gama.application/src/msi/gama/application/workbench/ApplicationWorkbenchAdvisor.java +++ b/msi.gama.application/src/msi/gama/application/workbench/ApplicationWorkbenchAdvisor.java @@ -1,8 +1,7 @@ /********************************************************************************************* * - * 'ApplicationWorkbenchAdvisor.java, in plugin msi.gama.application, is part of the source code of the - * GAMA modeling and simulation platform. - * (v. 1.8.1) + * 'ApplicationWorkbenchAdvisor.java, in plugin msi.gama.application, is part of the source code of the GAMA modeling + * and simulation platform. (v. 1.8.1) * * (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners * @@ -12,10 +11,8 @@ **********************************************************************************************/ package msi.gama.application.workbench; -import java.io.FileOutputStream; -import java.io.IOException; import java.util.Arrays; -import org.eclipse.core.internal.runtime.Activator; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; @@ -23,10 +20,8 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IDecoratorManager; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.IWorkbenchConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchWindowAdvisor; @@ -35,14 +30,9 @@ import org.eclipse.ui.internal.ide.application.IDEWorkbenchAdvisor; import org.eclipse.ui.statushandlers.AbstractStatusHandler; import org.eclipse.ui.statushandlers.StatusAdapter; -import org.eclipse.ui.themes.IThemeManager; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; + import msi.gama.application.Application; import msi.gama.application.workspace.WorkspaceModelsManager; -import msi.gama.application.workspace.WorkspacePreferences; import msi.gama.common.interfaces.IEventLayerDelegate; import msi.gama.common.interfaces.IGui; import msi.gama.common.util.FileUtils; @@ -50,8 +40,6 @@ import msi.gama.runtime.GAMA; import msi.gama.runtime.concurrent.GamaExecutorService; import ummisco.gama.dev.utils.DEBUG; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; public class ApplicationWorkbenchAdvisor extends IDEWorkbenchAdvisor { @@ -85,7 +73,7 @@ public void initialize(final IWorkbenchConfigurer configurer) { dm.setEnabled("org.eclipse.ui.LinkedResourceDecorator", false); dm.setEnabled("org.eclipse.ui.VirtualResourceDecorator", false); dm.setEnabled("org.eclipse.xtext.builder.nature.overlay", false); - if ( Display.getCurrent() != null ) { + if (Display.getCurrent() != null) { Display.getCurrent().getThread().setUncaughtExceptionHandler(GamaExecutorService.EXCEPTION_HANDLER); } } catch (final CoreException e) { @@ -100,18 +88,15 @@ public void postStartup() { super.postStartup(); FileUtils.cleanCache(); final String[] args = Platform.getApplicationArgs(); - if ( false ) { - DEBUG.LOG("Arguments received by GAMA : " + Arrays.toString(args)); - } - if ( args.length > 0 && args[0].contains("launcher.defaultAction") - && !args[0].contains("--launcher.defaultAction") ) { + if (false) { DEBUG.LOG("Arguments received by GAMA : " + Arrays.toString(args)); } + if (args.length > 0 && args[0].contains("launcher.defaultAction") + && !args[0].contains("--launcher.defaultAction")) return; - } - if ( args.length >= 1 ) { + if (args.length >= 1) { - if ( args[args.length - 1].endsWith(".gamr") ) { - for ( final IEventLayerDelegate delegate : EventLayerStatement.delegates ) { - if ( delegate.acceptSource(null, "launcher") ) { + if (args[args.length - 1].endsWith(".gamr")) { + for (final IEventLayerDelegate delegate : EventLayerStatement.delegates) { + if (delegate.acceptSource(null, "launcher")) { delegate.createFrom(null, args[args.length - 1], null); } } @@ -126,7 +111,7 @@ protected boolean checkCopyOfBuiltInModels() { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject[] projects = workspace.getRoot().getProjects(); // If no projects are registered at all, we are facing a fresh new workspace - if ( projects.length == 0 ) { return true; } + if (projects.length == 0) return true; return false; // Following is not ready for prime time ! // // If there are projects, we must be careful to distinguish user projects from built-in projects @@ -177,7 +162,8 @@ protected boolean checkCopyOfBuiltInModels() { // .openConfirm( // Display.getDefault().getActiveShell(), // "Update the models library", - // "A new version of the built-in library of models is available. Would you like to update the ones present in the workspace?"); + // "A new version of the built-in library of models is available. Would you like to update the ones present in + // the workspace?"); // // (2) erase the built-in projects from the workspace // if ( !create ) { return false; } // for ( IProject p : builtInProjects ) { @@ -196,13 +182,13 @@ public String getInitialWindowPerspectiveId() { } /** - * A workbench pre-shutdown method calls to prompt a confirmation of the shutdown and perform a - * saving of the workspace + * A workbench pre-shutdown method calls to prompt a confirmation of the shutdown and perform a saving of the + * workspace */ @Override public boolean preShutdown() { try { - saveEclipsePreferences(); + // saveEclipsePreferences(); GAMA.closeAllExperiments(true, true); PerspectiveHelper.deleteCurrentSimulationPerspective(); // So that they are not saved to the workbench.xmi file @@ -231,24 +217,23 @@ public void preStartup() { Job.getJobManager().suspend(); // super.preStartup(); /* Linking the stock models with the workspace if they are not already */ - if ( checkCopyOfBuiltInModels() ) { - WorkspaceModelsManager.linkSampleModelsToWorkspace(); - } - - } - - private void saveEclipsePreferences() { - final IPreferencesService service = Platform.getPreferencesService(); - - try (final FileOutputStream outputStream = - new FileOutputStream(Platform.getInstanceLocation().getURL().getPath() + "/.gama.epf")) { - service.exportPreferences(service.getRootNode(), WorkspacePreferences.getPreferenceFilters(), outputStream); - } catch (final CoreException | IOException e1) {} + if (checkCopyOfBuiltInModels()) { WorkspaceModelsManager.linkSampleModelsToWorkspace(); } } + // + // private void saveEclipsePreferences() { + // final IPreferencesService service = Platform.getPreferencesService(); + // + // try (final FileOutputStream outputStream = + // new FileOutputStream(Platform.getInstanceLocation().getURL().getPath() + "/.gama.epf")) { + // service.exportPreferences(service.getRootNode(), WorkspacePreferences.getPreferenceFilters(), outputStream); + // } catch (final CoreException | IOException e1) {} + // + // } /** * Method getWorkbenchErrorHandler() + * * @see org.eclipse.ui.internal.ide.application.IDEWorkbenchAdvisor#getWorkbenchErrorHandler() */ @Override @@ -258,20 +243,17 @@ public synchronized AbstractStatusHandler getWorkbenchErrorHandler() { @Override public void handle(final StatusAdapter statusAdapter, final int style) { final int severity = statusAdapter.getStatus().getSeverity(); - if ( severity == IStatus.INFO || severity == IStatus.CANCEL ) { return; } + if (severity == IStatus.INFO || severity == IStatus.CANCEL) return; final Throwable e = statusAdapter.getStatus().getException(); - if ( e instanceof OutOfMemoryError ) { + if (e instanceof OutOfMemoryError) { GamaExecutorService.EXCEPTION_HANDLER.uncaughtException(Thread.currentThread(), e); } final String message = statusAdapter.getStatus().getMessage(); // Stupid Eclipse - if ( !message.contains("File toolbar contribution item") - && !message.contains("Duplicate template id") ) { + if (!message.contains("File toolbar contribution item") && !message.contains("Duplicate template id")) { DEBUG.OUT("GAMA Caught a workbench message : " + message); } - if ( e != null ) { - e.printStackTrace(); - } + if (e != null) { e.printStackTrace(); } } }; } diff --git a/msi.gama.application/src/msi/gama/application/workspace/PickWorkspaceDialog.java b/msi.gama.application/src/msi/gama/application/workspace/PickWorkspaceDialog.java index 78363f9979..531956d64d 100644 --- a/msi.gama.application/src/msi/gama/application/workspace/PickWorkspaceDialog.java +++ b/msi.gama.application/src/msi/gama/application/workspace/PickWorkspaceDialog.java @@ -1,9 +1,8 @@ /********************************************************************************************* * - * 'PickWorkspaceDialog.java, in plugin msi.gama.application, is part of the source code of the - * GAMA modeling and simulation platform. - * (v. 1.8.1) - * + * 'PickWorkspaceDialog.java, in plugin msi.gama.application, is part of the source code of the GAMA modeling and + * simulation platform. (v. 1.8.1) + * * (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners * * Visit https://github.com/gama-platform/gama for license information and developers contact. @@ -17,7 +16,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; + import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.MessageDialog; @@ -33,19 +34,18 @@ import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; + import com.google.common.io.Files; /** - * Dialog that lets/forces a user to enter/select a workspace that will be used - * when saving all configuration files and settings. This dialog is shown at - * startup of the GUI just after the splash screen has shown. Inspired by + * Dialog that lets/forces a user to enter/select a workspace that will be used when saving all configuration files and + * settings. This dialog is shown at startup of the GUI just after the splash screen has shown. Inspired by * http://hexapixel.com/2009/01/12/rcp-workspaces */ public class PickWorkspaceDialog extends TitleAreaDialog { /* - * This are our preferences we will be using as the IPreferenceStore is not - * available yet + * This are our preferences we will be using as the IPreferenceStore is not available yet */ // FIX: Removed the static reference in case it was causing trouble. Issue // 240. @@ -53,7 +53,7 @@ public class PickWorkspaceDialog extends TitleAreaDialog { // static Preferences preferences = Preferences.userRoot().node("gama"); /* Various dialog messages */ private static final String strMsg = - "Your workspace is where settings and files of your Gama models will be stored."; + "Your workspace is where settings and files of your Gama models will be stored."; private static final String strInfo = "Please select a directory that will be the workspace root"; private static final String strError = "You must set a directory"; @@ -126,13 +126,11 @@ protected Control createDialogArea(final Composite parent) { final String lastUsed = WorkspacePreferences.getLastUsedWorkspaces(); lastUsedWorkspaces = new ArrayList<>(); - if ( lastUsed != null ) { + if (lastUsed != null) { final String[] all = lastUsed.split(splitChar); - for ( final String str : all ) { - lastUsedWorkspaces.add(str); - } + Collections.addAll(lastUsedWorkspaces, all); } - for ( final String last : lastUsedWorkspaces ) { + for (final String last : lastUsedWorkspaces) { workspacePathCombo.add(last); } @@ -146,10 +144,8 @@ protected Control createDialogArea(final Composite parent) { dd.setMessage(strInfo); dd.setFilterPath(workspacePathCombo.getText()); final String pick = dd.open(); - if ( pick == null ) { - if ( workspacePathCombo.getText().length() == 0 ) { - setMessage(strError, IMessageProvider.ERROR); - } + if (pick == null) { + if (workspacePathCombo.getText().length() == 0) { setMessage(strError, IMessageProvider.ERROR); } } else { setMessage(strMsg); workspacePathCombo.setText(pick); @@ -173,12 +169,10 @@ public String getSelectedWorkspaceLocation() { /* Suggests a default path based on the user.home/GAMA directory location */ private String getWorkspacePathSuggestion() { - final StringBuffer buf = new StringBuffer(); + final StringBuilder buf = new StringBuilder(); String uHome = System.getProperty("user.home"); - if ( uHome == null ) { - uHome = "c:"; - } + if (uHome == null) { uHome = "c:"; } buf.append(uHome).append(File.separator).append("gama_workspace"); @@ -196,11 +190,9 @@ protected void createButtonsForButtonBar(final Composite parent) { } /** - * This function will copy files or directories from one location to - * another. note that the source and the destination must be mutually - * exclusive. This function can not be used to copy a directory to a sub - * directory of itself. The function will also have problems if the - * destination files already exist. + * This function will copy files or directories from one location to another. note that the source and the + * destination must be mutually exclusive. This function can not be used to copy a directory to a sub directory of + * itself. The function will also have problems if the destination files already exist. * * @param src * -- A File object that represents the source for the copy @@ -211,28 +203,23 @@ protected void createButtonsForButtonBar(final Composite parent) { */ public static void copyFiles(final File src, final File dest) throws IOException { /* Check to ensure that the source is valid... */ - if ( !src.exists() ) { - throw new IOException("Can not find source: " + src.getAbsolutePath()); - } else if ( !src.canRead() ) { + if (!src.exists()) throw new IOException("Can not find source: " + src.getAbsolutePath()); + if (!src.canRead()) throw new IOException("Cannot read: " + src.getAbsolutePath() + ". Check file permissions."); - } /* Is this a directory copy? */ final List noCopy = Arrays.asList("org.eclipse.core.runtime", "org.eclipse.e4.workbench", - "org.eclipse.emf.common.ui", "org.eclipse.ui.workbench", "org.eclipse.xtext.builder"); - if ( src.isDirectory() ) { - if ( noCopy.contains(src.getName()) ) { return; } + "org.eclipse.emf.common.ui", "org.eclipse.ui.workbench", "org.eclipse.xtext.builder"); + if (src.isDirectory()) { + if (noCopy.contains(src.getName())) return; /* Does the destination already exist? */ - if ( !dest.exists() ) { - /* If not we need to make it exist if possible */ - if ( !dest.mkdirs() ) { - throw new IOException("Could not create direcotry: " + dest.getAbsolutePath()); - } - } + /* If not we need to make it exist if possible */ + if (!dest.exists() && !dest.mkdirs()) + throw new IOException("Could not create direcotry: " + dest.getAbsolutePath()); /* Get a listing of files... */ final String list[] = src.list(); /* Copy all the files in the list. */ - if ( list != null ) { - for ( final String element : list ) { + if (list != null) { + for (final String element : list) { final File dest1 = new File(dest, element); final File src1 = new File(src, element); copyFiles(src1, dest1); @@ -246,16 +233,16 @@ public static void copyFiles(final File src, final File dest) throws IOException protected void cloneCurrentWorkspace() { final String currentLocation = WorkspacePreferences.getLastSetWorkspaceDirectory(); - if ( currentLocation == null || currentLocation.isEmpty() ) { + if (currentLocation == null || currentLocation.isEmpty()) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", - "No current workspace exists. Can only clone from an existing workspace"); + "No current workspace exists. Can only clone from an existing workspace"); return; } final String newLocation = workspacePathCombo.getText(); // Fixes Issue #2848 - if ( newLocation.startsWith(currentLocation) ) { + if (newLocation.startsWith(currentLocation)) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", - "The path entered is either that of the current wokspace or of a subdirectory of it. Neither can be used as a destination."); + "The path entered is either that of the current wokspace or of a subdirectory of it. Neither can be used as a destination."); return; } cloning = true; @@ -270,13 +257,13 @@ protected void cloneCurrentWorkspace() { protected void okPressed() { final String str = workspacePathCombo.getText(); // scope.getGui().debug("Directory to create " + str); - if ( str.length() == 0 ) { + if (str.length() == 0) { setMessage(strError, IMessageProvider.ERROR); return; } final String ret = WorkspacePreferences.checkWorkspaceDirectory(str, true, true, cloning); - if ( ret != null ) { + if (ret != null) { setMessage(ret, IMessageProvider.ERROR); return; } @@ -284,14 +271,12 @@ protected void okPressed() { /* Save it so we can show it in combo later */ lastUsedWorkspaces.remove(str); - if ( !lastUsedWorkspaces.contains(str) ) { - lastUsedWorkspaces.add(0, str); - } + if (!lastUsedWorkspaces.contains(str)) { lastUsedWorkspaces.add(0, str); } /* Deal with the max history */ - if ( lastUsedWorkspaces.size() > maxHistory ) { + if (lastUsedWorkspaces.size() > maxHistory) { final List remove = new ArrayList<>(); - for ( int i = maxHistory; i < lastUsedWorkspaces.size(); i++ ) { + for (int i = maxHistory; i < lastUsedWorkspaces.size(); i++) { remove.add(lastUsedWorkspaces.get(i)); } @@ -299,12 +284,10 @@ protected void okPressed() { } /* Create a string concatenation of all our last used workspaces */ - final StringBuffer buf = new StringBuffer(); - for ( int i = 0; i < lastUsedWorkspaces.size(); i++ ) { + final StringBuilder buf = new StringBuilder(); + for (int i = 0; i < lastUsedWorkspaces.size(); i++) { buf.append(lastUsedWorkspaces.get(i)); - if ( i != lastUsedWorkspaces.size() - 1 ) { - buf.append(splitChar); - } + if (i != lastUsedWorkspaces.size() - 1) { buf.append(splitChar); } } /* Save them onto our preferences */ @@ -313,7 +296,7 @@ protected void okPressed() { /* Now create it */ final boolean ok = checkAndCreateWorkspaceRoot(str); - if ( !ok ) { + if (!ok) { // scope.getGui().debug("Problem creating " + str); setMessage("No workspace could be created at location " + str + ", please check the error log"); return; @@ -324,27 +307,27 @@ protected void okPressed() { /* And on our preferences as well */ // scope.getGui().debug("Writing " + str + " in the preferences"); - if ( cloning ) { + if (cloning) { final String previousLocation = WorkspacePreferences.getLastSetWorkspaceDirectory(); File workspaceDirectory = new File(previousLocation); - if ( !workspaceDirectory.exists() || previousLocation.equals(str) ) { + if (!workspaceDirectory.exists() || previousLocation.equals(str)) { final DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN); dialog.setText("Choose an existing workspace"); final String result = dialog.open(); - if ( result != null ) { + if (result != null) { workspaceDirectory = new File(result); } else { workspaceDirectory = null; } } - if ( workspaceDirectory != null ) { + if (workspaceDirectory != null) { final File targetDirectory = new File(str); try { copyFiles(workspaceDirectory, targetDirectory); - WorkspacePreferences.setApplyPrefs(true); + // WorkspacePreferences.setApplyPrefs(true); } catch (final Exception err) { MessageDialog.openError(Display.getDefault().getActiveShell(), "Error", - "There was an error cloning the workspace: " + err.getMessage()); + "There was an error cloning the workspace: " + err.getMessage()); return; } @@ -356,26 +339,23 @@ protected void okPressed() { } /** - * Checks to see if a workspace exists at a given directory string, and if - * not, creates it. Also puts our identifying file inside that workspace. + * Checks to see if a workspace exists at a given directory string, and if not, creates it. Also puts our + * identifying file inside that workspace. * * @param wsRoot * Workspace root directory as string - * @return true if all checks and creations succeeded, false if there was a - * problem + * @return true if all checks and creations succeeded, false if there was a problem */ public static boolean checkAndCreateWorkspaceRoot(final String wsRoot) { try { final File fRoot = new File(wsRoot); - if ( !fRoot.exists() ) { - // scope.getGui().debug("Folder " + wsRoot + " does not exist"); + if (!fRoot.exists()) // scope.getGui().debug("Folder " + wsRoot + " does not exist"); return false; - } - File dotFile = new File(wsRoot + File.separator + WorkspacePreferences.WS_IDENTIFIER); - if ( !dotFile.exists() ) { + File dotFile = new File(wsRoot + File.separator + WorkspacePreferences.WORKSPACE_IDENTIFIER); + if (!dotFile.exists()) { final boolean created = dotFile.createNewFile(); - if ( !created ) { return false; } + if (!created) return false; dotFile = new File(wsRoot + File.separator + WorkspacePreferences.getModelIdentifier()); dotFile.createNewFile(); } diff --git a/msi.gama.application/src/msi/gama/application/workspace/WorkspacePreferences.java b/msi.gama.application/src/msi/gama/application/workspace/WorkspacePreferences.java index 413f67259c..d464b3dc44 100644 --- a/msi.gama.application/src/msi/gama/application/workspace/WorkspacePreferences.java +++ b/msi.gama.application/src/msi/gama/application/workspace/WorkspacePreferences.java @@ -1,8 +1,7 @@ /********************************************************************************************* * - * 'WorkspacePreferences.java, in plugin msi.gama.application, is part of the source code of the - * GAMA modeling and simulation platform. - * (v. 1.8.1) + * 'WorkspacePreferences.java, in plugin msi.gama.application, is part of the source code of the GAMA modeling and + * simulation platform. (v. 1.8.1) * * (c) 2007-2020 UMI 209 UMMISCO IRD/UPMC & Partners * @@ -12,90 +11,52 @@ **********************************************************************************************/ package msi.gama.application.workspace; +import static msi.gama.common.preferences.GamaPreferenceStore.getStore; + import java.io.File; import java.io.FileFilter; -import java.io.FileInputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.Map; -import java.util.prefs.BackingStoreException; -import java.util.prefs.Preferences; -import org.eclipse.core.runtime.CoreException; + import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.IExportedPreferences; -import org.eclipse.core.runtime.preferences.IPreferenceFilter; -import org.eclipse.core.runtime.preferences.IPreferencesService; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.core.runtime.preferences.PreferenceFilterEntry; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Display; + import msi.gama.application.Application; -import msi.gama.common.preferences.GamaPreferences; import ummisco.gama.dev.utils.DEBUG; public class WorkspacePreferences { - static { - GamaPreferences.Interface.CORE_ASK_REBUILD.onChange(v -> askBeforeRebuildingWorkspace(v)); - GamaPreferences.Interface.CORE_ASK_OUTDATED.onChange(v -> askBeforeUsingOutdatedWorkspace(v)); - } - - /* - * The name of the file that tells us that the workspace directory belongs - * to our application - */ - - private static final String keyWorkspaceRootDir = "wsRootDir"; - private static final String keyRememberWorkspace = "wsRemember"; - private static final String keyLastUsedWorkspaces = "wsLastUsedWorkspaces"; - private static final String keyAskForRebuilding = "wsAskRebuildingWorkspace"; - private static final String keyAskForOutdated = "wsAskOutdatedWorkspace"; - - public static Preferences getNode() { - try { - if ( Preferences.userRoot().nodeExists("gama") ) { return Preferences.userRoot().node("gama"); } - } catch (final BackingStoreException e1) { - e1.printStackTrace(); - } - final Preferences p = Preferences.userRoot().node("gama"); - try { - p.flush(); - } catch (final BackingStoreException e) { - e.printStackTrace(); - } - return p; - } + private static final String KEY_WORSPACE_PATH = "pref_workspace_path"; + private static final String KEY_WORKSPACE_REMEMBER = "pref_workspace_remember"; + private static final String KEY_WORKSPACE_LIST = "pref_workspace_list"; + private static final String KEY_ASK_REBUILD = "pref_ask_rebuild"; + private static final String KEY_ASK_OUTDATED = "pref_ask_outdated"; + public static final String WORKSPACE_IDENTIFIER = ".gama_application_workspace"; + private static String MODEL_IDENTIFIER = null; - private static void flush() { - try { - getNode().flush(); - } catch (final BackingStoreException e) { - e.printStackTrace(); - } - } + static String selectedWorkspaceRootLocation; /** * Returns whether the user selected "remember workspace" in the preferences */ public static boolean isRememberWorkspace() { - return getNode().getBoolean(keyRememberWorkspace, false); + return getStore().getBoolean(KEY_WORKSPACE_REMEMBER, false); } public static void isRememberWorkspace(final boolean remember) { - getNode().putBoolean(keyRememberWorkspace, remember); - flush(); + getStore().putBoolean(KEY_WORKSPACE_REMEMBER, remember); } public static String getLastUsedWorkspaces() { - return getNode().get(keyLastUsedWorkspaces, ""); + return getStore().get(KEY_WORKSPACE_LIST, ""); } public static void setLastUsedWorkspaces(final String used) { - getNode().put(keyLastUsedWorkspaces, used); - flush(); + getStore().put(KEY_WORKSPACE_LIST, used); } /** @@ -104,42 +65,33 @@ public static void setLastUsedWorkspaces(final String used) { * @return null if none */ public static String getLastSetWorkspaceDirectory() { - return getNode().get(keyWorkspaceRootDir, ""); + return getStore().get(KEY_WORSPACE_PATH, ""); } public static void setLastSetWorkspaceDirectory(final String last) { - getNode().put(keyWorkspaceRootDir, last); - flush(); + getStore().put(KEY_WORSPACE_PATH, last); } public static boolean askBeforeRebuildingWorkspace() { // true by default - return getNode().getBoolean(keyAskForRebuilding, true); + return getStore().getBoolean(KEY_ASK_REBUILD, true); } public static void askBeforeRebuildingWorkspace(final boolean ask) { // true by default - getNode().putBoolean(keyAskForRebuilding, ask); - flush(); + getStore().putBoolean(KEY_ASK_REBUILD, ask); } public static boolean askBeforeUsingOutdatedWorkspace() { // true by default - return getNode().getBoolean(keyAskForOutdated, true); + return getStore().getBoolean(KEY_ASK_OUTDATED, true); } public static void askBeforeUsingOutdatedWorkspace(final boolean ask) { // true by default - getNode().putBoolean(keyAskForOutdated, ask); - flush(); + getStore().putBoolean(KEY_ASK_OUTDATED, ask); } - // static String lastWs; - static String selectedWorkspaceRootLocation; - static boolean applyPrefs; - public static final String WS_IDENTIFIER = ".gama_application_workspace"; - private static String MODEL_IDENTIFIER = null; - public static String getSelectedWorkspaceRootLocation() { return selectedWorkspaceRootLocation; } @@ -162,8 +114,8 @@ public static String getCurrentGamaStampString() { final long time = modelsRep.lastModified(); gamaStamp = ".built_in_models_" + time; - DEBUG.OUT( - ">GAMA version " + Platform.getProduct().getDefiningBundle().getVersion().toString() + " loading..."); + DEBUG.OUT(">GAMA version " + Platform.getProduct().getDefiningBundle().getVersion().toString() + + " loading..."); DEBUG.OUT(">GAMA models library version: " + gamaStamp); } catch (final IOException | URISyntaxException e) { e.printStackTrace(); @@ -171,144 +123,83 @@ public static String getCurrentGamaStampString() { return gamaStamp; } - public static IPreferenceFilter[] getPreferenceFilters() { - final IPreferenceFilter[] transfers = new IPreferenceFilter[1]; - - // For export all create a preference filter that can export - // all nodes of the Instance and Configuration scopes - transfers[0] = new IPreferenceFilter() { - - @Override - public String[] getScopes() { - return new String[] { InstanceScope.SCOPE }; - } - - @Override - public Map getMapping(final String scope) { - return null; - } - }; - - return transfers; - } - - public static boolean applyPrefs() { - return applyPrefs; - } - - public static void setApplyPrefs(final boolean b) { - applyPrefs = b; - } - - public static void applyEclipsePreferences(final String targetDirectory) { - final IPreferencesService service = Platform.getPreferencesService(); - IExportedPreferences prefs; - - try (FileInputStream input = new FileInputStream(new File(targetDirectory + "/.gama.epf"))) { - prefs = service.readPreferences(input); - service.applyPreferences(prefs, getPreferenceFilters()); - } catch (final IOException e) {} catch (final CoreException e) {} - setApplyPrefs(false); - - } - /** - * Ensures a workspace directory is OK in regards of reading/writing, etc. - * This method will get called externally as well. + * Ensures a workspace directory is OK in regards of reading/writing, etc. This method will get called externally as + * well. * * @param parentShell * Shell parent shell * @param workspaceLocation * Directory the user wants to use * @param askCreate - * Whether to ask if to create the workspace or not in this - * location if it does not exist already + * Whether to ask if to create the workspace or not in this location if it does not exist already * @param fromDialog - * Whether this method was called from our dialog or from - * somewhere else just to check a location + * Whether this method was called from our dialog or from somewhere else just to check a location * @return null if everything is ok, or an error message if not */ public static String checkWorkspaceDirectory(final String workspaceLocation, final boolean askCreate, - final boolean fromDialog, final boolean cloning) { + final boolean fromDialog, final boolean cloning) { final File f = new File(workspaceLocation); - if ( !f.exists() ) { - if ( askCreate ) { - final boolean create = - MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "New Directory", - workspaceLocation + " does not exist. Would you like to create a new workspace here" + - (cloning ? ", copy the projects and preferences of your current workspace into it, " : "") + - " and proceeed ?"); - if ( create ) { - try { - f.mkdirs(); - final File wsDot = new File(workspaceLocation + File.separator + WS_IDENTIFIER); - wsDot.createNewFile(); - final File dotFile = new File(workspaceLocation + File.separator + getModelIdentifier()); - dotFile.createNewFile(); - } catch (final RuntimeException err) { - err.printStackTrace(); - return "Error creating directories, please check folder permissions"; - } catch (final IOException er) { - er.printStackTrace(); - return "Error creating directories, please check folder permissions"; - } - } - - if ( !f.exists() ) { - return "The selected directory does not exist"; - } else { - return null; + if (!f.exists() && askCreate) { + final boolean create = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "New Directory", + workspaceLocation + " does not exist. Would you like to create a new workspace here" + + (cloning ? ", copy the projects and preferences of your current workspace into it, " : "") + + " and proceeed ?"); + if (create) { + try { + f.mkdirs(); + final File wsDot = new File(workspaceLocation + File.separator + WORKSPACE_IDENTIFIER); + wsDot.createNewFile(); + final File dotFile = new File(workspaceLocation + File.separator + getModelIdentifier()); + dotFile.createNewFile(); + } catch (final RuntimeException | IOException er) { + er.printStackTrace(); + return "Error creating directories, please check folder permissions"; } } + + if (!f.exists()) return "The selected directory does not exist"; + return null; } - if ( !f.canRead() ) { - // scope.getGui().debug("The selected directory is not readable"); + if (!f.canRead()) // scope.getGui().debug("The selected directory is not readable"); return "The selected directory is not readable"; - } - if ( !f.isDirectory() ) { - // scope.getGui().debug("The selected path is not a directory"); + if (!f.isDirectory()) // scope.getGui().debug("The selected path is not a directory"); return "The selected path is not a directory"; - } testWorkspaceSanity(f); - final File wsTest = new File(workspaceLocation + File.separator + WS_IDENTIFIER); - if ( fromDialog ) { - if ( !wsTest.exists() ) { + final File wsTest = new File(workspaceLocation + File.separator + WORKSPACE_IDENTIFIER); + if (fromDialog) { + if (!wsTest.exists()) { final boolean create = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), - "New Workspace", "The directory '" + wsTest.getAbsolutePath() + - "' exists but is not identified as a GAMA workspace. \n\nWould you like to use it anyway ?"); - if ( create ) { - try { - f.mkdirs(); - final File wsDot = new File(workspaceLocation + File.separator + WS_IDENTIFIER); - wsDot.createNewFile(); - } catch (final Exception err) { - return "Error creating directories, please check folder permissions"; - } - } else { - return "Please select a directory for your workspace"; + "New Workspace", "The directory '" + wsTest.getAbsolutePath() + + "' exists but is not identified as a GAMA workspace. \n\nWould you like to use it anyway ?"); + if (!create) return "Please select a directory for your workspace"; + try { + f.mkdirs(); + final File wsDot = new File(workspaceLocation + File.separator + WORKSPACE_IDENTIFIER); + wsDot.createNewFile(); + } catch (final Exception err) { + return "Error creating directories, please check folder permissions"; } - if ( !wsTest.exists() ) { return "The selected directory does not exist"; } + if (!wsTest.exists()) return "The selected directory does not exist"; return null; } - } else { - if ( !wsTest.exists() ) { return "The selected directory is not a workspace directory"; } - } + } else if (!wsTest.exists()) return "The selected directory is not a workspace directory"; final File dotFile = new File(workspaceLocation + File.separator + getModelIdentifier()); - if ( !dotFile.exists() ) { - if ( fromDialog ) { + if (!dotFile.exists()) { + if (fromDialog) { boolean create = true; - if ( askBeforeUsingOutdatedWorkspace() ) { + if (askBeforeUsingOutdatedWorkspace()) { create = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), - "Different version of the models library", - "The workspace contains a different version of the models library. Do you want to proceed anyway ?"); + "Different version of the models library", + "The workspace contains a different version of the models library. Do you want to proceed anyway ?"); } - if ( create ) { + if (create) { try { dotFile.createNewFile(); } catch (final IOException e) { @@ -319,44 +210,43 @@ public static String checkWorkspaceDirectory(final String workspaceLocation, fin } return "models"; - } else if ( cloning ) { + } + if (cloning) { final boolean b = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Existing workspace", - "The path entered is a path to an existing workspace. All its contents will be erased and replaced by the current workspace contents. Proceed anyway ?"); - if ( !b ) { return ""; } + "The path entered is a path to an existing workspace. All its contents will be erased and replaced by the current workspace contents. Proceed anyway ?"); + if (!b) return ""; } return null; } public static boolean testWorkspaceSanity(final File workspace) { DEBUG.OUT("[GAMA] Checking for workspace sanity"); - File[] files = workspace.listFiles((FileFilter) file -> file.getName().equals(".metadata")); - if ( files == null || files.length == 0 ) { return true; } + File[] files = workspace.listFiles((FileFilter) file -> ".metadata".equals(file.getName())); + if (files == null || files.length == 0) return true; final File[] logs = files[0].listFiles((FileFilter) file -> file.getName().contains(".log")); - if ( logs != null ) { - for ( final File log : logs ) { + if (logs != null) { + for (final File log : logs) { log.delete(); } } - files = files[0].listFiles((FileFilter) file -> file.getName().equals(".plugins")); - if ( files == null ) { return false; } - if ( files.length == 0 ) { return true; } - files = files[0].listFiles((FileFilter) file -> file.getName().equals("org.eclipse.core.resources")); - if ( files == null ) { return false; } - if ( files.length == 0 ) { return true; } + files = files[0].listFiles((FileFilter) file -> ".plugins".equals(file.getName())); + if (files == null) return false; + if (files.length == 0) return true; + files = files[0].listFiles((FileFilter) file -> "org.eclipse.core.resources".equals(file.getName())); + if (files == null) return false; + if (files.length == 0) return true; files = files[0].listFiles((FileFilter) file -> file.getName().contains("snap")); - if ( files == null ) { return false; } + if (files == null) return false; DEBUG.OUT("[GAMA] Workspace appears to be " + (files.length == 0 ? "clean" : "corrupted")); - if ( files.length == 0 ) { return true; } + if (files.length == 0) return true; boolean rebuild = true; - if ( askBeforeRebuildingWorkspace() ) { + if (askBeforeRebuildingWorkspace()) { rebuild = MessageDialog.openQuestion(Display.getDefault().getActiveShell(), "Corrupted workspace", - "The workspace appears to be corrupted (due to a previous crash) or it is currently used by another instance of the platform. Would you like GAMA to clean it ?"); + "The workspace appears to be corrupted (due to a previous crash) or it is currently used by another instance of the platform. Would you like GAMA to clean it ?"); } - if ( rebuild ) { - for ( final File file : files ) { - if ( file.exists() ) { - file.delete(); - } + if (rebuild) { + for (final File file : files) { + if (file.exists()) { file.delete(); } } Application.ClearWorkspace(true); return false; @@ -365,9 +255,7 @@ public static boolean testWorkspaceSanity(final File workspace) { } public static String getModelIdentifier() { - if ( MODEL_IDENTIFIER == null ) { - MODEL_IDENTIFIER = getCurrentGamaStampString(); - } + if (MODEL_IDENTIFIER == null) { MODEL_IDENTIFIER = getCurrentGamaStampString(); } return MODEL_IDENTIFIER; } diff --git a/msi.gama.core/src/msi/gama/common/preferences/GamaPreferenceStore.java b/msi.gama.core/src/msi/gama/common/preferences/GamaPreferenceStore.java index d4db8fe6eb..4b98f0d0f8 100644 --- a/msi.gama.core/src/msi/gama/common/preferences/GamaPreferenceStore.java +++ b/msi.gama.core/src/msi/gama/common/preferences/GamaPreferenceStore.java @@ -44,7 +44,7 @@ * @param */ @SuppressWarnings ({ "restriction", "unchecked", "rawtypes" }) -abstract class GamaPreferenceStore { +public abstract class GamaPreferenceStore { static { // DEBUG.ON(); @@ -84,21 +84,25 @@ protected List computeKeys() { @Override public void put(final String key, final String value) { store.put(key, value); + flush(); } @Override public void putInt(final String key, final int value) { store.putInt(key, value); + flush(); } @Override public void putDouble(final String key, final Double value) { store.putDouble(key, value); + flush(); } @Override public void putBoolean(final String key, final Boolean value) { store.putBoolean(key, value); + flush(); } @Override @@ -182,21 +186,25 @@ protected List computeKeys() { @Override public void put(final String key, final String value) { store.put(key, value); + flush(); } @Override public void putInt(final String key, final int value) { store.putInt(key, value); + flush(); } @Override public void putDouble(final String key, final Double value) { store.putDouble(key, value); + flush(); } @Override public void putBoolean(final String key, final Boolean value) { store.putBoolean(key, value); + flush(); } @Override diff --git a/ummisco.gama.annotations/src/ummisco/gama/dev/utils/FLAGS.java b/ummisco.gama.annotations/src/ummisco/gama/dev/utils/FLAGS.java index de2554d1c7..808cd65110 100644 --- a/ummisco.gama.annotations/src/ummisco/gama/dev/utils/FLAGS.java +++ b/ummisco.gama.annotations/src/ummisco/gama/dev/utils/FLAGS.java @@ -6,7 +6,8 @@ * turned into preferences at some point. * * Use -Dflag=true/false in your VM arguments in run configurations (or in the arguments passed to your VM in gama.ini) - * to change this default value (e.g. -Denable_logging=false) + * to change this default value (e.g. -Denable_logging=false). Note that preferences can also be set as system + * properties using the same syntax * * * @author A. Drogoul Aug. 2021 @@ -54,7 +55,7 @@ private static boolean get(final String name, final boolean def) { public static final boolean USE_GLOBAL_PREFERENCE_STORE = get("use_global_preference_store", true); /** - * Used in DEBUG, set to true to enable logging activities (which will follow the declaration ofD EBUG.ON() on the + * Used in DEBUG, set to true to enable logging activities (which will follow the declaration of DEBUG.ON() on the * classes). Set to false to suppress all logging. True by default */ public static final boolean ENABLE_LOGGING = get("enable_logging", true);