/**
*
*/
package newprocess.diagram.providers;
import newprocess.diagram.cust.decorators.ActivityTypeDecorator;
import newprocess.diagram.cust.decorators.OptionalDecorator;
import newprocess.diagram.cust.decorators.ReentrantDecorator;
import newprocess.diagram.cust.decorators.TemporalConditionDecorator;
import newprocess.diagram.edit.parts.AsyncActivity2EditPart;
import newprocess.diagram.edit.parts.AsyncActivityEditPart;
import newprocess.diagram.edit.parts.ConditionEditPart;
import newprocess.diagram.edit.parts.ConditionProxyEditPart;
import newprocess.diagram.edit.parts.EventEditPart;
import newprocess.diagram.edit.parts.ListenerEditPart;
import newprocess.diagram.edit.parts.ProcessEditPart;
import newprocess.diagram.edit.parts.SyncActivityEditPart;
import newprocess.diagram.part.New_processDiagramEditor;
import newprocess.diagram.part.New_processVisualIDRegistry;
import org.eclipse.gef.EditDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditDomain;
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.View;
/**
* @author sh
*
*/
public class ActivityDecoratorProvider implements IDecoratorProvider {
public static final String ACTIVITY_TYPE_DECORATOR_ID = "ActivityType";
public static final String OPTIONAL_DECORATOR_ID = "Optional";
public static final String REENETRANT_DECORATOR_ID = "Reentrant";
public static final String TEMPORAL_CONDITION_DECORATOR_ID = "TemporalCondition";
/* Create the decorator on the specified location
* @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider#createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget)
*/
public void createDecorators(IDecoratorTarget decoratorTarget) {
EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class);
if(isEditPartSupported(editPart)) {
Object model = editPart.getModel();
if(model instanceof View) {
View view = (View) model;
if(!(view instanceof Edge) && !view.isSetElement()) return;
}
EditDomain ed = editPart.getViewer().getEditDomain();
if(!(ed instanceof DiagramEditDomain)) return;
if(((DiagramEditDomain) ed).getEditorPart() instanceof New_processDiagramEditor) {
decoratorTarget.installDecorator(ACTIVITY_TYPE_DECORATOR_ID, new ActivityTypeDecorator(decoratorTarget));
decoratorTarget.installDecorator(OPTIONAL_DECORATOR_ID, new OptionalDecorator(decoratorTarget));
decoratorTarget.installDecorator(REENETRANT_DECORATOR_ID, new ReentrantDecorator(decoratorTarget));
decoratorTarget.installDecorator(TEMPORAL_CONDITION_DECORATOR_ID, new TemporalConditionDecorator(decoratorTarget));
}
}
}
/* Check if the provider provides the specified operation
* @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)
*/
public boolean provides(IOperation operation) {
if(!(operation instanceof CreateDecoratorsOperation)) return Boolean.FALSE;
IDecoratorTarget decoratorTarget = ((CreateDecoratorsOperation) operation).getDecoratorTarget();
View view = (View) decoratorTarget.getAdapter(View.class);
return view != null && ProcessEditPart.MODEL_ID
.equals(New_processVisualIDRegistry.getModelID(view));
}
/*
* Checks if the given EditPart should support Decorators
* @see org.eclipse.gmf.runtime.common.core.service.IProvider#addProviderChangeListener(org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener)
*/
private boolean isEditPartSupported(EditPart editPart) {
if(editPart instanceof AsyncActivityEditPart ||
editPart instanceof AsyncActivity2EditPart ||
editPart instanceof SyncActivityEditPart ||
editPart instanceof EventEditPart ||
editPart instanceof ListenerEditPart ||
editPart instanceof ConditionEditPart ||
editPart instanceof ConditionProxyEditPart)
return Boolean.TRUE;
return Boolean.FALSE;
}
public void addProviderChangeListener(IProviderChangeListener listener) {
}
public void removeProviderChangeListener(IProviderChangeListener listener) {
}
}
|