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 java.io.File;
13: import java.io.IOException;
14:
15: import org.eclipse.core.runtime.IPath;
16: import org.eclipse.core.runtime.IStatus;
17: import org.eclipse.core.runtime.Status;
18: import org.eclipse.ui.IWorkingSetManager;
19: import org.eclipse.ui.PlatformUI;
20: import org.eclipse.ui.internal.AbstractWorkingSetManager;
21: import org.eclipse.ui.internal.WorkbenchMessages;
22: import org.eclipse.ui.internal.WorkbenchPlugin;
23: import org.eclipse.ui.internal.WorkingSetManager;
24:
25: /**
26: * The WorkingSetSettingsTransfer is the settings transfer for the workbench
27: * working sets.
28: *
29: * @since 3.3
30: *
31: */
32: public class WorkingSetSettingsTransfer extends
33: WorkbenchSettingsTransfer {
34:
35: /*
36: * (non-Javadoc)
37: *
38: * @see org.eclipse.ui.preferences.SettingsTransfer#getName()
39: */
40: public String getName() {
41: return WorkbenchMessages.WorkingSets_Name;
42: }
43:
44: /*
45: * (non-Javadoc)
46: *
47: * @see org.eclipse.ui.preferences.SettingsTransfer#transferSettings(org.eclipse.core.runtime.IPath)
48: */
49: public IStatus transferSettings(IPath newWorkspaceRoot) {
50: IPath dataLocation = getNewWorkbenchStateLocation(newWorkspaceRoot);
51:
52: if (dataLocation == null)
53: return noWorkingSettingsStatus();
54:
55: dataLocation = dataLocation
56: .append(WorkingSetManager.WORKING_SET_STATE_FILENAME);
57:
58: File stateFile = new File(dataLocation.toOSString());
59:
60: try {
61: IWorkingSetManager manager = PlatformUI.getWorkbench()
62: .getWorkingSetManager();
63: if (manager instanceof AbstractWorkingSetManager)
64: ((AbstractWorkingSetManager) manager)
65: .saveState(stateFile);
66: else
67: return new Status(IStatus.ERROR,
68: WorkbenchPlugin.PI_WORKBENCH,
69: WorkbenchMessages.WorkingSets_CannotSave);
70: } catch (IOException e) {
71: new Status(
72: IStatus.ERROR,
73: WorkbenchPlugin.PI_WORKBENCH,
74: WorkbenchMessages.ProblemSavingWorkingSetState_message,
75: e);
76: }
77: return Status.OK_STATUS;
78:
79: }
80: }
|