Permalink
Browse files

Follow-up of the previous commit

Signed-off-by: AlexisDrogoul <alexis.drogoul@gmail.com>
  • Loading branch information...
1 parent a44d570 commit 81580f88b966060e9e24f49b6ab9ce12fb4ff99a @AlexisDrogoul AlexisDrogoul committed Dec 5, 2016
@@ -12,6 +12,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
+import java.util.Map;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -24,6 +25,7 @@
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.internal.ide.AboutInfo;
import org.eclipse.ui.internal.ide.application.IDEWorkbenchAdvisor;
import org.eclipse.ui.statushandlers.AbstractStatusHandler;
import org.eclipse.ui.statushandlers.StatusAdapter;
@@ -61,11 +63,6 @@ public void initialize(final IWorkbenchConfigurer configurer) {
e.printStackTrace();
}
- /* Linking the stock models with the workspace if they are not already */
- if ( checkCopyOfBuiltInModels() ) {
- WorkspaceModelsManager.linkSampleModelsToWorkspace();
- }
-
}
@Override
@@ -81,6 +78,7 @@ public void postStartup() {
}
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
@@ -170,6 +168,27 @@ public boolean preShutdown() {
}
+ @Override
+ public void preStartup() {
+ super.preStartup();
+ /* Linking the stock models with the workspace if they are not already */
+ if ( checkCopyOfBuiltInModels() ) {
+ WorkspaceModelsManager.linkSampleModelsToWorkspace();
+ }
+ }
+
+ @Override
+ public Map<String, AboutInfo> getNewlyAddedBundleGroups() {
+ // TODO Auto-generated method stub
+ return super.getNewlyAddedBundleGroups();
+ }
+
+ @Override
+ public boolean openWindows() {
+ // TODO Auto-generated method stub
+ return super.openWindows();
+ }
+
private void saveEclipsePreferences() {
final IPreferencesService service = Platform.getPreferencesService();
@@ -37,12 +37,15 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.equinox.internal.app.CommandLineArgs;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
@@ -413,8 +416,29 @@ private static void linkPluginsModelsToWorkspace() {
}
public static void linkSampleModelsToWorkspace() {
- linkModelsToWorkspace("msi.gama.models", "models", true);
- linkPluginsModelsToWorkspace();
+ final Job job = new Job("Updating the Built-in Models Library") {
+
+ @Override
+ protected IStatus run(final IProgressMonitor monitor) {
+ // Nothing to do really. Maybe a later version will remove this
+ // command. See Issue 669
+ while (!GamaBundleLoader.LOADED) {
+ try {
+ Thread.sleep(100);
+ } catch (final InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ linkModelsToWorkspace("msi.gama.models", "models", true);
+ linkPluginsModelsToWorkspace();
+ return Status.OK_STATUS;
+ }
+
+ };
+ job.setUser(true);
+ job.schedule();
+
}
/**
@@ -453,7 +477,8 @@ private static void linkModelsToWorkspace(final String plugin, final String path
findProjects(modelsRep, foundProjects);
importBuiltInProjects(plugin, core, workspace, foundProjects);
- stampWorkspaceFromModels();
+ if ( core )
+ stampWorkspaceFromModels();
}
@@ -1,8 +1,7 @@
/*********************************************************************************************
*
- * 'GamaBundleLoader.java, in plugin msi.gama.core, is part of the source code of the
- * GAMA modeling and simulation platform.
- * (c) 2007-2016 UMI 209 UMMISCO IRD/UPMC & Partners
+ * 'GamaBundleLoader.java, in plugin msi.gama.core, is part of the source code of the GAMA modeling and simulation
+ * platform. (c) 2007-2016 UMI 209 UMMISCO IRD/UPMC & Partners
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
@@ -46,6 +45,7 @@
*/
public class GamaBundleLoader {
+ public volatile static boolean LOADED = false;
public static String CORE_PLUGIN = "msi.gama.core";
public static String CORE_MODELS = "msi.gama.models";
public static String CURRENT_PLUGIN_NAME = CORE_PLUGIN;
@@ -108,6 +108,7 @@ public static void preBuildContributions() {
MODEL_PLUGINS.put(e.getContributor().getName(), e.getAttribute("name"));
}
// CRUCIAL INITIALIZATIONS
+ LOADED = true;
GamaMetaModel.INSTANCE.build();
Types.init();
@@ -156,9 +157,7 @@ private static boolean hasModels(final IContributor c) {
} catch (final MalformedURLException e) {
e.printStackTrace();
}
- if (url == null) {
- return false;
- }
+ if (url == null) { return false; }
File file = null;
try {
final URL new_url = FileLocator.resolve(url);
@@ -171,7 +170,7 @@ private static boolean hasModels(final IContributor c) {
return file != null && file.exists() && file.isDirectory();
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings ("unchecked")
public static void preBuild(final String s) {
GamaClassLoader.getInstance().addBundle(Platform.getBundle(s));
@@ -208,8 +207,7 @@ public static void preBuild(final String s) {
}
/**
- * The list of GAMA_PLUGINS declaring models, together with the inner path
- * to the folder containing model projects
+ * The list of GAMA_PLUGINS declaring models, together with the inner path to the folder containing model projects
*
* @return
*/
@@ -1,8 +1,7 @@
/*********************************************************************************************
*
- * 'UpdateBuiltInModelsHandler.java, in plugin ummisco.gama.ui.navigator, is part of the source code of the
- * GAMA modeling and simulation platform.
- * (c) 2007-2016 UMI 209 UMMISCO IRD/UPMC & Partners
+ * 'UpdateBuiltInModelsHandler.java, in plugin ummisco.gama.ui.navigator, is part of the source code of the GAMA
+ * modeling and simulation platform. (c) 2007-2016 UMI 209 UMMISCO IRD/UPMC & Partners
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
@@ -13,10 +12,6 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
@@ -29,19 +24,7 @@
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- final Job job = new Job("Updating the Built-in Models Library") {
-
- @Override
- protected IStatus run(final IProgressMonitor monitor) {
- // Nothing to do really. Maybe a later version will remove this
- // command. See Issue 669
- WorkspaceModelsManager.linkSampleModelsToWorkspace();
- return Status.OK_STATUS;
- }
-
- };
- job.setUser(true);
- job.schedule();
+ WorkspaceModelsManager.linkSampleModelsToWorkspace();
// job.addJobChangeListener(new JobChangeAdapter() {
//
@@ -1,8 +1,7 @@
/*********************************************************************************************
*
- * 'WorkbenchHelper.java, in plugin ummisco.gama.ui.shared, is part of the source code of the
- * GAMA modeling and simulation platform.
- * (c) 2007-2016 UMI 209 UMMISCO IRD/UPMC & Partners
+ * 'WorkbenchHelper.java, in plugin ummisco.gama.ui.shared, is part of the source code of the GAMA modeling and
+ * simulation platform. (c) 2007-2016 UMI 209 UMMISCO IRD/UPMC & Partners
*
* Visit https://github.com/gama-platform/gama for license information and developers contact.
*
@@ -23,6 +22,7 @@
import org.eclipse.ui.WorkbenchException;
import msi.gama.application.workspace.WorkspaceModelsManager;
+import ummisco.gama.ui.views.IGamlEditor;
public class WorkbenchHelper {
@@ -53,9 +53,7 @@ public static Display getDisplay() {
public static IWorkbenchPage getPage() {
final IWorkbenchWindow w = getWindow();
- if (w == null) {
- return null;
- }
+ if (w == null) { return null; }
final IWorkbenchPage p = w.getActivePage();
return p;
}
@@ -82,26 +80,24 @@ public static IWorkbenchWindow getWindow() {
if (w == null) {
final IWorkbenchWindow[] windows = getWorkbench().getWorkbenchWindows();
- if (windows != null && windows.length > 0) {
- return windows[0];
- }
+ if (windows != null && windows.length > 0) { return windows[0]; }
}
return w;
}
- public static IEditorPart getActiveEditor() {
+ public static IGamlEditor getActiveEditor() {
final IWorkbenchPage page = getPage();
if (page != null) {
- return page.getActiveEditor();
+ final IEditorPart editor = page.getActiveEditor();
+ if (editor instanceof IGamlEditor)
+ return (IGamlEditor) editor;
}
return null;
}
public static IWorkbenchPart getActivePart() {
final IWorkbenchPage page = getPage();
- if (page != null) {
- return page.getActivePart();
- }
+ if (page != null) { return page.getActivePart(); }
return null;
}
@@ -111,53 +107,37 @@ public static IWorkbench getWorkbench() {
public static IViewPart findView(final String id, final String second, final boolean restore) {
final IWorkbenchPage page = WorkbenchHelper.getPage();
- if (page == null) {
- return null;
- } // Closing the workbench
+ if (page == null) { return null; } // Closing the workbench
final IViewReference ref = page.findViewReference(id, second);
- if (ref == null) {
- return null;
- }
+ if (ref == null) { return null; }
final IViewPart part = ref.getView(restore);
return part;
}
public static void setWorkbenchWindowTitle(final String title) {
- run(new Runnable() {
-
- @Override
- public void run() {
- if (WorkbenchHelper.getShell() != null)
- WorkbenchHelper.getShell().setText(title);
- }
+ run(() -> {
+ if (WorkbenchHelper.getShell() != null)
+ WorkbenchHelper.getShell().setText(title);
});
}
public static void hideView(final String id) {
- run(new Runnable() {
-
- @Override
- public void run() {
- final IWorkbenchPage activePage = getPage();
- if (activePage == null) {
- return;
- } // Closing the workbench
- final IWorkbenchPart part = activePage.findView(id);
- if (part != null && activePage.isPartVisible(part)) {
- activePage.hideView((IViewPart) part);
- }
+ run(() -> {
+ final IWorkbenchPage activePage = getPage();
+ if (activePage == null) { return; } // Closing the workbench
+ final IWorkbenchPart part = activePage.findView(id);
+ if (part != null && activePage.isPartVisible(part)) {
+ activePage.hideView((IViewPart) part);
}
});
}
public static void hideView(final IViewPart gamaViewPart) {
final IWorkbenchPage activePage = getPage();
- if (activePage == null) {
- return;
- } // Closing the workbenc
+ if (activePage == null) { return; } // Closing the workbenc
activePage.hideView(gamaViewPart);
}

0 comments on commit 81580f8

Please sign in to comment.