显示/隐藏的菜单项取决于plugin.xml中的os.name

时间:2016-04-28 06:31:55

标签: java eclipse eclipse-plugin eclipse-rcp

我在plugin.xml中使用这种代码,以便根据操作系统类型显示/隐藏菜单项:

<menu label="Help">
    <command commandId="org.eclipse.ui.help.aboutAction" style="push">
        <visibleWhen checkEnabled="false">
            <not>
                <systemTest property="os.name" value="Mac OS X">
                </systemTest>
            </not>
        </visibleWhen>
    </command>
</menu>

问题是由System.getProperty("os.name")返回的os.name似乎不是很标准化。它可能取决于操作系统版本,特别是对于Microsoft Windows。

我想知道是否有最佳做法?

1 个答案:

答案 0 :(得分:1)

osgi.os环境变量具有更明确的OS值。其值在org.eclipse.osgi.service.environment.Constants

中定义
public static final String OS_WIN32 = "win32";
public static final String OS_LINUX = "linux";
public static final String OS_AIX = "aix";
public static final String OS_SOLARIS = "solaris";
public static final String OS_HPUX = "hpux";
public static final String OS_QNX = "qnx";
public static final String OS_MACOSX = "macosx";
public static final String OS_EPOC32 = "epoc32";
public static final String OS_OS400 = "os/400"; 
public static final String OS_OS390 = "os/390"; 
public static final String OS_ZOS = "z/os"; 
public static final String OS_UNKNOWN = "unknown";

注意:尽管名称(以及Constants类中的注释)win32适用于32位和64位Windows。

处理器架构还有osgi.arch

public static final String ARCH_X86 = "x86";
public static final String ARCH_X86_64 = "x86_64";
public static final String ARCH_PA_RISC = "PA_RISC";
public static final String ARCH_PPC = "ppc";
public static final String ARCH_PPC64 = "ppc64";
public static final String ARCH_SPARC = "sparc";
public static final String ARCH_IA64 = "ia64"; 
public static final String ARCH_IA64_32 = "ia64_32";

最后osgi.ws给出了窗口系统:

public static final String WS_WIN32 = "win32";
public static final String WS_WPF = "wpf"; 
public static final String WS_MOTIF = "motif";
public static final String WS_GTK = "gtk";
public static final String WS_PHOTON = "photon";
public static final String WS_CARBON = "carbon";
public static final String WS_COCOA = "cocoa";
public static final String WS_S60 = "s60";
public static final String WS_UNKNOWN = "unknown";