下面列出了怎么用org.eclipse.ui.internal.ide.ChooseWorkspaceData的API类实例代码及写法,或者点击链接到github查看源代码。
private static void makeCurrentWorkspaceToUsedOnNextLaunch() {
ChooseWorkspaceData data = new ChooseWorkspaceData(""); //$NON-NLS-1$
data.readPersistedData();
String[] recentWorkspaces = data.getRecentWorkspaces();
String workspaceRootPath = ResourceUtils.getWorkspaceRootPath();
boolean isFound = false;
for (String workspace : recentWorkspaces) {
if (workspace == null) continue;
workspace = (new File(workspace)).getAbsolutePath();
if (workspace.equals(workspaceRootPath)) {
isFound = true;
break;
}
}
if (!isFound) {
List<String> recentWorkspacesList = new ArrayList<String>(Arrays.asList(recentWorkspaces));
recentWorkspacesList.add(0, workspaceRootPath);
data.setRecentWorkspaces(recentWorkspacesList.toArray(new String[0]));
data.writePersistedData();
}
}
private static String getPreviousInstanceLocation(final Location instanceLocation) {
// CWD is Eclipse infrastructure which stores the location of the
// current workspace in a (text) file in the configuration area (Toolbox
// installation directory) in 1.5.3. With version 1.5.4 of the Toolbox, we will
// use this information below to migrate all workspaces to @user.home/.tlaplus.
final ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLocation.getDefault());
final List<String> recentWorkspaces = Arrays.asList(launchData.getRecentWorkspaces());
if (!recentWorkspaces.isEmpty()) {
// Get the first non-null workspace. It is the most recently used one.
for(int i = 0; i < recentWorkspaces.size(); i++) {
if (recentWorkspaces.get(i) != null) {
return recentWorkspaces.get(i);
}
}
}
return null;
}
private static void clearPreviousInstanceLocation(final Location instanceLocation) {
final ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLocation.getDefault());
launchData.setRecentWorkspaces(new String[0]);
launchData.writePersistedData();
}