KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > preferences > WorkbenchSettingsTransfer


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.ui.internal.preferences;
13
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Platform;
17 import org.eclipse.core.runtime.Status;
18 import org.eclipse.ui.internal.WorkbenchMessages;
19 import org.eclipse.ui.internal.WorkbenchPlugin;
20 import org.eclipse.ui.preferences.SettingsTransfer;
21
22 /**
23  * The WorkbenchSettingsTransfer is the abstract superclass of settings
24  * transfers in the workbench.
25  *
26  * @since 3.3
27  *
28  */

29 public abstract class WorkbenchSettingsTransfer extends SettingsTransfer {
30
31     /**
32      * Return a status message for missing workspace settings.
33      * @return IStatus
34      */

35     protected IStatus noWorkingSettingsStatus() {
36         return new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH,
37                 WorkbenchMessages.WorkbenchSettings_CouldNotFindLocation);
38     }
39
40     /**
41      * Return the workbench settings location for the new root
42      * @param newWorkspaceRoot
43      * @return IPath or <code>null</code> if it can't be determined.
44      */

45     protected IPath getNewWorkbenchStateLocation(IPath newWorkspaceRoot) {
46         IPath currentWorkspaceRoot = Platform.getLocation();
47     
48         IPath dataLocation = WorkbenchPlugin.getDefault().getDataLocation();
49     
50         if (dataLocation == null)
51             return null;
52         int segmentsToRemove = dataLocation
53                 .matchingFirstSegments(currentWorkspaceRoot);
54     
55         // Strip it down to the extension
56
dataLocation = dataLocation.removeFirstSegments(segmentsToRemove);
57         // Now add in the
58
dataLocation = newWorkspaceRoot.append(dataLocation);
59         return dataLocation;
60     }
61
62 }
63
Popular Tags