use of org.eclipse.osgi.service.datalocation.Location in project translationstudio8 by heartsome.
the class SystemPreferenceInitializer method initializeDefaultPreferences.
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(IPreferenceConstants.SYSTEM_AUTO_UPDATE, IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_WEEKLY);
store.setDefault(IPreferenceConstants.SYSTEM_CHECK_UPDATE_WITH_WEEKLY_DATE, 2);
store.setDefault(IPreferenceConstants.SYSTEM_LANGUAGE, IPreferenceConstants.SYSTEM_LANGUAGE_WITH_EN);
// 默认语言从产品的 ini 文件中取值
Location configArea = Platform.getInstallLocation();
String locale = "en";
URL location = null;
try {
location = new URL(configArea.getURL().toExternalForm() + "configuration" + File.separator + "config.ini");
} catch (MalformedURLException e) {
// This should never happen
LOGGER.error(Messages.getString("preferencepage.SystemPreferenceInitializer.logger1"), e);
}
try {
String fileName = location.getFile();
BufferedReader in = new BufferedReader(new FileReader(fileName));
boolean isNl = false;
String line = in.readLine();
while (line != null) {
if (line.startsWith("osgi.nl=")) {
isNl = true;
locale = line.substring("osgi.nl=".length()).trim();
break;
}
line = in.readLine();
}
in.close();
if (!isNl) {
locale = "en";
}
} catch (FileNotFoundException e) {
LOGGER.error(Messages.getString("preferencepage.SystemPreferenceInitializer.logger1"), e);
} catch (IOException e) {
LOGGER.error("", e);
}
if (locale != null) {
if (locale.startsWith("en")) {
CommonFunction.setSystemLanguage("en");
store.setValue(IPreferenceConstants.SYSTEM_LANGUAGE, IPreferenceConstants.SYSTEM_LANGUAGE_WITH_EN);
} else if (locale.startsWith("zh")) {
CommonFunction.setSystemLanguage("zh");
store.setValue(IPreferenceConstants.SYSTEM_LANGUAGE, IPreferenceConstants.SYSTEM_LANGUAGE_WITH_ZH_CN);
}
}
store.setDefault(IPreferenceConstants.SYSTEM_USER, System.getProperty("user.name"));
//将用户保存到平台首选项中
PlatformUI.getPreferenceStore().setDefault(IPreferenceConstants.SYSTEM_USER, store.getDefaultString(IPreferenceConstants.SYSTEM_USER));
FontData fd = JFaceResources.getDefaultFont().getFontData()[0];
store.setDefault(IPreferenceConstants.XLIFF_EDITOR_FONT_NAME, fd.getName());
int fontSize = fd.getHeight();
store.setDefault(IPreferenceConstants.XLIFF_EDITOR_FONT_SIZE, fontSize < 13 ? 13 : fontSize);
store.setDefault(IPreferenceConstants.MATCH_VIEW_FONT_NAME, fd.getName());
store.setDefault(IPreferenceConstants.MATCH_VIEW_FONT_SIZE, fontSize < 13 ? 13 : fontSize);
store.setDefault(IPreferenceConstants.XLIFF_EDITOR_SHOWHIDEN_NONPRINTCHARACTER, false);
}
use of org.eclipse.osgi.service.datalocation.Location in project translationstudio8 by heartsome.
the class SystemPreferencePage method changeLocale.
/**
* 修改产品 ini 文件中的语言
*/
private void changeLocale(String locale) {
Location configArea = Platform.getInstallLocation();
if (configArea == null) {
return;
}
URL location = null;
try {
location = new URL(configArea.getURL().toExternalForm() + "configuration" + File.separator + "config.ini");
} catch (MalformedURLException e) {
// This should never happen
}
try {
String fileName = location.getFile();
File file = new File(fileName);
fileName += ".bak";
file.renameTo(new File(fileName));
BufferedReader in = new BufferedReader(new FileReader(fileName));
BufferedWriter out = new BufferedWriter(new FileWriter(location.getFile()));
try {
String line = in.readLine();
while (line != null) {
if (line.startsWith("osgi.nl=")) {
out.write("osgi.nl=" + locale);
} else {
out.write(line);
}
out.newLine();
line = in.readLine();
}
out.flush();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
File tmpFile = new File(location.getFile() + ".bak");
if (tmpFile.exists()) {
tmpFile.delete();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.eclipse.osgi.service.datalocation.Location in project cubrid-manager by CUBRID.
the class FileUtil method getDefaultTempDataFilePath.
/**
*
* Return the default temporary data file directory
*
* @return String the temporary file path
*/
public static synchronized String getDefaultTempDataFilePath() {
Location instanceLoc = Platform.getInstanceLocation();
URL url = instanceLoc.getURL();
File file = new File(url.getFile());
String tmpDir = file.getAbsolutePath() + File.separator + "tempdata";
File tmpFile = new File(tmpDir);
if (!tmpFile.exists()) {
tmpFile.mkdirs();
}
return tmpDir;
}
use of org.eclipse.osgi.service.datalocation.Location in project cubrid-manager by CUBRID.
the class SelectWorkspaceDialog method okPressed.
/**
* Press ok
*/
protected void okPressed() {
String workspacePath = workspacePathCombo.getText();
if (workspacePath.length() == 0) {
setErrorMessage(Messages.errNoSelectWorkspace);
return;
}
if (isSwitchWorkspace && workspacePath.equals(getLastSetWorkspaceDirectory())) {
setErrorMessage(Messages.errWorkspaceUsed);
return;
}
//now create
String error = checkWorkspaceDirectory(workspacePath, true, productName, productVersion);
if (error != null) {
setErrorMessage(error);
return;
}
if (!isSwitchWorkspace) {
boolean isOk = false;
try {
Location instanceLoc = Platform.getInstanceLocation();
isOk = instanceLoc.set(new URL("file", null, workspacePath), true);
} catch (IllegalStateException e) {
isOk = false;
} catch (MalformedURLException e) {
isOk = false;
} catch (IOException e) {
isOk = false;
}
if (!isOk) {
setErrorMessage(Messages.errWorkspaceUsed);
return;
}
}
recentUsedWorkspaces.remove(workspacePath);
if (!recentUsedWorkspaces.contains(workspacePath)) {
recentUsedWorkspaces.add(0, workspacePath);
}
// deal with the max history
if (recentUsedWorkspaces.size() > MAX_HISTORY) {
List<String> remove = new ArrayList<String>();
for (int i = MAX_HISTORY; i < recentUsedWorkspaces.size(); i++) {
remove.add(recentUsedWorkspaces.get(i));
}
recentUsedWorkspaces.removeAll(remove);
}
// create a string concatenation of all our last used workspaces
StringBuffer buf = new StringBuffer();
for (int i = 0; i < recentUsedWorkspaces.size(); i++) {
buf.append(recentUsedWorkspaces.get(i));
if (i != recentUsedWorkspaces.size() - 1) {
buf.append(WORKSPACE_SPLIT_CHAR);
}
}
// save them into our preferences
PREFERENCES.putBoolean(KEY_NOT_SHOW_WORKSPACE_SELECTION_DIALOG, rememberWorkspaceButton.getSelection());
PREFERENCES.put(KEY_RECENT_WORKSPACES, buf.toString());
PREFERENCES.put(KEY_LAST_WORKSPACE, workspacePath);
try {
PREFERENCES.flush();
} catch (BackingStoreException e) {
//NOPMD
//ignore
}
super.okPressed();
}
use of org.eclipse.osgi.service.datalocation.Location in project cubrid-manager by CUBRID.
the class SelectWorkspaceDialog method getSuggestedWorkspacePath.
/**
*
* Get suggested workspace path
*
* @return String
*/
private String getSuggestedWorkspacePath() {
String workspacePath;
if (Util.isMac()) {
File file = new File(System.getProperty("user.home") + File.separator + "Documents" + File.separator + "CUBRIDManager");
workspacePath = file.getAbsolutePath();
} else {
Location installLoc = Platform.getInstallLocation();
URL url = installLoc.getURL();
File file = new File(url.getFile());
workspacePath = file.getAbsolutePath() + File.separator + "workspace";
}
return workspacePath;
}
Aggregations