Search in sources :

Example 1 with PreferenceLabelProvider

use of org.eclipse.jface.preference.PreferenceLabelProvider 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();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) HsPreferenceDialog(net.heartsome.cat.common.ui.dialog.HsPreferenceDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) Image(org.eclipse.swt.graphics.Image) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) PreferenceLabelProvider(org.eclipse.jface.preference.PreferenceLabelProvider)

Example 2 with PreferenceLabelProvider

use of org.eclipse.jface.preference.PreferenceLabelProvider 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();
}
Also used : HsPreferenceDialog(net.heartsome.cat.common.ui.dialog.HsPreferenceDialog) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) Image(org.eclipse.swt.graphics.Image) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) PreferenceLabelProvider(org.eclipse.jface.preference.PreferenceLabelProvider)

Aggregations

ArrayList (java.util.ArrayList)2 HsPreferenceDialog (net.heartsome.cat.common.ui.dialog.HsPreferenceDialog)2 IPreferenceNode (org.eclipse.jface.preference.IPreferenceNode)2 PreferenceLabelProvider (org.eclipse.jface.preference.PreferenceLabelProvider)2 PreferenceManager (org.eclipse.jface.preference.PreferenceManager)2 Image (org.eclipse.swt.graphics.Image)2 List (java.util.List)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 Button (org.eclipse.swt.widgets.Button)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1