01: /*******************************************************************************
02: * Copyright (c) 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.internal.preferences;
11:
12: import org.eclipse.core.runtime.IPath;
13: import org.eclipse.core.runtime.IStatus;
14: import org.eclipse.core.runtime.Platform;
15: import org.eclipse.core.runtime.Status;
16: import org.eclipse.ui.internal.WorkbenchMessages;
17: import org.eclipse.ui.internal.WorkbenchPlugin;
18: import org.eclipse.ui.preferences.SettingsTransfer;
19:
20: /**
21: * The WorkbenchSettingsTransfer is the abstract superclass of settings
22: * transfers in the workbench.
23: *
24: * @since 3.3
25: *
26: */
27: public abstract class WorkbenchSettingsTransfer extends
28: SettingsTransfer {
29:
30: /**
31: * Return a status message for missing workspace settings.
32: * @return IStatus
33: */
34: protected IStatus noWorkingSettingsStatus() {
35: return new Status(
36: IStatus.ERROR,
37: WorkbenchPlugin.PI_WORKBENCH,
38: WorkbenchMessages.WorkbenchSettings_CouldNotFindLocation);
39: }
40:
41: /**
42: * Return the workbench settings location for the new root
43: * @param newWorkspaceRoot
44: * @return IPath or <code>null</code> if it can't be determined.
45: */
46: protected IPath getNewWorkbenchStateLocation(IPath newWorkspaceRoot) {
47: IPath currentWorkspaceRoot = Platform.getLocation();
48:
49: IPath dataLocation = WorkbenchPlugin.getDefault()
50: .getDataLocation();
51:
52: if (dataLocation == null)
53: return null;
54: int segmentsToRemove = dataLocation
55: .matchingFirstSegments(currentWorkspaceRoot);
56:
57: // Strip it down to the extension
58: dataLocation = dataLocation
59: .removeFirstSegments(segmentsToRemove);
60: // Now add in the
61: dataLocation = newWorkspaceRoot.append(dataLocation);
62: return dataLocation;
63: }
64:
65: }
|