[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mdt-uml2tools.dev] Modifying class diagram editor popup menus

Hello,

The structure of the
org.eclipse.gmf.runtime.common.ui.services.action.contributionItemProviders
extension point is well defined here:
http://help.eclipse.org/help32/index.jsp?topic=/org.eclipse.gmf.doc/reference/api/runtime/org/eclipse/gmf/runtime/common/ui/services/action/contributionitem/package-summary.html

In your case, you may either use the objectClass="<fqn of selected
editpart>"' form of this, enumerating the all editpart's classes you
want to have the popup. In this case there will be a lot of
<contributionItemProviders> elements in your plugin.xml, with
objectClass="[oeu2d].clazz.Class2EditPart",
objectClass="[oeu2d].clazz.Class3EditPart" and so on. This is probably
boring but this way allow you to modify applicability rules without
recompilation.

If you want this popup to appear for all and any editparts in the
class diagram, you have to add approximately 140+ snippets in the
plugin.xml, so it does not seem to be a practical way.

Thus, I believe that you have to use
policyClass="<fqn-of-your-brand-new-class-that-implements-policy-interface>"
way.
Just write class that implements IPopupMenuContributionPolicy
interface, and in the only interface method returns true for selection
from class diagram and false otherwise.

While implementing the policy you have to do something like the code below

public class AllSelectedIsFromClassDiagramPolicy implements
IPopupMenuContributionPolicy {

	public boolean appliesTo(ISelection selection, IConfigurationElement
configuration) {
		if (false == selection instanceof IStructuredSelection){
			return false;
		}
		IStructuredSelection sSel = (IStructuredSelection)selection;
		if (sSel.isEmpty()){
			return false;
		}
		for (Iterator it = sSel.iterator(); it.hasNext();){
			Object next = it.next();
			if (false == next instanceof IGraphicalEditPart){
				return false;
			}
			IGraphicalEditPart editPart = (IGraphicalEditPart)next;
			if (!isFromClassDiagram(editPart)){
				return false;
			}
		}
		return true;
	}
	
	private static boolean isFromClassDiagram(IGraphicalEditPart ep){
		View notation = ep.getNotationView();
		if (notation == null){
			//strange
			return false;
		}
		return PackageEditPart.MODEL_ID.equals(UMLVisualIDRegistry.getModelID(notation));
	}

}

Hope it helps,
Regards, ,
Michael

On Feb 13, 2008 5:10 AM, Ogechi Nnadi <ogechi.nnadi@xxxxxxxxxx> wrote:
> Hi,
>
> I'm writing an application that adds a popup menu item to the
> UML2tools class diagram editor so that once you click on the popup
> menu item, it sends the URI (or the name) of the selected object to
> the console. Please tell me what extension point to extend from so
> that I can add the same menu item to the popup menu of all UML
> objects.
>
> In the archives of this list
> (http://dev.eclipse.org/newslists/news.eclipse.modeling.mdt.uml2tools/msg00275.html),
> a similar question was answered but it didn't say what class the
> popupStructuredContributionCriteria should inherit from, and what
> methods needed to be modified.
>
> Thanks,
>
> Ogechi Nnadi.
> _______________________________________________
> mdt-uml2tools.dev mailing list
> mdt-uml2tools.dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/mdt-uml2tools.dev
>