fixed 'add virtual attribute' handler and menu item to only appear when the eclipselink-orm.xml file is version 2.1 or greater
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml index 78a2f92..a7ae462 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/plugin.xml
@@ -177,6 +177,13 @@ properties="isLatestSupportedVersion, isNotLatestSupportedVersion" class="org.eclipse.jpt.jpa.core.internal.JptResourceModelPropertyTester"/> + <propertyTester + id="org.eclipse.jpt.jpa.ui.propertyTester.jpaContextNode" + type="org.eclipse.jpt.jpa.core.context.JpaContextNode" + namespace="org.eclipse.jpt.jpa.core" + properties="isCompatibleVersion" + class="org.eclipse.jpt.jpa.core.internal.JpaContextNodePropertyTester"/> + </extension>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaContextNodePropertyTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaContextNodePropertyTester.java new file mode 100644 index 0000000..e03a735 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JpaContextNodePropertyTester.java
@@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2012 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.jpa.core.internal; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; +import org.eclipse.jpt.jpa.core.context.JpaContextNode; + +/** + * Property tester for {@link JpaContextNode}. + * See <code>org.eclipse.jpt.jpa.core/plugin.xml</code> + */ +public class JpaContextNodePropertyTester + extends PropertyTester +{ + public static final String IS_COMPATIBLE_VERSION = "isCompatibleVersion"; //$NON-NLS-1$ + + + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + if (receiver instanceof JpaContextNode) { + return this.test((JpaContextNode) receiver, property, (String) expectedValue); + } + return false; + } + + private boolean test(JpaContextNode contextNode, String property, String expectedValue) { + if (property.equals(IS_COMPATIBLE_VERSION)) { + return JptJpaCorePlugin.resourceTypeIsCompatible(contextNode.getResourceType(), expectedValue); + } + return false; + } +}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml index accc7f1..3822421 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.ui/plugin.xml
@@ -181,15 +181,19 @@ commandId="org.eclipse.jpt.jpa.eclipselink.ui.persistentTypeAddVirtualAttribute" class="org.eclipse.jpt.jpa.eclipselink.ui.internal.handlers.AddVirtualAttributeHandler"> <activeWhen> - <reference - definitionId="org.eclipse.jpt.jpa.ui.reference.inJpaStructureView"> - </reference> + <and> + <with variable="activePartId"> + <equals value="org.eclipse.jpt.ui.jpaStructureView"/> + </with> + <with variable="selection"> + <count value="1"/> + <iterate operator="and"> + <instanceof value="org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmPersistentType"/> + <test property="org.eclipse.jpt.jpa.core.isCompatibleVersion" value="'2.1'"/> + </iterate> + </with> + </and> </activeWhen> - <enabledWhen> - <iterate> - <instanceof value="org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmPersistentType"/> - </iterate> - </enabledWhen> </handler> </extension> @@ -205,10 +209,11 @@ <command commandId="org.eclipse.jpt.jpa.eclipselink.ui.persistentTypeAddVirtualAttribute"> <visibleWhen> - <with - variable="selection"> - <iterate ifEmpty="false"> + <with variable="selection"> + <count value="1"/> + <iterate operator="and"> <instanceof value="org.eclipse.jpt.jpa.eclipselink.core.context.orm.EclipseLinkOrmPersistentType"/> + <test property="org.eclipse.jpt.jpa.core.isCompatibleVersion" value="'2.1'"/> </iterate> </with> </visibleWhen>