API consolidation for the otdt.ui plugin.

diff --git a/plugins/org.eclipse.objectteams.otdt.ui/plugin.xml b/plugins/org.eclipse.objectteams.otdt.ui/plugin.xml
index e10999f..570fbf7 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/plugin.xml
+++ b/plugins/org.eclipse.objectteams.otdt.ui/plugin.xml
@@ -291,7 +291,7 @@
          <action
         	   actionID="RulerClick"
                label="openteam"
-               class="org.eclipse.objectteams.otdt.ui.UpdateRulerAction"
+               class="org.eclipse.objectteams.otdt.internal.ui.callinmarkers.UpdateRulerAction"
                id="org.eclipse.objectteams.otdt.ui.actions.UpdateRulerAction">
          </action>
       </editorContribution>
@@ -301,7 +301,7 @@
          <action
         	   actionID="RulerClick"
                label="openteam"
-               class="org.eclipse.objectteams.otdt.ui.UpdateRulerAction"
+               class="org.eclipse.objectteams.otdt.internal.ui.callinmarkers.UpdateRulerAction"
                id="org.eclipse.objectteams.otdt.ui.actions.UpdateRulerAction">
          </action>
       </editorContribution>
@@ -415,7 +415,7 @@
    <extension
          point="org.eclipse.ui.handlers">
       <handler
-            class="org.eclipse.objectteams.otdt.ui.handlers.OpenBindingEditorHandler"
+            class="org.eclipse.objectteams.otdt.internal.ui.handlers.OpenBindingEditorHandler"
             commandId="org.eclipse.objectteams.otdt.ui.commands.openBindingEditor">
       </handler>
    </extension>
@@ -457,7 +457,7 @@
    <extension
          point="org.eclipse.ui.handlers">
       <handler
-            class="org.eclipse.objectteams.otdt.ui.handlers.CompareWithBaseMethodHandler"
+            class="org.eclipse.objectteams.otdt.internal.ui.handlers.CompareWithBaseMethodHandler"
             commandId="org.eclipse.objectteams.otdt.ui.commands.compareWithBaseMethod">
       </handler>
    </extension>
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIPluginConstants.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIPluginConstants.java
new file mode 100644
index 0000000..fe26b26
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/OTDTUIPluginConstants.java
@@ -0,0 +1,51 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2005, 2009 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ * 
+ * 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
+ * $Id: OTDTUIPluginConstants.java 23434 2010-02-03 23:52:31Z stephan $
+ * 
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ * 
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui;
+
+import org.eclipse.objectteams.otdt.core.ext.OTDTPlugin;
+
+/**
+ * A collection of all plugin related ids
+ * NOTE: Keep them up to date with ids in plugin.xml
+ * 
+ * @author kaiser
+ * @version $Id: OTDTUIPluginConstants.java 23434 2010-02-03 23:52:31Z stephan $
+ */
+@SuppressWarnings("nls")
+public interface OTDTUIPluginConstants
+{
+	public static final String UIPLUGIN_ID 		   = OTDTPlugin.PLUGIN_ID + ".ui";
+
+	public static final String RESOURCES_ID        = UIPLUGIN_ID + ".OTPluginResources";
+
+	// perspectives
+	public static final String PERSPECTIVE_ID      = UIPLUGIN_ID + ".OTJavaPerspective";
+
+	// wizards
+	public static final String NEW_TEAM_WIZARD_ID  = UIPLUGIN_ID + ".wizards.NewTeamCreationWizard";
+	public static final String NEW_ROLE_WIZARD_ID  = UIPLUGIN_ID + ".wizards.NewRoleCreationWizard";
+	
+	// extension point:
+	public static final String UPDATE_RULER_ACTION_EXTENDER_ID    		= "updateRulerActionExtenders";
+	public static final String UPDATE_RULER_ACTION_EXTENDER_CLASS 		= "class";
+	public static final String UPDATE_RULER_ACTION_EXTENDER_EDITORCLASS = "editorClass";
+
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerCreator2.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerCreator2.java
index 99425b6..c41fcb8 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerCreator2.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/CallinMarkerCreator2.java
@@ -73,7 +73,6 @@
 import org.eclipse.objectteams.otdt.core.OTModelManager;
 import org.eclipse.objectteams.otdt.core.search.OTSearchEngine;
 import org.eclipse.objectteams.otdt.internal.ui.preferences.GeneralPreferences;
-import org.eclipse.objectteams.otdt.ui.JavaEditorActivationListener;
 import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JavaEditorActivationListener.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JavaEditorActivationListener.java
new file mode 100644
index 0000000..b276b62
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/JavaEditorActivationListener.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * 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
+ * $Id: JavaEditorActivationListener.java 23434 2010-02-03 23:52:31Z stephan $
+ * 
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ * 
+ * Contributors:
+ * 		IBM Corporation - Initial API and implementation
+ * 		Fraunhofer FIRST - Initial API and implementation
+ * 		Technical University Berlin - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * @author gis
+ */
+public abstract class JavaEditorActivationListener implements IPartListener2, IWindowListener
+{
+//{OT_COPY_PASTE from CompilationUnitEditor and ClassFileEditor
+	protected abstract void activeJavaEditorChanged(IWorkbenchPart editor);
+
+	/*
+	 * @see org.eclipse.jdt.internal.ui.javaeditor.JavaEditor#getInputJavaElement()
+	 */
+	protected IJavaElement getInputJavaElement(IEditorPart editor) {
+	    final IEditorInput editorInput = editor.getEditorInput();
+	    
+	    if (editorInput instanceof IClassFileEditorInput)
+	    	return ((IClassFileEditorInput) editorInput).getClassFile();
+		else if (editor instanceof JavaEditor)
+			return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
+	    
+	    return null;
+	}
+//carp}
+	
+
+//{OT_COPY_PASTE from org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.ActivationListener
+	protected IWorkbenchPart fActiveEditor;
+    private IWorkbench fWorkbench;
+
+	public void installListener() {
+		/*
+		 * XXX: Don't in-line this field unless the following bug has been fixed:
+		 *      https://bugs.eclipse.org/bugs/show_bug.cgi?id=55246
+		 */
+		fWorkbench= PlatformUI.getWorkbench();
+		
+		fWorkbench.addWindowListener(this);
+		
+		// Ensure existing windows get connected
+		IWorkbenchWindow[] windows= fWorkbench.getWorkbenchWindows();
+		for (int i= 0, length= windows.length; i < length; i++)
+			windows[i].getPartService().addPartListener(this);
+	}
+	
+    public void uninstallListener() {
+        if (fWorkbench == null)
+            return;
+        
+		fWorkbench.removeWindowListener(this);
+		
+		// Ensure existing windows get disconnected
+		IWorkbenchWindow[] windows= fWorkbench.getWorkbenchWindows();
+		for (int i= 0, length= windows.length; i < length; i++)
+			windows[i].getPartService().removePartListener(this);
+	}
+	
+	public void partActivated(IWorkbenchPartReference ref) {
+		if (isJavaEditor(ref) && !isActiveEditor(ref))
+			activeJavaEditorChanged(ref.getPart(true));
+	}
+	
+	public void partBroughtToTop(IWorkbenchPartReference ref) {
+		if (isJavaEditor(ref) && !isActiveEditor(ref))
+			activeJavaEditorChanged(ref.getPart(true));
+	}
+	
+	public void partClosed(IWorkbenchPartReference ref) {
+		if (isActiveEditor(ref))
+			activeJavaEditorChanged(null);
+	}
+	
+	public void partDeactivated(IWorkbenchPartReference ref) {
+	}
+	
+	public void partOpened(IWorkbenchPartReference ref) {
+		if (isJavaEditor(ref) && !isActiveEditor(ref))
+			activeJavaEditorChanged(ref.getPart(true));
+	}
+	
+	public void partHidden(IWorkbenchPartReference ref) {
+	}
+	
+	public void partVisible(IWorkbenchPartReference ref) {
+		if (isJavaEditor(ref) && !isActiveEditor(ref))
+			activeJavaEditorChanged(ref.getPart(true));
+	}
+	
+	public void partInputChanged(IWorkbenchPartReference ref) {
+	}
+
+	public void windowActivated(IWorkbenchWindow window) {
+		IWorkbenchPartReference ref= window.getPartService().getActivePartReference();
+		if (isJavaEditor(ref) && !isActiveEditor(ref))
+			activeJavaEditorChanged(ref.getPart(true));
+	}
+
+	public void windowDeactivated(IWorkbenchWindow window) {
+	}
+
+	public void windowClosed(IWorkbenchWindow window) {
+		if (fActiveEditor != null && fActiveEditor.getSite() != null && window == fActiveEditor.getSite().getWorkbenchWindow()) 
+			activeJavaEditorChanged(null);
+		window.getPartService().removePartListener(this);
+	}
+
+	public void windowOpened(IWorkbenchWindow window) {
+		window.getPartService().addPartListener(this);
+	}
+	
+	protected boolean isActiveEditor(IWorkbenchPartReference ref) {
+		return ref != null && isActiveEditor(ref.getPart(false));
+	}
+	
+	protected boolean isActiveEditor(IWorkbenchPart part) {
+		return part != null && (part == fActiveEditor);
+	}
+	
+	protected boolean isJavaEditor(IWorkbenchPartReference ref) {
+		if (ref == null)
+			return false;
+		
+		String id= ref.getId();
+		return JavaUI.ID_CF_EDITOR.equals(id) || JavaUI.ID_CU_EDITOR.equals(id); 
+	}
+}
+//carp} -- end OT_COPY_PASTE
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/UpdateRulerAction.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/UpdateRulerAction.java
new file mode 100644
index 0000000..041228f
--- /dev/null
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/callinmarkers/UpdateRulerAction.java
@@ -0,0 +1,312 @@
+/**********************************************************************
+ * This file is part of "Object Teams Development Tooling"-Software
+ * 
+ * Copyright 2004, 2008 Fraunhofer Gesellschaft, Munich, Germany,
+ * for its Fraunhofer Institute for Computer Architecture and Software
+ * Technology (FIRST), Berlin, Germany and Technical University Berlin,
+ * Germany.
+ * 
+ * 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
+ * $Id: UpdateRulerAction.java 23435 2010-02-04 00:14:38Z stephan $
+ * 
+ * Please visit http://www.eclipse.org/objectteams for updates and contact.
+ * 
+ * Contributors:
+ * Fraunhofer FIRST - Initial API and implementation
+ * Technical University Berlin - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.objectteams.otdt.internal.ui.callinmarkers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.source.IVerticalRulerInfo;
+import org.eclipse.objectteams.otdt.core.IOTType;
+import org.eclipse.objectteams.otdt.core.IRoleType;
+import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.internal.ui.OTDTUIPluginConstants;
+import org.eclipse.objectteams.otdt.ui.IUpdateRulerActionExtender;
+import org.eclipse.objectteams.otdt.ui.OTDTUIPlugin;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * Action that is executed when the user right clicks on a binding marker at
+ * the vertical ruler and chooses a mapping (bound role class or callin mapping)
+ * from the ObjectTeams submenu.
+ *
+ * @author brcan
+ * @version $Id: UpdateRulerAction.java 23435 2010-02-04 00:14:38Z stephan $
+ */
+public class UpdateRulerAction extends AbstractRulerActionDelegate
+{
+	public final static String OT_PLAYEDBY_MENU_LABEL = OTDTUIPlugin.getResourceString("CallinMarker.menu_playedby_title"); //$NON-NLS-1$
+	public final static String OT_CALLIN_MENU_LABEL = OTDTUIPlugin.getResourceString("CallinMarker.menu_callin_title"); //$NON-NLS-1$
+	public final static String OT_CALLOUT_MENU_LABEL = OTDTUIPlugin.getResourceString("CallinMarker.menu_callout_title"); //$NON-NLS-1$
+	
+	private IEditorPart        _editor = null;
+	private IVerticalRulerInfo _rulerInfo = null;
+	
+	private List<IUpdateRulerActionExtender> extenders = null;
+
+	public UpdateRulerAction()
+	{
+	}
+
+	public void setActiveEditor(IAction callerAction, IEditorPart targetEditor)
+	{
+		_editor = targetEditor;
+
+		super.setActiveEditor(callerAction, targetEditor);
+	}
+	
+	protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo)
+	{
+		_rulerInfo = rulerInfo;
+    	
+		return null;
+	}
+	
+	public void menuAboutToShow(IMenuManager contextMenu)
+	{
+		IDocument    document    = null;
+		int          clickedLine = _rulerInfo.getLineOfLastMouseButtonActivity();
+		if (this._editor instanceof ITextEditor) {
+			ITextEditor textEditor = (ITextEditor) this._editor;
+			document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+		}
+		try
+		{
+			IMarker[] markers = findCallinMarkers();
+
+			if (markers != null && markers.length != 0)
+			{				
+				for (int idx = 0; idx < markers.length; idx++)
+				{
+					IMarker curMarker = markers[idx];
+
+					int line = curMarker.getAttribute(IMarker.LINE_NUMBER, -1);
+					if (line != -1)
+					{
+						if (line-1  == clickedLine) // IMarker.LINE_NUMBER is 1-based, others are 0-based
+							insertTeamMenus(contextMenu, curMarker);
+					} else if (document != null) {
+						// markers in ClassFileEditor have no line number, must go via position:
+						int start = curMarker.getAttribute(IMarker.CHAR_START, -1);
+						try {
+							if (clickedLine == document.getLineOfOffset(start))
+								insertTeamMenus(contextMenu, curMarker);
+						}
+						catch (BadLocationException e) { /* nop */ }
+					} 
+				}
+			}
+		}
+		catch (CoreException ex)
+		{
+			OTDTUIPlugin.logException("Problems extending ruler context menu", ex); //$NON-NLS-1$
+		}
+		// load and notify extenders:
+		if (this.extenders == null)
+			loadExtenders();
+		for (IUpdateRulerActionExtender extender : this.extenders)
+			extender.menuAboutToShow(contextMenu, document, this._editor, clickedLine);
+	}
+
+	private IMarker[] findCallinMarkers() throws CoreException
+	{
+		
+		final IEditorInput editorInput = _editor.getEditorInput();
+		if (editorInput instanceof IFileEditorInput) 
+		{
+			IFileEditorInput fileEditorInput = (IFileEditorInput)editorInput;
+			IFile            file            = fileEditorInput.getFile();			
+	
+			IMarker[] result = CallinMarker.getAllBindingMarkers(file);
+			return result;
+		} 
+		else if (editorInput instanceof IClassFileEditorInput) 
+		{			
+			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+			IMarker[] allMarkers = CallinMarker.getAllBindingMarkers(root);
+			
+			// now we have all CallinMarkers for all class files in the workspace, need to filter now: 
+			IClassFile classFile = ((IClassFileEditorInput) editorInput).getClassFile();
+			List<IMarker> filteredMarkers = new ArrayList<IMarker>(13);
+			for (IMarker marker : allMarkers)
+				if (JavaCore.isReferencedBy(classFile, marker))
+					filteredMarkers.add(marker);
+			return filteredMarkers.toArray(new IMarker[filteredMarkers.size()]);
+		}
+		return null;
+	}
+
+	/** Get the context menu of kind 'markerKind', creating it if ondemand. */
+    private IMenuManager getObjectTeamsMenu(IMenuManager contextMenu, String markerKind)
+    {
+    	String label;
+    	if (CallinMarker.CALLIN_ID.equals(markerKind))
+    		label = OT_CALLIN_MENU_LABEL;
+    	else if (CallinMarker.CALLOUT_ID.equals(markerKind))
+    		label = OT_CALLOUT_MENU_LABEL;
+    	else
+    		label = OT_PLAYEDBY_MENU_LABEL;
+    	
+    	IMenuManager subMenu = getSubMenu(contextMenu, label);
+    	if (subMenu != null)
+    		return subMenu;
+    	
+		MenuManager otMenu = new MenuManager(label, markerKind); // id cannot be null, re-use the markerKind
+		if (contextMenu.isEmpty())
+		    contextMenu.add(otMenu);
+		else // insert on top
+		    contextMenu.insertBefore(contextMenu.getItems()[0].getId(), otMenu);
+		return otMenu;
+    }
+
+    private IAction createOpenEditorAction(String label, final IJavaElement target)
+    {
+		Action result = new Action(label)
+		{
+			public void run()
+			{
+				try
+				{
+					IEditorPart part = EditorUtility.openInEditor(target);
+					if (target.exists()) // also initializes source positions if necessary
+						EditorUtility.revealInEditor(part, target);
+				}
+				catch (PartInitException ex)
+				{
+					OTDTUIPlugin.logException("Problems initializing editor", ex); //$NON-NLS-1$
+				}
+			}
+		};
+    	
+        return result;
+    }
+
+	List<IMember> getMappings (IMarker marker) throws CoreException 
+	{
+    	Object attr = marker.getAttribute(CallinMarker.ATTR_ROLE_ELEMENTS);
+    	if (attr == null || !(attr instanceof String))
+    		return null;
+    	String str = (String)attr;
+    	List<IMember> result = new ArrayList<IMember>();
+    	int start = 0;
+    	int pos;
+    	while ((pos = str.indexOf('\n', start)) != -1) {
+    		result.add((IMember)JavaCore.create(str.substring(start, pos)));
+    		start = pos+1;
+    	}
+    	return result;
+    }
+    
+    private void insertTeamMenus(IMenuManager contextMenu, IMarker marker) throws CoreException
+    {
+    	List<IMember> mappings = getMappings(marker);
+    	if (mappings == null) return;
+    	
+    	IMenuManager otMenu = getObjectTeamsMenu(contextMenu, marker.getType());
+    	
+        for (IMember curMapping : mappings) 
+        {
+        	IType type = (IType)(curMapping.getAncestor(IJavaElement.TYPE));
+        	IOTType otType = OTModelManager.getOTElement(type); // FIXME(SH): doesn't find role files??? (try StubUtility2)
+        	if (otType == null || !otType.isRole())
+        		continue;
+			
+        	IOTType teamType = ((IRoleType) otType).getTeam();
+ 			
+			IMenuManager curTeamMenu = null;
+					 			
+ 			if (!isSubMenuContained(otMenu, teamType.getElementName()))
+ 			{
+	            curTeamMenu = new MenuManager(teamType.getElementName());
+				otMenu.add(curTeamMenu);
+ 			}
+ 			else
+ 			{
+ 				curTeamMenu = getSubMenu(otMenu, teamType.getElementName());
+ 			}
+			String actLabel = getMappingLabel(type, curMapping);
+			curTeamMenu.add(createOpenEditorAction(actLabel, curMapping));
+        }
+    }
+
+    private String getMappingLabel(IType type, IMember mapping)
+    {
+    	if (type.equals(mapping)) return type.getElementName();
+    	
+        return type.getElementName() + ": " + mapping.getElementName(); //$NON-NLS-1$
+    }
+
+    private IMenuManager getSubMenu(IMenuManager otMenu, String subMenuName)
+    {
+    	if (otMenu == null)
+    		return null;
+
+    	IContributionItem[] items = otMenu.getItems();
+    	
+    	for (int idx = 0; idx < items.length; idx++)
+        {
+            if (items[idx] instanceof IMenuManager)
+            {
+            	MenuManager cur = (MenuManager)items[idx];
+            	if (cur.getMenuText().equals(subMenuName))
+            	{
+            		return cur; 
+            	}
+            }
+        }
+        
+        return null;
+    }
+
+    private boolean isSubMenuContained(IMenuManager menu, String subMenuName)
+    {
+        return getSubMenu(menu, subMenuName) != null;
+    }
+
+	private void loadExtenders() {
+		this.extenders = new ArrayList<IUpdateRulerActionExtender>();
+		IConfigurationElement[] configs = RegistryFactory.getRegistry().getConfigurationElementsFor(
+				OTDTUIPluginConstants.UIPLUGIN_ID, OTDTUIPluginConstants.UPDATE_RULER_ACTION_EXTENDER_ID);
+		for (IConfigurationElement config : configs) {
+			try {
+				if (this._editor.getClass().getName().equals(config.getAttribute(OTDTUIPluginConstants.UPDATE_RULER_ACTION_EXTENDER_EDITORCLASS)))
+					this.extenders.add((IUpdateRulerActionExtender) config.createExecutableExtension(OTDTUIPluginConstants.UPDATE_RULER_ACTION_EXTENDER_CLASS));
+			} catch (CoreException e) {
+				OTDTUIPlugin.log(e);
+			}
+		}		
+	}
+}
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/handlers/CompareWithBaseMethodHandler.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/handlers/CompareWithBaseMethodHandler.java
similarity index 99%
rename from plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/handlers/CompareWithBaseMethodHandler.java
rename to plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/handlers/CompareWithBaseMethodHandler.java
index 8f4870b..a02753a 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/handlers/CompareWithBaseMethodHandler.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/handlers/CompareWithBaseMethodHandler.java
@@ -14,7 +14,7 @@
  * Contributors:
  * Stephan Herrmann - Initial API and implementation
  **********************************************************************/
-package org.eclipse.objectteams.otdt.ui.handlers;
+package org.eclipse.objectteams.otdt.internal.ui.handlers;
 
 import java.util.ArrayList;
 import java.util.Iterator;
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/handlers/OpenBindingEditorHandler.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/handlers/OpenBindingEditorHandler.java
similarity index 98%
rename from plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/handlers/OpenBindingEditorHandler.java
rename to plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/handlers/OpenBindingEditorHandler.java
index 076265f..ece2162 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/handlers/OpenBindingEditorHandler.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/handlers/OpenBindingEditorHandler.java
@@ -18,7 +18,7 @@
  * Fraunhofer FIRST - Initial API and implementation
  * Technical University Berlin - Initial API and implementation
  **********************************************************************/
-package org.eclipse.objectteams.otdt.ui.handlers;
+package org.eclipse.objectteams.otdt.internal.ui.handlers;
 
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleCreator.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleCreator.java
index 0373fc3..113b617 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleCreator.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/RoleCreator.java
@@ -24,7 +24,7 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
-import org.eclipse.objectteams.otdt.ui.OTDTUIPluginConstants;
+import org.eclipse.objectteams.otdt.internal.ui.OTDTUIPluginConstants;
 
 
 /**
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TypeCreator.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TypeCreator.java
index c5ea053..7c2552f 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TypeCreator.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/internal/ui/wizards/typecreation/TypeCreator.java
@@ -79,7 +79,7 @@
 import org.eclipse.jface.text.templates.TemplateException;
 import org.eclipse.jface.text.templates.TemplateVariable;
 import org.eclipse.objectteams.otdt.core.compiler.IOTConstants;
-import org.eclipse.objectteams.otdt.ui.OTDTUIPluginConstants;
+import org.eclipse.objectteams.otdt.internal.ui.OTDTUIPluginConstants;
 import org.eclipse.text.edits.DeleteEdit;
 import org.eclipse.text.edits.MalformedTreeException;
 import org.eclipse.text.edits.MultiTextEdit;
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageConstants.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageConstants.java
index d8f4e5b..06be176 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageConstants.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageConstants.java
@@ -30,12 +30,6 @@
 @SuppressWarnings("nls")
 public interface ImageConstants
 {
-	public static final String IMG_PATH                 = "icons/ot/";
-
-	public static final String DEFAULT_PATH				= "default/";
-	public static final String HOVER_PATH				= "hover/";
-	public static final String DISABLED_PATH			= "disabled/";
-
 	// Method binding icons:
     public static final String CALLINBINDING_AFTER_IMG  = "callinbindingafter_obj.gif";
     public static final String CALLINBINDING_BEFORE_IMG = "callinbindingbefore_obj.gif";
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageManager.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageManager.java
index fa716f4..31f9f6b 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageManager.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/ImageManager.java
@@ -66,6 +66,12 @@
 
 	private static ImageManager _singleton;
 
+	// icon folders:
+	static final String IMG_PATH    	= "icons/ot/"; //$NON-NLS-1$
+	static final String DEFAULT_PATH	= "default/"; //$NON-NLS-1$
+	static final String HOVER_PATH		= "hover/"; //$NON-NLS-1$
+	static final String DISABLED_PATH	= "disabled/"; //$NON-NLS-1$
+
 	/**
 	 * Avoid multiple instances
 	 */
@@ -91,14 +97,14 @@
 	 * Add all plugin specific images to given ImageRegistry
 	 * @param reg - ImageRegistry to use 
 	 */
-	public void registerPluginImages(ImageRegistry reg)
+	protected void registerPluginImages(ImageRegistry reg)
 	{
 		ImageDescriptor descr;
 		
 		try
 		{
 			String[] pluginIcons = pluginIcons();
-			URL baseURL = new URL(getInstallLocation(), IMG_PATH);
+			URL baseURL = new URL(getInstallLocation(), ImageManager.IMG_PATH);
 			for (int idx = 0; idx < pluginIcons.length; idx++)
 			{
 				descr = ImageDescriptor.createFromURL(
@@ -112,20 +118,6 @@
 		}
 	}
 
-	private URL getInstallLocation() {
-		return getPlugin().getBundle().getEntry("/"); //$NON-NLS-1$
-	}
-
-	/** Override to specify which plugin we are serving. */
-	protected AbstractUIPlugin getPlugin() {
-		return OTDTUIPlugin.getDefault();
-	}
-	
-	/** Override to specify which icons should be registered. */
-	protected String[] pluginIcons() {
-		return _pluginIcons;
-	}
-
 	/**
 	 * Setup images for different action states
 	 * @param action - action to initialise
@@ -165,10 +157,27 @@
 		return getPlugin().getImageRegistry().get(imageKey);		
 	}
 
-	
+	/**
+	 * Get image descriptor from this Plugin's ImageRegistry
+	 * @param imageKey - image key from the set returned by pluginIcons().
+	 * @return image descriptor
+	 */	
 	public ImageDescriptor getDescriptor(String imageKey)
 	{
 		return getPlugin().getImageRegistry().getDescriptor(imageKey);
 	}
-
+	
+	private URL getInstallLocation() {
+		return getPlugin().getBundle().getEntry("/"); //$NON-NLS-1$
+	}
+	
+	/** Override to specify which plugin we are serving. */
+	protected AbstractUIPlugin getPlugin() {
+		return OTDTUIPlugin.getDefault();
+	}
+	
+	/** Override to specify which icons should be registered. */
+	protected String[] pluginIcons() {
+		return _pluginIcons;
+	}
 }
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/OTDTUIPlugin.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/OTDTUIPlugin.java
index 2fc4864..a0f1414 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/OTDTUIPlugin.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/OTDTUIPlugin.java
@@ -34,6 +34,7 @@
 import org.eclipse.jface.resource.ImageRegistry;
 import org.eclipse.objectteams.otdt.core.IOTJavaElement;
 import org.eclipse.objectteams.otdt.core.OTModelManager;
+import org.eclipse.objectteams.otdt.internal.ui.OTDTUIPluginConstants;
 import org.eclipse.objectteams.otdt.internal.ui.OTElementAdapterFactory;
 import org.eclipse.objectteams.otdt.internal.ui.callinmarkers.CallinMarkerCreator2;
 import org.eclipse.objectteams.otdt.internal.ui.callinmarkers.RoleBindingChangedListener;
@@ -66,24 +67,23 @@
         super();
         _singleton = this;
         
-        try
-        {
+        try {
 			_resourceBundle = ResourceBundle.getBundle( RESOURCES_ID );
-		}
-		catch (MissingResourceException ex)
-		{
+		} catch (MissingResourceException ex) {
 			logException("Error initializing resource bundle of OTDT/UI", ex); //$NON-NLS-1$
 			_resourceBundle = null;
 		}
     }
 
-    public static OTDTUIPlugin getDefault()
-    {
+    public static OTDTUIPlugin getDefault() {
         return _singleton;
     }
 
-	public static IWorkbenchPage getActivePage()
-	{
+    /**
+     * Answer the active workbench page
+     * @return active workbench page or null if no workbench window is active.
+     */
+	public static IWorkbenchPage getActivePage() {
 		return getDefault().internalGetActivePage();
 	}
 
@@ -100,32 +100,18 @@
      */
     public static String getResourceString(String key)
     {
-        ResourceBundle bundle = OTDTUIPlugin.getDefault().getResourceBundle();
-        try
-        {
+        ResourceBundle bundle = OTDTUIPlugin.getDefault()._resourceBundle;
+        try {
             return bundle.getString(key);
-        }
-        catch (MissingResourceException ex)
-        {
+        } catch (MissingResourceException ex) {
             return key;
         }
     }
 
-    public static IWorkspace getWorkspace()
-    {
-        return ResourcesPlugin.getWorkspace();
-    }
-
-    public ResourceBundle getResourceBundle()
-    {
-        return _resourceBundle;
-    }
-
     /**
      * Add Object Teams flavoured images to the image registry.
      */
-    protected void initializeImageRegistry(ImageRegistry reg)
-    {
+    protected void initializeImageRegistry(ImageRegistry reg) {
     	ImageManager.getSharedInstance().registerPluginImages(reg);    	
     }
 
@@ -165,7 +151,16 @@
 		_singleton.getLog().log(new Status(IStatus.ERROR, UIPLUGIN_ID, IStatus.OK, message, exception));
 	}
 
-    private void registerAdapter()
+    public static void log(Throwable t) {
+    	_singleton.getLog().log(new Status(IStatus.ERROR, UIPLUGIN_ID, t.getMessage(), t));
+	}
+
+	public static Status createErrorStatus(String message, Throwable exception)
+	{
+	    return new Status(IStatus.ERROR, UIPLUGIN_ID, IStatus.OK, message, exception);
+	}
+
+	private void registerAdapter()
     {
 		_otElementAdapterFactory = new OTElementAdapterFactory();
 		IAdapterManager manager = Platform.getAdapterManager();		
@@ -193,11 +188,9 @@
 		_baseClassChangedListener = null;
     }
 
-	public static Status createErrorStatus(String message, Throwable exception)
-	{
-	    return new Status(IStatus.ERROR, UIPLUGIN_ID, IStatus.OK, message, exception);
-	}
-	
+    /**
+     * @noreference external clients should not call this method, public only for org.eclipse.objectteams.otdt.ui.tests
+     */
 	public CallinMarkerCreator2 getCallinMarkerCreator()
 	{
 	    if (_callinMarkerCreator == null)
@@ -205,8 +198,4 @@
 	    
 	    return _callinMarkerCreator;
 	}
-
-	public static void log(Throwable t) {
-		getDefault().getLog().log(new Status(IStatus.ERROR, UIPLUGIN_ID, t.getMessage(), t));
-	}
 }
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/Util.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/Util.java
index f28e7b5..6617702 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/Util.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/Util.java
@@ -36,6 +36,8 @@
 
 
 /**
+ * Set of utility functions for manipulating names of OT elements for display in the UI.
+ * 
  * @author kaiser
  * @version $Id: Util.java 15419 2007-02-23 12:07:05Z stephan $
  */
@@ -83,6 +85,11 @@
 		return types; // due to arraycopy this might be different from the input
 	}
 	
+	/**
+	 * Remove any elements of type {@link IRoleFileType} from the input array.
+	 * @param types arbitrary input objects, supposedly some java elements.
+	 * @return a non-null list containing the filtered elements from types
+	 */
 	public static List<Object> removeExternalDefinedRoles(Object[] types)
 	{
 		ArrayList<Object> result = new ArrayList<Object>(types.length);
@@ -100,6 +107,11 @@
 		return result;
 	}
 
+	/**
+	 * Filter any java elements that represent generated (synthetic) stuff.
+	 * @param children
+	 * @return
+	 */
 	public static List<Object> filterOTGenerated(List<Object> children) {
 		ArrayList<Object> result = new ArrayList<Object>(children.size());
 		for (Object elem : children) {
@@ -111,7 +123,12 @@
 		return result;
 	}
 
-	/* same as above, but array instead of list */
+	/**
+	 * Filter any java elements that represent generated (synthetic) stuff
+	 * (same as above, but array instead of list).
+	 * @param children
+	 * @return
+	 */
 	public static Object[] filterOTGenerated(Object[] children) {
 		if (children == null) return children;
 		ArrayList<Object> result = new ArrayList<Object>(children.length);
@@ -124,6 +141,13 @@
 		return result.toArray();
 	}
 
+	/** 
+	 * Is the given java element generated by the compiler (i.e., synthetic)?
+	 * This function operates on all kinds of java elements applying appropriate
+	 * heuristics (mostly name based). 
+	 * @param elem
+	 * @return
+	 */
 	@SuppressWarnings("nls")
 	public static boolean isGenerated(IJavaElement elem) {
 		// TODO (SH): check whether ViewerFilters can do the job better.
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/OTTypeSelectionLabelProvider.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/OTTypeSelectionLabelProvider.java
index 28cd9ce..b16a323 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/OTTypeSelectionLabelProvider.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/OTTypeSelectionLabelProvider.java
@@ -35,7 +35,7 @@
  * @author kaschja
  * @version $Id: OTTypeSelectionLabelProvider.java 23435 2010-02-04 00:14:38Z stephan $
  */
-public class OTTypeSelectionLabelProvider extends LabelProvider
+class OTTypeSelectionLabelProvider extends LabelProvider
 {
 	private static final Image PKG_ICON = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_PACKAGE);
 
diff --git a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/TeamSelectionDialog.java b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/TeamSelectionDialog.java
index 595c4c9..3aa15ca 100644
--- a/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/TeamSelectionDialog.java
+++ b/plugins/org.eclipse.objectteams.otdt.ui/src/org/eclipse/objectteams/otdt/ui/dialogs/TeamSelectionDialog.java
@@ -105,11 +105,6 @@
 	    _searchFilters.add(filter);
 	}
 	
-	public void removeSearchFilter(ISearchFilter filter)
-	{
-	    _searchFilters.remove(filter);
-	}
-	
 	/*
 	 * @see AbstractElementListSelectionDialog#createFilteredList(Composite)
 	 */