구성 GMF Diagram 마우스 오른쪽 버튼 클릭 메뉴

9129 단어 eclipseGMF
BPM Diagram에서 Boundary Event의 중단 및 비중단을 실현합니다.
1. org.autumn.bpm.diagram 플러그인에 확장점 추가
<extension
      point="org.eclipse.gmf.runtime.common.ui.services.action.contributionItemProviders">
   <contributionItemProvider
         checkPluginLoaded="true"
         class="org.autumn.bpm.diagram.providers.DiagramActionProvider">
      <Priority
            name="Low">
      </Priority>
      <popupContribution
            class="org.eclipse.gmf.runtime.diagram.ui.providers.DiagramContextMenuProvider">
         <popupAction
               id="SetInterruptingAction"
               path="/additionsGroup">
         </popupAction>
         <popupStructuredContributionCriteria
               objectClass="org.autumn.bpm.model.diagram.edit.parts.BoundaryEventEditPart"
               objectCount="1">
         </popupStructuredContributionCriteria>
      </popupContribution>
      <popupContribution
            class="org.eclipse.gmf.runtime.diagram.ui.providers.DiagramContextMenuProvider">
         <popupAction
               id="SetInterruptingAction"
               path="/additionsGroup">
         </popupAction>
         <popupStructuredContributionCriteria
               objectClass="org.autumn.bpm.model.diagram.edit.parts.BoundaryEvent2EditPart"
               objectCount="1">
         </popupStructuredContributionCriteria>
      </popupContribution>
   </contributionItemProvider>
</extension>

Diagram ActionProvider에서 SetInterruptingAction을 생성합니다.
package org.autumn.bpm.diagram.providers;

import org.autumn.bpm.diagram.action.SetInterruptingAction;
import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IWorkbenchPage;

/**
 * Provide Action for Diagram context menu.
 * 
 * @author sunny
 * 
 */
public class DiagramActionProvider extends AbstractContributionItemProvider {

	@Override
	protected IAction createAction(String actionId, IWorkbenchPartDescriptor partDescriptor) {
		IWorkbenchPage workbenchPage = partDescriptor.getPartPage();
		if (SetInterruptingAction.ID.equals(actionId)) {
			return new SetInterruptingAction(workbenchPage);
		}
		return super.createAction(actionId, partDescriptor);
	}

}

확장자에SetInterruptingAction에서 다이어그램으로 가는 오른쪽 단추 메뉴를 등록하고 Boundary Event Edit Part, Boundary Event 2 Edit Part와 연결합니다.
SetInterruptingAction은 init 방법에서 등록된 ID를 설정하고 오른쪽 단추 메뉴에 대응하는 아이콘을 설정할 수 있습니다.SetInterruptingAction은refresh 방법에서 오른쪽 키 메뉴에 Action 표시의 Label과Action을 사용할 수 있는지 설정합니다.SetInterruptingAction은 Dorun 방법에서 Action과 관련된 명령을 실행합니다. 예를 들어 Boundary Event의 cancelActivity 속성을 설정합니다.
package org.autumn.bpm.diagram.action;

import org.autumn.bpm.model.BoundaryEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.ui.action.AbstractActionHandler;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;

/**
 * Sets the cancelActivity property of Boundary Event. Repaints the Boundary
 * Event figure.
 * 
 * @author sunny
 * 
 */
public class SetInterruptingAction extends AbstractActionHandler {

	public static final String ID = "SetInterruptingAction"; //$NON-NLS-1$

	public SetInterruptingAction(IWorkbenchPart workbenchPart) {
		super(workbenchPart);
	}

	public SetInterruptingAction(IWorkbenchPage workbenchPage) {
		super(workbenchPage);
	}

	@Override
	public void init() {
		super.init();
		setId(ID);
		setDescription("Sets the cancelActivity property of the selected element");
		setToolTipText(getDescription());
	}

	@Override
	public void refresh() {
		IStructuredSelection selection = getStructuredSelection();
		if (selection == null || (selection.isEmpty())) {
			setEnabled(false);
			return;
		}
		if (selection.getFirstElement() instanceof IGraphicalEditPart) {
			EObject object = ((IGraphicalEditPart) selection.getFirstElement()).getNotationView().getElement();
			if (object instanceof BoundaryEvent) {
				BoundaryEvent boundaryEvent = (BoundaryEvent) object;
				String name = boundaryEvent.getName() == null ? "BoundaryEvent" : boundaryEvent.getName();
				if (boundaryEvent.isCancelActivity()) {
					setText("Set " + name + " as Non-Interrupting");
				} else {
					setText("Set " + name + " as Interrupting");
				}
				setEnabled(true);
				return;
			}
		}
		setText("Sets the interrupting property");
		setEnabled(false);
	}

	@Override
	protected void doRun(IProgressMonitor progressMonitor) {
		IStructuredSelection selection = getStructuredSelection();
		if (selection == null || (selection.isEmpty())) {
			return;
		}
		if (selection.getFirstElement() instanceof IGraphicalEditPart) {
			IGraphicalEditPart part = (IGraphicalEditPart) selection.getFirstElement();
			final EObject object = ((IGraphicalEditPart) selection.getFirstElement()).getNotationView().getElement();
			if (object instanceof BoundaryEvent) {
				part.getDiagramEditDomain().getDiagramCommandStack().execute(new ICommandProxy(new MyCommand(object) {

					@Override
					protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
							throws ExecutionException {
						if (object instanceof BoundaryEvent) {
							((BoundaryEvent) object).setCancelActivity(!(((BoundaryEvent) object).isCancelActivity()));
						}
						return CommandResult.newOKCommandResult();
					}
				}), progressMonitor);

			}
		}
	}

	private abstract class MyCommand extends AbstractTransactionalCommand {
		public MyCommand(EObject elt) {
			super((TransactionalEditingDomain) AdapterFactoryEditingDomain.getEditingDomainFor(elt),
					"SetInterruptingAction", getWorkspaceFiles(elt));
		}
	}

}

2. Boundary EventEdit Part의 감청 이벤트 처리
/**
	 * @author sunny
	 */
	@Override
	protected void handleNotificationEvent(Notification notification) {
		if (notification.getEventType() == Notification.SET || notification.getEventType() == Notification.UNSET) {
			if (ModelPackage.eINSTANCE.getBoundaryEvent_CancelActivity().equals(notification.getFeature())) {
				getPrimaryShape().setInterrupting(notification.getNewBooleanValue());
			}
		}
		super.handleNotificationEvent(notification);
	}

cancelActivity의 속성에서 set 또는 unset 이벤트가 발생한 후 Boundary Event 그래픽을 다시 그립니다
/**
		 * @author sunny
		 */
		public void setInterrupting(boolean isInterrupting) {
			this.isInterrupting = isInterrupting;
			revalidate();
			repaint();
		}
@Override
		protected void paintOuter(Graphics graphics) {
			ActivityPainter.paintEventIntermediate(graphics, this.getBoundsForHandle(), isInterrupting);
		}

Boundary Event를 만들 때 Boundary Event 모형의 cancelActivity를 Boundary Event 도형의 isInterrupting 속성에 값을 부여합니다
/**
		 * @generated NOT
		 * @author sunny
		 */
		private void createContents() {
			createContentsGen();
			
			if (resolveSemanticElement() instanceof BoundaryEvent) {
				BoundaryEvent boundaryEvent = (BoundaryEvent) resolveSemanticElement();
				isInterrupting = boundaryEvent.isCancelActivity();
			}
		}

좋은 웹페이지 즐겨찾기