Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Rolka2013-04-11 10:57:53 +0000
committerGerrit Code Review @ Eclipse.org2013-04-12 13:29:48 +0000
commit5566d8127af598a6dc30d790768aec473c003942 (patch)
treecb2813a100c76edeecf4f618fa047c7bd372d926
parent3d996ff0b4a10627420bca71805ad2b5c9195e78 (diff)
downloadeclipse.platform.ui-5566d8127af598a6dc30d790768aec473c003942.tar.gz
eclipse.platform.ui-5566d8127af598a6dc30d790768aec473c003942.tar.xz
eclipse.platform.ui-5566d8127af598a6dc30d790768aec473c003942.zip
Bug 330135 - Start e4 RCP several times fails
The review comments have been applied Change-Id: Ie2a237c5b640178ea443ba8e84d10af0c31c03d3
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java38
-rw-r--r--bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java53
2 files changed, 70 insertions, 21 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
index 4f0947bb0a7..87b4099a198 100644
--- a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/E4Application.java
@@ -122,10 +122,12 @@ public class E4Application implements IApplication {
return display;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
*
* @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.
- * IApplicationContext) */
+ * IApplicationContext)
+ */
public Object start(IApplicationContext applicationContext)
throws Exception {
// set the display name before the Display is
@@ -150,8 +152,8 @@ public class E4Application implements IApplication {
// place it off so it's not visible
shell.setLocation(0, 10000);
}
-
- if (!checkInstanceLocation(instanceLocation, shell))
+ if (!checkInstanceLocation(instanceLocation, shell,
+ workbench.getContext()))
return EXIT_OK;
IEclipseContext workbenchContext = workbench.getContext();
@@ -344,7 +346,6 @@ public class E4Application implements IApplication {
eclipseContext.set(E4Workbench.INITIAL_WORKBENCH_MODEL_URI,
initialWorkbenchDefinitionInstance);
- eclipseContext.set(E4Workbench.INSTANCE_LOCATION, instanceLocation);
// Save and restore
boolean saveAndRestore;
@@ -355,6 +356,13 @@ public class E4Application implements IApplication {
eclipseContext.set(IWorkbench.PERSIST_STATE,
Boolean.valueOf(saveAndRestore));
+ // when -data @none or -data @noDefault options
+ if (instanceLocation != null && instanceLocation.getURL() != null) {
+ eclipseContext.set(E4Workbench.INSTANCE_LOCATION, instanceLocation);
+ } else {
+ eclipseContext.set(IWorkbench.PERSIST_STATE, false);
+ }
+
// Persisted state
boolean clearPersistedState;
value = getArgValue(IWorkbench.CLEAR_PERSISTED_STATE, appContext, true);
@@ -498,7 +506,16 @@ public class E4Application implements IApplication {
* Simplified copy of IDEAplication processing that does not offer to choose
* a workspace location.
*/
- private boolean checkInstanceLocation(Location instanceLocation, Shell shell) {
+ private boolean checkInstanceLocation(Location instanceLocation,
+ Shell shell, IEclipseContext context) {
+
+ // Eclipse has been run with -data @none or -data @noDefault options so
+ // we don't need to validate the location
+ if (instanceLocation == null
+ && Boolean.FALSE.equals(context.get(IWorkbench.PERSIST_STATE))) {
+ return true;
+ }
+
if (instanceLocation == null) {
MessageDialog
.openError(
@@ -510,7 +527,8 @@ public class E4Application implements IApplication {
// -data "/valid/path", workspace already set
if (instanceLocation.isSet()) {
- // make sure the meta data version is compatible (or the user has
+ // make sure the meta data version is compatible (or the user
+ // has
// chosen to overwrite it).
if (!checkValidWorkspace(shell, instanceLocation.getURL())) {
return false;
@@ -551,7 +569,8 @@ public class E4Application implements IApplication {
}
return false;
}
- /* // -data @noDefault or -data not specified, prompt and set
+ /*
+ * // -data @noDefault or -data not specified, prompt and set
* ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc
* .getDefault());
*
@@ -575,7 +594,8 @@ public class E4Application implements IApplication {
* already in use -- force the user to choose again
* MessageDialog.openError(shell,
* IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle,
- * IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage); } */
+ * IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage); }
+ */
return false;
}
diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java
index c0be7732468..177a9af2a14 100644
--- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java
+++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ResourceHandler.java
@@ -14,11 +14,10 @@
package org.eclipse.e4.ui.internal.workbench;
-import org.eclipse.e4.ui.workbench.IWorkbench;
-
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;
import java.util.Collections;
@@ -31,6 +30,7 @@ import org.eclipse.core.internal.runtime.PlatformURLPluginConnection;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.MApplicationElement;
@@ -41,6 +41,7 @@ import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicPackageImpl;
import org.eclipse.e4.ui.model.application.ui.impl.UiPackageImpl;
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuPackageImpl;
import org.eclipse.e4.ui.workbench.IModelResourceHandler;
+import org.eclipse.e4.ui.workbench.IWorkbench;
import org.eclipse.e4.ui.workbench.modeling.IModelReconcilingService;
import org.eclipse.e4.ui.workbench.modeling.ModelDelta;
import org.eclipse.e4.ui.workbench.modeling.ModelReconciler;
@@ -74,6 +75,7 @@ public class ResourceHandler implements IModelResourceHandler {
private URI applicationDefinitionInstance;
@Inject
+ @Optional
@Named(E4Workbench.INSTANCE_LOCATION)
private Location instanceLocation;
@@ -127,10 +129,11 @@ public class ResourceHandler implements IModelResourceHandler {
}
public Resource loadMostRecentModel() {
- File baseLocation = getBaseLocation();
// This is temporary code to migrate existing delta files into full models
if (deltaRestore && saveAndRestore && !clearPersistedState) {
+ File baseLocation = getBaseLocation();
File deltaFile = new File(baseLocation, "deltas.xml"); //$NON-NLS-1$
+
if (deltaFile.exists()) {
MApplication appElement = null;
try {
@@ -175,14 +178,17 @@ public class ResourceHandler implements IModelResourceHandler {
}
}
- File workbenchData = getWorkbenchSaveLocation();
-
- if (clearPersistedState && workbenchData.exists())
- workbenchData.delete();
-
+ File workbenchData = null;
URI restoreLocation = null;
- if (saveAndRestore)
+
+ if (saveAndRestore) {
+ workbenchData = getWorkbenchSaveLocation();
restoreLocation = URI.createFileURI(workbenchData.getAbsolutePath());
+ }
+
+ if (clearPersistedState && workbenchData != null && workbenchData.exists()) {
+ workbenchData.delete();
+ }
// last stored time-stamp
long restoreLastModified = restoreLocation == null ? 0L : new File(
@@ -228,12 +234,19 @@ public class ResourceHandler implements IModelResourceHandler {
* @return a resource with a proper save path with the model as contents
*/
public Resource createResourceWithApp(MApplication theApp) {
- URI saveLocation = URI.createFileURI(getWorkbenchSaveLocation().getAbsolutePath());
- Resource res = resourceSetImpl.createResource(saveLocation);
+ Resource res = createResource();
res.getContents().add((EObject) theApp);
return res;
}
+ private Resource createResource() {
+ if (saveAndRestore) {
+ URI saveLocation = URI.createFileURI(getWorkbenchSaveLocation().getAbsolutePath());
+ return resourceSetImpl.createResource(saveLocation);
+ }
+ return resourceSetImpl.createResource(URI.createURI("workbench.xmi")); //$NON-NLS-1$
+ }
+
private File getWorkbenchSaveLocation() {
File workbenchData = new File(getBaseLocation(), "workbench.xmi"); //$NON-NLS-1$
return workbenchData;
@@ -256,7 +269,7 @@ public class ResourceHandler implements IModelResourceHandler {
private Resource loadResource(URI uri) {
Resource resource;
try {
- resource = resourceSetImpl.getResource(uri, true);
+ resource = getResource(uri);
} catch (Exception e) {
// TODO We could use diagnostics for better analyzing the error
logger.error(e, "Unable to load resource " + uri.toString()); //$NON-NLS-1$
@@ -277,6 +290,22 @@ public class ResourceHandler implements IModelResourceHandler {
return resource;
}
+ private Resource getResource(URI uri) throws Exception {
+ Resource resource;
+ if (saveAndRestore) {
+ resource = resourceSetImpl.getResource(uri, true);
+ } else {
+ // Workaround for java.lang.IllegalStateException: No instance data can be specified
+ // thrown by org.eclipse.core.internal.runtime.DataArea.assertLocationInitialized
+ // The DataArea.assertLocationInitialized is called by ResourceSetImpl.getResource(URI,
+ // boolean)
+ resource = resourceSetImpl.createResource(uri);
+ resource.load(new URL(uri.toString()).openStream(), resourceSetImpl.getLoadOptions());
+ }
+
+ return resource;
+ }
+
protected long getLastApplicationModification() {
long appLastModified = 0L;
ResourceSetImpl resourceSetImpl = new ResourceSetImpl();

Back to the top