001: /**
002: *
003: */package newprocess.diagram.providers;
004:
005: import newprocess.diagram.cust.decorators.ActivityTypeDecorator;
006: import newprocess.diagram.cust.decorators.OptionalDecorator;
007: import newprocess.diagram.cust.decorators.ReentrantDecorator;
008: import newprocess.diagram.cust.decorators.TemporalConditionDecorator;
009: import newprocess.diagram.edit.parts.AsyncActivity2EditPart;
010: import newprocess.diagram.edit.parts.AsyncActivityEditPart;
011: import newprocess.diagram.edit.parts.ConditionEditPart;
012: import newprocess.diagram.edit.parts.ConditionProxyEditPart;
013: import newprocess.diagram.edit.parts.EventEditPart;
014: import newprocess.diagram.edit.parts.ListenerEditPart;
015: import newprocess.diagram.edit.parts.ProcessEditPart;
016: import newprocess.diagram.edit.parts.SyncActivityEditPart;
017: import newprocess.diagram.part.New_processDiagramEditor;
018: import newprocess.diagram.part.New_processVisualIDRegistry;
019:
020: import org.eclipse.gef.EditDomain;
021: import org.eclipse.gef.EditPart;
022: import org.eclipse.gmf.runtime.common.core.service.IOperation;
023: import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
024: import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
025: import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation;
026: import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
027: import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
028: import org.eclipse.gmf.runtime.notation.Edge;
029: import org.eclipse.gmf.runtime.notation.View;
030:
031: /**
032: * @author sh
033: *
034: */
035: public class ActivityDecoratorProvider implements IDecoratorProvider {
036:
037: public static final String ACTIVITY_TYPE_DECORATOR_ID = "ActivityType";
038: public static final String OPTIONAL_DECORATOR_ID = "Optional";
039: public static final String REENETRANT_DECORATOR_ID = "Reentrant";
040: public static final String TEMPORAL_CONDITION_DECORATOR_ID = "TemporalCondition";
041:
042: /* Create the decorator on the specified location
043: * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider#createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget)
044: */
045: public void createDecorators(IDecoratorTarget decoratorTarget) {
046: EditPart editPart = (EditPart) decoratorTarget
047: .getAdapter(EditPart.class);
048: if (isEditPartSupported(editPart)) {
049: Object model = editPart.getModel();
050: if (model instanceof View) {
051: View view = (View) model;
052: if (!(view instanceof Edge) && !view.isSetElement())
053: return;
054: }
055: EditDomain ed = editPart.getViewer().getEditDomain();
056: if (!(ed instanceof DiagramEditDomain))
057: return;
058:
059: if (((DiagramEditDomain) ed).getEditorPart() instanceof New_processDiagramEditor) {
060: decoratorTarget.installDecorator(
061: ACTIVITY_TYPE_DECORATOR_ID,
062: new ActivityTypeDecorator(decoratorTarget));
063: decoratorTarget.installDecorator(OPTIONAL_DECORATOR_ID,
064: new OptionalDecorator(decoratorTarget));
065: decoratorTarget.installDecorator(
066: REENETRANT_DECORATOR_ID,
067: new ReentrantDecorator(decoratorTarget));
068: decoratorTarget
069: .installDecorator(
070: TEMPORAL_CONDITION_DECORATOR_ID,
071: new TemporalConditionDecorator(
072: decoratorTarget));
073: }
074: }
075: }
076:
077: /* Check if the provider provides the specified operation
078: * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)
079: */
080: public boolean provides(IOperation operation) {
081: if (!(operation instanceof CreateDecoratorsOperation))
082: return Boolean.FALSE;
083: IDecoratorTarget decoratorTarget = ((CreateDecoratorsOperation) operation)
084: .getDecoratorTarget();
085: View view = (View) decoratorTarget.getAdapter(View.class);
086:
087: return view != null
088: && ProcessEditPart.MODEL_ID
089: .equals(New_processVisualIDRegistry
090: .getModelID(view));
091: }
092:
093: /*
094: * Checks if the given EditPart should support Decorators
095: * @see org.eclipse.gmf.runtime.common.core.service.IProvider#addProviderChangeListener(org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener)
096: */
097: private boolean isEditPartSupported(EditPart editPart) {
098: if (editPart instanceof AsyncActivityEditPart
099: || editPart instanceof AsyncActivity2EditPart
100: || editPart instanceof SyncActivityEditPart
101: || editPart instanceof EventEditPart
102: || editPart instanceof ListenerEditPart
103: || editPart instanceof ConditionEditPart
104: || editPart instanceof ConditionProxyEditPart)
105: return Boolean.TRUE;
106: return Boolean.FALSE;
107: }
108:
109: public void addProviderChangeListener(
110: IProviderChangeListener listener) {
111: }
112:
113: public void removeProviderChangeListener(
114: IProviderChangeListener listener) {
115: }
116: }
|