Skip to content
Snippets Groups Projects
Commit 71d36567 authored by David Trachtenherz's avatar David Trachtenherz
Browse files

Set to yellow

refs 451
parent c671b000
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,6 @@ import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.actions.ActionFactory;
import org.fortiss.tooling.kernel.ui.extension.IContextMenuContributor;
import org.fortiss.tooling.kernel.ui.extension.base.EObjectActionBase.EObjectActionFactory;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
......@@ -36,34 +35,37 @@ import org.fortiss.tooling.kernel.ui.service.IContextMenuService;
/**
* Base class for context menu contributors creating a sub-menu
* {@link IMenuManager} with actions provided by actions factories TODO: @review
* this link is wrong => {@link ActionFactory} returned by
* {@link #getActionFactories()}.
* {@link IMenuManager} with actions provided by actions factories
* {@link EObjectActionFactory} returned by {@link #getActionFactories()}.
*
* The class implements interface methods {@link #getMenuIcon()} and
* {@link #getMenuId()} returning {@code null} by default. Classes providing an
* own icon or id should override them.
*
* The generic type parameter {@code T} indicated the type of selection
* elements.
*
* @param <T>
* TODO document T here
* Indicates the type of selection elements.
*
* @author trachtenherz
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: DE788BDCC0598D12129DAA00E06DDE3E
* @ConQAT.Rating YELLOW Hash: 80829E4615DB836462F038D6662D7B02
*/
public abstract class ContextMenuSubMenuContributorBase<T extends EObject>
implements IContextMenuContributor {
// TODO reorder methods: implemented before abstract before default
// implementations
/** The name of the sub-menu */
protected abstract String getMenuName();
/** Returns the action factories for the actions to be shown in the menu */
protected abstract Collection<EObjectActionFactory<? super T>> getActionFactories();
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public final List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if (acceptSelection(selection, contextProvider)) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems
.add(createMenu(createActionsForElement((T) selection)));
return contributionItems;
}
return Collections.emptyList();
}
/** Creates action instances for the given selection. */
protected Collection<Action> createActionsForElement(T selection) {
......@@ -74,16 +76,6 @@ public abstract class ContextMenuSubMenuContributorBase<T extends EObject>
return list;
}
/** The image for the sub-menu */
protected ImageDescriptor getMenuIcon() {
return null;
}
/** The Id for the sub-menu */
protected String getMenuId() {
return null;
}
/**
* Creates a sub-menu {@link IMenuManager} containing specified actions.
*/
......@@ -96,20 +88,6 @@ public abstract class ContextMenuSubMenuContributorBase<T extends EObject>
return menu;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public final List<IContributionItem> getContributedItems(EObject selection,
ContextMenuContextProvider contextProvider) {
if (acceptSelection(selection, contextProvider)) {
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems
.add(createMenu(createActionsForElement((T) selection)));
return contributionItems;
}
return Collections.emptyList();
}
/** {@inheritDoc} */
@Override
public String getMenuSectionID() {
......@@ -122,4 +100,21 @@ public abstract class ContextMenuSubMenuContributorBase<T extends EObject>
*/
protected abstract boolean acceptSelection(EObject selection,
ContextMenuContextProvider contextProvider);
/** The name of the sub-menu */
protected abstract String getMenuName();
/** Returns the action factories for the actions to be shown in the menu */
protected abstract Collection<EObjectActionFactory<? super T>> getActionFactories();
/** The image for the sub-menu */
protected ImageDescriptor getMenuIcon() {
return null;
}
/** The Id for the sub-menu */
protected String getMenuId() {
return null;
}
}
\ No newline at end of file
......@@ -24,14 +24,15 @@ import org.eclipse.jface.resource.ImageDescriptor;
/**
* JFace {@link Action}, which uses an {@link EObject} as target.
*
* @author trachtenherz
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 4C545F6468D6051419AA91C0E3774061
* @ConQAT.Rating YELLOW Hash: C1322F3569D042E8A5F328AC1921085A
*/
public abstract class EObjectActionBase<T extends EObject> extends Action {
/** Factory for the action instances used for this menu */
/** Factory interface for action instances. */
public static interface EObjectActionFactory<T extends EObject> {
/** Creates and returns an action instance for the given target. */
EObjectActionBase<T> createAction(T target);
......@@ -53,7 +54,7 @@ public abstract class EObjectActionBase<T extends EObject> extends Action {
/** Constructor. */
public EObjectActionBase(T target, String text, ImageDescriptor image) {
this(text, image);
setTarget(target);
refresh(target);
}
/** Constructor. */
......@@ -71,16 +72,26 @@ public abstract class EObjectActionBase<T extends EObject> extends Action {
return target;
}
/** Refreshes the action's target and enabled state. */
public final void refresh(T element) {
setTarget(element);
if (element == null) {
/** Refreshes the enabled state for the current action target. */
public final void refresh() {
if (getTarget() == null) {
setEnabled(false);
return;
}
setEnabled(computeEnabled());
}
/**
* Refreshes the action's target and enabled state.
*
* @see #setTarget(EObject)
* @see #refresh()
*/
public final void refresh(T element) {
setTarget(element);
refresh();
}
/**
* Computes the enabled state of the action for the current target, which is
* not <code>null</code> when this method is called. The default
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment