001: package newprocess.diagram.providers;
002:
003: import java.lang.ref.WeakReference;
004:
005: import org.eclipse.gef.EditPart;
006: import org.eclipse.gef.EditPartFactory;
007: import org.eclipse.gmf.runtime.common.core.service.IOperation;
008: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
009: import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
010: import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
011: import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
012: import org.eclipse.gmf.runtime.notation.View;
013: import newprocess.diagram.edit.parts.New_processEditPartFactory;
014: import newprocess.diagram.edit.parts.ProcessEditPart;
015:
016: import newprocess.diagram.part.New_processVisualIDRegistry;
017:
018: /**
019: * @generated
020: */
021: public class New_processEditPartProvider extends
022: AbstractEditPartProvider {
023:
024: /**
025: * @generated
026: */
027: private EditPartFactory factory;
028:
029: /**
030: * @generated
031: */
032: private boolean allowCaching;
033:
034: /**
035: * @generated
036: */
037: private WeakReference cachedPart;
038:
039: /**
040: * @generated
041: */
042: private WeakReference cachedView;
043:
044: /**
045: * @generated
046: */
047: public New_processEditPartProvider() {
048: setFactory(new New_processEditPartFactory());
049: setAllowCaching(true);
050: }
051:
052: /**
053: * @generated
054: */
055: public final EditPartFactory getFactory() {
056: return factory;
057: }
058:
059: /**
060: * @generated
061: */
062: protected void setFactory(EditPartFactory factory) {
063: this .factory = factory;
064: }
065:
066: /**
067: * @generated
068: */
069: public final boolean isAllowCaching() {
070: return allowCaching;
071: }
072:
073: /**
074: * @generated
075: */
076: protected synchronized void setAllowCaching(boolean allowCaching) {
077: this .allowCaching = allowCaching;
078: if (!allowCaching) {
079: cachedPart = null;
080: cachedView = null;
081: }
082: }
083:
084: /**
085: * @generated
086: */
087: protected IGraphicalEditPart createEditPart(View view) {
088: EditPart part = factory.createEditPart(null, view);
089: if (part instanceof IGraphicalEditPart) {
090: return (IGraphicalEditPart) part;
091: }
092: return null;
093: }
094:
095: /**
096: * @generated
097: */
098: protected IGraphicalEditPart getCachedPart(View view) {
099: if (cachedView != null && cachedView.get() == view) {
100: return (IGraphicalEditPart) cachedPart.get();
101: }
102: return null;
103: }
104:
105: /**
106: * @generated
107: */
108: public synchronized IGraphicalEditPart createGraphicEditPart(
109: View view) {
110: if (isAllowCaching()) {
111: IGraphicalEditPart part = getCachedPart(view);
112: cachedPart = null;
113: cachedView = null;
114: if (part != null) {
115: return part;
116: }
117: }
118: return createEditPart(view);
119: }
120:
121: /**
122: * @generated
123: */
124: public synchronized boolean provides(IOperation operation) {
125: if (operation instanceof CreateGraphicEditPartOperation) {
126: View view = ((IEditPartOperation) operation).getView();
127: if (!ProcessEditPart.MODEL_ID
128: .equals(New_processVisualIDRegistry
129: .getModelID(view))) {
130: return false;
131: }
132: if (isAllowCaching() && getCachedPart(view) != null) {
133: return true;
134: }
135: IGraphicalEditPart part = createEditPart(view);
136: if (part != null) {
137: if (isAllowCaching()) {
138: cachedPart = new WeakReference(part);
139: cachedView = new WeakReference(view);
140: }
141: return true;
142: }
143: }
144: return false;
145: }
146: }
|