package org.camunda.bpm.modeler.ui.diagram.editor;

import java.util.ArrayList;

import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior;
import org.eclipse.graphiti.ui.editor.DefaultUpdateBehavior;
import org.eclipse.graphiti.ui.editor.DiagramBehavior;
import org.eclipse.graphiti.ui.editor.DiagramEditorContextMenuProvider;
import org.eclipse.graphiti.ui.editor.IDiagramContainerUI;
import org.eclipse.graphiti.ui.platform.IConfigurationProvider;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;

public class Bpmn2DiagramBehavior extends DiagramBehavior {

	public Bpmn2DiagramBehavior(IDiagramContainerUI diagramContainer) {
		super(diagramContainer);
	}
	
	@Override
	public DefaultUpdateBehavior createUpdateBehavior() {
		return new Bpmn2EditorUpdateBehavior(this);
	}
	
	@Override
	protected DefaultPersistencyBehavior createPersistencyBehavior() {
		return new Bpmn2PersistencyBehavior(this);
	}
	
	@Override
	protected ContextMenuProvider createContextMenuProvider() {
		return new DiagramEditorContextMenuProvider(getDiagramContainer().getGraphicalViewer(), getDiagramContainer().getActionRegistry(), (IConfigurationProvider) getConfigurationProvider()) {
			@Override
			public void buildContextMenu(IMenuManager manager) {
				super.buildContextMenu(manager);
				IAction action = getDiagramContainer().getActionRegistry().getAction("show.or.hide.source.view");
				action.setText(action.getText());
				manager.add(action);
			}
		};
	}
	
	@Override
	public PictogramElement[] getPictogramElementsForSelection() {
		// filter out invisible elements when setting selection
		PictogramElement[] pictogramElements = super.getPictogramElementsForSelection();
		if (pictogramElements==null)
			return null;
		ArrayList<PictogramElement> visibleList = new ArrayList<PictogramElement>();
		for (PictogramElement pe : pictogramElements) {
			if (pe.isVisible())
				visibleList.add(pe);
		}
		return visibleList.toArray(new PictogramElement[visibleList.size()]);
	}

}

@@ -82,53 +82,8 @@
 %0D%0A%0D%0A
-import org.eclipse.gef.ContextMenuProvider;%0D%0A
 impo
@@ -366,254 +366,27 @@
 tor.
-DiagramEditorContextMenuProvider;%0D%0Aimport org.eclipse.graphiti.ui.editor.IDiagramContainerUI;%0D%0Aimport org.eclipse.graphiti.ui.platform.IConfigurationProvider;%0D%0Aimport org.eclipse.jface.action.IAction;%0D%0Aimport org.eclipse.jface.action.IMenuManager
+IDiagramContainerUI
 ;%0D%0A%0D
@@ -826,567 +826,8 @@
 de%0D%0A
-%09protected ContextMenuProvider createContextMenuProvider() %7B%0D%0A%09%09return new DiagramEditorContextMenuProvider(getDiagramContainer().getGraphicalViewer(), getDiagramContainer().getActionRegistry(), (IConfigurationProvider) getConfigurationProvider()) %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public void buildContextMenu(IMenuManager manager) %7B%0D%0A%09%09%09%09super.buildContextMenu(manager);%0D%0A%09%09%09%09IAction action = getDiagramContainer().getActionRegistry().getAction(%22show.or.hide.source.view%22);%0D%0A%09%09%09%09action.setText(action.getText());%0D%0A%09%09%09%09manager.add(action);%0D%0A%09%09%09%7D%0D%0A%09%09%7D;%0D%0A%09%7D%0D%0A%09%0D%0A%09@Override%0D%0A
 %09pub

Delete unnecessary code