use of org.eclipse.jface.preference.IPreferenceNode in project translationstudio8 by heartsome.
the class ProjectSettingHandler method execute.
/**
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
runWizardPageExtension();
ISelection curSelection = HandlerUtil.getCurrentSelection(event);
if (curSelection != null && !curSelection.isEmpty() && curSelection instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) curSelection;
Object obj = selection.getFirstElement();
if (obj instanceof IProject) {
IProject project = (IProject) obj;
ProjectConfiger cfg = ProjectConfigerFactory.getProjectConfiger(project);
final ProjectInfoBean cfgBean = cfg.getCurrentProjectConfig();
cfgBean.setProjectName(project.getName());
ProjectSettingBaseInfoPage infoPage = new ProjectSettingBaseInfoPage(cfgBean);
ProjectSettingLanguagePage langPag = new ProjectSettingLanguagePage(cfgBean);
final PreferenceManager mgr = new PreferenceManager();
IPreferenceNode infoNode = new PreferenceNode("infoPage", infoPage);
IPreferenceNode langNode = new PreferenceNode("langPag", langPag);
mgr.addToRoot(infoNode);
mgr.addTo("infoPage", langNode);
AbstractProjectSettingPage pageTm = getPageByType("TM");
if (pageTm != null) {
pageTm.setProjectInfoBean(cfgBean);
IPreferenceNode extensionNode = new PreferenceNode("tmInfo", pageTm);
mgr.addTo("infoPage", extensionNode);
}
AbstractProjectSettingPage pageTb = getPageByType("TB");
if (pageTb != null) {
pageTb.setProjectInfoBean(cfgBean);
IPreferenceNode extensionNode = new PreferenceNode("tbInfo", pageTb);
mgr.addTo("infoPage", extensionNode);
}
for (AbstractProjectSettingPage page : extensionPages) {
page.setProjectInfoBean(cfgBean);
IPreferenceNode extensionNode = new PreferenceNode("tbInfo", page);
mgr.addTo("infoPage", extensionNode);
}
ProjectSettingDialog dialog = new ProjectSettingDialog(window.getShell(), mgr);
dialog.create();
dialog.setMessage(infoPage.getTitle());
if (dialog.open() == 0) {
cfg.updateProjectConfig(cfgBean);
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
logger.error("", e);
}
}
} else {
MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
return null;
}
} else {
MessageDialog.openError(window.getShell(), Messages.getString("handlers.ProjectSettingHandler.msgTitle"), Messages.getString("handlers.ProjectSettingHandler.msg1"));
return null;
}
return null;
}
use of org.eclipse.jface.preference.IPreferenceNode in project translationstudio8 by heartsome.
the class LicenseManageDialog method createButtonsForButtonBar.
@Override
protected void createButtonsForButtonBar(Composite parent) {
if (isShowBack) {
Button backBtn = createButton(parent, IDialogConstants.BACK_ID, Messages.getString("license.OfflineActiveDialog.backBtn"), false);
backBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setReturnCode(OK);
Point p = getShell().getLocation();
close();
ActiveMethodDialog dialog = new ActiveMethodDialog(getShell(), p);
int result = dialog.open();
if (result != IDialogConstants.OK_ID) {
System.exit(0);
}
}
});
}
Button button = createButton(parent, 11, Messages.getString("license.LicenseManageDialog.netconnection"), false);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
PreferenceManager mgr = window.getWorkbench().getPreferenceManager();
IPreferenceNode node = null;
@SuppressWarnings("unchecked") List<IPreferenceNode> lstNodes = mgr.getElements(PreferenceManager.PRE_ORDER);
for (IPreferenceNode n : lstNodes) {
if (n.getId().equals("org.eclipse.ui.net.proxy_preference_page_context")) {
node = n;
}
}
if (node == null) {
return;
}
mgr = new PreferenceManager();
mgr.addToRoot(node);
HsPreferenceDialog dlg = new HsPreferenceDialog(window.getShell(), mgr);
dlg.create();
final List<Image> imageList = new ArrayList<Image>();
dlg.getTreeViewer().setLabelProvider(new PreferenceLabelProvider() {
Image image = null;
public Image getImage(Object element) {
String id = ((IPreferenceNode) element).getId();
if ("org.eclipse.ui.net.proxy_preference_page_context".equals(id)) {
// 网络连接
image = Activator.getImageDescriptor("icons/network.png").createImage();
imageList.add(image);
return image;
} else {
return null;
}
}
});
dlg.open();
for (Image img : imageList) {
if (img != null && !img.isDisposed()) {
img.dispose();
}
}
imageList.clear();
}
});
boolean isDefault = false;
if (type == Constants.STATE_NOT_ACTIVATED || type == Constants.STATE_INVALID || type == Constants.STATE_EXPIRED || type == Constants.EXCEPTION_INT14 || type == Constants.EXCEPTION_INT15 || type == Constants.EXCEPTION_INT1 || type == Constants.EXCEPTION_INT2 || type == Constants.EXCEPTION_INT3 || type == Constants.EXCEPTION_INT4) {
createButton(parent, IDialogConstants.OK_ID, Messages.getString("license.LicenseManageDialog.activeBtn"), true);
isDefault = true;
}
createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("license.LicenseManageDialog.exitBtn"), !isDefault).setFocus();
}
use of org.eclipse.jface.preference.IPreferenceNode in project translationstudio8 by heartsome.
the class PreferenceUtil method openPreferenceDialog.
public static void openPreferenceDialog(IWorkbenchWindow window, final String defaultId) {
PreferenceManager mgr = window.getWorkbench().getPreferenceManager();
mgr.remove("net.heartsome.cat.ui.preferencePages.Perspectives");
mgr.remove("org.eclipse.ui.preferencePages.Workbench");
mgr.remove("org.eclipse.update.internal.ui.preferences.MainPreferencePage");
mgr.remove("org.eclipse.help.ui.browsersPreferencePage");
if (CommonFunction.checkEdition("L")) {
List<String> lstNodeId = new ArrayList<String>();
lstNodeId.add(SystemPreferencePage.ID);
lstNodeId.add(LanguageCodesPreferencePage.ID);
lstNodeId.add(ColorsPreferencePage.ID);
lstNodeId.add("org.eclipse.ui.preferencePages.Keys");
@SuppressWarnings("unchecked") List<IPreferenceNode> lstNodes = mgr.getElements(PreferenceManager.PRE_ORDER);
for (IPreferenceNode node : lstNodes) {
if (!lstNodeId.contains(node.getId())) {
mgr.remove(node);
}
}
}
final Object[] defaultNode = new Object[1];
HsPreferenceDialog dlg = new HsPreferenceDialog(window.getShell(), mgr);
dlg.create();
final List<Image> imageList = new ArrayList<Image>();
dlg.getTreeViewer().setLabelProvider(new PreferenceLabelProvider() {
public Image getImage(Object element) {
String id = ((IPreferenceNode) element).getId();
if (defaultId != null && id.equals(defaultId)) {
defaultNode[0] = element;
}
Image image = null;
if (SystemPreferencePage.ID.equals(id)) {
// 系统菜单
image = Activator.getImageDescriptor("images/preference/system/system.png").createImage();
imageList.add(image);
return image;
} else if (LanguageCodesPreferencePage.ID.equals(id)) {
// 系统 > 语言代码菜单
image = Activator.getImageDescriptor("images/preference/system/language.png").createImage();
imageList.add(image);
return image;
} else if (ColorsPreferencePage.ID.equals(id)) {
// 系统 > 颜色菜单
image = Activator.getImageDescriptor("images/preference/system/color.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.ui.qa.preference.SpellPage".equals(id)) {
// 品质检查 > 内置词典菜单
image = Activator.getImageDescriptor("images/preference/system/dictionary-in.png").createImage();
imageList.add(image);
return image;
} else if ("org.eclipse.ui.preferencePages.Keys".equals(id)) {
// 系统 > 快捷键菜单
image = Activator.getImageDescriptor("images/preference/system/keys.png").createImage();
imageList.add(image);
return image;
} else if ("org.eclipse.ui.net.proxy_preference_page_context".equals(id)) {
// 网络连接
image = Activator.getImageDescriptor("images/preference/system/network.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.ui.qa.preference.QAPage".equals(id)) {
// 品质检查菜单
image = Activator.getImageDescriptor("images/preference/qa/qa.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.ui.qa.preference.NonTranslationQAPage".equals(id)) {
// 品质检查 > 非译元素菜单
image = Activator.getImageDescriptor("images/preference/qa/not-trans-set.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.ui.qa.preference.QAInstalPage".equals(id)) {
// 品质检查 > 批量检查设置菜单
image = Activator.getImageDescriptor("images/preference/qa/check-set.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.ui.qa.preference.FileAnalysisInstalPage".equals(id)) {
// 文件分析
image = Activator.getImageDescriptor("images/preference/qa/fileAnalysis.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.ui.qa.preference.EquivalentPage".equals(id)) {
// 文件分析 -- > 加权系数设置
image = Activator.getImageDescriptor("images/preference/tm/equal-parameter.png").createImage();
imageList.add(image);
return image;
} else if (TranslationPreferencePage.ID.equals(id)) {
// 翻译菜单
image = Activator.getImageDescriptor("images/preference/translate/translation.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.pretranslation.preferencepage".equals(id)) {
// 预翻译
image = Activator.getImageDescriptor("images/preference/translate/pre-translation.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.machinetranslation.prefrence.MachineTranslationPreferencePage".equals(id)) {
// google
image = Activator.getImageDescriptor("images/preference/translate/pre-translation.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.bingtrans.preferencepage".equals(id)) {
// bing
image = Activator.getImageDescriptor("images/preference/translate/bing-translation.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.database.ui.tm.preference.tmpage".equals(id)) {
// 记忆库
image = Activator.getImageDescriptor("images/preference/tm/tm-db.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.database.ui.tb.preference.tbpage".equals(id)) {
// 术语库菜单
image = Activator.getImageDescriptor("images/preference/tb/tb-db.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.convert.ui.preference.FileTypePreferencePage".equals(id)) {
// 文件类型
image = Activator.getImageDescriptor("images/preference/file/documents.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.converter.msexcel2007.preference.ExcelPreferencePage".equals(id)) {
// Microsoft Excel 2007
image = Activator.getImageDescriptor("images/preference/file/excel_16.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.converter.pptx.preference.PPTXPreferencePage".equals(id)) {
// Microsoft PowerPoint 2007
image = Activator.getImageDescriptor("images/preference/file/powerpoint_16.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.converter.mif.preference.FrameMakerPreferencePage".equals(id)) {
// Adobe FrameMaker
image = Activator.getImageDescriptor("images/preference/file/framemaker_16.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage".equals(id)) {
// 项目属性
image = Activator.getImageDescriptor("images/preference/projectProperties.png").createImage();
imageList.add(image);
return image;
} else if ("net.heartsome.cat.ts.websearch.ui.preference.WebSearchPreferencePage".equals(id)) {
// 项目属性
image = Activator.getImageDescriptor("images/websearch/websearch16.png").createImage();
imageList.add(image);
return image;
} else {
return null;
}
}
});
if (defaultNode[0] != null) {
dlg.getTreeViewer().setSelection(new StructuredSelection(defaultNode), true);
dlg.getTreeViewer().getControl().setFocus();
}
// 修改BUG 2764, 品质检查--选项弹出的对话框有截断 robert 2012-12-03
if ("net.heartsome.cat.ts.ui.qa.preference.QAPage".equals(defaultId)) {
if (dlg.getShell().getSize().x < 860 || dlg.getShell().getSize().y < 716) {
dlg.getShell().setSize(860, 716);
}
} else if ("net.heartsome.cat.ts.ui.preferencepage.ProjectPropertiesPreferencePage".equals(defaultId)) {
int x = Util.isLinux() ? 839 : 908;
int y = Util.isLinux() ? 709 : 557;
dlg.getShell().setSize(Math.max(dlg.getShell().getSize().x, x), Math.max(dlg.getShell().getSize().y, y));
}
dlg.open();
// 清理资源
for (Image img : imageList) {
if (img != null && !img.isDisposed()) {
img.dispose();
}
}
imageList.clear();
}
use of org.eclipse.jface.preference.IPreferenceNode in project tdi-studio-se by Talend.
the class ProjectSettingDialog method getNodeManager.
/**
* get all projectsettingPage node dynamic. need get the different result each time. because the tester will calc
* dymamic.
*
* @return PreferenceManager
*/
private PreferenceManager getNodeManager() {
// PreferenceManager manager = new PreferenceManager(WorkbenchPlugin.PREFERENCE_PAGE_CATEGORY_SEPARATOR);
PreferenceManager manager = new PreferenceManager('/');
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] configurationElements = registry.getConfigurationElementsFor(//$NON-NLS-1$
"org.talend.repository.projectsetting_page");
Map<String, List<IPreferenceNode>> hasCategoriesNodes = new HashMap<String, List<IPreferenceNode>>();
for (IConfigurationElement element : configurationElements) {
ProjectSettingNode node = new ProjectSettingNode(element);
try {
//$NON-NLS-1$
IPreferencePage page = (IPreferencePage) element.createExecutableExtension("class");
node.setPage(page);
//$NON-NLS-1$
String id = element.getAttribute("id");
IConfigurationElement[] testers = element.getChildren("tester");
if (testers != null && testers.length == 1) {
// currently, only one tester is supported.
try {
IProjectSettingPageTester pageTester = (IProjectSettingPageTester) testers[0].createExecutableExtension("class");
if (pageTester != null) {
if (!pageTester.valid(element, node)) {
// don't add this page node.
continue;
}
}
} catch (CoreException ex) {
// can't create the tester
log.log(Level.WARN, "can't create the project setting tester for " + id, ex);
}
}
//$NON-NLS-1$
page.setDescription(element.getAttribute("description"));
//$NON-NLS-1$
page.setTitle(element.getAttribute("title"));
} catch (CoreException e) {
ExceptionHandler.process(e);
}
// add all into root.
manager.addToRoot(node);
// has category
String category = node.getCategory();
if (category != null && category.length() > 0) {
List<IPreferenceNode> list = hasCategoriesNodes.get(category);
if (list == null) {
list = new ArrayList<IPreferenceNode>();
hasCategoriesNodes.put(category, list);
}
list.add(node);
}
}
// add the speciall node for maven custom
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault().getService(IMavenUIService.class);
IPreferenceNode mavenCostomSetup = manager.find("projectsetting.MavenCustomSetup");
mavenUIService.addCustomMavenSettingChildren(mavenCostomSetup);
}
// find parent nodes for category
Map<String, IPreferenceNode> parentNodesMap = new HashMap<String, IPreferenceNode>();
for (String category : hasCategoriesNodes.keySet()) {
IPreferenceNode parent = manager.find(category);
if (parent != null) {
parentNodesMap.put(category, parent);
}
}
// process children nodes
for (String category : hasCategoriesNodes.keySet()) {
List<IPreferenceNode> list = hasCategoriesNodes.get(category);
if (list != null) {
IPreferenceNode parent = parentNodesMap.get(category);
Collections.sort(list, COMPARATOR);
for (IPreferenceNode node : list) {
// if the parent is not valid or not existed. the node won't show also.
// remove from root node.
manager.remove(node);
if (parent != null) {
// the parent existed.
parent.add(node);
}
}
}
}
// sort the root nodes
List<IPreferenceNode> rootSubNodesList = new ArrayList<IPreferenceNode>(Arrays.asList(manager.getRootSubNodes()));
Collections.sort(rootSubNodesList, COMPARATOR);
// clean all to re-add for order
manager.removeAll();
// add the sorted list to manager
for (IPreferenceNode rootSubNode : rootSubNodesList) {
manager.addToRoot(rootSubNode);
}
return manager;
}
use of org.eclipse.jface.preference.IPreferenceNode in project tdi-studio-se by Talend.
the class ProjectSettingsPreferenceDialog method openPage.
@Override
public boolean openPage(String nodeId, Object data) {
if (this instanceof IWorkbenchPreferenceContainer) {
((IWorkbenchPreferenceContainer) this).openPage(nodeId, data);
} else {
// impl by self
final IPreferenceNode node = findNodeMatching(nodeId);
if (node != null) {
getTreeViewer().setSelection(new StructuredSelection(node));
showPage(node);
}
IPreferencePage page = getCurrentPage();
if (page instanceof PreferencePage) {
((PreferencePage) page).applyData(data);
}
return true;
}
return false;
}
Aggregations