use of org.eclipse.jface.preference.IPreferenceStore in project tdi-studio-se by Talend.
the class BusinessRulersAndGridComposite method initializeControls.
/**
*
* Sets up controls with proper layouts and groups
*
* @param parent
*/
private void initializeControls(Composite parent) {
parent.setLayout(new GridLayout(1, false));
// Top row composite
Composite topComposite = widgetFactory.createComposite(parent);
topComposite.setLayout(new GridLayout(2, false));
// Create the groups for this section
createDisplayGroup(topComposite);
createMeasurementGroup(topComposite);
// Bottom row composite
Composite bottomComposite = widgetFactory.createComposite(parent);
bottomComposite.setLayout(new GridLayout(2, false));
// Create grid line settings
createGridlineGroup(bottomComposite);
Composite extraComposite = widgetFactory.createComposite(bottomComposite);
extraComposite.setLayout(new GridLayout(1, false));
// Create snap to grid checkbox
snapToGridButton = widgetFactory.createButton(extraComposite, SNAP_TO_GRID_LABEL, SWT.CHECK);
snapToGridButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// Set the snap to grid workspace property
setWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGRID, snapToGridButton.getSelection());
}
});
// Create snap to geometry checkbox
snapToGeometryButton = widgetFactory.createButton(extraComposite, SNAP_TO_GEOMETRY_LABEL, SWT.CHECK);
snapToGeometryButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
// Set the snap to geometry workspace property
setWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGEOMETRY, snapToGeometryButton.getSelection());
}
});
// Create restore to preferences defaults
restoreButton = widgetFactory.createButton(extraComposite, RESTORE_LABEL, SWT.PUSH);
restoreButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
restorePreferenceValues();
}
private void restorePreferenceValues() {
IPreferenceStore preferenceStore = getPreferenceStore();
// The workspace properties will always exist because it is set
//
IPreferenceStore wsPrefStore = getWorkspaceViewerProperties();
if (wsPrefStore.getBoolean(WorkspaceViewerProperties.GRIDORDER) == false) {
wsPrefStore.setValue(WorkspaceViewerProperties.GRIDORDER, true);
}
if (wsPrefStore.getInt(WorkspaceViewerProperties.GRIDLINECOLOR) != LIGHT_GRAY_RGB) {
wsPrefStore.setValue(WorkspaceViewerProperties.GRIDLINECOLOR, LIGHT_GRAY_RGB);
}
if (wsPrefStore.getInt(WorkspaceViewerProperties.GRIDLINESTYLE) != SWT.LINE_CUSTOM) {
wsPrefStore.setValue(WorkspaceViewerProperties.GRIDLINESTYLE, SWT.LINE_CUSTOM);
}
if (wsPrefStore.getBoolean(WorkspaceViewerProperties.VIEWRULERS) != preferenceStore.getBoolean(IPreferenceConstants.PREF_SHOW_RULERS)) {
wsPrefStore.setValue(WorkspaceViewerProperties.VIEWRULERS, preferenceStore.getBoolean(IPreferenceConstants.PREF_SHOW_RULERS));
}
if (wsPrefStore.getBoolean(WorkspaceViewerProperties.VIEWGRID) != preferenceStore.getBoolean(IPreferenceConstants.PREF_SHOW_GRID)) {
wsPrefStore.setValue(WorkspaceViewerProperties.VIEWGRID, preferenceStore.getBoolean(IPreferenceConstants.PREF_SHOW_GRID));
}
if (wsPrefStore.getBoolean(WorkspaceViewerProperties.SNAPTOGRID) != preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GRID)) {
wsPrefStore.setValue(WorkspaceViewerProperties.SNAPTOGRID, preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GRID));
}
if (wsPrefStore.getBoolean(WorkspaceViewerProperties.SNAPTOGEOMETRY) != preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GEOMETRY)) {
wsPrefStore.setValue(WorkspaceViewerProperties.SNAPTOGEOMETRY, preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GEOMETRY));
}
if ((wsPrefStore.getInt(WorkspaceViewerProperties.RULERUNIT) != preferenceStore.getInt(IPreferenceConstants.PREF_RULER_UNITS)) || (wsPrefStore.getDouble(WorkspaceViewerProperties.GRIDSPACING) != preferenceStore.getDouble(IPreferenceConstants.PREF_GRID_SPACING))) {
wsPrefStore.setValue(WorkspaceViewerProperties.RULERUNIT, preferenceStore.getInt(IPreferenceConstants.PREF_RULER_UNITS));
wsPrefStore.setValue(WorkspaceViewerProperties.GRIDSPACING, preferenceStore.getDouble(IPreferenceConstants.PREF_GRID_SPACING));
}
// reset the input values
setInput();
}
});
setInput();
}
use of org.eclipse.jface.preference.IPreferenceStore in project tdi-studio-se by Talend.
the class ComponentPreferenceInitializer method initializeDefaultPreferences.
public void initializeDefaultPreferences() {
IPreferenceStore preferenceStore = CodeGeneratorActivator.getDefault().getPreferenceStore();
//$NON-NLS-1$
preferenceStore.putValue(IComponentPreferenceConstant.LIMIT, "1000");
//$NON-NLS-1$
preferenceStore.setDefault(IComponentPreferenceConstant.LIMIT, "1000");
preferenceStore.putValue(IComponentPreferenceConstant.LINK_STYLE, LINK_STYLE.AUTO.toString());
}
use of org.eclipse.jface.preference.IPreferenceStore in project tdi-studio-se by Talend.
the class MapPreferenceInitializer method initializeDefaultPreferences.
@Override
public void initializeDefaultPreferences() {
IPreferenceStore prefs = getPluginPreferenceStore();
prefs.putValue(MapPrefsConstants.LINK_STYLE, LINK_STYLE.AUTO.toString());
}
use of org.eclipse.jface.preference.IPreferenceStore in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3PreferenceInitializer method initializeDefaultPreferences.
@Override
public void initializeDefaultPreferences() {
IPreferenceStore store = com.reprezen.swagedit.openapi3.Activator.getDefault().getPreferenceStore();
setColorPreferences(store);
}
use of org.eclipse.jface.preference.IPreferenceStore in project translationstudio8 by heartsome.
the class ConverterViewModel method convert.
/**
* 正向转换
* @param sourceItem
* @param monitor
* @return ;
*/
private Map<String, String> convert(final IConversionItem sourceItem, IProgressMonitor monitor) throws ConverterException {
Map<String, String> result = null;
boolean convertFlg = false;
String xliffDir = ConverterUtil.toLocalPath(configBean.getXliffDir());
String targetFile = ConverterUtil.toLocalPath(configBean.getTarget());
String skeletonFile = ConverterUtil.toLocalPath(configBean.getSkeleton());
// 转换前的准备
ConverterContext converterContext = new ConverterContext(configBean);
final Map<String, String> configuration = converterContext.getConvertConfiguration();
// 转换前,生成临时的XLIFF文件,用此文件生成指定目标语言的XLIFF文件
File targetTempFile = null;
try {
targetTempFile = File.createTempFile("tempxlf", "xlf");
} catch (IOException e) {
LOGGER.error(Messages.getString("model.ConverterViewModel.msg10"), e);
}
configuration.put(Converter.ATTR_XLIFF_FILE, targetTempFile.getAbsolutePath());
if (configBean.getFileType().equals(FileFormatUtils.MS)) {
IPreferenceStore ps = net.heartsome.cat.ts.ui.Activator.getDefault().getPreferenceStore();
String path = ps.getString(ITranslationPreferenceConstants.PATH_OF_OPENOFFICE);
String port = ps.getString(ITranslationPreferenceConstants.PORT_OF_OPENOFFICE);
configuration.put("ooPath", path);
configuration.put("ooPort", port);
}
// 创建skeleton文件
File skeleton = new File(skeletonFile);
if (!skeleton.exists()) {
try {
File parent = skeleton.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
skeleton.createNewFile();
} catch (IOException e) {
String message = MessageFormat.format(Messages.getString("model.ConverterViewModel.msg11"), skeletonFile);
LOGGER.error(message, e);
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message + "\n" + e.getMessage());
throw new ConverterException(status);
}
}
try {
// 执行转换
Converter converter = getConverter();
if (converter == null) {
// Build a message
String message = Messages.getString("model.ConverterViewModel.msg2") + configBean.getFileType();
// Build a new IStatus
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message);
throw new ConverterException(status);
}
result = converter.convert(configuration, monitor);
final String alert = result.get("ttx2xlfAlert39238409230481092830");
if (result.containsKey("ttx2xlfAlert39238409230481092830")) {
//ttx 转 xlf 时,提示含有未预翻译,不推荐,但没办法。
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.getString("handler.PreviewTranslationHandler.msgTitle"), alert);
}
});
}
// 处理骨架文件,将骨架文件路径修改为项目相对路径,此路径写入external-file节点的href属性
String projectPath = sourceItem.getProject().getLocation().toOSString();
String sklPath = skeletonFile.replace(projectPath, "");
// 处理目标语言, 创建多个目标语言的文件
List<Language> tgtLang = configBean.getHasSelTgtLangList();
if (tgtLang != null && tgtLang.size() > 0) {
// 解析XLIFF文件
File f = new File(targetTempFile.getAbsolutePath());
FileInputStream is = null;
byte[] b = new byte[(int) f.length()];
try {
is = new FileInputStream(f);
is.read(b);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
VTDGen vg = new VTDGen();
vg.setDoc(b);
try {
vg.parse(true);
} catch (VTDException e) {
String message = Messages.getString("model.ConverterViewModel.msg12");
LOGGER.error(message, e);
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message + "\n" + e.getMessage());
throw new ConverterException(status);
}
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils();
// 生成多个XLIFF文件,只是修改目标语言和骨架文件路径
for (Language lang : tgtLang) {
// 修复 bug 2949 ,当文件名中出现 XLIFF 时,文件名获取失败,下面注释代码为之前的代码。 --robert 2013-04-01
// String[] pathArray = targetFile.split(Constant.FOLDER_XLIFF);
// StringBuffer xlffPath = new StringBuffer(pathArray[0]);
// xlffPath.append(Constant.FOLDER_XLIFF).append(File.separator).append(lang.getCode())
// .append(pathArray[1]);
String fileName = targetFile.substring(xliffDir.length());
StringBuffer xlfPahtSB = new StringBuffer();
xlfPahtSB.append(xliffDir);
xlfPahtSB.append(File.separator);
xlfPahtSB.append(lang.getCode());
xlfPahtSB.append(fileName);
File tmpFile = new File(xlfPahtSB.toString());
generateTgtFileList.add(tmpFile);
if (!tmpFile.exists()) {
File parent = tmpFile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
try {
tmpFile.createNewFile();
} catch (IOException e) {
String message = Messages.getString("model.ConverterViewModel.msg13");
LOGGER.error(message, e);
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message + "\n" + e.getMessage());
throw new ConverterException(status);
}
}
try {
vu.bind(vn.duplicateNav());
} catch (NavException e) {
LOGGER.error("", e);
}
XMLModifier xm = vu.update("/xliff/file/@target-language", lang.getCode(), VTDUtils.CREATE_IF_NOT_EXIST);
xm = vu.update(null, xm, "/xliff/file/header/skl/external-file/@href", TextUtil.cleanString(sklPath));
FileOutputStream fos = null;
try {
fos = new FileOutputStream(tmpFile);
// 写入文件
xm.output(fos);
} catch (Exception e) {
String message = Messages.getString("model.ConverterViewModel.msg13");
LOGGER.error(message, e);
IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message + "\n" + e.getMessage());
throw new ConverterNotFoundException(status);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
LOGGER.error("", e);
}
}
}
}
vg.clear();
}
convertFlg = true;
} catch (OperationCanceledException e) {
LOGGER.info("ConverterViewerModel: 取消转换");
} finally {
if (!convertFlg) {
for (File f : generateTgtFileList) {
if (f != null && f.exists()) {
f.delete();
}
}
if (skeleton != null && skeleton.exists()) {
skeleton.delete();
}
}
targetTempFile.delete();
sourceItem.refresh();
}
return result;
}
Aggregations